godot-start/gdProtocol/ProtocolManager.gd

34 lines
1.0 KiB
GDScript
Raw Normal View History

2021-10-18 07:20:14 +00:00
const ComplexObject = preload("res://gdProtocol/packet/ComplexObject.gd")
const NormalObject = preload("res://gdProtocol/packet/NormalObject.gd")
const ObjectA = preload("res://gdProtocol/packet/ObjectA.gd")
const ObjectB = preload("res://gdProtocol/packet/ObjectB.gd")
const SimpleObject = preload("res://gdProtocol/packet/SimpleObject.gd")
const protocols = {}
static func getProtocol(protocolId: int):
return protocols[protocolId]
static func newInstance(protocolId: int):
2022-05-18 13:08:42 +00:00
var protocol = protocols[protocolId]
return protocol.new()
2021-10-18 07:20:14 +00:00
static func write(buffer, packet):
var protocolId: int = packet.PROTOCOL_ID
buffer.writeShort(protocolId)
var protocol = protocols[protocolId]
protocol.write(buffer, packet)
static func read(buffer):
2022-05-18 13:08:42 +00:00
var protocolId = buffer.readShort();
var protocol = protocols[protocolId]
var packet = protocol.read(buffer);
return packet;
2021-10-18 07:20:14 +00:00
static func initProtocol():
2021-10-18 11:43:09 +00:00
protocols[100] = ComplexObject
protocols[101] = NormalObject
protocols[102] = ObjectA
protocols[103] = ObjectB
protocols[104] = SimpleObject