2017-08-08 13:53:47 +02:00
|
|
|
#include <time.h>
|
|
|
|
|
2017-08-19 00:18:40 +02:00
|
|
|
#include <src/servers/Server_Common/Util/Util.h>
|
|
|
|
#include <src/servers/Server_Common/Network/PacketContainer.h>
|
2017-08-18 17:16:15 +02:00
|
|
|
#include "src/servers/Server_Zone/Network/GameConnection.h"
|
2017-08-08 13:53:47 +02:00
|
|
|
#include "Session.h"
|
|
|
|
|
2017-08-18 17:16:15 +02:00
|
|
|
#include "src/servers/Server_Zone/Actor/Player.h"
|
2017-08-08 13:53:47 +02:00
|
|
|
|
|
|
|
Core::Session::Session( uint32_t sessionId )
|
|
|
|
: m_sessionId( sessionId )
|
|
|
|
, m_lastDataTime( static_cast< uint32_t >( time( nullptr ) ) )
|
|
|
|
{
|
|
|
|
|
|
|
|
// boost::posix_time::ptime now = boost::date_time::not_a_date_time;
|
|
|
|
// now = boost::posix_time::microsec_clock::universal_time();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
Core::Session::~Session()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void Core::Session::setZoneConnection( Core::Network::GameConnectionPtr pZoneCon )
|
|
|
|
{
|
|
|
|
pZoneCon->m_conType = Network::ConnectionType::Zone;
|
|
|
|
m_pZoneConnection = pZoneCon;
|
|
|
|
}
|
|
|
|
|
2017-08-20 20:48:55 +02:00
|
|
|
void Core::Session::setChatConnection( Core::Network::GameConnectionPtr pChatCon )
|
|
|
|
{
|
|
|
|
pChatCon->m_conType = Network::ConnectionType::Chat;
|
|
|
|
m_pChatConnection = pChatCon;
|
|
|
|
}
|
|
|
|
|
2017-08-08 13:53:47 +02:00
|
|
|
Core::Network::GameConnectionPtr Core::Session::getZoneConnection() const
|
|
|
|
{
|
|
|
|
return m_pZoneConnection;
|
|
|
|
}
|
|
|
|
|
2017-08-20 20:48:55 +02:00
|
|
|
Core::Network::GameConnectionPtr Core::Session::getChatConnection() const
|
|
|
|
{
|
|
|
|
return m_pChatConnection;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-08-08 13:53:47 +02:00
|
|
|
bool Core::Session::loadPlayer()
|
|
|
|
{
|
|
|
|
|
|
|
|
m_pPlayer = Entity::PlayerPtr( new Entity::Player() );
|
|
|
|
|
|
|
|
if( !m_pPlayer->load( m_sessionId, shared_from_this() ) )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void Core::Session::close()
|
|
|
|
{
|
|
|
|
if( m_pZoneConnection )
|
|
|
|
m_pZoneConnection->Disconnect();
|
|
|
|
|
2017-10-06 00:13:29 +02:00
|
|
|
if( m_pChatConnection )
|
|
|
|
m_pChatConnection->Disconnect();
|
|
|
|
|
2017-08-08 13:53:47 +02:00
|
|
|
// remove the session from the player
|
|
|
|
if( m_pPlayer )
|
|
|
|
// reset the zone, so the zone handler knows to remove the actor
|
|
|
|
m_pPlayer->setCurrentZone( nullptr );
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t Core::Session::getId() const
|
|
|
|
{
|
|
|
|
return m_sessionId;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t Core::Session::getLastDataTime() const
|
|
|
|
{
|
|
|
|
return m_lastDataTime;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Core::Session::updateLastDataTime()
|
|
|
|
{
|
|
|
|
m_lastDataTime = static_cast< uint32_t >( time( nullptr ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
void Core::Session::update()
|
|
|
|
{
|
|
|
|
if( m_pZoneConnection )
|
|
|
|
{
|
|
|
|
m_pZoneConnection->processInQueue();
|
|
|
|
|
|
|
|
// SESSION LOGIC
|
|
|
|
m_pPlayer->update( Util::getTimeMs() );
|
|
|
|
|
|
|
|
m_pPlayer->createUpdateSql();
|
|
|
|
|
|
|
|
m_pZoneConnection->processOutQueue();
|
|
|
|
}
|
|
|
|
|
2017-08-20 20:48:55 +02:00
|
|
|
if( m_pZoneConnection )
|
|
|
|
{
|
|
|
|
m_pChatConnection->processInQueue();
|
|
|
|
m_pChatConnection->processOutQueue();
|
|
|
|
}
|
|
|
|
|
2017-08-08 13:53:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Core::Entity::PlayerPtr Core::Session::getPlayer() const
|
|
|
|
{
|
|
|
|
return m_pPlayer;
|
|
|
|
}
|
|
|
|
|