Skip to content

Commit

Permalink
Lobbyconfig fixes & enhancements
Browse files Browse the repository at this point in the history
  • Loading branch information
proepkes committed Jul 18, 2018
1 parent 0a7ad48 commit 50690c9
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 105 deletions.
17 changes: 10 additions & 7 deletions SpeedDate.ServerPlugins/Lobbies/LobbiesConfig.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using SpeedDate.Configuration;

namespace SpeedDate.ServerPlugins.Lobbies
Expand All @@ -9,21 +10,23 @@ class LobbiesConfig : IConfig
{
public string LobbyFiles { get; set; } = string.Empty;

public IEnumerable<string> ReadAllFiles()
public IEnumerable<(string filename, string content)> ReadAllFiles()
{
var result = new List<string>();
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;
Expand All @@ -32,7 +35,7 @@ public IEnumerable<string> ReadAllFiles()
}
}

result.Add(File.ReadAllText(fileName));
result.Add((file, File.ReadAllText(fileName)));
}

return result;
Expand Down
89 changes: 0 additions & 89 deletions SpeedDate.ServerPlugins/Lobbies/LobbiesExtensionMethods.cs

This file was deleted.

3 changes: 2 additions & 1 deletion SpeedDate.ServerPlugins/Lobbies/LobbiesHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
};
});

Expand Down
6 changes: 3 additions & 3 deletions SpeedDate.ServerPlugins/Lobbies/LobbiesPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ public IEnumerable<GameInfoPacket> GetPublicGames(IPeer peer, Dictionary<string,

public override void Loaded()
{
foreach (var lobbySettings in _config.ReadAllFiles())
foreach (var lobbyFile in _config.ReadAllFiles())
{
Factories.Add(lobbySettings, LobbiesHelper.CreateLobbyBuilder(new StringReader(lobbySettings)));
Factories.Add(lobbyFile.filename , LobbiesHelper.CreateLobbyBuilder(new StringReader(lobbyFile.content)));
}

Server.SetHandler(OpCodes.CreateLobby, HandleCreateLobby);
Expand Down Expand Up @@ -405,4 +405,4 @@ private void HandleGetLobbyTypes(IIncommingMessage message)
message.Respond(Factories.Keys.ToBytes(), ResponseStatus.Success);
}
}
}
}
10 changes: 5 additions & 5 deletions SpeedDate.ServerPlugins/Lobbies/TwoVsTwo.lobby
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@
</Teams>
<Controls>
<Control Key="speed" Label="Game Speed">
<Controloption IsDefault="true">1x</Controloption>
<Controloption>2x</Controloption>
<Controloption>3x</Controloption>
<Controloption IsDefault="true" Value="1x" />
<Controloption Value="2x" />
<Controloption Value="3x" />
</Control>
<Control Key="gravity" Label="Gravity">
<Controloption>On</Controloption>
<Controloption>Off</Controloption>
<Controloption Value="On" />
<Controloption Value="Off" />
</Control>
</Controls>
</Lobby>

0 comments on commit 50690c9

Please sign in to comment.