Improved network communication
This commit is contained in:
9
client/network/shared/Account.gd
Normal file
9
client/network/shared/Account.gd
Normal file
@ -0,0 +1,9 @@
|
||||
class_name Account
|
||||
|
||||
var username: String
|
||||
var password: String
|
||||
var position: Vector3
|
||||
|
||||
func _init(name: String, pw: String):
|
||||
username = name
|
||||
password = pw
|
23
client/network/shared/NetworkNode.gd
Normal file
23
client/network/shared/NetworkNode.gd
Normal file
@ -0,0 +1,23 @@
|
||||
class_name NetworkNode
|
||||
extends Node
|
||||
|
||||
var handlers: Array[Node] = []
|
||||
|
||||
func _init():
|
||||
handlers.resize(256)
|
||||
|
||||
func get_handler(index: int) -> PacketHandler:
|
||||
return handlers[index]
|
||||
|
||||
func set_handler(index: int, node: PacketHandler):
|
||||
handlers[index] = node
|
||||
|
||||
func handle_packet(packet: PackedByteArray, peer: PacketPeer):
|
||||
var type := packet.decode_u8(0)
|
||||
var handler := get_handler(type)
|
||||
|
||||
if handler == null:
|
||||
push_warning("Unknown packet type %d" % type)
|
||||
return
|
||||
|
||||
handler.handle_packet(packet.slice(1), peer)
|
9
client/network/shared/Packet.gd
Normal file
9
client/network/shared/Packet.gd
Normal file
@ -0,0 +1,9 @@
|
||||
class_name Packet
|
||||
|
||||
enum {
|
||||
PING = 1,
|
||||
LOGIN = 2,
|
||||
LOGOUT = 3,
|
||||
PLAYER_STATE = 10,
|
||||
PLAYER_MOVE = 11,
|
||||
}
|
5
client/network/shared/PacketHandler.gd
Normal file
5
client/network/shared/PacketHandler.gd
Normal file
@ -0,0 +1,5 @@
|
||||
class_name PacketHandler
|
||||
extends Node
|
||||
|
||||
func handle_packet(_data: PackedByteArray, _peer: PacketPeer):
|
||||
pass
|
Reference in New Issue
Block a user