2011-07-02 14:38:06 +00:00
|
|
|
/*****************************************************************************
|
|
|
|
|
* PokerTH - The open source texas holdem engine *
|
2012-12-25 15:06:23 +01:00
|
|
|
* Copyright (C) 2006-2012 Felix Hammer, Florian Thauer, Lothar May *
|
2011-07-02 14:38:06 +00:00
|
|
|
* *
|
|
|
|
|
* This program is free software: you can redistribute it and/or modify *
|
|
|
|
|
* it under the terms of the GNU Affero General Public License as *
|
|
|
|
|
* published by the Free Software Foundation, either version 3 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 Affero General Public License for more details. *
|
|
|
|
|
* *
|
|
|
|
|
* You should have received a copy of the GNU Affero General Public License *
|
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
|
2012-12-25 15:06:23 +01:00
|
|
|
* *
|
|
|
|
|
* *
|
|
|
|
|
* Additional permission under GNU AGPL version 3 section 7 *
|
|
|
|
|
* *
|
|
|
|
|
* If you modify this program, or any covered work, by linking or *
|
|
|
|
|
* combining it with the OpenSSL project's OpenSSL library (or a *
|
|
|
|
|
* modified version of that library), containing parts covered by the *
|
|
|
|
|
* terms of the OpenSSL or SSLeay licenses, the authors of PokerTH *
|
|
|
|
|
* (Felix Hammer, Florian Thauer, Lothar May) grant you additional *
|
|
|
|
|
* permission to convey the resulting work. *
|
|
|
|
|
* Corresponding Source for a non-source form of such a combination *
|
|
|
|
|
* shall include the source code for the parts of OpenSSL used as well *
|
|
|
|
|
* as that of the covered work. *
|
2011-07-02 14:38:06 +00:00
|
|
|
*****************************************************************************/
|
2007-11-16 15:24:25 +00:00
|
|
|
|
2009-05-04 21:11:29 +00:00
|
|
|
#include <boost/asio.hpp>
|
2008-04-16 20:38:11 +00:00
|
|
|
#include <net/socket_helper.h>
|
2007-11-16 15:24:25 +00:00
|
|
|
#include <net/clientthread.h>
|
|
|
|
|
#include <net/clientstate.h>
|
|
|
|
|
#include <net/clientcontext.h>
|
2009-05-10 22:21:20 +00:00
|
|
|
#include <net/senderhelper.h>
|
2009-03-21 01:39:00 +00:00
|
|
|
#include <net/downloaderthread.h>
|
2007-11-16 15:24:25 +00:00
|
|
|
#include <net/clientexception.h>
|
|
|
|
|
#include <net/socket_msg.h>
|
2010-08-01 19:23:08 +00:00
|
|
|
#include <net/net_helper.h>
|
2007-11-16 15:24:25 +00:00
|
|
|
#include <core/avatarmanager.h>
|
|
|
|
|
#include <core/loghelper.h>
|
|
|
|
|
#include <clientenginefactory.h>
|
|
|
|
|
#include <game.h>
|
2011-01-03 18:41:28 +00:00
|
|
|
#include <log.h>
|
2007-12-11 20:40:39 +00:00
|
|
|
#include <qttoolsinterface.h>
|
2007-11-16 15:24:25 +00:00
|
|
|
|
|
|
|
|
#include <boost/lambda/lambda.hpp>
|
2012-09-24 12:22:13 +02:00
|
|
|
#include <boost/foreach.hpp>
|
2012-02-04 21:39:24 +00:00
|
|
|
#include <boost/filesystem.hpp>
|
2007-11-16 15:24:25 +00:00
|
|
|
#include <sstream>
|
2011-08-28 17:14:03 +00:00
|
|
|
#include <fstream>
|
2007-12-11 20:40:39 +00:00
|
|
|
#include <memory>
|
2007-11-16 15:24:25 +00:00
|
|
|
#include <cassert>
|
2009-10-13 21:03:32 +00:00
|
|
|
#include <gsasl.h>
|
2007-11-16 15:24:25 +00:00
|
|
|
|
2011-08-28 17:14:03 +00:00
|
|
|
#define TEMP_AVATAR_FILENAME "avatar.tmp"
|
|
|
|
|
#define TEMP_GUID_FILENAME "guid.tmp"
|
|
|
|
|
#define CLIENT_GUID_SIZE 16
|
2009-06-14 22:07:41 +00:00
|
|
|
#define CLIENT_AVATAR_LOOP_MSEC 100
|
|
|
|
|
#define CLIENT_SEND_LOOP_MSEC 50
|
2009-03-21 01:39:00 +00:00
|
|
|
|
2007-11-16 15:24:25 +00:00
|
|
|
using namespace std;
|
2012-02-04 21:39:24 +00:00
|
|
|
using namespace boost::filesystem;
|
2009-05-04 21:11:29 +00:00
|
|
|
using boost::asio::ip::tcp;
|
2007-11-16 15:24:25 +00:00
|
|
|
|
2011-11-06 20:03:32 +00:00
|
|
|
ClientThread::ClientThread(GuiInterface &gui, AvatarManager &avatarManager, Log *myLog)
|
|
|
|
|
: m_ioService(new boost::asio::io_service), m_clientLog(myLog), m_curState(NULL), m_gui(gui),
|
2011-02-11 20:02:08 +00:00
|
|
|
m_avatarManager(avatarManager), m_isServerSelected(false),
|
|
|
|
|
m_curGameId(0), m_curGameNum(1), m_guiPlayerId(0), m_sessionEstablished(false),
|
|
|
|
|
m_stateTimer(*m_ioService), m_avatarTimer(*m_ioService)
|
2007-11-16 15:24:25 +00:00
|
|
|
{
|
|
|
|
|
m_context.reset(new ClientContext);
|
2007-12-11 20:40:39 +00:00
|
|
|
myQtToolsInterface.reset(CreateQtToolsWrapper());
|
2011-02-19 23:47:24 +00:00
|
|
|
m_senderHelper.reset(new SenderHelper(m_ioService));
|
2007-11-16 15:24:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ClientThread::~ClientThread()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
ClientThread::Init(
|
2008-05-10 15:47:48 +00:00
|
|
|
const string &serverAddress, const string &serverListUrl,
|
2011-10-20 21:19:58 +00:00
|
|
|
const string &serverPassword,
|
2008-05-10 15:47:48 +00:00
|
|
|
bool useServerList, unsigned serverPort, bool ipv6, bool sctp,
|
2009-09-24 20:10:40 +00:00
|
|
|
const string &avatarServerAddress, const string &playerName,
|
2009-11-14 12:39:25 +00:00
|
|
|
const string &avatarFile, const string &cacheDir)
|
2007-11-16 15:24:25 +00:00
|
|
|
{
|
2011-02-11 20:02:08 +00:00
|
|
|
if (IsRunning()) {
|
2007-11-16 15:24:25 +00:00
|
|
|
assert(false);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ClientContext &context = GetContext();
|
|
|
|
|
|
2009-06-16 22:00:07 +00:00
|
|
|
context.SetSctp(sctp);
|
2007-11-16 15:24:25 +00:00
|
|
|
context.SetAddrFamily(ipv6 ? AF_INET6 : AF_INET);
|
|
|
|
|
context.SetServerAddr(serverAddress);
|
2008-05-10 15:47:48 +00:00
|
|
|
context.SetServerListUrl(serverListUrl);
|
2011-10-20 21:19:58 +00:00
|
|
|
context.SetServerPassword(serverPassword);
|
2008-05-10 15:47:48 +00:00
|
|
|
context.SetUseServerList(useServerList);
|
2007-11-16 15:24:25 +00:00
|
|
|
context.SetServerPort(serverPort);
|
2009-03-18 15:01:43 +00:00
|
|
|
context.SetAvatarServerAddr(avatarServerAddress);
|
2007-11-16 15:24:25 +00:00
|
|
|
context.SetPlayerName(playerName);
|
|
|
|
|
context.SetAvatarFile(avatarFile);
|
2008-04-19 11:48:09 +00:00
|
|
|
context.SetCacheDir(cacheDir);
|
2011-08-28 17:14:03 +00:00
|
|
|
|
|
|
|
|
ReadSessionGuidFromFile();
|
2007-11-16 15:24:25 +00:00
|
|
|
}
|
|
|
|
|
|
2009-06-14 22:07:41 +00:00
|
|
|
void
|
|
|
|
|
ClientThread::SignalTermination()
|
|
|
|
|
{
|
|
|
|
|
Thread::SignalTermination();
|
|
|
|
|
m_ioService->stop();
|
|
|
|
|
}
|
|
|
|
|
|
2007-11-16 15:24:25 +00:00
|
|
|
void
|
|
|
|
|
ClientThread::SendKickPlayer(unsigned playerId)
|
|
|
|
|
{
|
2012-09-18 15:57:58 +02:00
|
|
|
boost::shared_ptr<NetPacket> packet(new NetPacket);
|
|
|
|
|
packet->GetMsg()->set_messagetype(PokerTHMessage::Type_KickPlayerRequestMessage);
|
|
|
|
|
KickPlayerRequestMessage *netKick = packet->GetMsg()->mutable_kickplayerrequestmessage();
|
|
|
|
|
netKick->set_gameid(GetGameId());
|
|
|
|
|
netKick->set_playerid(playerId);
|
2009-08-02 15:11:40 +00:00
|
|
|
m_ioService->post(boost::bind(&ClientThread::SendSessionPacket, shared_from_this(), packet));
|
2007-11-16 15:24:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
ClientThread::SendLeaveCurrentGame()
|
|
|
|
|
{
|
2012-09-18 15:57:58 +02:00
|
|
|
boost::shared_ptr<NetPacket> packet(new NetPacket);
|
|
|
|
|
packet->GetMsg()->set_messagetype(PokerTHMessage::Type_LeaveGameRequestMessage);
|
|
|
|
|
LeaveGameRequestMessage *netLeave = packet->GetMsg()->mutable_leavegamerequestmessage();
|
|
|
|
|
netLeave->set_gameid(GetGameId());
|
2009-08-02 15:11:40 +00:00
|
|
|
m_ioService->post(boost::bind(&ClientThread::SendSessionPacket, shared_from_this(), packet));
|
2007-11-16 15:24:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
ClientThread::SendStartEvent(bool fillUpWithCpuPlayers)
|
|
|
|
|
{
|
|
|
|
|
// Warning: This function is called in the context of the GUI thread.
|
|
|
|
|
// Create a network packet for the server start event.
|
2012-09-18 15:57:58 +02:00
|
|
|
boost::shared_ptr<NetPacket> packet(new NetPacket);
|
|
|
|
|
packet->GetMsg()->set_messagetype(PokerTHMessage::Type_StartEventMessage);
|
|
|
|
|
StartEventMessage *netStartEvent = packet->GetMsg()->mutable_starteventmessage();
|
|
|
|
|
netStartEvent->set_starteventtype(StartEventMessage::startEvent);
|
|
|
|
|
netStartEvent->set_gameid(GetGameId());
|
|
|
|
|
netStartEvent->set_fillwithcomputerplayers(fillUpWithCpuPlayers);
|
2009-08-02 15:11:40 +00:00
|
|
|
m_ioService->post(boost::bind(&ClientThread::SendSessionPacket, shared_from_this(), packet));
|
2007-11-16 15:24:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
ClientThread::SendPlayerAction()
|
|
|
|
|
{
|
|
|
|
|
// Warning: This function is called in the context of the GUI thread.
|
|
|
|
|
// Create a network packet containing the current player action.
|
2012-09-18 15:57:58 +02:00
|
|
|
boost::shared_ptr<NetPacket> packet(new NetPacket);
|
|
|
|
|
packet->GetMsg()->set_messagetype(PokerTHMessage::Type_MyActionRequestMessage);
|
|
|
|
|
MyActionRequestMessage *netMyAction = packet->GetMsg()->mutable_myactionrequestmessage();
|
|
|
|
|
netMyAction->set_gameid(GetGameId());
|
2007-11-16 15:24:25 +00:00
|
|
|
boost::shared_ptr<PlayerInterface> myPlayer = GetGame()->getSeatsList()->front();
|
2012-09-18 15:57:58 +02:00
|
|
|
netMyAction->set_handnum(GetGame()->getCurrentHandID());
|
|
|
|
|
netMyAction->set_gamestate(static_cast<NetGameState>(GetGame()->getCurrentHand()->getCurrentRound()));
|
|
|
|
|
netMyAction->set_myaction(static_cast<NetPlayerAction>(myPlayer->getMyAction()));
|
2007-11-16 15:24:25 +00:00
|
|
|
// Only send last bet if not fold/checked.
|
2009-08-02 15:11:40 +00:00
|
|
|
if (myPlayer->getMyAction() != PLAYER_ACTION_FOLD && myPlayer->getMyAction() != PLAYER_ACTION_CHECK)
|
2012-09-18 15:57:58 +02:00
|
|
|
netMyAction->set_myrelativebet(myPlayer->getMyLastRelativeSet());
|
2007-11-16 15:24:25 +00:00
|
|
|
else
|
2012-09-18 15:57:58 +02:00
|
|
|
netMyAction->set_myrelativebet(0);
|
2009-08-02 15:11:40 +00:00
|
|
|
// Just dump the packet.
|
|
|
|
|
m_ioService->post(boost::bind(&ClientThread::SendSessionPacket, shared_from_this(), packet));
|
2007-11-16 15:24:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2009-08-15 10:25:13 +00:00
|
|
|
ClientThread::SendGameChatMessage(const std::string &msg)
|
2007-11-16 15:24:25 +00:00
|
|
|
{
|
|
|
|
|
// Warning: This function is called in the context of the GUI thread.
|
|
|
|
|
// Create a network packet containing the chat message.
|
2012-09-18 15:57:58 +02:00
|
|
|
boost::shared_ptr<NetPacket> packet(new NetPacket);
|
|
|
|
|
packet->GetMsg()->set_messagetype(PokerTHMessage::Type_ChatRequestMessage);
|
|
|
|
|
ChatRequestMessage *netChat = packet->GetMsg()->mutable_chatrequestmessage();
|
|
|
|
|
netChat->set_targetgameid(GetGameId());
|
|
|
|
|
netChat->set_chattext(msg);
|
2009-08-15 10:25:13 +00:00
|
|
|
|
|
|
|
|
// Just dump the packet.
|
|
|
|
|
m_ioService->post(boost::bind(&ClientThread::SendSessionPacket, shared_from_this(), packet));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
ClientThread::SendLobbyChatMessage(const std::string &msg)
|
|
|
|
|
{
|
|
|
|
|
// Warning: This function is called in the context of the GUI thread.
|
|
|
|
|
// Create a network packet containing the chat message.
|
2012-09-18 15:57:58 +02:00
|
|
|
boost::shared_ptr<NetPacket> packet(new NetPacket);
|
|
|
|
|
packet->GetMsg()->set_messagetype(PokerTHMessage::Type_ChatRequestMessage);
|
|
|
|
|
ChatRequestMessage *netChat = packet->GetMsg()->mutable_chatrequestmessage();
|
|
|
|
|
netChat->set_chattext(msg);
|
2009-08-15 10:25:13 +00:00
|
|
|
|
2009-08-02 15:11:40 +00:00
|
|
|
// Just dump the packet.
|
|
|
|
|
m_ioService->post(boost::bind(&ClientThread::SendSessionPacket, shared_from_this(), packet));
|
2007-11-16 15:24:25 +00:00
|
|
|
}
|
|
|
|
|
|
2010-11-07 08:24:31 +00:00
|
|
|
void
|
|
|
|
|
ClientThread::SendPrivateChatMessage(unsigned targetPlayerId, const std::string &msg)
|
|
|
|
|
{
|
|
|
|
|
// Warning: This function is called in the context of the GUI thread.
|
|
|
|
|
// Create a network packet containing the chat message.
|
2012-09-18 15:57:58 +02:00
|
|
|
boost::shared_ptr<NetPacket> packet(new NetPacket);
|
|
|
|
|
packet->GetMsg()->set_messagetype(PokerTHMessage::Type_ChatRequestMessage);
|
|
|
|
|
ChatRequestMessage *netChat = packet->GetMsg()->mutable_chatrequestmessage();
|
|
|
|
|
netChat->set_targetplayerid(targetPlayerId);
|
|
|
|
|
netChat->set_chattext(msg);
|
2010-11-07 08:24:31 +00:00
|
|
|
|
|
|
|
|
// Just dump the packet.
|
|
|
|
|
m_ioService->post(boost::bind(&ClientThread::SendSessionPacket, shared_from_this(), packet));
|
|
|
|
|
}
|
|
|
|
|
|
2007-11-16 15:24:25 +00:00
|
|
|
void
|
2011-02-06 13:17:07 +00:00
|
|
|
ClientThread::SendJoinFirstGame(const std::string &password, bool autoLeave)
|
2007-11-16 15:24:25 +00:00
|
|
|
{
|
|
|
|
|
// Warning: This function is called in the context of the GUI thread.
|
|
|
|
|
// Create a network packet to request joining a game.
|
2012-09-18 15:57:58 +02:00
|
|
|
boost::shared_ptr<NetPacket> packet(new NetPacket);
|
|
|
|
|
packet->GetMsg()->set_messagetype(PokerTHMessage::Type_JoinExistingGameMessage);
|
|
|
|
|
JoinExistingGameMessage *netJoinGame = packet->GetMsg()->mutable_joinexistinggamemessage();
|
|
|
|
|
netJoinGame->set_gameid(1);
|
|
|
|
|
netJoinGame->set_autoleave(autoLeave);
|
2009-08-02 15:11:40 +00:00
|
|
|
|
2011-10-03 08:03:58 +00:00
|
|
|
if (!password.empty()) {
|
2012-09-18 15:57:58 +02:00
|
|
|
netJoinGame->set_password(password);
|
2011-10-03 08:03:58 +00:00
|
|
|
}
|
2009-08-02 15:11:40 +00:00
|
|
|
m_ioService->post(boost::bind(&ClientThread::SendSessionPacket, shared_from_this(), packet));
|
2007-11-16 15:24:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2011-02-06 13:17:07 +00:00
|
|
|
ClientThread::SendJoinGame(unsigned gameId, const std::string &password, bool autoLeave)
|
2007-11-16 15:24:25 +00:00
|
|
|
{
|
|
|
|
|
// Warning: This function is called in the context of the GUI thread.
|
|
|
|
|
// Create a network packet to request joining a game.
|
2012-09-18 15:57:58 +02:00
|
|
|
boost::shared_ptr<NetPacket> packet(new NetPacket);
|
|
|
|
|
packet->GetMsg()->set_messagetype(PokerTHMessage::Type_JoinExistingGameMessage);
|
|
|
|
|
JoinExistingGameMessage *netJoinGame = packet->GetMsg()->mutable_joinexistinggamemessage();
|
|
|
|
|
netJoinGame->set_gameid(gameId);
|
|
|
|
|
netJoinGame->set_autoleave(autoLeave);
|
2009-08-02 15:11:40 +00:00
|
|
|
|
2011-10-03 08:03:58 +00:00
|
|
|
if (!password.empty()) {
|
2012-09-18 15:57:58 +02:00
|
|
|
netJoinGame->set_password(password);
|
2011-10-03 08:03:58 +00:00
|
|
|
}
|
2009-08-02 15:11:40 +00:00
|
|
|
m_ioService->post(boost::bind(&ClientThread::SendSessionPacket, shared_from_this(), packet));
|
2007-11-16 15:24:25 +00:00
|
|
|
}
|
|
|
|
|
|
2011-09-11 17:41:56 +00:00
|
|
|
void
|
|
|
|
|
ClientThread::SendRejoinGame(unsigned gameId, bool autoLeave)
|
|
|
|
|
{
|
|
|
|
|
// Warning: This function is called in the context of the GUI thread.
|
|
|
|
|
// Create a network packet to request rejoining a running game.
|
2012-09-18 15:57:58 +02:00
|
|
|
boost::shared_ptr<NetPacket> packet(new NetPacket);
|
|
|
|
|
packet->GetMsg()->set_messagetype(PokerTHMessage::Type_RejoinExistingGameMessage);
|
|
|
|
|
RejoinExistingGameMessage *netJoinGame = packet->GetMsg()->mutable_rejoinexistinggamemessage();
|
|
|
|
|
netJoinGame->set_gameid(gameId);
|
|
|
|
|
netJoinGame->set_autoleave(autoLeave);
|
2011-09-11 17:41:56 +00:00
|
|
|
|
|
|
|
|
m_ioService->post(boost::bind(&ClientThread::SendSessionPacket, shared_from_this(), packet));
|
|
|
|
|
}
|
|
|
|
|
|
2007-11-16 15:24:25 +00:00
|
|
|
void
|
2011-02-06 13:17:07 +00:00
|
|
|
ClientThread::SendCreateGame(const GameData &gameData, const std::string &name, const std::string &password, bool autoLeave)
|
2007-11-16 15:24:25 +00:00
|
|
|
{
|
|
|
|
|
// Warning: This function is called in the context of the GUI thread.
|
|
|
|
|
// Create a network packet to request creating a new game.
|
2012-09-18 15:57:58 +02:00
|
|
|
boost::shared_ptr<NetPacket> packet(new NetPacket);
|
|
|
|
|
packet->GetMsg()->set_messagetype(PokerTHMessage::Type_JoinNewGameMessage);
|
|
|
|
|
JoinNewGameMessage *netJoinGame = packet->GetMsg()->mutable_joinnewgamemessage();
|
|
|
|
|
netJoinGame->set_autoleave(autoLeave);
|
|
|
|
|
NetGameInfo *gameInfo = netJoinGame->mutable_gameinfo();
|
|
|
|
|
NetPacket::SetGameData(gameData, *gameInfo);
|
|
|
|
|
gameInfo->set_gamename(name);
|
2009-08-02 15:11:40 +00:00
|
|
|
|
2011-10-03 08:03:58 +00:00
|
|
|
if (!password.empty()) {
|
2012-09-18 15:57:58 +02:00
|
|
|
netJoinGame->set_password(password);
|
2011-10-03 08:03:58 +00:00
|
|
|
}
|
2009-08-02 15:11:40 +00:00
|
|
|
m_ioService->post(boost::bind(&ClientThread::SendSessionPacket, shared_from_this(), packet));
|
2007-11-16 15:24:25 +00:00
|
|
|
}
|
|
|
|
|
|
2008-03-04 23:47:45 +00:00
|
|
|
void
|
|
|
|
|
ClientThread::SendResetTimeout()
|
|
|
|
|
{
|
2012-09-18 15:57:58 +02:00
|
|
|
boost::shared_ptr<NetPacket> packet(new NetPacket);
|
|
|
|
|
packet->GetMsg()->set_messagetype(PokerTHMessage::Type_ResetTimeoutMessage);
|
2013-01-01 14:31:04 +01:00
|
|
|
packet->GetMsg()->mutable_resettimeoutmessage();
|
2009-08-02 15:11:40 +00:00
|
|
|
m_ioService->post(boost::bind(&ClientThread::SendSessionPacket, shared_from_this(), packet));
|
2008-03-04 23:47:45 +00:00
|
|
|
}
|
|
|
|
|
|
2008-11-16 22:57:11 +00:00
|
|
|
void
|
|
|
|
|
ClientThread::SendAskKickPlayer(unsigned playerId)
|
|
|
|
|
{
|
2012-09-18 15:57:58 +02:00
|
|
|
boost::shared_ptr<NetPacket> packet(new NetPacket);
|
|
|
|
|
packet->GetMsg()->set_messagetype(PokerTHMessage::Type_AskKickPlayerMessage);
|
|
|
|
|
AskKickPlayerMessage *netAsk = packet->GetMsg()->mutable_askkickplayermessage();
|
|
|
|
|
netAsk->set_gameid(GetGameId());
|
|
|
|
|
netAsk->set_playerid(playerId);
|
2009-08-02 15:11:40 +00:00
|
|
|
m_ioService->post(boost::bind(&ClientThread::SendSessionPacket, shared_from_this(), packet));
|
2008-11-16 22:57:11 +00:00
|
|
|
}
|
|
|
|
|
|
2008-11-25 22:18:17 +00:00
|
|
|
void
|
|
|
|
|
ClientThread::SendVoteKick(bool doKick)
|
|
|
|
|
{
|
2012-09-18 15:57:58 +02:00
|
|
|
boost::shared_ptr<NetPacket> packet(new NetPacket);
|
|
|
|
|
packet->GetMsg()->set_messagetype(PokerTHMessage::Type_VoteKickRequestMessage);
|
|
|
|
|
VoteKickRequestMessage *netVote = packet->GetMsg()->mutable_votekickrequestmessage();
|
|
|
|
|
netVote->set_gameid(GetGameId());
|
2008-11-25 22:18:17 +00:00
|
|
|
{
|
|
|
|
|
boost::mutex::scoped_lock lock(m_curPetitionIdMutex);
|
2012-09-18 15:57:58 +02:00
|
|
|
netVote->set_petitionid(m_curPetitionId);
|
2008-11-25 22:18:17 +00:00
|
|
|
}
|
2012-09-18 15:57:58 +02:00
|
|
|
netVote->set_votekick(doKick);
|
2009-08-02 15:11:40 +00:00
|
|
|
m_ioService->post(boost::bind(&ClientThread::SendSessionPacket, shared_from_this(), packet));
|
2008-11-25 22:18:17 +00:00
|
|
|
}
|
|
|
|
|
|
2010-07-15 21:55:52 +00:00
|
|
|
void
|
|
|
|
|
ClientThread::SendShowMyCards()
|
|
|
|
|
{
|
2012-09-18 15:57:58 +02:00
|
|
|
boost::shared_ptr<NetPacket> packet(new NetPacket);
|
|
|
|
|
packet->GetMsg()->set_messagetype(PokerTHMessage::Type_ShowMyCardsRequestMessage);
|
2013-01-01 14:31:04 +01:00
|
|
|
packet->GetMsg()->mutable_showmycardsrequestmessage();
|
2010-07-15 21:55:52 +00:00
|
|
|
m_ioService->post(boost::bind(&ClientThread::SendSessionPacket, shared_from_this(), packet));
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-29 12:33:12 +00:00
|
|
|
void
|
|
|
|
|
ClientThread::SendInvitePlayerToCurrentGame(unsigned playerId)
|
|
|
|
|
{
|
2012-09-18 15:57:58 +02:00
|
|
|
boost::shared_ptr<NetPacket> packet(new NetPacket);
|
|
|
|
|
packet->GetMsg()->set_messagetype(PokerTHMessage::Type_InvitePlayerToGameMessage);
|
|
|
|
|
InvitePlayerToGameMessage *netInvite = packet->GetMsg()->mutable_inviteplayertogamemessage();
|
|
|
|
|
netInvite->set_gameid(GetGameId());
|
|
|
|
|
netInvite->set_playerid(playerId);
|
2010-03-30 12:07:48 +00:00
|
|
|
m_ioService->post(boost::bind(&ClientThread::SendSessionPacket, shared_from_this(), packet));
|
2010-03-29 12:33:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
ClientThread::SendRejectGameInvitation(unsigned gameId, DenyGameInvitationReason reason)
|
|
|
|
|
{
|
2012-09-18 15:57:58 +02:00
|
|
|
boost::shared_ptr<NetPacket> packet(new NetPacket);
|
|
|
|
|
packet->GetMsg()->set_messagetype(PokerTHMessage::Type_RejectGameInvitationMessage);
|
|
|
|
|
RejectGameInvitationMessage *netReject = packet->GetMsg()->mutable_rejectgameinvitationmessage();
|
|
|
|
|
netReject->set_gameid(gameId);
|
|
|
|
|
netReject->set_myrejectreason(static_cast<RejectGameInvitationMessage::RejectGameInvReason>(reason));
|
2010-03-30 12:07:48 +00:00
|
|
|
m_ioService->post(boost::bind(&ClientThread::SendSessionPacket, shared_from_this(), packet));
|
2010-03-29 12:33:12 +00:00
|
|
|
}
|
|
|
|
|
|
2010-12-24 12:27:46 +00:00
|
|
|
void
|
|
|
|
|
ClientThread::SendReportAvatar(unsigned reportedPlayerId, const std::string &avatarHash)
|
|
|
|
|
{
|
2012-09-18 15:57:58 +02:00
|
|
|
boost::shared_ptr<NetPacket> packet(new NetPacket);
|
|
|
|
|
packet->GetMsg()->set_messagetype(PokerTHMessage::Type_ReportAvatarMessage);
|
|
|
|
|
ReportAvatarMessage *netReport = packet->GetMsg()->mutable_reportavatarmessage();
|
|
|
|
|
netReport->set_reportedplayerid(reportedPlayerId);
|
2010-12-24 12:27:46 +00:00
|
|
|
MD5Buf tmpMD5;
|
2011-02-11 20:02:08 +00:00
|
|
|
if (tmpMD5.FromString(avatarHash) && !tmpMD5.IsZero()) {
|
2012-09-18 15:57:58 +02:00
|
|
|
netReport->set_reportedavatarhash(tmpMD5.GetData(), MD5_DATA_SIZE);
|
2010-12-24 12:27:46 +00:00
|
|
|
|
|
|
|
|
m_ioService->post(boost::bind(&ClientThread::SendSessionPacket, shared_from_this(), packet));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-03-31 20:14:11 +00:00
|
|
|
void
|
|
|
|
|
ClientThread::SendReportGameName(unsigned reportedGameId)
|
|
|
|
|
{
|
2012-09-18 15:57:58 +02:00
|
|
|
boost::shared_ptr<NetPacket> packet(new NetPacket);
|
|
|
|
|
packet->GetMsg()->set_messagetype(PokerTHMessage::Type_ReportGameMessage);
|
|
|
|
|
ReportGameMessage *netReport = packet->GetMsg()->mutable_reportgamemessage();
|
|
|
|
|
netReport->set_reportedgameid(reportedGameId);
|
2012-03-31 20:14:11 +00:00
|
|
|
m_ioService->post(boost::bind(&ClientThread::SendSessionPacket, shared_from_this(), packet));
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-24 23:04:02 +01:00
|
|
|
void
|
|
|
|
|
ClientThread::SendAdminRemoveGame(unsigned removeGameId)
|
|
|
|
|
{
|
|
|
|
|
boost::shared_ptr<NetPacket> packet(new NetPacket);
|
|
|
|
|
packet->GetMsg()->set_messagetype(PokerTHMessage::Type_AdminRemoveGameMessage);
|
|
|
|
|
AdminRemoveGameMessage *netRemove = packet->GetMsg()->mutable_adminremovegamemessage();
|
|
|
|
|
netRemove->set_removegameid(removeGameId);
|
|
|
|
|
m_ioService->post(boost::bind(&ClientThread::SendSessionPacket, shared_from_this(), packet));
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-28 20:38:37 +01:00
|
|
|
void
|
|
|
|
|
ClientThread::SendAdminBanPlayer(unsigned playerId)
|
|
|
|
|
{
|
|
|
|
|
boost::shared_ptr<NetPacket> packet(new NetPacket);
|
|
|
|
|
packet->GetMsg()->set_messagetype(PokerTHMessage::Type_AdminBanPlayerMessage);
|
|
|
|
|
AdminBanPlayerMessage *netBan = packet->GetMsg()->mutable_adminbanplayermessage();
|
|
|
|
|
netBan->set_banplayerid(playerId);
|
|
|
|
|
m_ioService->post(boost::bind(&ClientThread::SendSessionPacket, shared_from_this(), packet));
|
|
|
|
|
}
|
|
|
|
|
|
2009-06-14 22:07:41 +00:00
|
|
|
void
|
|
|
|
|
ClientThread::StartAsyncRead()
|
|
|
|
|
{
|
2011-02-19 23:47:24 +00:00
|
|
|
GetContext().GetSessionData()->GetReceiveBuffer().StartAsyncRead(GetContext().GetSessionData());
|
2009-06-14 22:07:41 +00:00
|
|
|
}
|
|
|
|
|
|
2011-02-23 09:53:01 +00:00
|
|
|
void
|
2011-03-10 20:55:46 +00:00
|
|
|
ClientThread::CloseSession(boost::shared_ptr<SessionData> /*session*/)
|
2011-02-23 09:53:01 +00:00
|
|
|
{
|
|
|
|
|
throw NetException(__FILE__, __LINE__, ERR_SOCK_CONN_RESET, 0);
|
|
|
|
|
}
|
|
|
|
|
|
2009-06-14 22:07:41 +00:00
|
|
|
void
|
2011-02-19 23:47:24 +00:00
|
|
|
ClientThread::HandlePacket(boost::shared_ptr<SessionData> /*session*/, boost::shared_ptr<NetPacket> packet)
|
2009-06-14 22:07:41 +00:00
|
|
|
{
|
2011-02-19 23:47:24 +00:00
|
|
|
GetState().HandlePacket(shared_from_this(), packet);
|
2009-06-14 22:07:41 +00:00
|
|
|
}
|
|
|
|
|
|
2009-04-05 12:31:12 +00:00
|
|
|
void
|
|
|
|
|
ClientThread::SelectServer(unsigned serverId)
|
|
|
|
|
{
|
|
|
|
|
boost::mutex::scoped_lock lock(m_selectServerMutex);
|
|
|
|
|
m_isServerSelected = true;
|
|
|
|
|
m_selectedServerId = serverId;
|
|
|
|
|
}
|
|
|
|
|
|
2009-11-14 15:04:31 +00:00
|
|
|
void
|
|
|
|
|
ClientThread::SetLogin(const std::string &userName, const std::string &password, bool isGuest)
|
|
|
|
|
{
|
|
|
|
|
boost::mutex::scoped_lock lock(m_loginDataMutex);
|
|
|
|
|
m_loginData.userName = userName;
|
|
|
|
|
m_loginData.password = password;
|
|
|
|
|
m_loginData.isGuest = isGuest;
|
|
|
|
|
}
|
|
|
|
|
|
2009-04-05 11:19:50 +00:00
|
|
|
ServerInfo
|
|
|
|
|
ClientThread::GetServerInfo(unsigned serverId) const
|
|
|
|
|
{
|
|
|
|
|
ServerInfo tmpInfo;
|
|
|
|
|
boost::mutex::scoped_lock lock(m_serverInfoMapMutex);
|
|
|
|
|
ServerInfoMap::const_iterator pos = m_serverInfoMap.find(serverId);
|
2011-02-11 20:02:08 +00:00
|
|
|
if (pos != m_serverInfoMap.end()) {
|
2009-04-05 11:19:50 +00:00
|
|
|
tmpInfo = pos->second;
|
|
|
|
|
}
|
|
|
|
|
return tmpInfo;
|
|
|
|
|
}
|
|
|
|
|
|
2007-11-16 15:24:25 +00:00
|
|
|
GameInfo
|
|
|
|
|
ClientThread::GetGameInfo(unsigned gameId) const
|
|
|
|
|
{
|
|
|
|
|
GameInfo tmpInfo;
|
|
|
|
|
boost::mutex::scoped_lock lock(m_gameInfoMapMutex);
|
|
|
|
|
GameInfoMap::const_iterator pos = m_gameInfoMap.find(gameId);
|
2011-02-11 20:02:08 +00:00
|
|
|
if (pos != m_gameInfoMap.end()) {
|
2007-11-16 15:24:25 +00:00
|
|
|
tmpInfo = pos->second;
|
|
|
|
|
}
|
|
|
|
|
return tmpInfo;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PlayerInfo
|
|
|
|
|
ClientThread::GetPlayerInfo(unsigned playerId) const
|
|
|
|
|
{
|
|
|
|
|
PlayerInfo info;
|
2011-02-11 20:02:08 +00:00
|
|
|
if (!GetCachedPlayerInfo(playerId, info)) {
|
2007-11-16 15:24:25 +00:00
|
|
|
ostringstream name;
|
|
|
|
|
name << "#" << playerId;
|
|
|
|
|
|
|
|
|
|
info.playerName = name.str();
|
|
|
|
|
}
|
|
|
|
|
return info;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
|
ClientThread::GetPlayerIdFromName(const string &playerName, unsigned &playerId) const
|
|
|
|
|
{
|
|
|
|
|
bool retVal = false;
|
|
|
|
|
|
|
|
|
|
boost::mutex::scoped_lock lock(m_playerInfoMapMutex);
|
|
|
|
|
PlayerInfoMap::const_reverse_iterator i = m_playerInfoMap.rbegin();
|
|
|
|
|
PlayerInfoMap::const_reverse_iterator end = m_playerInfoMap.rend();
|
|
|
|
|
|
2011-02-11 20:02:08 +00:00
|
|
|
while (i != end) {
|
|
|
|
|
if (i->second.playerName == playerName) {
|
2007-11-16 15:24:25 +00:00
|
|
|
playerId = i->first;
|
|
|
|
|
retVal = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
++i;
|
|
|
|
|
}
|
|
|
|
|
return retVal;
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-15 10:34:24 +00:00
|
|
|
unsigned
|
|
|
|
|
ClientThread::GetGameIdOfPlayer(unsigned playerId) const
|
|
|
|
|
{
|
|
|
|
|
unsigned gameId = 0; // Default: no game (invalid id).
|
|
|
|
|
|
|
|
|
|
// Iterate through all games to find the player.
|
|
|
|
|
boost::mutex::scoped_lock lock(m_gameInfoMapMutex);
|
|
|
|
|
GameInfoMap::const_iterator i = m_gameInfoMap.begin();
|
|
|
|
|
GameInfoMap::const_iterator i_end = m_gameInfoMap.end();
|
2011-02-11 20:02:08 +00:00
|
|
|
while (i != i_end) {
|
2010-07-15 10:34:24 +00:00
|
|
|
PlayerIdList::const_iterator j = (*i).second.players.begin();
|
|
|
|
|
PlayerIdList::const_iterator j_end = (*i).second.players.end();
|
2011-02-11 20:02:08 +00:00
|
|
|
while (j != j_end) {
|
|
|
|
|
if (playerId == *j) {
|
2010-07-15 10:34:24 +00:00
|
|
|
gameId = (*i).first;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
++j;
|
|
|
|
|
}
|
|
|
|
|
if (gameId)
|
|
|
|
|
break;
|
|
|
|
|
++i;
|
|
|
|
|
}
|
|
|
|
|
return gameId;
|
|
|
|
|
}
|
|
|
|
|
|
2007-11-16 15:24:25 +00:00
|
|
|
ClientCallback &
|
|
|
|
|
ClientThread::GetCallback()
|
|
|
|
|
{
|
|
|
|
|
return m_gui;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
GuiInterface &
|
|
|
|
|
ClientThread::GetGui()
|
|
|
|
|
{
|
|
|
|
|
return m_gui;
|
|
|
|
|
}
|
|
|
|
|
|
2011-11-09 21:39:37 +00:00
|
|
|
boost::shared_ptr<Log>
|
|
|
|
|
ClientThread::GetClientLog()
|
|
|
|
|
{
|
|
|
|
|
return m_clientLog;
|
|
|
|
|
}
|
|
|
|
|
|
2007-11-16 15:24:25 +00:00
|
|
|
AvatarManager &
|
|
|
|
|
ClientThread::GetAvatarManager()
|
|
|
|
|
{
|
|
|
|
|
return m_avatarManager;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
ClientThread::Main()
|
|
|
|
|
{
|
2009-03-21 10:28:27 +00:00
|
|
|
// Main loop.
|
2009-05-10 17:53:37 +00:00
|
|
|
boost::asio::io_service::work ioWork(*m_ioService);
|
2011-02-11 20:02:08 +00:00
|
|
|
try {
|
2009-10-13 21:03:32 +00:00
|
|
|
InitAuthContext();
|
|
|
|
|
// Start sub-threads.
|
|
|
|
|
m_avatarDownloader.reset(new DownloaderThread);
|
|
|
|
|
m_avatarDownloader->Run();
|
|
|
|
|
SetState(CLIENT_INITIAL_STATE::Instance());
|
|
|
|
|
RegisterTimers();
|
|
|
|
|
|
2009-06-17 21:22:01 +00:00
|
|
|
boost::asio::io_service::work ioWork(*m_ioService);
|
|
|
|
|
m_ioService->run(); // Will only be aborted asynchronously.
|
2009-06-15 22:34:07 +00:00
|
|
|
|
2011-02-11 20:02:08 +00:00
|
|
|
} catch (const PokerTHException &e) {
|
2012-02-04 21:39:24 +00:00
|
|
|
// Delete the cached server list, as it may be outdated.
|
|
|
|
|
path tmpServerListPath(GetCacheServerListFileName());
|
|
|
|
|
if (exists(tmpServerListPath)) {
|
|
|
|
|
remove(tmpServerListPath);
|
|
|
|
|
}
|
2007-11-16 15:24:25 +00:00
|
|
|
GetCallback().SignalNetClientError(e.GetErrorId(), e.GetOsErrorCode());
|
|
|
|
|
}
|
2009-06-17 21:22:01 +00:00
|
|
|
// Close the socket.
|
|
|
|
|
boost::system::error_code ec;
|
2009-08-17 10:11:51 +00:00
|
|
|
GetContext().GetSessionData()->GetAsioSocket()->close(ec);
|
2009-06-17 21:22:01 +00:00
|
|
|
// Set a state which does not do anything.
|
|
|
|
|
SetState(CLIENT_FINAL_STATE::Instance());
|
2009-06-14 22:07:41 +00:00
|
|
|
// Cancel timers.
|
|
|
|
|
GetStateTimer().cancel();
|
|
|
|
|
CancelTimers();
|
2009-03-21 10:28:27 +00:00
|
|
|
// Terminate sub-threads.
|
2009-03-21 19:56:53 +00:00
|
|
|
m_avatarDownloader->SignalTermination();
|
|
|
|
|
m_avatarDownloader->Join(DOWNLOADER_THREAD_TERMINATE_TIMEOUT);
|
2009-10-13 21:03:32 +00:00
|
|
|
|
|
|
|
|
ClearAuthContext();
|
2007-11-16 15:24:25 +00:00
|
|
|
}
|
|
|
|
|
|
2009-06-14 22:07:41 +00:00
|
|
|
void
|
|
|
|
|
ClientThread::RegisterTimers()
|
|
|
|
|
{
|
|
|
|
|
m_avatarTimer.expires_from_now(
|
|
|
|
|
boost::posix_time::milliseconds(CLIENT_AVATAR_LOOP_MSEC));
|
|
|
|
|
m_avatarTimer.async_wait(
|
|
|
|
|
boost::bind(
|
|
|
|
|
&ClientThread::TimerCheckAvatarDownloads, shared_from_this(), boost::asio::placeholders::error));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
ClientThread::CancelTimers()
|
|
|
|
|
{
|
|
|
|
|
m_avatarTimer.cancel();
|
|
|
|
|
}
|
|
|
|
|
|
2009-10-13 21:03:32 +00:00
|
|
|
void
|
|
|
|
|
ClientThread::InitAuthContext()
|
|
|
|
|
{
|
|
|
|
|
int res = gsasl_init(&m_authContext);
|
|
|
|
|
if (res != GSASL_OK)
|
|
|
|
|
throw ClientException(__FILE__, __LINE__, ERR_NET_GSASL_INIT_FAILED, 0);
|
|
|
|
|
|
2011-02-11 20:02:08 +00:00
|
|
|
if (!gsasl_server_support_p(m_authContext, "SCRAM-SHA-1")) {
|
2009-10-13 21:03:32 +00:00
|
|
|
gsasl_done(m_authContext);
|
|
|
|
|
throw ClientException(__FILE__, __LINE__, ERR_NET_GSASL_NO_SCRAM, 0);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
ClientThread::ClearAuthContext()
|
|
|
|
|
{
|
|
|
|
|
gsasl_done(m_authContext);
|
|
|
|
|
m_authContext = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2009-06-14 22:07:41 +00:00
|
|
|
void
|
|
|
|
|
ClientThread::InitGame()
|
|
|
|
|
{
|
2011-08-28 17:14:03 +00:00
|
|
|
// Store current session guid, in case we need to rejoin the game.
|
|
|
|
|
WriteSessionGuidToFile();
|
|
|
|
|
|
2009-06-14 22:07:41 +00:00
|
|
|
// EngineFactory erstellen
|
|
|
|
|
boost::shared_ptr<EngineFactory> factory(new ClientEngineFactory); // LocalEngine erstellen
|
|
|
|
|
|
|
|
|
|
MapPlayerDataList();
|
2011-09-28 20:20:08 +00:00
|
|
|
// TODO
|
|
|
|
|
//if (GetPlayerDataList().size() != (unsigned)GetStartData().numberOfPlayers)
|
|
|
|
|
// throw ClientException(__FILE__, __LINE__, ERR_NET_INVALID_PLAYER_COUNT, 0);
|
2012-09-18 15:57:58 +02:00
|
|
|
m_startData.numberOfPlayers = (int)GetPlayerDataList().size();
|
2011-01-03 18:41:28 +00:00
|
|
|
m_game.reset(new Game(&m_gui, factory, GetPlayerDataList(), GetGameData(), GetStartData(), m_curGameNum++, m_clientLog.get()));
|
2009-10-25 00:00:33 +00:00
|
|
|
// Initialize Minimum GUI speed.
|
|
|
|
|
int minimumGuiSpeed = 1;
|
|
|
|
|
if(GetGameData().delayBetweenHandsSec < 11) {
|
|
|
|
|
minimumGuiSpeed = 12-GetGameData().delayBetweenHandsSec;
|
|
|
|
|
}
|
|
|
|
|
GetGui().initGui(minimumGuiSpeed);
|
2009-06-14 22:07:41 +00:00
|
|
|
// Signal start of game to GUI.
|
|
|
|
|
GetCallback().SignalNetClientGameStart(m_game);
|
|
|
|
|
}
|
|
|
|
|
|
2007-11-16 15:24:25 +00:00
|
|
|
void
|
2009-06-17 21:22:01 +00:00
|
|
|
ClientThread::SendSessionPacket(boost::shared_ptr<NetPacket> packet)
|
2007-11-16 15:24:25 +00:00
|
|
|
{
|
2009-06-16 22:36:07 +00:00
|
|
|
// Put packets in a buffer until the session is established.
|
|
|
|
|
if (IsSessionEstablished())
|
|
|
|
|
GetSender().Send(GetContext().GetSessionData(), packet);
|
|
|
|
|
else
|
|
|
|
|
m_outPacketList.push_back(packet);
|
2007-11-16 15:24:25 +00:00
|
|
|
}
|
|
|
|
|
|
2009-06-20 18:41:03 +00:00
|
|
|
void
|
|
|
|
|
ClientThread::SendQueuedPackets()
|
|
|
|
|
{
|
2011-02-11 20:02:08 +00:00
|
|
|
if (!m_outPacketList.empty()) {
|
2009-06-20 18:41:03 +00:00
|
|
|
NetPacketList::iterator i = m_outPacketList.begin();
|
|
|
|
|
NetPacketList::iterator end = m_outPacketList.end();
|
|
|
|
|
|
2011-02-11 20:02:08 +00:00
|
|
|
while (i != end) {
|
2009-06-20 18:41:03 +00:00
|
|
|
GetSender().Send(GetContext().GetSessionData(), *i);
|
|
|
|
|
++i;
|
|
|
|
|
}
|
|
|
|
|
m_outPacketList.clear();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2007-11-16 15:24:25 +00:00
|
|
|
bool
|
|
|
|
|
ClientThread::GetCachedPlayerInfo(unsigned id, PlayerInfo &info) const
|
|
|
|
|
{
|
|
|
|
|
bool retVal = false;
|
|
|
|
|
|
|
|
|
|
boost::mutex::scoped_lock lock(m_playerInfoMapMutex);
|
|
|
|
|
PlayerInfoMap::const_iterator pos = m_playerInfoMap.find(id);
|
2011-02-11 20:02:08 +00:00
|
|
|
if (pos != m_playerInfoMap.end()) {
|
2007-11-16 15:24:25 +00:00
|
|
|
info = pos->second;
|
|
|
|
|
retVal = true;
|
|
|
|
|
}
|
|
|
|
|
return retVal;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
ClientThread::RequestPlayerInfo(unsigned id, bool requestAvatar)
|
|
|
|
|
{
|
2012-09-24 12:22:13 +02:00
|
|
|
list<unsigned> idList;
|
|
|
|
|
idList.push_back(id);
|
|
|
|
|
RequestPlayerInfo(idList, requestAvatar);
|
|
|
|
|
}
|
2007-11-16 15:24:25 +00:00
|
|
|
|
2012-09-24 12:22:13 +02:00
|
|
|
void
|
|
|
|
|
ClientThread::RequestPlayerInfo(const list<unsigned> &idList, bool requestAvatar)
|
|
|
|
|
{
|
|
|
|
|
boost::shared_ptr<NetPacket> packet(new NetPacket);
|
|
|
|
|
packet->GetMsg()->set_messagetype(PokerTHMessage::Type_PlayerInfoRequestMessage);
|
|
|
|
|
PlayerInfoRequestMessage *netPlayerInfo = packet->GetMsg()->mutable_playerinforequestmessage();
|
|
|
|
|
BOOST_FOREACH(unsigned playerId, idList) {
|
|
|
|
|
if (find(m_playerInfoRequestList.begin(), m_playerInfoRequestList.end(), playerId) == m_playerInfoRequestList.end()) {
|
|
|
|
|
netPlayerInfo->add_playerid(playerId);
|
|
|
|
|
m_playerInfoRequestList.push_back(playerId);
|
|
|
|
|
}
|
|
|
|
|
// Remember that we have to request an avatar.
|
|
|
|
|
if (requestAvatar) {
|
|
|
|
|
m_avatarShouldRequestList.push_back(playerId);
|
|
|
|
|
}
|
2007-11-16 15:24:25 +00:00
|
|
|
}
|
2012-09-24 12:22:13 +02:00
|
|
|
if (netPlayerInfo->playerid_size() > 0) {
|
|
|
|
|
GetSender().Send(GetContext().GetSessionData(), packet);
|
2007-11-16 15:24:25 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
ClientThread::SetPlayerInfo(unsigned id, const PlayerInfo &info)
|
|
|
|
|
{
|
|
|
|
|
{
|
|
|
|
|
boost::mutex::scoped_lock lock(m_playerInfoMapMutex);
|
|
|
|
|
// Remove previous player entry with different id
|
|
|
|
|
// for the same player name if it exists.
|
|
|
|
|
// This can only be one entry, since every time a duplicate
|
|
|
|
|
// name is added one is removed.
|
|
|
|
|
// Only erase non computer player entries.
|
2011-02-11 20:02:08 +00:00
|
|
|
if (info.playerName.substr(0, sizeof(SERVER_COMPUTER_PLAYER_NAME) - 1) != SERVER_COMPUTER_PLAYER_NAME) {
|
2007-11-16 15:24:25 +00:00
|
|
|
PlayerInfoMap::iterator i = m_playerInfoMap.begin();
|
|
|
|
|
PlayerInfoMap::iterator end = m_playerInfoMap.end();
|
2011-02-11 20:02:08 +00:00
|
|
|
while (i != end) {
|
|
|
|
|
if (i->first != id && i->second.playerName == info.playerName) {
|
2007-11-16 15:24:25 +00:00
|
|
|
m_playerInfoMap.erase(i);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
++i;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
m_playerInfoMap[id] = info;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Update player data for current game.
|
2011-12-29 22:09:11 +00:00
|
|
|
boost::shared_ptr<PlayerData> playerData(GetPlayerDataByUniqueId(id));
|
|
|
|
|
if (playerData) {
|
2007-11-16 15:24:25 +00:00
|
|
|
playerData->SetName(info.playerName);
|
|
|
|
|
playerData->SetType(info.ptype);
|
2011-02-11 20:02:08 +00:00
|
|
|
if (info.hasAvatar) {
|
2007-11-16 15:24:25 +00:00
|
|
|
string avatarFile;
|
2011-02-11 20:02:08 +00:00
|
|
|
if (GetAvatarManager().GetAvatarFileName(info.avatar, avatarFile)) {
|
2007-12-12 13:37:45 +00:00
|
|
|
playerData->SetAvatarFile(GetQtToolsInterface().stringToUtf8(avatarFile));
|
2007-11-16 15:24:25 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-12-29 22:09:11 +00:00
|
|
|
if (GetGame()) {
|
|
|
|
|
boost::shared_ptr<PlayerInterface> clientPlayer(GetGame()->getPlayerByUniqueId(id));
|
|
|
|
|
if (clientPlayer)
|
|
|
|
|
clientPlayer->setMyName(info.playerName);
|
|
|
|
|
// Skip avatar here, the game is already running.
|
|
|
|
|
}
|
2007-11-16 15:24:25 +00:00
|
|
|
|
2011-02-11 20:02:08 +00:00
|
|
|
if (find(m_avatarShouldRequestList.begin(), m_avatarShouldRequestList.end(), id) != m_avatarShouldRequestList.end()) {
|
2007-11-16 15:24:25 +00:00
|
|
|
m_avatarShouldRequestList.remove(id);
|
|
|
|
|
// Retrieve avatar if needed.
|
|
|
|
|
RetrieveAvatarIfNeeded(id, info);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Remove it from the request list.
|
|
|
|
|
m_playerInfoRequestList.remove(id);
|
|
|
|
|
|
|
|
|
|
// Notify GUI
|
|
|
|
|
GetCallback().SignalNetClientPlayerChanged(id, info.playerName);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
ClientThread::SetUnknownPlayer(unsigned id)
|
|
|
|
|
{
|
|
|
|
|
// Just remove it from the request list.
|
|
|
|
|
m_playerInfoRequestList.remove(id);
|
|
|
|
|
m_avatarShouldRequestList.remove(id);
|
|
|
|
|
LOG_ERROR("Server reported unknown player id: " << id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
ClientThread::SetNewGameAdmin(unsigned id)
|
|
|
|
|
{
|
|
|
|
|
// Update player data for current game.
|
|
|
|
|
boost::shared_ptr<PlayerData> playerData = GetPlayerDataByUniqueId(id);
|
2011-02-11 20:02:08 +00:00
|
|
|
if (playerData.get()) {
|
2010-03-26 21:41:35 +00:00
|
|
|
playerData->SetGameAdmin(true);
|
2007-11-16 15:24:25 +00:00
|
|
|
GetCallback().SignalNetClientNewGameAdmin(id, playerData->GetName());
|
2012-01-09 12:42:04 +00:00
|
|
|
if(m_game) {
|
|
|
|
|
m_clientLog->logPlayerAction(playerData->GetName(),LOG_ACTION_ADMIN);
|
|
|
|
|
}
|
2007-11-16 15:24:25 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
ClientThread::RetrieveAvatarIfNeeded(unsigned id, const PlayerInfo &info)
|
|
|
|
|
{
|
2011-02-11 20:02:08 +00:00
|
|
|
if (find(m_avatarHasRequestedList.begin(), m_avatarHasRequestedList.end(), id) == m_avatarHasRequestedList.end()) {
|
|
|
|
|
if (info.hasAvatar && !info.avatar.IsZero() && !GetAvatarManager().HasAvatar(info.avatar)) {
|
2007-11-16 15:24:25 +00:00
|
|
|
m_avatarHasRequestedList.push_back(id); // Never remove from this list. Only request once.
|
2009-03-18 15:01:43 +00:00
|
|
|
|
2009-03-21 01:39:00 +00:00
|
|
|
// Download from avatar server if applicable.
|
|
|
|
|
string avatarServerAddress(GetContext().GetAvatarServerAddr());
|
2011-02-11 20:02:08 +00:00
|
|
|
if (!avatarServerAddress.empty() && m_avatarDownloader) {
|
2009-03-22 00:39:25 +00:00
|
|
|
string serverFileName(info.avatar.ToString() + AvatarManager::GetAvatarFileExtension(info.avatarType));
|
2009-03-21 19:56:53 +00:00
|
|
|
m_avatarDownloader->QueueDownload(
|
|
|
|
|
id, avatarServerAddress + serverFileName, GetContext().GetCacheDir() + TEMP_AVATAR_FILENAME);
|
2011-02-11 20:02:08 +00:00
|
|
|
} else {
|
2012-09-18 15:57:58 +02:00
|
|
|
boost::shared_ptr<NetPacket> packet(new NetPacket);
|
|
|
|
|
packet->GetMsg()->set_messagetype(PokerTHMessage::Type_AvatarRequestMessage);
|
|
|
|
|
AvatarRequestMessage *netAvatar = packet->GetMsg()->mutable_avatarrequestmessage();
|
|
|
|
|
netAvatar->set_requestid(id);
|
|
|
|
|
netAvatar->set_avatarhash(info.avatar.GetData(), MD5_DATA_SIZE);
|
2009-08-02 15:11:40 +00:00
|
|
|
GetSender().Send(GetContext().GetSessionData(), packet);
|
2009-03-21 01:39:00 +00:00
|
|
|
}
|
2007-11-16 15:24:25 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2009-08-02 15:11:40 +00:00
|
|
|
ClientThread::AddTempAvatarFile(unsigned playerId, unsigned avatarSize, AvatarFileType type)
|
2007-11-16 15:24:25 +00:00
|
|
|
{
|
2009-08-02 15:11:40 +00:00
|
|
|
boost::shared_ptr<AvatarFile> tmpAvatar(new AvatarFile);
|
2007-11-16 15:24:25 +00:00
|
|
|
tmpAvatar->fileData.reserve(avatarSize);
|
|
|
|
|
tmpAvatar->fileType = type;
|
|
|
|
|
tmpAvatar->reportedSize = avatarSize;
|
|
|
|
|
|
|
|
|
|
m_tempAvatarMap[playerId] = tmpAvatar;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2009-08-02 15:11:40 +00:00
|
|
|
ClientThread::StoreInTempAvatarFile(unsigned playerId, const vector<unsigned char> &data)
|
2007-11-16 15:24:25 +00:00
|
|
|
{
|
2009-08-02 15:11:40 +00:00
|
|
|
AvatarFileMap::iterator pos = m_tempAvatarMap.find(playerId);
|
2007-11-16 15:24:25 +00:00
|
|
|
if (pos == m_tempAvatarMap.end())
|
|
|
|
|
throw ClientException(__FILE__, __LINE__, ERR_NET_INVALID_REQUEST_ID, 0);
|
|
|
|
|
// We trust the server (concerning size of the data).
|
|
|
|
|
std::copy(data.begin(), data.end(), back_inserter(pos->second->fileData));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2009-08-02 15:11:40 +00:00
|
|
|
ClientThread::CompleteTempAvatarFile(unsigned playerId)
|
2007-11-16 15:24:25 +00:00
|
|
|
{
|
2009-08-02 15:11:40 +00:00
|
|
|
AvatarFileMap::iterator pos = m_tempAvatarMap.find(playerId);
|
2007-11-16 15:24:25 +00:00
|
|
|
if (pos == m_tempAvatarMap.end())
|
|
|
|
|
throw ClientException(__FILE__, __LINE__, ERR_NET_INVALID_REQUEST_ID, 0);
|
2009-08-02 15:11:40 +00:00
|
|
|
boost::shared_ptr<AvatarFile> tmpAvatar = pos->second;
|
2007-11-16 15:24:25 +00:00
|
|
|
unsigned avatarSize = (unsigned)tmpAvatar->fileData.size();
|
|
|
|
|
if (avatarSize != tmpAvatar->reportedSize)
|
|
|
|
|
LOG_ERROR("Client received invalid avatar file size!");
|
|
|
|
|
else
|
2009-08-02 15:11:40 +00:00
|
|
|
PassAvatarFileToManager(playerId, tmpAvatar);
|
2007-11-16 15:24:25 +00:00
|
|
|
|
|
|
|
|
// Free memory.
|
|
|
|
|
m_tempAvatarMap.erase(pos);
|
|
|
|
|
}
|
|
|
|
|
|
2009-03-21 11:36:10 +00:00
|
|
|
void
|
2009-08-02 15:11:40 +00:00
|
|
|
ClientThread::PassAvatarFileToManager(unsigned playerId, boost::shared_ptr<AvatarFile> AvatarFile)
|
2009-03-21 11:36:10 +00:00
|
|
|
{
|
|
|
|
|
PlayerInfo tmpPlayerInfo;
|
|
|
|
|
if (!GetCachedPlayerInfo(playerId, tmpPlayerInfo))
|
|
|
|
|
LOG_ERROR("Client received invalid player id!");
|
2011-02-11 20:02:08 +00:00
|
|
|
else {
|
2009-08-02 15:11:40 +00:00
|
|
|
if (AvatarFile->fileType == AVATAR_FILE_TYPE_UNKNOWN)
|
|
|
|
|
AvatarFile->fileType = tmpPlayerInfo.avatarType;
|
|
|
|
|
if (!GetAvatarManager().StoreAvatarInCache(tmpPlayerInfo.avatar, AvatarFile->fileType, &AvatarFile->fileData[0], AvatarFile->reportedSize, false))
|
2009-03-21 11:36:10 +00:00
|
|
|
LOG_ERROR("Failed to store avatar in cache directory.");
|
|
|
|
|
|
|
|
|
|
// Update player info, but never re-request avatar.
|
|
|
|
|
SetPlayerInfo(playerId, tmpPlayerInfo);
|
|
|
|
|
|
|
|
|
|
string fileName;
|
2011-02-11 20:02:08 +00:00
|
|
|
if (GetAvatarManager().GetAvatarFileName(tmpPlayerInfo.avatar, fileName)) {
|
2009-03-21 11:36:10 +00:00
|
|
|
// Dynamically update avatar in GUI.
|
|
|
|
|
GetGui().setPlayerAvatar(playerId, GetQtToolsInterface().stringToUtf8(fileName));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2007-11-16 15:24:25 +00:00
|
|
|
void
|
|
|
|
|
ClientThread::SetUnknownAvatar(unsigned playerId)
|
|
|
|
|
{
|
|
|
|
|
m_tempAvatarMap.erase(playerId);
|
|
|
|
|
LOG_ERROR("Server reported unknown avatar for player: " << playerId);
|
|
|
|
|
}
|
|
|
|
|
|
2009-03-21 11:36:10 +00:00
|
|
|
void
|
2009-06-14 22:07:41 +00:00
|
|
|
ClientThread::TimerCheckAvatarDownloads(const boost::system::error_code& ec)
|
2009-03-21 11:36:10 +00:00
|
|
|
{
|
2011-02-11 20:02:08 +00:00
|
|
|
if (!ec) {
|
|
|
|
|
if (m_avatarDownloader && m_avatarDownloader->HasDownloadResult()) {
|
2009-06-14 22:07:41 +00:00
|
|
|
unsigned playerId;
|
2009-08-02 15:11:40 +00:00
|
|
|
boost::shared_ptr<AvatarFile> tmpAvatar(new AvatarFile);
|
2009-06-14 22:07:41 +00:00
|
|
|
m_avatarDownloader->GetDownloadResult(playerId, tmpAvatar->fileData);
|
|
|
|
|
tmpAvatar->reportedSize = tmpAvatar->fileData.size();
|
2009-08-02 15:11:40 +00:00
|
|
|
PassAvatarFileToManager(playerId, tmpAvatar);
|
2009-06-14 22:07:41 +00:00
|
|
|
}
|
|
|
|
|
m_avatarTimer.expires_from_now(
|
|
|
|
|
boost::posix_time::milliseconds(CLIENT_AVATAR_LOOP_MSEC));
|
|
|
|
|
m_avatarTimer.async_wait(
|
|
|
|
|
boost::bind(
|
|
|
|
|
&ClientThread::TimerCheckAvatarDownloads, shared_from_this(), boost::asio::placeholders::error));
|
2009-03-21 11:36:10 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2008-05-16 16:46:45 +00:00
|
|
|
void
|
|
|
|
|
ClientThread::UnsubscribeLobbyMsg()
|
|
|
|
|
{
|
2011-02-11 20:02:08 +00:00
|
|
|
if (GetContext().GetSubscribeLobbyMsg()) {
|
2008-05-16 20:42:46 +00:00
|
|
|
// Send unsubscribe request.
|
2012-09-18 15:57:58 +02:00
|
|
|
boost::shared_ptr<NetPacket> packet(new NetPacket);
|
|
|
|
|
packet->GetMsg()->set_messagetype(PokerTHMessage::Type_SubscriptionRequestMessage);
|
|
|
|
|
SubscriptionRequestMessage *netRequest = packet->GetMsg()->mutable_subscriptionrequestmessage();
|
|
|
|
|
netRequest->set_subscriptionaction(SubscriptionRequestMessage::unsubscribeGameList);
|
2009-08-02 15:11:40 +00:00
|
|
|
GetSender().Send(GetContext().GetSessionData(), packet);
|
2008-05-16 20:42:46 +00:00
|
|
|
GetContext().SetSubscribeLobbyMsg(false);
|
|
|
|
|
}
|
2008-05-16 16:46:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
ClientThread::ResubscribeLobbyMsg()
|
|
|
|
|
{
|
2011-02-11 20:02:08 +00:00
|
|
|
if (!GetContext().GetSubscribeLobbyMsg()) {
|
2008-05-16 20:42:46 +00:00
|
|
|
// Clear game info map as it is outdated.
|
|
|
|
|
ClearGameInfoMap();
|
|
|
|
|
// Send resubscribe request.
|
2012-09-18 15:57:58 +02:00
|
|
|
boost::shared_ptr<NetPacket> packet(new NetPacket);
|
|
|
|
|
packet->GetMsg()->set_messagetype(PokerTHMessage::Type_SubscriptionRequestMessage);
|
|
|
|
|
SubscriptionRequestMessage *netRequest = packet->GetMsg()->mutable_subscriptionrequestmessage();
|
|
|
|
|
netRequest->set_subscriptionaction(SubscriptionRequestMessage::resubscribeGameList);
|
2009-08-03 21:02:37 +00:00
|
|
|
GetSender().Send(GetContext().GetSessionData(), packet);
|
2008-05-16 20:42:46 +00:00
|
|
|
GetContext().SetSubscribeLobbyMsg(true);
|
|
|
|
|
}
|
2008-05-16 16:46:45 +00:00
|
|
|
}
|
|
|
|
|
|
2007-11-16 15:24:25 +00:00
|
|
|
const ClientContext &
|
|
|
|
|
ClientThread::GetContext() const
|
|
|
|
|
{
|
|
|
|
|
assert(m_context.get());
|
|
|
|
|
return *m_context;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ClientContext &
|
|
|
|
|
ClientThread::GetContext()
|
|
|
|
|
{
|
|
|
|
|
assert(m_context.get());
|
|
|
|
|
return *m_context;
|
|
|
|
|
}
|
|
|
|
|
|
2012-02-04 21:39:24 +00:00
|
|
|
string
|
|
|
|
|
ClientThread::GetCacheServerListFileName()
|
|
|
|
|
{
|
2012-06-17 13:35:31 +02:00
|
|
|
string fileName;
|
2012-02-04 21:39:24 +00:00
|
|
|
path tmpServerListPath(GetContext().GetCacheDir());
|
|
|
|
|
string serverListUrl(GetContext().GetServerListUrl());
|
|
|
|
|
// Retrieve the file name from the URL.
|
|
|
|
|
size_t pos = serverListUrl.find_last_of('/');
|
2012-06-17 13:35:31 +02:00
|
|
|
if (!GetContext().GetCacheDir().empty() && !serverListUrl.empty() && pos != string::npos && ++pos < serverListUrl.length()) {
|
|
|
|
|
tmpServerListPath /= serverListUrl.substr(pos);
|
|
|
|
|
fileName = tmpServerListPath.directory_string();
|
2012-02-04 21:39:24 +00:00
|
|
|
}
|
2012-06-17 13:35:31 +02:00
|
|
|
return fileName;
|
2012-02-04 21:39:24 +00:00
|
|
|
}
|
|
|
|
|
|
2009-03-21 10:28:27 +00:00
|
|
|
void
|
2009-05-04 21:11:29 +00:00
|
|
|
ClientThread::CreateContextSession()
|
2009-03-21 10:28:27 +00:00
|
|
|
{
|
2009-05-04 21:11:29 +00:00
|
|
|
bool validSocket = false;
|
|
|
|
|
// TODO sctp
|
|
|
|
|
try {
|
2009-06-14 22:07:41 +00:00
|
|
|
boost::shared_ptr<tcp::socket> newSock;
|
|
|
|
|
if (GetContext().GetAddrFamily() == AF_INET6)
|
|
|
|
|
newSock.reset(new boost::asio::ip::tcp::socket(*m_ioService, tcp::v6()));
|
|
|
|
|
else
|
|
|
|
|
newSock.reset(new boost::asio::ip::tcp::socket(*m_ioService, tcp::v4()));
|
2009-05-04 21:11:29 +00:00
|
|
|
boost::asio::socket_base::non_blocking_io command(true);
|
|
|
|
|
newSock->io_control(command);
|
|
|
|
|
newSock->set_option(tcp::no_delay(true));
|
|
|
|
|
newSock->set_option(boost::asio::socket_base::keep_alive(true));
|
|
|
|
|
|
|
|
|
|
GetContext().SetSessionData(boost::shared_ptr<SessionData>(new SessionData(
|
2011-02-11 20:02:08 +00:00
|
|
|
newSock,
|
|
|
|
|
SESSION_ID_GENERIC,
|
2011-12-11 14:54:17 +00:00
|
|
|
*this,
|
|
|
|
|
*m_ioService)));
|
2009-06-14 22:07:41 +00:00
|
|
|
GetContext().SetResolver(boost::shared_ptr<boost::asio::ip::tcp::resolver>(
|
2011-02-11 20:02:08 +00:00
|
|
|
new boost::asio::ip::tcp::resolver(*m_ioService)));
|
2009-05-04 21:11:29 +00:00
|
|
|
validSocket = true;
|
2011-02-11 20:02:08 +00:00
|
|
|
} catch (...) {
|
2009-05-04 21:11:29 +00:00
|
|
|
}
|
|
|
|
|
if (!validSocket)
|
2009-06-16 22:00:07 +00:00
|
|
|
throw ClientException(__FILE__, __LINE__, ERR_SOCK_CREATION_FAILED, 0);
|
2009-03-21 10:28:27 +00:00
|
|
|
}
|
|
|
|
|
|
2007-11-16 15:24:25 +00:00
|
|
|
ClientState &
|
|
|
|
|
ClientThread::GetState()
|
|
|
|
|
{
|
|
|
|
|
assert(m_curState);
|
|
|
|
|
return *m_curState;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
ClientThread::SetState(ClientState &newState)
|
|
|
|
|
{
|
2009-06-14 22:07:41 +00:00
|
|
|
if (m_curState)
|
|
|
|
|
m_curState->Exit(shared_from_this());
|
2007-11-16 15:24:25 +00:00
|
|
|
m_curState = &newState;
|
2009-06-14 22:07:41 +00:00
|
|
|
m_curState->Enter(shared_from_this());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
boost::asio::deadline_timer &
|
|
|
|
|
ClientThread::GetStateTimer()
|
|
|
|
|
{
|
|
|
|
|
return m_stateTimer;
|
2007-11-16 15:24:25 +00:00
|
|
|
}
|
|
|
|
|
|
2009-06-07 08:51:43 +00:00
|
|
|
SenderHelper &
|
|
|
|
|
ClientThread::GetSender()
|
|
|
|
|
{
|
|
|
|
|
assert(m_senderHelper);
|
|
|
|
|
return *m_senderHelper;
|
|
|
|
|
}
|
|
|
|
|
|
2007-11-16 15:24:25 +00:00
|
|
|
unsigned
|
|
|
|
|
ClientThread::GetGameId() const
|
|
|
|
|
{
|
|
|
|
|
boost::mutex::scoped_lock lock(m_curGameIdMutex);
|
|
|
|
|
return m_curGameId;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
ClientThread::SetGameId(unsigned id)
|
|
|
|
|
{
|
|
|
|
|
boost::mutex::scoped_lock lock(m_curGameIdMutex);
|
|
|
|
|
m_curGameId = id;
|
|
|
|
|
}
|
|
|
|
|
|
2009-10-13 21:03:32 +00:00
|
|
|
Gsasl *
|
|
|
|
|
ClientThread::GetAuthContext()
|
|
|
|
|
{
|
|
|
|
|
assert(m_authContext);
|
|
|
|
|
return m_authContext;
|
|
|
|
|
}
|
|
|
|
|
|
2007-11-16 15:24:25 +00:00
|
|
|
const GameData &
|
|
|
|
|
ClientThread::GetGameData() const
|
|
|
|
|
{
|
|
|
|
|
return m_gameData;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
ClientThread::SetGameData(const GameData &gameData)
|
|
|
|
|
{
|
|
|
|
|
m_gameData = gameData;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const StartData &
|
|
|
|
|
ClientThread::GetStartData() const
|
|
|
|
|
{
|
|
|
|
|
return m_startData;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
ClientThread::SetStartData(const StartData &startData)
|
|
|
|
|
{
|
|
|
|
|
m_startData = startData;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
unsigned
|
|
|
|
|
ClientThread::GetGuiPlayerId() const
|
|
|
|
|
{
|
2010-03-24 20:10:36 +00:00
|
|
|
boost::mutex::scoped_lock lock(m_guiPlayerIdMutex);
|
2007-11-16 15:24:25 +00:00
|
|
|
return m_guiPlayerId;
|
|
|
|
|
}
|
|
|
|
|
|
2011-12-21 20:56:41 +00:00
|
|
|
int
|
|
|
|
|
ClientThread::GetOrigGuiPlayerNum() const
|
|
|
|
|
{
|
|
|
|
|
return m_origGuiPlayerNum;
|
|
|
|
|
}
|
|
|
|
|
|
2007-11-16 15:24:25 +00:00
|
|
|
void
|
|
|
|
|
ClientThread::SetGuiPlayerId(unsigned guiPlayerId)
|
|
|
|
|
{
|
2010-03-24 20:10:36 +00:00
|
|
|
boost::mutex::scoped_lock lock(m_guiPlayerIdMutex);
|
2007-11-16 15:24:25 +00:00
|
|
|
m_guiPlayerId = guiPlayerId;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
boost::shared_ptr<Game>
|
|
|
|
|
ClientThread::GetGame()
|
|
|
|
|
{
|
|
|
|
|
return m_game;
|
|
|
|
|
}
|
|
|
|
|
|
2007-12-12 13:37:45 +00:00
|
|
|
QtToolsInterface &
|
|
|
|
|
ClientThread::GetQtToolsInterface()
|
|
|
|
|
{
|
|
|
|
|
assert(myQtToolsInterface.get());
|
|
|
|
|
return *myQtToolsInterface;
|
|
|
|
|
}
|
2007-11-16 15:24:25 +00:00
|
|
|
|
2011-12-29 21:19:06 +00:00
|
|
|
boost::shared_ptr<PlayerData>
|
|
|
|
|
ClientThread::CreatePlayerData(unsigned playerId, bool isGameAdmin)
|
|
|
|
|
{
|
|
|
|
|
boost::shared_ptr<PlayerData> playerData;
|
|
|
|
|
PlayerInfo info;
|
|
|
|
|
if (GetCachedPlayerInfo(playerId, info)) {
|
|
|
|
|
playerData.reset(
|
|
|
|
|
new PlayerData(playerId, 0, info.ptype,
|
2012-01-05 20:54:27 +00:00
|
|
|
info.isGuest ? PLAYER_RIGHTS_GUEST : PLAYER_RIGHTS_NORMAL, isGameAdmin));
|
2011-12-29 21:19:06 +00:00
|
|
|
playerData->SetName(info.playerName);
|
|
|
|
|
if (info.hasAvatar) {
|
|
|
|
|
string avatarFile;
|
|
|
|
|
if (GetAvatarManager().GetAvatarFileName(info.avatar, avatarFile))
|
|
|
|
|
playerData->SetAvatarFile(GetQtToolsInterface().stringToUtf8(avatarFile));
|
|
|
|
|
else
|
|
|
|
|
RetrieveAvatarIfNeeded(playerId, info);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
ostringstream name;
|
|
|
|
|
name << "#" << playerId;
|
|
|
|
|
|
|
|
|
|
// Request player info.
|
|
|
|
|
RequestPlayerInfo(playerId, true);
|
|
|
|
|
// Use temporary data until the PlayerInfo request is completed.
|
|
|
|
|
playerData.reset(
|
|
|
|
|
new PlayerData(playerId, 0, PLAYER_TYPE_HUMAN, PLAYER_RIGHTS_NORMAL, isGameAdmin));
|
|
|
|
|
playerData->SetName(name.str());
|
|
|
|
|
}
|
|
|
|
|
return playerData;
|
|
|
|
|
}
|
|
|
|
|
|
2007-11-16 15:24:25 +00:00
|
|
|
void
|
|
|
|
|
ClientThread::AddPlayerData(boost::shared_ptr<PlayerData> playerData)
|
|
|
|
|
{
|
2011-02-11 20:02:08 +00:00
|
|
|
if (playerData.get() && !playerData->GetName().empty()) {
|
2007-11-16 15:24:25 +00:00
|
|
|
m_playerDataList.push_back(playerData);
|
|
|
|
|
if (playerData->GetUniqueId() == GetGuiPlayerId())
|
2010-03-27 12:50:05 +00:00
|
|
|
GetCallback().SignalNetClientSelfJoined(playerData->GetUniqueId(), playerData->GetName(), playerData->IsGameAdmin());
|
2012-01-09 12:42:04 +00:00
|
|
|
else {
|
2010-03-27 12:50:05 +00:00
|
|
|
GetCallback().SignalNetClientPlayerJoined(playerData->GetUniqueId(), playerData->GetName(), playerData->IsGameAdmin());
|
2012-01-09 12:42:04 +00:00
|
|
|
// if(m_game) {
|
|
|
|
|
// m_clientLog->logPlayerAction(playerData->GetName(),LOG_ACTION_JOIN);
|
|
|
|
|
// }
|
|
|
|
|
}
|
2007-11-16 15:24:25 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2008-11-25 23:19:34 +00:00
|
|
|
ClientThread::RemovePlayerData(unsigned playerId, int removeReason)
|
2007-11-16 15:24:25 +00:00
|
|
|
{
|
|
|
|
|
boost::shared_ptr<PlayerData> tmpData;
|
|
|
|
|
|
|
|
|
|
PlayerDataList::iterator i = m_playerDataList.begin();
|
|
|
|
|
PlayerDataList::iterator end = m_playerDataList.end();
|
2011-02-11 20:02:08 +00:00
|
|
|
while (i != end) {
|
|
|
|
|
if ((*i)->GetUniqueId() == playerId) {
|
2007-11-16 15:24:25 +00:00
|
|
|
tmpData = *i;
|
|
|
|
|
m_playerDataList.erase(i);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
++i;
|
|
|
|
|
}
|
|
|
|
|
|
2011-02-11 20:02:08 +00:00
|
|
|
if (tmpData.get()) {
|
2007-11-16 15:24:25 +00:00
|
|
|
// Remove player from gui.
|
2011-12-23 19:32:56 +00:00
|
|
|
if (GetGame()) {
|
|
|
|
|
boost::shared_ptr<PlayerInterface> tmpPlayer(GetGame()->getPlayerByUniqueId(tmpData->GetUniqueId()));
|
|
|
|
|
if (tmpPlayer) {
|
|
|
|
|
tmpPlayer->setMyStayOnTableStatus(false);
|
|
|
|
|
}
|
|
|
|
|
}
|
2008-11-25 23:19:34 +00:00
|
|
|
GetCallback().SignalNetClientPlayerLeft(tmpData->GetUniqueId(), tmpData->GetName(), removeReason);
|
2012-01-05 20:54:27 +00:00
|
|
|
|
2012-01-09 12:42:04 +00:00
|
|
|
if(m_game) {
|
|
|
|
|
if(removeReason == NTF_NET_REMOVED_KICKED) {
|
|
|
|
|
m_clientLog->logPlayerAction(tmpData->GetName(),LOG_ACTION_KICKED);
|
|
|
|
|
} else {
|
|
|
|
|
m_clientLog->logPlayerAction(tmpData->GetName(),LOG_ACTION_LEFT);
|
|
|
|
|
}
|
2012-01-05 20:54:27 +00:00
|
|
|
}
|
|
|
|
|
|
2007-11-16 15:24:25 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
ClientThread::ClearPlayerDataList()
|
|
|
|
|
{
|
|
|
|
|
m_playerDataList.clear();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
ClientThread::MapPlayerDataList()
|
|
|
|
|
{
|
|
|
|
|
// Retrieve the GUI player.
|
|
|
|
|
boost::shared_ptr<PlayerData> guiPlayer = GetPlayerDataByUniqueId(GetGuiPlayerId());
|
|
|
|
|
assert(guiPlayer.get());
|
2011-12-21 20:56:41 +00:00
|
|
|
m_origGuiPlayerNum = guiPlayer->GetNumber();
|
2007-11-16 15:24:25 +00:00
|
|
|
|
|
|
|
|
// Create a copy of the player list so that the GUI player
|
|
|
|
|
// is player 0. This is mapped because the GUI depends on it.
|
|
|
|
|
PlayerDataList mappedList;
|
|
|
|
|
|
|
|
|
|
PlayerDataList::const_iterator i = m_playerDataList.begin();
|
|
|
|
|
PlayerDataList::const_iterator end = m_playerDataList.end();
|
|
|
|
|
int numPlayers = GetStartData().numberOfPlayers;
|
|
|
|
|
|
2011-02-11 20:02:08 +00:00
|
|
|
while (i != end) {
|
2007-11-16 15:24:25 +00:00
|
|
|
boost::shared_ptr<PlayerData> tmpData(new PlayerData(*(*i)));
|
2011-12-23 17:14:36 +00:00
|
|
|
int numberDiff = numPlayers - m_origGuiPlayerNum;
|
|
|
|
|
tmpData->SetNumber((tmpData->GetNumber() + numberDiff) % numPlayers);
|
2007-11-16 15:24:25 +00:00
|
|
|
mappedList.push_back(tmpData);
|
|
|
|
|
++i;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Sort the list by player number.
|
|
|
|
|
mappedList.sort(*boost::lambda::_1 < *boost::lambda::_2);
|
|
|
|
|
|
|
|
|
|
m_playerDataList = mappedList;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const PlayerDataList &
|
|
|
|
|
ClientThread::GetPlayerDataList() const
|
|
|
|
|
{
|
|
|
|
|
return m_playerDataList;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
boost::shared_ptr<PlayerData>
|
|
|
|
|
ClientThread::GetPlayerDataByUniqueId(unsigned id)
|
|
|
|
|
{
|
|
|
|
|
boost::shared_ptr<PlayerData> tmpPlayer;
|
|
|
|
|
|
|
|
|
|
PlayerDataList::const_iterator i = m_playerDataList.begin();
|
|
|
|
|
PlayerDataList::const_iterator end = m_playerDataList.end();
|
|
|
|
|
|
2011-02-11 20:02:08 +00:00
|
|
|
while (i != end) {
|
|
|
|
|
if ((*i)->GetUniqueId() == id) {
|
2007-11-16 15:24:25 +00:00
|
|
|
tmpPlayer = *i;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
++i;
|
|
|
|
|
}
|
|
|
|
|
return tmpPlayer;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
boost::shared_ptr<PlayerData>
|
|
|
|
|
ClientThread::GetPlayerDataByName(const std::string &name)
|
|
|
|
|
{
|
|
|
|
|
boost::shared_ptr<PlayerData> tmpPlayer;
|
|
|
|
|
|
2011-02-11 20:02:08 +00:00
|
|
|
if (!name.empty()) {
|
2007-11-16 15:24:25 +00:00
|
|
|
PlayerDataList::const_iterator i = m_playerDataList.begin();
|
|
|
|
|
PlayerDataList::const_iterator end = m_playerDataList.end();
|
|
|
|
|
|
2011-02-11 20:02:08 +00:00
|
|
|
while (i != end) {
|
|
|
|
|
if ((*i)->GetName() == name) {
|
2007-11-16 15:24:25 +00:00
|
|
|
tmpPlayer = *i;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
++i;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return tmpPlayer;
|
|
|
|
|
}
|
|
|
|
|
|
2009-04-05 11:19:50 +00:00
|
|
|
void
|
|
|
|
|
ClientThread::AddServerInfo(unsigned serverId, const ServerInfo &info)
|
|
|
|
|
{
|
|
|
|
|
{
|
|
|
|
|
boost::mutex::scoped_lock lock(m_serverInfoMapMutex);
|
|
|
|
|
m_serverInfoMap.insert(ServerInfoMap::value_type(serverId, info));
|
|
|
|
|
}
|
2009-04-05 13:11:52 +00:00
|
|
|
GetCallback().SignalNetClientServerListAdd(serverId);
|
2009-04-05 11:19:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
ClientThread::ClearServerInfoMap()
|
|
|
|
|
{
|
|
|
|
|
{
|
|
|
|
|
boost::mutex::scoped_lock lock(m_serverInfoMapMutex);
|
|
|
|
|
m_serverInfoMap.clear();
|
|
|
|
|
}
|
2009-04-05 13:11:52 +00:00
|
|
|
GetCallback().SignalNetClientServerListClear();
|
2009-04-05 11:19:50 +00:00
|
|
|
}
|
|
|
|
|
|
2009-04-05 12:31:12 +00:00
|
|
|
bool
|
|
|
|
|
ClientThread::GetSelectedServer(unsigned &serverId) const
|
|
|
|
|
{
|
|
|
|
|
bool retVal = false;
|
|
|
|
|
boost::mutex::scoped_lock lock(m_selectServerMutex);
|
2011-02-11 20:02:08 +00:00
|
|
|
if (m_isServerSelected) {
|
2009-04-05 12:31:12 +00:00
|
|
|
retVal = true;
|
|
|
|
|
serverId = m_selectedServerId;
|
|
|
|
|
}
|
|
|
|
|
return retVal;
|
|
|
|
|
}
|
2009-04-05 11:19:50 +00:00
|
|
|
|
|
|
|
|
void
|
|
|
|
|
ClientThread::UseServer(unsigned serverId)
|
|
|
|
|
{
|
2009-04-05 11:34:40 +00:00
|
|
|
ClientContext &context = GetContext();
|
2009-04-05 11:19:50 +00:00
|
|
|
ServerInfo useInfo(GetServerInfo(serverId));
|
|
|
|
|
|
|
|
|
|
if (context.GetAddrFamily() == AF_INET6)
|
|
|
|
|
context.SetServerAddr(useInfo.ipv6addr);
|
|
|
|
|
else
|
|
|
|
|
context.SetServerAddr(useInfo.ipv4addr);
|
|
|
|
|
|
|
|
|
|
context.SetServerPort((unsigned)useInfo.port);
|
|
|
|
|
context.SetAvatarServerAddr(useInfo.avatarServerAddr);
|
|
|
|
|
}
|
|
|
|
|
|
2009-11-14 15:04:31 +00:00
|
|
|
bool
|
|
|
|
|
ClientThread::GetLoginData(LoginData &loginData) const
|
|
|
|
|
{
|
|
|
|
|
bool retVal = false;
|
|
|
|
|
boost::mutex::scoped_lock lock(m_loginDataMutex);
|
2011-02-11 20:02:08 +00:00
|
|
|
if (!m_loginData.userName.empty()) {
|
2009-11-14 15:04:31 +00:00
|
|
|
loginData = m_loginData;
|
|
|
|
|
retVal = true;
|
|
|
|
|
}
|
|
|
|
|
return retVal;
|
|
|
|
|
}
|
|
|
|
|
|
2007-11-16 15:24:25 +00:00
|
|
|
void
|
|
|
|
|
ClientThread::AddGameInfo(unsigned gameId, const GameInfo &info)
|
|
|
|
|
{
|
|
|
|
|
{
|
|
|
|
|
boost::mutex::scoped_lock lock(m_gameInfoMapMutex);
|
|
|
|
|
m_gameInfoMap.insert(GameInfoMap::value_type(gameId, info));
|
|
|
|
|
}
|
|
|
|
|
GetCallback().SignalNetClientGameListNew(gameId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
ClientThread::UpdateGameInfoMode(unsigned gameId, GameMode mode)
|
|
|
|
|
{
|
|
|
|
|
bool found = false;
|
|
|
|
|
{
|
|
|
|
|
boost::mutex::scoped_lock lock(m_gameInfoMapMutex);
|
|
|
|
|
GameInfoMap::iterator pos = m_gameInfoMap.find(gameId);
|
2011-02-11 20:02:08 +00:00
|
|
|
if (pos != m_gameInfoMap.end()) {
|
2007-11-16 15:24:25 +00:00
|
|
|
found = true;
|
|
|
|
|
(*pos).second.mode = mode;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (found)
|
|
|
|
|
GetCallback().SignalNetClientGameListUpdateMode(gameId, mode);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
ClientThread::UpdateGameInfoAdmin(unsigned gameId, unsigned adminPlayerId)
|
|
|
|
|
{
|
|
|
|
|
bool found = false;
|
|
|
|
|
{
|
|
|
|
|
boost::mutex::scoped_lock lock(m_gameInfoMapMutex);
|
|
|
|
|
GameInfoMap::iterator pos = m_gameInfoMap.find(gameId);
|
2011-02-11 20:02:08 +00:00
|
|
|
if (pos != m_gameInfoMap.end()) {
|
2007-11-16 15:24:25 +00:00
|
|
|
found = true;
|
|
|
|
|
(*pos).second.adminPlayerId = adminPlayerId;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (found)
|
|
|
|
|
GetCallback().SignalNetClientGameListUpdateAdmin(gameId, adminPlayerId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
ClientThread::RemoveGameInfo(unsigned gameId)
|
|
|
|
|
{
|
|
|
|
|
bool found = false;
|
|
|
|
|
{
|
|
|
|
|
boost::mutex::scoped_lock lock(m_gameInfoMapMutex);
|
|
|
|
|
GameInfoMap::iterator pos = m_gameInfoMap.find(gameId);
|
2011-02-11 20:02:08 +00:00
|
|
|
if (pos != m_gameInfoMap.end()) {
|
2007-11-16 15:24:25 +00:00
|
|
|
found = true;
|
|
|
|
|
m_gameInfoMap.erase(pos);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (found)
|
|
|
|
|
GetCallback().SignalNetClientGameListRemove(gameId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
ClientThread::ModifyGameInfoAddPlayer(unsigned gameId, unsigned playerId)
|
|
|
|
|
{
|
|
|
|
|
bool playerAdded = false;
|
|
|
|
|
{
|
|
|
|
|
boost::mutex::scoped_lock lock(m_gameInfoMapMutex);
|
|
|
|
|
GameInfoMap::iterator pos = m_gameInfoMap.find(gameId);
|
2011-02-11 20:02:08 +00:00
|
|
|
if (pos != m_gameInfoMap.end()) {
|
2007-11-16 15:24:25 +00:00
|
|
|
pos->second.players.push_back(playerId);
|
|
|
|
|
playerAdded = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (playerAdded)
|
|
|
|
|
GetCallback().SignalNetClientGameListPlayerJoined(gameId, playerId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
ClientThread::ModifyGameInfoRemovePlayer(unsigned gameId, unsigned playerId)
|
|
|
|
|
{
|
|
|
|
|
bool playerRemoved = false;
|
|
|
|
|
{
|
|
|
|
|
boost::mutex::scoped_lock lock(m_gameInfoMapMutex);
|
|
|
|
|
GameInfoMap::iterator pos = m_gameInfoMap.find(gameId);
|
2011-02-11 20:02:08 +00:00
|
|
|
if (pos != m_gameInfoMap.end()) {
|
2007-11-16 15:24:25 +00:00
|
|
|
pos->second.players.remove(playerId);
|
|
|
|
|
playerRemoved = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (playerRemoved)
|
|
|
|
|
GetCallback().SignalNetClientGameListPlayerLeft(gameId, playerId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
ClientThread::ClearGameInfoMap()
|
|
|
|
|
{
|
|
|
|
|
boost::mutex::scoped_lock lock(m_gameInfoMapMutex);
|
|
|
|
|
m_gameInfoMap.clear();
|
|
|
|
|
}
|
|
|
|
|
|
2008-11-25 22:18:17 +00:00
|
|
|
void
|
|
|
|
|
ClientThread::StartPetition(unsigned petitionId, unsigned proposingPlayerId, unsigned kickPlayerId, int timeoutSec, int numVotesToKick)
|
|
|
|
|
{
|
|
|
|
|
{
|
|
|
|
|
boost::mutex::scoped_lock lock(m_curPetitionIdMutex);
|
|
|
|
|
m_curPetitionId = petitionId;
|
|
|
|
|
}
|
2008-12-07 21:47:53 +00:00
|
|
|
GetGui().startVoteOnKick(kickPlayerId, proposingPlayerId, timeoutSec, numVotesToKick);
|
2008-11-25 22:18:17 +00:00
|
|
|
if (GetGuiPlayerId() != kickPlayerId
|
2011-02-11 20:02:08 +00:00
|
|
|
&& GetGuiPlayerId() != proposingPlayerId) {
|
2008-11-25 22:18:17 +00:00
|
|
|
GetGui().changeVoteOnKickButtonsState(true);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-07 12:22:35 +00:00
|
|
|
void
|
|
|
|
|
ClientThread::UpdatePetition(unsigned petitionId, int /*numVotesAgainstKicking*/, int numVotesInFavourOfKicking, int numVotesToKick)
|
|
|
|
|
{
|
|
|
|
|
bool isCurPetition;
|
|
|
|
|
{
|
|
|
|
|
boost::mutex::scoped_lock lock(m_curPetitionIdMutex);
|
|
|
|
|
isCurPetition = m_curPetitionId == petitionId;
|
|
|
|
|
}
|
2011-02-11 20:02:08 +00:00
|
|
|
if (isCurPetition) {
|
2008-12-07 12:22:35 +00:00
|
|
|
GetGui().refreshVotesMonitor(numVotesInFavourOfKicking, numVotesToKick);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-07 11:48:01 +00:00
|
|
|
void
|
|
|
|
|
ClientThread::EndPetition(unsigned petitionId)
|
|
|
|
|
{
|
|
|
|
|
bool isCurPetition;
|
|
|
|
|
{
|
|
|
|
|
boost::mutex::scoped_lock lock(m_curPetitionIdMutex);
|
|
|
|
|
isCurPetition = m_curPetitionId == petitionId;
|
|
|
|
|
}
|
|
|
|
|
if (isCurPetition)
|
|
|
|
|
GetGui().endVoteOnKick();
|
|
|
|
|
}
|
|
|
|
|
|
2007-11-16 15:24:25 +00:00
|
|
|
void
|
|
|
|
|
ClientThread::UpdateStatData(const ServerStats &stats)
|
|
|
|
|
{
|
|
|
|
|
boost::mutex::scoped_lock lock(m_curStatsMutex);
|
|
|
|
|
if (stats.numberOfPlayersOnServer)
|
|
|
|
|
m_curStats.numberOfPlayersOnServer = stats.numberOfPlayersOnServer;
|
|
|
|
|
|
|
|
|
|
if (stats.totalPlayersEverLoggedIn)
|
|
|
|
|
m_curStats.totalPlayersEverLoggedIn = stats.totalPlayersEverLoggedIn;
|
|
|
|
|
|
|
|
|
|
if (stats.totalGamesEverCreated)
|
|
|
|
|
m_curStats.totalGamesEverCreated = stats.totalGamesEverCreated;
|
|
|
|
|
|
|
|
|
|
GetCallback().SignalNetClientStatsUpdate(m_curStats);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ServerStats
|
|
|
|
|
ClientThread::GetStatData() const
|
|
|
|
|
{
|
|
|
|
|
boost::mutex::scoped_lock lock(m_curStatsMutex);
|
|
|
|
|
return m_curStats;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
|
ClientThread::IsSessionEstablished() const
|
|
|
|
|
{
|
|
|
|
|
return m_sessionEstablished;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
ClientThread::SetSessionEstablished(bool flag)
|
|
|
|
|
{
|
2011-02-11 20:02:08 +00:00
|
|
|
if (m_sessionEstablished != flag) {
|
2009-06-20 18:41:03 +00:00
|
|
|
m_sessionEstablished = flag;
|
|
|
|
|
if (flag)
|
|
|
|
|
SendQueuedPackets();
|
|
|
|
|
}
|
2007-11-16 15:24:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
|
ClientThread::IsSynchronized() const
|
|
|
|
|
{
|
|
|
|
|
return m_playerInfoRequestList.empty();
|
|
|
|
|
}
|
|
|
|
|
|
2011-08-28 17:14:03 +00:00
|
|
|
void
|
|
|
|
|
ClientThread::ReadSessionGuidFromFile()
|
|
|
|
|
{
|
|
|
|
|
string guidFileName(GetContext().GetCacheDir() + TEMP_GUID_FILENAME);
|
|
|
|
|
ifstream guidStream(guidFileName.c_str(), ios::in | ios::binary);
|
2011-10-03 08:03:58 +00:00
|
|
|
if (guidStream.good()) {
|
2011-08-28 17:14:03 +00:00
|
|
|
std::vector<char> tmpGuid(CLIENT_GUID_SIZE);
|
|
|
|
|
guidStream.read(&tmpGuid[0], CLIENT_GUID_SIZE);
|
|
|
|
|
GetContext().SetSessionGuid(string(tmpGuid.begin(), tmpGuid.end()));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
ClientThread::WriteSessionGuidToFile() const
|
|
|
|
|
{
|
|
|
|
|
string guidFileName(GetContext().GetCacheDir() + TEMP_GUID_FILENAME);
|
|
|
|
|
ofstream guidStream(guidFileName.c_str(), ios::out | ios::trunc | ios::binary);
|
2011-10-03 08:03:58 +00:00
|
|
|
if (guidStream.good()) {
|
2011-08-28 17:14:03 +00:00
|
|
|
guidStream.write(GetContext().GetSessionGuid().c_str(), GetContext().GetSessionGuid().size());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|