GameserverConstructor -> GameServerFactory

This commit is contained in:
Mooshua 2023-08-13 11:46:58 -07:00
parent 94fc8a025e
commit fe0bb9e04a
3 changed files with 12 additions and 6 deletions

View File

@ -707,7 +707,7 @@ namespace BattleBitAPI.Server
}
// ---- Static ----
public static TGameServer CreateInstance<TGameServer>(Internal @internal, GameserverConstructor<TGameServer, TPlayer> constructor) where TGameServer : GameServer<TPlayer>
public static TGameServer CreateInstance<TGameServer>(Internal @internal, GameServerFactory<TGameServer, TPlayer> constructor) where TGameServer : GameServer<TPlayer>
{
var gameServer = constructor.Create();
gameServer.mInternal = @internal;

View File

@ -1,10 +1,16 @@
namespace BattleBitAPI.Server;
public class GameserverConstructor<TGameServer, TPlayer>
public class GameServerFactory<TGameServer, TPlayer>
where TGameServer: GameServer<TPlayer>
where TPlayer: Player<TPlayer>
{
/// <summary>
/// Create a new gameserver instance.
/// This will be whatever type you want to handle incoming
/// events for a connecting gameserver.
/// </summary>
/// <returns></returns>
public virtual TGameServer Create()
{
TGameServer gameServer = (TGameServer)Activator.CreateInstance(typeof(TGameServer));

View File

@ -67,10 +67,10 @@ namespace BattleBitAPI.Server
private mInstances<TPlayer, TGameServer> mInstanceDatabase;
// --- Construction ---
public ServerListener(GameserverConstructor<TGameServer, TPlayer> constructor = null)
public ServerListener(GameServerFactory<TGameServer, TPlayer> constructor = null)
{
this.mActiveConnections = new Dictionary<ulong, (TGameServer, GameServer<TPlayer>.Internal)>(16);
this.mInstanceDatabase = new mInstances<TPlayer, TGameServer>(constructor ?? new GameserverConstructor<TGameServer, TPlayer>());
this.mInstanceDatabase = new mInstances<TPlayer, TGameServer>(constructor ?? new GameServerFactory<TGameServer, TPlayer>());
}
// --- Starting ---
@ -1059,9 +1059,9 @@ namespace BattleBitAPI.Server
{
private Dictionary<ulong, (TGameServer, GameServer<TPlayer>.Internal)> mGameServerInstances;
private Dictionary<ulong, TPlayer> mPlayerInstances;
private GameserverConstructor<TGameServer, TPlayer> _constructor;
private GameServerFactory<TGameServer, TPlayer> _constructor;
public mInstances(GameserverConstructor<TGameServer, TPlayer> constructor)
public mInstances(GameServerFactory<TGameServer, TPlayer> constructor)
{
_constructor = constructor;
this.mGameServerInstances = new Dictionary<ulong, (TGameServer, GameServer<TPlayer>.Internal)>(64);