Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/tutorial/src/network/ConnectionManager.h @ 992

Last change on this file since 992 was 859, checked in by landauf, 17 years ago

more or less a copy of the trunk

File size: 1.9 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
23namespace std
24{
25  bool operator<(ENetAddress a, ENetAddress b);
26}
27
28namespace network
29{
30#define NETWORK_PORT 55556
31#define NETWORK_MAX_CONNECTIONS 50
32#define NETWORK_WAIT_TIMEOUT 5000
33#define NETWORK_SEND_WAIT 5
34
35  struct ClientList{
36    ENetEvent *event;
37    int ID;
38    ClientList *next;
39  };
40
41  class ConnectionManager{
42  public:
43    ConnectionManager(ClientInformation *head);
44    ConnectionManager(int port, const char *address, ClientInformation *head);
45    ConnectionManager(int port, std::string address, ClientInformation *head);
46    ENetPacket *getPacket(ENetAddress &address); // thread1
47    ENetPacket *getPacket(int &clientID);
48    bool queueEmpty();
49    void createListener();
50    bool quitListener();
51    bool addPacket(ENetPacket *packet, ENetPeer *peer);
52    bool addPacket(ENetPacket *packet, int ID);
53    bool addPacketAll(ENetPacket *packet);
54    bool sendPackets(ENetEvent *event);
55    bool sendPackets();
56  private:
57    bool clientDisconnect(ENetPeer *peer);
58    //bool clientDisconnect(ENetPeer peer);
59    bool processData(ENetEvent *event);
60    bool addClient(ENetEvent *event);
61    void receiverThread();
62    void disconnectClients();
63    int getClientID(ENetPeer peer);
64    int getClientID(ENetAddress address);
65    void syncClassid(int clientID);
66    ENetPeer *getClientPeer(int clientID);
67    PacketBuffer buffer;
68    PacketGenerator packet_gen;
69
70    ENetHost *server;
71    ENetAddress bindAddress;
72
73    bool quit; // quit-variable (communication with threads)
74    ClientInformation *head_;
75  };
76
77
78
79
80
81
82
83
84}
85
86#endif /* _ConnectionManager_H__ */
Note: See TracBrowser for help on using the repository browser.