Skip to content

Commit

Permalink
WIP: Configurable Lobbyfactories
Browse files Browse the repository at this point in the history
  • Loading branch information
proepkes committed Jul 16, 2018
1 parent e7fca13 commit dfd0652
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 74 deletions.
18 changes: 8 additions & 10 deletions SpeedDate.ServerPlugins/Lobbies/DemoLobbyFactories.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
using System.Collections.Generic;
using SpeedDate.Interfaces;
using SpeedDate.Network.Interfaces;
using SpeedDate.Packets.Lobbies;
using SpeedDate.ServerPlugins.Lobbies.Implementations;

namespace SpeedDate.ServerPlugins.Lobbies
{
Expand All @@ -20,7 +18,7 @@ public class DemoLobbyFactories
/// <param name="plugin"></param>
/// <param name="properties"></param>
/// <returns></returns>
public static ILobby OneVsOne(LobbiesPlugin plugin, Dictionary<string, string> properties, IPeer creator)
public static Lobby OneVsOne(LobbiesPlugin plugin, Dictionary<string, string> properties, IPeer creator)
{
// Create the teams
var teamA = new LobbyTeam("Team Blue")
Expand All @@ -41,7 +39,7 @@ public static ILobby OneVsOne(LobbiesPlugin plugin, Dictionary<string, string> p
var config = new LobbyConfig();

// Create the lobby
var lobby = new BaseLobby(plugin.GenerateLobbyId(),
var lobby = new Lobby(plugin.GenerateLobbyId(),
new[] { teamA, teamB }, plugin, config)
{
Name = ExtractLobbyName(properties)
Expand Down Expand Up @@ -75,7 +73,7 @@ public static ILobby OneVsOne(LobbiesPlugin plugin, Dictionary<string, string> p
/// <param name="plugin"></param>
/// <param name="properties"></param>
/// <returns></returns>
public static ILobby Deathmatch(LobbiesPlugin plugin, Dictionary<string, string> properties, IPeer creator)
public static Lobby Deathmatch(LobbiesPlugin plugin, Dictionary<string, string> properties, IPeer creator)
{
// Create the teams
var team = new LobbyTeam("")
Expand All @@ -87,7 +85,7 @@ public static ILobby Deathmatch(LobbiesPlugin plugin, Dictionary<string, string>
var config = new LobbyConfig();

// Create the lobby
var lobby = new BaseLobby(plugin.GenerateLobbyId(),
var lobby = new Lobby(plugin.GenerateLobbyId(),
new[] { team }, plugin, config)
{
Name = ExtractLobbyName(properties)
Expand All @@ -114,7 +112,7 @@ public static ILobby Deathmatch(LobbiesPlugin plugin, Dictionary<string, string>
/// <param name="plugin"></param>
/// <param name="properties"></param>
/// <returns></returns>
public static ILobby TwoVsTwoVsFour(LobbiesPlugin plugin, Dictionary<string, string> properties, IPeer creator)
public static Lobby TwoVsTwoVsFour(LobbiesPlugin plugin, Dictionary<string, string> properties, IPeer creator)
{
// Create the teams
var teamA = new LobbyTeam("Team Blue")
Expand Down Expand Up @@ -142,7 +140,7 @@ public static ILobby TwoVsTwoVsFour(LobbiesPlugin plugin, Dictionary<string, str
var config = new LobbyConfig();

// Create the lobby
var lobby = new BaseLobby(plugin.GenerateLobbyId(),
var lobby = new Lobby(plugin.GenerateLobbyId(),
new[] { teamA, teamB, teamC }, plugin, config)
{
Name = ExtractLobbyName(properties)
Expand Down Expand Up @@ -178,7 +176,7 @@ public static ILobby TwoVsTwoVsFour(LobbiesPlugin plugin, Dictionary<string, str
/// <param name="plugin"></param>
/// <param name="properties"></param>
/// <returns></returns>
public static ILobby ThreeVsThreeQueue(LobbiesPlugin plugin, Dictionary<string, string> properties, IPeer creator)
public static Lobby ThreeVsThreeQueue(LobbiesPlugin plugin, Dictionary<string, string> properties, IPeer creator)
{
// Create the teams
var teamA = new LobbyTeam("Team Blue")
Expand All @@ -203,7 +201,7 @@ public static ILobby ThreeVsThreeQueue(LobbiesPlugin plugin, Dictionary<string,
};

// Create the lobby
var lobby = new BaseLobbyAuto(plugin.GenerateLobbyId(),
var lobby = new LobbyAuto(plugin.GenerateLobbyId(),
new[] { teamA, teamB }, plugin, config)
{
Name = ExtractLobbyName(properties)
Expand Down
44 changes: 0 additions & 44 deletions SpeedDate.ServerPlugins/Lobbies/ILobby.cs

This file was deleted.

2 changes: 1 addition & 1 deletion SpeedDate.ServerPlugins/Lobbies/ILobbyFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ public interface ILobbyFactory
{
string Id { get; }

ILobby CreateLobby(Dictionary<string, string> properties, IPeer creator);
Lobby CreateLobby(Dictionary<string, string> properties, IPeer creator);
}
}
8 changes: 4 additions & 4 deletions SpeedDate.ServerPlugins/Lobbies/LobbiesPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public sealed class LobbiesPlugin : SpeedDateServerPlugin, IGamesProvider
private readonly Dictionary<string, ILobbyFactory> _factories = new Dictionary<string, ILobbyFactory>();
[Inject] private readonly ILogger _logger;

public readonly Dictionary<int, ILobby> Lobbies = new Dictionary<int, ILobby>();
public readonly Dictionary<int, Lobby> Lobbies = new Dictionary<int, Lobby>();
[Inject] internal readonly RoomsPlugin RoomsPlugin;
[Inject] internal readonly SpawnerPlugin SpawnerPlugin;

Expand Down Expand Up @@ -78,7 +78,7 @@ public void AddFactory(ILobbyFactory factory)
_factories[factory.Id] = factory;
}

public bool AddLobby(ILobby lobby)
public bool AddLobby(Lobby lobby)
{
if (Lobbies.ContainsKey(lobby.Id))
{
Expand All @@ -96,7 +96,7 @@ public bool AddLobby(ILobby lobby)
/// Invoked, when lobby is destroyed
/// </summary>
/// <param name="lobby"></param>
private void OnLobbyDestroyed(ILobby lobby)
private void OnLobbyDestroyed(Lobby lobby)
{
Lobbies.Remove(lobby.Id);
lobby.Destroyed -= OnLobbyDestroyed;
Expand Down Expand Up @@ -410,7 +410,7 @@ private void HandleGetLobbyInfo(IIncommingMessage message)
message.Respond(lobby.GenerateLobbyData(), ResponseStatus.Success);
}

public Dictionary<string, string> GetPublicLobbyProperties(IPeer peer, ILobby lobby,
public Dictionary<string, string> GetPublicLobbyProperties(IPeer peer, Lobby lobby,
Dictionary<string, string> playerFilters)
{
return lobby.GetPublicProperties(peer);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
using SpeedDate.ServerPlugins.Rooms;
using SpeedDate.ServerPlugins.Spawner;

namespace SpeedDate.ServerPlugins.Lobbies.Implementations
namespace SpeedDate.ServerPlugins.Lobbies
{
class BaseLobby : ILobby
public class Lobby
{
private LobbyState _state;
private LobbyMember _gameMaster;
Expand All @@ -23,9 +23,9 @@ class BaseLobby : ILobby
public event Action<LobbyMember> PlayerAdded;
public event Action<LobbyMember> PlayerRemoved;

public event Action<ILobby> Destroyed;
public event Action<Lobby> Destroyed;

public readonly Logger Logger = LogManager.GetLogger(typeof(BaseLobby).Name);
public readonly Logger Logger = LogManager.GetLogger(typeof(Lobby).Name);

protected readonly Dictionary<string, LobbyMember> Members;
protected readonly Dictionary<long, LobbyMember> MembersByPeerId;
Expand All @@ -38,7 +38,7 @@ class BaseLobby : ILobby
protected SpawnTask GameSpawnTask;
protected RegisteredRoom Room;

public BaseLobby(int lobbyId, IEnumerable<LobbyTeam> teams, LobbiesPlugin plugin, LobbyConfig config)
public Lobby(int lobbyId, IEnumerable<LobbyTeam> teams, LobbiesPlugin plugin, LobbyConfig config)
{
Id = lobbyId;
Plugin = plugin;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
using System.Threading.Tasks;
using SpeedDate.Packets.Lobbies;

namespace SpeedDate.ServerPlugins.Lobbies.Implementations
namespace SpeedDate.ServerPlugins.Lobbies
{
class BaseLobbyAuto : BaseLobby
class LobbyAuto : Lobby
{
public const float WaitSecondsAfterMinPlayersReached = 10;
public const float WaitSecondsAfterFullTeams = 5;

public BaseLobbyAuto(int lobbyId, IEnumerable<LobbyTeam> teams, LobbiesPlugin plugin, LobbyConfig config) : base(lobbyId, teams, plugin, config)
public LobbyAuto(int lobbyId, IEnumerable<LobbyTeam> teams, LobbiesPlugin plugin, LobbyConfig config) : base(lobbyId, teams, plugin, config)
{
config.EnableManualStart = true;
config.PlayAgainEnabled = false;
Expand Down
5 changes: 2 additions & 3 deletions SpeedDate.ServerPlugins/Lobbies/LobbyFactoryAnonymous.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Collections.Generic;
using SpeedDate.Interfaces;
using SpeedDate.Network.Interfaces;

namespace SpeedDate.ServerPlugins.Lobbies
Expand All @@ -13,7 +12,7 @@ public class LobbyFactoryAnonymous : ILobbyFactory
private readonly LobbiesPlugin _plugin;
private readonly LobbyCreationFactory _factory;

public delegate ILobby LobbyCreationFactory(LobbiesPlugin plugin, Dictionary<string, string> properties, IPeer creator);
public delegate Lobby LobbyCreationFactory(LobbiesPlugin plugin, Dictionary<string, string> properties, IPeer creator);

public LobbyFactoryAnonymous(string id, LobbiesPlugin plugin, LobbyCreationFactory factory)
{
Expand All @@ -22,7 +21,7 @@ public LobbyFactoryAnonymous(string id, LobbiesPlugin plugin, LobbyCreationFacto
_plugin = plugin;
}

public ILobby CreateLobby(Dictionary<string, string> properties, IPeer creator)
public Lobby CreateLobby(Dictionary<string, string> properties, IPeer creator)
{
var lobby = _factory.Invoke(_plugin, properties, creator);

Expand Down
4 changes: 2 additions & 2 deletions SpeedDate.ServerPlugins/Lobbies/LobbyUserExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ namespace SpeedDate.ServerPlugins.Lobbies
{
public class LobbyUserExtension
{
public IPeer Peer { get; private set; }
public IPeer Peer { get; }

/// <summary>
/// Lobby, to which current peer belongs
/// </summary>
public ILobby CurrentLobby { get; set; }
public Lobby CurrentLobby { get; set; }

public LobbyUserExtension(IPeer peer)
{
Expand Down
4 changes: 2 additions & 2 deletions SpeedDate.Test/SetUp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ namespace SpeedDate.Test
public class SetUp
{
public static readonly IPAddress MasterServerIp = IPAddress.Loopback;
public const int MasterServerPort = 60125;
public const string GuestPrefix = "Guest-";
public const int MasterServerPort = 12345;
public const string GuestPrefix = "TestGuest-";
public const string TestAccountPassword = "testPassword";

public static readonly AccountData TestAccount = new AccountData
Expand Down

0 comments on commit dfd0652

Please sign in to comment.