Skip to content

Commit

Permalink
Simplify getting default realm owner behaviour for /mapinfo
Browse files Browse the repository at this point in the history
  • Loading branch information
UnknownShadow200 committed Oct 16, 2021
1 parent 825cfab commit 71f7dd0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 20 deletions.
21 changes: 1 addition & 20 deletions MCGalaxy/Commands/Information/CmdMapInfo.cs
Expand Up @@ -98,7 +98,7 @@ public sealed class CmdMapInfo : Command2 {

string realmOwner = cfg.RealmOwner;
if (String.IsNullOrEmpty(cfg.RealmOwner)) {
realmOwner = DefaultRealmOwner(data.MapName);
realmOwner = LevelInfo.DefaultRealmOwner(data.MapName);
}
if (String.IsNullOrEmpty(realmOwner)) return;

Expand All @@ -124,25 +124,6 @@ public sealed class CmdMapInfo : Command2 {
cfg.Likes, cfg.Dislikes);
}

static string DefaultRealmOwner(string map) {
bool plus = Server.Config.ClassicubeAccountPlus;
// Early out when accounts have + and map doesn't.
if (plus && map.IndexOf('+') == -1) return null;

string name = null, origMap = map;
while (map.Length > 0 && Char.IsNumber(map[map.Length - 1])) {
// If the server does not have account with +, we have to account for the
// that say Player123's second level is Player1232, and the realm owner is Player123
name = plus ? null : PlayerDB.FindName(map);
if (name != null) break;
map = map.Substring(0, map.Length - 1);
}

if (name == null) name = PlayerDB.FindName(map);
if (name != null && !LevelInfo.IsRealmOwner(name, origMap)) return null;
return name;
}

void ShowEnv(Player p, MapInfo data, LevelConfig cfg) {
string url = cfg.Terrain.Length > 0 ? cfg.Terrain : Server.Config.DefaultTerrain;
if (url.Length > 0) {
Expand Down
18 changes: 18 additions & 0 deletions MCGalaxy/Levels/LevelInfo.cs
Expand Up @@ -19,6 +19,7 @@
using System.Collections.Generic;
using System.IO;
using System.Text;
using MCGalaxy.DB;
using MCGalaxy.Events.LevelEvents;
using MCGalaxy.SQL;

Expand Down Expand Up @@ -184,6 +185,7 @@ public static class LevelInfo {
return true;
}


public static bool IsRealmOwner(string name, string map) {
LevelConfig cfg = GetConfig(map);
return IsRealmOwner(map, cfg, name);
Expand All @@ -206,5 +208,21 @@ public static class LevelInfo {
// If no + though, don't use because otherwise people can register accounts and claim maps
return Server.Config.ClassicubeAccountPlus && map.CaselessStarts(name);
}

internal static string DefaultRealmOwner(string map) {
bool plus = Server.Config.ClassicubeAccountPlus;
// Early out when either
// 1) accounts aren't using +
// 2) map name doesn't include +
if (!plus || map.IndexOf('+') == -1) return null;

// Convert username+23 to username+
while (map.Length > 0 && Char.IsNumber(map[map.Length - 1])) {
map = map.Substring(0, map.Length - 1);
}

// Match the backwards compatibilty case of IsRealmOwner
return PlayerDB.FindName(map);
}
}
}

0 comments on commit 71f7dd0

Please sign in to comment.