Seek() public method

public Seek ( int offset, SeekOrigin origin ) : int
offset int
origin SeekOrigin
return int
Example #1
0
		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();
			int z = pvSrc.ReadInt16();
			int graphic = pvSrc.ReadInt16();

			pvSrc.Seek( 1, System.IO.SeekOrigin.Begin );

			Mobile from = state.Mobile;

			if ( from == null || from.Target == null )
				return;

			if ( x == 0 && y == 0 && z == 0 && serial != from.Serial )
			{
				bool ok = false;
				if ( serial.IsItem )
				{
					Item i = World.FindItem( serial );
					if ( i != null && i.Location == Point3D.Zero )
						ok = true;
				}
				else if ( serial.IsMobile )
				{
					Mobile m = World.FindMobile( serial );
					if ( m != null && m.Location == Point3D.Zero )
						ok = true;
				}

				object o = m_LastTarget[from];
				if ( !ok && o != null && o is Serial && serial != (Serial)o )
				{
					from.SendAsciiMessage( "This EasyUO target has been blocked." );
					from.Target.Cancel( from, TargetCancelType.Canceled );
					return;
				}
			}

			if ( from.Serial != serial )
				m_LastTarget[from] = serial;

			m_Real6C.OnReceive( state, pvSrc );	
		}
		public static void OpenChatWindowRequest( NetState state, PacketReader pvSrc )
		{
			Mobile from = state.Mobile;

			if ( !Enabled )
			{
				from.SendMessage( "The chat system has been disabled." );
				return;
			}

			pvSrc.Seek( 2, System.IO.SeekOrigin.Begin );
			/*string chatName = */
			pvSrc.ReadUnicodeStringSafe( ( 0x40 - 2 ) >> 1 ).Trim();

			string chatName = from.Name;

			SendCommandTo( from, ChatCommand.OpenChatWindow, chatName );
			ChatUser.AddChatUser( from );
		}
Example #3
0
        public static void LoginServerSeed(NetState state, PacketReader pvSrc)
        {
            int seed = pvSrc.ReadInt32(); // Seed

            int clientMaj = pvSrc.ReadInt32();
            int clientMin = pvSrc.ReadInt32();
            int clientRev = pvSrc.ReadInt32();
            int clientPat = pvSrc.ReadInt32();

            if ((seed == 0) && (clientMaj == 0) && (clientMin == 0) && (clientPat == 0) && (clientRev == 0))
            {
                state.SentFirstPacket = true;
                // This is UOExt. Cheers!
                state.Send(m_UOExtSupport);
                state.Flush();
                return;
            }

            // Enroute to old EF handler
            pvSrc.Seek(0, System.IO.SeekOrigin.Begin);
            m_OldEFHandler.OnReceive(state, pvSrc);

        }
Example #4
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 );

			title = Utility.FixHtml( title );
			author = Utility.FixHtml( author );

			#region AntiAdverts
			if (!String.IsNullOrWhiteSpace(title))
			{
				int exit = 100;
				string detected;

				while (AntiAdverts.Detect(title, out detected) && !String.IsNullOrWhiteSpace(detected) && --exit >= 0)
				{
					title = title.Replace(detected, new String('*', detected.Length));
				}
			}

			if (!String.IsNullOrWhiteSpace(author))
			{
				int exit = 100;
				string detected;

				while (AntiAdverts.Detect(author, out detected) && !String.IsNullOrWhiteSpace(detected) && --exit >= 0)
				{
					author = author.Replace(detected, new String('*', detected.Length));
				}
			}
			#endregion

			book.Title = title;
			book.Author = author;
		}
		public static void EquipReq( NetState state, PacketReader pvSrc )
		{
			Mobile from = state.Mobile;
			Item item = from.Holding;

			bool valid = ( item != null && item.HeldBy == from && item.Map == Map.Internal );

			from.Holding = null;

			if ( !valid ) {
				return;
			}

			pvSrc.Seek( 5, SeekOrigin.Current );
			Mobile to = World.FindMobile( pvSrc.ReadInt32() );

			if ( to == null )
				to = from;

			if ( !to.AllowEquipFrom( from ) || !to.EquipItem( item ) )
				item.Bounce( from );

			item.ClearBounce();
		}
		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 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();
				}
			}
		}
