/* * ORXONOX - the hottest 3D action shooter ever to exist * > www.orxonox.net < * * * License notice: * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * * Author: * Sandro 'smerkli' Merkli * Co-authors: * ... * */ #ifndef MASTERSERVERCOMM_H #define MASTERSERVERCOMM_H #include #include #include #include #include #include "util/Singleton.h" #include "core/OrxonoxClass.h" #include "core/CoreIncludes.h" #include "NetworkPrereqs.h" // tolua_begin namespace orxonox { class _NetworkExport MasterServerComm // tolua_end : public Singleton, public OrxonoxClass { // tolua_export friend class Singleton; public: /** constructor */ MasterServerComm(); /** destructor */ ~MasterServerComm(); /** \return 0 for success, other for error * * Initialize everything for the master server communication */ int initialize(); /** \param address Address to connect to (Host name or IP in text form) * \param port Port to connect on * \return 0 for success, other for error * * Connect to the master server with the given address on the given port. */ int connect( const char *address, unsigned int port ); /** \return 0 for success, other for error * * Disconnect from master server. */ int disconnect( void ); /** \param data The data to be sent. * \return 0 for success, other for error. * * Send a request to the master server containing data specified in data */ int sendRequest( const char *data ); /** \param data The data to be sent. * \return 0 for success, other for error. * * Send a request to the master server containing data specified in data * (string version) */ int sendRequest( std::string data ); /** \param callback The callback function to call with data receivced. * \return 0 for success, other for error * * Poll the master server for new data and act accordingly */ int pollForReply( int (*callback)( char*, ENetEvent* ), int delayms ); /** \return an instance of MasterServerComm * * Create and return an instance of MasterServerComm. */ static MasterServerComm& getInstance() { return Singleton::getInstance(); } // tolua_export private: /** client handle */ ENetHost *client; /** event data holder */ ENetEvent *event; /** address holder */ ENetAddress address; /** peer data holder */ ENetPeer *peer; /** Singleton pointer */ static MasterServerComm *singletonPtr_s; }; // tolua_export } // tolua_export #endif /* MASTERSERVERCOMM_H */