Improved connection handling
This commit is contained in:
@ -5,6 +5,11 @@ enum {
|
||||
FAIL = 1,
|
||||
}
|
||||
|
||||
var accounts := {
|
||||
"user1": Account.new("password"),
|
||||
"user2": Account.new("password"),
|
||||
}
|
||||
|
||||
func _ready():
|
||||
%Server.set_handler(Packet.LOGIN, self)
|
||||
|
||||
@ -19,7 +24,11 @@ func handle_packet(data: PackedByteArray, peer: PacketPeer):
|
||||
var username = login_request[0]
|
||||
var password = login_request[1]
|
||||
|
||||
if username != "username" || password != "password":
|
||||
if !accounts.has(username):
|
||||
fail_login(peer)
|
||||
return
|
||||
|
||||
if accounts[username].password != password:
|
||||
fail_login(peer)
|
||||
return
|
||||
|
||||
@ -32,4 +41,4 @@ func fail_login(peer: PacketPeer):
|
||||
var buffer := StreamPeerBuffer.new()
|
||||
buffer.put_8(Packet.LOGIN)
|
||||
buffer.put_8(FAIL)
|
||||
peer.put_packet(buffer.data_array)
|
||||
peer.put_packet(buffer.data_array)
|
||||
|
Reference in New Issue
Block a user