Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/network/ConnectionManager.h @ 1735

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

network branch merged into trunk

  • Property svn:eol-style set to native
File size: 3.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, (C) 2007
24 *   Co-authors:
25 *      ...
26 *
27 */
28
29//
30// C++ Interface: ConnectionManager
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 _ConnectionManager_H__
41#define _ConnectionManager_H__
42
43#include "NetworkPrereqs.h"
44
45#include <string>
46#include <map>
47// enet library for networking support
48#include <enet/enet.h>
49#include <boost/thread/thread.hpp>
50#include <boost/thread/recursive_mutex.hpp>
51
52#include "PacketBuffer.h"
53#include "packet/Packet.h"
54
55namespace std
56{
57  bool operator<(ENetAddress a, ENetAddress b);
58}
59
60namespace network
61{
62#define NETWORK_PORT 55556
63#define NETWORK_MAX_CONNECTIONS 50
64#define NETWORK_WAIT_TIMEOUT 1
65#define NETWORK_DEFAULT_CHANNEL 0
66
67  struct ClientList{
68    ENetEvent *event;
69    int ID;
70    ClientList *next;
71  };
72
73  class ConnectionManager{
74    public:
75    static boost::recursive_mutex enet_mutex;
76    ConnectionManager();
77    //ConnectionManager(ClientInformation *head);
78    ConnectionManager(int port);
79    ConnectionManager(int port, const char *address);
80    ConnectionManager(int port, std::string address);
81    ~ConnectionManager();
82    //ENetPacket *getPacket(ENetAddress &address); // thread1
83    //ENetPacket *getPacket(int &clientID);
84    ENetEvent *getEvent();
85    bool queueEmpty();
86    void createListener();
87    bool quitListener();
88//     bool addPacket(Packet::Packet *packet);
89    static bool addPacket(ENetPacket *packet, ENetPeer *peer);
90    static bool addPacket(ENetPacket *packet, int ID);
91    static bool addPacketAll(ENetPacket *packet);
92  //  bool sendPackets(ENetEvent *event);
93    bool sendPackets();
94    //bool createClient(int clientID);
95    void disconnectClient(ClientInformation *client);
96    void syncClassid(unsigned int clientID);
97
98  private:
99//     bool clientDisconnect(ENetPeer *peer);
100//     bool removeClient(int clientID);
101    bool processData(ENetEvent *event);
102    //bool addClient(ENetEvent *event);
103    void receiverThread();
104    void disconnectClients();
105    int getClientID(ENetPeer peer);
106    int getClientID(ENetAddress address);
107    ENetPeer *getClientPeer(int clientID);
108    //bool createShip(ClientInformation *client);
109    bool removeShip(ClientInformation *client);
110    PacketBuffer buffer;
111
112    ENetHost *server;
113    ENetAddress bindAddress;
114
115    bool quit; // quit-variable (communication with threads)
116
117    boost::thread *receiverThread_;
118    static ConnectionManager *instance_;
119
120  };
121
122}
123
124#endif /* _ConnectionManager_H__ */
Note: See TracBrowser for help on using the repository browser.