Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/network/ConnectionManager.h @ 2757

Last change on this file since 2757 was 2756, checked in by rgrieder, 16 years ago

Minimising problems when including windows.h because it defines macros like "min" and "max" if not explicitly specified.
There are two headers we use that include windows.h: OgreWindowEventUtilities.h and enet.h. I had to tweak a little bit there as well.

  • Property svn:eol-style set to native
File size: 3.5 KB
Line 
1/*
2 *   ORXONOX - the hottest 3D action shooter ever to exist
3 *                    > www.orxonox.net <
4 *
5 *
6 *   License notice:
7 *
8 *   This program is free software; you can redistribute it and/or
9 *   modify it under the terms of the GNU General Public License
10 *   as published by the Free Software Foundation; either version 2
11 *   of the License, or (at your option) any later version.
12 *
13 *   This program is distributed in the hope that it will be useful,
14 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
15 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 *   GNU General Public License for more details.
17 *
18 *   You should have received a copy of the GNU General Public License
19 *   along with this program; if not, write to the Free Software
20 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21 *
22 *   Author:
23 *      Oliver Scheuss, (C) 2007
24 *   Co-authors:
25 *      ...
26 *
27 */
28
29//
30// C++ Interface: ConnectionManager
31//
32// Description:
33//
34//
35// Author:  Oliver Scheuss, (C) 2007
36//
37// Copyright: See COPYING file that comes with this distribution
38//
39//
40#ifndef _ConnectionManager_H__
41#define _ConnectionManager_H__
42
43#include "NetworkPrereqs.h"
44
45#include <string>
46#include <map>
47// enet library for networking support
48#ifndef WIN32_LEAN_AND_MEAN
49#  define WIN32_LEAN_AND_MEAN
50#endif
51#define NOMINMAX // required to stop windows.h screwing up std::min definition
52#include <enet/enet.h>
53#include <boost/thread/recursive_mutex.hpp>
54
55#include "PacketBuffer.h"
56#include "packet/Packet.h"
57
58namespace boost { class thread; }
59
60namespace std
61{
62  bool operator<(ENetAddress a, ENetAddress b);
63}
64
65namespace orxonox
66{
67    const int NETWORK_PORT = 55556;
68    const int NETWORK_MAX_CONNECTIONS = 50;
69    const int NETWORK_WAIT_TIMEOUT = 1;
70    const int NETWORK_DEFAULT_CHANNEL = 0;
71
72  struct _NetworkExport ClientList{
73    ENetEvent *event;
74    int ID;
75    ClientList *next;
76  };
77
78  class _NetworkExport ConnectionManager{
79    public:
80    static boost::recursive_mutex enet_mutex;
81    ConnectionManager();
82    //ConnectionManager(ClientInformation *head);
83    ConnectionManager(int port);
84    ConnectionManager(int port, const char *address);
85    ConnectionManager(int port, const std::string& address);
86    ~ConnectionManager();
87    //ENetPacket *getPacket(ENetAddress &address); // thread1
88    //ENetPacket *getPacket(int &clientID);
89    ENetEvent *getEvent();
90    bool queueEmpty();
91    void createListener();
92    bool quitListener();
93//     bool addPacket(Packet::Packet *packet);
94    static bool addPacket(ENetPacket *packet, ENetPeer *peer);
95    static bool addPacket(ENetPacket *packet, int ID);
96    static bool addPacketAll(ENetPacket *packet);
97  //  bool sendPackets(ENetEvent *event);
98    bool sendPackets();
99    //bool createClient(int clientID);
100    void disconnectClient(ClientInformation *client);
101    void syncClassid(unsigned int clientID);
102
103  private:
104//     bool clientDisconnect(ENetPeer *peer);
105//     bool removeClient(int clientID);
106    bool processData(ENetEvent *event);
107    //bool addClient(ENetEvent *event);
108    void receiverThread();
109    void disconnectClients();
110    int getClientID(ENetPeer peer);
111    int getClientID(ENetAddress address);
112    ENetPeer *getClientPeer(int clientID);
113    PacketBuffer buffer;
114
115    ENetHost *server;
116    ENetAddress bindAddress;
117
118    bool quit; // quit-variable (communication with threads)
119
120    boost::thread *receiverThread_;
121    static ConnectionManager *instance_;
122
123  };
124
125}
126
127#endif /* _ConnectionManager_H__ */
Note: See TracBrowser for help on using the repository browser.