Skip to content

Commit 50690c9

Browse files
author
proepkes
committed
Lobbyconfig fixes & enhancements
1 parent 0a7ad48 commit 50690c9

5 files changed

Lines changed: 20 additions & 105 deletions

File tree

SpeedDate.ServerPlugins/Lobbies/LobbiesConfig.cs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Collections.Generic;
33
using System.IO;
4+
using System.Reflection;
45
using SpeedDate.Configuration;
56

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

12-
public IEnumerable<string> ReadAllFiles()
13+
public IEnumerable<(string filename, string content)> ReadAllFiles()
1314
{
14-
var result = new List<string>();
15+
var result = new List<(string, string)>();
1516
foreach (var file in LobbyFiles.Split(';'))
1617
{
17-
var fileName = file;
18+
var filePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
19+
var fileName = $"{filePath}\\{file}";
20+
1821
if (!File.Exists(fileName))
1922
{
20-
fileName = $"{file}.lobby";
23+
fileName = $"{filePath}\\{file}.lobby";
2124
if (!File.Exists(fileName)) //Search for file.lobby
2225
{
23-
fileName = $"Lobbies\\{file}";
26+
fileName = $"{filePath}\\Lobbies\\{file}";
2427
if (!File.Exists(fileName)) //Search for Lobbies\file
2528
{
26-
fileName = $"Lobbies\\{file}.lobby";
29+
fileName = $"{filePath}\\Lobbies\\{file}.lobby";
2730
if (!File.Exists(fileName)) //Search for Lobbies\file.lobby
2831
{
2932
continue;
@@ -32,7 +35,7 @@ public IEnumerable<string> ReadAllFiles()
3235
}
3336
}
3437

35-
result.Add(File.ReadAllText(fileName));
38+
result.Add((file, File.ReadAllText(fileName)));
3639
}
3740

3841
return result;

SpeedDate.ServerPlugins/Lobbies/LobbiesExtensionMethods.cs

Lines changed: 0 additions & 89 deletions
This file was deleted.

SpeedDate.ServerPlugins/Lobbies/LobbiesHelper.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ public static LobbyBuilder CreateLobbyBuilder(StringReader reader)
5050
EnableReadySystem = Convert.ToBoolean(xmlReader["EnableReadySystem"]),
5151
EnableTeamSwitching = Convert.ToBoolean(xmlReader["EnableTeamSwitching"]),
5252
PlayAgainEnabled = Convert.ToBoolean(xmlReader["PlayAgainEnabled"]),
53-
StartGameWhenAllReady = Convert.ToBoolean(xmlReader["StartGameWhenAllReady"])
53+
StartGameWhenAllReady = Convert.ToBoolean(xmlReader["StartGameWhenAllReady"]),
54+
Name = properties.ExtractLobbyName()
5455
};
5556
});
5657

SpeedDate.ServerPlugins/Lobbies/LobbiesPlugin.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@ public IEnumerable<GameInfoPacket> GetPublicGames(IPeer peer, Dictionary<string,
5151

5252
public override void Loaded()
5353
{
54-
foreach (var lobbySettings in _config.ReadAllFiles())
54+
foreach (var lobbyFile in _config.ReadAllFiles())
5555
{
56-
Factories.Add(lobbySettings, LobbiesHelper.CreateLobbyBuilder(new StringReader(lobbySettings)));
56+
Factories.Add(lobbyFile.filename , LobbiesHelper.CreateLobbyBuilder(new StringReader(lobbyFile.content)));
5757
}
5858

5959
Server.SetHandler(OpCodes.CreateLobby, HandleCreateLobby);
@@ -405,4 +405,4 @@ private void HandleGetLobbyTypes(IIncommingMessage message)
405405
message.Respond(Factories.Keys.ToBytes(), ResponseStatus.Success);
406406
}
407407
}
408-
}
408+
}

SpeedDate.ServerPlugins/Lobbies/TwoVsTwo.lobby

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@
1616
</Teams>
1717
<Controls>
1818
<Control Key="speed" Label="Game Speed">
19-
<Controloption IsDefault="true">1x</Controloption>
20-
<Controloption>2x</Controloption>
21-
<Controloption>3x</Controloption>
19+
<Controloption IsDefault="true" Value="1x" />
20+
<Controloption Value="2x" />
21+
<Controloption Value="3x" />
2222
</Control>
2323
<Control Key="gravity" Label="Gravity">
24-
<Controloption>On</Controloption>
25-
<Controloption>Off</Controloption>
24+
<Controloption Value="On" />
25+
<Controloption Value="Off" />
2626
</Control>
2727
</Controls>
2828
</Lobby>

0 commit comments

Comments
 (0)