Example #8
0
		private static void EquipItem(NetState state, PacketReader reader, ref byte[] buffer, ref int length)
		{
			int pos = reader.Seek(0, SeekOrigin.Current);
			reader.Seek(1, SeekOrigin.Begin);

			Item item = World.FindItem(reader.ReadInt32());

			reader.Seek(pos, SeekOrigin.Begin);

			if (EquipItemParent != null)
			{
				EquipItemParent(state, reader, ref buffer, ref length);
			}

			if (!CMOptions.ModuleEnabled || item == null || item.Deleted || !item.Layer.IsEquip())
			{
				return;
			}

			if (CMOptions.ModuleDebug)
			{
				CMOptions.ToConsole("EquipItem: {0} equiped {1}", state.Mobile, item);
			}

			Timer.DelayCall(() => Invalidate(state.Mobile, item));
		}
		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 EquipReq( NetState state, PacketReader pvSrc )
		{
			Mobile from = state.Mobile;
			Item item = from.Holding;

			bool valid = ( item != null && item.HeldBy == from && item.Map == Map.Internal );

			from.Holding = null;

			if ( !valid ) {
				return;
			}

			pvSrc.Seek( 5, SeekOrigin.Current );
			Mobile to = World.FindMobile( pvSrc.ReadInt32() );

			if ( to == null )
				to = from;

			try {
				if ( !to.AllowEquipFrom(from) || !to.EquipItem( item ))
					item.Bounce(from);
			} catch (Exception e) {
				log.Fatal(String.Format("Exception disarmed in equip {0} < {1}",
										to, item), e);
			}

			item.ClearBounce();
		}
 // UOSA
 public static void EncryptionResponse3D(NetState state, PacketReader pvSrc)
 {
     int size = pvSrc.ReadInt16();
     int publicKey_lenght = pvSrc.ReadInt32();
     int publicKey = pvSrc.Seek(publicKey_lenght, SeekOrigin.Current);
 }
Example #12
0
 public static void UOExtPacket(NetState state, PacketReader pvSrc)
 {
     byte header = pvSrc.ReadByte();
     int position = pvSrc.Seek(0, System.IO.SeekOrigin.Current);
     m_handler.ProcessBuffer(new NetStateAdapter(state), header, pvSrc.Buffer, position, (short)(pvSrc.Size - 4));
 }
		public static void ContentChange(NetState state, PacketReader pvSrc)
		{
			// need to deal with actual books
			//string entryText = String.Empty;
			//Mobile from = state.Mobile;

			int pos = pvSrc.Seek(0, SeekOrigin.Current);

			int serial = pvSrc.ReadInt32();

			Item bookitem = World.FindItem(serial);

			// first try it as a normal basebook
			if (bookitem is BaseBook)
			{
				// do the base book content change
				//BaseContentChange(bookitem as BaseBook, state, pvSrc);

				pvSrc.Seek(pos, SeekOrigin.Begin);

				if (PacketHandlerOverrides.ContentChangeParent != null)
				{
					PacketHandlerOverrides.ContentChangeParent.OnReceive(state, pvSrc);
				}
				else
				{
					BaseBook.ContentChange(state, pvSrc);
				}

				return;
			}

			// then try it as a text entry book
			var book = bookitem as BaseEntryBook;

			if (book == null)
			{
				return;
			}

			// get the number of available pages in the book
			int pageCount = pvSrc.ReadUInt16();

			if (pageCount > book.PagesCount)
			{
				return;
			}

			for (int i = 0; i < pageCount; ++i)
			{
				// get the current page number being read
				int index = pvSrc.ReadUInt16();

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

					int lineCount = pvSrc.ReadUInt16();

					if (lineCount <= 8)
					{
						var 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;
				}
			}

			var sb = new StringBuilder();

			// add the book lines to the entry string
			for (int i = 0; i < book.PagesCount; ++i)
			{
				foreach (string line in book.Pages[i].Lines)
				{
					sb.Append(line);
				}
			}

			// send the book text off to be processed by invoking the callback if it is a textentry book
			var tebook = book as XmlTextEntryBook;
			if (tebook != null && tebook.m_bookcallback != null)
			{
				tebook.m_bookcallback(state.Mobile, tebook.m_args, sb.ToString());
			}
		}
