[7611] | 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 | |
---|
[7745] | 29 | #ifndef MASTERSERVERCOMM_H |
---|
| 30 | #define MASTERSERVERCOMM_H |
---|
| 31 | |
---|
[7631] | 32 | #include <cstdlib> |
---|
| 33 | #include <cstdio> |
---|
[7650] | 34 | #include <string> |
---|
[7631] | 35 | #include <cstring> |
---|
| 36 | #include <enet/enet.h> |
---|
| 37 | |
---|
[7769] | 38 | |
---|
[7631] | 39 | namespace orxonox |
---|
[7611] | 40 | { |
---|
[7769] | 41 | class MasterServerComm |
---|
| 42 | { |
---|
[7631] | 43 | public: |
---|
| 44 | /** constructor */ |
---|
| 45 | MasterServerComm(); |
---|
[7611] | 46 | |
---|
[7631] | 47 | /** destructor */ |
---|
| 48 | ~MasterServerComm(); |
---|
[7611] | 49 | |
---|
[7631] | 50 | /** \return 0 for success, other for error |
---|
| 51 | * |
---|
| 52 | * Initialize everything for the master server communication |
---|
| 53 | */ |
---|
| 54 | int initialize(); |
---|
[7611] | 55 | |
---|
| 56 | |
---|
[7631] | 57 | /** \param address Address to connect to (Host name or IP in text form) |
---|
| 58 | * \param port Port to connect on |
---|
| 59 | * \return 0 for success, other for error |
---|
| 60 | * |
---|
| 61 | * Connect to the master server with the given address on the given port. |
---|
| 62 | */ |
---|
[7725] | 63 | int connect( const char *address, unsigned int port ); |
---|
[7611] | 64 | |
---|
[7761] | 65 | /** \return 0 for success, other for error |
---|
| 66 | * |
---|
| 67 | * Disconnect from master server. |
---|
| 68 | */ |
---|
[7763] | 69 | int disconnect( void ); |
---|
[7761] | 70 | |
---|
[7631] | 71 | /** \param data The data to be sent. |
---|
| 72 | * \return 0 for success, other for error. |
---|
| 73 | * |
---|
| 74 | * Send a request to the master server containing data specified in data |
---|
| 75 | */ |
---|
[7725] | 76 | int sendRequest( const char *data ); |
---|
[7611] | 77 | |
---|
[7650] | 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 | * (string version) |
---|
| 83 | */ |
---|
| 84 | int sendRequest( std::string data ); |
---|
| 85 | |
---|
[7631] | 86 | /** \param callback The callback function to call with data receivced. |
---|
| 87 | * \return 0 for success, other for error |
---|
| 88 | * |
---|
| 89 | * Poll the master server for new data and act accordingly */ |
---|
[7756] | 90 | int pollForReply( int (*callback)( char*, ENetEvent* ), int delayms ); |
---|
[7611] | 91 | |
---|
[7631] | 92 | private: |
---|
| 93 | /** client handle */ |
---|
| 94 | ENetHost *client; |
---|
[7611] | 95 | |
---|
[7631] | 96 | /** event data holder */ |
---|
[7684] | 97 | ENetEvent *event; |
---|
[7631] | 98 | |
---|
| 99 | /** address holder */ |
---|
| 100 | ENetAddress address; |
---|
| 101 | |
---|
| 102 | /** peer data holder */ |
---|
| 103 | ENetPeer *peer; |
---|
[7769] | 104 | }; |
---|
[7631] | 105 | |
---|
[7769] | 106 | } |
---|
[7745] | 107 | |
---|
| 108 | #endif /* MASTERSERVERCOMM_H */ |
---|