Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Aug 23, 2011, 12:45:53 AM (13 years ago)
Author:
landauf
Message:

merged output branch back to trunk.

Changes:

  • you have to include util/Output.h instead of util/Debug.h
  • COUT(x) is now called orxout(level)
  • output levels are now defined by an enum instead of numbers. see util/Output.h for the definition
  • it's possible to use output contexts with orxout(level, context). see util/Output.h for some common contexts. you can define more contexts
  • you must use 'endl' at the end of an output message, '\n' does not flush the message

Output levels:

  • instead of COUT(0) use orxout()
  • instead of COUT(1) use orxout(user_error) or orxout(internal_error)
  • instead of COUT(2) use orxout(user_warning) or orxout(internal_warning)
  • instead of COUT(3) use orxout(user_status/user_info) or orxout(internal_status/internal_info)
  • instead of COUT(4) use orxout(verbose)
  • instead of COUT(5) use orxout(verbose_more)
  • instead of COUT(6) use orxout(verbose_ultra)

Guidelines:

  • user_* levels are for the user, visible in the console and the log-file
  • internal_* levels are for developers, visible in the log-file
  • verbose_* levels are for debugging, only visible if the context of the output is activated

Usage in C++:

  • orxout() << "message" << endl;
  • orxout(level) << "message" << endl;
  • orxout(level, context) << "message" << endl;

Usage in Lua:

  • orxout("message")
  • orxout(orxonox.level.levelname, "message")
  • orxout(orxonox.level.levelname, "context", "message")

Usage in Tcl (and in the in-game-console):

  • orxout levelname message
  • orxout_context levelname context message
  • shortcuts: log message, error message, warning message, status message, info message, debug message
