Server.Network.PacketHandlers.DisplayGumpResponse C# (CSharp) Méthode

DisplayGumpResponse() public static méthode

public static DisplayGumpResponse ( Server.Network.NetState state, PacketReader pvSrc ) : void
state Server.Network.NetState
pvSrc PacketReader
Résultat void
        public static void DisplayGumpResponse( NetState state, PacketReader pvSrc )
        {
            int serial = pvSrc.ReadInt32();
            int typeID = pvSrc.ReadInt32();
            int buttonID = pvSrc.ReadInt32();

            foreach ( Gump gump in state.Gumps ) {
                if ( gump.Serial == serial && gump.TypeID == typeID ) {
                    var buttonExists = buttonID == 0; // 0 is always 'close'

                    if (!buttonExists)
                    {
                        foreach (var e in gump.Entries)
                        {
                            if (e is GumpButton && ((GumpButton)e).ButtonID == buttonID)
                            {
                                buttonExists = true;
                                break;
                            }

                            if (e is GumpImageTileButton && ((GumpImageTileButton)e).ButtonID == buttonID)
                            {
                                buttonExists = true;
                                break;
                            }
                        }
                    }

                    if (!buttonExists)
                    {
                        state.WriteConsole("Invalid gump response, disconnecting...");
                        state.Dispose();
                        return;
                    }

                    int switchCount = pvSrc.ReadInt32();

                    if ( switchCount < 0 || switchCount > gump.m_Switches ) {
                        state.WriteConsole( "Invalid gump response, disconnecting..." );
                        state.Dispose();
                        return;
                    }

                    int[] switches = new int[switchCount];

                    for ( int j = 0; j < switches.Length; ++j )
                        switches[j] = pvSrc.ReadInt32();

                    int textCount = pvSrc.ReadInt32();

                    if ( textCount < 0 || textCount > gump.m_TextEntries ) {
                        state.WriteConsole( "Invalid gump response, disconnecting..." );
                        state.Dispose();
                        return;
                    }

                    TextRelay[] textEntries = new TextRelay[textCount];

                    for ( int j = 0; j < textEntries.Length; ++j ) {
                        int entryID = pvSrc.ReadUInt16();
                        int textLength = pvSrc.ReadUInt16();

                        if ( textLength > 239 ) {
                            state.WriteConsole( "Invalid gump response, disconnecting..." );
                            state.Dispose();
                            return;
                        }

                        string text = pvSrc.ReadUnicodeStringSafe( textLength );
                        textEntries[j] = new TextRelay( entryID, text );
                    }

                    state.RemoveGump( gump );

                    GumpProfile prof = GumpProfile.Acquire( gump.GetType() );

                    if ( prof != null ) {
                        prof.Start();
                    }

                    gump.OnResponse( state, new RelayInfo( buttonID, switches, textEntries ) );

                    if ( prof != null ) {
                        prof.Finish();
                    }

                    return;
                }
            }

            if ( typeID == 461 ) { // Virtue gump
                int switchCount = pvSrc.ReadInt32();

                if ( buttonID == 1 && switchCount > 0 ) {
                    Mobile beheld = World.FindMobile( pvSrc.ReadInt32() );

                    if ( beheld != null ) {
                        EventSink.InvokeVirtueGumpRequest( new VirtueGumpRequestEventArgs( state.Mobile, beheld ) );
                    }
                } else {
                    Mobile beheld = World.FindMobile( serial );

                    if ( beheld != null ) {
                        EventSink.InvokeVirtueItemRequest( new VirtueItemRequestEventArgs( state.Mobile, beheld, buttonID ) );
                    }
                }
            }
        }
PacketHandlers