Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 1532 was 1505, checked in by rgrieder, 17 years ago

f* svn: It doesn't even inform you if you attempt to set a non existing property. It is svn:eol-style and not eol-style when using the command by the way…

  • Property svn:eol-style set to native
File size: 3.8 KB
RevLine 
[1502]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 "PacketManager.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
66  struct ClientList{
67    ENetEvent *event;
68    int ID;
69    ClientList *next;
70  };
71
72  class ConnectionManager{
73  public:
74    ConnectionManager();
75    ConnectionManager(ClientInformation *head);
76    ConnectionManager(ClientInformation *head, int port);
77    ConnectionManager(int port, const char *address, ClientInformation *head);
78    ConnectionManager(int port, std::string address, ClientInformation *head);
79    //ENetPacket *getPacket(ENetAddress &address); // thread1
80    //ENetPacket *getPacket(int &clientID);
81    ENetEvent *getEvent();
82    bool queueEmpty();
83    void createListener();
84    bool quitListener();
85    bool addPacket(ENetPacket *packet, ENetPeer *peer);
86    bool addPacket(ENetPacket *packet, int ID);
87    bool addPacketAll(ENetPacket *packet);
88  //  bool sendPackets(ENetEvent *event);
89    bool sendPackets();
90    //bool createClient(int clientID);
91    void disconnectClient(ClientInformation *client);
92    void syncClassid(int clientID);
93    bool sendWelcome(int clientID, int shipID, bool allowed);
94
95  private:
96//     bool clientDisconnect(ENetPeer *peer);
97//     bool removeClient(int clientID);
98    bool processData(ENetEvent *event);
99    //bool addClient(ENetEvent *event);
100    void receiverThread();
101    void disconnectClients();
102    int getClientID(ENetPeer peer);
103    int getClientID(ENetAddress address);
104    ENetPeer *getClientPeer(int clientID);
105    //bool createShip(ClientInformation *client);
106    bool removeShip(ClientInformation *client);
107    bool addFakeConnectRequest(ENetEvent *ev);
108    PacketBuffer buffer;
109    PacketGenerator packet_gen;
110
111    ENetHost *server;
112    ENetAddress bindAddress;
113
114    bool quit; // quit-variable (communication with threads)
115    ClientInformation *head_;
116
117    boost::thread *receiverThread_;
118    static boost::recursive_mutex enet_mutex_;
119//     int getNumberOfClients();
120    //functions to map what object every clients uses
121    /*std::map<int, int> clientsShip;
122    void addClientsObjectID( int clientID, int objectID );
123    int getClientsShipID( int clientID );
124    int getObjectsClientID( int objectID );
125    void deleteClientIDReg( int clientID );
126    void deleteObjectIDReg( int objectID );*/
127  };
128
129}
130
131#endif /* _ConnectionManager_H__ */
Note: See TracBrowser for help on using the repository browser.