Changeset 64a1f4e in network-game for server


Ignore:
Timestamp:
Jan 29, 2014, 2:06:36 AM (11 years ago)
Author:
dportnoy <dmp1488@…>
Branches:
master
Children:
8826eed
Parents:
d6b5f74
Message:

Game.addPlayer reset all the player's stats as well

File:
1 edited

Legend:

Unmodified
Added
Removed
  • server/server.cpp

    rd6b5f74 r64a1f4e  
    77#include <fstream>
    88#include <cstring>
    9 #include <cmath>
    109
    1110#include <vector>
     
    336335            cout << "new player id: " << p->getId() << endl;
    337336            p->setAddr(from);
    338             p->currentGame = NULL;
    339 
    340             // choose a random team (either 0 or 1)
    341             p->team = rand() % 2;
    342337
    343338            serverMsg.type = MSG_TYPE_PLAYER;
     
    696691
    697692         Player* p = findPlayerByAddr(mapPlayers, from);
    698          p->team = rand() % 2; // choose a random team (either 0 or 1)
    699          p->currentGame = g;
    700693
    701694         // tell the new player about all map objects
     
    723716         msgProcessor.sendMessage(&serverMsg, &from);
    724717
     718
     719         map<unsigned int, Player*>& oldPlayers = g->getPlayers();
     720         g->addPlayer(p);
     721
    725722         // send info to other players
    726723         serverMsg.type = MSG_TYPE_PLAYER_JOIN_GAME;
    727724         p->serialize(serverMsg.buffer);
    728725         cout << "Should be broadcasting the message" << endl;
    729          msgProcessor.broadcastMessage(serverMsg, g->getPlayers());
    730 
    731          g->addPlayer(p);
     726         msgProcessor.broadcastMessage(serverMsg, oldPlayers);
    732727
    733728
     
    735730         cout << "Sending other players to new player" << endl;
    736731         serverMsg.type = MSG_TYPE_PLAYER_JOIN_GAME;
    737 
    738732         
    739733         map<unsigned int, Player*>& allPlayers = g->getPlayers();
     
    747741            msgProcessor.sendMessage(&serverMsg, &from);
    748742         }
     743
    749744
    750745         int numPlayers = g->getNumPlayers();
Note: See TracChangeset for help on using the changeset viewer.