2011-07-02 14:38:06 +00:00
|
|
|
/*****************************************************************************
|
|
|
|
|
* PokerTH - The open source texas holdem engine *
|
|
|
|
|
* Copyright (C) 2006-2011 Felix Hammer, Florian Thauer, Lothar May *
|
|
|
|
|
* *
|
|
|
|
|
* This program is free software: you can redistribute it and/or modify *
|
|
|
|
|
* it under the terms of the GNU Affero General Public License as *
|
|
|
|
|
* published by the Free Software Foundation, either version 3 of the *
|
|
|
|
|
* License, or (at your option) any later version. *
|
|
|
|
|
* *
|
|
|
|
|
* This program is distributed in the hope that it will be useful, *
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
|
|
|
* GNU Affero General Public License for more details. *
|
|
|
|
|
* *
|
|
|
|
|
* You should have received a copy of the GNU Affero General Public License *
|
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
|
|
|
|
|
*****************************************************************************/
|
2007-11-16 15:24:25 +00:00
|
|
|
|
|
|
|
|
#include <net/serverlobbythread.h>
|
2009-05-31 19:45:20 +00:00
|
|
|
#include <net/servergame.h>
|
2009-06-18 20:16:22 +00:00
|
|
|
#include <net/serverbanmanager.h>
|
2007-11-16 15:24:25 +00:00
|
|
|
#include <net/serverexception.h>
|
2011-02-19 23:47:24 +00:00
|
|
|
#include <net/receivebuffer.h>
|
2009-05-10 22:21:20 +00:00
|
|
|
#include <net/senderhelper.h>
|
2009-08-20 11:42:13 +00:00
|
|
|
#include <net/serverircbotcallback.h>
|
2007-11-16 15:24:25 +00:00
|
|
|
#include <net/socket_msg.h>
|
2009-08-14 22:05:01 +00:00
|
|
|
#include <net/chatcleanermanager.h>
|
2010-08-01 19:23:08 +00:00
|
|
|
#include <net/net_helper.h>
|
2009-09-19 20:28:30 +00:00
|
|
|
#include <db/serverdbinterface.h>
|
|
|
|
|
#ifdef POKERTH_OFFICIAL_SERVER
|
2011-02-11 20:02:08 +00:00
|
|
|
#include <dbclosed/serverdbfactoryinternal.h>
|
2009-09-19 20:28:30 +00:00
|
|
|
#else
|
2011-02-11 20:02:08 +00:00
|
|
|
#include <db/serverdbfactorygeneric.h>
|
2009-09-19 20:28:30 +00:00
|
|
|
#endif
|
2007-11-16 15:24:25 +00:00
|
|
|
#include <core/avatarmanager.h>
|
|
|
|
|
#include <core/loghelper.h>
|
2008-04-21 22:27:15 +00:00
|
|
|
#include <core/openssl_wrapper.h>
|
2009-08-14 22:05:01 +00:00
|
|
|
#include <configfile.h>
|
2011-08-28 17:14:03 +00:00
|
|
|
#include <playerinterface.h>
|
2007-11-16 15:24:25 +00:00
|
|
|
|
|
|
|
|
#include <fstream>
|
2009-04-10 21:04:08 +00:00
|
|
|
#include <sstream>
|
2007-11-16 15:24:25 +00:00
|
|
|
#include <algorithm>
|
2009-11-15 08:52:17 +00:00
|
|
|
#include <cctype>
|
2007-11-16 15:24:25 +00:00
|
|
|
#include <boost/lambda/lambda.hpp>
|
|
|
|
|
#include <boost/filesystem.hpp>
|
|
|
|
|
#include <boost/bind.hpp>
|
2011-03-07 20:54:55 +00:00
|
|
|
#include <boost/foreach.hpp>
|
2011-02-09 22:09:29 +00:00
|
|
|
#include <boost/uuid/uuid.hpp>
|
2011-10-12 08:37:22 +00:00
|
|
|
#include <boost/algorithm/string.hpp>
|
2009-10-11 09:20:17 +00:00
|
|
|
#include <gsasl.h>
|
2007-11-16 15:24:25 +00:00
|
|
|
|
2011-03-07 20:54:55 +00:00
|
|
|
#define SERVER_MAX_NUM_LOBBY_SESSIONS 512 // Maximum number of idle users in lobby.
|
|
|
|
|
#define SERVER_MAX_NUM_TOTAL_SESSIONS 2000 // Total maximum of sessions, fitting a 2048 handle limit
|
2009-05-10 14:57:51 +00:00
|
|
|
|
2008-03-06 15:27:31 +00:00
|
|
|
#define SERVER_SAVE_STATISTICS_INTERVAL_SEC 60
|
2009-05-10 14:57:51 +00:00
|
|
|
#define SERVER_CHECK_SESSION_TIMEOUTS_INTERVAL_MSEC 500
|
2009-05-31 19:11:59 +00:00
|
|
|
#define SERVER_REMOVE_GAME_INTERVAL_MSEC 500
|
2009-05-10 14:57:51 +00:00
|
|
|
#define SERVER_REMOVE_PLAYER_INTERVAL_MSEC 100
|
2009-12-23 09:53:01 +00:00
|
|
|
#define SERVER_UPDATE_LOGIN_LOCK_INTERVAL_MSEC 1000
|
2009-06-01 19:49:16 +00:00
|
|
|
#define SERVER_PROCESS_SEND_INTERVAL_MSEC 10
|
2009-05-10 14:57:51 +00:00
|
|
|
|
2010-09-04 23:00:39 +00:00
|
|
|
#define SERVER_INIT_LOGIN_CLIENT_LOCK_SEC NetHelper::GetLoginLockSec()
|
2008-03-04 23:47:45 +00:00
|
|
|
|
2009-11-15 09:07:43 +00:00
|
|
|
#define SERVER_INIT_SESSION_TIMEOUT_SEC 60
|
2008-03-06 15:27:31 +00:00
|
|
|
#define SERVER_TIMEOUT_WARNING_REMAINING_SEC 60
|
2011-12-16 22:39:24 +00:00
|
|
|
#define SERVER_SESSION_ACTIVITY_TIMEOUT_SEC 1800 // 30 min, MUST be > SERVER_TIMEOUT_WARNING_REMAINING_SEC
|
2008-03-09 23:32:45 +00:00
|
|
|
#define SERVER_SESSION_FORCED_TIMEOUT_SEC 86400 // 1 day, should be quite large.
|
2007-11-16 15:24:25 +00:00
|
|
|
|
2011-02-06 14:56:08 +00:00
|
|
|
#define SERVER_ADDRESS_LOCALHOST_STR_V4 "127.0.0.1"
|
|
|
|
|
#define SERVER_ADDRESS_LOCALHOST_STR_V4V6 "::ffff:127.0.0.1"
|
2010-11-14 01:11:47 +00:00
|
|
|
#define SERVER_ADDRESS_LOCALHOST_STR "::1"
|
|
|
|
|
|
2008-03-06 15:27:31 +00:00
|
|
|
#define SERVER_STATISTICS_FILE_NAME "server_statistics.log"
|
|
|
|
|
#define SERVER_STATISTICS_STR_TOTAL_PLAYERS "TotalNumPlayersLoggedIn"
|
|
|
|
|
#define SERVER_STATISTICS_STR_TOTAL_GAMES "TotalNumGamesCreated"
|
|
|
|
|
#define SERVER_STATISTICS_STR_MAX_GAMES "MaxGamesOpen"
|
|
|
|
|
#define SERVER_STATISTICS_STR_MAX_PLAYERS "MaxPlayersLoggedIn"
|
2008-04-01 21:44:05 +00:00
|
|
|
#define SERVER_STATISTICS_STR_CUR_GAMES "CurGamesOpen"
|
|
|
|
|
#define SERVER_STATISTICS_STR_CUR_PLAYERS "CurPlayersLoggedIn"
|
2007-11-16 15:24:25 +00:00
|
|
|
|
|
|
|
|
using namespace std;
|
2009-05-04 21:11:29 +00:00
|
|
|
using boost::asio::ip::tcp;
|
2007-11-16 15:24:25 +00:00
|
|
|
|
|
|
|
|
|
2011-02-19 23:47:24 +00:00
|
|
|
class InternalServerCallback : public SessionDataCallback, public ChatCleanerCallback, public ServerDBCallback
|
2007-11-16 15:24:25 +00:00
|
|
|
{
|
|
|
|
|
public:
|
2009-09-19 20:28:30 +00:00
|
|
|
InternalServerCallback(ServerLobbyThread &server) : m_server(server) {}
|
|
|
|
|
virtual ~InternalServerCallback() {}
|
2007-11-16 15:24:25 +00:00
|
|
|
|
2011-02-19 23:47:24 +00:00
|
|
|
virtual void CloseSession(boost::shared_ptr<SessionData> session) {
|
2011-12-11 14:54:17 +00:00
|
|
|
m_server.CloseSession(session);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
virtual void SessionError(boost::shared_ptr<SessionData> session, int errorCode) {
|
|
|
|
|
m_server.SessionError(session, errorCode);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
virtual void SessionTimeoutWarning(boost::shared_ptr<SessionData> session, unsigned remainingSec) {
|
|
|
|
|
m_server.SessionTimeoutWarning(session, remainingSec);
|
2007-11-16 15:24:25 +00:00
|
|
|
}
|
2011-02-19 23:47:24 +00:00
|
|
|
|
|
|
|
|
virtual void HandlePacket(boost::shared_ptr<SessionData> session, boost::shared_ptr<NetPacket> packet) {
|
|
|
|
|
m_server.DispatchPacket(session, packet);
|
2009-01-11 20:12:26 +00:00
|
|
|
}
|
2010-07-14 16:13:18 +00:00
|
|
|
|
2011-02-11 20:02:08 +00:00
|
|
|
virtual void SignalChatBotMessage(const string &msg) {
|
2009-08-17 09:45:06 +00:00
|
|
|
m_server.SendChatBotMsg(msg);
|
|
|
|
|
}
|
2007-11-16 15:24:25 +00:00
|
|
|
|
2011-02-11 20:02:08 +00:00
|
|
|
virtual void SignalChatBotMessage(unsigned gameId, const std::string &msg) {
|
2011-01-30 18:28:44 +00:00
|
|
|
m_server.SendChatBotMsg(gameId, msg);
|
|
|
|
|
}
|
|
|
|
|
|
2011-02-11 20:02:08 +00:00
|
|
|
virtual void SignalKickPlayer(unsigned playerId) {
|
2010-07-14 16:13:18 +00:00
|
|
|
m_server.RemovePlayer(playerId, ERR_NET_PLAYER_KICKED);
|
|
|
|
|
}
|
|
|
|
|
|
2011-02-11 20:02:08 +00:00
|
|
|
virtual void SignalBanPlayer(unsigned playerId) {
|
2010-07-14 17:20:51 +00:00
|
|
|
string playerName(m_server.GetPlayerNameFromId(playerId));
|
2011-02-11 20:02:08 +00:00
|
|
|
if (!playerName.empty()) {
|
2010-07-14 17:55:49 +00:00
|
|
|
m_server.GetBanManager().BanPlayerName(playerName, 1);
|
2010-07-14 17:20:51 +00:00
|
|
|
m_server.RemovePlayer(playerId, ERR_NET_PLAYER_KICKED);
|
|
|
|
|
}
|
2010-07-14 16:13:18 +00:00
|
|
|
}
|
|
|
|
|
|
2012-01-08 13:02:29 +00:00
|
|
|
virtual void SignalMutePlayer(unsigned playerId) {
|
|
|
|
|
m_server.MutePlayerInGame(playerId);
|
|
|
|
|
}
|
|
|
|
|
|
2011-02-11 20:02:08 +00:00
|
|
|
virtual void ConnectSuccess() {
|
2009-10-24 21:49:11 +00:00
|
|
|
LOG_MSG("Successfully connected to database.");
|
2009-09-19 20:28:30 +00:00
|
|
|
}
|
|
|
|
|
|
2011-02-11 20:02:08 +00:00
|
|
|
virtual void ConnectFailed(const string &error) {
|
2009-10-24 21:49:11 +00:00
|
|
|
LOG_ERROR("DB connect error: " << error);
|
2009-10-03 17:03:51 +00:00
|
|
|
}
|
|
|
|
|
|
2011-02-11 20:02:08 +00:00
|
|
|
virtual void QueryError(const std::string &error) {
|
2009-10-24 21:49:11 +00:00
|
|
|
LOG_ERROR("DB query error: " << error);
|
2009-09-19 20:28:30 +00:00
|
|
|
}
|
|
|
|
|
|
2011-02-11 20:02:08 +00:00
|
|
|
virtual void PlayerLoginSuccess(unsigned requestId, const DBPlayerData &dbPlayerData) {
|
2010-04-01 16:20:57 +00:00
|
|
|
m_server.UserValid(requestId, dbPlayerData);
|
2009-09-24 20:10:40 +00:00
|
|
|
}
|
|
|
|
|
|
2011-02-11 20:02:08 +00:00
|
|
|
virtual void PlayerLoginFailed(unsigned requestId) {
|
2009-10-11 12:07:56 +00:00
|
|
|
m_server.UserInvalid(requestId);
|
2009-09-24 20:10:40 +00:00
|
|
|
}
|
|
|
|
|
|
2011-02-11 20:02:08 +00:00
|
|
|
virtual void PlayerLoginBlocked(unsigned requestId) {
|
2010-07-14 14:30:16 +00:00
|
|
|
m_server.UserBlocked(requestId);
|
|
|
|
|
}
|
|
|
|
|
|
2011-02-11 20:02:08 +00:00
|
|
|
virtual void AvatarIsBlacklisted(unsigned requestId) {
|
2011-01-09 00:22:00 +00:00
|
|
|
m_server.AvatarBlacklisted(requestId);
|
|
|
|
|
}
|
|
|
|
|
|
2011-02-11 20:02:08 +00:00
|
|
|
virtual void AvatarIsOK(unsigned requestId) {
|
2011-01-09 00:22:00 +00:00
|
|
|
m_server.AvatarOK(requestId);
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-20 22:38:03 +00:00
|
|
|
virtual void CreateGameSuccess(unsigned /*requestId*/) {
|
|
|
|
|
// Nothing to do.
|
2009-09-19 20:28:30 +00:00
|
|
|
}
|
|
|
|
|
|
2011-02-11 20:02:08 +00:00
|
|
|
virtual void CreateGameFailed(unsigned requestId) {
|
2009-10-24 21:49:11 +00:00
|
|
|
// TODO maybe handle request id.
|
|
|
|
|
LOG_ERROR("DB create game failed for request " << requestId);
|
2009-09-19 20:28:30 +00:00
|
|
|
}
|
|
|
|
|
|
2011-02-11 20:02:08 +00:00
|
|
|
virtual void ReportAvatarSuccess(unsigned requestId, unsigned replyId) {
|
2010-12-24 16:46:49 +00:00
|
|
|
m_server.SendReportAvatarResult(requestId, replyId, true);
|
|
|
|
|
}
|
|
|
|
|
|
2011-02-11 20:02:08 +00:00
|
|
|
virtual void ReportAvatarFailed(unsigned requestId, unsigned replyId) {
|
2010-12-24 16:46:49 +00:00
|
|
|
m_server.SendReportAvatarResult(requestId, replyId, false);
|
|
|
|
|
}
|
|
|
|
|
|
2012-04-08 16:54:31 +00:00
|
|
|
virtual void ReportGameSuccess(unsigned requestId, unsigned replyId) {
|
|
|
|
|
// TODO
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
virtual void ReportGameFailed(unsigned requestId, unsigned replyId) {
|
|
|
|
|
// TODO
|
|
|
|
|
}
|
|
|
|
|
|
2007-11-16 15:24:25 +00:00
|
|
|
private:
|
|
|
|
|
ServerLobbyThread &m_server;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
2011-01-03 18:41:28 +00:00
|
|
|
ServerLobbyThread::ServerLobbyThread(GuiInterface &gui, ServerMode mode, ServerIrcBotCallback &ircBotCb, ConfigFile &serverConfig,
|
2009-11-08 09:48:01 +00:00
|
|
|
AvatarManager &avatarManager, boost::shared_ptr<boost::asio::io_service> ioService)
|
2011-02-11 20:02:08 +00:00
|
|
|
: m_ioService(ioService), m_authContext(NULL), m_gui(gui), m_ircBotCb(ircBotCb), m_avatarManager(avatarManager),
|
|
|
|
|
m_mode(mode), m_serverConfig(serverConfig), m_curGameId(0), m_curUniquePlayerId(0), m_curSessionId(INVALID_SESSION + 1),
|
2011-12-11 17:12:26 +00:00
|
|
|
m_statDataChanged(false), m_removeGameTimer(*ioService),
|
2011-02-11 20:02:08 +00:00
|
|
|
m_saveStatisticsTimer(*ioService), m_loginLockTimer(*ioService),
|
|
|
|
|
m_startTime(boost::posix_time::second_clock::local_time())
|
2007-11-16 15:24:25 +00:00
|
|
|
{
|
2009-09-19 20:28:30 +00:00
|
|
|
m_internalServerCallback.reset(new InternalServerCallback(*this));
|
2011-02-19 23:47:24 +00:00
|
|
|
m_sender.reset(new SenderHelper(m_ioService));
|
2009-06-18 21:32:01 +00:00
|
|
|
m_banManager.reset(new ServerBanManager(m_ioService));
|
2009-09-19 20:28:30 +00:00
|
|
|
m_chatCleanerManager.reset(new ChatCleanerManager(*m_internalServerCallback, m_ioService));
|
|
|
|
|
DBFactory dbFactory;
|
|
|
|
|
m_database = dbFactory.CreateServerDBObject(*m_internalServerCallback, m_ioService);
|
2007-11-16 15:24:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ServerLobbyThread::~ServerLobbyThread()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2009-11-08 09:48:01 +00:00
|
|
|
ServerLobbyThread::Init(const string &logDir)
|
2007-11-16 15:24:25 +00:00
|
|
|
{
|
|
|
|
|
// Read previous server statistics.
|
2011-02-11 20:02:08 +00:00
|
|
|
if (!logDir.empty()) {
|
2007-11-16 15:24:25 +00:00
|
|
|
boost::filesystem::path logPath(logDir);
|
2011-02-11 20:02:08 +00:00
|
|
|
if (!logDir.empty()) {
|
2007-11-16 15:24:25 +00:00
|
|
|
logPath /= SERVER_STATISTICS_FILE_NAME;
|
|
|
|
|
m_statisticsFileName = logPath.directory_string();
|
|
|
|
|
ReadStatisticsFile();
|
|
|
|
|
}
|
|
|
|
|
}
|
2010-08-28 10:50:17 +00:00
|
|
|
m_database->Init(
|
2011-01-03 18:41:28 +00:00
|
|
|
m_serverConfig.readConfigString("DBServerAddress"),
|
|
|
|
|
m_serverConfig.readConfigString("DBServerUser"),
|
|
|
|
|
m_serverConfig.readConfigString("DBServerPassword"),
|
|
|
|
|
m_serverConfig.readConfigString("DBServerDatabaseName"),
|
|
|
|
|
m_serverConfig.readConfigString("DBServerEncryptionKey"));
|
2010-09-05 00:15:25 +00:00
|
|
|
|
2011-01-03 18:41:28 +00:00
|
|
|
GetBanManager().InitGameNameBadWordList(m_serverConfig.readConfigStringList("GameNameBadWordList"));
|
2007-11-16 15:24:25 +00:00
|
|
|
}
|
|
|
|
|
|
2009-06-01 19:49:16 +00:00
|
|
|
void
|
|
|
|
|
ServerLobbyThread::SignalTermination()
|
|
|
|
|
{
|
|
|
|
|
Thread::SignalTermination();
|
|
|
|
|
m_ioService->stop();
|
|
|
|
|
}
|
|
|
|
|
|
2007-11-16 15:24:25 +00:00
|
|
|
void
|
2009-05-04 21:11:29 +00:00
|
|
|
ServerLobbyThread::AddConnection(boost::shared_ptr<tcp::socket> sock)
|
2007-11-16 15:24:25 +00:00
|
|
|
{
|
2009-05-10 14:57:51 +00:00
|
|
|
// Create a new session.
|
2011-12-11 14:54:17 +00:00
|
|
|
boost::shared_ptr<SessionData> sessionData(new SessionData(sock, m_curSessionId++, *m_internalServerCallback, GetIOService()));
|
2009-05-10 14:57:51 +00:00
|
|
|
m_sessionManager.AddSession(sessionData);
|
|
|
|
|
|
|
|
|
|
LOG_VERBOSE("Accepted connection - session #" << sessionData->GetId() << ".");
|
|
|
|
|
|
2011-12-11 14:54:17 +00:00
|
|
|
sessionData->StartTimerInitTimeout(SERVER_INIT_SESSION_TIMEOUT_SEC);
|
|
|
|
|
sessionData->StartTimerGlobalTimeout(SERVER_SESSION_FORCED_TIMEOUT_SEC);
|
|
|
|
|
sessionData->StartTimerActivityTimeout(SERVER_SESSION_ACTIVITY_TIMEOUT_SEC, SERVER_TIMEOUT_WARNING_REMAINING_SEC);
|
|
|
|
|
|
2009-05-10 14:57:51 +00:00
|
|
|
bool hasClientIp = false;
|
2011-03-07 20:54:55 +00:00
|
|
|
unsigned numLobbySessions = m_sessionManager.GetRawSessionCount();
|
|
|
|
|
unsigned numGameSessions = m_gameSessionManager.GetRawSessionCount();
|
|
|
|
|
if (numLobbySessions <= SERVER_MAX_NUM_LOBBY_SESSIONS
|
|
|
|
|
&& numLobbySessions + numGameSessions <= SERVER_MAX_NUM_TOTAL_SESSIONS) {
|
2009-05-10 14:57:51 +00:00
|
|
|
boost::system::error_code errCode;
|
|
|
|
|
tcp::endpoint clientEndpoint = sock->remote_endpoint(errCode);
|
2011-02-11 20:02:08 +00:00
|
|
|
if (!errCode) {
|
2009-05-10 14:57:51 +00:00
|
|
|
string ipAddress = clientEndpoint.address().to_string(errCode);
|
2011-02-11 20:02:08 +00:00
|
|
|
if (!errCode && !ipAddress.empty()) {
|
2009-05-10 14:57:51 +00:00
|
|
|
sessionData->SetClientAddr(ipAddress);
|
|
|
|
|
hasClientIp = true;
|
2009-11-07 23:27:08 +00:00
|
|
|
|
|
|
|
|
boost::shared_ptr<NetPacket> packet(new NetPacket(NetPacket::Alloc));
|
|
|
|
|
packet->GetMsg()->present = PokerTHMessage_PR_announceMessage;
|
|
|
|
|
AnnounceMessage_t *netAnnounce = &packet->GetMsg()->choice.announceMessage;
|
|
|
|
|
netAnnounce->protocolVersion.major = NET_VERSION_MAJOR;
|
|
|
|
|
netAnnounce->protocolVersion.minor = NET_VERSION_MINOR;
|
|
|
|
|
netAnnounce->latestGameVersion.major = POKERTH_VERSION_MAJOR;
|
|
|
|
|
netAnnounce->latestGameVersion.minor = POKERTH_VERSION_MINOR;
|
|
|
|
|
netAnnounce->latestBetaRevision = POKERTH_BETA_REVISION;
|
2011-02-11 20:02:08 +00:00
|
|
|
switch (GetServerMode()) {
|
|
|
|
|
case SERVER_MODE_LAN:
|
|
|
|
|
netAnnounce->serverType = serverType_serverTypeLAN;
|
|
|
|
|
break;
|
|
|
|
|
case SERVER_MODE_INTERNET_NOAUTH:
|
|
|
|
|
netAnnounce->serverType = serverType_serverTypeInternetNoAuth;
|
|
|
|
|
break;
|
|
|
|
|
case SERVER_MODE_INTERNET_AUTH:
|
|
|
|
|
netAnnounce->serverType = serverType_serverTypeInternetAuth;
|
|
|
|
|
break;
|
2009-11-08 09:48:01 +00:00
|
|
|
}
|
2011-02-13 17:24:40 +00:00
|
|
|
{
|
|
|
|
|
boost::mutex::scoped_lock lock(m_statMutex);
|
|
|
|
|
netAnnounce->numPlayersOnServer = m_statData.numberOfPlayersOnServer;
|
|
|
|
|
}
|
2009-11-07 23:27:08 +00:00
|
|
|
GetSender().Send(sessionData, packet);
|
2011-02-19 23:47:24 +00:00
|
|
|
sessionData->GetReceiveBuffer().StartAsyncRead(sessionData);
|
2009-05-10 14:57:51 +00:00
|
|
|
}
|
|
|
|
|
}
|
2011-02-11 20:02:08 +00:00
|
|
|
if (!hasClientIp) {
|
2009-05-10 14:57:51 +00:00
|
|
|
// We do not accept sessions if we cannot
|
|
|
|
|
// retrieve the client address.
|
2011-03-10 20:55:46 +00:00
|
|
|
SessionError(sessionData, ERR_NET_INVALID_SESSION);
|
2009-05-10 14:57:51 +00:00
|
|
|
}
|
2011-02-11 20:02:08 +00:00
|
|
|
} else {
|
2009-05-10 14:57:51 +00:00
|
|
|
// Server is full.
|
|
|
|
|
// Gracefully close this session.
|
2011-03-10 20:55:46 +00:00
|
|
|
SessionError(sessionData, ERR_NET_SERVER_FULL);
|
2009-05-10 14:57:51 +00:00
|
|
|
}
|
2007-11-16 15:24:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2011-03-10 21:53:25 +00:00
|
|
|
ServerLobbyThread::ReAddSession(boost::shared_ptr<SessionData> session, int reason, unsigned gameId)
|
2007-11-16 15:24:25 +00:00
|
|
|
{
|
2011-03-10 20:55:46 +00:00
|
|
|
if (session && session->GetPlayerData()) {
|
2009-08-02 15:11:40 +00:00
|
|
|
boost::shared_ptr<NetPacket> packet(new NetPacket(NetPacket::Alloc));
|
|
|
|
|
packet->GetMsg()->present = PokerTHMessage_PR_gamePlayerMessage;
|
|
|
|
|
GamePlayerMessage_t *netPlayerMsg = &packet->GetMsg()->choice.gamePlayerMessage;
|
2011-03-10 21:53:25 +00:00
|
|
|
netPlayerMsg->gameId = gameId;
|
2009-08-02 15:11:40 +00:00
|
|
|
netPlayerMsg->gamePlayerNotification.present = gamePlayerNotification_PR_removedFromGame;
|
|
|
|
|
RemovedFromGame_t *removed = &netPlayerMsg->gamePlayerNotification.choice.removedFromGame;
|
|
|
|
|
|
2011-02-11 20:02:08 +00:00
|
|
|
switch (reason) {
|
|
|
|
|
case NTF_NET_REMOVED_GAME_FULL :
|
|
|
|
|
removed->removedFromGameReason = removedFromGameReason_gameIsFull;
|
|
|
|
|
break;
|
|
|
|
|
case NTF_NET_REMOVED_ALREADY_RUNNING :
|
|
|
|
|
removed->removedFromGameReason = removedFromGameReason_gameIsRunning;
|
|
|
|
|
break;
|
|
|
|
|
case NTF_NET_REMOVED_KICKED :
|
|
|
|
|
removed->removedFromGameReason = removedFromGameReason_kickedFromGame;
|
|
|
|
|
break;
|
|
|
|
|
case NTF_NET_REMOVED_TIMEOUT :
|
|
|
|
|
removed->removedFromGameReason = removedFromGameReason_gameTimeout;
|
|
|
|
|
break;
|
|
|
|
|
case NTF_NET_REMOVED_START_FAILED :
|
|
|
|
|
removed->removedFromGameReason = removedFromGameReason_removedStartFailed;
|
|
|
|
|
break;
|
|
|
|
|
default :
|
|
|
|
|
removed->removedFromGameReason = removedFromGameReason_removedOnRequest;
|
|
|
|
|
break;
|
2009-08-02 15:11:40 +00:00
|
|
|
}
|
2011-03-10 20:55:46 +00:00
|
|
|
GetSender().Send(session, packet);
|
2007-11-16 15:24:25 +00:00
|
|
|
|
2009-06-01 19:49:16 +00:00
|
|
|
HandleReAddedSession(session);
|
|
|
|
|
}
|
2007-11-16 15:24:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2011-03-10 21:53:25 +00:00
|
|
|
ServerLobbyThread::MoveSessionToGame(boost::shared_ptr<ServerGame> game, boost::shared_ptr<SessionData> session, bool autoLeave)
|
2007-11-16 15:24:25 +00:00
|
|
|
{
|
|
|
|
|
// Remove session from the lobby.
|
2011-03-10 20:55:46 +00:00
|
|
|
m_sessionManager.RemoveSession(session->GetId());
|
2007-11-16 15:24:25 +00:00
|
|
|
// Session is now in game state.
|
2011-03-10 20:55:46 +00:00
|
|
|
session->SetState(SessionData::Game);
|
2007-11-16 15:24:25 +00:00
|
|
|
// Store it in the list of game sessions.
|
|
|
|
|
m_gameSessionManager.AddSession(session);
|
2009-05-31 11:00:33 +00:00
|
|
|
// Set the game id of the session.
|
2011-03-10 21:53:25 +00:00
|
|
|
session->SetGame(game);
|
2009-06-20 12:14:06 +00:00
|
|
|
// Add session to the game.
|
2011-03-10 21:53:25 +00:00
|
|
|
game->AddSession(session);
|
2011-02-06 13:17:07 +00:00
|
|
|
// Optionally enable auto leave after game finish.
|
|
|
|
|
if (autoLeave)
|
2011-03-10 21:53:25 +00:00
|
|
|
game->SetPlayerAutoLeaveOnFinish(session->GetPlayerData()->GetUniqueId());
|
2007-11-16 15:24:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2011-03-10 20:55:46 +00:00
|
|
|
ServerLobbyThread::CloseSession(boost::shared_ptr<SessionData> session)
|
2007-11-16 15:24:25 +00:00
|
|
|
{
|
2011-03-10 20:55:46 +00:00
|
|
|
if (session && session->GetState() != SessionData::Closed) { // Make this call reentrant.
|
|
|
|
|
LOG_VERBOSE("Closing session #" << session->GetId() << ".");
|
2011-12-11 14:54:17 +00:00
|
|
|
|
2011-03-10 20:55:46 +00:00
|
|
|
session->SetState(SessionData::Closed);
|
2008-03-19 23:39:59 +00:00
|
|
|
|
2011-12-11 14:54:17 +00:00
|
|
|
boost::shared_ptr<ServerGame> tmpGame = session->GetGame();
|
|
|
|
|
if (tmpGame) {
|
|
|
|
|
tmpGame->RemoveSession(session, NTF_NET_INTERNAL);
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-10 20:55:46 +00:00
|
|
|
m_sessionManager.RemoveSession(session->GetId());
|
|
|
|
|
m_gameSessionManager.RemoveSession(session->GetId());
|
2007-11-16 15:24:25 +00:00
|
|
|
|
2011-03-10 20:55:46 +00:00
|
|
|
if (session->GetPlayerData())
|
|
|
|
|
NotifyPlayerLeftLobby(session->GetPlayerData()->GetUniqueId());
|
2009-07-22 20:22:14 +00:00
|
|
|
// Update stats (if needed).
|
|
|
|
|
UpdateStatisticsNumberOfPlayers();
|
2011-03-10 21:53:25 +00:00
|
|
|
session->SetGame(boost::shared_ptr<ServerGame>());
|
2011-12-17 10:29:56 +00:00
|
|
|
// Ignore error when shutting down the socket.
|
|
|
|
|
boost::system::error_code ec;
|
|
|
|
|
session->GetAsioSocket()->shutdown(boost::asio::ip::tcp::socket::shutdown_receive, ec);
|
2011-12-11 14:54:17 +00:00
|
|
|
// Close this session after send.
|
|
|
|
|
GetSender().SetCloseAfterSend(session);
|
|
|
|
|
// Cancel all timers of the session.
|
|
|
|
|
session->CancelTimers();
|
2009-07-22 20:22:14 +00:00
|
|
|
}
|
2007-11-16 15:24:25 +00:00
|
|
|
}
|
|
|
|
|
|
2008-05-11 21:41:30 +00:00
|
|
|
void
|
2011-03-10 20:55:46 +00:00
|
|
|
ServerLobbyThread::ResubscribeLobbyMsg(boost::shared_ptr<SessionData> session)
|
2008-05-11 21:41:30 +00:00
|
|
|
{
|
2009-06-01 19:49:16 +00:00
|
|
|
InternalResubscribeMsg(session);
|
2008-05-11 21:41:30 +00:00
|
|
|
}
|
|
|
|
|
|
2009-08-15 22:20:19 +00:00
|
|
|
void
|
|
|
|
|
ServerLobbyThread::NotifyPlayerJoinedLobby(unsigned playerId)
|
|
|
|
|
{
|
|
|
|
|
boost::shared_ptr<NetPacket> notify = CreateNetPacketPlayerListNew(playerId);
|
|
|
|
|
m_sessionManager.SendLobbyMsgToAllSessions(GetSender(), notify, SessionData::Established);
|
|
|
|
|
m_gameSessionManager.SendLobbyMsgToAllSessions(GetSender(), notify, SessionData::Game);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
ServerLobbyThread::NotifyPlayerLeftLobby(unsigned playerId)
|
|
|
|
|
{
|
|
|
|
|
boost::shared_ptr<NetPacket> notify = CreateNetPacketPlayerListLeft(playerId);
|
|
|
|
|
m_sessionManager.SendLobbyMsgToAllSessions(GetSender(), notify, SessionData::Established);
|
|
|
|
|
m_gameSessionManager.SendLobbyMsgToAllSessions(GetSender(), notify, SessionData::Game);
|
|
|
|
|
}
|
|
|
|
|
|
2007-11-16 15:24:25 +00:00
|
|
|
void
|
|
|
|
|
ServerLobbyThread::NotifyPlayerJoinedGame(unsigned gameId, unsigned playerId)
|
|
|
|
|
{
|
|
|
|
|
// Send notification to players in lobby.
|
2009-08-02 15:11:40 +00:00
|
|
|
boost::shared_ptr<NetPacket> packet(new NetPacket(NetPacket::Alloc));
|
|
|
|
|
packet->GetMsg()->present = PokerTHMessage_PR_gameListMessage;
|
|
|
|
|
GameListMessage_t *netListMsg = &packet->GetMsg()->choice.gameListMessage;
|
|
|
|
|
netListMsg->gameId = gameId;
|
|
|
|
|
|
|
|
|
|
netListMsg->gameListNotification.present = gameListNotification_PR_gameListPlayerJoined;
|
|
|
|
|
GameListPlayerJoined_t *playerJoined = &netListMsg->gameListNotification.choice.gameListPlayerJoined;
|
|
|
|
|
playerJoined->playerId = playerId;
|
|
|
|
|
|
2009-06-07 08:51:43 +00:00
|
|
|
m_sessionManager.SendLobbyMsgToAllSessions(GetSender(), packet, SessionData::Established);
|
|
|
|
|
m_gameSessionManager.SendLobbyMsgToAllSessions(GetSender(), packet, SessionData::Game);
|
2007-11-16 15:24:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
ServerLobbyThread::NotifyPlayerLeftGame(unsigned gameId, unsigned playerId)
|
|
|
|
|
{
|
|
|
|
|
// Send notification to players in lobby.
|
2009-08-02 15:11:40 +00:00
|
|
|
boost::shared_ptr<NetPacket> packet(new NetPacket(NetPacket::Alloc));
|
|
|
|
|
packet->GetMsg()->present = PokerTHMessage_PR_gameListMessage;
|
|
|
|
|
GameListMessage_t *netListMsg = &packet->GetMsg()->choice.gameListMessage;
|
|
|
|
|
netListMsg->gameId = gameId;
|
|
|
|
|
|
|
|
|
|
netListMsg->gameListNotification.present = gameListNotification_PR_gameListPlayerLeft;
|
|
|
|
|
GameListPlayerLeft_t *playerLeft = &netListMsg->gameListNotification.choice.gameListPlayerLeft;
|
|
|
|
|
playerLeft->playerId = playerId;
|
|
|
|
|
|
2009-06-07 08:51:43 +00:00
|
|
|
m_sessionManager.SendLobbyMsgToAllSessions(GetSender(), packet, SessionData::Established);
|
|
|
|
|
m_gameSessionManager.SendLobbyMsgToAllSessions(GetSender(), packet, SessionData::Game);
|
2007-11-16 15:24:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
ServerLobbyThread::NotifyGameAdminChanged(unsigned gameId, unsigned newAdminPlayerId)
|
|
|
|
|
{
|
|
|
|
|
// Send notification to players in lobby.
|
2009-08-02 15:11:40 +00:00
|
|
|
boost::shared_ptr<NetPacket> packet(new NetPacket(NetPacket::Alloc));
|
|
|
|
|
packet->GetMsg()->present = PokerTHMessage_PR_gameListMessage;
|
|
|
|
|
GameListMessage_t *netListMsg = &packet->GetMsg()->choice.gameListMessage;
|
|
|
|
|
netListMsg->gameId = gameId;
|
|
|
|
|
|
|
|
|
|
netListMsg->gameListNotification.present = gameListNotification_PR_gameListAdminChanged;
|
|
|
|
|
GameListAdminChanged_t *adminChanged = &netListMsg->gameListNotification.choice.gameListAdminChanged;
|
|
|
|
|
adminChanged->newAdminPlayerId = newAdminPlayerId;
|
|
|
|
|
|
2009-06-07 08:51:43 +00:00
|
|
|
m_sessionManager.SendLobbyMsgToAllSessions(GetSender(), packet, SessionData::Established);
|
|
|
|
|
m_gameSessionManager.SendLobbyMsgToAllSessions(GetSender(), packet, SessionData::Game);
|
2007-11-16 15:24:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
ServerLobbyThread::NotifyStartingGame(unsigned gameId)
|
|
|
|
|
{
|
|
|
|
|
boost::shared_ptr<NetPacket> packet = CreateNetPacketGameListUpdate(gameId, GAME_MODE_STARTED);
|
2009-06-07 08:51:43 +00:00
|
|
|
m_sessionManager.SendLobbyMsgToAllSessions(GetSender(), packet, SessionData::Established);
|
|
|
|
|
m_gameSessionManager.SendLobbyMsgToAllSessions(GetSender(), packet, SessionData::Game);
|
2007-11-16 15:24:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
ServerLobbyThread::NotifyReopeningGame(unsigned gameId)
|
|
|
|
|
{
|
|
|
|
|
boost::shared_ptr<NetPacket> packet = CreateNetPacketGameListUpdate(gameId, GAME_MODE_CREATED);
|
2009-06-07 08:51:43 +00:00
|
|
|
m_sessionManager.SendLobbyMsgToAllSessions(GetSender(), packet, SessionData::Established);
|
|
|
|
|
m_gameSessionManager.SendLobbyMsgToAllSessions(GetSender(), packet, SessionData::Game);
|
2007-11-16 15:24:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2011-03-10 20:55:46 +00:00
|
|
|
ServerLobbyThread::HandleGameRetrievePlayerInfo(boost::shared_ptr<SessionData> session, const PlayerInfoRequestMessage_t &playerInfoRequest)
|
2007-11-16 15:24:25 +00:00
|
|
|
{
|
|
|
|
|
// Someone within a game requested player info.
|
2009-08-02 15:11:40 +00:00
|
|
|
HandleNetPacketRetrievePlayerInfo(session, playerInfoRequest);
|
2007-11-16 15:24:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2011-03-10 20:55:46 +00:00
|
|
|
ServerLobbyThread::HandleGameRetrieveAvatar(boost::shared_ptr<SessionData> session, const AvatarRequestMessage_t &retrieveAvatar)
|
2007-11-16 15:24:25 +00:00
|
|
|
{
|
|
|
|
|
// Someone within a game requested an avatar.
|
2009-08-02 15:11:40 +00:00
|
|
|
HandleNetPacketRetrieveAvatar(session, retrieveAvatar);
|
2007-11-16 15:24:25 +00:00
|
|
|
}
|
|
|
|
|
|
2012-04-08 14:36:14 +00:00
|
|
|
void
|
|
|
|
|
ServerLobbyThread::HandleGameReportGame(boost::shared_ptr<SessionData> session, const ReportGameMessage_t &reportGame)
|
|
|
|
|
{
|
|
|
|
|
// Someone within a game reportet a game name.
|
|
|
|
|
HandleNetPacketReportGame(session, reportGame);
|
|
|
|
|
}
|
|
|
|
|
|
2009-08-15 14:51:21 +00:00
|
|
|
void
|
2011-03-10 20:55:46 +00:00
|
|
|
ServerLobbyThread::HandleChatRequest(boost::shared_ptr<SessionData> session, const ChatRequestMessage_t &chatRequest)
|
2009-08-15 14:51:21 +00:00
|
|
|
{
|
|
|
|
|
// Someone within a game sent a lobby message.
|
|
|
|
|
HandleNetPacketChatRequest(session, chatRequest);
|
|
|
|
|
}
|
|
|
|
|
|
2007-11-16 15:24:25 +00:00
|
|
|
bool
|
|
|
|
|
ServerLobbyThread::KickPlayerByName(const std::string &playerName)
|
|
|
|
|
{
|
|
|
|
|
bool retVal = false;
|
2011-03-10 20:55:46 +00:00
|
|
|
boost::shared_ptr<SessionData> session = m_sessionManager.GetSessionByPlayerName(playerName);
|
|
|
|
|
if (!session)
|
2007-11-16 15:24:25 +00:00
|
|
|
session = m_gameSessionManager.GetSessionByPlayerName(playerName);
|
|
|
|
|
|
2011-03-10 20:55:46 +00:00
|
|
|
if (session && session->GetPlayerData()) {
|
|
|
|
|
RemovePlayer(session->GetPlayerData()->GetUniqueId(), ERR_NET_PLAYER_KICKED);
|
2007-11-16 15:24:25 +00:00
|
|
|
retVal = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return retVal;
|
|
|
|
|
}
|
|
|
|
|
|
2012-02-13 20:28:55 +00:00
|
|
|
bool
|
|
|
|
|
ServerLobbyThread::RemoveGameByPlayerName(const std::string &playerName)
|
|
|
|
|
{
|
|
|
|
|
bool retVal = false;
|
|
|
|
|
boost::shared_ptr<SessionData> session = m_gameSessionManager.GetSessionByPlayerName(playerName);
|
|
|
|
|
|
|
|
|
|
if (session) {
|
|
|
|
|
boost::shared_ptr<ServerGame> game = session->GetGame();
|
|
|
|
|
if (game) {
|
|
|
|
|
m_ioService->post(boost::bind(&ServerLobbyThread::InternalRemoveGame, shared_from_this(), game));
|
|
|
|
|
retVal = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return retVal;
|
|
|
|
|
}
|
|
|
|
|
|
2009-04-10 21:54:59 +00:00
|
|
|
string
|
|
|
|
|
ServerLobbyThread::GetPlayerIPAddress(const std::string &playerName) const
|
|
|
|
|
{
|
|
|
|
|
string ipAddress;
|
2011-03-10 20:55:46 +00:00
|
|
|
boost::shared_ptr<SessionData> session = m_sessionManager.GetSessionByPlayerName(playerName);
|
|
|
|
|
if (!session)
|
2009-04-10 21:54:59 +00:00
|
|
|
session = m_gameSessionManager.GetSessionByPlayerName(playerName);
|
|
|
|
|
|
2011-03-10 20:55:46 +00:00
|
|
|
if (session)
|
|
|
|
|
ipAddress = session->GetClientAddr();
|
2009-04-10 21:54:59 +00:00
|
|
|
|
|
|
|
|
return ipAddress;
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-14 17:20:51 +00:00
|
|
|
std::string
|
|
|
|
|
ServerLobbyThread::GetPlayerNameFromId(unsigned playerId) const
|
|
|
|
|
{
|
|
|
|
|
string name;
|
2011-03-10 20:55:46 +00:00
|
|
|
boost::shared_ptr<SessionData> session = m_sessionManager.GetSessionByUniquePlayerId(playerId);
|
|
|
|
|
if (!session)
|
2010-07-14 17:20:51 +00:00
|
|
|
session = m_gameSessionManager.GetSessionByUniquePlayerId(playerId);
|
|
|
|
|
|
2011-03-10 20:55:46 +00:00
|
|
|
if (session && session->GetPlayerData())
|
|
|
|
|
name = session->GetPlayerData()->GetName();
|
2010-07-14 17:20:51 +00:00
|
|
|
|
|
|
|
|
return name;
|
|
|
|
|
}
|
|
|
|
|
|
2008-03-06 15:27:31 +00:00
|
|
|
void
|
|
|
|
|
ServerLobbyThread::RemovePlayer(unsigned playerId, unsigned errorCode)
|
|
|
|
|
{
|
2011-12-11 17:12:26 +00:00
|
|
|
m_ioService->post(boost::bind(&ServerLobbyThread::InternalRemovePlayer, shared_from_this(), playerId, errorCode));
|
2008-03-06 15:27:31 +00:00
|
|
|
}
|
|
|
|
|
|
2012-01-08 13:02:29 +00:00
|
|
|
void
|
|
|
|
|
ServerLobbyThread::MutePlayerInGame(unsigned playerId)
|
|
|
|
|
{
|
|
|
|
|
m_ioService->post(boost::bind(&ServerLobbyThread::InternalMutePlayerInGame, shared_from_this(), playerId));
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-26 13:50:09 +00:00
|
|
|
void
|
2008-12-26 16:47:14 +00:00
|
|
|
ServerLobbyThread::SendGlobalChat(const string &message)
|
2008-12-26 13:50:09 +00:00
|
|
|
{
|
2009-08-02 15:11:40 +00:00
|
|
|
boost::shared_ptr<NetPacket> packet(new NetPacket(NetPacket::Alloc));
|
|
|
|
|
packet->GetMsg()->present = PokerTHMessage_PR_chatMessage;
|
|
|
|
|
ChatMessage_t *netChat = &packet->GetMsg()->choice.chatMessage;
|
2009-08-15 10:25:13 +00:00
|
|
|
netChat->chatType.present = chatType_PR_chatTypeBroadcast;
|
2009-08-02 15:11:40 +00:00
|
|
|
OCTET_STRING_fromBuf(
|
|
|
|
|
&netChat->chatText,
|
|
|
|
|
message.c_str(),
|
2011-04-10 10:04:42 +00:00
|
|
|
(int)message.length());
|
2009-08-02 15:11:40 +00:00
|
|
|
|
2009-08-15 10:25:13 +00:00
|
|
|
m_sessionManager.SendToAllSessions(GetSender(), packet, SessionData::Established);
|
2009-08-02 15:11:40 +00:00
|
|
|
m_gameSessionManager.SendToAllSessions(GetSender(), packet, SessionData::Game);
|
2008-12-26 13:50:09 +00:00
|
|
|
}
|
|
|
|
|
|
2008-12-26 16:47:14 +00:00
|
|
|
void
|
|
|
|
|
ServerLobbyThread::SendGlobalMsgBox(const string &message)
|
|
|
|
|
{
|
2009-08-02 15:11:40 +00:00
|
|
|
boost::shared_ptr<NetPacket> packet(new NetPacket(NetPacket::Alloc));
|
|
|
|
|
packet->GetMsg()->present = PokerTHMessage_PR_dialogMessage;
|
|
|
|
|
DialogMessage_t *netDialog = &packet->GetMsg()->choice.dialogMessage;
|
|
|
|
|
|
|
|
|
|
OCTET_STRING_fromBuf(
|
|
|
|
|
&netDialog->notificationText,
|
|
|
|
|
message.c_str(),
|
2011-04-10 10:04:42 +00:00
|
|
|
(int)message.length());
|
2009-08-17 09:45:06 +00:00
|
|
|
m_sessionManager.SendToAllSessions(GetSender(), packet, SessionData::Established);
|
2009-08-02 15:11:40 +00:00
|
|
|
m_gameSessionManager.SendToAllSessions(GetSender(), packet, SessionData::Game);
|
2008-12-26 16:47:14 +00:00
|
|
|
}
|
|
|
|
|
|
2009-08-17 09:45:06 +00:00
|
|
|
void
|
|
|
|
|
ServerLobbyThread::SendChatBotMsg(const std::string &message)
|
|
|
|
|
{
|
|
|
|
|
boost::shared_ptr<NetPacket> packet(new NetPacket(NetPacket::Alloc));
|
|
|
|
|
packet->GetMsg()->present = PokerTHMessage_PR_chatMessage;
|
|
|
|
|
ChatMessage_t *netChat = &packet->GetMsg()->choice.chatMessage;
|
|
|
|
|
netChat->chatType.present = chatType_PR_chatTypeBot;
|
|
|
|
|
OCTET_STRING_fromBuf(
|
|
|
|
|
&netChat->chatText,
|
|
|
|
|
message.c_str(),
|
2011-04-10 10:04:42 +00:00
|
|
|
(int)message.length());
|
2009-08-17 09:45:06 +00:00
|
|
|
|
|
|
|
|
m_sessionManager.SendLobbyMsgToAllSessions(GetSender(), packet, SessionData::Established);
|
|
|
|
|
m_gameSessionManager.SendLobbyMsgToAllSessions(GetSender(), packet, SessionData::Game);
|
2009-08-20 11:42:13 +00:00
|
|
|
|
|
|
|
|
GetIrcBotCallback().SignalLobbyMessage(
|
|
|
|
|
0,
|
2011-02-11 20:02:08 +00:00
|
|
|
"(chat bot)",
|
2009-08-20 11:42:13 +00:00
|
|
|
message);
|
2009-08-17 09:45:06 +00:00
|
|
|
}
|
|
|
|
|
|
2011-01-30 18:28:44 +00:00
|
|
|
void
|
|
|
|
|
ServerLobbyThread::SendChatBotMsg(unsigned gameId, const std::string &message)
|
|
|
|
|
{
|
|
|
|
|
boost::shared_ptr<NetPacket> packet(new NetPacket(NetPacket::Alloc));
|
|
|
|
|
packet->GetMsg()->present = PokerTHMessage_PR_chatMessage;
|
|
|
|
|
ChatMessage_t *netChat = &packet->GetMsg()->choice.chatMessage;
|
|
|
|
|
netChat->chatType.present = chatType_PR_chatTypeBot;
|
|
|
|
|
OCTET_STRING_fromBuf(
|
|
|
|
|
&netChat->chatText,
|
|
|
|
|
message.c_str(),
|
2011-04-10 10:04:42 +00:00
|
|
|
(int)message.length());
|
2011-01-30 18:28:44 +00:00
|
|
|
|
|
|
|
|
GameMap::const_iterator pos = m_gameMap.find(gameId);
|
2011-02-11 20:02:08 +00:00
|
|
|
if (pos != m_gameMap.end()) {
|
2011-01-30 18:28:44 +00:00
|
|
|
pos->second->SendToAllPlayers(packet, SessionData::Game);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-08-17 11:26:03 +00:00
|
|
|
void
|
|
|
|
|
ServerLobbyThread::ReconnectChatBot()
|
|
|
|
|
{
|
|
|
|
|
m_chatCleanerManager->ReInit();
|
|
|
|
|
}
|
|
|
|
|
|
2007-11-16 15:24:25 +00:00
|
|
|
void
|
|
|
|
|
ServerLobbyThread::AddComputerPlayer(boost::shared_ptr<PlayerData> player)
|
|
|
|
|
{
|
|
|
|
|
boost::mutex::scoped_lock lock(m_computerPlayersMutex);
|
|
|
|
|
m_computerPlayers.insert(PlayerDataMap::value_type(player->GetUniqueId(), player));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
ServerLobbyThread::RemoveComputerPlayer(boost::shared_ptr<PlayerData> player)
|
|
|
|
|
{
|
|
|
|
|
boost::mutex::scoped_lock lock(m_computerPlayersMutex);
|
|
|
|
|
m_computerPlayers.erase(player->GetUniqueId());
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-30 13:02:43 +00:00
|
|
|
bool
|
2010-03-30 12:07:48 +00:00
|
|
|
ServerLobbyThread::SendToLobbyPlayer(unsigned playerId, boost::shared_ptr<NetPacket> packet)
|
|
|
|
|
{
|
2010-03-30 13:02:43 +00:00
|
|
|
bool retVal = false;
|
2011-03-10 20:55:46 +00:00
|
|
|
boost::shared_ptr<SessionData> tmpSession = m_sessionManager.GetSessionByUniquePlayerId(playerId);
|
|
|
|
|
if (tmpSession) {
|
|
|
|
|
GetSender().Send(tmpSession, packet);
|
2010-03-30 13:02:43 +00:00
|
|
|
retVal = true;
|
|
|
|
|
}
|
|
|
|
|
return retVal;
|
2010-03-30 12:07:48 +00:00
|
|
|
}
|
2011-02-11 20:02:08 +00:00
|
|
|
|
2007-11-16 15:24:25 +00:00
|
|
|
AvatarManager &
|
|
|
|
|
ServerLobbyThread::GetAvatarManager()
|
|
|
|
|
{
|
|
|
|
|
return m_avatarManager;
|
|
|
|
|
}
|
|
|
|
|
|
2011-01-30 18:28:44 +00:00
|
|
|
ChatCleanerManager &
|
|
|
|
|
ServerLobbyThread::GetChatCleaner()
|
|
|
|
|
{
|
|
|
|
|
assert(m_chatCleanerManager);
|
|
|
|
|
return *m_chatCleanerManager;
|
|
|
|
|
}
|
|
|
|
|
|
2007-11-16 15:24:25 +00:00
|
|
|
ServerStats
|
|
|
|
|
ServerLobbyThread::GetStats() const
|
|
|
|
|
{
|
|
|
|
|
boost::mutex::scoped_lock lock(m_statMutex);
|
|
|
|
|
return m_statData;
|
|
|
|
|
}
|
|
|
|
|
|
2007-11-28 23:31:34 +00:00
|
|
|
boost::posix_time::ptime
|
|
|
|
|
ServerLobbyThread::GetStartTime() const
|
|
|
|
|
{
|
|
|
|
|
return m_startTime;
|
|
|
|
|
}
|
|
|
|
|
|
2010-09-04 23:00:39 +00:00
|
|
|
ServerMode
|
|
|
|
|
ServerLobbyThread::GetServerMode() const
|
|
|
|
|
{
|
|
|
|
|
return m_mode;
|
|
|
|
|
}
|
|
|
|
|
|
2009-06-07 08:51:43 +00:00
|
|
|
SenderHelper &
|
2009-01-31 22:20:08 +00:00
|
|
|
ServerLobbyThread::GetSender()
|
|
|
|
|
{
|
|
|
|
|
assert(m_sender);
|
|
|
|
|
return *m_sender;
|
|
|
|
|
}
|
|
|
|
|
|
2009-06-12 15:48:34 +00:00
|
|
|
boost::asio::io_service &
|
|
|
|
|
ServerLobbyThread::GetIOService()
|
|
|
|
|
{
|
|
|
|
|
assert(m_ioService);
|
|
|
|
|
return *m_ioService;
|
|
|
|
|
}
|
|
|
|
|
|
2010-08-07 23:06:59 +00:00
|
|
|
boost::shared_ptr<ServerDBInterface>
|
2009-10-03 18:06:56 +00:00
|
|
|
ServerLobbyThread::GetDatabase()
|
|
|
|
|
{
|
2010-08-07 23:06:59 +00:00
|
|
|
return m_database;
|
2009-10-03 18:06:56 +00:00
|
|
|
}
|
|
|
|
|
|
2009-06-18 20:16:22 +00:00
|
|
|
ServerBanManager &
|
|
|
|
|
ServerLobbyThread::GetBanManager()
|
|
|
|
|
{
|
|
|
|
|
assert(m_banManager);
|
|
|
|
|
return *m_banManager;
|
|
|
|
|
}
|
|
|
|
|
|
2007-11-16 15:24:25 +00:00
|
|
|
u_int32_t
|
|
|
|
|
ServerLobbyThread::GetNextUniquePlayerId()
|
|
|
|
|
{
|
|
|
|
|
boost::mutex::scoped_lock lock(m_curUniquePlayerIdMutex);
|
2008-12-26 13:50:09 +00:00
|
|
|
m_curUniquePlayerId++;
|
|
|
|
|
if (m_curUniquePlayerId == 0) // 0 is an invalid id.
|
|
|
|
|
m_curUniquePlayerId++;
|
|
|
|
|
|
|
|
|
|
return m_curUniquePlayerId;
|
2007-11-16 15:24:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
u_int32_t
|
|
|
|
|
ServerLobbyThread::GetNextGameId()
|
|
|
|
|
{
|
2008-12-26 13:50:09 +00:00
|
|
|
m_curGameId++;
|
|
|
|
|
if (m_curGameId == 0) // 0 is an invalid id.
|
|
|
|
|
m_curGameId++;
|
|
|
|
|
|
|
|
|
|
return m_curGameId;
|
2007-11-16 15:24:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
ServerLobbyThread::Main()
|
|
|
|
|
{
|
2011-02-11 20:02:08 +00:00
|
|
|
try {
|
2009-10-11 09:20:17 +00:00
|
|
|
InitAuthContext();
|
|
|
|
|
|
|
|
|
|
InitChatCleaner();
|
|
|
|
|
// Start database engine.
|
|
|
|
|
m_database->Start();
|
|
|
|
|
// Register all timers.
|
|
|
|
|
RegisterTimers();
|
|
|
|
|
|
2009-06-17 21:22:01 +00:00
|
|
|
boost::asio::io_service::work ioWork(*m_ioService);
|
|
|
|
|
m_ioService->run(); // Will only be aborted asynchronously.
|
2009-06-04 22:13:52 +00:00
|
|
|
|
2011-02-11 20:02:08 +00:00
|
|
|
} catch (const PokerTHException &e) {
|
2007-11-16 15:24:25 +00:00
|
|
|
GetCallback().SignalNetServerError(e.GetErrorId(), e.GetOsErrorCode());
|
2009-07-12 21:12:55 +00:00
|
|
|
LOG_ERROR("Lobby exception: " << e.what());
|
2007-11-16 15:24:25 +00:00
|
|
|
}
|
2011-02-28 23:47:33 +00:00
|
|
|
// Clear all sessions and games.
|
2009-06-17 21:22:01 +00:00
|
|
|
m_sessionManager.Clear();
|
|
|
|
|
m_gameSessionManager.Clear();
|
2011-02-28 23:47:33 +00:00
|
|
|
BOOST_FOREACH(const GameMap::value_type& tmpGame, m_gameMap) {
|
|
|
|
|
tmpGame.second->Exit();
|
|
|
|
|
}
|
|
|
|
|
m_gameMap.clear();
|
2009-06-12 15:48:34 +00:00
|
|
|
// Cancel pending timer callbacks.
|
|
|
|
|
CancelTimers();
|
2009-09-26 22:10:43 +00:00
|
|
|
// Stop database engine.
|
|
|
|
|
m_database->Stop();
|
2009-10-11 09:20:17 +00:00
|
|
|
|
|
|
|
|
ClearAuthContext();
|
2009-05-10 14:57:51 +00:00
|
|
|
}
|
2007-11-16 15:24:25 +00:00
|
|
|
|
2009-05-10 14:57:51 +00:00
|
|
|
void
|
|
|
|
|
ServerLobbyThread::RegisterTimers()
|
|
|
|
|
{
|
|
|
|
|
// Remove closed games.
|
2009-06-12 15:48:34 +00:00
|
|
|
m_removeGameTimer.expires_from_now(
|
|
|
|
|
boost::posix_time::milliseconds(SERVER_REMOVE_GAME_INTERVAL_MSEC));
|
|
|
|
|
m_removeGameTimer.async_wait(
|
|
|
|
|
boost::bind(
|
|
|
|
|
&ServerLobbyThread::TimerRemoveGame, shared_from_this(), boost::asio::placeholders::error));
|
2009-05-10 14:57:51 +00:00
|
|
|
// Update the statistics file.
|
2009-06-12 15:48:34 +00:00
|
|
|
m_saveStatisticsTimer.expires_from_now(
|
|
|
|
|
boost::posix_time::seconds(SERVER_SAVE_STATISTICS_INTERVAL_SEC));
|
|
|
|
|
m_saveStatisticsTimer.async_wait(
|
|
|
|
|
boost::bind(
|
|
|
|
|
&ServerLobbyThread::TimerSaveStatisticsFile, shared_from_this(), boost::asio::placeholders::error));
|
2009-05-10 17:53:37 +00:00
|
|
|
// Update the avatar upload locks.
|
2009-12-23 09:53:01 +00:00
|
|
|
m_loginLockTimer.expires_from_now(
|
|
|
|
|
boost::posix_time::milliseconds(SERVER_UPDATE_LOGIN_LOCK_INTERVAL_MSEC));
|
|
|
|
|
m_loginLockTimer.async_wait(
|
2009-06-12 15:48:34 +00:00
|
|
|
boost::bind(
|
2009-12-23 09:53:01 +00:00
|
|
|
&ServerLobbyThread::TimerUpdateClientLoginLock, shared_from_this(), boost::asio::placeholders::error));
|
2009-06-12 15:48:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
ServerLobbyThread::CancelTimers()
|
|
|
|
|
{
|
|
|
|
|
m_removeGameTimer.cancel();
|
|
|
|
|
m_saveStatisticsTimer.cancel();
|
2009-12-23 09:53:01 +00:00
|
|
|
m_loginLockTimer.cancel();
|
2007-11-16 15:24:25 +00:00
|
|
|
}
|
|
|
|
|
|
2009-10-11 09:20:17 +00:00
|
|
|
void
|
|
|
|
|
ServerLobbyThread::InitAuthContext()
|
|
|
|
|
{
|
2009-10-13 21:03:32 +00:00
|
|
|
int res = gsasl_init(&m_authContext);
|
|
|
|
|
if (res != GSASL_OK)
|
|
|
|
|
throw ServerException(__FILE__, __LINE__, ERR_NET_GSASL_INIT_FAILED, 0);
|
|
|
|
|
|
2011-02-11 20:02:08 +00:00
|
|
|
if (!gsasl_server_support_p(m_authContext, "SCRAM-SHA-1")) {
|
2009-10-13 21:03:32 +00:00
|
|
|
gsasl_done(m_authContext);
|
|
|
|
|
throw ServerException(__FILE__, __LINE__, ERR_NET_GSASL_NO_SCRAM, 0);
|
|
|
|
|
}
|
2009-10-11 09:20:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
ServerLobbyThread::ClearAuthContext()
|
|
|
|
|
{
|
2009-10-11 12:07:56 +00:00
|
|
|
gsasl_done(m_authContext);
|
|
|
|
|
m_authContext = NULL;
|
2009-10-11 09:20:17 +00:00
|
|
|
}
|
|
|
|
|
|
2009-08-14 22:05:01 +00:00
|
|
|
void
|
|
|
|
|
ServerLobbyThread::InitChatCleaner()
|
|
|
|
|
{
|
2011-02-11 20:02:08 +00:00
|
|
|
if (m_serverConfig.readConfigInt("UseChatCleaner") != 0) {
|
2009-08-14 22:05:01 +00:00
|
|
|
m_chatCleanerManager->Init(
|
2011-02-11 20:02:08 +00:00
|
|
|
m_serverConfig.readConfigString("ChatCleanerHostAddress"),
|
|
|
|
|
m_serverConfig.readConfigInt("ChatCleanerPort"),
|
|
|
|
|
m_serverConfig.readConfigInt("ChatCleanerUseIpv6") != 0,
|
|
|
|
|
m_serverConfig.readConfigString("ChatCleanerClientAuth"),
|
|
|
|
|
m_serverConfig.readConfigString("ChatCleanerServerAuth"));
|
2009-08-14 22:05:01 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2007-11-16 15:24:25 +00:00
|
|
|
void
|
2011-03-10 20:55:46 +00:00
|
|
|
ServerLobbyThread::DispatchPacket(boost::shared_ptr<SessionData> session, boost::shared_ptr<NetPacket> packet)
|
2007-11-16 15:24:25 +00:00
|
|
|
{
|
2011-03-10 20:55:46 +00:00
|
|
|
if (session) {
|
2011-02-19 23:47:24 +00:00
|
|
|
// Retrieve current game, if applicable.
|
2011-03-10 21:53:25 +00:00
|
|
|
boost::shared_ptr<ServerGame> game = session->GetGame();
|
2011-02-19 23:47:24 +00:00
|
|
|
if (game) {
|
|
|
|
|
// We need to catch game-specific exceptions, so that they do not affect the server.
|
|
|
|
|
try {
|
|
|
|
|
game->HandlePacket(session, packet);
|
|
|
|
|
} catch (const PokerTHException &e) {
|
|
|
|
|
LOG_ERROR("Game " << game->GetId() << " - Read handler exception: " << e.what());
|
|
|
|
|
game->RemoveAllSessions();
|
2009-07-21 21:40:24 +00:00
|
|
|
}
|
2011-02-19 23:47:24 +00:00
|
|
|
} else
|
|
|
|
|
HandlePacket(session, packet);
|
2009-05-04 21:11:29 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2011-03-10 20:55:46 +00:00
|
|
|
ServerLobbyThread::HandlePacket(boost::shared_ptr<SessionData> session, boost::shared_ptr<NetPacket> packet)
|
2009-05-04 21:11:29 +00:00
|
|
|
{
|
2011-03-10 20:55:46 +00:00
|
|
|
if (session && packet) {
|
2009-05-04 21:11:29 +00:00
|
|
|
if (packet->IsClientActivity())
|
2011-03-10 20:55:46 +00:00
|
|
|
session->ResetActivityTimer();
|
2009-05-04 21:11:29 +00:00
|
|
|
|
2011-03-10 20:55:46 +00:00
|
|
|
if (session->GetState() == SessionData::Init) {
|
2009-08-02 15:11:40 +00:00
|
|
|
if (packet->GetMsg()->present == PokerTHMessage_PR_initMessage)
|
|
|
|
|
HandleNetPacketInit(session, packet->GetMsg()->choice.initMessage);
|
2011-02-11 20:02:08 +00:00
|
|
|
else if (packet->GetMsg()->present == PokerTHMessage_PR_authMessage) {
|
2009-10-18 20:53:58 +00:00
|
|
|
AuthMessage_t *authMsg = &packet->GetMsg()->choice.authMessage;
|
|
|
|
|
if (authMsg->present == AuthMessage_PR_authClientResponse)
|
|
|
|
|
HandleNetPacketAuthClientResponse(session, authMsg->choice.authClientResponse);
|
|
|
|
|
else
|
|
|
|
|
SessionError(session, ERR_SOCK_INVALID_STATE);
|
2011-02-11 20:02:08 +00:00
|
|
|
} else if (packet->GetMsg()->present == PokerTHMessage_PR_avatarReplyMessage) {
|
2009-08-02 15:11:40 +00:00
|
|
|
AvatarReplyMessage_t *avatarReply = &packet->GetMsg()->choice.avatarReplyMessage;
|
|
|
|
|
if (avatarReply->avatarResult.present == avatarResult_PR_avatarHeader)
|
|
|
|
|
HandleNetPacketAvatarHeader(session, avatarReply->requestId, avatarReply->avatarResult.choice.avatarHeader);
|
|
|
|
|
else if (avatarReply->avatarResult.present == avatarResult_PR_unknownAvatar)
|
|
|
|
|
HandleNetPacketUnknownAvatar(session, avatarReply->requestId, avatarReply->avatarResult.choice.unknownAvatar);
|
|
|
|
|
else
|
|
|
|
|
SessionError(session, ERR_SOCK_INVALID_STATE);
|
2011-02-11 20:02:08 +00:00
|
|
|
} else
|
2009-05-04 21:11:29 +00:00
|
|
|
SessionError(session, ERR_SOCK_INVALID_STATE);
|
2011-03-10 20:55:46 +00:00
|
|
|
} else if (session->GetState() == SessionData::ReceivingAvatar) {
|
2011-02-11 20:02:08 +00:00
|
|
|
if (packet->GetMsg()->present == PokerTHMessage_PR_avatarReplyMessage) {
|
2009-08-02 15:11:40 +00:00
|
|
|
AvatarReplyMessage_t *avatarReply = &packet->GetMsg()->choice.avatarReplyMessage;
|
|
|
|
|
if (avatarReply->avatarResult.present == avatarResult_PR_avatarData)
|
|
|
|
|
HandleNetPacketAvatarFile(session, avatarReply->requestId, avatarReply->avatarResult.choice.avatarData);
|
|
|
|
|
else if (avatarReply->avatarResult.present == avatarResult_PR_avatarEnd)
|
|
|
|
|
HandleNetPacketAvatarEnd(session, avatarReply->requestId, avatarReply->avatarResult.choice.avatarEnd);
|
|
|
|
|
else
|
|
|
|
|
SessionError(session, ERR_SOCK_INVALID_STATE);
|
2011-02-11 20:02:08 +00:00
|
|
|
} else
|
2009-05-04 21:11:29 +00:00
|
|
|
SessionError(session, ERR_SOCK_INVALID_STATE);
|
2011-02-11 20:02:08 +00:00
|
|
|
} else {
|
2009-08-02 15:11:40 +00:00
|
|
|
if (packet->GetMsg()->present == PokerTHMessage_PR_playerInfoRequestMessage)
|
|
|
|
|
HandleNetPacketRetrievePlayerInfo(session, packet->GetMsg()->choice.playerInfoRequestMessage);
|
|
|
|
|
else if (packet->GetMsg()->present == PokerTHMessage_PR_avatarRequestMessage)
|
|
|
|
|
HandleNetPacketRetrieveAvatar(session, packet->GetMsg()->choice.avatarRequestMessage);
|
|
|
|
|
else if (packet->GetMsg()->present == PokerTHMessage_PR_resetTimeoutMessage)
|
2012-01-28 12:51:42 +00:00
|
|
|
{}
|
2011-02-11 20:02:08 +00:00
|
|
|
else if (packet->GetMsg()->present == PokerTHMessage_PR_subscriptionRequestMessage) {
|
2009-08-02 15:11:40 +00:00
|
|
|
SubscriptionRequestMessage_t *subscriptionRequest = &packet->GetMsg()->choice.subscriptionRequestMessage;
|
|
|
|
|
if (subscriptionRequest->subscriptionAction == subscriptionAction_resubscribeGameList)
|
|
|
|
|
InternalResubscribeMsg(session);
|
|
|
|
|
else
|
2011-03-10 20:55:46 +00:00
|
|
|
session->ResetWantsLobbyMsg();
|
2011-02-11 20:02:08 +00:00
|
|
|
} else if (packet->GetMsg()->present == PokerTHMessage_PR_joinGameRequestMessage) {
|
2009-08-02 15:11:40 +00:00
|
|
|
JoinGameRequestMessage_t *joinRequest = &packet->GetMsg()->choice.joinGameRequestMessage;
|
|
|
|
|
if (joinRequest->joinGameAction.present == joinGameAction_PR_joinNewGame)
|
2011-10-03 08:03:58 +00:00
|
|
|
HandleNetPacketCreateGame(session, joinRequest->autoLeave, joinRequest->joinGameAction.choice.joinNewGame);
|
2009-08-02 15:11:40 +00:00
|
|
|
else if (joinRequest->joinGameAction.present == joinGameAction_PR_joinExistingGame)
|
2011-10-03 08:03:58 +00:00
|
|
|
HandleNetPacketJoinGame(session, joinRequest->autoLeave, joinRequest->joinGameAction.choice.joinExistingGame);
|
2011-09-11 17:41:56 +00:00
|
|
|
else if (joinRequest->joinGameAction.present == joinGameAction_PR_rejoinExistingGame)
|
|
|
|
|
HandleNetPacketRejoinGame(session, joinRequest->autoLeave, joinRequest->joinGameAction.choice.rejoinExistingGame);
|
2011-02-11 20:02:08 +00:00
|
|
|
} else if (packet->GetMsg()->present == PokerTHMessage_PR_chatRequestMessage)
|
2009-08-15 10:25:13 +00:00
|
|
|
HandleNetPacketChatRequest(session, packet->GetMsg()->choice.chatRequestMessage);
|
2010-03-30 17:10:37 +00:00
|
|
|
else if (packet->GetMsg()->present == PokerTHMessage_PR_rejectGameInvitationMessage)
|
|
|
|
|
HandleNetPacketRejectGameInvitation(session, packet->GetMsg()->choice.rejectGameInvitationMessage);
|
2012-04-08 14:36:14 +00:00
|
|
|
else if (packet->GetMsg()->present == PokerTHMessage_PR_reportGameMessage)
|
|
|
|
|
HandleNetPacketReportGame(session, packet->GetMsg()->choice.reportGameMessage);
|
2009-05-04 21:11:29 +00:00
|
|
|
else
|
|
|
|
|
SessionError(session, ERR_SOCK_INVALID_STATE);
|
2007-11-16 15:24:25 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2011-03-10 20:55:46 +00:00
|
|
|
ServerLobbyThread::HandleNetPacketInit(boost::shared_ptr<SessionData> session, const InitMessage_t &initMessage)
|
2007-11-16 15:24:25 +00:00
|
|
|
{
|
2011-03-10 20:55:46 +00:00
|
|
|
LOG_VERBOSE("Received init for session #" << session->GetId() << ".");
|
2008-03-20 00:06:19 +00:00
|
|
|
|
2009-12-23 09:53:01 +00:00
|
|
|
// Before any other processing, perform some denial of service and
|
|
|
|
|
// brute force attack prevention by checking whether the user recently sent an
|
|
|
|
|
// Init packet.
|
2011-02-11 20:02:08 +00:00
|
|
|
if (m_serverConfig.readConfigInt("ServerBruteForceProtection") != 0) {
|
2010-11-07 08:24:31 +00:00
|
|
|
bool recentlySentInit = false;
|
|
|
|
|
{
|
|
|
|
|
boost::mutex::scoped_lock lock(m_timerClientAddressMapMutex);
|
2011-03-10 20:55:46 +00:00
|
|
|
if (m_timerClientAddressMap.find(session->GetClientAddr()) != m_timerClientAddressMap.end())
|
2010-11-07 08:24:31 +00:00
|
|
|
recentlySentInit = true;
|
|
|
|
|
else
|
2011-03-10 20:55:46 +00:00
|
|
|
m_timerClientAddressMap[session->GetClientAddr()] = boost::timers::portable::microsec_timer();
|
2010-11-07 08:24:31 +00:00
|
|
|
}
|
2011-02-11 20:02:08 +00:00
|
|
|
if (recentlySentInit) {
|
2010-11-07 08:24:31 +00:00
|
|
|
SessionError(session, ERR_NET_INIT_BLOCKED);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2009-12-23 09:53:01 +00:00
|
|
|
}
|
|
|
|
|
|
2007-11-16 15:24:25 +00:00
|
|
|
// Check the protocol version.
|
2009-10-18 20:53:58 +00:00
|
|
|
if (initMessage.requestedVersion.major != NET_VERSION_MAJOR
|
2011-03-10 20:55:46 +00:00
|
|
|
|| session->GetPlayerData()) { // Has this session already sent an init?
|
2007-11-16 15:24:25 +00:00
|
|
|
SessionError(session, ERR_NET_VERSION_NOT_SUPPORTED);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2011-10-20 21:41:37 +00:00
|
|
|
#ifndef POKERTH_OFFICIAL_SERVER
|
|
|
|
|
// Check (clear text) server password (skip for official server, they are open to everyone).
|
2011-10-20 21:19:58 +00:00
|
|
|
string serverPassword;
|
|
|
|
|
if (initMessage.authServerPassword) {
|
|
|
|
|
serverPassword = STL_STRING_FROM_OCTET_STRING(*initMessage.authServerPassword);
|
|
|
|
|
}
|
|
|
|
|
if (serverPassword != m_serverConfig.readConfigString("ServerPassword")) {
|
|
|
|
|
SessionError(session, ERR_NET_INVALID_PASSWORD);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2011-10-20 21:41:37 +00:00
|
|
|
#endif
|
2007-11-16 15:24:25 +00:00
|
|
|
|
2009-08-02 15:11:40 +00:00
|
|
|
string playerName;
|
|
|
|
|
MD5Buf avatarMD5;
|
2009-11-14 15:04:31 +00:00
|
|
|
bool noAuth = false;
|
2009-11-15 08:41:29 +00:00
|
|
|
bool validGuest = false;
|
2011-02-11 20:02:08 +00:00
|
|
|
if (initMessage.login.present == login_PR_guestLogin) {
|
2009-10-23 22:21:34 +00:00
|
|
|
const GuestLogin_t *guestLogin = &initMessage.login.choice.guestLogin;
|
2009-10-24 21:49:11 +00:00
|
|
|
playerName = STL_STRING_FROM_OCTET_STRING(guestLogin->nickName);
|
2009-11-15 08:41:29 +00:00
|
|
|
// Verify guest player name.
|
|
|
|
|
if (playerName.length() > sizeof(SERVER_GUEST_PLAYER_NAME - 1)
|
2011-02-11 20:02:08 +00:00
|
|
|
&& playerName.substr(0, sizeof(SERVER_GUEST_PLAYER_NAME) - 1) == SERVER_GUEST_PLAYER_NAME) {
|
2009-11-15 08:41:29 +00:00
|
|
|
string guestId(playerName.substr(sizeof(SERVER_GUEST_PLAYER_NAME)));
|
2011-02-11 20:02:08 +00:00
|
|
|
if ((size_t)count_if(guestId.begin(), guestId.end(), ::isdigit) == guestId.size()) {
|
2009-11-15 08:41:29 +00:00
|
|
|
validGuest = true;
|
|
|
|
|
noAuth = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-02-11 20:02:08 +00:00
|
|
|
if (!validGuest) {
|
2009-11-15 08:41:29 +00:00
|
|
|
SessionError(session, ERR_NET_INVALID_PLAYER_NAME);
|
2009-11-15 09:02:00 +00:00
|
|
|
return;
|
|
|
|
|
}
|
2009-09-19 20:49:17 +00:00
|
|
|
}
|
2009-11-14 15:04:31 +00:00
|
|
|
#ifdef POKERTH_OFFICIAL_SERVER
|
2011-02-11 20:02:08 +00:00
|
|
|
else if (initMessage.login.present == login_PR_authenticatedLogin) {
|
2009-09-19 20:49:17 +00:00
|
|
|
const AuthenticatedLogin_t *authLogin = &initMessage.login.choice.authenticatedLogin;
|
2009-10-18 20:53:58 +00:00
|
|
|
string inAuthData((const char *)authLogin->clientUserData.buf, authLogin->clientUserData.size);
|
2009-09-19 21:01:51 +00:00
|
|
|
if (authLogin->avatar)
|
2010-03-21 15:30:13 +00:00
|
|
|
memcpy(avatarMD5.GetData(), authLogin->avatar->buf, MD5_DATA_SIZE);
|
2011-03-10 20:55:46 +00:00
|
|
|
session->CreateServerAuthSession(m_authContext);
|
|
|
|
|
if (session->AuthStep(1, inAuthData))
|
|
|
|
|
playerName = session->AuthGetUser();
|
2009-08-02 15:11:40 +00:00
|
|
|
}
|
2009-11-14 15:04:31 +00:00
|
|
|
#else
|
2011-02-11 20:02:08 +00:00
|
|
|
else if (initMessage.login.present == login_PR_unauthenticatedLogin) {
|
2009-11-14 15:04:31 +00:00
|
|
|
const UnauthenticatedLogin_t *noauthLogin = &initMessage.login.choice.unauthenticatedLogin;
|
|
|
|
|
playerName = STL_STRING_FROM_OCTET_STRING(noauthLogin->nickName);
|
|
|
|
|
if (noauthLogin->avatar)
|
2009-12-28 12:16:52 +00:00
|
|
|
memcpy(avatarMD5.GetData(), noauthLogin->avatar->buf, MD5_DATA_SIZE);
|
2009-11-14 15:04:31 +00:00
|
|
|
noAuth = true;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
2011-02-11 20:02:08 +00:00
|
|
|
else {
|
2009-09-26 16:05:35 +00:00
|
|
|
SessionError(session, ERR_NET_INVALID_PASSWORD);
|
2009-11-15 09:02:00 +00:00
|
|
|
return;
|
|
|
|
|
}
|
2009-08-02 15:11:40 +00:00
|
|
|
|
2007-11-16 15:24:25 +00:00
|
|
|
// Check whether the player name is correct.
|
|
|
|
|
// Partly, this is also done in netpacket.
|
|
|
|
|
// However, some disallowed names are checked only here.
|
2009-08-02 15:11:40 +00:00
|
|
|
if (playerName.empty()
|
2011-02-11 20:02:08 +00:00
|
|
|
|| playerName[0] == '#'
|
|
|
|
|
|| playerName[0] == ' '
|
|
|
|
|
|| playerName.substr(0, sizeof(SERVER_COMPUTER_PLAYER_NAME) - 1) == SERVER_COMPUTER_PLAYER_NAME) {
|
2007-11-16 15:24:25 +00:00
|
|
|
SessionError(session, ERR_NET_INVALID_PLAYER_NAME);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2009-04-07 22:04:38 +00:00
|
|
|
// Check whether the player name is banned.
|
2011-02-11 20:02:08 +00:00
|
|
|
if (GetBanManager().IsPlayerBanned(playerName)) {
|
2009-04-07 22:04:38 +00:00
|
|
|
SessionError(session, ERR_NET_PLAYER_BANNED);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2009-04-11 11:03:22 +00:00
|
|
|
// Check whether the peer IP address is banned.
|
2011-03-10 20:55:46 +00:00
|
|
|
if (GetBanManager().IsIPAddressBanned(session->GetClientAddr())) {
|
2009-04-11 11:03:22 +00:00
|
|
|
SessionError(session, ERR_NET_PLAYER_BANNED);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2009-04-07 22:04:38 +00:00
|
|
|
|
2007-11-16 15:24:25 +00:00
|
|
|
// Create player data object.
|
|
|
|
|
boost::shared_ptr<PlayerData> tmpPlayerData(
|
2010-03-26 21:41:35 +00:00
|
|
|
new PlayerData(GetNextUniquePlayerId(), 0, PLAYER_TYPE_HUMAN, validGuest ? PLAYER_RIGHTS_GUEST : PLAYER_RIGHTS_NORMAL, false));
|
2009-08-02 15:11:40 +00:00
|
|
|
tmpPlayerData->SetName(playerName);
|
|
|
|
|
tmpPlayerData->SetAvatarMD5(avatarMD5);
|
2011-10-03 08:03:58 +00:00
|
|
|
if (initMessage.myLastSessionId) {
|
2011-09-11 17:41:56 +00:00
|
|
|
tmpPlayerData->SetOldGuid(STL_STRING_FROM_OCTET_STRING(*initMessage.myLastSessionId));
|
2011-08-28 17:14:03 +00:00
|
|
|
}
|
2007-11-16 15:24:25 +00:00
|
|
|
|
|
|
|
|
// Set player data for session.
|
2011-03-10 20:55:46 +00:00
|
|
|
m_sessionManager.SetSessionPlayerData(session->GetId(), tmpPlayerData);
|
|
|
|
|
session->SetPlayerData(tmpPlayerData);
|
2007-11-16 15:24:25 +00:00
|
|
|
|
2009-11-14 15:04:31 +00:00
|
|
|
if (noAuth)
|
2009-09-19 21:01:51 +00:00
|
|
|
InitAfterLogin(session);
|
2007-11-16 15:24:25 +00:00
|
|
|
else
|
2009-10-18 20:53:58 +00:00
|
|
|
AuthenticatePlayer(session);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2011-03-10 20:55:46 +00:00
|
|
|
ServerLobbyThread::HandleNetPacketAuthClientResponse(boost::shared_ptr<SessionData> session, const AuthClientResponse_t &clientResponse)
|
2009-10-18 20:53:58 +00:00
|
|
|
{
|
2011-03-10 20:55:46 +00:00
|
|
|
if (session && session->GetPlayerData() && session->AuthGetCurStepNum() == 1) {
|
2009-10-24 21:49:11 +00:00
|
|
|
string authData = STL_STRING_FROM_OCTET_STRING(clientResponse.clientResponse);
|
2011-03-10 20:55:46 +00:00
|
|
|
if (session->AuthStep(2, authData)) {
|
|
|
|
|
string outVerification(session->AuthGetNextOutMsg());
|
2009-10-18 20:53:58 +00:00
|
|
|
|
|
|
|
|
boost::shared_ptr<NetPacket> packet(new NetPacket(NetPacket::Alloc));
|
|
|
|
|
packet->GetMsg()->present = PokerTHMessage_PR_authMessage;
|
|
|
|
|
AuthMessage_t *netAuth = &packet->GetMsg()->choice.authMessage;
|
|
|
|
|
netAuth->present = AuthMessage_PR_authServerVerification;
|
|
|
|
|
AuthServerVerification_t *verification = &netAuth->choice.authServerVerification;
|
|
|
|
|
OCTET_STRING_fromBuf(
|
|
|
|
|
&verification->serverVerification,
|
|
|
|
|
(char *)outVerification.c_str(),
|
2011-04-10 10:04:42 +00:00
|
|
|
(int)outVerification.size());
|
2011-03-10 20:55:46 +00:00
|
|
|
GetSender().Send(session, packet);
|
2009-10-18 20:53:58 +00:00
|
|
|
// The last message is only for server verification.
|
|
|
|
|
// We are done now, the user has logged in.
|
2011-01-09 00:22:00 +00:00
|
|
|
CheckAvatarBlacklist(session);
|
2011-02-11 20:02:08 +00:00
|
|
|
} else
|
2009-10-18 20:53:58 +00:00
|
|
|
SessionError(session, ERR_NET_INVALID_PASSWORD);
|
|
|
|
|
}
|
2007-11-16 15:24:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2011-03-10 20:55:46 +00:00
|
|
|
ServerLobbyThread::HandleNetPacketAvatarHeader(boost::shared_ptr<SessionData> session, unsigned /*requestId*/, const AvatarHeader_t &avatarHeader)
|
2007-11-16 15:24:25 +00:00
|
|
|
{
|
2011-03-10 20:55:46 +00:00
|
|
|
if (session->GetPlayerData()) {
|
2011-02-11 20:02:08 +00:00
|
|
|
if (avatarHeader.avatarSize >= MIN_AVATAR_FILE_SIZE && avatarHeader.avatarSize <= MAX_AVATAR_FILE_SIZE) {
|
2009-08-02 15:11:40 +00:00
|
|
|
boost::shared_ptr<AvatarFile> tmpAvatarFile(new AvatarFile);
|
|
|
|
|
tmpAvatarFile->fileData.reserve(avatarHeader.avatarSize);
|
|
|
|
|
tmpAvatarFile->fileType = static_cast<AvatarFileType>(avatarHeader.avatarType);
|
|
|
|
|
tmpAvatarFile->reportedSize = avatarHeader.avatarSize;
|
2007-11-16 15:24:25 +00:00
|
|
|
// Ignore request id for now.
|
|
|
|
|
|
2011-03-10 20:55:46 +00:00
|
|
|
session->GetPlayerData()->SetNetAvatarFile(tmpAvatarFile);
|
2007-11-16 15:24:25 +00:00
|
|
|
|
|
|
|
|
// Session is now receiving an avatar.
|
2011-03-10 20:55:46 +00:00
|
|
|
session->SetState(SessionData::ReceivingAvatar);
|
2011-02-11 20:02:08 +00:00
|
|
|
} else
|
2007-11-16 15:24:25 +00:00
|
|
|
SessionError(session, ERR_NET_AVATAR_TOO_LARGE);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2011-03-10 20:55:46 +00:00
|
|
|
ServerLobbyThread::HandleNetPacketUnknownAvatar(boost::shared_ptr<SessionData> session, unsigned /*requestId*/, const UnknownAvatar_t &/*unknownAvatar*/)
|
2007-11-16 15:24:25 +00:00
|
|
|
{
|
2011-03-10 20:55:46 +00:00
|
|
|
if (session->GetPlayerData()) {
|
2007-11-16 15:24:25 +00:00
|
|
|
// Free memory (just in case).
|
2011-03-10 20:55:46 +00:00
|
|
|
session->GetPlayerData()->SetNetAvatarFile(boost::shared_ptr<AvatarFile>());
|
|
|
|
|
session->GetPlayerData()->SetAvatarMD5(MD5Buf());
|
2007-11-16 15:24:25 +00:00
|
|
|
// Start session.
|
|
|
|
|
EstablishSession(session);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2011-03-10 20:55:46 +00:00
|
|
|
ServerLobbyThread::HandleNetPacketAvatarFile(boost::shared_ptr<SessionData> session, unsigned /*requestId*/, const AvatarData_t &avatarData)
|
2007-11-16 15:24:25 +00:00
|
|
|
{
|
2011-03-10 20:55:46 +00:00
|
|
|
if (session->GetPlayerData()) {
|
|
|
|
|
boost::shared_ptr<AvatarFile> tmpAvatar = session->GetPlayerData()->GetNetAvatarFile();
|
2011-02-11 20:02:08 +00:00
|
|
|
if (tmpAvatar.get() && tmpAvatar->fileData.size() + avatarData.avatarBlock.size <= tmpAvatar->reportedSize) {
|
2009-08-02 15:11:40 +00:00
|
|
|
std::copy(&avatarData.avatarBlock.buf[0], &avatarData.avatarBlock.buf[avatarData.avatarBlock.size], back_inserter(tmpAvatar->fileData));
|
2007-11-16 15:24:25 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2011-03-10 20:55:46 +00:00
|
|
|
ServerLobbyThread::HandleNetPacketAvatarEnd(boost::shared_ptr<SessionData> session, unsigned /*requestId*/, const AvatarEnd_t &/*avatarEnd*/)
|
2007-11-16 15:24:25 +00:00
|
|
|
{
|
2011-03-10 20:55:46 +00:00
|
|
|
if (session->GetPlayerData()) {
|
|
|
|
|
boost::shared_ptr<AvatarFile> tmpAvatar = session->GetPlayerData()->GetNetAvatarFile();
|
|
|
|
|
MD5Buf avatarMD5 = session->GetPlayerData()->GetAvatarMD5();
|
2011-02-11 20:02:08 +00:00
|
|
|
if (!avatarMD5.IsZero() && tmpAvatar.get()) {
|
2007-11-16 15:24:25 +00:00
|
|
|
unsigned avatarSize = (unsigned)tmpAvatar->fileData.size();
|
2011-02-11 20:02:08 +00:00
|
|
|
if (avatarSize == tmpAvatar->reportedSize) {
|
|
|
|
|
if (!GetAvatarManager().StoreAvatarInCache(avatarMD5, tmpAvatar->fileType, &tmpAvatar->fileData[0], avatarSize, true)) {
|
2011-03-10 20:55:46 +00:00
|
|
|
session->GetPlayerData()->SetAvatarMD5(MD5Buf());
|
2007-11-16 15:24:25 +00:00
|
|
|
LOG_ERROR("Failed to store avatar in cache directory.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Free memory.
|
2011-03-10 20:55:46 +00:00
|
|
|
session->GetPlayerData()->SetNetAvatarFile(boost::shared_ptr<AvatarFile>());
|
2009-03-22 00:39:25 +00:00
|
|
|
// Set avatar file name.
|
|
|
|
|
string avatarFileName;
|
|
|
|
|
if (GetAvatarManager().GetAvatarFileName(avatarMD5, avatarFileName))
|
2011-03-10 20:55:46 +00:00
|
|
|
session->GetPlayerData()->SetAvatarFile(avatarFileName);
|
2007-11-16 15:24:25 +00:00
|
|
|
// Init finished - start session.
|
|
|
|
|
EstablishSession(session);
|
2011-03-10 20:55:46 +00:00
|
|
|
LOG_MSG("Client \"" << session->GetClientAddr() << "\" uploaded avatar \""
|
2011-02-11 20:02:08 +00:00
|
|
|
<< boost::filesystem::path(avatarFileName).file_string() << "\".");
|
|
|
|
|
} else
|
2007-11-16 15:24:25 +00:00
|
|
|
SessionError(session, ERR_NET_WRONG_AVATAR_SIZE);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2011-03-10 20:55:46 +00:00
|
|
|
ServerLobbyThread::HandleNetPacketRetrievePlayerInfo(boost::shared_ptr<SessionData> session, const PlayerInfoRequestMessage_t &playerInfoRequest)
|
2007-11-16 15:24:25 +00:00
|
|
|
{
|
|
|
|
|
// Find player in lobby or in a game.
|
2011-03-10 20:55:46 +00:00
|
|
|
boost::shared_ptr<SessionData> tmpSession = m_sessionManager.GetSessionByUniquePlayerId(playerInfoRequest.playerId);
|
|
|
|
|
if (!tmpSession) {
|
|
|
|
|
tmpSession = m_gameSessionManager.GetSessionByUniquePlayerId(playerInfoRequest.playerId);
|
|
|
|
|
}
|
|
|
|
|
boost::shared_ptr<PlayerData> tmpPlayer;
|
|
|
|
|
if (tmpSession) {
|
|
|
|
|
tmpPlayer = tmpSession->GetPlayerData();
|
|
|
|
|
}
|
|
|
|
|
|
2011-02-11 20:02:08 +00:00
|
|
|
if (!tmpPlayer) {
|
2007-11-16 15:24:25 +00:00
|
|
|
boost::mutex::scoped_lock lock(m_computerPlayersMutex);
|
2009-08-02 15:11:40 +00:00
|
|
|
PlayerDataMap::const_iterator pos = m_computerPlayers.find(playerInfoRequest.playerId);
|
2007-11-16 15:24:25 +00:00
|
|
|
if (pos != m_computerPlayers.end())
|
|
|
|
|
tmpPlayer = pos->second;
|
|
|
|
|
}
|
|
|
|
|
|
2009-08-02 15:11:40 +00:00
|
|
|
boost::shared_ptr<NetPacket> packet(new NetPacket(NetPacket::Alloc));
|
|
|
|
|
packet->GetMsg()->present = PokerTHMessage_PR_playerInfoReplyMessage;
|
|
|
|
|
PlayerInfoReplyMessage_t *netPlayerInfoReply = &packet->GetMsg()->choice.playerInfoReplyMessage;
|
2010-07-25 09:31:13 +00:00
|
|
|
netPlayerInfoReply->playerId = playerInfoRequest.playerId;
|
2009-08-02 15:11:40 +00:00
|
|
|
|
2011-02-11 20:02:08 +00:00
|
|
|
if (tmpPlayer) {
|
2007-11-16 15:24:25 +00:00
|
|
|
// Send player info to client.
|
2009-08-02 15:11:40 +00:00
|
|
|
netPlayerInfoReply->playerInfoResult.present = playerInfoResult_PR_playerInfoData;
|
|
|
|
|
PlayerInfoData *data = &netPlayerInfoReply->playerInfoResult.choice.playerInfoData;
|
|
|
|
|
|
|
|
|
|
data->isHuman = tmpPlayer->GetType() == PLAYER_TYPE_HUMAN;
|
2010-03-24 15:54:04 +00:00
|
|
|
data->playerRights = static_cast<PlayerInfoRights>(tmpPlayer->GetRights());
|
2009-08-02 15:11:40 +00:00
|
|
|
OCTET_STRING_fromBuf(
|
|
|
|
|
&data->playerName,
|
|
|
|
|
tmpPlayer->GetName().c_str(),
|
2011-04-10 10:04:42 +00:00
|
|
|
(int)tmpPlayer->GetName().length());
|
2011-02-11 20:02:08 +00:00
|
|
|
if (!tmpPlayer->GetCountry().empty()) {
|
2010-04-01 17:09:49 +00:00
|
|
|
data->countryCode = OCTET_STRING_new_fromBuf(
|
2011-02-11 20:02:08 +00:00
|
|
|
&asn_DEF_UTF8String,
|
|
|
|
|
tmpPlayer->GetCountry().c_str(),
|
2011-04-10 10:04:42 +00:00
|
|
|
(int)tmpPlayer->GetCountry().length());
|
2010-04-01 17:09:49 +00:00
|
|
|
}
|
2011-02-11 20:02:08 +00:00
|
|
|
if (!tmpPlayer->GetAvatarMD5().IsZero()) {
|
2009-08-02 15:11:40 +00:00
|
|
|
data->avatarData = (struct PlayerInfoData::avatarData *)calloc(1, sizeof(struct PlayerInfoData::avatarData));
|
|
|
|
|
data->avatarData->avatarType = static_cast<NetAvatarType_t>(AvatarManager::GetAvatarFileType(tmpPlayer->GetAvatarFile()));
|
|
|
|
|
OCTET_STRING_fromBuf(
|
|
|
|
|
&data->avatarData->avatar,
|
2009-12-28 12:16:52 +00:00
|
|
|
(char *)tmpPlayer->GetAvatarMD5().GetData(),
|
2009-08-02 15:11:40 +00:00
|
|
|
MD5_DATA_SIZE);
|
2009-03-22 00:39:25 +00:00
|
|
|
}
|
2011-02-11 20:02:08 +00:00
|
|
|
} else {
|
2007-11-16 15:24:25 +00:00
|
|
|
// Unknown player id - notify client.
|
2009-08-02 15:11:40 +00:00
|
|
|
netPlayerInfoReply->playerInfoResult.present = playerInfoResult_PR_unknownPlayerInfo;
|
2007-11-16 15:24:25 +00:00
|
|
|
}
|
2011-03-10 20:55:46 +00:00
|
|
|
GetSender().Send(session, packet);
|
2007-11-16 15:24:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2011-03-10 20:55:46 +00:00
|
|
|
ServerLobbyThread::HandleNetPacketRetrieveAvatar(boost::shared_ptr<SessionData> session, const AvatarRequestMessage_t &retrieveAvatar)
|
2007-11-16 15:24:25 +00:00
|
|
|
{
|
|
|
|
|
bool avatarFound = false;
|
|
|
|
|
|
|
|
|
|
string tmpFile;
|
2009-08-02 15:11:40 +00:00
|
|
|
MD5Buf tmpMD5;
|
2009-12-28 12:16:52 +00:00
|
|
|
memcpy(tmpMD5.GetData(), retrieveAvatar.avatar.buf, MD5_DATA_SIZE);
|
2011-02-11 20:02:08 +00:00
|
|
|
if (GetAvatarManager().GetAvatarFileName(tmpMD5, tmpFile)) {
|
2007-11-16 15:24:25 +00:00
|
|
|
NetPacketList tmpPackets;
|
2011-02-11 20:02:08 +00:00
|
|
|
if (GetAvatarManager().AvatarFileToNetPackets(tmpFile, retrieveAvatar.requestId, tmpPackets) == 0) {
|
2007-11-16 15:24:25 +00:00
|
|
|
avatarFound = true;
|
2011-03-10 20:55:46 +00:00
|
|
|
GetSender().Send(session, tmpPackets);
|
2011-02-11 20:02:08 +00:00
|
|
|
} else
|
2007-11-16 15:24:25 +00:00
|
|
|
LOG_ERROR("Failed to read avatar file for network transmission.");
|
|
|
|
|
}
|
|
|
|
|
|
2011-02-11 20:02:08 +00:00
|
|
|
if (!avatarFound) {
|
2007-11-16 15:24:25 +00:00
|
|
|
// Notify client we didn't find the avatar.
|
2009-08-02 15:11:40 +00:00
|
|
|
boost::shared_ptr<NetPacket> unknownAvatar(new NetPacket(NetPacket::Alloc));
|
|
|
|
|
unknownAvatar->GetMsg()->present = PokerTHMessage_PR_avatarReplyMessage;
|
|
|
|
|
AvatarReplyMessage_t *netAvatarReply = &unknownAvatar->GetMsg()->choice.avatarReplyMessage;
|
|
|
|
|
netAvatarReply->requestId = retrieveAvatar.requestId;
|
|
|
|
|
netAvatarReply->avatarResult.present = avatarResult_PR_unknownAvatar;
|
|
|
|
|
|
2011-03-10 20:55:46 +00:00
|
|
|
GetSender().Send(session, unknownAvatar);
|
2007-11-16 15:24:25 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2011-10-03 08:03:58 +00:00
|
|
|
ServerLobbyThread::HandleNetPacketCreateGame(boost::shared_ptr<SessionData> session, bool autoLeave, const JoinNewGame_t &newGame)
|
2007-11-16 15:24:25 +00:00
|
|
|
{
|
2011-03-10 20:55:46 +00:00
|
|
|
LOG_VERBOSE("Creating new game, initiated by session #" << session->GetId() << ".");
|
2008-03-19 23:39:59 +00:00
|
|
|
|
2011-10-03 08:03:58 +00:00
|
|
|
string password;
|
|
|
|
|
if (newGame.password)
|
|
|
|
|
password = string((char *)newGame.password->buf, newGame.password->size);
|
|
|
|
|
|
2007-11-16 15:24:25 +00:00
|
|
|
// Create a new game.
|
2009-08-02 15:11:40 +00:00
|
|
|
GameData tmpData;
|
|
|
|
|
NetPacket::GetGameData(&newGame.gameInfo, tmpData);
|
2010-07-14 08:17:07 +00:00
|
|
|
string gameName(STL_STRING_FROM_OCTET_STRING(newGame.gameInfo.gameName));
|
2011-10-12 08:37:22 +00:00
|
|
|
// Always trim the game name.
|
|
|
|
|
boost::trim(gameName);
|
2012-02-03 21:34:26 +00:00
|
|
|
boost::replace_all(gameName, "\n", " ");
|
|
|
|
|
boost::replace_all(gameName, "\r", " ");
|
|
|
|
|
boost::replace_all(gameName, "\t", " ");
|
|
|
|
|
boost::replace_all(gameName, "\v", " ");
|
|
|
|
|
boost::replace_all(gameName, "\f", " ");
|
2010-03-31 14:08:46 +00:00
|
|
|
unsigned gameId = GetNextGameId();
|
2009-10-03 18:06:56 +00:00
|
|
|
|
2011-10-12 08:37:22 +00:00
|
|
|
if (gameName.empty() || !isprint(gameName[0])) {
|
|
|
|
|
SendJoinGameFailed(session, gameId, NTF_NET_JOIN_GAME_BAD_NAME);
|
|
|
|
|
} else if (IsGameNameInUse(gameName)) {
|
2011-03-10 20:55:46 +00:00
|
|
|
SendJoinGameFailed(session, gameId, NTF_NET_JOIN_GAME_NAME_IN_USE);
|
2011-02-11 20:02:08 +00:00
|
|
|
} else if (GetBanManager().IsBadGameName(gameName)) {
|
2011-03-10 20:55:46 +00:00
|
|
|
SendJoinGameFailed(session, gameId, NTF_NET_JOIN_GAME_BAD_NAME);
|
|
|
|
|
} else if (session->GetPlayerData()->GetRights() == PLAYER_RIGHTS_GUEST
|
2011-02-11 20:02:08 +00:00
|
|
|
&& tmpData.gameType != GAME_TYPE_NORMAL) {
|
2011-03-10 20:55:46 +00:00
|
|
|
SendJoinGameFailed(session, gameId, NTF_NET_JOIN_GUEST_FORBIDDEN);
|
2011-02-11 20:02:08 +00:00
|
|
|
} else if (!ServerGame::CheckSettings(tmpData, password, GetServerMode())) {
|
2011-03-10 20:55:46 +00:00
|
|
|
SendJoinGameFailed(session, gameId, NTF_NET_JOIN_INVALID_SETTINGS);
|
2011-02-11 20:02:08 +00:00
|
|
|
} else {
|
2010-03-28 14:53:08 +00:00
|
|
|
boost::shared_ptr<ServerGame> game(
|
|
|
|
|
new ServerGame(
|
|
|
|
|
shared_from_this(),
|
2010-03-31 14:08:46 +00:00
|
|
|
gameId,
|
2010-07-14 08:17:07 +00:00
|
|
|
gameName,
|
2010-03-28 14:53:08 +00:00
|
|
|
password,
|
|
|
|
|
tmpData,
|
2011-03-10 20:55:46 +00:00
|
|
|
session->GetPlayerData()->GetUniqueId(),
|
2012-04-08 14:36:14 +00:00
|
|
|
session->GetPlayerData()->GetDBId(),
|
2010-03-28 14:53:08 +00:00
|
|
|
GetGui(),
|
2012-01-02 21:04:49 +00:00
|
|
|
m_serverConfig));
|
2010-03-28 14:53:08 +00:00
|
|
|
game->Init();
|
2009-06-07 23:25:13 +00:00
|
|
|
|
2010-03-28 14:53:08 +00:00
|
|
|
// Add game to list of games.
|
|
|
|
|
InternalAddGame(game);
|
|
|
|
|
|
2011-03-10 21:53:25 +00:00
|
|
|
MoveSessionToGame(game, session, autoLeave);
|
2010-03-28 14:53:08 +00:00
|
|
|
}
|
2007-11-16 15:24:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2011-10-03 08:03:58 +00:00
|
|
|
ServerLobbyThread::HandleNetPacketJoinGame(boost::shared_ptr<SessionData> session, bool autoLeave, const JoinExistingGame_t &joinGame)
|
2007-11-16 15:24:25 +00:00
|
|
|
{
|
2011-10-03 08:03:58 +00:00
|
|
|
string password;
|
|
|
|
|
if (joinGame.password)
|
|
|
|
|
password = string((char *)joinGame.password->buf, joinGame.password->size);
|
|
|
|
|
|
2007-11-16 15:24:25 +00:00
|
|
|
// Join an existing game.
|
2009-08-02 15:11:40 +00:00
|
|
|
GameMap::iterator pos = m_gameMap.find(joinGame.gameId);
|
2007-11-16 15:24:25 +00:00
|
|
|
|
2011-02-11 20:02:08 +00:00
|
|
|
if (pos != m_gameMap.end()) {
|
2011-03-10 21:53:25 +00:00
|
|
|
boost::shared_ptr<ServerGame> game = pos->second;
|
|
|
|
|
const GameData &tmpData = game->GetGameData();
|
2011-03-10 20:55:46 +00:00
|
|
|
if (session->GetPlayerData()->GetRights() == PLAYER_RIGHTS_GUEST
|
2011-02-11 20:02:08 +00:00
|
|
|
&& tmpData.gameType != GAME_TYPE_NORMAL) {
|
2011-03-10 20:55:46 +00:00
|
|
|
SendJoinGameFailed(session, joinGame.gameId, NTF_NET_JOIN_GUEST_FORBIDDEN);
|
2011-02-11 20:02:08 +00:00
|
|
|
} else if (tmpData.gameType == GAME_TYPE_INVITE_ONLY
|
2011-03-10 21:53:25 +00:00
|
|
|
&& !game->IsPlayerInvited(session->GetPlayerData()->GetUniqueId())) {
|
2011-03-10 20:55:46 +00:00
|
|
|
SendJoinGameFailed(session, joinGame.gameId, NTF_NET_JOIN_NOT_INVITED);
|
2011-03-10 21:53:25 +00:00
|
|
|
} else if (!game->CheckPassword(password)) {
|
2011-03-10 20:55:46 +00:00
|
|
|
SendJoinGameFailed(session, joinGame.gameId, NTF_NET_JOIN_INVALID_PASSWORD);
|
2011-02-11 20:02:08 +00:00
|
|
|
} else if (tmpData.gameType == GAME_TYPE_RANKING
|
2011-03-10 20:55:46 +00:00
|
|
|
&& session->GetClientAddr() != SERVER_ADDRESS_LOCALHOST_STR
|
|
|
|
|
&& session->GetClientAddr() != SERVER_ADDRESS_LOCALHOST_STR_V4V6
|
|
|
|
|
&& session->GetClientAddr() != SERVER_ADDRESS_LOCALHOST_STR_V4
|
2011-03-10 21:53:25 +00:00
|
|
|
&& game->IsClientAddressConnected(session->GetClientAddr())) {
|
2011-03-10 20:55:46 +00:00
|
|
|
SendJoinGameFailed(session, joinGame.gameId, NTF_NET_JOIN_IP_BLOCKED);
|
2011-02-11 20:02:08 +00:00
|
|
|
} else {
|
2011-02-06 13:17:07 +00:00
|
|
|
MoveSessionToGame(game, session, autoLeave);
|
2010-08-01 20:15:49 +00:00
|
|
|
}
|
2011-02-11 20:02:08 +00:00
|
|
|
} else {
|
2011-03-10 20:55:46 +00:00
|
|
|
SendJoinGameFailed(session, joinGame.gameId, NTF_NET_JOIN_GAME_INVALID);
|
2007-11-16 15:24:25 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-09-11 17:41:56 +00:00
|
|
|
void
|
|
|
|
|
ServerLobbyThread::HandleNetPacketRejoinGame(boost::shared_ptr<SessionData> session, bool autoLeave, const RejoinExistingGame_t &rejoinGame)
|
|
|
|
|
{
|
|
|
|
|
// Rejoin a running game.
|
|
|
|
|
GameMap::iterator pos = m_gameMap.find(rejoinGame.gameId);
|
|
|
|
|
|
|
|
|
|
if (pos != m_gameMap.end()) {
|
|
|
|
|
boost::shared_ptr<ServerGame> game = pos->second;
|
2011-09-11 20:38:18 +00:00
|
|
|
MoveSessionToGame(game, session, autoLeave);
|
2011-09-11 17:41:56 +00:00
|
|
|
} else {
|
|
|
|
|
SendJoinGameFailed(session, rejoinGame.gameId, NTF_NET_JOIN_GAME_INVALID);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-08-15 10:25:13 +00:00
|
|
|
void
|
2011-03-10 20:55:46 +00:00
|
|
|
ServerLobbyThread::HandleNetPacketChatRequest(boost::shared_ptr<SessionData> session, const ChatRequestMessage_t &chatRequest)
|
2009-08-15 10:25:13 +00:00
|
|
|
{
|
2011-02-17 23:57:58 +00:00
|
|
|
bool chatSent = false;
|
2010-11-07 08:24:31 +00:00
|
|
|
// Guests are not allowed to chat.
|
2011-03-10 20:55:46 +00:00
|
|
|
if (session->GetPlayerData() && session->GetPlayerData()->GetRights() != PLAYER_RIGHTS_GUEST) {
|
2011-02-11 20:02:08 +00:00
|
|
|
if (chatRequest.chatRequestType.present == chatRequestType_PR_chatRequestTypeLobby) {
|
2010-11-07 08:24:31 +00:00
|
|
|
boost::shared_ptr<NetPacket> packet(new NetPacket(NetPacket::Alloc));
|
|
|
|
|
packet->GetMsg()->present = PokerTHMessage_PR_chatMessage;
|
|
|
|
|
ChatMessage_t *netChat = &packet->GetMsg()->choice.chatMessage;
|
|
|
|
|
netChat->chatType.present = chatType_PR_chatTypeLobby;
|
|
|
|
|
ChatTypeLobby_t *netLobbyChat = &netChat->chatType.choice.chatTypeLobby;
|
2011-03-10 20:55:46 +00:00
|
|
|
netLobbyChat->playerId = session->GetPlayerData()->GetUniqueId();
|
2010-11-07 08:24:31 +00:00
|
|
|
OCTET_STRING_fromBuf(
|
|
|
|
|
&netChat->chatText,
|
|
|
|
|
(char *)chatRequest.chatText.buf,
|
|
|
|
|
chatRequest.chatText.size);
|
2009-08-15 10:25:13 +00:00
|
|
|
|
2010-11-07 08:24:31 +00:00
|
|
|
m_sessionManager.SendLobbyMsgToAllSessions(GetSender(), packet, SessionData::Established);
|
|
|
|
|
m_gameSessionManager.SendLobbyMsgToAllSessions(GetSender(), packet, SessionData::Game);
|
2009-08-20 11:42:13 +00:00
|
|
|
|
2010-11-07 08:24:31 +00:00
|
|
|
string chatMsg = STL_STRING_FROM_OCTET_STRING(chatRequest.chatText);
|
|
|
|
|
// Send the message to the chat cleaner bot.
|
2011-01-30 18:28:44 +00:00
|
|
|
m_chatCleanerManager->HandleLobbyChatText(
|
2011-03-10 20:55:46 +00:00
|
|
|
session->GetPlayerData()->GetUniqueId(),
|
|
|
|
|
session->GetPlayerData()->GetName(),
|
2010-11-07 08:24:31 +00:00
|
|
|
chatMsg);
|
|
|
|
|
// Send the message to the irc bot.
|
|
|
|
|
GetIrcBotCallback().SignalLobbyMessage(
|
2011-03-10 20:55:46 +00:00
|
|
|
session->GetPlayerData()->GetUniqueId(),
|
|
|
|
|
session->GetPlayerData()->GetName(),
|
2010-11-07 08:24:31 +00:00
|
|
|
chatMsg);
|
2011-02-17 23:57:58 +00:00
|
|
|
chatSent = true;
|
2011-02-11 20:02:08 +00:00
|
|
|
} else if (chatRequest.chatRequestType.present == chatRequestType_PR_chatRequestTypePrivate) {
|
2010-11-07 08:24:31 +00:00
|
|
|
const ChatRequestTypePrivate_t *netPrivateChat = &chatRequest.chatRequestType.choice.chatRequestTypePrivate;
|
2011-03-10 20:55:46 +00:00
|
|
|
boost::shared_ptr<SessionData> targetSession = m_sessionManager.GetSessionByUniquePlayerId(netPrivateChat->targetPlayerId);
|
|
|
|
|
if (!targetSession)
|
2010-11-07 08:24:31 +00:00
|
|
|
targetSession = m_gameSessionManager.GetSessionByUniquePlayerId(netPrivateChat->targetPlayerId);
|
|
|
|
|
|
2011-03-10 20:55:46 +00:00
|
|
|
if (targetSession && targetSession->GetPlayerData()) {
|
2010-11-07 08:24:31 +00:00
|
|
|
// Only allow private messages to players which are not in running games.
|
2011-03-10 21:53:25 +00:00
|
|
|
boost::shared_ptr<ServerGame> tmpGame = targetSession->GetGame();
|
|
|
|
|
if (!tmpGame || !tmpGame->IsRunning()) {
|
2010-11-07 08:24:31 +00:00
|
|
|
boost::shared_ptr<NetPacket> packet(new NetPacket(NetPacket::Alloc));
|
|
|
|
|
packet->GetMsg()->present = PokerTHMessage_PR_chatMessage;
|
|
|
|
|
ChatMessage_t *netChat = &packet->GetMsg()->choice.chatMessage;
|
2011-02-11 23:02:29 +00:00
|
|
|
netChat->chatType.present = chatType_PR_chatTypePrivate;
|
|
|
|
|
ChatTypePrivate_t *netPrivateChat = &netChat->chatType.choice.chatTypePrivate;
|
2011-03-10 20:55:46 +00:00
|
|
|
netPrivateChat->playerId = session->GetPlayerData()->GetUniqueId();
|
2010-11-07 08:24:31 +00:00
|
|
|
OCTET_STRING_fromBuf(
|
|
|
|
|
&netChat->chatText,
|
|
|
|
|
(char *)chatRequest.chatText.buf,
|
|
|
|
|
chatRequest.chatText.size);
|
2011-03-10 20:55:46 +00:00
|
|
|
GetSender().Send(targetSession, packet);
|
2011-02-17 23:57:58 +00:00
|
|
|
chatSent = true;
|
2010-11-07 08:24:31 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2009-08-15 10:25:13 +00:00
|
|
|
}
|
2011-02-17 23:57:58 +00:00
|
|
|
// Other chat types are not allowed in the lobby.
|
|
|
|
|
if (!chatSent) {
|
|
|
|
|
boost::shared_ptr<NetPacket> packet(new NetPacket(NetPacket::Alloc));
|
|
|
|
|
packet->GetMsg()->present = PokerTHMessage_PR_chatRejectMessage;
|
|
|
|
|
ChatRejectMessage_t *netReject = &packet->GetMsg()->choice.chatRejectMessage;
|
|
|
|
|
OCTET_STRING_fromBuf(
|
|
|
|
|
&netReject->chatText,
|
|
|
|
|
(char *)chatRequest.chatText.buf,
|
|
|
|
|
chatRequest.chatText.size);
|
2011-03-10 20:55:46 +00:00
|
|
|
GetSender().Send(session, packet);
|
2011-02-17 23:57:58 +00:00
|
|
|
}
|
2009-08-15 10:25:13 +00:00
|
|
|
}
|
|
|
|
|
|
2010-03-30 17:10:37 +00:00
|
|
|
void
|
2011-03-10 20:55:46 +00:00
|
|
|
ServerLobbyThread::HandleNetPacketRejectGameInvitation(boost::shared_ptr<SessionData> session, const RejectGameInvitationMessage_t &reject)
|
2010-03-30 17:10:37 +00:00
|
|
|
{
|
|
|
|
|
GameMap::iterator pos = m_gameMap.find(reject.gameId);
|
|
|
|
|
|
2011-03-10 20:55:46 +00:00
|
|
|
if (pos != m_gameMap.end() && session->GetPlayerData()) {
|
2010-03-30 17:10:37 +00:00
|
|
|
ServerGame &game = *pos->second;
|
2011-03-10 20:55:46 +00:00
|
|
|
unsigned tmpPlayerId = session->GetPlayerData()->GetUniqueId();
|
2011-02-11 20:02:08 +00:00
|
|
|
if (game.IsPlayerInvited(tmpPlayerId)) {
|
2010-03-31 13:00:41 +00:00
|
|
|
// If he rejects, he is no longer invited.
|
|
|
|
|
game.RemovePlayerInvitation(tmpPlayerId);
|
|
|
|
|
// Send reject notification.
|
2010-03-30 17:10:37 +00:00
|
|
|
boost::shared_ptr<NetPacket> packet(new NetPacket(NetPacket::Alloc));
|
|
|
|
|
packet->GetMsg()->present = PokerTHMessage_PR_rejectInvNotifyMessage;
|
|
|
|
|
RejectInvNotifyMessage_t *netReject = &packet->GetMsg()->choice.rejectInvNotifyMessage;
|
|
|
|
|
netReject->gameId = reject.gameId;
|
2010-03-31 13:00:41 +00:00
|
|
|
netReject->playerId = tmpPlayerId;
|
2010-03-30 17:10:37 +00:00
|
|
|
netReject->playerRejectReason = reject.myRejectReason;
|
|
|
|
|
|
|
|
|
|
game.SendToAllPlayers(packet, SessionData::Game);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-04-08 14:36:14 +00:00
|
|
|
void
|
|
|
|
|
ServerLobbyThread::HandleNetPacketReportGame(boost::shared_ptr<SessionData> session, const ReportGameMessage_t &report)
|
|
|
|
|
{
|
2012-04-08 16:54:31 +00:00
|
|
|
GameMap::iterator pos = m_gameMap.find(report.reportedGameId);
|
|
|
|
|
|
|
|
|
|
if (pos != m_gameMap.end() && session->GetPlayerData()) {
|
|
|
|
|
if (!IsGameReported(report.reportedGameId)) {
|
|
|
|
|
// Temporarily note that this game was reported.
|
|
|
|
|
// This prevents spamming of the game report.
|
|
|
|
|
AddReportedGame(report.reportedGameId);
|
|
|
|
|
boost::shared_ptr<ServerGame> tmpGame(pos->second);
|
|
|
|
|
unsigned creatorDBId = tmpGame->GetCreatorDBId();
|
|
|
|
|
unsigned reporterDBId = session->GetPlayerData()->GetDBId();
|
|
|
|
|
GetDatabase()->AsyncReportGame(
|
|
|
|
|
session->GetPlayerData()->GetUniqueId(),
|
|
|
|
|
tmpGame->GetId(),
|
|
|
|
|
creatorDBId != 0 ? &creatorDBId : NULL,
|
|
|
|
|
tmpGame->GetId(),
|
|
|
|
|
tmpGame->GetName(),
|
|
|
|
|
reporterDBId != 0 ? &reporterDBId : NULL
|
|
|
|
|
);
|
|
|
|
|
} else {
|
|
|
|
|
boost::shared_ptr<NetPacket> packet(new NetPacket(NetPacket::Alloc));
|
|
|
|
|
packet->GetMsg()->present = PokerTHMessage_PR_reportGameAckMessage;
|
|
|
|
|
ReportGameAckMessage_t *netReportAck = &packet->GetMsg()->choice.reportGameAckMessage;
|
|
|
|
|
netReportAck->reportedGameId = report.reportedGameId;
|
|
|
|
|
netReportAck->reportGameResult = reportGameResult_gameReportDuplicate;
|
|
|
|
|
GetSender().Send(session, packet);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
boost::shared_ptr<NetPacket> packet(new NetPacket(NetPacket::Alloc));
|
|
|
|
|
packet->GetMsg()->present = PokerTHMessage_PR_reportGameAckMessage;
|
|
|
|
|
ReportGameAckMessage_t *netReportAck = &packet->GetMsg()->choice.reportGameAckMessage;
|
|
|
|
|
netReportAck->reportedGameId = report.reportedGameId;
|
|
|
|
|
netReportAck->reportGameResult = reportGameResult_gameReportInvalid;
|
|
|
|
|
GetSender().Send(session, packet);
|
|
|
|
|
}
|
2012-04-08 14:36:14 +00:00
|
|
|
}
|
|
|
|
|
|
2009-10-18 20:53:58 +00:00
|
|
|
void
|
2011-03-10 20:55:46 +00:00
|
|
|
ServerLobbyThread::AuthChallenge(boost::shared_ptr<SessionData> session, const string &secret)
|
2009-10-18 20:53:58 +00:00
|
|
|
{
|
2011-03-10 20:55:46 +00:00
|
|
|
if (session && session->GetPlayerData() && session->AuthGetCurStepNum() == 1) {
|
|
|
|
|
session->AuthSetPassword(secret); // For this auth session.
|
|
|
|
|
string outChallenge(session->AuthGetNextOutMsg());
|
2009-10-18 20:53:58 +00:00
|
|
|
|
|
|
|
|
boost::shared_ptr<NetPacket> packet(new NetPacket(NetPacket::Alloc));
|
|
|
|
|
packet->GetMsg()->present = PokerTHMessage_PR_authMessage;
|
|
|
|
|
AuthMessage_t *netAuth = &packet->GetMsg()->choice.authMessage;
|
|
|
|
|
netAuth->present = AuthMessage_PR_authServerChallenge;
|
|
|
|
|
AuthServerChallenge_t *challenge = &netAuth->choice.authServerChallenge;
|
|
|
|
|
OCTET_STRING_fromBuf(
|
|
|
|
|
&challenge->serverChallenge,
|
|
|
|
|
(char *)outChallenge.c_str(),
|
2011-04-10 10:56:16 +00:00
|
|
|
(int)outChallenge.size());
|
2011-03-10 20:55:46 +00:00
|
|
|
GetSender().Send(session, packet);
|
2009-10-18 20:53:58 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-01-09 00:22:00 +00:00
|
|
|
void
|
2011-03-10 20:55:46 +00:00
|
|
|
ServerLobbyThread::CheckAvatarBlacklist(boost::shared_ptr<SessionData> session)
|
2011-01-09 00:22:00 +00:00
|
|
|
{
|
2011-03-10 20:55:46 +00:00
|
|
|
if (session && session->GetPlayerData()) {
|
|
|
|
|
const MD5Buf &avatarMD5 = session->GetPlayerData()->GetAvatarMD5();
|
2011-01-09 00:22:00 +00:00
|
|
|
if (!avatarMD5.IsZero())
|
2011-03-10 20:55:46 +00:00
|
|
|
m_database->AsyncCheckAvatarBlacklist(session->GetPlayerData()->GetUniqueId(), avatarMD5.ToString());
|
2011-01-09 00:22:00 +00:00
|
|
|
else
|
|
|
|
|
InitAfterLogin(session);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
ServerLobbyThread::AvatarBlacklisted(unsigned playerId)
|
|
|
|
|
{
|
2011-03-10 20:55:46 +00:00
|
|
|
boost::shared_ptr<SessionData> tmpSession = m_sessionManager.GetSessionByUniquePlayerId(playerId, true);
|
|
|
|
|
if (tmpSession && tmpSession->GetPlayerData()) {
|
|
|
|
|
tmpSession->GetPlayerData()->SetAvatarMD5(MD5Buf()); // Reset avatar if blacklisted.
|
2011-01-09 20:50:58 +00:00
|
|
|
InitAfterLogin(tmpSession);
|
|
|
|
|
}
|
2011-01-09 00:22:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
ServerLobbyThread::AvatarOK(unsigned playerId)
|
|
|
|
|
{
|
2011-03-10 20:55:46 +00:00
|
|
|
boost::shared_ptr<SessionData> tmpSession = m_sessionManager.GetSessionByUniquePlayerId(playerId, true);
|
2011-01-09 00:22:00 +00:00
|
|
|
InitAfterLogin(tmpSession);
|
|
|
|
|
}
|
|
|
|
|
|
2009-09-19 21:01:51 +00:00
|
|
|
void
|
2011-03-10 20:55:46 +00:00
|
|
|
ServerLobbyThread::InitAfterLogin(boost::shared_ptr<SessionData> session)
|
2009-09-19 21:01:51 +00:00
|
|
|
{
|
2011-03-10 20:55:46 +00:00
|
|
|
if (session && session->GetPlayerData()) {
|
|
|
|
|
const MD5Buf &avatarMD5 = session->GetPlayerData()->GetAvatarMD5();
|
2009-09-26 16:14:22 +00:00
|
|
|
string avatarFileName;
|
|
|
|
|
if (!avatarMD5.IsZero()
|
2011-02-11 20:02:08 +00:00
|
|
|
&& !GetAvatarManager().GetAvatarFileName(avatarMD5, avatarFileName)) {
|
2009-12-23 09:53:01 +00:00
|
|
|
RequestPlayerAvatar(session);
|
2011-02-11 20:02:08 +00:00
|
|
|
} else {
|
2009-09-26 16:14:22 +00:00
|
|
|
if (!avatarFileName.empty())
|
2011-03-10 20:55:46 +00:00
|
|
|
session->GetPlayerData()->SetAvatarFile(avatarFileName);
|
2009-09-26 16:14:22 +00:00
|
|
|
EstablishSession(session);
|
|
|
|
|
}
|
2009-09-19 21:01:51 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2007-11-16 15:24:25 +00:00
|
|
|
void
|
2011-03-10 20:55:46 +00:00
|
|
|
ServerLobbyThread::EstablishSession(boost::shared_ptr<SessionData> session)
|
2007-11-16 15:24:25 +00:00
|
|
|
{
|
2011-03-10 20:55:46 +00:00
|
|
|
if (!session->GetPlayerData())
|
2007-11-16 15:24:25 +00:00
|
|
|
throw ServerException(__FILE__, __LINE__, ERR_NET_INVALID_SESSION, 0);
|
2010-08-23 17:37:22 +00:00
|
|
|
|
2011-12-27 17:26:03 +00:00
|
|
|
unsigned rejoinPlayerId = 0;
|
2011-09-11 17:41:56 +00:00
|
|
|
u_int32_t rejoinGameId = GetRejoinGameIdForPlayer(session->GetPlayerData()->GetName(), session->GetPlayerData()->GetOldGuid(), rejoinPlayerId);
|
2011-10-03 08:03:58 +00:00
|
|
|
if (rejoinGameId != 0) {
|
2011-08-28 17:14:03 +00:00
|
|
|
// Offer rejoin, and disconnect current player with the same name.
|
|
|
|
|
InternalRemovePlayer(rejoinPlayerId, ERR_NET_PLAYER_NAME_IN_USE);
|
2011-12-27 17:26:03 +00:00
|
|
|
} else {
|
|
|
|
|
// Check whether this player is already connected.
|
|
|
|
|
unsigned previousPlayerId = GetPlayerId(session->GetPlayerData()->GetName());
|
2012-01-05 19:59:35 +00:00
|
|
|
if (previousPlayerId != 0 && previousPlayerId != session->GetPlayerData()->GetUniqueId()) {
|
2012-01-02 10:42:35 +00:00
|
|
|
#ifdef POKERTH_OFFICIAL_SERVER
|
|
|
|
|
// If so, and this is a login server, disconnect the already connected player.
|
2011-12-27 17:26:03 +00:00
|
|
|
InternalRemovePlayer(previousPlayerId, ERR_NET_PLAYER_NAME_IN_USE);
|
|
|
|
|
#else
|
2012-01-02 10:42:35 +00:00
|
|
|
// If this is a server without password protection, close this new session and return.
|
|
|
|
|
SessionError(session, ERR_NET_PLAYER_NAME_IN_USE);
|
|
|
|
|
return;
|
2011-12-27 17:26:03 +00:00
|
|
|
#endif
|
2012-01-02 10:42:35 +00:00
|
|
|
}
|
2011-08-28 17:14:03 +00:00
|
|
|
}
|
|
|
|
|
|
2010-08-23 17:37:22 +00:00
|
|
|
// Run postlogin for DB
|
|
|
|
|
string tmpAvatarHash;
|
|
|
|
|
string tmpAvatarType;
|
2011-03-10 20:55:46 +00:00
|
|
|
if (!session->GetPlayerData()->GetAvatarMD5().IsZero()) {
|
|
|
|
|
tmpAvatarHash = session->GetPlayerData()->GetAvatarMD5().ToString();
|
|
|
|
|
tmpAvatarType = AvatarManager::GetAvatarFileExtension(AvatarManager::GetAvatarFileType(session->GetPlayerData()->GetAvatarFile()));
|
2010-08-23 17:37:22 +00:00
|
|
|
if (!tmpAvatarType.empty())
|
|
|
|
|
tmpAvatarType.erase(0, 1); // Only store extension without the "."
|
|
|
|
|
}
|
2011-03-10 20:55:46 +00:00
|
|
|
m_database->PlayerPostLogin(session->GetPlayerData()->GetDBId(), tmpAvatarHash, tmpAvatarType);
|
2010-08-23 17:37:22 +00:00
|
|
|
|
2011-08-28 17:14:03 +00:00
|
|
|
// Generate a new GUID.
|
|
|
|
|
boost::uuids::uuid sessionGuid(m_sessionIdGenerator());
|
|
|
|
|
session->GetPlayerData()->SetGuid(string((char *)&sessionGuid, boost::uuids::uuid::static_size()));
|
|
|
|
|
|
2007-11-16 15:24:25 +00:00
|
|
|
// Send ACK to client.
|
2009-08-15 13:43:00 +00:00
|
|
|
boost::shared_ptr<NetPacket> ack(new NetPacket(NetPacket::Alloc));
|
|
|
|
|
ack->GetMsg()->present = PokerTHMessage_PR_initAckMessage;
|
|
|
|
|
InitAckMessage_t *netInitAck = &ack->GetMsg()->choice.initAckMessage;
|
2011-02-09 22:09:29 +00:00
|
|
|
OCTET_STRING_fromBuf(
|
|
|
|
|
&netInitAck->yourSessionId,
|
2011-08-28 17:14:03 +00:00
|
|
|
session->GetPlayerData()->GetGuid().c_str(),
|
|
|
|
|
session->GetPlayerData()->GetGuid().size());
|
2011-03-10 20:55:46 +00:00
|
|
|
netInitAck->yourPlayerId = session->GetPlayerData()->GetUniqueId();
|
2011-10-03 08:03:58 +00:00
|
|
|
if (rejoinGameId != 0) {
|
2011-08-28 17:14:03 +00:00
|
|
|
netInitAck->rejoinGameId = (NonZeroId_t *)calloc(1, sizeof(NonZeroId_t));
|
|
|
|
|
*netInitAck->rejoinGameId = rejoinGameId;
|
|
|
|
|
}
|
2011-03-10 20:55:46 +00:00
|
|
|
GetSender().Send(session, ack);
|
2007-11-16 15:24:25 +00:00
|
|
|
|
2009-08-15 13:43:00 +00:00
|
|
|
// Send the connected players list to the client.
|
2011-03-10 20:55:46 +00:00
|
|
|
SendPlayerList(session);
|
2007-11-16 15:24:25 +00:00
|
|
|
// Send the game list to the client.
|
2011-03-10 20:55:46 +00:00
|
|
|
SendGameList(session);
|
2007-11-16 15:24:25 +00:00
|
|
|
|
|
|
|
|
// Session is now established.
|
2011-03-10 20:55:46 +00:00
|
|
|
session->SetState(SessionData::Established);
|
2007-11-16 15:24:25 +00:00
|
|
|
|
|
|
|
|
{
|
|
|
|
|
boost::mutex::scoped_lock lock(m_statMutex);
|
|
|
|
|
++m_statData.totalPlayersEverLoggedIn;
|
|
|
|
|
m_statDataChanged = true;
|
|
|
|
|
}
|
2009-08-15 13:43:00 +00:00
|
|
|
// Notify all players.
|
2011-03-10 20:55:46 +00:00
|
|
|
NotifyPlayerJoinedLobby(session->GetPlayerData()->GetUniqueId());
|
2009-08-15 13:43:00 +00:00
|
|
|
|
2007-11-16 15:24:25 +00:00
|
|
|
UpdateStatisticsNumberOfPlayers();
|
|
|
|
|
}
|
|
|
|
|
|
2009-09-19 21:01:51 +00:00
|
|
|
void
|
2011-03-10 20:55:46 +00:00
|
|
|
ServerLobbyThread::AuthenticatePlayer(boost::shared_ptr<SessionData> session)
|
2009-09-19 21:01:51 +00:00
|
|
|
{
|
2011-03-10 20:55:46 +00:00
|
|
|
if(session->GetPlayerData()) {
|
|
|
|
|
m_database->AsyncPlayerLogin(session->GetPlayerData()->GetUniqueId(), session->GetPlayerData()->GetName());
|
2010-08-22 19:35:43 +00:00
|
|
|
}
|
2009-09-24 20:10:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2010-04-01 16:20:57 +00:00
|
|
|
ServerLobbyThread::UserValid(unsigned playerId, const DBPlayerData &dbPlayerData)
|
2009-09-24 20:10:40 +00:00
|
|
|
{
|
2011-03-10 20:55:46 +00:00
|
|
|
boost::shared_ptr<SessionData> tmpSession = m_sessionManager.GetSessionByUniquePlayerId(playerId, true);
|
|
|
|
|
if (tmpSession && tmpSession->GetPlayerData()) {
|
|
|
|
|
tmpSession->GetPlayerData()->SetDBId(dbPlayerData.id);
|
|
|
|
|
tmpSession->GetPlayerData()->SetCountry(dbPlayerData.country);
|
2010-09-04 16:43:30 +00:00
|
|
|
this->AuthChallenge(tmpSession, dbPlayerData.secret);
|
|
|
|
|
}
|
2009-09-24 20:10:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2009-10-11 12:07:56 +00:00
|
|
|
ServerLobbyThread::UserInvalid(unsigned playerId)
|
2009-09-24 20:10:40 +00:00
|
|
|
{
|
2009-09-26 16:05:35 +00:00
|
|
|
SessionError(m_sessionManager.GetSessionByUniquePlayerId(playerId, true), ERR_NET_INVALID_PASSWORD);
|
2009-09-19 21:01:51 +00:00
|
|
|
}
|
|
|
|
|
|
2010-12-24 16:46:49 +00:00
|
|
|
void
|
|
|
|
|
ServerLobbyThread::SendReportAvatarResult(unsigned byPlayerId, unsigned reportedPlayerId, bool success)
|
|
|
|
|
{
|
2011-03-10 20:55:46 +00:00
|
|
|
boost::shared_ptr<SessionData> session = m_sessionManager.GetSessionByUniquePlayerId(byPlayerId);
|
|
|
|
|
if (!session)
|
2010-12-24 16:46:49 +00:00
|
|
|
session = m_gameSessionManager.GetSessionByUniquePlayerId(byPlayerId);
|
2011-03-10 20:55:46 +00:00
|
|
|
if (session) {
|
2010-12-24 16:46:49 +00:00
|
|
|
boost::shared_ptr<NetPacket> packet(new NetPacket(NetPacket::Alloc));
|
|
|
|
|
packet->GetMsg()->present = PokerTHMessage_PR_reportAvatarAckMessage;
|
|
|
|
|
ReportAvatarAckMessage_t *netReportAck = &packet->GetMsg()->choice.reportAvatarAckMessage;
|
|
|
|
|
netReportAck->reportedPlayerId = reportedPlayerId;
|
2012-03-31 20:14:11 +00:00
|
|
|
netReportAck->reportAvatarResult = success ? reportAvatarResult_avatarReportAccepted : reportAvatarResult_avatarReportInvalid;
|
2011-03-10 20:55:46 +00:00
|
|
|
GetSender().Send(session, packet);
|
2010-12-24 16:46:49 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-14 14:30:16 +00:00
|
|
|
void
|
|
|
|
|
ServerLobbyThread::UserBlocked(unsigned playerId)
|
|
|
|
|
{
|
2010-07-14 15:40:14 +00:00
|
|
|
SessionError(m_sessionManager.GetSessionByUniquePlayerId(playerId, true), ERR_NET_PLAYER_BLOCKED);
|
2010-07-14 14:30:16 +00:00
|
|
|
}
|
|
|
|
|
|
2007-11-16 15:24:25 +00:00
|
|
|
void
|
2011-03-10 20:55:46 +00:00
|
|
|
ServerLobbyThread::RequestPlayerAvatar(boost::shared_ptr<SessionData> session)
|
2007-11-16 15:24:25 +00:00
|
|
|
{
|
2011-03-10 20:55:46 +00:00
|
|
|
if (!session->GetPlayerData())
|
2007-11-16 15:24:25 +00:00
|
|
|
throw ServerException(__FILE__, __LINE__, ERR_NET_INVALID_SESSION, 0);
|
|
|
|
|
// Ask the client to send its avatar.
|
2009-08-02 15:11:40 +00:00
|
|
|
boost::shared_ptr<NetPacket> packet(new NetPacket(NetPacket::Alloc));
|
|
|
|
|
packet->GetMsg()->present = PokerTHMessage_PR_avatarRequestMessage;
|
|
|
|
|
AvatarRequestMessage_t *netAvatarRequest = &packet->GetMsg()->choice.avatarRequestMessage;
|
2011-03-10 20:55:46 +00:00
|
|
|
netAvatarRequest->requestId = session->GetPlayerData()->GetUniqueId();
|
2009-08-02 15:11:40 +00:00
|
|
|
OCTET_STRING_fromBuf(
|
|
|
|
|
&netAvatarRequest->avatar,
|
2011-03-10 20:55:46 +00:00
|
|
|
(char *)session->GetPlayerData()->GetAvatarMD5().GetData(),
|
2009-08-02 15:11:40 +00:00
|
|
|
MD5_DATA_SIZE);
|
2011-03-10 20:55:46 +00:00
|
|
|
GetSender().Send(session, packet);
|
2007-11-16 15:24:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2009-06-12 15:48:34 +00:00
|
|
|
ServerLobbyThread::TimerRemoveGame(const boost::system::error_code &ec)
|
2007-11-16 15:24:25 +00:00
|
|
|
{
|
2011-02-11 20:02:08 +00:00
|
|
|
if (!ec) {
|
2009-06-12 15:48:34 +00:00
|
|
|
// Synchronously remove games which have been closed.
|
|
|
|
|
GameMap::iterator i = m_gameMap.begin();
|
|
|
|
|
GameMap::iterator end = m_gameMap.end();
|
2011-02-11 20:02:08 +00:00
|
|
|
while (i != end) {
|
2009-06-12 15:48:34 +00:00
|
|
|
GameMap::iterator next = i;
|
|
|
|
|
++next;
|
|
|
|
|
boost::shared_ptr<ServerGame> tmpGame = i->second;
|
|
|
|
|
if (!tmpGame->GetSessionManager().HasSessions())
|
|
|
|
|
InternalRemoveGame(tmpGame); // This will delete the game.
|
|
|
|
|
i = next;
|
|
|
|
|
}
|
2009-06-12 16:04:58 +00:00
|
|
|
// Restart timer
|
|
|
|
|
m_removeGameTimer.expires_from_now(
|
|
|
|
|
boost::posix_time::milliseconds(SERVER_REMOVE_GAME_INTERVAL_MSEC));
|
|
|
|
|
m_removeGameTimer.async_wait(
|
|
|
|
|
boost::bind(
|
|
|
|
|
&ServerLobbyThread::TimerRemoveGame, shared_from_this(), boost::asio::placeholders::error));
|
2009-06-12 15:48:34 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2009-12-23 09:53:01 +00:00
|
|
|
ServerLobbyThread::TimerUpdateClientLoginLock(const boost::system::error_code &ec)
|
2009-06-12 15:48:34 +00:00
|
|
|
{
|
2011-02-11 20:02:08 +00:00
|
|
|
if (!ec) {
|
2009-12-23 09:53:01 +00:00
|
|
|
boost::mutex::scoped_lock lock(m_timerClientAddressMapMutex);
|
2009-06-12 15:48:34 +00:00
|
|
|
|
2009-12-23 09:53:01 +00:00
|
|
|
TimerClientAddressMap::iterator i = m_timerClientAddressMap.begin();
|
|
|
|
|
TimerClientAddressMap::iterator end = m_timerClientAddressMap.end();
|
2008-05-11 21:41:30 +00:00
|
|
|
|
2011-02-11 20:02:08 +00:00
|
|
|
while (i != end) {
|
2009-06-12 15:48:34 +00:00
|
|
|
TimerClientAddressMap::iterator next = i;
|
|
|
|
|
++next;
|
2010-10-11 15:44:56 +00:00
|
|
|
if (i->second.elapsed().total_seconds() > (int)SERVER_INIT_LOGIN_CLIENT_LOCK_SEC)
|
2009-12-23 09:53:01 +00:00
|
|
|
m_timerClientAddressMap.erase(i);
|
2009-06-12 15:48:34 +00:00
|
|
|
i = next;
|
2008-05-11 21:41:30 +00:00
|
|
|
}
|
2009-06-12 16:04:58 +00:00
|
|
|
// Restart timer
|
2009-12-23 09:53:01 +00:00
|
|
|
m_loginLockTimer.expires_from_now(
|
|
|
|
|
boost::posix_time::milliseconds(SERVER_UPDATE_LOGIN_LOCK_INTERVAL_MSEC));
|
|
|
|
|
m_loginLockTimer.async_wait(
|
2009-06-12 16:04:58 +00:00
|
|
|
boost::bind(
|
2009-12-23 09:53:01 +00:00
|
|
|
&ServerLobbyThread::TimerUpdateClientLoginLock, shared_from_this(), boost::asio::placeholders::error));
|
2008-05-11 21:41:30 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-14 08:17:07 +00:00
|
|
|
bool
|
|
|
|
|
ServerLobbyThread::IsGameNameInUse(const std::string &gameName) const
|
|
|
|
|
{
|
|
|
|
|
bool found = false;
|
|
|
|
|
GameMap::const_iterator i = m_gameMap.begin();
|
|
|
|
|
GameMap::const_iterator end = m_gameMap.end();
|
|
|
|
|
|
2011-02-11 20:02:08 +00:00
|
|
|
while (i != end) {
|
|
|
|
|
if ((*i).second->GetName() == gameName) {
|
2010-07-14 08:17:07 +00:00
|
|
|
found = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
++i;
|
|
|
|
|
}
|
|
|
|
|
return found;
|
|
|
|
|
}
|
|
|
|
|
|
2009-06-01 10:23:44 +00:00
|
|
|
boost::shared_ptr<ServerGame>
|
|
|
|
|
ServerLobbyThread::InternalGetGameFromId(unsigned gameId)
|
|
|
|
|
{
|
|
|
|
|
boost::shared_ptr<ServerGame> game;
|
2011-02-11 20:02:08 +00:00
|
|
|
if (gameId) {
|
2009-06-01 10:23:44 +00:00
|
|
|
GameMap::iterator pos = m_gameMap.find(gameId);
|
|
|
|
|
|
|
|
|
|
if (pos != m_gameMap.end())
|
|
|
|
|
game = pos->second;
|
|
|
|
|
}
|
|
|
|
|
return game;
|
|
|
|
|
}
|
|
|
|
|
|
2007-11-16 15:24:25 +00:00
|
|
|
void
|
2009-05-31 20:14:46 +00:00
|
|
|
ServerLobbyThread::InternalAddGame(boost::shared_ptr<ServerGame> game)
|
2007-11-16 15:24:25 +00:00
|
|
|
{
|
|
|
|
|
// Add game to list.
|
|
|
|
|
m_gameMap.insert(GameMap::value_type(game->GetId(), game));
|
|
|
|
|
// Notify all players.
|
2009-06-07 08:51:43 +00:00
|
|
|
m_sessionManager.SendLobbyMsgToAllSessions(GetSender(), CreateNetPacketGameListNew(*game), SessionData::Established);
|
|
|
|
|
m_gameSessionManager.SendLobbyMsgToAllSessions(GetSender(), CreateNetPacketGameListNew(*game), SessionData::Game);
|
2007-11-16 15:24:25 +00:00
|
|
|
|
|
|
|
|
{
|
|
|
|
|
boost::mutex::scoped_lock lock(m_statMutex);
|
|
|
|
|
++m_statData.totalGamesEverCreated;
|
2008-04-01 21:44:05 +00:00
|
|
|
++m_statData.numberOfGamesOpen;
|
2007-11-16 15:24:25 +00:00
|
|
|
unsigned numGames = static_cast<unsigned>(m_gameMap.size());
|
|
|
|
|
if (numGames > m_statData.maxGamesOpen)
|
|
|
|
|
m_statData.maxGamesOpen = numGames;
|
|
|
|
|
m_statDataChanged = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2009-05-31 20:14:46 +00:00
|
|
|
ServerLobbyThread::InternalRemoveGame(boost::shared_ptr<ServerGame> game)
|
2007-11-16 15:24:25 +00:00
|
|
|
{
|
2008-04-01 21:44:05 +00:00
|
|
|
{
|
|
|
|
|
boost::mutex::scoped_lock lock(m_statMutex);
|
2011-02-11 20:02:08 +00:00
|
|
|
if (m_statData.numberOfGamesOpen) {
|
2008-04-01 21:44:05 +00:00
|
|
|
--m_statData.numberOfGamesOpen;
|
|
|
|
|
m_statDataChanged = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
2007-11-16 15:24:25 +00:00
|
|
|
// Remove game from list.
|
|
|
|
|
m_gameMap.erase(game->GetId());
|
|
|
|
|
// Remove all sessions left in the game.
|
2009-05-31 19:11:59 +00:00
|
|
|
game->ResetComputerPlayerList();
|
2007-11-16 15:24:25 +00:00
|
|
|
game->RemoveAllSessions();
|
2009-06-07 23:25:13 +00:00
|
|
|
game->Exit();
|
2007-11-16 15:24:25 +00:00
|
|
|
// Notify all players.
|
|
|
|
|
boost::shared_ptr<NetPacket> packet = CreateNetPacketGameListUpdate(game->GetId(), GAME_MODE_CLOSED);
|
2009-06-07 08:51:43 +00:00
|
|
|
m_sessionManager.SendLobbyMsgToAllSessions(GetSender(), packet, SessionData::Established);
|
|
|
|
|
m_gameSessionManager.SendLobbyMsgToAllSessions(GetSender(), packet, SessionData::Game);
|
2007-11-16 15:24:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2008-03-06 15:27:31 +00:00
|
|
|
ServerLobbyThread::InternalRemovePlayer(unsigned playerId, unsigned errorCode)
|
2007-11-16 15:24:25 +00:00
|
|
|
{
|
2011-03-10 20:55:46 +00:00
|
|
|
boost::shared_ptr<SessionData> session = m_sessionManager.GetSessionByUniquePlayerId(playerId, true);
|
|
|
|
|
if (session)
|
2008-03-06 15:27:31 +00:00
|
|
|
SessionError(session, errorCode);
|
2011-02-11 20:02:08 +00:00
|
|
|
else {
|
2012-01-08 13:02:29 +00:00
|
|
|
// Remove player from game.
|
|
|
|
|
boost::shared_ptr<SessionData> session = m_gameSessionManager.GetSessionByUniquePlayerId(playerId);
|
|
|
|
|
if (session) {
|
|
|
|
|
boost::shared_ptr<ServerGame> tmpGame = session->GetGame();
|
|
|
|
|
if (tmpGame) {
|
2008-03-06 15:27:31 +00:00
|
|
|
tmpGame->RemovePlayer(playerId, errorCode);
|
2007-11-16 15:24:25 +00:00
|
|
|
}
|
2012-01-08 13:02:29 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
ServerLobbyThread::InternalMutePlayerInGame(unsigned playerId)
|
|
|
|
|
{
|
|
|
|
|
boost::shared_ptr<SessionData> session = m_gameSessionManager.GetSessionByUniquePlayerId(playerId);
|
|
|
|
|
if (session) {
|
|
|
|
|
boost::shared_ptr<ServerGame> tmpGame = session->GetGame();
|
|
|
|
|
if (tmpGame) {
|
|
|
|
|
tmpGame->MutePlayer(playerId, true);
|
2007-11-16 15:24:25 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2008-05-11 21:41:30 +00:00
|
|
|
void
|
2011-03-10 20:55:46 +00:00
|
|
|
ServerLobbyThread::InternalResubscribeMsg(boost::shared_ptr<SessionData> session)
|
2008-05-11 21:41:30 +00:00
|
|
|
{
|
2011-03-10 20:55:46 +00:00
|
|
|
if (!session->WantsLobbyMsg()) {
|
|
|
|
|
session->SetWantsLobbyMsg();
|
|
|
|
|
SendPlayerList(session);
|
|
|
|
|
SendGameList(session);
|
2008-05-12 10:50:19 +00:00
|
|
|
// Send new statistics information.
|
2011-02-11 20:02:08 +00:00
|
|
|
/* boost::shared_ptr<NetPacket> packet(new NetPacket(NetPacket::Alloc));
|
|
|
|
|
packet->GetMsg()->present = PokerTHMessage_PR_statisticsMessage;
|
|
|
|
|
StatisticsMessage_t *netStatistics = &packet->GetMsg()->choice.statisticsMessage;
|
2008-05-12 10:50:19 +00:00
|
|
|
|
2011-02-11 20:02:08 +00:00
|
|
|
StatisticsData_t *data = (StatisticsData_t *)calloc(1, sizeof(struct StatisticsData));
|
|
|
|
|
data->statisticsType = statisticsType_statNumberOfPlayers;
|
|
|
|
|
data->statisticsValue = m_sessionManager.GetRawSessionCount() + m_gameSessionManager.GetRawSessionCount();
|
|
|
|
|
ASN_SEQUENCE_ADD(&netStatistics->statisticsData.list, data);
|
2009-08-02 15:11:40 +00:00
|
|
|
|
2011-03-10 20:55:46 +00:00
|
|
|
GetSender().Send(session, packet);*/
|
2008-05-11 21:41:30 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2007-11-16 15:24:25 +00:00
|
|
|
void
|
2011-03-10 20:55:46 +00:00
|
|
|
ServerLobbyThread::HandleReAddedSession(boost::shared_ptr<SessionData> session)
|
2007-11-16 15:24:25 +00:00
|
|
|
{
|
|
|
|
|
// Remove session from game session list.
|
2011-03-10 20:55:46 +00:00
|
|
|
m_gameSessionManager.RemoveSession(session->GetId());
|
2007-11-16 15:24:25 +00:00
|
|
|
|
2011-03-07 20:54:55 +00:00
|
|
|
if (m_sessionManager.GetRawSessionCount() <= SERVER_MAX_NUM_LOBBY_SESSIONS) {
|
2007-11-16 15:24:25 +00:00
|
|
|
// Set state (back) to established.
|
2011-03-10 20:55:46 +00:00
|
|
|
session->SetState(SessionData::Established);
|
2011-03-10 21:53:25 +00:00
|
|
|
session->SetGame(boost::shared_ptr<ServerGame>());
|
2007-11-16 15:24:25 +00:00
|
|
|
// Add session to lobby list.
|
|
|
|
|
m_sessionManager.AddSession(session);
|
2011-02-11 20:02:08 +00:00
|
|
|
} else {
|
2007-11-16 15:24:25 +00:00
|
|
|
// Gracefully close this session.
|
|
|
|
|
SessionError(session, ERR_NET_SERVER_FULL);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2008-03-06 15:27:31 +00:00
|
|
|
void
|
2011-12-11 14:54:17 +00:00
|
|
|
ServerLobbyThread::SessionTimeoutWarning(boost::shared_ptr<SessionData> session, unsigned remainingSec)
|
2008-03-04 23:47:45 +00:00
|
|
|
{
|
2011-12-11 14:54:17 +00:00
|
|
|
boost::shared_ptr<NetPacket> packet(new NetPacket(NetPacket::Alloc));
|
|
|
|
|
packet->GetMsg()->present = PokerTHMessage_PR_timeoutWarningMessage;
|
|
|
|
|
TimeoutWarningMessage_t *netWarning = &packet->GetMsg()->choice.timeoutWarningMessage;
|
|
|
|
|
netWarning->timeoutReason = timeoutReason_timeoutNoDataReceived;
|
|
|
|
|
netWarning->remainingSeconds = remainingSec;
|
|
|
|
|
GetSender().Send(session, packet);
|
2011-12-11 19:37:51 +00:00
|
|
|
|
|
|
|
|
if (session->GetGame() && session->GetPlayerData()) {
|
|
|
|
|
session->GetGame()->MarkPlayerAsInactive(session->GetPlayerData()->GetUniqueId());
|
|
|
|
|
}
|
2008-03-04 23:47:45 +00:00
|
|
|
}
|
|
|
|
|
|
2007-11-16 15:24:25 +00:00
|
|
|
void
|
2011-03-10 20:55:46 +00:00
|
|
|
ServerLobbyThread::SessionError(boost::shared_ptr<SessionData> session, int errorCode)
|
2007-11-16 15:24:25 +00:00
|
|
|
{
|
2011-03-10 20:55:46 +00:00
|
|
|
if (session) {
|
2011-12-11 19:37:51 +00:00
|
|
|
if (errorCode == ERR_NET_PLAYER_KICKED || errorCode == ERR_NET_SESSION_TIMED_OUT) {
|
|
|
|
|
if (session->GetGame() && session->GetPlayerData()) {
|
|
|
|
|
session->GetGame()->MarkPlayerAsKicked(session->GetPlayerData()->GetUniqueId());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-10 20:55:46 +00:00
|
|
|
SendError(session, errorCode);
|
2007-11-16 15:24:25 +00:00
|
|
|
CloseSession(session);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
ServerLobbyThread::SendError(boost::shared_ptr<SessionData> s, int errorCode)
|
|
|
|
|
{
|
2008-03-19 23:39:59 +00:00
|
|
|
LOG_VERBOSE("Sending error code " << errorCode << " to session #" << s->GetId() << ".");
|
2009-08-02 15:11:40 +00:00
|
|
|
boost::shared_ptr<NetPacket> packet(new NetPacket(NetPacket::Alloc));
|
|
|
|
|
packet->GetMsg()->present = PokerTHMessage_PR_errorMessage;
|
|
|
|
|
ErrorMessage_t *netError = &packet->GetMsg()->choice.errorMessage;
|
|
|
|
|
netError->errorReason = NetPacket::GameErrorToNetError(errorCode);
|
2009-06-07 08:51:43 +00:00
|
|
|
GetSender().Send(s, packet);
|
2007-11-16 15:24:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2010-03-31 14:08:46 +00:00
|
|
|
ServerLobbyThread::SendJoinGameFailed(boost::shared_ptr<SessionData> s, unsigned gameId, int reason)
|
2007-11-16 15:24:25 +00:00
|
|
|
{
|
2009-08-02 15:11:40 +00:00
|
|
|
boost::shared_ptr<NetPacket> packet(new NetPacket(NetPacket::Alloc));
|
|
|
|
|
packet->GetMsg()->present = PokerTHMessage_PR_joinGameReplyMessage;
|
|
|
|
|
JoinGameReplyMessage_t *netJoinReply = &packet->GetMsg()->choice.joinGameReplyMessage;
|
2010-03-31 14:08:46 +00:00
|
|
|
netJoinReply->gameId = gameId;
|
2009-08-02 15:11:40 +00:00
|
|
|
|
|
|
|
|
netJoinReply->joinGameResult.present = joinGameResult_PR_joinGameFailed;
|
|
|
|
|
JoinGameFailed_t *joinFailed = &netJoinReply->joinGameResult.choice.joinGameFailed;
|
|
|
|
|
|
2011-02-11 20:02:08 +00:00
|
|
|
switch (reason) {
|
|
|
|
|
case NTF_NET_JOIN_GAME_FULL :
|
|
|
|
|
joinFailed->joinGameFailureReason = joinGameFailureReason_gameIsFull;
|
|
|
|
|
break;
|
|
|
|
|
case NTF_NET_JOIN_ALREADY_RUNNING :
|
|
|
|
|
joinFailed->joinGameFailureReason = joinGameFailureReason_gameIsRunning;
|
|
|
|
|
break;
|
|
|
|
|
case NTF_NET_JOIN_INVALID_PASSWORD :
|
|
|
|
|
joinFailed->joinGameFailureReason = joinGameFailureReason_invalidPassword;
|
|
|
|
|
break;
|
|
|
|
|
case NTF_NET_JOIN_GUEST_FORBIDDEN :
|
|
|
|
|
joinFailed->joinGameFailureReason = joinGameFailureReason_notAllowedAsGuest;
|
|
|
|
|
break;
|
|
|
|
|
case NTF_NET_JOIN_NOT_INVITED :
|
|
|
|
|
joinFailed->joinGameFailureReason = joinGameFailureReason_notInvited;
|
|
|
|
|
break;
|
|
|
|
|
case NTF_NET_JOIN_GAME_NAME_IN_USE :
|
|
|
|
|
joinFailed->joinGameFailureReason = joinGameFailureReason_gameNameInUse;
|
|
|
|
|
break;
|
|
|
|
|
case NTF_NET_JOIN_GAME_BAD_NAME :
|
|
|
|
|
joinFailed->joinGameFailureReason = joinGameFailureReason_badGameName;
|
|
|
|
|
break;
|
|
|
|
|
case NTF_NET_JOIN_INVALID_SETTINGS :
|
|
|
|
|
joinFailed->joinGameFailureReason = joinGameFailureReason_invalidSettings;
|
|
|
|
|
break;
|
|
|
|
|
case NTF_NET_JOIN_IP_BLOCKED :
|
|
|
|
|
joinFailed->joinGameFailureReason = joinGameFailureReason_ipAddressBlocked;
|
|
|
|
|
break;
|
2011-09-11 17:41:56 +00:00
|
|
|
case NTF_NET_JOIN_REJOIN_FAILED :
|
|
|
|
|
joinFailed->joinGameFailureReason = joinGameFailureReason_rejoinFailed;
|
|
|
|
|
break;
|
2011-02-11 20:02:08 +00:00
|
|
|
default :
|
|
|
|
|
joinFailed->joinGameFailureReason = joinGameFailureReason_invalidGame;
|
|
|
|
|
break;
|
2009-08-02 15:11:40 +00:00
|
|
|
}
|
2009-06-07 08:51:43 +00:00
|
|
|
GetSender().Send(s, packet);
|
2007-11-16 15:24:25 +00:00
|
|
|
}
|
|
|
|
|
|
2009-08-15 13:43:00 +00:00
|
|
|
void
|
|
|
|
|
ServerLobbyThread::SendPlayerList(boost::shared_ptr<SessionData> s)
|
|
|
|
|
{
|
|
|
|
|
// Retrieve all player ids.
|
2009-08-15 14:08:48 +00:00
|
|
|
PlayerIdList idList(m_sessionManager.GetPlayerIdList(SessionData::Established));
|
|
|
|
|
PlayerIdList gameIdList(m_gameSessionManager.GetPlayerIdList(SessionData::Game));
|
2009-08-15 13:43:00 +00:00
|
|
|
idList.splice(idList.begin(), gameIdList);
|
|
|
|
|
// Send all player ids to client.
|
|
|
|
|
PlayerIdList::const_iterator i = idList.begin();
|
|
|
|
|
PlayerIdList::const_iterator end = idList.end();
|
2011-02-11 20:02:08 +00:00
|
|
|
while (i != end) {
|
2009-08-15 13:43:00 +00:00
|
|
|
GetSender().Send(s, CreateNetPacketPlayerListNew(*i));
|
|
|
|
|
++i;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2007-11-16 15:24:25 +00:00
|
|
|
void
|
|
|
|
|
ServerLobbyThread::SendGameList(boost::shared_ptr<SessionData> s)
|
|
|
|
|
{
|
|
|
|
|
GameMap::const_iterator game_i = m_gameMap.begin();
|
|
|
|
|
GameMap::const_iterator game_end = m_gameMap.end();
|
2011-02-11 20:02:08 +00:00
|
|
|
while (game_i != game_end) {
|
2009-06-07 08:51:43 +00:00
|
|
|
GetSender().Send(s, CreateNetPacketGameListNew(*game_i->second));
|
2007-11-16 15:24:25 +00:00
|
|
|
++game_i;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
ServerLobbyThread::UpdateStatisticsNumberOfPlayers()
|
|
|
|
|
{
|
|
|
|
|
ServerStats stats;
|
2011-02-13 17:24:40 +00:00
|
|
|
// Get all logged-in sessions and all sessions within a game.
|
|
|
|
|
unsigned curNumberOfPlayersOnServer = m_sessionManager.GetEstablishedSessionCount() + m_gameSessionManager.GetRawSessionCount();
|
2007-11-16 15:24:25 +00:00
|
|
|
{
|
|
|
|
|
boost::mutex::scoped_lock lock(m_statMutex);
|
2011-02-11 20:02:08 +00:00
|
|
|
if (curNumberOfPlayersOnServer != m_statData.numberOfPlayersOnServer) {
|
2007-11-16 15:24:25 +00:00
|
|
|
m_statData.numberOfPlayersOnServer = stats.numberOfPlayersOnServer = curNumberOfPlayersOnServer;
|
|
|
|
|
if (curNumberOfPlayersOnServer > m_statData.maxPlayersLoggedIn)
|
|
|
|
|
m_statData.maxPlayersLoggedIn = curNumberOfPlayersOnServer;
|
|
|
|
|
m_statDataChanged = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// Do not send other stats than number of players for now.
|
2009-08-15 13:43:00 +00:00
|
|
|
//BroadcastStatisticsUpdate(stats);
|
2007-11-16 15:24:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
ServerLobbyThread::BroadcastStatisticsUpdate(const ServerStats &stats)
|
|
|
|
|
{
|
2011-02-11 20:02:08 +00:00
|
|
|
if (stats.numberOfPlayersOnServer) {
|
2009-08-02 15:11:40 +00:00
|
|
|
boost::shared_ptr<NetPacket> packet(new NetPacket(NetPacket::Alloc));
|
|
|
|
|
packet->GetMsg()->present = PokerTHMessage_PR_statisticsMessage;
|
|
|
|
|
StatisticsMessage_t *netStatistics = &packet->GetMsg()->choice.statisticsMessage;
|
2007-11-16 15:24:25 +00:00
|
|
|
|
2009-08-02 15:11:40 +00:00
|
|
|
StatisticsData_t *data = (StatisticsData_t *)calloc(1, sizeof(struct StatisticsData));
|
|
|
|
|
data->statisticsType = statisticsType_statNumberOfPlayers;
|
|
|
|
|
data->statisticsValue = m_sessionManager.GetRawSessionCount() + m_gameSessionManager.GetRawSessionCount();
|
|
|
|
|
ASN_SEQUENCE_ADD(&netStatistics->statisticsData.list, data);
|
|
|
|
|
|
|
|
|
|
m_sessionManager.SendLobbyMsgToAllSessions(GetSender(), packet, SessionData::Established);
|
|
|
|
|
m_gameSessionManager.SendLobbyMsgToAllSessions(GetSender(), packet, SessionData::Game);
|
2007-11-16 15:24:25 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
ServerLobbyThread::ReadStatisticsFile()
|
|
|
|
|
{
|
|
|
|
|
ifstream i(m_statisticsFileName.c_str(), ios_base::in);
|
|
|
|
|
|
2011-02-11 20:02:08 +00:00
|
|
|
if (!i.fail() && !i.eof()) {
|
2007-11-16 15:24:25 +00:00
|
|
|
boost::mutex::scoped_lock lock(m_statMutex);
|
2011-02-11 20:02:08 +00:00
|
|
|
do {
|
2007-11-16 15:24:25 +00:00
|
|
|
string statisticsType;
|
|
|
|
|
unsigned statisticsValue;
|
|
|
|
|
i >> statisticsType;
|
|
|
|
|
i >> statisticsValue;
|
|
|
|
|
if (statisticsType == SERVER_STATISTICS_STR_TOTAL_PLAYERS)
|
|
|
|
|
m_statData.totalPlayersEverLoggedIn = statisticsValue;
|
|
|
|
|
else if (statisticsType == SERVER_STATISTICS_STR_TOTAL_GAMES)
|
|
|
|
|
m_statData.totalGamesEverCreated = statisticsValue;
|
|
|
|
|
else if (statisticsType == SERVER_STATISTICS_STR_MAX_PLAYERS)
|
|
|
|
|
m_statData.maxPlayersLoggedIn = statisticsValue;
|
|
|
|
|
else if (statisticsType == SERVER_STATISTICS_STR_MAX_GAMES)
|
|
|
|
|
m_statData.maxGamesOpen = statisticsValue;
|
2008-04-01 21:44:05 +00:00
|
|
|
// other statistics are non-persistant and not read.
|
2007-11-16 15:24:25 +00:00
|
|
|
} while (!i.fail() && !i.eof());
|
|
|
|
|
m_statDataChanged = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2009-06-12 15:48:34 +00:00
|
|
|
ServerLobbyThread::TimerSaveStatisticsFile(const boost::system::error_code &ec)
|
2007-11-16 15:24:25 +00:00
|
|
|
{
|
2011-02-11 20:02:08 +00:00
|
|
|
if (!ec) {
|
2009-06-12 15:48:34 +00:00
|
|
|
LOG_VERBOSE("Saving statistics.");
|
|
|
|
|
boost::mutex::scoped_lock lock(m_statMutex);
|
2011-02-11 20:02:08 +00:00
|
|
|
if (m_statDataChanged) {
|
2009-06-12 15:48:34 +00:00
|
|
|
ofstream o(m_statisticsFileName.c_str(), ios_base::out | ios_base::trunc);
|
2011-02-11 20:02:08 +00:00
|
|
|
if (!o.fail()) {
|
2009-06-12 15:48:34 +00:00
|
|
|
o << SERVER_STATISTICS_STR_TOTAL_PLAYERS " " << m_statData.totalPlayersEverLoggedIn << endl;
|
|
|
|
|
o << SERVER_STATISTICS_STR_TOTAL_GAMES " " << m_statData.totalGamesEverCreated << endl;
|
|
|
|
|
o << SERVER_STATISTICS_STR_MAX_PLAYERS " " << m_statData.maxPlayersLoggedIn << endl;
|
|
|
|
|
o << SERVER_STATISTICS_STR_MAX_GAMES " " << m_statData.maxGamesOpen << endl;
|
|
|
|
|
o << SERVER_STATISTICS_STR_CUR_PLAYERS " " << m_statData.numberOfPlayersOnServer << endl;
|
|
|
|
|
o << SERVER_STATISTICS_STR_CUR_GAMES " " << m_statData.numberOfGamesOpen << endl;
|
|
|
|
|
m_statDataChanged = false;
|
|
|
|
|
}
|
2007-11-16 15:24:25 +00:00
|
|
|
}
|
2009-06-12 16:04:58 +00:00
|
|
|
// Restart timer
|
|
|
|
|
m_saveStatisticsTimer.expires_from_now(
|
|
|
|
|
boost::posix_time::seconds(SERVER_SAVE_STATISTICS_INTERVAL_SEC));
|
|
|
|
|
m_saveStatisticsTimer.async_wait(
|
|
|
|
|
boost::bind(
|
|
|
|
|
&ServerLobbyThread::TimerSaveStatisticsFile, shared_from_this(), boost::asio::placeholders::error));
|
2007-11-16 15:24:25 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ServerCallback &
|
|
|
|
|
ServerLobbyThread::GetCallback()
|
|
|
|
|
{
|
|
|
|
|
return m_gui;
|
|
|
|
|
}
|
|
|
|
|
|
2009-08-20 11:42:13 +00:00
|
|
|
ServerIrcBotCallback &
|
|
|
|
|
ServerLobbyThread::GetIrcBotCallback()
|
|
|
|
|
{
|
|
|
|
|
return m_ircBotCb;
|
|
|
|
|
}
|
|
|
|
|
|
2009-09-19 20:28:30 +00:00
|
|
|
InternalServerCallback &
|
2007-11-16 15:24:25 +00:00
|
|
|
ServerLobbyThread::GetSenderCallback()
|
|
|
|
|
{
|
2009-09-19 20:28:30 +00:00
|
|
|
assert(m_internalServerCallback.get());
|
|
|
|
|
return *m_internalServerCallback;
|
2007-11-16 15:24:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
GuiInterface &
|
|
|
|
|
ServerLobbyThread::GetGui()
|
|
|
|
|
{
|
|
|
|
|
return m_gui;
|
|
|
|
|
}
|
|
|
|
|
|
2011-12-27 17:26:03 +00:00
|
|
|
unsigned
|
|
|
|
|
ServerLobbyThread::GetPlayerId(const string &name) const
|
2007-11-16 15:24:25 +00:00
|
|
|
{
|
2011-12-27 17:26:03 +00:00
|
|
|
unsigned playerId = 0;
|
2007-11-16 15:24:25 +00:00
|
|
|
|
2011-12-27 17:26:03 +00:00
|
|
|
boost::shared_ptr<SessionData> tmpSession(m_sessionManager.GetSessionByPlayerName(name));
|
2007-11-16 15:24:25 +00:00
|
|
|
|
2011-12-27 17:26:03 +00:00
|
|
|
if (!tmpSession)
|
|
|
|
|
tmpSession = m_gameSessionManager.GetSessionByPlayerName(name);
|
2007-11-16 15:24:25 +00:00
|
|
|
|
2011-12-27 17:26:03 +00:00
|
|
|
if (tmpSession && tmpSession->GetPlayerData())
|
|
|
|
|
playerId = tmpSession->GetPlayerData()->GetUniqueId();
|
|
|
|
|
|
|
|
|
|
return playerId;
|
2007-11-16 15:24:25 +00:00
|
|
|
}
|
|
|
|
|
|
2009-08-15 13:43:00 +00:00
|
|
|
boost::shared_ptr<NetPacket>
|
|
|
|
|
ServerLobbyThread::CreateNetPacketPlayerListNew(unsigned playerId)
|
|
|
|
|
{
|
|
|
|
|
boost::shared_ptr<NetPacket> packet(new NetPacket(NetPacket::Alloc));
|
|
|
|
|
packet->GetMsg()->present = PokerTHMessage_PR_playerListMessage;
|
|
|
|
|
PlayerListMessage_t *netPlayerList = &packet->GetMsg()->choice.playerListMessage;
|
|
|
|
|
netPlayerList->playerId = playerId;
|
|
|
|
|
netPlayerList->playerListNotification = playerListNotification_playerListNew;
|
|
|
|
|
return packet;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
boost::shared_ptr<NetPacket>
|
|
|
|
|
ServerLobbyThread::CreateNetPacketPlayerListLeft(unsigned playerId)
|
|
|
|
|
{
|
|
|
|
|
boost::shared_ptr<NetPacket> packet(new NetPacket(NetPacket::Alloc));
|
|
|
|
|
packet->GetMsg()->present = PokerTHMessage_PR_playerListMessage;
|
|
|
|
|
PlayerListMessage_t *netPlayerList = &packet->GetMsg()->choice.playerListMessage;
|
|
|
|
|
netPlayerList->playerId = playerId;
|
|
|
|
|
netPlayerList->playerListNotification = playerListNotification_playerListLeft;
|
|
|
|
|
return packet;
|
|
|
|
|
}
|
|
|
|
|
|
2007-11-16 15:24:25 +00:00
|
|
|
boost::shared_ptr<NetPacket>
|
2009-05-31 20:14:46 +00:00
|
|
|
ServerLobbyThread::CreateNetPacketGameListNew(const ServerGame &game)
|
2007-11-16 15:24:25 +00:00
|
|
|
{
|
2009-08-02 15:11:40 +00:00
|
|
|
boost::shared_ptr<NetPacket> packet(new NetPacket(NetPacket::Alloc));
|
|
|
|
|
packet->GetMsg()->present = PokerTHMessage_PR_gameListMessage;
|
|
|
|
|
GameListMessage_t *netGameList = &packet->GetMsg()->choice.gameListMessage;
|
|
|
|
|
netGameList->gameId = game.GetId();
|
|
|
|
|
|
|
|
|
|
netGameList->gameListNotification.present = gameListNotification_PR_gameListNew;
|
|
|
|
|
GameListNew_t *gameNew = &netGameList->gameListNotification.choice.gameListNew;
|
|
|
|
|
gameNew->adminPlayerId = game.GetAdminPlayerId();
|
|
|
|
|
gameNew->gameMode = game.IsRunning() ? NetGameMode_gameStarted : NetGameMode_gameCreated;
|
|
|
|
|
NetPacket::SetGameData(game.GetGameData(), &gameNew->gameInfo);
|
|
|
|
|
OCTET_STRING_fromBuf(
|
|
|
|
|
&gameNew->gameInfo.gameName,
|
|
|
|
|
game.GetName().c_str(),
|
2011-04-10 10:04:42 +00:00
|
|
|
(int)game.GetName().length());
|
2009-08-02 15:11:40 +00:00
|
|
|
gameNew->isPrivate = game.IsPasswordProtected();
|
|
|
|
|
|
|
|
|
|
PlayerIdList tmpList = game.GetPlayerIdList();
|
|
|
|
|
PlayerIdList::const_iterator i = tmpList.begin();
|
|
|
|
|
PlayerIdList::const_iterator end = tmpList.end();
|
2011-02-11 20:02:08 +00:00
|
|
|
while (i != end) {
|
2009-08-02 15:11:40 +00:00
|
|
|
NonZeroId_t *playerId = (NonZeroId_t *)calloc(1, sizeof(NonZeroId_t));
|
|
|
|
|
*playerId = *i;
|
|
|
|
|
ASN_SEQUENCE_ADD(&gameNew->playerIds.list, playerId);
|
|
|
|
|
++i;
|
|
|
|
|
}
|
|
|
|
|
|
2007-11-16 15:24:25 +00:00
|
|
|
return packet;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
boost::shared_ptr<NetPacket>
|
|
|
|
|
ServerLobbyThread::CreateNetPacketGameListUpdate(unsigned gameId, GameMode mode)
|
|
|
|
|
{
|
2009-08-02 15:11:40 +00:00
|
|
|
boost::shared_ptr<NetPacket> packet(new NetPacket(NetPacket::Alloc));
|
|
|
|
|
packet->GetMsg()->present = PokerTHMessage_PR_gameListMessage;
|
|
|
|
|
GameListMessage_t *netGameList = &packet->GetMsg()->choice.gameListMessage;
|
|
|
|
|
netGameList->gameId = gameId;
|
|
|
|
|
|
|
|
|
|
netGameList->gameListNotification.present = gameListNotification_PR_gameListUpdate;
|
|
|
|
|
GameListUpdate_t *gameUpdate = &netGameList->gameListNotification.choice.gameListUpdate;
|
|
|
|
|
|
|
|
|
|
gameUpdate->gameMode = mode;
|
2007-11-16 15:24:25 +00:00
|
|
|
return packet;
|
|
|
|
|
}
|
|
|
|
|
|
2011-09-11 17:41:56 +00:00
|
|
|
u_int32_t
|
|
|
|
|
ServerLobbyThread::GetRejoinGameIdForPlayer(const std::string &playerName, const std::string &guid, unsigned &outPlayerUniqueId)
|
|
|
|
|
{
|
|
|
|
|
u_int32_t retGameId = 0;
|
2011-11-13 14:28:54 +00:00
|
|
|
if (!guid.empty()) {
|
|
|
|
|
GameMap::iterator i = m_gameMap.begin();
|
|
|
|
|
GameMap::iterator end = m_gameMap.end();
|
|
|
|
|
while (i != end) {
|
|
|
|
|
boost::shared_ptr<ServerGame> tmpGame = i->second;
|
|
|
|
|
boost::shared_ptr<PlayerInterface> tmpPlayer = tmpGame->GetPlayerInterfaceFromGame(playerName);
|
2012-01-28 11:50:33 +00:00
|
|
|
if (tmpPlayer && tmpPlayer->getMyGuid() == guid && tmpPlayer->getMyCash() > 0) {
|
2011-11-13 14:28:54 +00:00
|
|
|
retGameId = tmpGame->GetId();
|
|
|
|
|
outPlayerUniqueId = tmpPlayer->getMyUniqueID();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
++i;
|
2011-09-11 17:41:56 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return retGameId;
|
|
|
|
|
}
|
|
|
|
|
|