Example #14
0
		public static void LookReq(NetState state, PacketReader pvSrc)
		{
			Mobile from = state.Mobile;

			int pos = pvSrc.Seek(0, SeekOrigin.Current);

			Serial s = pvSrc.ReadInt32();

			pvSrc.Seek(pos, SeekOrigin.Begin);

			if (s.IsMobile)
			{
				Mobile m = World.FindMobile(s);

				if (m != null && from.CanSee(m) && Utility.InUpdateRange(from, m) &&
					XmlScript.HasTrigger(m, TriggerName.onSingleClick) &&
					UberScriptTriggers.Trigger(m, from, TriggerName.onSingleClick))
				{
					return;
				}
			}
			else if (s.IsItem)
			{
				Item item = World.FindItem(s);

				if (item != null && !item.Deleted && from.CanSee(item) &&
					Utility.InUpdateRange(from.Location, item.GetWorldLocation(from)) &&
					XmlScript.HasTrigger(item, TriggerName.onSingleClick) &&
					UberScriptTriggers.Trigger(item, from, TriggerName.onSingleClick, item))
				{
					return;
				}
			}

			if (PacketHandlerOverrides.LookReqParent != null)
			{
				PacketHandlerOverrides.LookReqParent.OnReceive(state, pvSrc);
			}
			else
			{
				PacketHandlers.LookReq(state, pvSrc);
			}
		}
Example #15
0
		public static void UseReq(NetState state, PacketReader pvSrc)
		{
			Mobile from = state.Mobile;

			if (from.AccessLevel >= AccessLevel.GameMaster || DateTime.UtcNow >= from.NextActionTime)
			{
				int pos = pvSrc.Seek(0, SeekOrigin.Current);

				int value = pvSrc.ReadInt32();

				pvSrc.Seek(pos, SeekOrigin.Begin);

				if ((value & ~0x7FFFFFFF) != 0)
				{
					from.OnPaperdollRequest();
				}
				else
				{
					Serial s = value;

					bool blockdefaultonuse = false;

					if (s.IsMobile)
					{
						Mobile m = World.FindMobile(s);

						if (m != null && !m.Deleted)
						{
							blockdefaultonuse = (XmlScript.HasTrigger(m, TriggerName.onUse) &&
												 UberScriptTriggers.Trigger(m, from, TriggerName.onUse)) ||
												(XmlScript.HasTrigger(from, TriggerName.onUse) && UberScriptTriggers.Trigger(from, from, TriggerName.onUse));

							if (!blockdefaultonuse && !m.Deleted)
							{
								//from.Use(m);

								if (PacketHandlerOverrides.UseReqParent != null)
								{
									PacketHandlerOverrides.UseReqParent.OnReceive(state, pvSrc);
								}
								else
								{
									PacketHandlers.UseReq(state, pvSrc);
								}

								return;
							}
						}
					}
					else if (s.IsItem)
					{
						Item item = World.FindItem(s);

						if (item != null && !item.Deleted)
						{
							blockdefaultonuse = (XmlScript.HasTrigger(from, TriggerName.onUse) &&
												 UberScriptTriggers.Trigger(from, from, TriggerName.onUse)) ||
												(XmlScript.HasTrigger(item, TriggerName.onUse) && UberScriptTriggers.Trigger(item, from, TriggerName.onUse));

							// need to check the item again in case it was modified in the OnUse or OnUser method
							if (!blockdefaultonuse && !item.Deleted)
							{
								//from.Use(item);
								
								if (PacketHandlerOverrides.UseReqParent != null)
								{
									PacketHandlerOverrides.UseReqParent.OnReceive(state, pvSrc);
								}
								else
								{
									PacketHandlers.UseReq(state, pvSrc);
								}

								return;
							}
						}
					}
				}

				from.NextActionTime = DateTime.UtcNow + Mobile.ServerWideObjectDelay;
			}
			else
			{
				from.SendActionMessage();
			}
		}
