Added auth tokens
This commit is contained in:
@ -27,20 +27,11 @@ func _process(_delta):
|
||||
# Accept new connections
|
||||
while server.is_connection_available():
|
||||
var peer: PacketPeerUDP = server.take_connection()
|
||||
var address := "%s:%d" % [peer.get_packet_ip(), peer.get_packet_port()]
|
||||
|
||||
if !clients.has(address):
|
||||
var connection = Connection.new()
|
||||
connection.peer = peer
|
||||
connection.address = address
|
||||
clients[address] = connection
|
||||
peer_connected(connection)
|
||||
|
||||
clients[address].last_packet = now
|
||||
peer_to_client(peer).last_packet = now
|
||||
|
||||
# Process packets from clients
|
||||
for key in clients:
|
||||
var client = clients[key]
|
||||
for address in clients:
|
||||
var client = clients[address]
|
||||
var peer = client.peer
|
||||
|
||||
while peer.get_available_packet_count() > 0:
|
||||
@ -62,8 +53,24 @@ func _process(_delta):
|
||||
packet_count = 0
|
||||
last_statistics = Time.get_ticks_msec()
|
||||
|
||||
func peer_connected(c: Connection):
|
||||
func peer_address(peer: PacketPeerUDP):
|
||||
return "%s:%d" % [peer.get_packet_ip(), peer.get_packet_port()]
|
||||
|
||||
func peer_to_client(peer: PacketPeerUDP) -> Client:
|
||||
var address = peer_address(peer)
|
||||
|
||||
if !clients.has(address):
|
||||
var client = Client.new()
|
||||
client.peer = peer
|
||||
client.address = address
|
||||
clients[address] = client
|
||||
peer_connected(client)
|
||||
return client
|
||||
|
||||
return clients[address]
|
||||
|
||||
func peer_connected(c: Client):
|
||||
print("[Server] Connected: ", c.address)
|
||||
|
||||
func peer_disconnected(c: Connection):
|
||||
func peer_disconnected(c: Client):
|
||||
print("[Server] Disconnected: ", c.address)
|
||||
|
Reference in New Issue
Block a user