Skip to content
Snippets Groups Projects
Commit 91289028 authored by deuce's avatar deuce
Browse files

Handle failures to connect gracefully when running twint500.js

This allows using it to set the server/portname.
parent 5828702c
No related branches found
No related tags found
No related merge requests found
......@@ -137,6 +137,7 @@ function GameSettings()
var f=new File(fname("game.ini"));
var i;
this.save=GameSettings_Save;
if(file_exists(f.name)) {
f.open("r+");
for(i=0; i<GameSettingProperties.length; i++) {
......@@ -149,10 +150,14 @@ function GameSettings()
this[GameSettingProperties[i].prop]=GameSettingProperties[i].def;
}
}
db=new JSONClient(this.Server,this.Port);
var s=db.read(this.DB,'settings',LOCK_READ);
for(i in s) {
this[i]=s[i];
try {
db=new JSONClient(this.Server,this.Port);
var s=db.read(this.DB,'settings',LOCK_READ);
for(i in s) {
this[i]=s[i];
}
}
catch(e) {
db=undefined;
}
this.save=GameSettings_Save;
}
......@@ -40,6 +40,10 @@ var LOCK_WRITE=2;
var LOCK_READ=1;
Settings=new GameSettings();
if(db==undefined) {
alert("ERROR: Configuation invalid");
exit(1);
}
load(fname("ports.js"));
load(fname("planets.js"));
......
......@@ -12,13 +12,21 @@ var LOCK_READ=1;
load(fname("gamesettings.js"));
load(fname("sector_map.js"));
load(fname("ports_map.js"));
var Settings=new GameSettings();
var Settings;
try {
Settings=new GameSettings();
}
catch (e) {
print(e);
}
var db;
function ConfigureSettings()
{
var i;
var last=0;
var connected=false;
var old_help;
for(;;) {
var list=new Array();
......@@ -33,15 +41,35 @@ function ConfigureSettings()
var q=uifc.list(WIN_MID|WIN_SAV, 0, 0, 0, 0, 0, "Save Changes?", ["Yes", "No"]);
if(q!=-1) {
if(q==0)
db=new JSONClient(Settings.Server,Settings.Port);
db.connect();
try {
db=new JSONClient(Settings.Server,Settings.Port);
db.connect();
connected=true;
}
catch (e) {
old_help=uifc.help_text;
uifc.help_text=e;
uifc.msg("WARNING: Unable to connect to server (F1 for details)");
uifc.help_text=old_help;
connected=false;
}
Settings.save();
break;
}
}
else {
db=new JSONClient(Settings.Server,Settings.Port);
db.connect();
try {
db=new JSONClient(Settings.Server,Settings.Port);
db.connect();
connected=true;
}
catch (e) {
old_help=uifc.help_text;
uifc.help_text=e;
uifc.msg("WARNING: Unable to connect to server (F1 for details)");
uifc.help_text=old_help;
connected=false;
}
break;
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment