home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / include / kgame / kgamemessage.h < prev    next >
Encoding:
C/C++ Source or Header  |  2005-10-10  |  5.8 KB  |  174 lines

  1. /*
  2.     This file is part of the KDE games library
  3.     Copyright (C) 2001 Martin Heni (martin@heni-online.de)
  4.     Copyright (C) 2001 Andreas Beckermann (b_mann@gmx.de)
  5.  
  6.     This library is free software; you can redistribute it and/or
  7.     modify it under the terms of the GNU Library General Public
  8.     License version 2 as published by the Free Software Foundation.
  9.  
  10.     This library is distributed in the hope that it will be useful,
  11.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  13.     Library General Public License for more details.
  14.  
  15.     You should have received a copy of the GNU Library General Public License
  16.     along with this library; see the file COPYING.LIB.  If not, write to
  17.     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  18.     Boston, MA 02110-1301, USA.
  19. */
  20. /*
  21.     $Id: kgamemessage.h 465369 2005-09-29 14:33:08Z mueller $
  22. */
  23. #ifndef __KGAMEMSG_H_
  24. #define __KGAMEMSG_H_
  25.  
  26. #include <qdatastream.h>
  27. #include <kdemacros.h>
  28.  
  29. class KDE_EXPORT KGameMessage
  30. {
  31.   public:
  32.     /**
  33.      * Creates a fully qualified player ID which contains the original
  34.      * player id in the lower bits and the game number in the higher bits.
  35.      * Do not rely on the exact bit positions as they are internal.
  36.      *
  37.      * See also @ref rawPlayerId and @ref rawGameId which are the inverse
  38.      * operations
  39.      *
  40.      * @param playerid the player id - can include a gameid (will get removed)
  41.      * @param gameid The game id (<64). 0 For broadcast.
  42.      * @return the new player id
  43.      */
  44.     static Q_UINT32 createPlayerId(int player, Q_UINT32 game);
  45.  
  46.     /**
  47.      * Returns the raw playerid, that is, a id which does not
  48.      * contain the game number encoded in it. See also @ref createPlayerId which
  49.      * is the inverse operation.
  50.      *
  51.      * @param the player id
  52.      * @return the raw player id
  53.      **/
  54.     static int rawPlayerId(Q_UINT32 playerid);
  55.  
  56.     /**
  57.      * Returns the raw game id, that is, the game id the player
  58.      * belongs to. Se also @ref createPlayerId which is the inverse operation.
  59.      *
  60.      * @param the player id
  61.      * @return the raw game id
  62.      **/
  63.     static Q_UINT32 rawGameId(Q_UINT32 playerid);
  64.  
  65.     /**
  66.      * Checks whether a message receiver/sender is a player
  67.      *
  68.      * @param id The ID of the sender/receiver
  69.      * @return true/false
  70.      */
  71.     static bool isPlayer(Q_UINT32 id);
  72.  
  73.     /**
  74.      * Checks whether the sender/receiver of a message is a game
  75.      *
  76.      * @param id The ID of the sender/receiver
  77.      * @return true/false
  78.      */
  79.     static bool isGame(Q_UINT32 id);
  80.  
  81.     /**
  82.      * Creates a message header given cookie,sender,receiver,...
  83.      *
  84.      * Also puts "hidden" header into the stream which are used by KGameClient
  85.      * (message length and magic cookie). If you don't need them remove them
  86.      * with @ref dropExternalHeader
  87.      */
  88.     static void createHeader(QDataStream &msg, Q_UINT32 sender, Q_UINT32 receiver, int msgid);
  89.  
  90.     /**
  91.      * Retrieves the information like cookie,sender,receiver,... from a message header 
  92.      *
  93.      * Note that it could be necessary to call @ref dropExternalHeader first
  94.      */
  95.     static void extractHeader(QDataStream &msg,Q_UINT32 &sender, Q_UINT32 &receiver, int &msgid);
  96.  
  97.     /**
  98.      * Creates a property header  given the property id
  99.      */
  100.     static void createPropertyHeader(QDataStream &msg, int id);
  101.  
  102.     /**
  103.      * Retrieves the property id from a property message header
  104.      */
  105.     static void extractPropertyHeader(QDataStream &msg, int &id);
  106.  
  107.     /**
  108.      * Creates a property header given the property id
  109.      */
  110.     static void createPropertyCommand(QDataStream &msg, int cmdid, int pid, int cmd);
  111.  
  112.     /**
  113.      * Retrieves the property id from a property message header
  114.      */
  115.     static void extractPropertyCommand(QDataStream &msg, int &pid, int &cmd);
  116.  
  117.     /**
  118.      * @return Version of the network library
  119.      */
  120.     static int version();
  121.  
  122.     /**
  123.      * This function takes a @ref GameMessageIds as argument and returns a
  124.      * suitable string for it. This string can't be used to identify a message
  125.      * (as it is i18n'ed) but it can make debugging more easy. See also @ref
  126.      * KGameDebugDialog.
  127.      * @return Either a i18n'ed string (the name of the id) or QString::null if
  128.      * the msgid is unknown
  129.      **/
  130.     static QString messageId2Text(int msgid);
  131.  
  132.  
  133.   /**
  134.    * Message Ids used inside @ref KGame.
  135.    *
  136.    * You can use your own custom message Id by adding @p IdUser to it.
  137.    **/
  138. // please document every new id with a short comment
  139.   enum GameMessageIds {
  140. // game init, game load, disconnect, ...
  141.     IdSetupGame=1,         // sent to a newly connected player
  142.     IdSetupGameContinue=2, // continue the setup
  143.     IdGameLoad=3,          // load/save the game to the client
  144.     IdGameConnected=4,     // Client successfully connected to master
  145.     IdSyncRandom=5,        // new random seed set - sync games
  146.     IdDisconnect=6,        // KGame object disconnects from game
  147.     IdGameSetupDone=7,     // New game client is now operational
  148.  
  149. // properties
  150.     IdPlayerProperty=20,   // a player property changed
  151.     IdGameProperty=21,     // a game property changed
  152.  
  153. // player management
  154.     IdAddPlayer=30,         // add a player
  155.     IdRemovePlayer=31,      // the player will be removed
  156.     IdActivatePlayer=32,    // Activate a player
  157.     IdInactivatePlayer=33,  // Inactivate a player
  158.     IdTurn=34,              // Turn to be prepared
  159.  
  160. // to-be-categorized
  161.     IdError=100,            // an error occurred
  162.     IdPlayerInput=101,      // a player input occurred
  163.     IdIOAdded=102,          // KGameIO got added to a player...init this IO
  164.  
  165. // special ids for computer player
  166.     IdProcessQuery=220,     // Process queries data (process only)
  167.     IdPlayerId=221,         // PlayerId got changed (process only)
  168.  
  169.     IdUser=256          // a user specified message
  170.   };
  171. };
  172.  
  173. #endif
  174.