コード例 #1
0
        public override async Task OnConnected(HttpContext context, WebSocket socket)
        {
            string name = "Nome";

            if (!string.IsNullOrEmpty(name) && salaService.GetPlayers().Count < 6)
            {
                WebSocketConnectionManager.AddSocket(socket);
                var jogador = salaService.AdicionarJogador(WebSocketConnectionManager.GetId(socket), name);
                await SendMessageAsync(WebSocketConnectionManager.GetId(socket), JsonConvert.SerializeObject(jogador.ToJogadorViewItem()));

                // await GetPlayers();
            }
        }
コード例 #2
0
        public override async Task ReceiveAsync(WebSocket socket, WebSocketReceiveResult result, byte[] buffer)
        {
            string message       = Encoding.UTF8.GetString(buffer, 0, result.Count);
            var    comandPayload = message.Split("|");

            if (comandPayload.Count() == 2)
            {
                if (comandPayload[0].Contains("pronto"))
                {
                    salaService.SetReady(WebSocketConnectionManager.GetId(socket));
                    await GetPlayers();
                }
                else
                {
                    await SendMessageToAllAsync(message);
                }
            }
        }
コード例 #3
0
 public WebSocketHandler(WebSocketConnectionManager webSocketConnectionManager)
 {
     WebSocketConnectionManager = webSocketConnectionManager;
 }
コード例 #4
0
 public RoomHandler(WebSocketConnectionManager webSocketConnectionManager, ISalaService salaService) : base(webSocketConnectionManager)
 {
     this.salaService = salaService;
 }