diff --git a/xtrn/tw2/computer.js b/xtrn/tw2/computer.js index 81a60b7164695f45a086b4507f37925b710c97e5..b90317e0d9208e1cc9a1ae350bcf325b382c7e13 100644 --- a/xtrn/tw2/computer.js +++ b/xtrn/tw2/computer.js @@ -32,10 +32,10 @@ function ComputerMenu() case 'P': /* 33780 */ console.write("What sector number is the port in? "); - seclen=db.read('tw2','sectors.length',LOCK_READ); + seclen=db.read(Settings.DB,'sectors.length',LOCK_READ); sec=InputFunc([{min:0,max:seclen-1}]); if(sec > 0 && sec < seclen) { - var sector=db.read('tw2','sectors.'+sec,LOCK_READ); + var sector=db.read(Settings.DB,'sectors.'+sec,LOCK_READ); if(sector.Port==0 || (sector.Fighters>0 && sector.Fighters!=player.Record)) { console.crlf(); console.writeln("I have no information about that port."); @@ -52,7 +52,7 @@ function ComputerMenu() case 'S': /* 33830 */ console.write("What sector do you want to get to? "); - seclen=db.read('tw2','sectors.length',LOCK_READ); + seclen=db.read(Settings.DB,'sectors.length',LOCK_READ); sec=InputFunc([{min:0,max:seclen-1}]); if(sec > 0 && sec < seclen) { if(sec==player.Sector) { @@ -83,7 +83,7 @@ function ComputerMenu() console.crlf(); console.write("Ranking Players."); TWRank(); - console.writeln(db.read('tw2','ranking',LOCK_READ)); + console.writeln(db.read(Settings.DB,'ranking',LOCK_READ)); break; case 'M': /* 33960 */ diff --git a/xtrn/tw2/editor.js b/xtrn/tw2/editor.js index 5e752dcf65a676535a1937ba68f8eb9675dd4f00..ccd17125945a10eeb3726e626d62fad1bf7d693d 100644 --- a/xtrn/tw2/editor.js +++ b/xtrn/tw2/editor.js @@ -131,12 +131,12 @@ function PlanetEdit() console.write("Planet name or sector number: "); var plid=console.getstr(42); var planet=null; - var planetsLen=db.read('tw2','planets.length',LOCK_READ); + var planetsLen=db.read(Settings.DB,'planets.length',LOCK_READ); var sector=null; /* First, search by name */ for(i=1; i<planetsLen; i++) { - planet=db.read('tw2','planets.'+i,LOCK_READ); + planet=db.read(Settings.DB,'planets.'+i,LOCK_READ); if(planet.Name.toUpperCase().search(plid.toUpperCase())!=-1) { console.write(planet.Name+" ["+planet.Sector+"] Y/[N]? "); if(InputFunc(['Y','N'])=='Y') { @@ -153,11 +153,11 @@ function PlanetEdit() secnum=parseInt(plid); } catch (e) {} - var seclen=db.read('tw2','sectors.length',LOCK_READ); + var seclen=db.read(Settings.DB,'sectors.length',LOCK_READ); if(secnum > 0 && secnum < seclen) { - sector=db.read('tw2','sectors.'+secnum,LOCK_READ); + sector=db.read(Settings.DB,'sectors.'+secnum,LOCK_READ); if(sector.Planet > 0 && sector.Planet < planets.length) { - planet=db.read('tw2','planets.'+sector.Planet,LOCK_READ); + planet=db.read(Settings.DB,'planets.'+sector.Planet,LOCK_READ); console.write(planet.Name+" ["+planet.Sector+"] Y/[N]? "); if(InputFunc(['Y','N'])!='Y') { planet=null; @@ -177,11 +177,11 @@ function PlanetEdit() if(planetNum==-1) console.writeln("No room for additional planets."); else { - planet=db.read('tw2','planets.'+planetNum,LOCK_READ); + planet=db.read(Settings.DB,'planets.'+planetNum,LOCK_READ); console.write("Sector? "); planet.Sector=InputFunc([{min:0,max:planets.length-1}]); if(planet.Sector > 0 && planet.Sector<planets.length) { - sector=db.read('tw2','sectors.'+planet.Sector,LOCK_READ); + sector=db.read(Settings.DB,'sectors.'+planet.Sector,LOCK_READ); sector.Planet=planet.Record; console.write("Planet name: "); planet.Name=console.getstr(41); @@ -198,13 +198,13 @@ function PlanetEdit() return; if(sector==null) - sector=db.read('tw2','sectors.'+planet.Sector,LOCK_READ); + sector=db.read(Settings.DB,'sectors.'+planet.Sector,LOCK_READ); var oldsector=planet.Sector; LockedEditProperties(planet, PlanetProperties); /* Planet moved... */ if(planet.Sector != oldsector) { - var newsector=db.read('tw2','sectors.'+planet.Sector,LOCK_READ); + var newsector=db.read(Settings.DB,'sectors.'+planet.Sector,LOCK_READ); if(newsector.Planet > 0) { console.writeln("Sector "+newsector.Record+" already has a planet. Planet returned to sector "+sector.Record+"."); @@ -212,7 +212,7 @@ function PlanetEdit() } else { sector.Planet=0; - db.write('tw2','sectors.'+oldsector); + db.write(Settings.DB,'sectors.'+oldsector); newsector.Planet=planetNum; sector=newsector; } @@ -220,8 +220,8 @@ function PlanetEdit() /* Planet doesn't exist (move to sector zero */ if(!planet.Created) planet.Sector=0; - db.write('tw2','planets.'+planetNum,planet,LOCK_WRITE); - db.write('tw2','sectors.'+planet.Sector,sector,LOCK_WRITE); + db.write(Settings.DB,'planets.'+planetNum,planet,LOCK_WRITE); + db.write(Settings.DB,'sectors.'+planet.Sector,sector,LOCK_WRITE); } function PlayerEdit() @@ -281,13 +281,13 @@ function PortEdit() console.write("Port name or sector number: "); var plid=console.getstr(42); var port=null; - var portsLen=db.read('tw2','ports.length',LOCK_READ); + var portsLen=db.read(Settings.DB,'ports.length',LOCK_READ); var portNum=0; var sector=null; /* First, search by name */ for(i=1; i<portsLen; i++) { - port=db.read('tw2','ports.'+i,LOCK_READ); + port=db.read(Settings.DB,'ports.'+i,LOCK_READ); if(port.Name.toUpperCase().search(plid.toUpperCase())!=-1) { console.write(port.Name+" Y/[N]? "); if(InputFunc(['Y','N'])=='Y') { @@ -304,12 +304,12 @@ function PortEdit() secnum=parseInt(plid); } catch (e) {} - var seclen=db.read('tw2','sectors.length',LOCK_READ); + var seclen=db.read(Settings.DB,'sectors.length',LOCK_READ); if(secnum > 0 && secnum < seclen) { - sector=db.read('tw2','sectors.'+secnum,LOCK_READ); - var plen=db.read('tw2','ports.length',LOCK_READ); + sector=db.read(Settings.DB,'sectors.'+secnum,LOCK_READ); + var plen=db.read(Settings.DB,'ports.length',LOCK_READ); if(sector.Port > 0 && sector.Port < plen) { - port=db.read('tw2','ports.'+sector.Port,LOCK_READ); + port=db.read(Settings.DB,'ports.'+sector.Port,LOCK_READ); console.write(port.Name+" ["+secnum+"] Y/[N]? "); if(InputFunc(['Y','N'])!='Y') { port=null; @@ -327,36 +327,36 @@ function PortEdit() return; if(sector==null) - sector=db.read('tw2','sectors.'+port.Sector,LOCK_READ); + sector=db.read(Settings.DB,'sectors.'+port.Sector,LOCK_READ); LockedEditProperties(port, PortProperties); - db.write('tw2','ports.'+portNum,port,LOCK_WRITE); + db.write(Settings.DB,'ports.'+portNum,port,LOCK_WRITE); sector.Put(); } function SectorEdit() { - var seclen=db.read('tw2','sectors.length',LOCK_READ); + var seclen=db.read(Settings.DB,'sectors.length',LOCK_READ); console.write("Sector: "); var sec=InputFunc([{max:(seclen-1)}]); if(sec>0 && sec <seclen) { - var sector=db.read('tw2','sectors.'+sec,LOCK_READ); + var sector=db.read(Settings.DB,'sectors.'+sec,LOCK_READ); EditProperties(sector, SectorProperties); - db.write('tw2','sectors.'+sec,sector,LOCK_WRITE); + db.write(Settings.DB,'sectors.'+sec,sector,LOCK_WRITE); } } function TeamEdit() { console.write("Team: "); - var t=InputFunc([{max:(db.read('tw2','teams.length',LOCK_READ)-1)}]); + var t=InputFunc([{max:(db.read(Settings.DB,'teams.length',LOCK_READ)-1)}]); if(t>0 && t <teams.length) { - var team=db.read('tw2','teams.length', LOCK_READ); + var team=db.read(Settings.DB,'teams.length', LOCK_READ); LockedEditProperties(team, TeamProperties); - db.write('tw2','teams.length', team, LOCK_WRITE); + db.write(Settings.DB,'teams.length', team, LOCK_WRITE); } } diff --git a/xtrn/tw2/gamesettings.js b/xtrn/tw2/gamesettings.js index 56bfb185cd225e0b143f0540d6c3034d8a989430..c581a7b82065ecde02e338b48a834ff8f8baf57f 100644 --- a/xtrn/tw2/gamesettings.js +++ b/xtrn/tw2/gamesettings.js @@ -15,6 +15,12 @@ var GameSettingProperties=[ ,type:"Integer" ,def:"10088" } + ,{ // This index (2) is hard-coded. + prop:"DB" + ,name:"Server scope" + ,type:"String" + ,def:"tw2" + } ,{ prop:"EditorPassword" ,name:"Editor Password" @@ -115,11 +121,15 @@ function GameSettings_Save() f.iniSetValue(null, 'Port', this.Server); else f.iniRemoveKey(null, 'Port'); + if(this.Port!=GameSettingProperties[2].def) + f.iniSetValue(null, 'DB', this.DB); + else + f.iniRemoveKey(null, 'DB'); - for(i=2; i<GameSettingProperties.length; i++) { + for(i=3; i<GameSettingProperties.length; i++) { s[GameSettingProperties[i].prop]=this[GameSettingProperties[i].prop]; } - db.write('tw2','settings',s,LOCK_WRITE); + db.write(Settings.DB,'settings',s,LOCK_WRITE); } function GameSettings() @@ -141,7 +151,7 @@ function GameSettings() } db=new JSONClient(this.Server,this.Port); db.connect(); - var s=db.read('tw2','settings',LOCK_READ); + var s=db.read(this.DB,'settings',LOCK_READ); for(i in s) { this[i]=s[i]; } diff --git a/xtrn/tw2/maint.js b/xtrn/tw2/maint.js index 2df61106c5717ce0c5b20248230bd9ebee43646e..327f65cde1aa93e489d03ac4b61c681c0a83fe98 100644 --- a/xtrn/tw2/maint.js +++ b/xtrn/tw2/maint.js @@ -37,7 +37,7 @@ function RunMaint() console.writeln(" by Chris Sherrick (PTL)"); console.crlf(); console.writeln("This program is run once per day."); - db.push('tw2','log',{Date:strftime("%a %b %d %H:%M:%S %Z"),Message:user.alias+": Maintence program ran"},LOCK_WRITE); + db.push(Settings.DB,'log',{Date:strftime("%a %b %d %H:%M:%S %Z"),Message:user.alias+": Maintence program ran"},LOCK_WRITE); DeleteInactive(); @@ -50,7 +50,7 @@ function DeleteInactive() { console.writeln("Deleting inactive players"); var oldest_allowed=strftime("%Y:%m:%d",time()-Settings.DaysInactivity*86400); - var allplayers=db.read('tw2','players',LOCK_READ); + var allplayers=db.read(Settings.DB,'players',LOCK_READ); for(i=1; i<allplayers.length; i++) { if(allplayers[i].QWKID==system.qwk_id && allplayers[i].UserNumber > 0) { if((!file_exists(system.data_dir+format("user/%04d.tw2",p.UserNumber))) || (p.LastOnDay < oldest_allowed && p.KilledBy != 0)) { @@ -63,26 +63,26 @@ function DeleteInactive() function MoveCabalGroup(cabal, cabalRecord, target) { var i; - var cabalsLen=db.read('tw2','cabals.length'); + var cabalsLen=db.read(Settings.DB,'cabals.length'); if(cabal.Sector==0 || cabal.Size < 1) return; - db.lock('tw2','sectors.'+cabal.Sector,LOCK_WRITE); - var sector=db.read('tw2','sectors.'+cabal.Sector); + db.lock(Settings.DB,'sectors.'+cabal.Sector,LOCK_WRITE); + var sector=db.read(Settings.DB,'sectors.'+cabal.Sector); sector.Fighters -= cabal.Size; if(sector.Fighters < 1) { sector.Fighters=0; sector.FighterOwner=0; } - db.write('tw2','sectors.'+cabal.Sector,sector); - db.unlock('tw2','sectors.'+cabal.Sector); + db.write(Settings.DB,'sectors.'+cabal.Sector,sector); + db.unlock(Settings.DB,'sectors.'+cabal.Sector); /* Set new sector */ cabal.Sector=target; - db.lock('tw2','sectors.'+cabal.Sector,LOCK_WRITE); - sector=db.read('tw2','sectors.'+cabal.Sector); + db.lock(Settings.DB,'sectors.'+cabal.Sector,LOCK_WRITE); + sector=db.read(Settings.DB,'sectors.'+cabal.Sector); /* Attack dropped fighters */ if(sector.Fighters > 0 && sector.FighterOwner != -1) { @@ -110,8 +110,8 @@ function MoveCabalGroup(cabal, cabalRecord, target) msg.To=sector.FighterOwner; msg.From=-1; msg.Destroyed=killed; - db.push('tw2','updates',msg,LOCK_WRITE); - db.push('tw2','log',{Date:strftime("%a %b %d %H:%M:%S %Z"),Message:" Group "+cabalRecord+" --> Sector "+target+" ("+ownername+"): lost "+killed+", dstrd "+lost+" ("+(sector.Fighters==0?"Player":"Cabal")+" ftrs dstrd)"},LOCK_WRITE); + db.push(Settings.DB,'updates',msg,LOCK_WRITE); + db.push(Settings.DB,'log',{Date:strftime("%a %b %d %H:%M:%S %Z"),Message:" Group "+cabalRecord+" --> Sector "+target+" ("+ownername+"): lost "+killed+", dstrd "+lost+" ("+(sector.Fighters==0?"Player":"Cabal")+" ftrs dstrd)"},LOCK_WRITE); if(cabal.Size==0) { cabal=eval(DefaultCabal.toSource()); return; @@ -121,8 +121,8 @@ function MoveCabalGroup(cabal, cabalRecord, target) sector.Fighters=cabal.Size; } } - db.write('tw2','sectors.'+cabal.Sector,sector); - db.unlock('tw2','sectors.'+cabal.Sector); + db.write(Settings.DB,'sectors.'+cabal.Sector,sector); + db.unlock(Settings.DB,'sectors.'+cabal.Sector); CabalAttack(cabal, cabalRecord); if(cabal.Sector==0 || cabal.Size < 1) @@ -133,7 +133,7 @@ function MoveCabalGroup(cabal, cabalRecord, target) for(i=1; i<cabalsLen; i++) { if(i==cabalRecord) continue; - var othercabal=db.read('tw2','cabals.'+i); + var othercabal=db.read(Settings.DB,'cabals.'+i); /* Merge Groups */ if(othercabal.Sector==cabal.Sector) { if(i < cabalRecord) { @@ -144,8 +144,8 @@ function MoveCabalGroup(cabal, cabalRecord, target) cabal.Size += othercabal.Size; othercabal=eval(DefaultCabal.toSource()); } - db.write('tw2','cabals.'+cabalRecord, cabal); - db.write('tw2','cabals.'+i, othercabal); + db.write(Settings.DB,'cabals.'+cabalRecord, cabal); + db.write(Settings.DB,'cabals.'+i, othercabal); } } } @@ -158,29 +158,29 @@ function MoveCabal() var group2; var wgroup,agroup,hgroup; var path,next; - db.lock('tw2','cabals',LOCK_WRITE); - var cabalsLen=db.read('tw2','cabals.length'); + db.lock(Settings.DB,'cabals',LOCK_WRITE); + var cabalsLen=db.read(Settings.DB,'cabals.length'); console.writeln("Moving the Cabal."); - db.push('tw2','log',{Date:strftime("%a %b %d %H:%M:%S %Z"),Message:" Cabal report:"},LOCK_WRITE); + db.push(Settings.DB,'log',{Date:strftime("%a %b %d %H:%M:%S %Z"),Message:" Cabal report:"},LOCK_WRITE); /* Validate Groups and count the total */ for(i=1; i<cabalsLen; i++) { - cabal=db.read('tw2','cabals.'+i); - var sector=db.read('tw2','sectors.'+cabal.Sector,LOCK_READ); + cabal=db.read(Settings.DB,'cabals.'+i); + var sector=db.read(Settings.DB,'sectors.'+cabal.Sector,LOCK_READ); cabal.Size=sector.Fighters; if(sector.FighterOwner != -1 || sector.Fighters==0) { cabal.Sector=0; cabal.Size=0; cabal.Goal=0; } - db.write('tw2','cabals.'+i, cabal); + db.write(Settings.DB,'cabals.'+i, cabal); total+=cabal.Size; } /* Move group 2 into sector 85 (merge into group 1) */ - cabal=db.read('tw2','cabals.2'); + cabal=db.read(Settings.DB,'cabals.2'); MoveCabalGroup(cabal, 2, 85); - db.write('tw2','cabals.2',cabal); + db.write(Settings.DB,'cabals.2',cabal); /* Note, this seems to have a max limit of 2000 for regeneration */ var regen=Settings.CabalRegeneration; @@ -189,22 +189,22 @@ function MoveCabal() if(regen<1) regen=0; - cabal=db.read('tw2','cabals.1'); + cabal=db.read(Settings.DB,'cabals.1'); cabal.Size += regen; /* Split off group 2 */ - group2=db.read('tw2','cabals.2'); + group2=db.read(Settings.DB,'cabals.2'); if(cabal.Size > 1000) { group2.Size=cabal.Size-1000; group2.Sector=85; MoveCabalGroup(group2, 2, 83); - db.write('tw2','cabals.2',cabal2); + db.write(Settings.DB,'cabals.2',cabal2); } - var seclen=db.read('tw2','sectors.length',LOCK_READ); + var seclen=db.read(Settings.DB,'sectors.length',LOCK_READ); /* Create wandering groups */ for(i=3; i<6; i++) { - wgroup=db.read('tw2','cabals.'+i); + wgroup=db.read(Settings.DB,'cabals.'+i); if(wgroup.Size < 1 || wgroup.Sector < 1 || wgroup.Sector >= seclen) { if(group2.size >= 600) { wgroup.Size=100; @@ -217,13 +217,13 @@ function MoveCabal() else { wgroup=eval(DefaultCabal.toSource()); } - db.write('tw2','cabals.'+i, wgroup); + db.write(Settings.DB,'cabals.'+i, wgroup); } } /* Create attack groups */ for(i=6; i<9; i++) { - agroup=db.read('tw2','cabals.'+i); + agroup=db.read(Settings.DB,'cabals.'+i); if(agroup.Size < 1 || agroup.Sector < 1 || agroup.Sector >= seclen) { if(group2.size >= 550) { agroup.Size=50; @@ -236,12 +236,12 @@ function MoveCabal() else { agroup=eval(DefaultCabal.toSource()); } - db.write('tw2','cabals.'+i, agroup); + db.write(Settings.DB,'cabals.'+i, agroup); } } /* Create hunter group */ - hgroup=db.read('tw2','cabals.9'); + hgroup=db.read(Settings.DB,'cabals.9'); if(hgroup.Size < 1 || hgroup.Sector < 1 || hgroup.Sector >= seclen) { if(group2.size >= 500) { hgroup.Size=group2.Size-500; @@ -252,13 +252,13 @@ function MoveCabal() else { hgroup=eval(DefaultCabal.toSource()); } - db.write('tw2','cabals.9', hgroup); + db.write(Settings.DB,'cabals.9', hgroup); } - db.write('tw2','cabals.2', group2); + db.write(Settings.DB,'cabals.2', group2); /* Move wandering groups */ for(i=3; i<6; i++) { - wgroup=db.read('tw2','cabals.'+i); + wgroup=db.read(Settings.DB,'cabals.'+i); if(wgroup.Size < 1 || wgroup.Sector == 0) continue; /* Choose new target */ @@ -273,12 +273,12 @@ function MoveCabal() while(path[0] < 8) path.shift(); MoveCabalGroup(wgroup,i,path[0]); - db.write('tw2','cabals.'+i,wgroup); + db.write(Settings.DB,'cabals.'+i,wgroup); } /* Move Attack Groups */ for(i=6; i<9; i++) { - agroup=db.read('tw2','cabals.'+i); + agroup=db.read(Settings.DB,'cabals.'+i); if(agroup.Size < 1 || agroup.Sector == 0) continue; /* Choose new target */ @@ -295,13 +295,13 @@ function MoveCabal() if(next < 8) continue; MoveCabalGroup(agroup,i,next); - db.write('tw2','cabals.'+i,agroup); + db.write(Settings.DB,'cabals.'+i,agroup); } } /* Move hunter groups... */ for(i=9; i<10; i++) { - hgroup=db.read('tw2','cabals.'+i); + hgroup=db.read(Settings.DB,'cabals.'+i); if(hgroup.Size < 1 || hgroup.Sector == 0) continue; /* Choose target */ @@ -313,11 +313,11 @@ function MoveCabal() while(path.length > 0 && hgroup.Size > 0) { next=path.shift(); MoveCabalGroup(hgroup,i,next); - db.write('tw2','cabals.'+i,hgroup); + db.write(Settings.DB,'cabals.'+i,hgroup); } } } - db.unlock('tw2','cabals',LOCK_WRITE); + db.unlock(Settings.DB,'cabals',LOCK_WRITE); } function CabalAttack(cabal, cabalRecord) @@ -331,10 +331,10 @@ function CabalAttack(cabal, cabalRecord) var attackwith=0; var ranks=RankPlayers(); - db.lock('tw2','sectors.'+cabal.Sector,LOCK_WRITE); - var sector=db.read('tw2','sectors.'+cabal.Sector); + db.lock(Settings.DB,'sectors.'+cabal.Sector,LOCK_WRITE); + var sector=db.read(Settings.DB,'sectors.'+cabal.Sector); if(sector.FighterOwner != -1) { /* Huh? */ - db.unlock('tw2','sectors.'+cabal.Sector); + db.unlock(Settings.DB,'sectors.'+cabal.Sector); return; } @@ -380,7 +380,7 @@ function CabalAttack(cabal, cabalRecord) } } cabal.Size += attackwith; - db.push('tw2','log',{Date:strftime("%a %b %d %H:%M:%S %Z"),Message:" Group "+cabalRecord+" --> "+otherplayer.Alias+": lost "+killed+ ", dstrd "+killed+" ("+(cabal.Size==0?"Cabal":"Player")+" dstrd)"},LOCK_WRITE); + db.push(Settings.DB,'log',{Date:strftime("%a %b %d %H:%M:%S %Z"),Message:" Group "+cabalRecord+" --> "+otherplayer.Alias+": lost "+killed+ ", dstrd "+killed+" ("+(cabal.Size==0?"Cabal":"Player")+" dstrd)"},LOCK_WRITE); if(cabal.Size==0) cabaleval(DefaultCabal.toSource()); else { /* Player destroyed by the cabal! */ @@ -388,28 +388,28 @@ function CabalAttack(cabal, cabalRecord) otherplayer.Sector=0; } otherplayer.Put(); - db.write('tw2','cabals.'+cabalRecord, cabal); + db.write(Settings.DB,'cabals.'+cabalRecord, cabal); } sector.Fighters += cabal.Size; if(cabal.Size > 0) sector.FighterOwner=-1; - db.write('tw2','sectors.'+cabal.Sector,sector); - db.unlock('tw2','sectors.'+cabal.Sector); + db.write(Settings.DB,'sectors.'+cabal.Sector,sector); + db.unlock(Settings.DB,'sectors.'+cabal.Sector); } function InitializeCabal() { - var sector=db.read('tw2','sectors.85',LOCK_READ); + var sector=db.read(Settings.DB,'sectors.85',LOCK_READ); uifc.pop("Initializing the Cabal"); sector_map[85].Fighters=3000; sector_map[85].FightersOwner=-1; sector.Fighters=3000; sector.FightersOwner=-1; - db.write('tw2','sectors.85',sector,LOCK_WRITE); - db.lock('tw2','cabals',LOCK_WRITE); - db.write('tw2','cabals',[]); - db.push('tw2','cabals',DefaultCabal); + db.write(Settings.DB,'sectors.85',sector,LOCK_WRITE); + db.lock(Settings.DB,'cabals',LOCK_WRITE); + db.write(Settings.DB,'cabals',[]); + db.push(Settings.DB,'cabals',DefaultCabal); for(i=1; i<10; i++) { var grp=eval(DefaultCabal.toSource()); if(i==1) { @@ -417,7 +417,7 @@ function InitializeCabal() grp.Sector=85; grp.Goal=85; } - db.write('tw2','cabals.'+i,grp); + db.write(Settings.DB,'cabals.'+i,grp); } - db.unlock('tw2','cabals'); + db.unlock(Settings.DB,'cabals'); } diff --git a/xtrn/tw2/messages.js b/xtrn/tw2/messages.js index 7c50e02c70f996997459912cc0a4e540e109c1ef..94d11f04cdd955d49eb811141441dcd8ad92ce21 100644 --- a/xtrn/tw2/messages.js +++ b/xtrn/tw2/messages.js @@ -56,8 +56,8 @@ function ReadPMsg() { console.writeln("The following happened to your ship since your last time on:"); // TODO: Fix this up... - db.lock('tw2','updates',LOCK_WRITE); - var updates=db.read('tw2','updates'); + db.lock(Settings.DB,'updates',LOCK_WRITE); + var updates=db.read(Settings.DB,'updates'); var count=0; var msgstr=''; for(i=0; i<updates.length; i++) { @@ -79,8 +79,8 @@ function ReadPMsg() i--; } } - db.write('tw2','updates',updates); - db.unlock('tw2','updates'); + db.write(Settings.DB,'updates',updates); + db.unlock(Settings.DB,'updates'); if(count==0) console.writeln("Nothing"); else @@ -97,7 +97,7 @@ function RadioMessage(from, to, msg) rmsg.From=from; rmsg.To=to; rmsg.Message=msg; - db.push('tw2','radio',rmsg,LOCK_WRITE); + db.push(Settings.DB,'radio',rmsg,LOCK_WRITE); console.writeln("Message sent."); return; } @@ -110,8 +110,8 @@ function ReadRadio() console.crlf(); console.writeln("Checking for Radio Messages sent to you."); - db.lock('tw2','radio',LOCK_WRITE); - var radio=db.read('tw2','radio'); + db.lock(Settings.DB,'radio',LOCK_WRITE); + var radio=db.read(Settings.DB,'radio'); for(i=0; i<radio.length; i++) { if(radio[i].Read) continue; @@ -131,8 +131,8 @@ function ReadRadio() i--; count++; } - db.write('tw2','radio',radio); - db.unlock('tw2','radio'); + db.write(Settings.DB,'radio',radio); + db.unlock(Settings.DB,'radio'); if(count < 1) console.writeln("None Received."); else @@ -173,12 +173,12 @@ function ResetAllMessages() var i; uifc.pop("SysOp Messages"); - db.write('tw2','log',[],LOCK_WRITE); - db.push('tw2','log',{Date:strftime("%a %b %d %H:%M:%S %Z"),Message:" TW 500 initialized"},LOCK_WRITE); + db.write(Settings.DB,'log',[],LOCK_WRITE); + db.push(Settings.DB,'log',{Date:strftime("%a %b %d %H:%M:%S %Z"),Message:" TW 500 initialized"},LOCK_WRITE); uifc.pop("Player Messages"); - db.write('tw2','updates',[],LOCK_WRITE); + db.write(Settings.DB,'updates',[],LOCK_WRITE); uifc.pop("Radio Messages"); - db.write('tw2','radio',[],LOCK_WRITE); + db.write(Settings.DB,'radio',[],LOCK_WRITE); } diff --git a/xtrn/tw2/planets.js b/xtrn/tw2/planets.js index 13717faa372676ed842fd4fc666997a4f82dd63c..489c84110d2e413c4cdbc24412d8184931ef7221 100644 --- a/xtrn/tw2/planets.js +++ b/xtrn/tw2/planets.js @@ -58,7 +58,7 @@ function LandOnPlanet() console.crlf(); console.attributes="HY"; console.writeln("Landing..."); - var sector=db.read('tw2','sectors.'+player.Sector,LOCK_READ); + var sector=db.read(Settings.DB,'sectors.'+player.Sector,LOCK_READ); var planet=null; if(sector.Planet==0) { @@ -68,24 +68,24 @@ function LandOnPlanet() else { /* 32310 */ /* Lock the planet file and ensure we can land... */ - db.lock('tw2','planets.'+sector.Planet,LOCK_WRITE); - planet=db.read('tw2','planets.'+sector.Planet); + db.lock(Settings.DB,'planets.'+sector.Planet,LOCK_WRITE); + planet=db.read(Settings.DB,'planets.'+sector.Planet); planet.OccupiedCount++; player.Landed=true; player.Put(); LockedProduction(planet); - db.write('tw2','planets.'+sector.Planet,planet); - db.unlock('tw2','planets.'+sector.Planet); + db.write(Settings.DB,'planets.'+sector.Planet,planet); + db.unlock(Settings.DB,'planets.'+sector.Planet); PlanetReport(sector.Planet); console.attributes="HW"; PlanetMenu(sector.Planet); - db.lock('tw2','planets.'+sector.Planet,LOCK_WRITE); - planet=db.read('tw2','planets.'+sector.Planet); + db.lock(Settings.DB,'planets.'+sector.Planet,LOCK_WRITE); + planet=db.read(Settings.DB,'planets.'+sector.Planet); planet.OccupiedCount--; - db.write('tw2','planets.'+sector.Planet,planet); - db.unlock('tw2','planets.'+sector.Planet); + db.write(Settings.DB,'planets.'+sector.Planet,planet); + db.unlock(Settings.DB,'planets.'+sector.Planet); player.Landed=false; player.Put(); } @@ -98,11 +98,11 @@ function NextAvailablePlanet() var planet; var planetLen; - db.lock('tw2','planets',LOCK_WRITE); - planetLen=db.read('tw2','planets.length'); + db.lock(Settings.DB,'planets',LOCK_WRITE); + planetLen=db.read(Settings.DB,'planets.length'); for(i=1; i<planetLen; i++) { - planet=db.read('tw2','planets.'+i); + planet=db.read(Settings.DB,'planets.'+i); if(!planet.Created) break; planet=null; @@ -111,12 +111,12 @@ function NextAvailablePlanet() if(planet != null) { planet.Created=true; planet.Sector=0; - db.write('tw2','planets.'+i,planet); - db.unlock('tw2','planets'); - db.lock('tw2','planets.'+i,LOCK_WRITE); + db.write(Settings.DB,'planets.'+i,planet); + db.unlock(Settings.DB,'planets'); + db.lock(Settings.DB,'planets.'+i,LOCK_WRITE); } else { - db.unlock('tw2','planets'); + db.unlock(Settings.DB,'planets'); return -1; } return(i); @@ -143,14 +143,14 @@ function CreatePlanet(sectorNum) return(false); } - planet=db.read('tw2','planets.'+planetNum); - db.unlock('tw2','planets.'+planetNum); + planet=db.read(Settings.DB,'planets.'+planetNum); + db.unlock(Settings.DB,'planets.'+planetNum); planet.Name=''; console.write("What do you want to name this planet? (41 chars. max)? "); planet.Name=console.getstr(41); - db.lock('tw2','planets.'+planetNum,LOCK_WRITE); - db.lock('tw2','sectors.'+sectorNum,LOCK_WRITE); - var sector=db.read('tw2','sectors.'+sectorNum); + db.lock(Settings.DB,'planets.'+planetNum,LOCK_WRITE); + db.lock(Settings.DB,'sectors.'+sectorNum,LOCK_WRITE); + var sector=db.read(Settings.DB,'sectors.'+sectorNum); if(sector.Planet != 0) { console.crlf(); console.writeln("While you were deciding on a name, someone else has created a planet in this"); @@ -159,9 +159,9 @@ function CreatePlanet(sectorNum) } if(planet.Name=='') { planet.Created=false; - db.write('tw2','planets.'+planetNum, planet); - db.unlock('tw2','planets.'+planetNum); - db.unlock('tw2','sectors.'+sectorNum); + db.write(Settings.DB,'planets.'+planetNum, planet); + db.unlock(Settings.DB,'planets.'+planetNum); + db.unlock(Settings.DB,'sectors.'+sectorNum); return(false); } for(i=0; i<Commodities.length; i++) { @@ -174,11 +174,11 @@ function CreatePlanet(sectorNum) sector.Planet=planetNum; planet.LastUpdated=time(); planet.Created=true; - db.write('tw2','planets.'+planetNum, planet); - db.write('tw2','sectors.'+sectorNum, sector); - db.unlock('tw2','planets.'+planetNum); - db.unlock('tw2','sectors.'+sectorNum); - db.push('tw2','log',{Date:strftime("%a %b %d %H:%M:%S %Z"),Message:" - "+player.Alias+" made a planet: "+planet.Name},LOCK_WRITE); + db.write(Settings.DB,'planets.'+planetNum, planet); + db.write(Settings.DB,'sectors.'+sectorNum, sector); + db.unlock(Settings.DB,'planets.'+planetNum); + db.unlock(Settings.DB,'sectors.'+sectorNum); + db.push(Settings.DB,'log',{Date:strftime("%a %b %d %H:%M:%S %Z"),Message:" - "+player.Alias+" made a planet: "+planet.Name},LOCK_WRITE); console.crlf(); console.writeln("Planet created"); return(true); @@ -187,9 +187,9 @@ function CreatePlanet(sectorNum) function PlanetReport(planetNum) { - db.lock('tw2','planets.'+planetNum,LOCK_WRITE); - var planet=db.read('tw2','planets.'+planetNum); - db.unlock('tw2','planets.'+planetNum,LOCK_WRITE); + db.lock(Settings.DB,'planets.'+planetNum,LOCK_WRITE); + var planet=db.read(Settings.DB,'planets.'+planetNum); + db.unlock(Settings.DB,'planets.'+planetNum,LOCK_WRITE); console.crlf(); console.attributes="HC"; console.writeln("Planet: "+planet.Name); @@ -271,26 +271,26 @@ function DestroyPlanet(planetNum) console.attributes="Y"; console.write("Are you sure (Y/N)[N]? "); if(InputFunc(['Y','N'])=='Y') { - db.lock('tw2','planets.'+planetNum,LOCK_WRITE); + db.lock(Settings.DB,'planets.'+planetNum,LOCK_WRITE); secnum=planet.Sector; - db.lock('tw2','sector.'+secnum,LOCK_WRITE); - var planet=db.read('tw2','planets.'+planetNum); + db.lock(Settings.DB,'sector.'+secnum,LOCK_WRITE); + var planet=db.read(Settings.DB,'planets.'+planetNum); if(planet.OccupiedCount > 1) { console.writeln("Another player prevents destroying the planet."); - db.unlock('tw2','planets.'+planetNum,LOCK_WRITE); - db.unlock('tw2','sector.'+secnum); + db.unlock(Settings.DB,'planets.'+planetNum,LOCK_WRITE); + db.unlock(Settings.DB,'sector.'+secnum); return(false); } - var sector=db.read('tw2','sectors.'+secnum); + var sector=db.read(Settings.DB,'sectors.'+secnum); if(sector.Planet==planetNum) sector.Planet=0; planet.Created=false; planet.Sector=0; - db.write('tw2','sectors.'+secnum,sector); - db.unlock('tw2','sector.'+secnum); - db.write('tw2','planets.'+planetNum,planet); - db.unlock('tw2','planets.'+planetNum,LOCK_WRITE); - db.push('tw2','log',{Date:strftime("%a %b %d %H:%M:%S %Z"),Message:" - " + player.Alias + " destroyed the planet in sector " + secnum},LOCK_WRITE); + db.write(Settings.DB,'sectors.'+secnum,sector); + db.unlock(Settings.DB,'sector.'+secnum); + db.write(Settings.DB,'planets.'+planetNum,planet); + db.unlock(Settings.DB,'planets.'+planetNum,LOCK_WRITE); + db.push(Settings.DB,'log',{Date:strftime("%a %b %d %H:%M:%S %Z"),Message:" - " + player.Alias + " destroyed the planet in sector " + secnum},LOCK_WRITE); console.writeln("Planet destroyed."); return(true); } @@ -308,8 +308,8 @@ function PlanetTakeAll(planetNum, freeholds) /* * Re-read the planet struct */ - db.lock('tw2','planets.'+planetNum,LOCK_WRITE); - planet=db.read('tw2','planets.'+planetNum); + db.lock(Settings.DB,'planets.'+planetNum,LOCK_WRITE); + planet=db.read(Settings.DB,'planets.'+planetNum); for(i=Commodities.length-1; i>=0; i--) { var take=parseInt(planet.Commodities[i]); if(take > freeholds) @@ -325,8 +325,8 @@ function PlanetTakeAll(planetNum, freeholds) break; } } - db.write('tw2','planets.'+planetNum,planet); - db.unlock('tw2','planets.'+planetNum,LOCK_WRITE); + db.write(Settings.DB,'planets.'+planetNum,planet); + db.unlock(Settings.DB,'planets.'+planetNum,LOCK_WRITE); player.Put(); return(freeholds); } @@ -348,33 +348,33 @@ function PlanetIncreaseProd(planetNum) var keynum=parseInt(InputFunc(values)); if(keynum > 0 && keynum <= Commodities.length) { keynum--; - db.lock('tw2','planets.'+planetNum,LOCK_WRITE); - planet=db.read('tw2','planets.'+planetNum); + db.lock(Settings.DB,'planets.'+planetNum,LOCK_WRITE); + planet=db.read(Settings.DB,'planets.'+planetNum); if(planet.Production[keynum]>19) { console.writeln("It's at its maximum value."); - db.unlock('tw2','planets.'+planetNum); + db.unlock(Settings.DB,'planets.'+planetNum); return; } var max=parseInt(player.Credits/(Commodities[keynum].price*20)); if(max<1) { console.writeln("You're too poor. You only have "+player.Credits+" credits."); - db.unlock('tw2','planets.'+planetNum); + db.unlock(Settings.DB,'planets.'+planetNum); return; } if(planet.Production[keynum]+max > 19) max=20-planet.Production[keynum]; - db.unlock('tw2','planets.'+planetNum); + db.unlock(Settings.DB,'planets.'+planetNum); console.write(Commodities[keynum].name+": Increase by how many units? "); var incr=InputFunc([{min:0,max:max}]); if(incr > 0 && incr <= max) { - db.lock('tw2','planets.'+planetNum,LOCK_WRITE); - planet=db.read('tw2','planets.'+planetNum); + db.lock(Settings.DB,'planets.'+planetNum,LOCK_WRITE); + planet=db.read(Settings.DB,'planets.'+planetNum); if(planet.Production[keynum]+incr > 20) incr=20-planet.Production[keynum]; player.Credits -= incr*Commodities[keynum].price*20; planet.Production[keynum]+=incr; - db.write('tw2','planets.'+planetNum,planet); - db.unlock('tw2','planets'); + db.write(Settings.DB,'planets.'+planetNum,planet); + db.unlock(Settings.DB,'planets'); player.Put(); console.writeln("Production of "+Commodities[keynum].name+" increased by "+incr+" for "+incr*Commodities[keynum].price*20+" credits."); } @@ -396,24 +396,24 @@ function PlanetTakeCommodity(planetNum, commodity, freeholds) /* * Re-read the planet struct */ - db.lock('tw2','planets.'+planetNum,LOCK_WRITE); - planet=db.read('tw2','planets.'+planetNum); + db.lock(Settings.DB,'planets.'+planetNum,LOCK_WRITE); + planet=db.read(Settings.DB,'planets.'+planetNum); max=freeholds; if(max > parseInt(planet.Commodities[commodity])) max=parseInt(planet.Commodities[commodity]); if(take > max) { console.writeln("They don't have that many."); - db.unlock('tw2','planets.'+planetNum,LOCK_WRITE); + db.unlock(Settings.DB,'planets.'+planetNum,LOCK_WRITE); return(freeholds); } if(take > freeholds) { console.writeln("You don't have enough free cargo holds."); - db.unlock('tw2','planets.'+planetNum,LOCK_WRITE); + db.unlock(Settings.DB,'planets.'+planetNum,LOCK_WRITE); return(freeholds); } planet.Commodities[commodity]-=take; - db.write('tw2','planets.'+planetNum,planet); - db.unlock('tw2','planets.'+planetNum,LOCK_WRITE); + db.write(Settings.DB,'planets.'+planetNum,planet); + db.unlock(Settings.DB,'planets.'+planetNum,LOCK_WRITE); player.Commodities[commodity]+=take; freeholds -= take; player.Put(); @@ -425,11 +425,11 @@ function ResetAllPlanets() var i; uifc.pop("Creating Planets"); - db.lock('tw2','planets',LOCK_WRITE); - db.write('tw2','planets',[]); - db.push('tw2','planets',DefaultPlanet); + db.lock(Settings.DB,'planets',LOCK_WRITE); + db.write(Settings.DB,'planets',[]); + db.push(Settings.DB,'planets',DefaultPlanet); for(i=0; i<Settings.MaxPlanets; i++) { - db.push('tw2','planets',DefaultPlanet); + db.push(Settings.DB,'planets',DefaultPlanet); } - db.unlock('tw2','planets'); + db.unlock(Settings.DB,'planets'); } diff --git a/xtrn/tw2/players.js b/xtrn/tw2/players.js index 7bd3ec4943f6548658c669a921fb1186e0e6e988..a1dafa9b6e76895b57075cbc18b6fc171faaf775 100644 --- a/xtrn/tw2/players.js +++ b/xtrn/tw2/players.js @@ -114,7 +114,7 @@ var players = { var ret; if(playerNum==undefined) return ret; - ret=db.read('tw2','players.'+playerNum,lock); + ret=db.read(Settings.DB,'players.'+playerNum,lock); ret.Record=playerNum; ret.PutLocked=function(lock) { var p={}; @@ -123,7 +123,7 @@ var players = { for(i in PlayerProperties) { p[PlayerProperties[i]['prop']]=this[PlayerProperties[i]['prop']]; } - db.write('tw2','players.'+this.Record,p,lock); + db.write(Settings.DB,'players.'+this.Record,p,lock); } ret.Put=function () { this.PutLocked(LOCK_WRITE); @@ -139,7 +139,7 @@ var players = { return this.GetLocked(playerNum, LOCK_READ); }, get length() { - return(db.read('tw2','players.length',LOCK_READ)); + return(db.read(Settings.DB,'players.length',LOCK_READ)); } } @@ -152,10 +152,9 @@ function AttackPlayer() console.writeln("You don't have any fighters."); return(false); } - var sector=db.read('tw2','sectors.'+player.Sector,LOCK_READ); + var sector=db.read(Settings.DB,'sectors.'+player.Sector,LOCK_READ); for(i=0;i<sector.Ships.length; i++) { var otherplayer=players.Get(sector.Ships[i]); -log(otherplayer.Sector+'=='+player.Sector+", "+ otherplayer.Record+'!='+player.Record+", "+otherplayer.KilledBy+"!=0, "+otherplayer.UserNumber+"!=0, !"+otherplayer.Online); if(otherplayer.Sector==player.Sector && otherplayer.Record!=player.Record && otherplayer.KilledBy==0 @@ -236,7 +235,7 @@ function PlayerMove() console.attributes="HW"; console.write("Warps lead to: "); - var sector=db.read('tw2','sectors.'+player.Sector,LOCK_READ); + var sector=db.read(Settings.DB,'sectors.'+player.Sector,LOCK_READ); var i; var avail=new Array(); for(i=0; i<sector.Warps.length; i++) { @@ -305,8 +304,8 @@ function KilledBy(killed, killer, notify) /* 15300 */ killed.KilledBy=killer.Record; killed.Put(); - db.lock('tw2','sectors',LOCK_WRITE); - var sectors=db.read('tw2','sectors'); + db.lock(Settings.DB,'sectors',LOCK_WRITE); + var sectors=db.read(Settings.DB,'sectors'); /* Destroy all deployed fighters */ for(i=1; i<sectors.length; i++) { if(sectors[i].FighterOwner==player.Record) { @@ -314,27 +313,27 @@ function KilledBy(killed, killer, notify) /* 15300 */ sectors[i].FighterOwner=0; } } - db.write('tw2','sectors',sectors); - db.unlock('tw2','sectors'+i); + db.write(Settings.DB,'sectors',sectors); + db.unlock(Settings.DB,'sectors.'+i); if(killed.TeamNumber > 0) { var ktn=killed.TeamNumber; - db.lock('tw2','teams.'+ktn,LOCK_WRITE); - var team=db.read('tw2','teams.'+ktn); + db.lock(Settings.DB,'teams.'+ktn,LOCK_WRITE); + var team=db.read(Settings.DB,'teams.'+ktn); var i; for(i=0; i<team.Members.length; i++) { if(team.Members[i]==killed.Record) { team.Members.splice(i,1); - db.write('tw2','teams.'+ktn); + db.write(Settings.DB,'teams.'+ktn); killed.TeamNumber=0; killed.Put(); } } - db.unlock('tw2','teams.'+ktn); + db.unlock(Settings.DB,'teams.'+ktn); } if(notify) - db.push('tw2','log',{Date:strftime("%a %b %d %H:%M:%S %Z"),Message:" - "+killer.Alias+" killed "+killed.Alias},LOCK_WRITE); + db.push(Settings.DB,'log',{Date:strftime("%a %b %d %H:%M:%S %Z"),Message:" - "+killer.Alias+" killed "+killed.Alias},LOCK_WRITE); } function RankPlayers() @@ -342,8 +341,8 @@ function RankPlayers() var i; var rank=new Array(); var fighters=new Array(); - var universe=db.read('tw2','sectors',LOCK_READ); - var allplayers=db.read('tw2','players',LOCK_READ); + var universe=db.read(Settings.DB,'sectors',LOCK_READ); + var allplayers=db.read(Settings.DB,'players',LOCK_READ); for(i=1; i<universe.length; i++) { if(universe[i].Fighters > 0 && universe[i].FighterOwner > 0) { @@ -428,7 +427,7 @@ function TWRank() rstr += format("%4d %13d %6d\r\n",(i+1),tsort[i].Score,tsort[i].Record); } } - db.write('tw2','ranking',rstr,LOCK_WRITE); + db.write(Settings.DB,'ranking',rstr,LOCK_WRITE); } function JSON_DoBattle(oppPath, otherteam) @@ -445,8 +444,8 @@ function JSON_DoBattle(oppPath, otherteam) var lost=0; var killed=0; - db.lock('tw2',oppPath,LOCK_WRITE); - var opp=db.read('tw2',oppPath); + db.lock(Settings.DB,oppPath,LOCK_WRITE); + var opp=db.read(Settings.DB,oppPath); player.Fighters -= use; while(use && opp.Fighters) { if(player.TeamNumber > 0 && otherteam) { @@ -481,15 +480,15 @@ function JSON_DoBattle(oppPath, otherteam) } } player.Fighters += use; - db.write('tw2',oppPath,opp); - db.unlock('tw2',oppPath); + db.write(Settings.DB,oppPath,opp); + db.unlock(Settings.DB,oppPath); player.Put(); console.writeln("You lost "+lost+" fighter(s), "+player.Fighters+" remain."); if(opp.Fighters > 0) - console.write("You destroyed "+killed+" enemy fighters, "+opp.Fighters+" remain."); + console.writeln("You destroyed "+killed+" enemy fighters, "+opp.Fighters+" remain."); else - console.write("You destroyed all of the enemy fighters."); + console.writeln("You destroyed all of the enemy fighters."); return(killed); } } @@ -562,7 +561,7 @@ function DoBattle(opp, otherteam) function MatchPlayer(name) { var i; - var allplayers=db.read('tw2','players',LOCK_READ); + var allplayers=db.read(Settings.DB,'players',LOCK_READ); name=name.toUpperCase(); for(i=1; i<allplayers.length; i++) { @@ -590,31 +589,31 @@ function DeletePlayer(player) player.ReInit(); player.UserNumber=0; player.Alias="<Deleted>"; - db.lock('tw2','sectors.'+player.Sector,LOCK_WRITE); - sector=db.read('tw2','sectors.'+player.Sector,LOCK_WRITE); + db.lock(Settings.DB,'sectors.'+player.Sector,LOCK_WRITE); + sector=db.read(Settings.DB,'sectors.'+player.Sector,LOCK_WRITE); for(i=0; i<sector.Ships.length; i++) { if(sector.Ships[i]==player.Record) { sector.Ships.splice(i,1); i--; } } - db.write('tw2','sectors.'+player.Sector,sector); + db.write(Settings.DB,'sectors.'+player.Sector,sector); player.Sector=0; player.Put(); - db.unlock('tw2','sectors.'+player.Sector); + db.unlock(Settings.DB,'sectors.'+player.Sector); /* Set fighter owner to "Deleted Player" */ var i; - db.lock('tw2','sectors',LOCK_WRITE); - var sectors=db.read('tw2','sectors'); + db.lock(Settings.DB,'sectors',LOCK_WRITE); + var sectors=db.read(Settings.DB,'sectors'); for(i=1; i<sectors.length; i++) { if(sectors[i].FighterOwner==player.Record) { sectors[i].FighterOwner=-98; } } - db.unlock('tw2','sectors'); + db.unlock(Settings.DB,'sectors'); /* Set messages TO the deleted player as read and FROM as from deleted */ - db.lock('tw2','updates',LOCK_WRITE); - var updates=db.read('tw2','updates'); + db.lock(Settings.DB,'updates',LOCK_WRITE); + var updates=db.read(Settings.DB,'updates'); for(i=0; i<updates.length; i++) { if(updates[i].To==player.Record && !msg.Read) { updates.splice(i,1); @@ -624,11 +623,11 @@ function DeletePlayer(player) updates[i].From=-98; } } - db.write('tw2','updates',updates); - db.unlock('tw2','updates'); + db.write(Settings.DB,'updates',updates); + db.unlock(Settings.DB,'updates'); /* Set radio messages TO the deleted player as read and FROM as from deleted */ - db.lock('tw2','radio',LOCK_WRITE); - var radio=db.read('tw2','radio'); + db.lock(Settings.DB,'radio',LOCK_WRITE); + var radio=db.read(Settings.DB,'radio'); for(i=0; i<radio.length; i++) { if(radio[i].To==player.Record && !msg.Read) { radio.splice(i,1); @@ -638,19 +637,19 @@ function DeletePlayer(player) radio[i].From=-98; } } - db.write('tw2','radio',radio); - db.unlock('tw2','radio'); + db.write(Settings.DB,'radio',radio); + db.unlock(Settings.DB,'radio'); /* Set killed bys to Deleted Player */ - db.lock('tw2','players',LOCK_WRITE); - var allplayers=db.read('tw2','players'); + db.lock(Settings.DB,'players',LOCK_WRITE); + var allplayers=db.read(Settings.DB,'players'); for(i=1; i<allplayers.length; i++) { if(allplayers[i].KilledBy==player.Record) { allplayers[i].KilledBy=-98; } } - db.write('tw2','players'); - db.unlock('tw2','players'); - db.push('tw2','log',{Date:strftime("%a %b %d %H:%M:%S %Z"),Message:" - "+player.Alias+" deleted from game"},LOCK_WRITE); + db.write(Settings.DB,'players'); + db.unlock(Settings.DB,'players'); + db.push(Settings.DB,'log',{Date:strftime("%a %b %d %H:%M:%S %Z"),Message:" - "+player.Alias+" deleted from game"},LOCK_WRITE); } function MoveTo(to) @@ -662,12 +661,12 @@ function MoveTo(to) return(false); } if(to > 0) { - db.lock('tw2','sectors.'+player.Sector,LOCK_WRITE); - sector=db.read('tw2','sectors.'+player.Sector); + db.lock(Settings.DB,'sectors.'+player.Sector,LOCK_WRITE); + sector=db.read(Settings.DB,'sectors.'+player.Sector); for(i=0; i<sector.Warps.length; i++) { if(sector.Warps[i]==to) { - db.lock('tw2','sectors.'+to,LOCK_WRITE); - newsector=db.read('tw2','sectors.'+to); + db.lock(Settings.DB,'sectors.'+to,LOCK_WRITE); + newsector=db.read(Settings.DB,'sectors.'+to); newsector.Ships.push(player.Record); for(i=0; i<sector.Ships.length; i++) { if(sector.Ships[i]==player.Record) { @@ -675,18 +674,18 @@ function MoveTo(to) i--; } } - db.write('tw2','sectors.'+player.Sector,sector); - db.write('tw2','sectors.'+to,newsector); + db.write(Settings.DB,'sectors.'+player.Sector,sector); + db.write(Settings.DB,'sectors.'+to,newsector); player.TurnsLeft--; player.LastIn=player.Sector; player.Sector=to; player.Put(); - db.unlock('tw2','sectors.'+player.Sector); - db.unlock('tw2','sectors.'+player.LastIn); + db.unlock(Settings.DB,'sectors.'+player.Sector); + db.unlock(Settings.DB,'sectors.'+player.LastIn); return(true); } } - db.unlock('tw2','sectors.'+player.Sector,LOCK_WRITE); + db.unlock(Settings.DB,'sectors.'+player.Sector,LOCK_WRITE); console.writeln("You can't get there from here."); } return(false); @@ -699,12 +698,12 @@ function LoadPlayer() var playerNum=0; for(var done=false; !done;) { - db.lock('tw2','players',LOCK_WRITE); - allplayers=db.read('tw2','players'); + db.lock(Settings.DB,'players',LOCK_WRITE); + allplayers=db.read(Settings.DB,'players'); for(i=1; i<allplayers.length; i++) { player=allplayers[i]; if(player.QWKID==system.qwk_id && player.UserNumber == user.number && (!file_exists(system.data_dir+format("user/%04d.tw2",player.UserNumber)))) { - db.unlock('tw2','players',LOCK_WRITE); + db.unlock(Settings.DB,'players',LOCK_WRITE); DeletePlayer(player); break; } @@ -725,8 +724,8 @@ function LoadPlayer() player.Online=true; player.PutLocked(); } - db.unlock('tw2','players'); - db.lock('tw2','players.'+player.Record,LOCK_WRITE); + db.unlock(Settings.DB,'players'); + db.lock(Settings.DB,'players.'+player.Record,LOCK_WRITE); console.attributes="G"; console.writeln("I can't find your record, so I am assuming you are a new player."); console.attributes="M"; @@ -735,7 +734,7 @@ function LoadPlayer() console.writeln("I'm sorry but the game is full."); console.writeln("Please leave a message for the Sysop so"); console.writeln("he can save a space for you when one opens up."); - db.push('tw2','log',{Date:strftime("%a %b %d %H:%M:%S %Z"),Message:": New player not allowed - game full."},LOCK_WRITE); + db.push(Settings.DB,'log',{Date:strftime("%a %b %d %H:%M:%S %Z"),Message:": New player not allowed - game full."},LOCK_WRITE); return(false); } console.crlf(); @@ -746,19 +745,19 @@ function LoadPlayer() player.ReInit(); player.Online=true; player.PutLocked(); - db.unlock('tw2','players.'+player.Record); + db.unlock(Settings.DB,'players.'+player.Record); - db.push('tw2','log',{Date:strftime("%a %b %d %H:%M:%S %Z"),Message:user.alias+": New Player logged on"},LOCK_WRITE); + db.push(Settings.DB,'log',{Date:strftime("%a %b %d %H:%M:%S %Z"),Message:user.alias+": New Player logged on"},LOCK_WRITE); Instructions(); } else { player=players.GetLocked(playerNum); player.Online=true; player.PutLocked(); - db.unlock('tw2','players'); + db.unlock(Settings.DB,'players'); console.crlf(); /* TODO: BASIC magic... N$ appears empty tw2.bas: 242 */ - db.push('tw2','log',{Date:strftime("%a %b %d %H:%M:%S %Z"),Message:user.alias+": Logged on"},LOCK_WRITE); + db.push(Settings.DB,'log',{Date:strftime("%a %b %d %H:%M:%S %Z"),Message:user.alias+": Logged on"},LOCK_WRITE); if(strftime("%Y:%m:%d") < player.LastOnDay) { console.writeln("I'm sorry, but you won't be allowed on until " + player.LastOnDay); return(false); @@ -808,16 +807,16 @@ function LoadPlayer() ReadRadio(); - if(player.Sector < 1 || player.Sector >= db.read('tw2','sectors.length',LOCK_READ)) { + if(player.Sector < 1 || player.Sector >= db.read(Settings.DB,'sectors.length',LOCK_READ)) { console.writeln("You are being moved to sector 1"); player.Sector=1; - db.lock('tw2','sectors.'+player.Sector,LOCK_WRITE); - sector=db.read('tw2','sectors.'+player.Sector); + db.lock(Settings.DB,'sectors.'+player.Sector,LOCK_WRITE); + sector=db.read(Settings.DB,'sectors.'+player.Sector); sector.Ships.push(player.Record); - db.write('tw2','sectors.'+player.Sector,sector); + db.write(Settings.DB,'sectors.'+player.Sector,sector); player.Put(); - db.unlock('tw2','sectors.'+player.Sector); - db.unlock('tw2','sectors.'+player.LastIn); + db.unlock(Settings.DB,'sectors.'+player.Sector); + db.unlock(Settings.DB,'sectors.'+player.LastIn); player.Put(); } @@ -837,7 +836,7 @@ function DropFighters() console.writeln("You can't leave fighters in the Union (sectors 1-7)"); return(false); } - var sector=db.read('tw2','sectors.'+player.Sector,LOCK_READ); + var sector=db.read(Settings.DB,'sectors.'+player.Sector,LOCK_READ); if(sector.Fighters > 0 && sector.FighterOwner != player.Record) { console.writeln("There are already fighters in this sector!"); return(false); @@ -849,30 +848,30 @@ function DropFighters() if(newf > 9999) newf=9999; newf=InputFunc([{min:0,max:newf}]); - db.lock('tw2','sectors.'+player.Sector,LOCK_WRITE); - sector=db.read('tw2','sectors.'+player.Sector,LOCK_READ); + db.lock(Settings.DB,'sectors.'+player.Sector,LOCK_WRITE); + sector=db.read(Settings.DB,'sectors.'+player.Sector,LOCK_READ); if(sector.Fighters > 0 && sector.FighterOwner != player.Record) { console.writeln("There are already fighters in this sector!"); - db.unlock('tw2','sectors.'+player.Sector); + db.unlock(Settings.DB,'sectors.'+player.Sector); return(false); } if(newf >= 0 && newf <=player.Fighters+sector.Fighters) { if((player.Fighters+sector.Fighters)-newf > 9999) { console.writeln("Too many ships in your fleet! You are limited to 9999"); - db.unlock('tw2','sectors.'+player.Sector); + db.unlock(Settings.DB,'sectors.'+player.Sector); return(false); } player.Fighters=(player.Fighters+sector.Fighters)-newf; sector.Fighters=newf; if(sector.Fighters > 0) sector.FighterOwner=player.Record; - db.write('tw2','sectors.'+player.Sector,sector); - db.unlock('tw2','sectors.'+player.Sector); + db.write(Settings.DB,'sectors.'+player.Sector,sector); + db.unlock(Settings.DB,'sectors.'+player.Sector); player.Put(); console.writeln("Done. You have " + player.Fighters + " fighter(s) in your fleet."); return(true); } - db.unlock('tw2','sectors.'+player.Sector); + db.unlock(Settings.DB,'sectors.'+player.Sector); return(false); } @@ -882,16 +881,16 @@ function ResetAllPlayers() var player={}; var i; - db.lock('tw2','players',LOCK_WRITE); - db.write('tw2','players',[]); + db.lock(Settings.DB,'players',LOCK_WRITE); + db.write(Settings.DB,'players',[]); for(i in PlayerProperties) { player[PlayerProperties[i]['prop']]=PlayerProperties[i]['def']; } player.UserNumber=0; player.Sector=0; - db.push('tw2','players',{Excuse:"I hate zero-based arrays, so I'm just stuffing this crap in here"}); + db.push(Settings.DB,'players',{Excuse:"I hate zero-based arrays, so I'm just stuffing this crap in here"}); for(i=0; i<Settings.MaxPlayers; i++) { - db.push('tw2','players',player); + db.push(Settings.DB,'players',player); } - db.unlock('tw2','players'); + db.unlock(Settings.DB,'players'); } diff --git a/xtrn/tw2/ports.js b/xtrn/tw2/ports.js index 2ed512bfa322b8e27f3397a23377199dbee52cf3..eecc1ad6f9c9acad7906f237a57699cc4090a30f 100644 --- a/xtrn/tw2/ports.js +++ b/xtrn/tw2/ports.js @@ -132,18 +132,18 @@ function DockAtSol() } function PortReport(portNum) { - db.lock('tw2','ports.'+portNum,LOCK_WRITE); - var port=db.read('tw2','ports.'+portNum); + db.lock(Settings.DB,'ports.'+portNum,LOCK_WRITE); + var port=db.read(Settings.DB,'ports.'+portNum); var i; if(port==null) { - db.unlock('tw2','ports.'+portNum); + db.unlock(Settings.DB,'ports.'+portNum); return(null); } /* 33000 */ LockedProduction(port); - db.write('tw2','ports.'+portNum,port); - db.unlock('tw2','ports.'+portNum,port); + db.write(Settings.DB,'ports.'+portNum,port); + db.unlock(Settings.DB,'ports.'+portNum,port); var ret=new Array(Commodities.length); for(i=0; i<Commodities.length; i++) { ret[i]=new Object(); @@ -259,24 +259,24 @@ function Transact(type, price, vary, avail) function DockAtRegularPort() { - var sector=db.read('tw2','sectors.'+player.Sector,LOCK_READ); + var sector=db.read(Settings.DB,'sectors.'+player.Sector,LOCK_READ); var amount; var sale; var count; var port; /* Lock the port file and ensure we can dock... */ - db.lock('tw2','ports.'+sector.Port,LOCK_WRITE); - port=db.read('tw2','ports.'+sector.Port); + db.lock(Settings.DB,'ports.'+sector.Port,LOCK_WRITE); + port=db.read(Settings.DB,'ports.'+sector.Port); if(port.OccupiedBy != 0) { console.writeln("The port is busy. Try again later."); - db.unlock('tw2','ports.'+sector.Port); + db.unlock(Settings.DB,'ports.'+sector.Port); return; } port.OccupiedBy=player.Record; LockedProduction(port); - db.write('tw2','ports.'+sector.Port,port); - db.unlock('tw2','ports.'+sector.Port); + db.write(Settings.DB,'ports.'+sector.Port,port); + db.unlock(Settings.DB,'ports.'+sector.Port); sale=PortReport(sector.Port); console.attributes="HR"; count=0; @@ -291,7 +291,7 @@ function DockAtRegularPort() if(amount >= 0) { count++; port.Commodities[i] -= amount; - db.write('tw2','ports.'+sector.Port,port,LOCK_WRITE); + db.write(Settings.DB,'ports.'+sector.Port,port,LOCK_WRITE); } } } @@ -302,7 +302,7 @@ function DockAtRegularPort() if(amount >= 0) { count++; port.Commodities[i] -= amount; - db.write('tw2','ports.'+sector.Port,port,LOCK_WRITE); + db.write(Settings.DB,'ports.'+sector.Port,port,LOCK_WRITE); } } } @@ -313,7 +313,7 @@ function DockAtRegularPort() } port.OccupiedBy=0; - db.write('tw2','ports.'+sector.Port,port,LOCK_WRITE); + db.write(Settings.DB,'ports.'+sector.Port,port,LOCK_WRITE); } @@ -326,7 +326,7 @@ function DockAtPort() console.writeln("Sorry, but you don't have any turns left."); return; } - var sector=db.read('tw2','sectors.'+player.Sector,LOCK_READ); + var sector=db.read(Settings.DB,'sectors.'+player.Sector,LOCK_READ); if(sector.Port<1) { console.writeln("There are no ports in this sector."); return; @@ -351,9 +351,9 @@ function InitializePorts() uifc.pop("Placing Ports"); - db.lock('tw2','ports',LOCK_WRITE); - db.write('tw2','ports',[]); - db.push('tw2','ports',DefaultPort); + db.lock(Settings.DB,'ports',LOCK_WRITE); + db.write(Settings.DB,'ports',[]); + db.push(Settings.DB,'ports',DefaultPort); /* Place ports */ for(i=0; i<ports_init.length; i++) { @@ -365,13 +365,13 @@ function InitializePorts() port.Production=[ports_init[i].OreProduction, ports_init[i].OrgProduction, ports_init[i].EquProduction]; port.PriceVariance=[ports_init[i].OreDeduction,ports_init[i].OrgDeduction,ports_init[i].EquDeduction]; - db.lock('tw2','sectors.'+ports_init[i].Sector,LOCK_WRITE); - var sector=db.read('tw2','sectors.'+ports_init[i].Sector); + db.lock(Settings.DB,'sectors.'+ports_init[i].Sector,LOCK_WRITE); + var sector=db.read(Settings.DB,'sectors.'+ports_init[i].Sector); sector.Port=i+1; - db.write('tw2','sectors.'+ports_init[i].Sector,sector); - db.unlock('tw2','sectors.'+ports_init[i].Sector); + db.write(Settings.DB,'sectors.'+ports_init[i].Sector,sector); + db.unlock(Settings.DB,'sectors.'+ports_init[i].Sector); - db.push('tw2','ports',port); + db.push(Settings.DB,'ports',port); } - db.unlock('tw2','ports'); + db.unlock(Settings.DB,'ports'); } diff --git a/xtrn/tw2/sectors.js b/xtrn/tw2/sectors.js index b8ccc966734069816e0a756b6de11c684dacd25f..4f36f11493f6c738ab6fd46e360b5c8b658e2d92 100644 --- a/xtrn/tw2/sectors.js +++ b/xtrn/tw2/sectors.js @@ -56,13 +56,13 @@ function CheckSector() player.Put(); console.writeln("Unfortunately, victory is fleeting..."); - db.lock('tw2','sectors.85',LOCK_WRITE); - var sector=db.read('tw2','sectors.85'); + db.lock(Settings.DB,'sectors.85',LOCK_WRITE); + var sector=db.read(Settings.DB,'sectors.85'); sector.Fighters=3000; sector.FighterOwner=-1; - sector=db.write('tw2','sectors.85',sector); - db.unlock('tw2','sectors.85'); - db.push('tw2','twopeng',{Date:strftime("%Y:%m:%d"),Message:"Congratulations go to "+player.Alias+ + sector=db.write(Settings.DB,'sectors.85',sector); + db.unlock(Settings.DB,'sectors.85'); + db.push(Settings.DB,'twopeng',{Date:strftime("%Y:%m:%d"),Message:"Congratulations go to "+player.Alias+ " who invaded the Cabal empire on " + strftime("%b %d, %Y") + " and received 100,000 points!"},LOCK_WRITE); return(false); @@ -78,7 +78,7 @@ function EnterSector() /* 20000 */ var i; console.attributes="Y"; - sector=db.read('tw2','sectors.'+player.Sector,LOCK_READ); + sector=db.read(Settings.DB,'sectors.'+player.Sector,LOCK_READ); DisplaySector(sector,player.Sector,false); if(sector.FighterOwner > 0) { otherplayer=players.Get(sector.FighterOwner); @@ -104,13 +104,13 @@ function EnterSector() /* 20000 */ player.Points+=killed*100; console.writeln("You just recieved "+(killed*100)+" points for that."); } - db.read('tw2','sectors.'+player.Sector,LOCK_READ); + db.read(Settings.DB,'sectors.'+player.Sector,LOCK_READ); if(sector.Fighters==0) console.writeln("You destroyed all the fighters."); break; case 'D': console.writeln("<Display>"); - sector=db.read('tw2','sector.'+player.Sector,LOCK_READ); + sector=db.read(Settings.DB,'sector.'+player.Sector,LOCK_READ); DisplaySector(sector,player.Sector,false); break; case 'I': @@ -126,16 +126,16 @@ function EnterSector() /* 20000 */ break; case 'R': console.writeln("<Retreat>"); - var sectorsLen=db.reaD('tw2','sectors.length',LOCK_READ); + var sectorsLen=db.reaD(Settings.DB,'sectors.length',LOCK_READ); if(player.LastIn<1 || player.LastIn>=sectorsLen) player.LastIn=random(sectorsLen-1)+1; if(player.Fighters<1) { if(random(2)==1) { console.writeln("You escaped!"); - db.lock('tw2','sectors.'+player.Sector,LOCK_WRITE); - db.lock('tw2','sectors.'+player.LastIn,LOCK_WRITE); - sector=db.read('tw2','sectors.'+player.Sector); - lastsector=db.read('tw2','sectors.'+player.Sector); + db.lock(Settings.DB,'sectors.'+player.Sector,LOCK_WRITE); + db.lock(Settings.DB,'sectors.'+player.LastIn,LOCK_WRITE); + sector=db.read(Settings.DB,'sectors.'+player.Sector); + lastsector=db.read(Settings.DB,'sectors.'+player.Sector); lastsector.Ships.push(player.Record); for(i=0; i<sector.Ships.length; i++) { if(sector.Ships[i]==player.Record) { @@ -143,12 +143,12 @@ function EnterSector() /* 20000 */ i--; } } - db.write('tw2','sectors.'+player.Sector,sector); - db.write('tw2','sectors.'+player.LastIn,lastsector); + db.write(Settings.DB,'sectors.'+player.Sector,sector); + db.write(Settings.DB,'sectors.'+player.LastIn,lastsector); player.Sector=player.LastIn; player.Put(); - db.unlock('tw2','sectors.'+player.Sector); - db.unlock('tw2','sectors.'+player.LastIn); + db.unlock(Settings.DB,'sectors.'+player.Sector); + db.unlock(Settings.DB,'sectors.'+player.LastIn); return(false); } console.attributes="R"; @@ -163,10 +163,10 @@ function EnterSector() /* 20000 */ else { player.Fighters--; console.writeln("You have "+player.Fighters+" fighter(s) left."); - db.lock('tw2','sectors.'+player.Sector,LOCK_WRITE); - db.lock('tw2','sectors.'+player.LastIn,LOCK_WRITE); - sector=db.read('tw2','sectors.'+player.Sector); - lastsector=db.read('tw2','sectors.'+player.Sector); + db.lock(Settings.DB,'sectors.'+player.Sector,LOCK_WRITE); + db.lock(Settings.DB,'sectors.'+player.LastIn,LOCK_WRITE); + sector=db.read(Settings.DB,'sectors.'+player.Sector); + lastsector=db.read(Settings.DB,'sectors.'+player.Sector); lastsector.Ships.push(player.Record); for(i=0; i<sector.Ships.length; i++) { if(sector.Ships[i]==player.Record) { @@ -174,12 +174,12 @@ function EnterSector() /* 20000 */ i--; } } - db.write('tw2','sectors.'+player.Sector,sector); - db.write('tw2','sectors.'+player.LastIn,lastsector); + db.write(Settings.DB,'sectors.'+player.Sector,sector); + db.write(Settings.DB,'sectors.'+player.LastIn,lastsector); player.Sector=player.LastIn; player.Put(); - db.unlock('tw2','sectors.'+player.Sector); - db.unlock('tw2','sectors.'+player.LastIn); + db.unlock(Settings.DB,'sectors.'+player.Sector); + db.unlock(Settings.DB,'sectors.'+player.LastIn); return(false); } break; @@ -234,7 +234,7 @@ function DisplaySector(sector, secnum, helponly) console.attributes="HR"; console.write("Port "); if(sector.Port > 0) { - var port=db.read('tw2','ports.'+sector.Port,LOCK_READ); + var port=db.read(Settings.DB,'ports.'+sector.Port,LOCK_READ); console.write(port.Name+", class "+port.Class); } else @@ -242,7 +242,7 @@ function DisplaySector(sector, secnum, helponly) console.crlf(); console.attributes="HB"; if(sector.Planet) { - var planet=db.read('tw2','planets.'+sector.Planet,LOCK_READ); + var planet=db.read(Settings.DB,'planets.'+sector.Planet,LOCK_READ); console.writeln("Planet "+planet.Name); } console.attributes="HC"; @@ -302,7 +302,7 @@ function ShortestPath(start, end) { var i,j; var hops=0; - var seclen=db.read('tw2','sectors.length',LOCK_READ); + var seclen=db.read(Settings.DB,'sectors.length',LOCK_READ); var univ=new Array(seclen); var done=false; var ret=new Array(); @@ -315,7 +315,7 @@ function ShortestPath(start, end) if(univ[pos].Warps[i]==0) continue; if(univ[univ[pos].Warps[i]]==undefined) { - univ[univ[pos].Warps[i]]=db.read('tw2','sectors.'+univ[pos].Warps[i],LOCK_READ); + univ[univ[pos].Warps[i]]=db.read(Settings.DB,'sectors.'+univ[pos].Warps[i],LOCK_READ); univ[univ[pos].Warps[i]].hops=hops; univ[univ[pos].Warps[i]].from=pos; if(univ[pos].Warps[i]==end) @@ -326,7 +326,7 @@ function ShortestPath(start, end) } /* Do the expansion */ - univ[start]=db.read('tw2','sectors.'+start,LOCK_READ); + univ[start]=db.read(Settings.DB,'sectors.'+start,LOCK_READ); univ[start].hops=hops; while(!done) { for(i=1; i<seclen; i++) { @@ -354,14 +354,14 @@ function InitializeSectors() uifc.pop("Writing Sectors"); /* Write sectors.dat */ - db.lock('tw2','sectors',LOCK_WRITE); - db.write('tw2','sectors',[]); - db.push('tw2','sectors',{Excuse:"I hate zero-based arrays, so I'm just stuffing this crap in here"}); + db.lock(Settings.DB,'sectors',LOCK_WRITE); + db.write(Settings.DB,'sectors',[]); + db.push(Settings.DB,'sectors',{Excuse:"I hate zero-based arrays, so I'm just stuffing this crap in here"}); for(i=0; i<sector_map.length; i++) { var sector=eval(DefaultSector.toSource()); for(prop in sector_map[i]) sector[prop]=sector_map[i][prop]; - db.push('tw2','sectors',sector); + db.push(Settings.DB,'sectors',sector); } - db.unlock('tw2','sectors',LOCK_WRITE); + db.unlock(Settings.DB,'sectors',LOCK_WRITE); } diff --git a/xtrn/tw2/teams.js b/xtrn/tw2/teams.js index 9f590053a10877613a47dca907ddee67e31a1442..df49e0fd6685b007d9cd8a98877d1210bb0d3963 100644 --- a/xtrn/tw2/teams.js +++ b/xtrn/tw2/teams.js @@ -80,7 +80,7 @@ function LocateTeam() console.writeln("Name Sector"); console.writeln("==================== ======"); var count=0; - var team=db.read('tw2','teams.'+player.TeamNumber,LOCK_READ); + var team=db.read(Settings.DB,'teams.'+player.TeamNumber,LOCK_READ); var i; for(i=0;i<team.Members.length; i++) { var otherplayer=players.Get(team.Members[i]); @@ -122,9 +122,9 @@ function CreateTeam() console.writeln("REMEMBER YOUR TEAM PASSWORD!"); var team=null; var teamNum=-1; - var teamLen=db.read('tw2','teams.length',LOCK_READ); + var teamLen=db.read(Settings.DB,'teams.length',LOCK_READ); for(i=1; i<teamLen; i++) { - team=db.read('tw2','teams.'+i,LOCK_READ); + team=db.read(Settings.DB,'teams.'+i,LOCK_READ); if(team.Members.length > 0) { teamNum=i; break; @@ -136,12 +136,12 @@ function CreateTeam() } team.Password=password; team.Members[0]=player.Record; - db.push('tw2','teams',team,LOCK_WRITE); + db.push(Settings.DB,'teams',team,LOCK_WRITE); /* Now find the record we just wrote... */ if(teamNum==-1) { - teamLen=db.read('tw2','teams.length',LOCK_READ); + teamLen=db.read(Settings.DB,'teams.length',LOCK_READ); for(i=1; i<teamLen; i++) { - team=db.read('tw2','teams.'+i,LOCK_READ); + team=db.read(Settings.DB,'teams.'+i,LOCK_READ); if(team.Members.length > 0 && team.Members[0]==player.Record) { teamNum=i; break; @@ -151,7 +151,7 @@ function CreateTeam() player.TeamNumber=teamNum; player.Put(); console.attributes="HYI"; - db.push('tw2','log',{Date:strftime("%a %b %d %H:%M:%S %Z"),Message:player.Alias+" Created Team "+teamNum+" the " /* TNAM$ */},LOCK_WRITE); + db.push(Settings.DB,'log',{Date:strftime("%a %b %d %H:%M:%S %Z"),Message:player.Alias+" Created Team "+teamNum+" the " /* TNAM$ */},LOCK_WRITE); console.writeln("Team number [" + teamNum + "] CREATED!"); console.attributes="HK"; return(true); @@ -159,7 +159,7 @@ function CreateTeam() function JoinTeam() { - var teamLen=db.read('tw2','teams.length',LOCK_READ); + var teamLen=db.read(Settings.DB,'teams.length',LOCK_READ); if(player.TeamNumber > 0) { console.writeln("You already belong to a Team! "); @@ -172,7 +172,7 @@ function JoinTeam() if(!(tnum > 0 && tnum < teamLen)) return(false); - var team=db.read('tw2','teams.'+tnum,LOCK_READ); + var team=db.read(Settings.DB,'teams.'+tnum,LOCK_READ); if(team.Members.length > 3) { console.writeln("The Team you picked has a maximum amount of members!"); return(false); @@ -184,19 +184,19 @@ function JoinTeam() return(false); } var i; - db.lock('tw2','teams.'+tnum,LOCK_WRITE); - team=db.read('tw2','teams.'+tnum); + db.lock(Settings.DB,'teams.'+tnum,LOCK_WRITE); + team=db.read(Settings.DB,'teams.'+tnum); if(team.Members.length > 3) { console.writeln("The Team you picked has a maximum amount of members!"); - db.unlock('tw2','teams.'+tnum); + db.unlock(Settings.DB,'teams.'+tnum); return(false); } team.Members.push(player.Record); player.TeamNumber=tnum; - db.write('tw2','teams.'+tnum, team); - db.unlock('tw2','teams.'+tnum); + db.write(Settings.DB,'teams.'+tnum, team); + db.unlock(Settings.DB,'teams.'+tnum); player.Put(); - db.push('tw2','log',{Date:strftime("%a %b %d %H:%M:%S %Z"),Message:player.Alias + " Joined Team "+tnum},LOCK_WRITE); + db.push(Settings.DB,'log',{Date:strftime("%a %b %d %H:%M:%S %Z"),Message:player.Alias + " Joined Team "+tnum},LOCK_WRITE); console.attributes="HC"; console.writeln("Your Team info has been recorded! Have fun!"); console.attributes="HK"; @@ -212,16 +212,16 @@ function QuitTeam() console.write("Are you sure you wish to quit your Team [N]? "); if(InputFunc(['Y','N'])=='Y') { var teamNum=player.TeamNumber; - db.lock('tw2','teams.'+teamNum,LOCK_WRITE); - var team=db.read('tw2','teams.'+teamNum); + db.lock(Settings.DB,'teams.'+teamNum,LOCK_WRITE); + var team=db.read(Settings.DB,'teams.'+teamNum); var i; for(i=0; i<team.Members.length; i++) { if(team.Members[i]==player.Record) { team.Members.splice(i,1); player.TeamNumber=0; player.Put(); - db.write('tw2', 'teams.'+teamNum, team); - db.unlock('tw2','teams.'+teamNum); + db.write(Settings.DB, 'teams.'+teamNum, team); + db.unlock(Settings.DB,'teams.'+teamNum); console.crlf(); console.attributes="HG"; console.writeln("You have been removed from Team play"); @@ -230,10 +230,10 @@ function QuitTeam() } } } - db.unlock('tw2','teams.'+teamNum); + db.unlock(Settings.DB,'teams.'+teamNum); console.attributes="HR"; console.writeln("Corrupt team detected on quit! Please notify the Sysop!"); - db.push('tw2','log',{Date:strftime("%a %b %d %H:%M:%S %Z"),Message:"!!! Team "+player.TeamNumber+" is corrupted (quit)!"},LOCK_WRITE); + db.push(Settings.DB,'log',{Date:strftime("%a %b %d %H:%M:%S %Z"),Message:"!!! Team "+player.TeamNumber+" is corrupted (quit)!"},LOCK_WRITE); return(false); } @@ -249,7 +249,7 @@ function TeamTransfer(type) var i; var otherplayer=null; - var team=db.read('tw2','teams.'+player.TeamNumber,LOCK_READ); + var team=db.read(Settings.DB,'teams.'+player.TeamNumber,LOCK_READ); for(i=0;i<team.Members.length; i++) { otherplayer=players.Get(team.Members[i]); if(otherplayer.Sector==player.Sector @@ -298,6 +298,6 @@ function TeamTransfer(type) function InitializeTeams() { uifc.pop("Teams"); - db.write('tw2','teams',[],LOCK_WRITE); - db.push('tw2','teams',{Excuse:"I hate zero-based arrays, so I'm just stuffing this crap in here"},LOCK_WRITE); + db.write(Settings.DB,'teams',[],LOCK_WRITE); + db.push(Settings.DB,'teams',{Excuse:"I hate zero-based arrays, so I'm just stuffing this crap in here"},LOCK_WRITE); } diff --git a/xtrn/tw2/tw2.js b/xtrn/tw2/tw2.js index 650e4062e249ee4af82845c1e8553d86f10b04cf..fed11e076830025fada52a19441d5350bb1434f7 100644 --- a/xtrn/tw2/tw2.js +++ b/xtrn/tw2/tw2.js @@ -86,7 +86,7 @@ function Menu(sector) break; case 'D': console.writeln("<Display>"); - sector=db.read('tw2','sectors.'+player.Sector,LOCK_READ); + sector=db.read(Settings.DB,'sectors.'+player.Sector,LOCK_READ); DisplaySector(sector,player.Sector,false); continue; case 'E': @@ -139,7 +139,7 @@ function Menu(sector) console.writeln("<Help>"); console.crlf(); if(user.settings&USER_ANSI) { - sector=db.read('tw2','sectors.'+player.Sector,LOCK_READ); + sector=db.read(Settings.DB,'sectors.'+player.Sector,LOCK_READ); DisplaySector(sector,player.Sector,true); } else @@ -167,7 +167,7 @@ function Menu(sector) } break; } - sector=db.read('tw2','sectors.'+player.Sector,LOCK_READ); + sector=db.read(Settings.DB,'sectors.'+player.Sector,LOCK_READ); } } @@ -176,30 +176,30 @@ function do_exit() if(player != undefined) { player.Online=false; if(player.Ported || player.Landed) { - var sector=db.read('tw2','sectors.'+player.Sector,LOCK_READ); + var sector=db.read(Settings.DB,'sectors.'+player.Sector,LOCK_READ); if(player.Ported) { console.writeln("Leaving the port..."); player.Ported=false; - db.lock('tw2','ports.'+sector.Port,LOCK_WRITE); - port=db.read('tw2','ports.'+sector.Port); + db.lock(Settings.DB,'ports.'+sector.Port,LOCK_WRITE); + port=db.read(Settings.DB,'ports.'+sector.Port); port.OccupiedBy=0; - db.write('tw2','ports.'+sector.Port,port); - db.unlock('tw2','ports.'+sector.Port); + db.write(Settings.DB,'ports.'+sector.Port,port); + db.unlock(Settings.DB,'ports.'+sector.Port); } if(player.Landed) { console.writeln("Launching from planet..."); player.Landed=false; try { - db.lock('tw2','planets.'+sector.Planet,LOCK_WRITE); + db.lock(Settings.DB,'planets.'+sector.Planet,LOCK_WRITE); } catch (e) { - db.push('tw2','log',{Date:strftime("%a %b %d %H:%M:%S %Z"),Message:"!!! Error locking planets file!\n"+e},LOCK_WRITE); + db.push(Settings.DB,'log',{Date:strftime("%a %b %d %H:%M:%S %Z"),Message:"!!! Error locking planets file!\n"+e},LOCK_WRITE); return; } - var planet=db.read('tw2','planets.'+sector.Planet); + var planet=db.read(Settings.DB,'planets.'+sector.Planet); planet.OccupiedCount--; - db.write('tw2','planets.'+sector.Planet,planet); - db.unlock('tw2','planets.'+sector.Planet); + db.write(Settings.DB,'planets.'+sector.Planet,planet); + db.unlock(Settings.DB,'planets.'+sector.Planet); } } player.TimeUsed += time()-on_at; @@ -257,13 +257,13 @@ function Production(place) function ShowOpeng() { - var len=db.read('tw2','twopeng.lengh',LOCK_READ); + var len=db.read(Settings.DB,'twopeng.lengh',LOCK_READ); var i; var msg; // TODO: Only show "new" stuff from here... for(i=0; i<len; i++) { - msg=db.read('tw2','twopeng.'+i,LOCK_READ); + msg=db.read(Settings.DB,'twopeng.'+i,LOCK_READ); console.writeln(msg.Message); console.crlf(); } diff --git a/xtrn/tw2/twint500.js b/xtrn/tw2/twint500.js index 3d0e0d9be4310220806144efd2ce4ae9fdc65c74..1f2619d28b986389f6f167aa35274c98c64d9ddc 100644 --- a/xtrn/tw2/twint500.js +++ b/xtrn/tw2/twint500.js @@ -106,7 +106,7 @@ InitializeTeams(); InitializeSectors(); InitializePorts(); InitializeCabal(); -db.write('tw2','twopeng',[],LOCK_WRITE); +db.write(Settings.DB,'twopeng',[],LOCK_WRITE); uifc.pop(); uifc.bail();