2010-03-27 08:09:34 +01:00
|
|
|
|
// ==============================================================
|
|
|
|
|
// This file is part of Glest (www.glest.org)
|
|
|
|
|
//
|
2010-04-22 01:13:39 +02:00
|
|
|
|
// Copyright (C) 2001-2008 Marti<74>o Figueroa
|
2010-03-27 08:09:34 +01: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_
|
|
|
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
|
|
#include "game_constants.h"
|
|
|
|
|
#include "network_interface.h"
|
|
|
|
|
#include "connection_slot.h"
|
|
|
|
|
#include "socket.h"
|
2010-09-07 07:25:40 +02:00
|
|
|
|
#include "leak_dumper.h"
|
2010-03-27 08:09:34 +01:00
|
|
|
|
|
|
|
|
|
using std::vector;
|
|
|
|
|
using Shared::Platform::ServerSocket;
|
|
|
|
|
|
2010-12-29 02:10:53 +01:00
|
|
|
|
namespace Shared { namespace PlatformCommon { class FTPServerThread; }}
|
|
|
|
|
|
|
|
|
|
//using Shared::PlatformCommon::FTPServerThread;
|
|
|
|
|
|
2010-03-27 08:09:34 +01:00
|
|
|
|
namespace Glest{ namespace Game{
|
|
|
|
|
|
2010-05-15 20:59:17 +02:00
|
|
|
|
// =====================================================
|
|
|
|
|
// class ServerInterface
|
|
|
|
|
// =====================================================
|
|
|
|
|
|
2011-01-07 07:21:23 +01:00
|
|
|
|
class ServerInterface: public GameNetworkInterface, public ConnectionSlotCallbackInterface, public SimpleTaskCallbackInterface, public FTPClientValidationInterface {
|
2010-03-27 08:09:34 +01:00
|
|
|
|
|
2011-01-11 23:09:46 +01:00
|
|
|
|
class TextMessageQueue {
|
|
|
|
|
public:
|
|
|
|
|
string text;
|
|
|
|
|
int teamIndex;
|
|
|
|
|
bool echoLocal;
|
|
|
|
|
};
|
|
|
|
|
|
2010-03-27 08:09:34 +01:00
|
|
|
|
private:
|
|
|
|
|
ConnectionSlot* slots[GameConstants::maxPlayers];
|
2010-12-18 20:52:47 +01:00
|
|
|
|
Mutex slotAccessorMutexes[GameConstants::maxPlayers];
|
|
|
|
|
|
2010-03-27 08:09:34 +01:00
|
|
|
|
ServerSocket serverSocket;
|
|
|
|
|
bool gameHasBeenInitiated;
|
|
|
|
|
int gameSettingsUpdateCount;
|
2010-04-29 01:59:37 +02:00
|
|
|
|
SwitchSetupRequest* switchSetupRequests[GameConstants::maxPlayers];
|
2010-05-15 20:59:17 +02:00
|
|
|
|
Mutex serverSynchAccessor;
|
2010-06-15 07:36:07 +02:00
|
|
|
|
int currentFrameCount;
|
2010-05-15 20:59:17 +02:00
|
|
|
|
|
2010-06-28 02:21:12 +02:00
|
|
|
|
time_t gameStartTime;
|
2010-03-27 08:09:34 +01:00
|
|
|
|
|
2010-10-23 11:06:47 +02:00
|
|
|
|
SimpleTaskThread *publishToMasterserverThread;
|
|
|
|
|
Mutex masterServerThreadAccessor;
|
|
|
|
|
time_t lastMasterserverHeartbeatTime;
|
2010-10-24 00:06:49 +02:00
|
|
|
|
bool needToRepublishToMasterserver;
|
2010-10-23 11:06:47 +02:00
|
|
|
|
|
2010-12-29 02:10:53 +01:00
|
|
|
|
Shared::PlatformCommon::FTPServerThread *ftpServer;
|
2011-01-10 16:50:16 +01:00
|
|
|
|
bool exitServer;
|
2011-01-11 09:45:58 +01:00
|
|
|
|
int64 nextEventId;
|
2010-12-29 02:10:53 +01:00
|
|
|
|
|
2011-01-11 23:09:46 +01:00
|
|
|
|
Mutex textMessageQueueThreadAccessor;
|
|
|
|
|
vector<TextMessageQueue> textMessageQueue;
|
|
|
|
|
|
2010-03-27 08:09:34 +01:00
|
|
|
|
public:
|
|
|
|
|
ServerInterface();
|
|
|
|
|
virtual ~ServerInterface();
|
|
|
|
|
|
|
|
|
|
virtual Socket* getSocket() {return &serverSocket;}
|
|
|
|
|
virtual const Socket* getSocket() const {return &serverSocket;}
|
|
|
|
|
virtual void close();
|
|
|
|
|
|
|
|
|
|
//message processing
|
|
|
|
|
virtual void update();
|
|
|
|
|
virtual void updateLobby(){};
|
|
|
|
|
virtual void updateKeyframe(int frameCount);
|
|
|
|
|
virtual void waitUntilReady(Checksum* checksum);
|
|
|
|
|
|
|
|
|
|
// message sending
|
2010-07-01 02:08:59 +02:00
|
|
|
|
virtual void sendTextMessage(const string &text, int teamIndex, bool echoLocal=false);
|
2010-12-25 23:38:00 +01:00
|
|
|
|
void sendTextMessage(const string &text, int teamIndex, bool echoLocal, int lockedSlotIndex);
|
|
|
|
|
|
2011-01-11 23:09:46 +01:00
|
|
|
|
void queueTextMessage(const string &text, int teamIndex, bool echoLocal=false);
|
|
|
|
|
|
2010-03-27 08:09:34 +01:00
|
|
|
|
virtual void quitGame(bool userManuallyQuit);
|
|
|
|
|
|
|
|
|
|
//misc
|
2010-06-04 21:42:58 +02:00
|
|
|
|
virtual string getNetworkStatus() ;
|
2010-03-27 08:09:34 +01:00
|
|
|
|
|
|
|
|
|
ServerSocket* getServerSocket() {return &serverSocket;}
|
2010-04-29 01:59:37 +02:00
|
|
|
|
SwitchSetupRequest** getSwitchSetupRequests() {return &switchSetupRequests[0];}
|
2010-03-27 08:09:34 +01:00
|
|
|
|
void addSlot(int playerIndex);
|
2010-04-30 03:08:29 +02:00
|
|
|
|
bool switchSlot(int fromPlayerIndex,int toPlayerIndex);
|
2010-12-25 23:38:00 +01:00
|
|
|
|
void removeSlot(int playerIndex, int lockedSlotIndex=-1);
|
2010-03-27 08:09:34 +01:00
|
|
|
|
ConnectionSlot* getSlot(int playerIndex);
|
|
|
|
|
int getConnectedSlotCount();
|
2010-05-12 17:25:56 +02:00
|
|
|
|
int getOpenSlotCount();
|
2010-03-27 08:09:34 +01:00
|
|
|
|
|
|
|
|
|
bool launchGame(const GameSettings* gameSettings);
|
2010-08-26 21:01:44 +02:00
|
|
|
|
void setGameSettings(GameSettings *serverGameSettings, bool waitForClientAck);
|
2010-04-22 01:13:39 +02:00
|
|
|
|
void broadcastGameSetup(const GameSettings* gameSettings);
|
2010-05-12 17:25:56 +02:00
|
|
|
|
void updateListen();
|
2010-05-13 09:13:53 +02:00
|
|
|
|
virtual bool getConnectHasHandshaked() const { return false; }
|
2010-03-27 08:09:34 +01:00
|
|
|
|
|
2010-05-15 20:59:17 +02:00
|
|
|
|
virtual void slotUpdateTask(ConnectionSlotEvent *event);
|
2010-05-17 08:41:05 +02:00
|
|
|
|
bool hasClientConnection();
|
2010-06-15 07:36:07 +02:00
|
|
|
|
int getCurrentFrameCount() const { return currentFrameCount; }
|
2010-08-07 05:26:38 +02:00
|
|
|
|
std::pair<bool,bool> clientLagCheck(ConnectionSlot* connectionSlot,bool skipNetworkBroadCast=false);
|
2010-05-15 20:59:17 +02:00
|
|
|
|
|
2010-06-29 08:50:35 +02:00
|
|
|
|
bool signalClientReceiveCommands(ConnectionSlot* connectionSlot,
|
2010-06-17 23:46:36 +02:00
|
|
|
|
int slotIndex,
|
|
|
|
|
bool socketTriggered,
|
|
|
|
|
ConnectionSlotEvent &event);
|
|
|
|
|
void updateSocketTriggeredList(std::map<PLATFORM_SOCKET,bool> &socketTriggeredList);
|
|
|
|
|
|
2010-06-24 03:23:18 +02:00
|
|
|
|
bool isPortBound() const { return serverSocket.isPortBound(); }
|
|
|
|
|
int getBindPort() const { return serverSocket.getBindPort(); }
|
|
|
|
|
|
2010-07-09 19:12:57 +02:00
|
|
|
|
void broadcastPing(const NetworkMessagePing* networkMessage, int excludeSlot= -1) {
|
|
|
|
|
this->broadcastMessage(networkMessage,excludeSlot);
|
|
|
|
|
}
|
|
|
|
|
|
2010-08-21 15:04:52 +02:00
|
|
|
|
virtual string getHumanPlayerName(int index=-1);
|
2010-10-22 09:28:55 +02:00
|
|
|
|
virtual int getHumanPlayerIndex() const;
|
2010-08-21 15:04:52 +02:00
|
|
|
|
|
2010-10-24 00:06:49 +02:00
|
|
|
|
bool getNeedToRepublishToMasterserver() const {return needToRepublishToMasterserver;}
|
|
|
|
|
void setNeedToRepublishToMasterserver(bool value) {needToRepublishToMasterserver = value;}
|
|
|
|
|
|
2010-05-21 18:36:08 +02:00
|
|
|
|
public:
|
|
|
|
|
|
|
|
|
|
Mutex * getServerSynchAccessor() { return &serverSynchAccessor; }
|
|
|
|
|
|
2011-01-02 07:46:48 +01:00
|
|
|
|
virtual void simpleTask(BaseThread *callingThread);
|
2010-12-30 16:56:02 +01:00
|
|
|
|
void addClientToServerIPAddress(uint32 clientIp,uint32 ServerIp);
|
2011-01-07 07:21:23 +01:00
|
|
|
|
virtual int isValidClientType(uint32 clientIp);
|
2010-10-23 11:06:47 +02:00
|
|
|
|
|
2010-03-27 08:09:34 +01:00
|
|
|
|
private:
|
2010-05-21 18:36:08 +02:00
|
|
|
|
|
2010-12-25 23:38:00 +01:00
|
|
|
|
void broadcastMessage(const NetworkMessage* networkMessage, int excludeSlot= -1,int lockedSlotIndex=-1);
|
2010-03-27 08:09:34 +01:00
|
|
|
|
void broadcastMessageToConnectedClients(const NetworkMessage* networkMessage, int excludeSlot = -1);
|
2010-05-04 04:32:43 +02:00
|
|
|
|
bool shouldDiscardNetworkMessage(NetworkMessageType networkMessageType,ConnectionSlot* connectionSlot);
|
2010-05-15 20:59:17 +02:00
|
|
|
|
void updateSlot(ConnectionSlotEvent *event);
|
2010-08-20 22:03:06 +02:00
|
|
|
|
void validateConnectedClients();
|
2010-10-23 11:06:47 +02:00
|
|
|
|
|
|
|
|
|
std::map<string,string> publishToMasterserver();
|
2011-01-11 09:45:58 +01:00
|
|
|
|
|
|
|
|
|
int64 getNextEventId();
|
2011-01-11 23:09:46 +01:00
|
|
|
|
|
|
|
|
|
void processTextMessageQueue();
|
2010-03-27 08:09:34 +01:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
}}//end namespace
|
|
|
|
|
|
|
|
|
|
#endif
|