diff --git a/.gitignore b/.gitignore index 5d138d4..59e1c5b 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,7 @@ export_presets.cfg # System/tool-specific ignores .directory *~ + +# Ignore binary & package +*.bin +*.pck diff --git a/README.md b/README.md index 704882f..d03a004 100644 --- a/README.md +++ b/README.md @@ -49,7 +49,7 @@ Ex.: export_presets.cfg ``` [preset.0] -name="khaganat.linux" +name="khaganat.linux.64" platform="Linux/X11" runnable=true custom_features="" @@ -76,7 +76,7 @@ custom_template/debug="" ### Generate package ``` -godot --path . --export khaganat.linux khaganat.linux.bin +godot --path . --export khaganat.linux.64 khaganat.linux64.bin ``` ## Launch client khaganat diff --git a/assets/Scripts/Network/net_low_level.gd b/assets/Scripts/Network/net_low_level.gd index 05e8e4f..96e0d2e 100644 --- a/assets/Scripts/Network/net_low_level.gd +++ b/assets/Scripts/Network/net_low_level.gd @@ -45,6 +45,8 @@ enum CLFECOMMON { SYSTEM_ACK_QUIT_CODE = 9, NUMBITSINLONGACK = 512} +const NUM_BITS_IN_LONG_ACK = 512 + var _connection_state var _socketUDP @@ -63,6 +65,12 @@ var _long_ack_bit_field var _last_ack_in_long_ack var _latest_sync +var _latest_probe_time +var _latest_probe +var _latest_probes + +var _quit_id +var _update_time var _queue_message_system func _ready(): @@ -75,8 +83,14 @@ func _ready(): _socketUDP = PacketPeerUDP.new() _queue_message_system = Array() _long_ack_bit_field = preload("res://bitset.gdns").new() + _long_ack_bit_field.resize(512) _last_ack_in_long_ack = 0 _latest_sync = 0 + _latest_probe_time = 0 + _latest_probe = 0 + _latest_probes = Array() + _update_time = 0 + _quit_id = 0 func send_system_login(user_addr, user_key, user_id, lang): var msgout = preload("res://bitstream.gdns").new() @@ -88,6 +102,7 @@ func send_system_login(user_addr, user_key, user_id, lang): msgout.put_string_hexa32(user_id) msgout.put_string(lang) print("[net_low_level:send_system_login] Send System Login :" + msgout.show()) + # To connect you need send 1st message var res = _socketUDP.put_packet(msgout.get_data()) if ( res != OK): print("[net_low_level:send_system_login] Error to send system login : " + str(res)) @@ -96,7 +111,8 @@ func send_system_login(user_addr, user_key, user_id, lang): func send_system_sync(): var msgout = preload("res://bitstream.gdns").new() - var curtime = OS.get_ticks_msec() + msgout.put_sint32(_current_received_number) + msgout.put_bool(true) msgout.put_uint8(CLFECOMMON.SYSTEM_ACK_SYNC_CODE) msgout.put_sint32(_last_received_number) msgout.put_sint32(_last_ack_in_long_ack) @@ -104,6 +120,35 @@ func send_system_sync(): msgout.put_sint32(_latest_sync) _queue_message_system.append(msgout) +func send_system_ack_probe(): + var msgout = preload("res://bitstream.gdns").new() + msgout.put_sint32(_current_received_number) + msgout.put_bool(true) + msgout.put_uint8(CLFECOMMON.SYSTEM_ACK_PROBE_CODE) + msgout.put_sint32(_latest_probes.size()) + for data in _latest_probes: + msgout.put_sint32(data) + _latest_probes.clear() + #_queue_message_system.append(msgout) + var res = _socketUDP.put_packet(msgout.get_data()) + if ( res != OK): + print("[net_low_level:send_system_quit] Error to send system quit : " + str(res)) + return + +func send_system_quit(): + var msgout = preload("res://bitstream.gdns").new() + _quit_id += 1 + msgout.put_sint32(_current_received_number) + msgout.put_bool(true) + msgout.put_uint8(CLFECOMMON.SYSTEM_QUIT_CODE) + msgout.put_sint32(_quit_id) + #_queue_message_system.append(msgout) + _connection_state == TCONNECTIONSTATE.QUIT + var res = _socketUDP.put_packet(msgout.get_data()) + if ( res != OK): + print("[net_low_level:send_system_quit] Error to send system quit : " + str(res)) + return + func send_systemm_disconnect(): var msgout = preload("res://bitstream.gdns").new() msgout.put_sint32(_current_received_number) @@ -131,11 +176,48 @@ func connect_to_server(user_addr, user_key, user_id): _socketUDP.set_dest_address(khaganat_host, khaganat_port) send_system_login(user_addr, user_key, user_id, lang) +func decode_system_message(msgin): + var message = msgin.get_uint8() + print("[net_low_level:analyze_message_received] Message type:" + str(message) ) + match message: + CLFECOMMON.SYSTEM_LOGIN_CODE: + pass + CLFECOMMON.SYSTEM_SYNC_CODE: + var synchronize = msgin.get_uint32() + var stime = msgin.get_sint64() + _latest_sync = msgin.get_uint32() + var msg_xml = msgin.get_array_uint8(16) + var database_xml = msgin.get_array_uint8(16) + print("[net_low_level:analyze_message_received] synchronize:" + str(synchronize) + " stime:" + str(stime) + " latest_sync:" + str(_latest_sync)) + var num = "" + for item in msg_xml: + num += str(item) + "." + print(num) + num = "" + for item in database_xml: + num += str(item) + "." + print(num) + send_system_sync() + CLFECOMMON.SYSTEM_STALLED_CODE: + pass + CLFECOMMON.SYSTEM_PROBE_CODE: + _latest_probe_time = _update_time + _latest_probe = msgin.get_sint32() + _latest_probes.append(_latest_probe) + send_system_ack_probe() + CLFECOMMON.SYSTEM_SERVER_DOWN_CODE: + pass + _: + print("[net_low_level:analyze_message_received] Message type unknown (" + str(message) + ")") + +func decode_normal_message(msgin): + pass + func analyze_message_received(msgbytes): + # khanat-opennel-code/code/ryzom/server/src/frontend_service/fe_receive_sub.cpp:769 void CFeReceiveSub::handleReceivedMsg( CClientHost *clienthost ) + _update_time = OS.get_ticks_msec() var msgin = preload("res://bitstream.gdns").new() msgin.put_data(msgbytes) - #if msgin.size() == 0: - # return _current_received_number = msgin.get_sint32() var system_mode = msgin.get_bool() print("[net_low_level:analyze_message_received] Tick:" + str(_current_received_number) + ", Mode:" + str(system_mode) + ", Size:" + str(msgin.size())) @@ -170,46 +252,19 @@ func analyze_message_received(msgbytes): _ack_bit_mask = 0x00000000 _last_ack_bit = ackBit for i in range(_last_received_number + 1, _current_received_number): - _long_ack_bit_field.clear_bit(i & 511) # (512 - 1) mask 9bit - _long_ack_bit_field.put(_current_received_number & 511, ackBool) # (512 - 1) mask 9bit - if _last_ack_in_long_ack <= (_last_received_number - 512): - _last_ack_in_long_ack = _last_received_number - 511 # (512 - 1) mask 9bit - - print("[net_low_level:analyze_message_received] _last_ack_in_long_ack:" + str(_last_ack_in_long_ack) + ", _long_ack_bit_field:" + _long_ack_bit_field.show()) - - var message = msgin.get_uint8() - print("[net_low_level:analyze_message_received] Message type:" + str(message) ) - match message: - CLFECOMMON.SYSTEM_LOGIN_CODE: - pass - CLFECOMMON.SYSTEM_SYNC_CODE: - var synchronize = msgin.get_uint32() - var stime = msgin.get_sint64() - _latest_sync = msgin.get_uint32() - var msg_xml = msgin.get_array_uint8(16) - var database_xml = msgin.get_array_uint8(16) - print("[net_low_level:analyze_message_received] synchronize:" + str(synchronize) + " stime:" + str(stime) + " latest_sync:" + str(_latest_sync)) - var num = "" - for item in msg_xml: - num += str(item) + "." - print(num) - num = "" - for item in database_xml: - num += str(item) + "." - print(num) - send_system_sync() - CLFECOMMON.SYSTEM_STALLED_CODE: - pass - CLFECOMMON.SYSTEM_PROBE_CODE: - pass - CLFECOMMON.SYSTEM_SERVER_DOWN_CODE: - pass - _: - print("[net_low_level:analyze_message_received] Message type unknown (" + str(message) + ")") - + _long_ack_bit_field.clear_bit(i & (NUM_BITS_IN_LONG_ACK -1)) + _long_ack_bit_field.put(_current_received_number & (NUM_BITS_IN_LONG_ACK-1), ackBool) + if _last_ack_in_long_ack <= (_last_received_number - NUM_BITS_IN_LONG_ACK): + _last_ack_in_long_ack = _last_received_number - NUM_BITS_IN_LONG_ACK + 1 _last_received_number = _current_received_number + if system_mode: + decode_system_message(msgin) + else: + decode_normal_message(msgin) + func _process(delta): + var max_read = 10 if _connection_state == TCONNECTIONSTATE.NOTINITIALISED: return if _connection_state == TCONNECTIONSTATE.NOTCONNECTED: @@ -218,14 +273,16 @@ func _process(delta): return if _queue_message_system.size() > 0: var msgout = _queue_message_system.pop_front() - print("[net_low_level:_process] Send data system") + print("[net_low_level:_process] Send data system (" + str(msgout.size()) + ", " + msgout.show() + ")" ) _socketUDP.put_packet(msgout.get_data()) - if _socketUDP.get_available_packet_count() == 0: - return - var msgbytes = _socketUDP.get_packet() - if msgbytes.size() > 0: - analyze_message_received(msgbytes) + if _latest_probes.size() > 0: + send_system_ack_probe() + + while _socketUDP.get_available_packet_count() > 0 and max_read > 0: + var msgbytes = _socketUDP.get_packet() + if msgbytes.size() > 0: + analyze_message_received(msgbytes) func _exit_tree(): disconnect_server() \ No newline at end of file diff --git a/gdnative/.gitignore b/gdnative/.gitignore new file mode 100644 index 0000000..1861cdc --- /dev/null +++ b/gdnative/.gitignore @@ -0,0 +1,2 @@ +bin/ +.sconsign.dblite diff --git a/gdnative/src/bitstream.cpp b/gdnative/src/bitstream.cpp index 7a25181..9aca249 100644 --- a/gdnative/src/bitstream.cpp +++ b/gdnative/src/bitstream.cpp @@ -94,7 +94,7 @@ bool BitStream::is_little_endian() int BitStream::size() { - return (this->_pos * 7) / 8; + return (this->_pos + 7) / 8; } int BitStream::size_data()