Split client and server

This commit is contained in:
2024-01-24 00:09:50 +01:00
parent 532a1faa21
commit 26c52a00b3
59 changed files with 335 additions and 142 deletions

29
client/network/Login.gd Normal file
View File

@ -0,0 +1,29 @@
extends PacketHandler
var auth_token: String
func _ready():
%Client.set_handler(Packet.LOGIN, self)
send_login()
func handle_packet(data: PackedByteArray, _peer: PacketPeer):
if data[0] != 0:
print("[Client] Login failed.")
return
print("[Client] Login succeeded.")
auth_token = data.slice(1).get_string_from_ascii()
print("[Client] Auth token: %s" % auth_token)
func send_login():
if is_logged_in():
return
var buffer := StreamPeerBuffer.new()
buffer.put_8(Packet.LOGIN)
buffer.put_data(JSON.stringify(["user1", "password"]).to_utf8_buffer())
%Client.socket.put_packet(buffer.data_array)
print("[Client] Connecting...")
func is_logged_in() -> bool:
return auth_token != ""