Changeset edfd1d0 in network-game for server/server.cpp


Ignore:
Timestamp:
Dec 25, 2012, 6:27:14 PM (12 years ago)
Author:
dportnoy <dmp1488@…>
Branches:
master
Children:
4c202e0
Parents:
baaf6c8
Message:

Moved the Player class to the common directory, added a position to Player, added a new message type for sending player info, and made the server broadcast player positions everytime it receives and replies to a message

File:
1 edited

Legend:

Unmodified
Added
Removed
  • server/server.cpp

    rbaaf6c8 redfd1d0  
    77#include <vector>
    88#include <algorithm>
    9 
    10 #include <fcntl.h>
    11 #include <assert.h>
     9#include <cstring>
    1210
    1311#include <sys/socket.h>
     
    1614#include <arpa/inet.h>
    1715
     16/*
    1817#include <openssl/bio.h>
    1918#include <openssl/ssl.h>
    2019#include <openssl/err.h>
     20*/
    2121
    2222#include "../common/Compiler.h"
     23#include "../common/Common.h"
    2324#include "../common/Message.h"
    24 #include "../common/Common.h"
    25 
    26 #include "Player.h"
     25#include "../common/Player.h"
     26
    2727#include "DataAccess.h"
    2828
     
    6363
    6464   return NULL;
     65}
     66
     67void broadcastPlayerPositions(vector<Player> &vec, int sock)
     68{
     69   vector<Player>::iterator it, it2;
     70   NETWORK_MSG serverMsg;
     71
     72   serverMsg.type = MSG_TYPE_PLAYER;   
     73
     74   for (it = vec.begin(); it != vec.end(); it++)
     75   {
     76      strncpy(serverMsg.buffer, (char*)&*it, sizeof(Player));
     77
     78      for (it2 = vec.begin(); it2 != vec.end(); it2++)
     79      {
     80         if ( sendMessage(&serverMsg, sock, &(it2->addr)) < 0 )
     81            error("sendMessage");
     82      }
     83   }
    6584}
    6685
     
    7392   vector<Player> vctPlayers;
    7493
    75    SSL_load_error_strings();
    76    ERR_load_BIO_strings();
    77    OpenSSL_add_all_algorithms();
     94   //SSL_load_error_strings();
     95   //ERR_load_BIO_strings();
     96   //OpenSSL_add_all_algorithms();
    7897
    7998   if (argc < 2) {
     
    127146               error("sendMessage");
    128147         }
    129       }
    130 
     148
     149         broadcastPlayerPositions(vctPlayers, sock);
     150      }
    131151   }
    132152
Note: See TracChangeset for help on using the changeset viewer.