[2488852] | 1 | #include <cstdlib>
|
---|
[371ce29] | 2 | #include <cstdio>
|
---|
[e3535b3] | 3 | #include <unistd.h>
|
---|
[2488852] | 4 | #include <string>
|
---|
[e3535b3] | 5 | #include <iostream>
|
---|
[3b1efcc] | 6 | #include <sstream>
|
---|
[edfd1d0] | 7 | #include <cstring>
|
---|
[60017fc] | 8 | #include <cmath>
|
---|
[371ce29] | 9 |
|
---|
[01d0d00] | 10 | #include <vector>
|
---|
| 11 | #include <map>
|
---|
| 12 |
|
---|
[d211210] | 13 | #include <sys/time.h>
|
---|
| 14 |
|
---|
[73f75c1] | 15 | #include <sys/socket.h>
|
---|
[371ce29] | 16 | #include <netdb.h>
|
---|
[73f75c1] | 17 | #include <netinet/in.h>
|
---|
| 18 | #include <arpa/inet.h>
|
---|
| 19 |
|
---|
[b128109] | 20 | #include <crypt.h>
|
---|
| 21 |
|
---|
[edfd1d0] | 22 | /*
|
---|
[e3535b3] | 23 | #include <openssl/bio.h>
|
---|
| 24 | #include <openssl/ssl.h>
|
---|
| 25 | #include <openssl/err.h>
|
---|
[edfd1d0] | 26 | */
|
---|
[e3535b3] | 27 |
|
---|
[b53c6b3] | 28 | #include "../common/Compiler.h"
|
---|
[3b1efcc] | 29 | #include "../common/Common.h"
|
---|
[edfd1d0] | 30 | #include "../common/Message.h"
|
---|
[60017fc] | 31 | #include "../common/WorldMap.h"
|
---|
[edfd1d0] | 32 | #include "../common/Player.h"
|
---|
[8dad966] | 33 | #include "../common/Projectile.h"
|
---|
[b53c6b3] | 34 |
|
---|
[36082e8] | 35 | #include "DataAccess.h"
|
---|
[d2b411a] | 36 |
|
---|
[e3535b3] | 37 | using namespace std;
|
---|
| 38 |
|
---|
[d211210] | 39 | // from used to be const. Removed that so I could take a reference
|
---|
| 40 | // and use it to send messages
|
---|
[8dad966] | 41 | bool processMessage(const NETWORK_MSG &clientMsg, struct sockaddr_in &from, map<unsigned int, Player>& mapPlayers, WorldMap* gameMap, unsigned int& unusedPlayerId, NETWORK_MSG &serverMsg, int sock, int &scoreBlue, int &scoreRed);
|
---|
[01d0d00] | 42 |
|
---|
[8dad966] | 43 | void updateUnusedPlayerId(unsigned int& id, map<unsigned int, Player>& mapPlayers);
|
---|
| 44 | void updateUnusedProjectileId(unsigned int& id, map<unsigned int, Projectile>& mapProjectiles);
|
---|
[8e540f4] | 45 |
|
---|
[73f75c1] | 46 | // this should probably go somewhere in the common folder
|
---|
[e3535b3] | 47 | void error(const char *msg)
|
---|
| 48 | {
|
---|
| 49 | perror(msg);
|
---|
| 50 | exit(0);
|
---|
| 51 | }
|
---|
| 52 |
|
---|
[01d0d00] | 53 | Player *findPlayerByName(map<unsigned int, Player> &m, string name)
|
---|
[2488852] | 54 | {
|
---|
[01d0d00] | 55 | map<unsigned int, Player>::iterator it;
|
---|
[2488852] | 56 |
|
---|
[01d0d00] | 57 | for (it = m.begin(); it != m.end(); it++)
|
---|
[2488852] | 58 | {
|
---|
[01d0d00] | 59 | if ( it->second.name.compare(name) == 0 )
|
---|
| 60 | return &(it->second);
|
---|
[2488852] | 61 | }
|
---|
| 62 |
|
---|
| 63 | return NULL;
|
---|
| 64 | }
|
---|
| 65 |
|
---|
[01d0d00] | 66 | Player *findPlayerByAddr(map<unsigned int, Player> &m, const sockaddr_in &addr)
|
---|
[73f75c1] | 67 | {
|
---|
[01d0d00] | 68 | map<unsigned int, Player>::iterator it;
|
---|
[73f75c1] | 69 |
|
---|
[01d0d00] | 70 | for (it = m.begin(); it != m.end(); it++)
|
---|
[73f75c1] | 71 | {
|
---|
[01d0d00] | 72 | if ( it->second.addr.sin_addr.s_addr == addr.sin_addr.s_addr &&
|
---|
| 73 | it->second.addr.sin_port == addr.sin_port )
|
---|
| 74 | return &(it->second);
|
---|
[73f75c1] | 75 | }
|
---|
| 76 |
|
---|
| 77 | return NULL;
|
---|
| 78 | }
|
---|
| 79 |
|
---|
[e3535b3] | 80 | int main(int argc, char *argv[])
|
---|
| 81 | {
|
---|
| 82 | int sock, length, n;
|
---|
| 83 | struct sockaddr_in server;
|
---|
[3b1efcc] | 84 | struct sockaddr_in from; // info of client sending the message
|
---|
[e084950] | 85 | NETWORK_MSG clientMsg, serverMsg;
|
---|
[01d0d00] | 86 | map<unsigned int, Player> mapPlayers;
|
---|
[8dad966] | 87 | map<unsigned int, Projectile> mapProjectiles;
|
---|
| 88 | unsigned int unusedPlayerId = 1, unusedProjectileId = 1;
|
---|
[b8601ee] | 89 | int scoreBlue, scoreRed;
|
---|
| 90 |
|
---|
| 91 | scoreBlue = 0;
|
---|
| 92 | scoreRed = 0;
|
---|
[e084950] | 93 |
|
---|
[edfd1d0] | 94 | //SSL_load_error_strings();
|
---|
| 95 | //ERR_load_BIO_strings();
|
---|
| 96 | //OpenSSL_add_all_algorithms();
|
---|
[e3535b3] | 97 |
|
---|
| 98 | if (argc < 2) {
|
---|
[73f75c1] | 99 | cerr << "ERROR, no port provided" << endl;
|
---|
| 100 | exit(1);
|
---|
[e3535b3] | 101 | }
|
---|
[60017fc] | 102 |
|
---|
[7b43385] | 103 | WorldMap* gameMap = WorldMap::loadMapFromFile("../data/map.txt");
|
---|
[6e66ffd] | 104 |
|
---|
| 105 | // add some items to the map. They will be sent out
|
---|
| 106 | // to players when they login
|
---|
[5f868c0] | 107 | for (int y=0; y<gameMap->height; y++) {
|
---|
| 108 | for (int x=0; x<gameMap->width; x++) {
|
---|
| 109 | switch (gameMap->getStructure(x, y)) {
|
---|
| 110 | case WorldMap::STRUCTURE_BLUE_FLAG:
|
---|
| 111 | gameMap->addObject(WorldMap::OBJECT_BLUE_FLAG, x*25+12, y*25+12);
|
---|
| 112 | break;
|
---|
| 113 | case WorldMap::STRUCTURE_RED_FLAG:
|
---|
| 114 | gameMap->addObject(WorldMap::OBJECT_RED_FLAG, x*25+12, y*25+12);
|
---|
| 115 | break;
|
---|
| 116 | }
|
---|
| 117 | }
|
---|
| 118 | }
|
---|
[6e66ffd] | 119 |
|
---|
[371ce29] | 120 | sock = socket(AF_INET, SOCK_DGRAM, 0);
|
---|
[e3535b3] | 121 | if (sock < 0) error("Opening socket");
|
---|
| 122 | length = sizeof(server);
|
---|
| 123 | bzero(&server,length);
|
---|
| 124 | server.sin_family=AF_INET;
|
---|
| 125 | server.sin_port=htons(atoi(argv[1]));
|
---|
[2488852] | 126 | server.sin_addr.s_addr=INADDR_ANY;
|
---|
| 127 | if ( bind(sock, (struct sockaddr *)&server, length) < 0 )
|
---|
[e084950] | 128 | error("binding");
|
---|
[73f75c1] | 129 |
|
---|
[371ce29] | 130 | set_nonblock(sock);
|
---|
| 131 |
|
---|
[da692b9] | 132 | bool broadcastResponse;
|
---|
[d211210] | 133 | timespec ts;
|
---|
[430c80e] | 134 | int timeLastUpdated = 0, curTime = 0, timeLastBroadcast = 0;
|
---|
[cb1f288] | 135 | while (true) {
|
---|
[371ce29] | 136 |
|
---|
| 137 | usleep(5000);
|
---|
| 138 |
|
---|
[d211210] | 139 | clock_gettime(CLOCK_REALTIME, &ts);
|
---|
[430c80e] | 140 | // make the number smaller so millis can fit in an int
|
---|
[d69eb32] | 141 | ts.tv_sec -= 1368000000;
|
---|
[430c80e] | 142 | curTime = ts.tv_sec*1000 + ts.tv_nsec/1000000;
|
---|
[d211210] | 143 |
|
---|
[430c80e] | 144 | if (timeLastUpdated == 0 || (curTime-timeLastUpdated) >= 50) {
|
---|
[d211210] | 145 | timeLastUpdated = curTime;
|
---|
| 146 |
|
---|
[8dad966] | 147 | // move all players
|
---|
[d211210] | 148 | // maybe put this in a separate method
|
---|
[23559e7] | 149 | map<unsigned int, Player>::iterator it;
|
---|
| 150 | FLOAT_POSITION oldPos;
|
---|
| 151 | bool broadcastMove = false;
|
---|
[d211210] | 152 | for (it = mapPlayers.begin(); it != mapPlayers.end(); it++) {
|
---|
[23559e7] | 153 | oldPos = it->second.pos;
|
---|
| 154 | if (it->second.move(gameMap)) {
|
---|
| 155 |
|
---|
| 156 | // check if the move needs to be canceled
|
---|
| 157 | switch(gameMap->getElement(it->second.pos.x/25, it->second.pos.y/25)) {
|
---|
| 158 | case WorldMap::TERRAIN_NONE:
|
---|
| 159 | case WorldMap::TERRAIN_OCEAN:
|
---|
| 160 | case WorldMap::TERRAIN_ROCK:
|
---|
[e4c60ba] | 161 | {
|
---|
[23559e7] | 162 | it->second.pos = oldPos;
|
---|
| 163 | it->second.target.x = it->second.pos.x;
|
---|
| 164 | it->second.target.y = it->second.pos.y;
|
---|
| 165 | broadcastMove = true;
|
---|
| 166 | break;
|
---|
[e4c60ba] | 167 | }
|
---|
[23559e7] | 168 | default:
|
---|
| 169 | // if there are no obstacles, do nothing
|
---|
| 170 | break;
|
---|
| 171 | }
|
---|
| 172 |
|
---|
[e4c60ba] | 173 | WorldMap::ObjectType flagType;
|
---|
| 174 | POSITION pos;
|
---|
[7553db9] | 175 | bool flagTurnedIn = false;
|
---|
[446dc65] | 176 | bool flagReturned = false;
|
---|
| 177 | bool ownFlagAtBase = false;
|
---|
| 178 |
|
---|
[e4c60ba] | 179 | switch(gameMap->getStructure(it->second.pos.x/25, it->second.pos.y/25)) {
|
---|
| 180 | case WorldMap::STRUCTURE_BLUE_FLAG:
|
---|
| 181 | {
|
---|
[7553db9] | 182 | if (it->second.team == 0 && it->second.hasRedFlag)
|
---|
| 183 | {
|
---|
[446dc65] | 184 | // check that your flag is at your base
|
---|
| 185 | pos = gameMap->getStructureLocation(WorldMap::STRUCTURE_BLUE_FLAG);
|
---|
| 186 |
|
---|
| 187 | vector<WorldMap::Object>* vctObjects = gameMap->getObjects();
|
---|
| 188 | vector<WorldMap::Object>::iterator itObjects;
|
---|
| 189 |
|
---|
| 190 | for (itObjects = vctObjects->begin(); itObjects != vctObjects->end(); itObjects++) {
|
---|
| 191 | if (itObjects->type == WorldMap::OBJECT_BLUE_FLAG) {
|
---|
| 192 | if (itObjects->pos.x == pos.x*25+12 && itObjects->pos.y == pos.y*25+12) {
|
---|
| 193 | ownFlagAtBase = true;
|
---|
| 194 | break;
|
---|
| 195 | }
|
---|
| 196 | }
|
---|
| 197 | }
|
---|
| 198 |
|
---|
| 199 | if (ownFlagAtBase) {
|
---|
| 200 | it->second.hasRedFlag = false;
|
---|
| 201 | flagType = WorldMap::OBJECT_RED_FLAG;
|
---|
| 202 | pos = gameMap->getStructureLocation(WorldMap::STRUCTURE_RED_FLAG);
|
---|
| 203 | flagTurnedIn = true;
|
---|
| 204 | scoreBlue++;
|
---|
| 205 | }
|
---|
[e4c60ba] | 206 | }
|
---|
[7553db9] | 207 |
|
---|
| 208 | break;
|
---|
[e4c60ba] | 209 | }
|
---|
| 210 | case WorldMap::STRUCTURE_RED_FLAG:
|
---|
| 211 | {
|
---|
[7553db9] | 212 | if (it->second.team == 1 && it->second.hasBlueFlag)
|
---|
| 213 | {
|
---|
[446dc65] | 214 | // check that your flag is at your base
|
---|
| 215 | pos = gameMap->getStructureLocation(WorldMap::STRUCTURE_RED_FLAG);
|
---|
| 216 |
|
---|
| 217 | vector<WorldMap::Object>* vctObjects = gameMap->getObjects();
|
---|
| 218 | vector<WorldMap::Object>::iterator itObjects;
|
---|
| 219 |
|
---|
| 220 | for (itObjects = vctObjects->begin(); itObjects != vctObjects->end(); itObjects++) {
|
---|
| 221 | if (itObjects->type == WorldMap::OBJECT_RED_FLAG) {
|
---|
| 222 | if (itObjects->pos.x == pos.x*25+12 && itObjects->pos.y == pos.y*25+12) {
|
---|
| 223 | ownFlagAtBase = true;
|
---|
| 224 | break;
|
---|
| 225 | }
|
---|
| 226 | }
|
---|
| 227 | }
|
---|
| 228 |
|
---|
| 229 | if (ownFlagAtBase) {
|
---|
| 230 | it->second.hasBlueFlag = false;
|
---|
| 231 | flagType = WorldMap::OBJECT_BLUE_FLAG;
|
---|
| 232 | pos = gameMap->getStructureLocation(WorldMap::STRUCTURE_BLUE_FLAG);
|
---|
| 233 | flagTurnedIn = true;
|
---|
| 234 | scoreRed++;
|
---|
| 235 | }
|
---|
[e4c60ba] | 236 | }
|
---|
| 237 |
|
---|
[7553db9] | 238 | break;
|
---|
| 239 | }
|
---|
| 240 | }
|
---|
[e4c60ba] | 241 |
|
---|
[7553db9] | 242 | if (flagTurnedIn) {
|
---|
| 243 | // send an OBJECT message to add the flag back to its spawn point
|
---|
| 244 | pos.x = pos.x*25+12;
|
---|
| 245 | pos.y = pos.y*25+12;
|
---|
| 246 | gameMap->addObject(flagType, pos.x, pos.y);
|
---|
[e4c60ba] | 247 |
|
---|
[7553db9] | 248 | serverMsg.type = MSG_TYPE_OBJECT;
|
---|
| 249 | gameMap->getObjects()->back().serialize(serverMsg.buffer);
|
---|
[e4c60ba] | 250 |
|
---|
[7553db9] | 251 | map<unsigned int, Player>::iterator it2;
|
---|
| 252 | for (it2 = mapPlayers.begin(); it2 != mapPlayers.end(); it2++)
|
---|
| 253 | {
|
---|
| 254 | if ( sendMessage(&serverMsg, sock, &(it2->second.addr)) < 0 )
|
---|
| 255 | error("sendMessage");
|
---|
[e4c60ba] | 256 | }
|
---|
[7553db9] | 257 |
|
---|
[b8601ee] | 258 | serverMsg.type = MSG_TYPE_SCORE;
|
---|
| 259 | memcpy(serverMsg.buffer, &scoreBlue, 4);
|
---|
| 260 | memcpy(serverMsg.buffer+4, &scoreRed, 4);
|
---|
| 261 |
|
---|
| 262 | for (it2 = mapPlayers.begin(); it2 != mapPlayers.end(); it2++)
|
---|
| 263 | {
|
---|
| 264 | if ( sendMessage(&serverMsg, sock, &(it2->second.addr)) < 0 )
|
---|
| 265 | error("sendMessage");
|
---|
| 266 | }
|
---|
| 267 |
|
---|
[7553db9] | 268 | // this means a PLAYER message will be sent
|
---|
| 269 | broadcastMove = true;
|
---|
[e4c60ba] | 270 | }
|
---|
| 271 |
|
---|
[446dc65] | 272 | // go through all objects and check if the player is close to one and if its their flag
|
---|
| 273 | vector<WorldMap::Object>* vctObjects = gameMap->getObjects();
|
---|
| 274 | vector<WorldMap::Object>::iterator itObjects;
|
---|
| 275 | POSITION structPos;
|
---|
| 276 |
|
---|
| 277 | for (itObjects = vctObjects->begin(); itObjects != vctObjects->end(); itObjects++) {
|
---|
| 278 | POSITION pos = itObjects->pos;
|
---|
| 279 |
|
---|
| 280 | if (posDistance(it->second.pos, pos.toFloat()) < 10) {
|
---|
| 281 | if (it->second.team == 0 &&
|
---|
| 282 | itObjects->type == WorldMap::OBJECT_BLUE_FLAG) {
|
---|
| 283 | structPos = gameMap->getStructureLocation(WorldMap::STRUCTURE_BLUE_FLAG);
|
---|
| 284 | flagReturned = true;
|
---|
| 285 | break;
|
---|
| 286 | } else if (it->second.team == 1 &&
|
---|
| 287 | itObjects->type == WorldMap::OBJECT_RED_FLAG) {
|
---|
| 288 | structPos = gameMap->getStructureLocation(WorldMap::STRUCTURE_RED_FLAG);
|
---|
| 289 | flagReturned = true;
|
---|
| 290 | break;
|
---|
| 291 | }
|
---|
| 292 | }
|
---|
| 293 | }
|
---|
| 294 |
|
---|
| 295 | if (flagReturned) {
|
---|
| 296 | itObjects->pos.x = structPos.x*25+12;
|
---|
| 297 | itObjects->pos.y = structPos.y*25+12;
|
---|
| 298 |
|
---|
| 299 | serverMsg.type = MSG_TYPE_OBJECT;
|
---|
| 300 | itObjects->serialize(serverMsg.buffer);
|
---|
| 301 |
|
---|
| 302 | map<unsigned int, Player>::iterator it2;
|
---|
| 303 | for (it2 = mapPlayers.begin(); it2 != mapPlayers.end(); it2++)
|
---|
| 304 | {
|
---|
| 305 | if ( sendMessage(&serverMsg, sock, &(it2->second.addr)) < 0 )
|
---|
| 306 | error("sendMessage");
|
---|
| 307 | }
|
---|
| 308 | }
|
---|
| 309 |
|
---|
[23559e7] | 310 | if (broadcastMove) {
|
---|
| 311 | serverMsg.type = MSG_TYPE_PLAYER;
|
---|
| 312 | it->second.serialize(serverMsg.buffer);
|
---|
| 313 |
|
---|
| 314 | cout << "about to broadcast move" << endl;
|
---|
[b07eeac] | 315 | map<unsigned int, Player>::iterator it2;
|
---|
[23559e7] | 316 | for (it2 = mapPlayers.begin(); it2 != mapPlayers.end(); it2++)
|
---|
| 317 | {
|
---|
| 318 | if ( sendMessage(&serverMsg, sock, &(it2->second.addr)) < 0 )
|
---|
| 319 | error("sendMessage");
|
---|
| 320 | }
|
---|
[d211210] | 321 | }
|
---|
| 322 | }
|
---|
[8dad966] | 323 |
|
---|
| 324 | // check if the player's attack animation is complete
|
---|
| 325 | if (it->second.isAttacking && it->second.timeAttackStarted+it->second.attackCooldown <= getCurrentMillis()) {
|
---|
| 326 | it->second.isAttacking = false;
|
---|
[8795a38] | 327 | cout << "Attack animation is complete" << endl;
|
---|
[8dad966] | 328 |
|
---|
| 329 | //send everyone an ATTACK message
|
---|
| 330 | cout << "about to broadcast attack" << endl;
|
---|
| 331 |
|
---|
| 332 | serverMsg.type = MSG_TYPE_ATTACK;
|
---|
| 333 | memcpy(serverMsg.buffer, &it->second.id, 4);
|
---|
| 334 | memcpy(serverMsg.buffer+4, &it->second.targetPlayer, 4);
|
---|
| 335 |
|
---|
| 336 | map<unsigned int, Player>::iterator it2;
|
---|
| 337 | for (it2 = mapPlayers.begin(); it2 != mapPlayers.end(); it2++)
|
---|
| 338 | {
|
---|
| 339 | if ( sendMessage(&serverMsg, sock, &(it2->second.addr)) < 0 )
|
---|
| 340 | error("sendMessage");
|
---|
| 341 | }
|
---|
| 342 |
|
---|
| 343 | if (it->second.attackType == Player::ATTACK_MELEE) {
|
---|
| 344 | Player* target = &mapPlayers[it->second.targetPlayer];
|
---|
| 345 |
|
---|
| 346 | target->health -= it->second.damage;
|
---|
| 347 | if (target->health < 0)
|
---|
| 348 | target->health = 0;
|
---|
| 349 |
|
---|
| 350 | serverMsg.type = MSG_TYPE_PLAYER;
|
---|
| 351 | target->serialize(serverMsg.buffer);
|
---|
| 352 | }else if (it->second.attackType == Player::ATTACK_RANGED) {
|
---|
| 353 | Projectile proj(it->second.pos.x, it->second.pos.y, it->second.targetPlayer, it->second.damage);
|
---|
| 354 | proj.id = unusedProjectileId;
|
---|
| 355 | updateUnusedProjectileId(unusedProjectileId, mapProjectiles);
|
---|
| 356 | mapProjectiles[proj.id] = proj;
|
---|
| 357 |
|
---|
[8795a38] | 358 | int x = it->second.pos.x;
|
---|
| 359 | int y = it->second.pos.y;
|
---|
| 360 |
|
---|
[8dad966] | 361 | serverMsg.type = MSG_TYPE_PROJECTILE;
|
---|
[8795a38] | 362 | memcpy(serverMsg.buffer, &proj.id, 4);
|
---|
| 363 | memcpy(serverMsg.buffer+4, &x, 4);
|
---|
| 364 | memcpy(serverMsg.buffer+8, &y, 4);
|
---|
| 365 | memcpy(serverMsg.buffer+12, &it->second.targetPlayer, 4);
|
---|
[8dad966] | 366 | }else {
|
---|
| 367 | cout << "Invalid attack type: " << it->second.attackType << endl;
|
---|
| 368 | }
|
---|
| 369 |
|
---|
| 370 | // broadcast either a PLAYER or PROJECTILE message
|
---|
| 371 | for (it2 = mapPlayers.begin(); it2 != mapPlayers.end(); it2++)
|
---|
| 372 | {
|
---|
| 373 | if ( sendMessage(&serverMsg, sock, &(it2->second.addr)) < 0 )
|
---|
| 374 | error("sendMessage");
|
---|
| 375 | }
|
---|
| 376 | }
|
---|
| 377 | }
|
---|
| 378 |
|
---|
| 379 | // move all projectiles
|
---|
| 380 | map<unsigned int, Projectile>::iterator itProj;
|
---|
| 381 | for (itProj = mapProjectiles.begin(); itProj != mapProjectiles.end(); itProj++) {
|
---|
| 382 | if (itProj->second.move(mapPlayers)) {
|
---|
| 383 | // send a REMOVE_PROJECTILE message
|
---|
| 384 | serverMsg.type = MSG_TYPE_REMOVE_PROJECTILE;
|
---|
| 385 | memcpy(serverMsg.buffer, &itProj->second.id, 4);
|
---|
| 386 | mapProjectiles.erase(itProj->second.id);
|
---|
| 387 |
|
---|
| 388 | map<unsigned int, Player>::iterator it2;
|
---|
| 389 | for (it2 = mapPlayers.begin(); it2 != mapPlayers.end(); it2++)
|
---|
| 390 | {
|
---|
| 391 | if ( sendMessage(&serverMsg, sock, &(it2->second.addr)) < 0 )
|
---|
| 392 | error("sendMessage");
|
---|
| 393 | }
|
---|
| 394 |
|
---|
| 395 | // send a PLAYER message after dealing damage
|
---|
[8795a38] | 396 | Player* target = &mapPlayers[itProj->second.target];
|
---|
[8dad966] | 397 |
|
---|
| 398 | target->health -= itProj->second.damage;
|
---|
| 399 | if (target->health < 0)
|
---|
| 400 | target->health = 0;
|
---|
| 401 |
|
---|
| 402 | serverMsg.type = MSG_TYPE_PLAYER;
|
---|
| 403 | target->serialize(serverMsg.buffer);
|
---|
| 404 |
|
---|
| 405 | for (it2 = mapPlayers.begin(); it2 != mapPlayers.end(); it2++)
|
---|
| 406 | {
|
---|
| 407 | if ( sendMessage(&serverMsg, sock, &(it2->second.addr)) < 0 )
|
---|
| 408 | error("sendMessage");
|
---|
| 409 | }
|
---|
| 410 | }
|
---|
[d211210] | 411 | }
|
---|
| 412 | }
|
---|
| 413 |
|
---|
[e084950] | 414 | n = receiveMessage(&clientMsg, sock, &from);
|
---|
[8e540f4] | 415 |
|
---|
[371ce29] | 416 | if (n >= 0) {
|
---|
[8dad966] | 417 | broadcastResponse = processMessage(clientMsg, from, mapPlayers, gameMap, unusedPlayerId, serverMsg, sock, scoreBlue, scoreRed);
|
---|
[371ce29] | 418 |
|
---|
[da692b9] | 419 | if (broadcastResponse)
|
---|
[3b1efcc] | 420 | {
|
---|
[da692b9] | 421 | cout << "Should be broadcasting the message" << endl;
|
---|
| 422 |
|
---|
[01d0d00] | 423 | map<unsigned int, Player>::iterator it;
|
---|
| 424 | for (it = mapPlayers.begin(); it != mapPlayers.end(); it++)
|
---|
[3b1efcc] | 425 | {
|
---|
[d211210] | 426 | cout << "Sent message back to " << it->second.name << endl;
|
---|
[01d0d00] | 427 | if ( sendMessage(&serverMsg, sock, &(it->second.addr)) < 0 )
|
---|
[3b1efcc] | 428 | error("sendMessage");
|
---|
| 429 | }
|
---|
| 430 | }
|
---|
| 431 | else
|
---|
| 432 | {
|
---|
[da692b9] | 433 | cout << "Should be sending back the message" << endl;
|
---|
| 434 |
|
---|
[3b1efcc] | 435 | if ( sendMessage(&serverMsg, sock, &from) < 0 )
|
---|
| 436 | error("sendMessage");
|
---|
| 437 | }
|
---|
[7b43385] | 438 | }
|
---|
[8e540f4] | 439 | }
|
---|
[371ce29] | 440 |
|
---|
[8e540f4] | 441 | return 0;
|
---|
| 442 | }
|
---|
| 443 |
|
---|
[8dad966] | 444 | bool processMessage(const NETWORK_MSG& clientMsg, struct sockaddr_in& from, map<unsigned int, Player>& mapPlayers, WorldMap* gameMap, unsigned int& unusedPlayerId, NETWORK_MSG& serverMsg, int sock, int &scoreBlue, int &scoreRed)
|
---|
[8e540f4] | 445 | {
|
---|
[41ad8ed] | 446 | DataAccess da;
|
---|
| 447 |
|
---|
[b8cb03f] | 448 | cout << "Received message" << endl;
|
---|
[8e540f4] | 449 | cout << "MSG: type: " << clientMsg.type << endl;
|
---|
| 450 | cout << "MSG contents: " << clientMsg.buffer << endl;
|
---|
| 451 |
|
---|
[da692b9] | 452 | // maybe we should make a message class and have this be a member
|
---|
[3b1efcc] | 453 | bool broadcastResponse = false;
|
---|
| 454 |
|
---|
[8e540f4] | 455 | // Check that if an invalid message is sent, the client will correctly
|
---|
| 456 | // receive and display the response. Maybe make a special error msg type
|
---|
| 457 | switch(clientMsg.type)
|
---|
| 458 | {
|
---|
| 459 | case MSG_TYPE_REGISTER:
|
---|
[d2b411a] | 460 | {
|
---|
[8e540f4] | 461 | string username(clientMsg.buffer);
|
---|
| 462 | string password(strchr(clientMsg.buffer, '\0')+1);
|
---|
[d2b411a] | 463 |
|
---|
[8e540f4] | 464 | cout << "username: " << username << endl;
|
---|
| 465 | cout << "password: " << password << endl;
|
---|
[d2b411a] | 466 |
|
---|
[3b1efcc] | 467 | int error = da.insertPlayer(username, password);
|
---|
[41ad8ed] | 468 |
|
---|
[3b1efcc] | 469 | if (!error)
|
---|
| 470 | strcpy(serverMsg.buffer, "Registration successful.");
|
---|
| 471 | else
|
---|
| 472 | strcpy(serverMsg.buffer, "Registration failed. Please try again.");
|
---|
[8e540f4] | 473 |
|
---|
| 474 | serverMsg.type = MSG_TYPE_REGISTER;
|
---|
[d2b411a] | 475 |
|
---|
[8e540f4] | 476 | break;
|
---|
| 477 | }
|
---|
| 478 | case MSG_TYPE_LOGIN:
|
---|
| 479 | {
|
---|
[60017fc] | 480 | cout << "Got login message" << endl;
|
---|
| 481 |
|
---|
[d211210] | 482 | serverMsg.type = MSG_TYPE_LOGIN;
|
---|
| 483 |
|
---|
[8e540f4] | 484 | string username(clientMsg.buffer);
|
---|
[41ad8ed] | 485 | string password(strchr(clientMsg.buffer, '\0')+1);
|
---|
[8e540f4] | 486 |
|
---|
[41ad8ed] | 487 | Player* p = da.getPlayer(username);
|
---|
[d2b411a] | 488 |
|
---|
[b128109] | 489 | if (p == NULL || !da.verifyPassword(password, p->password))
|
---|
[41ad8ed] | 490 | {
|
---|
| 491 | strcpy(serverMsg.buffer, "Incorrect username or password");
|
---|
| 492 | }
|
---|
[01d0d00] | 493 | else if(findPlayerByName(mapPlayers, username) != NULL)
|
---|
[41ad8ed] | 494 | {
|
---|
| 495 | strcpy(serverMsg.buffer, "Player has already logged in.");
|
---|
| 496 | }
|
---|
| 497 | else
|
---|
[8e540f4] | 498 | {
|
---|
[d211210] | 499 | serverMsg.type = MSG_TYPE_PLAYER;
|
---|
| 500 |
|
---|
[8dad966] | 501 | updateUnusedPlayerId(unusedPlayerId, mapPlayers);
|
---|
| 502 | p->id = unusedPlayerId;
|
---|
[d211210] | 503 | cout << "new player id: " << p->id << endl;
|
---|
[df79cfd] | 504 | p->setAddr(from);
|
---|
| 505 |
|
---|
| 506 | // choose a random team (either 0 or 1)
|
---|
| 507 | p->team = rand() % 2;
|
---|
[d211210] | 508 |
|
---|
[46fa35a] | 509 | // choose a random class
|
---|
| 510 | int intClass = rand() % 2;
|
---|
| 511 | switch (intClass) {
|
---|
| 512 | case 0:
|
---|
| 513 | p->setClass(Player::CLASS_WARRIOR);
|
---|
| 514 | break;
|
---|
| 515 | case 1:
|
---|
| 516 | p->setClass(Player::CLASS_RANGER);
|
---|
| 517 | break;
|
---|
| 518 | }
|
---|
| 519 |
|
---|
[d211210] | 520 | // tell the new player about all the existing players
|
---|
| 521 | cout << "Sending other players to new player" << endl;
|
---|
| 522 |
|
---|
| 523 | map<unsigned int, Player>::iterator it;
|
---|
| 524 | for (it = mapPlayers.begin(); it != mapPlayers.end(); it++)
|
---|
| 525 | {
|
---|
| 526 | it->second.serialize(serverMsg.buffer);
|
---|
| 527 |
|
---|
| 528 | cout << "sending info about " << it->second.name << endl;
|
---|
[5f868c0] | 529 | cout << "sending id " << it->second.id << endl;
|
---|
| 530 | if ( sendMessage(&serverMsg, sock, &from) < 0 )
|
---|
| 531 | error("sendMessage");
|
---|
| 532 | }
|
---|
| 533 |
|
---|
| 534 | // tell the new player about all map objects
|
---|
| 535 | // (currently just the flags)
|
---|
| 536 | serverMsg.type = MSG_TYPE_OBJECT;
|
---|
[e487381] | 537 | vector<WorldMap::Object>* vctObjects = gameMap->getObjects();
|
---|
[5f868c0] | 538 | vector<WorldMap::Object>::iterator itObjects;
|
---|
| 539 | cout << "sending items" << endl;
|
---|
[e487381] | 540 | for (itObjects = vctObjects->begin(); itObjects != vctObjects->end(); itObjects++) {
|
---|
[5f868c0] | 541 | itObjects->serialize(serverMsg.buffer);
|
---|
| 542 | cout << "sending item id " << itObjects->id << endl;
|
---|
[d211210] | 543 | if ( sendMessage(&serverMsg, sock, &from) < 0 )
|
---|
| 544 | error("sendMessage");
|
---|
| 545 | }
|
---|
[59061f6] | 546 |
|
---|
[b8601ee] | 547 | // send the current score
|
---|
| 548 | serverMsg.type = MSG_TYPE_SCORE;
|
---|
| 549 | memcpy(serverMsg.buffer, &scoreBlue, 4);
|
---|
| 550 | memcpy(serverMsg.buffer+4, &scoreRed, 4);
|
---|
| 551 | if ( sendMessage(&serverMsg, sock, &from) < 0 )
|
---|
| 552 | error("sendMessage");
|
---|
| 553 |
|
---|
| 554 | serverMsg.type = MSG_TYPE_PLAYER;
|
---|
[594d2e9] | 555 | p->serialize(serverMsg.buffer);
|
---|
[d211210] | 556 | cout << "Should be broadcasting the message" << endl;
|
---|
| 557 |
|
---|
| 558 | for (it = mapPlayers.begin(); it != mapPlayers.end(); it++)
|
---|
| 559 | {
|
---|
| 560 | cout << "Sent message back to " << it->second.name << endl;
|
---|
| 561 | if ( sendMessage(&serverMsg, sock, &(it->second.addr)) < 0 )
|
---|
| 562 | error("sendMessage");
|
---|
| 563 | }
|
---|
| 564 |
|
---|
| 565 | serverMsg.type = MSG_TYPE_LOGIN;
|
---|
[8dad966] | 566 | mapPlayers[unusedPlayerId] = *p;
|
---|
[07028b9] | 567 | }
|
---|
| 568 |
|
---|
[41ad8ed] | 569 | delete(p);
|
---|
[07028b9] | 570 |
|
---|
[8e540f4] | 571 | break;
|
---|
| 572 | }
|
---|
| 573 | case MSG_TYPE_LOGOUT:
|
---|
| 574 | {
|
---|
| 575 | string name(clientMsg.buffer);
|
---|
| 576 | cout << "Player logging out: " << name << endl;
|
---|
| 577 |
|
---|
[01d0d00] | 578 | Player *p = findPlayerByName(mapPlayers, name);
|
---|
[633f42a] | 579 |
|
---|
[8e540f4] | 580 | if (p == NULL)
|
---|
| 581 | {
|
---|
| 582 | strcpy(serverMsg.buffer, "That player is not logged in. This is either a bug, or you're trying to hack the server.");
|
---|
[8a3ef42] | 583 | cout << "Player not logged in" << endl;
|
---|
[07028b9] | 584 | }
|
---|
[01d0d00] | 585 | else if ( p->addr.sin_addr.s_addr != from.sin_addr.s_addr ||
|
---|
| 586 | p->addr.sin_port != from.sin_port )
|
---|
[07028b9] | 587 | {
|
---|
[8e540f4] | 588 | strcpy(serverMsg.buffer, "That player is logged in using a differemt connection. This is either a bug, or you're trying to hack the server.");
|
---|
[8a3ef42] | 589 | cout << "Player logged in using a different connection" << endl;
|
---|
[2488852] | 590 | }
|
---|
[8e540f4] | 591 | else
|
---|
[2488852] | 592 | {
|
---|
[8dad966] | 593 | if (p->id < unusedPlayerId)
|
---|
| 594 | unusedPlayerId = p->id;
|
---|
[01d0d00] | 595 | mapPlayers.erase(p->id);
|
---|
[41ad8ed] | 596 | strcpy(serverMsg.buffer, "You have successfully logged out.");
|
---|
[8e540f4] | 597 | }
|
---|
[07028b9] | 598 |
|
---|
[d211210] | 599 | serverMsg.type = MSG_TYPE_LOGOUT;
|
---|
[8a3ef42] | 600 |
|
---|
[8e540f4] | 601 | break;
|
---|
| 602 | }
|
---|
| 603 | case MSG_TYPE_CHAT:
|
---|
| 604 | {
|
---|
[da692b9] | 605 | cout << "Got a chat message" << endl;
|
---|
| 606 |
|
---|
[01d0d00] | 607 | Player *p = findPlayerByAddr(mapPlayers, from);
|
---|
[07028b9] | 608 |
|
---|
[8e540f4] | 609 | if (p == NULL)
|
---|
| 610 | {
|
---|
| 611 | strcpy(serverMsg.buffer, "No player is logged in using this connection. This is either a bug, or you're trying to hack the server.");
|
---|
[2488852] | 612 | }
|
---|
[8e540f4] | 613 | else
|
---|
| 614 | {
|
---|
[3b1efcc] | 615 | broadcastResponse = true;
|
---|
| 616 |
|
---|
[b128109] | 617 | ostringstream oss;
|
---|
| 618 | oss << p->name << ": " << clientMsg.buffer;
|
---|
[3b1efcc] | 619 |
|
---|
[b128109] | 620 | strcpy(serverMsg.buffer, oss.str().c_str());
|
---|
[8e540f4] | 621 | }
|
---|
| 622 |
|
---|
| 623 | serverMsg.type = MSG_TYPE_CHAT;
|
---|
| 624 |
|
---|
| 625 | break;
|
---|
[e084950] | 626 | }
|
---|
[b128109] | 627 | case MSG_TYPE_PLAYER_MOVE:
|
---|
| 628 | {
|
---|
| 629 | cout << "PLAYER_MOVE" << endl;
|
---|
| 630 |
|
---|
| 631 | int id, x, y;
|
---|
| 632 |
|
---|
| 633 | memcpy(&id, clientMsg.buffer, 4);
|
---|
| 634 | memcpy(&x, clientMsg.buffer+4, 4);
|
---|
| 635 | memcpy(&y, clientMsg.buffer+8, 4);
|
---|
[7b43385] | 636 |
|
---|
[b128109] | 637 | cout << "x: " << x << endl;
|
---|
| 638 | cout << "y: " << y << endl;
|
---|
| 639 | cout << "id: " << id << endl;
|
---|
[7b43385] | 640 |
|
---|
[b128109] | 641 | if ( mapPlayers[id].addr.sin_addr.s_addr == from.sin_addr.s_addr &&
|
---|
| 642 | mapPlayers[id].addr.sin_port == from.sin_port )
|
---|
| 643 | {
|
---|
[60017fc] | 644 | // we need to make sure the player can move here
|
---|
| 645 | if (0 <= x && x < 300 && 0 <= y && y < 300 &&
|
---|
| 646 | gameMap->getElement(x/25, y/25) == WorldMap::TERRAIN_GRASS)
|
---|
| 647 | {
|
---|
[7b43385] | 648 | cout << "valid terrain" << endl;
|
---|
| 649 |
|
---|
[60017fc] | 650 | mapPlayers[id].target.x = x;
|
---|
| 651 | mapPlayers[id].target.y = y;
|
---|
| 652 |
|
---|
| 653 | serverMsg.type = MSG_TYPE_PLAYER_MOVE;
|
---|
| 654 |
|
---|
| 655 | memcpy(serverMsg.buffer, &id, 4);
|
---|
[d211210] | 656 | memcpy(serverMsg.buffer+4, &mapPlayers[id].target.x, 4);
|
---|
| 657 | memcpy(serverMsg.buffer+8, &mapPlayers[id].target.y, 4);
|
---|
[60017fc] | 658 |
|
---|
| 659 | broadcastResponse = true;
|
---|
| 660 | }
|
---|
| 661 | else
|
---|
| 662 | cout << "Bad terrain detected" << endl;
|
---|
[b128109] | 663 | }
|
---|
| 664 | else // nned to send back a message indicating failure
|
---|
| 665 | cout << "Player id (" << id << ") doesn't match sender" << endl;
|
---|
| 666 |
|
---|
| 667 | break;
|
---|
| 668 | }
|
---|
[5299436] | 669 | case MSG_TYPE_PICKUP_FLAG:
|
---|
| 670 | {
|
---|
| 671 | // may want to check the id matches the sender, just like for PLAYER_NOVE
|
---|
| 672 | cout << "PICKUP_FLAG" << endl;
|
---|
| 673 |
|
---|
| 674 | int id;
|
---|
| 675 |
|
---|
| 676 | memcpy(&id, clientMsg.buffer, 4);
|
---|
| 677 | cout << "id: " << id << endl;
|
---|
| 678 |
|
---|
[5c84d54] | 679 | vector<WorldMap::Object>* vctObjects = gameMap->getObjects();
|
---|
| 680 | vector<WorldMap::Object>::iterator itObjects;
|
---|
| 681 |
|
---|
| 682 | for (itObjects = vctObjects->begin(); itObjects != vctObjects->end();) {
|
---|
| 683 | POSITION pos = itObjects->pos;
|
---|
| 684 | bool gotFlag = false;
|
---|
| 685 |
|
---|
| 686 | if (posDistance(mapPlayers[id].pos, pos.toFloat()) < 10) {
|
---|
| 687 | switch (itObjects->type) {
|
---|
| 688 | case WorldMap::OBJECT_BLUE_FLAG:
|
---|
| 689 | if (mapPlayers[id].team == 1) {
|
---|
| 690 | gotFlag = true;
|
---|
| 691 | mapPlayers[id].hasBlueFlag = true;
|
---|
| 692 | broadcastResponse = true;
|
---|
| 693 | }
|
---|
| 694 | break;
|
---|
| 695 | case WorldMap::OBJECT_RED_FLAG:
|
---|
| 696 | if (mapPlayers[id].team == 0) {
|
---|
| 697 | gotFlag = true;
|
---|
| 698 | mapPlayers[id].hasRedFlag = true;
|
---|
| 699 | broadcastResponse = true;
|
---|
| 700 | }
|
---|
| 701 | break;
|
---|
| 702 | }
|
---|
| 703 |
|
---|
| 704 | if (gotFlag) {
|
---|
| 705 | serverMsg.type = MSG_TYPE_REMOVE_OBJECT;
|
---|
| 706 | memcpy(serverMsg.buffer, &itObjects->id, 4);
|
---|
| 707 |
|
---|
| 708 | map<unsigned int, Player>::iterator it;
|
---|
| 709 | for (it = mapPlayers.begin(); it != mapPlayers.end(); it++)
|
---|
| 710 | {
|
---|
| 711 | if ( sendMessage(&serverMsg, sock, &(it->second.addr)) < 0 )
|
---|
| 712 | error("sendMessage");
|
---|
| 713 | }
|
---|
| 714 |
|
---|
| 715 | // remove the object from the server-side map
|
---|
| 716 | cout << "size before: " << gameMap->getObjects()->size() << endl;
|
---|
| 717 | itObjects = vctObjects->erase(itObjects);
|
---|
| 718 | cout << "size after: " << gameMap->getObjects()->size() << endl;
|
---|
| 719 | }
|
---|
| 720 | }
|
---|
| 721 |
|
---|
| 722 | if (!gotFlag)
|
---|
| 723 | itObjects++;
|
---|
| 724 | }
|
---|
| 725 |
|
---|
| 726 | serverMsg.type = MSG_TYPE_PLAYER;
|
---|
| 727 | mapPlayers[id].serialize(serverMsg.buffer);
|
---|
| 728 |
|
---|
[5299436] | 729 | break;
|
---|
| 730 | }
|
---|
[e487381] | 731 | case MSG_TYPE_DROP_FLAG:
|
---|
| 732 | {
|
---|
| 733 | // may want to check the id matches the sender, just like for PLAYER_NOVE
|
---|
| 734 | cout << "DROP_FLAG" << endl;
|
---|
| 735 |
|
---|
| 736 | int id;
|
---|
| 737 |
|
---|
| 738 | memcpy(&id, clientMsg.buffer, 4);
|
---|
| 739 | cout << "id: " << id << endl;
|
---|
| 740 |
|
---|
| 741 | WorldMap::ObjectType flagType = WorldMap::OBJECT_NONE;
|
---|
| 742 | if (mapPlayers[id].hasBlueFlag)
|
---|
| 743 | flagType = WorldMap::OBJECT_BLUE_FLAG;
|
---|
| 744 | else if (mapPlayers[id].hasRedFlag)
|
---|
| 745 | flagType = WorldMap::OBJECT_RED_FLAG;
|
---|
| 746 |
|
---|
| 747 | gameMap->addObject(flagType, mapPlayers[id].pos.x, mapPlayers[id].pos.y);
|
---|
| 748 |
|
---|
| 749 | // need to send the OBJECT message too
|
---|
| 750 | serverMsg.type = MSG_TYPE_OBJECT;
|
---|
| 751 | gameMap->getObjects()->back().serialize(serverMsg.buffer);
|
---|
| 752 |
|
---|
| 753 | map<unsigned int, Player>::iterator it;
|
---|
| 754 | for (it = mapPlayers.begin(); it != mapPlayers.end(); it++)
|
---|
| 755 | {
|
---|
| 756 | if ( sendMessage(&serverMsg, sock, &(it->second.addr)) < 0 )
|
---|
| 757 | error("sendMessage");
|
---|
| 758 | }
|
---|
| 759 |
|
---|
| 760 | mapPlayers[id].hasBlueFlag = false;
|
---|
| 761 | mapPlayers[id].hasRedFlag = false;
|
---|
| 762 |
|
---|
| 763 | serverMsg.type = MSG_TYPE_PLAYER;
|
---|
| 764 | mapPlayers[id].serialize(serverMsg.buffer);
|
---|
| 765 |
|
---|
| 766 | broadcastResponse = true;
|
---|
| 767 |
|
---|
| 768 | break;
|
---|
| 769 | }
|
---|
[4b4b153] | 770 | case MSG_TYPE_START_ATTACK:
|
---|
| 771 | {
|
---|
| 772 | cout << "Received a START_ATTACK message" << endl;
|
---|
| 773 |
|
---|
[8a4ed74] | 774 | int id, targetId;
|
---|
| 775 |
|
---|
| 776 | memcpy(&id, clientMsg.buffer, 4);
|
---|
| 777 | memcpy(&targetId, clientMsg.buffer+4, 4);
|
---|
| 778 |
|
---|
[8dad966] | 779 | Player* source = &mapPlayers[id];
|
---|
| 780 | source->timeAttackStarted = getCurrentMillis();
|
---|
| 781 | source->targetPlayer = targetId;
|
---|
[8795a38] | 782 | source->isAttacking = true;
|
---|
[8dad966] | 783 |
|
---|
[4b4b153] | 784 | serverMsg.type = MSG_TYPE_START_ATTACK;
|
---|
[8dad966] | 785 | memcpy(serverMsg.buffer, &id, 4);
|
---|
| 786 | memcpy(serverMsg.buffer+4, &targetId, 4);
|
---|
[4b4b153] | 787 | broadcastResponse = true;
|
---|
[8a4ed74] | 788 |
|
---|
| 789 | break;
|
---|
[4b4b153] | 790 | }
|
---|
| 791 | case MSG_TYPE_ATTACK:
|
---|
| 792 | {
|
---|
| 793 | cout << "Received am ATTACK message" << endl;
|
---|
[8dad966] | 794 | cout << "ERROR: Clients should not send ATTACK messages" << endl;
|
---|
[8a4ed74] | 795 |
|
---|
| 796 | break;
|
---|
[4b4b153] | 797 | }
|
---|
[8e540f4] | 798 | default:
|
---|
| 799 | {
|
---|
| 800 | strcpy(serverMsg.buffer, "Server error occured. Report this please.");
|
---|
[e084950] | 801 |
|
---|
[8e540f4] | 802 | serverMsg.type = MSG_TYPE_CHAT;
|
---|
[e084950] | 803 |
|
---|
[8e540f4] | 804 | break;
|
---|
| 805 | }
|
---|
[e3535b3] | 806 | }
|
---|
[da692b9] | 807 |
|
---|
| 808 | return broadcastResponse;
|
---|
[e3535b3] | 809 | }
|
---|
[da692b9] | 810 |
|
---|
[8dad966] | 811 | void updateUnusedPlayerId(unsigned int& id, map<unsigned int, Player>& mapPlayers)
|
---|
[01d0d00] | 812 | {
|
---|
[1106210] | 813 | while (mapPlayers.find(id) != mapPlayers.end())
|
---|
| 814 | id++;
|
---|
[01d0d00] | 815 | }
|
---|
[8dad966] | 816 |
|
---|
| 817 | void updateUnusedProjectileId(unsigned int& id, map<unsigned int, Projectile>& mapProjectiles)
|
---|
| 818 | {
|
---|
| 819 | while (mapProjectiles.find(id) != mapProjectiles.end())
|
---|
| 820 | id++;
|
---|
| 821 | }
|
---|