Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 1518 for code/branches


Ignore:
Timestamp:
Jun 2, 2008, 9:15:15 PM (16 years ago)
Author:
scheusso
Message:

we are able to chat now ;) just use the command char <string>

Location:
code/branches/network/src
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • code/branches/network/src/core/ConsoleCommand.h

    r1505 r1518  
    4242
    4343#define SetConsoleCommandGeneric(fakevariable, classname, command, bCreateShortcut) \
    44     ConsoleCommand& fakevariable = ClassManager<classname>::getIdentifier()->addConsoleCommand(command, bCreateShortcut)
     44    orxonox::ConsoleCommand& fakevariable = orxonox::ClassManager<classname>::getIdentifier()->addConsoleCommand(command, bCreateShortcut)
    4545
    4646
     
    5252
    5353#define SetConsoleCommandShortcutGeneric(fakevariable, command) \
    54     ConsoleCommand& fakevariable = CommandExecutor::addConsoleCommandShortcut(command)
     54    orxonox::ConsoleCommand& fakevariable = orxonox::CommandExecutor::addConsoleCommandShortcut(command)
    5555
    5656
  • code/branches/network/src/network/Client.cc

    r1505 r1518  
    4242#include "Synchronisable.h"
    4343#include "core/CoreIncludes.h"
     44#include "core/ConsoleCommand.h"
     45#include "Server.h"
    4446
    4547namespace network
    4648{
     49  SetConsoleCommandShortcut(Client, Chat);
     50 
    4751  Client* Client::_sClient = 0;
    4852 
     
    142146 
    143147
     148  void Client::Chat( std::string message ){
     149    if(Client::getSingleton())
     150      Client::getSingleton()->sendChat(message);
     151    else if(Server::getSingleton())
     152      Server::getSingleton()->sendChat(message);
     153  }
    144154 
    145155
     
    224234  }
    225235
    226   void Client::processChat( chat *data){
    227     COUT(0) << "Server: " << data->message << std::endl;
     236  void Client::processChat( chat *data, int clientId){
     237    COUT(1) << data->message << std::endl;
    228238    delete[] data->message;
    229239    delete data;
  • code/branches/network/src/network/Client.h

    r1505 r1518  
    7575    bool closeConnection();
    7676
    77     bool sendChat( std::string message );
     77    static void Chat( std::string message );
    7878   
    7979    int getShipID(){return shipID_;}
     
    9696    bool isSynched_;
    9797
     98    bool sendChat( std::string message );
     99   
    98100    // implement data processing functions of PacketDecoder
    99101    void processGamestate( GameStateCompressed *data, int clientID);
    100102    void processClassid(classid *clid);
    101     void processChat( chat *data);
     103    void processChat( chat *data, int clientId );
    102104    bool processWelcome( welcome *w );
    103105    int clientID_;     // this is the id the server gave to us
  • code/branches/network/src/network/ConnectionManager.cc

    r1505 r1518  
    168168    boost::recursive_mutex::scoped_lock lock(enet_mutex_);
    169169    for(ClientInformation *i=head_->next(); i!=0; i=i->next()){
    170       if(enet_peer_send(i->getPeer(), (enet_uint8)i->getID(), packet)!=0)
     170      COUT(3) << "adding broadcast packet for client: " << i->getID() << std::endl;
     171      if(enet_peer_send(i->getPeer(), 0, packet)!=0)
    171172        return false;
    172173    }
  • code/branches/network/src/network/Server.cc

    r1516 r1518  
    5151#include "util/Sleep.h"
    5252#include "objects/SpaceShip.h"
    53 
     53#include "core/ConsoleCommand.h"
    5454
    5555namespace network
    5656{
    57  
    58  
    59 #define MAX_FAILURES 20;
    60 #define NETWORK_FREQUENCY 30
     57  #define MAX_FAILURES 20;
     58  #define NETWORK_FREQUENCY 30
     59 
     60  Server *Server::instance_=0;
     61 
     62  Server *Server::createSingleton(){
     63    if(!instance_)
     64      instance_ = new Server();
     65    return instance_;
     66  }
     67  Server *Server::createSingleton(int port){
     68    if(!instance_)
     69      instance_ = new Server(port);
     70    return instance_;
     71  }
     72  Server *Server::createSingleton(int port, std::string bindAddress){
     73    if(!instance_)
     74      instance_ = new Server(port, bindAddress);
     75    return instance_;
     76  }
     77  Server *Server::createSingleton(int port, const char *bindAddress){
     78    if(!instance_)
     79      instance_ = new Server(port, bindAddress);
     80    return instance_;
     81  }
     82 
     83  Server *Server::getSingleton(){
     84    return instance_;
     85  }
     86 
    6187 
    6288  /**
     
    127153  * @return true/false
    128154  */
    129   bool Server::sendMSG(std::string msg) {
    130     ENetPacket *packet = packet_gen.chatMessage(msg.c_str());
    131     //std::cout <<"adding packets" << std::endl;
    132     return connection->addPacketAll(packet);
     155  bool Server::sendChat(std::string msg) {
     156    return sendChat(msg.c_str());
    133157  }
    134158
     
    138162  * @return true/false
    139163  */
    140   bool Server::sendMSG(const char *msg) {
    141     ENetPacket *packet = packet_gen.chatMessage(msg);
    142     COUT(4) <<"Server: adding Packets" << std::endl;
     164  bool Server::sendChat(const char *msg) {
     165    char *message = new char [strlen(msg)+10+1];
     166    sprintf(message, "Player %d: %s", CLIENTID_SERVER, msg);
     167    COUT(1) << message << std::endl;
     168    ENetPacket *packet = packet_gen.chatMessage(message);
     169    COUT(5) <<"Server: adding Packets" << std::endl;
    143170    return connection->addPacketAll(packet);
    144171  }
     
    288315  }
    289316 
     317  void Server::processChat( chat *data, int clientId){
     318    char *message = new char [strlen(data->message)+10+1];
     319    sprintf(message, "Player %d: %s", clientId, data->message);
     320    COUT(1) << message << std::endl;
     321    ENetPacket *pck = packet_gen.chatMessage(message);
     322    connection->addPacketAll(pck);
     323    delete[] data->message;
     324    delete data;
     325  }
     326 
    290327  bool Server::addClient(ENetEvent *event){
    291328    ClientInformation *temp = clients->insertBack(new ClientInformation);
  • code/branches/network/src/network/Server.h

    r1505 r1518  
    5353namespace network
    5454{
     55  #define CLIENTID_SERVER 0
     56 
    5557  /**
    5658  * This class is the root class of the network module for a server.
     
    5961  class _NetworkExport Server : public PacketDecoder, public orxonox::Tickable{
    6062  public:
    61     Server();
    62     Server(int port);
    63     Server(int port, std::string bindAddress);
    64     Server(int port, const char *bindAddress);
     63    static Server *createSingleton();
     64    static Server *createSingleton(int port);
     65    static Server *createSingleton(int port, std::string bindAddress);
     66    static Server *createSingleton(int port, const char *bindAddress);
     67   
     68    static Server *getSingleton();
     69   
    6570    void open();
    6671    void close();
    67     bool sendMSG(std::string msg);
    68     bool sendMSG(const char *msg);
     72    bool sendChat(std::string msg);
     73    bool sendChat(const char *msg);
    6974    void tick(float time);
    7075  protected:
     
    7277    void updateGamestate();
    7378  private:
     79    Server();
     80    Server(int port);
     81    Server(int port, std::string bindAddress);
     82    Server(int port, const char *bindAddress);
     83   
     84    static Server *instance_;
     85   
    7486    bool addClient(ENetEvent *event);
    7587    bool createClient(int clientID);
     
    8294    bool processConnectRequest( connectRequest *con, int clientID );
    8395    void processGamestate( GameStateCompressed *data, int clientID);
     96    void processChat( chat *data, int clientId);
    8497    ConnectionManager *connection;
    8598    GameStateManager *gamestates;
  • code/branches/network/src/orxonox/Orxonox.cc

    r1512 r1518  
    127127      network::Client::destroySingleton();
    128128    if (server_g)
    129       delete server_g;
     129      delete network::Server::getSingleton();
    130130  }
    131131
     
    303303    COUT(2) << "Loading level in server mode" << std::endl;
    304304
    305     server_g = new network::Server(serverPort_);
     305    //server_g = new network::Server(serverPort_);
     306    server_g = network::Server::createSingleton(serverPort_);
    306307
    307308    if (!loadScene())
Note: See TracChangeset for help on using the changeset viewer.