Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/network_old/src/network/ConnectionManager.h @ 937

Last change on this file since 937 was 880, checked in by dumenim, 17 years ago

some functions for clientID↔objectID mapping added

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// enet library for networking support
17#include <enet/enet.h>
18
19#include "NetworkPrereqs.h"
20#include "PacketBuffer.h"
21#include "PacketManager.h"
22#include "map"
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, std::string> clientsShip;
79    void regClientsObjectID( int clientID, std::string objectID );
80    std::string getClientsShipID( int clientID );
81    int getObjectsClientID( std::string objectID );
82    void deleteClientIDReg( int clientID );
83    void deleteObjectIDReg( std::string objectID );
84  };
85}
86
87#endif /* _ConnectionManager_H__ */
Note: See TracBrowser for help on using the repository browser.