Example #16
0
		public static void OpenChatWindowRequest( NetState state, PacketReader pvSrc )
		{
			Mobile from = state.Mobile;

			if ( !m_Enabled )
			{
				from.SendMessage( "The chat system has been disabled." );
				return;
			}

			pvSrc.Seek( 2, System.IO.SeekOrigin.Begin );
			string chatName = pvSrc.ReadUnicodeStringSafe( ( 0x40 - 2 ) >> 1 ).Trim();

			Account acct = state.Account as Account;

			string accountChatName = null;

			if ( acct != null )
				accountChatName = acct.GetTag( "ChatName" );

			if ( accountChatName != null )
				accountChatName = accountChatName.Trim();

			if ( accountChatName != null && accountChatName.Length > 0 )
			{
				if ( chatName.Length > 0 && chatName != accountChatName )
					from.SendMessage( "You cannot change chat nickname once it has been set." );
			}
			else
			{
				if ( chatName == null || chatName.Length == 0 )
				{
					SendCommandTo( from, ChatCommand.AskNewNickname );
					return;
				}

				if ( NameVerification.Validate( chatName, 2, 31, true, true, true, 0, NameVerification.SpaceDashPeriodQuote ) && chatName.ToLower().IndexOf( "system" ) == -1 )
				{
					// TODO: Optimize this search

					foreach ( Account checkAccount in Accounts.Table.Values )
					{
						string existingName = checkAccount.GetTag( "ChatName" );

						if ( existingName != null )
						{
							existingName = existingName.Trim();

							if ( Insensitive.Equals( existingName, chatName ) )
							{
								from.SendMessage( "Nickname already in use." );
								SendCommandTo( from, ChatCommand.AskNewNickname );
								return;
							}
						}
					}

					accountChatName = chatName;

					if ( acct != null )
						acct.AddTag( "ChatName", chatName );
				}
				else
				{
					from.SendLocalizedMessage( 501173 ); // That name is disallowed.
					SendCommandTo( from, ChatCommand.AskNewNickname );
					return;
				}
			}

			SendCommandTo( from, ChatCommand.OpenChatWindow, accountChatName );
			ChatUser.AddChatUser( from );
		}
