2010-03-27 07:09:34 +00:00
|
|
|
// ==============================================================
|
|
|
|
// This file is part of Glest (www.glest.org)
|
|
|
|
//
|
2011-12-14 07:40:48 +00:00
|
|
|
// Copyright (C) 2001-2008 Martiño Figueroa
|
2010-03-27 07:09:34 +00:00
|
|
|
//
|
|
|
|
// You can redistribute this code 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
|
|
|
|
// ==============================================================
|
|
|
|
|
|
|
|
#ifndef _GLEST_GAME_SERVERINTERFACE_H_
|
|
|
|
#define _GLEST_GAME_SERVERINTERFACE_H_
|
|
|
|
|
2012-04-20 01:04:05 +00:00
|
|
|
#ifdef WIN32
|
|
|
|
#include <winsock2.h>
|
|
|
|
#include <winsock.h>
|
|
|
|
#endif
|
2010-03-27 07:09:34 +00:00
|
|
|
|
2012-04-20 01:04:05 +00:00
|
|
|
#include <vector>
|
2010-03-27 07:09:34 +00:00
|
|
|
#include "game_constants.h"
|
|
|
|
#include "network_interface.h"
|
|
|
|
#include "connection_slot.h"
|
|
|
|
#include "socket.h"
|
2010-09-07 05:25:40 +00:00
|
|
|
#include "leak_dumper.h"
|
2010-03-27 07:09:34 +00:00
|
|
|
|
|
|
|
using std::vector;
|
|
|
|
using Shared::Platform::ServerSocket;
|
|
|
|
|
2010-12-29 01:10:53 +00:00
|
|
|
namespace Shared { namespace PlatformCommon { class FTPServerThread; }}
|
|
|
|
|
|
|
|
//using Shared::PlatformCommon::FTPServerThread;
|
|
|
|
|
2010-03-27 07:09:34 +00:00
|
|
|
namespace Glest{ namespace Game{
|
|
|
|
|
2010-05-15 18:59:17 +00:00
|
|
|
// =====================================================
|
|
|
|
// class ServerInterface
|
|
|
|
// =====================================================
|
|
|
|
|
2011-04-05 18:39:47 +00:00
|
|
|
class ServerInterface: public GameNetworkInterface,
|
|
|
|
public ConnectionSlotCallbackInterface,
|
2012-03-03 23:59:44 +00:00
|
|
|
// This is for publishing game status to the masterserver
|
2011-04-05 18:39:47 +00:00
|
|
|
public SimpleTaskCallbackInterface,
|
|
|
|
public FTPClientValidationInterface {
|
2010-03-27 07:09:34 +00:00
|
|
|
|
2011-01-11 22:09:46 +00:00
|
|
|
class TextMessageQueue {
|
|
|
|
public:
|
|
|
|
string text;
|
|
|
|
int teamIndex;
|
|
|
|
bool echoLocal;
|
2011-04-05 18:39:47 +00:00
|
|
|
string targetLanguage;
|
2011-01-11 22:09:46 +00:00
|
|
|
};
|
|
|
|
|
2010-03-27 07:09:34 +00:00
|
|
|
private:
|
|
|
|
ConnectionSlot* slots[GameConstants::maxPlayers];
|
2011-12-02 16:07:59 +00:00
|
|
|
Mutex *slotAccessorMutexes[GameConstants::maxPlayers];
|
2010-12-18 19:52:47 +00:00
|
|
|
|
2010-03-27 07:09:34 +00:00
|
|
|
ServerSocket serverSocket;
|
|
|
|
bool gameHasBeenInitiated;
|
|
|
|
int gameSettingsUpdateCount;
|
2010-04-28 23:59:37 +00:00
|
|
|
SwitchSetupRequest* switchSetupRequests[GameConstants::maxPlayers];
|
2011-12-02 16:07:59 +00:00
|
|
|
Mutex *serverSynchAccessor;
|
2010-06-15 05:36:07 +00:00
|
|
|
int currentFrameCount;
|
2010-05-15 18:59:17 +00:00
|
|
|
|
2010-06-28 00:21:12 +00:00
|
|
|
time_t gameStartTime;
|
2010-03-27 07:09:34 +00:00
|
|
|
|
2011-05-18 21:14:14 +00:00
|
|
|
time_t lastGlobalLagCheckTime;
|
|
|
|
|
2010-10-23 09:06:47 +00:00
|
|
|
SimpleTaskThread *publishToMasterserverThread;
|
2011-12-02 16:07:59 +00:00
|
|
|
Mutex *masterServerThreadAccessor;
|
2010-10-23 09:06:47 +00:00
|
|
|
time_t lastMasterserverHeartbeatTime;
|
2010-10-23 22:06:49 +00:00
|
|
|
bool needToRepublishToMasterserver;
|
2010-10-23 09:06:47 +00:00
|
|
|
|
2010-12-29 01:10:53 +00:00
|
|
|
Shared::PlatformCommon::FTPServerThread *ftpServer;
|
2011-01-10 15:50:16 +00:00
|
|
|
bool exitServer;
|
2011-01-11 08:45:58 +00:00
|
|
|
int64 nextEventId;
|
2010-12-29 01:10:53 +00:00
|
|
|
|
2011-12-02 16:07:59 +00:00
|
|
|
Mutex *textMessageQueueThreadAccessor;
|
2011-01-11 22:09:46 +00:00
|
|
|
vector<TextMessageQueue> textMessageQueue;
|
|
|
|
|
2011-12-02 16:07:59 +00:00
|
|
|
Mutex *broadcastMessageQueueThreadAccessor;
|
2011-01-12 00:16:50 +00:00
|
|
|
vector<pair<const NetworkMessage *,int> > broadcastMessageQueue;
|
|
|
|
|
2011-12-02 16:07:59 +00:00
|
|
|
Mutex *inBroadcastMessageThreadAccessor;
|
2011-01-13 08:17:18 +00:00
|
|
|
bool inBroadcastMessage;
|
|
|
|
|
2011-09-24 07:46:56 +00:00
|
|
|
bool masterserverAdminRequestLaunch;
|
|
|
|
|
2011-10-12 06:54:36 +00:00
|
|
|
vector<string> mapFiles;
|
|
|
|
vector<string> techTreeFiles;
|
|
|
|
vector<string> tilesetFiles;
|
|
|
|
|
2011-11-23 08:00:09 +00:00
|
|
|
map<string,pair<uint64,time_t> > badClientConnectIPList;
|
|
|
|
|
2012-03-25 06:55:43 +00:00
|
|
|
ServerSocket *serverSocketAdmin;
|
|
|
|
|
2010-03-27 07:09:34 +00:00
|
|
|
public:
|
2011-03-11 12:14:24 +00:00
|
|
|
ServerInterface(bool publishEnabled);
|
2010-03-27 07:09:34 +00:00
|
|
|
virtual ~ServerInterface();
|
|
|
|
|
2011-11-25 09:12:53 +00:00
|
|
|
virtual Socket* getSocket(bool mutexLock=true) {return &serverSocket;}
|
2010-10-23 22:06:49 +00:00
|
|
|
|
2011-11-25 09:12:53 +00:00
|
|
|
//const virtual Socket *getSocket() const {
|
|
|
|
// return &serverSocket;
|
|
|
|
//}
|
2011-01-13 01:46:32 +00:00
|
|
|
|
2012-07-21 00:23:27 +00:00
|
|
|
time_t getGameStartTime() const { return gameStartTime; }
|
|
|
|
|
2011-01-13 01:46:32 +00:00
|
|
|
virtual void close();
|
|
|
|
virtual void update();
|
2011-01-13 08:17:18 +00:00
|
|
|
virtual void updateLobby() { };
|
2011-01-13 01:46:32 +00:00
|
|
|
virtual void updateKeyframe(int frameCount);
|
2012-03-20 04:53:26 +00:00
|
|
|
virtual void setKeyframe(int frameCount) { currentFrameCount = frameCount; }
|
|
|
|
|
2011-01-13 01:46:32 +00:00
|
|
|
virtual void waitUntilReady(Checksum *checksum);
|
2011-04-05 18:39:47 +00:00
|
|
|
virtual void sendTextMessage(const string & text, int teamIndex, bool echoLocal, string targetLanguage);
|
|
|
|
void sendTextMessage(const string & text, int teamIndex, bool echoLocal, string targetLanguage, int lockedSlotIndex);
|
2012-06-12 20:37:00 +00:00
|
|
|
|
2011-04-05 18:39:47 +00:00
|
|
|
void queueTextMessage(const string & text, int teamIndex, bool echoLocal, string targetLanguage);
|
2012-06-12 20:37:00 +00:00
|
|
|
|
|
|
|
virtual void sendMarkCellMessage(Vec2i targetPos, int factionIndex, string note);
|
|
|
|
void sendMarkCellMessage(Vec2i targetPos, int factionIndex, string note, int lockedSlotIndex);
|
|
|
|
|
2012-07-13 21:50:34 +00:00
|
|
|
virtual void sendHighlightCellMessage(Vec2i targetPos, int factionIndex);
|
|
|
|
void sendHighlightCellMessage(Vec2i targetPos, int factionIndex, int lockedSlotIndex);
|
|
|
|
|
2012-06-13 16:19:44 +00:00
|
|
|
virtual void sendUnMarkCellMessage(Vec2i targetPos, int factionIndex);
|
|
|
|
void sendUnMarkCellMessage(Vec2i targetPos, int factionIndex, int lockedSlotIndex);
|
|
|
|
|
2011-01-13 01:46:32 +00:00
|
|
|
virtual void quitGame(bool userManuallyQuit);
|
|
|
|
virtual string getNetworkStatus();
|
|
|
|
ServerSocket *getServerSocket()
|
|
|
|
{
|
|
|
|
return &serverSocket;
|
|
|
|
}
|
|
|
|
|
|
|
|
SwitchSetupRequest **getSwitchSetupRequests()
|
|
|
|
{
|
|
|
|
return &switchSetupRequests[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
void addSlot(int playerIndex);
|
|
|
|
bool switchSlot(int fromPlayerIndex, int toPlayerIndex);
|
|
|
|
void removeSlot(int playerIndex, int lockedSlotIndex = -1);
|
|
|
|
ConnectionSlot *getSlot(int playerIndex);
|
2012-07-07 05:35:25 +00:00
|
|
|
int getSlotCount();
|
2011-01-13 01:46:32 +00:00
|
|
|
int getConnectedSlotCount();
|
2012-07-07 05:35:25 +00:00
|
|
|
|
2011-01-13 01:46:32 +00:00
|
|
|
int getOpenSlotCount();
|
|
|
|
bool launchGame(const GameSettings *gameSettings);
|
2012-01-20 04:15:13 +00:00
|
|
|
void validateGameSettings(GameSettings *serverGameSettings);
|
2011-01-13 01:46:32 +00:00
|
|
|
void setGameSettings(GameSettings *serverGameSettings, bool waitForClientAck);
|
2012-01-20 04:15:13 +00:00
|
|
|
void broadcastGameSetup(GameSettings *gameSettingsBuffer, bool setGameSettingsBuffer=false);
|
2011-09-24 07:46:56 +00:00
|
|
|
|
2011-09-26 04:50:13 +00:00
|
|
|
int getGameSettingsUpdateCount();
|
2011-09-24 07:46:56 +00:00
|
|
|
|
|
|
|
bool getMasterserverAdminRequestLaunch() const { return masterserverAdminRequestLaunch; }
|
|
|
|
void setMasterserverAdminRequestLaunch(bool value) { masterserverAdminRequestLaunch = value; }
|
|
|
|
|
2011-01-13 01:46:32 +00:00
|
|
|
void updateListen();
|
|
|
|
virtual bool getConnectHasHandshaked() const
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void slotUpdateTask(ConnectionSlotEvent *event);
|
|
|
|
bool hasClientConnection();
|
2011-11-25 09:12:53 +00:00
|
|
|
bool isClientConnected(int index);
|
|
|
|
|
2011-01-13 01:46:32 +00:00
|
|
|
int getCurrentFrameCount() const
|
|
|
|
{
|
|
|
|
return currentFrameCount;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::pair<bool,bool> clientLagCheck(ConnectionSlot *connectionSlot, bool skipNetworkBroadCast = false);
|
|
|
|
bool signalClientReceiveCommands(ConnectionSlot *connectionSlot, int slotIndex, bool socketTriggered, ConnectionSlotEvent & event);
|
|
|
|
void updateSocketTriggeredList(std::map<PLATFORM_SOCKET,bool> & socketTriggeredList);
|
|
|
|
bool isPortBound() const
|
|
|
|
{
|
|
|
|
return serverSocket.isPortBound();
|
|
|
|
}
|
|
|
|
|
|
|
|
int getBindPort() const
|
|
|
|
{
|
|
|
|
return serverSocket.getBindPort();
|
|
|
|
}
|
|
|
|
|
|
|
|
void broadcastPing(const NetworkMessagePing *networkMessage, int excludeSlot = -1)
|
|
|
|
{
|
|
|
|
this->broadcastMessage(networkMessage, excludeSlot);
|
|
|
|
}
|
|
|
|
|
|
|
|
void queueBroadcastMessage(const NetworkMessage *networkMessage, int excludeSlot = -1);
|
|
|
|
virtual string getHumanPlayerName(int index = -1);
|
|
|
|
virtual int getHumanPlayerIndex() const;
|
|
|
|
bool getNeedToRepublishToMasterserver() const
|
|
|
|
{
|
|
|
|
return needToRepublishToMasterserver;
|
|
|
|
}
|
|
|
|
|
|
|
|
void setNeedToRepublishToMasterserver(bool value)
|
|
|
|
{
|
|
|
|
needToRepublishToMasterserver = value;
|
|
|
|
}
|
2010-05-21 16:36:08 +00:00
|
|
|
|
2011-03-11 12:14:24 +00:00
|
|
|
void setPublishEnabled(bool value);
|
|
|
|
|
2011-11-23 08:00:09 +00:00
|
|
|
bool getGameHasBeenInitiated() const { return gameHasBeenInitiated; }
|
|
|
|
|
2011-01-13 01:46:32 +00:00
|
|
|
public:
|
2011-01-13 08:17:18 +00:00
|
|
|
Mutex *getServerSynchAccessor() {
|
2011-12-02 16:07:59 +00:00
|
|
|
return serverSynchAccessor;
|
2011-01-13 01:46:32 +00:00
|
|
|
}
|
2010-05-21 16:36:08 +00:00
|
|
|
|
2011-01-13 01:46:32 +00:00
|
|
|
virtual void simpleTask(BaseThread *callingThread);
|
|
|
|
void addClientToServerIPAddress(uint32 clientIp, uint32 ServerIp);
|
2011-01-07 06:21:23 +00:00
|
|
|
virtual int isValidClientType(uint32 clientIp);
|
2011-11-29 05:07:18 +00:00
|
|
|
virtual int isClientAllowedToGetFile(uint32 clientIp, const char *username, const char *filename);
|
|
|
|
|
2011-11-23 08:00:09 +00:00
|
|
|
void notifyBadClientConnectAttempt(string ipAddress);
|
2012-03-25 06:55:43 +00:00
|
|
|
std::string DumpStatsToLog(bool dumpToStringOnly) const;
|
2011-03-11 12:14:24 +00:00
|
|
|
|
2012-04-13 20:20:40 +00:00
|
|
|
virtual void saveGame(XmlNode *rootNode);
|
|
|
|
|
2010-03-27 07:09:34 +00:00
|
|
|
private:
|
2011-01-13 01:46:32 +00:00
|
|
|
void broadcastMessage(const NetworkMessage *networkMessage, int excludeSlot = -1, int lockedSlotIndex = -1);
|
|
|
|
void broadcastMessageToConnectedClients(const NetworkMessage *networkMessage, int excludeSlot = -1);
|
|
|
|
bool shouldDiscardNetworkMessage(NetworkMessageType networkMessageType, ConnectionSlot *connectionSlot);
|
|
|
|
void updateSlot(ConnectionSlotEvent *event);
|
|
|
|
void validateConnectedClients();
|
|
|
|
std::map<string,string> publishToMasterserver();
|
2011-01-11 08:45:58 +00:00
|
|
|
int64 getNextEventId();
|
2011-01-11 22:09:46 +00:00
|
|
|
void processTextMessageQueue();
|
2011-01-12 00:16:50 +00:00
|
|
|
void processBroadCastMessageQueue();
|
2011-09-24 07:46:56 +00:00
|
|
|
|
2011-01-13 01:46:32 +00:00
|
|
|
protected:
|
2011-01-13 08:17:18 +00:00
|
|
|
void signalClientsToRecieveData(std::map<PLATFORM_SOCKET,bool> & socketTriggeredList, std::map<int,ConnectionSlotEvent> & eventList, std::map<int,bool> & mapSlotSignalledList);
|
|
|
|
void checkForCompletedClients(std::map<int,bool> & mapSlotSignalledList,std::vector <string> &errorMsgList,std::map<int,ConnectionSlotEvent> &eventList);
|
2011-11-25 05:37:55 +00:00
|
|
|
void checkForLaggingClients(std::map<int,bool> &mapSlotSignalledList, std::map<int,ConnectionSlotEvent> &eventList, std::map<PLATFORM_SOCKET,bool> &socketTriggeredList,std::vector <string> &errorMsgList);
|
2011-01-13 08:17:18 +00:00
|
|
|
void executeNetworkCommandsFromClients();
|
|
|
|
void dispatchPendingChatMessages(std::vector <string> &errorMsgList);
|
2012-06-12 20:37:00 +00:00
|
|
|
void dispatchPendingMarkCellMessages(std::vector <string> &errorMsgList);
|
2012-06-13 16:19:44 +00:00
|
|
|
void dispatchPendingUnMarkCellMessages(std::vector <string> &errorMsgList);
|
2012-07-13 21:50:34 +00:00
|
|
|
void dispatchPendingHighlightCellMessages(std::vector <string> &errorMsgList);
|
|
|
|
|
2012-03-03 23:59:44 +00:00
|
|
|
|
|
|
|
void shutdownMasterserverPublishThread();
|
2010-03-27 07:09:34 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}}//end namespace
|
|
|
|
|
|
|
|
#endif
|