Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 369 was 369, checked in by scheusso, 16 years ago

PacketDecoder:

Extended Class to make inheriting easier…

-added virtual function, that can be implemented by lower classes

Client:

Added some function, changed some things (input, gamestate, connectionhandling)

Server:

same as client

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// enet library for networking support
18#include <enet/enet.h>
19// boost.thread library for multithreading support
20#include <boost/thread/thread.hpp>
21#include <boost/bind.hpp>
22// headerfile
23#include "ConnectionManager.h"
24#include "PacketBuffer.h"
25
26namespace network{
27  //
28#define NETWORK_PORT 55556
29#define NETWORK_MAX_CONNECTIONS 50
30#define NETWORK_WAIT_TIMEOUT 5000
31#define NETWORK_SEND_WAIT 5
32  //just some defines to make life easier ;)
33// #define ENetEvent std::ENetEvent
34// #define ENetHost std::ENetHost
35// #define ENetAddress std::ENetAddress
36// #define ENetPeer std::ENetPeer
37
38  struct ClientList{
39    ENetEvent *event;
40    int ID;
41    ClientList *next;
42  };
43
44  class ConnectionManager{
45    public:
46    ConnectionManager();
47    ConnectionManager(int port, const char *address);
48    ConnectionManager(int port, std::string address);
49    ENetPacket *getPacket(ENetAddress &address); // thread1
50    // check wheter the packet queue is empty
51    bool queueEmpty();
52    // create a new listener thread
53    void createListener();
54    bool quitListener();
55    // add a packet to queue for a specific client peer
56    bool addPacket(ENetPacket *packet, ENetPeer *peer);
57    // add ad packet to queue for a specific client ID
58    bool addPacket(ENetPacket *packet, int ID);
59    // add a packet to queue for all clients
60    bool addPacketAll(ENetPacket *packet);
61    // send out all queued packets
62    bool sendPackets(ENetEvent *event);
63    bool sendPackets();
64    private:
65    bool clientDisconnect(ENetPeer *peer);
66    bool processData(ENetEvent *event);
67    bool addClient(ENetEvent *event);
68    // implementation of the listener
69    void receiverThread(); //thread2
70    void disconnectClients();
71    //packetbuffer
72    PacketBuffer buffer;
73    // enet stuff
74    ENetHost *server;
75    ENetAddress bindAddress;
76    // quit-variable (communication with threads)
77    bool quit;
78    // clientlist
79    ClientList *client;
80//     thread group
81//     boost::thread_group threads;
82  };
83
84
85
86
87
88
89
90
91}
92
93#endif
Note: See TracBrowser for help on using the repository browser.