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

Fix various bugs surrounding entering a guarded sector.

parent 600a6b7f
Branches
Tags
No related merge requests found
...@@ -293,11 +293,11 @@ function DestroyPlanet(planetNum) ...@@ -293,11 +293,11 @@ function DestroyPlanet(planetNum)
db.lock(Settings.DB,'planets.'+planetNum,LOCK_WRITE); db.lock(Settings.DB,'planets.'+planetNum,LOCK_WRITE);
var planet=db.read(Settings.DB,"planets."+planetNum); var planet=db.read(Settings.DB,"planets."+planetNum);
secnum=planet.Sector; secnum=planet.Sector;
db.lock(Settings.DB,'sector.'+secnum,LOCK_WRITE); db.lock(Settings.DB,'sectors.'+secnum,LOCK_WRITE);
if(planet.OccupiedCount > 1) { if(planet.OccupiedCount > 1) {
console.writeln("Another player prevents destroying the planet."); console.writeln("Another player prevents destroying the planet.");
db.unlock(Settings.DB,'planets.'+planetNum); db.unlock(Settings.DB,'planets.'+planetNum);
db.unlock(Settings.DB,'sector.'+secnum); db.unlock(Settings.DB,'sectors.'+secnum);
return(false); return(false);
} }
var sector=db.read(Settings.DB,'sectors.'+secnum); var sector=db.read(Settings.DB,'sectors.'+secnum);
...@@ -306,7 +306,7 @@ function DestroyPlanet(planetNum) ...@@ -306,7 +306,7 @@ function DestroyPlanet(planetNum)
planet.Created=false; planet.Created=false;
planet.Sector=0; planet.Sector=0;
db.write(Settings.DB,'sectors.'+secnum,sector); db.write(Settings.DB,'sectors.'+secnum,sector);
db.unlock(Settings.DB,'sector.'+secnum); db.unlock(Settings.DB,'sectors.'+secnum);
db.write(Settings.DB,'planets.'+planetNum,planet); db.write(Settings.DB,'planets.'+planetNum,planet);
db.unlock(Settings.DB,'planets.'+planetNum); db.unlock(Settings.DB,'planets.'+planetNum);
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); 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);
......
...@@ -104,13 +104,13 @@ function EnterSector() /* 20000 */ ...@@ -104,13 +104,13 @@ function EnterSector() /* 20000 */
player.Points+=killed*100; player.Points+=killed*100;
console.writeln("You just recieved "+(killed*100)+" points for that."); console.writeln("You just recieved "+(killed*100)+" points for that.");
} }
db.read(Settings.DB,'sectors.'+player.Sector,LOCK_READ); sector=db.read(Settings.DB,'sectors.'+player.Sector,LOCK_READ);
if(sector.Fighters==0) if(sector.Fighters==0)
console.writeln("You destroyed all the fighters."); console.writeln("You destroyed all the fighters.");
break; break;
case 'D': case 'D':
console.writeln("<Display>"); console.writeln("<Display>");
sector=db.read(Settings.DB,'sector.'+player.Sector,LOCK_READ); sector=db.read(Settings.DB,'sectors.'+player.Sector,LOCK_READ);
DisplaySector(sector,player.Sector,false); DisplaySector(sector,player.Sector,false);
break; break;
case 'I': case 'I':
...@@ -127,15 +127,17 @@ function EnterSector() /* 20000 */ ...@@ -127,15 +127,17 @@ function EnterSector() /* 20000 */
case 'R': case 'R':
console.writeln("<Retreat>"); console.writeln("<Retreat>");
var sectorsLen=db.read(Settings.DB,'sectors.length',LOCK_READ); var sectorsLen=db.read(Settings.DB,'sectors.length',LOCK_READ);
if(player.LastIn<1 || player.LastIn>=sectorsLen) while(player.LastIn<1 || player.LastIn>=sectorsLen || player.LastIn==player.Sector) {
player.LastIn=random(sectorsLen-1)+1; player.LastIn=random(sectorsLen-1)+1;
}
var oldsector=player.Sector;
if(player.Fighters<1) { if(player.Fighters<1) {
if(random(2)==1) { if(random(2)==1) {
console.writeln("You escaped!"); console.writeln("You escaped!");
db.lock(Settings.DB,'sectors.'+player.Sector,LOCK_WRITE); db.lock(Settings.DB,'sectors.'+player.Sector,LOCK_WRITE);
db.lock(Settings.DB,'sectors.'+player.LastIn,LOCK_WRITE); db.lock(Settings.DB,'sectors.'+player.LastIn,LOCK_WRITE);
sector=db.read(Settings.DB,'sectors.'+player.Sector); sector=db.read(Settings.DB,'sectors.'+player.Sector);
lastsector=db.read(Settings.DB,'sectors.'+player.Sector); lastsector=db.read(Settings.DB,'sectors.'+player.LastIn);
lastsector.Ships.push(player.Record); lastsector.Ships.push(player.Record);
for(i=0; i<sector.Ships.length; i++) { for(i=0; i<sector.Ships.length; i++) {
if(sector.Ships[i]==player.Record) { if(sector.Ships[i]==player.Record) {
...@@ -147,7 +149,7 @@ function EnterSector() /* 20000 */ ...@@ -147,7 +149,7 @@ function EnterSector() /* 20000 */
db.write(Settings.DB,'sectors.'+player.LastIn,lastsector); db.write(Settings.DB,'sectors.'+player.LastIn,lastsector);
player.Sector=player.LastIn; player.Sector=player.LastIn;
player.Put(); player.Put();
db.unlock(Settings.DB,'sectors.'+player.Sector); db.unlock(Settings.DB,'sectors.'+oldsector);
db.unlock(Settings.DB,'sectors.'+player.LastIn); db.unlock(Settings.DB,'sectors.'+player.LastIn);
return(false); return(false);
} }
...@@ -166,7 +168,7 @@ function EnterSector() /* 20000 */ ...@@ -166,7 +168,7 @@ function EnterSector() /* 20000 */
db.lock(Settings.DB,'sectors.'+player.Sector,LOCK_WRITE); db.lock(Settings.DB,'sectors.'+player.Sector,LOCK_WRITE);
db.lock(Settings.DB,'sectors.'+player.LastIn,LOCK_WRITE); db.lock(Settings.DB,'sectors.'+player.LastIn,LOCK_WRITE);
sector=db.read(Settings.DB,'sectors.'+player.Sector); sector=db.read(Settings.DB,'sectors.'+player.Sector);
lastsector=db.read(Settings.DB,'sectors.'+player.Sector); lastsector=db.read(Settings.DB,'sectors.'+player.LastIn);
lastsector.Ships.push(player.Record); lastsector.Ships.push(player.Record);
for(i=0; i<sector.Ships.length; i++) { for(i=0; i<sector.Ships.length; i++) {
if(sector.Ships[i]==player.Record) { if(sector.Ships[i]==player.Record) {
...@@ -178,7 +180,7 @@ function EnterSector() /* 20000 */ ...@@ -178,7 +180,7 @@ function EnterSector() /* 20000 */
db.write(Settings.DB,'sectors.'+player.LastIn,lastsector); db.write(Settings.DB,'sectors.'+player.LastIn,lastsector);
player.Sector=player.LastIn; player.Sector=player.LastIn;
player.Put(); player.Put();
db.unlock(Settings.DB,'sectors.'+player.Sector); db.unlock(Settings.DB,'sectors.'+oldsector);
db.unlock(Settings.DB,'sectors.'+player.LastIn); db.unlock(Settings.DB,'sectors.'+player.LastIn);
return(false); return(false);
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment