Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

merged network branch (windows,multiplayer fixes) back to trunk

  • Property svn:eol-style set to native
File size: 3.1 KB
RevLine 
[1502]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
[2756]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
[1502]52#include <enet/enet.h>
53#include <boost/thread/recursive_mutex.hpp>
54
55#include "PacketBuffer.h"
[1735]56#include "packet/Packet.h"
[1502]57
[1755]58namespace boost { class thread; }
59
[1502]60namespace std
61{
62  bool operator<(ENetAddress a, ENetAddress b);
63}
64
[2171]65namespace orxonox
[1502]66{
[1785]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;
[1502]71
[2087]72  struct _NetworkExport ClientList{
[1502]73    ENetEvent *event;
74    int ID;
75    ClientList *next;
76  };
77
[2087]78  class _NetworkExport ConnectionManager{
[1735]79    public:
80    static boost::recursive_mutex enet_mutex;
[1502]81    ConnectionManager();
[1735]82    ConnectionManager(int port);
83    ConnectionManager(int port, const char *address);
[2087]84    ConnectionManager(int port, const std::string& address);
[1735]85    ~ConnectionManager();
[1502]86    ENetEvent *getEvent();
87    bool queueEmpty();
88    void createListener();
89    bool quitListener();
[1735]90    static bool addPacket(ENetPacket *packet, ENetPeer *peer);
91    static bool addPacket(ENetPacket *packet, int ID);
92    static bool addPacketAll(ENetPacket *packet);
[1502]93    bool sendPackets();
94    void disconnectClient(ClientInformation *client);
[1735]95    void syncClassid(unsigned int clientID);
[1502]96
97  private:
98    bool processData(ENetEvent *event);
99    void receiverThread();
100    void disconnectClients();
101    int getClientID(ENetPeer peer);
102    int getClientID(ENetAddress address);
103    ENetPeer *getClientPeer(int clientID);
104    PacketBuffer buffer;
105
106    ENetHost *server;
107    ENetAddress bindAddress;
108
109    bool quit; // quit-variable (communication with threads)
110
111    boost::thread *receiverThread_;
[1735]112    static ConnectionManager *instance_;
113
[1502]114  };
115
116}
117
118#endif /* _ConnectionManager_H__ */
Note: See TracBrowser for help on using the repository browser.