Skip to content
Permalink
Browse files

Fix /rules admin permission check being case sensitive

  • Loading branch information...
UnknownShadow200 committed Sep 6, 2018
1 parent 36489b5 commit 8c80d5b45277101690a434700aba0b700bb477b6
Showing with 24 additions and 20 deletions.
  1. +14 −13 fCraft/Commands/InfoCommands.cs
  2. +10 −7 fCraft/Player/PlayerDB.cs
@@ -697,23 +697,24 @@ static void BDBDBHandler(Player player, CommandReader cmd)
player.Message( " Bandwidth: {0:0.0} KB/s up, {1:0.0} KB/s down",
bytesSentRate / 1000, bytesReceivedRate / 1000 );

PlayerInfo[] infos = PlayerDB.PlayerInfoList;
player.Message( " Tracking {0:N0} players ({1} online, {2} banned ({3:0.0}%), {4} IP-banned).",
PlayerDB.PlayerInfoList.Length,
infos.Length,
Server.CountVisiblePlayers( player ),
PlayerDB.BannedCount,
PlayerDB.BannedPercentage,
IPBanList.Count );

player.Message(" Players built {0:N0}; deleted {1:N0}; drew {2:N0} blocks; wrote {3:N0} messages; issued {4:N0} kicks; spent {5:N0} hours total (Average: {6:N0} hours); joined {7:N0} times (Average: {8:N0} times)",
PlayerDB.PlayerInfoList.Sum( p => p.BlocksBuilt ),
PlayerDB.PlayerInfoList.Sum( p => p.BlocksDeleted ),
PlayerDB.PlayerInfoList.Sum( p => p.BlocksDrawn ),
PlayerDB.PlayerInfoList.Sum( p => p.MessagesWritten ),
PlayerDB.PlayerInfoList.Sum( p => p.TimesKickedOthers ),
PlayerDB.PlayerInfoList.Sum(p => p.TotalTime.TotalHours),
PlayerDB.PlayerInfoList.Average(p => p.TotalTime.TotalHours),
PlayerDB.PlayerInfoList.Sum(p => p.TimesVisited),
PlayerDB.PlayerInfoList.Average(p => p.TimesVisited));
infos.Sum( p => p.BlocksBuilt ),
infos.Sum( p => p.BlocksDeleted ),
infos.Sum( p => p.BlocksDrawn ),
infos.Sum( p => p.MessagesWritten ),
infos.Sum( p => p.TimesKickedOthers ),
infos.Sum(p => p.TotalTime.TotalHours),
infos.Average(p => p.TotalTime.TotalHours),
infos.Sum(p => p.TimesVisited),
infos.Average(p => p.TimesVisited));

player.Message( " There are {0} worlds available ({1} loaded, {2} hidden).",
WorldManager.Worlds.Length,
@@ -771,8 +772,8 @@ static void BDBDBHandler(Player player, CommandReader cmd)
//}

List<PlayerInfo> matches = new List<PlayerInfo>();
PlayerInfo[] allPlayers = PlayerDB.PlayerInfoList;
foreach (PlayerInfo pl in allPlayers) {
PlayerInfo[] infos = PlayerDB.PlayerInfoList;
foreach (PlayerInfo pl in infos) {
string nick = pl.DisplayedName == null ? pl.Name : pl.DisplayedName;
if (Color.StripColors(nick, false).CaselessEquals(target)) matches.Add(pl);
}
@@ -921,7 +922,7 @@ static void ListStaffHandler(Player player, CommandReader cmd)
section, matches.JoinToString());
} else if (matches.Count == 1) {
section = Path.GetFileNameWithoutExtension(matches[0]);
if (section.IndexOf("Admin") >= 0 && !player.IsStaff) {
if (section.CaselessContains("Admin") && !player.IsStaff) {
player.Message("You need to be staff to read the Admin Rules.");
return;
}
@@ -217,7 +217,7 @@ public static class PlayerDB {
RunCompatibilityChecks( version );
}

unsafe static void Split(string line, ref string[] fields, out int count) {
static void Split(string line, ref string[] fields, out int count) {
// Effectively string.split(',') but without the two passes and memory allocations.
count = 0;
int start = 0, len = 0;
@@ -453,6 +453,7 @@ public static class PlayerDB {
CheckIfLoaded();
List<PlayerInfo> result = new List<PlayerInfo>();
int count = 0;

PlayerInfo[] cache = PlayerInfoList;
for( int i = 0; i < cache.Length; i++ ) {
if( cache[i].LastIP.Equals( address ) ) {
@@ -483,6 +484,7 @@ public static class PlayerDB {
int count = 0;
uint addressInt = address.AsUInt();
uint netMask = IPAddressUtil.NetMask( range );

PlayerInfo[] cache = PlayerInfoList;
for( int i = 0; i < cache.Length; i++ ) {
if( cache[i].LastIP.Match( addressInt, netMask ) ) {
@@ -508,6 +510,7 @@ public static class PlayerDB {
CheckIfLoaded();
List<PlayerInfo> result = new List<PlayerInfo>();
int count = 0;

PlayerInfo[] cache = PlayerInfoList;
for( int i = 0; i < cache.Length; i++ ) {
if( regex.IsMatch( cache[i].Name ) ) {
@@ -771,15 +774,15 @@ public static class PlayerDB {
internal static int CountInactivePlayers() {
lock( AddLocker ) {
Dictionary<IPAddress, List<PlayerInfo>> playersByIP = new Dictionary<IPAddress, List<PlayerInfo>>();
PlayerInfo[] playerInfoListCache = PlayerInfoList;
for( int i = 0; i < playerInfoListCache.Length; i++ ) {
if( !playersByIP.ContainsKey( playerInfoListCache[i].LastIP ) ) {
playersByIP[playerInfoListCache[i].LastIP] = new List<PlayerInfo>();
PlayerInfo[] cache = PlayerInfoList;
for( int i = 0; i < cache.Length; i++ ) {
if( !playersByIP.ContainsKey( cache[i].LastIP ) ) {
playersByIP[cache[i].LastIP] = new List<PlayerInfo>();
}
playersByIP[playerInfoListCache[i].LastIP].Add( PlayerInfoList[i] );
playersByIP[cache[i].LastIP].Add( PlayerInfoList[i] );
}

return playerInfoListCache.Count( t => PlayerIsInactive( playersByIP, t, true ) );
return cache.Count( t => PlayerIsInactive( playersByIP, t, true ) );
}
}

0 comments on commit 8c80d5b

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