diff --git a/assets/Scripts/Config/connexion.gd b/assets/Scripts/Config/connexion.gd index 4a0ba10..40eee31 100644 --- a/assets/Scripts/Config/connexion.gd +++ b/assets/Scripts/Config/connexion.gd @@ -20,6 +20,8 @@ class connexion: var _url_login = "https://lirria.khaganat.net/login/r2_login.php" # var _url_register = "http://149.91.80.160/ams/index.php?page=register" var _url_register = "http://lirria.khaganat.net/ams/index.php?page=register" + + var _config_filename = "user://connexion.cfg" var _language = "fr" var _valid_certificate = true @@ -31,7 +33,7 @@ class connexion: config_file.set_value("register", "url", _url_register) config_file.set_value("global", "valid_certificate", _valid_certificate) config_file.set_value("global", "language", _language) - config_file.save("user://connexion.cfg") + config_file.save(_config_filename) func _init(): print("[config connexion] Load connexion config") @@ -39,9 +41,9 @@ class connexion: var config_file = ConfigFile.new() # /home//.local/share/godot/app_userdata/Khanat/connexion.cfg - var err = config_file.load("user://connexion.cfg") + var err = config_file.load(_config_filename) if err: - print("Error code when loading player config file khanat.cfg: ", err) + print("Error code when loading player config file connexion.cfg: ", err) save() self._url_login = config_file.get_value("login", "url", self._url_login) diff --git a/gui_scene/GUI/Settings/Settings.gd b/gui_scene/GUI/Settings/Settings.gd index d4ea05b..075b9c5 100644 --- a/gui_scene/GUI/Settings/Settings.gd +++ b/gui_scene/GUI/Settings/Settings.gd @@ -4,53 +4,53 @@ signal return_pressed signal font_changed( value ) func _ready(): - $Menus/TabContainer/Display/ScrollContainer/VBoxContainer/Fullscreen/CheckBox.pressed = ProjectSettings.get_setting( "display/window/size/fullscreen" ) - $Menus/TabContainer/Display/ScrollContainer/VBoxContainer/Borderless/CheckBox.pressed = ProjectSettings.get_setting( "display/window/size/borderless" ) - $Menus/TabContainer/Display/ScrollContainer/VBoxContainer/Resizable/CheckBox.pressed = ProjectSettings.get_setting( "display/window/size/resizable" ) - $Menus/TabContainer/Display/ScrollContainer/VBoxContainer/CurrentScreen/SpinBox.value = OS.current_screen + $Menus/TabContainer/Display/ScrollContainer/VBoxContainer/Fullscreen/CheckBox.pressed = ProjectSettings.get_setting( "display/window/size/fullscreen" ) + $Menus/TabContainer/Display/ScrollContainer/VBoxContainer/Borderless/CheckBox.pressed = ProjectSettings.get_setting( "display/window/size/borderless" ) + $Menus/TabContainer/Display/ScrollContainer/VBoxContainer/Resizable/CheckBox.pressed = ProjectSettings.get_setting( "display/window/size/resizable" ) + $Menus/TabContainer/Display/ScrollContainer/VBoxContainer/CurrentScreen/SpinBox.value = OS.current_screen - $Menus/TabContainer/connexion/v_box_container/h_box_container4/language.add_item("fr") - $Menus/TabContainer/connexion/v_box_container/h_box_container4/language.add_item("en") - load_settings() + $Menus/TabContainer/connexion/v_box_container/h_box_container4/language.add_item("fr") + $Menus/TabContainer/connexion/v_box_container/h_box_container4/language.add_item("en") + load_settings() func _on_font_size_bar_value_changed(value): - $Menus/TabContainer/Test/ScrollContainer/VBoxContainer/font_size/font_size_value.text = str( value ) - $Menus.get_theme().default_font.size = value - emit_signal( "font_changed", value ) + $Menus/TabContainer/Test/ScrollContainer/VBoxContainer/font_size/font_size_value.text = str( value ) + $Menus.get_theme().default_font.size = value + emit_signal( "font_changed", value ) func load_settings(): - var config_file = ConfigFile.new() - var err = config_file.load( "user://settings.cfg" ) - if err == ERR_CANT_OPEN or err == ERR_FILE_NOT_FOUND: - # On suppose que le fichier n'existe pas encore, donc on le crée. - config_file.set_value( "theme", "font_size", 14 ) - config_file.save( "user://settings.cfg" ) - elif not err == OK: - print("[res://gui_scene/GUI/Settings/Settings.gd:load_settings] Error code when loading config file: ", err) + var config_file = ConfigFile.new() + var err = config_file.load( "user://settings.cfg" ) + if err == ERR_CANT_OPEN or err == ERR_FILE_NOT_FOUND: + # On suppose que le fichier n'existe pas encore, donc on le crée. + config_file.set_value( "theme", "font_size", 14 ) + config_file.save( "user://settings.cfg" ) + elif not err == OK: + print("[res://gui_scene/GUI/Settings/Settings.gd:load_settings] Error code when loading config file: ", err) - global.font_size = config_file.get_value( "theme", "font_size" ) - if $Menus.get_theme(): - $Menus.get_theme().default_font.size = global.font_size - $Menus/TabContainer/Test/ScrollContainer/VBoxContainer/font_size_bar.value = global.font_size - $Menus/TabContainer/Test/ScrollContainer/VBoxContainer/font_size/font_size_value.text = str( global.font_size ) + global.font_size = config_file.get_value( "theme", "font_size" ) + if $Menus.get_theme(): + $Menus.get_theme().default_font.size = global.font_size + $Menus/TabContainer/Test/ScrollContainer/VBoxContainer/font_size_bar.value = global.font_size + $Menus/TabContainer/Test/ScrollContainer/VBoxContainer/font_size/font_size_value.text = str( global.font_size ) - #var connexion = load("res://assets/Scripts/Config/connexion.gd").new() - var script_connexion = preload("res://assets/Scripts/Config/connexion.gd") - var connexion = script_connexion.connexion.new() - var language = connexion.get_language() - $Menus/TabContainer/connexion/v_box_container/h_box_container/register.text = connexion.get_url_register() - $Menus/TabContainer/connexion/v_box_container/h_box_container2/connexion.text = connexion.get_url_login() - $Menus/TabContainer/connexion/v_box_container/h_box_container3/certificate_valid.pressed = connexion.get_valid_certificate() - # language - for i in range(0, $Menus/TabContainer/connexion/v_box_container/h_box_container4/language.get_item_count()): - if $Menus/TabContainer/connexion/v_box_container/h_box_container4/language.get_item_text(i) == language: - $Menus/TabContainer/connexion/v_box_container/h_box_container4/language.select(i) - break - #$Menus/TabContainer/connexion/v_box_container/h_box_container4/language. - #.selected = language - #$Menus/TabContainer/connexion/v_box_container/h_box_container4/language.selected + #var connexion = load("res://assets/Scripts/Config/connexion.gd").new() + var script_connexion = preload("res://assets/Scripts/Config/connexion.gd") + var connexion = script_connexion.connexion.new() + var language = connexion.get_language() + $Menus/TabContainer/connexion/v_box_container/h_box_container/register.text = connexion.get_url_register() + $Menus/TabContainer/connexion/v_box_container/h_box_container2/connexion.text = connexion.get_url_login() + $Menus/TabContainer/connexion/v_box_container/h_box_container3/certificate_valid.pressed = connexion.get_valid_certificate() + # language + for i in range(0, $Menus/TabContainer/connexion/v_box_container/h_box_container4/language.get_item_count()): + if $Menus/TabContainer/connexion/v_box_container/h_box_container4/language.get_item_text(i) == language: + $Menus/TabContainer/connexion/v_box_container/h_box_container4/language.select(i) + break + #$Menus/TabContainer/connexion/v_box_container/h_box_container4/language. + #.selected = language + #$Menus/TabContainer/connexion/v_box_container/h_box_container4/language.selected #func _on_ReturnButton_pressed(): # var config_file = ConfigFile.new() @@ -63,64 +63,64 @@ func load_settings(): func _on_Title_text_changed(new_text): - # ---------------------------------- - # Changing windows title - var new_title = "Khanat" - new_text = new_text.strip_edges() - if not new_text == "": - new_title = new_text - new_title += " (" + String(OS.get_window_size().x) + "x" + String(OS.get_window_size().y) + ")" - OS.set_window_title( new_title ) - # ---------------------------------- + # ---------------------------------- + # Changing windows title + var new_title = "Khanat" + new_text = new_text.strip_edges() + if not new_text == "": + new_title = new_text + new_title += " (" + String(OS.get_window_size().x) + "x" + String(OS.get_window_size().y) + ")" + OS.set_window_title( new_title ) + # ---------------------------------- func _on_Fullscreen_toggled(button_pressed): - if ProjectSettings.has_setting( "display/window/size/fullscreen" ): - ProjectSettings.set_setting("display/window/size/fullscreen", button_pressed) - OS.window_fullscreen = ProjectSettings.get_setting("display/window/size/fullscreen") + if ProjectSettings.has_setting( "display/window/size/fullscreen" ): + ProjectSettings.set_setting("display/window/size/fullscreen", button_pressed) + OS.window_fullscreen = ProjectSettings.get_setting("display/window/size/fullscreen") func _on_Borderless_toggled(button_pressed): - if ProjectSettings.has_setting( "display/window/size/borderless" ): - ProjectSettings.set_setting("display/window/size/borderless", button_pressed) - OS.window_borderless = ProjectSettings.get_setting("display/window/size/borderless") + if ProjectSettings.has_setting( "display/window/size/borderless" ): + ProjectSettings.set_setting("display/window/size/borderless", button_pressed) + OS.window_borderless = ProjectSettings.get_setting("display/window/size/borderless") func _on_Resizable_toggled(button_pressed): - if ProjectSettings.has_setting( "display/window/size/resizable" ): - ProjectSettings.set_setting("display/window/size/resizable", button_pressed) - OS.window_resizable = ProjectSettings.get_setting("display/window/size/resizable") + if ProjectSettings.has_setting( "display/window/size/resizable" ): + ProjectSettings.set_setting("display/window/size/resizable", button_pressed) + OS.window_resizable = ProjectSettings.get_setting("display/window/size/resizable") # La fonction existe dans la doc mais le moteur lui ne la reconnait pas, # soit il y a une subtilité quelquepart soit la doc n'est pas à jour. func _on_AlwaysOnTop_toggled(button_pressed): # OS.set_window_always_on_top( button_pressed ) - pass + pass func _on_SpinBox_value_changed(value): - OS.current_screen = value + OS.current_screen = value func _on_ApplyButton_pressed(): - var config_file = ConfigFile.new() - var err = config_file.load( "user://settings.cfg" ) - if err: - print("[res://gui_scene/GUI/Settings/Settings.gd:_on_ApplyButton_pressed] Error code when loading config file: ", err) - config_file.set_value("theme", "font_size", $Menus.get_theme().default_font.size) - config_file.save( "user://settings.cfg" ) + var config_file = ConfigFile.new() + var err = config_file.load( "user://settings.cfg" ) + if err: + print("[res://gui_scene/GUI/Settings/Settings.gd:_on_ApplyButton_pressed] Error code when loading config file: ", err) + config_file.set_value("theme", "font_size", $Menus.get_theme().default_font.size) + config_file.save( "user://settings.cfg" ) - # Save Connexion - var script_connexion = preload("res://assets/Scripts/Config/connexion.gd") - var connexion = script_connexion.connexion.new() - connexion.set_url_register($Menus/TabContainer/connexion/v_box_container/h_box_container/register.text) - connexion.set_url_login($Menus/TabContainer/connexion/v_box_container/h_box_container2/connexion.text) - var id = $Menus/TabContainer/connexion/v_box_container/h_box_container4/language.get_selected_id() - var language = $Menus/TabContainer/connexion/v_box_container/h_box_container4/language.get_item_text(id) - connexion.set_language(language) - connexion.set_valid_certificate($Menus/TabContainer/connexion/v_box_container/h_box_container3/certificate_valid.pressed) - connexion.save() - emit_signal( "return_pressed" ) + # Save Connexion + var script_connexion = preload("res://assets/Scripts/Config/connexion.gd") + var connexion = script_connexion.connexion.new() + connexion.set_url_register($Menus/TabContainer/connexion/v_box_container/h_box_container/register.text) + connexion.set_url_login($Menus/TabContainer/connexion/v_box_container/h_box_container2/connexion.text) + var id = $Menus/TabContainer/connexion/v_box_container/h_box_container4/language.get_selected_id() + var language = $Menus/TabContainer/connexion/v_box_container/h_box_container4/language.get_item_text(id) + connexion.set_language(language) + connexion.set_valid_certificate($Menus/TabContainer/connexion/v_box_container/h_box_container3/certificate_valid.pressed) + connexion.save() + emit_signal( "return_pressed" ) func _on_CancelButton_pressed(): - emit_signal( "return_pressed" ) + emit_signal( "return_pressed" ) func _unhandled_input(event): - if event is InputEventKey: - if event.pressed and event.scancode == KEY_ESCAPE: - emit_signal( "return_pressed" ) + if event is InputEventKey: + if event.pressed and event.scancode == KEY_ESCAPE: + emit_signal( "return_pressed" ) diff --git a/gui_scene/GUI/Settings/Settings.tscn b/gui_scene/GUI/Settings/Settings.tscn index 11caf26..5632bea 100644 --- a/gui_scene/GUI/Settings/Settings.tscn +++ b/gui_scene/GUI/Settings/Settings.tscn @@ -71,6 +71,9 @@ custom_constants/margin_top = 0 custom_constants/margin_left = 0 custom_constants/margin_bottom = 0 script = ExtResource( 2 ) +__meta__ = { +"_edit_use_anchors_": false +} [node name="texture_rect" type="TextureRect" parent="."] margin_right = 1280.0 @@ -231,7 +234,6 @@ margin_top = 49.0 mouse_filter = 0 [node name="ScrollContainer" type="ScrollContainer" parent="Menus/TabContainer/Controles"] -editor/display_folded = true margin_right = 1280.0 margin_bottom = 574.0 size_flags_horizontal = 3 @@ -294,7 +296,6 @@ margin_bottom = -1.0 hint_tooltip = "Interface." [node name="Header" type="HBoxContainer" parent="Menus/TabContainer/Controles/ScrollContainer/TabContainer/Interface"] -editor/display_folded = true margin_right = 1022.0 margin_bottom = 38.0 @@ -401,7 +402,6 @@ margin_right = -1.0 margin_bottom = -1.0 [node name="Header" type="HBoxContainer" parent="Menus/TabContainer/Controles/ScrollContainer/TabContainer/Deplacement"] -editor/display_folded = true margin_right = 1022.0 margin_bottom = 37.0 @@ -707,8 +707,8 @@ margin_right = 1280.0 margin_bottom = 139.0 [node name="certificate_valid" type="CheckBox" parent="Menus/TabContainer/connexion/v_box_container/h_box_container3"] -margin_left = 485.0 -margin_right = 794.0 +margin_left = 517.0 +margin_right = 762.0 margin_bottom = 33.0 size_flags_horizontal = 6 size_flags_vertical = 6 diff --git a/login_scene/message_system.gd b/login_scene/message_system.gd index 78a70b4..c537ff8 100644 --- a/login_scene/message_system.gd +++ b/login_scene/message_system.gd @@ -6,25 +6,48 @@ extends Control # var b = "text" var _networkconnection = NetworkConnection.new() +var _history = Array() +const StringManager = preload("res://assets/Scripts/Config/string_manager.gd") +var _string_manager = StringManager.new() +var _phrases_not_decoded = Array() # Called when the node enters the scene tree for the first time. func _ready(): pass # Replace with function body. +func analyze_message(message): + if message['action'] == Action.ACTION_POSITION_CODE: + pass + elif message['action'] == Action.ACTION_GENERIC_CODE: + if message['impulse'] == ImpulseBase.STRING_MANAGER_RELOAD_CACHE: + print(message['timestamp']) + _string_manager.set_timestamp(message['timestamp']) + elif message['impulse'] == ImpulseBase.STRING_MANAGER_PHRASE_SEND: + if _string_manager.check_phases(message['dynId']) == false: + _phrases_not_decoded.append(message) + var command = {'action': Action.ACTION_GENERIC_CODE, 'impulse': ImpulseBase.STRING_MANAGER_STRING_RQ, "stringId": message['dynId']} + _networkconnection.put_command(command); + _networkconnection.put_command(command); + return # Called every frame. 'delta' is the elapsed time since the previous frame. func _process(delta): _networkconnection.process(delta) var data = _networkconnection.get_server_messages() ##print("******* data:", data.size(), data) - if data.size() > 0: + while data.size() >0: + var message = data.pop_front() + _history.append(message) + print(message) + analyze_message(message) + if _history.size() > 0: # just to see last message (normally cleanned each time we read message) - while data.size() > 10: - var ele = data.pop_front() - print("*** remove:" , ele) + while _history.size() > 10: + var element = _history.pop_front() + print("*** remove:" , element) var message = "tick :" + String(_networkconnection.get_server_tick()) + '\n' - for i in range(0, data.size()): - message += String(data[i]) + '\n' + for i in range(0, _history.size()): + message += String(_history[i]) + '\n' $label.text = message func _show(): diff --git a/modules/action/action_factory.cpp b/modules/action/action_factory.cpp index dd7a0b6..f156e9a 100644 --- a/modules/action/action_factory.cpp +++ b/modules/action/action_factory.cpp @@ -21,6 +21,7 @@ #include "core/reference.h" #include "core/array.h" #include "core/dictionary.h" +#include "core/list.h" #include "modules/debug/debug.h" #include "modules/networkconnection/network_data.h" #include "modules/networkconnection/state_connexion.h" @@ -28,6 +29,8 @@ #include "modules/referentialmessage/referentialmessagecore.h" #include "modules/impulse/impulsebase.h" #include "action_factory.h" +#include "action_genericmultipart.h" +#include "action.h" void ActionFactory::decode_message(NetworkData * data, Ref msgin) { @@ -35,9 +38,11 @@ void ActionFactory::decode_message(NetworkData * data, Ref msgin) ReferentialMessage ref_msg; uint32_t id = ref_msg.read_command(msgin); DBG_PRINT("Decode message:" + ImpulseBase::get_command_name(id)); - value["command"] = id; + value["action"] = Action::CODE::ACTION_GENERIC_CODE; + value["impulse"] = id; #ifdef DEBUG_ENABLED - value["command_debug"] = ImpulseBase::get_command_name(id); + value["action_debug"] = "ACTION_GENERIC_CODE"; + value["impulse_debug"] = ImpulseBase::get_command_name(id); #endif switch(id) { @@ -67,6 +72,65 @@ void ActionFactory::decode_message(NetworkData * data, Ref msgin) } case ImpulseBase::Impulse::CONNECTION_USER_CHARS: { + // khanat-opennel-code/code/ryzom/client/src/net_manager.cpp void impulseUserChars(NLMISC::CBitMemStream &impulse) + // khanat-opennel-code/code/ryzom/server/src/entities_game_service/entity_manager/entity_callbacks.cpp void sendCharactersSummary( CPlayer *player, bool AllAutorized, uint32 bitfieldOwnerOfActiveAnimSession, uint32 bitfieldOwnerOfEditSession ) + uint32_t i; + value["ServerPeopleActive"] = msgin->get_uint8(); + value["ServerCareerActive"] = msgin->get_uint8(); + uint32_t character_summaries_Len = msgin->get_uint32(); + + value["CharacterSummaries_Len"] = character_summaries_Len; + Array character_summaries; + for(i=0;iget_version(); + character["Mainland"] = msgin->get_uint32(); + character["Name"] = msgin->get_ustring(); + character["People"] = msgin->get_uint32(); + character["Location"] = msgin->get_uint32(); + character["VisualPropA"] = msgin->get_uint64(); + character["VisualPropB"] = msgin->get_uint64(); + character["VisualPropC"] = msgin->get_uint64(); + character["SheetId"] = msgin->get_uint32(); + character["Title"] = msgin->get_sint32(); + character["CharacterSlot"] = msgin->get_uint8(); + character["InRingSession"] = msgin->get_bool(); + character["HasEditSession"] = msgin->get_bool(); + character["InNewbieland"] = msgin->get_bool(); + character_summaries.append(character); + } + value["CharacterSummaries"] = character_summaries; + + uint32_t shard_names_Len = msgin->get_uint32(); + value["shardNames_Len"] = shard_names_Len; + Array shard_names; + for(i=0;iget_string(); + shard_names.append(shard_name); + } + value["ShardNames"] = shard_names; + + value["Privileges"] = msgin->get_string(); + value["FreeTrial"] = msgin->get_bool(); + + uint32_t mainlands_len = msgin->get_uint32(); + value["Mainlands_Len"] = mainlands_len; + Array mainlands; + for(i=0;iget_uint32(); + mainland["Name"] = msgin->get_ustring(); + mainland["Description"] = msgin->get_ustring(); + mainland["LanguageCode"] = msgin->get_string(); + mainland["Online"] = msgin->get_bool(); + mainlands.append(mainland); + } + value["Mainlands"] = mainlands; + break; } case ImpulseBase::Impulse::CONNECTION_CREATE_CHAR: @@ -935,6 +999,17 @@ void ActionFactory::decode_message(NetworkData * data, Ref msgin) } case ImpulseBase::Impulse::STRING_MANAGER_PHRASE_SEND: { + int i = 1; + uint32_t dynId = msgin->get_uint32(); + value["dynId"] = dynId; + uint32_t StringId = msgin->get_uint32(); + value["StringId_0"] = StringId; + while(msgin->number_bit_not_read() > 32) + { + StringId = msgin->get_uint32(); + value["StringId_" + itos(i)] = StringId; + ++i; + } break; } case ImpulseBase::Impulse::STRING_MANAGER_STRING_RQ: @@ -953,7 +1028,7 @@ void ActionFactory::decode_message(NetworkData * data, Ref msgin) //param.push_back(timestamp); value["timestamp"] = timestamp; - data->_server_messages.push_back(value); + //data->_server_messages.push_back(value); break; } case ImpulseBase::Impulse::GUILD_CREATE: @@ -1389,6 +1464,7 @@ void ActionFactory::decode_message(NetworkData * data, Ref msgin) break; } } + data->_server_messages.push_back(value); #ifdef DEBUG_ENABLED // Check if we have read all data - only on debug mode { @@ -1397,7 +1473,8 @@ void ActionFactory::decode_message(NetworkData * data, Ref msgin) { DBG_PRINT("Read : " + itos(msgin->number_bit_not_read())); if ( msgin->number_bit_not_read() >= 8 ) - last_data = msgin->get_uint8(); + //last_data = msgin->get_uint8(); + last_data = 1; else last_data = msgin->get_serial(msgin->number_bit_not_read()); if ( last_data != 0 ) @@ -1411,6 +1488,156 @@ void ActionFactory::decode_message(NetworkData * data, Ref msgin) #endif } +void ActionFactory::encode_message(Dictionary value, Ref msgout) +{ + ReferentialMessage ref_msg; + int id = value["impulse"]; + + ref_msg.write_command((ImpulseBase::Impulse)id, msgout); + DBG_PRINT("[ActionFactory::pack] ACTION_GENERIC_CODE encode_message A:" + itos(id) + " / " + msgout->show_detail()); + switch(id) + { + case ImpulseBase::Impulse::TARGET_PARTY: + { + break; + } + case ImpulseBase::Impulse::STRING_MANAGER_STRING_RQ: + { + uint32_t stringId = value["stringId"]; + msgout->put_uint32(stringId); + DBG_PRINT("[ActionFactory::pack] ACTION_GENERIC_CODE encode_message B:" + itos(id) + " / " + msgout->show_detail()); + break; + } + default: + { + break; + } + } +} + +void ActionFactory::code(int code, Ref msgout) +{ + if(code < 4) + { + msgout->put_bool(true); + msgout->put_serial(code, 2); + } + else + { + msgout->put_bool(false); + msgout->put_uint8(code); + } +} + +void ActionFactory::pack(NetworkData * data) +{ + while(data->_command_to_send.size()) + { + DBG_PRINT("[ActionFactory::pack]"); + Dictionary value = data->_command_to_send.pop_front(); + int id = value["action"]; + switch(id) + { + case Action::CODE::ACTION_POSITION_CODE: + { + break; + } + case Action::CODE::ACTION_GENERIC_CODE: + case Action::CODE::ACTION_GENERIC_MULTI_PART_CODE: + { + Ref msg; + msg.instance(); + encode_message(value, msg); + DBG_PRINT("[ActionFactory::pack] ACTION_GENERIC_CODE encode_message :" + msg->show_detail()); + + if( msg->size_data() < MAX_IMPULSE_BIT_SIZE ) // 1840 bits= 230*8 + { + // ACTION_GENERIC_CODE + Ref msgout; + msgout.instance(); + code(Action::CODE::ACTION_GENERIC_CODE, msgout); + msg->complet_byte(); + DBG_PRINT("[ActionFactory::pack] ACTION_GENERIC_CODE encode_message (Bis):" + msg->show_detail()); + DBG_PRINT("[ActionFactory::pack] ACTION_GENERIC_CODE prepared A :" + msgout->show_detail()); + msgout->put_uint32(msg->size()); + DBG_PRINT("[ActionFactory::pack] ACTION_GENERIC_CODE prepared B :" + msgout->show_detail()); + msgout->put_bitstream(msg.ptr()); + DBG_PRINT("[ActionFactory::pack] ACTION_GENERIC_CODE prepared C :" + msgout->show_detail()); + data->_client_messages.append(msgout); //data->_client_messages.append(msgout->get_data()); + DBG_PRINT("[ActionFactory::pack] ACTION_GENERIC_CODE prepared D :" + msgout->show_detail()); + msgout.unref(); + } + else + { + // ACTION_GENERIC_MULTI_PART_CODE + uint32_t size; + uint32_t last = 0; + uint32_t minimumBitSizeForMP = 1 + 2 + 2 + 4; // header + uint32_t availableSize = (MAX_IMPULSE_BIT_SIZE - minimumBitSizeForMP); // 8 + uint32_t bytelen = msg->size(); + uint16_t part; + uint16_t nbBlock = (bytelen + availableSize - 1); // availableSize + uint8_t num = data->_impulse_multi_part_number; + PoolByteArray msgTemp; + data->_impulse_multi_part_number += 1; + msg->complet_byte(); + for(part = 0 ; part < nbBlock ; ++part) + { + Ref msgout; + msgout.instance(); + code(Action::CODE::ACTION_GENERIC_MULTI_PART_CODE, msgout); + msgout->put_uint8(num); + msgout->put_uint16(part); + msgout->put_uint16(nbBlock); + size = availableSize; + if ( size + last > bytelen) + size = bytelen - last; + last = size; + msgout->put_uint32(size); + msgout->get_array_uint8(size); + //msgout->put_bitstream(msg.ptr());-------TODO + data->_client_messages.append(msgout); // data->_client_messages.append(msgout->get_data()); + DBG_PRINT("[ActionFactory::pack] ACTION_GENERIC_MULTI_PART_CODE prepared :" + msgout->show_detail()); + msgout.unref(); + } + } + msg.unref(); + break; + } + case Action::CODE::ACTION_SINT64: + { + break; + } + case Action::CODE::ACTION_SYNC_CODE: + { + // not used, here + break; + } + case Action::CODE::ACTION_DISCONNECTION_CODE: + { + break; + } + case Action::CODE::ACTION_ASSOCIATION_CODE: + { + break; + } + case Action::CODE::ACTION_LOGIN_CODE: + { + // not used, here + break; + } + case Action::CODE::ACTION_TARGET_SLOT_CODE: + { + break; + } + case Action::CODE::ACTION_DUMMY_CODE: + { + break; + } + } + } +} + void ActionFactory::unpack(NetworkData * data, Ref msgin) { bool shortcode = msgin->get_bool(); @@ -1423,7 +1650,7 @@ void ActionFactory::unpack(NetworkData * data, Ref msgin) DBG_PRINT("code:" + itos(code)); switch (code) { - case ACTIONCODE::ACTION_POSITION_CODE: + case Action::CODE::ACTION_POSITION_CODE: { // khanat-opennel-code/code/ryzom/common/src/game_share/action_position.cpp:34 void CActionPosition::unpack (NLMISC::CBitMemStream &message) // px ( 16 bit unsigned ) @@ -1431,21 +1658,32 @@ void ActionFactory::unpack(NetworkData * data, Ref msgin) // pz ( 16 bit unsigned ) : low bit have other signification // 0x01 : IsRelative // 0x02 : Interior - DBG_PRINT("ACTION_GENERIC_CODE"); + DBG_PRINT("ACTION_POSITION_CODE"); uint16_t px = msgin->get_uint16(); uint16_t py = msgin->get_uint16(); uint16_t pz = msgin->get_uint16(); bool IsRelative = (pz & 0x1) != 0; bool Interior = (pz & 0x2) != 0; - DBG_PRINT("ACTION_GENERIC_CODE px:" + uitos(px) + " py:" + uitos(py) + " pz:" + uitos(pz) + " IsRelative:" + uitos(IsRelative) + " Interior:" + uitos(Interior)); + Dictionary msg; + msg["action"] = code; + #ifdef DEBUG_ENABLED + msg["action_debug"] = "ACTION_POSITION_CODE"; + #endif + msg["px"] = px; + msg["py"] = px; + msg["pz"] = px; + msg["IsRelative"] = IsRelative; + msg["Interior"] = Interior; + data->_server_messages.push_back(msg); + DBG_PRINT("ACTION_POSITION_CODE px:" + uitos(px) + " py:" + uitos(py) + " pz:" + uitos(pz) + " IsRelative:" + uitos(IsRelative) + " Interior:" + uitos(Interior)); break; } - case ACTIONCODE::ACTION_GENERIC_CODE: + case Action::CODE::ACTION_GENERIC_CODE: { - DBG_PRINT("ACTION_GENERIC_CODE"); // khanat-opennel-code/code/ryzom/common/src/game_share/action_generic.cpp void CActionGeneric::unpack (NLMISC::CBitMemStream &message) // size ( 32 bits unsigned ) : if size > 512 we have an error (normally reject by server) // StreamByte ( Array : size * 8 bits unsigned ) + DBG_PRINT("ACTION_GENERIC_CODE"); uint32_t size = msgin->get_uint32(); DBG_PRINT("ACTION_GENERIC_CODE size:" + uitos(size)); PoolByteArray StreamByte = msgin->get_array_uint8(size); @@ -1458,96 +1696,183 @@ void ActionFactory::unpack(NetworkData * data, Ref msgin) tmp.unref(); break; } - case ACTIONCODE::ACTION_GENERIC_MULTI_PART_CODE: + case Action::CODE::ACTION_GENERIC_MULTI_PART_CODE: { - DBG_PRINT("ACTION_GENERIC_MULTI_PART_CODE"); // khanat-opennel-code/code/ryzom/common/src/game_share/action_generic_multi_part.h:46 virtual void unpack (NLMISC::CBitMemStream &message) // Number ( 8 bits unsigned ) // Part ( 16 bits unsigned ) // NbBlock ( 16 bits unsigned ) // size ( 32 bits unsigned ) // PartCont ( Array : size * 8 bits unsigned ) + DBG_PRINT("ACTION_GENERIC_MULTI_PART_CODE"); uint8_t Number = msgin->get_uint8(); uint16_t Part = msgin->get_uint16(); uint16_t NbBlock = msgin->get_uint16(); uint32_t size = msgin->get_uint32(); PoolByteArray StreamByte = msgin->get_array_uint8(size); - //BitStream StreamByte = msgin->get_bitstream(size); DBG_PRINT("ACTION_GENERIC_MULTI_PART_CODE Number:" + uitos(Number) + " Part:" + uitos(Part) + " NbBlock:" + uitos(NbBlock) + " size:" + uitos(size)); + if ( ! data->_block.has(Number) ) + { + Dictionary newelement; + data->_block[Number] = newelement; + data->_block_used[Number] = 0; + //data->_block[Number] = new GenericMultiPart(Number, NbBlock); + } + Dictionary ele = data->_block[Number]; //[Part] = StreamByte; + ele[Part] = StreamByte; + { + Ref tmp; + tmp.instance(); + tmp->put_array_uint8(StreamByte); + tmp.unref(); + } + if( ele.size() == NbBlock) + { + int used = data->_block_used[Number]; + if ( used != 0 ) + break; + int i; + PoolByteArray full; + for(i = 0;i < NbBlock; ++i) + { + PoolByteArray tmp = ele[i]; + full.append_array(ele[i]); + } + Ref tmp; + tmp.instance(); + tmp->put_array_uint8(full); + decode_message(data, tmp); + tmp.unref(); + data->_block_used[Number] = 20; + } break; } - case ACTIONCODE::ACTION_SINT64: + case Action::CODE::ACTION_SINT64: { - DBG_PRINT("ACTION_SINT64"); // khanat-opennel-code/code/ryzom/common/src/game_share/action_sint64.cpp:86 void CActionSint64::unpack (NLMISC::CBitMemStream &message) // value ( 64 bits unsigned ) + DBG_PRINT("ACTION_SINT64"); uint64_t value = msgin->get_uint64(); + Dictionary msg; + msg["action"] = code; + #ifdef DEBUG_ENABLED + msg["action_debug"] = "ACTION_SINT64"; + #endif + msg["value"] = value; + data->_server_messages.push_back(msg); DBG_PRINT("ACTION_SINT64 value:" + uitos(value)); break; } - case ACTIONCODE::ACTION_SYNC_CODE: + case Action::CODE::ACTION_SYNC_CODE: { - DBG_PRINT("ACTION_SYNC_CODE"); // khanat-opennel-code/code/ryzom/common/src/game_share/action_sync.h:44 virtual void unpack (NLMISC::CBitMemStream &message) // Sync ( 32 bits unsigned ) // BKEntityId ( 64 bits unsigned ) [see definition : khanat-opennel-code/code/nel/include/nel/misc/entity_id.h:64] + DBG_PRINT("ACTION_SYNC_CODE"); uint32_t Sync = msgin->get_uint32(); uint64_t BKEntityId = msgin->get_uint64(); + Dictionary msg; + msg["action"] = code; + #ifdef DEBUG_ENABLED + msg["action_debug"] = "ACTION_SYNC_CODE"; + #endif + msg["Sync"] = Sync; + msg["BKEntityId"] = BKEntityId; + data->_server_messages.push_back(msg); DBG_PRINT("ACTION_SYNC_CODE Sync:" + uitos(Sync) + " BKEntityId:" + uitos(BKEntityId)); break; } - case ACTIONCODE::ACTION_DISCONNECTION_CODE: + case Action::CODE::ACTION_DISCONNECTION_CODE: { // khanat-opennel-code/code/ryzom/common/src/game_share/action_disconnection.h // No data DBG_PRINT("ACTION_DISCONNECTION_CODE"); + Dictionary msg; + msg["action"] = code; + #ifdef DEBUG_ENABLED + msg["action_debug"] = "ACTION_DISCONNECTION_CODE"; + #endif + data->_server_messages.push_back(msg); break; } - case ACTIONCODE::ACTION_ASSOCIATION_CODE: + case Action::CODE::ACTION_ASSOCIATION_CODE: { - DBG_PRINT("ACTION_ASSOCIATION_CODE"); // khanat-opennel-code/code/ryzom/common/src/game_share/action_association.h virtual void unpack (NLMISC::CBitMemStream &message) // IsNewAssociation ( bool / 1 bit ) // if IsNewAssociation is true: // SheetId ( 32 bits unsigned ) // Replace ( bool / 1 bit ) + DBG_PRINT("ACTION_ASSOCIATION_CODE"); uint32_t SheetId = msgin->get_uint32(); bool Replace = msgin->get_bool(); + Dictionary msg; + msg["action"] = code; + #ifdef DEBUG_ENABLED + msg["action_debug"] = "ACTION_ASSOCIATION_CODE"; + #endif + msg["SheetId"] = SheetId; + msg["Replace"] = Replace; + data->_server_messages.push_back(msg); DBG_PRINT("ACTION_ASSOCIATION_CODE SheetId:" + uitos(SheetId) + " Replace:" + uitos(Replace)); break; } - case ACTIONCODE::ACTION_LOGIN_CODE: + case Action::CODE::ACTION_LOGIN_CODE: { - DBG_PRINT("ACTION_LOGIN_CODE"); // khanat-opennel-code/code/ryzom/common/src/game_share/action_login.h virtual void unpack (NLMISC::CBitMemStream &message) // ua ( 32 bits unsigned ) // uk ( 32 bits unsigned ) // ui ( 32 bits unsigned ) + DBG_PRINT("ACTION_LOGIN_CODE"); uint32_t ua = msgin->get_uint32(); uint32_t uk = msgin->get_uint32(); uint32_t ui = msgin->get_uint32(); + Dictionary msg; + msg["action"] = code; + #ifdef DEBUG_ENABLED + msg["action_debug"] = "ACTION_LOGIN_CODE"; + #endif + msg["ua"] = ua; + msg["uk"] = uk; + msg["ui"] = ui; + data->_server_messages.push_back(msg); DBG_PRINT("ACTION_LOGIN_CODE ua:" + uitos(ua) + " uk:" + uitos(uk)+ " ui:" + uitos(ui)); break; } - case ACTIONCODE::ACTION_TARGET_SLOT_CODE: + case Action::CODE::ACTION_TARGET_SLOT_CODE: { - DBG_PRINT("ACTION_TARGET_SLOT_CODE"); // khanat-opennel-code/code/ryzom/common/src/game_share/action_target_slot.h virtual void unpack (NLMISC::CBitMemStream &message) // Slot ( 8 bits unsigned ) // TargetOrPickup (2 bits unsigned) + DBG_PRINT("ACTION_TARGET_SLOT_CODE"); uint8_t Slot = msgin->get_uint8(); uint32_t TargetOrPickup = msgin->get_serial(2); + Dictionary msg; + msg["action"] = code; + #ifdef DEBUG_ENABLED + msg["action_debug"] = "ACTION_TARGET_SLOT_CODE"; + #endif + msg["Slot"] = Slot; + msg["TargetOrPickup"] = TargetOrPickup; + data->_server_messages.push_back(msg); DBG_PRINT("ACTION_TARGET_SLOT_CODE Slot:" + uitos(Slot) + " TargetOrPickup:" + uitos(TargetOrPickup)); break; } - case ACTIONCODE::ACTION_DUMMY_CODE: + case Action::CODE::ACTION_DUMMY_CODE: { - DBG_PRINT("ACTION_DUMMY_CODE"); // khanat-opennel-code/code/ryzom/common/src/game_share/action_dummy.h virtual void unpack (NLMISC::CBitMemStream &message) // Dummy1 ( 32 bits unsigned ) // Dummy2 ( 32 bits unsigned ) + DBG_PRINT("ACTION_DUMMY_CODE"); uint32_t Dummy1 = msgin->get_uint32(); uint32_t Dummy2 = msgin->get_uint32(); + Dictionary msg; + msg["action"] = code; + #ifdef DEBUG_ENABLED + msg["action_debug"] = "ACTION_DUMMY_CODE"; + #endif + msg["Dummy1"] = Dummy1; + msg["Dummy2"] = Dummy2; + data->_server_messages.push_back(msg); DBG_PRINT("ACTION_DUMMY_CODE Dummy1:" + uitos(Dummy1) + " Dummy2:" + uitos(Dummy2)); break; } @@ -1570,6 +1895,7 @@ void ActionFactory::decode(NetworkData * data, Ref msgin) int channel; int num; data->_last_received_ack = msgin->get_uint32(); + DBG_PRINT("last_received_ack:" + itos(data->_last_received_ack)); for( level=0 ; level < 3 ; ++level ) { DBG_PRINT("level:" + itos(level)); @@ -1611,5 +1937,47 @@ void ActionFactory::decode(NetworkData * data, Ref msgin) next = msgin->get_bool(); DBG_PRINT("next:" + itos(next)); } - } + } + clear_old_block(data); +} + +void ActionFactory::clear_old_block(NetworkData * data) +{ + int i; + + i = data->_block.size(); + while(i>0) + { + i--; + Variant value = data->_block_used.get_value_at_index(i); + Variant key = data->_block_used.get_key_at_index(i); + int used = data->_block_used[key]; + if ( used >= 2 ) + { + used --; + data->_block_used[key] = used; + } + else if ( used > 0 ) + { + data->_block_used.erase(key); + data->_block.erase(key); + DBG_PRINT("Remove block - key:" + String(key)); + } + } +} + +void ActionFactory::clear_all_block(NetworkData * data) +{ + int i; + + DBG_PRINT("Remove all block"); + i = data->_block.size(); + while(i>0) + { + i--; + Variant key = data->_block_used.get_key_at_index(i); + data->_block_used.erase(key); + data->_block.erase(key); + DBG_PRINT("Remove block: key:" + String(key)); + } } \ No newline at end of file diff --git a/modules/action/action_factory.h b/modules/action/action_factory.h index 5097228..cdde3b9 100644 --- a/modules/action/action_factory.h +++ b/modules/action/action_factory.h @@ -24,12 +24,20 @@ #include "core/object.h" #include "modules/networkconnection/network_data.h" +// 1840 bits= 230*8 +#define MAX_IMPULSE_BIT_SIZE 1840 + class ActionFactory { public: - void decode_message(NetworkData * data, Ref msgin); - void unpack(NetworkData * data, Ref msgin); - void decode(NetworkData * data, Ref msgin); + static void decode_message(NetworkData * data, Ref msgin); + static void encode_message(Dictionary value, Ref msgout); + static void code(int code, Ref msgout); + static void pack(NetworkData * data); + static void unpack(NetworkData * data, Ref msgin); + static void decode(NetworkData * data, Ref msgin); + static void clear_old_block(NetworkData * data); + static void clear_all_block(NetworkData * data); }; #endif \ No newline at end of file diff --git a/modules/action/register_types.cpp b/modules/action/register_types.cpp index 9934347..e15e39e 100644 --- a/modules/action/register_types.cpp +++ b/modules/action/register_types.cpp @@ -3,10 +3,11 @@ #include "register_types.h" #include "core/class_db.h" -#include "action_factory.h" +//#include "action_factory.h" +#include "action.h" void register_action_types() { - //ClassDB::register_class(); + ClassDB::register_class(); } void unregister_action_types() { diff --git a/modules/bitstream/bitstream.cpp b/modules/bitstream/bitstream.cpp index 9037cb8..f3cb0f4 100644 --- a/modules/bitstream/bitstream.cpp +++ b/modules/bitstream/bitstream.cpp @@ -21,6 +21,7 @@ Build : */ #include "modules/bitstream/bitstream.h" +#include "modules/debug/debug.h" // TODO - check if on godot we have a function or variable to get if processor is little_endian or not bool little_endian = false; @@ -31,6 +32,7 @@ void BitStream::_bind_methods() ClassDB::bind_method(D_METHOD("is_little_endian"), &BitStream::is_little_endian); + ClassDB::bind_method(D_METHOD("complet_byte"), &BitStream::complet_byte); ClassDB::bind_method(D_METHOD("size"), &BitStream::size); ClassDB::bind_method(D_METHOD("size_data"), &BitStream::size_data); ClassDB::bind_method(D_METHOD("number_bit_not_read"), &BitStream::number_bit_not_read); @@ -49,6 +51,7 @@ void BitStream::_bind_methods() ClassDB::bind_method(D_METHOD("put_string", "value"), &BitStream::put_string); ClassDB::bind_method(D_METHOD("put_string_hexa32", "hexa"), &BitStream::put_string_hexa32); ClassDB::bind_method(D_METHOD("put_array_uint8", "value"), &BitStream::put_array_uint8); + ClassDB::bind_method(D_METHOD("put_version", "value"), &BitStream::put_version); ClassDB::bind_method(D_METHOD("show"), &BitStream::show); ClassDB::bind_method(D_METHOD("show_detail"), &BitStream::show_detail); @@ -67,7 +70,10 @@ void BitStream::_bind_methods() ClassDB::bind_method(D_METHOD("get_uint32"), &BitStream::get_uint32); ClassDB::bind_method(D_METHOD("get_sint64"), &BitStream::get_sint64); ClassDB::bind_method(D_METHOD("get_uint64"), &BitStream::get_uint64); + ClassDB::bind_method(D_METHOD("get_version", "value"), &BitStream::get_version); ClassDB::bind_method(D_METHOD("get_array_uint8", "length"), &BitStream::get_array_uint8); + ClassDB::bind_method(D_METHOD("get_string"), &BitStream::get_string); + ClassDB::bind_method(D_METHOD("get_ustring"), &BitStream::get_ustring); } void BitStream::clear() @@ -100,17 +106,23 @@ bool BitStream::is_little_endian() return little_endian; } -int BitStream::size() +void BitStream::complet_byte() +{ + // function to add 0 and have size multiple of 8 bit + this->_pos = ((this->_pos + 7) / 8) * 8; +} + +uint32_t BitStream::size() { return (this->_pos + 7) / 8; } -int BitStream::size_data() +uint32_t BitStream::size_data() { return this->_pos; } -int BitStream::number_bit_not_read() +uint32_t BitStream::number_bit_not_read() { return this->_pos - this->_read; } @@ -255,6 +267,60 @@ void BitStream::put_array_uint8(PoolByteArray value) this->put_serial(value[i], 8); } +void BitStream::put_bitstream(BitStream & value) +{ + uint32_t last_read; + uint32_t nb; + last_read = value._read; + value._read = 0; + while ( value.number_bit_not_read() >= 32 ) + put_uint32(value.get_uint32()); + while ( value.number_bit_not_read() >= 16 ) + put_uint16(value.get_uint16()); + while ( value.number_bit_not_read() >= 8 ) + put_uint8(value.get_uint8()); + nb = value.number_bit_not_read(); + if( nb > 0 ) + put_serial(value.get_serial(nb), nb); + + // restore pos read + value._read = last_read; +} + +void BitStream::put_bitstream(BitStream * value) +{ + uint32_t last_read; + uint32_t nb; + last_read = value->_read; + value->_read = 0; + while ( value->number_bit_not_read() >= 32 ) + put_uint32(value->get_uint32()); + while ( value->number_bit_not_read() >= 16 ) + put_uint16(value->get_uint16()); + while ( value->number_bit_not_read() >= 8 ) + put_uint8(value->get_uint8()); + nb = value->number_bit_not_read(); + if( nb > 0 ) + put_serial(value->get_serial(nb), nb); + DBG_PRINT("put_bitstream: " + itos(nb) + " / " + itos(_pos)); + + // restore pos read + value->_read = last_read; +} + +void BitStream::put_version(uint32_t value) +{ + if ( value < 255 ) // 0xff + { + this->put_uint8(value); + } + else + { + this->put_uint8(255); + this->put_uint32(value); + } +} + String BitStream::show() { String ret; @@ -308,7 +374,9 @@ String BitStream::show_detail() while ( t > 0 ) { const char c = '0' + ( t % 10 ); - strsize = String(&c) + strsize; + CharString tmp ; + tmp += c; + strsize = tmp + strsize; t /= 10; } @@ -318,11 +386,13 @@ String BitStream::show_detail() while ( t > 0 ) { const char c = '0' + ( t % 10 ); - strpos = String(&c) + strpos; + CharString tmp ; + tmp += c; + strpos = tmp + strpos; t /= 10; } - return "[size:" + strsize + ", pos:" + strpos + "]" + ret ; + return "[size:" + String(strsize) + ", pos:" + String(strpos) + "]" + ret ; } String BitStream::show_counter() @@ -466,14 +536,32 @@ uint64_t BitStream::get_uint64() return (v1 << 32) | v2; } +uint32_t BitStream::get_version() +{ + uint32_t ret; + ret = this->get_uint8(); + if ( ret == 255 ) // 0xff + { + ret = this->get_uint32(); + } + return ret; +} + PoolByteArray BitStream::get_array_uint8(uint32_t length) { PoolByteArray ret; - while(length != 0) + while(length > 0) { ret.append(this->get_serial(8)); --length; } + /* + if (length == 1) + { + int nb = this->number_bit_not_read(); + ret.append(this->get_serial(nb)); + } + */ return ret; } @@ -486,4 +574,48 @@ BitStream BitStream::get_bitstream(uint32_t length) --length; } return a; +} + +String BitStream::get_string() +{ + String ret; + uint32_t size = this->get_uint32(); + union S { + uint8_t v; + char c; + }; + + while(size > 0) + { + S x; + x.v = this->get_uint8(); + CharString cs; + cs += x.c; + ret += cs; + --size; + } + return ret; +} + +String BitStream::get_ustring() +{ + // Read Utf-16 + String ret; + uint32_t size = this->get_uint32(); + union S { + uint16_t v; + char c[2]; + }; + + while(size > 0) + { + S x; + x.v = this->get_uint16(); + CharString cs; + cs += x.c[0]; + cs += x.c[1]; + ret += cs; + --size; + } + return ret; } \ No newline at end of file diff --git a/modules/bitstream/bitstream.h b/modules/bitstream/bitstream.h index 619c07c..12d7455 100644 --- a/modules/bitstream/bitstream.h +++ b/modules/bitstream/bitstream.h @@ -40,9 +40,11 @@ public: bool is_little_endian(); - int size(); - int size_data(); - int number_bit_not_read(); + void complet_byte(); + + uint32_t size(); + uint32_t size_data(); + uint32_t number_bit_not_read(); void put_serial(uint32_t value, uint32_t nbits); void put_bool(bool value); @@ -58,6 +60,9 @@ public: void put_char(String value); void put_string(String value); void put_array_uint8(PoolByteArray value); + void put_bitstream(BitStream & value); + void put_bitstream(BitStream * value); + void put_version(uint32_t value); String show(); String show_detail(); @@ -79,8 +84,11 @@ public: uint32_t get_uint32(); int64_t get_sint64(); uint64_t get_uint64(); + uint32_t get_version(); PoolByteArray get_array_uint8(uint32_t length); BitStream get_bitstream(uint32_t length); + String get_string(); + String get_ustring(); }; #endif diff --git a/modules/networkconnection/network_connection.cpp b/modules/networkconnection/network_connection.cpp index 997af48..85fc72f 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("put_command"), &NetworkConnection::put_command); ClassDB::bind_method(D_METHOD("get_server_messages"), &NetworkConnection::get_server_messages); ClassDB::bind_method(D_METHOD("get_server_tick"), &NetworkConnection::get_server_tick); ClassDB::bind_method(D_METHOD("terminate_network_connection"), &NetworkConnection::terminate_network_connection); @@ -92,6 +93,11 @@ MessageDescriptionNode & NetworkConnection::get_master_message_description_node( } */ +void NetworkConnection::put_command(Variant command) +{ + NetworkConnectionCore::get_singleton()->put_command(command); +} + Variant NetworkConnection::get_server_messages() { return NetworkConnectionCore::get_singleton()->get_server_messages(); diff --git a/modules/networkconnection/network_connection.h b/modules/networkconnection/network_connection.h index 57e2b9d..d803d97 100644 --- a/modules/networkconnection/network_connection.h +++ b/modules/networkconnection/network_connection.h @@ -45,6 +45,8 @@ public: void process(int delta); int get_state(); + void put_command(Variant command); + Variant get_server_messages(); Variant get_server_tick(); diff --git a/modules/networkconnection/network_connection_core.cpp b/modules/networkconnection/network_connection_core.cpp index b4bc5a1..87dad5b 100644 --- a/modules/networkconnection/network_connection_core.cpp +++ b/modules/networkconnection/network_connection_core.cpp @@ -23,6 +23,7 @@ #include "check_memory.h" #include "network_connection_core.h" +#include "modules/action/action_factory.h" #include "modules/debug/debug.h" NetworkConnectionCore *NetworkConnectionCore::singleton = nullptr; @@ -200,6 +201,11 @@ void NetworkConnectionCore::process(int delta) this->_state_connexion->send_message(); } +void NetworkConnectionCore::put_command(Variant command) +{ + _network_data._command_to_send.append(command); +} + Variant NetworkConnectionCore::get_server_messages() { return _network_data._server_messages; @@ -223,6 +229,7 @@ void NetworkConnectionCore::terminate_connexion() if ( NetworkConnectionCore::singleton == nullptr ) return; DBG_PRINT("Terminate network connexion .."); + ActionFactory::clear_all_block(& NetworkConnectionCore::get_singleton()->_network_data); delete NetworkConnectionCore::singleton; NetworkConnectionCore::singleton = nullptr; } diff --git a/modules/networkconnection/network_connection_core.h b/modules/networkconnection/network_connection_core.h index fe4803a..dc7d97d 100644 --- a/modules/networkconnection/network_connection_core.h +++ b/modules/networkconnection/network_connection_core.h @@ -91,6 +91,8 @@ public: void process(int delta); bool connected(); + void put_command(Variant command); + Variant get_server_messages(); Variant get_server_tick(); diff --git a/modules/networkconnection/network_data.cpp b/modules/networkconnection/network_data.cpp index 479f093..858c040 100644 --- a/modules/networkconnection/network_data.cpp +++ b/modules/networkconnection/network_data.cpp @@ -50,6 +50,8 @@ void NetworkData::initialize() this->_client_sync = 0; this->_current_send_number = 0; + + this->_impulse_multi_part_number = 0; } void NetworkData::reset_last_ack() diff --git a/modules/networkconnection/network_data.h b/modules/networkconnection/network_data.h index b6a648e..96cff29 100644 --- a/modules/networkconnection/network_data.h +++ b/modules/networkconnection/network_data.h @@ -26,7 +26,7 @@ #include "core/reference.h" #include "modules/bitset/bitset.h" #include "core/ustring.h" -//#include "core/dictionary.h" +#include "core/dictionary.h" #include "core/array.h" //define MAX_LOOP_READ_BY_STEP 10 @@ -73,9 +73,16 @@ public: uint32_t _last_ack_1[2]; uint32_t _last_ack_2[4]; - //Dictionary _server_messages; - Array _server_messages; + Array _server_messages; // Array contains all messages we received (from server) + // Manage GENERIC_MULTI_PART_CODE + Dictionary _block; + Dictionary _block_used; // true if we red this block + + // + Array _client_messages; // Array contains all messages we will send + Array _command_to_send; // Array all command to send (all data will be send to _client_messages) + uint8_t _impulse_multi_part_number; NetworkData(); ~NetworkData(); diff --git a/modules/networkconnection/state_connexion.cpp b/modules/networkconnection/state_connexion.cpp index 8e0b4a9..c96fb45 100644 --- a/modules/networkconnection/state_connexion.cpp +++ b/modules/networkconnection/state_connexion.cpp @@ -103,24 +103,27 @@ void StateConnectionNotInitialized::connect_to_server() */ void StateConnectionLogin::send_system_quit() { - DBG_PRINT("send quit to server"); + DBG_PRINT("send quit to server msg:" + itos(this->_data->_current_send_number)); BitStream msgout; - msgout.put_uint32(this->_data->_current_received_number); + msgout.put_uint32(this->_data->_current_send_number); msgout.put_bool(true); msgout.put_uint8(CLFECOMMON::SYSTEM_QUIT_CODE); msgout.put_sint32(this->_data->_quit_id); + DBG_PRINT("Send msg:" + itos(this->_data->_current_send_number) + " - " + msgout.show_detail()); if ( this->_network->_socketUDP->put_packet_buffer(msgout.get_data()) != Error::OK ) { ERR_PRINT("Error to send disconnect"); } this->_network->_state_connexion = & this->_network->_state_quit; + this->_data->_current_send_number ++; } void StateConnectionLogin::send_message() { BitStream msgout; - msgout.put_uint32(this->_data->_current_received_number); + DBG_PRINT("Send quit to server msg:" + itos(this->_data->_current_send_number)); + msgout.put_uint32(this->_data->_current_send_number); msgout.put_bool(true); msgout.put_uint8(CLFECOMMON::SYSTEM_LOGIN_CODE); msgout.put_string_hexa32(this->_data->_user_addr); @@ -128,6 +131,7 @@ void StateConnectionLogin::send_message() msgout.put_string_hexa32(this->_data->_user_id); msgout.put_string(this->_data->_lang); Error ret; + DBG_PRINT("Send msg:" + itos(this->_data->_current_send_number) + " - " + msgout.show_detail()); ret = this->_network->_socketUDP->put_packet_buffer(msgout.get_data()); // , msgout.get_data().size() if ( ret != Error::OK) { @@ -143,6 +147,7 @@ void StateConnectionLogin::send_message() } DBG_PRINT("Connected to khganat"); this->_network->_state_connexion = & this->_network->_state_synchronize; + this->_data->_current_send_number ++; } /* @@ -151,32 +156,35 @@ void StateConnectionLogin::send_message() void StateConnectionSynchronize::send_system_quit() { - DBG_PRINT("Send quit to server"); + DBG_PRINT("Send quit to server msg:" + itos(this->_data->_current_send_number)); BitStream msgout; - msgout.put_uint32(this->_data->_current_received_number); + msgout.put_uint32(this->_data->_current_send_number); msgout.put_bool(true); msgout.put_uint8(CLFECOMMON::SYSTEM_QUIT_CODE); msgout.put_sint32(this->_data->_quit_id); + DBG_PRINT("Send msg:" + itos(this->_data->_current_send_number) + " - " + msgout.show_detail()); if ( this->_network->_socketUDP->put_packet_buffer(msgout.get_data()) != Error::OK ) { ERR_PRINT("Error to send quit"); } this->_network->_state_connexion = & this->_network->_state_quit; + this->_data->_current_send_number ++; } void StateConnectionSynchronize::send_system_ack_sync() { - DBG_PRINT("Send system ACK Sync to server"); + DBG_PRINT("Send system ACK Sync to server msg:" + itos(this->_data->_current_send_number)); Ref msgout; msgout.instance(); - msgout->put_uint32(this->_data->_current_received_number); + msgout->put_uint32(this->_data->_current_send_number); msgout->put_bool(true); msgout->put_uint8(CLFECOMMON::SYSTEM_ACK_SYNC_CODE); msgout->put_sint32(this->_data->_last_received_number); msgout->put_sint32(this->_data->_last_ack_in_long_ack); this->_data->_long_ack_bit_field.write_serial(msgout); msgout->put_sint32(this->_data->_server_sync); + DBG_PRINT("Send msg:" + itos(this->_data->_current_send_number) + " - " + msgout->show_detail()); if (this->_network->_socketUDP->put_packet_buffer(msgout->get_data()) != Error::OK) { ERR_PRINT("Error to send ack sync"); @@ -185,6 +193,7 @@ void StateConnectionSynchronize::send_system_ack_sync() msgout.unref(); this->_data->_client_sync = this->_data->_server_sync; this->_network->_state_connexion = & this->_network->_state_connected; + this->_data->_current_send_number ++; } void StateConnectionSynchronize::receive_system_sync(Ref msgin) @@ -289,29 +298,32 @@ void StateConnectionSynchronize::send_message() void StateConnectionConnected::send_system_quit() { - DBG_PRINT("Send quit to server"); + DBG_PRINT("Send quit to server msg:" + itos(this->_data->_current_send_number)); BitStream msgout; - msgout.put_uint32(this->_data->_current_received_number); + msgout.put_uint32(this->_data->_current_send_number); msgout.put_bool(true); msgout.put_uint8(CLFECOMMON::SYSTEM_QUIT_CODE); msgout.put_sint32(this->_data->_quit_id); + DBG_PRINT("Send msg:" + itos(this->_data->_current_send_number) + " - " + msgout.show_detail()); if ( this->_network->_socketUDP->put_packet_buffer(msgout.get_data()) != Error::OK ) { ERR_PRINT("Error to send disconnect"); } this->_network->_state_connexion = & this->_network->_state_quit; + this->_data->_current_send_number ++; } void StateConnectionConnected::send_system_disconnect() { //if ( this->_state != STATE::Connected && this->_state != STATE::ForceSynchronize ) return; - DBG_PRINT("Send disconnect to server"); + DBG_PRINT("Send disconnect to server msg:" + itos(this->_data->_current_send_number)); BitStream msgout; - msgout.put_uint32(this->_data->_current_received_number); + msgout.put_uint32(this->_data->_current_send_number); msgout.put_bool(true); msgout.put_uint8(CLFECOMMON::SYSTEM_DISCONNECTION_CODE); + DBG_PRINT("Send msg:" + itos(this->_data->_current_send_number) + " - " + msgout.show_detail()); if ( this->_network->_socketUDP->put_packet_buffer(msgout.get_data()) != Error::OK ) { ERR_PRINT("Error to send disconnect"); @@ -319,15 +331,15 @@ void StateConnectionConnected::send_system_disconnect() this->_network->_socketUDP->close(); // this->_state = STATE::Disconnect; this->_network->_state_connexion = & this->_network->_state_not_initialized; + this->_data->_current_send_number ++; } void StateConnectionConnected::send_system_ack_sync() { - DBG_PRINT("Send system ACK Sync to server"); - + DBG_PRINT("Send system ACK Sync to server msg:" + itos(this->_data->_current_send_number)); Ref msgout; msgout.instance(); - msgout->put_uint32(this->_data->_current_received_number); + msgout->put_uint32(this->_data->_current_send_number); msgout->put_bool(true); msgout->put_uint8(CLFECOMMON::SYSTEM_ACK_SYNC_CODE); msgout->put_sint32(this->_data->_last_received_number); @@ -341,16 +353,17 @@ void StateConnectionConnected::send_system_ack_sync() } msgout.unref(); this->_data->_client_sync = this->_data->_server_sync; + this->_data->_current_send_number ++; } void StateConnectionConnected::send_system_ack_probe() { // khanat-opennel-code/code/ryzom/server/src/frontend_service/fe_receive_sub.cpp:1121 void CFeReceiveSub::handleReceivedMsg( CClientHost *clienthost ) - DBG_PRINT("Send system ACK PROBE to server"); + DBG_PRINT("Send system ACK PROBE to server msg:" + itos(this->_data->_current_send_number)); int max = this->_data->_latest_probes.size() ; BitStream msgout; - msgout.put_uint32(this->_data->_current_received_number); + msgout.put_uint32(this->_data->_current_send_number); msgout.put_bool(true); msgout.put_uint8(CLFECOMMON::SYSTEM_ACK_PROBE_CODE); msgout.put_sint32(max); @@ -359,31 +372,62 @@ void StateConnectionConnected::send_system_ack_probe() int data = this->_data->_latest_probes[i]; msgout.put_sint32(data); } + + DBG_PRINT("Send msg:" + itos(this->_data->_current_send_number) + " - " + msgout.show_detail()); if (this->_network->_socketUDP->put_packet_buffer(msgout.get_data()) != Error::OK) { ERR_PRINT("Error to send disconnect"); return; } this->_data->_latest_probes.clear(); + this->_data->_current_send_number ++; } -void StateConnectionConnected::send_system_ask_tick() +void StateConnectionConnected::send_normal_message() { // khanat-opennel-code/code/ryzom/client/src/network_connection.cpp # void CNetworkConnection::sendNormalMessage() - DBG_PRINT("Send system ACK TICK"); + DBG_PRINT("Send Normal Message msg:" + itos(this->_data->_current_send_number)); BitStream msgout; - msgout.put_uint32(this->_data->_current_received_number); + msgout.put_uint32(this->_data->_current_send_number); + DBG_PRINT("msgout A:" + msgout.show_detail()); msgout.put_bool(false); + DBG_PRINT("msgout B:" + msgout.show_detail()); msgout.put_uint32(this->_data->_last_received_number); + DBG_PRINT("msgout C:" + msgout.show_detail()); 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)); + DBG_PRINT("msgout D:" + msgout.show_detail()); + /* + msgout.pushUint32(self.Cycle) // cycle = self._CurrentServerTick + numberActions = len(self.Actions) + msgout.pushUint8(numberActions) + */ + while( this->_data->_client_messages.size() > 0 ) + { + DBG_PRINT("Send message"); + msgout.put_uint32(this->_data->_current_server_tick); + DBG_PRINT("msgout E:" + msgout.show_detail()); + msgout.put_uint8(1); + DBG_PRINT("msgout F:" + msgout.show_detail()); + Ref tmp = this->_data->_client_messages.pop_front(); // PoolByteArray tmp = this->_data->_client_messages.pop_front(); + //msgout.put_array_uint8(tmp); // TODO - Erreur de copie (changer le type) + msgout.put_bitstream(tmp.ptr()); /// ERREUR COPIE + DBG_PRINT("Send message " + msgout.show_detail()); + if ( msgout.number_bit_not_read() > 3840 ) // 3840 = 480*8 + break; + // break; // TODO - a supprimer pour l'instant on envoie qu'un paquet + } + DBG_PRINT("msgout G:" + msgout.show_detail()); + + DBG_PRINT("Send msg:" + itos(this->_data->_current_send_number) + " - " + msgout.show_detail()); + DBG_PRINT("current_received_number:" + itos(this->_data->_current_send_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; + this->_data->_current_send_number ++; } void StateConnectionConnected::receive_system_sync(Ref msgin) @@ -500,12 +544,15 @@ void StateConnectionConnected::receive_message(int index) void StateConnectionConnected::send_message() { + ActionFactory::pack(this->_data); if ( this->_data->_server_sync != this->_data->_client_sync ) this->send_system_ack_sync(); else if (this->_data->_latest_probes.size() != 0 ) this->send_system_ack_probe(); else if (this->_data->_recieved_new_server_tick == true) - this->send_system_ask_tick(); + this->send_normal_message(); + //else if (this->_data->_client_messages.size() > 0) + /// this->send_normal_message(); } /* * diff --git a/modules/networkconnection/state_connexion.h b/modules/networkconnection/state_connexion.h index b4aee5e..5887016 100644 --- a/modules/networkconnection/state_connexion.h +++ b/modules/networkconnection/state_connexion.h @@ -26,6 +26,7 @@ #include "modules/bitset/bitset.h" #include "modules/bitstreamqueue/bitstreamqueue.h" #include "network_data.h" +#include "modules/action/action.h" #define MAX_SIZE_BIT_STREAM_QUEUE 10 //define NUM_BITS_IN_LONG_ACK 512 @@ -58,21 +59,6 @@ enum CLFECOMMON { NUMBITSINLONGACK = 512 }; -enum ACTIONCODE { - ACTION_POSITION_CODE = 0, - ACTION_GENERIC_CODE = 1, - ACTION_GENERIC_MULTI_PART_CODE = 2, - ACTION_SINT64 = 3, - ACTION_SYNC_CODE = 10, - ACTION_DISCONNECTION_CODE = 11, - ACTION_ASSOCIATION_CODE = 12, - ACTION_LOGIN_CODE = 13, - ACTION_TARGET_SLOT_CODE = 40, - ACTION_DUMMY_CODE = 99, - ACTION_NONE = 999 -}; - - class NetworkConnectionCore; // Virtual class reference for network state @@ -142,7 +128,7 @@ public: void send_system_disconnect(); void send_system_ack_sync(); void send_system_ack_probe(); - void send_system_ask_tick(); + void send_normal_message(); void receive_system_sync(Ref msgin); void receive_message(int index); void send_message(); diff --git a/modules/referentialmessage/referentialmessage.cpp b/modules/referentialmessage/referentialmessage.cpp index d5e7bb9..f0962b3 100644 --- a/modules/referentialmessage/referentialmessage.cpp +++ b/modules/referentialmessage/referentialmessage.cpp @@ -21,6 +21,7 @@ #include "referentialmessage.h" #include "core/os/os.h" +#include "modules/impulse/impulsebase.h" void ReferentialMessage::_bind_methods() { @@ -46,6 +47,11 @@ int ReferentialMessage::read_command(Ref msgin) return ReferentialMessageCore::get_singleton()->read_command(msgin); } +void ReferentialMessage::write_command(ImpulseBase::Impulse command, Ref msgout) +{ + ReferentialMessageCore::get_singleton()->write_command(command, msgout); +} + void ReferentialMessage::clear_session() { ReferentialMessageCore::clear_session(); diff --git a/modules/referentialmessage/referentialmessage.h b/modules/referentialmessage/referentialmessage.h index a57e62d..a178b24 100644 --- a/modules/referentialmessage/referentialmessage.h +++ b/modules/referentialmessage/referentialmessage.h @@ -25,6 +25,7 @@ //#include "core/dictionary.h" //#include "modules/bitstream/bitstream.h" #include "modules/referentialmessage/referentialmessagecore.h" +#include "modules/impulse/impulsebase.h" class ReferentialMessage : public Reference { GDCLASS(ReferentialMessage, Reference) @@ -38,7 +39,9 @@ public: void _init() {}; void read_referential(Dictionary dictionary_message); void show(); + int read_command(Ref msgin); + void write_command(ImpulseBase::Impulse command, Ref msgout); void clear_session(); }; diff --git a/modules/referentialmessage/referentialmessagecore.cpp b/modules/referentialmessage/referentialmessagecore.cpp index a1c30a0..93e7616 100644 --- a/modules/referentialmessage/referentialmessagecore.cpp +++ b/modules/referentialmessage/referentialmessagecore.cpp @@ -169,4 +169,16 @@ void ReferentialMessageCore::clear_session() int ReferentialMessageCore::read_command(Ref msgin) { return _decoder->read_command(msgin); +} + +void ReferentialMessageCore::write_command(ImpulseBase::Impulse command, Ref msgout) +{ + #ifdef DEBUG_ENABLED + if ( command >= ImpulseBase::Impulse::__LAST_ELEMENT ) + { + ERR_PRINT("Out of range (" + itos(command) + " / " + itos(ImpulseBase::Impulse::__LAST_ELEMENT) + ")"); + throw "Out of range"; + } + #endif + msgout->put_bitstream(_encoder[command]); } \ No newline at end of file diff --git a/modules/referentialmessage/referentialmessagecore.h b/modules/referentialmessage/referentialmessagecore.h index 8ebf4be..b38b8bd 100644 --- a/modules/referentialmessage/referentialmessagecore.h +++ b/modules/referentialmessage/referentialmessagecore.h @@ -100,6 +100,7 @@ public: static void clear_session(); int read_command(Ref msgin); + void write_command(ImpulseBase::Impulse command, Ref msgout); }; #endif \ No newline at end of file diff --git a/project.godot b/project.godot index c71b79a..a43858b 100644 --- a/project.godot +++ b/project.godot @@ -8,9 +8,14 @@ config_version=4 -_global_script_classes=[ ] +_global_script_classes=[ { +"base": "Reference", +"class": "string_manager", +"language": "GDScript", +"path": "res://assets/Scripts/Config/string_manager.gd" +} ] _global_script_class_icons={ - +"string_manager": "" } [application] diff --git a/scenes/GUI/Settings/Settings.gd b/scenes/GUI/Settings/Settings.gd index 4aed0e5..2b0ec27 100644 --- a/scenes/GUI/Settings/Settings.gd +++ b/scenes/GUI/Settings/Settings.gd @@ -4,87 +4,87 @@ signal return_pressed signal font_changed( value ) func _ready(): - $Menus/TabContainer/Display/ScrollContainer/VBoxContainer/Fullscreen/CheckBox.pressed = ProjectSettings.get_setting( "display/window/size/fullscreen" ) - $Menus/TabContainer/Display/ScrollContainer/VBoxContainer/Borderless/CheckBox.pressed = ProjectSettings.get_setting( "display/window/size/borderless" ) - $Menus/TabContainer/Display/ScrollContainer/VBoxContainer/Resizable/CheckBox.pressed = ProjectSettings.get_setting( "display/window/size/resizable" ) - $Menus/TabContainer/Display/ScrollContainer/VBoxContainer/CurrentScreen/SpinBox.value = OS.current_screen + $Menus/TabContainer/Display/ScrollContainer/VBoxContainer/Fullscreen/CheckBox.pressed = ProjectSettings.get_setting( "display/window/size/fullscreen" ) + $Menus/TabContainer/Display/ScrollContainer/VBoxContainer/Borderless/CheckBox.pressed = ProjectSettings.get_setting( "display/window/size/borderless" ) + $Menus/TabContainer/Display/ScrollContainer/VBoxContainer/Resizable/CheckBox.pressed = ProjectSettings.get_setting( "display/window/size/resizable" ) + $Menus/TabContainer/Display/ScrollContainer/VBoxContainer/CurrentScreen/SpinBox.value = OS.current_screen - load_settings() + load_settings() func _on_font_size_bar_value_changed(value): - $Menus/TabContainer/Test/ScrollContainer/VBoxContainer/font_size/font_size_value.text = str( value ) - $Menus.get_theme().default_font.size = value - emit_signal( "font_changed", value ) + $Menus/TabContainer/Test/ScrollContainer/VBoxContainer/font_size/font_size_value.text = str( value ) + $Menus.get_theme().default_font.size = value + emit_signal( "font_changed", value ) func load_settings(): - var config_file = ConfigFile.new() - var err = config_file.load( "user://settings.cfg" ) - if err == ERR_CANT_OPEN or err == ERR_FILE_NOT_FOUND: - # On suppose que le fichier n'existe pas encore, donc on le crée. - config_file.set_value( "theme", "font_size", 14 ) - config_file.save( "user://settings.cfg" ) - elif not err == OK: - print("[res://scenes/GUI/Settings/Settings.gd:load_settings] Error code when loading config file: ", err) + var config_file = ConfigFile.new() + var err = config_file.load( "user://settings.cfg" ) + if err == ERR_CANT_OPEN or err == ERR_FILE_NOT_FOUND: + # On suppose que le fichier n'existe pas encore, donc on le crée. + config_file.set_value( "theme", "font_size", 14 ) + config_file.save( "user://settings.cfg" ) + elif not err == OK: + print("[res://scenes/GUI/Settings/Settings.gd:load_settings] Error code when loading config file: ", err) - global.font_size = config_file.get_value( "theme", "font_size" ) - if $Menus.get_theme(): - $Menus.get_theme().default_font.size = global.font_size - $Menus/TabContainer/Test/ScrollContainer/VBoxContainer/font_size_bar.value = global.font_size - $Menus/TabContainer/Test/ScrollContainer/VBoxContainer/font_size/font_size_value.text = str( global.font_size ) + global.font_size = config_file.get_value( "theme", "font_size" ) + if $Menus.get_theme(): + $Menus.get_theme().default_font.size = global.font_size + $Menus/TabContainer/Test/ScrollContainer/VBoxContainer/font_size_bar.value = global.font_size + $Menus/TabContainer/Test/ScrollContainer/VBoxContainer/font_size/font_size_value.text = str( global.font_size ) func _on_ReturnButton_pressed(): - var config_file = ConfigFile.new() - var err = config_file.load( "user://settings.cfg" ) - if err: - print("[res://scenes/GUI/Settings/Settings.gd:_on_ReturnButton_pressed] Error code when loading config file: ", err) + var config_file = ConfigFile.new() + var err = config_file.load( "user://settings.cfg" ) + if err: + print("[res://scenes/GUI/Settings/Settings.gd:_on_ReturnButton_pressed] Error code when loading config file: ", err) - config_file.set_value("theme", "font_size", $Menus.get_theme().default_font.size) + config_file.set_value("theme", "font_size", $Menus.get_theme().default_font.size) - config_file.save( "user://settings.cfg" ) + config_file.save( "user://settings.cfg" ) - emit_signal( "return_pressed" ) + emit_signal( "return_pressed" ) func _on_Title_text_changed(new_text): - # ---------------------------------- - # Changing windows title - var new_title = "Khanat" - new_text = new_text.strip_edges() - if not new_text == "": - new_title = new_text - new_title += " (" + String(OS.get_window_size().x) + "x" + String(OS.get_window_size().y) + ")" - OS.set_window_title( new_title ) - # ---------------------------------- + # ---------------------------------- + # Changing windows title + var new_title = "Khanat" + new_text = new_text.strip_edges() + if not new_text == "": + new_title = new_text + new_title += " (" + String(OS.get_window_size().x) + "x" + String(OS.get_window_size().y) + ")" + OS.set_window_title( new_title ) + # ---------------------------------- func _on_Fullscreen_toggled(button_pressed): - if ProjectSettings.has_setting( "display/window/size/fullscreen" ): - ProjectSettings.set_setting("display/window/size/fullscreen", button_pressed) - OS.window_fullscreen = ProjectSettings.get_setting("display/window/size/fullscreen") + if ProjectSettings.has_setting( "display/window/size/fullscreen" ): + ProjectSettings.set_setting("display/window/size/fullscreen", button_pressed) + OS.window_fullscreen = ProjectSettings.get_setting("display/window/size/fullscreen") func _on_Borderless_toggled(button_pressed): - if ProjectSettings.has_setting( "display/window/size/borderless" ): - ProjectSettings.set_setting("display/window/size/borderless", button_pressed) - OS.window_borderless = ProjectSettings.get_setting("display/window/size/borderless") + if ProjectSettings.has_setting( "display/window/size/borderless" ): + ProjectSettings.set_setting("display/window/size/borderless", button_pressed) + OS.window_borderless = ProjectSettings.get_setting("display/window/size/borderless") func _on_Resizable_toggled(button_pressed): - if ProjectSettings.has_setting( "display/window/size/resizable" ): - ProjectSettings.set_setting("display/window/size/resizable", button_pressed) - OS.window_resizable = ProjectSettings.get_setting("display/window/size/resizable") + if ProjectSettings.has_setting( "display/window/size/resizable" ): + ProjectSettings.set_setting("display/window/size/resizable", button_pressed) + OS.window_resizable = ProjectSettings.get_setting("display/window/size/resizable") # La fonction existe dans la doc mais le moteur lui ne la reconnait pas, # soit il y a une subtilité quelquepart soit la doc n'est pas à jour. func _on_AlwaysOnTop_toggled(button_pressed): # OS.set_window_always_on_top( button_pressed ) - pass + pass func _on_SpinBox_value_changed(value): - OS.current_screen = value + OS.current_screen = value func _on_FluteButton_pressed(): - pass # Replace with function body. + pass # Replace with function body. diff --git a/scenes/GUI/Settings/Settings.tscn b/scenes/GUI/Settings/Settings.tscn index c9c0a0a..92f5120 100644 --- a/scenes/GUI/Settings/Settings.tscn +++ b/scenes/GUI/Settings/Settings.tscn @@ -89,7 +89,6 @@ custom_styles/tab_bg = SubResource( 5 ) custom_styles/panel = SubResource( 6 ) [node name="Display" type="MarginContainer" parent="Menus/TabContainer"] -editor/display_folded = true anchor_right = 1.0 anchor_bottom = 1.0 margin_top = 49.0 @@ -112,7 +111,6 @@ size_flags_vertical = 2 custom_constants/separation = 8 [node name="Fullscreen" type="HBoxContainer" parent="Menus/TabContainer/Display/ScrollContainer/VBoxContainer"] -editor/display_folded = true margin_right = 1196.0 margin_bottom = 41.0 @@ -150,7 +148,6 @@ margin_bottom = 41.0 size_flags_horizontal = 2 [node name="Resizable" type="HBoxContainer" parent="Menus/TabContainer/Display/ScrollContainer/VBoxContainer"] -editor/display_folded = true margin_top = 98.0 margin_right = 1196.0 margin_bottom = 139.0 @@ -278,7 +275,6 @@ margin_bottom = -1.0 hint_tooltip = "Interface." [node name="Header" type="HBoxContainer" parent="Menus/TabContainer/Controles/ScrollContainer/TabContainer/Interface"] -editor/display_folded = true margin_right = 1022.0 margin_bottom = 38.0 @@ -385,7 +381,6 @@ margin_right = -1.0 margin_bottom = -1.0 [node name="Header" type="HBoxContainer" parent="Menus/TabContainer/Controles/ScrollContainer/TabContainer/Deplacement"] -editor/display_folded = true margin_right = 1022.0 margin_bottom = 37.0