ReadString() public method

public ReadString ( ) : string
return string
        private static void BountyEntryResponse( NetState ns, PacketReader pvSrc )
        {
            Mobile from = ns.Mobile;
            if ( from == null )
                return;
            Mobile killer = World.FindMobile( (Serial)pvSrc.ReadInt32() );
            byte typeid = pvSrc.ReadByte();
            byte index = pvSrc.ReadByte();
            bool cancel = pvSrc.ReadByte() == 0;
            short responseLen = pvSrc.ReadInt16();
            string resp = pvSrc.ReadString();

            if ( killer != null && !cancel )
            {
                int bounty = Utility.ToInt32( resp );
                if ( bounty > 5000 )
                    bounty = 5000;
                bounty = from.BankBox.ConsumeUpTo( typeof( Gold ), bounty, true );

                killer.Kills++;
                if ( killer is PlayerMobile && bounty > 0 )
                {
                    PlayerMobile kpm = (PlayerMobile)killer;
                    kpm.Bounty += bounty;
                    killer.SendAsciiMessage( "{0} has placed a bounty of {1}gp on your head!", from.Name, bounty );
                    if ( kpm.Bounty >= 5000 && kpm.Kills > 1 && kpm.BankBox.Items.Count > 0 && kpm.Karma <= (int)Noto.Dark )
                    {
                        killer.SayTo( killer, true, "A bounty hath been issued for thee, and thy worldly goods are hereby confiscated!" );
                        kpm.Bounty += EmptyAndGetGold( killer.BankBox.Items );
                    }
                }
            }

            SendNext( from );
        }
Example #2
0
        public static void Authenticate( NetState state, PacketReader pvSrc )
        {
            string user = pvSrc.ReadString( 30 );
            string pw = pvSrc.ReadString( 30 );

            Account a = Accounts.GetAccount( user );
            if ( a == null )
            {
                state.Send( new Login( LoginResponse.NoUser ) );
                log.Warn(String.Format("ADMIN: Invalid username '{0}' from {1}",
                                       user, state));
                DelayedDisconnect( state );
            }
            else if ( !a.HasAccess( state ) )
            {
                state.Send( new Login( LoginResponse.BadIP ) );
                log.Warn(String.Format("ADMIN: Access to '{0}' from {1} denied.",
                                       user, state));
                DelayedDisconnect( state );
            }
            else if ( !a.CheckPassword( pw ) )
            {
                state.Send( new Login( LoginResponse.BadPass ) );
                log.Warn(String.Format("ADMIN: Invalid password '{0}' for user '{1}' from {2}",
                                       pw, user, state));
                DelayedDisconnect( state );
            }
            else if ( a.AccessLevel != AccessLevel.Administrator || a.Banned )
            {
                log.Warn(String.Format("ADMIN: Account '{0}' does not have admin access. Connection Denied.",
                                       user));
                state.Send( new Login( LoginResponse.NoAccess ) );
                DelayedDisconnect( state );
            }
            else
            {
                log.Warn(String.Format("ADMIN: Access granted to '{0}' from {1}",
                                       user, state));
                state.Account = a;
                a.LogAccess( state );
                a.LastLogin = DateTime.Now;

                state.Send( new Login( LoginResponse.OK ) );
                state.Send( Compress( new ConsoleData( m_ConsoleData.ToString() ) ) );
                m_Auth.Add( state );
            }
        }
