2007-01-13 02:40:33 +00:00
|
|
|
/***************************************************************************
|
|
|
|
|
* Copyright (C) 2006 by FThauer FHammer *
|
|
|
|
|
* f.thauer@web.de *
|
|
|
|
|
* *
|
|
|
|
|
* This program is free software; you can redistribute it 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. *
|
|
|
|
|
* *
|
|
|
|
|
* This program is distributed in the hope that it will be useful, *
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
|
|
|
* GNU General Public License for more details. *
|
|
|
|
|
* *
|
|
|
|
|
* You should have received a copy of the GNU General Public License *
|
|
|
|
|
* along with this program; if not, write to the *
|
|
|
|
|
* Free Software Foundation, Inc., *
|
|
|
|
|
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
|
|
|
|
***************************************************************************/
|
2009-08-02 15:11:40 +00:00
|
|
|
#include <boost/asio.hpp>
|
2008-04-16 20:38:11 +00:00
|
|
|
#include <net/socket_helper.h>
|
2007-01-13 02:40:33 +00:00
|
|
|
#include "session.h"
|
|
|
|
|
#include "game.h"
|
2010-12-20 20:30:12 +00:00
|
|
|
#include "log.h"
|
2007-01-13 02:40:33 +00:00
|
|
|
#include "guiinterface.h"
|
2007-01-21 14:20:15 +00:00
|
|
|
#include "configfile.h"
|
2007-12-11 19:35:02 +00:00
|
|
|
#include <qttoolsinterface.h>
|
2007-05-18 17:13:27 +00:00
|
|
|
#include <localenginefactory.h>
|
|
|
|
|
#include <clientenginefactory.h>
|
2007-02-18 13:45:56 +00:00
|
|
|
#include <net/clientthread.h>
|
2007-11-16 22:34:38 +00:00
|
|
|
#include <net/servermanager.h>
|
2007-09-26 11:48:33 +00:00
|
|
|
#include <net/ircthread.h>
|
2007-09-08 20:40:46 +00:00
|
|
|
#include <core/avatarmanager.h>
|
2007-01-21 14:20:15 +00:00
|
|
|
|
2007-05-22 23:27:21 +00:00
|
|
|
#include <sstream>
|
|
|
|
|
|
2009-03-21 01:39:00 +00:00
|
|
|
#define NET_CLIENT_TERMINATE_TIMEOUT_MSEC 2000
|
2007-09-30 13:15:52 +00:00
|
|
|
#define NET_IRC_TERMINATE_TIMEOUT_MSEC 2000
|
2007-01-13 02:40:33 +00:00
|
|
|
|
2007-08-26 12:15:10 +00:00
|
|
|
#define NET_DEFAULT_GAME "default"
|
|
|
|
|
|
2009-04-15 18:02:16 +00:00
|
|
|
|
2007-01-13 02:40:33 +00:00
|
|
|
using namespace std;
|
|
|
|
|
|
2007-05-13 12:35:27 +00:00
|
|
|
Session::Session(GuiInterface *g, ConfigFile *c)
|
2010-12-18 23:10:10 +00:00
|
|
|
: currentGameNum(0), myGui(g), myConfig(c), myLog(0), myGameType(GAME_TYPE_NONE)
|
2007-08-19 20:58:57 +00:00
|
|
|
{
|
2010-03-30 12:25:30 +00:00
|
|
|
myQtToolsInterface = CreateQtToolsWrapper();
|
2011-01-03 17:56:06 +00:00
|
|
|
myLog = new Log(myConfig->readConfigString("LogDir"),myConfig->readConfigInt("LogOnOff"));
|
2007-01-13 02:40:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Session::~Session()
|
|
|
|
|
{
|
2010-03-30 12:25:30 +00:00
|
|
|
terminateNetworkClient();
|
|
|
|
|
terminateNetworkServer();
|
|
|
|
|
delete myQtToolsInterface;
|
|
|
|
|
myQtToolsInterface = 0;
|
2011-01-03 17:56:06 +00:00
|
|
|
delete myLog;
|
|
|
|
|
myLog = 0;
|
2007-01-13 02:40:33 +00:00
|
|
|
}
|
|
|
|
|
|
2007-09-08 21:43:15 +00:00
|
|
|
bool Session::init()
|
|
|
|
|
{
|
2010-03-30 12:25:30 +00:00
|
|
|
myAvatarManager.reset(new AvatarManager(
|
|
|
|
|
myConfig->readConfigInt("ServerUsePutAvatars") == 1,
|
|
|
|
|
myConfig->readConfigString("ServerPutAvatarsAddress"),
|
|
|
|
|
myConfig->readConfigString("ServerPutAvatarsUser"),
|
|
|
|
|
myConfig->readConfigString("ServerPutAvatarsPassword")
|
|
|
|
|
));
|
|
|
|
|
bool retVal = myAvatarManager->Init(
|
|
|
|
|
myQtToolsInterface->stringFromUtf8(myConfig->readConfigString("AppDataDir")),
|
|
|
|
|
myQtToolsInterface->stringFromUtf8(myConfig->readConfigString("CacheDir")));
|
|
|
|
|
addOwnAvatar(myQtToolsInterface->stringFromUtf8(myConfig->readConfigString("MyAvatar")));
|
|
|
|
|
myAvatarManager->RemoveOldAvatarCacheEntries();
|
|
|
|
|
return retVal;
|
2007-09-08 21:43:15 +00:00
|
|
|
}
|
2007-01-13 02:40:33 +00:00
|
|
|
|
2007-10-15 08:37:32 +00:00
|
|
|
void Session::init(boost::shared_ptr<AvatarManager> manager)
|
|
|
|
|
{
|
2010-03-30 12:25:30 +00:00
|
|
|
myAvatarManager = manager;
|
2007-10-15 08:37:32 +00:00
|
|
|
}
|
|
|
|
|
|
2007-11-22 01:11:17 +00:00
|
|
|
void Session::addOwnAvatar(const std::string &avatarFile)
|
|
|
|
|
{
|
2010-03-30 12:25:30 +00:00
|
|
|
myAvatarManager->AddSingleAvatar(avatarFile);
|
2007-11-22 01:11:17 +00:00
|
|
|
}
|
|
|
|
|
|
2007-05-20 00:16:29 +00:00
|
|
|
void Session::startLocalGame(const GameData &gameData, const StartData &startData) {
|
2007-05-02 21:20:54 +00:00
|
|
|
|
2010-03-30 12:25:30 +00:00
|
|
|
myGameType = GAME_TYPE_LOCAL;
|
2007-10-08 20:14:44 +00:00
|
|
|
|
2010-03-30 12:25:30 +00:00
|
|
|
currentGame.reset();
|
|
|
|
|
currentGameNum++;
|
2007-01-13 02:40:33 +00:00
|
|
|
|
2010-03-30 12:25:30 +00:00
|
|
|
myGui->initGui(gameData.guiSpeed);
|
2007-05-20 00:16:29 +00:00
|
|
|
|
2010-03-30 12:25:30 +00:00
|
|
|
PlayerDataList playerDataList;
|
|
|
|
|
for(int i = 0; i < startData.numberOfPlayers; i++) {
|
2007-04-26 21:11:13 +00:00
|
|
|
|
2010-03-30 12:25:30 +00:00
|
|
|
//Namen und Avatarpfad abfragen
|
|
|
|
|
ostringstream myName;
|
|
|
|
|
if (i==0) { myName << "MyName"; }
|
|
|
|
|
else { myName << "Opponent" << i << "Name"; }
|
|
|
|
|
ostringstream myAvatar;
|
|
|
|
|
if (i==0) { myAvatar << "MyAvatar"; }
|
|
|
|
|
else { myAvatar << "Opponent" << i << "Avatar"; }
|
2007-04-26 21:11:13 +00:00
|
|
|
|
2010-03-30 12:25:30 +00:00
|
|
|
//PlayerData erzeugen
|
|
|
|
|
// UniqueId = PlayerNumber for local games.
|
|
|
|
|
boost::shared_ptr<PlayerData> playerData(new PlayerData(i, i,
|
|
|
|
|
i == 0 ? PLAYER_TYPE_HUMAN : PLAYER_TYPE_COMPUTER,
|
|
|
|
|
PLAYER_RIGHTS_NORMAL,
|
|
|
|
|
i == 0));
|
|
|
|
|
playerData->SetName(myConfig->readConfigString(myName.str()));
|
|
|
|
|
playerData->SetAvatarFile(myConfig->readConfigString(myAvatar.str()));
|
2007-04-26 21:11:13 +00:00
|
|
|
|
2010-03-30 12:25:30 +00:00
|
|
|
playerDataList.push_back(playerData);
|
|
|
|
|
}
|
|
|
|
|
// EngineFactory erstellen
|
|
|
|
|
boost::shared_ptr<EngineFactory> factory(new LocalEngineFactory(myConfig)); // LocalEngine erstellen
|
2007-05-18 17:13:27 +00:00
|
|
|
|
2010-12-20 20:30:12 +00:00
|
|
|
currentGame.reset(new Game(myGui, factory, playerDataList, gameData, startData, currentGameNum, myLog));
|
2007-05-18 17:13:27 +00:00
|
|
|
|
2010-03-30 12:25:30 +00:00
|
|
|
//// SPIEL-SCHLEIFE
|
|
|
|
|
currentGame->initHand();
|
|
|
|
|
currentGame->startHand();
|
|
|
|
|
// SPIEL-SCHLEIFE
|
2007-05-18 17:13:27 +00:00
|
|
|
}
|
|
|
|
|
|
2007-05-20 00:16:29 +00:00
|
|
|
void Session::startClientGame(boost::shared_ptr<Game> game)
|
2007-05-18 17:13:27 +00:00
|
|
|
{
|
2010-03-30 12:25:30 +00:00
|
|
|
currentGameNum++;
|
2007-05-18 17:13:27 +00:00
|
|
|
|
2010-03-30 12:25:30 +00:00
|
|
|
currentGame = game;
|
2007-01-13 02:40:33 +00:00
|
|
|
}
|
2007-02-18 13:45:56 +00:00
|
|
|
|
2007-05-11 12:01:13 +00:00
|
|
|
Game *Session::getCurrentGame()
|
|
|
|
|
{
|
2010-03-30 12:25:30 +00:00
|
|
|
return currentGame.get();
|
2007-05-11 12:01:13 +00:00
|
|
|
}
|
|
|
|
|
|
2007-05-14 12:40:42 +00:00
|
|
|
GuiInterface *Session::getGui()
|
|
|
|
|
{
|
2010-03-30 12:25:30 +00:00
|
|
|
return myGui;
|
2007-05-14 12:40:42 +00:00
|
|
|
}
|
|
|
|
|
|
2007-10-15 08:37:32 +00:00
|
|
|
Session::GameType Session::getGameType()
|
2007-10-08 20:14:44 +00:00
|
|
|
{
|
2010-03-30 12:25:30 +00:00
|
|
|
return myGameType;
|
2007-10-08 20:14:44 +00:00
|
|
|
}
|
|
|
|
|
|
2007-10-15 08:37:32 +00:00
|
|
|
boost::shared_ptr<AvatarManager> Session::getAvatarManager()
|
|
|
|
|
{
|
2010-03-30 12:25:30 +00:00
|
|
|
return myAvatarManager;
|
2007-10-15 08:37:32 +00:00
|
|
|
}
|
|
|
|
|
|
2009-11-08 21:18:25 +00:00
|
|
|
void Session::startInternetClient()
|
2007-08-26 12:15:10 +00:00
|
|
|
{
|
2010-03-30 12:25:30 +00:00
|
|
|
if (myNetClient || !myGui)
|
|
|
|
|
{
|
|
|
|
|
assert(false);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
myGameType = GAME_TYPE_INTERNET;
|
2007-10-08 20:14:44 +00:00
|
|
|
|
2010-03-30 12:25:30 +00:00
|
|
|
myNetClient.reset(new ClientThread(*myGui, *myAvatarManager));
|
|
|
|
|
bool useAvatarServer = myConfig->readConfigInt("UseAvatarServer") != 0;
|
2009-04-05 21:26:36 +00:00
|
|
|
|
2010-03-30 12:25:30 +00:00
|
|
|
myNetClient->Init(
|
|
|
|
|
myConfig->readConfigString("InternetServerAddress"),
|
|
|
|
|
myConfig->readConfigString("InternetServerListAddress"),
|
|
|
|
|
myConfig->readConfigInt("InternetServerConfigMode") == 0,
|
|
|
|
|
myConfig->readConfigInt("InternetServerPort"),
|
|
|
|
|
myConfig->readConfigInt("InternetServerUseIpv6") == 1,
|
|
|
|
|
myConfig->readConfigInt("InternetServerUseSctp") == 1,
|
|
|
|
|
useAvatarServer ? myConfig->readConfigString("AvatarServerAddress") : "",
|
|
|
|
|
myConfig->readConfigString("MyName"),
|
|
|
|
|
myConfig->readConfigString("MyAvatar"),
|
|
|
|
|
myQtToolsInterface->stringFromUtf8(myConfig->readConfigString("CacheDir")));
|
|
|
|
|
myNetClient->Run();
|
2007-08-26 12:15:10 +00:00
|
|
|
}
|
|
|
|
|
|
2009-11-14 12:39:25 +00:00
|
|
|
void Session::startNetworkClient(const string &serverAddress, unsigned serverPort, bool ipv6, bool sctp)
|
2007-02-18 13:45:56 +00:00
|
|
|
{
|
2010-03-30 12:25:30 +00:00
|
|
|
if (myNetClient || !myGui)
|
|
|
|
|
{
|
|
|
|
|
assert(false);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
myGameType = GAME_TYPE_NETWORK;
|
2007-10-08 20:14:44 +00:00
|
|
|
|
2010-03-30 12:25:30 +00:00
|
|
|
myNetClient.reset(new ClientThread(*myGui, *myAvatarManager));
|
|
|
|
|
myNetClient->Init(
|
|
|
|
|
serverAddress,
|
|
|
|
|
"",
|
|
|
|
|
false,
|
|
|
|
|
serverPort,
|
|
|
|
|
ipv6,
|
|
|
|
|
sctp,
|
|
|
|
|
"", // no avatar server
|
|
|
|
|
myConfig->readConfigString("MyName"),
|
|
|
|
|
myConfig->readConfigString("MyAvatar"),
|
|
|
|
|
myQtToolsInterface->stringFromUtf8(myConfig->readConfigString("CacheDir")));
|
|
|
|
|
myNetClient->Run();
|
|
|
|
|
myNetClient->SendJoinFirstGame("");
|
2007-02-18 13:45:56 +00:00
|
|
|
}
|
|
|
|
|
|
2007-08-26 12:15:10 +00:00
|
|
|
void Session::startNetworkClientForLocalServer(const GameData &gameData)
|
2007-03-20 14:05:16 +00:00
|
|
|
{
|
2010-03-30 12:25:30 +00:00
|
|
|
if (myNetClient || !myGui)
|
|
|
|
|
{
|
|
|
|
|
assert(false);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
myGameType = GAME_TYPE_NETWORK;
|
2007-10-08 20:14:44 +00:00
|
|
|
|
2010-03-30 12:25:30 +00:00
|
|
|
myNetClient.reset(new ClientThread(*myGui, *myAvatarManager));
|
|
|
|
|
bool useIpv6 = myConfig->readConfigInt("ServerUseIpv6") == 1;
|
|
|
|
|
const char *loopbackAddr = useIpv6 ? "::1" : "127.0.0.1";
|
|
|
|
|
myNetClient->Init(
|
|
|
|
|
loopbackAddr,
|
|
|
|
|
"",
|
|
|
|
|
false,
|
|
|
|
|
myConfig->readConfigInt("ServerPort"),
|
|
|
|
|
useIpv6,
|
|
|
|
|
myConfig->readConfigInt("ServerUseSctp") == 1,
|
|
|
|
|
"", // no avatar server
|
|
|
|
|
myConfig->readConfigString("MyName"),
|
|
|
|
|
myConfig->readConfigString("MyAvatar"),
|
|
|
|
|
myQtToolsInterface->stringFromUtf8(myConfig->readConfigString("CacheDir")));
|
|
|
|
|
myNetClient->Run();
|
|
|
|
|
myNetClient->SendCreateGame(gameData, NET_DEFAULT_GAME, "");
|
2007-03-20 14:05:16 +00:00
|
|
|
}
|
|
|
|
|
|
2007-02-18 13:45:56 +00:00
|
|
|
void Session::terminateNetworkClient()
|
|
|
|
|
{
|
2010-03-30 12:25:30 +00:00
|
|
|
if (!myNetClient)
|
|
|
|
|
return; // already terminated
|
|
|
|
|
myNetClient->SignalTermination();
|
|
|
|
|
// Give the threads some time to terminate.
|
|
|
|
|
if (myNetClient->Join(NET_CLIENT_TERMINATE_TIMEOUT_MSEC))
|
|
|
|
|
myNetClient.reset();
|
2007-10-08 20:14:44 +00:00
|
|
|
|
2010-03-30 12:25:30 +00:00
|
|
|
// If termination fails, leave a memory leak to prevent a crash.
|
|
|
|
|
myGameType = GAME_TYPE_NONE;
|
2007-02-18 13:45:56 +00:00
|
|
|
}
|
2007-02-25 23:16:26 +00:00
|
|
|
|
2007-08-21 12:34:33 +00:00
|
|
|
void Session::clientCreateGame(const GameData &gameData, const string &name, const string &password)
|
|
|
|
|
{
|
2010-03-30 12:25:30 +00:00
|
|
|
if (!myNetClient)
|
|
|
|
|
return; // only act if client is running.
|
|
|
|
|
myNetClient->SendCreateGame(gameData, name, password);
|
2007-08-21 12:34:33 +00:00
|
|
|
}
|
|
|
|
|
|
2007-09-05 19:14:34 +00:00
|
|
|
void Session::clientJoinGame(unsigned gameId, const std::string &password)
|
2007-08-21 12:34:33 +00:00
|
|
|
{
|
2010-03-30 12:25:30 +00:00
|
|
|
if (!myNetClient)
|
|
|
|
|
return; // only act if client is running.
|
|
|
|
|
myNetClient->SendJoinGame(gameId, password);
|
2007-08-21 12:34:33 +00:00
|
|
|
}
|
|
|
|
|
|
2009-11-08 09:48:01 +00:00
|
|
|
void Session::startNetworkServer(bool dedicated)
|
2007-02-25 23:16:26 +00:00
|
|
|
{
|
2010-03-30 12:25:30 +00:00
|
|
|
if (myNetServer)
|
|
|
|
|
{
|
|
|
|
|
assert(false);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2007-11-16 00:58:23 +00:00
|
|
|
|
2010-03-30 12:25:30 +00:00
|
|
|
myNetServer.reset(new ServerManager(*myGui, myConfig, *myAvatarManager));
|
2007-11-16 00:58:23 +00:00
|
|
|
|
2010-03-30 12:25:30 +00:00
|
|
|
boost::shared_ptr<IrcThread> tmpIrcAdminThread;
|
|
|
|
|
boost::shared_ptr<IrcThread> tmpIrcLobbyThread;
|
|
|
|
|
if (myConfig->readConfigInt("UseAdminIRC"))
|
|
|
|
|
{
|
|
|
|
|
tmpIrcAdminThread = boost::shared_ptr<IrcThread>(new IrcThread(&myNetServer->GetAdminBot()));
|
2007-11-16 00:58:23 +00:00
|
|
|
|
2010-03-30 12:25:30 +00:00
|
|
|
tmpIrcAdminThread->Init(
|
|
|
|
|
myConfig->readConfigString("AdminIRCServerAddress"),
|
|
|
|
|
myConfig->readConfigInt("AdminIRCServerPort"),
|
|
|
|
|
myConfig->readConfigInt("AdminIRCServerUseIpv6") == 1,
|
|
|
|
|
myConfig->readConfigString("AdminIRCServerNick"),
|
|
|
|
|
myConfig->readConfigString("AdminIRCChannel"),
|
|
|
|
|
myConfig->readConfigString("AdminIRCChannelPassword"));
|
|
|
|
|
}
|
2009-08-20 15:19:41 +00:00
|
|
|
|
2010-03-30 12:25:30 +00:00
|
|
|
if (myConfig->readConfigInt("UseLobbyIRC"))
|
|
|
|
|
{
|
|
|
|
|
tmpIrcLobbyThread = boost::shared_ptr<IrcThread>(new IrcThread(&myNetServer->GetLobbyBot()));
|
2007-11-16 00:58:23 +00:00
|
|
|
|
2010-03-30 12:25:30 +00:00
|
|
|
tmpIrcLobbyThread->Init(
|
|
|
|
|
myConfig->readConfigString("LobbyIRCServerAddress"),
|
|
|
|
|
myConfig->readConfigInt("LobbyIRCServerPort"),
|
|
|
|
|
myConfig->readConfigInt("LobbyIRCServerUseIpv6") == 1,
|
|
|
|
|
myConfig->readConfigString("LobbyIRCServerNick"),
|
|
|
|
|
myConfig->readConfigString("LobbyIRCChannel"),
|
|
|
|
|
myConfig->readConfigString("LobbyIRCChannelPassword"));
|
|
|
|
|
}
|
2009-11-08 09:48:01 +00:00
|
|
|
|
2010-03-30 12:25:30 +00:00
|
|
|
ServerMode mode;
|
|
|
|
|
if (dedicated)
|
|
|
|
|
{
|
|
|
|
|
#ifdef POKERTH_OFFICIAL_SERVER
|
|
|
|
|
mode = SERVER_MODE_INTERNET_AUTH;
|
|
|
|
|
#else
|
|
|
|
|
mode = SERVER_MODE_INTERNET_NOAUTH;
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
mode = SERVER_MODE_LAN;
|
2007-11-16 00:58:23 +00:00
|
|
|
|
2010-03-30 12:25:30 +00:00
|
|
|
myNetServer->Init(
|
|
|
|
|
myConfig->readConfigInt("ServerPort"),
|
|
|
|
|
myConfig->readConfigInt("ServerUseIpv6") == 1,
|
|
|
|
|
myConfig->readConfigInt("ServerUseSctp") == 1 ? TRANSPORT_PROTOCOL_TCP_SCTP : TRANSPORT_PROTOCOL_TCP,
|
|
|
|
|
mode,
|
|
|
|
|
myQtToolsInterface->stringFromUtf8(myConfig->readConfigString("LogDir")),
|
|
|
|
|
tmpIrcAdminThread,
|
|
|
|
|
tmpIrcLobbyThread
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
myNetServer->RunAll();
|
2007-02-25 23:16:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Session::terminateNetworkServer()
|
|
|
|
|
{
|
2010-03-30 12:25:30 +00:00
|
|
|
if (!myNetServer)
|
|
|
|
|
return; // already terminated
|
|
|
|
|
myNetServer->SignalTerminationAll();
|
|
|
|
|
// Give the thread some time to terminate.
|
|
|
|
|
if (myNetServer->JoinAll(true))
|
|
|
|
|
myNetServer.reset();
|
|
|
|
|
// If termination fails, leave a memory leak to prevent a crash.
|
2007-02-25 23:16:26 +00:00
|
|
|
}
|
|
|
|
|
|
2007-11-16 22:34:38 +00:00
|
|
|
bool Session::pollNetworkServerTerminated()
|
2007-07-30 23:22:58 +00:00
|
|
|
{
|
2010-03-30 12:25:30 +00:00
|
|
|
bool retVal = false;
|
|
|
|
|
if (!myNetServer)
|
|
|
|
|
retVal = true; // already terminated
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
myNetServer->Process();
|
|
|
|
|
if (myNetServer->JoinAll(false))
|
|
|
|
|
retVal = true;
|
|
|
|
|
}
|
|
|
|
|
return retVal;
|
2007-07-30 23:22:58 +00:00
|
|
|
}
|
|
|
|
|
|
2007-09-06 19:09:05 +00:00
|
|
|
void Session::sendLeaveCurrentGame()
|
|
|
|
|
{
|
2010-03-30 12:25:30 +00:00
|
|
|
if (!myNetClient)
|
|
|
|
|
return; // only act if client is running.
|
|
|
|
|
myNetClient->SendLeaveCurrentGame();
|
2007-09-06 19:09:05 +00:00
|
|
|
}
|
|
|
|
|
|
2007-09-05 19:14:34 +00:00
|
|
|
void Session::sendStartEvent(bool fillUpWithCpuPlayers)
|
2007-08-02 20:52:13 +00:00
|
|
|
{
|
2010-03-30 12:25:30 +00:00
|
|
|
if (!myNetClient)
|
|
|
|
|
return; // only act if client is running.
|
|
|
|
|
myNetClient->SendStartEvent(fillUpWithCpuPlayers);
|
2007-08-02 20:52:13 +00:00
|
|
|
}
|
|
|
|
|
|
2007-05-23 22:31:56 +00:00
|
|
|
void Session::sendClientPlayerAction()
|
|
|
|
|
{
|
2010-03-30 12:25:30 +00:00
|
|
|
if (!myNetClient)
|
|
|
|
|
return; // only act if client is running.
|
|
|
|
|
myNetClient->SendPlayerAction();
|
2007-05-23 22:31:56 +00:00
|
|
|
}
|
|
|
|
|
|
2009-08-15 10:25:13 +00:00
|
|
|
void Session::sendGameChatMessage(const std::string &message)
|
2007-06-07 21:19:06 +00:00
|
|
|
{
|
2010-03-30 12:25:30 +00:00
|
|
|
if (!myNetClient)
|
|
|
|
|
return; // only act if client is running.
|
|
|
|
|
myNetClient->SendGameChatMessage(message);
|
2009-08-15 10:25:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Session::sendLobbyChatMessage(const std::string &message)
|
|
|
|
|
{
|
2010-03-30 12:25:30 +00:00
|
|
|
if (!myNetClient)
|
|
|
|
|
return;
|
|
|
|
|
myNetClient->SendLobbyChatMessage(message);
|
2007-05-25 00:09:51 +00:00
|
|
|
}
|
2007-05-26 17:06:03 +00:00
|
|
|
|
2010-11-07 08:24:31 +00:00
|
|
|
void Session::sendPrivateChatMessage(unsigned targetPlayerId, const std::string &message)
|
|
|
|
|
{
|
|
|
|
|
if (!myNetClient)
|
|
|
|
|
return;
|
|
|
|
|
myNetClient->SendPrivateChatMessage(targetPlayerId, message);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-09-05 19:14:34 +00:00
|
|
|
void Session::kickPlayer(unsigned playerId)
|
2007-06-07 21:19:06 +00:00
|
|
|
{
|
2010-03-30 12:25:30 +00:00
|
|
|
if (!myNetClient)
|
|
|
|
|
return; // only act if client is running.
|
|
|
|
|
myNetClient->SendKickPlayer(playerId);
|
2007-06-07 21:19:06 +00:00
|
|
|
}
|
|
|
|
|
|
2008-03-04 23:47:45 +00:00
|
|
|
void Session::resetNetworkTimeout()
|
|
|
|
|
{
|
2010-03-30 12:25:30 +00:00
|
|
|
if (!myNetClient)
|
|
|
|
|
return; // only act if client is running.
|
|
|
|
|
myNetClient->SendResetTimeout();
|
2008-03-04 23:47:45 +00:00
|
|
|
}
|
|
|
|
|
|
2007-10-27 18:51:53 +00:00
|
|
|
void Session::kickPlayer(const string &playerName)
|
|
|
|
|
{
|
2010-03-30 12:25:30 +00:00
|
|
|
if (!myNetClient)
|
|
|
|
|
return; // only act if client is running.
|
|
|
|
|
unsigned playerId;
|
|
|
|
|
if (myNetClient->GetPlayerIdFromName(playerName, playerId))
|
|
|
|
|
kickPlayer(playerId);
|
2007-10-27 18:51:53 +00:00
|
|
|
}
|
|
|
|
|
|
2008-11-16 22:57:11 +00:00
|
|
|
void Session::startVoteKickPlayer(unsigned playerId)
|
|
|
|
|
{
|
2010-03-30 12:25:30 +00:00
|
|
|
if (!myNetClient)
|
|
|
|
|
return; // only act if client is running.
|
|
|
|
|
myNetClient->SendAskKickPlayer(playerId);
|
2008-11-16 22:57:11 +00:00
|
|
|
}
|
|
|
|
|
|
2009-04-05 12:31:12 +00:00
|
|
|
void Session::selectServer(unsigned serverId)
|
|
|
|
|
{
|
2010-03-30 12:25:30 +00:00
|
|
|
if (!myNetClient)
|
|
|
|
|
return; // only act if client is running.
|
|
|
|
|
myNetClient->SelectServer(serverId);
|
2009-04-05 12:31:12 +00:00
|
|
|
}
|
|
|
|
|
|
2009-11-14 15:04:31 +00:00
|
|
|
void
|
2010-03-30 12:25:30 +00:00
|
|
|
Session::setLogin(const std::string &userName, const std::string &password, bool isGuest)
|
2009-11-14 15:04:31 +00:00
|
|
|
{
|
2010-03-30 12:25:30 +00:00
|
|
|
if (!myNetClient)
|
|
|
|
|
return; // only act if client is running.
|
|
|
|
|
myNetClient->SetLogin(userName, password, isGuest);
|
2009-11-14 15:04:31 +00:00
|
|
|
}
|
|
|
|
|
|
2010-03-29 12:33:12 +00:00
|
|
|
void
|
2010-03-30 12:25:30 +00:00
|
|
|
Session::invitePlayerToCurrentGame(unsigned playerId)
|
2010-03-29 12:33:12 +00:00
|
|
|
{
|
2010-03-30 12:25:30 +00:00
|
|
|
if (!myNetClient)
|
|
|
|
|
return; // only act if client is running.
|
|
|
|
|
myNetClient->SendInvitePlayerToCurrentGame(playerId);
|
2010-03-29 12:33:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2010-03-30 12:25:30 +00:00
|
|
|
Session::acceptGameInvitation(unsigned gameId)
|
2010-03-29 12:33:12 +00:00
|
|
|
{
|
2010-03-30 12:25:30 +00:00
|
|
|
if (!myNetClient)
|
|
|
|
|
return; // only act if client is running.
|
|
|
|
|
myNetClient->SendJoinGame(gameId, "");
|
2010-03-29 12:33:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2010-03-30 12:25:30 +00:00
|
|
|
Session::rejectGameInvitation(unsigned gameId, DenyGameInvitationReason reason)
|
2010-03-29 12:33:12 +00:00
|
|
|
{
|
2010-03-30 12:25:30 +00:00
|
|
|
if (!myNetClient)
|
|
|
|
|
return; // only act if client is running.
|
|
|
|
|
myNetClient->SendRejectGameInvitation(gameId, reason);
|
2010-03-29 12:33:12 +00:00
|
|
|
}
|
|
|
|
|
|
2010-12-24 12:27:46 +00:00
|
|
|
void Session::reportBadAvatar(unsigned reportedPlayerId, const std::string &avatarHash)
|
|
|
|
|
{
|
|
|
|
|
if (!myNetClient)
|
|
|
|
|
return; // only act if client is running.
|
|
|
|
|
myNetClient->SendReportAvatar(reportedPlayerId, avatarHash);
|
|
|
|
|
}
|
|
|
|
|
|
2008-11-25 22:18:17 +00:00
|
|
|
void Session::voteKick(bool doKick)
|
|
|
|
|
{
|
2010-03-30 12:25:30 +00:00
|
|
|
if (!myNetClient)
|
|
|
|
|
return; // only act if client is running.
|
|
|
|
|
myNetClient->SendVoteKick(doKick);
|
2008-11-25 22:18:17 +00:00
|
|
|
}
|
|
|
|
|
|
2010-07-15 21:55:52 +00:00
|
|
|
void Session::showMyCards()
|
|
|
|
|
{
|
|
|
|
|
if (!myNetClient)
|
2010-07-18 11:42:42 +00:00
|
|
|
return; // only act if client is running.
|
2010-07-15 21:55:52 +00:00
|
|
|
myNetClient->SendShowMyCards();
|
|
|
|
|
}
|
|
|
|
|
|
2007-05-26 17:06:03 +00:00
|
|
|
bool Session::isNetworkClientRunning() const
|
|
|
|
|
{
|
2010-03-30 12:25:30 +00:00
|
|
|
// This, and every place which calls this, is a HACK.
|
|
|
|
|
return myNetClient.get() != NULL;
|
2007-05-26 17:06:03 +00:00
|
|
|
}
|
2007-06-04 16:19:11 +00:00
|
|
|
|
2007-06-10 23:28:25 +00:00
|
|
|
bool Session::isNetworkServerRunning() const
|
|
|
|
|
{
|
2010-03-30 12:25:30 +00:00
|
|
|
// This, and every place which calls this, is a HACK.
|
|
|
|
|
return myNetServer.get() != NULL;
|
2007-06-10 23:28:25 +00:00
|
|
|
}
|
2007-08-27 09:57:51 +00:00
|
|
|
|
2009-04-05 11:19:50 +00:00
|
|
|
ServerInfo Session::getClientServerInfo(unsigned serverId) const
|
|
|
|
|
{
|
2010-03-30 12:25:30 +00:00
|
|
|
ServerInfo info;
|
|
|
|
|
if (myNetClient)
|
|
|
|
|
info = myNetClient->GetServerInfo(serverId);
|
|
|
|
|
return info;
|
2009-04-05 11:19:50 +00:00
|
|
|
}
|
|
|
|
|
|
2007-10-28 19:38:49 +00:00
|
|
|
GameInfo Session::getClientGameInfo(unsigned playerId) const
|
2007-08-27 09:57:51 +00:00
|
|
|
{
|
2010-03-30 12:25:30 +00:00
|
|
|
GameInfo info;
|
|
|
|
|
if (myNetClient)
|
|
|
|
|
info = myNetClient->GetGameInfo(playerId);
|
|
|
|
|
return info;
|
2007-09-02 16:36:52 +00:00
|
|
|
}
|
|
|
|
|
|
2007-10-28 19:38:49 +00:00
|
|
|
PlayerInfo Session::getClientPlayerInfo(unsigned playerId) const
|
2007-09-02 16:36:52 +00:00
|
|
|
{
|
2010-03-30 12:25:30 +00:00
|
|
|
PlayerInfo info;
|
|
|
|
|
if (myNetClient)
|
|
|
|
|
info = myNetClient->GetPlayerInfo(playerId);
|
|
|
|
|
return info;
|
2007-08-27 09:57:51 +00:00
|
|
|
}
|
|
|
|
|
|
2010-07-15 10:34:24 +00:00
|
|
|
unsigned Session::getGameIdOfPlayer(unsigned playerId) const
|
|
|
|
|
{
|
|
|
|
|
unsigned gameId = 0;
|
|
|
|
|
if (myNetClient)
|
|
|
|
|
gameId = myNetClient->GetGameIdOfPlayer(playerId);
|
|
|
|
|
return gameId;
|
|
|
|
|
}
|
|
|
|
|
|
2007-10-28 19:38:49 +00:00
|
|
|
ServerStats Session::getClientStats() const
|
2007-10-20 22:22:11 +00:00
|
|
|
{
|
2010-03-30 12:25:30 +00:00
|
|
|
ServerStats stats;
|
|
|
|
|
if (myNetClient)
|
|
|
|
|
stats = myNetClient->GetStatData();
|
|
|
|
|
return stats;
|
2007-10-20 22:22:11 +00:00
|
|
|
}
|
|
|
|
|
|
2007-10-28 19:38:49 +00:00
|
|
|
unsigned Session::getClientCurrentGameId() const
|
|
|
|
|
{
|
2010-03-30 12:25:30 +00:00
|
|
|
unsigned id = 0;
|
|
|
|
|
if (myNetClient)
|
|
|
|
|
id = myNetClient->GetGameId();
|
|
|
|
|
return id;
|
2007-10-28 19:38:49 +00:00
|
|
|
}
|
|
|
|
|
|
2010-03-24 20:10:36 +00:00
|
|
|
unsigned Session::getClientUniquePlayerId() const
|
|
|
|
|
{
|
2010-03-30 12:25:30 +00:00
|
|
|
unsigned id = 0;
|
|
|
|
|
if (myNetClient)
|
|
|
|
|
id = myNetClient->GetGuiPlayerId();
|
|
|
|
|
return id;
|
2010-03-24 20:10:36 +00:00
|
|
|
}
|
|
|
|
|
|
2007-11-01 10:09:29 +00:00
|
|
|
bool Session::getAvatarFile(const MD5Buf &avatarMD5, std::string &fileName)
|
|
|
|
|
{
|
2010-03-30 12:25:30 +00:00
|
|
|
bool retVal = false;
|
|
|
|
|
if (myAvatarManager.get())
|
|
|
|
|
{
|
|
|
|
|
string tmpFileName;
|
|
|
|
|
retVal = myAvatarManager->GetAvatarFileName(avatarMD5, tmpFileName);
|
|
|
|
|
if (retVal)
|
|
|
|
|
fileName = myQtToolsInterface->stringToUtf8(tmpFileName);
|
|
|
|
|
}
|
|
|
|
|
return retVal;
|
2007-11-01 10:09:29 +00:00
|
|
|
}
|
|
|
|
|
|