Skip to content

Commit

Permalink
feat(game-service): close connection if max connections
Browse files Browse the repository at this point in the history
  • Loading branch information
codingben committed Apr 13, 2023
1 parent d84e0b9 commit 1bfb630
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/game-service/Game.Application/GameApplication.cs
Expand Up @@ -15,6 +15,7 @@
var fleckLog = Env.GetString("FLECK_LOG");
var imLog = Env.GetString("IM_LOG");
var gameLog = Env.GetString("GAME_LOG");
var maxConnections = Env.GetInt("MAX_CONNECTIONS");

FleckLog.LogAction = FleckLogAction.LogAction;
FleckLog.Level = (LogLevel)Enum.Parse(typeof(LogLevel), fleckLog);
Expand All @@ -26,7 +27,7 @@
var serverComponents = new ComponentCollection(new IComponent[]
{
new IdGenerator(),
new GameClientCollection(),
new GameClientCollection(maxConnections),
new GameSceneCollection(),
new GameSceneManager()
});
Expand All @@ -48,6 +49,10 @@
connection,
gameClientCollection,
gameSceneCollection);
if (gameClientCollection.Add(gameClient) == false)
{
connection.Close();
gameClientCollection.Add(gameClient);
GameLog.Debug($"Client #{id} disconnected because server reached maximum number of clients.");
}
});

0 comments on commit 1bfb630

Please sign in to comment.