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 ) )
{
list[count] = address;
list[count] = Utility.Intern( address );
count++;
}
}
@ -881,10 +881,7 @@ namespace Server.Accounting
return false;
}
IPAddress ipAddress;
try { ipAddress = ( (IPEndPoint) ns.Socket.RemoteEndPoint ).Address; }
catch { return false; }
IPAddress ipAddress = ns.Address;
bool accessAllowed = ( m_IPRestrictions.Length == 0 || IPLimiter.IsExempt( ipAddress ) );

View file

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

View file

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

View file

@ -993,36 +993,6 @@ namespace Server.Commands
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" )]
[Description( "Saves the world." )]
private static void Save_OnCommand( CommandEventArgs e )

View file

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

View file

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

View file

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

View file

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

View file

@ -82,6 +82,27 @@ namespace Server
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 )
{
bool valid = true;