2007-11-16 15:24:25 +00:00
|
|
|
/***************************************************************************
|
|
|
|
|
* Copyright (C) 2007 by Lothar May *
|
|
|
|
|
* *
|
|
|
|
|
* 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. *
|
|
|
|
|
***************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include <net/clientstate.h>
|
|
|
|
|
#include <net/clientthread.h>
|
|
|
|
|
#include <net/clientcontext.h>
|
2009-05-10 22:21:20 +00:00
|
|
|
#include <net/senderhelper.h>
|
2007-11-16 15:24:25 +00:00
|
|
|
#include <net/receiverhelper.h>
|
|
|
|
|
#include <net/netpacket.h>
|
|
|
|
|
#include <net/resolverthread.h>
|
|
|
|
|
#include <net/clientexception.h>
|
|
|
|
|
#include <net/socket_helper.h>
|
|
|
|
|
#include <net/socket_msg.h>
|
2008-04-19 11:48:09 +00:00
|
|
|
#include <net/downloadhelper.h>
|
2007-11-16 15:24:25 +00:00
|
|
|
#include <core/avatarmanager.h>
|
2008-04-29 22:46:27 +00:00
|
|
|
#include <core/crypthelper.h>
|
2007-12-12 13:37:45 +00:00
|
|
|
#include <qttoolsinterface.h>
|
2007-11-16 15:24:25 +00:00
|
|
|
|
|
|
|
|
#include <game.h>
|
|
|
|
|
#include <playerinterface.h>
|
|
|
|
|
|
2008-04-19 11:48:09 +00:00
|
|
|
#include "tinyxml.h"
|
|
|
|
|
#include "zlib.h"
|
2007-11-16 15:24:25 +00:00
|
|
|
#include <boost/bind.hpp>
|
2008-04-19 11:48:09 +00:00
|
|
|
#include <boost/iostreams/filtering_streambuf.hpp>
|
|
|
|
|
#include <boost/iostreams/copy.hpp>
|
|
|
|
|
#include <boost/iostreams/filter/zlib.hpp>
|
|
|
|
|
#include <boost/filesystem.hpp>
|
2007-11-16 15:24:25 +00:00
|
|
|
|
2008-04-19 11:48:09 +00:00
|
|
|
#include <iostream>
|
|
|
|
|
#include <fstream>
|
2007-11-16 15:24:25 +00:00
|
|
|
#include <sstream>
|
|
|
|
|
|
|
|
|
|
using namespace std;
|
2008-04-19 11:48:09 +00:00
|
|
|
using namespace boost::filesystem;
|
2007-11-16 15:24:25 +00:00
|
|
|
|
|
|
|
|
#define CLIENT_WAIT_TIMEOUT_MSEC 50
|
|
|
|
|
#define CLIENT_CONNECT_TIMEOUT_SEC 10
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ClientState::~ClientState()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
ClientStateInit &
|
|
|
|
|
ClientStateInit::Instance()
|
|
|
|
|
{
|
|
|
|
|
static ClientStateInit state;
|
|
|
|
|
return state;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ClientStateInit::ClientStateInit()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ClientStateInit::~ClientStateInit()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2009-06-14 22:07:41 +00:00
|
|
|
void
|
|
|
|
|
ClientStateInit::Enter(boost::shared_ptr<ClientThread> client)
|
2007-11-16 15:24:25 +00:00
|
|
|
{
|
2009-06-14 22:07:41 +00:00
|
|
|
ClientContext &context = client->GetContext();
|
2007-11-16 15:24:25 +00:00
|
|
|
|
|
|
|
|
if (context.GetServerAddr().empty())
|
|
|
|
|
throw ClientException(__FILE__, __LINE__, ERR_SOCK_SERVERADDR_NOT_SET, 0);
|
|
|
|
|
|
|
|
|
|
if (context.GetServerPort() < 1024)
|
|
|
|
|
throw ClientException(__FILE__, __LINE__, ERR_SOCK_INVALID_PORT, 0);
|
|
|
|
|
|
2009-06-14 22:07:41 +00:00
|
|
|
client->CreateContextSession();
|
|
|
|
|
client->GetCallback().SignalNetClientConnect(MSG_SOCK_INIT_DONE);
|
2007-11-24 14:04:18 +00:00
|
|
|
|
2008-05-10 15:47:48 +00:00
|
|
|
if (context.GetUseServerList())
|
2009-06-14 22:07:41 +00:00
|
|
|
client->SetState(ClientStateStartServerListDownload::Instance());
|
2008-05-10 15:47:48 +00:00
|
|
|
else
|
2009-06-14 22:07:41 +00:00
|
|
|
client->SetState(ClientStateStartResolve::Instance());
|
|
|
|
|
}
|
2007-11-16 15:24:25 +00:00
|
|
|
|
2009-06-14 22:07:41 +00:00
|
|
|
void
|
|
|
|
|
ClientStateInit::Exit(boost::shared_ptr<ClientThread> /*client*/)
|
|
|
|
|
{
|
|
|
|
|
// Nothing to do.
|
2007-11-16 15:24:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
ClientStateStartResolve &
|
|
|
|
|
ClientStateStartResolve::Instance()
|
|
|
|
|
{
|
|
|
|
|
static ClientStateStartResolve state;
|
|
|
|
|
return state;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ClientStateStartResolve::ClientStateStartResolve()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ClientStateStartResolve::~ClientStateStartResolve()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2009-06-14 22:07:41 +00:00
|
|
|
void
|
|
|
|
|
ClientStateStartResolve::Enter(boost::shared_ptr<ClientThread> client)
|
2007-11-16 15:24:25 +00:00
|
|
|
{
|
2009-06-14 22:07:41 +00:00
|
|
|
ClientContext &context = client->GetContext();
|
|
|
|
|
ostringstream portStr;
|
|
|
|
|
portStr << context.GetServerPort();
|
|
|
|
|
boost::asio::ip::tcp::resolver::query q(context.GetServerAddr(), portStr.str());
|
2007-11-16 15:24:25 +00:00
|
|
|
|
2009-06-14 22:07:41 +00:00
|
|
|
context.GetResolver()->async_resolve(
|
|
|
|
|
q,
|
|
|
|
|
boost::bind(&ClientStateStartResolve::HandleResolve,
|
|
|
|
|
this,
|
|
|
|
|
boost::asio::placeholders::error,
|
|
|
|
|
boost::asio::placeholders::iterator,
|
|
|
|
|
client));
|
2007-11-16 15:24:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2009-06-14 22:07:41 +00:00
|
|
|
ClientStateStartResolve::Exit(boost::shared_ptr<ClientThread> client)
|
2007-11-16 15:24:25 +00:00
|
|
|
{
|
2009-06-14 22:07:41 +00:00
|
|
|
client->GetContext().GetResolver()->cancel();
|
2007-11-16 15:24:25 +00:00
|
|
|
}
|
|
|
|
|
|
2009-06-14 22:07:41 +00:00
|
|
|
void
|
|
|
|
|
ClientStateStartResolve::HandleResolve(const boost::system::error_code& ec, boost::asio::ip::tcp::resolver::iterator endpoint_iterator,
|
|
|
|
|
boost::shared_ptr<ClientThread> client)
|
2007-11-16 15:24:25 +00:00
|
|
|
{
|
2009-06-14 22:07:41 +00:00
|
|
|
if (!ec && &client->GetState() == this)
|
2007-11-16 15:24:25 +00:00
|
|
|
{
|
2009-06-14 22:07:41 +00:00
|
|
|
client->GetCallback().SignalNetClientConnect(MSG_SOCK_RESOLVE_DONE);
|
|
|
|
|
// Use the first resolver result.
|
|
|
|
|
ClientStateStartConnect::Instance().SetRemoteEndpoint(endpoint_iterator);
|
|
|
|
|
client->SetState(ClientStateStartConnect::Instance());
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (ec != boost::asio::error::operation_aborted)
|
2007-11-16 15:24:25 +00:00
|
|
|
throw ClientException(__FILE__, __LINE__, ERR_SOCK_RESOLVE_FAILED, 0);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
2008-04-19 11:48:09 +00:00
|
|
|
ClientStateStartServerListDownload &
|
|
|
|
|
ClientStateStartServerListDownload::Instance()
|
|
|
|
|
{
|
|
|
|
|
static ClientStateStartServerListDownload state;
|
|
|
|
|
return state;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ClientStateStartServerListDownload::ClientStateStartServerListDownload()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ClientStateStartServerListDownload::~ClientStateStartServerListDownload()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2009-06-14 22:07:41 +00:00
|
|
|
void
|
|
|
|
|
ClientStateStartServerListDownload::Enter(boost::shared_ptr<ClientThread> client)
|
2008-04-19 11:48:09 +00:00
|
|
|
{
|
2009-06-14 22:07:41 +00:00
|
|
|
const ClientContext &context = client->GetContext();
|
2008-04-19 11:48:09 +00:00
|
|
|
path tmpServerListPath(context.GetCacheDir());
|
2008-05-10 15:47:48 +00:00
|
|
|
string serverListUrl(context.GetServerListUrl());
|
|
|
|
|
// Retrieve the file name from the URL.
|
|
|
|
|
size_t pos = serverListUrl.find_last_of('/');
|
2008-05-10 18:07:46 +00:00
|
|
|
if (serverListUrl.empty() || pos == string::npos || ++pos >= serverListUrl.length())
|
2008-05-10 15:47:48 +00:00
|
|
|
{
|
2008-05-10 18:07:46 +00:00
|
|
|
throw ClientException(__FILE__, __LINE__, ERR_SOCK_INVALID_SERVERLIST_URL, 0);
|
2008-05-10 15:47:48 +00:00
|
|
|
}
|
|
|
|
|
tmpServerListPath /= serverListUrl.substr(pos);
|
2008-04-29 22:46:27 +00:00
|
|
|
if (exists(tmpServerListPath))
|
|
|
|
|
{
|
|
|
|
|
// Download and compare md5.
|
|
|
|
|
tmpServerListPath = change_extension(tmpServerListPath, extension(tmpServerListPath) + ".md5");
|
2009-06-14 22:07:41 +00:00
|
|
|
boost::shared_ptr<DownloadHelper> downloader(new DownloadHelper);
|
2008-05-10 15:47:48 +00:00
|
|
|
downloader->Init(serverListUrl + ".md5", tmpServerListPath.directory_string());
|
2009-06-14 22:07:41 +00:00
|
|
|
ClientStateSynchronizingServerList::Instance().SetDownloadHelper(downloader);
|
|
|
|
|
client->SetState(ClientStateSynchronizingServerList::Instance());
|
2008-04-29 22:46:27 +00:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// Download server list.
|
2009-06-14 22:07:41 +00:00
|
|
|
boost::shared_ptr<DownloadHelper> downloader(new DownloadHelper);
|
2008-05-10 15:47:48 +00:00
|
|
|
downloader->Init(serverListUrl, tmpServerListPath.directory_string());
|
2009-06-14 22:07:41 +00:00
|
|
|
ClientStateDownloadingServerList::Instance().SetDownloadHelper(downloader);
|
|
|
|
|
client->SetState(ClientStateDownloadingServerList::Instance());
|
2008-04-29 22:46:27 +00:00
|
|
|
}
|
2009-06-14 22:07:41 +00:00
|
|
|
}
|
2008-04-19 11:48:09 +00:00
|
|
|
|
2009-06-14 22:07:41 +00:00
|
|
|
void
|
|
|
|
|
ClientStateStartServerListDownload::Exit(boost::shared_ptr<ClientThread> /*client*/)
|
|
|
|
|
{
|
|
|
|
|
// Nothing to do.
|
2008-04-19 11:48:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
2008-04-29 22:46:27 +00:00
|
|
|
ClientStateSynchronizingServerList &
|
|
|
|
|
ClientStateSynchronizingServerList::Instance()
|
|
|
|
|
{
|
|
|
|
|
static ClientStateSynchronizingServerList state;
|
|
|
|
|
return state;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ClientStateSynchronizingServerList::ClientStateSynchronizingServerList()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ClientStateSynchronizingServerList::~ClientStateSynchronizingServerList()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2009-06-14 22:07:41 +00:00
|
|
|
ClientStateSynchronizingServerList::Enter(boost::shared_ptr<ClientThread> client)
|
2008-04-29 22:46:27 +00:00
|
|
|
{
|
2009-06-14 22:07:41 +00:00
|
|
|
client->GetStateTimer().expires_from_now(
|
|
|
|
|
boost::posix_time::milliseconds(CLIENT_WAIT_TIMEOUT_MSEC));
|
|
|
|
|
client->GetStateTimer().async_wait(
|
|
|
|
|
boost::bind(
|
|
|
|
|
&ClientStateSynchronizingServerList::TimerLoop, this, boost::asio::placeholders::error, client));
|
2008-04-29 22:46:27 +00:00
|
|
|
}
|
|
|
|
|
|
2009-06-14 22:07:41 +00:00
|
|
|
void
|
|
|
|
|
ClientStateSynchronizingServerList::Exit(boost::shared_ptr<ClientThread> client)
|
2008-04-29 22:46:27 +00:00
|
|
|
{
|
2009-06-14 22:07:41 +00:00
|
|
|
client->GetStateTimer().cancel();
|
|
|
|
|
}
|
2008-04-29 22:46:27 +00:00
|
|
|
|
2009-06-14 22:07:41 +00:00
|
|
|
void
|
|
|
|
|
ClientStateSynchronizingServerList::SetDownloadHelper(boost::shared_ptr<DownloadHelper> helper)
|
|
|
|
|
{
|
|
|
|
|
m_downloadHelper = helper;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
ClientStateSynchronizingServerList::TimerLoop(const boost::system::error_code& ec, boost::shared_ptr<ClientThread> client)
|
|
|
|
|
{
|
|
|
|
|
if (!ec && &client->GetState() == this)
|
2008-04-29 22:46:27 +00:00
|
|
|
{
|
2009-06-14 22:07:41 +00:00
|
|
|
if (m_downloadHelper->Process())
|
|
|
|
|
{
|
|
|
|
|
m_downloadHelper.reset();
|
|
|
|
|
ClientContext &context = client->GetContext();
|
|
|
|
|
path md5ServerListPath(context.GetCacheDir());
|
2008-05-10 15:47:48 +00:00
|
|
|
|
2009-06-14 22:07:41 +00:00
|
|
|
// No more checking needed as this was done before.
|
|
|
|
|
md5ServerListPath /= context.GetServerListUrl().substr(context.GetServerListUrl().find_last_of('/') + 1) + ".md5";
|
|
|
|
|
path serverListPath = change_extension(md5ServerListPath, "");
|
|
|
|
|
// Compare the md5 sums.
|
|
|
|
|
string tmpMd5;
|
|
|
|
|
{
|
|
|
|
|
ifstream inFile(md5ServerListPath.directory_string().c_str(), ios_base::in);
|
|
|
|
|
if (inFile.fail())
|
|
|
|
|
throw ClientException(__FILE__, __LINE__, ERR_SOCK_OPEN_MD5_FAILED, 0);
|
|
|
|
|
inFile >> tmpMd5;
|
|
|
|
|
}
|
|
|
|
|
MD5Buf downloadedMd5;
|
|
|
|
|
if (!downloadedMd5.FromString(tmpMd5))
|
|
|
|
|
throw ClientException(__FILE__, __LINE__, ERR_SOCK_INVALID_SERVERLIST_MD5, 0);
|
|
|
|
|
MD5Buf currentMd5;
|
|
|
|
|
if (!CryptHelper::MD5Sum(serverListPath.directory_string(), currentMd5))
|
|
|
|
|
throw ClientException(__FILE__, __LINE__, ERR_SOCK_INVALID_SERVERLIST_MD5, 0);
|
|
|
|
|
if (downloadedMd5 == currentMd5)
|
|
|
|
|
{
|
|
|
|
|
// Server list is still current.
|
|
|
|
|
client->SetState(ClientStateReadingServerList::Instance());
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// Download new server list.
|
|
|
|
|
// Paranoia check before removing the file, we do not want to delete wrong files.
|
|
|
|
|
path tmpPath(serverListPath);
|
|
|
|
|
if (path(context.GetCacheDir()) == tmpPath.remove_leaf())
|
|
|
|
|
{
|
|
|
|
|
remove(serverListPath);
|
|
|
|
|
client->SetState(ClientStateStartServerListDownload::Instance());
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
throw ClientException(__FILE__, __LINE__, ERR_SOCK_INVALID_SERVERLIST_URL, 0);
|
|
|
|
|
}
|
2008-04-29 22:46:27 +00:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2009-06-14 22:07:41 +00:00
|
|
|
// Download still in process. Delay.
|
|
|
|
|
client->GetStateTimer().expires_from_now(
|
|
|
|
|
boost::posix_time::milliseconds(CLIENT_WAIT_TIMEOUT_MSEC));
|
|
|
|
|
client->GetStateTimer().async_wait(
|
|
|
|
|
boost::bind(
|
|
|
|
|
&ClientStateSynchronizingServerList::TimerLoop, this, boost::asio::placeholders::error, client));
|
2008-04-29 22:46:27 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
2008-04-19 11:48:09 +00:00
|
|
|
ClientStateDownloadingServerList &
|
|
|
|
|
ClientStateDownloadingServerList::Instance()
|
|
|
|
|
{
|
|
|
|
|
static ClientStateDownloadingServerList state;
|
|
|
|
|
return state;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ClientStateDownloadingServerList::ClientStateDownloadingServerList()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ClientStateDownloadingServerList::~ClientStateDownloadingServerList()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2009-06-14 22:07:41 +00:00
|
|
|
ClientStateDownloadingServerList::Enter(boost::shared_ptr<ClientThread> client)
|
2008-04-19 11:48:09 +00:00
|
|
|
{
|
2009-06-14 22:07:41 +00:00
|
|
|
client->GetStateTimer().expires_from_now(
|
|
|
|
|
boost::posix_time::milliseconds(CLIENT_WAIT_TIMEOUT_MSEC));
|
|
|
|
|
client->GetStateTimer().async_wait(
|
|
|
|
|
boost::bind(
|
|
|
|
|
&ClientStateDownloadingServerList::TimerLoop, this, boost::asio::placeholders::error, client));
|
2008-04-19 11:48:09 +00:00
|
|
|
}
|
|
|
|
|
|
2009-06-14 22:07:41 +00:00
|
|
|
void
|
|
|
|
|
ClientStateDownloadingServerList::Exit(boost::shared_ptr<ClientThread> client)
|
2008-04-19 11:48:09 +00:00
|
|
|
{
|
2009-06-14 22:07:41 +00:00
|
|
|
client->GetStateTimer().cancel();
|
|
|
|
|
}
|
2008-04-19 11:48:09 +00:00
|
|
|
|
2009-06-14 22:07:41 +00:00
|
|
|
void
|
|
|
|
|
ClientStateDownloadingServerList::SetDownloadHelper(boost::shared_ptr<DownloadHelper> helper)
|
|
|
|
|
{
|
|
|
|
|
m_downloadHelper = helper;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
ClientStateDownloadingServerList::TimerLoop(const boost::system::error_code& ec, boost::shared_ptr<ClientThread> client)
|
|
|
|
|
{
|
|
|
|
|
if (!ec && &client->GetState() == this)
|
2008-04-19 11:48:09 +00:00
|
|
|
{
|
2009-06-14 22:07:41 +00:00
|
|
|
if (m_downloadHelper->Process())
|
|
|
|
|
{
|
|
|
|
|
m_downloadHelper.reset();
|
|
|
|
|
client->SetState(ClientStateReadingServerList::Instance());
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
client->GetStateTimer().expires_from_now(
|
|
|
|
|
boost::posix_time::milliseconds(CLIENT_WAIT_TIMEOUT_MSEC));
|
|
|
|
|
client->GetStateTimer().async_wait(
|
|
|
|
|
boost::bind(
|
|
|
|
|
&ClientStateDownloadingServerList::TimerLoop, this, boost::asio::placeholders::error, client));
|
|
|
|
|
}
|
2008-04-19 11:48:09 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
2008-04-29 22:46:27 +00:00
|
|
|
ClientStateReadingServerList &
|
|
|
|
|
ClientStateReadingServerList::Instance()
|
|
|
|
|
{
|
|
|
|
|
static ClientStateReadingServerList state;
|
|
|
|
|
return state;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ClientStateReadingServerList::ClientStateReadingServerList()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ClientStateReadingServerList::~ClientStateReadingServerList()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2009-06-14 22:07:41 +00:00
|
|
|
void
|
|
|
|
|
ClientStateReadingServerList::Enter(boost::shared_ptr<ClientThread> client)
|
2008-04-29 22:46:27 +00:00
|
|
|
{
|
2009-06-14 22:07:41 +00:00
|
|
|
ClientContext &context = client->GetContext();
|
2008-04-29 22:46:27 +00:00
|
|
|
path zippedServerListPath(context.GetCacheDir());
|
2008-05-10 15:47:48 +00:00
|
|
|
zippedServerListPath /= context.GetServerListUrl().substr(context.GetServerListUrl().find_last_of('/') + 1);
|
|
|
|
|
path xmlServerListPath;
|
|
|
|
|
if (extension(zippedServerListPath) == ".z")
|
2008-04-29 22:46:27 +00:00
|
|
|
{
|
2008-05-10 15:47:48 +00:00
|
|
|
xmlServerListPath = change_extension(zippedServerListPath, "");
|
|
|
|
|
|
|
|
|
|
// Unzip the file using zlib.
|
2008-05-10 18:07:46 +00:00
|
|
|
try {
|
2008-05-10 15:47:48 +00:00
|
|
|
ifstream inFile(zippedServerListPath.directory_string().c_str(), ios_base::in | ios_base::binary);
|
|
|
|
|
ofstream outFile(xmlServerListPath.directory_string().c_str(), ios_base::out);
|
|
|
|
|
boost::iostreams::filtering_streambuf<boost::iostreams::input> in;
|
|
|
|
|
in.push(boost::iostreams::zlib_decompressor());
|
|
|
|
|
in.push(inFile);
|
|
|
|
|
boost::iostreams::copy(in, outFile);
|
2008-05-10 18:07:46 +00:00
|
|
|
} catch (...)
|
|
|
|
|
{
|
|
|
|
|
throw ClientException(__FILE__, __LINE__, ERR_SOCK_UNZIP_FAILED, 0);
|
2008-05-10 15:47:48 +00:00
|
|
|
}
|
2008-04-29 22:46:27 +00:00
|
|
|
}
|
2008-05-10 15:47:48 +00:00
|
|
|
else
|
|
|
|
|
xmlServerListPath = zippedServerListPath;
|
2008-04-29 22:46:27 +00:00
|
|
|
|
|
|
|
|
// Parse the server address.
|
|
|
|
|
TiXmlDocument doc(xmlServerListPath.directory_string());
|
|
|
|
|
|
|
|
|
|
if (doc.LoadFile())
|
|
|
|
|
{
|
2009-06-14 22:07:41 +00:00
|
|
|
client->ClearServerInfoMap();
|
2009-04-05 11:19:50 +00:00
|
|
|
int serverCount = 0;
|
|
|
|
|
unsigned lastServerInfoId = 0;
|
|
|
|
|
TiXmlHandle docHandle(&doc);
|
|
|
|
|
const TiXmlElement *nextServer = docHandle.FirstChild("ServerList" ).FirstChild("Server").ToElement();
|
|
|
|
|
while (nextServer)
|
2008-04-29 22:46:27 +00:00
|
|
|
{
|
2009-04-05 11:19:50 +00:00
|
|
|
ServerInfo serverInfo;
|
|
|
|
|
{
|
|
|
|
|
int tmpId;
|
2009-04-12 11:29:37 +00:00
|
|
|
nextServer->QueryIntAttribute("id", &tmpId);
|
2009-04-05 11:19:50 +00:00
|
|
|
serverInfo.id = (unsigned)tmpId;
|
|
|
|
|
}
|
|
|
|
|
const TiXmlNode *nameNode = nextServer->FirstChild("Name");
|
|
|
|
|
const TiXmlNode *sponsorNode = nextServer->FirstChild("Sponsor");
|
|
|
|
|
const TiXmlNode *countryNode = nextServer->FirstChild("Country");
|
|
|
|
|
const TiXmlNode *addr4Node = nextServer->FirstChild("IPv4Address");
|
|
|
|
|
const TiXmlNode *addr6Node = nextServer->FirstChild("IPv6Address");
|
|
|
|
|
const TiXmlNode *sctpNode = nextServer->FirstChild("SCTP");
|
|
|
|
|
const TiXmlNode *portNode = nextServer->FirstChild("Port");
|
2008-05-10 18:07:46 +00:00
|
|
|
|
2009-04-05 11:19:50 +00:00
|
|
|
// IPv6 support for avatar servers depends on this address and on libcurl.
|
|
|
|
|
const TiXmlNode *avatarNode = nextServer->FirstChild("AvatarServerAddress");
|
2009-03-18 15:01:43 +00:00
|
|
|
|
2009-04-05 11:34:40 +00:00
|
|
|
if (!nameNode || !nameNode->ToElement() || !addr4Node || !addr4Node->ToElement()
|
|
|
|
|
|| !addr6Node || !addr6Node->ToElement() || !portNode || !portNode->ToElement())
|
2008-05-10 18:07:46 +00:00
|
|
|
throw ClientException(__FILE__, __LINE__, ERR_SOCK_INVALID_SERVERLIST_XML, 0);
|
|
|
|
|
|
2009-04-05 11:19:50 +00:00
|
|
|
serverInfo.name = nameNode->ToElement()->Attribute("value");
|
|
|
|
|
serverInfo.ipv4addr = addr4Node->ToElement()->Attribute("value");
|
|
|
|
|
serverInfo.ipv6addr = addr6Node->ToElement()->Attribute("value");
|
|
|
|
|
portNode->ToElement()->QueryIntAttribute("value", &serverInfo.port);
|
2008-05-10 18:07:46 +00:00
|
|
|
|
2009-04-05 11:19:50 +00:00
|
|
|
// Optional parameters:
|
|
|
|
|
if (sponsorNode && sponsorNode->ToElement())
|
|
|
|
|
serverInfo.sponsor = sponsorNode->ToElement()->Attribute("value");
|
|
|
|
|
if (countryNode && countryNode->ToElement())
|
|
|
|
|
serverInfo.country = countryNode->ToElement()->Attribute("value");
|
|
|
|
|
if (sctpNode && sctpNode->ToElement())
|
2009-03-18 15:01:43 +00:00
|
|
|
{
|
2009-04-05 11:19:50 +00:00
|
|
|
int tmpSctp;
|
2009-04-05 11:34:40 +00:00
|
|
|
sctpNode->ToElement()->QueryIntAttribute("value", &tmpSctp);
|
|
|
|
|
serverInfo.supportsSctp = tmpSctp == 1 ? true : false;
|
2009-03-18 15:01:43 +00:00
|
|
|
}
|
2009-04-05 11:19:50 +00:00
|
|
|
if (avatarNode && avatarNode->ToElement())
|
|
|
|
|
serverInfo.avatarServerAddr = avatarNode->ToElement()->Attribute("value");
|
2009-03-18 15:01:43 +00:00
|
|
|
|
2009-06-14 22:07:41 +00:00
|
|
|
client->AddServerInfo(serverInfo.id, serverInfo);
|
2009-04-05 11:19:50 +00:00
|
|
|
nextServer = nextServer->NextSiblingElement();
|
|
|
|
|
lastServerInfoId = serverInfo.id;
|
|
|
|
|
serverCount++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (serverCount == 1)
|
|
|
|
|
{
|
2009-06-14 22:07:41 +00:00
|
|
|
client->UseServer(lastServerInfoId);
|
|
|
|
|
client->GetCallback().SignalNetClientConnect(MSG_SOCK_SERVER_LIST_DONE);
|
|
|
|
|
client->SetState(ClientStateStartResolve::Instance());
|
2008-04-29 22:46:27 +00:00
|
|
|
}
|
2009-04-05 12:31:12 +00:00
|
|
|
else if (serverCount > 1)
|
2009-04-05 11:19:50 +00:00
|
|
|
{
|
2009-06-14 22:07:41 +00:00
|
|
|
client->GetCallback().SignalNetClientServerListShow();
|
|
|
|
|
client->SetState(ClientStateWaitChooseServer::Instance());
|
2009-04-05 11:19:50 +00:00
|
|
|
}
|
2008-05-10 18:07:46 +00:00
|
|
|
else
|
|
|
|
|
throw ClientException(__FILE__, __LINE__, ERR_SOCK_INVALID_SERVERLIST_XML, 0);
|
2008-04-29 22:46:27 +00:00
|
|
|
}
|
2008-05-10 18:07:46 +00:00
|
|
|
else
|
|
|
|
|
throw ClientException(__FILE__, __LINE__, ERR_SOCK_INVALID_SERVERLIST_XML, 0);
|
2009-06-14 22:07:41 +00:00
|
|
|
}
|
2008-05-10 18:07:46 +00:00
|
|
|
|
2009-06-14 22:07:41 +00:00
|
|
|
void
|
|
|
|
|
ClientStateReadingServerList::Exit(boost::shared_ptr<ClientThread> /*client*/)
|
|
|
|
|
{
|
|
|
|
|
// Nothing to do.
|
2009-04-05 12:31:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
ClientStateWaitChooseServer &
|
|
|
|
|
ClientStateWaitChooseServer::Instance()
|
|
|
|
|
{
|
|
|
|
|
static ClientStateWaitChooseServer state;
|
|
|
|
|
return state;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ClientStateWaitChooseServer::ClientStateWaitChooseServer()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ClientStateWaitChooseServer::~ClientStateWaitChooseServer()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2009-06-14 22:07:41 +00:00
|
|
|
void
|
|
|
|
|
ClientStateWaitChooseServer::Enter(boost::shared_ptr<ClientThread> client)
|
2009-04-05 12:31:12 +00:00
|
|
|
{
|
2009-06-14 22:07:41 +00:00
|
|
|
client->GetStateTimer().expires_from_now(
|
|
|
|
|
boost::posix_time::milliseconds(CLIENT_WAIT_TIMEOUT_MSEC));
|
|
|
|
|
client->GetStateTimer().async_wait(
|
|
|
|
|
boost::bind(
|
|
|
|
|
&ClientStateWaitChooseServer::TimerLoop, this, boost::asio::placeholders::error, client));
|
|
|
|
|
}
|
2009-04-05 12:31:12 +00:00
|
|
|
|
2009-06-14 22:07:41 +00:00
|
|
|
void
|
|
|
|
|
ClientStateWaitChooseServer::Exit(boost::shared_ptr<ClientThread> client)
|
|
|
|
|
{
|
|
|
|
|
client->GetStateTimer().cancel();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
ClientStateWaitChooseServer::TimerLoop(const boost::system::error_code& ec, boost::shared_ptr<ClientThread> client)
|
|
|
|
|
{
|
|
|
|
|
if (!ec && &client->GetState() == this)
|
2009-04-05 12:31:12 +00:00
|
|
|
{
|
2009-06-14 22:07:41 +00:00
|
|
|
unsigned serverId;
|
|
|
|
|
if (client->GetSelectedServer(serverId))
|
|
|
|
|
{
|
|
|
|
|
client->UseServer(serverId);
|
|
|
|
|
client->GetCallback().SignalNetClientConnect(MSG_SOCK_SERVER_LIST_DONE);
|
|
|
|
|
client->SetState(ClientStateStartResolve::Instance());
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
client->GetStateTimer().expires_from_now(
|
|
|
|
|
boost::posix_time::milliseconds(CLIENT_WAIT_TIMEOUT_MSEC));
|
|
|
|
|
client->GetStateTimer().async_wait(
|
|
|
|
|
boost::bind(
|
|
|
|
|
&ClientStateWaitChooseServer::TimerLoop, this, boost::asio::placeholders::error, client));
|
|
|
|
|
}
|
2009-04-05 12:31:12 +00:00
|
|
|
}
|
2008-04-29 22:46:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
2007-11-16 15:24:25 +00:00
|
|
|
ClientStateStartConnect &
|
|
|
|
|
ClientStateStartConnect::Instance()
|
|
|
|
|
{
|
|
|
|
|
static ClientStateStartConnect state;
|
|
|
|
|
return state;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ClientStateStartConnect::ClientStateStartConnect()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ClientStateStartConnect::~ClientStateStartConnect()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2009-06-14 22:07:41 +00:00
|
|
|
void
|
|
|
|
|
ClientStateStartConnect::Enter(boost::shared_ptr<ClientThread> client)
|
2007-11-16 15:24:25 +00:00
|
|
|
{
|
2009-06-14 22:07:41 +00:00
|
|
|
client->GetStateTimer().expires_from_now(
|
|
|
|
|
boost::posix_time::seconds(CLIENT_CONNECT_TIMEOUT_SEC));
|
|
|
|
|
client->GetStateTimer().async_wait(
|
|
|
|
|
boost::bind(
|
|
|
|
|
&ClientStateStartConnect::TimerTimeout, this, boost::asio::placeholders::error, client));
|
2007-11-16 15:24:25 +00:00
|
|
|
|
2009-06-14 22:07:41 +00:00
|
|
|
boost::asio::ip::tcp::endpoint endpoint = *m_remoteEndpointIterator;
|
|
|
|
|
client->GetContext().GetSessionData()->GetAsioSocket()->async_connect(
|
|
|
|
|
endpoint,
|
|
|
|
|
boost::bind(&ClientStateStartConnect::HandleConnect,
|
|
|
|
|
this,
|
|
|
|
|
boost::asio::placeholders::error,
|
|
|
|
|
++m_remoteEndpointIterator,
|
|
|
|
|
client));
|
2007-11-16 15:24:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2009-06-14 22:07:41 +00:00
|
|
|
ClientStateStartConnect::Exit(boost::shared_ptr<ClientThread> client)
|
2007-11-16 15:24:25 +00:00
|
|
|
{
|
2009-06-14 22:07:41 +00:00
|
|
|
client->GetStateTimer().cancel();
|
2007-11-16 15:24:25 +00:00
|
|
|
}
|
|
|
|
|
|
2009-06-14 22:07:41 +00:00
|
|
|
void
|
|
|
|
|
ClientStateStartConnect::SetRemoteEndpoint(boost::asio::ip::tcp::resolver::iterator endpointIterator)
|
2007-11-16 15:24:25 +00:00
|
|
|
{
|
2009-06-14 22:07:41 +00:00
|
|
|
m_remoteEndpointIterator = endpointIterator;
|
|
|
|
|
}
|
2007-11-16 15:24:25 +00:00
|
|
|
|
2009-06-14 22:07:41 +00:00
|
|
|
void
|
|
|
|
|
ClientStateStartConnect::HandleConnect(const boost::system::error_code& ec, boost::asio::ip::tcp::resolver::iterator endpoint_iterator,
|
|
|
|
|
boost::shared_ptr<ClientThread> client)
|
|
|
|
|
{
|
|
|
|
|
if (&client->GetState() == this)
|
2007-11-16 15:24:25 +00:00
|
|
|
{
|
2009-06-14 22:07:41 +00:00
|
|
|
if (!ec)
|
|
|
|
|
{
|
|
|
|
|
client->GetCallback().SignalNetClientConnect(MSG_SOCK_CONNECT_DONE);
|
|
|
|
|
client->SetState(ClientStateStartSession::Instance());
|
|
|
|
|
}
|
|
|
|
|
else if (endpoint_iterator != boost::asio::ip::tcp::resolver::iterator())
|
|
|
|
|
{
|
|
|
|
|
// Try next resolve entry.
|
|
|
|
|
ClientContext &context = client->GetContext();
|
2009-08-17 10:11:51 +00:00
|
|
|
boost::system::error_code ec;
|
|
|
|
|
context.GetSessionData()->GetAsioSocket()->close(ec);
|
2009-06-14 22:07:41 +00:00
|
|
|
boost::asio::ip::tcp::endpoint endpoint = *endpoint_iterator;
|
|
|
|
|
context.GetSessionData()->GetAsioSocket()->async_connect(
|
|
|
|
|
endpoint,
|
|
|
|
|
boost::bind(&ClientStateStartConnect::HandleConnect,
|
|
|
|
|
this,
|
|
|
|
|
boost::asio::placeholders::error,
|
|
|
|
|
++m_remoteEndpointIterator,
|
|
|
|
|
client));
|
|
|
|
|
}
|
2007-11-16 15:24:25 +00:00
|
|
|
else
|
2009-06-14 22:07:41 +00:00
|
|
|
{
|
|
|
|
|
if (ec != boost::asio::error::operation_aborted)
|
|
|
|
|
throw ClientException(__FILE__, __LINE__, ERR_SOCK_CONNECT_FAILED, ec.value());
|
|
|
|
|
}
|
2007-11-16 15:24:25 +00:00
|
|
|
}
|
2009-06-14 22:07:41 +00:00
|
|
|
}
|
2007-11-16 15:24:25 +00:00
|
|
|
|
2009-06-14 22:07:41 +00:00
|
|
|
void
|
|
|
|
|
ClientStateStartConnect::TimerTimeout(const boost::system::error_code& ec, boost::shared_ptr<ClientThread> client)
|
|
|
|
|
{
|
|
|
|
|
if (!ec && &client->GetState() == this)
|
|
|
|
|
{
|
2009-08-17 10:11:51 +00:00
|
|
|
boost::system::error_code ec;
|
|
|
|
|
client->GetContext().GetSessionData()->GetAsioSocket()->close(ec);
|
2009-06-14 22:07:41 +00:00
|
|
|
throw ClientException(__FILE__, __LINE__, ERR_SOCK_CONNECT_TIMEOUT, 0);
|
|
|
|
|
}
|
2007-11-16 15:24:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
AbstractClientStateReceiving::AbstractClientStateReceiving()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AbstractClientStateReceiving::~AbstractClientStateReceiving()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2009-06-14 22:07:41 +00:00
|
|
|
void
|
|
|
|
|
AbstractClientStateReceiving::HandlePacket(boost::shared_ptr<ClientThread> client, boost::shared_ptr<NetPacket> tmpPacket)
|
|
|
|
|
{
|
2009-08-02 15:11:40 +00:00
|
|
|
if (tmpPacket->GetMsg()->present == PokerTHMessage_PR_playerInfoReplyMessage)
|
2009-06-14 22:07:41 +00:00
|
|
|
{
|
2009-08-02 15:11:40 +00:00
|
|
|
unsigned playerId = tmpPacket->GetMsg()->choice.playerInfoReplyMessage.playerId;
|
|
|
|
|
if (tmpPacket->GetMsg()->choice.playerInfoReplyMessage.playerInfoResult.present == playerInfoResult_PR_playerInfoData)
|
|
|
|
|
{
|
|
|
|
|
PlayerInfo tmpInfo;
|
|
|
|
|
PlayerInfoData_t *netInfo = &tmpPacket->GetMsg()->choice.playerInfoReplyMessage.playerInfoResult.choice.playerInfoData;
|
|
|
|
|
tmpInfo.playerName = STL_STRING_FROM_OCTET_STRING(netInfo->playerName);
|
2010-03-24 15:54:04 +00:00
|
|
|
tmpInfo.ptype = netInfo->isHuman ? PLAYER_TYPE_HUMAN : PLAYER_TYPE_COMPUTER;
|
|
|
|
|
tmpInfo.isGuest = netInfo->playerRights == PlayerInfoRights_playerRightsGuest;
|
2009-08-02 15:11:40 +00:00
|
|
|
if (netInfo->avatarData != NULL)
|
|
|
|
|
{
|
|
|
|
|
tmpInfo.hasAvatar = true;
|
2009-12-28 12:16:52 +00:00
|
|
|
memcpy(tmpInfo.avatar.GetData(), netInfo->avatarData->avatar.buf, MD5_DATA_SIZE);
|
2009-08-02 15:11:40 +00:00
|
|
|
tmpInfo.avatarType = (AvatarFileType)netInfo->avatarData->avatarType;
|
|
|
|
|
}
|
|
|
|
|
client->SetPlayerInfo(
|
|
|
|
|
playerId,
|
|
|
|
|
tmpInfo);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
client->SetUnknownPlayer(playerId);
|
|
|
|
|
}
|
2009-06-14 22:07:41 +00:00
|
|
|
}
|
2009-08-02 15:11:40 +00:00
|
|
|
else if (tmpPacket->GetMsg()->present == PokerTHMessage_PR_gamePlayerMessage)
|
2009-06-14 22:07:41 +00:00
|
|
|
{
|
2009-08-02 15:11:40 +00:00
|
|
|
GamePlayerMessage_t *netGamePlayer = &tmpPacket->GetMsg()->choice.gamePlayerMessage;
|
|
|
|
|
// unsigned gameId = netGamePlayer->gameId;
|
|
|
|
|
if (netGamePlayer->gamePlayerNotification.present == gamePlayerNotification_PR_removedFromGame)
|
|
|
|
|
{
|
|
|
|
|
RemovedFromGame_t *netRemoved = &netGamePlayer->gamePlayerNotification.choice.removedFromGame;
|
|
|
|
|
|
|
|
|
|
client->ClearPlayerDataList();
|
|
|
|
|
// Resubscribe Lobby messages.
|
|
|
|
|
client->ResubscribeLobbyMsg();
|
|
|
|
|
// Show Lobby.
|
|
|
|
|
client->GetCallback().SignalNetClientWaitDialog();
|
2009-08-04 22:24:31 +00:00
|
|
|
int removeReason;
|
|
|
|
|
switch (netRemoved->removedFromGameReason)
|
|
|
|
|
{
|
|
|
|
|
case removedFromGameReason_kickedFromGame :
|
|
|
|
|
removeReason = NTF_NET_REMOVED_KICKED;
|
|
|
|
|
break;
|
|
|
|
|
case removedFromGameReason_gameIsFull :
|
|
|
|
|
removeReason = NTF_NET_REMOVED_GAME_FULL;
|
|
|
|
|
break;
|
|
|
|
|
case removedFromGameReason_gameIsRunning :
|
|
|
|
|
removeReason = NTF_NET_REMOVED_ALREADY_RUNNING;
|
|
|
|
|
break;
|
|
|
|
|
case removedFromGameReason_gameTimeout :
|
|
|
|
|
removeReason = NTF_NET_REMOVED_TIMEOUT;
|
|
|
|
|
break;
|
|
|
|
|
case removedFromGameReason_removedStartFailed :
|
|
|
|
|
removeReason = NTF_NET_REMOVED_START_FAILED;
|
|
|
|
|
break;
|
|
|
|
|
default :
|
|
|
|
|
removeReason = NTF_NET_REMOVED_ON_REQUEST;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
client->GetCallback().SignalNetClientRemovedFromGame(removeReason);
|
2009-08-02 15:11:40 +00:00
|
|
|
client->SetState(ClientStateWaitJoin::Instance());
|
|
|
|
|
}
|
|
|
|
|
else if (netGamePlayer->gamePlayerNotification.present == gamePlayerNotification_PR_gamePlayerLeft)
|
|
|
|
|
{
|
|
|
|
|
// A player left the game.
|
|
|
|
|
GamePlayerLeft_t *netLeft = &netGamePlayer->gamePlayerNotification.choice.gamePlayerLeft;
|
|
|
|
|
|
|
|
|
|
// Signal to GUI and remove from data list.
|
|
|
|
|
client->RemovePlayerData(netLeft->playerId, netLeft->gamePlayerLeftReason);
|
|
|
|
|
}
|
|
|
|
|
else if (netGamePlayer->gamePlayerNotification.present == gamePlayerNotification_PR_gameAdminChanged)
|
|
|
|
|
{
|
|
|
|
|
// New admin for the game.
|
|
|
|
|
GameAdminChanged_t *netChanged = &netGamePlayer->gamePlayerNotification.choice.gameAdminChanged;
|
|
|
|
|
|
|
|
|
|
// Set new game admin and signal to GUI.
|
|
|
|
|
client->SetNewGameAdmin(netChanged->newAdminPlayerId);
|
|
|
|
|
}
|
2009-06-14 22:07:41 +00:00
|
|
|
}
|
2009-08-02 15:11:40 +00:00
|
|
|
else if (tmpPacket->GetMsg()->present == PokerTHMessage_PR_timeoutWarningMessage)
|
2009-06-14 22:07:41 +00:00
|
|
|
{
|
2009-08-02 15:11:40 +00:00
|
|
|
TimeoutWarningMessage_t *tmpTimeout = &tmpPacket->GetMsg()->choice.timeoutWarningMessage;
|
|
|
|
|
client->GetCallback().SignalNetClientShowTimeoutDialog((NetTimeoutReason)tmpTimeout->timeoutReason, tmpTimeout->remainingSeconds);
|
2009-06-14 22:07:41 +00:00
|
|
|
}
|
2009-08-02 15:11:40 +00:00
|
|
|
else if (tmpPacket->GetMsg()->present == PokerTHMessage_PR_chatMessage)
|
2009-06-14 22:07:41 +00:00
|
|
|
{
|
|
|
|
|
// Chat message - display it in the GUI.
|
2009-08-02 15:11:40 +00:00
|
|
|
ChatMessage_t *netMessage = &tmpPacket->GetMsg()->choice.chatMessage;
|
2007-11-16 15:24:25 +00:00
|
|
|
|
2009-06-14 22:07:41 +00:00
|
|
|
string playerName;
|
2009-08-15 10:25:13 +00:00
|
|
|
if (netMessage->chatType.present == chatType_PR_chatTypeBroadcast)
|
2007-11-16 15:24:25 +00:00
|
|
|
{
|
2009-08-15 10:25:13 +00:00
|
|
|
client->GetCallback().SignalNetClientGameChatMsg("(global notice)", STL_STRING_FROM_OCTET_STRING(netMessage->chatText));
|
|
|
|
|
client->GetCallback().SignalNetClientLobbyChatMsg("(global notice)", STL_STRING_FROM_OCTET_STRING(netMessage->chatText));
|
2007-11-16 15:24:25 +00:00
|
|
|
}
|
2009-08-17 09:45:06 +00:00
|
|
|
else if (netMessage->chatType.present == chatType_PR_chatTypeBot)
|
|
|
|
|
{
|
|
|
|
|
client->GetCallback().SignalNetClientLobbyChatMsg("(chat bot)", STL_STRING_FROM_OCTET_STRING(netMessage->chatText));
|
|
|
|
|
}
|
2009-08-15 10:25:13 +00:00
|
|
|
else if (netMessage->chatType.present == chatType_PR_chatTypeGame)
|
2009-06-14 22:07:41 +00:00
|
|
|
{
|
2009-08-15 10:25:13 +00:00
|
|
|
unsigned playerId = netMessage->chatType.choice.chatTypeGame.playerId;
|
|
|
|
|
boost::shared_ptr<PlayerData> tmpPlayer = client->GetPlayerDataByUniqueId(playerId);
|
2009-06-14 22:07:41 +00:00
|
|
|
if (tmpPlayer.get())
|
|
|
|
|
playerName = tmpPlayer->GetName();
|
2009-08-15 10:25:13 +00:00
|
|
|
if (!playerName.empty())
|
|
|
|
|
client->GetCallback().SignalNetClientGameChatMsg(playerName, STL_STRING_FROM_OCTET_STRING(netMessage->chatText));
|
|
|
|
|
}
|
|
|
|
|
else if (netMessage->chatType.present == chatType_PR_chatTypeLobby)
|
|
|
|
|
{
|
|
|
|
|
unsigned playerId = netMessage->chatType.choice.chatTypeLobby.playerId;
|
2009-08-15 14:51:21 +00:00
|
|
|
PlayerInfo info;
|
|
|
|
|
if (client->GetCachedPlayerInfo(playerId, info))
|
|
|
|
|
client->GetCallback().SignalNetClientLobbyChatMsg(info.playerName, STL_STRING_FROM_OCTET_STRING(netMessage->chatText));
|
2009-06-14 22:07:41 +00:00
|
|
|
}
|
2007-11-16 15:24:25 +00:00
|
|
|
}
|
2009-08-02 15:11:40 +00:00
|
|
|
else if (tmpPacket->GetMsg()->present == PokerTHMessage_PR_dialogMessage)
|
2009-06-14 22:07:41 +00:00
|
|
|
{
|
|
|
|
|
// Message box - display it in the GUI.
|
2009-08-02 15:11:40 +00:00
|
|
|
DialogMessage_t *netDialog = &tmpPacket->GetMsg()->choice.dialogMessage;
|
|
|
|
|
client->GetCallback().SignalNetClientMsgBox(STL_STRING_FROM_OCTET_STRING(netDialog->notificationText));
|
2009-06-14 22:07:41 +00:00
|
|
|
}
|
2009-08-15 13:43:00 +00:00
|
|
|
else if (tmpPacket->GetMsg()->present == PokerTHMessage_PR_playerListMessage)
|
|
|
|
|
{
|
|
|
|
|
PlayerListMessage_t *netPlayerList = &tmpPacket->GetMsg()->choice.playerListMessage;
|
2009-08-15 22:20:19 +00:00
|
|
|
|
|
|
|
|
if (netPlayerList->playerListNotification == playerListNotification_playerListNew)
|
2009-08-15 13:43:00 +00:00
|
|
|
{
|
2009-08-15 22:20:19 +00:00
|
|
|
PlayerInfo info;
|
|
|
|
|
if (!client->GetCachedPlayerInfo(netPlayerList->playerId, info))
|
|
|
|
|
{
|
|
|
|
|
// Request player info.
|
|
|
|
|
ostringstream name;
|
|
|
|
|
name << "#" << netPlayerList->playerId;
|
|
|
|
|
info.playerName = name.str();
|
|
|
|
|
client->RequestPlayerInfo(netPlayerList->playerId);
|
|
|
|
|
}
|
|
|
|
|
client->GetCallback().SignalLobbyPlayerJoined(netPlayerList->playerId, info.playerName);
|
|
|
|
|
}
|
|
|
|
|
else if (netPlayerList->playerListNotification == playerListNotification_playerListLeft)
|
|
|
|
|
{
|
|
|
|
|
client->GetCallback().SignalLobbyPlayerLeft(netPlayerList->playerId);
|
2009-08-15 13:43:00 +00:00
|
|
|
}
|
|
|
|
|
}
|
2009-08-02 15:11:40 +00:00
|
|
|
else if (tmpPacket->GetMsg()->present == PokerTHMessage_PR_gameListMessage)
|
2009-06-14 22:07:41 +00:00
|
|
|
{
|
2009-08-02 15:11:40 +00:00
|
|
|
GameListMessage_t *netGameList = &tmpPacket->GetMsg()->choice.gameListMessage;
|
|
|
|
|
unsigned gameId = netGameList->gameId;
|
2007-11-16 15:24:25 +00:00
|
|
|
|
2009-08-02 15:11:40 +00:00
|
|
|
if (netGameList->gameListNotification.present == gameListNotification_PR_gameListNew)
|
2009-06-14 22:07:41 +00:00
|
|
|
{
|
2009-08-02 15:11:40 +00:00
|
|
|
// A new game was created on the server.
|
|
|
|
|
GameListNew_t *netListNew = &netGameList->gameListNotification.choice.gameListNew;
|
|
|
|
|
|
|
|
|
|
NonZeroId_t **playerIds = netListNew->playerIds.list.array;
|
|
|
|
|
unsigned numPlayers = netListNew->playerIds.list.count;
|
|
|
|
|
// Request player info for players if needed.
|
2009-08-02 21:22:05 +00:00
|
|
|
GameInfo tmpInfo;
|
|
|
|
|
for (unsigned i = 0; i < numPlayers; i++)
|
2009-06-14 22:07:41 +00:00
|
|
|
{
|
2009-08-02 21:22:05 +00:00
|
|
|
PlayerInfo info;
|
|
|
|
|
unsigned playerId = *playerIds[i];
|
|
|
|
|
if (!client->GetCachedPlayerInfo(playerId, info))
|
2009-08-02 15:11:40 +00:00
|
|
|
{
|
2009-08-02 21:22:05 +00:00
|
|
|
// Request player info.
|
|
|
|
|
client->RequestPlayerInfo(playerId);
|
2009-08-02 15:11:40 +00:00
|
|
|
}
|
2009-08-02 21:22:05 +00:00
|
|
|
tmpInfo.players.push_back(playerId);
|
2009-08-02 15:11:40 +00:00
|
|
|
}
|
2009-08-02 21:22:05 +00:00
|
|
|
tmpInfo.adminPlayerId = netListNew->adminPlayerId;
|
|
|
|
|
tmpInfo.isPasswordProtected = netListNew->isPrivate ? true : false;
|
2009-08-03 22:26:45 +00:00
|
|
|
tmpInfo.mode = static_cast<GameMode>(netListNew->gameMode);
|
2009-08-02 21:22:05 +00:00
|
|
|
tmpInfo.name = STL_STRING_FROM_OCTET_STRING(netListNew->gameInfo.gameName);
|
|
|
|
|
NetPacket::GetGameData(&netListNew->gameInfo, tmpInfo.data);
|
|
|
|
|
|
|
|
|
|
client->AddGameInfo(gameId, tmpInfo);
|
2009-08-02 15:11:40 +00:00
|
|
|
}
|
|
|
|
|
else if (netGameList->gameListNotification.present == gameListNotification_PR_gameListUpdate)
|
2009-06-14 22:07:41 +00:00
|
|
|
{
|
2009-08-02 15:11:40 +00:00
|
|
|
// An existing game was updated on the server.
|
|
|
|
|
GameListUpdate_t *netListUpdate = &netGameList->gameListNotification.choice.gameListUpdate;
|
|
|
|
|
if (netListUpdate->gameMode == NetGameMode_gameClosed)
|
|
|
|
|
client->RemoveGameInfo(gameId);
|
|
|
|
|
else
|
|
|
|
|
client->UpdateGameInfoMode(gameId, static_cast<GameMode>(netListUpdate->gameMode));
|
|
|
|
|
}
|
|
|
|
|
else if (netGameList->gameListNotification.present == gameListNotification_PR_gameListPlayerJoined)
|
|
|
|
|
{
|
|
|
|
|
GameListPlayerJoined_t *netListJoined = &netGameList->gameListNotification.choice.gameListPlayerJoined;
|
|
|
|
|
|
|
|
|
|
client->ModifyGameInfoAddPlayer(gameId, netListJoined->playerId);
|
|
|
|
|
// Request player info if needed.
|
|
|
|
|
PlayerInfo info;
|
|
|
|
|
if (!client->GetCachedPlayerInfo(netListJoined->playerId, info))
|
|
|
|
|
{
|
|
|
|
|
client->RequestPlayerInfo(netListJoined->playerId);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (netGameList->gameListNotification.present == gameListNotification_PR_gameListPlayerLeft)
|
|
|
|
|
{
|
|
|
|
|
GameListPlayerLeft_t *netListLeft = &netGameList->gameListNotification.choice.gameListPlayerLeft;
|
|
|
|
|
|
|
|
|
|
client->ModifyGameInfoRemovePlayer(gameId, netListLeft->playerId);
|
|
|
|
|
}
|
|
|
|
|
else if (netGameList->gameListNotification.present == gameListNotification_PR_gameListAdminChanged)
|
|
|
|
|
{
|
|
|
|
|
GameListAdminChanged_t *netListAdmin = &netGameList->gameListNotification.choice.gameListAdminChanged;
|
|
|
|
|
|
|
|
|
|
client->UpdateGameInfoAdmin(gameId, netListAdmin->newAdminPlayerId);
|
2009-06-14 22:07:41 +00:00
|
|
|
}
|
|
|
|
|
}
|
2009-08-02 15:11:40 +00:00
|
|
|
else if (tmpPacket->GetMsg()->present == PokerTHMessage_PR_startKickPetitionMessage)
|
2009-06-14 22:07:41 +00:00
|
|
|
{
|
2009-08-02 15:11:40 +00:00
|
|
|
StartKickPetitionMessage_t *netStartPetition = &tmpPacket->GetMsg()->choice.startKickPetitionMessage;
|
|
|
|
|
client->StartPetition(netStartPetition->petitionId, netStartPetition->proposingPlayerId,
|
|
|
|
|
netStartPetition->kickPlayerId, netStartPetition->kickTimeoutSec, netStartPetition->numVotesNeededToKick);
|
2009-06-14 22:07:41 +00:00
|
|
|
}
|
2009-08-02 15:11:40 +00:00
|
|
|
else if (tmpPacket->GetMsg()->present == PokerTHMessage_PR_kickPetitionUpdateMessage)
|
2009-06-14 22:07:41 +00:00
|
|
|
{
|
2009-08-02 15:11:40 +00:00
|
|
|
KickPetitionUpdateMessage_t *netPetitionUpdate = &tmpPacket->GetMsg()->choice.kickPetitionUpdateMessage;
|
|
|
|
|
client->UpdatePetition(netPetitionUpdate->petitionId, netPetitionUpdate->numVotesAgainstKicking,
|
|
|
|
|
netPetitionUpdate->numVotesInFavourOfKicking, netPetitionUpdate->numVotesNeededToKick);
|
2009-06-14 22:07:41 +00:00
|
|
|
}
|
2009-08-02 15:11:40 +00:00
|
|
|
else if (tmpPacket->GetMsg()->present == PokerTHMessage_PR_endKickPetitionMessage)
|
2009-06-14 22:07:41 +00:00
|
|
|
{
|
2009-08-02 15:11:40 +00:00
|
|
|
EndKickPetitionMessage_t *netEndPetition = &tmpPacket->GetMsg()->choice.endKickPetitionMessage;
|
|
|
|
|
client->EndPetition(netEndPetition->petitionId);
|
2009-06-14 22:07:41 +00:00
|
|
|
}
|
2009-08-02 15:11:40 +00:00
|
|
|
else if (tmpPacket->GetMsg()->present == PokerTHMessage_PR_avatarReplyMessage)
|
2009-06-14 22:07:41 +00:00
|
|
|
{
|
2009-08-02 15:11:40 +00:00
|
|
|
AvatarReplyMessage_t *netAvatarReply = &tmpPacket->GetMsg()->choice.avatarReplyMessage;
|
|
|
|
|
unsigned requestId = netAvatarReply->requestId;
|
|
|
|
|
if (netAvatarReply->avatarResult.present == avatarResult_PR_avatarHeader)
|
|
|
|
|
{
|
|
|
|
|
AvatarHeader_t *netAvatarHeader = &netAvatarReply->avatarResult.choice.avatarHeader;
|
|
|
|
|
client->AddTempAvatarFile(requestId, netAvatarHeader->avatarSize, static_cast<AvatarFileType>(netAvatarHeader->avatarType));
|
|
|
|
|
}
|
|
|
|
|
else if (netAvatarReply->avatarResult.present == avatarResult_PR_avatarData)
|
|
|
|
|
{
|
|
|
|
|
AvatarData_t *netAvatarData = &netAvatarReply->avatarResult.choice.avatarData;
|
|
|
|
|
vector<unsigned char> fileData(netAvatarData->avatarBlock.size);
|
|
|
|
|
memcpy(&fileData[0], netAvatarData->avatarBlock.buf, netAvatarData->avatarBlock.size);
|
|
|
|
|
client->StoreInTempAvatarFile(requestId, fileData);
|
|
|
|
|
}
|
|
|
|
|
else if (netAvatarReply->avatarResult.present == avatarResult_PR_avatarEnd)
|
|
|
|
|
{
|
|
|
|
|
client->CompleteTempAvatarFile(requestId);
|
|
|
|
|
}
|
|
|
|
|
else if (netAvatarReply->avatarResult.present == avatarResult_PR_unknownAvatar)
|
|
|
|
|
{
|
|
|
|
|
client->SetUnknownAvatar(requestId);
|
|
|
|
|
}
|
2009-06-14 22:07:41 +00:00
|
|
|
}
|
2009-08-02 15:11:40 +00:00
|
|
|
else if (tmpPacket->GetMsg()->present == PokerTHMessage_PR_statisticsMessage)
|
2009-06-14 22:07:41 +00:00
|
|
|
{
|
2009-08-02 15:11:40 +00:00
|
|
|
StatisticsMessage_t *netStatistics = &tmpPacket->GetMsg()->choice.statisticsMessage;
|
|
|
|
|
|
|
|
|
|
StatisticsData **statData = netStatistics->statisticsData.list.array;
|
|
|
|
|
unsigned numStats = netStatistics->statisticsData.list.count;
|
|
|
|
|
// Request player info for players if needed.
|
|
|
|
|
if (numStats && statData && *statData)
|
|
|
|
|
{
|
|
|
|
|
ServerStats tmpStats;
|
|
|
|
|
for (unsigned i = 0; i < numStats; i++)
|
|
|
|
|
{
|
|
|
|
|
if (statData[i]->statisticsType == statisticsType_statNumberOfPlayers)
|
|
|
|
|
tmpStats.numberOfPlayersOnServer = statData[i]->statisticsValue;
|
|
|
|
|
}
|
|
|
|
|
client->UpdateStatData(tmpStats);
|
|
|
|
|
}
|
2009-06-14 22:07:41 +00:00
|
|
|
}
|
2009-08-02 15:11:40 +00:00
|
|
|
else if (tmpPacket->GetMsg()->present == PokerTHMessage_PR_errorMessage)
|
2009-06-14 22:07:41 +00:00
|
|
|
{
|
|
|
|
|
// Server reported an error.
|
2009-08-02 15:11:40 +00:00
|
|
|
ErrorMessage_t *netError = &tmpPacket->GetMsg()->choice.errorMessage;
|
2009-06-14 22:07:41 +00:00
|
|
|
// Show the error.
|
2009-08-02 15:11:40 +00:00
|
|
|
throw ClientException(__FILE__, __LINE__, NetPacket::NetErrorToGameError(netError->errorReason), 0);
|
2009-06-14 22:07:41 +00:00
|
|
|
}
|
2009-08-03 20:42:32 +00:00
|
|
|
|
|
|
|
|
InternalHandlePacket(client, tmpPacket);
|
2007-11-16 15:24:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
2009-11-14 12:39:25 +00:00
|
|
|
ClientStateStartSession &
|
|
|
|
|
ClientStateStartSession::Instance()
|
|
|
|
|
{
|
|
|
|
|
static ClientStateStartSession state;
|
|
|
|
|
return state;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ClientStateStartSession::ClientStateStartSession()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ClientStateStartSession::~ClientStateStartSession()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
ClientStateStartSession::Enter(boost::shared_ptr<ClientThread> client)
|
|
|
|
|
{
|
2009-11-14 15:04:31 +00:00
|
|
|
// Now we finally start receiving data.
|
|
|
|
|
client->StartAsyncRead();
|
2009-11-14 12:39:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
ClientStateStartSession::Exit(boost::shared_ptr<ClientThread> /*client*/)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
ClientStateStartSession::InternalHandlePacket(boost::shared_ptr<ClientThread> client, boost::shared_ptr<NetPacket> tmpPacket)
|
|
|
|
|
{
|
|
|
|
|
if (tmpPacket->GetMsg()->present == PokerTHMessage_PR_announceMessage)
|
|
|
|
|
{
|
|
|
|
|
// Server has send announcement - check data.
|
|
|
|
|
AnnounceMessage_t *netAnnounce = &tmpPacket->GetMsg()->choice.announceMessage;
|
|
|
|
|
// Check current game version.
|
|
|
|
|
if (netAnnounce->latestGameVersion.major != POKERTH_VERSION_MAJOR
|
|
|
|
|
|| netAnnounce->latestGameVersion.minor != POKERTH_VERSION_MINOR)
|
|
|
|
|
{
|
|
|
|
|
client->GetCallback().SignalNetClientNotification(NTF_NET_NEW_RELEASE_AVAILABLE);
|
|
|
|
|
}
|
|
|
|
|
else if (POKERTH_BETA_REVISION && netAnnounce->latestBetaRevision != POKERTH_BETA_REVISION)
|
|
|
|
|
{
|
|
|
|
|
client->GetCallback().SignalNetClientNotification(NTF_NET_OUTDATED_BETA);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
ClientContext &context = client->GetContext();
|
|
|
|
|
|
|
|
|
|
// CASE 1: Authenticated login (username, challenge/response for password).
|
|
|
|
|
if (netAnnounce->serverType == serverType_serverTypeInternetAuth)
|
|
|
|
|
{
|
|
|
|
|
client->GetCallback().SignalNetClientLoginShow();
|
|
|
|
|
client->SetState(ClientStateWaitEnterLogin::Instance());
|
|
|
|
|
}
|
2009-11-14 15:04:31 +00:00
|
|
|
// CASE 2: Unauthenticated login (network game or dedicated server without auth backend).
|
2009-11-14 12:39:25 +00:00
|
|
|
else if (netAnnounce->serverType == serverType_serverTypeInternetNoAuth
|
|
|
|
|
|| netAnnounce->serverType == serverType_serverTypeLAN)
|
|
|
|
|
{
|
|
|
|
|
boost::shared_ptr<NetPacket> init(new NetPacket(NetPacket::Alloc));
|
|
|
|
|
init->GetMsg()->present = PokerTHMessage_PR_initMessage;
|
|
|
|
|
InitMessage_t *netInit = &init->GetMsg()->choice.initMessage;
|
|
|
|
|
netInit->requestedVersion.major = NET_VERSION_MAJOR;
|
|
|
|
|
netInit->requestedVersion.minor = NET_VERSION_MINOR;
|
2009-11-14 15:04:31 +00:00
|
|
|
netInit->login.present = login_PR_unauthenticatedLogin;
|
|
|
|
|
UnauthenticatedLogin_t *noauthLogin = &netInit->login.choice.unauthenticatedLogin;
|
|
|
|
|
OCTET_STRING_fromBuf(&noauthLogin->nickName,
|
2009-11-14 12:39:25 +00:00
|
|
|
context.GetPlayerName().c_str(),
|
|
|
|
|
context.GetPlayerName().length());
|
2009-11-14 15:04:31 +00:00
|
|
|
string avatarFile = client->GetQtToolsInterface().stringFromUtf8(context.GetAvatarFile());
|
|
|
|
|
if (!avatarFile.empty())
|
|
|
|
|
{
|
|
|
|
|
MD5Buf tmpMD5;
|
|
|
|
|
if (client->GetAvatarManager().GetHashForAvatar(avatarFile, tmpMD5))
|
|
|
|
|
{
|
|
|
|
|
// TODO: use sha1.
|
|
|
|
|
noauthLogin->avatar =
|
|
|
|
|
OCTET_STRING_new_fromBuf(
|
|
|
|
|
&asn_DEF_OCTET_STRING,
|
2009-12-28 12:16:52 +00:00
|
|
|
(const char *)tmpMD5.GetData(),
|
2009-11-14 15:04:31 +00:00
|
|
|
MD5_DATA_SIZE);
|
|
|
|
|
}
|
|
|
|
|
}
|
2009-11-14 12:39:25 +00:00
|
|
|
client->GetSender().Send(context.GetSessionData(), init);
|
2009-11-14 15:04:31 +00:00
|
|
|
client->SetState(ClientStateWaitSession::Instance());
|
2009-11-14 12:39:25 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
ClientStateWaitEnterLogin &
|
|
|
|
|
ClientStateWaitEnterLogin::Instance()
|
|
|
|
|
{
|
|
|
|
|
static ClientStateWaitEnterLogin state;
|
|
|
|
|
return state;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ClientStateWaitEnterLogin::ClientStateWaitEnterLogin()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ClientStateWaitEnterLogin::~ClientStateWaitEnterLogin()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
ClientStateWaitEnterLogin::Enter(boost::shared_ptr<ClientThread> client)
|
|
|
|
|
{
|
|
|
|
|
client->GetStateTimer().expires_from_now(
|
|
|
|
|
boost::posix_time::milliseconds(CLIENT_WAIT_TIMEOUT_MSEC));
|
|
|
|
|
client->GetStateTimer().async_wait(
|
|
|
|
|
boost::bind(
|
|
|
|
|
&ClientStateWaitEnterLogin::TimerLoop, this, boost::asio::placeholders::error, client));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
ClientStateWaitEnterLogin::Exit(boost::shared_ptr<ClientThread> client)
|
|
|
|
|
{
|
|
|
|
|
client->GetStateTimer().cancel();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
ClientStateWaitEnterLogin::TimerLoop(const boost::system::error_code& ec, boost::shared_ptr<ClientThread> client)
|
|
|
|
|
{
|
|
|
|
|
if (!ec && &client->GetState() == this)
|
|
|
|
|
{
|
2009-11-14 15:04:31 +00:00
|
|
|
ClientThread::LoginData loginData;
|
|
|
|
|
if (client->GetLoginData(loginData))
|
2009-11-14 12:39:25 +00:00
|
|
|
{
|
2009-11-14 15:04:31 +00:00
|
|
|
ClientContext &context = client->GetContext();
|
2009-11-14 12:39:25 +00:00
|
|
|
boost::shared_ptr<NetPacket> init(new NetPacket(NetPacket::Alloc));
|
|
|
|
|
init->GetMsg()->present = PokerTHMessage_PR_initMessage;
|
|
|
|
|
InitMessage_t *netInit = &init->GetMsg()->choice.initMessage;
|
|
|
|
|
netInit->requestedVersion.major = NET_VERSION_MAJOR;
|
|
|
|
|
netInit->requestedVersion.minor = NET_VERSION_MINOR;
|
2009-11-15 08:41:29 +00:00
|
|
|
|
|
|
|
|
context.SetPlayerName(loginData.userName);
|
|
|
|
|
|
|
|
|
|
// Handle guest login first.
|
|
|
|
|
if (loginData.isGuest)
|
2009-11-14 12:39:25 +00:00
|
|
|
{
|
2009-11-15 08:41:29 +00:00
|
|
|
context.SetPassword("");
|
2010-03-26 21:41:35 +00:00
|
|
|
context.SetPlayerRights(PLAYER_RIGHTS_GUEST);
|
2009-11-15 08:41:29 +00:00
|
|
|
netInit->login.present = login_PR_guestLogin;
|
|
|
|
|
GuestLogin_t *guestLogin = &netInit->login.choice.guestLogin;
|
|
|
|
|
OCTET_STRING_fromBuf(&guestLogin->nickName,
|
|
|
|
|
context.GetPlayerName().c_str(),
|
|
|
|
|
context.GetPlayerName().length());
|
2009-11-15 09:07:43 +00:00
|
|
|
|
|
|
|
|
client->GetSender().Send(context.GetSessionData(), init);
|
|
|
|
|
client->SetState(ClientStateWaitSession::Instance());
|
2009-11-15 08:41:29 +00:00
|
|
|
}
|
|
|
|
|
// If the player is not a guest, authenticate.
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
context.SetPassword(loginData.password);
|
|
|
|
|
netInit->login.present = login_PR_authenticatedLogin;
|
|
|
|
|
AuthenticatedLogin_t *authLogin = &netInit->login.choice.authenticatedLogin;
|
|
|
|
|
// Send authentication user data for challenge/response in init.
|
|
|
|
|
boost::shared_ptr<SessionData> tmpSession = context.GetSessionData();
|
|
|
|
|
tmpSession->CreateClientAuthSession(client->GetAuthContext(), context.GetPlayerName(), context.GetPassword());
|
|
|
|
|
if (!tmpSession->AuthStep(1, ""))
|
|
|
|
|
throw ClientException(__FILE__, __LINE__, ERR_NET_INVALID_PASSWORD, 0);
|
|
|
|
|
string outUserData(tmpSession->AuthGetNextOutMsg());
|
|
|
|
|
OCTET_STRING_fromBuf(&authLogin->clientUserData,
|
|
|
|
|
outUserData.c_str(),
|
|
|
|
|
outUserData.length());
|
|
|
|
|
string avatarFile = client->GetQtToolsInterface().stringFromUtf8(context.GetAvatarFile());
|
|
|
|
|
if (!avatarFile.empty())
|
2009-11-14 12:39:25 +00:00
|
|
|
{
|
2009-11-15 08:41:29 +00:00
|
|
|
MD5Buf tmpMD5;
|
|
|
|
|
if (client->GetAvatarManager().GetHashForAvatar(avatarFile, tmpMD5))
|
|
|
|
|
{
|
|
|
|
|
// TODO: use sha1.
|
|
|
|
|
authLogin->avatar =
|
|
|
|
|
OCTET_STRING_new_fromBuf(
|
|
|
|
|
&asn_DEF_OCTET_STRING,
|
2009-12-28 12:16:52 +00:00
|
|
|
(const char *)tmpMD5.GetData(),
|
2009-11-15 08:41:29 +00:00
|
|
|
MD5_DATA_SIZE);
|
|
|
|
|
}
|
2009-11-14 12:39:25 +00:00
|
|
|
}
|
2009-11-15 09:07:43 +00:00
|
|
|
client->GetSender().Send(context.GetSessionData(), init);
|
|
|
|
|
client->SetState(ClientStateWaitAuthChallenge::Instance());
|
2009-11-14 12:39:25 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
client->GetStateTimer().expires_from_now(
|
|
|
|
|
boost::posix_time::milliseconds(CLIENT_WAIT_TIMEOUT_MSEC));
|
|
|
|
|
client->GetStateTimer().async_wait(
|
|
|
|
|
boost::bind(
|
|
|
|
|
&ClientStateWaitEnterLogin::TimerLoop, this, boost::asio::placeholders::error, client));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
2009-10-22 22:55:19 +00:00
|
|
|
ClientStateWaitAuthChallenge &
|
|
|
|
|
ClientStateWaitAuthChallenge::Instance()
|
|
|
|
|
{
|
|
|
|
|
static ClientStateWaitAuthChallenge state;
|
|
|
|
|
return state;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ClientStateWaitAuthChallenge::ClientStateWaitAuthChallenge()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ClientStateWaitAuthChallenge::~ClientStateWaitAuthChallenge()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2010-03-30 17:10:37 +00:00
|
|
|
ClientStateWaitAuthChallenge::Enter(boost::shared_ptr<ClientThread> /*client*/)
|
2009-10-22 22:55:19 +00:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
ClientStateWaitAuthChallenge::Exit(boost::shared_ptr<ClientThread> /*client*/)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
ClientStateWaitAuthChallenge::InternalHandlePacket(boost::shared_ptr<ClientThread> client, boost::shared_ptr<NetPacket> tmpPacket)
|
|
|
|
|
{
|
2009-11-14 12:39:25 +00:00
|
|
|
if (tmpPacket->GetMsg()->present == PokerTHMessage_PR_authMessage)
|
2009-10-22 22:55:19 +00:00
|
|
|
{
|
|
|
|
|
// Check subtype.
|
|
|
|
|
AuthMessage_t *netAuth = &tmpPacket->GetMsg()->choice.authMessage;
|
|
|
|
|
if (netAuth->present == AuthMessage_PR_authServerChallenge)
|
|
|
|
|
{
|
|
|
|
|
AuthServerChallenge_t *netChallenge = &netAuth->choice.authServerChallenge;
|
2009-10-24 21:49:11 +00:00
|
|
|
string challengeStr = STL_STRING_FROM_OCTET_STRING(netChallenge->serverChallenge);
|
2009-10-22 22:55:19 +00:00
|
|
|
boost::shared_ptr<SessionData> tmpSession = client->GetContext().GetSessionData();
|
|
|
|
|
if (!tmpSession->AuthStep(2, challengeStr.c_str()))
|
|
|
|
|
throw ClientException(__FILE__, __LINE__, ERR_NET_INVALID_PASSWORD, 0);
|
|
|
|
|
string outUserData(tmpSession->AuthGetNextOutMsg());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
boost::shared_ptr<NetPacket> packet(new NetPacket(NetPacket::Alloc));
|
|
|
|
|
packet->GetMsg()->present = PokerTHMessage_PR_authMessage;
|
|
|
|
|
AuthMessage_t *outAuth = &packet->GetMsg()->choice.authMessage;
|
|
|
|
|
outAuth->present = AuthMessage_PR_authClientResponse;
|
|
|
|
|
AuthClientResponse_t *outResponse = &outAuth->choice.authClientResponse;
|
|
|
|
|
|
|
|
|
|
OCTET_STRING_fromBuf(&outResponse->clientResponse,
|
|
|
|
|
outUserData.c_str(),
|
|
|
|
|
outUserData.length());
|
|
|
|
|
client->GetSender().Send(tmpSession, packet);
|
|
|
|
|
client->SetState(ClientStateWaitAuthVerify::Instance());
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
throw ClientException(__FILE__, __LINE__, ERR_NET_INVALID_PASSWORD, 0);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
ClientStateWaitAuthVerify &
|
|
|
|
|
ClientStateWaitAuthVerify::Instance()
|
|
|
|
|
{
|
|
|
|
|
static ClientStateWaitAuthVerify state;
|
|
|
|
|
return state;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ClientStateWaitAuthVerify::ClientStateWaitAuthVerify()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ClientStateWaitAuthVerify::~ClientStateWaitAuthVerify()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
ClientStateWaitAuthVerify::Enter(boost::shared_ptr<ClientThread> /*client*/)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
ClientStateWaitAuthVerify::Exit(boost::shared_ptr<ClientThread> /*client*/)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
ClientStateWaitAuthVerify::InternalHandlePacket(boost::shared_ptr<ClientThread> client, boost::shared_ptr<NetPacket> tmpPacket)
|
|
|
|
|
{
|
|
|
|
|
if (tmpPacket->GetMsg()->present == PokerTHMessage_PR_authMessage)
|
|
|
|
|
{
|
|
|
|
|
// Check subtype.
|
|
|
|
|
AuthMessage_t *netAuth = &tmpPacket->GetMsg()->choice.authMessage;
|
|
|
|
|
if (netAuth->present == AuthMessage_PR_authServerVerification)
|
|
|
|
|
{
|
|
|
|
|
AuthServerVerification_t *netVerification = &netAuth->choice.authServerVerification;
|
2009-10-24 21:49:11 +00:00
|
|
|
string verificationStr = STL_STRING_FROM_OCTET_STRING(netVerification->serverVerification);
|
2009-10-22 22:55:19 +00:00
|
|
|
boost::shared_ptr<SessionData> tmpSession = client->GetContext().GetSessionData();
|
|
|
|
|
if (!tmpSession->AuthStep(3, verificationStr.c_str()))
|
|
|
|
|
throw ClientException(__FILE__, __LINE__, ERR_NET_INVALID_PASSWORD, 0);
|
|
|
|
|
|
|
|
|
|
client->SetState(ClientStateWaitSession::Instance());
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
throw ClientException(__FILE__, __LINE__, ERR_NET_INVALID_PASSWORD, 0);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
2007-11-16 15:24:25 +00:00
|
|
|
ClientStateWaitSession &
|
|
|
|
|
ClientStateWaitSession::Instance()
|
|
|
|
|
{
|
|
|
|
|
static ClientStateWaitSession state;
|
|
|
|
|
return state;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ClientStateWaitSession::ClientStateWaitSession()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ClientStateWaitSession::~ClientStateWaitSession()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2009-06-14 22:07:41 +00:00
|
|
|
void
|
2009-10-22 22:55:19 +00:00
|
|
|
ClientStateWaitSession::Enter(boost::shared_ptr<ClientThread> /*client*/)
|
2007-11-16 15:24:25 +00:00
|
|
|
{
|
2009-06-14 22:07:41 +00:00
|
|
|
}
|
2007-11-16 15:24:25 +00:00
|
|
|
|
2009-06-14 22:07:41 +00:00
|
|
|
void
|
|
|
|
|
ClientStateWaitSession::Exit(boost::shared_ptr<ClientThread> /*client*/)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
ClientStateWaitSession::InternalHandlePacket(boost::shared_ptr<ClientThread> client, boost::shared_ptr<NetPacket> tmpPacket)
|
|
|
|
|
{
|
2009-08-02 15:11:40 +00:00
|
|
|
if (tmpPacket->GetMsg()->present == PokerTHMessage_PR_initAckMessage)
|
2007-11-16 15:24:25 +00:00
|
|
|
{
|
|
|
|
|
// Everything is fine - we are in the lobby.
|
2009-08-02 15:11:40 +00:00
|
|
|
InitAckMessage_t *netInitAck = &tmpPacket->GetMsg()->choice.initAckMessage;
|
|
|
|
|
client->SetGuiPlayerId(netInitAck->yourPlayerId);
|
2007-11-16 15:24:25 +00:00
|
|
|
|
2009-06-14 22:07:41 +00:00
|
|
|
client->SetSessionEstablished(true);
|
|
|
|
|
client->GetCallback().SignalNetClientConnect(MSG_SOCK_SESSION_DONE);
|
|
|
|
|
client->SetState(ClientStateWaitJoin::Instance());
|
2007-11-16 15:24:25 +00:00
|
|
|
}
|
2009-08-02 15:11:40 +00:00
|
|
|
else if (tmpPacket->GetMsg()->present == PokerTHMessage_PR_avatarRequestMessage)
|
2007-11-16 15:24:25 +00:00
|
|
|
{
|
|
|
|
|
// Before letting us join the lobby, the server requests our avatar.
|
2009-08-02 15:11:40 +00:00
|
|
|
AvatarRequestMessage_t *netAvatarRequest = &tmpPacket->GetMsg()->choice.avatarRequestMessage;
|
2007-11-16 15:24:25 +00:00
|
|
|
|
2009-08-02 15:11:40 +00:00
|
|
|
// TODO compare SHA1.
|
2007-11-16 15:24:25 +00:00
|
|
|
NetPacketList tmpList;
|
2009-06-14 22:07:41 +00:00
|
|
|
int avatarError = client->GetAvatarManager().AvatarFileToNetPackets(
|
|
|
|
|
client->GetQtToolsInterface().stringFromUtf8(client->GetContext().GetAvatarFile()),
|
2009-08-02 15:11:40 +00:00
|
|
|
netAvatarRequest->requestId,
|
2007-11-16 15:24:25 +00:00
|
|
|
tmpList);
|
|
|
|
|
|
|
|
|
|
if (!avatarError)
|
2009-06-14 22:07:41 +00:00
|
|
|
client->GetSender().Send(client->GetContext().GetSessionData(), tmpList);
|
2007-11-16 15:24:25 +00:00
|
|
|
else
|
|
|
|
|
throw ClientException(__FILE__, __LINE__, avatarError, 0);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
ClientStateWaitJoin &
|
|
|
|
|
ClientStateWaitJoin::Instance()
|
|
|
|
|
{
|
|
|
|
|
static ClientStateWaitJoin state;
|
|
|
|
|
return state;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ClientStateWaitJoin::ClientStateWaitJoin()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ClientStateWaitJoin::~ClientStateWaitJoin()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2009-06-14 22:07:41 +00:00
|
|
|
void
|
|
|
|
|
ClientStateWaitJoin::Enter(boost::shared_ptr<ClientThread> /*client*/)
|
2007-11-16 15:24:25 +00:00
|
|
|
{
|
2009-06-14 22:07:41 +00:00
|
|
|
}
|
2007-11-16 15:24:25 +00:00
|
|
|
|
2009-06-14 22:07:41 +00:00
|
|
|
void
|
|
|
|
|
ClientStateWaitJoin::Exit(boost::shared_ptr<ClientThread> /*client*/)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
ClientStateWaitJoin::InternalHandlePacket(boost::shared_ptr<ClientThread> client, boost::shared_ptr<NetPacket> tmpPacket)
|
|
|
|
|
{
|
|
|
|
|
ClientContext &context = client->GetContext();
|
|
|
|
|
|
2009-08-02 15:11:40 +00:00
|
|
|
if (tmpPacket->GetMsg()->present == PokerTHMessage_PR_joinGameReplyMessage)
|
2007-11-16 15:24:25 +00:00
|
|
|
{
|
2009-08-02 15:11:40 +00:00
|
|
|
JoinGameReplyMessage_t *netJoinReply = &tmpPacket->GetMsg()->choice.joinGameReplyMessage;
|
|
|
|
|
unsigned gameId = netJoinReply->gameId;
|
|
|
|
|
if (netJoinReply->joinGameResult.present == joinGameResult_PR_joinGameAck)
|
|
|
|
|
{
|
|
|
|
|
// Successfully joined a game.
|
|
|
|
|
JoinGameAck_t *netJoinAck = &netJoinReply->joinGameResult.choice.joinGameAck;
|
|
|
|
|
client->SetGameId(gameId);
|
|
|
|
|
GameData tmpData;
|
|
|
|
|
NetPacket::GetGameData(&netJoinAck->gameInfo, tmpData);
|
|
|
|
|
client->SetGameData(tmpData);
|
2007-11-16 15:24:25 +00:00
|
|
|
|
2009-08-02 15:11:40 +00:00
|
|
|
// Player number is 0 on init. Will be set when the game starts.
|
|
|
|
|
boost::shared_ptr<PlayerData> playerData(
|
|
|
|
|
new PlayerData(client->GetGuiPlayerId(), 0, PLAYER_TYPE_HUMAN,
|
2010-03-26 21:41:35 +00:00
|
|
|
context.GetPlayerRights(), netJoinAck->areYouGameAdmin));
|
2009-08-02 15:11:40 +00:00
|
|
|
playerData->SetName(context.GetPlayerName());
|
|
|
|
|
playerData->SetAvatarFile(context.GetAvatarFile());
|
|
|
|
|
client->AddPlayerData(playerData);
|
2007-11-16 15:24:25 +00:00
|
|
|
|
2009-08-02 15:11:40 +00:00
|
|
|
client->GetCallback().SignalNetClientGameInfo(MSG_NET_GAME_CLIENT_JOIN);
|
|
|
|
|
client->SetState(ClientStateWaitGame::Instance());
|
|
|
|
|
}
|
|
|
|
|
else if (netJoinReply->joinGameResult.present == joinGameResult_PR_joinGameFailed)
|
|
|
|
|
{
|
|
|
|
|
// Failed to join a game.
|
|
|
|
|
JoinGameFailed_t *netJoinFailed = &netJoinReply->joinGameResult.choice.joinGameFailed;
|
|
|
|
|
|
|
|
|
|
int failureCode;
|
|
|
|
|
switch (netJoinFailed->joinGameFailureReason)
|
|
|
|
|
{
|
|
|
|
|
case joinGameFailureReason_invalidGame :
|
|
|
|
|
failureCode = NTF_NET_JOIN_GAME_INVALID;
|
|
|
|
|
break;
|
|
|
|
|
case joinGameFailureReason_gameIsFull :
|
|
|
|
|
failureCode = NTF_NET_JOIN_GAME_FULL;
|
|
|
|
|
break;
|
|
|
|
|
case joinGameFailureReason_gameIsRunning :
|
|
|
|
|
failureCode = NTF_NET_JOIN_ALREADY_RUNNING;
|
|
|
|
|
break;
|
|
|
|
|
case joinGameFailureReason_invalidPassword :
|
|
|
|
|
failureCode = NTF_NET_JOIN_INVALID_PASSWORD;
|
|
|
|
|
break;
|
2010-03-28 14:53:08 +00:00
|
|
|
case joinGameFailureReason_notAllowedAsGuest :
|
|
|
|
|
failureCode = NTF_NET_JOIN_GUEST_FORBIDDEN;
|
|
|
|
|
break;
|
2010-03-30 12:07:48 +00:00
|
|
|
case joinGameFailureReason_notInvited :
|
|
|
|
|
failureCode = NTF_NET_JOIN_NOT_INVITED;
|
|
|
|
|
break;
|
2009-08-02 15:11:40 +00:00
|
|
|
default :
|
|
|
|
|
failureCode = NTF_NET_INTERNAL;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
client->GetCallback().SignalNetClientNotification(failureCode);
|
|
|
|
|
}
|
2007-11-16 15:24:25 +00:00
|
|
|
}
|
2010-03-30 12:07:48 +00:00
|
|
|
else if (tmpPacket->GetMsg()->present == PokerTHMessage_PR_inviteNotifyMessage)
|
|
|
|
|
{
|
|
|
|
|
InviteNotifyMessage_t *netInvNotify = &tmpPacket->GetMsg()->choice.inviteNotifyMessage;
|
|
|
|
|
if (netInvNotify->playerIdWho == client->GetGuiPlayerId())
|
|
|
|
|
{
|
|
|
|
|
client->GetCallback().SignalSelfGameInvitation(netInvNotify->gameId, netInvNotify->playerIdByWhom);
|
|
|
|
|
}
|
|
|
|
|
}
|
2007-11-16 15:24:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
ClientStateWaitGame &
|
|
|
|
|
ClientStateWaitGame::Instance()
|
|
|
|
|
{
|
|
|
|
|
static ClientStateWaitGame state;
|
|
|
|
|
return state;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ClientStateWaitGame::ClientStateWaitGame()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ClientStateWaitGame::~ClientStateWaitGame()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2009-06-14 22:07:41 +00:00
|
|
|
void
|
|
|
|
|
ClientStateWaitGame::Enter(boost::shared_ptr<ClientThread> /*client*/)
|
2007-11-16 15:24:25 +00:00
|
|
|
{
|
2009-06-14 22:07:41 +00:00
|
|
|
}
|
2007-11-16 15:24:25 +00:00
|
|
|
|
2009-06-14 22:07:41 +00:00
|
|
|
void
|
|
|
|
|
ClientStateWaitGame::Exit(boost::shared_ptr<ClientThread> /*client*/)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
ClientStateWaitGame::InternalHandlePacket(boost::shared_ptr<ClientThread> client, boost::shared_ptr<NetPacket> tmpPacket)
|
|
|
|
|
{
|
2009-08-02 15:11:40 +00:00
|
|
|
if (tmpPacket->GetMsg()->present == PokerTHMessage_PR_startEventMessage)
|
2007-11-16 15:24:25 +00:00
|
|
|
{
|
2009-06-14 22:07:41 +00:00
|
|
|
client->SetState(ClientStateSynchronizeStart::Instance());
|
2007-11-16 15:24:25 +00:00
|
|
|
}
|
2009-08-02 15:11:40 +00:00
|
|
|
else if (tmpPacket->GetMsg()->present == PokerTHMessage_PR_gamePlayerMessage)
|
2007-11-16 15:24:25 +00:00
|
|
|
{
|
2009-08-02 15:11:40 +00:00
|
|
|
GamePlayerMessage_t *netGamePlayer = &tmpPacket->GetMsg()->choice.gamePlayerMessage;
|
|
|
|
|
// unsigned gameId = netGamePlayer->gameId;
|
|
|
|
|
if (netGamePlayer->gamePlayerNotification.present == gamePlayerNotification_PR_gamePlayerJoined)
|
2007-11-16 15:24:25 +00:00
|
|
|
{
|
2009-08-02 15:11:40 +00:00
|
|
|
// Another player joined the network game.
|
|
|
|
|
GamePlayerJoined_t *netPlayerJoined = &netGamePlayer->gamePlayerNotification.choice.gamePlayerJoined;
|
|
|
|
|
|
|
|
|
|
boost::shared_ptr<PlayerData> playerData;
|
|
|
|
|
PlayerInfo info;
|
|
|
|
|
if (client->GetCachedPlayerInfo(netPlayerJoined->playerId, info))
|
2007-11-16 15:24:25 +00:00
|
|
|
{
|
2009-08-02 15:11:40 +00:00
|
|
|
playerData.reset(
|
2010-03-26 21:41:35 +00:00
|
|
|
new PlayerData(netPlayerJoined->playerId, 0, info.ptype,
|
|
|
|
|
info.isGuest ? PLAYER_RIGHTS_GUEST : PLAYER_RIGHTS_NORMAL, netPlayerJoined->isGameAdmin));
|
2009-08-02 15:11:40 +00:00
|
|
|
playerData->SetName(info.playerName);
|
|
|
|
|
if (info.hasAvatar)
|
|
|
|
|
{
|
|
|
|
|
string avatarFile;
|
|
|
|
|
if (client->GetAvatarManager().GetAvatarFileName(info.avatar, avatarFile))
|
|
|
|
|
playerData->SetAvatarFile(client->GetQtToolsInterface().stringToUtf8(avatarFile));
|
|
|
|
|
else
|
|
|
|
|
client->RetrieveAvatarIfNeeded(netPlayerJoined->playerId, info);
|
|
|
|
|
}
|
2007-11-16 15:24:25 +00:00
|
|
|
}
|
2009-08-02 15:11:40 +00:00
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
ostringstream name;
|
|
|
|
|
name << "#" << netPlayerJoined->playerId;
|
2007-11-16 15:24:25 +00:00
|
|
|
|
2009-08-02 15:11:40 +00:00
|
|
|
// Request player info.
|
|
|
|
|
client->RequestPlayerInfo(netPlayerJoined->playerId, true);
|
|
|
|
|
// Use temporary data until the PlayerInfo request is completed.
|
|
|
|
|
playerData.reset(
|
2010-03-26 21:41:35 +00:00
|
|
|
new PlayerData(netPlayerJoined->playerId, 0, PLAYER_TYPE_HUMAN, PLAYER_RIGHTS_NORMAL, netPlayerJoined->isGameAdmin));
|
2009-08-02 15:11:40 +00:00
|
|
|
playerData->SetName(name.str());
|
|
|
|
|
}
|
|
|
|
|
client->AddPlayerData(playerData);
|
2007-11-16 15:24:25 +00:00
|
|
|
}
|
|
|
|
|
}
|
2010-03-30 13:02:43 +00:00
|
|
|
else if (tmpPacket->GetMsg()->present == PokerTHMessage_PR_inviteNotifyMessage)
|
|
|
|
|
{
|
|
|
|
|
InviteNotifyMessage_t *netInvNotify = &tmpPacket->GetMsg()->choice.inviteNotifyMessage;
|
2010-03-30 13:09:03 +00:00
|
|
|
client->GetCallback().SignalPlayerGameInvitation(
|
2010-03-30 13:02:43 +00:00
|
|
|
netInvNotify->gameId,
|
|
|
|
|
netInvNotify->playerIdWho,
|
|
|
|
|
netInvNotify->playerIdByWhom);
|
|
|
|
|
}
|
|
|
|
|
else if (tmpPacket->GetMsg()->present == PokerTHMessage_PR_rejectInvNotifyMessage)
|
|
|
|
|
{
|
|
|
|
|
RejectInvNotifyMessage_t *netRejNotify = &tmpPacket->GetMsg()->choice.rejectInvNotifyMessage;
|
2010-03-30 13:09:03 +00:00
|
|
|
client->GetCallback().SignalPlayerGameInvitation(
|
2010-03-30 13:02:43 +00:00
|
|
|
netRejNotify->gameId,
|
|
|
|
|
netRejNotify->playerId,
|
|
|
|
|
static_cast<DenyGameInvitationReason>(netRejNotify->playerRejectReason));
|
|
|
|
|
}
|
2007-11-16 15:24:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
ClientStateSynchronizeStart &
|
|
|
|
|
ClientStateSynchronizeStart::Instance()
|
|
|
|
|
{
|
|
|
|
|
static ClientStateSynchronizeStart state;
|
|
|
|
|
return state;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ClientStateSynchronizeStart::ClientStateSynchronizeStart()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ClientStateSynchronizeStart::~ClientStateSynchronizeStart()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2009-06-14 22:07:41 +00:00
|
|
|
void
|
|
|
|
|
ClientStateSynchronizeStart::Enter(boost::shared_ptr<ClientThread> client)
|
2007-11-16 15:24:25 +00:00
|
|
|
{
|
2009-06-14 22:07:41 +00:00
|
|
|
client->GetStateTimer().expires_from_now(
|
|
|
|
|
boost::posix_time::milliseconds(CLIENT_WAIT_TIMEOUT_MSEC));
|
|
|
|
|
client->GetStateTimer().async_wait(
|
|
|
|
|
boost::bind(
|
|
|
|
|
&ClientStateSynchronizeStart::TimerLoop, this, boost::asio::placeholders::error, client));
|
2007-11-16 15:24:25 +00:00
|
|
|
}
|
|
|
|
|
|
2009-06-14 22:07:41 +00:00
|
|
|
void
|
|
|
|
|
ClientStateSynchronizeStart::Exit(boost::shared_ptr<ClientThread> client)
|
2007-11-16 15:24:25 +00:00
|
|
|
{
|
2009-06-14 22:07:41 +00:00
|
|
|
client->GetStateTimer().cancel();
|
|
|
|
|
}
|
2007-11-16 15:24:25 +00:00
|
|
|
|
2009-06-14 22:07:41 +00:00
|
|
|
void
|
|
|
|
|
ClientStateSynchronizeStart::TimerLoop(const boost::system::error_code& ec, boost::shared_ptr<ClientThread> client)
|
|
|
|
|
{
|
|
|
|
|
if (!ec && &client->GetState() == this)
|
|
|
|
|
{
|
|
|
|
|
if (client->IsSynchronized())
|
|
|
|
|
{
|
|
|
|
|
// Acknowledge start.
|
2009-08-02 15:11:40 +00:00
|
|
|
boost::shared_ptr<NetPacket> startAck(new NetPacket(NetPacket::Alloc));
|
|
|
|
|
startAck->GetMsg()->present = PokerTHMessage_PR_startEventAckMessage;
|
|
|
|
|
StartEventAckMessage_t *netStartAck = &startAck->GetMsg()->choice.startEventAckMessage;
|
|
|
|
|
netStartAck->gameId = client->GetGameId();
|
|
|
|
|
|
2009-06-14 22:07:41 +00:00
|
|
|
client->GetSender().Send(client->GetContext().GetSessionData(), startAck);
|
|
|
|
|
// Unsubscribe lobby messages.
|
|
|
|
|
client->UnsubscribeLobbyMsg();
|
|
|
|
|
|
|
|
|
|
client->SetState(ClientStateWaitStart::Instance());
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
client->GetStateTimer().expires_from_now(
|
|
|
|
|
boost::posix_time::milliseconds(CLIENT_WAIT_TIMEOUT_MSEC));
|
|
|
|
|
client->GetStateTimer().async_wait(
|
|
|
|
|
boost::bind(
|
|
|
|
|
&ClientStateSynchronizeStart::TimerLoop, this, boost::asio::placeholders::error, client));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2009-06-15 22:34:07 +00:00
|
|
|
ClientStateSynchronizeStart::InternalHandlePacket(boost::shared_ptr<ClientThread> /*client*/, boost::shared_ptr<NetPacket> tmpPacket)
|
2009-06-14 22:07:41 +00:00
|
|
|
{
|
2009-08-02 15:11:40 +00:00
|
|
|
if (tmpPacket->GetMsg()->present == PokerTHMessage_PR_gameStartMessage)
|
2007-11-16 15:24:25 +00:00
|
|
|
throw ClientException(__FILE__, __LINE__, ERR_NET_START_TIMEOUT, 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
ClientStateWaitStart &
|
|
|
|
|
ClientStateWaitStart::Instance()
|
|
|
|
|
{
|
|
|
|
|
static ClientStateWaitStart state;
|
|
|
|
|
return state;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ClientStateWaitStart::ClientStateWaitStart()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ClientStateWaitStart::~ClientStateWaitStart()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2009-06-14 22:07:41 +00:00
|
|
|
void
|
|
|
|
|
ClientStateWaitStart::Enter(boost::shared_ptr<ClientThread> /*client*/)
|
2007-11-16 15:24:25 +00:00
|
|
|
{
|
2009-06-14 22:07:41 +00:00
|
|
|
}
|
2007-11-16 15:24:25 +00:00
|
|
|
|
2009-06-14 22:07:41 +00:00
|
|
|
void
|
|
|
|
|
ClientStateWaitStart::Exit(boost::shared_ptr<ClientThread> /*client*/)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
ClientStateWaitStart::InternalHandlePacket(boost::shared_ptr<ClientThread> client, boost::shared_ptr<NetPacket> tmpPacket)
|
|
|
|
|
{
|
2009-08-02 15:11:40 +00:00
|
|
|
if (tmpPacket->GetMsg()->present == PokerTHMessage_PR_gameStartMessage)
|
2007-11-16 15:24:25 +00:00
|
|
|
{
|
|
|
|
|
// Start the network game as client.
|
2009-08-02 15:11:40 +00:00
|
|
|
GameStartMessage_t *netGameStart = &tmpPacket->GetMsg()->choice.gameStartMessage;
|
2007-11-16 15:24:25 +00:00
|
|
|
|
2009-08-02 15:11:40 +00:00
|
|
|
StartData startData;
|
|
|
|
|
startData.numberOfPlayers = netGameStart->playerSeats.list.count;
|
|
|
|
|
startData.startDealerPlayerId = netGameStart->startDealerPlayerId;
|
|
|
|
|
client->SetStartData(startData);
|
2007-11-16 15:24:25 +00:00
|
|
|
|
|
|
|
|
// Set player numbers using the game start data slots.
|
2009-08-02 15:11:40 +00:00
|
|
|
NonZeroId_t **playerIds = netGameStart->playerSeats.list.array;
|
|
|
|
|
unsigned numPlayers = netGameStart->playerSeats.list.count;
|
|
|
|
|
// Request player info for players if needed.
|
|
|
|
|
if (numPlayers && playerIds && *playerIds)
|
2007-11-16 15:24:25 +00:00
|
|
|
{
|
2009-08-02 15:11:40 +00:00
|
|
|
for (unsigned i = 0; i < numPlayers; i++)
|
|
|
|
|
{
|
|
|
|
|
unsigned playerId = *playerIds[i];
|
|
|
|
|
boost::shared_ptr<PlayerData> tmpPlayer = client->GetPlayerDataByUniqueId(playerId);
|
|
|
|
|
if (!tmpPlayer.get())
|
|
|
|
|
throw ClientException(__FILE__, __LINE__, ERR_NET_UNKNOWN_PLAYER_ID, 0);
|
|
|
|
|
tmpPlayer->SetNumber(i);
|
|
|
|
|
}
|
2007-11-16 15:24:25 +00:00
|
|
|
}
|
2009-08-02 15:11:40 +00:00
|
|
|
else
|
|
|
|
|
throw ClientException(__FILE__, __LINE__, ERR_NET_INVALID_PLAYER_COUNT, 0);
|
2007-11-16 15:24:25 +00:00
|
|
|
|
2009-06-14 22:07:41 +00:00
|
|
|
client->InitGame();
|
|
|
|
|
client->GetCallback().SignalNetClientGameInfo(MSG_NET_GAME_CLIENT_START);
|
|
|
|
|
client->SetState(ClientStateWaitHand::Instance());
|
2007-11-16 15:24:25 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
ClientStateWaitHand &
|
|
|
|
|
ClientStateWaitHand::Instance()
|
|
|
|
|
{
|
|
|
|
|
static ClientStateWaitHand state;
|
|
|
|
|
return state;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ClientStateWaitHand::ClientStateWaitHand()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ClientStateWaitHand::~ClientStateWaitHand()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2009-06-14 22:07:41 +00:00
|
|
|
void
|
|
|
|
|
ClientStateWaitHand::Enter(boost::shared_ptr<ClientThread> /*client*/)
|
2007-11-16 15:24:25 +00:00
|
|
|
{
|
2009-06-14 22:07:41 +00:00
|
|
|
}
|
2007-11-16 15:24:25 +00:00
|
|
|
|
2009-06-14 22:07:41 +00:00
|
|
|
void
|
|
|
|
|
ClientStateWaitHand::Exit(boost::shared_ptr<ClientThread> /*client*/)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
ClientStateWaitHand::InternalHandlePacket(boost::shared_ptr<ClientThread> client, boost::shared_ptr<NetPacket> tmpPacket)
|
|
|
|
|
{
|
2009-08-02 15:11:40 +00:00
|
|
|
if (tmpPacket->GetMsg()->present == PokerTHMessage_PR_handStartMessage)
|
2007-11-16 15:24:25 +00:00
|
|
|
{
|
|
|
|
|
// Remove all players which left the server.
|
2009-06-14 22:07:41 +00:00
|
|
|
client->RemoveDisconnectedPlayers();
|
2009-08-02 15:11:40 +00:00
|
|
|
|
2007-11-16 15:24:25 +00:00
|
|
|
// Hand was started.
|
|
|
|
|
// These are the cards. Good luck.
|
2009-08-02 15:11:40 +00:00
|
|
|
HandStartMessage_t *netHandStart = &tmpPacket->GetMsg()->choice.handStartMessage;
|
2007-11-16 15:24:25 +00:00
|
|
|
int myCards[2];
|
2009-08-02 15:11:40 +00:00
|
|
|
myCards[0] = (int)netHandStart->yourCard1;
|
|
|
|
|
myCards[1] = (int)netHandStart->yourCard2;
|
2009-06-14 22:07:41 +00:00
|
|
|
client->GetGame()->getSeatsList()->front()->setMyCards(myCards);
|
|
|
|
|
client->GetGame()->initHand();
|
2009-08-02 15:11:40 +00:00
|
|
|
client->GetGame()->getCurrentHand()->setSmallBlind(netHandStart->smallBlind);
|
|
|
|
|
client->GetGame()->getCurrentHand()->getCurrentBeRo()->setMinimumRaise(2 * netHandStart->smallBlind);
|
2009-06-14 22:07:41 +00:00
|
|
|
client->GetGame()->startHand();
|
|
|
|
|
client->GetGui().dealHoleCards();
|
|
|
|
|
client->GetGui().refreshGameLabels(GAME_STATE_PREFLOP);
|
|
|
|
|
client->GetGui().refreshPot();
|
|
|
|
|
client->GetGui().waitForGuiUpdateDone();
|
2007-11-16 15:24:25 +00:00
|
|
|
|
2009-06-14 22:07:41 +00:00
|
|
|
client->GetCallback().SignalNetClientGameInfo(MSG_NET_GAME_CLIENT_HAND_START);
|
|
|
|
|
client->SetState(ClientStateRunHand::Instance());
|
2007-11-16 15:24:25 +00:00
|
|
|
}
|
2009-08-02 15:11:40 +00:00
|
|
|
else if (tmpPacket->GetMsg()->present == PokerTHMessage_PR_endOfGameMessage)
|
2007-11-16 15:24:25 +00:00
|
|
|
{
|
2009-06-14 22:07:41 +00:00
|
|
|
boost::shared_ptr<Game> curGame = client->GetGame();
|
2007-11-16 15:24:25 +00:00
|
|
|
if (curGame.get())
|
|
|
|
|
{
|
2009-08-02 15:11:40 +00:00
|
|
|
EndOfGameMessage_t *netEndOfGame = &tmpPacket->GetMsg()->choice.endOfGameMessage;
|
|
|
|
|
|
|
|
|
|
boost::shared_ptr<PlayerInterface> tmpPlayer = curGame->getPlayerByUniqueId(netEndOfGame->winnerPlayerId);
|
2007-11-16 15:24:25 +00:00
|
|
|
if (!tmpPlayer)
|
|
|
|
|
throw ClientException(__FILE__, __LINE__, ERR_NET_UNKNOWN_PLAYER_ID, 0);
|
2009-06-14 22:07:41 +00:00
|
|
|
client->GetGui().logPlayerWinGame(tmpPlayer->getMyName(), curGame->getMyGameID());
|
2008-05-12 10:50:19 +00:00
|
|
|
// Resubscribe Lobby messages.
|
2009-06-14 22:07:41 +00:00
|
|
|
client->ResubscribeLobbyMsg();
|
2008-05-12 10:50:19 +00:00
|
|
|
// Show Lobby dialog.
|
2009-06-14 22:07:41 +00:00
|
|
|
client->GetCallback().SignalNetClientWaitDialog();
|
|
|
|
|
client->GetCallback().SignalNetClientGameInfo(MSG_NET_GAME_CLIENT_END);
|
|
|
|
|
client->SetState(ClientStateWaitGame::Instance());
|
2007-11-16 15:24:25 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
ClientStateRunHand &
|
|
|
|
|
ClientStateRunHand::Instance()
|
|
|
|
|
{
|
|
|
|
|
static ClientStateRunHand state;
|
|
|
|
|
return state;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ClientStateRunHand::ClientStateRunHand()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ClientStateRunHand::~ClientStateRunHand()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2009-06-14 22:07:41 +00:00
|
|
|
void
|
|
|
|
|
ClientStateRunHand::Enter(boost::shared_ptr<ClientThread> /*client*/)
|
2007-11-16 15:24:25 +00:00
|
|
|
{
|
2009-06-14 22:07:41 +00:00
|
|
|
}
|
2007-11-16 15:24:25 +00:00
|
|
|
|
2009-06-14 22:07:41 +00:00
|
|
|
void
|
|
|
|
|
ClientStateRunHand::Exit(boost::shared_ptr<ClientThread> /*client*/)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
ClientStateRunHand::InternalHandlePacket(boost::shared_ptr<ClientThread> client, boost::shared_ptr<NetPacket> tmpPacket)
|
|
|
|
|
{
|
|
|
|
|
boost::shared_ptr<Game> curGame = client->GetGame();
|
2009-08-02 15:11:40 +00:00
|
|
|
if (tmpPacket->GetMsg()->present == PokerTHMessage_PR_playersActionDoneMessage)
|
2007-11-16 15:24:25 +00:00
|
|
|
{
|
2009-08-02 15:11:40 +00:00
|
|
|
PlayersActionDoneMessage_t *netActionDone = &tmpPacket->GetMsg()->choice.playersActionDoneMessage;
|
|
|
|
|
|
|
|
|
|
boost::shared_ptr<PlayerInterface> tmpPlayer = curGame->getPlayerByUniqueId(netActionDone->playerId);
|
2009-06-14 22:07:41 +00:00
|
|
|
if (!tmpPlayer)
|
|
|
|
|
throw ClientException(__FILE__, __LINE__, ERR_NET_UNKNOWN_PLAYER_ID, 0);
|
|
|
|
|
|
|
|
|
|
bool isBigBlind = false;
|
|
|
|
|
|
2009-08-02 15:11:40 +00:00
|
|
|
if (netActionDone->gameState == NetGameState_statePreflopSmallBlind)
|
2007-11-16 15:24:25 +00:00
|
|
|
{
|
2009-06-14 22:07:41 +00:00
|
|
|
curGame->getCurrentHand()->getCurrentBeRo()->setSmallBlindPositionId(tmpPlayer->getMyUniqueID());
|
|
|
|
|
tmpPlayer->setMyButton(BUTTON_SMALL_BLIND);
|
2007-11-16 15:24:25 +00:00
|
|
|
}
|
2009-08-02 15:11:40 +00:00
|
|
|
else if (netActionDone->gameState == NetGameState_statePreflopBigBlind)
|
2007-11-16 15:24:25 +00:00
|
|
|
{
|
2009-06-14 22:07:41 +00:00
|
|
|
curGame->getCurrentHand()->getCurrentBeRo()->setBigBlindPositionId(tmpPlayer->getMyUniqueID());
|
|
|
|
|
tmpPlayer->setMyButton(BUTTON_BIG_BLIND);
|
|
|
|
|
isBigBlind = true;
|
|
|
|
|
}
|
|
|
|
|
else // no blind -> log
|
|
|
|
|
{
|
2009-08-02 15:11:40 +00:00
|
|
|
if (netActionDone->playerAction)
|
2009-06-14 22:07:41 +00:00
|
|
|
{
|
2009-08-02 15:11:40 +00:00
|
|
|
assert(netActionDone->totalPlayerBet >= (long)tmpPlayer->getMySet());
|
2009-06-14 22:07:41 +00:00
|
|
|
client->GetGui().logPlayerActionMsg(
|
|
|
|
|
tmpPlayer->getMyName(),
|
2009-08-02 15:11:40 +00:00
|
|
|
netActionDone->playerAction,
|
|
|
|
|
netActionDone->totalPlayerBet - tmpPlayer->getMySet());
|
2009-06-14 22:07:41 +00:00
|
|
|
}
|
|
|
|
|
// Update last players turn only after the blinds.
|
|
|
|
|
curGame->getCurrentHand()->setLastPlayersTurn(tmpPlayer->getMyID());
|
|
|
|
|
}
|
|
|
|
|
|
2009-08-02 15:11:40 +00:00
|
|
|
tmpPlayer->setMyAction(netActionDone->playerAction);
|
|
|
|
|
tmpPlayer->setMySetAbsolute(netActionDone->totalPlayerBet);
|
|
|
|
|
tmpPlayer->setMyCash(netActionDone->playerMoney);
|
|
|
|
|
curGame->getCurrentHand()->getCurrentBeRo()->setHighestSet(netActionDone->highestSet);
|
|
|
|
|
curGame->getCurrentHand()->getCurrentBeRo()->setMinimumRaise(netActionDone->minimumRaise);
|
2009-06-14 22:07:41 +00:00
|
|
|
curGame->getCurrentHand()->getBoard()->collectSets();
|
|
|
|
|
curGame->getCurrentHand()->switchRounds();
|
|
|
|
|
|
|
|
|
|
//log blinds sets after setting bigblind-button
|
|
|
|
|
if (isBigBlind) {
|
2009-08-02 15:11:40 +00:00
|
|
|
client->GetGui().logNewBlindsSetsMsg(
|
|
|
|
|
curGame->getPlayerByUniqueId(curGame->getCurrentHand()->getCurrentBeRo()->getSmallBlindPositionId())->getMySet(),
|
|
|
|
|
curGame->getPlayerByUniqueId(curGame->getCurrentHand()->getCurrentBeRo()->getBigBlindPositionId())->getMySet(),
|
|
|
|
|
curGame->getPlayerByUniqueId(curGame->getCurrentHand()->getCurrentBeRo()->getSmallBlindPositionId())->getMyName(),
|
|
|
|
|
curGame->getPlayerByUniqueId(curGame->getCurrentHand()->getCurrentBeRo()->getBigBlindPositionId())->getMyName());
|
2009-06-14 22:07:41 +00:00
|
|
|
client->GetGui().flushLogAtHand();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Stop the timeout for the player.
|
|
|
|
|
client->GetGui().stopTimeoutAnimation(tmpPlayer->getMyID());
|
|
|
|
|
|
|
|
|
|
// Unmark last player in GUI.
|
|
|
|
|
client->GetGui().refreshGroupbox(tmpPlayer->getMyID(), 3);
|
|
|
|
|
|
|
|
|
|
// Refresh GUI
|
|
|
|
|
if (tmpPlayer->getMyID() == 0)
|
|
|
|
|
client->GetGui().disableMyButtons();
|
|
|
|
|
client->GetGui().refreshAction(tmpPlayer->getMyID(), tmpPlayer->getMyAction());
|
|
|
|
|
client->GetGui().refreshPot();
|
|
|
|
|
client->GetGui().refreshSet();
|
|
|
|
|
client->GetGui().refreshCash();
|
|
|
|
|
client->GetGui().refreshButton();
|
|
|
|
|
client->GetGui().updateMyButtonsState();
|
|
|
|
|
}
|
2009-08-02 15:11:40 +00:00
|
|
|
else if (tmpPacket->GetMsg()->present == PokerTHMessage_PR_playersTurnMessage)
|
2009-06-14 22:07:41 +00:00
|
|
|
{
|
2009-08-02 15:11:40 +00:00
|
|
|
PlayersTurnMessage_t *netPlayersTurn = &tmpPacket->GetMsg()->choice.playersTurnMessage;
|
|
|
|
|
|
|
|
|
|
boost::shared_ptr<PlayerInterface> tmpPlayer = curGame->getPlayerByUniqueId(netPlayersTurn->playerId);
|
2009-06-14 22:07:41 +00:00
|
|
|
if (!tmpPlayer)
|
|
|
|
|
throw ClientException(__FILE__, __LINE__, ERR_NET_UNKNOWN_PLAYER_ID, 0);
|
|
|
|
|
|
|
|
|
|
// Set round.
|
2009-08-02 15:11:40 +00:00
|
|
|
if (curGame->getCurrentHand()->getCurrentRound() != netPlayersTurn->gameState)
|
2009-06-14 22:07:41 +00:00
|
|
|
{
|
|
|
|
|
ResetPlayerActions(*curGame);
|
2009-08-02 15:11:40 +00:00
|
|
|
curGame->getCurrentHand()->setCurrentRound(netPlayersTurn->gameState);
|
2009-06-14 22:07:41 +00:00
|
|
|
// Refresh actions.
|
|
|
|
|
client->GetGui().refreshSet();
|
|
|
|
|
client->GetGui().refreshAction();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Next player's turn.
|
|
|
|
|
curGame->getCurrentHand()->getCurrentBeRo()->setCurrentPlayersTurnId(tmpPlayer->getMyID());
|
|
|
|
|
curGame->getCurrentHand()->getCurrentBeRo()->setPlayersTurn(tmpPlayer->getMyID());
|
|
|
|
|
|
|
|
|
|
// Mark current player in GUI.
|
|
|
|
|
int guiStatus = 2;
|
|
|
|
|
if (!tmpPlayer->getMyActiveStatus())
|
|
|
|
|
guiStatus = 0;
|
|
|
|
|
else if (tmpPlayer->getMyAction() == PLAYER_ACTION_FOLD)
|
|
|
|
|
guiStatus = 1;
|
|
|
|
|
client->GetGui().refreshGroupbox(tmpPlayer->getMyID(), guiStatus);
|
|
|
|
|
client->GetGui().refreshAction(tmpPlayer->getMyID(), PLAYER_ACTION_NONE);
|
|
|
|
|
|
|
|
|
|
// Start displaying the timeout for the player.
|
|
|
|
|
client->GetGui().startTimeoutAnimation(tmpPlayer->getMyID(), client->GetGameData().playerActionTimeoutSec);
|
|
|
|
|
|
|
|
|
|
if (tmpPlayer->getMyID() == 0) // Is this the GUI player?
|
|
|
|
|
client->GetGui().meInAction();
|
|
|
|
|
}
|
2009-08-02 15:11:40 +00:00
|
|
|
else if (tmpPacket->GetMsg()->present == PokerTHMessage_PR_dealFlopCardsMessage)
|
2009-06-14 22:07:41 +00:00
|
|
|
{
|
2009-08-02 15:11:40 +00:00
|
|
|
DealFlopCardsMessage_t *netDealFlop = &tmpPacket->GetMsg()->choice.dealFlopCardsMessage;
|
|
|
|
|
|
2009-06-14 22:07:41 +00:00
|
|
|
int tmpCards[5];
|
2009-08-02 15:11:40 +00:00
|
|
|
tmpCards[0] = static_cast<int>(netDealFlop->flopCard1);
|
|
|
|
|
tmpCards[1] = static_cast<int>(netDealFlop->flopCard2);
|
|
|
|
|
tmpCards[2] = static_cast<int>(netDealFlop->flopCard3);
|
2009-06-14 22:07:41 +00:00
|
|
|
tmpCards[3] = tmpCards[4] = 0;
|
|
|
|
|
curGame->getCurrentHand()->getBoard()->setMyCards(tmpCards);
|
|
|
|
|
curGame->getCurrentHand()->getBoard()->collectPot();
|
|
|
|
|
curGame->getCurrentHand()->setLastPlayersTurn(-1);
|
|
|
|
|
|
|
|
|
|
client->GetGui().logDealBoardCardsMsg(GAME_STATE_FLOP, tmpCards[0], tmpCards[1], tmpCards[2], tmpCards[3], tmpCards[4]);
|
|
|
|
|
client->GetGui().refreshGameLabels(GAME_STATE_FLOP);
|
|
|
|
|
client->GetGui().refreshPot();
|
|
|
|
|
client->GetGui().refreshSet();
|
|
|
|
|
client->GetGui().dealBeRoCards(1);
|
|
|
|
|
}
|
2009-08-02 15:11:40 +00:00
|
|
|
else if (tmpPacket->GetMsg()->present == PokerTHMessage_PR_dealTurnCardMessage)
|
2009-06-14 22:07:41 +00:00
|
|
|
{
|
2009-08-02 15:11:40 +00:00
|
|
|
DealTurnCardMessage_t *netDealTurn = &tmpPacket->GetMsg()->choice.dealTurnCardMessage;
|
|
|
|
|
|
2009-06-14 22:07:41 +00:00
|
|
|
int tmpCards[5];
|
|
|
|
|
curGame->getCurrentHand()->getBoard()->getMyCards(tmpCards);
|
2009-08-02 15:11:40 +00:00
|
|
|
tmpCards[3] = static_cast<int>(netDealTurn->turnCard);
|
2009-06-14 22:07:41 +00:00
|
|
|
curGame->getCurrentHand()->getBoard()->setMyCards(tmpCards);
|
|
|
|
|
curGame->getCurrentHand()->getBoard()->collectPot();
|
|
|
|
|
curGame->getCurrentHand()->setLastPlayersTurn(-1);
|
|
|
|
|
|
|
|
|
|
client->GetGui().logDealBoardCardsMsg(GAME_STATE_TURN, tmpCards[0], tmpCards[1], tmpCards[2], tmpCards[3], tmpCards[4]);
|
|
|
|
|
client->GetGui().refreshGameLabels(GAME_STATE_TURN);
|
|
|
|
|
client->GetGui().refreshPot();
|
|
|
|
|
client->GetGui().refreshSet();
|
|
|
|
|
client->GetGui().dealBeRoCards(2);
|
|
|
|
|
}
|
2009-08-02 15:11:40 +00:00
|
|
|
else if (tmpPacket->GetMsg()->present == PokerTHMessage_PR_dealRiverCardMessage)
|
2009-06-14 22:07:41 +00:00
|
|
|
{
|
2009-08-02 15:11:40 +00:00
|
|
|
DealRiverCardMessage_t *netDealRiver = &tmpPacket->GetMsg()->choice.dealRiverCardMessage;
|
|
|
|
|
|
2009-06-14 22:07:41 +00:00
|
|
|
int tmpCards[5];
|
|
|
|
|
curGame->getCurrentHand()->getBoard()->getMyCards(tmpCards);
|
2009-08-02 15:11:40 +00:00
|
|
|
tmpCards[4] = static_cast<int>(netDealRiver->riverCard);
|
2009-06-14 22:07:41 +00:00
|
|
|
curGame->getCurrentHand()->getBoard()->setMyCards(tmpCards);
|
|
|
|
|
curGame->getCurrentHand()->getBoard()->collectPot();
|
|
|
|
|
curGame->getCurrentHand()->setLastPlayersTurn(-1);
|
|
|
|
|
|
|
|
|
|
client->GetGui().logDealBoardCardsMsg(GAME_STATE_RIVER, tmpCards[0], tmpCards[1], tmpCards[2], tmpCards[3], tmpCards[4]);
|
|
|
|
|
client->GetGui().refreshGameLabels(GAME_STATE_RIVER);
|
|
|
|
|
client->GetGui().refreshPot();
|
|
|
|
|
client->GetGui().refreshSet();
|
|
|
|
|
client->GetGui().dealBeRoCards(3);
|
|
|
|
|
}
|
2009-08-02 15:11:40 +00:00
|
|
|
else if (tmpPacket->GetMsg()->present == PokerTHMessage_PR_allInShowCardsMessage)
|
2009-06-14 22:07:41 +00:00
|
|
|
{
|
2009-08-02 15:11:40 +00:00
|
|
|
AllInShowCardsMessage_t *netAllInShow = &tmpPacket->GetMsg()->choice.allInShowCardsMessage;
|
|
|
|
|
|
2009-06-14 22:07:41 +00:00
|
|
|
curGame->getCurrentHand()->setAllInCondition(true);
|
|
|
|
|
|
2009-08-02 15:11:40 +00:00
|
|
|
// Set player numbers using the game start data slots.
|
|
|
|
|
PlayerAllIn_t **allInPlayers = netAllInShow->playersAllIn.list.array;
|
|
|
|
|
unsigned numPlayers = netAllInShow->playersAllIn.list.count;
|
|
|
|
|
// Request player info for players if needed.
|
2009-08-02 21:22:05 +00:00
|
|
|
for (unsigned i = 0; i < numPlayers; i++)
|
2009-06-14 22:07:41 +00:00
|
|
|
{
|
2009-08-02 21:22:05 +00:00
|
|
|
PlayerAllIn_t *p = allInPlayers[i];
|
2007-11-16 15:24:25 +00:00
|
|
|
|
2009-08-02 21:22:05 +00:00
|
|
|
boost::shared_ptr<PlayerInterface> tmpPlayer = curGame->getPlayerByUniqueId(p->playerId);
|
|
|
|
|
if (!tmpPlayer)
|
|
|
|
|
throw ClientException(__FILE__, __LINE__, ERR_NET_UNKNOWN_PLAYER_ID, 0);
|
2009-08-02 15:11:40 +00:00
|
|
|
|
2009-08-02 21:22:05 +00:00
|
|
|
int tmpCards[2];
|
|
|
|
|
tmpCards[0] = static_cast<int>(p->allInCard1);
|
|
|
|
|
tmpCards[1] = static_cast<int>(p->allInCard2);
|
|
|
|
|
tmpPlayer->setMyCards(tmpCards);
|
2007-11-16 15:24:25 +00:00
|
|
|
}
|
2009-06-14 22:07:41 +00:00
|
|
|
client->GetGui().flipHolecardsAllIn();
|
|
|
|
|
}
|
2009-08-02 15:11:40 +00:00
|
|
|
else if (tmpPacket->GetMsg()->present == PokerTHMessage_PR_endOfHandMessage)
|
2009-06-14 22:07:41 +00:00
|
|
|
{
|
2009-08-02 15:11:40 +00:00
|
|
|
EndOfHandMessage_t *netEndHand = &tmpPacket->GetMsg()->choice.endOfHandMessage;
|
2009-06-14 22:07:41 +00:00
|
|
|
|
2009-08-02 15:11:40 +00:00
|
|
|
if (netEndHand->endOfHandType.present == endOfHandType_PR_endOfHandHideCards)
|
2007-11-16 15:24:25 +00:00
|
|
|
{
|
2009-08-02 15:11:40 +00:00
|
|
|
EndOfHandHideCards_t *hideCards = &netEndHand->endOfHandType.choice.endOfHandHideCards;
|
|
|
|
|
curGame->getCurrentHand()->getBoard()->collectPot();
|
|
|
|
|
// Reset player sets
|
|
|
|
|
ResetPlayerSets(*curGame);
|
|
|
|
|
client->GetGui().refreshPot();
|
|
|
|
|
client->GetGui().refreshSet();
|
|
|
|
|
// Synchronize with GUI.
|
|
|
|
|
client->GetGui().waitForGuiUpdateDone();
|
|
|
|
|
|
|
|
|
|
// End of Hand, but keep cards hidden.
|
|
|
|
|
boost::shared_ptr<PlayerInterface> tmpPlayer = curGame->getPlayerByUniqueId(hideCards->playerId);
|
2007-11-16 15:24:25 +00:00
|
|
|
if (!tmpPlayer)
|
|
|
|
|
throw ClientException(__FILE__, __LINE__, ERR_NET_UNKNOWN_PLAYER_ID, 0);
|
|
|
|
|
|
2009-08-02 15:11:40 +00:00
|
|
|
tmpPlayer->setMyCash(hideCards->playerMoney);
|
|
|
|
|
tmpPlayer->setLastMoneyWon(hideCards->moneyWon);
|
|
|
|
|
list<unsigned> winnerList;
|
|
|
|
|
winnerList.push_back(tmpPlayer->getMyUniqueID());
|
2007-11-16 15:24:25 +00:00
|
|
|
|
2009-08-02 15:11:40 +00:00
|
|
|
curGame->getCurrentHand()->getBoard()->setPot(0);
|
|
|
|
|
curGame->getCurrentHand()->getBoard()->setWinners(winnerList);
|
|
|
|
|
|
|
|
|
|
client->GetGui().postRiverRunAnimation1();
|
|
|
|
|
|
|
|
|
|
// Wait for next Hand.
|
|
|
|
|
client->GetCallback().SignalNetClientGameInfo(MSG_NET_GAME_SERVER_HAND_END);
|
|
|
|
|
client->SetState(ClientStateWaitHand::Instance());
|
2007-11-16 15:24:25 +00:00
|
|
|
}
|
2009-08-02 15:11:40 +00:00
|
|
|
else if (netEndHand->endOfHandType.present == endOfHandType_PR_endOfHandShowCards)
|
|
|
|
|
{
|
|
|
|
|
EndOfHandShowCards_t *showCards = &netEndHand->endOfHandType.choice.endOfHandShowCards;
|
2007-11-16 15:24:25 +00:00
|
|
|
|
2009-08-02 15:11:40 +00:00
|
|
|
curGame->getCurrentHand()->getBoard()->collectPot();
|
|
|
|
|
// Reset player sets
|
|
|
|
|
ResetPlayerSets(*curGame);
|
|
|
|
|
client->GetGui().refreshPot();
|
|
|
|
|
client->GetGui().refreshSet();
|
|
|
|
|
// Synchronize with GUI.
|
|
|
|
|
client->GetGui().waitForGuiUpdateDone();
|
2007-11-16 15:24:25 +00:00
|
|
|
|
2009-08-02 15:11:40 +00:00
|
|
|
// End of Hand, show cards.
|
|
|
|
|
list<unsigned> winnerList;
|
|
|
|
|
int highestValueOfCards = 0;
|
|
|
|
|
PlayerResult_t **playerResults = showCards->playerResults.list.array;
|
|
|
|
|
unsigned numResults = showCards->playerResults.list.count;
|
|
|
|
|
// Request player info for players if needed.
|
2009-08-02 21:22:05 +00:00
|
|
|
for (unsigned i = 0; i < numResults; i++)
|
2009-08-02 15:11:40 +00:00
|
|
|
{
|
2009-08-02 21:22:05 +00:00
|
|
|
PlayerResult_t *r = playerResults[i];
|
2009-08-02 15:11:40 +00:00
|
|
|
|
2009-08-02 21:22:05 +00:00
|
|
|
boost::shared_ptr<PlayerInterface> tmpPlayer = curGame->getPlayerByUniqueId(r->playerId);
|
|
|
|
|
if (!tmpPlayer)
|
|
|
|
|
throw ClientException(__FILE__, __LINE__, ERR_NET_UNKNOWN_PLAYER_ID, 0);
|
2009-08-02 15:11:40 +00:00
|
|
|
|
2009-08-02 21:22:05 +00:00
|
|
|
int tmpCards[2];
|
|
|
|
|
int bestHandPos[5];
|
|
|
|
|
tmpCards[0] = static_cast<int>(r->resultCard1);
|
|
|
|
|
tmpCards[1] = static_cast<int>(r->resultCard2);
|
|
|
|
|
tmpPlayer->setMyCards(tmpCards);
|
|
|
|
|
for (int num = 0; num < 5; num++)
|
|
|
|
|
bestHandPos[num] = *r->bestHandPosition.list.array[num];
|
|
|
|
|
tmpPlayer->setMyCardsValueInt(r->cardsValue);
|
|
|
|
|
tmpPlayer->setMyBestHandPosition(bestHandPos);
|
|
|
|
|
if (tmpPlayer->getMyCardsValueInt() > highestValueOfCards)
|
|
|
|
|
highestValueOfCards = tmpPlayer->getMyCardsValueInt();
|
|
|
|
|
tmpPlayer->setMyCash(r->playerMoney);
|
|
|
|
|
tmpPlayer->setLastMoneyWon(r->moneyWon);
|
|
|
|
|
if (r->moneyWon)
|
|
|
|
|
winnerList.push_back(r->playerId);
|
2009-08-02 15:11:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
curGame->getCurrentHand()->getCurrentBeRo()->setHighestCardsValue(highestValueOfCards);
|
|
|
|
|
curGame->getCurrentHand()->getBoard()->setPot(0);
|
|
|
|
|
curGame->getCurrentHand()->getBoard()->setWinners(winnerList);
|
|
|
|
|
|
|
|
|
|
client->GetGui().postRiverRunAnimation1();
|
|
|
|
|
|
|
|
|
|
// Wait for next Hand.
|
|
|
|
|
client->GetCallback().SignalNetClientGameInfo(MSG_NET_GAME_CLIENT_HAND_END);
|
|
|
|
|
client->SetState(ClientStateWaitHand::Instance());
|
|
|
|
|
}
|
2007-11-16 15:24:25 +00:00
|
|
|
}
|
|
|
|
|
// Synchronize with GUI.
|
2009-06-14 22:07:41 +00:00
|
|
|
client->GetGui().waitForGuiUpdateDone();
|
2007-11-16 15:24:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
ClientStateRunHand::ResetPlayerActions(Game &curGame)
|
|
|
|
|
{
|
|
|
|
|
// Reset player actions
|
|
|
|
|
PlayerListIterator i = curGame.getSeatsList()->begin();
|
|
|
|
|
PlayerListIterator end = curGame.getSeatsList()->end();
|
|
|
|
|
|
|
|
|
|
while (i != end)
|
|
|
|
|
{
|
|
|
|
|
int action = (*i)->getMyAction();
|
|
|
|
|
if (action != 1 && action != 6)
|
|
|
|
|
(*i)->setMyAction(0);
|
|
|
|
|
(*i)->setMySetNull();
|
|
|
|
|
++i;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
ClientStateRunHand::ResetPlayerSets(Game &curGame)
|
|
|
|
|
{
|
|
|
|
|
PlayerListIterator i = curGame.getSeatsList()->begin();
|
|
|
|
|
PlayerListIterator end = curGame.getSeatsList()->end();
|
|
|
|
|
while (i != end)
|
|
|
|
|
{
|
|
|
|
|
(*i)->setMySetNull();
|
|
|
|
|
++i;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-06-15 22:34:07 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
ClientStateFinal &
|
|
|
|
|
ClientStateFinal::Instance()
|
|
|
|
|
{
|
|
|
|
|
static ClientStateFinal state;
|
|
|
|
|
return state;
|
|
|
|
|
}
|