diff --git a/Application/Manager.cs b/Application/Manager.cs
index 39788bc3..d55dde26 100644
--- a/Application/Manager.cs
+++ b/Application/Manager.cs
@@ -290,6 +290,7 @@ namespace IW4MAdmin.Application
Commands.Add(new CSetPassword());
Commands.Add(new CPing());
Commands.Add(new CSetGravatar());
+ Commands.Add(new CNextMap());
foreach (Command C in SharedLibraryCore.Plugins.PluginImporter.ActiveCommands)
Commands.Add(C);
diff --git a/Application/Server.cs b/Application/Server.cs
index 594ff01b..5801cc98 100644
--- a/Application/Server.cs
+++ b/Application/Server.cs
@@ -1055,6 +1055,7 @@ namespace IW4MAdmin
{
Manager.GetMessageTokens().Add(new SharedLibraryCore.Helpers.MessageToken("TOTALPLAYERS", (Server s) => Manager.GetClientService().GetTotalClientsAsync().Result.ToString()));
Manager.GetMessageTokens().Add(new SharedLibraryCore.Helpers.MessageToken("VERSION", (Server s) => Application.Program.Version.ToString()));
+ Manager.GetMessageTokens().Add(new SharedLibraryCore.Helpers.MessageToken("NEXTMAP", (Server s) => SharedLibraryCore.Commands.CNextMap.GetNextMap(s).Result));
}
}
}
diff --git a/SharedLibraryCore/Commands/NativeCommands.cs b/SharedLibraryCore/Commands/NativeCommands.cs
index 622e66c6..d4e7c642 100644
--- a/SharedLibraryCore/Commands/NativeCommands.cs
+++ b/SharedLibraryCore/Commands/NativeCommands.cs
@@ -1244,4 +1244,62 @@ namespace SharedLibraryCore.Commands
}
}
}
+
+ ///
+ /// Retrieves the next map in rotation
+ ///
+ public class CNextMap : Command
+ {
+ public CNextMap() : base("nextmap", Utilities.CurrentLocalization.LocalizationIndex["COMMANDS_NEXTMAP_DESC"], "nm", Player.Permission.User, false) { }
+ public static async Task GetNextMap(Server s)
+ {
+ string mapRotation = (await s.GetDvarAsync("sv_mapRotation")).Value.ToLower();
+ var regexMatches = Regex.Matches(mapRotation, @"(gametype +([a-z]{1,4}))? *map ([a-z|_]+)", RegexOptions.IgnoreCase).ToList();
+ // find the current map in the rotation
+ var currentMap = regexMatches.Where(m => m.Groups[3].ToString() == s.CurrentMap.Name);
+ var lastMap = regexMatches.LastOrDefault();
+ Map nextMap = null;
+
+ // the current map is not in rotation
+ if (currentMap.Count() == 0)
+ {
+ nextMap = new Map()
+ {
+ // this happens if it's an unknown custom or DLC map
+ Alias = "Unknown"
+ };
+ }
+
+ // there's duplicate maps in rotation
+ else if (currentMap.Count() > 1)
+ {
+ // gametype has been manually specified
+ var duplicateMaps = currentMap.Where(m => !string.IsNullOrEmpty(m.Groups[1].ToString()));
+
+ // more than one instance of map in rotation
+ if (duplicateMaps.Count() > 0)
+ {
+ currentMap = duplicateMaps.Where(m => m.Groups[2].ToString() == s.Gametype);
+ }
+
+ // else we just have to assume it's the first one
+ }
+
+ // if the current map is the last map, the next map is the first map
+ var nextMapMatch = currentMap.First().Index != lastMap.Index ?
+ regexMatches[regexMatches.IndexOf(currentMap.First()) + 1] :
+ regexMatches.First();
+ nextMap = s.Maps.FirstOrDefault(m => m.Name == nextMapMatch.Groups[3].ToString()) ?? nextMap;
+ string nextGametype = nextMapMatch.Groups[2].ToString().Length == 0 ?
+ Utilities.GetLocalizedGametype(s.Gametype) :
+ Utilities.GetLocalizedGametype(nextMapMatch.Groups[2].ToString());
+
+ return $"{Utilities.CurrentLocalization.LocalizationIndex["COMMANDS_NEXTMAP_SUCCESS"]} ^5{nextMap.Alias}/{nextGametype}";
+ }
+
+ public override async Task ExecuteAsync(GameEvent E)
+ {
+ await E.Origin.Tell(await GetNextMap(E.Owner));
+ }
+ }
}