Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/netp5/src/network/Connection.h @ 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.4 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//
30// C++ Interface: Connection
31//
32// Description:
33//
34//
35// Author:  Oliver Scheuss, (C) 2007
36//
37// Copyright: See COPYING file that comes with this distribution
38//
39//
40#ifndef _Connection_H__
41#define _Connection_H__
42
43#include "NetworkPrereqs.h"
44
45#include <string>
46#include <map>
47#include <enet/enet.h>
48
49#include "packet/Packet.h"
50
51namespace orxonox
52{
53    const int NETWORK_PORT = 55556;
54    const int NETWORK_MAX_CONNECTIONS = 50;
55    const int NETWORK_WAIT_TIMEOUT = 1;
56    const int NETWORK_DEFAULT_CHANNEL = 0;
57
58//   struct _NetworkExport ClientList{
59//     ENetEvent *event;
60//     int ID;
61//     ClientList *next;
62//   };
63
64  class _NetworkExport Connection{
65  public:
66    ~Connection();
67   
68    static bool addPacket(ENetPacket *packet, ENetPeer *peer);
69    bool sendPackets();
70    ENetHost* getHost(){ return this->host_; }
71
72  protected:
73    Connection();
74    static Connection* getInstance(){ return Connection::instance_; }
75   
76    int service(ENetEvent* event){ return enet_host_service( this->host_, event, NETWORK_WAIT_TIMEOUT ); }
77    void disconnectPeer(ENetPeer *peer){ enet_peer_disconnect(peer, 0); }
78   
79    void processQueue();
80    virtual void addClient(ENetEvent* event)=0;
81    virtual void disconnectClient(ENetEvent* event)=0;
82    virtual bool processPacket(ENetEvent* event){ packet::Packet *p = packet::Packet::createPacket(event->packet, event->peer); return p->process(); }
83   
84    ENetHost *host_;
85  private:
86    ENetAddress *bindAddress_;
87
88    static Connection *instance_;
89
90  };
91
92}
93
94#endif /* _Connection_H__ */
Note: See TracBrowser for help on using the repository browser.