Big Refactor.
General support for encryption and decryption. Game Session creation. Discovery Server. Still broken as hell, but less so?
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
/*
|
||||
#include "../global_define.h"
|
||||
|
||||
PacketBuffer::PacketBuffer( uint16_t command, uint32_t event_seq, uint32_t hint_size )
|
||||
@@ -258,4 +259,5 @@ void process_networking()
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
@@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
#include <memory>
|
||||
#include "socket.h"
|
||||
|
||||
@@ -77,9 +78,11 @@ public:
|
||||
uint32_t write_position;
|
||||
uint32_t read_position;
|
||||
};
|
||||
*/
|
||||
|
||||
typedef std::shared_ptr< PacketBuffer > sptr_packet;
|
||||
|
||||
//typedef std::shared_ptr< PacketBuffer > sptr_packet;
|
||||
/*
|
||||
sptr_packet make_packet( uint16_t command, uint32_t event_id, uint32_t hint_size );
|
||||
sptr_packet make_packet( sptr_packet request );
|
||||
void process_networking();
|
||||
void process_networking();
|
||||
*/
|
||||
@@ -1,4 +1,4 @@
|
||||
|
||||
/*
|
||||
#include "../global_define.h"
|
||||
|
||||
#include "protocol_broker.h"
|
||||
@@ -22,7 +22,7 @@ void Protocol::Broker::process_request( sptr_socket socket, sptr_packet request
|
||||
auto protocol_iter = BROKER_PROTOCOL.find( request->get_command() );
|
||||
if( protocol_iter == BROKER_PROTOCOL.end() )
|
||||
{
|
||||
logging.error( "UNDEFINED PROTOCOL: %02X", request->get_command() );
|
||||
Log::Error( "UNDEFINED PROTOCOL: %02X", request->get_command() );
|
||||
logging.packet( request->buffer, false );
|
||||
return;
|
||||
}
|
||||
@@ -45,4 +45,5 @@ void Protocol::Broker::process_notice( sptr_socket s, sptr_packet r )
|
||||
{
|
||||
} break;
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
@@ -7,11 +7,9 @@
|
||||
// ╠╩╗╠╦╝║ ║╠╩╗║╣ ╠╦╝ ╠═╝╠╦╝║ ║ ║ ║ ║║ ║ ║║
|
||||
// ╚═╝╩╚═╚═╝╩ ╩╚═╝╩╚═ ╩ ╩╚═╚═╝ ╩ ╚═╝╚═╝╚═╝╩═╝
|
||||
|
||||
#include "packet.h"
|
||||
#include "socket.h"
|
||||
|
||||
/*
|
||||
namespace Protocol::Broker
|
||||
{
|
||||
void process_request( sptr_socket socket, sptr_packet r ); // Process incoming packets
|
||||
void process_notice( sptr_socket socket, sptr_packet r ); // Process socket notices
|
||||
}
|
||||
}*/
|
||||
@@ -1,4 +1,4 @@
|
||||
|
||||
/*
|
||||
#include "../global_define.h"
|
||||
|
||||
using namespace Protocol::Game;
|
||||
@@ -38,7 +38,7 @@ void Protocol::Game::process_request( sptr_socket socket, sptr_packet request )
|
||||
auto protocol_iter = GAME_PROTOCOL.find( request->get_command() );
|
||||
if( protocol_iter == GAME_PROTOCOL.end() )
|
||||
{
|
||||
logging.error( "UNDEFINED PROTOCOL: %02X", request->get_command() );
|
||||
Log::Error( "UNDEFINED PROTOCOL: %02X", request->get_command() );
|
||||
logging.packet( request->buffer, false );
|
||||
return;
|
||||
}
|
||||
@@ -210,3 +210,4 @@ void Protocol::Game::ReqUpdateGameData( sptr_client client, sptr_packet request
|
||||
}
|
||||
client->socket->send( res );
|
||||
}
|
||||
*/
|
||||
@@ -7,9 +7,7 @@
|
||||
// ║ ╦╠═╣║║║║╣ ╠═╝╠╦╝║ ║ ║ ║ ║║ ║ ║║
|
||||
// ╚═╝╩ ╩╩ ╩╚═╝ ╩ ╩╚═╚═╝ ╩ ╚═╝╚═╝╚═╝╩═╝
|
||||
|
||||
#include "packet.h"
|
||||
#include "socket.h"
|
||||
|
||||
/*
|
||||
namespace Protocol::Game
|
||||
{
|
||||
void process_request( sptr_socket s, sptr_packet r ); // Process incoming packets
|
||||
@@ -25,4 +23,4 @@ namespace Protocol::Game
|
||||
void ReqGetEncryptionKey( sptr_client client, sptr_packet request ); // 2700
|
||||
void ReqGetRules( sptr_client client, sptr_packet request ); // 4200
|
||||
void ReqUpdateGameData( sptr_client client, sptr_packet request ); // 4400
|
||||
}
|
||||
}*/
|
||||
@@ -1,4 +1,4 @@
|
||||
|
||||
/*
|
||||
#include "../global_define.h"
|
||||
|
||||
#include "protocol_gateway.h"
|
||||
@@ -23,7 +23,7 @@ void Protocol::Gateway::process_request( sptr_socket socket, sptr_packet request
|
||||
auto protocol_iter = GATEWAY_PROTOCOL.find( request->get_command() );
|
||||
if( protocol_iter == GATEWAY_PROTOCOL.end() )
|
||||
{
|
||||
logging.error( "UNDEFINED PROTOCOL: %02X", request->get_command() );
|
||||
Log::Error( "UNDEFINED PROTOCOL: %02X", request->get_command() );
|
||||
logging.packet( request->buffer, false );
|
||||
return;
|
||||
}
|
||||
@@ -57,3 +57,4 @@ void Protocol::Gateway::ReqGetServerAddress( sptr_socket socket, sptr_packet req
|
||||
}
|
||||
socket->send( res );
|
||||
}
|
||||
*/
|
||||
@@ -7,13 +7,11 @@
|
||||
// ║ ╦╠═╣ ║ ║╣ ║║║╠═╣╚╦╝ ╠═╝╠╦╝║ ║ ║ ║ ║║ ║ ║║
|
||||
// ╚═╝╩ ╩ ╩ ╚═╝╚╩╝╩ ╩ ╩ ╩ ╩╚═╚═╝ ╩ ╚═╝╚═╝╚═╝╩═╝
|
||||
|
||||
#include "packet.h"
|
||||
#include "socket.h"
|
||||
|
||||
/*
|
||||
namespace Protocol::Gateway
|
||||
{
|
||||
void process_request( sptr_socket socket, sptr_packet r ); // Process incoming packets
|
||||
void process_notice( sptr_socket socket, sptr_packet r ); // Process socket notices
|
||||
|
||||
void ReqGetServerAddress( sptr_socket socket, sptr_packet r ); // 4300
|
||||
}
|
||||
}*/
|
||||
@@ -1,66 +0,0 @@
|
||||
|
||||
#include "../global_define.h"
|
||||
#include "socket.h"
|
||||
|
||||
CRealmSocket::CRealmSocket()
|
||||
{
|
||||
fd = INVALID_SOCKET;
|
||||
|
||||
memset( &local_address, 0, sizeof( local_address ) );
|
||||
memset( &remote_address, 0, sizeof( remote_address ) );
|
||||
port = 0;
|
||||
|
||||
type = RealmSocketType::TCP;
|
||||
channel = RealmChannelType::INVALID;
|
||||
|
||||
flag.disconnected = 0;
|
||||
flag.is_listener = 0;
|
||||
flag.want_more_read_data = 0;
|
||||
flag.want_more_write_data = 0;
|
||||
|
||||
last_write_position = 0;
|
||||
|
||||
latency = 0;
|
||||
last_recv_time = 0.0;
|
||||
last_send_time = 0.0;
|
||||
}
|
||||
|
||||
CRealmSocket::~CRealmSocket()
|
||||
{
|
||||
if( INVALID_SOCKET != fd )
|
||||
{
|
||||
closesocket( fd );
|
||||
}
|
||||
|
||||
fd = INVALID_SOCKET;
|
||||
|
||||
memset( &local_address, 0, sizeof( local_address ) );
|
||||
memset( &remote_address, 0, sizeof( remote_address ) );
|
||||
port = 0;
|
||||
|
||||
type = RealmSocketType::TCP;
|
||||
channel = RealmChannelType::INVALID;
|
||||
|
||||
flag.disconnected = 0;
|
||||
flag.is_listener = 0;
|
||||
flag.want_more_read_data = 0;
|
||||
flag.want_more_write_data = 0;
|
||||
|
||||
last_write_position = 0;
|
||||
|
||||
latency = 0;
|
||||
last_recv_time = 0.0;
|
||||
last_send_time = 0.0;
|
||||
}
|
||||
|
||||
void CRealmSocket::send( const sptr_packet p )
|
||||
{
|
||||
// TODO: UDP sockets probably need to be handled differently
|
||||
//
|
||||
// Swap the packet size to network byte order
|
||||
*( uint32_t * )&p->buffer[ 0 ] = Math::swap_endian( p->write_position );
|
||||
|
||||
logging.packet( p->buffer, true );
|
||||
std::lock_guard< std::mutex > lock( write_mutex );
|
||||
write_queue.push_back( p );
|
||||
}
|
||||
@@ -1,62 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <mutex>
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
|
||||
#include "packet.h"
|
||||
|
||||
enum class RealmSocketType
|
||||
{
|
||||
TCP = 0,
|
||||
UDP,
|
||||
};
|
||||
|
||||
enum class RealmChannelType
|
||||
{
|
||||
INVALID = 0,
|
||||
GATEWAY,
|
||||
GAME,
|
||||
DISCOVERY,
|
||||
};
|
||||
|
||||
class CRealmSocket
|
||||
{
|
||||
public:
|
||||
CRealmSocket();
|
||||
~CRealmSocket();
|
||||
|
||||
void send( const sptr_packet p );
|
||||
|
||||
struct s_flag
|
||||
{
|
||||
bool disconnected;
|
||||
bool is_listener;
|
||||
bool want_more_read_data;
|
||||
bool want_more_write_data;
|
||||
} flag;
|
||||
|
||||
RealmSocketType type;
|
||||
RealmChannelType channel;
|
||||
|
||||
SOCKET fd;
|
||||
uint16_t port;
|
||||
sockaddr_in local_address;
|
||||
sockaddr_in remote_address;
|
||||
std::string peer_ip_address;
|
||||
|
||||
uint32_t last_write_position;
|
||||
|
||||
double_t latency;
|
||||
double_t last_recv_time;
|
||||
double_t last_send_time;
|
||||
|
||||
std::mutex write_mutex;
|
||||
std::mutex read_mutex;
|
||||
|
||||
std::vector< uint8_t > read_buffer;
|
||||
std::list< sptr_packet > read_queue;
|
||||
std::list< sptr_packet > write_queue;
|
||||
};
|
||||
|
||||
typedef std::shared_ptr< CRealmSocket > sptr_socket;
|
||||
@@ -1,4 +1,4 @@
|
||||
|
||||
/*
|
||||
#include "../global_define.h"
|
||||
#include "socket_manager.h"
|
||||
|
||||
@@ -67,7 +67,7 @@ bool CSocketManager::open_tcp_listener( std::string ip, uint16_t port, RealmChan
|
||||
|
||||
if( bind( socket->fd, ( LPSOCKADDR )&addr, sizeof( addr ) ) != 0 )
|
||||
{
|
||||
logging.error( "Could not open socket on %s:%d", ip.c_str(), port );
|
||||
Log::Error( "Could not open socket on %s:%d", ip.c_str(), port );
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -84,7 +84,7 @@ bool CSocketManager::open_tcp_listener( std::string ip, uint16_t port, RealmChan
|
||||
|
||||
socket_list.push_back( socket );
|
||||
|
||||
logging.information( "Open TCP Listener on %s:%d", ip.c_str(), port );
|
||||
Log::Info( "Open TCP Listener on %s:%d", ip.c_str(), port );
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -108,7 +108,7 @@ bool CSocketManager::open_udp_listener( std::string ip, uint16_t port, RealmChan
|
||||
|
||||
if( bind( socket->fd, ( LPSOCKADDR )&addr, sizeof( addr ) ) != 0 )
|
||||
{
|
||||
logging.error( "Could not open socket on %s:%d", ip.c_str(), port );
|
||||
Log::Error( "Could not open socket on %s:%d", ip.c_str(), port );
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -123,7 +123,7 @@ bool CSocketManager::open_udp_listener( std::string ip, uint16_t port, RealmChan
|
||||
|
||||
socket_list.push_back( socket );
|
||||
|
||||
logging.information( "Open UDP Listener on %s:%d", ip.c_str(), port );
|
||||
Log::Info( "Open UDP Listener on %s:%d", ip.c_str(), port );
|
||||
|
||||
return false;
|
||||
}
|
||||
@@ -166,11 +166,11 @@ void CSocketManager::accept_new_tcp( sptr_socket from_socket )
|
||||
|
||||
if( from_socket->channel == RealmChannelType::GATEWAY )
|
||||
{
|
||||
logging.information( "[GATEWAY] : New connection from %s", ( *new_socket ).peer_ip_address.c_str() );
|
||||
Log::Info( "[GATEWAY] : New connection from %s", ( *new_socket ).peer_ip_address.c_str() );
|
||||
}
|
||||
else if( from_socket->channel == RealmChannelType::GAME )
|
||||
{
|
||||
logging.information( "[GAME] : New connection from %s", ( *new_socket ).peer_ip_address.c_str() );
|
||||
Log::Info( "[GAME] : New connection from %s", ( *new_socket ).peer_ip_address.c_str() );
|
||||
}
|
||||
|
||||
new_socket->last_recv_time = net_time.GetAppMilliTime();
|
||||
@@ -306,7 +306,7 @@ void CSocketManager::TCP_TryReadData( sptr_socket socket )
|
||||
{
|
||||
case WSAECONNRESET:
|
||||
{
|
||||
logging.information( "Connection %s reset by peer.", socket->peer_ip_address.c_str() );
|
||||
Log::Info( "Connection %s reset by peer.", socket->peer_ip_address.c_str() );
|
||||
} break;
|
||||
}
|
||||
|
||||
@@ -465,3 +465,4 @@ void CSocketManager::UDP_TryWriteData( sptr_socket s )
|
||||
|
||||
s->write_mutex.unlock();
|
||||
}
|
||||
*/
|
||||
@@ -1,5 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
#include <vector>
|
||||
#include <set>
|
||||
#include <thread>
|
||||
@@ -53,4 +53,4 @@ private:
|
||||
|
||||
void UDP_TryReadData( sptr_socket s );
|
||||
void UDP_TryWriteData( sptr_socket s );
|
||||
};
|
||||
};*/
|
||||
Reference in New Issue
Block a user