Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/network2/src/network/ConnectionManager.h @ 1081

Last change on this file since 1081 was 1008, checked in by dumenim, 17 years ago

changed some comments and catched some return values and maybe some stuff we have to unchange

File size: 3.0 KB
Line 
1//
2// C++ Interface: ConnectionManager
3//
4// Description:
5//
6//
7// Author:  Oliver Scheuss, (C) 2007
8//
9// Copyright: See COPYING file that comes with this distribution
10//
11//
12#ifndef _ConnectionManager_H__
13#define _ConnectionManager_H__
14
15#include <string>
16#include <map>
17// enet library for networking support
18#include <enet/enet.h>
19
20#include "NetworkPrereqs.h"
21#include "PacketBuffer.h"
22#include "PacketManager.h"
23
24namespace std
25{
26  bool operator<(ENetAddress a, ENetAddress b);
27}
28
29namespace network
30{
31#define NETWORK_PORT 55556
32#define NETWORK_MAX_CONNECTIONS 50
33#define NETWORK_WAIT_TIMEOUT 5000
34#define NETWORK_SEND_WAIT 5
35
36  struct ClientList{
37    ENetEvent *event;
38    int ID;
39    ClientList *next;
40  };
41
42  class ConnectionManager{
43  public:
44    ConnectionManager(ClientInformation *head);
45    ConnectionManager(int port, const char *address, ClientInformation *head);
46    ConnectionManager(int port, std::string address, ClientInformation *head);
47    ENetPacket *getPacket(ENetAddress &address); // thread1
48    ENetPacket *getPacket(int &clientID);
49    bool queueEmpty();
50    void createListener();
51    bool quitListener();
52    bool addPacket(ENetPacket *packet, ENetPeer *peer);
53    bool addPacket(ENetPacket *packet, int ID);
54    bool addPacketAll(ENetPacket *packet);
55    bool sendPackets(ENetEvent *event);
56    bool sendPackets();
57
58    //##### for testing purpose only #####
59    ConnectionManager();
60    std::map<int, int> testGetClientsShip() { 
61      return clientsShip; 
62    }
63    void testAddClientsShipID( int clientID, int objectID ) {
64      addClientsObjectID( clientID, objectID );
65    }
66    int testGetClientsShipID( int clientID ) { 
67      return getClientsShipID( clientID ); 
68    }
69    int testGetObjectsClientID( int objectID ) {
70       return getObjectsClientID( objectID );
71    }
72    void testDeleteClientsIDReg( int clientID ) { 
73      deleteClientIDReg( clientID );
74    }
75    void testDeleteObjectIDReg( int objectID ) {
76      deleteObjectIDReg( objectID );
77    }
78    //##### for testing purpose only #####
79  private:
80    bool clientDisconnect(ENetPeer *peer);
81    //bool clientDisconnect(ENetPeer peer);
82    bool processData(ENetEvent *event);
83    bool addClient(ENetEvent *event);
84    void receiverThread();
85    void disconnectClients();
86    int getClientID(ENetPeer peer);
87    int getClientID(ENetAddress address);
88    void syncClassid(int clientID);
89    ENetPeer *getClientPeer(int clientID);
90    PacketBuffer buffer;
91    PacketGenerator packet_gen;
92
93    ENetHost *server;
94    ENetAddress bindAddress;
95
96    bool quit; // quit-variable (communication with threads)
97    ClientInformation *head_;
98   
99    //functions to map what object every clients uses
100    std::map<int, int> clientsShip;
101    void addClientsObjectID( int clientID, int objectID );
102    int getClientsShipID( int clientID );
103    int getObjectsClientID( int objectID );
104    void deleteClientIDReg( int clientID );
105    void deleteObjectIDReg( int objectID );
106    int getNumberOfClients();
107  };
108
109}
110
111#endif /* _ConnectionManager_H__ */
Note: See TracBrowser for help on using the repository browser.