Exemplo n.º 1
0
        public async Task ReplicateToClients(string message, List <ChatUser> chatUsers)
        {
            var relevantChatUsers = new List <ChatUserDTO>();

            foreach (var chatUser in chatUsers)
            {
                relevantChatUsers.Add(new ChatUserDTO
                {
                    ChatUserId = chatUser.UserId,
                    Platform   = chatUser.Platform
                });
            }
            var serverResponse = new MUDServerResponse
            {
                ServerAuthToken   = "TestToken",
                RelevantChatUsers = relevantChatUsers,
                Response          = message
            };
            var responseMessage = JsonConvert.SerializeObject(serverResponse);

            await _messageHubContext.Clients.All.SendAsync("Send", responseMessage);
        }
Exemplo n.º 2
0
        public async Task Send(string message)
        {
            var clientMessage = JsonConvert.DeserializeObject <MUDClientMessage>(message);

            var response = await _mudHelper.ProcessPlayerInput(clientMessage.Message, clientMessage.ChatUserId, clientMessage.ChatUsername, clientMessage.Platform);

            if (response != "")
            {
                var relevantChatUsers = new List <ChatUserDTO>();
                relevantChatUsers.Add(new ChatUserDTO
                {
                    ChatUserId = clientMessage.ChatUserId,
                    Platform   = clientMessage.Platform
                });
                var serverResponse = new MUDServerResponse
                {
                    ServerAuthToken   = "TestToken",
                    RelevantChatUsers = relevantChatUsers,
                    Response          = response
                };
                var responseMessage = JsonConvert.SerializeObject(serverResponse);
                await Clients.All.SendAsync("Send", responseMessage);
            }
        }