update network utp communication

This commit is contained in:
AleaJactaEst 2019-12-11 22:27:49 +01:00
parent fa0e971291
commit 6619fd3f0f
5 changed files with 112 additions and 49 deletions

4
.gitignore vendored
View file

@ -11,3 +11,7 @@ export_presets.cfg
# System/tool-specific ignores # System/tool-specific ignores
.directory .directory
*~ *~
# Ignore binary & package
*.bin
*.pck

View file

@ -49,7 +49,7 @@ Ex.: export_presets.cfg
``` ```
[preset.0] [preset.0]
name="khaganat.linux" name="khaganat.linux.64"
platform="Linux/X11" platform="Linux/X11"
runnable=true runnable=true
custom_features="" custom_features=""
@ -76,7 +76,7 @@ custom_template/debug=""
### Generate package ### Generate package
``` ```
godot --path . --export khaganat.linux khaganat.linux.bin godot --path . --export khaganat.linux.64 khaganat.linux64.bin
``` ```
## Launch client khaganat ## Launch client khaganat

View file

@ -45,6 +45,8 @@ enum CLFECOMMON {
SYSTEM_ACK_QUIT_CODE = 9, SYSTEM_ACK_QUIT_CODE = 9,
NUMBITSINLONGACK = 512} NUMBITSINLONGACK = 512}
const NUM_BITS_IN_LONG_ACK = 512
var _connection_state var _connection_state
var _socketUDP var _socketUDP
@ -63,6 +65,12 @@ var _long_ack_bit_field
var _last_ack_in_long_ack var _last_ack_in_long_ack
var _latest_sync var _latest_sync
var _latest_probe_time
var _latest_probe
var _latest_probes
var _quit_id
var _update_time
var _queue_message_system var _queue_message_system
func _ready(): func _ready():
@ -75,8 +83,14 @@ func _ready():
_socketUDP = PacketPeerUDP.new() _socketUDP = PacketPeerUDP.new()
_queue_message_system = Array() _queue_message_system = Array()
_long_ack_bit_field = preload("res://bitset.gdns").new() _long_ack_bit_field = preload("res://bitset.gdns").new()
_long_ack_bit_field.resize(512)
_last_ack_in_long_ack = 0 _last_ack_in_long_ack = 0
_latest_sync = 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): func send_system_login(user_addr, user_key, user_id, lang):
var msgout = preload("res://bitstream.gdns").new() 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_hexa32(user_id)
msgout.put_string(lang) msgout.put_string(lang)
print("[net_low_level:send_system_login] Send System Login :" + msgout.show()) 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()) var res = _socketUDP.put_packet(msgout.get_data())
if ( res != OK): if ( res != OK):
print("[net_low_level:send_system_login] Error to send system login : " + str(res)) 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(): func send_system_sync():
var msgout = preload("res://bitstream.gdns").new() 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_uint8(CLFECOMMON.SYSTEM_ACK_SYNC_CODE)
msgout.put_sint32(_last_received_number) msgout.put_sint32(_last_received_number)
msgout.put_sint32(_last_ack_in_long_ack) msgout.put_sint32(_last_ack_in_long_ack)
@ -104,6 +120,35 @@ func send_system_sync():
msgout.put_sint32(_latest_sync) msgout.put_sint32(_latest_sync)
_queue_message_system.append(msgout) _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(): func send_systemm_disconnect():
var msgout = preload("res://bitstream.gdns").new() var msgout = preload("res://bitstream.gdns").new()
msgout.put_sint32(_current_received_number) 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) _socketUDP.set_dest_address(khaganat_host, khaganat_port)
send_system_login(user_addr, user_key, user_id, lang) 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): 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() var msgin = preload("res://bitstream.gdns").new()
msgin.put_data(msgbytes) msgin.put_data(msgbytes)
#if msgin.size() == 0:
# return
_current_received_number = msgin.get_sint32() _current_received_number = msgin.get_sint32()
var system_mode = msgin.get_bool() 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())) 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 _ack_bit_mask = 0x00000000
_last_ack_bit = ackBit _last_ack_bit = ackBit
for i in range(_last_received_number + 1, _current_received_number): 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.clear_bit(i & (NUM_BITS_IN_LONG_ACK -1))
_long_ack_bit_field.put(_current_received_number & 511, ackBool) # (512 - 1) mask 9bit _long_ack_bit_field.put(_current_received_number & (NUM_BITS_IN_LONG_ACK-1), ackBool)
if _last_ack_in_long_ack <= (_last_received_number - 512): if _last_ack_in_long_ack <= (_last_received_number - NUM_BITS_IN_LONG_ACK):
_last_ack_in_long_ack = _last_received_number - 511 # (512 - 1) mask 9bit _last_ack_in_long_ack = _last_received_number - NUM_BITS_IN_LONG_ACK + 1
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) + ")")
_last_received_number = _current_received_number _last_received_number = _current_received_number
if system_mode:
decode_system_message(msgin)
else:
decode_normal_message(msgin)
func _process(delta): func _process(delta):
var max_read = 10
if _connection_state == TCONNECTIONSTATE.NOTINITIALISED: if _connection_state == TCONNECTIONSTATE.NOTINITIALISED:
return return
if _connection_state == TCONNECTIONSTATE.NOTCONNECTED: if _connection_state == TCONNECTIONSTATE.NOTCONNECTED:
@ -218,14 +273,16 @@ func _process(delta):
return return
if _queue_message_system.size() > 0: if _queue_message_system.size() > 0:
var msgout = _queue_message_system.pop_front() 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()) _socketUDP.put_packet(msgout.get_data())
if _socketUDP.get_available_packet_count() == 0: if _latest_probes.size() > 0:
return send_system_ack_probe()
var msgbytes = _socketUDP.get_packet()
if msgbytes.size() > 0: while _socketUDP.get_available_packet_count() > 0 and max_read > 0:
analyze_message_received(msgbytes) var msgbytes = _socketUDP.get_packet()
if msgbytes.size() > 0:
analyze_message_received(msgbytes)
func _exit_tree(): func _exit_tree():
disconnect_server() disconnect_server()

2
gdnative/.gitignore vendored Normal file
View file

@ -0,0 +1,2 @@
bin/
.sconsign.dblite

View file

@ -94,7 +94,7 @@ bool BitStream::is_little_endian()
int BitStream::size() int BitStream::size()
{ {
return (this->_pos * 7) / 8; return (this->_pos + 7) / 8;
} }
int BitStream::size_data() int BitStream::size_data()