update network part
This commit is contained in:
parent
0b2dee6019
commit
b29218ffff
11 changed files with 92 additions and 24 deletions
|
@ -21,7 +21,7 @@ var _networkconnection = NetworkConnection.new()
|
||||||
var _referentialmessage = ReferentialMessage.new()
|
var _referentialmessage = ReferentialMessage.new()
|
||||||
|
|
||||||
func _ready():
|
func _ready():
|
||||||
pass
|
pass
|
||||||
|
|
||||||
#func send_system_login(host, port, user_addr, user_key, user_id, lang):
|
#func send_system_login(host, port, user_addr, user_key, user_id, lang):
|
||||||
# _networkconnection.define_server(host, port)
|
# _networkconnection.define_server(host, port)
|
||||||
|
@ -30,26 +30,31 @@ func _ready():
|
||||||
# _networkconnection.connect_to_server()
|
# _networkconnection.connect_to_server()
|
||||||
|
|
||||||
func send_system_quit():
|
func send_system_quit():
|
||||||
_networkconnection.send_system_quit()
|
_networkconnection.send_system_quit()
|
||||||
|
|
||||||
func send_systemm_disconnect():
|
func send_systemm_disconnect():
|
||||||
_networkconnection.send_systemm_disconnect()
|
_networkconnection.send_systemm_disconnect()
|
||||||
|
|
||||||
func disconnect_server():
|
func disconnect_server():
|
||||||
_networkconnection.disconnect_server()
|
_networkconnection.disconnect_server()
|
||||||
|
|
||||||
func connect_to_server(host, port, user_addr, user_key, user_id, lang):
|
func connect_to_server(host, port, user_addr, user_key, user_id, lang):
|
||||||
_networkconnection.define_server(host, port)
|
_networkconnection.define_server(host, port)
|
||||||
_networkconnection.define_user(user_addr, user_key, user_id)
|
_networkconnection.define_user(user_addr, user_key, user_id)
|
||||||
_networkconnection.define_lang(lang)
|
_networkconnection.define_lang(lang)
|
||||||
_networkconnection.connect_to_server()
|
_networkconnection.connect_to_server()
|
||||||
#send_system_login(host, port, user_addr, user_key, user_id, lang)
|
#send_system_login(host, port, user_addr, user_key, user_id, lang)
|
||||||
|
|
||||||
func _process(delta):
|
func _process(delta):
|
||||||
_networkconnection.process(delta)
|
_networkconnection.process(delta)
|
||||||
|
var data = _networkconnection.get_server_messages()
|
||||||
|
#print("******* data:", data.size(), data)
|
||||||
|
if data.size() > 0:
|
||||||
|
var ele = data.pop_front()
|
||||||
|
print("*** ele:" , ele)
|
||||||
|
|
||||||
func _exit_tree():
|
func _exit_tree():
|
||||||
print("[net_low_level] End")
|
print("[net_low_level] End")
|
||||||
disconnect_server()
|
disconnect_server()
|
||||||
_networkconnection.terminate_network_connection()
|
_networkconnection.terminate_network_connection()
|
||||||
_referentialmessage.clear_session()
|
_referentialmessage.clear_session()
|
||||||
|
|
|
@ -19,6 +19,8 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "core/reference.h"
|
#include "core/reference.h"
|
||||||
|
#include "core/array.h"
|
||||||
|
#include "core/dictionary.h"
|
||||||
#include "modules/debug/debug.h"
|
#include "modules/debug/debug.h"
|
||||||
#include "modules/networkconnection/network_data.h"
|
#include "modules/networkconnection/network_data.h"
|
||||||
#include "modules/networkconnection/state_connexion.h"
|
#include "modules/networkconnection/state_connexion.h"
|
||||||
|
@ -26,11 +28,16 @@
|
||||||
#include "modules/referentialmessage/referentialmessage.h"
|
#include "modules/referentialmessage/referentialmessage.h"
|
||||||
#include "modules/referentialmessage/referentialmessagecore.h"
|
#include "modules/referentialmessage/referentialmessagecore.h"
|
||||||
|
|
||||||
void ActionFactory::decode_message(Ref<BitStream> msgin)
|
void ActionFactory::decode_message(NetworkData * data, Ref<BitStream> msgin)
|
||||||
{
|
{
|
||||||
|
Dictionary value;
|
||||||
ReferentialMessage ref_msg;
|
ReferentialMessage ref_msg;
|
||||||
uint32_t id = ref_msg.read_command(msgin);
|
uint32_t id = ref_msg.read_command(msgin);
|
||||||
DBG_PRINT("Decode message:" + get_command_name(id));
|
DBG_PRINT("Decode message:" + get_command_name(id));
|
||||||
|
value["command"] = id;
|
||||||
|
#ifdef DEBUG_ENABLED
|
||||||
|
value["command_debug"] = get_command_name(id);
|
||||||
|
#endif
|
||||||
switch(id)
|
switch(id)
|
||||||
{
|
{
|
||||||
case ReferentialMessageCore::Command::TARGET_PARTY:
|
case ReferentialMessageCore::Command::TARGET_PARTY:
|
||||||
|
@ -941,6 +948,11 @@ void ActionFactory::decode_message(Ref<BitStream> msgin)
|
||||||
{
|
{
|
||||||
uint32_t timestamp = msgin->get_uint32();
|
uint32_t timestamp = msgin->get_uint32();
|
||||||
DBG_PRINT("Decode message:" + get_command_name(id) + " timestamp:" + itos(timestamp));
|
DBG_PRINT("Decode message:" + get_command_name(id) + " timestamp:" + itos(timestamp));
|
||||||
|
|
||||||
|
//param.push_back(timestamp);
|
||||||
|
value["timestamp"] = timestamp;
|
||||||
|
|
||||||
|
data->_server_messages.push_back(value);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case ReferentialMessageCore::Command::GUILD_CREATE:
|
case ReferentialMessageCore::Command::GUILD_CREATE:
|
||||||
|
@ -1379,15 +1391,15 @@ void ActionFactory::decode_message(Ref<BitStream> msgin)
|
||||||
#ifdef DEBUG_ENABLED
|
#ifdef DEBUG_ENABLED
|
||||||
// Check if we have read all data - only on debug mode
|
// Check if we have read all data - only on debug mode
|
||||||
{
|
{
|
||||||
uint32_t data;
|
uint32_t last_data;
|
||||||
while ( msgin->number_bit_not_read() > 0 )
|
while ( msgin->number_bit_not_read() > 0 )
|
||||||
{
|
{
|
||||||
DBG_PRINT("Read : " + itos(msgin->number_bit_not_read()));
|
DBG_PRINT("Read : " + itos(msgin->number_bit_not_read()));
|
||||||
if ( msgin->number_bit_not_read() >= 8 )
|
if ( msgin->number_bit_not_read() >= 8 )
|
||||||
data = msgin->get_uint8();
|
last_data = msgin->get_uint8();
|
||||||
else
|
else
|
||||||
data = msgin->get_serial(msgin->number_bit_not_read());
|
last_data = msgin->get_serial(msgin->number_bit_not_read());
|
||||||
if ( data != 0 )
|
if ( last_data != 0 )
|
||||||
{
|
{
|
||||||
ERR_PRINT("Missing some data - we dont' have translate all data : " + msgin->show());
|
ERR_PRINT("Missing some data - we dont' have translate all data : " + msgin->show());
|
||||||
break;
|
break;
|
||||||
|
@ -1398,7 +1410,7 @@ void ActionFactory::decode_message(Ref<BitStream> msgin)
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void ActionFactory::unpack(Ref<BitStream> msgin)
|
void ActionFactory::unpack(NetworkData * data, Ref<BitStream> msgin)
|
||||||
{
|
{
|
||||||
bool shortcode = msgin->get_bool();
|
bool shortcode = msgin->get_bool();
|
||||||
uint8_t code;
|
uint8_t code;
|
||||||
|
@ -1441,7 +1453,7 @@ void ActionFactory::unpack(Ref<BitStream> msgin)
|
||||||
Ref<BitStream> tmp;
|
Ref<BitStream> tmp;
|
||||||
tmp.instance();
|
tmp.instance();
|
||||||
tmp->put_array_uint8(StreamByte);
|
tmp->put_array_uint8(StreamByte);
|
||||||
decode_message(tmp);
|
decode_message(data, tmp);
|
||||||
tmp.unref();
|
tmp.unref();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -1592,7 +1604,7 @@ void ActionFactory::decode(NetworkData * data, Ref<BitStream> msgin)
|
||||||
last_ack[channel] = data->_current_send_number;
|
last_ack[channel] = data->_current_send_number;
|
||||||
}
|
}
|
||||||
num ++;
|
num ++;
|
||||||
unpack(msgin);
|
unpack(data, msgin);
|
||||||
|
|
||||||
// read next packet
|
// read next packet
|
||||||
next = msgin->get_bool();
|
next = msgin->get_bool();
|
||||||
|
|
|
@ -27,8 +27,8 @@
|
||||||
class ActionFactory
|
class ActionFactory
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
void decode_message(Ref<BitStream> msgin);
|
void decode_message(NetworkData * data, Ref<BitStream> msgin);
|
||||||
void unpack(Ref<BitStream> msgin);
|
void unpack(NetworkData * data, Ref<BitStream> msgin);
|
||||||
void decode(NetworkData * data, Ref<BitStream> msgin);
|
void decode(NetworkData * data, Ref<BitStream> msgin);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -31,6 +31,7 @@ void NetworkConnection::_bind_methods()
|
||||||
ClassDB::bind_method(D_METHOD("process", "delta"), &NetworkConnection::process);
|
ClassDB::bind_method(D_METHOD("process", "delta"), &NetworkConnection::process);
|
||||||
ClassDB::bind_method(D_METHOD("get_state"), &NetworkConnection::get_state);
|
ClassDB::bind_method(D_METHOD("get_state"), &NetworkConnection::get_state);
|
||||||
ClassDB::bind_method(D_METHOD("connect_to_server"), &NetworkConnection::connect_to_server);
|
ClassDB::bind_method(D_METHOD("connect_to_server"), &NetworkConnection::connect_to_server);
|
||||||
|
ClassDB::bind_method(D_METHOD("get_server_messages"), &NetworkConnection::get_server_messages);
|
||||||
ClassDB::bind_method(D_METHOD("terminate_network_connection"), &NetworkConnection::terminate_network_connection);
|
ClassDB::bind_method(D_METHOD("terminate_network_connection"), &NetworkConnection::terminate_network_connection);
|
||||||
//ClassDB::bind_method(D_METHOD("get_master_message_description_node"), &NetworkConnection::get_master_message_description_node);
|
//ClassDB::bind_method(D_METHOD("get_master_message_description_node"), &NetworkConnection::get_master_message_description_node);
|
||||||
}
|
}
|
||||||
|
@ -82,12 +83,19 @@ void NetworkConnection::process(int delta)
|
||||||
{
|
{
|
||||||
NetworkConnectionCore::get_singleton()->process(delta);
|
NetworkConnectionCore::get_singleton()->process(delta);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
MessageDescriptionNode & NetworkConnection::get_master_message_description_node()
|
MessageDescriptionNode & NetworkConnection::get_master_message_description_node()
|
||||||
{
|
{
|
||||||
return NetworkConnectionCore::get_singleton()->get_master_message_description_node();
|
return NetworkConnectionCore::get_singleton()->get_master_message_description_node();
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
Variant NetworkConnection::get_server_messages()
|
||||||
|
{
|
||||||
|
return NetworkConnectionCore::get_singleton()->get_server_messages();
|
||||||
|
}
|
||||||
|
|
||||||
void NetworkConnection::terminate_network_connection()
|
void NetworkConnection::terminate_network_connection()
|
||||||
{
|
{
|
||||||
NetworkConnectionCore::terminate_connexion();
|
NetworkConnectionCore::terminate_connexion();
|
||||||
|
|
|
@ -44,6 +44,9 @@ public:
|
||||||
void disconnect_server();
|
void disconnect_server();
|
||||||
void process(int delta);
|
void process(int delta);
|
||||||
int get_state();
|
int get_state();
|
||||||
|
|
||||||
|
Variant get_server_messages();
|
||||||
|
|
||||||
void terminate_network_connection();
|
void terminate_network_connection();
|
||||||
|
|
||||||
//MessageDescriptionNode & get_master_message_description_node();
|
//MessageDescriptionNode & get_master_message_description_node();
|
||||||
|
|
|
@ -200,6 +200,11 @@ void NetworkConnectionCore::process(int delta)
|
||||||
this->_state_connexion->send_message();
|
this->_state_connexion->send_message();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Variant NetworkConnectionCore::get_server_messages()
|
||||||
|
{
|
||||||
|
return _network_data._server_messages;
|
||||||
|
}
|
||||||
|
|
||||||
bool NetworkConnectionCore::is_active()
|
bool NetworkConnectionCore::is_active()
|
||||||
{
|
{
|
||||||
DBG_PRINT("is_active ..");
|
DBG_PRINT("is_active ..");
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
|
|
||||||
#include "core/reference.h"
|
#include "core/reference.h"
|
||||||
#include "core/io/packet_peer_udp.h"
|
#include "core/io/packet_peer_udp.h"
|
||||||
|
#include "core/variant.h"
|
||||||
#include "modules/bitset/bitset.h"
|
#include "modules/bitset/bitset.h"
|
||||||
#include "modules/bitstreamqueue/bitstreamqueue.h"
|
#include "modules/bitstreamqueue/bitstreamqueue.h"
|
||||||
#include "state_connexion.h"
|
#include "state_connexion.h"
|
||||||
|
@ -89,6 +90,9 @@ public:
|
||||||
|
|
||||||
void process(int delta);
|
void process(int delta);
|
||||||
bool connected();
|
bool connected();
|
||||||
|
|
||||||
|
Variant get_server_messages();
|
||||||
|
|
||||||
static bool is_active();
|
static bool is_active();
|
||||||
static void terminate_connexion();
|
static void terminate_connexion();
|
||||||
//MessageDescriptionNode & get_master_message_description_node();
|
//MessageDescriptionNode & get_master_message_description_node();
|
||||||
|
|
|
@ -32,6 +32,7 @@ NetworkData::~NetworkData()
|
||||||
void NetworkData::initialize()
|
void NetworkData::initialize()
|
||||||
{
|
{
|
||||||
// Initialize counter
|
// Initialize counter
|
||||||
|
this->_recieved_new_server_tick = false;
|
||||||
this->_current_received_number = 0;
|
this->_current_received_number = 0;
|
||||||
this->_last_received_number = 0;
|
this->_last_received_number = 0;
|
||||||
this->_quit_id = 0;
|
this->_quit_id = 0;
|
||||||
|
|
|
@ -26,6 +26,8 @@
|
||||||
#include "core/reference.h"
|
#include "core/reference.h"
|
||||||
#include "modules/bitset/bitset.h"
|
#include "modules/bitset/bitset.h"
|
||||||
#include "core/ustring.h"
|
#include "core/ustring.h"
|
||||||
|
//#include "core/dictionary.h"
|
||||||
|
#include "core/array.h"
|
||||||
|
|
||||||
//define MAX_LOOP_READ_BY_STEP 10
|
//define MAX_LOOP_READ_BY_STEP 10
|
||||||
#define NUM_BITS_IN_LONG_ACK 1024
|
#define NUM_BITS_IN_LONG_ACK 1024
|
||||||
|
@ -35,6 +37,7 @@ class NetworkData
|
||||||
public:
|
public:
|
||||||
uint32_t _ack_bit_mask;
|
uint32_t _ack_bit_mask;
|
||||||
|
|
||||||
|
bool _recieved_new_server_tick;
|
||||||
uint32_t _current_server_tick;
|
uint32_t _current_server_tick;
|
||||||
uint32_t _current_client_tick;
|
uint32_t _current_client_tick;
|
||||||
|
|
||||||
|
@ -70,6 +73,10 @@ public:
|
||||||
uint32_t _last_ack_1[2];
|
uint32_t _last_ack_1[2];
|
||||||
uint32_t _last_ack_2[4];
|
uint32_t _last_ack_2[4];
|
||||||
|
|
||||||
|
//Dictionary _server_messages;
|
||||||
|
Array _server_messages;
|
||||||
|
|
||||||
|
|
||||||
NetworkData();
|
NetworkData();
|
||||||
~NetworkData();
|
~NetworkData();
|
||||||
|
|
||||||
|
|
|
@ -367,6 +367,25 @@ void StateConnectionConnected::send_system_ack_probe()
|
||||||
this->_data->_latest_probes.clear();
|
this->_data->_latest_probes.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void StateConnectionConnected::send_system_ask_tick()
|
||||||
|
{
|
||||||
|
// khanat-opennel-code/code/ryzom/client/src/network_connection.cpp # void CNetworkConnection::sendNormalMessage()
|
||||||
|
DBG_PRINT("Send system ACK TICK");
|
||||||
|
|
||||||
|
BitStream msgout;
|
||||||
|
msgout.put_uint32(this->_data->_current_received_number);
|
||||||
|
msgout.put_bool(false);
|
||||||
|
msgout.put_uint32(this->_data->_last_received_number);
|
||||||
|
msgout.put_uint32(this->_data->_ack_bit_mask);
|
||||||
|
DBG_PRINT("current_received_number:" + itos(this->_data->_current_received_number) + " last_received_number:" + itos(this->_data->_last_received_number) + " ack_bit_mask:" + itos(this->_data->_ack_bit_mask));
|
||||||
|
if (this->_network->_socketUDP->put_packet_buffer(msgout.get_data()) != Error::OK)
|
||||||
|
{
|
||||||
|
ERR_PRINT("Error to send disconnect");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this->_data->_recieved_new_server_tick = false;
|
||||||
|
}
|
||||||
|
|
||||||
void StateConnectionConnected::receive_system_sync(Ref<BitStream> msgin)
|
void StateConnectionConnected::receive_system_sync(Ref<BitStream> msgin)
|
||||||
{
|
{
|
||||||
bool valide = true;
|
bool valide = true;
|
||||||
|
@ -430,6 +449,7 @@ void StateConnectionConnected::receive_message(int index)
|
||||||
}
|
}
|
||||||
|
|
||||||
this->_data->_current_received_number = current_received_number;
|
this->_data->_current_received_number = current_received_number;
|
||||||
|
this->_data->_recieved_new_server_tick = true;
|
||||||
Ref<BitStream> msgin = field->get_msgin();
|
Ref<BitStream> msgin = field->get_msgin();
|
||||||
|
|
||||||
system_mode = msgin->get_bool();
|
system_mode = msgin->get_bool();
|
||||||
|
@ -484,6 +504,8 @@ void StateConnectionConnected::send_message()
|
||||||
this->send_system_ack_sync();
|
this->send_system_ack_sync();
|
||||||
if (this->_data->_latest_probes.size() != 0 )
|
if (this->_data->_latest_probes.size() != 0 )
|
||||||
this->send_system_ack_probe();
|
this->send_system_ack_probe();
|
||||||
|
if (this->_data->_recieved_new_server_tick == true)
|
||||||
|
this->send_system_ask_tick();
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
*
|
*
|
||||||
|
|
|
@ -142,6 +142,7 @@ public:
|
||||||
void send_system_disconnect();
|
void send_system_disconnect();
|
||||||
void send_system_ack_sync();
|
void send_system_ack_sync();
|
||||||
void send_system_ack_probe();
|
void send_system_ack_probe();
|
||||||
|
void send_system_ask_tick();
|
||||||
void receive_system_sync(Ref<BitStream> msgin);
|
void receive_system_sync(Ref<BitStream> msgin);
|
||||||
void receive_message(int index);
|
void receive_message(int index);
|
||||||
void send_message();
|
void send_message();
|
||||||
|
|
Loading…
Reference in a new issue