TODO: ack in packet header

This commit is contained in:
ChillerDragon 2022-10-29 17:04:35 +02:00
parent 4544bb3e1a
commit 8352033d0b
2 changed files with 24 additions and 4 deletions

View file

@ -73,10 +73,11 @@ NETMSGTYPE_SV_COMMANDINFOREMOVE = 38
NETMSGTYPE_CL_COMMAND = 39
NUM_NETMSGTYPES = 40
NET_CTRLMSG_CONNECT = 0x01
NET_CTRLMSG_ACCEPT = 0x02
NET_CTRLMSG_CLOSE = 0x04
NET_CTRLMSG_TOKEN = 0x05
NET_CTRLMSG_KEEPALIVE = 0
NET_CTRLMSG_CONNECT = 1
NET_CTRLMSG_ACCEPT = 2
NET_CTRLMSG_CLOSE = 4
NET_CTRLMSG_TOKEN = 5
NET_CONNSTATE_OFFLINE = 0
NET_CONNSTATE_TOKEN = 1

View file

@ -35,6 +35,7 @@ class TwClient
@ip = 'localhost'
@port = 8303
@packet_flags = {}
@ticks = 0
end
def send_msg(data)
@ -44,6 +45,19 @@ class TwClient
@s.send(msg.pack('C*'), 0, @ip, @port)
end
# does not help because server
# drops the invalid acks
# so we have to finally
# create a proper
# sendpacket() method
# that sends a proper header
def send_ctrl_keepalive()
# size and flags
header = [0x04, 0x0A, 0x00] + str_bytes(@token)
msg = header + [NET_CTRLMSG_KEEPALIVE]
@s.send(msg.pack('C*'), 0, @ip, @port)
end
def send_msg_connect()
header = [0x04, 0x00, 0x00] + str_bytes(@token)
msg = header + [NET_CTRLMSG_CONNECT] + str_bytes(@client_token) + Array.new(501, 0x00)
@ -262,6 +276,11 @@ class TwClient
else # process non-connless packets
process_server_packet(packet.payload)
end
@ticks += 1
if @ticks % 10 == 0
send_ctrl_keepalive
end
end
def disconnect