ReadUInt16() public méthode

public ReadUInt16 ( ) : ushort
Résultat ushort
Exemple #1
0
        public static void HeritageTransform(NetState state, PacketReader reader)
        {
            Mobile m = state.Mobile;
			
            if (reader.Size == 5)
            {
                m.SendLocalizedMessage(1073645); // You may try this again later...	
				
                HeritageQuester.RemovePending(m);
            }
            else if (reader.Size == 15)
            { 
                if (HeritageQuester.IsPending(m))
                {
                    HeritageQuester quester = HeritageQuester.Pending(m);
				
                    m.Race = quester.Race;
					
                    m.Hue = reader.ReadUInt16();
                    m.HairItemID = reader.ReadUInt16();
                    m.HairHue = reader.ReadUInt16();
                    m.FacialHairItemID = reader.ReadUInt16();
                    m.FacialHairHue = reader.ReadUInt16();
				
                    HeritageQuester.RemovePending(m);
                    quester.CheckCompleted(m, true); // removes done quests
					
                    if (m.Race == Race.Elf)
                        m.SendLocalizedMessage(1073653); // You are now fully initiated into the Elven culture.
                    else if (m.Race == Race.Human)						
                        m.SendLocalizedMessage(1073654); // You are now fully human.
                }
            }
        }
		public static void ProfileReq( NetState state, PacketReader pvSrc )
		{
			int type = pvSrc.ReadByte();
			Serial serial = pvSrc.ReadInt32();

			Mobile beholder = state.Mobile;
			Mobile beheld = World.FindMobile( serial );

			if ( beheld == null )
				return;

			switch ( type )
			{
				case 0x00: // display request
				{
					EventSink.InvokeProfileRequest( new ProfileRequestEventArgs( beholder, beheld ) );

					break;
				}
				case 0x01: // edit request
				{
					pvSrc.ReadInt16(); // Skip
					int length = pvSrc.ReadUInt16();

					if ( length > 511 )
						return;

					string text = pvSrc.ReadUnicodeString( length );

					EventSink.InvokeChangeProfileRequest( new ChangeProfileRequestEventArgs( beholder, beheld, text ) );

					break;
				}
			}
		}
		private static void UpdateAccount( NetState state, PacketReader pvSrc )
		{
			string username = pvSrc.ReadString();
			string pass = pvSrc.ReadString();

			Account a = Accounts.GetAccount( username );

			if ( a == null )
				a = Accounts.AddAccount( username, pass );
			else if ( pass != "(hidden)" )
				a.SetPassword( pass );

			if ( a != state.Account )
			{
				a.AccessLevel = (AccessLevel)pvSrc.ReadByte();
				a.Banned = pvSrc.ReadBoolean();
			}
			else
			{
				pvSrc.ReadInt16();//skip both
				state.Send( new MessageBoxMessage( "Warning: When editing your own account, account status and accesslevel cannot be changed.", "Editing Own Account" ) );
			}

			ArrayList list = new ArrayList();
			ushort length = pvSrc.ReadUInt16();
			bool invalid = false;
			for (int i=0;i<length;i++)
			{
				string add = pvSrc.ReadString();
				if ( Utility.IsValidIP( add ) )
					list.Add( add );
				else
					invalid = true;
			}

			if ( list.Count > 0 )
				a.IPRestrictions = (string[])list.ToArray( typeof( string ) );
			else
				a.IPRestrictions = new string[0];

			if ( invalid )
				state.Send( new MessageBoxMessage( "Warning: one or more of the IP Restrictions you specified was not valid.", "Invalid IP Restriction" ) );
			state.Send( new MessageBoxMessage( "Account updated successfully.", "Account Updated" ) );
		}
		public static void SystemInfo( NetState state, PacketReader pvSrc )
		{
			int v1 = pvSrc.ReadByte();
			int v2 = pvSrc.ReadUInt16();
			int v3 = pvSrc.ReadByte();
			string s1 = pvSrc.ReadString( 32 );
			string s2 = pvSrc.ReadString( 32 );
			string s3 = pvSrc.ReadString( 32 );
			string s4 = pvSrc.ReadString( 32 );
			int v4 = pvSrc.ReadUInt16();
			int v5 = pvSrc.ReadUInt16();
			int v6 = pvSrc.ReadInt32();
			int v7 = pvSrc.ReadInt32();
			int v8 = pvSrc.ReadInt32();
		}
		public static void DeleteStatic( NetState state, PacketReader pvSrc )
		{
			if ( VerifyGC( state ) )
			{
				int x = pvSrc.ReadInt16();
				int y = pvSrc.ReadInt16();
				int z = pvSrc.ReadInt16();
				int id = pvSrc.ReadUInt16();

				Console.WriteLine( "God Client: {0}: Delete Static ({1}, {2}, {3}) 0x{4:X}", state, x, y, z, id );
			}
		}
		public static void CreateCharacter70160( NetState state, PacketReader pvSrc )
		{
			int unk1 = pvSrc.ReadInt32();
			int unk2 = pvSrc.ReadInt32();
			int unk3 = pvSrc.ReadByte();
			string name = pvSrc.ReadString( 30 );

			pvSrc.Seek( 2, SeekOrigin.Current );
			int flags = pvSrc.ReadInt32();
			pvSrc.Seek( 8, SeekOrigin.Current );
			int prof = pvSrc.ReadByte();
			pvSrc.Seek( 15, SeekOrigin.Current );

			int genderRace = pvSrc.ReadByte();

			int str = pvSrc.ReadByte();
			int dex = pvSrc.ReadByte();
			int intl= pvSrc.ReadByte();
			int is1 = pvSrc.ReadByte();
			int vs1 = pvSrc.ReadByte();
			int is2 = pvSrc.ReadByte();
			int vs2 = pvSrc.ReadByte();
			int is3 = pvSrc.ReadByte();
			int vs3 = pvSrc.ReadByte();
			int is4 = pvSrc.ReadByte();
			int vs4 = pvSrc.ReadByte();

			int hue = pvSrc.ReadUInt16();
			int hairVal = pvSrc.ReadInt16();
			int hairHue = pvSrc.ReadInt16();
			int hairValf= pvSrc.ReadInt16();
			int hairHuef= pvSrc.ReadInt16();
			pvSrc.ReadByte();
			int cityIndex = pvSrc.ReadByte();
			int charSlot = pvSrc.ReadInt32();
			int clientIP = pvSrc.ReadInt32();
			int shirtHue = pvSrc.ReadInt16();
			int pantsHue = pvSrc.ReadInt16();

			/*
			0x00, 0x01
			0x02, 0x03 -> Human Male, Human Female
			0x04, 0x05 -> Elf Male, Elf Female
			0x05, 0x06 -> Gargoyle Male, Gargoyle Female
			*/

			bool female = ((genderRace % 2) != 0);

			Race race = null;

			byte raceID = (byte)(genderRace < 4 ? 0 : ((genderRace / 2) - 1));
			race = Race.Races[raceID];
		
			if( race == null )
				race = Race.DefaultRace;

			CityInfo[] info = state.CityInfo;
			IAccount a = state.Account;

			if ( info == null || a == null || cityIndex < 0 || cityIndex >= info.Length )
			{
				state.Dispose();
			}
			else
			{
				// Check if anyone is using this account
				for ( int i = 0; i < a.Length; ++i )
				{
					Mobile check = a[i];

					if ( check != null && check.Map != Map.Internal )
					{
						Console.WriteLine( "Login: {0}: Account in use", state );
						state.Send( new PopupMessage( PMMessage.CharInWorld ) );
						return;
					}
				}

				state.Flags = (ClientFlags)flags;

				CharacterCreatedEventArgs args = new CharacterCreatedEventArgs(
					state, a,
					name, female, hue,
					str, dex, intl,
					info[cityIndex],
					new SkillNameValue[4]
					{
						new SkillNameValue( (SkillName)is1, vs1 ),
						new SkillNameValue( (SkillName)is2, vs2 ),
						new SkillNameValue( (SkillName)is3, vs3 ),
						new SkillNameValue( (SkillName)is4, vs4 ),
					},
					shirtHue, pantsHue,
					hairVal, hairHue,
					hairValf, hairHuef,
					prof,
					race
					);

				state.Send( new ClientVersionReq() );

				state.BlockAllPackets = true;

				EventSink.InvokeCharacterCreated( args );

				Mobile m = args.Mobile;

				if ( m != null )
				{
					state.Mobile = m;
					m.NetState = state;
					new LoginTimer( state, m ).Start();
				}
				else
				{
					state.BlockAllPackets = false;
					state.Dispose();
				}
			}
		}
		public static void VendorBuyReply( NetState state, PacketReader pvSrc )
		{
			pvSrc.Seek( 1, SeekOrigin.Begin );

			int msgSize = pvSrc.ReadUInt16();
			Mobile vendor = World.FindMobile( pvSrc.ReadInt32() );
			byte flag = pvSrc.ReadByte();

			if ( vendor == null )
			{
				return;
			}
			else if ( vendor.Deleted || !Utility.RangeCheck( vendor.Location, state.Mobile.Location, 10 ) )
			{
				state.Send( new EndVendorBuy( vendor ) );
				return;
			}

			if ( flag == 0x02 )
			{
				msgSize -= 1+2+4+1;

				if ( (msgSize / 7) > 100 )
					return;

				List<BuyItemResponse> buyList = new List<BuyItemResponse>( msgSize / 7 );
				for ( ;msgSize>0;msgSize-=7)
				{
					byte layer = pvSrc.ReadByte();
					Serial serial = pvSrc.ReadInt32();
					int amount = pvSrc.ReadInt16();
				
					buyList.Add( new BuyItemResponse( serial, amount ) );
				}

				if ( buyList.Count > 0 )
				{
					IVendor v = vendor as IVendor;

					if ( v != null && v.OnBuyItems( state.Mobile, buyList ) )
						state.Send( new EndVendorBuy( vendor ) );
				}
			}
			else
			{
				state.Send( new EndVendorBuy( vendor ) );
			}
		}
		public static void StringQueryResponse( NetState state, PacketReader pvSrc )
		{
			int serial = pvSrc.ReadInt32();
			pvSrc.ReadUInt16(); // unknown
			bool ok = pvSrc.ReadBoolean();
			int length = pvSrc.ReadUInt16();
			string str = null;
			if ( length > 0 )
				str = pvSrc.ReadString(length - 1);

			StringQueryCollection stringqueries = state.StringQueries;

			for ( int i = 0; i < stringqueries.Count; ++i )
			{
				StringQuery stringquery = stringqueries[i];

				if ( stringquery.Serial == serial )
				{
					stringquery.OnResponse( state, ok, str );

					state.RemoveStringQuery( i );
					return;
				}
			}
		}
