Changeset 99afbb8 in network-game for server


Ignore:
Timestamp:
Sep 26, 2013, 2:59:02 AM (11 years ago)
Author:
dportnoy <dmp1488@…>
Branches:
master
Children:
2ee386d
Parents:
50e6c7a
Message:

The server keeps track of games and adds players to them

File:
1 edited

Legend:

Unmodified
Added
Removed
  • server/server.cpp

    r50e6c7a r99afbb8  
    3535#include "../common/Player.h"
    3636#include "../common/Projectile.h"
     37#include "../common/Game.h"
    3738
    3839#include "DataAccess.h"
     
    4445// from used to be const. Removed that so I could take a reference
    4546// and use it to send messages
    46 bool processMessage(const NETWORK_MSG &clientMsg, struct sockaddr_in &from, MessageProcessor &msgProcessor, map<unsigned int, Player>& mapPlayers, WorldMap* gameMap, unsigned int& unusedPlayerId, NETWORK_MSG &serverMsg, int sock, int &scoreBlue, int &scoreRed, ofstream& outputLog);
     47bool processMessage(const NETWORK_MSG &clientMsg, struct sockaddr_in &from, MessageProcessor &msgProcessor, map<unsigned int, Player>& mapPlayers, map<string, Game>& mapGames, WorldMap* gameMap, unsigned int& unusedPlayerId, NETWORK_MSG &serverMsg, int sock, int &scoreBlue, int &scoreRed, ofstream& outputLog);
    4748
    4849void updateUnusedPlayerId(unsigned int& id, map<unsigned int, Player>& mapPlayers);
     
    99100   map<unsigned int, Player> mapPlayers;
    100101   map<unsigned int, Projectile> mapProjectiles;
     102   map<string, Game> mapGames;
    101103   unsigned int unusedPlayerId = 1, unusedProjectileId = 1;
    102104   int scoreBlue, scoreRed;
     
    530532
    531533      if (n >= 0) {
    532          broadcastResponse = processMessage(clientMsg, from, msgProcessor, mapPlayers, gameMap, unusedPlayerId, serverMsg, sock, scoreBlue, scoreRed, outputLog);
     534         broadcastResponse = processMessage(clientMsg, from, msgProcessor, mapPlayers, mapGames, gameMap, unusedPlayerId, serverMsg, sock, scoreBlue, scoreRed, outputLog);
    533535
    534536         if (broadcastResponse)
     
    560562}
    561563
    562 bool processMessage(const NETWORK_MSG &clientMsg, struct sockaddr_in &from, MessageProcessor &msgProcessor, map<unsigned int, Player>& mapPlayers, WorldMap* gameMap, unsigned int& unusedPlayerId, NETWORK_MSG &serverMsg, int sock, int &scoreBlue, int &scoreRed, ofstream& outputLog)
     564bool processMessage(const NETWORK_MSG &clientMsg, struct sockaddr_in &from, MessageProcessor &msgProcessor, map<unsigned int, Player>& mapPlayers, map<string, Game>& mapGames, WorldMap* gameMap, unsigned int& unusedPlayerId, NETWORK_MSG &serverMsg, int sock, int &scoreBlue, int &scoreRed, ofstream& outputLog)
    563565{
    564566   DataAccess da;
     
    933935         cout << "Game name: " << gameName << endl;
    934936
    935          // temp var
    936          int numPlayers = 0;
     937         mapGames[gameName] = Game(gameName);
     938         mapGames[gameName].addPlayer(findPlayerByAddr(mapPlayers, from));
     939         int numPlayers = mapGames[gameName].getNumPlayers();
    937940
    938941         serverMsg.type = MSG_TYPE_GAME_INFO;
     
    950953         cout << "Game name: " << gameName << endl;
    951954
    952          // temp var
    953          int numPlayers = 0;
     955         mapGames[gameName].addPlayer(findPlayerByAddr(mapPlayers, from));
     956         int numPlayers = mapGames[gameName].getNumPlayers();
    954957
    955958         serverMsg.type = MSG_TYPE_GAME_INFO;
Note: See TracChangeset for help on using the changeset viewer.