Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Dec 31, 2007, 7:40:23 PM (16 years ago)
Author:
rgrieder
Message:
  • added dll support to the network library
  • improved header file dependency in network
File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/FICN/src/network/Server.cc

    r660 r777  
    1111//
    1212
     13#include <iostream>
    1314
     15#include "ConnectionManager.h"
     16#include "PacketTypes.h"
     17#include "GameStateManager.h"
     18#include "ClientInformation.h"
     19//#include "NetworkFrameListener.h"
    1420#include "Server.h"
    1521
    16 namespace network{
    1722
     23namespace network
     24{
    1825  /**
    19    * Constructor for default values (bindaddress is set to ENET_HOST_ANY
    20    *
    21    */
    22   Server::Server(){
     26  * Constructor for default values (bindaddress is set to ENET_HOST_ANY
     27  *
     28  */
     29  Server::Server() {
    2330    packet_gen = PacketGenerator();
    2431    clients = new ClientInformation(true);
     
    2835
    2936  /**
    30    * Constructor
    31    * @param port Port to listen on
    32    * @param bindAddress Address to listen on
    33    */
    34   Server::Server(int port, std::string bindAddress){
     37  * Constructor
     38  * @param port Port to listen on
     39  * @param bindAddress Address to listen on
     40  */
     41  Server::Server(int port, std::string bindAddress) {
    3542    packet_gen = PacketGenerator();
    3643    clients = new ClientInformation();
     
    4047
    4148  /**
    42    * Constructor
    43    * @param port Port to listen on
    44    * @param bindAddress Address to listen on
    45    */
    46   Server::Server(int port, const char *bindAddress){
     49  * Constructor
     50  * @param port Port to listen on
     51  * @param bindAddress Address to listen on
     52  */
     53  Server::Server(int port, const char *bindAddress) {
    4754    packet_gen = PacketGenerator();
    4855    clients = new ClientInformation();
     
    5259
    5360  /**
    54    * This function opens the server by creating the listener thread
    55    */
    56   void Server::open(){
     61  * This function opens the server by creating the listener thread
     62  */
     63  void Server::open() {
    5764    connection->createListener();
    5865    return;
     
    6067
    6168  /**
    62    * This function closes the server
    63    */
    64   void Server::close(){
     69  * This function closes the server
     70  */
     71  void Server::close() {
    6572    connection->quitListener();
    6673    return;
     
    6875
    6976  /**
    70    * This function sends out a message to all clients
    71    * @param msg message
    72    * @return true/false
    73    */
    74   bool Server::sendMSG(std::string msg){
     77  * This function sends out a message to all clients
     78  * @param msg message
     79  * @return true/false
     80  */
     81  bool Server::sendMSG(std::string msg) {
    7582    ENetPacket *packet = packet_gen.chatMessage(msg.c_str());
    7683    //std::cout <<"adding packets" << std::endl;
     
    7986    return connection->sendPackets();
    8087  }
     88
    8189  /**
    82    * This function sends out a message to all clients
    83    * @param msg message
    84    * @return true/false
    85    */
    86   bool Server::sendMSG(const char *msg){
     90  * This function sends out a message to all clients
     91  * @param msg message
     92  * @return true/false
     93  */
     94  bool Server::sendMSG(const char *msg) {
    8795    ENetPacket *packet = packet_gen.chatMessage(msg);
    8896    std::cout <<"adding Packets" << std::endl;
     
    9098    //std::cout <<"added packets" << std::endl;
    9199    if (connection->sendPackets()){
    92         std::cout << "Sucessfully" << std::endl;
    93         return true;
     100      std::cout << "Sucessfully" << std::endl;
     101      return true;
    94102    }
    95103    return false;
     
    97105
    98106  /**
    99    * Run this function once every tick
    100    * calls processQueue and updateGamestate
    101    * @param time time since last tick
    102    */
    103   void Server::tick(float time){
     107  * Run this function once every tick
     108  * calls processQueue and updateGamestate
     109  * @param time time since last tick
     110  */
     111  void Server::tick(float time) {
    104112    processQueue();
    105113    updateGamestate();
     
    108116
    109117  /**
    110    * processes all the packets waiting in the queue
    111    */
    112   void Server::processQueue(){
     118  * processes all the packets waiting in the queue
     119  */
     120  void Server::processQueue() {
    113121    ENetPacket *packet;
    114122    int clientID=-1;
     
    121129
    122130  /**
    123    * takes a new snapshot of the gamestate and sends it to the clients
    124    */
    125   void Server::updateGamestate(){
     131  * takes a new snapshot of the gamestate and sends it to the clients
     132  */
     133  void Server::updateGamestate() {
    126134    gamestates->update();
    127135    //std::cout << "updated gamestate, sending it" << std::endl;
     
    131139
    132140  /**
    133    * sends the gamestate
    134    */
    135   bool Server::sendGameState(){
     141  * sends the gamestate
     142  */
     143  bool Server::sendGameState() {
    136144    std::cout << "starting gamestate" << std::endl;
    137145    ClientInformation *temp = clients;
     
    160168    if(added)
    161169      return connection->sendPackets();
    162     else return false;
    163     //return true;
     170    else
     171      return false;
    164172  }
    165173
    166   void Server::processAck( ack *data, int clientID){
     174  void Server::processAck( ack *data, int clientID) {
    167175    clients->findClient(clientID)->setGamestateID(data->a);
    168176  }
Note: See TracChangeset for help on using the changeset viewer.