Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Oct 19, 2008, 9:50:36 PM (16 years ago)
Author:
landauf
Message:

added chat overlay

Location:
code/branches/objecthierarchy/src/network
Files:
2 added
13 edited

Legend:

Unmodified
Added
Removed
  • code/branches/objecthierarchy/src/network/CMakeLists.txt

    r1940 r1953  
    11SET( NETWORK_SRC_FILES
     2  ChatListener.cc
    23  Client.cc
    34  ClientConnection.cc
  • code/branches/objecthierarchy/src/network/Client.cc

    r1917 r1953  
    4646#include "core/CoreIncludes.h"
    4747#include "packet/Packet.h"
     48
    4849// #include "packet/Acknowledgement.h"
    4950
     
    6970  * @param port port of the application on the server
    7071  */
    71   Client::Client(std::string address, int port) : client_connection(port, address){
     72  Client::Client(const std::string& address, int port) : client_connection(port, address){
    7273    isConnected=false;
    7374    isSynched_=false;
     
    116117  }
    117118
    118   bool Client::processChat(std::string message, unsigned int playerID){
    119     COUT(1) << "Player " << playerID << ": " << message << std::endl;
     119  bool Client::processChat(const std::string& message, unsigned int playerID){
     120//    COUT(1) << "Player " << playerID << ": " << message << std::endl;
    120121    return true;
    121122  }
    122  
     123
    123124  /**
    124125   * This function implements the method of sending a chat message to the server
    125    * @param message message to be sent 
     126   * @param message message to be sent
    126127   * @return result(true/false)
    127128   */
    128   bool Client::chat(std::string message){
     129  bool Client::chat(const std::string& message){
    129130    packet::Chat *m = new packet::Chat(message, Host::getPlayerID());
    130131    return m->send();
     
    134135  /**
    135136   * Processes incoming packets, sends a gamestate to the server and does the cleanup
    136    * @param time 
     137   * @param time
    137138   */
    138139  void Client::tick(float time){
  • code/branches/objecthierarchy/src/network/Client.h

    r1907 r1953  
    6666  public:
    6767    Client();
    68     Client(std::string address, int port);
     68    Client(const std::string& address, int port);
    6969    Client(const char *address, int port);
    7070    ~Client();
    71    
     71
    7272    bool establishConnection();
    7373    bool closeConnection();
    7474    bool queuePacket(ENetPacket *packet, int clientID);
    75     bool processChat(std::string message, unsigned int playerID);
    76     virtual bool chat(std::string message);
     75    bool processChat(const std::string& message, unsigned int playerID);
     76    virtual bool chat(const std::string& message);
     77    virtual bool broadcast(const std::string& message) { return false; }
    7778    //bool sendChat(packet::Chat *chat);
    78    
    79 //    static void Chat( std::string message );
    80    
    81     //static void setShipID( unsigned int shipID){ dynamic_cast<Client *>(instance_)->shipID_=shipID; }
    82     static void setClientID( unsigned int clientID){ dynamic_cast<Client *>(instance_)->clientID_=clientID; }
    83    
     79
    8480    void tick(float time);
    8581
    8682  private:
    8783    virtual bool isServer_(){return false;}
    88    
     84
    8985    ClientConnection client_connection;
    9086    GamestateClient gamestate;
    9187    bool isConnected;
    9288    bool isSynched_;
    93    
     89
    9490    bool gameStateFailure_;
    9591  };
  • code/branches/objecthierarchy/src/network/ClientConnection.cc

    r1907 r1953  
    5454  boost::recursive_mutex ClientConnection::enet_mutex_;
    5555
    56   ClientConnection::ClientConnection(int port, std::string address) {
     56  ClientConnection::ClientConnection(int port, const std::string& address) {
    5757    quit=false;
    5858    server=NULL;
  • code/branches/objecthierarchy/src/network/ClientConnection.h

    r1916 r1953  
    6262  class _NetworkExport ClientConnection{
    6363  public:
    64     ClientConnection(int port, std::string address);
     64    ClientConnection(int port, const std::string& address);
    6565    ClientConnection(int port, const char* address);
    6666    ~ClientConnection();
  • code/branches/objecthierarchy/src/network/ClientInformation.cc

    r1952 r1953  
    4545namespace network
    4646{
    47  
     47
    4848  ClientInformation *ClientInformation::head_=0;
    49  
     49
    5050  ClientInformation::ClientInformation() {
    5151    if(!head_)
     
    129129    return true;
    130130  }
    131  
     131
    132132  bool ClientInformation::setPartialGamestateID(int id){
    133133    if(!this)
     
    150150      return NULL;
    151151  }
    152  
     152
    153153  int ClientInformation::getFailures(){
    154154    return failures_;
     
    160160    failures_=0;
    161161  }
    162  
     162
    163163  enet_uint32 ClientInformation::getRTT(){
    164164    return peer_->roundTripTime;
    165165  }
    166  
     166
    167167  enet_uint32 ClientInformation::getPacketLoss(){
    168168    return peer_->packetLoss;
     
    175175      return -1;
    176176  }
    177  
     177
    178178  int ClientInformation::getPartialGamestateID() {
    179179    if(this)
     
    197197
    198198  bool ClientInformation::removeClient(int clientID) {
    199     if(clientID==CLIENTID_UNKNOWN)
     199    if((unsigned int)clientID==CLIENTID_UNKNOWN)
    200200      return false;
    201201    ClientInformation *temp = head_;
  • code/branches/objecthierarchy/src/network/ClientInformation.h

    r1916 r1953  
    4747
    4848#define GAMESTATEID_INITIAL -1
    49 #define CLIENTID_UNKNOWN -2
    5049
    5150// WATCH OUT: THE CLIENTINFORMATION LIST IS NOT THREADSAFE ANYMORE
     
    5352namespace network
    5453{
     54  static const unsigned int CLIENTID_UNKNOWN = (unsigned int)-2;
     55
    5556  /**
    5657  * This class implements a list for client informations
  • code/branches/objecthierarchy/src/network/ConnectionManager.cc

    r1916 r1953  
    8888  }
    8989
    90   ConnectionManager::ConnectionManager(int port, std::string address) :receiverThread_(0) {
     90  ConnectionManager::ConnectionManager(int port, const std::string& address) :receiverThread_(0) {
    9191    assert(instance_==0);
    9292    instance_=this;
  • code/branches/objecthierarchy/src/network/ConnectionManager.h

    r1916 r1953  
    7979    ConnectionManager(int port);
    8080    ConnectionManager(int port, const char *address);
    81     ConnectionManager(int port, std::string address);
     81    ConnectionManager(int port, const std::string& address);
    8282    ~ConnectionManager();
    8383    //ENetPacket *getPacket(ENetAddress &address); // thread1
  • code/branches/objecthierarchy/src/network/Host.cc

    r1907 r1953  
    3232#include "core/ConsoleCommand.h"
    3333#include "packet/Packet.h"
     34#include "ChatListener.h"
    3435
    3536namespace network {
     
    3839
    3940Host *Host::instance_=0;
    40  
     41
    4142/**
    4243 * @brief Constructor: assures that only one reference will be created and sets the pointer
     
    9091 * @return playerID
    9192 */
    92 unsigned int Host::getPlayerID(){ 
     93unsigned int Host::getPlayerID(){
    9394  if(!instance_)
    9495    return 0;
     
    9697}
    9798
    98 bool Host::Chat(std::string message){
     99bool Host::Chat(const std::string& message){
    99100  if(!instance_)
    100101    return false;
     
    102103}
    103104
    104 bool Host::incomingChat(std::string message, unsigned int playerID){
     105bool Host::Broadcast(const std::string& message){
     106  if(!instance_)
     107    return false;
     108  return instance_->broadcast(message);
     109}
     110
     111bool Host::incomingChat(const std::string& message, unsigned int playerID){
     112  for (orxonox::ObjectList<ChatListener>::iterator it = orxonox::ObjectList<ChatListener>::begin(); it != orxonox::ObjectList<ChatListener>::end(); ++it)
     113    it->incomingChat(message, playerID);
     114
    105115  return instance_->processChat(message, playerID);
    106116}
  • code/branches/objecthierarchy/src/network/Host.h

    r1916 r1953  
    5050    //virtual bool sendChat(packet::Chat *chat)=0;
    5151    virtual bool queuePacket(ENetPacket *packet, int clientID)=0;
    52     virtual bool chat(std::string message)=0;
    53     virtual bool processChat(std::string message, unsigned int playerID)=0;
     52    virtual bool chat(const std::string& message)=0;
     53    virtual bool broadcast(const std::string& message)=0;
     54    virtual bool processChat(const std::string& message, unsigned int playerID)=0;
    5455    virtual bool isServer_()=0;
    5556
     
    7374    static void setShipID(unsigned int id){ instance_->shipID_ = id; }
    7475    static bool isServer(){ return instance_->isServer_(); }
    75     static bool Chat(std::string message);
    76     static bool incomingChat(std::string message, unsigned int playerID);
     76    static bool Chat(const std::string& message);
     77    static bool Broadcast(const std::string& message);
     78    static bool incomingChat(const std::string& message, unsigned int playerID);
    7779  private:
    7880};
  • code/branches/objecthierarchy/src/network/Server.cc

    r1952 r1953  
    5858#include "packet/DeleteObjects.h"
    5959#include <util/Convert.h>
     60#include "ChatListener.h"
    6061
    6162namespace network
     
    8586  * @param bindAddress Address to listen on
    8687  */
    87   Server::Server(int port, std::string bindAddress) {
     88  Server::Server(int port, const std::string& bindAddress) {
    8889    timeSinceLastUpdate_=0;
    8990    connection = new ConnectionManager(port, bindAddress);
     
    128129  }
    129130
    130   bool Server::processChat(std::string message, unsigned int playerID){
     131  bool Server::processChat(const std::string& message, unsigned int playerID){
    131132    ClientInformation *temp = ClientInformation::getBegin();
    132133    packet::Chat *chat;
     
    138139      temp = temp->next();
    139140    }
    140     COUT(1) << "Player " << playerID << ": " << message << std::endl;
     141//    COUT(1) << "Player " << playerID << ": " << message << std::endl;
    141142    return true;
    142143  }
     
    304305      listener++;
    305306    }
    306    
     307
    307308    newid++;
    308309
     
    367368  }
    368369
    369   bool Server::chat(std::string message){
     370  bool Server::chat(const std::string& message){
     371      return this->sendChat(message, Host::getPlayerID());
     372  }
     373
     374  bool Server::broadcast(const std::string& message){
     375      return this->sendChat(message, CLIENTID_UNKNOWN);
     376  }
     377
     378  bool Server::sendChat(const std::string& message, unsigned int clientID){
    370379    ClientInformation *temp = ClientInformation::getBegin();
    371380    packet::Chat *chat;
    372381    while(temp){
    373       chat = new packet::Chat(message, Host::getPlayerID());
     382      chat = new packet::Chat(message, clientID);
    374383      chat->setClientID(temp->getID());
    375384      if(!chat->send())
     
    377386      temp = temp->next();
    378387    }
    379     COUT(1) << "Player " << Host::getPlayerID() << ": " << message << std::endl;
     388//    COUT(1) << "Player " << Host::getPlayerID() << ": " << message << std::endl;
     389    for (orxonox::ObjectList<ChatListener>::iterator it = orxonox::ObjectList<ChatListener>::begin(); it != orxonox::ObjectList<ChatListener>::end(); ++it)
     390      it->incomingChat(message, clientID);
     391
    380392    return true;
    381393  }
  • code/branches/objecthierarchy/src/network/Server.h

    r1916 r1953  
    6161    Server();
    6262    Server(int port);
    63     Server(int port, std::string bindAddress);
     63    Server(int port, const std::string& bindAddress);
    6464    Server(int port, const char *bindAddress);
    6565    ~Server();
     
    6767    void open();
    6868    void close();
    69     bool processChat(std::string message, unsigned int playerID);
     69    bool processChat(const std::string& message, unsigned int playerID);
    7070    bool queuePacket(ENetPacket *packet, int clientID);
    7171    void tick(float time);
     
    8686    bool sendGameState();
    8787    bool sendObjectDeletes();
    88     virtual bool chat(std::string message);
     88    virtual bool chat(const std::string& message);
     89    virtual bool broadcast(const std::string& message);
     90    bool sendChat(const std::string& message, unsigned int clientID);
    8991
    9092    //void processChat( chat *data, int clientId);
Note: See TracChangeset for help on using the changeset viewer.