Location:
code/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/trunk

  • code/trunk/src/libraries/network/Server.cc

    r8706 r8858  
    4747
    4848#include "util/Clock.h"
    49 #include "util/Debug.h"
     49#include "util/Output.h"
    5050#include "core/ObjectList.h"
    5151#include "core/command/Executor.h"
     
    5656#include "packet/Gamestate.h"
    5757#include "packet/Welcome.h"
    58 #include "ChatListener.h"
    5958// #include "ClientInformation.h"
    6059#include "FunctionCallManager.h"
    6160#include "GamestateManager.h"
    62 #include "WANDiscovery.h"
    6361
    6462namespace orxonox
     
    10098  }
    10199
    102 
    103   /** helper that connects to the master server */
    104   void Server::helper_ConnectToMasterserver()
    105   {
    106 //     WANDiscovery::getInstance().msc.sendRequest( MSPROTO_GAME_SERVER " "
    107 //       MSPROTO_REGISTER_SERVER );
    108   }
    109 
    110100  /**
    111101  * This function opens the server by creating the listener thread
     
    114104  {
    115105    Host::setActive(true);
    116     COUT(4) << "opening server" << endl;
     106    orxout(verbose, context::network) << "opening server" << endl;
    117107    this->openListener();
    118    
     108
    119109    /* make discoverable on LAN */
    120110    LANDiscoverable::setActivity(true);
     
    122112    /* make discoverable on WAN */
    123113    WANDiscoverable::setActivity(true);
    124     /* TODO this needs to be optional, we need a switch from the UI to
    125      * enable/disable this
    126      */
    127 //     helper_ConnectToMasterserver();
    128114
    129115    /* done */
     
    137123  {
    138124    Host::setActive(false);
    139     COUT(4) << "closing server" << endl;
     125    orxout(verbose, context::network) << "closing server" << endl;
    140126    this->disconnectClients();
    141127    this->closeListener();
    142128
    143129    /* tell master server we're closing */
    144     COUT(2) << "disconnecting." << endl;
    145     WANDiscoverable::setActivity(false);   
    146     COUT(2) << "disconnecting done" << endl;
     130    orxout(internal_info, context::network) << "disconnecting." << endl;
     131    WANDiscoverable::setActivity(false);
     132    orxout(internal_info, context::network) << "disconnecting done" << endl;
    147133
    148134    LANDiscoverable::setActivity(false);
    149135    return;
    150   }
    151 
    152   bool Server::processChat(const std::string& message, unsigned int playerID)
    153   {
    154 //     ClientInformation *temp = ClientInformation::getBegin();
    155     packet::Chat *chat;
    156 //     while(temp){
    157     chat = new packet::Chat(message, playerID);
    158     chat->setPeerID(NETWORK_PEER_ID_BROADCAST);
    159     chat->send( static_cast<Host*>(this) );
    160 //         COUT(3) << "could not send Chat message to client ID: " << temp->getID() << std::endl;
    161 //       temp = temp->next();
    162 //     }
    163 //    COUT(1) << "Player " << playerID << ": " << message << std::endl;
    164     return true;
    165   }
    166 
    167 
    168   /* handle incoming data */
    169   int rephandler( char *addr, ENetEvent *ev )
    170   {
    171     /* reply to pings */
    172     if( !strncmp( (char *)ev->packet->data, MSPROTO_PING_GAMESERVER,
    173       MSPROTO_PING_GAMESERVER_LEN ) )
    174       //this->msc.sendRequest( MSPROTO_ACK );
    175       /* NOTE implement this after pollForReply
    176        * reimplementation
    177        */
    178       return 0;
    179 
    180     /* done handling, return all ok code 0 */
    181     return 0;
    182   }
    183 
    184   void Server::helper_HandleMasterServerRequests()
    185   {
    186     /* poll the master server for replies and see whether something
    187      * has to be done or changed.
    188      */
    189     //WANDiscovery::getInstance().msc.pollForReply( rhandler, 10 );
    190136  }
    191137
     
    202148    // receive and process incoming discovery packets
    203149    LANDiscoverable::update();
    204    
    205     // receive and process requests from master server
    206     /* todo */
    207     //helper_HandleMasterServerRequests();
    208150
    209151    if ( GamestateManager::hasPeers() )
     
    246188  {
    247189//     for( ClientInformation* temp=ClientInformation::getBegin(); temp!=0; temp=temp->next() )
    248 //       COUT(0) << "Round trip time to client with ID: " << temp->getID() << " is " << temp->getRTT() << " ms" << endl;
     190//       orxout(message) << "Round trip time to client with ID: " << temp->getID() << " is " << temp->getRTT() << " ms" << endl;
    249191  }
    250192
     
    268210      return;
    269211    GamestateManager::update();
    270 //     COUT(5) << "Server: one gamestate update complete, goig to sendGameState" << std::endl;
    271     //std::cout << "updated gamestate, sending it" << std::endl;
     212//     orxout(verbose_more, context::network) << "Server: one gamestate update complete, goig to sendGameState" << endl;
     213    //orxout(verbose_more, context::network) << "updated gamestate, sending it" << endl;
    272214    //if(clients->getGamestateID()!=GAMESTATEID_INITIAL)
    273215    sendGameStates();
    274216    sendObjectDeletes();
    275 //     COUT(5) << "Server: one sendGameState turn complete, repeat in next tick" << std::endl;
    276     //std::cout << "sent gamestate" << std::endl;
     217//     orxout(verbose_more, context::network) << "Server: one sendGameState turn complete, repeat in next tick" << endl;
     218    //orxout(verbose_more, context::network) << "sent gamestate" << endl;
    277219  }
    278220
     
    305247      return true;  //everything ok (no deletes this tick)
    306248    }
    307 //     COUT(3) << "sending DeleteObjects" << std::endl;
     249//     orxout(verbose, context::network) << "sending DeleteObjects" << endl;
    308250//     while(temp != NULL){
    309251//       if( !(temp->getSynched()) )
    310252//       {
    311 //         COUT(5) << "Server: not sending gamestate" << std::endl;
     253//         orxout(verbose_more, context::network) << "Server: not sending gamestate" << endl;
    312254//         temp=temp->next();
    313255//         continue;
     
    318260    del->setPeerID(NETWORK_PEER_ID_BROADCAST);
    319261    if ( !del->send( static_cast<Host*>(this) ) )
    320       COUT(3) << "Server: could not broadcast deleteObjects packet" << std::endl;
     262      orxout(internal_warning, context::network) << "Server: could not broadcast deleteObjects packet" << endl;
    321263//       temp=temp->next();
    322264      // gs gets automatically deleted by enet callback
     
    330272  {
    331273//     static unsigned int newid=1;
    332 // 
    333 //     COUT(2) << "Server: adding client" << std::endl;
     274//
     275//     orxout(internal_info, context::network) << "Server: adding client" << endl;
    334276//     ClientInformation *temp = ClientInformation::insertBack(new ClientInformation);
    335277//     if(!temp)
    336278//     {
    337 //       COUT(2) << "Server: could not add client" << std::endl;
     279//       orxout(internal_warning, context::network) << "Server: could not add client" << endl;
    338280//     }
    339281//     temp->setID(newid);
     
    347289//     ++newid;
    348290
    349     COUT(3) << "Server: added client id: " << peerID << std::endl;
     291    orxout(internal_info, context::network) << "Server: added client id: " << peerID << endl;
    350292    createClient(peerID);
    351293}
     
    353295  void Server::removePeer(uint32_t peerID)
    354296  {
    355     COUT(4) << "removing client from list" << std::endl;
     297    orxout(verbose, context::network) << "removing client from list" << endl;
    356298//     ClientInformation *client = ClientInformation::findClient(&event->peer->address);
    357299//     if(!client)
     
    375317//     }
    376318  }
    377  
     319
    378320  void Server::processPacket(packet::Packet* packet)
    379321  {
     
    395337//     if(!temp)
    396338//     {
    397 //       COUT(2) << "Server. could not create client with id: " << clientID << std::endl;
     339//       orxout(internal_error, context::network) << "Server. could not create client with id: " << clientID << endl;
    398340//       return false;
    399341//     }
    400 //     COUT(4) << "Con.Man: creating client id: " << temp->getID() << std::endl;
     342//     orxout(verbose, context::network) << "Con.Man: creating client id: " << temp->getID() << endl;
    401343
    402344    // synchronise class ids
     
    411353//     temp->setSynched(true);
    412354    GamestateManager::setSynched(clientID);
    413    
    414     COUT(4) << "sending welcome" << std::endl;
     355
     356    orxout(verbose, context::network) << "sending welcome" << endl;
    415357    packet::Welcome *w = new packet::Welcome(clientID);
    416358    w->setPeerID(clientID);
     
    438380  }
    439381
    440   bool Server::chat(const std::string& message)
    441   {
    442       return this->sendChat(message, Host::getPlayerID());
    443   }
    444 
    445   bool Server::broadcast(const std::string& message)
    446   {
    447       return this->sendChat(message, NETWORK_PEER_ID_BROADCAST);
    448   }
    449 
    450   bool Server::sendChat(const std::string& message, unsigned int clientID)
    451   {
    452 //     ClientInformation *temp = ClientInformation::getBegin();
    453     packet::Chat *chat;
    454 //     while(temp)
    455     {
    456       chat = new packet::Chat(message, clientID);
    457       chat->setPeerID(NETWORK_PEER_ID_BROADCAST);
    458       chat->send( static_cast<Host*>(this) );
    459 //         COUT(3) << "could not send Chat message to client ID: " << temp->getID() << std::endl;
    460 //       temp = temp->next();
    461     }
    462 //    COUT(1) << "Player " << Host::getPlayerID() << ": " << message << std::endl;
    463     for (ObjectList<ChatListener>::iterator it = ObjectList<ChatListener>::begin(); it != ObjectList<ChatListener>::end(); ++it)
    464       it->incomingChat(message, clientID);
    465 
    466     return true;
     382  /**
     383   * @brief Sends a chat message to the given target ID.
     384   * @param message message to be sent
     385   * @param sourceID the ID of the sender
     386   * @param targetID the ID of the receiver
     387   */
     388  void Server::doSendChat(const std::string& message, unsigned int sourceID, unsigned int targetID)
     389  {
     390    // check if the target exists. just ignore the message otherwise
     391    if (!this->isValidTarget(targetID)) // TODO: remove this if an invalid clientIDs don't trigger assertions anymore
     392      return;
     393
     394    // send the message to the target
     395    packet::Chat* packet = new packet::Chat(message, sourceID, targetID);
     396    packet->setPeerID(targetID);
     397    packet->send( static_cast<Host*>(this) );
     398
     399    // if the target is (or includes) this host as well, call the parent function which passes the message to the listeners
     400    if (targetID == NETWORK_PEER_ID_BROADCAST || targetID == Host::getPlayerID())
     401      Host::doReceiveChat(message, sourceID, targetID);
     402  }
     403
     404  /**
     405   * @brief Gets called if a packet::Chat packet is received. Forwards the packet to the target
     406   * and calls the parent function if necessary.
     407   */
     408  void Server::doReceiveChat(const std::string& message, unsigned int sourceID, unsigned int targetID)
     409  {
     410      this->doSendChat(message, sourceID, targetID);
     411  }
     412
     413  /**
     414   * @brief Returns true if the target ID is in the list of clients (or if it
     415   * corresponds to the broadcast or the server ID).
     416   */
     417  bool Server::isValidTarget(unsigned int targetID)
     418  {
     419    if (targetID == NETWORK_PEER_ID_BROADCAST || targetID == NETWORK_PEER_ID_SERVER)
     420      return true;
     421
     422    std::vector<uint32_t>::iterator it;
     423    for( it=this->clientIDs_.begin(); it!=this->clientIDs_.end(); ++it )
     424      if( *it == targetID )
     425        return true;
     426
     427    return false;
    467428  }
    468429
     
    476437    }
    477438    assert(failures<10);
    478     COUT(4) << "syncClassid:\tall synchClassID packets have been sent" << std::endl;
     439    orxout(verbose, context::network) << "syncClassid:\tall synchClassID packets have been sent" << endl;
    479440  }
    480441
Note: See TracChangeset for help on using the changeset viewer.