Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/netp5/src/network/Connection.cc @ 3201

Last change on this file since 3201 was 3201, checked in by scheusso, 15 years ago

cleaned up server connection handling
client is yet to come

File size: 2.3 KB
Line 
1/*
2 *   ORXONOX - the hottest 3D action shooter ever to exist
3 *                    > www.orxonox.net <
4 *
5 *
6 *   License notice:
7 *
8 *   This program is free software; you can redistribute it and/or
9 *   modify it under the terms of the GNU General Public License
10 *   as published by the Free Software Foundation; either version 2
11 *   of the License, or (at your option) any later version.
12 *
13 *   This program is distributed in the hope that it will be useful,
14 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
15 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 *   GNU General Public License for more details.
17 *
18 *   You should have received a copy of the GNU General Public License
19 *   along with this program; if not, write to the Free Software
20 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21 *
22 *   Author:
23 *      Oliver Scheuss
24 *   Co-authors:
25 *      ...
26 *
27 */
28
29#include "Connection.h"
30
31#include <iostream>
32#include <cassert>
33
34#include "util/Debug.h"
35#include "util/Math.h"
36#include "util/Sleep.h"
37#include "ClientInformation.h"
38#include "synchronisable/Synchronisable.h"
39#include "packet/ClassID.h"
40
41namespace orxonox
42{
43  Connection *Connection::instance_=0;
44
45  Connection::Connection():
46    host_(0)
47  {
48    assert(instance_==0);
49    Connection::instance_=this;
50  }
51
52  Connection::~Connection(){
53    Connection::instance_=0;
54  }
55
56  bool Connection::addPacket(ENetPacket *packet, ENetPeer *peer) {
57    if(enet_peer_send(peer, NETWORK_DEFAULT_CHANNEL, packet)!=0)
58      return false;
59    else
60      return true;
61  }
62
63  bool Connection::sendPackets() {
64    if ( !Connection::instance_ || this->host_==NULL )
65      return false;
66    enet_host_flush(this->host_);
67    return true;
68  }
69
70  void Connection::processQueue() {
71    ENetEvent event;
72   
73    assert(this->host_);
74
75    if( enet_host_service( this->host_, &event, NETWORK_WAIT_TIMEOUT ) > 0 )
76    {
77      switch(event.type){
78        // log handling ================
79        case ENET_EVENT_TYPE_CONNECT:
80          addClient( &event );
81          break;
82        case ENET_EVENT_TYPE_DISCONNECT:
83          disconnectClient( &event );
84          break;
85        case ENET_EVENT_TYPE_RECEIVE:
86          processPacket( &event );
87          break;
88        case ENET_EVENT_TYPE_NONE:
89          break;
90      }
91    }
92  }
93
94}
Note: See TracBrowser for help on using the repository browser.