ScummVM API documentation
net_lobby.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 #ifndef SCUMM_HE_NET_LOBBY_H
23 #define SCUMM_HE_NET_LOBBY_H
24 
25 #include "backends/networking/curl/socket.h"
26 #include "backends/networking/curl/url.h"
27 #include "common/formats/json.h"
28 
29 #include "scumm/he/net/net_main.h"
30 
31 #define MAX_USER_NAME 16
32 
33 // Boneyards (Lobby) opcodes.
34 #define OP_NET_OPEN_WEB_URL 2121
35 #define OP_NET_DOWNLOAD_PLAYBOOK 2122
36 #define OP_NET_CONNECT 2200
37 #define OP_NET_DISCONNECT 2201
38 #define OP_NET_LOGIN 2202
39 #define OP_NET_ENTER_AREA 2204
40 #define OP_NET_GET_NUM_PLAYERS_IN_AREA 2205
41 #define OP_NET_FETCH_PLAYERS_INFO_IN_AREA 2206
42 #define OP_NET_GET_PLAYERS_INFO 2207
43 #define OP_NET_START_HOSTING_GAME 2208
44 #define OP_NET_CALL_PLAYER 2209
45 #define OP_NET_PING_OPPONENT 2211
46 #define OP_NET_RECEIVER_BUSY 2212
47 #define OP_NET_COUNTER_CHALLENGE 2213
48 #define OP_NET_GET_PROFILE 2214
49 #define OP_NET_DECLINE_CHALLENGE 2215
50 #define OP_NET_ACCEPT_CHALLENGE 2216
51 #define OP_NET_STOP_CALLING 2217
52 #define OP_NET_CHANGE_ICON 2218
53 #define OP_NET_SET_PHONE_STATUS 2220
54 #define OP_NET_ANSWER_PHONE 2221
55 #define OP_NET_LEAVE_AREA 2222
56 #define OP_NET_GAME_FINISHED 2223
57 #define OP_NET_GAME_STARTED 2224
58 #define OP_NET_UPDATE_PROFILE_ARRAY 2225
59 #define OP_NET_LOCATE_PLAYER 2226
60 #define OP_NET_GET_POPULATION 2227
61 #define OP_NET_SET_POLL_ANSWER 2228
62 #define OP_NET_UNKNOWN_2229 2229
63 // Used in baseball to get news, poll and banner.
64 #define OP_NET_DOWNLOAD_FILE 2238
65 
66 // MAIA (Updater) opcodes.
67 #define OP_NET_UPDATE_INIT 3000
68 #define OP_NET_FETCH_UPDATES 3002
69 
70 // Commands for VAR_REMOTE_START_SCRIPT. (55 in football; 324 in baseball)
71 #define OP_REMOTE_SYSTEM_ALERT 9911
72 #define OP_REMOTE_START_CONNECTION 9919
73 #define OP_REMOTE_RECEIVE_CHALLENGE 9920
74 #define OP_REMOTE_OPPONENT_ANSWERS 9921
75 #define OP_REMOTE_OPPONENT_BUSY 9922
76 #define OP_REMOTE_COUNTER_CHALLENGE 9923
77 #define OP_REMOTE_OPPONENT_DECLINES 9924
78 #define OP_REMOTE_OPPONENT_ACCEPTS 9925
79 #define OP_REMOTE_PING_TEST_RESULT 9927
80 
81 namespace Scumm {
82 
83 class ScummEngine_v90he;
84 
85 class Lobby {
86 public:
87  Lobby(ScummEngine_v90he *vm);
88  ~Lobby();
89 
90  void doNetworkOnceAFrame();
91  void send(Common::JSONObject &data);
92 
93  int32 dispatch(int op, int numArgs, int32 *args);
94 
95  int _sessionId;
96 protected:
97  ScummEngine_v90he *_vm;
98  Common::String _gameName;
99  Networking::CurlSocket *_socket;
100 
101  Common::String _buffer;
102 
103  Common::JSONArray _playersList;
104 
105  int _userId;
106  Common::String _userName;
107  int _playerId; // Opponent's user ID.
108 
109  int _areaIdForPopulation; // The area id we're waiting for population for (to prevent getting population for one area while wanting another).
110 
111  bool _inArea;
112  int _gamesPlaying;
113 
114  bool _inGame;
115 
116  void writeStringArray(int array, Common::String string);
117  void runRemoteStartScript(int *args);
118  void systemAlert(int type, Common::String message);
119 
120  void receiveData();
121  void processLine(Common::String line);
122 
123  void handleHeartbeat();
124 
125  void openUrl(const char *url);
126 
127  bool connect();
128  void disconnect(bool lost = false);
129 
130  void login(const char *userName, const char *password);
131  void handleLoginResp(int errorCode, int userId, Common::String sessionServer, Common::String response);
132 
133  void getUserProfile(int userId);
134  void handleProfileInfo(Common::JSONArray profile);
135 
136  void handleTeams(Common::JSONArray userTeam, Common::JSONArray opponentTeam, int error, Common::String message);
137 
138  void downloadFile(const char *downloadPath, const char *filename);
139  void handleFileData(Common::String filename, Common::String data);
140 
141  void setIcon(int icon);
142  void setPollAnswer(int pollAnswer);
143 
144  void sendGameResults(int userId, int arrayIndex, int lastFlag);
145 
146  void getPopulation(int areaId, int unknown);
147  void handlePopulation(int areaId, int population);
148 
149  void locatePlayer(int userNameArray);
150  void handleLocateResp(int code, int areaId, Common::String area);
151 
152  void enterArea(int32 areaId);
153  void leaveArea();
154 
155  void getPlayersList(int start, int end);
156  bool _checkPlayersLists(Common::JSONArray other);
157  void handlePlayersList(Common::JSONArray playersList);
158  void getPlayerInfo(int32 idx);
159 
160  void handleGamesPlaying(int games);
161 
162  void setPhoneStatus(int status);
163 
164  void sendBusy(int playerId);
165  void handleReceiverBusy();
166 
167  void pingPlayer(int playerId);
168  void handlePingResult(int ping);
169 
170  void challengePlayer(int32 playerId, int32 stadium);
171  void handleReceiveChallenge(int playerId, int stadium, Common::String name);
172 
173  void challengeTimeout(int playerId);
174 
175  int32 answerPhone(int playerId);
176  void handleConsideringChallenge();
177 
178  void counterChallenge(int stadium);
179  void handleCounterChallenge(int stadium);
180 
181  void declineChallenge(int playerId);
182  void handleDeclineChallenge(int notResponding);
183 
184  void acceptChallenge(int playerId);
185  void handleAcceptChallenge();
186 
187  void startHostingGame(int playerId);
188 
189  void handleGameSession(int sessionId);
190 
191  void gameStarted(int hoster, int player, int playerNameArray);
192  void gameFinished();
193 
194 };
195 
196 } // End of namespace Scumm
197 
198 #endif
Definition: str.h:59
Definition: array.h:52
Definition: socket.h:40
Definition: net_lobby.h:85
Definition: hashmap.h:85
void NORETURN_PRE error(MSVC_PRINTF const char *s,...) GCC_PRINTF(1
Definition: actor.h:30