diff --git a/assets/Scripts/Network/net_low_level.gd b/assets/Scripts/Network/net_low_level.gd index 576bb98..849b812 100644 --- a/assets/Scripts/Network/net_low_level.gd +++ b/assets/Scripts/Network/net_low_level.gd @@ -21,7 +21,7 @@ var _networkconnection = NetworkConnection.new() var _referentialmessage = ReferentialMessage.new() func _ready(): - pass + pass #func send_system_login(host, port, user_addr, user_key, user_id, lang): # _networkconnection.define_server(host, port) @@ -30,26 +30,31 @@ func _ready(): # _networkconnection.connect_to_server() func send_system_quit(): - _networkconnection.send_system_quit() + _networkconnection.send_system_quit() func send_systemm_disconnect(): - _networkconnection.send_systemm_disconnect() + _networkconnection.send_systemm_disconnect() func disconnect_server(): - _networkconnection.disconnect_server() + _networkconnection.disconnect_server() func connect_to_server(host, port, user_addr, user_key, user_id, lang): - _networkconnection.define_server(host, port) - _networkconnection.define_user(user_addr, user_key, user_id) - _networkconnection.define_lang(lang) - _networkconnection.connect_to_server() - #send_system_login(host, port, user_addr, user_key, user_id, lang) + _networkconnection.define_server(host, port) + _networkconnection.define_user(user_addr, user_key, user_id) + _networkconnection.define_lang(lang) + _networkconnection.connect_to_server() + #send_system_login(host, port, user_addr, user_key, user_id, lang) 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(): - print("[net_low_level] End") - disconnect_server() - _networkconnection.terminate_network_connection() - _referentialmessage.clear_session() + print("[net_low_level] End") + disconnect_server() + _networkconnection.terminate_network_connection() + _referentialmessage.clear_session() diff --git a/modules/command/action_factory.cpp b/modules/command/action_factory.cpp index 144b11d..1c2541c 100644 --- a/modules/command/action_factory.cpp +++ b/modules/command/action_factory.cpp @@ -19,6 +19,8 @@ */ #include "core/reference.h" +#include "core/array.h" +#include "core/dictionary.h" #include "modules/debug/debug.h" #include "modules/networkconnection/network_data.h" #include "modules/networkconnection/state_connexion.h" @@ -26,11 +28,16 @@ #include "modules/referentialmessage/referentialmessage.h" #include "modules/referentialmessage/referentialmessagecore.h" -void ActionFactory::decode_message(Ref msgin) +void ActionFactory::decode_message(NetworkData * data, Ref msgin) { + Dictionary value; ReferentialMessage ref_msg; uint32_t id = ref_msg.read_command(msgin); DBG_PRINT("Decode message:" + get_command_name(id)); + value["command"] = id; + #ifdef DEBUG_ENABLED + value["command_debug"] = get_command_name(id); + #endif switch(id) { case ReferentialMessageCore::Command::TARGET_PARTY: @@ -941,6 +948,11 @@ void ActionFactory::decode_message(Ref msgin) { uint32_t timestamp = msgin->get_uint32(); 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; } case ReferentialMessageCore::Command::GUILD_CREATE: @@ -1379,15 +1391,15 @@ void ActionFactory::decode_message(Ref msgin) #ifdef DEBUG_ENABLED // 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 ) { DBG_PRINT("Read : " + itos(msgin->number_bit_not_read())); if ( msgin->number_bit_not_read() >= 8 ) - data = msgin->get_uint8(); + last_data = msgin->get_uint8(); else - data = msgin->get_serial(msgin->number_bit_not_read()); - if ( data != 0 ) + last_data = msgin->get_serial(msgin->number_bit_not_read()); + if ( last_data != 0 ) { ERR_PRINT("Missing some data - we dont' have translate all data : " + msgin->show()); break; @@ -1398,7 +1410,7 @@ void ActionFactory::decode_message(Ref msgin) #endif } -void ActionFactory::unpack(Ref msgin) +void ActionFactory::unpack(NetworkData * data, Ref msgin) { bool shortcode = msgin->get_bool(); uint8_t code; @@ -1441,7 +1453,7 @@ void ActionFactory::unpack(Ref msgin) Ref tmp; tmp.instance(); tmp->put_array_uint8(StreamByte); - decode_message(tmp); + decode_message(data, tmp); tmp.unref(); break; } @@ -1592,7 +1604,7 @@ void ActionFactory::decode(NetworkData * data, Ref msgin) last_ack[channel] = data->_current_send_number; } num ++; - unpack(msgin); + unpack(data, msgin); // read next packet next = msgin->get_bool(); diff --git a/modules/command/action_factory.h b/modules/command/action_factory.h index f4a48db..5097228 100644 --- a/modules/command/action_factory.h +++ b/modules/command/action_factory.h @@ -27,8 +27,8 @@ class ActionFactory { public: - void decode_message(Ref msgin); - void unpack(Ref msgin); + void decode_message(NetworkData * data, Ref msgin); + void unpack(NetworkData * data, Ref msgin); void decode(NetworkData * data, Ref msgin); }; diff --git a/modules/networkconnection/network_connection.cpp b/modules/networkconnection/network_connection.cpp index e4fefdb..0959a36 100644 --- a/modules/networkconnection/network_connection.cpp +++ b/modules/networkconnection/network_connection.cpp @@ -31,6 +31,7 @@ void NetworkConnection::_bind_methods() ClassDB::bind_method(D_METHOD("process", "delta"), &NetworkConnection::process); 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("get_server_messages"), &NetworkConnection::get_server_messages); 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); } @@ -82,12 +83,19 @@ void NetworkConnection::process(int delta) { NetworkConnectionCore::get_singleton()->process(delta); } + /* MessageDescriptionNode & NetworkConnection::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() { NetworkConnectionCore::terminate_connexion(); diff --git a/modules/networkconnection/network_connection.h b/modules/networkconnection/network_connection.h index 24a3f18..d97fb42 100644 --- a/modules/networkconnection/network_connection.h +++ b/modules/networkconnection/network_connection.h @@ -44,6 +44,9 @@ public: void disconnect_server(); void process(int delta); int get_state(); + + Variant get_server_messages(); + void terminate_network_connection(); //MessageDescriptionNode & get_master_message_description_node(); diff --git a/modules/networkconnection/network_connection_core.cpp b/modules/networkconnection/network_connection_core.cpp index 2a05c45..f4f8ee9 100644 --- a/modules/networkconnection/network_connection_core.cpp +++ b/modules/networkconnection/network_connection_core.cpp @@ -200,6 +200,11 @@ void NetworkConnectionCore::process(int delta) this->_state_connexion->send_message(); } +Variant NetworkConnectionCore::get_server_messages() +{ + return _network_data._server_messages; +} + bool NetworkConnectionCore::is_active() { DBG_PRINT("is_active .."); diff --git a/modules/networkconnection/network_connection_core.h b/modules/networkconnection/network_connection_core.h index 6289af6..39a90c9 100644 --- a/modules/networkconnection/network_connection_core.h +++ b/modules/networkconnection/network_connection_core.h @@ -23,6 +23,7 @@ #include "core/reference.h" #include "core/io/packet_peer_udp.h" +#include "core/variant.h" #include "modules/bitset/bitset.h" #include "modules/bitstreamqueue/bitstreamqueue.h" #include "state_connexion.h" @@ -89,6 +90,9 @@ public: void process(int delta); bool connected(); + + Variant get_server_messages(); + static bool is_active(); static void terminate_connexion(); //MessageDescriptionNode & get_master_message_description_node(); diff --git a/modules/networkconnection/network_data.cpp b/modules/networkconnection/network_data.cpp index 2d0550a..479f093 100644 --- a/modules/networkconnection/network_data.cpp +++ b/modules/networkconnection/network_data.cpp @@ -32,6 +32,7 @@ NetworkData::~NetworkData() void NetworkData::initialize() { // Initialize counter + this->_recieved_new_server_tick = false; this->_current_received_number = 0; this->_last_received_number = 0; this->_quit_id = 0; diff --git a/modules/networkconnection/network_data.h b/modules/networkconnection/network_data.h index 5650936..b6a648e 100644 --- a/modules/networkconnection/network_data.h +++ b/modules/networkconnection/network_data.h @@ -26,6 +26,8 @@ #include "core/reference.h" #include "modules/bitset/bitset.h" #include "core/ustring.h" +//#include "core/dictionary.h" +#include "core/array.h" //define MAX_LOOP_READ_BY_STEP 10 #define NUM_BITS_IN_LONG_ACK 1024 @@ -35,6 +37,7 @@ class NetworkData public: uint32_t _ack_bit_mask; + bool _recieved_new_server_tick; uint32_t _current_server_tick; uint32_t _current_client_tick; @@ -70,6 +73,10 @@ public: uint32_t _last_ack_1[2]; uint32_t _last_ack_2[4]; + //Dictionary _server_messages; + Array _server_messages; + + NetworkData(); ~NetworkData(); diff --git a/modules/networkconnection/state_connexion.cpp b/modules/networkconnection/state_connexion.cpp index 30ade29..770a05e 100644 --- a/modules/networkconnection/state_connexion.cpp +++ b/modules/networkconnection/state_connexion.cpp @@ -367,6 +367,25 @@ void StateConnectionConnected::send_system_ack_probe() 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 msgin) { bool valide = true; @@ -430,6 +449,7 @@ void StateConnectionConnected::receive_message(int index) } this->_data->_current_received_number = current_received_number; + this->_data->_recieved_new_server_tick = true; Ref msgin = field->get_msgin(); system_mode = msgin->get_bool(); @@ -484,6 +504,8 @@ void StateConnectionConnected::send_message() this->send_system_ack_sync(); if (this->_data->_latest_probes.size() != 0 ) this->send_system_ack_probe(); + if (this->_data->_recieved_new_server_tick == true) + this->send_system_ask_tick(); } /* * diff --git a/modules/networkconnection/state_connexion.h b/modules/networkconnection/state_connexion.h index 703a92e..b4aee5e 100644 --- a/modules/networkconnection/state_connexion.h +++ b/modules/networkconnection/state_connexion.h @@ -142,6 +142,7 @@ public: void send_system_disconnect(); void send_system_ack_sync(); void send_system_ack_probe(); + void send_system_ask_tick(); void receive_system_sync(Ref msgin); void receive_message(int index); void send_message();