From 50690c99cafb817b01df78c685bc3e48ca3f5a33 Mon Sep 17 00:00:00 2001 From: proepkes Date: Wed, 18 Jul 2018 19:58:26 +0200 Subject: [PATCH] Lobbyconfig fixes & enhancements --- .../Lobbies/LobbiesConfig.cs | 17 ++-- .../Lobbies/LobbiesExtensionMethods.cs | 89 ------------------- .../Lobbies/LobbiesHelper.cs | 3 +- .../Lobbies/LobbiesPlugin.cs | 6 +- .../Lobbies/TwoVsTwo.lobby | 10 +-- 5 files changed, 20 insertions(+), 105 deletions(-) delete mode 100644 SpeedDate.ServerPlugins/Lobbies/LobbiesExtensionMethods.cs diff --git a/SpeedDate.ServerPlugins/Lobbies/LobbiesConfig.cs b/SpeedDate.ServerPlugins/Lobbies/LobbiesConfig.cs index fbf80d2..22d1bdd 100644 --- a/SpeedDate.ServerPlugins/Lobbies/LobbiesConfig.cs +++ b/SpeedDate.ServerPlugins/Lobbies/LobbiesConfig.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.IO; +using System.Reflection; using SpeedDate.Configuration; namespace SpeedDate.ServerPlugins.Lobbies @@ -9,21 +10,23 @@ class LobbiesConfig : IConfig { public string LobbyFiles { get; set; } = string.Empty; - public IEnumerable ReadAllFiles() + public IEnumerable<(string filename, string content)> ReadAllFiles() { - var result = new List(); + var result = new List<(string, string)>(); foreach (var file in LobbyFiles.Split(';')) { - var fileName = file; + var filePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); + var fileName = $"{filePath}\\{file}"; + if (!File.Exists(fileName)) { - fileName = $"{file}.lobby"; + fileName = $"{filePath}\\{file}.lobby"; if (!File.Exists(fileName)) //Search for file.lobby { - fileName = $"Lobbies\\{file}"; + fileName = $"{filePath}\\Lobbies\\{file}"; if (!File.Exists(fileName)) //Search for Lobbies\file { - fileName = $"Lobbies\\{file}.lobby"; + fileName = $"{filePath}\\Lobbies\\{file}.lobby"; if (!File.Exists(fileName)) //Search for Lobbies\file.lobby { continue; @@ -32,7 +35,7 @@ public IEnumerable ReadAllFiles() } } - result.Add(File.ReadAllText(fileName)); + result.Add((file, File.ReadAllText(fileName))); } return result; diff --git a/SpeedDate.ServerPlugins/Lobbies/LobbiesExtensionMethods.cs b/SpeedDate.ServerPlugins/Lobbies/LobbiesExtensionMethods.cs deleted file mode 100644 index f842281..0000000 --- a/SpeedDate.ServerPlugins/Lobbies/LobbiesExtensionMethods.cs +++ /dev/null @@ -1,89 +0,0 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Text; -using SpeedDate.Configuration; -using SpeedDate.Packets.Lobbies; - -namespace SpeedDate.ServerPlugins.Lobbies -{ - public static class LobbiesHelper - { - public static string ExtractLobbyName(this Dictionary properties) - { - return properties.ContainsKey(OptionKeys.LobbyName) ? properties[OptionKeys.LobbyName] : Lobby.DefaultName; - } - - public static LobbyBuilder CreateLobbyBuilder(StringReader reader) - { - var config = reader.ReadToEnd(); - - return (plugin, properties, creator) => - { - Lobby result = null; - - var xmlReader = new XmlParser(config); - - var teams = new List(); - xmlReader.SearchEach("Team", () => - { - teams.Add(new LobbyTeam(xmlReader["Name"]) - { - MinPlayers = Convert.ToInt32(xmlReader["MinPlayers"]), - MaxPlayers = Convert.ToInt32(xmlReader["MaxPlayers"]) - }); - }); - - xmlReader = new XmlParser(config); - xmlReader.Search("Lobby", () => - { - result = new Lobby(plugin.GenerateLobbyId(), teams, plugin) - { - DisplayName = xmlReader["DisplayName"], - Autostart = Convert.ToBoolean(xmlReader["Autostart"]), - AllowJoiningWhenGameIsLive = Convert.ToBoolean(xmlReader["AllowJoiningWhenGameIsLive"]), - AllowPlayersChangeLobbyProperties = - Convert.ToBoolean(xmlReader["AllowPlayersChangeLobbyProperties"]), - KeepAliveWithZeroPlayers = Convert.ToBoolean(xmlReader["KeepAliveWithZeroPlayers"]), - EnableGameMasters = Convert.ToBoolean(xmlReader["EnableGameMasters"]), - EnableManualStart = Convert.ToBoolean(xmlReader["EnableManualStart"]), - EnableReadySystem = Convert.ToBoolean(xmlReader["EnableReadySystem"]), - EnableTeamSwitching = Convert.ToBoolean(xmlReader["EnableTeamSwitching"]), - PlayAgainEnabled = Convert.ToBoolean(xmlReader["PlayAgainEnabled"]), - StartGameWhenAllReady = Convert.ToBoolean(xmlReader["StartGameWhenAllReady"]) - }; - }); - - xmlReader = new XmlParser(config); - xmlReader.SearchEach("Control", () => - { - var defaultValue = ""; - var control = new LobbyPropertyData - { - PropertyKey = xmlReader["Key"], - Label = xmlReader["Label"], - Options = new List() - }; - xmlReader.SearchEach("Controloption", () => - { - var value = xmlReader["Value"]; - if (xmlReader["IsDefault"] != null) - { - defaultValue = value; - } - control.Options.Add(value); - }); - result.AddControl(control, defaultValue); - }); - - - if (result.Autostart) - { - result.StartAutomation(); - } - - return result; - }; - } - } -} diff --git a/SpeedDate.ServerPlugins/Lobbies/LobbiesHelper.cs b/SpeedDate.ServerPlugins/Lobbies/LobbiesHelper.cs index f842281..0869623 100644 --- a/SpeedDate.ServerPlugins/Lobbies/LobbiesHelper.cs +++ b/SpeedDate.ServerPlugins/Lobbies/LobbiesHelper.cs @@ -50,7 +50,8 @@ public static LobbyBuilder CreateLobbyBuilder(StringReader reader) EnableReadySystem = Convert.ToBoolean(xmlReader["EnableReadySystem"]), EnableTeamSwitching = Convert.ToBoolean(xmlReader["EnableTeamSwitching"]), PlayAgainEnabled = Convert.ToBoolean(xmlReader["PlayAgainEnabled"]), - StartGameWhenAllReady = Convert.ToBoolean(xmlReader["StartGameWhenAllReady"]) + StartGameWhenAllReady = Convert.ToBoolean(xmlReader["StartGameWhenAllReady"]), + Name = properties.ExtractLobbyName() }; }); diff --git a/SpeedDate.ServerPlugins/Lobbies/LobbiesPlugin.cs b/SpeedDate.ServerPlugins/Lobbies/LobbiesPlugin.cs index cf64d43..2489f76 100644 --- a/SpeedDate.ServerPlugins/Lobbies/LobbiesPlugin.cs +++ b/SpeedDate.ServerPlugins/Lobbies/LobbiesPlugin.cs @@ -51,9 +51,9 @@ public IEnumerable GetPublicGames(IPeer peer, Dictionary - 1x - 2x - 3x + + + - On - Off + +