From 448cb41a28d84ccdc49dbca02f5f7a4afd603c52 Mon Sep 17 00:00:00 2001
From: mcmlxxix <>
Date: Mon, 21 Jan 2013 17:31:36 +0000
Subject: [PATCH] don't attempt to run maintenenace, load players, display
 rank, or anything else that you cant do if the game hasnt been initialized by
 the sysop (display message to user urging them yell at the sysop).

---
 xtrn/tw2/gamesettings.js |  3 +--
 xtrn/tw2/tw2.js          | 29 +++++++++++++++++++++--------
 2 files changed, 22 insertions(+), 10 deletions(-)

diff --git a/xtrn/tw2/gamesettings.js b/xtrn/tw2/gamesettings.js
index df32a31145..f60d707f1c 100644
--- a/xtrn/tw2/gamesettings.js
+++ b/xtrn/tw2/gamesettings.js
@@ -126,7 +126,7 @@ function GameSettings_Save()
 	else
 		f.iniRemoveKey(null, 'DB');
 
-	for(i=3; i<GameSettingProperties.length; i++) {
+	for(var i=3; i<GameSettingProperties.length; i++) {
 		s[GameSettingProperties[i].prop]=this[GameSettingProperties[i].prop];
 	}
 	db.write(Settings.DB,'settings',s,LOCK_WRITE);
@@ -150,7 +150,6 @@ function GameSettings()
 		}
 	}
 	db=new JSONClient(this.Server,this.Port);
-	db.connect();
 	var s=db.read(this.DB,'settings',LOCK_READ);
 	for(i in s) {
 		this[i]=s[i];
diff --git a/xtrn/tw2/tw2.js b/xtrn/tw2/tw2.js
index 7953f63f0f..419649671a 100644
--- a/xtrn/tw2/tw2.js
+++ b/xtrn/tw2/tw2.js
@@ -29,6 +29,7 @@ var Commodities=[
 var Settings;
 var player=null;
 var sector=null;
+var initialized=null;
 var exit_tw2=false;
 
 load("json-client.js");
@@ -37,6 +38,7 @@ load(fname("gamesettings.js"));
 var db;
 var LOCK_WRITE=2;
 var LOCK_READ=1;
+
 Settings=new GameSettings();
 
 load(fname("ports.js"));
@@ -226,7 +228,9 @@ function do_exit()
 			player.Put();
 	}
 	console.writeln("Returning to Door monitor...");
-	TWRank();
+	if(initialized != undefined) {
+		TWRank();
+	}
 }
 
 function Instructions()
@@ -276,7 +280,7 @@ function Production(place)
 
 function ShowOpeng()
 {
-	var len=db.read(Settings.DB,'twopeng.lengh',LOCK_READ);
+	var len=db.read(Settings.DB,'twopeng.length',LOCK_READ);
 	var i;
 	var msg;
 
@@ -286,6 +290,7 @@ function ShowOpeng()
 		console.writeln(msg.Message);
 		console.crlf();
 	}
+	return len;
 }
 
 function main()
@@ -294,10 +299,6 @@ function main()
 
 try {
 	js.on_exit("do_exit()");
-	/* Run maintenance */
-	if(Settings.MaintLastRan < today) {
-		RunMaint();
-	}
 
 	console.attributes="C";
 	console.crlf();
@@ -310,7 +311,20 @@ try {
 	console.center("Sysop  "+system.operator);
 	console.crlf();
 	console.crlf();
-	ShowOpeng();
+	initialized = ShowOpeng();
+	
+	/* Make sure game has been 'big-banged' */
+	if(initialized == undefined) {
+		console.attributes="R";
+		console.writeln("The game has not been initialized.");
+		console.writeln("Please notify the SysOp.");
+		exit(0);
+	}
+	
+	/* Run maintenance */
+	if(Settings.MaintLastRan < today) {
+		RunMaint();
+	}
 	console.attributes="W";
 	console.writeln("Initializing...");
 	console.writeln("Searching my records for your name.");
@@ -318,7 +332,6 @@ try {
 		exit(0);
 
 	console.pause();
-
 	while(player.KilledBy==0 && exit_tw2==false) {
 		if(EnterSector()) {
 			if(CheckSector())
-- 
GitLab