Example #3
0
        private static void AccountSearch(NetState state, PacketReader pvSrc)
        {
            AcctSearchType type = (AcctSearchType)pvSrc.ReadByte();
            string term = pvSrc.ReadString();

            if (type == AcctSearchType.IP && !Utility.IsValidIP(term))
            {
                state.Send(new MessageBoxMessage("Invalid search term.\nThe IP sent was not valid.", "Invalid IP"));
                return;
            }
            else
            {
                term = term.ToUpper();
            }

            ArrayList list = new ArrayList();

            foreach (Account a in Accounts.GetAccounts())
            {
                if (!CanAccessAccount(state.Account, a))
                    continue;

                switch ( type )
                {
                    case AcctSearchType.Username:
                        {
                            if (a.Username.ToUpper().IndexOf(term) != -1)
                                list.Add(a);
                            break;
                        }
                    case AcctSearchType.IP:
                        {
                            for (int i = 0; i < a.LoginIPs.Length; i++)
                            {
                                if (Utility.IPMatch(term, a.LoginIPs[i]))
                                {
                                    list.Add(a);
                                    break;
                                }
                            }
                            break;
                        }
                }
            }

            if (list.Count > 0)
            {
                if (list.Count <= 25)
                    state.Send(AdminNetwork.Compress(new AccountSearchResults(list)));
                else
                    state.Send(new MessageBoxMessage("There were more than 25 matches to your search.\nNarrow the search parameters and try again.", "Too Many Results"));
            }
            else
            {
                state.Send(new MessageBoxMessage("There were no results to your search.\nPlease try again.", "No Matches"));
            }
        }
		public static void AssistVersion( NetState state, PacketReader pvSrc )
		{
			int unk = pvSrc.ReadInt32();
			string av = pvSrc.ReadString();
		}
		public static void ClientVersion( NetState state, PacketReader pvSrc )
		{
			CV version = state.Version = new CV( pvSrc.ReadString() );

			EventSink.InvokeClientVersionReceived( new ClientVersionReceivedArgs( state, version ) );
		}
		public static void AccountLogin( NetState state, PacketReader pvSrc )
		{
			if ( state.SentFirstPacket )
			{
				state.Dispose();
				return;
			}

			state.SentFirstPacket = true;

			string username = pvSrc.ReadString( 30 );
			string password = pvSrc.ReadString( 30 );

			AccountLoginEventArgs e = new AccountLoginEventArgs( state, username, password );

			try {
				EventSink.InvokeAccountLogin(e);
			} catch (Exception ex) {
				log.Fatal(String.Format("Exception disarmed in AccountLogin {0}",
										username), ex);
			}

			if (e.Accepted && Core.Config.Features["quick-local-connect"]) {
				/* we have to remember username+password, because it
				   is required to emulate a GameLogin packet */
				state.Username = username;
				state.Password = password;
			}

			if ( e.Accepted )
				AccountLogin_ReplyAck( state );
			else
				AccountLogin_ReplyRej( state, e.RejectReason );
		}
		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 AccountLogin( NetState state, PacketReader pvSrc )
		{
			if ( state.SentFirstPacket )
			{
				state.Dispose();
				return;
			}

			state.SentFirstPacket = true;

			string username = pvSrc.ReadString( 30 );
			string password = pvSrc.ReadString( 30 );

			AccountLoginEventArgs e = new AccountLoginEventArgs( state, username, password );

			EventSink.InvokeAccountLogin( e );

			if ( e.Accepted )
				AccountLogin_ReplyAck( state );
			else
				AccountLogin_ReplyRej( state, e.RejectReason );
		}
		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 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;
				}
			}
		}
		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 TextCommand( NetState state, PacketReader pvSrc )
		{
			int type = pvSrc.ReadByte();
			string command = pvSrc.ReadString();

			Mobile m = state.Mobile;

			switch ( type )
			{
				case 0x00: // Go
				{
					if ( VerifyGC( state ) )
					{
						try
						{
							string[] split = command.Split( ' ' );

							int x = Utility.ToInt32( split[0] );
							int y = Utility.ToInt32( split[1] );

							int z;

							if ( split.Length >= 3 )
								z = Utility.ToInt32( split[2] );
							else if ( m.Map != null )
								z = m.Map.GetAverageZ( x, y );
							else
								z = 0;

							m.Location = new Point3D( x, y, z );
						}
						catch
						{
						}
					}

					break;
				}
				case 0xC7: // Animate
				{
					EventSink.InvokeAnimateRequest( new AnimateRequestEventArgs( m, command ) );

					break;
				}
				case 0x24: // Use skill
				{
					int skillIndex;

					try{ skillIndex = Convert.ToInt32( command.Split( ' ' )[0] ); }
					catch{ break; }

					try {
						Skills.UseSkill( m, skillIndex );
					} catch (Exception e) {
						log.Fatal(String.Format("Exception disarmed in UseSkill {0} > {1}",
												state.Mobile, skillIndex), e);
					}

					break;
				}
				case 0x43: // Open spellbook
				{
					int booktype;

					try{ booktype = Convert.ToInt32( command ); }
					catch{ booktype = 1; }

					EventSink.InvokeOpenSpellbookRequest( new OpenSpellbookRequestEventArgs( m, booktype ) );

					break;
				}
				case 0x27: // Cast spell from book
				{
					string[] split = command.Split( ' ' );

					if ( split.Length > 0 )
					{
						int spellID = Utility.ToInt32( split[0] ) - 1;
						int serial = split.Length > 1 ? Utility.ToInt32( split[1] ) : -1;

						try {
							EventSink.InvokeCastSpellRequest( new CastSpellRequestEventArgs( m, spellID, World.FindItem( serial ) ) );
						} catch (Exception e) {
							log.Fatal(String.Format("Exception disarmed in CastSpell I {0}, spell {1}",
													state.Mobile, spellID), e);
						}
					}

					break;
				}
				case 0x58: // Open door
				{
					try {
						EventSink.InvokeOpenDoorMacroUsed( new OpenDoorMacroEventArgs( m ) );
					} catch (Exception e) {
						log.Fatal(String.Format("Exception disarmed in OpenDoor {0}",
												state.Mobile), e);
					}

					break;
				}
				case 0x56: // Cast spell from macro
				{
					int spellID = Utility.ToInt32( command ) - 1;

					try {
						EventSink.InvokeCastSpellRequest( new CastSpellRequestEventArgs( m, spellID, null ) );
					} catch (Exception e) {
						log.Fatal(String.Format("Exception disarmed in CastSpell II {0}, spell {1}",
												state.Mobile, spellID), e);
					}

					break;
				}
				default:
				{
					log.WarnFormat("Client: {0}: Unknown text-command type 0x{1:X2}: {2}",
								   state, type, command);
					break;
				}
			}
		}
		public static void UnicodePromptResponse( NetState state, PacketReader pvSrc )
		{
			int serial = pvSrc.ReadInt32();
			int prompt = pvSrc.ReadInt32();
			int type = pvSrc.ReadInt32();
			/*string lang = */pvSrc.ReadString( 4 );
			string text = pvSrc.ReadUnicodeStringLESafe();

			if ( text.Length > 128 )
				return;

			Mobile from = state.Mobile;
			Prompt p = from.Prompt;

			if ( p != null && p.Serial == serial && p.Serial == prompt )
			{
				from.Prompt = null;

				try {
					if ( type == 0 )
						p.OnCancel( from );
					else
						p.OnResponse( from, text );
				} catch (Exception e) {
					log.Fatal(String.Format("Exception disarmed in UnicodePrompt response {0}, type {1}",
											state.Mobile, type), e);
				}
			}
		}
		public static void NewRegion( NetState state, PacketReader pvSrc )
		{
			if ( VerifyGC( state ) )
			{
				string name = pvSrc.ReadString( 40 );
				/*int unk = */pvSrc.ReadInt32();
				/*int x = */pvSrc.ReadInt16();
				/*int y = */pvSrc.ReadInt16();
				/*int width = */pvSrc.ReadInt16();
				/*int height = */pvSrc.ReadInt16();
				/*int zStart = */pvSrc.ReadInt16();
				/*int zEnd = */pvSrc.ReadInt16();
				string desc = pvSrc.ReadString( 40 );
				/*int soundFX = */pvSrc.ReadInt16();
				/*int music = */pvSrc.ReadInt16();
				/*int nightFX = */pvSrc.ReadInt16();
				/*int dungeon = */pvSrc.ReadByte();
				/*int light = */pvSrc.ReadInt16();

				log.InfoFormat("God Client: {0}: New Region '{1}' ('{2}')",
							   state, name, desc);
			}
		}
		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();
		}
		private static void OnAddAuthID( NetState state, PacketReader pvSrc ) {
			if (!state.Super) {
				log.WarnFormat("Client {0} attempted to inject an AuthID",
							   state);
				state.Dispose(false);
				return;
			}

			int authID = pvSrc.ReadInt32();
			/*String username =*/ pvSrc.ReadString(30);
			AddAuthID(authID);

			state.Send(new AddAuthIDAck(authID));
		}
		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
		}
