Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jul 28, 2010, 8:29:32 PM (14 years ago)
Author:
scheusso
Message:

some new features:
-Orxonox servers announce themselves now inside a LAN (and can provide some information (e.g. server name, etc.) to the client )
-Orxonox clients discover the servers inside the LAN and list them in the menu

Location:
code/branches/presentation3
Files:
6 added
22 edited

Legend:

Unmodified
Added
Removed
  • code/branches/presentation3/data/gui/layouts/MultiplayerMenu.layout

    r6746 r7161  
    1616            <Property Name="VertFormatting" Value="TopAligned" />
    1717            <Property Name="UnifiedAreaRect" Value="{{0.25,0},{0.2875,0},{0.75,0},{0.6375,0}}" />
    18             <Window Type="MenuWidgets/Listbox" Name="orxonox/MultiplayerLevelListbox" >
     18            <Window Type="MenuWidgets/Listbox" Name="orxonox/MultiplayerListbox" >
    1919                <Property Name="UnifiedMaxSize" Value="{{1,0},{1,0}}" />
    2020                <Property Name="UnifiedAreaRect" Value="{{0.05,0},{0.15,0},{0.95,0},{0.8,0}}" />
  • code/branches/presentation3/data/gui/scripts/MultiplayerMenu.lua

    r6746 r7161  
    44
    55function P.onLoad()
    6     listbox = winMgr:getWindow("orxonox/MultiplayerLevelListbox")
    7     preselect = orxonox.LevelManager:getInstance():getDefaultLevel()
     6    P.multiplayerMode = "startClient"
     7end
     8
     9function P.onShow()
     10    if P.multiplayerMode == "startClient" then
     11        local window = winMgr:getWindow("orxonox/MultiplayerJoinButton")
     12        local button = tolua.cast(window,"CEGUI::RadioButton")
     13        button:setSelected(true)
     14        P.showServerList()
     15    end
     16    if P.multiplayerMode == "startServer" then
     17        local window = winMgr:getWindow("orxonox/MultiplayerHostButton")
     18        local button = tolua.cast(window,"CEGUI::RadioButton")
     19        button:setSelected(true)
     20        P.showLevelList()
     21    end
     22    if P.multiplayerMode == "startDedicated" then
     23        local window = winMgr:getWindow("orxonox/MultiplayerDedicatedButton")
     24        local button = tolua.cast(window,"CEGUI::RadioButton")
     25        button:setSelected(true)
     26        P.showLevelList()
     27    end
     28end
     29
     30function P.MultiplayerJoinButton_clicked(e)
     31    P.multiplayerMode = "startClient"
     32    P.showServerList()
     33end
     34
     35function P.MultiplayerHostButton_clicked(e)
     36    P.multiplayerMode = "startServer"
     37    P.showLevelList()
     38end
     39
     40function P.MultiplayerDedicatedButton_clicked(e)
     41    P.multiplayerMode = "startDedicated"
     42    P.showLevelList()
     43end
     44
     45function P.MultiplayerStartButton_clicked(e)
     46    local choice = winMgr:getWindow("orxonox/MultiplayerListbox"):getFirstSelectedItem()
     47    if P.multiplayerMode == "startClient" then
     48        if choice then
     49            local client = orxonox.Client:getInstance()
     50            local index = tolua.cast(choice, "CEGUI::ListboxItem"):getID()
     51            client:setDestination( P.serverList[index][2], 55556 )
     52        else
     53            return
     54        end
     55    else
     56        if choice then
     57            orxonox.LevelManager:getInstance():setDefaultLevel(choice:getText() .. ".oxw")
     58        else
     59            return
     60        end
     61    end
     62    orxonox.execute(P.multiplayerMode)
     63    hideAllMenuSheets()
     64end
     65
     66function P.MultiplayerBackButton_clicked(e)
     67    hideMenuSheet(P.name)
     68end
     69
     70function P.showLevelList()
     71    local listbox = winMgr:getWindow("orxonox/MultiplayerListbox")
     72    CEGUI.toListbox(listbox):resetList()
     73    local preselect = orxonox.LevelManager:getInstance():getDefaultLevel()
    874    orxonox.LevelManager:getInstance():compileAvailableLevelList()
    975    local levelList = {}
     
    1985    end
    2086    table.sort(levelList)
     87    index = 1
    2188    for k,v in pairs(levelList) do
    22         item = CEGUI.createListboxTextItem(v)
     89        local item = CEGUI.createListboxTextItem(v)
    2390        item:setSelectionBrushImage(menuImageSet, "MultiListSelectionBrush")
     91        item:setID(index)
     92        index = index + 1
    2493        CEGUI.toListbox(listbox):addItem(item)
    2594        if v .. ".oxw" == preselect then
     
    2796        end
    2897    end
    29     local multiplayerMode = "startClient"
    30     if multiplayerMode == "startClient" then
    31         window = winMgr:getWindow("orxonox/MultiplayerJoinButton")
    32         button = tolua.cast(window,"CEGUI::RadioButton")
    33         button:setSelected(true)
    3498    end
    35     if multiplayerMode == "startServer" then
    36         window = winMgr:getWindow("orxonox/MultiplayerHostButton")
    37         button = tolua.cast(window,"CEGUI::RadioButton")
    38         button:setSelected(true)
     99   
     100function P.showServerList()
     101    local listbox = winMgr:getWindow("orxonox/MultiplayerListbox")
     102    CEGUI.toListbox(listbox):resetList()
     103    local discovery = orxonox.LANDiscovery:getInstance()
     104    discovery:discover()
     105    P.serverList = {}
     106    local index = 0
     107    local servername = ""
     108    local serverip = ""
     109    while true do
     110        servername = discovery:getServerListItemName(index)
     111        if servername == "" then
     112            break
     113        end
     114        serverip = discovery:getServerListItemIP(index)
     115        if serverip == "" then
     116          break
     117        end
     118        table.insert(P.serverList, {servername, serverip})
     119        index = index + 1
    39120    end
    40     if multiplayerMode == "startDedicated" then
    41         window = winMgr:getWindow("orxonox/MultiplayerDedicatedButton")
    42         button = tolua.cast(window,"CEGUI::RadioButton")
    43         button:setSelected(true)
     121    index = 1
     122    for k,v in pairs(P.serverList) do
     123        local item = CEGUI.createListboxTextItem( v[1] .. ": " .. v[2] )
     124        item:setID(index)
     125        index = index + 1
     126        item:setSelectionBrushImage(menuImageSet, "MultiListSelectionBrush")
     127        CEGUI.toListbox(listbox):addItem(item)
    44128    end
    45 end
    46 
    47 function P.MultiplayerJoinButton_clicked(e)
    48     multiplayerMode = "startClient"
    49 end
    50 
    51 function P.MultiplayerHostButton_clicked(e)
    52     multiplayerMode = "startServer"
    53 end
    54 
    55 function P.MultiplayerDedicatedButton_clicked(e)
    56     multiplayerMode = "startDedicated"
    57 end
    58 
    59 function P.MultiplayerStartButton_clicked(e)
    60     local choice = winMgr:getWindow("orxonox/MultiplayerLevelListbox"):getFirstSelectedItem()
    61     if choice then
    62         orxonox.LevelManager:getInstance():setDefaultLevel(choice:getText() .. ".oxw")
    63         orxonox.execute(multiplayerMode)
    64         hideAllMenuSheets()
    65     end
    66 end
    67 
    68 function P.MultiplayerBackButton_clicked(e)
    69     hideMenuSheet(P.name)
    70129end
    71130
  • code/branches/presentation3/src/libraries/network/CMakeLists.txt

    r7135 r7161  
    2929  GamestateClient.cc
    3030  GamestateHandler.cc
     31  LANDiscoverable.cc
     32  LANDiscovery.cc
    3133  NetworkFunction.cc
    3234  Host.cc
     
    4850  GamestateManager.h
    4951  Host.h
     52  LANDiscoverable.h
     53  LANDiscovery.h
    5054  NetworkFunction.h
    5155  NetworkPrecompiledHeaders.h
     
    6064
    6165ORXONOX_ADD_LIBRARY(network
     66  TOLUA_FILES
     67    Client.h
     68    LANDiscovery.h
    6269  PCH_FILE
    6370    NetworkPrecompiledHeaders.h
  • code/branches/presentation3/src/libraries/network/Client.cc

    r6417 r7161  
    5050#include "FunctionCallManager.h"
    5151#include "core/CoreIncludes.h"
     52#include "core/CommandLineParser.h"
    5253#include "core/Game.h"
     54#include "core/ScopedSingletonManager.h"
    5355
    5456namespace orxonox
    5557{
    5658
     59  ManageScopedSingleton( Client, ScopeID::Root, true );
    5760
    5861  /**
     
    6164  */
    6265  Client::Client():
     66      gamestate(0),
    6367      isSynched_(false),
    6468      gameStateFailure_(false),
    6569      timeSinceLastUpdate_(0)
    6670  {
    67   }
    68 
    69   /**
    70   * Constructor for the Client class
    71   * @param address the server address
    72   * @param port port of the application on the server
    73   */
    74   Client::Client(const std::string& address, int port):
    75       isSynched_(false),
    76       gameStateFailure_(false),
    77       timeSinceLastUpdate_(0)
    78   {
    79       setPort( port );
    80       setServerAddress( address );
    81   }
    82 
    83   Client::~Client(){
     71    this->setDestination( CommandLineParser::getValue("dest").getString(), CommandLineParser::getValue("port") );
     72  }
     73
     74  Client::~Client()
     75  {
    8476    if ( ClientConnection::isConnected() )
    8577      closeConnection();
     
    9082  * @return true/false
    9183  */
    92   bool Client::establishConnection(){
     84  bool Client::establishConnection()
     85  {
    9386    Synchronisable::setClient(true);
    94     return ClientConnection::establishConnection();
     87    this->gamestate = new GamestateClient();
     88    if( ClientConnection::establishConnection() )
     89    {
     90      Host::setActive(true);
     91      return true;
     92    }
     93    else
     94      return false;
    9595  }
    9696
     
    9999  * @return true/false
    100100  */
    101   bool Client::closeConnection(){
     101  bool Client::closeConnection()
     102  {
     103    assert(this->gamestate);
     104    delete this->gamestate;
     105    this->gamestate = 0;
     106    Host::setActive(false);
    102107    return ClientConnection::closeConnection();
    103108  }
    104 
    105   bool Client::queuePacket(ENetPacket *packet, int clientID){
     109 
     110  void Client::setDestination(const std::string& serverAddress, unsigned int port)
     111  {
     112    ClientConnection::setServerAddress(serverAddress);
     113    ClientConnection::setPort(port);
     114  }
     115
     116  bool Client::queuePacket(ENetPacket *packet, int clientID)
     117  {
    106118    bool b = ClientConnection::addPacket(packet);
    107119    assert(b);
     
    109121  }
    110122
    111   bool Client::processChat(const std::string& message, unsigned int playerID){
     123  bool Client::processChat(const std::string& message, unsigned int playerID)
     124  {
    112125//    COUT(1) << "Player " << playerID << ": " << message << std::endl;
    113126    return true;
    114127  }
    115128
    116   void Client::printRTT(){
     129  void Client::printRTT()
     130  {
    117131    COUT(0) << "Round trip time to server is " << ClientConnection::getRTT() << " ms" << endl;
    118132  }
     
    123137   * @return result(true/false)
    124138   */
    125   bool Client::chat(const std::string& message){
     139  bool Client::chat(const std::string& message)
     140  {
    126141    packet::Chat *m = new packet::Chat(message, Host::getPlayerID());
    127142    return m->send();
     
    133148   * @param time
    134149   */
    135   void Client::update(const Clock& time){
     150  void Client::update(const Clock& time)
     151  {
    136152    //this steers our network frequency
    137153    timeSinceLastUpdate_+=time.getDeltaTime();
     
    143159      {
    144160        COUT(4) << "popping partial gamestate: " << std::endl;
    145         packet::Gamestate *gs = gamestate.getGamestate();
     161        packet::Gamestate *gs = gamestate->getGamestate();
    146162        //assert(gs); <--- there might be the case that no data has to be sent, so its commented out now
    147163        if(gs){
     
    157173
    158174    Connection::processQueue();
    159     if(gamestate.processGamestates())
     175    if(gamestate->processGamestates())
    160176    {
    161177      if(!isSynched_)
    162178        isSynched_=true;
    163179    }
    164     gamestate.cleanup();
     180    gamestate->cleanup();
    165181    Connection::sendPackets();
    166182
     
    184200  }
    185201
     202
     203
    186204}
  • code/branches/presentation3/src/libraries/network/Client.h

    r5961 r7161  
    4747
    4848#include "util/UtilPrereqs.h"
     49#include "util/Singleton.h"
    4950#include "ClientConnection.h"
    5051#include "GamestateClient.h"
    5152#include "Host.h"
     53#include "LANDiscovery.h"
     54#include "packet/ServerInformation.h"
    5255
     56// tolua_begin
    5357namespace orxonox
    5458{
     59// tolua_end
    5560  /**
    5661  Client *client;
     
    6065  *
    6166  */
    62   class _NetworkExport Client : public Host, public ClientConnection{
     67  class _NetworkExport Client // tolua_export
     68    : public Host, protected ClientConnection, public Singleton<Client>
     69  { // tolua_export
     70  friend class Singleton<Client>;
    6371  public:
    6472    Client();
    65     Client(const std::string& address, int port);
    6673    ~Client();
     74   
     75    static Client* getInstance(){ return singletonPtr_s; } // tolua_export
    6776
    6877    bool establishConnection();
     78    void setDestination( const std::string& serverAddress, unsigned int port ); // tolua_export
    6979    bool closeConnection();
    7080    bool queuePacket(ENetPacket *packet, int clientID);
     
    8191    virtual bool isServer_(){return false;}
    8292
    83     GamestateClient gamestate;
     93    static Client* singletonPtr_s;
     94    GamestateClient* gamestate;
    8495    bool isSynched_;
    8596
    8697    bool gameStateFailure_;
    8798    float timeSinceLastUpdate_;
    88   };
     99  }; // tolua_export
    89100
    90101
    91 }
     102} // tolua_export
    92103
    93104#endif /* _Client_H__ */
  • code/branches/presentation3/src/libraries/network/Connection.cc

    r6417 r7161  
    3636namespace orxonox
    3737{
    38   Connection *Connection::instance_=0;
     38//   Connection *Connection::instance_=0;
    3939
    4040  Connection::Connection():
    4141    host_(0)
    4242  {
    43     assert(instance_==0);
    44     Connection::instance_=this;
     43//     assert(instance_==0);
     44//     Connection::instance_=this;
    4545    enet_initialize();
    4646    atexit(enet_deinitialize);
     
    4848
    4949  Connection::~Connection(){
    50     Connection::instance_=0;
     50//     Connection::instance_=0;
    5151  }
    5252
     
    6767
    6868  bool Connection::sendPackets() {
    69     if ( !Connection::instance_ || this->host_==NULL )
     69    if ( /*!Connection::instance_ || */this->host_==NULL )
    7070      return false;
    7171    enet_host_flush(this->host_);
  • code/branches/presentation3/src/libraries/network/Connection.h

    r6417 r7161  
    6161  protected:
    6262    Connection();
    63     static Connection* getInstance(){ return Connection::instance_; }
     63//     static Connection* getInstance(){ return Connection::instance_; }
    6464
    6565    int service(ENetEvent* event);
     
    7575    ENetAddress *bindAddress_;
    7676
    77     static Connection *instance_;
     77//     static Connection *instance_;
    7878
    7979  };
  • code/branches/presentation3/src/libraries/network/Host.cc

    r5961 r7161  
    3838namespace orxonox {
    3939
    40 SetConsoleCommandShortcut(Host, Chat);
     40  SetConsoleCommandShortcut(Host, Chat);
    4141
    42 Host *Host::instance_=0;
     42  // Host*               Host::instance_=0;
     43  uint32_t            Host::clientID_s=0;
     44  uint32_t            Host::shipID_s=-1;
     45  std::vector<Host*>  Host::instances_s;
    4346
    44 /**
    45  * @brief Constructor: assures that only one reference will be created and sets the pointer
    46  */
    47 Host::Host()
    48 {
    49   clientID_=0;
    50   assert(instance_==0);
    51   instance_=this;
    52   this->printRTTCC_ = createConsoleCommand( createFunctor(&Host::printRTT, this), "printRTT" );
    53   CommandExecutor::addConsoleCommandShortcut( this->printRTTCC_ );
    54 }
     47  /**
     48  * @brief Constructor: assures that only one reference will be created and sets the pointer
     49  */
     50  Host::Host()
     51  {
     52  //   assert(instance_==0);
     53    instances_s.push_back(this);
     54    this->printRTTCC_ = createConsoleCommand( createFunctor(&Host::printRTT, this), "printRTT" );
     55    CommandExecutor::addConsoleCommandShortcut( this->printRTTCC_ );
     56    this->bIsActive_ = false;
     57  }
    5558
    5659
    57 /**
    58  * @brief Destructor: resets the instance pointer to 0
    59  */
    60 Host::~Host()
    61 {
    62   instance_=0;
    63   if( this->printRTTCC_ )
    64     delete this->printRTTCC_;
    65 }
     60  /**
     61  * @brief Destructor: resets the instance pointer to 0
     62  */
     63  Host::~Host()
     64  {
     65    assert( std::find( instances_s.begin(), instances_s.end(), this )!=instances_s.end() );
     66    instances_s.erase(std::find( instances_s.begin(), instances_s.end(), this ));
     67    if( this->printRTTCC_ )
     68      delete this->printRTTCC_;
     69  }
    6670
    67 /**
    68  * This function is used to add an enetpacket to be sent to another peer
    69  * @param packet Packet to be added
    70  * @param clientID ID of the client the packet should be sent to
    71  * @return success?
    72  */
    73 bool Host::addPacket(ENetPacket *packet, int clientID){
    74   if(instance_)
    75     return instance_->queuePacket(packet, clientID);
    76   else
    77     return false;
    78 }
     71  /**
     72  * This function is used to add an enetpacket to be sent to another peer
     73  * @param packet Packet to be added
     74  * @param clientID ID of the client the packet should be sent to
     75  * @return success?
     76  */
     77  bool Host::addPacket(ENetPacket *packet, int clientID)
     78  {
     79    bool result = true;
     80    for( std::vector<Host*>::iterator it = instances_s.begin(); it!=instances_s.end(); ++it )
     81    {
     82      if( (*it)->isActive() )
     83      {
     84        if( !(*it)->queuePacket(packet, clientID) )
     85          result = false;
     86      }
     87    }
     88    return result;
     89  }
    7990
    80 /**
    81  * This function returns the ID of the player
    82  * @return playerID
    83  */
    84 unsigned int Host::getPlayerID(){
    85   if(!instance_)
    86     return 0;
    87   return instance_->clientID_;
    88 }
     91  bool Host::Chat(const std::string& message)
     92  {
     93    if(instances_s.size()==0)
     94    {
     95      for (ObjectList<ChatListener>::iterator it = ObjectList<ChatListener>::begin(); it != ObjectList<ChatListener>::end(); ++it)
     96        it->incomingChat(message, 0);
     97      return true;
     98    }
     99    else
     100    {
     101      bool result = true;
     102      for( std::vector<Host*>::iterator it = instances_s.begin(); it!=instances_s.end(); ++it )
     103      {
     104        if( (*it)->isActive() )
     105        {
     106          if( !(*it)->chat(message) )
     107            result = false;
     108        }
     109      }
     110      return result;
     111    }
     112  }
    89113
    90 bool Host::Chat(const std::string& message){
    91   if(!instance_)
     114  bool Host::Broadcast(const std::string& message)
     115  {
     116    if(instances_s.size()==0)
     117    {
     118      for (ObjectList<ChatListener>::iterator it = ObjectList<ChatListener>::begin(); it != ObjectList<ChatListener>::end(); ++it)
     119        it->incomingChat(message, CLIENTID_UNKNOWN);
     120      return true;
     121    }
     122    else
     123    {
     124      bool result = true;
     125      for( std::vector<Host*>::iterator it = instances_s.begin(); it!=instances_s.end(); ++it )
     126      {
     127        if( (*it)->isActive() )
     128        {
     129          if( !(*it)->broadcast(message) )
     130            result = false;
     131        }
     132      }
     133      return result;
     134    }
     135  }
     136
     137  bool Host::incomingChat(const std::string& message, unsigned int playerID)
    92138  {
    93139    for (ObjectList<ChatListener>::iterator it = ObjectList<ChatListener>::begin(); it != ObjectList<ChatListener>::end(); ++it)
    94       it->incomingChat(message, 0);
    95     return true;
     140      it->incomingChat(message, playerID);
     141   
     142    bool result = true;
     143    for( std::vector<Host*>::iterator it = instances_s.begin(); it!=instances_s.end(); ++it )
     144    {
     145      if( (*it)->isActive() )
     146      {
     147        if( !(*it)->processChat(message, playerID) )
     148          result = false;
     149      }
     150    }
     151    return result;
    96152  }
    97   return instance_->chat(message);
    98 }
    99153
    100 bool Host::Broadcast(const std::string& message){
    101   if(!instance_)
     154  bool Host::isServer()
    102155  {
    103     for (ObjectList<ChatListener>::iterator it = ObjectList<ChatListener>::begin(); it != ObjectList<ChatListener>::end(); ++it)
    104       it->incomingChat(message, CLIENTID_UNKNOWN);
    105     return true;
     156    for (std::vector<Host*>::iterator it=instances_s.begin(); it!=instances_s.end(); ++it )
     157    {
     158      if( (*it)->isServer_() )
     159        return true;
     160    }
     161    return false;
    106162  }
    107   else
    108     return instance_->broadcast(message);
    109 }
    110 
    111 bool Host::incomingChat(const std::string& message, unsigned int playerID){
    112   for (ObjectList<ChatListener>::iterator it = ObjectList<ChatListener>::begin(); it != ObjectList<ChatListener>::end(); ++it)
    113     it->incomingChat(message, playerID);
    114 
    115   return instance_->processChat(message, playerID);
    116 }
    117163
    118164}//namespace orxonox
  • code/branches/presentation3/src/libraries/network/Host.h

    r7153 r7161  
    3333#include "core/CorePrereqs.h"
    3434
     35#include <vector>
     36
    3537namespace orxonox {
    3638
     
    6365    Host();
    6466    virtual ~Host();
    65     static Host *instance_;
    66     unsigned int clientID_;
    67     unsigned int shipID_;
     67    void setActive( bool bActive ){ bIsActive_ = bActive; }
     68//     static Host *instance_;
    6869
    6970  public:
    70     static bool running(){return instance_!=0;}
     71//     static Host* getInstance(){ return instance_; }
     72    static bool running(){ return instances_s.size(); }
    7173    static bool addPacket(ENetPacket *packet, int clientID=0);
    7274    //static bool chat(std::string& message);
    7375//     static bool receiveChat(packet::Chat *message, unsigned int clientID);
    74     static unsigned int getPlayerID();
    75     static unsigned int getShipID(){return instance_->shipID_;}
    76     static void setClientID(unsigned int id){ instance_->clientID_ = id; }
    77     static void setShipID(unsigned int id){ instance_->shipID_ = id; }
    78     static bool isServer(){ return instance_->isServer_(); }
     76    static unsigned int getPlayerID(){ return clientID_s; }
     77    static unsigned int getShipID(){return shipID_s;}
     78    static void setClientID(unsigned int id){ clientID_s = id; }
     79    static void setShipID(unsigned int id){ shipID_s = id; }
     80    static bool isServer();
    7981    static bool Chat(const std::string& message);
    8082    static bool Broadcast(const std::string& message);
    8183    static bool incomingChat(const std::string& message, unsigned int playerID);
    8284    virtual void printRTT()=0;
     85    bool isActive(){ return bIsActive_; }
    8386  private:
    8487    ConsoleCommand* printRTTCC_;
     88    static uint32_t clientID_s;
     89    static uint32_t shipID_s;
     90    static std::vector<Host*> instances_s;
     91    bool bIsActive_;
    8592};
    8693
  • code/branches/presentation3/src/libraries/network/NetworkPrereqs.h

    r6417 r7161  
    6464namespace orxonox
    6565{
    66   static const unsigned int GAMESTATEID_INITIAL = static_cast<unsigned int>(-1);
    67   static const unsigned int CLIENTID_UNKNOWN    = static_cast<unsigned int>(-2);
     66  static const unsigned int GAMESTATEID_INITIAL     = static_cast<unsigned int>(-1);
     67  static const unsigned int CLIENTID_UNKNOWN        = static_cast<unsigned int>(-2);
     68  extern const char* LAN_DISCOVERY_MESSAGE;
     69  extern const char* LAN_DISCOVERY_ACK;
     70  static const unsigned int LAN_DISCOVERY_PORT      = 55557;
    6871}
    6972
  • code/branches/presentation3/src/libraries/network/Server.cc

    r6417 r7161  
    6969  *
    7070  */
    71   Server::Server() {
     71  Server::Server()
     72  {
    7273    this->timeSinceLastUpdate_=0;
    7374  }
    7475
    75   Server::Server(int port){
     76  Server::Server(int port)
     77  {
    7678    this->setPort( port );
    7779    this->timeSinceLastUpdate_=0;
     
    8385  * @param bindAddress Address to listen on
    8486  */
    85   Server::Server(int port, const std::string& bindAddress) {
     87  Server::Server(int port, const std::string& bindAddress)
     88  {
    8689    this->setPort( port );
    8790    this->setBindAddress( bindAddress );
     
    9295  * @brief Destructor
    9396  */
    94   Server::~Server(){
     97  Server::~Server()
     98  {
    9599  }
    96100
     
    98102  * This function opens the server by creating the listener thread
    99103  */
    100   void Server::open() {
     104  void Server::open()
     105  {
     106    Host::setActive(true);
    101107    COUT(4) << "opening server" << endl;
    102108    this->openListener();
     109    LANDiscoverable::setActivity(true);
    103110    return;
    104111  }
     
    107114  * This function closes the server
    108115  */
    109   void Server::close() {
     116  void Server::close()
     117  {
     118    Host::setActive(false);
    110119    COUT(4) << "closing server" << endl;
    111120    this->disconnectClients();
    112121    this->closeListener();
     122    LANDiscoverable::setActivity(false);
    113123    return;
    114124  }
    115125
    116   bool Server::processChat(const std::string& message, unsigned int playerID){
     126  bool Server::processChat(const std::string& message, unsigned int playerID)
     127  {
    117128    ClientInformation *temp = ClientInformation::getBegin();
    118129    packet::Chat *chat;
     
    134145  * @param time time since last tick
    135146  */
    136   void Server::update(const Clock& time) {
     147  void Server::update(const Clock& time)
     148  {
    137149    // receive incoming packets
    138150    Connection::processQueue();
     151    // receive and process incoming discovery packets
     152    LANDiscoverable::update();
    139153
    140154    if ( ClientInformation::hasClients() )
     
    157171  }
    158172
    159   bool Server::queuePacket(ENetPacket *packet, int clientID){
     173  bool Server::queuePacket(ENetPacket *packet, int clientID)
     174  {
    160175    return ServerConnection::addPacket(packet, clientID);
    161176  }
     
    164179   * @brief: returns ping time to client in milliseconds
    165180   */
    166   unsigned int Server::getRTT(unsigned int clientID){
     181  unsigned int Server::getRTT(unsigned int clientID)
     182  {
    167183    assert(ClientInformation::findClient(clientID));
    168184    return ClientInformation::findClient(clientID)->getRTT();
     
    178194   * @brief: return packet loss ratio to client (scales from 0 to 1)
    179195   */
    180   double Server::getPacketLoss(unsigned int clientID){
     196  double Server::getPacketLoss(unsigned int clientID)
     197  {
    181198    assert(ClientInformation::findClient(clientID));
    182199    return ClientInformation::findClient(clientID)->getPacketLoss();
     
    186203  * takes a new snapshot of the gamestate and sends it to the clients
    187204  */
    188   void Server::updateGamestate() {
     205  void Server::updateGamestate()
     206  {
    189207    if( ClientInformation::getBegin()==NULL )
    190208      //no client connected
     
    208226  * sends the gamestate
    209227  */
    210   bool Server::sendGameState() {
     228  bool Server::sendGameState()
     229  {
    211230//     COUT(5) << "Server: starting function sendGameState" << std::endl;
    212231//     ClientInformation *temp = ClientInformation::getBegin();
     
    244263  }
    245264
    246   bool Server::sendObjectDeletes(){
     265  bool Server::sendObjectDeletes()
     266  {
    247267    ClientInformation *temp = ClientInformation::getBegin();
    248268    if( temp == NULL )
     
    257277//     COUT(3) << "sending DeleteObjects" << std::endl;
    258278    while(temp != NULL){
    259       if( !(temp->getSynched()) ){
     279      if( !(temp->getSynched()) )
     280      {
    260281        COUT(5) << "Server: not sending gamestate" << std::endl;
    261282        temp=temp->next();
     
    276297
    277298
    278   void Server::addPeer(ENetEvent *event){
     299  void Server::addPeer(ENetEvent *event)
     300  {
    279301    static unsigned int newid=1;
    280302
    281303    COUT(2) << "Server: adding client" << std::endl;
    282304    ClientInformation *temp = ClientInformation::insertBack(new ClientInformation);
    283     if(!temp){
     305    if(!temp)
     306    {
    284307      COUT(2) << "Server: could not add client" << std::endl;
    285308    }
     
    310333  }
    311334
    312   bool Server::createClient(int clientID){
     335  bool Server::createClient(int clientID)
     336  {
    313337    ClientInformation *temp = ClientInformation::findClient(clientID);
    314     if(!temp){
     338    if(!temp)
     339    {
    315340      COUT(2) << "Conn.Man. could not create client with id: " << clientID << std::endl;
    316341      return false;
     
    345370  }
    346371
    347   void Server::disconnectClient( ClientInformation *client ){
     372  void Server::disconnectClient( ClientInformation *client )
     373  {
    348374    ServerConnection::disconnectClient( client );
    349375    GamestateManager::removeClient(client);
     
    352378  }
    353379
    354   bool Server::chat(const std::string& message){
     380  bool Server::chat(const std::string& message)
     381  {
    355382      return this->sendChat(message, Host::getPlayerID());
    356383  }
    357384
    358   bool Server::broadcast(const std::string& message){
     385  bool Server::broadcast(const std::string& message)
     386  {
    359387      return this->sendChat(message, CLIENTID_UNKNOWN);
    360388  }
    361389
    362   bool Server::sendChat(const std::string& message, unsigned int clientID){
     390  bool Server::sendChat(const std::string& message, unsigned int clientID)
     391  {
    363392    ClientInformation *temp = ClientInformation::getBegin();
    364393    packet::Chat *chat;
    365     while(temp){
     394    while(temp)
     395    {
    366396      chat = new packet::Chat(message, clientID);
    367397      chat->setClientID(temp->getID());
     
    377407  }
    378408
    379   void Server::syncClassid(unsigned int clientID) {
     409  void Server::syncClassid(unsigned int clientID)
     410  {
    380411    int failures=0;
    381412    packet::ClassID *classid = new packet::ClassID();
  • code/branches/presentation3/src/libraries/network/Server.h

    r6417 r7161  
    3737#include "GamestateManager.h"
    3838#include "ServerConnection.h"
     39#include "LANDiscoverable.h"
    3940
    4041namespace orxonox
     
    4546  * It implements all functions necessary for a Server
    4647  */
    47   class _NetworkExport Server : public Host, public ServerConnection, public GamestateManager{
     48  class _NetworkExport Server : public Host, public ServerConnection, public GamestateManager, public LANDiscoverable{
    4849  public:
    4950    Server();
  • code/branches/presentation3/src/libraries/network/ServerConnection.cc

    r6417 r7161  
    9494
    9595  bool ServerConnection::addPacketAll(ENetPacket *packet) {
    96     if ( !Connection::getInstance() )
    97       return false;
    98     enet_host_broadcast( Connection::getInstance()->getHost(), 0, packet);
     96//     if ( !Connection::getInstance() )
     97//       return false;
     98    enet_host_broadcast( Connection::getHost(), 0, packet);
    9999    return true;
    100100  }
  • code/branches/presentation3/src/libraries/network/ServerConnection.h

    r6417 r7161  
    5656    bool openListener();
    5757    bool closeListener();
    58     static bool addPacket(ENetPacket *packet, unsigned int ID);
    59     static bool addPacketAll(ENetPacket *packet);
     58    bool addPacket(ENetPacket *packet, unsigned int ID);
     59    bool addPacketAll(ENetPacket *packet);
    6060    virtual void disconnectClient(ClientInformation *client);
    6161    void disconnectClient(int clientID);
  • code/branches/presentation3/src/libraries/network/packet/CMakeLists.txt

    r5929 r7161  
    1111  Welcome.cc
    1212COMPILATION_END
     13  ServerInformation.cc
    1314)
    1415
     
    2324  Gamestate.h
    2425  Packet.h
     26  ServerInformation.h
    2527  Welcome.h
    2628)
  • code/branches/presentation3/src/libraries/network/packet/Packet.cc

    r7153 r7161  
    6262std::map<size_t, Packet *> Packet::packetMap_;
    6363
    64 Packet::Packet(){
     64Packet::Packet()
     65{
    6566  flags_ = PACKET_FLAG_DEFAULT;
    6667  packetDirection_ = Direction::Outgoing;
     
    7172}
    7273
    73 Packet::Packet(uint8_t *data, unsigned int clientID){
     74Packet::Packet(uint8_t *data, unsigned int clientID)
     75{
    7476  flags_ = PACKET_FLAG_DEFAULT;
    7577  packetDirection_ = Direction::Incoming;
  • code/branches/presentation3/src/libraries/network/synchronisable/Synchronisable.cc

    r7153 r7161  
    5454    static uint32_t idCounter=0;
    5555    objectMode_=0x1; // by default do not send data to server
    56     if ( GameMode::isMaster() || ( Host::running() && Host::isServer() ) )
     56    if ( GameMode::isMaster()/* || ( Host::running() && Host::isServer() )*/ )
    5757    {
    5858      this->setObjectID( idCounter++ );
  • code/branches/presentation3/src/libraries/util/Serialise.h

    r7127 r7161  
    5353    template <class T> inline bool checkEquality( const T& variable, uint8_t* mem );
    5454
     55 
     56  // =========== char*
     57   
     58  inline uint32_t returnSize( char*& variable )
     59  {
     60    return strlen(variable)+1;
     61  }
     62     
     63  inline void saveAndIncrease( char*& variable, uint8_t*& mem )
     64  {
     65    strcpy((char*)mem, variable);
     66    mem += returnSize(variable);
     67  }
     68       
     69  inline void loadAndIncrease( char*& variable, uint8_t*& mem )
     70  {
     71    if( variable )
     72      delete variable;
     73    uint32_t len = strlen((char*)mem)+1;
     74    variable = new char[len];
     75    strcpy((char*)variable, (char*)mem);
     76    mem += len;
     77  }
     78         
     79  inline bool checkEquality( char*& variable, uint8_t* mem )
     80  {
     81    return strcmp(variable, (char*)mem)==0;
     82  }
     83   
    5584// =================== Template specialisation stuff =============
    5685
     
    394423        return memcmp(&temp, mem, sizeof(uint64_t))==0;
    395424    }
    396 
     425       
    397426// =========== string
    398427
  • code/branches/presentation3/src/orxonox/CameraManager.cc

    r6417 r7161  
    6868    void CameraManager::requestFocus(Camera* camera)
    6969    {
     70      COUT(0) << "bliub" << endl;
    7071        // notify old camera (if it exists)
    7172        if (!this->cameraList_.empty())
  • code/branches/presentation3/src/orxonox/Main.cc

    r6105 r7161  
    4040#include "core/LuaState.h"
    4141#include "ToluaBindOrxonox.h"
     42#include "ToluaBindNetwork.h"
    4243#include "Main.h"
    4344
     
    5152
    5253DeclareToluaInterface(Orxonox);
     54DeclareToluaInterface(Network);
    5355
    5456namespace orxonox
  • code/branches/presentation3/src/orxonox/gamestates/GSClient.cc

    r7122 r7161  
    4444    GSClient::GSClient(const GameStateInfo& info)
    4545        : GameState(info)
    46         , client_(0)
    4746    {
    4847    }
     
    5655        GameMode::setIsClient(true);
    5756
    58         this->client_ = new Client(CommandLineParser::getValue("dest").getString(), CommandLineParser::getValue("port"));
     57//         this->client_ = new Client();
     58//         this->client_->setDestination(CommandLineParser::getValue("dest").getString(), CommandLineParser::getValue("port") );
    5959
    60         if(!client_->establishConnection())
     60        if( !Client::getInstance()->establishConnection() )
    6161        {
    62             delete this->client_;
    6362            ThrowException(InitialisationFailed, "Could not establish connection with server.");
    6463        }
    6564
    66         client_->update(Game::getInstance().getGameClock());
     65        Client::getInstance()->update(Game::getInstance().getGameClock());
    6766    }
    6867
    6968    void GSClient::deactivate()
    7069    {
    71         client_->closeConnection();
     70        Client::getInstance()->closeConnection();
    7271
    7372        // destroy client
    74         delete this->client_;
     73//         delete this->client_;
    7574
    7675        GameMode::setIsClient(false);
     
    7978    void GSClient::update(const Clock& time)
    8079    {
    81         client_->update(time);
     80        Client::getInstance()->update(time);
    8281    }
    8382}
  • code/branches/presentation3/src/orxonox/gamestates/GSClient.h

    r5929 r7161  
    4646        void deactivate();
    4747        void update(const Clock& time);
    48 
    49     private:
    50         Client* client_;
    5148    };
    5249}
Note: See TracChangeset for help on using the changeset viewer.