public void RegisterHandler(PacketOpcode.CLIENT code, AbstractServerPacketHandle handler) { try { registered[(short)code] = handler; } catch (Exception e) { Debug.LogError("Error registering handler - " + code); Debug.LogError(e.Message); } }
private void Start() { pingHandle = this.gameObject.AddComponent <PingHandle>(); RegisterHandler(PacketOpcode.CLIENT.PING, pingHandle); foreach (AbstractServerPacketHandle handle in handlers) { if (handle == null) { continue; } RegisterHandler(handle.getOpcode(), handle); } }
private AbstractServerPacketHandle GetHandler(short packetId) { if (packetId > registered.Length) { return(null); } AbstractServerPacketHandle handler = registered[packetId]; if (handler != null) { return(handler); } return(null); }
public void DelegateHandler(ClientObject client, PacketInStream packet) { lock (objectLock) { short head = packet.readShort(); AbstractServerPacketHandle handler = GetHandler(head); if (!handler.IsActive(client)) { return; } if (handler.IsNeedDebug()) { packet.printHex("Server"); } handler.DelegatePacket(new InPackageObject(client, packet)); } }