コード例 #1
0
        public override void HandlePacket(BinaryReader reader, int whoAmI)
        {
            //In case i f*ck the code
            try
            {
                string type = reader.ReadString();
#if DEBUG
                Main.NewText($"Received packet: [c/ff3333:{type}]");
#endif
                switch (type)
                {
                case SpawnStarterPacket.NAME:
                {
                    //Server can't have any UI
                    if (whoAmI == 256)
                    {
                        return;
                    }
                    SpawnStarterPacket packet = new SpawnStarterPacket();
                    packet.HandleFromClient(reader, whoAmI);
                }
                break;

                case BaseCatchPacket.NAME:
                {
                    //Server should handle it from client
                    if (whoAmI == 256)
                    {
                        return;
                    }
                    BaseCatchPacket packet = new BaseCatchPacket();
                    packet.HandleFromClient(reader, whoAmI);
                }
                break;

                default:
                    if (packetStore.ContainsKey(type))
                    {
                        if (whoAmI == 256)
                        {
                            packetStore[type].HandleFromServer(reader);
                        }
                        else
                        {
                            packetStore[type].HandleFromClient(reader, whoAmI);
                        }
                    }
                    break;
                }
            }
            catch (Exception e)
            {
                Logger.ErrorFormat(
                    "Exception appear in HandlePacket. Please, contact mod devs with folowing stacktrace:\n\n{0}\n\n{1}",
                    e.Message, e.StackTrace);
#if DEBUG
                Main.NewText($"[c/ff3322:{e.Message}]");
#endif
            }
        }
コード例 #2
0
        public override void HandlePacket(BinaryReader reader, int whoAmI)
        {
            //In case i f*ck the code
            try
            {
                string type = reader.ReadString();
                switch (type)
                {
                case SpawnStarterPacket.NAME:
                {
                    //Server can't have any UI
                    if (whoAmI == 256)
                    {
                        return;
                    }
                    SpawnStarterPacket packet = new SpawnStarterPacket();
                    packet.HandleFromClient(reader, whoAmI);
                }
                break;

                case BaseCatchPacket.NAME:
                {
                    //Server should handle it from client
                    if (whoAmI == 256)
                    {
                        return;
                    }
                    BaseCatchPacket packet = new BaseCatchPacket();
                    packet.HandleFromClient(reader, whoAmI);
                }
                break;
                }
            }
            catch (Exception e)
            {
                Logger.ErrorFormat(
                    "Exception appear in HandlePacket. Please, contact mod devs with folowing stacktrace:\n\n{0}\n\n{1}",
                    e.Message, e.StackTrace);
            }
        }