Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Oct 12, 2008, 7:40:47 PM (16 years ago)
Author:
scheusso
Message:

merged network branch back to trunk

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/trunk/src/network/packet/Chat.cc

    r1763 r1907  
    2929#include "Chat.h"
    3030#include <assert.h>
     31#include "network/Host.h"
    3132
    3233namespace network {
    3334namespace packet {
    3435 
    35 #define PACKET_FLAGS_CHAT ENET_PACKET_FLAG_RELIABLE
    36 #define _PACKETID         0
    37 #define _MESSAGELENGTH    _PACKETID + sizeof(ENUM::Type)
    38 #define _MESSAGE          _MESSAGELENGTH + sizeof(unsigned int)
     36#define   PACKET_FLAGS_CHAT ENET_PACKET_FLAG_RELIABLE
     37#define   _PACKETID         0
     38const int _PLAYERID     =   _PACKETID + sizeof(ENUM::Type);
     39#define   _MESSAGELENGTH    _PLAYERID + sizeof(uint32_t)
     40#define   _MESSAGE          _MESSAGELENGTH + sizeof(uint32_t)
    3941
    40 Chat::Chat( std::string& message, int clientID )
     42Chat::Chat( std::string message, unsigned int playerID )
    4143 : Packet()
    4244{
     
    4446  messageLength_ = message.length()+1;
    4547  data_=new unsigned char[ getSize() ];
    46   *(ENUM::Type *)&data_[ _PACKETID ] = ENUM::Chat;
    47   *(unsigned int *)&data_[ _MESSAGELENGTH ] = messageLength_;
    48   memcpy( &data_[ _MESSAGE ], (void *)message.c_str(), messageLength_ );
    49   clientID_=clientID;
     48  *(ENUM::Type *)(data_ + _PACKETID ) = ENUM::Chat;
     49  *(unsigned int *)(data_ + _PLAYERID ) = playerID;
     50  *(unsigned int *)(data_ + _MESSAGELENGTH ) = messageLength_;
     51  memcpy( data_+_MESSAGE, (void *)message.c_str(), messageLength_ );
    5052}
    5153
    52 Chat::Chat( unsigned char *data, int clientID )
     54Chat::Chat( uint8_t* data, unsigned int clientID )
    5355  : Packet(data, clientID)
    5456{
    55   messageLength_ = *(unsigned int *)&data[ _MESSAGELENGTH ];
     57  messageLength_ = *(uint32_t *)(data + _MESSAGELENGTH );
    5658}
    5759
     
    6567
    6668bool Chat::process(){
    67   //TODO: change this !!!
    68   assert(0);
     69  bool b = Host::incomingChat(std::string((const char*)data_+_MESSAGE), *(uint32_t *)(data_+_PLAYERID));
    6970  delete this;
    70   return true;
     71  return b;
    7172}
    7273
    7374unsigned char *Chat::getMessage(){
    74   return &data_[ _MESSAGE ];
     75  return data_ + _MESSAGE;
    7576}
    7677
Note: See TracChangeset for help on using the changeset viewer.