Example #18
0
        private static void RemoveAccount(NetState state, PacketReader pvSrc)
        {
            if (state.Account.AccessLevel < AccessLevel.Administrator)
            {
                state.Send(new MessageBoxMessage("You do not have permission to delete accounts.", "Account Access Exception"));
                return;
            }

            IAccount a = Accounts.GetAccount(pvSrc.ReadString());

            if (a == null)
            {
                state.Send(new MessageBoxMessage("The account could not be found (and thus was not deleted).", "Account Not Found"));
            }
            else if (!CanAccessAccount(state.Account, a))
            {
                state.Send(new MessageBoxMessage("You cannot delete an account with an access level greater than or equal to your own.", "Account Access Exception"));
            }
            else if (a == state.Account)
            {
                state.Send(new MessageBoxMessage("You may not delete your own account.", "Not Allowed"));
            }
            else
            {
                RemoteAdminLogging.WriteLine(state, "Deleted Account {0}", a);
                a.Delete();
                state.Send(new MessageBoxMessage("The requested account (and all it's characters) has been deleted.", "Account Deleted"));
            }
        }
		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 #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 GameLogin( NetState state, PacketReader pvSrc )
		{
			if ( state.SentFirstPacket )
			{
				state.Dispose();
				return;
			}

			state.SentFirstPacket = true;

			int authID = pvSrc.ReadInt32();

			if ( m_AuthIDWindow.ContainsKey( authID ) ) {
				AuthIDPersistence ap = m_AuthIDWindow[authID];
				m_AuthIDWindow.Remove( authID );

				state.Version = ap.Version;
			} else if ( m_ClientVerification ) {
				Console.WriteLine( "Login: {0}: Invalid client detected, disconnecting", state );
				state.Dispose();
				return;
			}
			
			if ( state.m_AuthID != 0 && authID != state.m_AuthID )
			{
				Console.WriteLine( "Login: {0}: Invalid client detected, disconnecting", state );
				state.Dispose();
				return;
			}
			else if ( state.m_AuthID == 0 && authID != state.m_Seed )
			{
				Console.WriteLine( "Login: {0}: Invalid client detected, disconnecting", state );
				state.Dispose();
				return;
			}

			string username = pvSrc.ReadString( 30 );
			string password = pvSrc.ReadString( 30 );

			GameLoginEventArgs e = new GameLoginEventArgs( state, username, password );

			EventSink.InvokeGameLogin( e );

			if ( e.Accepted )
			{
				state.CityInfo = e.CityInfo;
				state.CompressionEnabled = true;

				state.Send( SupportedFeatures.Instantiate( state ) );

				if ( state.NewCharacterList ) {
					state.Send( new CharacterList( state.Account, state.CityInfo ) );
				} else {
					state.Send( new CharacterListOld( state.Account, state.CityInfo ) );
				}
			}
			else
			{
				state.Dispose();
			}
		}
		public static void TextCommand( NetState state, PacketReader pvSrc )
		{
			int type = pvSrc.ReadByte();
			string command = pvSrc.ReadString();

			Mobile m = state.Mobile;

			switch ( type )
			{
				case 0x00: // Go
				{
					if ( VerifyGC( state ) )
					{
						try
						{
							string[] split = command.Split( ' ' );

							int x = Utility.ToInt32( split[0] );
							int y = Utility.ToInt32( split[1] );

							int z;

							if ( split.Length >= 3 )
								z = Utility.ToInt32( split[2] );
							else if ( m.Map != null )
								z = m.Map.GetAverageZ( x, y );
							else
								z = 0;

							m.Location = new Point3D( x, y, z );
						}
						catch
						{
						}
					}

					break;
				}
				case 0xC7: // Animate
				{
					EventSink.InvokeAnimateRequest( new AnimateRequestEventArgs( m, command ) );

					break;
				}
				case 0x24: // Use skill
				{
					int skillIndex;

					if ( !int.TryParse( command.Split( ' ' )[0], out skillIndex ) )
						break;

					Skills.UseSkill( m, skillIndex );

					break;
				}
				case 0x43: // Open spellbook
				{
					int booktype;

					if ( !int.TryParse( command, out booktype ) )
						booktype = 1;

					EventSink.InvokeOpenSpellbookRequest( new OpenSpellbookRequestEventArgs( m, booktype ) );

					break;
				}
				case 0x27: // Cast spell from book
				{
					string[] split = command.Split( ' ' );

					if ( split.Length > 0 )
					{
						int spellID = Utility.ToInt32( split[0] ) - 1;
						int serial = split.Length > 1 ? Utility.ToInt32( split[1] ) : -1;

						EventSink.InvokeCastSpellRequest( new CastSpellRequestEventArgs( m, spellID, World.FindItem( serial ) ) );
					}

					break;
				}
				case 0x58: // Open door
				{
					EventSink.InvokeOpenDoorMacroUsed( new OpenDoorMacroEventArgs( m ) );

					break;
				}
				case 0x56: // Cast spell from macro
				{
					int spellID = Utility.ToInt32( command ) - 1;

					EventSink.InvokeCastSpellRequest( new CastSpellRequestEventArgs( m, spellID, null ) );

					break;
				}
				case 0xF4: // Invoke virtues from macro
				{
					int virtueID = Utility.ToInt32( command ) - 1;

					EventSink.InvokeVirtueMacroRequest( new VirtueMacroRequestEventArgs( m, virtueID ) );

					break;
				}
				case 0x2F: // Old scroll double click
				{
					/*
					 * This command is still sent for items 0xEF3 - 0xEF9
					 *
					 * Command is one of three, depending on the item ID of the scroll:
					 * - [scroll serial]
					 * - [scroll serial] [target serial]
					 * - [scroll serial] [x] [y] [z]
					 */
					break;
				}
				default:
				{
					Console.WriteLine( "Client: {0}: Unknown text-command type 0x{1:X2}: {2}", state, type, command );
					break;
				}
			}
		}
		public static void ObjectHelpRequest( NetState state, PacketReader pvSrc )
		{
			Mobile from = state.Mobile;

			Serial serial = pvSrc.ReadInt32();
			int unk = pvSrc.ReadByte();
			string lang = pvSrc.ReadString( 3 );

			if ( serial.IsItem )
			{
				Item item = World.FindItem( serial );

				if ( item != null && from.Map == item.Map && Utility.InUpdateRange( item.GetWorldLocation(), from.Location ) && from.CanSee( item ) )
					item.OnHelpRequest( from );
			}
			else if ( serial.IsMobile )
			{
				Mobile m = World.FindMobile( serial );

				if ( m != null && from.Map == m.Map && Utility.InUpdateRange( m.Location, from.Location ) && from.CanSee( m ) )
					m.OnHelpRequest( m );
			}
		}
		private static void RemoveAccount( NetState state, PacketReader pvSrc )
		{
			Account a = Accounts.GetAccount( pvSrc.ReadString() );

			if ( a == null )
			{
				state.Send( new MessageBoxMessage( "The account could not be found (and thus was not deleted).", "Account Not Found" ) );
			}
			else if ( a == state.Account )
			{
				state.Send( new MessageBoxMessage( "You may not delete your own account.", "Not Allowed" ) );
			}
			else
			{
				for (int i=0;i<a.Length;i++)
				{
					if ( a[i] != null )
						a[i].Delete();
				}

				Accounts.Table.Remove( a.Username );
				state.Send( new MessageBoxMessage( "The requested account (and all it's characters) has been deleted.", "Account Deleted" ) );
			}
		}
		public static void NewRegion( NetState state, PacketReader pvSrc )
		{
			if ( VerifyGC( state ) )
			{
				string name = pvSrc.ReadString( 40 );
				int unk = pvSrc.ReadInt32();
				int x = pvSrc.ReadInt16();
				int y = pvSrc.ReadInt16();
				int width = pvSrc.ReadInt16();
				int height = pvSrc.ReadInt16();
				int zStart = pvSrc.ReadInt16();
				int zEnd = pvSrc.ReadInt16();
				string desc = pvSrc.ReadString( 40 );
				int soundFX = pvSrc.ReadInt16();
				int music = pvSrc.ReadInt16();
				int nightFX = pvSrc.ReadInt16();
				int dungeon = pvSrc.ReadByte();
				int light = pvSrc.ReadInt16();

				Console.WriteLine( "God Client: {0}: New Region '{1}' ('{2}')", state, name, desc );
			}
		}
		public static void GameLogin( NetState state, PacketReader pvSrc )
		{
			if ( state.SentFirstPacket )
			{
				state.Dispose();
				return;
			}

			state.SentFirstPacket = true;

			int authID = pvSrc.ReadInt32();

			if (Core.Config.Login.IgnoreAuthID)
				AddAuthID(authID);

			if ( !IsValidAuthID( authID ) )
			{
				log.WarnFormat("Login: {0}: Invalid client detected, disconnecting", state);
				state.Dispose();
				return;
			}
			else if ( state.m_AuthID != 0 && authID != state.m_AuthID )
			{
				log.WarnFormat("Login: {0}: Invalid client detected, disconnecting", state);
				state.Dispose();
				return;
			}
			else if ( state.m_AuthID == 0 && authID != state.m_Seed )
			{
				log.WarnFormat("Login: {0}: Invalid client detected, disconnecting", state);
				state.Dispose();
				return;
			}

			string username = pvSrc.ReadString( 30 );
			string password = pvSrc.ReadString( 30 );

			GameLoginInternal(state, username, password, true);
		}
		public static void UnicodePromptResponse( NetState state, PacketReader pvSrc )
		{
			int serial = pvSrc.ReadInt32();
			int prompt = pvSrc.ReadInt32();
			int type = pvSrc.ReadInt32();
			string lang = pvSrc.ReadString( 4 );
			string text = pvSrc.ReadUnicodeStringLESafe();

			if ( text.Length > 128 )
				return;

			Mobile from = state.Mobile;
			Prompt p = from.Prompt;

			if ( p != null && p.Serial == serial && p.Serial == prompt )
			{
				from.Prompt = null;

				if ( type == 0 )
					p.OnCancel( from );
				else
					p.OnResponse( from, text );
			}
		}
		public static void UnicodeSpeech( NetState state, PacketReader pvSrc )
		{
			Mobile from = state.Mobile;

			MessageType type = (MessageType)pvSrc.ReadByte();
			int hue = pvSrc.ReadInt16();
			pvSrc.ReadInt16(); // font
			string lang = pvSrc.ReadString( 4 );
			string text;

			bool isEncoded = (type & MessageType.Encoded) != 0;
			int[] keywords;

			if ( isEncoded )
			{
				int value = pvSrc.ReadInt16();
				int count = (value & 0xFFF0) >> 4;
				int hold = value & 0xF;

				if ( count < 0 || count > 50 )
					return;

				KeywordList keyList = m_KeywordList;

				for ( int i = 0; i < count; ++i )
				{
					int speechID;

					if ( (i & 1) == 0 )
					{
						hold <<= 8;
						hold |= pvSrc.ReadByte();
						speechID = hold;
						hold = 0;
					}
					else
					{
						value = pvSrc.ReadInt16();
						speechID = (value & 0xFFF0) >> 4;
						hold = value & 0xF;
					}

					if ( !keyList.Contains( speechID ) )
						keyList.Add( speechID );
				}

				text = pvSrc.ReadUTF8StringSafe();

				keywords = keyList.ToArray();
			}
			else
			{
				text = pvSrc.ReadUnicodeStringSafe();

				keywords = m_EmptyInts;
			}

			text = text.Trim();

			if ( text.Length <= 0 || text.Length > 128 )
				return;

			type &= ~MessageType.Encoded;

			if ( !Enum.IsDefined( typeof( MessageType ), type ) )
				type = MessageType.Regular;

			from.Language = lang;
			from.DoSpeech( text, keywords, type, Utility.ClipDyedHue( hue ) );
		}
		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 Language( NetState state, PacketReader pvSrc )
		{
			string lang = pvSrc.ReadString( 4 );

			if ( state.Mobile != null )
				state.Mobile.Language = lang;
		}