| [1711] | 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 |  | 
|---|
| [1705] | 32 | #include "Welcome.h" | 
|---|
| [1711] | 33 | #include "network/Host.h" | 
|---|
| [1751] | 34 | #include "network/Synchronisable.h" | 
|---|
| [1732] | 35 | #include "core/CoreIncludes.h" | 
|---|
| [1709] | 36 | #include <assert.h> | 
|---|
| [1705] | 37 |  | 
|---|
| [2112] | 38 | namespace orxonox { | 
|---|
| [1705] | 39 | namespace packet { | 
|---|
|  | 40 |  | 
|---|
|  | 41 | #define PACKET_FLAGS_CLASSID  ENET_PACKET_FLAG_RELIABLE | 
|---|
|  | 42 | #define _PACKETID             0 | 
|---|
|  | 43 | #define _CLIENTID             _PACKETID + sizeof(ENUM::Type) | 
|---|
| [1907] | 44 | #define _SHIPID               _CLIENTID + sizeof(uint32_t) | 
|---|
| [1705] | 45 |  | 
|---|
|  | 46 | Welcome::Welcome( unsigned int clientID, unsigned int shipID ) | 
|---|
| [1711] | 47 | : Packet() | 
|---|
| [1705] | 48 | { | 
|---|
|  | 49 | flags_ = flags_ | PACKET_FLAGS_CLASSID; | 
|---|
| [1709] | 50 | assert(getSize()); | 
|---|
| [1907] | 51 | data_=new uint8_t[ getSize() ]; | 
|---|
| [1709] | 52 | assert(data_); | 
|---|
| [1713] | 53 | *(packet::ENUM::Type *)(data_ + _PACKETID ) = packet::ENUM::Welcome; | 
|---|
| [1907] | 54 | *(uint32_t *)&data_[ _CLIENTID ] = clientID; | 
|---|
|  | 55 | *(uint32_t *)&data_[ _SHIPID ] = shipID; | 
|---|
| [1705] | 56 | } | 
|---|
|  | 57 |  | 
|---|
| [1907] | 58 | Welcome::Welcome( uint8_t* data, unsigned int clientID ) | 
|---|
| [1711] | 59 | : Packet(data, clientID) | 
|---|
| [1705] | 60 | { | 
|---|
|  | 61 | } | 
|---|
|  | 62 |  | 
|---|
|  | 63 | Welcome::~Welcome() | 
|---|
|  | 64 | { | 
|---|
|  | 65 | } | 
|---|
|  | 66 |  | 
|---|
| [1907] | 67 | uint8_t *Welcome::getData(){ | 
|---|
| [1705] | 68 | return data_; | 
|---|
|  | 69 | } | 
|---|
|  | 70 |  | 
|---|
|  | 71 | unsigned int Welcome::getSize() const{ | 
|---|
| [2112] | 72 | return sizeof(packet::ENUM::Type) + 2*sizeof(uint32_t); | 
|---|
| [1705] | 73 | } | 
|---|
|  | 74 |  | 
|---|
|  | 75 | bool Welcome::process(){ | 
|---|
|  | 76 | unsigned int shipID, clientID; | 
|---|
| [1907] | 77 | clientID = *(uint32_t *)&data_[ _CLIENTID ]; | 
|---|
|  | 78 | shipID = *(uint32_t *)&data_[ _SHIPID ]; | 
|---|
| [1711] | 79 | Host::setClientID(clientID); | 
|---|
|  | 80 | Host::setShipID(shipID); | 
|---|
| [1732] | 81 | COUT(3) << "Welcome set clientId: " << clientID << " shipID: " << shipID << std::endl; | 
|---|
| [1751] | 82 | Synchronisable::setClient(true); | 
|---|
| [1711] | 83 | delete this; | 
|---|
| [1705] | 84 | return true; | 
|---|
|  | 85 | } | 
|---|
|  | 86 |  | 
|---|
|  | 87 |  | 
|---|
|  | 88 | } //namespace packet | 
|---|
| [2112] | 89 | }//namespace orxonox | 
|---|