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)
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
This class takes care of round or move management as well of the gameover condition.
Definition: kgamesequence.h:42
void emitSignal(KGamePropertyBase *me)
Called by KGamePropertyHandler only! Internal function!
Definition: kgame.cpp:1440
uint playerCount() const
Returns how many players are plugged into the game.
Definition: kgame.cpp:680
KPlayer * loadPlayer(TQDataStream &stream, bool isvirtual=false)
Load the player list from a stream.
Definition: kgame.cpp:354
virtual bool loadgame(TQDataStream &stream, bool network, bool reset)
Load a saved game, from file OR network.
Definition: kgame.cpp:182
void lockDirectEmit()
Called by the KGame or KPlayer object or the handler itself to delay emmiting of signals.
Definition: kgamepropertyhandler.cpp:283
void signalConnectionBroken()
Our connection to the KMessageServer has broken.
KPlayer * findPlayer(TQ_UINT32 id) const
Returns the player object for a given player id.
Definition: kgame.cpp:386
virtual bool save(TQDataStream &stream, bool saveplayers=true)
Save a game to a file OR to network.
Definition: kgame.cpp:284
bool removePlayer(KPlayer *player)
Sends a message over the network, msgid=IdRemovePlayer.
Definition: kgame.h:223
void sendError(int error, const TQByteArray &message, TQ_UINT32 receiver=0, TQ_UINT32 sender=0)
Sends a network message.
Definition: kgamenetwork.cpp:450
bool setTurn(bool b, bool exclusive=true)
Sets whether this player is the next to turn.
Definition: kplayer.cpp:285
A collection class for KGameProperty objects.
Definition: kgamepropertyhandler.h:72
bool sendPlayerProperty(int msgid, TQDataStream &s, TQ_UINT32 playerId)
This is called by KPlayer::sendProperty only! Internal function!
Definition: kgame.cpp:1428
virtual bool load(TQDataStream &stream)
Loads properties from the datastream.
Definition: kgamepropertyhandler.cpp:188
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 systemRemovePlayer(KPlayer *player, bool deleteit)
Removes a player from the game.
Definition: kgame.cpp:532
void savePlayers(TQDataStream &stream, KGamePlayerList *list=0)
Save the player list to a stream.
Definition: kgame.cpp:332
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.
void signalMessageUpdate(int msgid, TQ_UINT32 receiver, TQ_UINT32 sender)
We got an network message.
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...
bool inactivatePlayer(KPlayer *player)
sends inactivate player: internal use only?
Definition: kgame.cpp:582
void slotServerDisconnected()
This slot is called whenever the connection to the server is lost (ie the signal KGameNetwork::signal...
Definition: kgame.cpp:1262
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 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 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
void signalNetworkData(int msgid, const TQByteArray &buffer, TQ_UINT32 receiver, TQ_UINT32 sender)
We got an user defined update message.
virtual int checkGameOver(KPlayer *player)
Check whether the game is over.
Definition: kgamesequence.cpp:119
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
virtual const TQString & group() const
Query the group the player belongs to.
Definition: kplayer.cpp:186
KPlayer * playerInputFinished(KPlayer *player)
Called after the player input is processed by the game.
Definition: kgame.cpp:758
void sendProperty(int msgid, TQDataStream &stream, bool *sent)
Called by KGamePropertyHandler only! Internal function!
Definition: kgame.cpp:1431
KGamePlayerList * inactivePlayerList()
Returns a list of all inactive players.
Definition: kgame.cpp:693
virtual KPlayer * nextPlayer(KPlayer *last, bool exclusive=true)
Select the next player in a turn based game.
Definition: kgamesequence.cpp:50
void signalClientJoinedGame(TQ_UINT32 clientid, KGame *me)
Is emmited after a client is successfully connected to the game.
virtual void negotiateNetworkGame(TQ_UINT32 clientID)
This member function will transmit e.g.
Definition: kgame.cpp:1376
void signalLoadError(TQDataStream &stream, bool network, int cookie, bool &result)
Is emmited if a game with a different version cookie is loaded.
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
bool isAdmin() const
The admin of a game is the one who initializes newly connected clients using negotiateNetworkGame and...
Definition: kgamenetwork.cpp:104
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 signalGameOver(int status, KPlayer *current, KGame *me)
Is emitted after a call to gameOver() returns a non zero return code.
virtual bool playerInput(TQDataStream &msg, KPlayer *player)=0
A player input occurred.
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
void signalReplacePlayerIO(KPlayer *player, bool *remove)
When a client disconnects from the game usually all players from that client are removed.
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
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!
virtual bool systemPlayerInput(TQDataStream &msg, KPlayer *player, TQ_UINT32 sender=0)
Called when a player input arrives from KMessageServer.
Definition: kgame.cpp:727
void syncRandom()
syncronise the random numbers with all network clients not used by KGame - if it should be kept then ...
Definition: kgame.cpp:1234
virtual bool load(TQDataStream &stream)
Load a saved player, from file OR network.
Definition: kplayer.cpp:314
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
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.
KRandomSequence * random() const
Returns a pointer to the game's KRandomSequence.
Definition: kgame.cpp:705
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 networkTransmission(TQDataStream &stream, int msgid, TQ_UINT32 sender)
Receives a message.
Definition: kplayer.cpp:353
virtual bool save(TQDataStream &stream)
Saves properties into the datastream.
Definition: kgamepropertyhandler.cpp:210
void disconnect()
Disconnect the current connection and establish a new local one.
Definition: kgamenetwork.cpp:273
void setGameSequence(KGameSequence *sequence)
Set a new KGameSequence to control player management.
Definition: kgame.cpp:799
int networkPriority() const
Returns whether this player can be replaced by a network connection player.
Definition: kplayer.cpp:213
KGamePropertyHandler * dataHandler() const
Returns a pointer to the KGame property handler.
Definition: kgame.cpp:689
virtual bool load(TQDataStream &stream, bool reset=true)
Load a saved game, from file OR network.
Definition: kgame.cpp:179
void playerDeleted(KPlayer *player)
Called by the destructor of KPlayer to remove itself from the game.
Definition: kgame.cpp:492
void signalLoadPrePlayers(TQDataStream &stream)
The game will be loaded from the given stream.
void unlockDirectEmit()
Removes the lock from the emitting of property signals.
Definition: kgamepropertyhandler.cpp:288
void setPolicy(GamePolicy p, bool recursive=true)
Changes the consistency policy of a property.
Definition: kgame.cpp:1452
virtual bool save(TQDataStream &stream)
Save a player to a file OR to network.
Definition: kplayer.cpp:340
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 KPlayer * nextPlayer(KPlayer *last, bool exclusive=true)
Definition: kgame.cpp:823