Exemple #9
0
		public static void ContentChange( NetState state, PacketReader pvSrc )
		{
			Mobile from = state.Mobile;
			BaseBook book = World.FindItem( pvSrc.ReadInt32() ) as BaseBook;

			string ParsedContents = "";

			if ( book == null || !book.Writable || !from.InRange( book.GetWorldLocation(), 1 ) )
				return;

			int pageCount = pvSrc.ReadUInt16();

			if ( pageCount > book.PagesCount )
				return;

			for ( int i = 0; i < pageCount; ++i )
			{
				int index = pvSrc.ReadUInt16();

				if ( index >= 1 && index <= book.PagesCount )
				{
					--index;

					int lineCount = pvSrc.ReadUInt16();

					if ( lineCount <= 8 )
					{
						string[] lines = new string[lineCount];

						for ( int j = 0; j < lineCount; ++j ) {
							if ( (lines[j] = pvSrc.ReadUTF8StringSafe()).Length >= 80 )
								return;
							ParsedContents = ParsedContents + lines[j];
						}
						
						book.Pages[index].Lines = lines;

					}
					else
					{
						return;
					}
				}
				else
				{
					return;
				}
			}
			
			//erl: log the changed content (applied on page turn or book close, records page changed)
			// ||--
			
			// Log the changes
			StreamWriter LogFile = new StreamWriter( "logs/bookchange.log", true );
			LogFile.WriteLine("{0}: {1}: {2}: x:{3}, y:{4}, z:{5}: {6}: {7}", DateTime.Now, from.Account, from.Name, from.Location.X, from.Location.Y, from.Location.Z, book.Title, ParsedContents);
			LogFile.Close();

			// Update LastEdited property
			book.LastEdited = from.Serial.ToString();

			// ---||

		}
		private static void Emulator( NetState state, PacketReader pvSrc )
		{
			int code = pvSrc.ReadUInt16();
			switch (code) {
			case 0x0001:
				OnAddAuthID(state, pvSrc);
				break;
			}
		}
		public static void SystemInfo( NetState state, PacketReader pvSrc )
		{
			/*int v1 = */pvSrc.ReadByte();
			/*int v2 = */pvSrc.ReadUInt16();
			/*int v3 = */pvSrc.ReadByte();
			/*string s1 = */pvSrc.ReadString( 32 );
			/*string s2 = */pvSrc.ReadString( 32 );
			/*string s3 = */pvSrc.ReadString( 32 );
			/*string s4 = */pvSrc.ReadString( 32 );
			/*int v4 = */pvSrc.ReadUInt16();
			/*int v5 = */pvSrc.ReadUInt16();
			/*int v6 = */pvSrc.ReadInt32();
			/*int v7 = */pvSrc.ReadInt32();
			/*int v8 = */pvSrc.ReadInt32();
		}
		public static void CreateCharacter( NetState state, PacketReader pvSrc )
		{
			/*int unk1 = */pvSrc.ReadInt32();
			/*int unk2 = */pvSrc.ReadInt32();
			/*int unk3 = */pvSrc.ReadByte();
			string name = pvSrc.ReadString( 30 );

			pvSrc.Seek( 2, SeekOrigin.Current );
			int flags = pvSrc.ReadInt32();
			pvSrc.Seek( 8, SeekOrigin.Current );
			int prof = pvSrc.ReadByte();
			pvSrc.Seek( 15, SeekOrigin.Current );

			bool female = pvSrc.ReadByte() > 0 ? true : false;
			/*int genderRace = pvSrc.ReadByte();*/
			int str = pvSrc.ReadByte();
			int dex = pvSrc.ReadByte();
			int intl= pvSrc.ReadByte();
			int is1 = pvSrc.ReadByte();
			int vs1 = pvSrc.ReadByte();
			int is2 = pvSrc.ReadByte();
			int vs2 = pvSrc.ReadByte();
			int is3 = pvSrc.ReadByte();
			int vs3 = pvSrc.ReadByte();
			int hue = pvSrc.ReadUInt16();
			int hairVal = pvSrc.ReadInt16();
			int hairHue = pvSrc.ReadInt16();
			int hairValf= pvSrc.ReadInt16();
			int hairHuef= pvSrc.ReadInt16();
			pvSrc.ReadByte();
			int cityIndex = pvSrc.ReadByte();
			/*int charSlot = */pvSrc.ReadInt32();
			/*int clientIP = */pvSrc.ReadInt32();
			int shirtHue = pvSrc.ReadInt16();
			int pantsHue = pvSrc.ReadInt16();

			CityInfo[] info = state.CityInfo;
			IAccount a = state.Account;

			if ( info == null || a == null || cityIndex < 0 || cityIndex >= info.Length )
			{
				state.Dispose();
			}
			else
			{
				// Check if anyone is using this account
				for ( int i = 0; i < a.Length; ++i )
				{
					Mobile check = a[i];

					if ( check != null && check.Map != Map.Internal )
					{
						log.InfoFormat("Login: {0}: Account in use", state);
						state.Send( new PopupMessage( PMMessage.CharInWorld ) );
						return;
					}
				}

				state.Flags = flags;

				CharacterCreatedEventArgs args = new CharacterCreatedEventArgs(
					state, a,
					name, female, hue,
					str, dex, intl,
					info[cityIndex],
					new SkillNameValue[3]
					{
						new SkillNameValue( (SkillName)is1, vs1 ),
						new SkillNameValue( (SkillName)is2, vs2 ),
						new SkillNameValue( (SkillName)is3, vs3 ),
					},
					shirtHue, pantsHue,
					hairVal, hairHue,
					hairValf, hairHuef,
					prof );

				state.Send( new ClientVersionReq() );

				state.BlockAllPackets = true;

				try {
					EventSink.InvokeCharacterCreated(args);
				} catch (Exception ex) {
					log.Fatal(String.Format("Exception disarmed in CharacterCreated {0}",
											name), ex);
				}

				Mobile m = args.Mobile;

				if ( m != null )
				{
					state.Mobile = m;
					m.NetState = state;
					new LoginTimer( state, m ).Start();
				}
				else
				{
					state.BlockAllPackets = false;
					state.Dispose();
				}
			}
		}
		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 )
				{
					int switchCount = pvSrc.ReadInt32();

					if ( switchCount < 0 || switchCount > gump.m_Switches )
					{
						log.InfoFormat("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 )
					{
						log.InfoFormat("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 );
					}

					state.RemoveGump( gump );

					try {
						gump.OnResponse( state, new RelayInfo( buttonID, switches, textEntries ) );
					} catch (Exception e) {
						log.Fatal(String.Format("Exception disarmed in gump response of {0}",
												gump), e);
					}

					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 ) );
				}
			}
		}
		public static void LiftReq( NetState state, PacketReader pvSrc )
		{
			Serial serial = pvSrc.ReadInt32();
			int amount = pvSrc.ReadUInt16();
			Item item = World.FindItem( serial );

			bool rejected;
			LRReason reject;

			try {
				state.Mobile.Lift( item, amount, out rejected, out reject );
			} catch (Exception e) {
				log.Fatal(String.Format("Exception disarmed in lift {0}, {1} x {2}",
										state.Mobile, item, amount), e);
			}
		}
		public static void ClientType( NetState state, PacketReader pvSrc )
		{
			pvSrc.ReadUInt16();

			int type = pvSrc.ReadUInt16();
			CV version = state.Version = new CV( pvSrc.ReadString() );

			//EventSink.InvokeClientVersionReceived( new ClientVersionReceivedArgs( state, version ) );//todo
		}
