| 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 | #include "Welcome.h" | 
|---|
| 32 |  | 
|---|
| 33 | #include <cassert> | 
|---|
| 34 | #include "util/Output.h" | 
|---|
| 35 | #include "network/Host.h" | 
|---|
| 36 | #include "network/synchronisable/Synchronisable.h" | 
|---|
| 37 |  | 
|---|
| 38 | namespace orxonox { | 
|---|
| 39 | namespace packet { | 
|---|
| 40 |  | 
|---|
| 41 | #define PACKET_FLAGS_CLASSID  PacketFlag::Reliable | 
|---|
| 42 | #define _PACKETID             0 | 
|---|
| 43 | #define _CLIENTID             _PACKETID + sizeof(Type::Value) | 
|---|
| 44 | #define _ENDIANTEST           _CLIENTID + sizeof(uint32_t) | 
|---|
| 45 |  | 
|---|
| 46 | Welcome::Welcome( uint32_t clientID ) | 
|---|
| 47 | : Packet() | 
|---|
| 48 | { | 
|---|
| 49 | flags_ = flags_ | PACKET_FLAGS_CLASSID; | 
|---|
| 50 | assert(getSize()); | 
|---|
| 51 | data_=new uint8_t[ getSize() ]; | 
|---|
| 52 | assert(data_); | 
|---|
| 53 | *(packet::Type::Value *)(data_ + _PACKETID ) = packet::Type::Welcome; | 
|---|
| 54 | *(uint32_t *)(data_ + _CLIENTID ) = static_cast<uint32_t>(clientID); | 
|---|
| 55 | *(uint32_t *)(data_ + _ENDIANTEST ) = 0xFEDC4321; | 
|---|
| 56 | } | 
|---|
| 57 |  | 
|---|
| 58 | Welcome::Welcome( uint8_t* data, uint32_t clientID ) | 
|---|
| 59 | : Packet(data, clientID) | 
|---|
| 60 | { | 
|---|
| 61 | } | 
|---|
| 62 |  | 
|---|
| 63 | Welcome::~Welcome() | 
|---|
| 64 | { | 
|---|
| 65 | } | 
|---|
| 66 |  | 
|---|
| 67 | uint8_t *Welcome::getData(){ | 
|---|
| 68 | return data_; | 
|---|
| 69 | } | 
|---|
| 70 |  | 
|---|
| 71 | unsigned int Welcome::getSize() const{ | 
|---|
| 72 | return sizeof(packet::Type::Value) + 2*sizeof(uint32_t); | 
|---|
| 73 | } | 
|---|
| 74 |  | 
|---|
| 75 | bool Welcome::process(orxonox::Host* host){ | 
|---|
| 76 | uint32_t clientID; | 
|---|
| 77 | clientID = *(uint32_t *)(data_ + _CLIENTID ); | 
|---|
| 78 | assert(*(uint32_t *)(data_ + _ENDIANTEST ) == 0xFEDC4321); | 
|---|
| 79 | host->setClientID(clientID); | 
|---|
| 80 | orxout(internal_info, context::packets) << "Welcome set clientId: " << clientID << endl; | 
|---|
| 81 | Synchronisable::setClient(true); | 
|---|
| 82 | delete this; | 
|---|
| 83 | return true; | 
|---|
| 84 | } | 
|---|
| 85 |  | 
|---|
| 86 |  | 
|---|
| 87 | } //namespace packet | 
|---|
| 88 | }//namespace orxonox | 
|---|