Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/presentation/src/libraries/network/MasterServerComm.h @ 7768

Last change on this file since 7768 was 7768, checked in by smerkli, 13 years ago

fixes

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 *      Sandro 'smerkli' Merkli
24 *   Co-authors:
25 *      ...
26 *
27 */
28
29#ifndef MASTERSERVERCOMM_H
30#define MASTERSERVERCOMM_H
31
32#include <cstdlib>
33#include <cstdio>
34#include <string>
35#include <cstring>
36#include <enet/enet.h>
37#include "util/Singleton.h"
38#include "core/OrxonoxClass.h"
39#include "core/CoreIncludes.h"
40#include "NetworkPrereqs.h"
41
42// tolua_begin
43namespace orxonox
44{
45  class _NetworkExport MasterServerComm
46  // tolua_end
47    : public Singleton<MasterServerComm>, public OrxonoxClass
48  { // tolua_export
49    friend class Singleton<MasterServerComm>;
50    public: 
51      /** constructor */
52      MasterServerComm();
53
54      /** destructor */
55      ~MasterServerComm();
56
57      /** \return 0 for success, other for error
58       *
59       * Initialize everything for the master server communication
60       */
61      int initialize();
62
63
64      /** \param address Address to connect to (Host name or IP in text form)
65       * \param port Port to connect on
66       * \return 0 for success, other for error
67       *
68       * Connect to the master server with the given address on the given port.
69       */
70      int connect( const char *address, unsigned int port );
71
72      /** \return 0 for success, other for error
73       *
74       * Disconnect from master server.
75       */
76      int disconnect( void );
77
78      /** \param data The data to be sent.
79       * \return 0 for success, other for error.
80       *
81       * Send a request to the master server containing data specified in data
82       */
83      int sendRequest( const char *data );
84
85      /** \param data The data to be sent.
86       * \return 0 for success, other for error.
87       *
88       * Send a request to the master server containing data specified in data
89       * (string version)
90       */
91      int sendRequest( std::string data );
92
93      /** \param callback The callback function to call with data receivced.
94       * \return 0 for success, other for error
95       *
96       * Poll the master server for new data and act accordingly */
97      int pollForReply( int (*callback)( char*, ENetEvent* ), int delayms );
98
99      /** \return an instance of MasterServerComm
100       *
101       * Create and return an instance of  MasterServerComm.
102       */
103      static MasterServerComm& getInstance() { return Singleton<MasterServerComm>::getInstance(); } // tolua_export
104
105    private:
106      /** client handle */
107      ENetHost *client;
108
109      /** event data holder */
110      ENetEvent *event;
111
112      /** address holder */
113      ENetAddress address;
114
115      /** peer data holder */
116      ENetPeer *peer;
117
118      /** Singleton pointer */
119      static MasterServerComm *singletonPtr_s;
120  }; // tolua_export
121
122} // tolua_export
123
124#endif /* MASTERSERVERCOMM_H */
Note: See TracBrowser for help on using the repository browser.