| 1 |  | 
|---|
| 2 |  | 
|---|
| 3 | /* | 
|---|
| 4 |  *   ORXONOX - the hottest 3D action shooter ever to exist | 
|---|
| 5 |  *                    > www.orxonox.net < | 
|---|
| 6 |  * | 
|---|
| 7 |  * | 
|---|
| 8 |  *   License notice: | 
|---|
| 9 |  * | 
|---|
| 10 |  *   This program is free software; you can redistribute it and/or | 
|---|
| 11 |  *   modify it under the terms of the GNU General Public License | 
|---|
| 12 |  *   as published by the Free Software Foundation; either version 2 | 
|---|
| 13 |  *   of the License, or (at your option) any later version. | 
|---|
| 14 |  * | 
|---|
| 15 |  *   This program is distributed in the hope that it will be useful, | 
|---|
| 16 |  *   but WITHOUT ANY WARRANTY; without even the implied warranty of | 
|---|
| 17 |  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
|---|
| 18 |  *   GNU General Public License for more details. | 
|---|
| 19 |  * | 
|---|
| 20 |  *   You should have received a copy of the GNU General Public License | 
|---|
| 21 |  *   along with this program; if not, write to the Free Software | 
|---|
| 22 |  *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA. | 
|---|
| 23 |  * | 
|---|
| 24 |  *   Author: | 
|---|
| 25 |  *      Oliver Scheuss, (C) 2008 | 
|---|
| 26 |  *   Co-authors: | 
|---|
| 27 |  *      ... | 
|---|
| 28 |  * | 
|---|
| 29 |  */ | 
|---|
| 30 |  | 
|---|
| 31 |  | 
|---|
| 32 | #include "Welcome.h" | 
|---|
| 33 | #include <enet/enet.h> | 
|---|
| 34 | #include <cassert> | 
|---|
| 35 | #include "network/Host.h" | 
|---|
| 36 | #include "network/synchronisable/Synchronisable.h" | 
|---|
| 37 | #include "core/CoreIncludes.h" | 
|---|
| 38 |  | 
|---|
| 39 | namespace orxonox { | 
|---|
| 40 | namespace packet { | 
|---|
| 41 |  | 
|---|
| 42 | #define PACKET_FLAGS_CLASSID  ENET_PACKET_FLAG_RELIABLE | 
|---|
| 43 | #define _PACKETID             0 | 
|---|
| 44 | #define _CLIENTID             _PACKETID + sizeof(ENUM::Type) | 
|---|
| 45 | #define _ENDIANTEST           _CLIENTID + sizeof(uint32_t) | 
|---|
| 46 |  | 
|---|
| 47 |   Welcome::Welcome( uint32_t clientID, uint32_t shipID ) | 
|---|
| 48 |  : Packet() | 
|---|
| 49 | { | 
|---|
| 50 |   flags_ = flags_ | PACKET_FLAGS_CLASSID; | 
|---|
| 51 |   assert(getSize()); | 
|---|
| 52 |   data_=new uint8_t[ getSize() ]; | 
|---|
| 53 |   assert(data_); | 
|---|
| 54 |   *(packet::ENUM::Type *)(data_ + _PACKETID ) = packet::ENUM::Welcome; | 
|---|
| 55 |   *(uint32_t *)(data_ + _CLIENTID ) = static_cast<uint32_t>(clientID); | 
|---|
| 56 |   *(uint32_t *)(data_ + _ENDIANTEST ) = 0xFEDC4321; | 
|---|
| 57 | } | 
|---|
| 58 |  | 
|---|
| 59 | Welcome::Welcome( uint8_t* data, uint32_t clientID ) | 
|---|
| 60 |   : Packet(data, clientID) | 
|---|
| 61 | { | 
|---|
| 62 | } | 
|---|
| 63 |  | 
|---|
| 64 | Welcome::~Welcome() | 
|---|
| 65 | { | 
|---|
| 66 | } | 
|---|
| 67 |  | 
|---|
| 68 | uint8_t *Welcome::getData(){ | 
|---|
| 69 |   return data_; | 
|---|
| 70 | } | 
|---|
| 71 |  | 
|---|
| 72 | unsigned int Welcome::getSize() const{ | 
|---|
| 73 |   return sizeof(packet::ENUM::Type) + 2*sizeof(uint32_t); | 
|---|
| 74 | } | 
|---|
| 75 |  | 
|---|
| 76 | bool Welcome::process(){ | 
|---|
| 77 |   uint32_t clientID; | 
|---|
| 78 |   clientID = *(uint32_t *)(data_ + _CLIENTID ); | 
|---|
| 79 |   assert(*(uint32_t *)(data_ + _ENDIANTEST ) == 0xFEDC4321); | 
|---|
| 80 |   Host::setClientID(clientID); | 
|---|
| 81 |   COUT(3) << "Welcome set clientId: " << clientID << endl; | 
|---|
| 82 |   Synchronisable::setClient(true); | 
|---|
| 83 |   delete this; | 
|---|
| 84 |   return true; | 
|---|
| 85 | } | 
|---|
| 86 |  | 
|---|
| 87 |  | 
|---|
| 88 | } //namespace packet | 
|---|
| 89 | }//namespace orxonox | 
|---|