Skip to content

Commit

Permalink
Some optimization, show more information on shutdown
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonty800 committed Aug 6, 2013
1 parent 113c161 commit f92a94b
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 22 deletions.
2 changes: 1 addition & 1 deletion ConfigGUI/AddWorldPopup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ static void MapDimensionValidating( object sender, CancelEventArgs e ) {
void tName_Validating( object sender, CancelEventArgs e ) {
if( fCraft.World.IsValidName( tName.Text ) &&
(!MainForm.IsWorldNameTaken( tName.Text ) ||
(originalWorldName != null && tName.Text.ToLower() == originalWorldName.ToLower())) ) {
(originalWorldName != null && tName.Text.Equals(originalWorldName, StringComparison.OrdinalIgnoreCase))) ) {
tName.ForeColor = SystemColors.ControlText;
} else {
tName.ForeColor = System.Drawing.Color.Red;
Expand Down
2 changes: 1 addition & 1 deletion ConfigGUI/MainForm.Adapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ void LoadWorldList() {
XAttribute mainWorldAttr = root.Attribute( "main" );
if( mainWorldAttr != null ) {
foreach( WorldListEntry world in Worlds ) {
if( world.Name.ToLower() == mainWorldAttr.Value.ToLower() ) {
if( world.Name.Equals(mainWorldAttr.Value, StringComparison.OrdinalIgnoreCase) ) {
cMainWorld.SelectedItem = world.Name;
break;
}
Expand Down
6 changes: 3 additions & 3 deletions fCraft/Commands/BuildingCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ static void Door ( Player player, Command cmd ) {
Door doorFound = null;
lock ( player.World.Map.Doors.SyncRoot ) {
foreach ( Door door in player.World.Map.Doors ) {
if ( door.Name.ToLower().Equals( doorName.ToLower() ) ) {
if ( door.Name.Equals( doorName, StringComparison.OrdinalIgnoreCase ) ) {
doorFound = door;
found = true;
break;
Expand All @@ -209,7 +209,7 @@ static void Door ( Player player, Command cmd ) {
bool found = false;
lock ( player.World.Map.Doors.SyncRoot ) {
foreach ( Door door in player.World.Map.Doors ) {
if ( door.Name.ToLower().Equals( doorName.ToLower() ) ) {
if ( door.Name.Equals( doorName, StringComparison.OrdinalIgnoreCase ) ) {
World doorWorld = WorldManager.FindWorldExact( door.World );
player.Message( "Door '{0}&S' was created by {1}&S at {2}",
door.Name, door.Creator, door.Created );
Expand Down Expand Up @@ -336,7 +336,7 @@ static void DrawImageHandler ( Player player, Command cmd ) {
static void DrawImgCallback ( Player player, Vector3I[] marks, object tag ) {
string Url = ( string )tag;
if ( Url.StartsWith( "++" ) ) Url = Url.Replace( "++", "i.imgur.com/" );
if ( !Url.ToLower().StartsWith( "http://" ) ) Url = "http://" + Url;
if ( !Url.StartsWith( "http://", StringComparison.OrdinalIgnoreCase ) ) Url = "http://" + Url;

player.MessageNow( "&HDrawImg: Downloading image from {0}", Url );

Expand Down
19 changes: 11 additions & 8 deletions fCraft/Commands/MaintenanceCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,17 +112,20 @@ DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
};

static void FixRealms ( Player player, Command cmd ) {
var Players = PlayerDB.PlayerInfoList;
int Count = 0;
foreach ( World w in WorldManager.Worlds ) {
foreach ( PlayerInfo p in Players ) {
if ( p.Name == w.Name ) {
w.IsHidden = false;
w.IsRealm = true;
Count++;
player.Message( "Managing worlds..." );
new System.Threading.Thread( new System.Threading.ThreadStart( delegate {
foreach ( World w in WorldManager.Worlds ) {
foreach ( PlayerInfo p in PlayerDB.PlayerInfoList ) {
if ( p == null || w == null ) return;
if ( p.Name == w.Name ) {
w.IsHidden = false;
w.IsRealm = true;
Count++;
}
}
}
}
} ) ).Start();
player.Message( "Converted {0} worlds to Realms", Count.ToString() );
}

Expand Down
6 changes: 3 additions & 3 deletions fCraft/Commands/WorldCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ static void MessageBlock ( Player player, Command cmd ) {

lock ( player.World.Map.MessageBlocks.SyncRoot ) {
foreach ( MessageBlock MessageBlock in player.World.Map.MessageBlocks ) {
if ( MessageBlock.Name.ToLower().Equals( MessageBlockName.ToLower() ) ) {
if ( MessageBlock.Name.Equals( MessageBlockName, StringComparison.OrdinalIgnoreCase ) ) {
MessageBlockFound = MessageBlock;
found = true;
break;
Expand All @@ -420,7 +420,7 @@ static void MessageBlock ( Player player, Command cmd ) {
player.Message( "Could not find MessageBlock as this world doesn't contain a MessageBlock." );
}
}
} else if ( option.ToLower().Equals( "info" ) ) {
} else if ( option.Equals( "info", StringComparison.OrdinalIgnoreCase ) ) {
string MessageBlockName = cmd.Next();

if ( MessageBlockName == null ) {
Expand All @@ -431,7 +431,7 @@ static void MessageBlock ( Player player, Command cmd ) {

lock ( player.World.Map.MessageBlocks.SyncRoot ) {
foreach ( MessageBlock MessageBlock in player.World.Map.MessageBlocks ) {
if ( MessageBlock.Name.ToLower().Equals( MessageBlockName.ToLower() ) ) {
if ( MessageBlock.Name.Equals( MessageBlockName, StringComparison.OrdinalIgnoreCase ) ) {
World MessageBlockWorld = WorldManager.FindWorldExact( MessageBlock.World );
player.Message( "MessageBlock '{0}&S' was created by {1}&S at {2}",
MessageBlock.Name, MessageBlock.Creator, MessageBlock.Created );
Expand Down
4 changes: 4 additions & 0 deletions fCraft/Network/Player.Networking.cs
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,10 @@ bool LoginSequence () {
GentlyKickBetaClients();
return false;

case 250:
GentlyKickBetaClients();
return false;

case ( byte )'G':
ServeCfg();
return false;
Expand Down
2 changes: 1 addition & 1 deletion fCraft/Portals/Portal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ public static bool DoesNameExist ( World world, String name ) {
if ( world.Map.Portals != null ) {
if ( world.Map.Portals.Count > 0 ) {
foreach ( Portal portal in world.Map.Portals ) {
if ( portal.Name.Equals( name ) ) {
if ( portal.Name.Equals( name, StringComparison.OrdinalIgnoreCase ) ) {
return true;
}
}
Expand Down
2 changes: 1 addition & 1 deletion fCraft/System/Scheduler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ internal static void BeginShutdown() {
#if DEBUG_SCHEDULER
Logger.Log( LogType.Debug, "Scheduler: BeginShutdown..." );
#endif
if (ConfigKey.HbSaverKey.Enabled())
if ( ConfigKey.HbSaverKey.Enabled() && ConfigKey.IsPublic.Enabled() )
{
if (!Server.IsRestarting)
{
Expand Down
9 changes: 5 additions & 4 deletions fCraft/System/Server.cs
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ public static bool StartServer() {
// list loaded worlds
WorldManager.UpdateWorldList();
Logger.Log( LogType.SystemActivity,
"{0} available worlds: {0}",
"{0} available worlds",
WorldManager.Worlds.Length );

Logger.Log( LogType.SystemActivity,
Expand Down Expand Up @@ -475,6 +475,7 @@ static void ShutdownNow( [NotNull] ShutdownParams shutdownParams ) {
// kick all players
lock( SessionLock ) {
if( Sessions.Count > 0 ) {
Logger.Log( LogType.SystemActivity, "Shutdown: Kicking {0} players...", Sessions.Count );
foreach( Player p in Sessions ) {
// NOTE: kick packet delivery here is not currently guaranteed
p.Kick( "Server shutting down (" + shutdownParams.ReasonString + Color.White + ")", LeaveReason.ServerShutdown );
Expand All @@ -488,7 +489,7 @@ static void ShutdownNow( [NotNull] ShutdownParams shutdownParams ) {
IRC.Disconnect();

if ( WorldManager.Worlds != null ) {
Logger.Log( LogType.SystemActivity, "Shutdown: Saving worlds..." );
Logger.Log( LogType.SystemActivity, "Shutdown: Saving {0} worlds...", WorldManager.Worlds.Length );
lock ( WorldManager.SyncRoot ) {
// unload all worlds (includes saving)
foreach ( World world in WorldManager.Worlds ) {
Expand All @@ -503,7 +504,7 @@ static void ShutdownNow( [NotNull] ShutdownParams shutdownParams ) {
Scheduler.EndShutdown();

if ( IsRunning ) {
Logger.Log( LogType.SystemActivity, "Shutdown: Saving databases..." );
Logger.Log( LogType.SystemActivity, "Shutdown: Saving databases... ({0} players and {1} IP bans)", PlayerDB.PlayerInfoList.Length, IPBanList.Count );
if ( PlayerDB.IsLoaded ) PlayerDB.Save();
if ( IPBanList.IsLoaded ) IPBanList.Save();
}
Expand All @@ -525,7 +526,7 @@ public static void Shutdown( [NotNull] ShutdownParams shutdownParams, bool waitF
lock( ShutdownLock ) {
if( !CancelShutdown() ) return;
shutdownThread = new Thread( ShutdownThread ) {
Name = "fCraft.Shutdown"
Name = "800Craft.Shutdown"
};
if( shutdownParams.Delay >= ChatTimer.MinDuration ) {
string timerMsg = String.Format( "Server {0} ({1})",
Expand Down

0 comments on commit f92a94b

Please sign in to comment.