More organized communication strategy.

This commit is contained in:
2021-02-13 19:14:43 -06:00
parent 1826c07601
commit d76e4f7a8b
13 changed files with 212 additions and 173 deletions

View File

@@ -28,7 +28,6 @@ namespace Gameboard.ShogiUI.Sockets.Managers.ClientActionHandlers
public async Task Handle(WebSocket socket, string json, string userName)
{
logger.LogInformation("Socket Request \n{0}\n", new[] { json });
var request = JsonConvert.DeserializeObject<CreateGameRequest>(json);
var postSessionResponse = await repository.PostSession(new PostSession
{
@@ -43,7 +42,7 @@ namespace Gameboard.ShogiUI.Sockets.Managers.ClientActionHandlers
Game = new Game
{
GameName = postSessionResponse.SessionName,
Players = new string[] { userName }
Players = new[] { userName }
}
};
@@ -52,15 +51,15 @@ namespace Gameboard.ShogiUI.Sockets.Managers.ClientActionHandlers
response.Error = "Game already exists.";
}
var serialized = JsonConvert.SerializeObject(response);
logger.LogInformation("Socket Response \n{0}\n", new[] { serialized });
if (request.IsPrivate)
{
var serialized = JsonConvert.SerializeObject(response);
logger.LogInformation("Response to {0} \n{1}\n", userName, serialized);
await socket.SendTextAsync(serialized);
}
else
{
await communicationManager.BroadcastToAll(serialized);
await communicationManager.BroadcastToAll(response);
}
}
}