Exemple #16
0
        public static void ContentChange(NetState state, PacketReader pvSrc)
        {
            Mobile from = state.Mobile;
            BaseBook book = World.FindItem(pvSrc.ReadInt32()) as BaseBook;

            if (book == null || !book.Writable || !from.InRange(book.GetWorldLocation(), 1) || !book.IsAccessibleTo(from))
                return;

            int pageCount = pvSrc.ReadUInt16();

            if (pageCount > book.PagesCount)
                return;

            for (int i = 0; i < pageCount; ++i)
            {
                int index = pvSrc.ReadUInt16();

                if (index >= 1 && index <= book.PagesCount)
                {
                    --index;

                    int lineCount = pvSrc.ReadUInt16();

                    if (lineCount <= 8)
                    {
                        string[] lines = new string[lineCount];

                        for (int j = 0; j < lineCount; ++j)
                            if ((lines[j] = pvSrc.ReadUTF8StringSafe()).Length >= 80)
                                return;

                        book.Pages[index].Lines = lines;
                    }
                    else
                    {
                        return;
                    }
                }
                else
                {
                    return;
                }
            }
        }
		public static void PlayCharacter( NetState state, PacketReader pvSrc )
		{
			pvSrc.ReadInt32(); // 0xEDEDEDED

			string name = pvSrc.ReadString( 30 );

			pvSrc.Seek( 2, SeekOrigin.Current );
			int flags = pvSrc.ReadInt32();

			if ( FeatureProtection.DisabledFeatures != 0 && ThirdPartyAuthCallback != null )
			{
				bool authOK = false;

				ulong razorFeatures = (((ulong)pvSrc.ReadUInt32())<<32) | ((ulong)pvSrc.ReadUInt32());

				if ( razorFeatures == (ulong)FeatureProtection.DisabledFeatures )
				{
					bool match = true;
					for ( int i=0; match && i < m_ThirdPartyAuthKey.Length; i++ )
						match = match && pvSrc.ReadByte() == m_ThirdPartyAuthKey[i];
						
					if ( match )
						authOK = true;
				}
                else
                {
                    pvSrc.Seek( 16, SeekOrigin.Current );
                }

				ThirdPartyAuthCallback( state, authOK );
			}
			else
			{
				pvSrc.Seek( 24, SeekOrigin.Current );
			}

			if ( ThirdPartyHackedCallback != null )
			{
				pvSrc.Seek( -2, SeekOrigin.Current );
				if ( pvSrc.ReadUInt16() == 0xDEAD )
					ThirdPartyHackedCallback( state, true );
			}

			if ( !state.Running )
				return;

			int charSlot = pvSrc.ReadInt32();
			int clientIP = pvSrc.ReadInt32();

			IAccount a = state.Account;

			if ( a == null || charSlot < 0 || charSlot >= a.Length )
			{
				state.Dispose();
			}
			else
			{
				Mobile m = a[charSlot];

				// Check if anyone is using this account
				for ( int i = 0; i < a.Length; ++i )
				{
					Mobile check = a[i];

					if ( check != null && check.Map != Map.Internal && check != m )
					{
						Console.WriteLine( "Login: {0}: Account in use", state );
						state.Send( new PopupMessage( PMMessage.CharInWorld ) );
						return;
					}
				}

				if ( m == null )
				{
					state.Dispose();
				}
				else
				{
					if ( m.NetState != null )
						m.NetState.Dispose();

					NetState.ProcessDisposedQueue();

					state.Send( new ClientVersionReq() );

					state.BlockAllPackets = true;

					state.Flags = (ClientFlags)flags;

					state.Mobile = m;
					m.NetState = state;

					new LoginTimer( state, m ).Start();
				}
			}
		}
