[1711] | 1 | /* |
---|
| 2 | * ORXONOX - the hottest 3D action shooter ever to exist |
---|
| 3 | * > www.orxonox.net < |
---|
| 4 | * |
---|
| 5 | * |
---|
| 6 | * License notice: |
---|
| 7 | * |
---|
| 8 | * This program is free software; you can redistribute it and/or |
---|
| 9 | * modify it under the terms of the GNU General Public License |
---|
| 10 | * as published by the Free Software Foundation; either version 2 |
---|
| 11 | * of the License, or (at your option) any later version. |
---|
| 12 | * |
---|
| 13 | * This program is distributed in the hope that it will be useful, |
---|
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 16 | * GNU General Public License for more details. |
---|
| 17 | * |
---|
| 18 | * You should have received a copy of the GNU General Public License |
---|
| 19 | * along with this program; if not, write to the Free Software |
---|
| 20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
---|
| 21 | * |
---|
| 22 | * Author: |
---|
| 23 | * Oliver Scheuss <scheusso [at] ee.ethz.ch>, (C) 2008 |
---|
| 24 | * Co-authors: |
---|
| 25 | * ... |
---|
| 26 | * |
---|
| 27 | */ |
---|
| 28 | |
---|
[1701] | 29 | #include "Chat.h" |
---|
[1711] | 30 | #include <assert.h> |
---|
[1701] | 31 | |
---|
| 32 | namespace network { |
---|
| 33 | namespace packet { |
---|
| 34 | |
---|
| 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) |
---|
| 39 | |
---|
| 40 | Chat::Chat( std::string& message, int clientID ) |
---|
[1711] | 41 | : Packet() |
---|
[1701] | 42 | { |
---|
| 43 | flags_ = flags_ | PACKET_FLAGS_CHAT; |
---|
| 44 | messageLength_ = message.length()+1; |
---|
| 45 | data_=new unsigned char[ getSize() ]; |
---|
[1712] | 46 | *(ENUM::Type *)&data_[ _PACKETID ] = ENUM::Chat; |
---|
[1701] | 47 | *(unsigned int *)&data_[ _MESSAGELENGTH ] = messageLength_; |
---|
| 48 | memcpy( &data_[ _MESSAGE ], (void *)message.c_str(), messageLength_ ); |
---|
| 49 | clientID_=clientID; |
---|
| 50 | } |
---|
| 51 | |
---|
| 52 | Chat::Chat( unsigned char *data, int clientID ) |
---|
[1711] | 53 | : Packet(data, clientID) |
---|
[1701] | 54 | { |
---|
| 55 | messageLength_ = *(unsigned int *)&data[ _MESSAGELENGTH ]; |
---|
| 56 | } |
---|
| 57 | |
---|
| 58 | Chat::~Chat() |
---|
| 59 | { |
---|
| 60 | } |
---|
| 61 | |
---|
| 62 | unsigned int Chat::getSize() const{ |
---|
| 63 | return _MESSAGE + messageLength_; |
---|
| 64 | } |
---|
| 65 | |
---|
| 66 | bool Chat::process(){ |
---|
| 67 | //TODO: change this !!! |
---|
[1711] | 68 | assert(0); |
---|
| 69 | delete this; |
---|
[1701] | 70 | return true; |
---|
| 71 | } |
---|
| 72 | |
---|
| 73 | unsigned char *Chat::getMessage(){ |
---|
| 74 | return &data_[ _MESSAGE ]; |
---|
| 75 | } |
---|
| 76 | |
---|
| 77 | } //namespace packet |
---|
| 78 | } //namespace network |
---|