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_CLIENTINTERFACE_H_
|
|
|
|
#define _GLEST_GAME_CLIENTINTERFACE_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 "network_interface.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 Shared::Platform::Ip;
|
|
|
|
using Shared::Platform::ClientSocket;
|
|
|
|
using std::vector;
|
|
|
|
|
|
|
|
namespace Glest{ namespace Game{
|
|
|
|
|
|
|
|
// =====================================================
|
|
|
|
// class ClientInterface
|
|
|
|
// =====================================================
|
|
|
|
|
2012-03-03 23:59:44 +00:00
|
|
|
class ClientInterface: public GameNetworkInterface,
|
|
|
|
public SimpleTaskCallbackInterface {
|
2010-03-27 07:09:34 +00:00
|
|
|
private:
|
|
|
|
static const int messageWaitTimeout;
|
|
|
|
static const int waitSleepTime;
|
2010-06-15 05:36:07 +00:00
|
|
|
static const int maxNetworkCommandListSendTimeWait;
|
2010-03-27 07:09:34 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
ClientSocket *clientSocket;
|
|
|
|
string serverName;
|
|
|
|
bool introDone;
|
|
|
|
bool launchGame;
|
|
|
|
int playerIndex;
|
2010-04-21 23:13:39 +00:00
|
|
|
bool gameSettingsReceived;
|
2011-10-22 00:19:38 +00:00
|
|
|
int gameSettingsReceivedCount;
|
2010-05-12 15:25:56 +00:00
|
|
|
time_t connectedTime;
|
|
|
|
bool gotIntro;
|
2010-03-27 07:09:34 +00:00
|
|
|
|
|
|
|
Ip ip;
|
|
|
|
int port;
|
|
|
|
|
2010-06-15 05:36:07 +00:00
|
|
|
int currentFrameCount;
|
|
|
|
time_t lastNetworkCommandListSendTime;
|
|
|
|
|
2010-08-07 03:26:38 +00:00
|
|
|
time_t clientSimulationLagStartTime;
|
2010-08-05 05:58:14 +00:00
|
|
|
string versionString;
|
2010-08-23 15:40:43 +00:00
|
|
|
int sessionKey;
|
2011-01-15 18:56:03 +00:00
|
|
|
int serverFTPPort;
|
2010-08-05 05:58:14 +00:00
|
|
|
|
2012-03-03 23:59:44 +00:00
|
|
|
SimpleTaskThread *networkCommandListThread;
|
|
|
|
Mutex *networkCommandListThreadAccessor;
|
|
|
|
std::map<int,Commands> cachedPendingCommands; //commands ready to be given
|
|
|
|
uint64 cachedPendingCommandsIndex;
|
2013-03-02 00:30:26 +00:00
|
|
|
uint64 cachedLastPendingFrameCount;
|
2013-02-27 06:46:42 +00:00
|
|
|
|
|
|
|
bool joinGameInProgress;
|
|
|
|
bool joinGameInProgressLaunch;
|
2013-02-15 18:25:10 +00:00
|
|
|
bool pausedForInGameJoin;
|
|
|
|
bool readyForInGameJoin;
|
2013-03-01 06:52:33 +00:00
|
|
|
bool resumeInGameJoin;
|
2012-03-03 23:59:44 +00:00
|
|
|
|
2010-03-27 07:09:34 +00:00
|
|
|
public:
|
|
|
|
ClientInterface();
|
|
|
|
virtual ~ClientInterface();
|
|
|
|
|
2011-11-25 09:12:53 +00:00
|
|
|
virtual Socket* getSocket(bool mutexLock=true) {return clientSocket;}
|
|
|
|
//virtual const Socket* getSocket() const {return clientSocket;}
|
2010-03-27 07:09:34 +00:00
|
|
|
virtual void close();
|
|
|
|
|
2013-02-15 18:25:10 +00:00
|
|
|
bool getJoinGameInProgress() const { return joinGameInProgress; }
|
2013-02-27 06:46:42 +00:00
|
|
|
bool getJoinGameInProgressLaunch() const { return joinGameInProgressLaunch; }
|
2013-02-15 18:25:10 +00:00
|
|
|
|
|
|
|
bool getPausedForInGameJoin() const { return pausedForInGameJoin; }
|
|
|
|
bool getReadyForInGameJoin() const { return readyForInGameJoin; }
|
|
|
|
|
2013-03-01 06:52:33 +00:00
|
|
|
bool getResumeInGameJoin() const { return resumeInGameJoin; }
|
|
|
|
void sendResumeGameMessage();
|
|
|
|
|
2013-03-02 00:53:55 +00:00
|
|
|
uint64 getCachedLastPendingFrameCount();
|
|
|
|
|
2010-03-27 07:09:34 +00:00
|
|
|
//message processing
|
|
|
|
virtual void update();
|
|
|
|
virtual void updateLobby();
|
|
|
|
virtual void updateKeyframe(int frameCount);
|
2012-03-20 04:53:26 +00:00
|
|
|
virtual void setKeyframe(int frameCount) { currentFrameCount = frameCount; }
|
2010-03-27 07:09:34 +00:00
|
|
|
virtual void waitUntilReady(Checksum* checksum);
|
|
|
|
|
|
|
|
// message sending
|
2011-04-05 18:39:47 +00:00
|
|
|
virtual void sendTextMessage(const string &text, int teamIndex, bool echoLocal,
|
|
|
|
string targetLanguage);
|
2010-03-27 07:09:34 +00:00
|
|
|
virtual void quitGame(bool userManuallyQuit);
|
|
|
|
|
2012-09-20 22:18:10 +00:00
|
|
|
virtual void sendMarkCellMessage(Vec2i targetPos, int factionIndex, string note,int playerIndex);
|
2012-06-13 16:19:44 +00:00
|
|
|
virtual void sendUnMarkCellMessage(Vec2i targetPos, int factionIndex);
|
2012-07-13 21:50:34 +00:00
|
|
|
virtual void sendHighlightCellMessage(Vec2i targetPos, int factionIndex);
|
2010-03-27 07:09:34 +00:00
|
|
|
//misc
|
2010-06-04 19:42:58 +00:00
|
|
|
virtual string getNetworkStatus() ;
|
2010-03-27 07:09:34 +00:00
|
|
|
|
|
|
|
//accessors
|
|
|
|
string getServerName() const {return serverName;}
|
|
|
|
bool getLaunchGame() const {return launchGame;}
|
|
|
|
bool getIntroDone() const {return introDone;}
|
2010-04-21 23:13:39 +00:00
|
|
|
bool getGameSettingsReceived() const {return gameSettingsReceived;}
|
2011-10-22 00:19:38 +00:00
|
|
|
void setGameSettingsReceived(bool value);
|
|
|
|
|
|
|
|
int getGameSettingsReceivedCount() const { return gameSettingsReceivedCount; }
|
|
|
|
|
2010-03-27 07:09:34 +00:00
|
|
|
int getPlayerIndex() const {return playerIndex;}
|
|
|
|
//const GameSettings *getGameSettings() {return &gameSettings;}
|
|
|
|
|
|
|
|
void connect(const Ip &ip, int port);
|
|
|
|
void reset();
|
|
|
|
|
2010-04-02 02:33:32 +00:00
|
|
|
void discoverServers(DiscoveredServersInterface *cb);
|
|
|
|
void stopServerDiscovery();
|
2010-04-28 23:59:37 +00:00
|
|
|
|
2013-02-16 10:07:36 +00:00
|
|
|
void sendSwitchSetupRequest(string selectedFactionName, int8 currentSlotIndex,
|
|
|
|
int8 toSlotIndex, int8 toTeam,string networkPlayerName,
|
2011-04-05 18:39:47 +00:00
|
|
|
int8 networkPlayerStatus, int8 flags,
|
|
|
|
string language);
|
2010-05-13 07:13:53 +00:00
|
|
|
virtual bool getConnectHasHandshaked() const { return gotIntro; }
|
2010-06-04 19:42:58 +00:00
|
|
|
std::string getServerIpAddress();
|
2010-04-01 06:31:10 +00:00
|
|
|
|
2010-06-15 05:36:07 +00:00
|
|
|
int getCurrentFrameCount() const { return currentFrameCount; }
|
|
|
|
|
2010-07-09 15:01:49 +00:00
|
|
|
virtual void sendPingMessage(int32 pingFrequency, int64 pingTime);
|
|
|
|
|
2010-08-05 05:58:14 +00:00
|
|
|
const string &getVersionString() const {return versionString;}
|
2010-08-21 13:04:52 +00:00
|
|
|
virtual string getHumanPlayerName(int index=-1);
|
2010-10-22 07:28:55 +00:00
|
|
|
virtual int getHumanPlayerIndex() const {return playerIndex;}
|
2011-01-15 18:56:03 +00:00
|
|
|
int getServerFTPPort() const { return serverFTPPort; }
|
2010-08-05 05:58:14 +00:00
|
|
|
|
2011-09-24 07:46:56 +00:00
|
|
|
int getSessionKey() const { return sessionKey; }
|
2012-03-03 04:33:39 +00:00
|
|
|
bool isMasterServerAdminOverride();
|
2011-09-24 07:46:56 +00:00
|
|
|
|
|
|
|
void setGameSettings(GameSettings *serverGameSettings);
|
|
|
|
void broadcastGameSetup(const GameSettings *gameSettings);
|
|
|
|
void broadcastGameStart(const GameSettings *gameSettings);
|
|
|
|
|
2012-03-03 23:59:44 +00:00
|
|
|
virtual void simpleTask(BaseThread *callingThread);
|
|
|
|
|
2012-04-13 20:20:40 +00:00
|
|
|
virtual void saveGame(XmlNode *rootNode) {};
|
|
|
|
|
2010-05-21 16:36:08 +00:00
|
|
|
protected:
|
|
|
|
|
|
|
|
Mutex * getServerSynchAccessor() { return NULL; }
|
2011-02-15 03:32:14 +00:00
|
|
|
NetworkMessageType waitForMessage();
|
2010-07-06 05:30:34 +00:00
|
|
|
bool shouldDiscardNetworkMessage(NetworkMessageType networkMessageType);
|
2012-03-03 23:59:44 +00:00
|
|
|
|
|
|
|
void updateFrame(int *checkFrame);
|
|
|
|
void shutdownNetworkCommandListThread();
|
|
|
|
bool getNetworkCommand(int frameCount, int currentCachedPendingCommandsIndex);
|
2010-03-27 07:09:34 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}}//end namespace
|
|
|
|
|
|
|
|
#endif
|