updated a few places to use NetState.Address rather than Socket.RemoteEndPoint.Address

added Utility.Intern(IPAddress) and implemented where appropriate
This commit is contained in:
krrios 2007-04-25 00:42:47 +00:00
parent 442b48d406
commit e15ed963d8
9 changed files with 29 additions and 43 deletions

View file

@ -740,7 +740,7 @@ namespace Server.Accounting
if( IPAddress.TryParse( Utility.GetText( ip, null ), out address ) ) if( IPAddress.TryParse( Utility.GetText( ip, null ), out address ) )
{ {
list[count] = address; list[count] = Utility.Intern( address );
count++; count++;
} }
} }
@ -881,10 +881,7 @@ namespace Server.Accounting
return false; return false;
} }
IPAddress ipAddress; IPAddress ipAddress = ns.Address;
try { ipAddress = ( (IPEndPoint) ns.Socket.RemoteEndPoint ).Address; }
catch { return false; }
bool accessAllowed = ( m_IPRestrictions.Length == 0 || IPLimiter.IsExempt( ipAddress ) ); bool accessAllowed = ( m_IPRestrictions.Length == 0 || IPLimiter.IsExempt( ipAddress ) );

View file

@ -120,7 +120,7 @@ namespace Server.Misc
try try
{ {
IPAddress ipAddress = ((IPEndPoint)ns.Socket.RemoteEndPoint).Address; IPAddress ipAddress = ns.Address;
if ( Utility.IPMatchClassC( accessList[0], ipAddress ) ) if ( Utility.IPMatchClassC( accessList[0], ipAddress ) )
{ {

View file

@ -956,7 +956,7 @@ namespace Server.Commands.Generic
try try
{ {
Firewall.Add( ((IPEndPoint)state.Socket.RemoteEndPoint).Address ); Firewall.Add( state.Address );
AddResponse( "They have been firewalled." ); AddResponse( "They have been firewalled." );
} }
catch ( Exception ex ) catch ( Exception ex )

View file

@ -993,36 +993,6 @@ namespace Server.Commands
e.Mobile.Target = new PickMoveTarget(); e.Mobile.Target = new PickMoveTarget();
} }
private class FirewallTarget : Target
{
public FirewallTarget() : base( -1, false, TargetFlags.None )
{
}
protected override void OnTarget( Mobile from, object targeted )
{
if ( targeted is Mobile )
{
Mobile targ = (Mobile)targeted;
NetState state = targ.NetState;
if ( state != null )
{
CommandLogging.WriteLine( from, "{0} {1} firewalling {2}", from.AccessLevel, CommandLogging.Format( from ), CommandLogging.Format( targeted ) );
try
{
Firewall.Add( ((IPEndPoint)state.Socket.RemoteEndPoint).Address );
}
catch
{
}
}
}
}
}
[Usage( "Save" )] [Usage( "Save" )]
[Description( "Saves the world." )] [Description( "Saves the world." )]
private static void Save_OnCommand( CommandEventArgs e ) private static void Save_OnCommand( CommandEventArgs e )

View file

@ -459,7 +459,7 @@ namespace Server.Factions
case 0: case 0:
{ {
m_From = reader.ReadMobile(); m_From = reader.ReadMobile();
m_Address = reader.ReadIPAddress(); m_Address = Utility.Intern( reader.ReadIPAddress() );
m_Time = reader.ReadDateTime(); m_Time = reader.ReadDateTime();
break; break;

View file

@ -74,9 +74,7 @@ namespace Server.Misc
private static bool IsLocalMachine( NetState state ) private static bool IsLocalMachine( NetState state )
{ {
Socket sock = state.Socket; IPAddress theirAddress = state.Address;
IPAddress theirAddress = ((IPEndPoint)sock.RemoteEndPoint).Address;
if ( IPAddress.IsLoopback( theirAddress ) ) if ( IPAddress.IsLoopback( theirAddress ) )
return true; return true;

View file

@ -377,7 +377,7 @@ namespace Server.Misc
m_Voters = new IPAddress[reader.ReadInt()]; m_Voters = new IPAddress[reader.ReadInt()];
for ( int i = 0; i < m_Voters.Length; ++i ) for ( int i = 0; i < m_Voters.Length; ++i )
m_Voters[i] = reader.ReadIPAddress(); m_Voters[i] = Utility.Intern( reader.ReadIPAddress() );
break; break;
} }

View file

@ -515,7 +515,7 @@ namespace Server.Network {
m_Instances.Add( this ); m_Instances.Add( this );
try { try {
m_Address = ( ( IPEndPoint ) m_Socket.RemoteEndPoint ).Address; m_Address = Utility.Intern( ( ( IPEndPoint ) m_Socket.RemoteEndPoint ).Address );
m_ToString = m_Address.ToString(); m_ToString = m_Address.ToString();
} catch { } catch {
m_Address = IPAddress.None; m_Address = IPAddress.None;

View file

@ -82,6 +82,27 @@ namespace Server
str = Intern( str ); str = Intern( str );
} }
private static Dictionary<IPAddress, IPAddress> _ipAddressTable;
public static IPAddress Intern( IPAddress ipAddress ) {
if ( _ipAddressTable == null ) {
_ipAddressTable = new Dictionary<IPAddress, IPAddress>();
}
IPAddress interned;
if ( !_ipAddressTable.TryGetValue( ipAddress, out interned ) ) {
interned = ipAddress;
_ipAddressTable[ipAddress] = interned;
}
return interned;
}
public static void Intern( ref IPAddress ipAddress ) {
ipAddress = Intern( ipAddress );
}
public static bool IsValidIP( string text ) public static bool IsValidIP( string text )
{ {
bool valid = true; bool valid = true;