[173] | 1 | // |
---|
| 2 | // C++ Interface: ConnectionManager |
---|
| 3 | // |
---|
[285] | 4 | // Description: |
---|
[173] | 5 | // |
---|
| 6 | // |
---|
[196] | 7 | // Author: Oliver Scheuss, (C) 2007 |
---|
[173] | 8 | // |
---|
| 9 | // Copyright: See COPYING file that comes with this distribution |
---|
| 10 | // |
---|
| 11 | // |
---|
| 12 | #ifndef NETWORK_CONNECTIONMANAGER_H |
---|
| 13 | #define NETWORK_CONNECTIONMANAGER_H |
---|
| 14 | |
---|
[196] | 15 | #include <iostream> |
---|
[230] | 16 | #include <string> |
---|
[380] | 17 | #include <map> |
---|
| 18 | #include <vector> |
---|
[196] | 19 | // enet library for networking support |
---|
| 20 | #include <enet/enet.h> |
---|
| 21 | // boost.thread library for multithreading support |
---|
| 22 | #include <boost/thread/thread.hpp> |
---|
| 23 | #include <boost/bind.hpp> |
---|
[380] | 24 | // headerfiles |
---|
[436] | 25 | #include "ClientInformation.h" |
---|
[285] | 26 | #include "ConnectionManager.h" |
---|
| 27 | #include "PacketBuffer.h" |
---|
[400] | 28 | #include "PacketManager.h" |
---|
| 29 | #include "orxonox/core/IdentifierIncludes.h" |
---|
[173] | 30 | |
---|
[381] | 31 | namespace std{ |
---|
| 32 | bool operator<(ENetAddress a, ENetAddress b); |
---|
| 33 | } |
---|
| 34 | |
---|
[173] | 35 | namespace network{ |
---|
| 36 | // |
---|
[211] | 37 | #define NETWORK_PORT 55556 |
---|
[173] | 38 | #define NETWORK_MAX_CONNECTIONS 50 |
---|
| 39 | #define NETWORK_WAIT_TIMEOUT 5000 |
---|
[196] | 40 | #define NETWORK_SEND_WAIT 5 |
---|
[285] | 41 | |
---|
[173] | 42 | struct ClientList{ |
---|
[196] | 43 | ENetEvent *event; |
---|
[173] | 44 | int ID; |
---|
| 45 | ClientList *next; |
---|
| 46 | }; |
---|
[381] | 47 | |
---|
[173] | 48 | class ConnectionManager{ |
---|
| 49 | public: |
---|
[436] | 50 | ConnectionManager(ClientInformation *head); |
---|
| 51 | ConnectionManager(int port, const char *address, ClientInformation *head); |
---|
| 52 | ConnectionManager(int port, std::string address, ClientInformation *head); |
---|
[204] | 53 | ENetPacket *getPacket(ENetAddress &address); // thread1 |
---|
[380] | 54 | ENetPacket *getPacket(int &clientID); |
---|
[196] | 55 | bool queueEmpty(); |
---|
| 56 | void createListener(); |
---|
| 57 | bool quitListener(); |
---|
| 58 | bool addPacket(ENetPacket *packet, ENetPeer *peer); |
---|
| 59 | bool addPacket(ENetPacket *packet, int ID); |
---|
| 60 | bool addPacketAll(ENetPacket *packet); |
---|
| 61 | bool sendPackets(ENetEvent *event); |
---|
[369] | 62 | bool sendPackets(); |
---|
[436] | 63 | private: |
---|
[196] | 64 | bool clientDisconnect(ENetPeer *peer); |
---|
[436] | 65 | //bool clientDisconnect(ENetPeer peer); |
---|
[196] | 66 | bool processData(ENetEvent *event); |
---|
| 67 | bool addClient(ENetEvent *event); |
---|
[380] | 68 | void receiverThread(); |
---|
[369] | 69 | void disconnectClients(); |
---|
[380] | 70 | int getClientID(ENetPeer peer); |
---|
| 71 | int getClientID(ENetAddress address); |
---|
[400] | 72 | void syncClassid(int clientID); |
---|
[436] | 73 | ENetPeer *getClientPeer(int clientID); |
---|
[173] | 74 | PacketBuffer buffer; |
---|
[400] | 75 | PacketGenerator packet_gen; |
---|
[380] | 76 | |
---|
[173] | 77 | ENetHost *server; |
---|
| 78 | ENetAddress bindAddress; |
---|
[380] | 79 | |
---|
| 80 | bool quit; // quit-variable (communication with threads) |
---|
[436] | 81 | ClientInformation *head_; |
---|
[173] | 82 | }; |
---|
[285] | 83 | |
---|
| 84 | |
---|
| 85 | |
---|
| 86 | |
---|
| 87 | |
---|
| 88 | |
---|
| 89 | |
---|
| 90 | |
---|
[173] | 91 | } |
---|
| 92 | |
---|
[196] | 93 | #endif |
---|