Improved main scene code
This commit is contained in:
@ -1,29 +1,26 @@
|
||||
extends PacketHandler
|
||||
|
||||
var auth_token: String
|
||||
|
||||
func _ready():
|
||||
DisplayServer.window_set_title(Global.username)
|
||||
send_login()
|
||||
signal success
|
||||
signal failure
|
||||
|
||||
func handle_packet(data: PackedByteArray, _peer: PacketPeer):
|
||||
var buffer := StreamPeerBuffer.new()
|
||||
buffer.data_array = data
|
||||
|
||||
|
||||
var error := buffer.get_8()
|
||||
if error != 0:
|
||||
print("[%s] Login failed." % Global.username)
|
||||
failure.emit()
|
||||
return
|
||||
|
||||
Global.account_id = buffer.get_string()
|
||||
auth_token = buffer.get_string()
|
||||
Global.auth_token = buffer.get_string()
|
||||
|
||||
print("[%s] Login succeeded." % Global.username)
|
||||
print("[%s] ID: %s" % [Global.username, Global.account_id])
|
||||
print("[%s] Auth token: %s" % [Global.username, auth_token])
|
||||
print("[%s] Auth token: %s" % [Global.username, Global.auth_token])
|
||||
|
||||
DisplayServer.window_set_title("%s - %s" % [Global.username, Global.account_id])
|
||||
DisplayServer.window_set_position(Vector2((Global.instance_id % 2) * 960, (Global.instance_id / 2 % 2) * 540))
|
||||
success.emit()
|
||||
|
||||
func send_login():
|
||||
if is_logged_in():
|
||||
@ -37,4 +34,4 @@ func send_login():
|
||||
print("[%s] Connecting..." % Global.username)
|
||||
|
||||
func is_logged_in() -> bool:
|
||||
return auth_token != ""
|
||||
return Global.auth_token != ""
|
@ -21,10 +21,7 @@ func send_ping():
|
||||
buffer.put_8(count)
|
||||
%Client.send(buffer.data_array)
|
||||
history[count] = get_time()
|
||||
count += 1
|
||||
|
||||
if count >= HISTORY_SIZE:
|
||||
count = 0
|
||||
count = (count + 1) % HISTORY_SIZE
|
||||
|
||||
func get_time() -> float:
|
||||
return Time.get_unix_time_from_system()
|
||||
|
Reference in New Issue
Block a user