Exemple #18
0
        public static void HeaderChange(NetState state, PacketReader pvSrc)
        {
            Mobile from = state.Mobile;
            BaseBook book = World.FindItem(pvSrc.ReadInt32()) as BaseBook;

            if (book == null || !book.Writable || !from.InRange(book.GetWorldLocation(), 1) || !book.IsAccessibleTo(from))
                return;

            pvSrc.Seek(4, SeekOrigin.Current); // Skip flags and page count

            int titleLength = pvSrc.ReadUInt16();

            if (titleLength > 60)
                return;

            string title = pvSrc.ReadUTF8StringSafe(titleLength);

            int authorLength = pvSrc.ReadUInt16();

            if (authorLength > 30)
                return;

            string author = pvSrc.ReadUTF8StringSafe(authorLength);

            book.Title = Utility.FixHtml(title);
            book.Author = Utility.FixHtml(author);
        }
		public static void EncodedCommand( NetState state, PacketReader pvSrc )
		{
			IEntity e = World.FindEntity( pvSrc.ReadInt32() );
			int packetID = pvSrc.ReadUInt16();

			EncodedPacketHandler ph = GetEncodedHandler( packetID );

			if ( ph != null )
			{
				if ( ph.Ingame && state.Mobile == null )
				{
					Console.WriteLine( "Client: {0}: Sent ingame packet (0xD7x{1:X2}) before having been attached to a mobile", state, packetID );
					state.Dispose();
				}
				else if ( ph.Ingame && state.Mobile.Deleted )
				{
					state.Dispose();
				}
				else
				{
					ph.OnReceive( state, e, new EncodedReader( pvSrc ) );
				}
			}
			else
			{
				pvSrc.Trace( state );
			}
		}
