Split client and server
This commit is contained in:
29
client/network/Login.gd
Normal file
29
client/network/Login.gd
Normal 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 != ""
|
Reference in New Issue
Block a user