Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/FICN/src/network/ConnectionManager.h @ 400

Last change on this file since 400 was 400, checked in by scheusso, 17 years ago

CLient, Server

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