Changeset 0129700 in network-game


Ignore:
Timestamp:
Dec 19, 2013, 3:31:45 AM (11 years ago)
Author:
dportnoy <dmp1488@…>
Branches:
master
Children:
fef7c69
Parents:
70fc3e8
Message:

The Game class validates player movement on the server side

Files:
3 edited

Legend:

Unmodified
Added
Removed
  • common/Game.cpp

    r70fc3e8 r0129700  
    6767}
    6868
     69bool Game::startPlayerMovement(unsigned int id, int x, int y) {
     70   // need to check if players actually contains the id
     71   Player* p = players[id];
     72
     73   // we need to make sure the player can move here
     74   if (0 <= x && x < this->worldMap->width*25 &&
     75       0 <= y && y < this->worldMap->height*25 &&
     76       this->worldMap->getElement(x/25, y/25) == WorldMap::TERRAIN_GRASS)
     77   {
     78      p->target.x = x;
     79      p->target.y = y;
     80
     81      p->isChasing = false;
     82      p->isAttacking = false;
     83
     84      return true;
     85   }
     86   else
     87      return false;
     88}
     89
    6990void Game::setRedScore(int score) {
    7091   this->redScore = score;
  • common/Game.h

    r70fc3e8 r0129700  
    4141   bool addPlayer(Player* p);
    4242   bool removePlayer(unsigned int id);
     43   bool startPlayerMovement(unsigned int id, int x, int y);
    4344   void setBlueScore(int score);
    4445   void setRedScore(int score);
  • server/server.cpp

    r70fc3e8 r0129700  
    818818              p->addr.sin_port == from.sin_port )
    819819         {
    820             // we need to make sure the player can move here
    821             if (0 <= x && x < gameMap->width*25 && 0 <= y && y < gameMap->height*25 &&
    822                gameMap->getElement(x/25, y/25) == WorldMap::TERRAIN_GRASS)
    823             {
    824                cout << "valid terrain" << endl;
    825 
    826                p->target.x = x;
    827                p->target.y = y;
    828 
    829                p->isChasing = false;
    830                p->isAttacking = false;
    831 
     820            if (p->currentGame->startPlayerMovement(id, x, y)) {
    832821               serverMsg.type = MSG_TYPE_PLAYER_MOVE;
    833822               
Note: See TracChangeset for help on using the changeset viewer.