Debian Codegraph @

src/network/cyberoroconnection.h

raw symbols SCIP
1 /***************************************************************************
2 * Copyright (C) 2009 by The qGo Project *
3 * *
4 * This file is part of qGo. *
5 * *
6 * qGo is free software: you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
10 * *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program; if not, see <http://www.gnu.org/licenses/> *
18 * or write to the Free Software Foundation, Inc., *
19 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
20 ***************************************************************************/
21
22
23 #include <QtNetwork>
24 #include "networkconnection.h"
25 #include "messages.h"
26 #include <vector>
27
28 class BoardDispatch;
29 class GameDialogDispatch;
30 class TalkDispatch;
31 class QuickConnection;
32
33 class CyberOroConnection : public NetworkConnection
34 {
35 public:
36 CyberOroConnection(const ConnectionCredentials credentials);
37 ~CyberOroConnection();
38 virtual void sendText(QString text);
39 virtual void sendText(const char * text);
40 virtual void sendDisconnect(void);
41 virtual void sendMsg(unsigned int game_id, QString text);
42 virtual void sendMsg(PlayerListing * player, QString text);
43 virtual void sendToggle(const QString & param, bool val);
44 virtual void sendObserve(const GameListing * game);
45 virtual void sendObserveOutside(const GameListing * game);
46 virtual void sendStatsRequest(const PlayerListing *) {}
47 virtual void sendPlayersRequest(void) {}
48 virtual void sendGamesRequest(void) {}
49 virtual void sendMatchInvite(const PlayerListing * opponent);
50 virtual void adjournGame(const GameListing * game);
51 virtual void sendMove(unsigned int game_id, class MoveRecord * move);
52 virtual void sendRequestCount(unsigned int game_id);
53 virtual void sendRequestMatchMode(unsigned int game_id);
54 virtual void sendAcceptCountRequest(class GameData * data);
55 virtual void sendRefuseCountRequest(class GameData * data);
56 virtual void sendAcceptRequestMatchMode(unsigned int game_id);
57 virtual void sendDeclineRequestMatchMode(unsigned int game_id);
58 virtual void sendTimeLoss(unsigned int game_id);
59 virtual void sendMatchRequest(class MatchRequest * mr);
60 virtual void sendRematchRequest(void);
61 virtual void sendRematchAccept(void);
62 virtual void declineMatchOffer(const PlayerListing * opponent);
63 virtual void cancelMatchOffer(const PlayerListing * opponent);
64 virtual void acceptMatchOffer(const PlayerListing * opponent, class MatchRequest * mr);
65 virtual void sendAdjournRequest(void);
66 virtual void sendAdjourn(void);
67 virtual void sendRefuseAdjourn(void);
68 virtual void handlePendingData();
69 virtual void onReady(void);
70 virtual void changeServer(void);
71 virtual void createRoom(void);
72 virtual void sendCreateRoom(class RoomCreate * room);
73 virtual void sendJoinRoom(const RoomListing & room, const char * password = 0);
74
75 virtual char * sendRequestAccountInfo(int * size, void * p);
76 virtual void handleAccountInfoMsg(int size, char * msg);
77
78 virtual void addFriend(PlayerListing * player);
79 virtual void removeFriend(PlayerListing * player);
80 virtual char * sendAddFriend(int * size, void * p);
81 virtual void recvFriendResponse(int size, char * msg);
82 virtual char * sendRemoveFriend(int * size, void * p);
83 virtual void addBlock(PlayerListing * player);
84 virtual void removeBlock(PlayerListing * player);
85 virtual char * sendAddBlock(int * size, void * p);
86 virtual char * sendRemoveBlock(int * size, void * p);
87
88 virtual const PlayerListing * getOurListing(void);
89 virtual unsigned short getRoomNumber(void) { return room_were_in; }
90
91 virtual void closeBoardDispatch(unsigned int game_id);
92
93 virtual int gd_verifyBoardSize(int v);
94 virtual QTime gd_checkMainTime(TimeSystem s, const QTime & t);
95 virtual QTime gd_checkPeriodTime(TimeSystem s, const QTime & t);
96 virtual unsigned int gd_checkPeriods(TimeSystem s, unsigned int p);
97
98 virtual unsigned int rankToScore(QString rank);
99 virtual unsigned long getGameDialogFlags(void);
100 virtual bool playerTrackingByID(void) { return true; }
101 virtual bool netWillEnterScoreMode(void) { return true; }
102 virtual bool supportsMultipleUndo(void) { return true; }
103 virtual bool supportsRequestMatchMode(void) { return true; }
104 virtual bool supportsRequestAdjourn(void) { return true; }
105 virtual bool supportsRequestCount(void) { return true; }
106 virtual bool supportsObserveOutside(void) { return true; }
107 virtual bool supportsServerChange(void) { return true; }
108 virtual bool supportsRematch(void) { return true; }
109 virtual bool supportsFriendList(void) { return true; }
110 virtual bool supportsBlockList(void) { return true; }
111 virtual unsigned long getPlayerListColumns(void) { return PL_NOMATCHPREFS; }
112 virtual bool supportsCreateRoom(void) { return true; }
113 virtual void saveIfDoesntSave(GameData * data);
114 virtual unsigned long getRoomStructureFlags(void) { return (RS_NOROOMLIST | RS_ONEROOMATATIME | RS_ONEGAMEPERROOM); }
115 virtual const char * getCodecString(void);
116 virtual QString getPlaceString(void);
117 virtual void timerEvent(QTimerEvent * event);
118 private:
119 void handleServerList(unsigned char *msg);
120 int reconnectToServer(void);
121 void sendPersonalChat(const PlayerListing * player, const char * text);
122 void sendRoomChat(const char * text);
123 friend class SetPhrasePalette;
124 void sendServerChat(QString text);
125 void requestAccountInfo(void);
126 void sendLogin(void);
127 void sendSetChatMsg(unsigned short phrase_id);
128 void sendObserveAfterJoining(const GameListing * game);
129 void sendFinishObserving(const GameListing * game);
130 void sendLeave(const GameListing *);
131 void sendGameUpdate(unsigned short game_code);
132 void sendKeepAlive(const GameListing * game);
133 void sendRequestKeepAlive(const GameListing * game);
134 enum FriendsBlocksMsgType { fbm_addFriend, fbm_removeFriend, fbm_addBlock, fbm_removeBlock };
135 char * sendFriendsBlocksMsg(int * size, void * p, enum FriendsBlocksMsgType f);
136 void sendMatchInvite(const PlayerListing * player, bool accepting);
137 void sendDeclineMatchInvite(const PlayerListing * player);
138 void sendDeclineMatchOffer(const PlayerListing * player);
139 void sendMatchOfferPending(const PlayerListing * player);
140 void sendMatchOfferCancel(const PlayerListing * player);
141 void sendMatchOffer(const MatchRequest & mr, bool offercounteroffer = false);
142 void sendInvitationSettings(bool invite);
143 void sendUndo(unsigned int game_code, const MoveRecord * move);
144 void sendDeclineUndo(unsigned int game_code, const MoveRecord * move);
145 void sendAcceptUndo(unsigned int game_code, const MoveRecord * move);
146 void sendRemoveStones(unsigned int game_code, const MoveRecord * move);
147 void sendEndgame12Msg(unsigned int game_id, unsigned short msg_code);
148 void sendEnterScoring(unsigned int game_code);
149 void sendDoneScoring(unsigned int game_id, unsigned short opp_id);
150 void sendResign(unsigned int game_code);
151 void sendMatchResult(unsigned short game_code);
152 void sendNigiri(unsigned short game_code, bool odd);
153 void sendDisconnectMsg(void);
154 void sendChallengeResponse(void);
155 void encode(unsigned char * h, unsigned int cycle_size);
156 void handleMessage(QString msg);
157 void handleMessage(unsigned char * msg, unsigned int size);
158 void handleCodeTable(unsigned char * msg, unsigned int size);
159 void handleConnected(unsigned char * msg, unsigned int size);
160 void handlePlayerList(unsigned char * msg, unsigned int size);
161 QString rating_pointsToRank(unsigned int rp);
162 QString getCountryFromCode(unsigned char code);
163 void handleRoomList(unsigned char * msg, unsigned int size);
164 void handleBroadcastGamesList(unsigned char * msg, unsigned int size);
165 int getPhase(unsigned char byte);
166 QString getRoomTag(unsigned char byte);
167 void handleGamesList(unsigned char * msg, unsigned int size);
168 void handlePlayerConnect(unsigned char * msg, unsigned int size);
169 void handlePlayerRoomJoin(unsigned char * msg, unsigned int size);
170 void removeObserverFromGameListing(const PlayerListing * p);
171 void handlePlayerDisconnect2(unsigned char * msg, unsigned int size);
172 void handleServerAnnouncement(unsigned char * msg, unsigned int size);
173 void handleServerAnnouncementwithLink(unsigned char * msg, unsigned int size);
174 void handleServerRoomChat(unsigned char * msg, unsigned int size);
175 void handlePersonalChat(unsigned char * msg, unsigned int size);
176 void handleRoomChat(unsigned char * msg, unsigned int size);
177 void handleSetPhraseChatMsg(unsigned char * msg, unsigned int size);
178 void handleNewGame(unsigned char * msg, unsigned int size);
179 void handleGameEnded(unsigned char * msg, unsigned int size);
180 void handleNewRoom(unsigned char * msg, unsigned int size);
181 void handleGameMsg(unsigned char * msg, unsigned int size);
182 void handleBettingMatchStart(unsigned char * msg, unsigned int size);
183 void handleBettingMatchResult(unsigned char * msg, unsigned int size);
184 void handleRequestCount(unsigned char * msg, unsigned int size);
185 void handleAcceptCountRequest(unsigned char * msg, unsigned int size);
186 void handleRejectCountRequest(unsigned char * msg, unsigned int size);
187 void handleRequestMatchMode(unsigned char * msg, unsigned int size);
188 void handleRejectMatchModeRequest(unsigned char * msg, unsigned int size);
189 void handleTimeLoss(unsigned char * msg, unsigned int size);
190 void handleMove(unsigned char * msg, unsigned int size);
191 void handleUndo(unsigned char * msg, unsigned int size);
192 void handleDeclineUndo(unsigned char * msg, unsigned int size);
193 void handleAcceptUndo(unsigned char * msg, unsigned int size);
194 void handleMoveList(unsigned char * msg, unsigned int size);
195 void handleMoveList2(unsigned char * msg, unsigned int size);
196 void handleObserverList(unsigned char * msg, unsigned int size);
197 void handleMatchOpened(unsigned char * msg, unsigned int size);
198 void addObserverListToBoard(BoardDispatch * boarddispatch);
199 void handleResumeMatch(unsigned char * msg, unsigned int size);
200 void handleObserveAfterJoining(unsigned char * msg, unsigned int size);
201 void handleInvitationSettings(unsigned char * msg, unsigned int size);
202 QString getStatusFromCode(unsigned char code, QString rank);
203 int compareRanks(QString rankA, QString rankB);
204 void handleCreateRoom(unsigned char * msg, unsigned int size);
205 void handleAdjournRequest(unsigned char * msg, unsigned int size);
206 void handleAdjournDecline(unsigned char * msg, unsigned int size);
207 void handleAdjourn(unsigned char * msg, unsigned int size);
208 void handleMatchInvite(unsigned char * msg, unsigned int size);
209 void handleMatchOffer(unsigned char * msg, unsigned int size);
210 void handleRematchRequest(unsigned char * msg, unsigned int size);
211 void handleRematchAccept(unsigned char * msg, unsigned int size);
212 void handleMatchDecline(unsigned char * msg, unsigned int size);
213 void handleAcceptMatchInvite(unsigned char * msg, unsigned int size);
214 void handleDeclineMatchInvite(unsigned char * msg, unsigned int size);
215 void handleMatchOfferPending(unsigned char * msg, unsigned int size);
216 void handleResign(unsigned char * msg, unsigned int size);
217 void handleEnterScoring(unsigned char * msg, unsigned int size);
218 void handleRemoveStones(unsigned char * msg, unsigned int size);
219 void handleStonesDone(unsigned char * msg, unsigned int size);
220 void handleScore(unsigned char * msg, unsigned int size);
221 void handleGamePhaseUpdate(unsigned char * msg, unsigned int size);
222 void handleMsg3(unsigned char * msg, unsigned int size);
223 void handleFriends(unsigned char * msg, unsigned int size);
224 void handleMsg2(unsigned char * msg, unsigned int size);
225 void handleNigiri(unsigned char * msg, unsigned int size);
226 int time_to_seconds(const QString & time);
227 void killActiveMatchTimers(void);
228 void startMatchTimers(bool ourTurn);
229 void setRoomNumber(unsigned short number);
230 void setAttachedGame(PlayerListing * const player, unsigned short game_id);
231
232 /* We should really just have the player listing for ourself FIXME */
233 unsigned short our_player_id;
234 unsigned char our_special_byte;
235 QTextCodec * textCodec;
236 QTextCodec * serverCodec;
237 class SetPhrasePalette * setphrasepalette;
238 /* FIXME */
239 std::vector <class ServerItem *> serverList;
240 int current_server_index;
241 unsigned char * challenge_response;
242 unsigned char * codetable;
243 unsigned int codetable_IV, codetable_IV2;
244
245 QuickConnection * metaserverQC;
246
247 /* Since 0a7d comes before 1a81 and one has the number for human
248 * consumption and the other the game_code necessary for joining,
249 * etc., we'll just combine them both at 1a81, checking names */
250 std::vector <GameListing *> rooms_without_owners;
251 std::map <unsigned short, unsigned short> game_code_to_number;
252 unsigned short playerlist_skipnumber;
253 unsigned short playerlist_received;
254 unsigned short playerlist_roomnumber;
255 unsigned short playerlist_observernumber;
256 unsigned short roomlist_observers;
257 std::vector <PlayerListing *> playerlist_inorder;
258
259 unsigned short room_were_in;
260 unsigned short connecting_to_game_number; //awkward FIXME
261
262 bool we_send_nigiri;
263
264
265 int matchKeepAliveTimerID, matchRequestKeepAliveTimerID;
266 std::vector <MoveRecord> deadStonesList;
267
268 virtual void OnConnected();
269 };