Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 1049 was 1021, checked in by bknecht, 17 years ago

merged back that script-branch

File size: 2.3 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  private:
58    bool clientDisconnect(ENetPeer *peer);
59    //bool clientDisconnect(ENetPeer peer);
60    bool processData(ENetEvent *event);
61    bool addClient(ENetEvent *event);
62    void receiverThread();
63    void disconnectClients();
64    int getClientID(ENetPeer peer);
65    int getClientID(ENetAddress address);
66    void syncClassid(int clientID);
67    ENetPeer *getClientPeer(int clientID);
68    PacketBuffer buffer;
69    PacketGenerator packet_gen;
70
71    ENetHost *server;
72    ENetAddress bindAddress;
73
74    bool quit; // quit-variable (communication with threads)
75    ClientInformation *head_;
76   
77    //functions to map what object every clients uses
78    std::map<int, int> clientsShip;
79    void addClientsObjectID( int clientID, int objectID );
80    int getClientsShipID( int clientID );
81    int getObjectsClientID( int objectID );
82    void deleteClientIDReg( int clientID );
83    void deleteObjectIDReg( int objectID );
84  };
85
86
87
88
89
90
91
92
93}
94
95#endif /* _ConnectionManager_H__ */
Note: See TracBrowser for help on using the repository browser.