[atlantik-cvs] CVS: kdegames/atlantik/libatlantikclient atlantik_network.cpp, 1.95.2.2, 1.95.2.3 atlantik_network.h, 1.47.2.2, 1.47.2.3
[email protected] Sat, 15 Nov 2003 23:09:09 +0100 (CET)
| Newsgroups | gmane.comp.kde.devel.atlantik |
|---|---|
| Message-ID | <[email protected]> |
Update of /home/kde/kdegames/atlantik/libatlantikclient
In directory office:/tmp/cvs-serv27006/libatlantikclient
Modified Files:
Tag: atlantik_3_3_branch
atlantik_network.cpp atlantik_network.h
Log Message:
deprecate updategamelist for gameupdate
Index: atlantik_network.cpp
===================================================================
RCS file: /home/kde/kdegames/atlantik/libatlantikclient/atlantik_network.cpp,v
retrieving revision 1.95.2.2
retrieving revision 1.95.2.3
diff -u -d -r1.95.2.2 -r1.95.2.3
--- atlantik_network.cpp 15 Nov 2003 13:36:03 -0000 1.95.2.2
+++ atlantik_network.cpp 15 Nov 2003 22:09:07 -0000 1.95.2.3
@@ -25,17 +25,14 @@
#include <klocale.h>
#include <atlantic_core.h>
-#include <player.h>
+#include <auction.h>
#include <estate.h>
#include <estategroup.h>
+#include <game.h>
+#include <player.h>
#include <trade.h>
-#include <auction.h>
#include "atlantik_network.h"
-#include "atlantik_network.moc"
-
-//#include "atlantik.h"
-//#include "trade_widget.h"
AtlantikNetwork::AtlantikNetwork(AtlanticCore *atlanticCore) : KExtendedSocket(0, 0, KExtendedSocket::inputBufferedSocket)
{
@@ -119,17 +116,6 @@
writeData(QString(".hs%1").arg(estate ? estate->id() : -1));
}
-void AtlantikNetwork::cmdGamesList()
-{
- emit msgStatus(i18n("Requesting game list..."));
- writeData(".gl");
-}
-
-void AtlantikNetwork::getPlayerList()
-{
- writeData(".gp");
-}
-
void AtlantikNetwork::newGame(const QString &gameType)
{
writeData(QString(".gn%1").arg(gameType));
@@ -297,38 +283,12 @@
emit addCloseButton();
}
}
- else if (e.tagName() == "updategamelist")
- {
- QString type = e.attributeNode(QString("type")).value();
- if (type == "full")
- emit gameListClear();
-
- QDomNode n_game = n.firstChild();
- while(!n_game.isNull())
- {
- QDomElement e_game = n_game.toElement();
- if (!e_game.isNull() && e_game.tagName() == "game")
- {
- if (type=="del")
- emit gameListDel(e_game.attributeNode(QString("id")).value());
- else if (type=="edit")
- emit gameListEdit(e_game.attributeNode(QString("id")).value(), e_game.attributeNode(QString("name")).value(), e_game.attributeNode(QString("description")).value(), e_game.attributeNode(QString("players")).value(), e_game.attributeNode(QString("gametype")).value(), e_game.attributeNode(QString("canbejoined")).value().toInt());
- else if (type=="add" || type=="full")
- emit gameListAdd(e_game.attributeNode(QString("id")).value(), e_game.attributeNode(QString("name")).value(), e_game.attributeNode(QString("description")).value(), e_game.attributeNode(QString("players")).value(), e_game.attributeNode(QString("gametype")).value(), e_game.attributeNode(QString("canbejoined")).value().toInt());
- }
- n_game = n_game.nextSibling();
- }
- if (type == "full")
- emit gameListEndUpdate();
- }
else if (e.tagName() == "client")
{
a = e.attributeNode(QString("playerid"));
if (!a.isNull())
- {
m_playerId = a.value().toInt();
- cmdGamesList();
- }
+
a = e.attributeNode(QString("cookie"));
if (!a.isNull())
emit clientCookie(a.value());
@@ -350,6 +310,18 @@
}
emit endConfigUpdate();
}
+ else if (e.tagName() == "deletegame")
+ {
+ a = e.attributeNode(QString("gameid"));
+ if (!a.isNull())
+ {
+ int gameId = a.value().toInt();
+
+ Game *game = m_atlanticCore->findGame(gameId);
+ if (game)
+ m_atlanticCore->removeGame(game);
+ }
+ }
else if (e.tagName() == "gameupdate")
{
int gameId = -1;
@@ -361,18 +333,45 @@
kdDebug() << "gameupdate for " << QString::number(gameId) << " with playerSelf in game " << QString::number(m_atlanticCore->playerSelf() ? m_atlanticCore->playerSelf()->gameId() : -2) << endl;
+ Game *game = 0;
+ if (gameId == -1)
+ {
+ a = e.attributeNode(QString("gametype"));
+ if (!a.isNull())
+ game = m_atlanticCore->newGame(gameId, a.value());
+ }
+ else if (!(game = m_atlanticCore->findGame(gameId)))
+ game = m_atlanticCore->newGame(gameId);
+
+ a = e.attributeNode(QString("canbejoined"));
+ if (game && !a.isNull())
+ game->setCanBeJoined(a.value().toInt());
+
+
+ a = e.attributeNode(QString("description"));
+ if (game && !a.isNull())
+ game->setDescription(a.value());
+
+ a = e.attributeNode(QString("name"));
+ if (game && !a.isNull())
+ game->setName(a.value());
+
+ a = e.attributeNode(QString("players"));
+ if (game && !a.isNull())
+ game->setPlayers(a.value().toInt());
+
QString status = e.attributeNode(QString("status")).value();
if (status == "config")
- {
emit gameConfig();
- getPlayerList();
- }
else if (status == "init")
emit gameInit();
else if (status == "run")
emit gameRun();
else if (status == "end")
emit gameEnd();
+
+ if (game)
+ game->update();
}
}
else if (e.tagName() == "deleteplayer")
@@ -397,17 +396,8 @@
playerId = a.value().toInt();
Player *player;
- bool b_newPlayer = false;
if (!(player = m_atlanticCore->findPlayer(playerId)))
- {
- // Create player object
- player = m_atlanticCore->newPlayer(playerId);
-
- if (playerId == m_playerId)
- player->setIsSelf(true);
-
- b_newPlayer = true;
- }
+ player = m_atlanticCore->newPlayer( playerId, (m_playerId == playerId) );
// Update player name
a = e.attributeNode(QString("name"));
@@ -501,14 +491,8 @@
}
}
- // Emit signal so GUI implementations can create view(s)
- // TODO: port to atlanticcore and create view there
if (player)
- {
- if (b_newPlayer)
- emit newPlayer(player);
player->update();
- }
}
}
else if (e.tagName() == "estategroupupdate")
@@ -645,7 +629,6 @@
int tradeId = a.value().toInt();
Trade *trade = m_atlanticCore->findTrade(tradeId);
- bool b_newTrade = false;
if (!trade)
{
// Create trade object
@@ -655,7 +638,6 @@
QObject::connect(trade, SIGNAL(updateMoney(Trade *, unsigned int, Player *, Player *)), this, SLOT(tradeUpdateMoney(Trade *, unsigned int, Player *, Player *)));
QObject::connect(trade, SIGNAL(reject(Trade *)), this, SLOT(tradeReject(Trade *)));
QObject::connect(trade, SIGNAL(accept(Trade *)), this, SLOT(tradeAccept(Trade *)));
- b_newTrade = true;
}
a = e.attributeNode(QString("revision"));
@@ -698,7 +680,7 @@
Player *player = m_atlanticCore->findPlayer(e.attributeNode(QString("actor")).value().toInt());
if (trade)
trade->reject(player);
- if (player && player->isSelf())
+ if ( player && player == m_atlanticCore->playerSelf() )
{
m_atlanticCore->removeTrade(trade);
trade = 0;
@@ -764,14 +746,8 @@
}
}
- // Emit signal so GUI implementations can create view(s)
- // TODO: port to atlanticcore and create view there
if (trade)
- {
- if (b_newTrade)
- emit newTrade(trade);
trade->update();
- }
}
}
else if (e.tagName() == "auctionupdate")
@@ -859,3 +835,5 @@
{
emit msgStatus(i18n("Connection failed! Error code: %1").arg(error), "connect_no");
}
+
+#include "atlantik_network.moc"
Index: atlantik_network.h
===================================================================
RCS file: /home/kde/kdegames/atlantik/libatlantikclient/atlantik_network.h,v
retrieving revision 1.47.2.2
retrieving revision 1.47.2.3
diff -u -d -r1.47.2.2 -r1.47.2.3
--- atlantik_network.h 15 Nov 2003 13:36:03 -0000 1.47.2.2
+++ atlantik_network.h 15 Nov 2003 22:09:07 -0000 1.47.2.3
@@ -40,14 +40,12 @@
AtlantikNetwork(AtlanticCore *atlanticCore);
virtual ~AtlantikNetwork(void);
void setName(QString name);
- void cmdGamesList();
void cmdChat(QString msg);
private slots:
void writeData(QString msg);
void rollDice();
void endTurn();
- void getPlayerList();
void newGame(const QString &gameType);
void reconnect(const QString &cookie);
void startGame();
@@ -77,18 +75,8 @@
void serverConnect(const QString host, int port);
void joinGame(int gameId);
void slotRead();
-
-signals:
- /**
- * A new player was created. This signal might be replaced with one in
- * the AtlanticCore class in the future, but it is here now because we
- * do not want GUI implementations to create a view until the
- * playerupdate message has been fully parsed.
- *
- * @param player Created Player object.
- */
- void newPlayer(Player *player);
+signals:
/**
* A new estate was created. This signal might be replaced with one in
* the AtlanticCore class in the future, but it is here now because we
@@ -109,16 +97,6 @@
*/
void newEstateGroup(EstateGroup *estateGroup);
- /**
- * A new trade was created. This signal might be replaced with one in
- * the AtlanticCore class in the future, but it is here now because we
- * do not want GUI implementations to create a view until the
- * tradeupdate message has been fully parsed.
- *
- * @param trade Created Trade object.
- */
- void newTrade(Trade *trade);
-
void msgInfo(QString);
void msgError(QString);
void msgChat(QString, QString);
@@ -131,12 +109,6 @@
void gameOption(QString title, QString type, QString value, QString edit, QString command);
void endConfigUpdate();
-
- void gameListClear();
- void gameListEndUpdate();
- void gameListAdd(QString gameId, QString name, QString description, QString players, QString gameType, bool canBeJoined);
- void gameListEdit(QString gameId, QString name, QString description, QString players, QString gameType, bool canBeJoined);
- void gameListDel(QString gameId);
void gameConfig();
void gameInit();