private async Task <String> InitSocket(WebSocket socket, HttpContext context) { var auth = await context.AuthenticateAsync(); String id; if (auth.Succeeded && auth.Principal.Identity.IsAuthenticated) { Player user = await userManager.GetUserAsync(auth.Principal); id = manager.AddSocket(socket, user.Name); if (id == null) { await CloseConnection(user.Name, manager.GetSocketById(user.Name)); id = manager.AddSocket(socket, user.Name); } } else { id = manager.AddSocket(socket, "Player " + manager.ID++); } var json = JsonConvert.SerializeObject(new ServerResponse() { Type = "Credentials", Value = id }); await WebSocketHelper.Send(json, socket); return(id); }
public static WebSocket[] GetPlayerSockets(GameDataModel game, WebSocketManager manager) { var players = game.PlayerIDs.Split(","); var playerCount = CountPlayers(players); WebSocket[] playerSockets = new WebSocket[playerCount]; for (int i = 0; i < playerSockets.Length; i++) { playerSockets[i] = manager.GetSocketById(players[i]); } return(playerSockets); }