Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/network/packet/Welcome.cc @ 1735

Last change on this file since 1735 was 1735, checked in by scheusso, 16 years ago

network branch merged into trunk

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