Skip to content
Permalink
Browse files

Minor code cleanup

  • Loading branch information...
UnknownShadow200 committed May 17, 2017
1 parent 0b472e2 commit c44dec328f596554a67ac0effad35c5b63daf81b
@@ -692,8 +692,8 @@ static void BDBDBHandler(Player player, CommandReader cmd)
Environment.Version );
}

double bytesReceivedRate = Server.Players.Aggregate( 0d, ( i, p ) => i + p.BytesReceivedRate );
double bytesSentRate = Server.Players.Aggregate( 0d, ( i, p ) => i + p.BytesSentRate );
double bytesReceivedRate = Server.Players.Sum( p => p.BytesReceivedRate );
double bytesSentRate = Server.Players.Sum( p => p.BytesSentRate );
player.Message( " Bandwidth: {0:0.0} KB/s up, {1:0.0} KB/s down",
bytesSentRate / 1000, bytesReceivedRate / 1000 );

@@ -1322,7 +1322,7 @@ static void ListStaffHandler(Player player, CommandReader cmd)
string output = "";
if (param.StartsWith("*") && param.EndsWith("*")) {
foreach (CommandDescriptor item in items) {
if (item.Name.ToLower().Contains(param.ToLower().Trim('*'))) {
if (item.Name.CaselessContains(param.Trim('*'))) {
output += item.MinRank.Color + item.Name + "&S, ";
}
}
@@ -1335,7 +1335,7 @@ static void ListStaffHandler(Player player, CommandReader cmd)
return;
} else if (param.EndsWith("*")) {
foreach (CommandDescriptor item in items) {
if (item.Name.CaselessStarts(param.ToLower().Trim('*'))) {
if (item.Name.CaselessStarts(param.Trim('*'))) {
output += item.MinRank.Color + item.Name + "&S, ";
}
}
@@ -1348,7 +1348,7 @@ static void ListStaffHandler(Player player, CommandReader cmd)
return;
} else if (param.StartsWith("*")) {
foreach (CommandDescriptor item in items) {
if (item.Name.CaselessEnds(param.ToLower().Trim('*'))) {
if (item.Name.CaselessEnds(param.Trim('*'))) {
output += item.MinRank.Color + item.Name + "&S, ";
}
}
@@ -1711,7 +1711,7 @@ static void GameSetHandler(Player player, CommandReader cmd)
} else if (param.EndsWith("*") && param.StartsWith("*")) {
listName = "worlds containing \"" + param.ToLower().Replace("*", "") + "\"";
extraParam = param.ToLower();
worlds = WorldManager.Worlds.Where(w => w.Name.ToLower().Contains(param.ToLower().Replace("*", ""))).ToArray();
worlds = WorldManager.Worlds.Where(w => w.Name.CaselessContains(param.Replace("*", ""))).ToArray();
} else if (param.EndsWith("*")) {
listName = "worlds starting with \"" + param.ToLower().Replace("*", "") + "\"";
extraParam = param.ToLower();
@@ -3504,14 +3504,15 @@ static void WorldClearHandler(Player player, CommandReader cmd)
WorldManager.Worlds.Where( w =>
w.Name.StartsWith("PW_") && w.AccessSecurity.Check(player.Info) &&
!w.Name.StartsWith(mapName)).ToArray();
if (own.Any()) {

if (own.Length > 0) {
player.Message("Your personal worlds: {0}", own.JoinToClassyString());
}
if (others.Any()) {
if (others.Length > 0) {
player.Message("Player personal worlds you have access to: {0}",
others.JoinToClassyString());
}
if (!own.Any() && !others.Any()) {
if (own.Length == 0 && others.Length == 0) {
player.Message("You do not have access to any personal worlds.");
}
}
@@ -696,7 +696,7 @@ struct HighlightZoneArgs {
player.Message( " Type &H/ZInfo ZoneName&S for details." );

if (player.IsSuper || !player.Supports(CpeExt.SelectionCuboid)) return;
if (showZones.ToLower() !="yes") return;
if (!showZones.CaselessEquals("yes")) return;

HighlightZoneArgs args = new HighlightZoneArgs() { Player = player, Zones = zones };
Scheduler.NewTask(HighlightZones, args)
@@ -770,7 +770,7 @@ bool LoginSequence()
return false;
}

if (string.IsNullOrEmpty(ClientName) || !ClientName.ToLower().Contains("classicalsharp")) {
if (string.IsNullOrEmpty(ClientName) || !ClientName.CaselessContains("classicalsharp")) {
Message("&bIt is recommended that you use the ClassicalSharp client!");
Message("&9http://123dmwm.tk/cs &bredirects to the official download.");
}
@@ -43,7 +43,7 @@ public static class Chat
}

foreach (ChatFilter Swear in ChatFilter.Filters) {
if (rawMessage.ToLower().Contains(Swear.Word.ToLower())) {
if (rawMessage.CaselessContains(Swear.Word)) {
rawMessage = rawMessage.ReplaceString(Swear.Word, Swear.Replacement, StringComparison.InvariantCultureIgnoreCase);
}
}
@@ -113,7 +113,7 @@ public static class Chat
using (var reader = new StreamReader(responseStream, encoding))
fullUrl = reader.ReadToEnd();
}
if (!fullUrl.ToLower().Contains(match.ToString().ToLower()) && !match.ToString().ToLower().Contains(fullUrl.ToLower())) {
if (!fullUrl.CaselessContains(match.ToString()) && !match.ToString().CaselessContains(fullUrl)) {
fullUrls.Add(fullUrl);
}
}

This file was deleted.

Oops, something went wrong.
@@ -222,6 +222,24 @@ public static class StringUtil {
public static bool CaselessContains(this string a, string b) {
return a.IndexOf(b, StringComparison.OrdinalIgnoreCase) >= 0;
}

public static string ReplaceString(this string str, string oldValue, string newValue, StringComparison comparison) {
StringBuilder sb = new StringBuilder();

int previousIndex = 0;
int index = str.IndexOf(oldValue, comparison);
while (index != -1) {
sb.Append(str.Substring(previousIndex, index - previousIndex));
sb.Append(newValue);
index += oldValue.Length;

previousIndex = index;
index = str.IndexOf(oldValue, index, comparison);
}
sb.Append(str.Substring(previousIndex));

return sb.ToString();
}
}


@@ -159,7 +159,6 @@
<Compile Include="Player\ChatFilter.cs" />
<Compile Include="Player\PlayerHacks.cs" />
<Compile Include="Player\Report.cs" />
<Compile Include="Player\Replace.cs" />
<Compile Include="Player\SearchOptions.cs" />
<Compile Include="Player\SecurityController.cs" />
<Compile Include="Plugins\Plugin.cs" />

0 comments on commit c44dec3

Please sign in to comment.
You can’t perform that action at this time.