Example #17
0
		private static void OnSingleClick(NetState state, PacketReader pvSrc)
		{
			if (state == null || pvSrc == null)
			{
				return;
			}

			PlayerMobile viewer = null;
			PlayerMobile target = null;
			TitleDisplay? d = null;

			if (CMOptions.ModuleEnabled && state.Mobile is PlayerMobile)
			{
				viewer = (PlayerMobile)state.Mobile;

				int pos = pvSrc.Seek(0, SeekOrigin.Current);

				pvSrc.Seek(1, SeekOrigin.Begin);

				Serial s = pvSrc.ReadInt32();

				pvSrc.Seek(pos, SeekOrigin.Begin);

				if (s.IsMobile)
				{
					target = World.FindMobile(s) as PlayerMobile;

					if (target != null && viewer.CanSee(target) && Utility.InUpdateRange(viewer, target))
					{
						Title t;

						if (GetTitle(target, out t) && t != null)
						{
							d = t.Display;
						}
					}
				}
			}

            var battle = AutoPvP.FindBattle(target) as UOF_PvPBattle;

			if (d != null && d.Value == TitleDisplay.BeforeName && (battle == null || !battle.IncognitoMode))
			{
				DisplayTitle(viewer, target);
			}

			if (LookReqParent != null)
			{
				LookReqParent.OnReceive(state, pvSrc);
			}
			else
			{
				PacketHandlers.LookReq(state, pvSrc);
			}

			if (d != null && d.Value == TitleDisplay.AfterName && (battle == null || !battle.IncognitoMode))
			{
				DisplayTitle(viewer, target);
			}
		}
        public static void EquipReq( NetState state, PacketReader pvSrc )
        {
            Mobile from = state.Mobile;
            Item item = from.Holding;

            if ( item == null )
                return;

            from.Holding = null;

            pvSrc.Seek( 5, SeekOrigin.Current );
            Mobile to = World.FindMobile( pvSrc.ReadInt32() );

            if ( to == null )
                to = from;

            bool success = false;

            try {
                if (to.AllowEquipFrom(from))
                    success = to.EquipItem(item);
            } catch (Exception e) {
                Console.WriteLine("Exception disarmed in equip {0} < {1}: {2}",
                                  to, item, e);
            }

            if (!success)
                item.Bounce(from);

            item.ClearBounce();
        }
		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();
			pvSrc.Seek( 24, SeekOrigin.Current );

			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 )
					{
						log.InfoFormat("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 = flags;

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

					new LoginTimer( state, m ).Start();
				}
			}
		}
			public void EncodeOutgoingPacket(NetState to, ref byte[] packetBuffer, ref int packetLength)
			{
				byte[] buffer;
				int bufferLength;
				byte packetId;

				if (to.CompressionEnabled)
				{
					var firstByte = Decompressor.DecompressFirstByte(packetBuffer, packetLength);

					if (!firstByte.HasValue)
					{
						Utility.PushColor(ConsoleColor.Yellow);
						Console.WriteLine("Outgoing Packet Override: Unable to decompress packet!");
						Utility.PopColor();

						return;
					}

					packetId = firstByte.Value;
				}
				else
				{
					packetId = packetBuffer[0];
				}

				var oHandler = GetHandler(packetId) ?? GetExtendedHandler(packetId);

				if (oHandler != null)
				{
					if (to.CompressionEnabled)
					{
						Decompressor.DecompressAll(packetBuffer, packetLength, _UnpackBuffer, out bufferLength);

						buffer = new byte[bufferLength];
						Buffer.BlockCopy(_UnpackBuffer, 0, buffer, 0, bufferLength);
					}
					else
					{
						buffer = packetBuffer;
					}

					var reader = new PacketReader(buffer, packetLength, false);
					reader.Seek(0, SeekOrigin.Begin);

					oHandler(to, reader, ref packetBuffer, ref packetLength);
				}

				if (_Successor != null)
				{
					_Successor.EncodeOutgoingPacket(to, ref packetBuffer, ref packetLength);
				}
			}
Example #21
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 ) )
				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 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.ReadBoolean();
            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 )
            {
                Console.WriteLine( cityIndex );
                Console.WriteLine( 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 = 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.BlockAllPackets = true;

                EventSink.InvokeCharacterCreated( args );

                Mobile m = args.Mobile;

                if ( m != null )
                {
                    state.Mobile = m;
                    m.NetState = state;

                    state.BlockAllPackets = false;
                    DoLogin( state, m );
                }
                else
                {
                    state.BlockAllPackets = false;
                    state.Dispose();
                }
            }
        }
Example #23
0
        public static void OldHeaderChange(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

            string title = pvSrc.ReadStringSafe(60);
            string author = pvSrc.ReadStringSafe(30);

            book.Title = Utility.FixHtml(title);
            book.Author = Utility.FixHtml(author);
        }
        public static void EquipReq( NetState state, PacketReader pvSrc )
        {
            Mobile from = state.Mobile;
            Item item = from.Holding;

            if ( item == null )
                return;

            from.Holding = null;

            pvSrc.Seek( 5, SeekOrigin.Current );
            Mobile to = World.FindMobile( pvSrc.ReadInt32() );

            if ( to == null )
                to = from;

            if ( !to.AllowEquipFrom( from ) || !to.EquipItem( item ) )
                item.Bounce( from );

            item.ClearBounce();
        }
		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();
				}
			}
		}
Example #26
0
        public static void EquipReq( NetState state, PacketReader pvSrc )
        {
            Mobile from = state.Mobile;

            // genova: support uo:kr
            if (from.NetState != null /*&& from.NetState.IsKRClient*/)
                from.NetState.Send(new KRDropConfirm());

            Item item = from.Holding;

            bool valid = ( item != null && item.HeldBy == from && item.Map == Map.Internal );

            from.Holding = null;

            if ( !valid ) {
                return;
            }

            pvSrc.Seek( 5, SeekOrigin.Current );
            Mobile to = World.FindMobile( pvSrc.ReadInt32() );

            if ( to == null )
                to = from;

            if ( !to.AllowEquipFrom( from ) || !to.EquipItem( item ) )
                item.Bounce( from );

            item.ClearBounce();
        }
		public static void DeleteCharacter( NetState state, PacketReader pvSrc )
		{
			pvSrc.Seek( 30, SeekOrigin.Current );
			int index = pvSrc.ReadInt32();

			EventSink.InvokeDeleteRequest( new DeleteRequestEventArgs( state, index ) );
		}
