Server.Gumps.BanDurationGump.OnResponse C# (CSharp) Méthode

OnResponse() public méthode

public OnResponse ( Server sender, RelayInfo info ) : void
sender Server
info RelayInfo
Résultat void
		public override void OnResponse( Server.Network.NetState sender, RelayInfo info )
		{
			Mobile from = sender.Mobile;

			if ( from.AccessLevel < AccessLevel.Administrator )
				return;

			TextRelay d = info.GetTextEntry( 0 );
			TextRelay h = info.GetTextEntry( 1 );
			TextRelay m = info.GetTextEntry( 2 );
			TextRelay s = info.GetTextEntry( 3 );

			TextRelay c = info.GetTextEntry( 10 );

			TimeSpan duration;
			bool shouldSet;

			string fromString = from.ToString();

			switch ( info.ButtonID )
			{
				case 0:
				{
					for ( int i = 0; i < m_List.Count; ++i )
					{
						Account a = (Account)m_List[i];

						a.SetUnspecifiedBan( from );
					}

					from.SendMessage( "Duration unspecified." );
					return;
				}
				case 1: // infinite
				{
					duration = TimeSpan.MaxValue;
					shouldSet = true;
					break;
				}
				case 2: // From D:H:M:S
				{
					if ( d != null && h != null && m != null && s != null )
					{
						try
						{
							duration = new TimeSpan( Utility.ToInt32( d.Text ), Utility.ToInt32( h.Text ), Utility.ToInt32( m.Text ), Utility.ToInt32( s.Text ) );
							shouldSet = true;

							break;
						}
						catch
						{
						}
					}

					duration = TimeSpan.Zero;
					shouldSet = false;

					break;
				}
				case 3: // From D
				{
					if ( d != null )
					{
						try
						{
							duration = TimeSpan.FromDays( Utility.ToDouble( d.Text ) );
							shouldSet = true;

							break;
						}
						catch
						{
						}
					}

					duration = TimeSpan.Zero;
					shouldSet = false;

					break;
				}
				case 4: // From H
				{
					if ( h != null )
					{
						try
						{
							duration = TimeSpan.FromHours( Utility.ToDouble( h.Text ) );
							shouldSet = true;

							break;
						}
						catch
						{
						}
					}

					duration = TimeSpan.Zero;
					shouldSet = false;

					break;
				}
				case 5: // From M
				{
					if ( m != null )
					{
						try
						{
							duration = TimeSpan.FromMinutes( Utility.ToDouble( m.Text ) );
							shouldSet = true;

							break;
						}
						catch
						{
						}
					}

					duration = TimeSpan.Zero;
					shouldSet = false;

					break;
				}
				case 6: // From S
				{
					if ( s != null )
					{
						try
						{
							duration = TimeSpan.FromSeconds( Utility.ToDouble( s.Text ) );
							shouldSet = true;

							break;
						}
						catch
						{
						}
					}

					duration = TimeSpan.Zero;
					shouldSet = false;

					break;
				}
				default: return;
			}

			if ( shouldSet ) {
				string comment = null;
				
				if ( c != null ) {
					comment = c.Text.Trim();

					if ( comment.Length == 0 )
						comment = null;
				}

				for ( int i = 0; i < m_List.Count; ++i )
				{
					Account a = (Account)m_List[i];

					a.SetBanTags( from, DateTime.Now, duration );

					if ( comment != null )
						a.Comments.Add( new AccountComment( from.RawName, String.Format( "Duration: {0}, Comment: {1}", (( duration == TimeSpan.MaxValue )? "Infinite" : duration.ToString()), comment ) ) );
				}

				if ( duration == TimeSpan.MaxValue )
					from.SendMessage( "Ban Duration: Infinite" );
				else
					from.SendMessage( "Ban Duration: {0}", duration );
			}
			else
			{
				from.SendMessage( "Time values were improperly formatted." );
				from.SendGump( new BanDurationGump( m_List ) );
			}
		}
	}