| 1 | |
| 2 | /** |
| 3 | * |
| 4 | * @file clientgame.cpp |
| 5 | * |
| 6 | * Part of the OpenJazz project |
| 7 | * |
| 8 | * @par History: |
| 9 | * - 23rd August 2005: Created level.c and menu.c |
| 10 | * - 3rd of February 2009: Renamed level.c to level.cpp and menu.c to menu.cpp |
| 11 | * - 9th March 2009: Created game.cpp from parts of menu.cpp and level.cpp |
| 12 | * - 18th July 2009: Created clientgame.cpp from parts of game.cpp |
| 13 | * |
| 14 | * @par Licence: |
| 15 | * Copyright (c) 2005-2017 AJ Thomson |
| 16 | * |
| 17 | * OpenJazz is distributed under the terms of |
| 18 | * the GNU General Public License, version 2.0 |
| 19 | * |
| 20 | */ |
| 21 | |
| 22 | |
| 23 | #include "game.h"cxx . . $ `<file>/src/game/game.h`/ |
| 24 | #include "gamemode.h"cxx . . $ `<file>/src/game/gamemode.h`/ |
| 25 | |
| 26 | #include "io/controls.h"cxx . . $ `<file>/src/io/controls.h`/ |
| 27 | #include "io/file.h"cxx . . $ `<file>/src/io/file.h`/ |
| 28 | #include "io/gfx/font.h"cxx . . $ `<file>/src/io/gfx/font.h`/ |
| 29 | #include "io/gfx/video.h"cxx . . $ `<file>/src/io/gfx/video.h`/ |
| 30 | #include "io/network.h"cxx . . $ `<file>/src/io/network.h`/ |
| 31 | #include "player/player.h"cxx . . $ `<file>/src/player/player.h`/ |
| 32 | #include "loop.h"cxx . . $ `<file>/src/loop.h`/ |
| 33 | #include "setup.h"cxx . . $ `<file>/src/setup.h`/ |
| 34 | #include "util.h"cxx . . $ `<file>/src/util.h`/ |
| 35 | |
| 36 | #include <string.h> |
| 37 | |
| 38 | |
| 39 | /** |
| 40 | * Create game client |
| 41 | * |
| 42 | * @param address Address of the server to which to connect |
| 43 | */ |
| 44 | ClientGamecxx . . $ ClientGame#::ClientGamecxx . . $ ClientGame#ClientGame(fda57c8427c60377). (char* address) { |
| 45 | |
| 46 | unsigned char buffer[BUFFER_LENGTHcxx . . $ `src/game/game.h:78:9`!]; |
| 47 | unsigned int timeout; |
| 48 | int count, ret; |
| 49 | GameModeTypecxx . . $ GameModeType# modeType; |
| 50 | |
| 51 | sockcxx . . $ ClientGame#sock. = netcxx . . $ net.->joincxx . . $ Network#join(1ef8e6ec083aabb9).(address); |
| 52 | |
| 53 | if (sockcxx . . $ ClientGame#sock. < 0) throw sockcxx . . $ ClientGame#sock.; // Tee hee hee hee hee. |
| 54 | |
| 55 | |
| 56 | // Receive initialisation message |
| 57 | |
| 58 | count = 0; |
| 59 | timeout = globalTickscxx . . $ globalTicks. + T_SCHECKcxx . . $ `src/game/game.h:37:9`! + T_TIMEOUTcxx . . $ `src/io/network.h:41:9`!; |
| 60 | |
| 61 | // Wait for whole message to arrive |
| 62 | while (count < MTL_G_PROPScxx . . $ `src/game/game.h:63:9`!) { |
| 63 | |
| 64 | if (loopcxx . . $ loop(fd873fd06cfe1135).(NORMAL_LOOPcxx . . $ NORMAL_LOOP.) == E_QUITcxx . . $ `src/OpenJazz.h:67:9`!) { |
| 65 | |
| 66 | netcxx . . $ net.->closecxx . . $ Network#close(d4f767463ce0a6b3).(sockcxx . . $ ClientGame#sock.); |
| 67 | |
| 68 | throw E_QUITcxx . . $ `src/OpenJazz.h:67:9`!; |
| 69 | |
| 70 | } |
| 71 | |
| 72 | if (controlscxx . . $ controls..releasecxx . . $ Controls#release(83c267b20bac841a).(C_ESCAPEcxx . . $ `src/io/controls.h:39:9`!)) { |
| 73 | |
| 74 | netcxx . . $ net.->closecxx . . $ Network#close(d4f767463ce0a6b3).(sockcxx . . $ ClientGame#sock.); |
| 75 | |
| 76 | throw E_RETURNcxx . . $ `src/OpenJazz.h:66:9`!; |
| 77 | |
| 78 | } |
| 79 | |
| 80 | SDL_Delay(T_MENU_FRAMEcxx . . $ `src/io/gfx/video.h:78:9`!); |
| 81 | |
| 82 | videocxx . . $ video..clearScreencxx . . $ Video#clearScreen(d4f767463ce0a6b3).(0); |
| 83 | fontmn2cxx . . $ fontmn2.->showStringCenteredcxx . . $ Font#showStringCentered(dffc78c69bf84bb8).("WAITING FOR REPLY"); |
| 84 | |
| 85 | ret = netcxx . . $ net.->recvcxx . . $ Network#recv(ef9024b465536c23).(sockcxx . . $ ClientGame#sock., buffer + count, MTL_G_PROPScxx . . $ `src/game/game.h:63:9`! - count); |
| 86 | |
| 87 | if (ret > 0) count += ret; |
| 88 | |
| 89 | if (globalTickscxx . . $ globalTicks. > timeout) { |
| 90 | |
| 91 | netcxx . . $ net.->closecxx . . $ Network#close(d4f767463ce0a6b3).(sockcxx . . $ ClientGame#sock.); |
| 92 | |
| 93 | throw E_TIMEOUTcxx . . $ `src/OpenJazz.h:58:9`!; |
| 94 | |
| 95 | } |
| 96 | |
| 97 | } |
| 98 | |
| 99 | // Make sure message is valid |
| 100 | if (buffer[1] != MT_G_PROPScxx . . $ `src/game/game.h:47:9`!) { |
| 101 | |
| 102 | netcxx . . $ net.->closecxx . . $ Network#close(d4f767463ce0a6b3).(sockcxx . . $ ClientGame#sock.); |
| 103 | |
| 104 | throw E_DATAcxx . . $ `src/OpenJazz.h:56:9`!; |
| 105 | |
| 106 | } else if (buffer[2] != 1) { |
| 107 | |
| 108 | netcxx . . $ net.->closecxx . . $ Network#close(d4f767463ce0a6b3).(sockcxx . . $ ClientGame#sock.); |
| 109 | |
| 110 | throw E_VERSIONcxx . . $ `src/OpenJazz.h:57:9`!; |
| 111 | |
| 112 | } |
| 113 | |
| 114 | printf("Connected to server (version %d).\n", buffer[2]); |
| 115 | |
| 116 | // Copy game parameters |
| 117 | modeType = GameModeTypecxx . . $ GameModeType#(buffer[3]); |
| 118 | difficultycxx . . $ Game#difficulty. = static_cast<difficultyTypecxx . . $ difficultyType#>(buffer[4]); |
| 119 | maxPlayerscxx . . $ ClientGame#maxPlayers. = buffer[5]; |
| 120 | nPlayerscxx . . $ nPlayers. = buffer[6]; |
| 121 | clientIDcxx . . $ ClientGame#clientID. = buffer[7]; |
| 122 | |
| 123 | printf("Game mode %d, difficulty %d, %d of %d players.\n", modeType, +cxx . . $ operator+(19ccb40277a922df).difficultycxx . . $ Game#difficulty., nPlayerscxx . . $ nPlayers., maxPlayerscxx . . $ ClientGame#maxPlayers.); |
| 124 | |
| 125 | if (nPlayerscxx . . $ nPlayers. > maxPlayerscxx . . $ ClientGame#maxPlayers.) { |
| 126 | |
| 127 | netcxx . . $ net.->closecxx . . $ Network#close(d4f767463ce0a6b3).(sockcxx . . $ ClientGame#sock.); |
| 128 | |
| 129 | throw E_DATAcxx . . $ `src/OpenJazz.h:56:9`!; |
| 130 | |
| 131 | } |
| 132 | |
| 133 | |
| 134 | modecxx . . $ Game#mode. = createModecxx . . $ Game#createMode(14876a996d2f6cf).(modeType); |
| 135 | |
| 136 | if (!modecxx . . $ Game#mode.) { |
| 137 | |
| 138 | netcxx . . $ net.->closecxx . . $ Network#close(d4f767463ce0a6b3).(sockcxx . . $ ClientGame#sock.); |
| 139 | |
| 140 | throw E_DATAcxx . . $ `src/OpenJazz.h:56:9`!; |
| 141 | |
| 142 | } |
| 143 | |
| 144 | |
| 145 | // Create players |
| 146 | nPlayerscxx . . $ nPlayers. = 0; |
| 147 | playerscxx . . $ players. = new Playercxx . . $ Player#Player(49f6e7a06ebc5aa8).[maxPlayerscxx . . $ ClientGame#maxPlayers.]; |
| 148 | |
| 149 | |
| 150 | // Download the level from the server |
| 151 | |
| 152 | levelFilecxx . . $ Game#levelFile. = createStringcxx . . $ createString(a8b8e32347182212).(LEVEL_FILEcxx . . $ `src/io/network.h:47:9`!); |
| 153 | filecxx . . $ ClientGame#file. = NULLcxx . . $ `<external>/15298297234472979974/stddef.h:416:9`!; |
| 154 | |
| 155 | ret = setLevelcxx . . $ ClientGame#setLevel(1ef8e6ec083aabb9).(NULLcxx . . $ `<external>/15298297234472979974/stddef.h:416:9`!); |
| 156 | |
| 157 | if (ret < 0) { |
| 158 | |
| 159 | netcxx . . $ net.->closecxx . . $ Network#close(d4f767463ce0a6b3).(sockcxx . . $ ClientGame#sock.); |
| 160 | |
| 161 | if (filecxx . . $ ClientGame#file.) delete filecxx . . $ ClientGame#file.; |
| 162 | |
| 163 | delete modecxx . . $ Game#mode.; |
| 164 | |
| 165 | throw ret; |
| 166 | |
| 167 | } |
| 168 | |
| 169 | // Add a new player to the game |
| 170 | |
| 171 | buffer[0] = MTL_G_PJOINcxx . . $ `src/game/game.h:64:9`! + strlen(setupcxx . . $ setup..characterNamecxx . . $ Setup#characterName.); |
| 172 | buffer[1] = MT_G_PJOINcxx . . $ `src/game/game.h:48:9`!; |
| 173 | buffer[2] = clientIDcxx . . $ ClientGame#clientID.; |
| 174 | buffer[3] = 0; // Player's number, assigned by the server |
| 175 | buffer[4] = 0; // Player's team, assigned by the server |
| 176 | memcpy(buffer + 5, setupcxx . . $ setup..characterColscxx . . $ Setup#characterCols., 4); |
| 177 | memcpy(buffer + 9, setupcxx . . $ setup..characterNamecxx . . $ Setup#characterName., strlen(setupcxx . . $ setup..characterNamecxx . . $ Setup#characterName.) + 1); |
| 178 | sendcxx . . $ ClientGame#send(f25546b61a629de7).(buffer); |
| 179 | |
| 180 | |
| 181 | // Wait for acknowledgement |
| 182 | |
| 183 | localPlayercxx . . $ localPlayer. = NULLcxx . . $ `<external>/15298297234472979974/stddef.h:416:9`!; |
| 184 | |
| 185 | while (!localPlayercxx . . $ localPlayer.) { |
| 186 | |
| 187 | if (loopcxx . . $ loop(fd873fd06cfe1135).(NORMAL_LOOPcxx . . $ NORMAL_LOOP.) == E_QUITcxx . . $ `src/OpenJazz.h:67:9`!) { |
| 188 | |
| 189 | netcxx . . $ net.->closecxx . . $ Network#close(d4f767463ce0a6b3).(sockcxx . . $ ClientGame#sock.); |
| 190 | |
| 191 | if (filecxx . . $ ClientGame#file.) delete filecxx . . $ ClientGame#file.; |
| 192 | |
| 193 | delete modecxx . . $ Game#mode.; |
| 194 | |
| 195 | throw E_QUITcxx . . $ `src/OpenJazz.h:67:9`!; |
| 196 | |
| 197 | } |
| 198 | |
| 199 | if (controlscxx . . $ controls..releasecxx . . $ Controls#release(83c267b20bac841a).(C_ESCAPEcxx . . $ `src/io/controls.h:39:9`!)) { |
| 200 | |
| 201 | netcxx . . $ net.->closecxx . . $ Network#close(d4f767463ce0a6b3).(sockcxx . . $ ClientGame#sock.); |
| 202 | |
| 203 | if (filecxx . . $ ClientGame#file.) delete filecxx . . $ ClientGame#file.; |
| 204 | |
| 205 | delete modecxx . . $ Game#mode.; |
| 206 | |
| 207 | throw E_RETURNcxx . . $ `src/OpenJazz.h:66:9`!; |
| 208 | |
| 209 | } |
| 210 | |
| 211 | videocxx . . $ video..clearScreencxx . . $ Video#clearScreen(d4f767463ce0a6b3).(0); |
| 212 | fontmn2cxx . . $ fontmn2.->showStringCenteredcxx . . $ Font#showStringCentered(dffc78c69bf84bb8).("JOINING GAME"); |
| 213 | |
| 214 | ret = stepcxx . . $ ClientGame#step(4c679297bf94b9eb).(0); |
| 215 | |
| 216 | if (ret < 0) { |
| 217 | |
| 218 | netcxx . . $ net.->closecxx . . $ Network#close(d4f767463ce0a6b3).(sockcxx . . $ ClientGame#sock.); |
| 219 | |
| 220 | if (filecxx . . $ ClientGame#file.) delete filecxx . . $ ClientGame#file.; |
| 221 | |
| 222 | delete modecxx . . $ Game#mode.; |
| 223 | |
| 224 | throw ret; |
| 225 | |
| 226 | } |
| 227 | |
| 228 | } |
| 229 | |
| 230 | } |
| 231 | |
| 232 | |
| 233 | /** |
| 234 | * Disconnect and destroy client |
| 235 | */ |
| 236 | ClientGamecxx . . $ ClientGame#::~cxx . . $ ClientGame#`~ClientGame`(49f6e7a06ebc5aa8).ClientGamecxx . . $ ClientGame# () { |
| 237 | |
| 238 | netcxx . . $ net.->closecxx . . $ Network#close(d4f767463ce0a6b3).(sockcxx . . $ ClientGame#sock.); |
| 239 | |
| 240 | if (filecxx . . $ ClientGame#file.) delete filecxx . . $ ClientGame#file.; |
| 241 | |
| 242 | delete modecxx . . $ Game#mode.; |
| 243 | |
| 244 | } |
| 245 | |
| 246 | |
| 247 | /** |
| 248 | * Set the next level and receive level data from server |
| 249 | * |
| 250 | * @param fileName The file name of the next level |
| 251 | * |
| 252 | * @return Error code |
| 253 | */ |
| 254 | int ClientGamecxx . . $ ClientGame#::setLevelcxx . . $ ClientGame#setLevel(1ef8e6ec083aabb9). (char* fileName) { |
| 255 | |
| 256 | (void)fileName; |
| 257 | |
| 258 | int ret; |
| 259 | |
| 260 | videocxx . . $ video..setPalettecxx . . $ Video#setPalette(d5421d17e1a4b2b2).(menuPalettecxx . . $ menuPalette.); |
| 261 | |
| 262 | // Wait for level data to start arriving |
| 263 | while (!filecxx . . $ ClientGame#file. && levelFilecxx . . $ Game#levelFile.) { |
| 264 | |
| 265 | if (loopcxx . . $ loop(fd873fd06cfe1135).(NORMAL_LOOPcxx . . $ NORMAL_LOOP.) == E_QUITcxx . . $ `src/OpenJazz.h:67:9`!) return E_QUITcxx . . $ `src/OpenJazz.h:67:9`!; |
| 266 | |
| 267 | if (controlscxx . . $ controls..releasecxx . . $ Controls#release(83c267b20bac841a).(C_ESCAPEcxx . . $ `src/io/controls.h:39:9`!)) return E_RETURNcxx . . $ `src/OpenJazz.h:66:9`!; |
| 268 | |
| 269 | SDL_Delay(T_MENU_FRAMEcxx . . $ `src/io/gfx/video.h:78:9`!); |
| 270 | |
| 271 | videocxx . . $ video..clearScreencxx . . $ Video#clearScreen(d4f767463ce0a6b3).(0); |
| 272 | fontmn2cxx . . $ fontmn2.->showStringCenteredcxx . . $ Font#showStringCentered(dffc78c69bf84bb8).("WAITING FOR SERVER"); |
| 273 | |
| 274 | ret = stepcxx . . $ ClientGame#step(4c679297bf94b9eb).(0); |
| 275 | |
| 276 | if (ret < 0) return ret; |
| 277 | |
| 278 | } |
| 279 | |
| 280 | // Wait for level data to finish arriving |
| 281 | while (filecxx . . $ ClientGame#file. && levelFilecxx . . $ Game#levelFile.) { |
| 282 | |
| 283 | if (loopcxx . . $ loop(fd873fd06cfe1135).(NORMAL_LOOPcxx . . $ NORMAL_LOOP.) == E_QUITcxx . . $ `src/OpenJazz.h:67:9`!) return E_QUITcxx . . $ `src/OpenJazz.h:67:9`!; |
| 284 | |
| 285 | if (controlscxx . . $ controls..releasecxx . . $ Controls#release(83c267b20bac841a).(C_ESCAPEcxx . . $ `src/io/controls.h:39:9`!)) return E_RETURNcxx . . $ `src/OpenJazz.h:66:9`!; |
| 286 | |
| 287 | SDL_Delay(T_MENU_FRAMEcxx . . $ `src/io/gfx/video.h:78:9`!); |
| 288 | |
| 289 | videocxx . . $ video..clearScreencxx . . $ Video#clearScreen(d4f767463ce0a6b3).(0); |
| 290 | |
| 291 | // TODO: center / align stuff better |
| 292 | fontmn2cxx . . $ fontmn2.->showStringcxx . . $ Font#showString(7e50a619d5a117f1).("downloaded", canvasWcxx . . $ canvasW. >> 2, (canvasHcxx . . $ canvasH. >> 1) - 16); |
| 293 | fontmn2cxx . . $ fontmn2.->showNumbercxx . . $ Font#showNumber(b1146eedae1e1d0b).(filecxx . . $ ClientGame#file.->tellcxx . . $ File#tell(b126dc7c1de90089).(), (canvasWcxx . . $ canvasW. >> 2) + 56, canvasHcxx . . $ canvasH. >> 1); |
| 294 | fontmn2cxx . . $ fontmn2.->showStringcxx . . $ Font#showString(7e50a619d5a117f1).("bytes", (canvasWcxx . . $ canvasW. >> 2) + 64, canvasHcxx . . $ canvasH. >> 1); |
| 295 | |
| 296 | ret = stepcxx . . $ ClientGame#step(4c679297bf94b9eb).(0); |
| 297 | |
| 298 | if (ret < 0) return ret; |
| 299 | |
| 300 | } |
| 301 | |
| 302 | return E_NONEcxx . . $ `src/OpenJazz.h:69:9`!; |
| 303 | |
| 304 | } |
| 305 | |
| 306 | |
| 307 | /** |
| 308 | * Send data to server |
| 309 | * |
| 310 | * @param buffer Data to send. First byte indicates length. |
| 311 | */ |
| 312 | void ClientGamecxx . . $ ClientGame#::sendcxx . . $ ClientGame#send(f25546b61a629de7). (unsigned char* buffer) { |
| 313 | |
| 314 | netcxx . . $ net.->sendcxx . . $ Network#send(b2cc8657ba51080d).(sockcxx . . $ ClientGame#sock., buffer); |
| 315 | |
| 316 | } |
| 317 | |
| 318 | |
| 319 | /** |
| 320 | * Game iteration |
| 321 | * |
| 322 | * @param ticks Current time |
| 323 | * |
| 324 | * @return Error code |
| 325 | */ |
| 326 | int ClientGamecxx . . $ ClientGame#::stepcxx . . $ ClientGame#step(4c679297bf94b9eb). (unsigned int ticks) { |
| 327 | |
| 328 | int length; |
| 329 | |
| 330 | // Receive data from server |
| 331 | |
| 332 | if (receivedcxx . . $ ClientGame#received. == 0) { |
| 333 | |
| 334 | // Not currently receiving a message |
| 335 | // See if there is a new message to receive |
| 336 | |
| 337 | length = netcxx . . $ net.->recvcxx . . $ Network#recv(ef9024b465536c23).(sockcxx . . $ ClientGame#sock., recvBuffercxx . . $ ClientGame#recvBuffer., 1); |
| 338 | |
| 339 | if (length > 0) receivedcxx . . $ ClientGame#received.++; |
| 340 | |
| 341 | } |
| 342 | |
| 343 | if (receivedcxx . . $ ClientGame#received. > 0) { |
| 344 | |
| 345 | // Currently receiving a message |
| 346 | // See if there is any more data |
| 347 | |
| 348 | length = netcxx . . $ net.->recvcxx . . $ Network#recv(ef9024b465536c23).(sockcxx . . $ ClientGame#sock., recvBuffercxx . . $ ClientGame#recvBuffer. + receivedcxx . . $ ClientGame#received., |
| 349 | recvBuffercxx . . $ ClientGame#recvBuffer.[0] - receivedcxx . . $ ClientGame#received.); |
| 350 | |
| 351 | if (length > 0) receivedcxx . . $ ClientGame#received. += length; |
| 352 | |
| 353 | |
| 354 | // See if the whole message has arrived |
| 355 | |
| 356 | if (receivedcxx . . $ ClientGame#received. >= recvBuffercxx . . $ ClientGame#recvBuffer.[0]) { |
| 357 | |
| 358 | switch (recvBuffercxx . . $ ClientGame#recvBuffer.[1] & MCMASKcxx . . $ `src/game/game.h:42:9`!) { |
| 359 | |
| 360 | case MC_GAMEcxx . . $ `src/game/game.h:43:9`!: |
| 361 | |
| 362 | if (recvBuffercxx . . $ ClientGame#recvBuffer.[1] == MT_G_LEVELcxx . . $ `src/game/game.h:50:9`!) { |
| 363 | |
| 364 | bool firstMessage; |
| 365 | |
| 366 | if (!filecxx . . $ ClientGame#file.) { |
| 367 | |
| 368 | // Not already storing level data, so open the file |
| 369 | |
| 370 | try { |
| 371 | |
| 372 | filecxx . . $ ClientGame#file. = new Filecxx . . $ File#File(e99a0a23efd851c6).(levelFilecxx . . $ Game#levelFile., PATH_TYPE_TEMPcxx . . $ PATH_TYPE_TEMP., true); |
| 373 | |
| 374 | } catch (int e) { |
| 375 | |
| 376 | return e; |
| 377 | |
| 378 | } |
| 379 | |
| 380 | firstMessage = true; |
| 381 | |
| 382 | } else |
| 383 | firstMessage = false; |
| 384 | |
| 385 | if (filecxx . . $ ClientGame#file.) { |
| 386 | |
| 387 | filecxx . . $ ClientGame#file.->seekcxx . . $ File#seek(918ebd27a9ddbad3).((recvBuffercxx . . $ ClientGame#recvBuffer.[2] << 8) + recvBuffercxx . . $ ClientGame#recvBuffer.[3], true); |
| 388 | |
| 389 | for (int i = 4; i < recvBuffercxx . . $ ClientGame#recvBuffer.[0]; i++) |
| 390 | filecxx . . $ ClientGame#file.->storeCharcxx . . $ File#storeChar(ac50b47256ae7414).(recvBuffercxx . . $ ClientGame#recvBuffer.[i]); |
| 391 | |
| 392 | } |
| 393 | |
| 394 | // If a zero-length block has been sent, it is the last |
| 395 | if (recvBuffercxx . . $ ClientGame#recvBuffer.[0] == MTL_G_LEVELcxx . . $ `src/game/game.h:66:9`!) { |
| 396 | |
| 397 | if (firstMessage) { |
| 398 | |
| 399 | // If the last message was also the first, |
| 400 | // then the run of levels has ended |
| 401 | |
| 402 | delete[] levelFilecxx . . $ Game#levelFile.; |
| 403 | levelFilecxx . . $ Game#levelFile. = NULLcxx . . $ `<external>/15298297234472979974/stddef.h:416:9`!; |
| 404 | |
| 405 | } |
| 406 | |
| 407 | delete filecxx . . $ ClientGame#file.; |
| 408 | filecxx . . $ ClientGame#file. = NULLcxx . . $ `<external>/15298297234472979974/stddef.h:416:9`!; |
| 409 | |
| 410 | } |
| 411 | |
| 412 | break; |
| 413 | |
| 414 | } |
| 415 | |
| 416 | if ((recvBuffercxx . . $ ClientGame#recvBuffer.[1] == MT_G_PJOINcxx . . $ `src/game/game.h:48:9`!) && |
| 417 | (recvBuffercxx . . $ ClientGame#recvBuffer.[3] < maxPlayerscxx . . $ ClientGame#maxPlayers.)) { |
| 418 | |
| 419 | printf("Player %d joined the game.\n", recvBuffercxx . . $ ClientGame#recvBuffer.[3]); |
| 420 | |
| 421 | // Add the new player, and any that have been missed |
| 422 | int player_num; |
| 423 | for (player_num = nPlayerscxx . . $ nPlayers.; player_num <= recvBuffercxx . . $ ClientGame#recvBuffer.[3]; player_num++) { |
| 424 | |
| 425 | playerscxx . . $ players.[player_num].initcxx . . $ Player#init(eadcf6f4775e9cbb).(this, reinterpret_cast<char*>(recvBuffercxx . . $ ClientGame#recvBuffer. + 9), |
| 426 | recvBuffercxx . . $ ClientGame#recvBuffer. + 5, recvBuffercxx . . $ ClientGame#recvBuffer.[4]); |
| 427 | addLevelPlayercxx . . $ Game#addLevelPlayer(34e2c302b1f0e5dd).(playerscxx . . $ players. + player_num); |
| 428 | |
| 429 | printf("Player %d joined team %d.\n", player_num, recvBuffercxx . . $ ClientGame#recvBuffer.[4]); |
| 430 | |
| 431 | } |
| 432 | |
| 433 | nPlayerscxx . . $ nPlayers. = player_num; |
| 434 | |
| 435 | if (recvBuffercxx . . $ ClientGame#recvBuffer.[2] == clientIDcxx . . $ ClientGame#clientID.) |
| 436 | localPlayercxx . . $ localPlayer. = playerscxx . . $ players. + recvBuffercxx . . $ ClientGame#recvBuffer.[3]; |
| 437 | |
| 438 | } |
| 439 | |
| 440 | if ((recvBuffercxx . . $ ClientGame#recvBuffer.[1] == MT_G_PQUITcxx . . $ `src/game/game.h:49:9`!) && |
| 441 | (recvBuffercxx . . $ ClientGame#recvBuffer.[2] < nPlayerscxx . . $ nPlayers.)) { |
| 442 | |
| 443 | printf("Player %d left the game.\n", recvBuffercxx . . $ ClientGame#recvBuffer.[2]); |
| 444 | |
| 445 | // Remove the player |
| 446 | |
| 447 | playerscxx . . $ players.[recvBuffercxx . . $ ClientGame#recvBuffer.[2]].deinitcxx . . $ Player#deinit(49f6e7a06ebc5aa8).(); |
| 448 | |
| 449 | // If necessary, move more recent players |
| 450 | for (int i = recvBuffercxx . . $ ClientGame#recvBuffer.[2]; i < nPlayerscxx . . $ nPlayers.; i++) |
| 451 | memcpy(static_cast<void*>(playerscxx . . $ players. + i), playerscxx . . $ players. + i + 1, |
| 452 | sizeof(Playercxx . . $ Player#)); |
| 453 | |
| 454 | // Clear duplicate pointers |
| 455 | memset(static_cast<void*>(playerscxx . . $ players. + nPlayerscxx . . $ nPlayers.), 0, sizeof(Playercxx . . $ Player#)); |
| 456 | |
| 457 | } |
| 458 | |
| 459 | if (recvBuffercxx . . $ ClientGame#recvBuffer.[1] == MT_G_CHECKcxx . . $ `src/game/game.h:51:9`!) { |
| 460 | |
| 461 | checkXcxx . . $ Game#checkX. = recvBuffercxx . . $ ClientGame#recvBuffer.[2]; |
| 462 | checkYcxx . . $ Game#checkY. = recvBuffercxx . . $ ClientGame#recvBuffer.[3]; |
| 463 | |
| 464 | if (recvBuffercxx . . $ ClientGame#recvBuffer.[0] > 4) { |
| 465 | |
| 466 | checkXcxx . . $ Game#checkX. += recvBuffercxx . . $ ClientGame#recvBuffer.[4] << 8; |
| 467 | checkYcxx . . $ Game#checkY. += recvBuffercxx . . $ ClientGame#recvBuffer.[5] << 8; |
| 468 | |
| 469 | } |
| 470 | |
| 471 | } |
| 472 | |
| 473 | if (recvBuffercxx . . $ ClientGame#recvBuffer.[1] == MT_G_SCOREcxx . . $ `src/game/game.h:52:9`!) { |
| 474 | |
| 475 | for (int i = 0; i < nPlayerscxx . . $ nPlayers.; i++) { |
| 476 | |
| 477 | if (playerscxx . . $ players.[i].getTeamcxx . . $ Player#getTeam(7c4be072098b358f).() == recvBuffercxx . . $ ClientGame#recvBuffer.[2]) |
| 478 | playerscxx . . $ players.[i].teamScorecxx . . $ Player#teamScore.++; |
| 479 | |
| 480 | } |
| 481 | |
| 482 | } |
| 483 | |
| 484 | if (recvBuffercxx . . $ ClientGame#recvBuffer.[1] == MT_G_LTYPEcxx . . $ `src/game/game.h:53:9`!) { |
| 485 | |
| 486 | levelTypecxx . . $ Game#levelType. = (LevelTypecxx . . $ LevelType#)recvBuffercxx . . $ ClientGame#recvBuffer.[2]; |
| 487 | |
| 488 | } |
| 489 | |
| 490 | break; |
| 491 | |
| 492 | case MC_LEVELcxx . . $ `src/game/game.h:44:9`!: |
| 493 | |
| 494 | if (baseLevelcxx . . $ Game#baseLevel.) baseLevelcxx . . $ Game#baseLevel.->receivecxx . . $ Level#receive(f25546b61a629de7).(recvBuffercxx . . $ ClientGame#recvBuffer.); |
| 495 | |
| 496 | break; |
| 497 | |
| 498 | case MC_PLAYERcxx . . $ `src/game/game.h:45:9`!: |
| 499 | |
| 500 | if (recvBuffercxx . . $ ClientGame#recvBuffer.[2] < maxPlayerscxx . . $ ClientGame#maxPlayers.) |
| 501 | playerscxx . . $ players.[recvBuffercxx . . $ ClientGame#recvBuffer.[2]].receivecxx . . $ Player#receive(f25546b61a629de7).(recvBuffercxx . . $ ClientGame#recvBuffer.); |
| 502 | |
| 503 | break; |
| 504 | |
| 505 | } |
| 506 | |
| 507 | receivedcxx . . $ ClientGame#received. = 0; |
| 508 | |
| 509 | } |
| 510 | |
| 511 | } |
| 512 | |
| 513 | if (ticks >= checkTimecxx . . $ Game#checkTime.) { |
| 514 | |
| 515 | // Check for disconnection |
| 516 | |
| 517 | if (!(netcxx . . $ net.->isConnectedcxx . . $ Network#isConnected(83c267b20bac841a).(sockcxx . . $ ClientGame#sock.))) { |
| 518 | |
| 519 | if (filecxx . . $ ClientGame#file.) delete filecxx . . $ ClientGame#file.; |
| 520 | filecxx . . $ ClientGame#file. = NULLcxx . . $ `<external>/15298297234472979974/stddef.h:416:9`!; |
| 521 | |
| 522 | return E_N_DISCONNECTcxx . . $ `src/OpenJazz.h:50:9`!; |
| 523 | |
| 524 | } |
| 525 | |
| 526 | checkTimecxx . . $ Game#checkTime. = ticks + T_CCHECKcxx . . $ `src/game/game.h:39:9`!; |
| 527 | |
| 528 | } |
| 529 | |
| 530 | if (localPlayercxx . . $ localPlayer. && (ticks >= sendTimecxx . . $ Game#sendTime.)) { |
| 531 | |
| 532 | // Update server |
| 533 | unsigned char sendBuffer[BUFFER_LENGTHcxx . . $ `src/game/game.h:78:9`!]; |
| 534 | sendBuffer[0] = MTL_P_TEMPcxx . . $ `src/game/game.h:76:9`!; |
| 535 | sendBuffer[1] = MT_P_TEMPcxx . . $ `src/game/game.h:60:9`!; |
| 536 | sendBuffer[2] = 0; |
| 537 | localPlayercxx . . $ localPlayer.->sendcxx . . $ Player#send(f25546b61a629de7).(sendBuffer); |
| 538 | sendcxx . . $ ClientGame#send(f25546b61a629de7).(sendBuffer); |
| 539 | |
| 540 | sendTimecxx . . $ Game#sendTime. = ticks + T_CSENDcxx . . $ `src/game/game.h:38:9`!; |
| 541 | |
| 542 | } |
| 543 | |
| 544 | return E_NONEcxx . . $ `src/OpenJazz.h:69:9`!; |
| 545 | |
| 546 | } |
| 547 | |
| 548 | |
| 549 | /** |
| 550 | * Ask server to award team a point |
| 551 | * |
| 552 | * @param team Team to receive point |
| 553 | */ |
| 554 | void ClientGamecxx . . $ ClientGame#::scorecxx . . $ ClientGame#score(ac50b47256ae7414). (unsigned char team) { |
| 555 | |
| 556 | unsigned char buffer[MTL_G_SCOREcxx . . $ `src/game/game.h:68:9`!]; |
| 557 | |
| 558 | // Inform server |
| 559 | buffer[0] = MTL_G_SCOREcxx . . $ `src/game/game.h:68:9`!; |
| 560 | buffer[1] = MT_G_SCOREcxx . . $ `src/game/game.h:52:9`!; |
| 561 | buffer[2] = team; |
| 562 | sendcxx . . $ ClientGame#send(f25546b61a629de7).(buffer); |
| 563 | |
| 564 | } |
| 565 | |
| 566 | |
| 567 | /** |
| 568 | * Ask server to approve new checkpoint |
| 569 | * |
| 570 | * @param gridX X-coordinate (in tiles) of the checkpoint |
| 571 | * @param gridY Y-coordinate (in tiles) of the checkpoint |
| 572 | */ |
| 573 | void ClientGamecxx . . $ ClientGame#::setCheckpointcxx . . $ ClientGame#setCheckpoint(3e454b8ccf442868). (int gridX, int gridY) { |
| 574 | |
| 575 | unsigned char buffer[MTL_G_CHECKcxx . . $ `src/game/game.h:67:9`!]; |
| 576 | |
| 577 | buffer[0] = MTL_G_CHECKcxx . . $ `src/game/game.h:67:9`!; |
| 578 | buffer[1] = MT_G_CHECKcxx . . $ `src/game/game.h:51:9`!; |
| 579 | buffer[2] = gridX & 0xFF; |
| 580 | buffer[3] = gridY & 0xFF; |
| 581 | buffer[4] = (gridX >> 8) & 0xFF; |
| 582 | buffer[5] = (gridY >> 8) & 0xFF; |
| 583 | sendcxx . . $ ClientGame#send(f25546b61a629de7).(buffer); |
| 584 | |
| 585 | } |