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):
|
|
|
|
var protocol = protocols[protocolId]
|
|
|
|
return protocol.new()
|
|
|
|
|
|
|
|
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):
|
|
|
|
var protocolId = buffer.readShort();
|
|
|
|
var protocol = protocols[protocolId]
|
|
|
|
var packet = protocol.read(buffer);
|
|
|
|
return packet;
|
|
|
|
|
|
|
|
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
|