KDEGames
kgame.cpp
68 d->mProperties->registerHandler(KGameMessage::IdGameProperty, this, SLOT(sendProperty(int, QDataStream &, bool *)), SLOT(emitSignal(KGamePropertyBase *)));
159 qCWarning(KDEGAMESPRIVATE_KGAME_LOG) << "Trying to load different game version we=" << cookie() << "saved=" << c;
319 qCDebug(KDEGAMESPRIVATE_KGAME_LOG) << "Player " << id << "not found...asking user to create one";
326 qCWarning(KDEGAMESPRIVATE_KGAME_LOG) << " No user defined player created. Creating default KPlayer. This crashes if you have overwritten KPlayer!!!! ";
375 qCWarning(KDEGAMESPRIVATE_KGAME_LOG) << "cannot add more than" << maxPlayers() << "players - deleting...";
382 qCDebug(KDEGAMESPRIVATE_KGAME_LOG) << "NEW!!! player" << newplayer << "now has id" << newplayer->id();
386 qCDebug(KDEGAMESPRIVATE_KGAME_LOG) << "player" << newplayer << "already has an id:" << newplayer->id();
410 qCWarning(KDEGAMESPRIVATE_KGAME_LOG) << "trying to add NULL player in KGame::systemAddPlayer()";
418 qCCritical(KDEGAMESPRIVATE_KGAME_LOG) << "ERROR: Double adding player !!!!! NOT GOOD !!!!!! " << newplayer->id() << "...I delete it again";
422 qCDebug(KDEGAMESPRIVATE_KGAME_LOG) << "Trying to add player" << newplayer << " maxPlayers=" << maxPlayers() << " playerCount=" << playerCount();
453 qCWarning(KDEGAMESPRIVATE_KGAME_LOG) << "trying to remove NULL player in KGame::removePlayer( )";
678 qCDebug(KDEGAMESPRIVATE_KGAME_LOG) << "KGame: Got playerInput from messageServer... sender:" << sender;
744void KGame::networkTransmission(QDataStream &stream, int msgid, quint32 receiver, quint32 sender, quint32 /*clientID*/)
750 // qCDebug(KDEGAMESPRIVATE_KGAME_LOG) << ": we="<<(int)gameId()<<" id="<<msgid<<" recv=" << receiver << "sender=" << sender;
756 // qCDebug(KDEGAMESPRIVATE_KGAME_LOG) << "message id" << msgid << "seems to be for a player ("<<active=p->isActive()<<" recv="<< receiver;
785 qCDebug(KDEGAMESPRIVATE_KGAME_LOG) << "our game id is" << gameId() << "Lib version=" << v << "App Cookie=" << c;
788 qCCritical(KDEGAMESPRIVATE_KGAME_LOG) << "IdGameSetup: Negotiate Game: cookie mismatch I'am=" << cookie() << " master=" << c;
891 Q_EMIT signalNetworkData(msgid - KGameMessage::IdUser, ((QBuffer *)stream.device())->readAll(), receiver, sender);
911 qCDebug(KDEGAMESPRIVATE_KGAME_LOG) << "Master got player" << player->id() << " rawgame=" << KGameMessage::rawGameId(player->id()) << "from sender"
914 qCCritical(KDEGAMESPRIVATE_KGAME_LOG) << "Client tries to add player with wrong game id - cheat possible";
923 qCDebug(KDEGAMESPRIVATE_KGAME_LOG) << "Master calculates how many players to activate client has cnt=" << cnt;
925 qCDebug(KDEGAMESPRIVATE_KGAME_LOG) << "The user deactivated " << inactivateIds.count() << "player already";
931 qCDebug(KDEGAMESPRIVATE_KGAME_LOG) << "havePlayers" << cnt + playerCount() - inactivateIds.count();
933 qCDebug(KDEGAMESPRIVATE_KGAME_LOG) << " Still to deactivate " << (int)(cnt + playerCount() - inactivateIds.count()) - (int)maxPlayers();
966 qCDebug(KDEGAMESPRIVATE_KGAME_LOG) << "Marking player" << currentPlayer->id() << "for inactivation";
969 qCCritical(KDEGAMESPRIVATE_KGAME_LOG) << "Couldn't find a player to deactivate. That is not so good...";
974 qCDebug(KDEGAMESPRIVATE_KGAME_LOG) << "Altogether deactivated" << inactivateIds.count() << "players";
995 qCCritical(KDEGAMESPRIVATE_KGAME_LOG) << "We should deactivate a player, but cannot find it...not good.";
1006 qCDebug(KDEGAMESPRIVATE_KGAME_LOG) << " -> the client can ******** reactivate ******** " << player->id();
1035 qCDebug(KDEGAMESPRIVATE_KGAME_LOG) << "Client: playerlistcount=" << d->mPlayerList.count() << "tmplistcout=" << cnt;
1056 qCWarning(KDEGAMESPRIVATE_KGAME_LOG) << "KGame::setupGame(): Player list is not empty! or cnt!=0=" << cnt;
1092 qCDebug(KDEGAMESPRIVATE_KGAME_LOG) << "Playerlist of client=" << d->mPlayerList.count() << "count";
1093 qCDebug(KDEGAMESPRIVATE_KGAME_LOG) << "Inactive Playerlist of client=" << d->mInactivePlayerList.count() << "count";
1094 for (KGamePlayerList::iterator it = d->mPlayerList.begin(); it != d->mPlayerList.end(); ++it) {
1124 for (KGamePlayerList::iterator it = d->mPlayerList.begin(); it != d->mPlayerList.end(); ++it) {
1129 qCDebug(KDEGAMESPRIVATE_KGAME_LOG) << "Player id" << oldid << " changed to" << player->id() << "as we are now local";
1151 qCDebug(KDEGAMESPRIVATE_KGAME_LOG) << "Playerlist of client=" << d->mPlayerList.count() << "count";
1152 for (KGamePlayerList::iterator it = d->mPlayerList.begin(); it != d->mPlayerList.end(); ++it) {
1155 qCDebug(KDEGAMESPRIVATE_KGAME_LOG) << "Player" << player->id() << "belongs to the removed game";
1177 if (((int)playerCount() < maxPlayers() || maxPlayers() < 0) && player && KGameMessage::rawGameId(it1) != clientID) {
1213bool KGame::sendGroupMessage(const QByteArray &msg, int msgid, quint32 sender, const QString &group)
1227bool KGame::sendGroupMessage(const QDataStream &msg, int msgid, quint32 sender, const QString &group)
1232bool KGame::sendGroupMessage(const QString &msg, int msgid, quint32 sender, const QString &group)
1281 for (KGamePlayerList::iterator it = d->mPlayerList.begin(); it != d->mPlayerList.end(); ++it) {
static bool isPlayer(quint32 id)
Checks whether a message receiver/sender is a player.
Definition kgamemessage.cpp:34
static quint32 rawGameId(quint32 playerid)
Returns the raw game id, that is, the game id the player belongs to.
Definition kgamemessage.cpp:29
static quint32 createPlayerId(int player, quint32 game)
Creates a fully qualified player ID which contains the original player id in the lower bits and the g...
Definition kgamemessage.cpp:16
The KGameNetwork class is the KGame class with network support.
Definition kgamenetwork.h:39
bool isAdmin() const
The admin of a game is the one who initializes newly connected clients using negotiateNetworkGame and...
Definition kgamenetwork.cpp:89
void signalClientConnected(quint32 clientID)
This signal is emitted whenever the KMessageServer sends us a message that a new client connected.
void disconnect()
Disconnect the current connection and establish a new local one.
Definition kgamenetwork.cpp:273
bool sendMessage(const QByteArray &buffer, int msgid, quint32 receiver=0, quint32 sender=0)
Send a network message msg with a given message ID msgid to all clients.
Definition kgamenetwork.cpp:444
void signalConnectionBroken()
Our connection to the KMessageServer has broken.
void signalClientDisconnected(quint32 clientID, bool broken)
This signal is emitted whenever the KMessageServer sends us a message that a connection to a client w...
void sendError(int error, const QByteArray &message, quint32 receiver=0, quint32 sender=0)
Sends a network message.
Definition kgamenetwork.cpp:449
bool sendSystemMessage(const QByteArray &buffer, int msgid, quint32 receiver=0, quint32 sender=0)
Sends a network message msg with a given msg id msgid to all clients.
Definition kgamenetwork.cpp:390
int registerData(int id, KGamePropertyHandler *owner, PropertyPolicy p, const QString &name=QString())
You have to register a KGamePropertyBase before you can use it.
Definition kgameproperty.cpp:87
A collection class for KGameProperty objects.
Definition kgamepropertyhandler.h:64
void setPolicy(KGamePropertyBase::PropertyPolicy p, bool userspace=true)
Set the policy for all kgame variables which are currently registered in the KGame property handler.
Definition kgamepropertyhandler.cpp:215
void registerHandler(int id, const QObject *receiver, const char *send, const char *emit)
Register the handler with a parent.
Definition kgamepropertyhandler.cpp:75
virtual bool save(QDataStream &stream)
Saves properties into the datastream.
Definition kgamepropertyhandler.cpp:193
bool addProperty(KGamePropertyBase *data, const QString &name=QString())
Adds a KGameProperty property to the handler.
Definition kgamepropertyhandler.cpp:134
virtual bool load(QDataStream &stream)
Loads properties from the datastream.
Definition kgamepropertyhandler.cpp:171
void unlockDirectEmit()
Removes the lock from the emitting of property signals.
Definition kgamepropertyhandler.cpp:271
void lockDirectEmit()
Called by the KGame or KPlayer object or the handler itself to delay emitting of signals.
Definition kgamepropertyhandler.cpp:266
bool processMessage(QDataStream &stream, int id, bool isSender)
Main message process function.
Definition kgamepropertyhandler.cpp:86
void changeValue(type v)
This function does both, change the local value and change the network value.
Definition kgameproperty.h:777
bool setLocal(type v)
This function sets the value of the property directly, i.e.
Definition kgameproperty.h:748
This class takes care of round or move management as well of the gameover condition.
Definition kgamesequence.h:36
virtual KPlayer * nextPlayer(KPlayer *last, bool exclusive=true)
Select the next player in a turn based game.
Definition kgamesequence.cpp:54
virtual int checkGameOver(KPlayer *player)
Check whether the game is over.
Definition kgamesequence.cpp:111
virtual bool sendPlayerInput(QDataStream &msg, KPlayer *player, quint32 sender=0)
Called by KPlayer to send a player input to the KMessageServer.
Definition kgame.cpp:652
void signalSavePrePlayers(QDataStream &stream)
The game will be saved to the given stream.
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:308
KGamePlayerList * inactivePlayerList()
Returns a list of all inactive players.
Definition kgame.cpp:632
virtual void newPlayersJoin(KGamePlayerList *oldplayer, KGamePlayerList *newplayer, QList< int > &inactivate)
This virtual function can be overwritten for your own player management.
Definition kgame.h:712
bool sendPlayerProperty(int msgid, QDataStream &s, quint32 playerId)
This is called by KPlayer::sendProperty only! Internal function!
Definition kgame.cpp:1245
void slotClientDisconnected(quint32 clientId, bool broken)
This slot is called whenever the connection to a client is lost (ie the signal KGameNetwork::signalCl...
Definition kgame.cpp:1142
void signalMessageUpdate(int msgid, quint32 receiver, quint32 sender)
We got an network message.
bool removePlayer(KPlayer *player)
Sends a message over the network, msgid=IdRemovePlayer.
Definition kgame.h:197
void signalPropertyChanged(KGamePropertyBase *property, KGame *me)
This signal is emitted if a player property changes its value and the property is set to notify this ...
bool addPlayer(KPlayer *newplayer)
Note that KPlayer::save must be implemented properly, as well as KPlayer::rtti This will only send a ...
Definition kgame.cpp:365
void signalReplacePlayerIO(KPlayer *player, bool *remove)
When a client disconnects from the game usually all players from that client are removed.
void setGameSequence(KGameSequence *sequence)
Set a new KGameSequence to control player management.
Definition kgame.cpp:720
virtual bool savegame(QDataStream &stream, bool network, bool saveplayers)
Save a game, to file OR network.
Definition kgame.cpp:254
void networkTransmission(QDataStream &stream, int msgid, quint32 receiver, quint32 sender, quint32 clientID) override
This will either forward an incoming message to a specified player (see KPlayer::networkTransmission)...
Definition kgame.cpp:744
void signalNetworkData(int msgid, const QByteArray &buffer, quint32 receiver, quint32 sender)
We got an user defined update message.
void slotServerDisconnected()
This slot is called whenever the connection to the server is lost (ie the signal KGameNetwork::signal...
Definition kgame.cpp:1083
bool activatePlayer(KPlayer *player)
sends activate player: internal use only?
Definition kgame.cpp:552
void signalGameOver(int status, KPlayer *current, KGame *me)
Is emitted after a call to gameOver() returns a non zero return code.
KPlayer * findPlayer(quint32 id) const
Returns the player object for a given player id.
Definition kgame.cpp:343
virtual bool loadgame(QDataStream &stream, bool network, bool reset)
Load a saved game, from file OR network.
Definition kgame.cpp:150
KPlayer * playerInputFinished(KPlayer *player)
Called after the player input is processed by the game.
Definition kgame.cpp:692
KGamePropertyHandler * dataHandler() const
Returns a pointer to the KGame property handler.
Definition kgame.cpp:627
void signalLoadError(QDataStream &stream, bool network, int cookie, bool &result)
Is emitted if a game with a different version cookie is loaded.
void emitSignal(KGamePropertyBase *me)
Called by KGamePropertyHandler only! Internal function!
Definition kgame.cpp:1258
void sendProperty(int msgid, QDataStream &stream, bool *sent)
Called by KGamePropertyHandler only! Internal function!
Definition kgame.cpp:1250
KPlayer * loadPlayer(QDataStream &stream, bool isvirtual=false)
Load the player list from a stream.
Definition kgame.cpp:313
virtual bool load(QDataStream &stream, bool reset=true)
Load a saved game, from file OR network.
Definition kgame.cpp:145
bool inactivatePlayer(KPlayer *player)
sends inactivate player: internal use only?
Definition kgame.cpp:510
void playerDeleted(KPlayer *player)
Called by the destructor of KPlayer to remove itself from the game.
Definition kgame.cpp:435
virtual void negotiateNetworkGame(quint32 clientID)
This member function will transmit e.g.
Definition kgame.cpp:1190
void signalPlayerLeftGame(KPlayer *player)
a player left the game because of a broken connection or so!
virtual bool systemPlayerInput(QDataStream &msg, KPlayer *player, quint32 sender=0)
Called when a player input arrives from KMessageServer.
Definition kgame.cpp:668
void savePlayers(QDataStream &stream, KGamePlayerList *list=nullptr)
Save the player list to a stream.
Definition kgame.cpp:293
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 savePlayer(QDataStream &stream, KPlayer *player)
Prepare a player for being added.
Definition kgame.cpp:284
bool sendGroupMessage(const QByteArray &msg, int msgid, quint32 sender, const QString &group)
See KGameNetwork::sendMessage.
Definition kgame.cpp:1213
void signalLoadPrePlayers(QDataStream &stream)
The game will be loaded from the given stream.
void signalClientJoinedGame(quint32 clientid, KGame *me)
Is emitted after a client is successfully connected to the game.
virtual bool playerInput(QDataStream &msg, KPlayer *player)=0
A player input occurred.
virtual bool save(QDataStream &stream, bool saveplayers=true)
Save a game to a file OR to network.
Definition kgame.cpp:249
void slotClientConnected(quint32 clientId)
Calls negotiateNetworkGame() See KGameNetwork::signalClientConnected.
Definition kgame.cpp:1076
KGamePropertyBase * findProperty(int id) const
This function allows to find the pointer to a player property when you know its id.
Definition kgame.cpp:1263
void setPolicy(GamePolicy p, bool recursive=true)
Changes the consistency policy of a property.
Definition kgame.cpp:1272
void systemRemovePlayer(KPlayer *player, bool deleteit)
Removes a player from the game.
Definition kgame.cpp:470
void networkTransmission(QDataStream &stream, int msgid, quint32 sender)
Receives a message.
Definition kplayer.cpp:387
virtual bool save(QDataStream &stream)
Save a player to a file OR to network.
Definition kplayer.cpp:375
bool setTurn(bool b, bool exclusive=true)
Sets whether this player is the next to turn.
Definition kplayer.cpp:329
virtual bool load(QDataStream &stream)
Load a saved player, from file OR network.
Definition kplayer.cpp:352
virtual const QString & group() const
Query the group the player belongs to.
Definition kplayer.cpp:212
int networkPriority() const
Returns whether this player can be replaced by a network connection player.
Definition kplayer.cpp:257
Q_SCRIPTABLE Q_NOREPLY void abort()
Q_SCRIPTABLE CaptureState status()
QString i18n(const char *text, const TYPE &arg...)
QIODevice * device() const const
bool open(FILE *fh, OpenMode mode, FileHandleFlags handleFlags)
virtual void close() override
ReadOnly
void append(QList< T > &&value)
const_reference at(qsizetype i) const const
iterator begin()
void clear()
qsizetype count() const const
iterator end()
qsizetype indexOf(const AT &value, qsizetype from) const const
bool isEmpty() const const
void prepend(parameter_type value)
qsizetype removeAll(const AT &t)
value_type takeFirst()
Q_EMITQ_EMIT
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
QObject * sender() const const
T dequeue()
void enqueue(const T &t)
bool isEmpty() const const
singleShot
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:13:43 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:13:43 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.