2010-03-27 08:09:34 +01:00
|
|
|
// ==============================================================
|
|
|
|
// This file is part of Glest (www.glest.org)
|
|
|
|
//
|
2011-12-14 08:40:48 +01:00
|
|
|
// Copyright (C) 2001-2008 Martiñ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_CLIENTINTERFACE_H_
|
|
|
|
#define _GLEST_GAME_CLIENTINTERFACE_H_
|
|
|
|
|
2012-04-20 03:04:05 +02:00
|
|
|
#ifdef WIN32
|
|
|
|
#include <winsock2.h>
|
|
|
|
#include <winsock.h>
|
|
|
|
#endif
|
2010-03-27 08:09:34 +01:00
|
|
|
|
2012-04-20 03:04:05 +02:00
|
|
|
#include <vector>
|
2010-03-27 08:09:34 +01:00
|
|
|
#include "network_interface.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 Shared::Platform::Ip;
|
|
|
|
using Shared::Platform::ClientSocket;
|
|
|
|
using std::vector;
|
|
|
|
|
|
|
|
namespace Glest{ namespace Game{
|
|
|
|
|
2013-03-09 21:57:06 +01:00
|
|
|
class ClientInterface;
|
|
|
|
|
|
|
|
class ClientInterfaceThread : public BaseThread, public SlaveThreadControllerInterface {
|
|
|
|
protected:
|
|
|
|
|
|
|
|
ClientInterface *clientInterface;
|
|
|
|
|
|
|
|
virtual void setQuitStatus(bool value);
|
|
|
|
|
|
|
|
public:
|
|
|
|
ClientInterfaceThread(ClientInterface *client);
|
|
|
|
virtual ~ClientInterfaceThread();
|
|
|
|
virtual void execute();
|
|
|
|
|
|
|
|
virtual void setMasterController(MasterSlaveThreadController *master) { }
|
|
|
|
virtual void signalSlave(void *userdata) { }
|
|
|
|
|
|
|
|
virtual bool canShutdown(bool deleteSelfIfShutdownDelayed=false);
|
|
|
|
};
|
|
|
|
|
2010-03-27 08:09:34 +01:00
|
|
|
// =====================================================
|
|
|
|
// class ClientInterface
|
|
|
|
// =====================================================
|
|
|
|
|
2013-03-09 21:57:06 +01:00
|
|
|
class ClientInterface: public GameNetworkInterface {
|
2010-03-27 08:09:34 +01:00
|
|
|
private:
|
|
|
|
static const int messageWaitTimeout;
|
|
|
|
static const int waitSleepTime;
|
2010-06-15 07:36:07 +02:00
|
|
|
static const int maxNetworkCommandListSendTimeWait;
|
2010-03-27 08:09:34 +01:00
|
|
|
|
|
|
|
private:
|
|
|
|
ClientSocket *clientSocket;
|
|
|
|
string serverName;
|
|
|
|
bool introDone;
|
|
|
|
bool launchGame;
|
|
|
|
int playerIndex;
|
2010-04-22 01:13:39 +02:00
|
|
|
bool gameSettingsReceived;
|
2011-10-22 02:19:38 +02:00
|
|
|
int gameSettingsReceivedCount;
|
2010-05-12 17:25:56 +02:00
|
|
|
time_t connectedTime;
|
|
|
|
bool gotIntro;
|
2010-03-27 08:09:34 +01:00
|
|
|
|
|
|
|
Ip ip;
|
|
|
|
int port;
|
|
|
|
|
2010-06-15 07:36:07 +02:00
|
|
|
int currentFrameCount;
|
2013-03-02 08:33:01 +01:00
|
|
|
int lastSentFrameCount;
|
2010-06-15 07:36:07 +02:00
|
|
|
time_t lastNetworkCommandListSendTime;
|
|
|
|
|
2010-08-07 05:26:38 +02:00
|
|
|
time_t clientSimulationLagStartTime;
|
2010-08-05 07:58:14 +02:00
|
|
|
string versionString;
|
2010-08-23 17:40:43 +02:00
|
|
|
int sessionKey;
|
2011-01-15 19:56:03 +01:00
|
|
|
int serverFTPPort;
|
2010-08-05 07:58:14 +02:00
|
|
|
|
2013-06-01 04:31:12 +02:00
|
|
|
string serverUUID;
|
2013-11-02 20:05:59 +01:00
|
|
|
string serverPlatform;
|
2013-06-01 04:31:12 +02:00
|
|
|
|
2013-03-09 21:57:06 +01:00
|
|
|
ClientInterfaceThread *networkCommandListThread;
|
|
|
|
|
2012-03-04 00:59:44 +01:00
|
|
|
Mutex *networkCommandListThreadAccessor;
|
|
|
|
std::map<int,Commands> cachedPendingCommands; //commands ready to be given
|
2013-09-12 05:33:43 +02:00
|
|
|
std::map<int,vector<uint32> > cachedPendingCommandCRCs; //commands ready to be given
|
2012-03-04 00:59:44 +01:00
|
|
|
uint64 cachedPendingCommandsIndex;
|
2013-03-02 01:30:26 +01:00
|
|
|
uint64 cachedLastPendingFrameCount;
|
2013-04-07 17:27:55 +02:00
|
|
|
int64 timeClientWaitedForLastMessage;
|
2013-02-27 07:46:42 +01:00
|
|
|
|
2013-03-16 07:55:16 +01:00
|
|
|
Mutex *flagAccessor;
|
2013-02-27 07:46:42 +01:00
|
|
|
bool joinGameInProgress;
|
|
|
|
bool joinGameInProgressLaunch;
|
2013-02-15 19:25:10 +01:00
|
|
|
bool readyForInGameJoin;
|
2013-03-01 07:52:33 +01:00
|
|
|
bool resumeInGameJoin;
|
2012-03-04 00:59:44 +01:00
|
|
|
|
2013-05-29 08:06:43 +02:00
|
|
|
Mutex *quitThreadAccessor;
|
2013-03-08 09:42:08 +01:00
|
|
|
bool quitThread;
|
|
|
|
|
2013-05-29 08:06:43 +02:00
|
|
|
bool getQuitThread();
|
|
|
|
void setQuitThread(bool value);
|
|
|
|
bool getQuit();
|
|
|
|
void setQuit(bool value);
|
|
|
|
|
2010-03-27 08:09:34 +01:00
|
|
|
public:
|
|
|
|
ClientInterface();
|
|
|
|
virtual ~ClientInterface();
|
|
|
|
|
2014-01-24 22:44:21 +01:00
|
|
|
virtual std::string getIpAddress(bool mutexLock=true);
|
2011-11-25 10:12:53 +01:00
|
|
|
virtual Socket* getSocket(bool mutexLock=true) {return clientSocket;}
|
2010-03-27 08:09:34 +01:00
|
|
|
virtual void close();
|
|
|
|
|
2013-03-16 07:55:16 +01:00
|
|
|
bool getJoinGameInProgress();
|
|
|
|
bool getJoinGameInProgressLaunch();
|
2013-02-15 19:25:10 +01:00
|
|
|
|
2013-03-16 07:55:16 +01:00
|
|
|
bool getReadyForInGameJoin();
|
2013-02-15 19:25:10 +01:00
|
|
|
|
2013-03-16 07:55:16 +01:00
|
|
|
bool getResumeInGameJoin();
|
2013-03-01 07:52:33 +01:00
|
|
|
void sendResumeGameMessage();
|
|
|
|
|
2013-03-02 01:53:55 +01:00
|
|
|
uint64 getCachedLastPendingFrameCount();
|
2013-04-07 17:27:55 +02:00
|
|
|
int64 getTimeClientWaitedForLastMessage();
|
2013-03-02 01:53:55 +01:00
|
|
|
|
2010-03-27 08:09:34 +01:00
|
|
|
//message processing
|
|
|
|
virtual void update();
|
|
|
|
virtual void updateLobby();
|
|
|
|
virtual void updateKeyframe(int frameCount);
|
2012-03-20 05:53:26 +01:00
|
|
|
virtual void setKeyframe(int frameCount) { currentFrameCount = frameCount; }
|
2010-03-27 08:09:34 +01:00
|
|
|
virtual void waitUntilReady(Checksum* checksum);
|
|
|
|
|
|
|
|
// message sending
|
2011-04-05 20:39:47 +02:00
|
|
|
virtual void sendTextMessage(const string &text, int teamIndex, bool echoLocal,
|
|
|
|
string targetLanguage);
|
2010-03-27 08:09:34 +01:00
|
|
|
virtual void quitGame(bool userManuallyQuit);
|
|
|
|
|
2012-09-21 00:18:10 +02:00
|
|
|
virtual void sendMarkCellMessage(Vec2i targetPos, int factionIndex, string note,int playerIndex);
|
2012-06-13 18:19:44 +02:00
|
|
|
virtual void sendUnMarkCellMessage(Vec2i targetPos, int factionIndex);
|
2012-07-13 23:50:34 +02:00
|
|
|
virtual void sendHighlightCellMessage(Vec2i targetPos, int factionIndex);
|
2010-03-27 08:09:34 +01:00
|
|
|
//misc
|
2010-06-04 21:42:58 +02:00
|
|
|
virtual string getNetworkStatus() ;
|
2010-03-27 08:09:34 +01:00
|
|
|
|
|
|
|
//accessors
|
|
|
|
string getServerName() const {return serverName;}
|
|
|
|
bool getLaunchGame() const {return launchGame;}
|
|
|
|
bool getIntroDone() const {return introDone;}
|
2010-04-22 01:13:39 +02:00
|
|
|
bool getGameSettingsReceived() const {return gameSettingsReceived;}
|
2011-10-22 02:19:38 +02:00
|
|
|
void setGameSettingsReceived(bool value);
|
|
|
|
|
|
|
|
int getGameSettingsReceivedCount() const { return gameSettingsReceivedCount; }
|
|
|
|
|
2010-03-27 08:09:34 +01:00
|
|
|
int getPlayerIndex() const {return playerIndex;}
|
|
|
|
|
|
|
|
void connect(const Ip &ip, int port);
|
|
|
|
void reset();
|
|
|
|
|
2010-04-02 04:33:32 +02:00
|
|
|
void discoverServers(DiscoveredServersInterface *cb);
|
|
|
|
void stopServerDiscovery();
|
2010-04-29 01:59:37 +02:00
|
|
|
|
2013-02-16 11:07:36 +01:00
|
|
|
void sendSwitchSetupRequest(string selectedFactionName, int8 currentSlotIndex,
|
|
|
|
int8 toSlotIndex, int8 toTeam,string networkPlayerName,
|
2011-04-05 20:39:47 +02:00
|
|
|
int8 networkPlayerStatus, int8 flags,
|
|
|
|
string language);
|
2010-05-13 09:13:53 +02:00
|
|
|
virtual bool getConnectHasHandshaked() const { return gotIntro; }
|
2010-06-04 21:42:58 +02:00
|
|
|
std::string getServerIpAddress();
|
2010-04-01 08:31:10 +02:00
|
|
|
|
2010-06-15 07:36:07 +02:00
|
|
|
int getCurrentFrameCount() const { return currentFrameCount; }
|
|
|
|
|
2010-07-09 17:01:49 +02:00
|
|
|
virtual void sendPingMessage(int32 pingFrequency, int64 pingTime);
|
|
|
|
|
2010-08-05 07:58:14 +02:00
|
|
|
const string &getVersionString() const {return versionString;}
|
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 {return playerIndex;}
|
2011-01-15 19:56:03 +01:00
|
|
|
int getServerFTPPort() const { return serverFTPPort; }
|
2010-08-05 07:58:14 +02:00
|
|
|
|
2011-09-24 09:46:56 +02:00
|
|
|
int getSessionKey() const { return sessionKey; }
|
2012-03-03 05:33:39 +01:00
|
|
|
bool isMasterServerAdminOverride();
|
2011-09-24 09:46:56 +02:00
|
|
|
|
|
|
|
void setGameSettings(GameSettings *serverGameSettings);
|
|
|
|
void broadcastGameSetup(const GameSettings *gameSettings);
|
|
|
|
void broadcastGameStart(const GameSettings *gameSettings);
|
|
|
|
|
2013-03-09 21:57:06 +01:00
|
|
|
void updateNetworkFrame();
|
2012-03-04 00:59:44 +01:00
|
|
|
|
2012-04-13 22:20:40 +02:00
|
|
|
virtual void saveGame(XmlNode *rootNode) {};
|
|
|
|
|
2010-05-21 18:36:08 +02:00
|
|
|
protected:
|
|
|
|
|
|
|
|
Mutex * getServerSynchAccessor() { return NULL; }
|
2013-03-23 23:32:51 +01:00
|
|
|
NetworkMessageType waitForMessage(int waitMicroseconds=0);
|
2010-07-06 07:30:34 +02:00
|
|
|
bool shouldDiscardNetworkMessage(NetworkMessageType networkMessageType);
|
2012-03-04 00:59:44 +01:00
|
|
|
|
|
|
|
void updateFrame(int *checkFrame);
|
2013-05-29 08:06:43 +02:00
|
|
|
void shutdownNetworkCommandListThread(MutexSafeWrapper &safeMutexWrapper);
|
2012-03-04 00:59:44 +01:00
|
|
|
bool getNetworkCommand(int frameCount, int currentCachedPendingCommandsIndex);
|
2013-03-12 23:50:26 +01:00
|
|
|
|
|
|
|
void close(bool lockMutex);
|
2010-03-27 08:09:34 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
}}//end namespace
|
|
|
|
|
|
|
|
#endif
|