Example #28
0
        private static void OnAsciiPacket( NetState state, PacketReader pvSrc )
        {
            byte type = pvSrc.ReadByte();

            if ( type == 0x20 )
            {
                pvSrc.ReadInt16(); // hue
                pvSrc.ReadInt16(); // font

                StringBuilder cheat = new StringBuilder(), version = new StringBuilder();

                int pos = 0;

                /*
                'C'(43) 'H'(48) 'E'(45) 'A'(41) 'T'(54) ' '
                (20) 'U'(55) 'O'(4F) '.'(2E) 'e'(65) 'x'(78) 'e'(65) ' '(20)
                '1'(31) ' '(20)
                '0'(30) '-'(2D) '-'(2D) ''(0)
                '&'(26) '^'(5E) 'O'(D8) ''(1) ''(1F) 'c'(A9) ''(1A) ''(F9) 'a'(61) ''(7F) 'B'(42) '?'(99) 'E'(CA) ''(D0) '?'(8B) 'B'(42)
                '1'(31) '.'(2E) '0'(30) '.'(2E) '1'(31) '0'(30) ''(0)
                 */

                for (pos=0; pos < 128; )
                {
                    byte c = pvSrc.ReadByte();

                    c ^= m_Key[pos++ & 0xF];

                    if ( c == 0 )
                        break;

                    //Console.Write(String.Format("'{0}'({0:X}) ", c));

                    cheat.Append( (char)c ); // todo: better way to convert byte to char?
                }

                bool allZero = true;
                bool cryptValid = true;
                StringBuilder sum = new StringBuilder();
                for ( int i = 0; i < 16; i++ )
                {
                    byte c = pvSrc.ReadByte();

                    if ( c != 0 )
                        allZero = false;

                    c ^= m_Key[pos++ & 0xF];

                    sum.AppendFormat("{0:X} ", c);

                    cryptValid = cryptValid && c == CryptDLLChecksum[i];
                }

                if (!cryptValid && !allZero)
                {
                    try
                    {
                        sum.AppendFormat("\t{0}\t{1}", state.Mobile.Account, DateTime.Now);

                        using (StreamWriter sw = new StreamWriter("CryptSums.log", true))
                            sw.WriteLine(sum.ToString());
                    }
                    catch
                    {
                    }
                }

                for ( ; pos < 128; )
                {
                    byte c = pvSrc.ReadByte();

                    c ^= m_Key[pos++ & 0xF];

                    if (c == 0)
                        break;
                    version.Append( (char)c );
                }

                Version ver;

                try {
                    ver = new Version( version.ToString() );
                } catch {
                    ver = new Version( 0, 0, 0 );
                }

                /*Console.WriteLine( "Auth... String=\"{0}\"", cheat.ToString() );
                Console.WriteLine( "Valid={0} / allZero={1}", cryptValid, allZero );
                Console.WriteLine( "Version={0}", version.ToString() );*/

                /*int now = (int)(DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds;
                int timeStamp = pvSrc.ReadByte() | (pvSrc.ReadByte()<<8) | (pvSrc.ReadByte()<<16) | (pvSrc.ReadByte()<<24);
                timeStamp = ~timeStamp;
                timeStamp ^= 0x54494D45;

                int serverIP = pvSrc.ReadByte() | (pvSrc.ReadByte()<<8) | (pvSrc.ReadByte()<<16) | (pvSrc.ReadByte()<<24);
                serverIP = ~serverIP;
                serverIP ^= timeStamp;*/

                string val = cheat.ToString();

                string[] split = val.Split( ' ' );

                if ( split.Length >= 2 && split[0] == "CHEAT" )
                {
                    split[1] = split[1].ToUpper();

                    // this could be changed to only allow certain programs (EXPLORER.EXE, UO.EXE, UOG.EXE, etc) and block all others.

                    ClientValidity vd = m_Table[state] as ClientValidity;

                    if ( vd == null )
                        return;

                    vd.m_GotResp = true;

                    if ( split[1] == "RAZOR.EXE" )
                    {
                        vd.m_ClientType = ClientType.OldRazor;
                    }
                    else if ( split[1] == "INJECTION.EXE" || split[1] == "ILAUNCH.EXE" )
                    {
                        vd.m_ClientType = ClientType.Injection;
                    }
                    else if ( split[1] == "UO.EXE" ) // only new razor should report this.
                    {
                        //if ( Math.Abs( now - timeStamp ) > 60*60*15 ) // the packet is good for 15 hours only
                        //	vd.m_ClientType = ClientType.FakeRazor;
                        //else
                        if ( ver < CryptDLLVersion )
                            vd.m_ClientType = ClientType.OldRazor;
                        else
                            vd.m_ClientType = ClientType.NewRazor;

                        if ( !allZero && !cryptValid )
                        {
                            vd.m_TPHackedDLL = true;
                        }
                    }
                    else if ( split[1] == "EASYUO.EXE" || split[1] == "EUOX.EXE" || split[1] == "EUO.EXE" )
                    {
                        vd.m_ClientType = ClientType.EasyUO;
                    }
                    else if ( split[1] == "UOG.EXE" )
                    {
                        // UOG.EXE is an old razor user or a UOG only user
                    }
                    else if ( split[1] == "EXPLORER.EXE" || split[1] == "IEXPLORE.EXE" || split[1] == "CONNEC" || split[1] == "CONNECTUO.EXE" || split[1] == "CUODESKTOP.EXE" )
                    {
                        // these are launched from ConnectUO or by double clicking client.exe
                    }
                    else
                    {
                        try
                        {
                            string str = string.Format("{0} {1}", split[1], state.Account);
                            bool found = false;

                            for (int i = 0; i<m_Exes.Count;i++)
                            {
                                if (((string)m_Exes[i]) == str)
                                {
                                    found = true;
                                    break;
                                }
                            }

                            if ( !found )
                            {
                                m_Exes.Add( str );
                                using ( StreamWriter sw = new StreamWriter( "ExeNames.log", true ) )
                                    sw.WriteLine( "{0} {1}", str, DateTime.Now );
                            }
                        }
                        catch
                        {
                        }
                    }
                }
            }
            else
            {
                // seek back to the begining and call the default handler
                pvSrc.Seek( 3, SeekOrigin.Begin );
                PacketHandlers.AsciiSpeech( state, pvSrc );
            }
        }
