generics, cleanups

This commit is contained in:
mark 2006-06-24 19:53:26 +00:00
parent 6fcfced3fa
commit 071898373e
5 changed files with 58 additions and 76 deletions

View file

@ -909,12 +909,10 @@ namespace Server.Accounting
return;
if ( m_LoginIPs.Length == 0 )
{
if ( AccountHandler.IPTables[ipAddress] == null )
AccountHandler.IPTables[ipAddress] = 1;
if ( AccountHandler.IPTable.ContainsKey( ipAddress ) )
AccountHandler.IPTable[ipAddress]++;
else
AccountHandler.IPTables[ipAddress] = (int) AccountHandler.IPTables[ipAddress] + 1;
}
AccountHandler.IPTable[ipAddress] = 1;
bool contains = false;

View file

@ -1,12 +1,12 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Net;
using Server;
using Server.Network;
using Server.Accounting;
using Server.Engines.Help;
using System.Collections;
using Server.Commands;
using Server.Engines.Help;
using Server.Network;
namespace Server.Misc
{
@ -205,45 +205,35 @@ namespace Server.Misc
public static bool CanCreate( IPAddress ip )
{
if ( IPTables[ip] == null ) //Sanity
if ( !IPTable.ContainsKey( ip ) )
return true;
return ((int)IPTables[ip] < MaxAccountsPerIP);
/*
if ( (int)IPTables[ip] >= MaxAccountsPerIP )
return false;
else
return true;
*/
return ( IPTable[ip] < MaxAccountsPerIP );
}
private static Hashtable m_IPTables;
private static Dictionary<IPAddress, Int32> m_IPTable;
public static Hashtable IPTables
public static Dictionary<IPAddress, Int32> IPTable
{
get
{
if ( m_IPTables == null )
if ( m_IPTable == null )
{
m_IPTables = new Hashtable();
m_IPTable = new Dictionary<IPAddress, Int32>();
foreach ( Account a in Accounts.GetAccounts() )
{
if ( a.LoginIPs.Length > 0 )
{
IPAddress ip = a.LoginIPs[0];
if ( m_IPTables[ip] == null )
m_IPTables[ip] = 1;
if ( m_IPTable.ContainsKey( ip ) )
m_IPTable[ip]++;
else
m_IPTables[ip] = (int)m_IPTables[ip] + 1;
m_IPTable[ip] = 1;
}
}
}
return m_IPTables;
return m_IPTable;
}
}
@ -299,7 +289,7 @@ namespace Server.Misc
if ( acct == null )
{
if ( AutoAccountCreation && un.Trim().Length > 0 ) //To prevent someone from mkaing an account of just '' or a bunch of meaningless spaces
if ( AutoAccountCreation && un.Trim().Length > 0 ) //To prevent someone from making an account of just '' or a bunch of meaningless spaces
{
e.State.Account = acct = CreateAccount( e.State, un, pw );
e.Accepted = acct == null ? false : acct.CheckAccess( e.State );

View file

@ -1,5 +1,5 @@
using System;
using System.Collections;
using System.Collections.Generic;
using Server;
using Server.Items;
using Server.Mobiles;
@ -165,17 +165,15 @@ namespace Server.Spells
m.CheckSkill( MoveSkill, RequiredSkill, RequiredSkill + 37.5 );
}
private static Hashtable m_Table = new Hashtable();
private static Dictionary<Mobile, SpecialMove> m_Table = new Dictionary<Mobile, SpecialMove>();
public static Hashtable Table{ get{ return m_Table; } }
public static Dictionary<Mobile, SpecialMove> Table{ get{ return m_Table; } }
public static void ClearAllMoves( Mobile m )
{
foreach ( DictionaryEntry de in SpellRegistry.SpecialMoves )
foreach ( KeyValuePair<Int32, SpecialMove> kvp in SpellRegistry.SpecialMoves )
{
SpecialMove move = (SpecialMove)de.Value;
int moveID = SpellRegistry.GetRegistryNumber( move );
int moveID = kvp.Key;
if ( moveID != -1 )
m.Send( new ToggleSpecialAbility( moveID + 1, false ) );
@ -195,7 +193,8 @@ namespace Server.Spells
return null;
}
SpecialMove move = (SpecialMove)m_Table[m];
SpecialMove move = null;
m_Table.TryGetValue( m, out move );
if ( move != null && move.ValidatesDuringHit && !move.Validate( m ) )
{
@ -248,7 +247,8 @@ namespace Server.Spells
public static void ClearCurrentMove( Mobile m )
{
SpecialMove move = (SpecialMove)m_Table[m];
SpecialMove move = null;
m_Table.TryGetValue( m, out move );
if ( move != null )
{
@ -268,7 +268,7 @@ namespace Server.Spells
}
private static Hashtable m_PlayersTable = new Hashtable();
private static Dictionary<Mobile, SpecialMoveContext> m_PlayersTable = new Dictionary<Mobile, SpecialMoveContext>();
private static void AddContext( Mobile m, SpecialMoveContext context )
{
@ -289,12 +289,13 @@ namespace Server.Spells
private static SpecialMoveContext GetContext( Mobile m )
{
return ( m_PlayersTable[m] as SpecialMoveContext );
return ( m_PlayersTable.ContainsKey( m ) ? m_PlayersTable[m] : null );
}
public static bool GetContext( Mobile m, Type type )
{
SpecialMoveContext context = m_PlayersTable[m] as SpecialMoveContext;
SpecialMoveContext context = null;
m_PlayersTable.TryGetValue( m, out context );
if ( context == null )
return false;

View file

@ -1,10 +1,10 @@
using System;
using System.Collections.Generic;
using System.IO;
using Server.Items;
using System.Collections;
using Server.Spells.Necromancy;
using Server.Spells.Chivalry;
using Server.Spells.Bushido;
using Server.Spells.Chivalry;
using Server.Items;
using Server.Spells.Necromancy;
using Server.Spells.Ninjitsu;
namespace Server.Spells
@ -33,16 +33,19 @@ namespace Server.Spells
m_Count = 0;
for ( int i = 0; i < m_Types.Length; ++i )
{
if ( m_Types[i] != null )
++m_Count;
}
}
return m_Count;
}
}
private static Dictionary<Type, Int32> m_IDsFromTypes = new Dictionary<Type, Int32>( m_Types.Length );
private static Dictionary<Int32, SpecialMove> m_SpecialMoves = new Dictionary<Int32, SpecialMove>();
public static Dictionary<Int32, SpecialMove> SpecialMoves { get { return m_SpecialMoves; } }
public static int GetRegistryNumber( ISpell s )
{
return GetRegistryNumber( s.GetType() );
@ -53,20 +56,14 @@ namespace Server.Spells
return GetRegistryNumber( s.GetType() );
}
private static Hashtable m_IDsFromTypes = new Hashtable( m_Types.Length );
public static int GetRegistryNumber( Type type )
{
if( m_IDsFromTypes.Contains( type ) )
return (int)m_IDsFromTypes[type];
if( m_IDsFromTypes.ContainsKey( type ) )
return m_IDsFromTypes[type];
return -1;
}
private static Hashtable m_SpecialMoves = new Hashtable();
public static Hashtable SpecialMoves { get { return m_SpecialMoves; } }
public static void Register( int spellID, Type type )
{
if ( spellID < 0 || spellID >= m_Types.Length )
@ -77,7 +74,7 @@ namespace Server.Spells
m_Types[spellID] = type;
if( m_IDsFromTypes[type] == null )
if( !m_IDsFromTypes.ContainsKey( type ) )
m_IDsFromTypes.Add( type, spellID );
if( type.IsSubclassOf( typeof( SpecialMove ) ) )
@ -104,13 +101,10 @@ namespace Server.Spells
Type t = m_Types[spellID];
if ( t == null || !t.IsSubclassOf( typeof( SpecialMove ) ) ) //Ensure correct registration
if ( t == null || !t.IsSubclassOf( typeof( SpecialMove ) ) || !m_SpecialMoves.ContainsKey( spellID ) )
return null;
if( m_SpecialMoves.ContainsKey( spellID ) )
return m_SpecialMoves[spellID] as SpecialMove;
return null;
return m_SpecialMoves[spellID];
}
private static object[] m_Params = new object[2];

View file

@ -1,44 +1,43 @@
using System;
using System.Collections;
using System.Collections.Generic;
using Server;
using Server.Items;
using Server.Mobiles;
using Server.Spells;
using Server.Spells.Necromancy;
using Server.Mobiles;
using Server.Items;
using Server.Spells.Ninjitsu;
namespace Server.Spells.Ninjitsu
{
public class MirrorImage : NinjaSpell
{
private static Hashtable m_CloneCount = new Hashtable();
private static Dictionary<Mobile, Int32> m_CloneCount = new Dictionary<Mobile, Int32>();
public static bool HasClone( Mobile m )
{
return (m_CloneCount.Contains( m ) && ((int)m_CloneCount[m]) > 0);
return m_CloneCount.ContainsKey( m );
}
public static void AddClone( Mobile m )
{
if( m == null )
if ( m == null )
return;
if( m_CloneCount.Contains( m ) )
m_CloneCount[m] = ((int)m_CloneCount[m] +1);
if ( m_CloneCount.ContainsKey( m ) )
m_CloneCount[m]++;
else
m_CloneCount.Add( m, 1 );
m_CloneCount[m] = 1;
}
public static void RemoveClone( Mobile m )
{
if( m == null )
if ( m == null )
return;
if( m_CloneCount.Contains( m ) )
if ( m_CloneCount.ContainsKey( m ) )
{
m_CloneCount[m] = ((int)m_CloneCount[m] -1);
m_CloneCount[m]--;
if( ((int)m_CloneCount[m]) <= 0 )
if ( m_CloneCount[m] == 0 )
m_CloneCount.Remove( m );
}
}