Example #1
0
        public void DisplayGumpResponse( GameClient 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 )
                {
                    int switchCount = pvSrc.ReadInt32();

                    if ( switchCount < 0 || switchCount > gump.m_Switches )
                    {
                        Console.WriteLine( "Client: {0}: Invalid gump response, disconnecting...", state );
                        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 )
                    {
                        Console.WriteLine( "Client: {0}: Invalid gump response, disconnecting...", state );
                        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 )
                            return;

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

                    try
                    {
                        gump.OnResponse( state, new RelayInfo( buttonID, switches, textEntries ) );
                    }
                    catch ( Exception e )
                    {
                        Logger.Error( "Exception disarmed in gump response of {0}: {1}", gump, e );
                    }

                    state.RemoveGump( gump );
                    return;
                }
            }

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

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

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

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