Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/network/src/network/packet/Welcome.cc @ 1711

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

we use enetcallback for destroying packets now (unfortunately there are still some problems)

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