public override void HandlePost(HttpListenerContext ctx, WebUser user, string postData) { MapApiParams p = null; if ((p = TryJsonParse <MapApiParams>(ctx, postData)) == null) { return; } switch (p.Action) { case "maps_installed": List <ServerMap> mapList = Core.Database.GetMaps(); WebAdmin.SendHtml(ctx, ToJson(mapList)); break; case "maps_save": WebServer.LogAudit(user, "modified the map rotation"); WebAdmin.SendHtml(ctx, ToJson(SaveMapRot(p))); break; case "maps_rotation": WebAdmin.SendHtml(ctx, ToJson(GetMapRotation())); break; } }
private MapSaveResponse SaveMapRot(MapApiParams p) { List <string> mapRot = p.Maps; MapSaveResponse r; sRMtx.WaitOne(); try { ServerMap.SaveMapRotation(Core, mapRot); //theres a good chance that only maps were updated //in this case we dont want to re-write ServerSettings.cfg -> check if Randomize changed if (Core.Server.Settings.Randomize != p.Randomize) { Core.Server.Settings.Randomize = p.Randomize; Core.Server.Settings.WriteToFile(Core); } r = new MapSaveResponse(); } catch (Exception e) { r = new MapSaveResponse(e); } finally { sRMtx.ReleaseMutex(); } return(r); }
private MapSaveResponse SaveMapRot(MapApiParams p) { List <string> mapRot = p.Maps; MapSaveResponse r; sRMtx.WaitOne(); try { ServerMap.SaveMapRotation(Core, mapRot); if (Core.Config.EnableRuntime && Core.Server.Status == ServerStatus.Online) { Core.Scheduler.PushTask(() => Core.Rcon.UpdateMapList(mapRot)); } //there's a good chance that only maps were updated //in this case we dont want to re-write ServerSettings.cfg -> check if Randomize changed if (Core.Server.Settings.Randomize != p.Randomize) { Core.Server.Settings.Randomize = p.Randomize; Core.Server.Settings.WriteToFile(Core); if (Core.Config.EnableRuntime && Core.Server.Status == ServerStatus.Online) { Core.Scheduler.PushTask(() => Core.Rcon.SendCommand("randomize", p.Randomize ? "1" : "0")); } } r = new MapSaveResponse(); } catch (Exception e) { r = new MapSaveResponse(e); } finally { sRMtx.ReleaseMutex(); } return(r); }