From 07e1e26a2164ca0f902e301832ad3bdbdbc8aad9 Mon Sep 17 00:00:00 2001
From: mcmlxxix <>
Date: Thu, 17 Jan 2013 22:20:41 +0000
Subject: [PATCH] a few more lobby fixes. add some debug logging to the AI
 thread to figure out why they sometimes try to attack themselves (and some
 secondary checking to make sure they dont)

---
 xtrn/dicewarz2/ai.js       |  5 +++++
 xtrn/dicewarz2/dicefunc.js |  4 +++-
 xtrn/dicewarz2/game.js     | 16 ++++------------
 3 files changed, 12 insertions(+), 13 deletions(-)

diff --git a/xtrn/dicewarz2/ai.js b/xtrn/dicewarz2/ai.js
index f9a2a8893f..d79939b134 100644
--- a/xtrn/dicewarz2/ai.js
+++ b/xtrn/dicewarz2/ai.js
@@ -366,6 +366,11 @@ function attack(computer) {
 		var attacker=game.players[attacking.owner];
 		var defender=game.players[defending.owner];
 		
+		if(attacking.owner == defending.owner) {
+			log(LOG_ERROR,"invalid attack attempted: " + attacking.id + "->" + defending.id);
+			continue;
+		}
+		
 		var a=new Roll(attacking.owner);
 		for(var r=0;r<attacking.dice;r++) {
 			var roll=random(6)+1;
diff --git a/xtrn/dicewarz2/dicefunc.js b/xtrn/dicewarz2/dicefunc.js
index b0151dc403..436e7cf93e 100644
--- a/xtrn/dicewarz2/dicefunc.js
+++ b/xtrn/dicewarz2/dicefunc.js
@@ -104,8 +104,10 @@ function canAttack(map,base) {
 		var neighbors=getNeighboringTiles(base,map);
 		for(var n=0;n<neighbors.length;n++) {
 			var tile=neighbors[n];
-			if(tile.owner!=base.owner) 
+			if(tile.owner !== base.owner) {
+				log(LOG_DEBUG,"Adding attack option: " + base.id + "(" + base.owner + ")->" + tile.id + "(" + tile.owner + ")");
 				valid_targets.push(tile);
+			}
 		}
 	}
 	return valid_targets;
diff --git a/xtrn/dicewarz2/game.js b/xtrn/dicewarz2/game.js
index 9ab1589e3a..d2b416d301 100644
--- a/xtrn/dicewarz2/game.js
+++ b/xtrn/dicewarz2/game.js
@@ -356,16 +356,7 @@ function lobby() {
 	}
 	function processUpdate(update) {
 		if(update.oper == "WRITE") {
-			var p = update.location.split(".");
-			var obj=data;
-			
-			while(p.length > 1) {
-				var child=p.shift();
-				obj = obj[child];
-			}
-			
-			var child = p.shift();
-			obj[child] = update.data;
+			/* todo: make this smarter */
 			gameList();
 		}
 	}
@@ -423,8 +414,8 @@ function lobby() {
 	}
 	function gameList()	{
 		listFrame.clear();
-		var games = client.read(game_id,"games",1);
-		var sorted = sortGameData(games);
+		data.games = client.read(game_id,"games",1);
+		var sorted = sortGameData(data.games);
 		wrap(listFrame,"\1gGames in progress          ",sorted.started);
 		wrap(listFrame,"\1gGames needing more players ",sorted.waiting);
 		wrap(listFrame,"\1gYou are involved in games  ",sorted.yourgames);
@@ -743,6 +734,7 @@ function playGame(gameNumber) {
 			if(tnum) {
 				map.tiles[tnum] = update.data;
 				drawTile(map,map.tiles[tnum]);
+				listPlayers();
 			}
 			
 			if(pnum) {
-- 
GitLab