Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 1953 for code/branches


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

added chat overlay

Location:
code/branches/objecthierarchy/src
Files:
4 added
20 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);
  • code/branches/objecthierarchy/src/orxonox/CMakeLists.txt

    r1940 r1953  
    3333  overlays/hud/HUDRadar.cc
    3434  overlays/hud/HUDSpeedBar.cc
     35  overlays/hud/ChatOverlay.cc
    3536
    3637  tools/BillboardSet.cc
  • code/branches/objecthierarchy/src/orxonox/objects/gametypes/Gametype.cc

    r1950 r1953  
    3434#include "objects/infos/PlayerInfo.h"
    3535
     36#include "network/Host.h"
     37
    3638namespace orxonox
    3739{
     
    5456            return (*it);
    5557
     58        return 0;
     59    }
     60
     61    PlayerInfo* Gametype::getClient(unsigned int clientID)
     62    {
     63        Gametype* gametype = Gametype::getCurrentGametype();
     64        if (gametype)
     65        {
     66            std::map<unsigned int, PlayerInfo*>::const_iterator it = gametype->clients_.find(clientID);
     67            if (it != gametype->clients_.end())
     68                return it->second;
     69        }
     70        else
     71        {
     72            for (ObjectList<PlayerInfo>::iterator it = ObjectList<PlayerInfo>::begin(); it != ObjectList<PlayerInfo>::end(); ++it)
     73                if (it->getClientID() == clientID)
     74                    return (*it);
     75        }
    5676        return 0;
    5777    }
     
    112132    void Gametype::playerJoined(PlayerInfo* player)
    113133    {
    114         COUT(0) << "player " << player->getName() << " joined" << std::endl;
     134        std::string message = player->getName() + " entered the game";
     135        COUT(0) << message << std::endl;
     136        network::Host::Broadcast(message);
    115137    }
    116138
    117139    void Gametype::playerLeft(PlayerInfo* player)
    118140    {
    119         COUT(0) << "player " << player->getName() << " left" << std::endl;
     141        std::string message = player->getName() + " left the game";
     142        COUT(0) << message << std::endl;
     143        network::Host::Broadcast(message);
    120144    }
    121145
     
    126150            if (player->getName() != player->getOldName())
    127151            {
    128                 COUT(0) << "player " << player->getOldName() << " changed name to " << player->getName() << std::endl;
     152                std::string message = player->getOldName() + " changed name to " + player->getName();
     153                COUT(0) << message << std::endl;
     154                network::Host::Broadcast(message);
    129155            }
    130156        }
  • code/branches/objecthierarchy/src/orxonox/objects/gametypes/Gametype.h

    r1950 r1953  
    5050            static void listPlayers();
    5151
     52            inline const std::map<unsigned int, PlayerInfo*>& getClients() const
     53                { return this->clients_; }
     54            inline const std::set<PlayerInfo*>& getPlayers() const
     55                { return this->players_; }
     56            static PlayerInfo* getClient(unsigned int clientID);
     57
    5258        protected:
    5359            virtual void clientConnected(unsigned int clientID);
  • code/branches/objecthierarchy/src/orxonox/objects/infos/PlayerInfo.cc

    r1950 r1953  
    5151
    5252        this->ping_ = -1;
    53         this->clientID_ = (unsigned int)-1;
     53        this->clientID_ = network::CLIENTID_UNKNOWN;
    5454        this->bLocalPlayer_ = Core::isStandalone();
    5555        this->bLocalPlayer_ = false;
     
    6060        this->registerVariables();
    6161
    62         COUT(0) << "created PlayerInfo (" << this->getObjectID() << ")" << std::endl;
     62//COUT(0) << "created PlayerInfo (" << this->getObjectID() << ")" << std::endl;
    6363    }
    6464
     
    6868        if (gametype)
    6969            gametype->removePlayer(this);
    70         COUT(0) << "destroyed PlayerInfo (" << this->getObjectID() << ")" << std::endl;
     70//COUT(0) << "destroyed PlayerInfo (" << this->getObjectID() << ")" << std::endl;
    7171    }
    7272
    7373    void PlayerInfo::setConfigValues()
    7474    {
    75         SetConfigValue(playerName_, "Player").callback(this, &PlayerInfo::checkName);
     75        SetConfigValue(nick_, "Player").callback(this, &PlayerInfo::checkNick);
    7676    }
    7777
    78     void PlayerInfo::checkName()
     78    void PlayerInfo::checkNick()
    7979    {
    80 std::cout << "# PI(" << this->getObjectID() << "): checkName: " << this->bLocalPlayer_ << std::endl;
    81         if (this->bLocalPlayer_ && Core::isMaster())
    82             this->setName(this->playerName_);
     80//std::cout << "# PI(" << this->getObjectID() << "): checkName: " << this->bLocalPlayer_ << std::endl;
     81        if (this->bLocalPlayer_)
     82        {
     83            this->playerName_ = this->nick_;
     84
     85            if (Core::isMaster())
     86                this->setName(this->playerName_);
     87        }
    8388    }
    8489
    8590    void PlayerInfo::changedName()
    8691    {
    87 std::cout << "# PI(" << this->getObjectID() << "): changedName to " << this->getName() << std::endl;
     92//std::cout << "# PI(" << this->getObjectID() << "): changedName to " << this->getName() << std::endl;
    8893        Gametype* gametype = Gametype::getCurrentGametype();
    8994        if (gametype)
     
    103108    void PlayerInfo::clientChangedName()
    104109    {
    105 std::cout << "# PI(" << this->getObjectID() << "): clientChangedName() to " << this->playerName_ << std::endl;
     110//std::cout << "# PI(" << this->getObjectID() << "): clientChangedName() from " << this->getName() << " to " << this->playerName_ << std::endl;
    106111        this->setName(this->playerName_);
    107112    }
     
    109114    void PlayerInfo::checkClientID()
    110115    {
    111 std::cout << "# PI(" << this->getObjectID() << "): checkClientID()" << std::endl;
     116//std::cout << "# PI(" << this->getObjectID() << "): checkClientID()" << std::endl;
    112117        this->bHumanPlayer_ = true;
    113118
    114119        if (this->clientID_ == network::Host::getPlayerID())
    115120        {
    116 std::cout << "# PI(" << this->getObjectID() << "): checkClientID(): it's the client's ID" << std::endl;
     121//std::cout << "# PI(" << this->getObjectID() << "): checkClientID(): it's the client's ID" << std::endl;
    117122            this->bLocalPlayer_ = true;
     123            this->playerName_ = this->nick_;
    118124//std::cout << "# PI(" << this->getObjectID() << "): checkClientID(): name: " << this->getName() << std::endl;
    119125
    120126            if (Core::isClient())
    121127            {
    122 std::cout << "# PI(" << this->getObjectID() << "): checkClientID(): we're on a client: set object mode to bidirectional" << std::endl;
     128//std::cout << "# PI(" << this->getObjectID() << "): checkClientID(): we're on a client: set object mode to bidirectional" << std::endl;
    123129                this->setObjectMode(network::direction::bidirectional);
    124                 this->playerName_ += "blub";
    125 std::cout << "# PI(" << this->getObjectID() << "): checkClientID(): proposed name: " << this->playerName_ << std::endl;
     130//std::cout << "# PI(" << this->getObjectID() << "): checkClientID(): proposed name: " << this->playerName_ << std::endl;
    126131            }
    127132            else
    128133            {
    129 std::cout << "# PI(" << this->getObjectID() << "): checkClientID(): we're not on a client: finish setup" << std::endl;
     134//std::cout << "# PI(" << this->getObjectID() << "): checkClientID(): we're not on a client: finish setup" << std::endl;
    130135                this->clientChangedName();
    131136                this->bFinishedSetup_ = true;
     
    137142    void PlayerInfo::finishedSetup()
    138143    {
    139 std::cout << "# PI(" << this->getObjectID() << "): finishedSetup(): " << this->bFinishedSetup_ << std::endl;
     144//std::cout << "# PI(" << this->getObjectID() << "): finishedSetup(): " << this->bFinishedSetup_ << std::endl;
    140145        if (Core::isClient())
    141146        {
    142 std::cout << "# PI(" << this->getObjectID() << "): finishedSetup(): we're a client: finish setup" << std::endl;
     147//std::cout << "# PI(" << this->getObjectID() << "): finishedSetup(): we're a client: finish setup" << std::endl;
    143148            this->bFinishedSetup_ = true;
    144149        }
    145150        else if (this->bFinishedSetup_)
    146151        {
    147 std::cout << "# PI(" << this->getObjectID() << "): finishedSetup(): we're a server: add player" << std::endl;
     152//std::cout << "# PI(" << this->getObjectID() << "): finishedSetup(): we're a server: add player" << std::endl;
    148153            Gametype* gametype = Gametype::getCurrentGametype();
    149154            if (gametype)
     
    152157        else
    153158        {
    154 std::cout << "# PI(" << this->getObjectID() << "): finishedSetup(): we're a server: client not yet finished" << std::endl;
     159//std::cout << "# PI(" << this->getObjectID() << "): finishedSetup(): we're a server: client not yet finished" << std::endl;
    155160        }
    156161    }
  • code/branches/objecthierarchy/src/orxonox/objects/infos/PlayerInfo.h

    r1946 r1953  
    6060            void checkClientID();
    6161            void finishedSetup();
    62             void checkName();
     62            void checkNick();
    6363            void clientChangedName();
    6464
     
    7070
    7171            std::string playerName_;
     72            std::string nick_;
    7273    };
    7374}
  • code/branches/objecthierarchy/src/orxonox/overlays/console/InGameConsole.cc

    r1879 r1953  
    613613        @return The converted string
    614614    */
    615     /*static*/ Ogre::UTFString InGameConsole::convert2UTF(std::string s)
     615    /*static*/ Ogre::UTFString InGameConsole::convert2UTF(const std::string& text)
    616616    {
    617617        Ogre::UTFString utf;
    618618        Ogre::UTFString::code_point cp;
    619         for (unsigned int i = 0; i < s.size(); ++i)
    620         {
    621           cp = s[i];
     619        for (unsigned int i = 0; i < text.size(); ++i)
     620        {
     621          cp = text[i];
    622622          cp &= 0xFF;
    623623          utf.append(1, cp);
  • code/branches/objecthierarchy/src/orxonox/overlays/console/InGameConsole.h

    r1879 r1953  
    6161        static void closeConsole();
    6262
     63        static Ogre::UTFString convert2UTF(const std::string& text);
     64
    6365    private: // functions
    6466        InGameConsole(const InGameConsole& other);
     
    8385        // config value related
    8486        void bHidesAllInputChanged();
    85 
    86         static Ogre::UTFString convert2UTF(std::string s);
    8787
    8888    private: // variables
Note: See TracChangeset for help on using the changeset viewer.