[atlantik-cvs] CVS: kdegames/atlantik/libatlantikclient atlantik_network.cpp, 1.95.2.3, 1.95.2.4

[email protected] Mon, 17 Nov 2003 03:50:44 +0100 (CET)
Newsgroups gmane.comp.kde.devel.atlantik
Message-ID <[email protected]>
Update of /home/kde/kdegames/atlantik/libatlantikclient
In directory office:/tmp/cvs-serv10286/libatlantikclient

Modified Files:
      Tag: atlantik_3_3_branch
	atlantik_network.cpp 
Log Message:
more gameupdate changes, game master is now a server-wide property

Index: atlantik_network.cpp
===================================================================
RCS file: /home/kde/kdegames/atlantik/libatlantikclient/atlantik_network.cpp,v
retrieving revision 1.95.2.3
retrieving revision 1.95.2.4
diff -u -d -r1.95.2.3 -r1.95.2.4
--- atlantik_network.cpp	15 Nov 2003 22:09:07 -0000	1.95.2.3
+++ atlantik_network.cpp	17 Nov 2003 02:50:42 -0000	1.95.2.4
@@ -331,13 +331,17 @@
 				{
 					gameId = a.value().toInt();
 
-					kdDebug() << "gameupdate for " << QString::number(gameId) << " with playerSelf in game " << QString::number(m_atlanticCore->playerSelf() ? m_atlanticCore->playerSelf()->gameId() : -2) << endl;
+					if ( m_atlanticCore->playerSelf() && m_atlanticCore->playerSelf()->game() )
+						kdDebug() << "gameupdate for " << QString::number(gameId) << " with playerSelf in game " << QString::number(m_atlanticCore->playerSelf()->game()->id()) << endl;
+					else
+						kdDebug() << "gameupdate for " << QString::number(gameId) << endl;
+
 
 					Game *game = 0;
 					if (gameId == -1)
 					{
 						a = e.attributeNode(QString("gametype"));
-						if (!a.isNull())
+						if ( !a.isNull() && !(game = m_atlanticCore->findGame(a.value())) )
 							game = m_atlanticCore->newGame(gameId, a.value());
 					}
 					else if (!(game = m_atlanticCore->findGame(gameId)))
@@ -360,6 +364,11 @@
 					if (game && !a.isNull())
 						game->setPlayers(a.value().toInt());
 
+					// FIXME: create player if non-existant
+					a = e.attributeNode(QString("master"));
+					if (game && !a.isNull())
+						game->setMaster(m_atlanticCore->findPlayer(a.value().toInt()));
+
 					QString status = e.attributeNode(QString("status")).value();
 					if (status == "config")
 						emit gameConfig();
@@ -407,7 +416,19 @@
 					// Update player game
 					a = e.attributeNode(QString("game"));
 					if (player && !a.isNull())
-						player->setGame(a.value().toInt());
+					{
+						int gameId = a.value().toInt();
+						if (gameId == -1)
+							player->setGame( 0 );
+						else
+						{
+							// Ensure setGame succeeds by creating game if necessary
+							Game *game = m_atlanticCore->findGame(a.value().toInt());
+							if (!game)
+								game = m_atlanticCore->newGame(a.value().toInt()); // 
+							player->setGame( game );
+						}
+					}
 
 					// Update player host
 					a = e.attributeNode(QString("host"));
@@ -423,10 +444,6 @@
 					a = e.attributeNode(QString("money"));
 					if (player && !a.isNull())
 						player->setMoney(a.value().toInt());
-
-					a = e.attributeNode(QString("master"));
-					if (player && !a.isNull())
-						player->setMaster(a.value().toInt());
 
 					a = e.attributeNode(QString("bankrupt"));
 					if (player && !a.isNull())