Changeset edfd1d0 in network-game for server


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

Location:
server
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • server/DataAccess.h

    rbaaf6c8 redfd1d0  
    66#include <mysql/mysql.h>
    77
    8 #include "Player.h"
     8#include "../common/Player.h"
    99
    1010using namespace std;
  • server/makefile

    rbaaf6c8 redfd1d0  
    33FLAGS = $(LIB_FLAGS)
    44COMMON_PATH = ../common
    5 DEPENDENCIES = Message.o Player.o DataAccess.o
     5DEPENDENCIES = Common.o Message.o Player.o DataAccess.o
    66
    77server : server.cpp $(DEPENDENCIES)
    88        $(CC) -o $@ $+ $(FLAGS)
    99
     10Common.o : $(COMMON_PATH)/Common.cpp
     11        $(CC) -c -o $@ $?
     12
    1013Message.o : $(COMMON_PATH)/Message.cpp
     14        $(CC) -c -o $@ $?
     15
     16Player.o : $(COMMON_PATH)/Player.cpp
    1117        $(CC) -c -o $@ $?
    1218
  • 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.