KDEGames

kgamemessage.cpp
1 /*
2  This file is part of the KDE games library
3  SPDX-FileCopyrightText: 2001 Martin Heni <kde at heni-online.de>
4  SPDX-FileCopyrightText: 2001 Andreas Beckermann <[email protected]>
5 
6  SPDX-License-Identifier: LGPL-2.0-only
7 */
8 
9 #include "kgamemessage.h"
10 
11 // KF
12 #include <KLocalizedString>
13 
14 #define MESSAGE_VERSION 2
15 
16 quint32 KGameMessage::createPlayerId(int oldplayerid,quint32 gameid)
17 {
18  int p;
19  p = oldplayerid & 0x3ff; // remove game id
20  p |= (gameid << 10);
21  return p;
22 }
23 
24 int KGameMessage::rawPlayerId(quint32 playerid)
25 {
26  return playerid & 0x03ff;
27 }
28 
29 quint32 KGameMessage::rawGameId(quint32 playerid)
30 {
31  return (playerid & 0xfc00) >> 10;
32 }
33 
34 bool KGameMessage::isPlayer(quint32 msgid)
35 {
36  if (msgid & 0xfc00) {
37  return true;
38  } else {
39  return false;
40  }
41 }
42 
43 bool KGameMessage::isGame(quint32 msgid)
44 {
45  return !isPlayer(msgid);
46 }
47 
48 
49 void KGameMessage::createHeader(QDataStream &msg,quint32 sender,quint32 receiver,int msgid)
50 {
51  msg << (qint16)sender << (qint16)receiver << (qint16)msgid;
52 }
53 
54 void KGameMessage::extractHeader(QDataStream &msg,quint32 &sender,quint32 &receiver,int &msgid)
55 {
56  qint16 d3,d4,d5;
57  msg >> d3 >> d4 >> d5;
58  sender=d3;receiver=d4;msgid=d5;
59 }
60 
61 void KGameMessage::createPropertyHeader(QDataStream &msg,int id)
62 {
63  msg << (qint16)id;
64 }
65 
66 void KGameMessage::extractPropertyHeader(QDataStream &msg,int &id)
67 {
68  qint16 d1;
69  msg >> d1;
70  id=d1;
71 }
72 
73 void KGameMessage::createPropertyCommand(QDataStream &msg,int cmdid,int pid,int cmd)
74 {
75  createPropertyHeader(msg,cmdid);
76  msg << (qint16)pid ;
77  msg << (qint8)cmd ;
78 }
79 
80 void KGameMessage::extractPropertyCommand(QDataStream &msg,int &pid,int &cmd)
81 {
82  qint16 d1;
83  qint8 d2;
84  msg >> d1 >> d2;
85  pid=d1;
86  cmd=d2;
87 }
88 
89 int KGameMessage::version()
90 {
91  return MESSAGE_VERSION;
92 }
93 
94 QString KGameMessage::messageId2Text(int msgid)
95 {
96 // this should contain all KGameMessage::GameMessageIds
97 // feel free to add missing ones, to remove obsolete one and even feel free to
98 // let it be ;-)
99  switch (msgid) {
100  case KGameMessage::IdSetupGame:
101  return i18n("Setup Game");
102  case KGameMessage::IdSetupGameContinue:
103  return i18n("Setup Game Continue");
104  case KGameMessage::IdGameLoad:
105  return i18n("Load Game");
106  case KGameMessage::IdGameConnected:
107  return i18n("Client game connected");
108  case KGameMessage::IdGameSetupDone:
109  return i18n("Game setup done");
110  case KGameMessage::IdSyncRandom:
111  return i18n("Synchronize Random");
112  case KGameMessage::IdDisconnect:
113  return i18n("Disconnect");
114  case KGameMessage::IdPlayerProperty:
115  return i18n("Player Property");
116  case KGameMessage::IdGameProperty:
117  return i18n("Game Property");
118  case KGameMessage::IdAddPlayer:
119  return i18n("Add Player");
120  case KGameMessage::IdRemovePlayer:
121  return i18n("Remove Player");
122  case KGameMessage::IdActivatePlayer:
123  return i18n("Activate Player");
124  case KGameMessage::IdInactivatePlayer:
125  return i18n("Inactivate Player");
126  case KGameMessage::IdTurn:
127  return i18n("Id Turn");
128  case KGameMessage::IdError:
129  return i18n("Error Message");
130  case KGameMessage::IdPlayerInput:
131  return i18n("Player Input");
132  case KGameMessage::IdIOAdded:
133  return i18n("An IO was added");
134  case KGameMessage::IdProcessQuery:
135  return i18n("Process Query");
136  case KGameMessage::IdPlayerId:
137  return i18n("Player ID");
138  case KGameMessage::IdUser: // IdUser must be unknown for use, too!
139  default:
140  return QString();
141  }
142 }
QString i18n(const char *text, const TYPE &arg...)
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Tue Dec 7 2021 22:34:14 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.