コード例 #1
0
 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);
     }
 }
コード例 #2
0
 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);
     }
 }
コード例 #3
0
        private AbstractServerPacketHandle GetHandler(short packetId)
        {
            if (packetId > registered.Length)
            {
                return(null);
            }

            AbstractServerPacketHandle handler = registered[packetId];

            if (handler != null)
            {
                return(handler);
            }
            return(null);
        }
コード例 #4
0
 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));
     }
 }