| 1 |
// Copyright © 2001-2004 Rob Kaper <[email protected]>, |
| 2 |
// 2001 Erik Bourget <[email protected]> |
| 3 |
// 2010-2015 Sylvain Rochet <[email protected]> |
| 4 |
// |
| 5 |
// This program is free software; you can redistribute it and/or |
| 6 |
// modify it under the terms of the GNU General Public License |
| 7 |
// version 2 as published by the Free Software Foundation. |
| 8 |
// |
| 9 |
// This program is distributed in the hope that it will be useful, |
| 10 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 12 |
// General Public License for more details. |
| 13 |
// |
| 14 |
// You should have received a copy of the GNU General Public License |
| 15 |
// along with this program; see the file COPYING. If not, see |
| 16 |
// <http://www.gnu.org/licenses/>. |
| 17 |
|
| 18 |
#ifndef __MONOPD_SERVER_H__ |
| 19 |
#define __MONOPD_SERVER_H__ |
| 20 |
|
| 21 |
#include "gameobject.h" |
| 22 |
#include "listener.h" |
| 23 |
|
| 24 |
#include <sys/types.h> |
| 25 |
#include <sys/socket.h> |
| 26 |
#include <netdb.h> |
| 27 |
#include <string> |
| 28 |
|
| 29 |
class Auction; |
| 30 |
class GameConfig; |
| 31 |
class Event; |
| 32 |
class Game; |
| 33 |
class Player; |
| 34 |
class Socket; |
| 35 |
|
| 36 |
class MonopdServer : public GameObject |
| 37 |
{ |
| 38 |
public: |
| 39 |
MonopdServer(int argc, char **argv); |
| 40 |
~MonopdServer(); |
| 41 |
|
| 42 |
void closedSocket(Socket *socket); |
| 43 |
Game *findGame(Player *player); |
| 44 |
void delGame(Game *game, bool verbose = true); |
| 45 |
Player *findPlayer(Socket *socket); |
| 46 |
void delPlayer(Player *player); |
| 47 |
|
| 48 |
void welcomeNew(Socket *socket); |
| 49 |
void welcomeMetaserver(Socket *socket); |
| 50 |
void closedMetaserver(Socket *socket); |
| 51 |
void processInput(Socket *socket, const std::string data2); |
| 52 |
int timeleftEvent(); |
| 53 |
|
| 54 |
private: |
| 55 |
void updateSystemdStatus(); |
| 56 |
|
| 57 |
Event *newEvent(unsigned int eventType, Game *game = 0, int id = 0); |
| 58 |
Event *findEvent(Auction *auction); |
| 59 |
Event *findEvent(Game *game, unsigned int eventType); |
| 60 |
Event *findEvent(Game *game, GameObject *object); |
| 61 |
void delEvent(Event *event); |
| 62 |
void processEvents(); |
| 63 |
Game *findGame(int gameId); |
| 64 |
GameConfig *newGameConfig(const std::string id, const std::string name, const std::string description); |
| 65 |
void delGameConfig(GameConfig *gameConfig); |
| 66 |
Player *findPlayer(int playerId); |
| 67 |
Player *findPlayer(const std::string &name); |
| 68 |
Player *findCookie(const std::string &cookie); |
| 69 |
|
| 70 |
void newGame(Player *player, const std::string gameType); |
| 71 |
void joinGame(Player *player, unsigned int gameId, const bool &specator = false); |
| 72 |
void exitGame(Game *game, Player *player); |
| 73 |
void setGameDescription(Player *pInput, std::string data); |
| 74 |
void reconnectPlayer(Player *player, const std::string &cookie); |
| 75 |
|
| 76 |
void registerMetaserver(); |
| 77 |
void loadConfig(); |
| 78 |
void loadGameTemplates(); |
| 79 |
void ioWrite(const char *data, ...); |
| 80 |
void ioWrite(const std::string &data, const bool &noGameOnly = false); |
| 81 |
void sendGameTemplateList(Player *player); |
| 82 |
void sendXMLUpdates(); |
| 83 |
void sendXMLUpdate(Player *player, bool fullUpdate = false, bool excludeSelf = false); |
| 84 |
void setPlayerName(Player *player, std::string name); |
| 85 |
void setPlayerImage(Player *player, std::string image); |
| 86 |
|
| 87 |
std::vector<Event *> m_events; |
| 88 |
std::vector<Game *> m_games; |
| 89 |
std::vector<GameConfig *> m_gameConfigs; |
| 90 |
std::vector<Player *> m_players; |
| 91 |
|
| 92 |
Listener *m_listener; |
| 93 |
unsigned int m_nextGameId, m_nextPlayerId; |
| 94 |
std::string m_metaserverIdentity, m_metaserverHost; |
| 95 |
int m_port, m_metaserverPort; |
| 96 |
bool m_useMetaserver; |
| 97 |
bool m_metaserverBusy; |
| 98 |
Event *m_metaserverEvent; |
| 99 |
struct addrinfo *m_metaserverAddrinfo; |
| 100 |
}; |
| 101 |
|
| 102 |
#endif |