2011-07-02 14:38:06 +00:00
|
|
|
/*****************************************************************************
|
|
|
|
|
* PokerTH - The open source texas holdem engine *
|
2012-12-25 15:06:23 +01:00
|
|
|
* Copyright (C) 2006-2012 Felix Hammer, Florian Thauer, Lothar May *
|
2011-07-02 14:38:06 +00:00
|
|
|
* *
|
|
|
|
|
* This program is free software: you can redistribute it and/or modify *
|
|
|
|
|
* it under the terms of the GNU Affero General Public License as *
|
|
|
|
|
* published by the Free Software Foundation, either version 3 of the *
|
|
|
|
|
* License, or (at your option) any later version. *
|
|
|
|
|
* *
|
|
|
|
|
* This program is distributed in the hope that it will be useful, *
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
|
|
|
* GNU Affero General Public License for more details. *
|
|
|
|
|
* *
|
|
|
|
|
* You should have received a copy of the GNU Affero General Public License *
|
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
|
2012-12-25 15:06:23 +01:00
|
|
|
* *
|
|
|
|
|
* *
|
|
|
|
|
* Additional permission under GNU AGPL version 3 section 7 *
|
|
|
|
|
* *
|
|
|
|
|
* If you modify this program, or any covered work, by linking or *
|
|
|
|
|
* combining it with the OpenSSL project's OpenSSL library (or a *
|
|
|
|
|
* modified version of that library), containing parts covered by the *
|
|
|
|
|
* terms of the OpenSSL or SSLeay licenses, the authors of PokerTH *
|
|
|
|
|
* (Felix Hammer, Florian Thauer, Lothar May) grant you additional *
|
|
|
|
|
* permission to convey the resulting work. *
|
|
|
|
|
* Corresponding Source for a non-source form of such a combination *
|
|
|
|
|
* shall include the source code for the parts of OpenSSL used as well *
|
|
|
|
|
* as that of the covered work. *
|
2011-07-02 14:38:06 +00:00
|
|
|
*****************************************************************************/
|
2007-11-16 15:24:25 +00:00
|
|
|
/* Session data (a session is a valid client connection). */
|
|
|
|
|
|
|
|
|
|
#ifndef _SESSIONDATA_H_
|
|
|
|
|
#define _SESSIONDATA_H_
|
|
|
|
|
|
2009-01-11 20:12:26 +00:00
|
|
|
typedef unsigned SessionId;
|
|
|
|
|
|
2009-05-04 21:11:29 +00:00
|
|
|
#include <boost/asio.hpp>
|
2014-03-29 16:13:53 +01:00
|
|
|
#include <boost/asio/steady_timer.hpp>
|
2009-05-07 22:36:51 +00:00
|
|
|
#include <boost/thread.hpp>
|
2011-02-19 23:47:24 +00:00
|
|
|
#include <boost/enable_shared_from_this.hpp>
|
2009-05-07 22:36:51 +00:00
|
|
|
#include <string>
|
2019-09-09 19:28:59 +02:00
|
|
|
#include <array>
|
2009-05-07 22:36:51 +00:00
|
|
|
|
2007-11-16 15:24:25 +00:00
|
|
|
#include <net/socket_helper.h>
|
2009-01-11 20:12:26 +00:00
|
|
|
#include <net/sessiondatacallback.h>
|
2007-11-16 15:24:25 +00:00
|
|
|
|
|
|
|
|
#define INVALID_SESSION 0
|
|
|
|
|
#define SESSION_ID_INIT INVALID_SESSION
|
|
|
|
|
#define SESSION_ID_GENERIC 0xFFFFFFFF
|
|
|
|
|
|
2009-10-11 12:07:56 +00:00
|
|
|
struct Gsasl;
|
|
|
|
|
struct Gsasl_session;
|
2013-09-15 22:54:45 +02:00
|
|
|
struct WebSocketData;
|
2011-02-19 23:47:24 +00:00
|
|
|
class ReceiveBuffer;
|
2011-02-19 17:55:21 +00:00
|
|
|
class SendBuffer;
|
2011-02-19 23:47:24 +00:00
|
|
|
class NetPacket;
|
2011-03-10 20:55:46 +00:00
|
|
|
class PlayerData;
|
2011-03-10 21:53:25 +00:00
|
|
|
class ServerGame;
|
2009-10-11 12:07:56 +00:00
|
|
|
|
2011-02-19 23:47:24 +00:00
|
|
|
class SessionData : public boost::enable_shared_from_this<SessionData>
|
2007-11-16 15:24:25 +00:00
|
|
|
{
|
|
|
|
|
public:
|
2013-09-01 18:09:15 +02:00
|
|
|
enum State { Init = 1, ReceivingAvatar = 2, Established = 4, Game = 8, Spectating = 16, SpectatorWaiting = 32, Closed = 128 };
|
2007-11-16 15:24:25 +00:00
|
|
|
|
2011-12-11 14:54:17 +00:00
|
|
|
SessionData(boost::shared_ptr<boost::asio::ip::tcp::socket> sock, SessionId id, SessionDataCallback &cb, boost::asio::io_service &ioService);
|
2013-09-15 22:54:45 +02:00
|
|
|
SessionData(boost::shared_ptr<WebSocketData> webData, SessionId id, SessionDataCallback &cb, boost::asio::io_service &ioService, int filler);
|
2007-11-16 15:24:25 +00:00
|
|
|
~SessionData();
|
|
|
|
|
|
|
|
|
|
SessionId GetId() const;
|
2009-05-04 21:11:29 +00:00
|
|
|
|
2011-03-10 21:53:25 +00:00
|
|
|
boost::shared_ptr<ServerGame> GetGame() const;
|
|
|
|
|
void SetGame(boost::shared_ptr<ServerGame> game);
|
2009-05-04 21:11:29 +00:00
|
|
|
|
2007-11-16 15:24:25 +00:00
|
|
|
State GetState() const;
|
|
|
|
|
void SetState(State state);
|
|
|
|
|
|
2009-01-25 21:56:43 +00:00
|
|
|
boost::shared_ptr<boost::asio::ip::tcp::socket> GetAsioSocket();
|
2013-09-16 23:11:16 +02:00
|
|
|
boost::shared_ptr<WebSocketData> GetWebData();
|
2007-11-16 15:24:25 +00:00
|
|
|
|
2009-10-13 21:52:10 +00:00
|
|
|
bool CreateServerAuthSession(Gsasl *context);
|
|
|
|
|
bool CreateClientAuthSession(Gsasl *context, const std::string &userName, const std::string &password);
|
2009-10-18 20:53:58 +00:00
|
|
|
bool AuthStep(int stepNum, const std::string &inData);
|
|
|
|
|
std::string AuthGetUser() const;
|
|
|
|
|
void AuthSetPassword(const std::string &password);
|
2010-09-04 11:56:40 +00:00
|
|
|
std::string AuthGetPassword() const;
|
2009-10-18 20:53:58 +00:00
|
|
|
std::string AuthGetNextOutMsg() const;
|
|
|
|
|
int AuthGetCurStepNum() const;
|
2009-10-11 12:07:56 +00:00
|
|
|
|
2007-11-16 15:24:25 +00:00
|
|
|
void SetReadyFlag();
|
|
|
|
|
void ResetReadyFlag();
|
|
|
|
|
bool IsReady() const;
|
2008-05-11 21:41:30 +00:00
|
|
|
void SetWantsLobbyMsg();
|
|
|
|
|
void ResetWantsLobbyMsg();
|
|
|
|
|
bool WantsLobbyMsg() const;
|
2007-11-16 15:24:25 +00:00
|
|
|
|
|
|
|
|
const std::string &GetClientAddr() const;
|
|
|
|
|
void SetClientAddr(const std::string &addr);
|
|
|
|
|
|
2017-08-16 13:55:18 +02:00
|
|
|
ReceiveBuffer &GetReceiveBuffer()
|
|
|
|
|
{
|
2011-02-19 23:47:24 +00:00
|
|
|
return *m_receiveBuffer;
|
2011-02-19 13:56:49 +00:00
|
|
|
}
|
2017-08-16 13:55:18 +02:00
|
|
|
SendBuffer &GetSendBuffer()
|
|
|
|
|
{
|
2011-02-19 17:55:21 +00:00
|
|
|
return *m_sendBuffer;
|
2011-02-19 13:56:49 +00:00
|
|
|
}
|
2007-11-16 15:24:25 +00:00
|
|
|
|
2017-08-16 13:55:18 +02:00
|
|
|
void Close()
|
|
|
|
|
{
|
2011-02-26 10:09:45 +00:00
|
|
|
m_callback.CloseSession(shared_from_this());
|
|
|
|
|
}
|
2013-09-15 22:54:45 +02:00
|
|
|
void CloseSocketHandle();
|
|
|
|
|
void CloseWebSocketHandle();
|
2017-08-16 13:55:18 +02:00
|
|
|
void HandlePacket(boost::shared_ptr<NetPacket> packet)
|
|
|
|
|
{
|
2011-02-26 10:09:45 +00:00
|
|
|
m_callback.HandlePacket(shared_from_this(), packet);
|
|
|
|
|
}
|
2011-02-19 23:47:24 +00:00
|
|
|
|
2008-03-04 23:47:45 +00:00
|
|
|
void ResetActivityTimer();
|
2011-12-11 14:54:17 +00:00
|
|
|
|
|
|
|
|
void StartTimerInitTimeout(unsigned timeoutSec);
|
|
|
|
|
void StartTimerGlobalTimeout(unsigned timeoutSec);
|
|
|
|
|
void StartTimerActivityTimeout(unsigned timeoutSec, unsigned warningRemainingSec);
|
|
|
|
|
void CancelTimers();
|
2008-03-04 23:47:45 +00:00
|
|
|
|
2011-03-10 20:55:46 +00:00
|
|
|
void SetPlayerData(boost::shared_ptr<PlayerData> player);
|
|
|
|
|
boost::shared_ptr<PlayerData> GetPlayerData();
|
|
|
|
|
|
2019-09-09 19:40:03 +02:00
|
|
|
void SetPlayerLastGames(array<long, 25> lastGames);
|
|
|
|
|
array<long, 25> GetPlayerLastGames();
|
2019-09-09 19:21:15 +02:00
|
|
|
|
2013-09-15 22:54:45 +02:00
|
|
|
std::string GetRemoteIPAddressFromSocket() const;
|
|
|
|
|
|
2009-10-11 12:07:56 +00:00
|
|
|
protected:
|
2011-02-19 13:56:49 +00:00
|
|
|
SessionData(const SessionData &other);
|
|
|
|
|
SessionData &operator=(const SessionData &other);
|
2009-10-11 12:07:56 +00:00
|
|
|
void InternalClearAuthSession();
|
2011-12-11 14:54:17 +00:00
|
|
|
void TimerInitTimeout(const boost::system::error_code &ec);
|
|
|
|
|
void TimerSessionTimeout(const boost::system::error_code &ec);
|
|
|
|
|
void TimerActivityWarning(const boost::system::error_code &ec);
|
2009-10-11 12:07:56 +00:00
|
|
|
|
2007-11-16 15:24:25 +00:00
|
|
|
private:
|
2013-09-15 22:54:45 +02:00
|
|
|
boost::shared_ptr<boost::asio::ip::tcp::socket> m_socket;
|
|
|
|
|
boost::shared_ptr<WebSocketData> m_webData;
|
2007-11-16 15:24:25 +00:00
|
|
|
const SessionId m_id;
|
2011-03-10 21:53:25 +00:00
|
|
|
boost::weak_ptr<ServerGame> m_game;
|
2007-11-16 15:24:25 +00:00
|
|
|
State m_state;
|
|
|
|
|
std::string m_clientAddr;
|
2011-02-19 23:47:24 +00:00
|
|
|
boost::shared_ptr<ReceiveBuffer> m_receiveBuffer;
|
|
|
|
|
boost::shared_ptr<SendBuffer> m_sendBuffer;
|
2007-11-16 15:24:25 +00:00
|
|
|
bool m_readyFlag;
|
2008-05-11 21:41:30 +00:00
|
|
|
bool m_wantsLobbyMsg;
|
2011-12-11 14:54:17 +00:00
|
|
|
unsigned m_activityTimeoutSec;
|
|
|
|
|
unsigned m_activityWarningRemainingSec;
|
2014-03-29 16:13:53 +01:00
|
|
|
boost::asio::steady_timer m_initTimeoutTimer;
|
|
|
|
|
boost::asio::steady_timer m_globalTimeoutTimer;
|
|
|
|
|
boost::asio::steady_timer m_activityTimeoutTimer;
|
2009-01-11 20:12:26 +00:00
|
|
|
SessionDataCallback &m_callback;
|
2009-10-11 12:07:56 +00:00
|
|
|
Gsasl_session *m_authSession;
|
|
|
|
|
int m_curAuthStep;
|
2009-10-18 20:53:58 +00:00
|
|
|
std::string m_nextGsaslMsg;
|
2010-09-04 11:56:40 +00:00
|
|
|
std::string m_password;
|
2011-03-10 20:55:46 +00:00
|
|
|
boost::shared_ptr<PlayerData> m_playerData;
|
2007-11-16 15:24:25 +00:00
|
|
|
|
2019-09-09 19:59:59 +02:00
|
|
|
array<long, 25> m_lastGames;
|
2019-09-09 19:21:15 +02:00
|
|
|
|
2007-11-16 15:24:25 +00:00
|
|
|
mutable boost::mutex m_dataMutex;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#endif
|