Example #29
0
		public static string[] DecodePropertyList(this ObjectPropertyList list, ClilocLNG lng)
		{
			if (lng == ClilocLNG.NULL)
			{
				lng = DefaultLanguage;
			}

			int length;
			var data = list.Compile(false, out length);
			var msgs = new List<string>();

			var reader = new PacketReader(data, length, false);
			reader.Seek(15, SeekOrigin.Begin);

			for (int i = 15; i < data.Length - 4;)
			{
				int index = reader.ReadInt32();
				int paramLength = reader.ReadInt16() / 2;

				string param = String.Empty;

				if (paramLength > 0)
				{
					param = reader.ReadUnicodeStringLE(paramLength);
				}

				msgs.Add(GetString(lng, index, param));

				i += (6 + paramLength);
			}

			return msgs.ToArray();
		}
Example #30
0
        private static void OnEncode0xB0_0xDD(NetState state, PacketReader reader, ref byte[] buffer, ref int length)
        {
            if (state == null || reader == null || buffer == null || length < 0)
                return;

            int pos = reader.Seek(0, SeekOrigin.Current);
            reader.Seek(3, SeekOrigin.Begin);
            int serial = reader.ReadInt32();
            reader.Seek(pos, SeekOrigin.Begin);

            if (serial < 0 || !_InternalInstances.ContainsKey(serial))
                return;

            CompileCheckOnSend(serial);
        }