[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;
|
---|
| 327 |
|
---|
| 328 | //send everyone an ATTACK message
|
---|
| 329 | cout << "about to broadcast attack" << endl;
|
---|
| 330 |
|
---|
| 331 | serverMsg.type = MSG_TYPE_ATTACK;
|
---|
| 332 | memcpy(serverMsg.buffer, &it->second.id, 4);
|
---|
| 333 | memcpy(serverMsg.buffer+4, &it->second.targetPlayer, 4);
|
---|
| 334 |
|
---|
| 335 | map<unsigned int, Player>::iterator it2;
|
---|
| 336 | for (it2 = mapPlayers.begin(); it2 != mapPlayers.end(); it2++)
|
---|
| 337 | {
|
---|
| 338 | if ( sendMessage(&serverMsg, sock, &(it2->second.addr)) < 0 )
|
---|
| 339 | error("sendMessage");
|
---|
| 340 | }
|
---|
| 341 |
|
---|
| 342 | if (it->second.attackType == Player::ATTACK_MELEE) {
|
---|
| 343 | Player* target = &mapPlayers[it->second.targetPlayer];
|
---|
| 344 |
|
---|
| 345 | target->health -= it->second.damage;
|
---|
| 346 | if (target->health < 0)
|
---|
| 347 | target->health = 0;
|
---|
| 348 |
|
---|
| 349 | serverMsg.type = MSG_TYPE_PLAYER;
|
---|
| 350 | target->serialize(serverMsg.buffer);
|
---|
| 351 | }else if (it->second.attackType == Player::ATTACK_RANGED) {
|
---|
| 352 | Projectile proj(it->second.pos.x, it->second.pos.y, it->second.targetPlayer, it->second.damage);
|
---|
| 353 | proj.id = unusedProjectileId;
|
---|
| 354 | updateUnusedProjectileId(unusedProjectileId, mapProjectiles);
|
---|
| 355 | mapProjectiles[proj.id] = proj;
|
---|
| 356 |
|
---|
| 357 | serverMsg.type = MSG_TYPE_PROJECTILE;
|
---|
| 358 | memcpy(serverMsg.buffer, &it->second.pos.x, 4);
|
---|
| 359 | memcpy(serverMsg.buffer+4, &it->second.pos.y, 4);
|
---|
| 360 | memcpy(serverMsg.buffer+8, &it->second.targetPlayer, 4);
|
---|
| 361 | }else {
|
---|
| 362 | cout << "Invalid attack type: " << it->second.attackType << endl;
|
---|
| 363 | }
|
---|
| 364 |
|
---|
| 365 | // broadcast either a PLAYER or PROJECTILE message
|
---|
| 366 | for (it2 = mapPlayers.begin(); it2 != mapPlayers.end(); it2++)
|
---|
| 367 | {
|
---|
| 368 | if ( sendMessage(&serverMsg, sock, &(it2->second.addr)) < 0 )
|
---|
| 369 | error("sendMessage");
|
---|
| 370 | }
|
---|
| 371 | }
|
---|
| 372 | }
|
---|
| 373 |
|
---|
| 374 | // move all projectiles
|
---|
| 375 | map<unsigned int, Projectile>::iterator itProj;
|
---|
| 376 | for (itProj = mapProjectiles.begin(); itProj != mapProjectiles.end(); itProj++) {
|
---|
| 377 | if (itProj->second.move(mapPlayers)) {
|
---|
| 378 | // send a REMOVE_PROJECTILE message
|
---|
| 379 | serverMsg.type = MSG_TYPE_REMOVE_PROJECTILE;
|
---|
| 380 | memcpy(serverMsg.buffer, &itProj->second.id, 4);
|
---|
| 381 | mapProjectiles.erase(itProj->second.id);
|
---|
| 382 |
|
---|
| 383 | map<unsigned int, Player>::iterator it2;
|
---|
| 384 | for (it2 = mapPlayers.begin(); it2 != mapPlayers.end(); it2++)
|
---|
| 385 | {
|
---|
| 386 | if ( sendMessage(&serverMsg, sock, &(it2->second.addr)) < 0 )
|
---|
| 387 | error("sendMessage");
|
---|
| 388 | }
|
---|
| 389 |
|
---|
| 390 | // send a PLAYER message after dealing damage
|
---|
| 391 | Player* target = &mapPlayers[it->second.targetPlayer];
|
---|
| 392 |
|
---|
| 393 | target->health -= itProj->second.damage;
|
---|
| 394 | if (target->health < 0)
|
---|
| 395 | target->health = 0;
|
---|
| 396 |
|
---|
| 397 | serverMsg.type = MSG_TYPE_PLAYER;
|
---|
| 398 | target->serialize(serverMsg.buffer);
|
---|
| 399 |
|
---|
| 400 | for (it2 = mapPlayers.begin(); it2 != mapPlayers.end(); it2++)
|
---|
| 401 | {
|
---|
| 402 | if ( sendMessage(&serverMsg, sock, &(it2->second.addr)) < 0 )
|
---|
| 403 | error("sendMessage");
|
---|
| 404 | }
|
---|
| 405 | }
|
---|
[d211210] | 406 | }
|
---|
| 407 | }
|
---|
| 408 |
|
---|
[e084950] | 409 | n = receiveMessage(&clientMsg, sock, &from);
|
---|
[8e540f4] | 410 |
|
---|
[371ce29] | 411 | if (n >= 0) {
|
---|
[8dad966] | 412 | broadcastResponse = processMessage(clientMsg, from, mapPlayers, gameMap, unusedPlayerId, serverMsg, sock, scoreBlue, scoreRed);
|
---|
[371ce29] | 413 |
|
---|
[da692b9] | 414 | if (broadcastResponse)
|
---|
[3b1efcc] | 415 | {
|
---|
[da692b9] | 416 | cout << "Should be broadcasting the message" << endl;
|
---|
| 417 |
|
---|
[01d0d00] | 418 | map<unsigned int, Player>::iterator it;
|
---|
| 419 | for (it = mapPlayers.begin(); it != mapPlayers.end(); it++)
|
---|
[3b1efcc] | 420 | {
|
---|
[d211210] | 421 | cout << "Sent message back to " << it->second.name << endl;
|
---|
[01d0d00] | 422 | if ( sendMessage(&serverMsg, sock, &(it->second.addr)) < 0 )
|
---|
[3b1efcc] | 423 | error("sendMessage");
|
---|
| 424 | }
|
---|
| 425 | }
|
---|
| 426 | else
|
---|
| 427 | {
|
---|
[da692b9] | 428 | cout << "Should be sending back the message" << endl;
|
---|
| 429 |
|
---|
[3b1efcc] | 430 | if ( sendMessage(&serverMsg, sock, &from) < 0 )
|
---|
| 431 | error("sendMessage");
|
---|
| 432 | }
|
---|
[7b43385] | 433 | }
|
---|
[8e540f4] | 434 | }
|
---|
[371ce29] | 435 |
|
---|
[8e540f4] | 436 | return 0;
|
---|
| 437 | }
|
---|
| 438 |
|
---|
[8dad966] | 439 | 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] | 440 | {
|
---|
[41ad8ed] | 441 | DataAccess da;
|
---|
| 442 |
|
---|
[b8cb03f] | 443 | cout << "Received message" << endl;
|
---|
[8e540f4] | 444 | cout << "MSG: type: " << clientMsg.type << endl;
|
---|
| 445 | cout << "MSG contents: " << clientMsg.buffer << endl;
|
---|
| 446 |
|
---|
[da692b9] | 447 | // maybe we should make a message class and have this be a member
|
---|
[3b1efcc] | 448 | bool broadcastResponse = false;
|
---|
| 449 |
|
---|
[8e540f4] | 450 | // Check that if an invalid message is sent, the client will correctly
|
---|
| 451 | // receive and display the response. Maybe make a special error msg type
|
---|
| 452 | switch(clientMsg.type)
|
---|
| 453 | {
|
---|
| 454 | case MSG_TYPE_REGISTER:
|
---|
[d2b411a] | 455 | {
|
---|
[8e540f4] | 456 | string username(clientMsg.buffer);
|
---|
| 457 | string password(strchr(clientMsg.buffer, '\0')+1);
|
---|
[d2b411a] | 458 |
|
---|
[8e540f4] | 459 | cout << "username: " << username << endl;
|
---|
| 460 | cout << "password: " << password << endl;
|
---|
[d2b411a] | 461 |
|
---|
[3b1efcc] | 462 | int error = da.insertPlayer(username, password);
|
---|
[41ad8ed] | 463 |
|
---|
[3b1efcc] | 464 | if (!error)
|
---|
| 465 | strcpy(serverMsg.buffer, "Registration successful.");
|
---|
| 466 | else
|
---|
| 467 | strcpy(serverMsg.buffer, "Registration failed. Please try again.");
|
---|
[8e540f4] | 468 |
|
---|
| 469 | serverMsg.type = MSG_TYPE_REGISTER;
|
---|
[d2b411a] | 470 |
|
---|
[8e540f4] | 471 | break;
|
---|
| 472 | }
|
---|
| 473 | case MSG_TYPE_LOGIN:
|
---|
| 474 | {
|
---|
[60017fc] | 475 | cout << "Got login message" << endl;
|
---|
| 476 |
|
---|
[d211210] | 477 | serverMsg.type = MSG_TYPE_LOGIN;
|
---|
| 478 |
|
---|
[8e540f4] | 479 | string username(clientMsg.buffer);
|
---|
[41ad8ed] | 480 | string password(strchr(clientMsg.buffer, '\0')+1);
|
---|
[8e540f4] | 481 |
|
---|
[41ad8ed] | 482 | Player* p = da.getPlayer(username);
|
---|
[d2b411a] | 483 |
|
---|
[b128109] | 484 | if (p == NULL || !da.verifyPassword(password, p->password))
|
---|
[41ad8ed] | 485 | {
|
---|
| 486 | strcpy(serverMsg.buffer, "Incorrect username or password");
|
---|
| 487 | }
|
---|
[01d0d00] | 488 | else if(findPlayerByName(mapPlayers, username) != NULL)
|
---|
[41ad8ed] | 489 | {
|
---|
| 490 | strcpy(serverMsg.buffer, "Player has already logged in.");
|
---|
| 491 | }
|
---|
| 492 | else
|
---|
[8e540f4] | 493 | {
|
---|
[d211210] | 494 | serverMsg.type = MSG_TYPE_PLAYER;
|
---|
| 495 |
|
---|
[8dad966] | 496 | updateUnusedPlayerId(unusedPlayerId, mapPlayers);
|
---|
| 497 | p->id = unusedPlayerId;
|
---|
[d211210] | 498 | cout << "new player id: " << p->id << endl;
|
---|
[df79cfd] | 499 | p->setAddr(from);
|
---|
| 500 |
|
---|
| 501 | // choose a random team (either 0 or 1)
|
---|
| 502 | p->team = rand() % 2;
|
---|
[d211210] | 503 |
|
---|
[46fa35a] | 504 | // choose a random class
|
---|
| 505 | int intClass = rand() % 2;
|
---|
| 506 | switch (intClass) {
|
---|
| 507 | case 0:
|
---|
| 508 | p->setClass(Player::CLASS_WARRIOR);
|
---|
| 509 | break;
|
---|
| 510 | case 1:
|
---|
| 511 | p->setClass(Player::CLASS_RANGER);
|
---|
| 512 | break;
|
---|
| 513 | }
|
---|
| 514 |
|
---|
[d211210] | 515 | // tell the new player about all the existing players
|
---|
| 516 | cout << "Sending other players to new player" << endl;
|
---|
| 517 |
|
---|
| 518 | map<unsigned int, Player>::iterator it;
|
---|
| 519 | for (it = mapPlayers.begin(); it != mapPlayers.end(); it++)
|
---|
| 520 | {
|
---|
| 521 | it->second.serialize(serverMsg.buffer);
|
---|
| 522 |
|
---|
| 523 | cout << "sending info about " << it->second.name << endl;
|
---|
[5f868c0] | 524 | cout << "sending id " << it->second.id << endl;
|
---|
| 525 | if ( sendMessage(&serverMsg, sock, &from) < 0 )
|
---|
| 526 | error("sendMessage");
|
---|
| 527 | }
|
---|
| 528 |
|
---|
| 529 | // tell the new player about all map objects
|
---|
| 530 | // (currently just the flags)
|
---|
| 531 | serverMsg.type = MSG_TYPE_OBJECT;
|
---|
[e487381] | 532 | vector<WorldMap::Object>* vctObjects = gameMap->getObjects();
|
---|
[5f868c0] | 533 | vector<WorldMap::Object>::iterator itObjects;
|
---|
| 534 | cout << "sending items" << endl;
|
---|
[e487381] | 535 | for (itObjects = vctObjects->begin(); itObjects != vctObjects->end(); itObjects++) {
|
---|
[5f868c0] | 536 | itObjects->serialize(serverMsg.buffer);
|
---|
| 537 | cout << "sending item id " << itObjects->id << endl;
|
---|
[d211210] | 538 | if ( sendMessage(&serverMsg, sock, &from) < 0 )
|
---|
| 539 | error("sendMessage");
|
---|
| 540 | }
|
---|
[59061f6] | 541 |
|
---|
[b8601ee] | 542 | // send the current score
|
---|
| 543 | serverMsg.type = MSG_TYPE_SCORE;
|
---|
| 544 | memcpy(serverMsg.buffer, &scoreBlue, 4);
|
---|
| 545 | memcpy(serverMsg.buffer+4, &scoreRed, 4);
|
---|
| 546 | if ( sendMessage(&serverMsg, sock, &from) < 0 )
|
---|
| 547 | error("sendMessage");
|
---|
| 548 |
|
---|
| 549 | serverMsg.type = MSG_TYPE_PLAYER;
|
---|
[594d2e9] | 550 | p->serialize(serverMsg.buffer);
|
---|
[d211210] | 551 | cout << "Should be broadcasting the message" << endl;
|
---|
| 552 |
|
---|
| 553 | for (it = mapPlayers.begin(); it != mapPlayers.end(); it++)
|
---|
| 554 | {
|
---|
| 555 | cout << "Sent message back to " << it->second.name << endl;
|
---|
| 556 | if ( sendMessage(&serverMsg, sock, &(it->second.addr)) < 0 )
|
---|
| 557 | error("sendMessage");
|
---|
| 558 | }
|
---|
| 559 |
|
---|
| 560 | serverMsg.type = MSG_TYPE_LOGIN;
|
---|
[8dad966] | 561 | mapPlayers[unusedPlayerId] = *p;
|
---|
[07028b9] | 562 | }
|
---|
| 563 |
|
---|
[41ad8ed] | 564 | delete(p);
|
---|
[07028b9] | 565 |
|
---|
[8e540f4] | 566 | break;
|
---|
| 567 | }
|
---|
| 568 | case MSG_TYPE_LOGOUT:
|
---|
| 569 | {
|
---|
| 570 | string name(clientMsg.buffer);
|
---|
| 571 | cout << "Player logging out: " << name << endl;
|
---|
| 572 |
|
---|
[01d0d00] | 573 | Player *p = findPlayerByName(mapPlayers, name);
|
---|
[633f42a] | 574 |
|
---|
[8e540f4] | 575 | if (p == NULL)
|
---|
| 576 | {
|
---|
| 577 | strcpy(serverMsg.buffer, "That player is not logged in. This is either a bug, or you're trying to hack the server.");
|
---|
[8a3ef42] | 578 | cout << "Player not logged in" << endl;
|
---|
[07028b9] | 579 | }
|
---|
[01d0d00] | 580 | else if ( p->addr.sin_addr.s_addr != from.sin_addr.s_addr ||
|
---|
| 581 | p->addr.sin_port != from.sin_port )
|
---|
[07028b9] | 582 | {
|
---|
[8e540f4] | 583 | 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] | 584 | cout << "Player logged in using a different connection" << endl;
|
---|
[2488852] | 585 | }
|
---|
[8e540f4] | 586 | else
|
---|
[2488852] | 587 | {
|
---|
[8dad966] | 588 | if (p->id < unusedPlayerId)
|
---|
| 589 | unusedPlayerId = p->id;
|
---|
[01d0d00] | 590 | mapPlayers.erase(p->id);
|
---|
[41ad8ed] | 591 | strcpy(serverMsg.buffer, "You have successfully logged out.");
|
---|
[8e540f4] | 592 | }
|
---|
[07028b9] | 593 |
|
---|
[d211210] | 594 | serverMsg.type = MSG_TYPE_LOGOUT;
|
---|
[8a3ef42] | 595 |
|
---|
[8e540f4] | 596 | break;
|
---|
| 597 | }
|
---|
| 598 | case MSG_TYPE_CHAT:
|
---|
| 599 | {
|
---|
[da692b9] | 600 | cout << "Got a chat message" << endl;
|
---|
| 601 |
|
---|
[01d0d00] | 602 | Player *p = findPlayerByAddr(mapPlayers, from);
|
---|
[07028b9] | 603 |
|
---|
[8e540f4] | 604 | if (p == NULL)
|
---|
| 605 | {
|
---|
| 606 | 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] | 607 | }
|
---|
[8e540f4] | 608 | else
|
---|
| 609 | {
|
---|
[3b1efcc] | 610 | broadcastResponse = true;
|
---|
| 611 |
|
---|
[b128109] | 612 | ostringstream oss;
|
---|
| 613 | oss << p->name << ": " << clientMsg.buffer;
|
---|
[3b1efcc] | 614 |
|
---|
[b128109] | 615 | strcpy(serverMsg.buffer, oss.str().c_str());
|
---|
[8e540f4] | 616 | }
|
---|
| 617 |
|
---|
| 618 | serverMsg.type = MSG_TYPE_CHAT;
|
---|
| 619 |
|
---|
| 620 | break;
|
---|
[e084950] | 621 | }
|
---|
[b128109] | 622 | case MSG_TYPE_PLAYER_MOVE:
|
---|
| 623 | {
|
---|
| 624 | cout << "PLAYER_MOVE" << endl;
|
---|
| 625 |
|
---|
| 626 | int id, x, y;
|
---|
| 627 |
|
---|
| 628 | memcpy(&id, clientMsg.buffer, 4);
|
---|
| 629 | memcpy(&x, clientMsg.buffer+4, 4);
|
---|
| 630 | memcpy(&y, clientMsg.buffer+8, 4);
|
---|
[7b43385] | 631 |
|
---|
[b128109] | 632 | cout << "x: " << x << endl;
|
---|
| 633 | cout << "y: " << y << endl;
|
---|
| 634 | cout << "id: " << id << endl;
|
---|
[7b43385] | 635 |
|
---|
[b128109] | 636 | if ( mapPlayers[id].addr.sin_addr.s_addr == from.sin_addr.s_addr &&
|
---|
| 637 | mapPlayers[id].addr.sin_port == from.sin_port )
|
---|
| 638 | {
|
---|
[60017fc] | 639 | // we need to make sure the player can move here
|
---|
| 640 | if (0 <= x && x < 300 && 0 <= y && y < 300 &&
|
---|
| 641 | gameMap->getElement(x/25, y/25) == WorldMap::TERRAIN_GRASS)
|
---|
| 642 | {
|
---|
[7b43385] | 643 | cout << "valid terrain" << endl;
|
---|
| 644 |
|
---|
[60017fc] | 645 | mapPlayers[id].target.x = x;
|
---|
| 646 | mapPlayers[id].target.y = y;
|
---|
| 647 |
|
---|
| 648 | serverMsg.type = MSG_TYPE_PLAYER_MOVE;
|
---|
| 649 |
|
---|
| 650 | memcpy(serverMsg.buffer, &id, 4);
|
---|
[d211210] | 651 | memcpy(serverMsg.buffer+4, &mapPlayers[id].target.x, 4);
|
---|
| 652 | memcpy(serverMsg.buffer+8, &mapPlayers[id].target.y, 4);
|
---|
[60017fc] | 653 |
|
---|
| 654 | broadcastResponse = true;
|
---|
| 655 | }
|
---|
| 656 | else
|
---|
| 657 | cout << "Bad terrain detected" << endl;
|
---|
[b128109] | 658 | }
|
---|
| 659 | else // nned to send back a message indicating failure
|
---|
| 660 | cout << "Player id (" << id << ") doesn't match sender" << endl;
|
---|
| 661 |
|
---|
| 662 | break;
|
---|
| 663 | }
|
---|
[5299436] | 664 | case MSG_TYPE_PICKUP_FLAG:
|
---|
| 665 | {
|
---|
| 666 | // may want to check the id matches the sender, just like for PLAYER_NOVE
|
---|
| 667 | cout << "PICKUP_FLAG" << endl;
|
---|
| 668 |
|
---|
| 669 | int id;
|
---|
| 670 |
|
---|
| 671 | memcpy(&id, clientMsg.buffer, 4);
|
---|
| 672 | cout << "id: " << id << endl;
|
---|
| 673 |
|
---|
[5c84d54] | 674 | vector<WorldMap::Object>* vctObjects = gameMap->getObjects();
|
---|
| 675 | vector<WorldMap::Object>::iterator itObjects;
|
---|
| 676 |
|
---|
| 677 | for (itObjects = vctObjects->begin(); itObjects != vctObjects->end();) {
|
---|
| 678 | POSITION pos = itObjects->pos;
|
---|
| 679 | bool gotFlag = false;
|
---|
| 680 |
|
---|
| 681 | if (posDistance(mapPlayers[id].pos, pos.toFloat()) < 10) {
|
---|
| 682 | switch (itObjects->type) {
|
---|
| 683 | case WorldMap::OBJECT_BLUE_FLAG:
|
---|
| 684 | if (mapPlayers[id].team == 1) {
|
---|
| 685 | gotFlag = true;
|
---|
| 686 | mapPlayers[id].hasBlueFlag = true;
|
---|
| 687 | broadcastResponse = true;
|
---|
| 688 | }
|
---|
| 689 | break;
|
---|
| 690 | case WorldMap::OBJECT_RED_FLAG:
|
---|
| 691 | if (mapPlayers[id].team == 0) {
|
---|
| 692 | gotFlag = true;
|
---|
| 693 | mapPlayers[id].hasRedFlag = true;
|
---|
| 694 | broadcastResponse = true;
|
---|
| 695 | }
|
---|
| 696 | break;
|
---|
| 697 | }
|
---|
| 698 |
|
---|
| 699 | if (gotFlag) {
|
---|
| 700 | serverMsg.type = MSG_TYPE_REMOVE_OBJECT;
|
---|
| 701 | memcpy(serverMsg.buffer, &itObjects->id, 4);
|
---|
| 702 |
|
---|
| 703 | map<unsigned int, Player>::iterator it;
|
---|
| 704 | for (it = mapPlayers.begin(); it != mapPlayers.end(); it++)
|
---|
| 705 | {
|
---|
| 706 | if ( sendMessage(&serverMsg, sock, &(it->second.addr)) < 0 )
|
---|
| 707 | error("sendMessage");
|
---|
| 708 | }
|
---|
| 709 |
|
---|
| 710 | // remove the object from the server-side map
|
---|
| 711 | cout << "size before: " << gameMap->getObjects()->size() << endl;
|
---|
| 712 | itObjects = vctObjects->erase(itObjects);
|
---|
| 713 | cout << "size after: " << gameMap->getObjects()->size() << endl;
|
---|
| 714 | }
|
---|
| 715 | }
|
---|
| 716 |
|
---|
| 717 | if (!gotFlag)
|
---|
| 718 | itObjects++;
|
---|
| 719 | }
|
---|
| 720 |
|
---|
| 721 | serverMsg.type = MSG_TYPE_PLAYER;
|
---|
| 722 | mapPlayers[id].serialize(serverMsg.buffer);
|
---|
| 723 |
|
---|
[5299436] | 724 | break;
|
---|
| 725 | }
|
---|
[e487381] | 726 | case MSG_TYPE_DROP_FLAG:
|
---|
| 727 | {
|
---|
| 728 | // may want to check the id matches the sender, just like for PLAYER_NOVE
|
---|
| 729 | cout << "DROP_FLAG" << endl;
|
---|
| 730 |
|
---|
| 731 | int id;
|
---|
| 732 |
|
---|
| 733 | memcpy(&id, clientMsg.buffer, 4);
|
---|
| 734 | cout << "id: " << id << endl;
|
---|
| 735 |
|
---|
| 736 | WorldMap::ObjectType flagType = WorldMap::OBJECT_NONE;
|
---|
| 737 | if (mapPlayers[id].hasBlueFlag)
|
---|
| 738 | flagType = WorldMap::OBJECT_BLUE_FLAG;
|
---|
| 739 | else if (mapPlayers[id].hasRedFlag)
|
---|
| 740 | flagType = WorldMap::OBJECT_RED_FLAG;
|
---|
| 741 |
|
---|
| 742 | gameMap->addObject(flagType, mapPlayers[id].pos.x, mapPlayers[id].pos.y);
|
---|
| 743 |
|
---|
| 744 | // need to send the OBJECT message too
|
---|
| 745 | serverMsg.type = MSG_TYPE_OBJECT;
|
---|
| 746 | gameMap->getObjects()->back().serialize(serverMsg.buffer);
|
---|
| 747 |
|
---|
| 748 | map<unsigned int, Player>::iterator it;
|
---|
| 749 | for (it = mapPlayers.begin(); it != mapPlayers.end(); it++)
|
---|
| 750 | {
|
---|
| 751 | if ( sendMessage(&serverMsg, sock, &(it->second.addr)) < 0 )
|
---|
| 752 | error("sendMessage");
|
---|
| 753 | }
|
---|
| 754 |
|
---|
| 755 | mapPlayers[id].hasBlueFlag = false;
|
---|
| 756 | mapPlayers[id].hasRedFlag = false;
|
---|
| 757 |
|
---|
| 758 | serverMsg.type = MSG_TYPE_PLAYER;
|
---|
| 759 | mapPlayers[id].serialize(serverMsg.buffer);
|
---|
| 760 |
|
---|
| 761 | broadcastResponse = true;
|
---|
| 762 |
|
---|
| 763 | break;
|
---|
| 764 | }
|
---|
[4b4b153] | 765 | case MSG_TYPE_START_ATTACK:
|
---|
| 766 | {
|
---|
| 767 | cout << "Received a START_ATTACK message" << endl;
|
---|
| 768 |
|
---|
[8a4ed74] | 769 | int id, targetId;
|
---|
| 770 |
|
---|
| 771 | memcpy(&id, clientMsg.buffer, 4);
|
---|
| 772 | memcpy(&targetId, clientMsg.buffer+4, 4);
|
---|
| 773 |
|
---|
[8dad966] | 774 | Player* source = &mapPlayers[id];
|
---|
| 775 | source->timeAttackStarted = getCurrentMillis();
|
---|
| 776 | source->targetPlayer = targetId;
|
---|
| 777 |
|
---|
[4b4b153] | 778 | serverMsg.type = MSG_TYPE_START_ATTACK;
|
---|
[8dad966] | 779 | memcpy(serverMsg.buffer, &id, 4);
|
---|
| 780 | memcpy(serverMsg.buffer+4, &targetId, 4);
|
---|
[4b4b153] | 781 | broadcastResponse = true;
|
---|
[8a4ed74] | 782 |
|
---|
| 783 | break;
|
---|
[4b4b153] | 784 | }
|
---|
| 785 | case MSG_TYPE_ATTACK:
|
---|
| 786 | {
|
---|
| 787 | cout << "Received am ATTACK message" << endl;
|
---|
[8dad966] | 788 | cout << "ERROR: Clients should not send ATTACK messages" << endl;
|
---|
[8a4ed74] | 789 |
|
---|
| 790 | break;
|
---|
[4b4b153] | 791 | }
|
---|
[8e540f4] | 792 | default:
|
---|
| 793 | {
|
---|
| 794 | strcpy(serverMsg.buffer, "Server error occured. Report this please.");
|
---|
[e084950] | 795 |
|
---|
[8e540f4] | 796 | serverMsg.type = MSG_TYPE_CHAT;
|
---|
[e084950] | 797 |
|
---|
[8e540f4] | 798 | break;
|
---|
| 799 | }
|
---|
[e3535b3] | 800 | }
|
---|
[da692b9] | 801 |
|
---|
| 802 | return broadcastResponse;
|
---|
[e3535b3] | 803 | }
|
---|
[da692b9] | 804 |
|
---|
[8dad966] | 805 | void updateUnusedPlayerId(unsigned int& id, map<unsigned int, Player>& mapPlayers)
|
---|
[01d0d00] | 806 | {
|
---|
[1106210] | 807 | while (mapPlayers.find(id) != mapPlayers.end())
|
---|
| 808 | id++;
|
---|
[01d0d00] | 809 | }
|
---|
[8dad966] | 810 |
|
---|
| 811 | void updateUnusedProjectileId(unsigned int& id, map<unsigned int, Projectile>& mapProjectiles)
|
---|
| 812 | {
|
---|
| 813 | while (mapProjectiles.find(id) != mapProjectiles.end())
|
---|
| 814 | id++;
|
---|
| 815 | }
|
---|