Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/network/src/network/ConnectionManager.h @ 1379

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

added command line argument —port

File size: 3.8 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
51#include "PacketBuffer.h"
52#include "PacketManager.h"
53
54namespace std
55{
56  bool operator<(ENetAddress a, ENetAddress b);
57}
58
59namespace network
60{
61#define NETWORK_PORT 55556
62#define NETWORK_MAX_CONNECTIONS 50
63#define NETWORK_WAIT_TIMEOUT 5000
64#define NETWORK_SEND_WAIT 5
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    bool queueEmpty();
82    void createListener();
83    bool quitListener();
84    bool addPacket(ENetPacket *packet, ENetPeer *peer);
85    bool addPacket(ENetPacket *packet, int ID);
86    bool addPacketAll(ENetPacket *packet);
87  //  bool sendPackets(ENetEvent *event);
88    bool sendPackets();
89    bool createClient(int clientID);
90    void disconnectClient(ClientInformation *client);
91
92  private:
93    bool clientDisconnect(ENetPeer *peer);
94    bool removeClient(int clientID);
95    bool processData(ENetEvent *event);
96    bool addClient(ENetEvent *event);
97    void receiverThread();
98    void disconnectClients();
99    int getClientID(ENetPeer peer);
100    int getClientID(ENetAddress address);
101    void syncClassid(int clientID);
102    ENetPeer *getClientPeer(int clientID);
103    bool createShip(ClientInformation *client);
104    bool removeShip(ClientInformation *client);
105    bool sendWelcome(int clientID, int shipID, bool allowed);
106    bool addFakeConnectRequest(ENetEvent *ev);
107    PacketBuffer buffer;
108    PacketGenerator packet_gen;
109
110    ENetHost *server;
111    ENetAddress bindAddress;
112
113    bool quit; // quit-variable (communication with threads)
114    ClientInformation *head_;
115
116    boost::thread *receiverThread_;
117//     int getNumberOfClients();
118    //functions to map what object every clients uses
119    /*std::map<int, int> clientsShip;
120    void addClientsObjectID( int clientID, int objectID );
121    int getClientsShipID( int clientID );
122    int getObjectsClientID( int objectID );
123    void deleteClientIDReg( int clientID );
124    void deleteObjectIDReg( int objectID );*/
125  };
126
127}
128
129#endif /* _ConnectionManager_H__ */
Note: See TracBrowser for help on using the repository browser.