示例#1
0
        private void OnPacketReceived(object sender, IPBEPacket packet)
        {
            // TODO: Kick players who are sending broken packets or sending too many
            Type type = packet.GetType();

            Debug.WriteLine($"Packet received ({BattleId} {TrainerName} \"{type.Name}\")");
            if (_packetType != null && type.Equals(_packetType))
            {
                _packetType = null;
                switch (packet)
                {
                case PBELegalPartyResponsePacket lprp:
                {
                    Console.WriteLine($"Received party ({BattleId} {TrainerName})");
                    if (!Server.Settings.Equals(lprp.Party.Settings))
                    {
                        Console.WriteLine("Party does not have matching settings!");
                        Console.WriteLine("\tServer: \"{0}\"", Server.Settings);
                        Console.WriteLine("\tParty: \"{0}\"", lprp.Party.Settings);
                    }
                    else
                    {
                        _party = lprp.Party;
                        resetEvent.Set();
                    }
                    break;
                }

                case PBEPartyResponsePacket prp:
                {
                    Console.WriteLine($"Received party ({BattleId} {TrainerName})");
                    _party = prp.Party;
                    resetEvent.Set();
                    break;
                }

                default: resetEvent.Set(); break;
                }
            }
            else if (_actionType != null && (type.Equals(_actionType) || type.Equals(typeof(PBEFleeResponsePacket))))
            {
                _actionType = null;
                switch (packet)
                {
                case PBEActionsResponsePacket arp: Server.ActionsSubmitted(this, arp.Actions); break;

                case PBEFleeResponsePacket _: Server.FleeSubmitted(this); break;

                case PBESwitchInResponsePacket sirp: Server.SwitchesSubmitted(this, sirp.Switches); break;

                default: throw new ArgumentOutOfRangeException(nameof(packet));
                }
            }
        }
示例#2
0
        private void OnPacketReceived(object sender, IPBEPacket packet)
        {
            Debug.WriteLine($"Packet received ({BattleId} \"{packet.GetType().Name}\")");
            resetEvent.Set();
            if (BattleId < 2)
            {
                switch (packet)
                {
                case PBEActionsResponsePacket arp:
                {
                    Server.ActionsSubmitted(this, arp.Actions);
                    break;
                }

                case PBEPartyResponsePacket prp:
                {
                    Console.WriteLine($"Received team from {TrainerName}!");
                    if (!submittedTeam)
                    {
                        submittedTeam = true;
                        PBETeamShell s = prp.TeamShell;
                        Server.PartySubmitted(this, s);
                        s.Dispose();
                    }
                    else
                    {
                        Console.WriteLine("Team submitted multiple times!");
                    }
                    break;
                }

                case PBESwitchInResponsePacket sirp:
                {
                    Server.SwitchesSubmitted(this, sirp.Switches);
                    break;
                }
                }
            }
            // TODO: Kick players who are sending bogus packets or sending too many
        }