kgame.cpp
63 TQPtrQueue<KPlayer> mAddPlayerList;// this is a list of to-be-added players. See addPlayer() docu
141 KGamePlayerList tmp = d->mPlayerList; // in case of PolicyClean player=d->mPlayerList.first() is infinite
192 kdWarning(11001) << "Trying to load different game version we="<<cookie() << " saved=" << c << endl;
351 kdWarning(11001) << " No user defined player created. Creating default KPlayer. This crashes if you have overwritten KPlayer!!!! " << endl;
361 kdDebug(11001) << k_funcinfo << "Player "<< id << " not found...asking user to create one " << endl;
368 kdWarning(11001) << " No user defined player created. Creating default KPlayer. This crashes if you have overwritten KPlayer!!!! " << endl;
373 kdDebug(11001) << " USER Player " << newplayer << " done player->rtti=" << newplayer->rtti() << " rtti=" << rtti << endl;
414 kdDebug(11001) << k_funcinfo << ": " << "; maxPlayers=" << maxPlayers() << " playerCount=" << playerCount() << endl;
423 kdWarning(11001) << "cannot add more than " << maxPlayers() << " players - deleting..." << endl;
432 kdDebug(11001) << k_funcinfo << "NEW!!! player " << newplayer << " now has id " << newplayer->id() << endl;
438 kdDebug(11001) << k_funcinfo << "player " << newplayer << " already has an id: " << newplayer->id() << endl;
474 kdError(11001) << "ERROR: Double adding player !!!!! NOT GOOD !!!!!! " << newplayer->id() << "...I delete it again" << endl;
479 kdDebug(11001) << "Trying to add player " << newplayer <<" maxPlayers="<<maxPlayers()<<" playerCount="<<playerCount() << endl;
494 kdDebug(11001) << k_funcinfo << ": id (" << player->id() << ") to be removed " << player << endl;
517 kdDebug(11001) << k_funcinfo << ": id (" << player->id() << ") to be removed " << player << endl;
542 kdWarning(11001) << "player " << player << "(" << player->id() << ") Could not be found!" << endl;
843 void KGame::networkTransmission(TQDataStream &stream, int msgid, TQ_UINT32 receiver, TQ_UINT32 sender, TQ_UINT32 /*clientID*/)
849 // kdDebug(11001) << k_funcinfo << ": we="<<(int)gameId()<<" id="<<msgid<<" recv=" << receiver << " sender=" << sender << endl;
857 //kdDebug(11001) << "message id " << msgid << " seems to be for a player ("<<active=p->isActive()<<" recv="<< receiver << endl;
890 kdDebug(11001) << " ===================> (Client) " << k_funcinfo << ": Got IdSetupGame ================== " << endl;
891 kdDebug(11001) << "our game id is " << gameId() << " Lib version=" << v << " App Cookie=" << c << endl;
895 kdError(11001) << "IdGameSetup: Negotiate Game: cookie mismatch I'am="<<cookie()<<" master="<<c<<endl;
999 kdDebug(11001) << "====> (ALL) " << k_funcinfo << ": Got IdGameConnected for client "<< cid << " we are =" << gameId() << endl;
1036 emit signalNetworkData(msgid - KGameMessage::IdUser,((TQBuffer*)stream.device())->readAll(),receiver,sender);
1060 kdDebug(11001) << " Master got player " << player->id() <<" rawgame=" << KGameMessage::rawGameId(player->id()) << " from sender " << sender << endl;
1075 kdDebug(11001) << " Master calculates how many players to activate client has cnt=" << cnt << endl;
1077 kdDebug(11001) << " The user deactivated "<< inactivateIds.count() << " player already " << endl;
1206 kdDebug(11001) << "Client: playerlistcount=" << d->mPlayerList.count() << " tmplistcout=" << cnt << endl;
1272 kdDebug(11001) << "Inactive Playerlist of client=" << d->mInactivePlayerList.count() << " count" << endl;
1313 kdDebug(11001) << "Player id " << oldid <<" changed to " << player->id() << " as we are now local" << endl;
1361 if (((int)playerCount() < maxPlayers() || maxPlayers() < 0) && player && KGameMessage::rawGameId(*it1) != clientID)
1378 kdDebug(11001) << "===========================" << k_funcinfo << ": clientID=" << clientID << " =========================== "<< endl;
1399 bool KGame::sendGroupMessage(const TQByteArray &msg, int msgid, TQ_UINT32 sender, const TQString& group)
1414 bool KGame::sendGroupMessage(const TQDataStream &msg, int msgid, TQ_UINT32 sender, const TQString& group)
1417 bool KGame::sendGroupMessage(const TQString& msg, int msgid, TQ_UINT32 sender, const TQString& group)
bool sendPlayerProperty(int msgid, TQDataStream &s, TQ_UINT32 playerId)
This is called by KPlayer::sendProperty only! Internal function!
Definition: kgame.cpp:1428
void setGameSequence(KGameSequence *sequence)
Set a new KGameSequence to control player management.
Definition: kgame.cpp:799
void savePlayers(TQDataStream &stream, KGamePlayerList *list=0)
Save the player list to a stream.
Definition: kgame.cpp:332
virtual bool savegame(TQDataStream &stream, bool network, bool saveplayers)
Save a game, to file OR network.
Definition: kgame.cpp:287
virtual KPlayer * createPlayer(int rtti, int io, bool isvirtual)
This virtual function is called if the KGame needs to create a new player.
Definition: kgame.cpp:349
virtual void newPlayersJoin(KGamePlayerList *oldplayer, KGamePlayerList *newplayer, TQValueList< int > &inactivate)
This virtual function can be overwritten for your own player management.
Definition: kgame.h:754
bool removePlayer(KPlayer *player)
Sends a message over the network, msgid=IdRemovePlayer.
Definition: kgame.h:223
uint playerCount() const
Returns how many players are plugged into the game.
Definition: kgame.cpp:680
virtual const TQString & group() const
Query the group the player belongs to.
Definition: kplayer.cpp:186
virtual int checkGameOver(KPlayer *player)
Check whether the game is over.
Definition: kgamesequence.cpp:119
void setPolicy(GamePolicy p, bool recursive=true)
Changes the consistency policy of a property.
Definition: kgame.cpp:1452
void signalMessageUpdate(int msgid, TQ_UINT32 receiver, TQ_UINT32 sender)
We got an network message.
virtual bool save(TQDataStream &stream, bool saveplayers=true)
Save a game to a file OR to network.
Definition: kgame.cpp:284
void signalClientDisconnected(TQ_UINT32 clientID, bool broken)
This signal is emitted whenever the KMessageServer sends us a message that a connection to a client w...
virtual bool save(TQDataStream &stream)
Save a player to a file OR to network.
Definition: kplayer.cpp:340
KPlayer * loadPlayer(TQDataStream &stream, bool isvirtual=false)
Load the player list from a stream.
Definition: kgame.cpp:354
int networkPriority() const
Returns whether this player can be replaced by a network connection player.
Definition: kplayer.cpp:213
void savePlayer(TQDataStream &stream, KPlayer *player)
Prepare a player for being added.
Definition: kgame.cpp:323
virtual void networkTransmission(TQDataStream &stream, int msgid, TQ_UINT32 receiver, TQ_UINT32 sender, TQ_UINT32 clientID)
This will either forward an incoming message to a specified player (see KPlayer::networkTransmission)...
Definition: kgame.cpp:843
virtual bool loadgame(TQDataStream &stream, bool network, bool reset)
Load a saved game, from file OR network.
Definition: kgame.cpp:182
bool setTurn(bool b, bool exclusive=true)
Sets whether this player is the next to turn.
Definition: kplayer.cpp:285
void unlockDirectEmit()
Removes the lock from the emitting of property signals.
Definition: kgamepropertyhandler.cpp:288
void signalConnectionBroken()
Our connection to the KMessageServer has broken.
KPlayer * playerInputFinished(KPlayer *player)
Called after the player input is processed by the game.
Definition: kgame.cpp:758
void slotClientConnected(TQ_UINT32 clientId)
Calls negotiateNetworkGame() See KGameNetwork::signalClientConnected.
Definition: kgame.cpp:1254
void addPlayer(KPlayer *newplayer)
Note that KPlayer::save must be implemented properly, as well as KPlayer::rtti This will only send a ...
Definition: kgame.cpp:412
void systemRemovePlayer(KPlayer *player, bool deleteit)
Removes a player from the game.
Definition: kgame.cpp:532
bool inactivatePlayer(KPlayer *player)
sends inactivate player: internal use only?
Definition: kgame.cpp:582
bool activatePlayer(KPlayer *player)
sends activate player: internal use only?
Definition: kgame.cpp:630
void signalClientLeftGame(int clientID, int oldgamestatus, KGame *me)
This signal is emitted after a network partner left the game (either by a broken connection or volunt...
void signalLoad(TQDataStream &stream)
The game will be loaded from the given stream.
virtual bool load(TQDataStream &stream)
Loads properties from the datastream.
Definition: kgamepropertyhandler.cpp:188
void slotClientDisconnected(TQ_UINT32 clientId, bool broken)
This slot is called whenever the connection to a client is lost (ie the signal KGameNetwork::signalCl...
Definition: kgame.cpp:1325
void slotServerDisconnected()
This slot is called whenever the connection to the server is lost (ie the signal KGameNetwork::signal...
Definition: kgame.cpp:1262
void sendProperty(int msgid, TQDataStream &stream, bool *sent)
Called by KGamePropertyHandler only! Internal function!
Definition: kgame.cpp:1431
A collection class for KGameProperty objects.
Definition: kgamepropertyhandler.h:72
void signalNetworkData(int msgid, const TQByteArray &buffer, TQ_UINT32 receiver, TQ_UINT32 sender)
We got an user defined update message.
void signalClientJoinedGame(TQ_UINT32 clientid, KGame *me)
Is emmited after a client is successfully connected to the game.
bool sendSystemMessage(const TQByteArray &buffer, int msgid, TQ_UINT32 receiver=0, TQ_UINT32 sender=0)
Sends a network message msg with a given msg id msgid to all clients.
Definition: kgamenetwork.cpp:396
void signalGameOver(int status, KPlayer *current, KGame *me)
Is emitted after a call to gameOver() returns a non zero return code.
virtual void negotiateNetworkGame(TQ_UINT32 clientID)
This member function will transmit e.g.
Definition: kgame.cpp:1376
void networkTransmission(TQDataStream &stream, int msgid, TQ_UINT32 sender)
Receives a message.
Definition: kplayer.cpp:353
KRandomSequence * random() const
Returns a pointer to the game's KRandomSequence.
Definition: kgame.cpp:705
bool sendGroupMessage(const TQByteArray &msg, int msgid, TQ_UINT32 sender, const TQString &group)
See KGameNetwork::sendMessage.
Definition: kgame.cpp:1399
void signalPlayerLeftGame(KPlayer *player)
a player left the game because of a broken connection or so!
void syncRandom()
syncronise the random numbers with all network clients not used by KGame - if it should be kept then ...
Definition: kgame.cpp:1234
void setPolicy(KGamePropertyBase::PropertyPolicy p, bool userspace=true)
Set the policy for all kgame variables which are currently registerd in the KGame proeprty handler.
Definition: kgamepropertyhandler.cpp:232
bool isVirtual() const
Is this player a virtual player, ie is it created by mirroring a real player from another network gam...
Definition: kplayer.cpp:204
KGamePropertyBase * findProperty(int id) const
This function allows to find the pointer to a player property when you know it's id.
Definition: kgame.cpp:1445
void disconnect()
Disconnect the current connection and establish a new local one.
Definition: kgamenetwork.cpp:273
virtual bool playerInput(TQDataStream &msg, KPlayer *player)=0
A player input occurred.
virtual bool save(TQDataStream &stream)
Saves properties into the datastream.
Definition: kgamepropertyhandler.cpp:210
void signalLoadError(TQDataStream &stream, bool network, int cookie, bool &result)
Is emmited if a game with a different version cookie is loaded.
virtual bool load(TQDataStream &stream)
Load a saved player, from file OR network.
Definition: kplayer.cpp:314
virtual KPlayer * nextPlayer(KPlayer *last, bool exclusive=true)
Select the next player in a turn based game.
Definition: kgamesequence.cpp:50
bool isAdmin() const
The admin of a game is the one who initializes newly connected clients using negotiateNetworkGame and...
Definition: kgamenetwork.cpp:104
KGamePropertyHandler * dataHandler() const
Returns a pointer to the KGame property handler.
Definition: kgame.cpp:689
void signalReplacePlayerIO(KPlayer *player, bool *remove)
When a client disconnects from the game usually all players from that client are removed.
KGamePlayerList * inactivePlayerList()
Returns a list of all inactive players.
Definition: kgame.cpp:693
virtual bool sendPlayerInput(TQDataStream &msg, KPlayer *player, TQ_UINT32 sender=0)
Called by KPlayer to send a player input to the KMessageServer.
Definition: kgame.cpp:709
virtual bool systemPlayerInput(TQDataStream &msg, KPlayer *player, TQ_UINT32 sender=0)
Called when a player input arrives from KMessageServer.
Definition: kgame.cpp:727
The KGameNetwork class is the KGame class with network support.
Definition: kgamenetwork.h:46
bool addProperty(KGamePropertyBase *data, TQString name=0)
Adds a KGameProperty property to the handler.
Definition: kgamepropertyhandler.cpp:151
virtual KPlayer * nextPlayer(KPlayer *last, bool exclusive=true)
Definition: kgame.cpp:823
void signalClientConnected(TQ_UINT32 clientID)
This signal is emitted whenever the KMessageServer sends us a message that a new client connected.
void signalSavePrePlayers(TQDataStream &stream)
The game will be saved to the given stream.
void emitSignal(KGamePropertyBase *me)
Called by KGamePropertyHandler only! Internal function!
Definition: kgame.cpp:1440
void playerDeleted(KPlayer *player)
Called by the destructor of KPlayer to remove itself from the game.
Definition: kgame.cpp:492
void signalPropertyChanged(KGamePropertyBase *property, KGame *me)
This signal is emmited if a player property changes its value and the property is set to notify this ...
void lockDirectEmit()
Called by the KGame or KPlayer object or the handler itself to delay emmiting of signals.
Definition: kgamepropertyhandler.cpp:283
KPlayer * findPlayer(TQ_UINT32 id) const
Returns the player object for a given player id.
Definition: kgame.cpp:386
This class takes care of round or move management as well of the gameover condition.
Definition: kgamesequence.h:42
bool sendMessage(const TQByteArray &buffer, int msgid, TQ_UINT32 receiver=0, TQ_UINT32 sender=0)
Send a network message msg with a given message ID msgid to all clients.
Definition: kgamenetwork.cpp:447
void sendError(int error, const TQByteArray &message, TQ_UINT32 receiver=0, TQ_UINT32 sender=0)
Sends a network message.
Definition: kgamenetwork.cpp:450
virtual bool load(TQDataStream &stream, bool reset=true)
Load a saved game, from file OR network.
Definition: kgame.cpp:179
void signalLoadPrePlayers(TQDataStream &stream)
The game will be loaded from the given stream.