Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/archive/tutorialFS09/src/network/ConnectionManager.h @ 11634

Last change on this file since 11634 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
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(int port);
83    ConnectionManager(int port, const char *address);
84    ConnectionManager(int port, const std::string& address);
85    ~ConnectionManager();
86    ENetEvent *getEvent();
87    bool queueEmpty();
88    void createListener();
89    bool quitListener();
90    static bool addPacket(ENetPacket *packet, ENetPeer *peer);
91    static bool addPacket(ENetPacket *packet, int ID);
92    static bool addPacketAll(ENetPacket *packet);
93    bool sendPackets();
94    void disconnectClient(ClientInformation *client);
95    void syncClassid(unsigned int clientID);
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_;
112    static ConnectionManager *instance_;
113
114  };
115
116}
117
118#endif /* _ConnectionManager_H__ */
Note: See TracBrowser for help on using the repository browser.