Exemple #20
0
        private static void UpdateAccount(NetState state, PacketReader pvSrc)
        { 
            if (state.Account.AccessLevel < AccessLevel.Administrator)
            {
                state.Send(new MessageBoxMessage("You do not have permission to edit accounts.", "Account Access Exception"));
                return;
            }

            string username = pvSrc.ReadString();
            string pass = pvSrc.ReadString();

            Account a = Accounts.GetAccount(username) as Account;

            if (a != null && !CanAccessAccount(state.Account, a))
            {
                state.Send(new MessageBoxMessage("You cannot edit an account with an access level greater than or equal to your own.", "Account Access Exception"));
            }
            else
            {
                bool CreatedAccount = false;
                bool UpdatedPass = false;
                bool oldbanned = a == null ? false : a.Banned;
                AccessLevel oldAcessLevel = a == null ? 0 : a.AccessLevel;

                if (a == null)
                {
                    a = new Account(username, pass);
                    CreatedAccount = true;
                }
                else if (pass != "(hidden)")
                {
                    a.SetPassword(pass);
                    UpdatedPass = true;
                }

                if (a != state.Account)
                {
                    AccessLevel newAccessLevel = (AccessLevel)pvSrc.ReadByte();
                    if (a.AccessLevel != newAccessLevel)
                    {
                        if (newAccessLevel >= state.Account.AccessLevel)
                            state.Send(new MessageBoxMessage("Warning: You may not set an access level greater than or equal to your own.", "Account Access Level update denied."));
                        else
                            a.AccessLevel = newAccessLevel;
                    }
                    bool newBanned = pvSrc.ReadBoolean();
                    if (newBanned != a.Banned)
                    {
                        oldbanned = a.Banned;
                        a.Banned = newBanned;
                        a.Comments.Add(new AccountComment(state.Account.Username, newBanned ? "Banned via Remote Admin" : "Unbanned via Remote Admin"));
                    }
                }
                else
                {
                    pvSrc.ReadInt16();//skip both
                    state.Send(new MessageBoxMessage("Warning: When editing your own account, Account Status and Access Level cannot be changed.", "Editing Own Account"));
                }

                ArrayList list = new ArrayList();
                ushort length = pvSrc.ReadUInt16();
                bool invalid = false;
                for (int i = 0; i < length; i++)
                {
                    string add = pvSrc.ReadString();
                    if (Utility.IsValidIP(add))
                        list.Add(add);
                    else
                        invalid = true;
                }

                if (list.Count > 0)
                    a.IPRestrictions = (string[])list.ToArray(typeof(string));
                else
                    a.IPRestrictions = new string[0];

                if (invalid)
                    state.Send(new MessageBoxMessage("Warning: one or more of the IP Restrictions you specified was not valid.", "Invalid IP Restriction"));

                if (CreatedAccount)
                    RemoteAdminLogging.WriteLine(state, "Created account {0} with Access Level {1}", a.Username, a.AccessLevel);
                else
                {
                    string changes = string.Empty;
                    if (UpdatedPass)
                        changes += " Password Changed.";
                    if (oldAcessLevel != a.AccessLevel)
                        changes = string.Format("{0} Access level changed from {1} to {2}.", changes, oldAcessLevel, a.AccessLevel);
                    if (oldbanned != a.Banned)
                        changes += a.Banned ? " Banned." : " Unbanned.";
                    RemoteAdminLogging.WriteLine(state, "Updated account {0}:{1}", a.Username, changes);
                }

                state.Send(new MessageBoxMessage("Account updated successfully.", "Account Updated"));
            }
        }
		public static void VendorSellReply( NetState state, PacketReader pvSrc )
		{
			Serial serial = pvSrc.ReadInt32();
			Mobile vendor = World.FindMobile( serial );

			if ( vendor == null )
			{
				return;
			}
			else if ( vendor.Deleted || !Utility.RangeCheck( vendor.Location, state.Mobile.Location, 10 ) )
			{
				state.Send( new EndVendorSell( vendor ) );
				return;
			}

			int count = pvSrc.ReadUInt16();
			if ( count < 100 && pvSrc.Size == (1+2+4+2+(count*6)) )
			{
				List<SellItemResponse> sellList = new List<SellItemResponse>( count );

				for (int i=0;i<count;i++)
				{
					Item item = World.FindItem( pvSrc.ReadInt32() );
					int Amount = pvSrc.ReadInt16();

					if ( item != null && Amount > 0 )
						sellList.Add(  new SellItemResponse( item, Amount ) );
				}

				if ( sellList.Count > 0 )
				{
					IVendor v = vendor as IVendor;

					if ( v != null && v.OnSellItems( state.Mobile, sellList ) )
						state.Send( new EndVendorSell( vendor ) );
				}
			}
		}
		public static void TargetResponse( NetState state, PacketReader pvSrc )
		{
			int type = pvSrc.ReadByte();
			int targetID = pvSrc.ReadInt32();
			int flags = pvSrc.ReadByte();
			Serial serial = pvSrc.ReadInt32();
			int x = pvSrc.ReadInt16(), y = pvSrc.ReadInt16(), z = pvSrc.ReadInt16();
			int graphic = pvSrc.ReadUInt16();

			if ( targetID == unchecked( (int) 0xDEADBEEF ) )
				return;

			Mobile from = state.Mobile;

			Target t = from.Target;

			if ( t != null )
			{
				TargetProfile prof = TargetProfile.Acquire( t.GetType() );

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

				try {
					if ( x == -1 && y == -1 && !serial.IsValid )
					{
						// User pressed escape
						t.Cancel( from, TargetCancelType.Canceled );
					}
					else if ( Target.TargetIDValidation && t.TargetID != targetID )
					{
						// Sanity, prevent fake target
						return;
					}
					else
					{
						object toTarget;

						if ( type == 1 )
						{
							if ( graphic == 0 )
							{
								toTarget = new LandTarget( new Point3D( x, y, z ), from.Map );
							}
							else
							{
								Map map = from.Map;

								if ( map == null || map == Map.Internal )
								{
									t.Cancel( from, TargetCancelType.Canceled );
									return;
								}
								else
								{
									StaticTile[] tiles = map.Tiles.GetStaticTiles( x, y, !t.DisallowMultis );

									bool valid = false;

									if ( state.HighSeas ) {
										ItemData id = TileData.ItemTable[graphic&TileData.MaxItemValue];
										if ( id.Surface ) {
											z -= id.Height;
										}
									}

									for ( int i = 0; !valid && i < tiles.Length; ++i )
									{
										if ( tiles[i].Z == z && tiles[i].ID == graphic )
											valid = true;
									}

									if ( !valid )
									{
										t.Cancel( from, TargetCancelType.Canceled );
										return;
									}
									else
									{
										toTarget = new StaticTarget( new Point3D( x, y, z ), graphic );
									}
								}
							}
						}
						else if ( serial.IsMobile )
						{
							toTarget = World.FindMobile( serial );
						}
						else if ( serial.IsItem )
						{
							toTarget = World.FindItem( serial );
						}
						else
						{
							t.Cancel( from, TargetCancelType.Canceled );
							return;
						}

						t.Invoke( from, toTarget );
					}
				} finally {
					if ( prof != null ) {
						prof.Finish();
					}
				}
			}
		}
		public static void Edit( NetState state, PacketReader pvSrc )
		{
			if ( VerifyGC( state ) )
			{
				int type = pvSrc.ReadByte(); // 10 = static, 7 = npc, 4 = dynamic
				int x = pvSrc.ReadInt16();
				int y = pvSrc.ReadInt16();
				int id = pvSrc.ReadInt16();
				int z = pvSrc.ReadSByte();
				int hue = pvSrc.ReadUInt16();

				Console.WriteLine( "God Client: {0}: Edit {6} ({1}, {2}, {3}) 0x{4:X} (0x{5:X})", state, x, y, z, id, hue, type );
			}
		}
		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 ) {
					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 ) );
					}
				}
			}
		}
		public static void NewTerrain( NetState state, PacketReader pvSrc )
		{
			if ( VerifyGC( state ) )
			{
				int x = pvSrc.ReadInt16();
				int y = pvSrc.ReadInt16();
				int id = pvSrc.ReadUInt16();
				int width = pvSrc.ReadInt16();
				int height = pvSrc.ReadInt16();

				Console.WriteLine( "God Client: {0}: New Terrain ({1}, {2})+({3}, {4}) 0x{5:X4}", state, x, y, width, height, id );
			}
		}
		public static void ExtendedCommand( NetState state, PacketReader pvSrc )
		{
			int packetID = pvSrc.ReadUInt16();

			PacketHandler ph = GetExtendedHandler( packetID );

			if ( ph != null )
			{
				if ( ph.Ingame && state.Mobile == null )
				{
					Console.WriteLine( "Client: {0}: Sent ingame packet (0xBFx{1:X2}) before having been attached to a mobile", state, packetID );
					state.Dispose();
				}
				else if ( ph.Ingame && state.Mobile.Deleted )
				{
					state.Dispose();
				}
				else
				{
					ph.OnReceive( state, pvSrc );
				}
			}
			else
			{
				pvSrc.Trace( state );
			}
		}
		public static void LiftReq( NetState state, PacketReader pvSrc )
		{
			Serial serial = pvSrc.ReadInt32();
			int amount = pvSrc.ReadUInt16();
			Item item = World.FindItem( serial );

			bool rejected;
			LRReason reject;

			state.Mobile.Lift( item, amount, out rejected, out reject );
		}
		public static void ContextMenuResponse( NetState state, PacketReader pvSrc )
		{
			Mobile from = state.Mobile;

			if ( from != null )
			{
				ContextMenu menu = from.ContextMenu;

				from.ContextMenu = null;

				if ( menu != null && from != null && from == menu.From )
				{
					IEntity entity = World.FindEntity( pvSrc.ReadInt32() );

					if ( entity != null && entity == menu.Target && from.CanSee( entity ) )
					{
						Point3D p;

						if ( entity is Mobile )
							p = entity.Location;
						else if ( entity is Item )
							p = ((Item)entity).GetWorldLocation();
						else
							return;

						int index = pvSrc.ReadUInt16();

						if ( index >= 0 && index < menu.Entries.Length )
						{
							ContextMenuEntry e = menu.Entries[index];

							int range = e.Range;

							if ( range == -1 )
								range = 18;

							if ( e.Enabled && from.InRange( p, range ) )
								e.OnClick();
						}
					}
				}
			}
		}
        public static void DisplayGumpResponse(NetState state, PacketReader pvSrc)
        {
            int serial = pvSrc.ReadInt32();
            int typeID = pvSrc.ReadInt32();
            int buttonID = pvSrc.ReadInt32();

            List<Gump> gumps = state.Gumps;

            for (int i = 0; i < gumps.Count; ++i)
            {
                Gump gump = gumps[i];

                if (gump.Serial == serial && gump.TypeID == typeID)
                {
                    int switchCount = pvSrc.ReadInt32();

                    if (switchCount < 0)
                    {
                        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)
                    {
                        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);
                    }

                    state.RemoveGump(i);

                    if (!CheckResponse(gump, state.Mobile, buttonID))
                        return;

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

                    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));
                }
            }
        }
 private static void Emulator( NetState state, PacketReader pvSrc )
 {
     int code = pvSrc.ReadUInt16();
     /*
     switch (code) {
     }
     */
 }