public void OnAnswerReceived(HostCommandData commandData, Guid guid) { AnswerReceived(this, new AnswerReceivedEventArgs { PlayerName = commandData.PlayerName, AnswerIndex = (int)commandData.Data }); }
public void OnPlayerDeparted(HostCommandData commandData, Guid guid) { PlayerDeparted(this, new PlayerEventArgs { PlayerName = commandData.PlayerName }); _manager.RemoveParticipant(guid); _playerToParticipantMap.Remove(commandData.PlayerName); }
public void OnPlayerDeparted(HostCommandData commandData, Guid guid) { this.PlayerDeparted(this, new PlayerEventArgs { PlayerName = commandData.PlayerName }); this.PlayerMap.Remove(commandData.PlayerName); this.Host.RemoveClient(guid); }
private async Task OnPlayerJoined(HostCommandData commandData, Guid guid) { Guid duplicatePlayerID; if (!this.PlayerMap.TryGetValue(commandData.PlayerName, out duplicatePlayerID)) { this.PlayerMap.Add(commandData.PlayerName, guid); this.PlayerJoined(this, new PlayerEventArgs { PlayerName = commandData.PlayerName }); await this.SendJoinStatusMessageToPlayer(guid, true); } else { await this.SendJoinStatusMessageToPlayer(guid, false); } }
/// <summary> /// When a message is received from the participant, this method will attempt to add the participant and send a join status message /// back indicating whether the participant was added successfully. /// </summary> private async Task OnPlayerJoinedAsync(HostCommandData commandData, Guid guid) { Guid duplicatePlayerID; if (!_playerToParticipantMap.TryGetValue(commandData.PlayerName, out duplicatePlayerID)) { _playerToParticipantMap.Add(commandData.PlayerName, guid); PlayerJoined(this, new PlayerEventArgs { PlayerName = commandData.PlayerName }); await SendJoinStatusMessageToPlayerAsync(guid, true); } else { await SendJoinStatusMessageToPlayerAsync(guid, false); } }
public HostCommunicator() { _manager.ParticipantConnected += (async(sender, e) => { // A player has joined the game. _participantCommunicationChannels.Add(_manager.CreateCommunicationChannel(e.Id)); HostCommandData data = new HostCommandData { PlayerName = e.Message.ToString(), Data = null, Command = Command.Join }; await OnPlayerJoinedAsync(data, e.Id); }); _managerCommunicationChannel.MessageReceived += ((sender, e) => { // Decode the message. The command of the message is the first phrase before a '-' character. string[] message = e.Message.ToString().Split('-'); switch (message[0]) { case LEAVE_COMMAND: // The participant sent a message to leave the game. OnPlayerDeparted( new HostCommandData { PlayerName = message[1], Command = Command.Leave, }, _playerToParticipantMap[message[1]]); break; case ANSWER_COMMAND: // The participant sent a message to answer a question. OnAnswerReceived( new HostCommandData { PlayerName = message[1], Command = Command.Answer, Data = int.Parse(message[2]) }, _playerToParticipantMap[message[1]]); break; } }); }
public void OnAnswerReceived(HostCommandData commandData, Guid guid) { this.AnswerReceived(this, new AnswerReceivedEventArgs { PlayerName = commandData.PlayerName, AnswerIndex = (int)commandData.Data }); }
public HostCommunicator() { _manager.ParticipantConnected += (async (sender, e) => { // A player has joined the game. _participantCommunicationChannels.Add(_manager.CreateCommunicationChannel(e.Id)); HostCommandData data = new HostCommandData { PlayerName = e.Message.ToString(), Data = null, Command = Command.Join }; await OnPlayerJoinedAsync(data, e.Id); }); _managerCommunicationChannel.MessageReceived += ((sender, e) => { // Decode the message. The command of the message is the first phrase before a '-' character. string[] message = e.Message.ToString().Split('-'); switch (message[0]) { case LEAVE_COMMAND: // The participant sent a message to leave the game. OnPlayerDeparted( new HostCommandData { PlayerName = message[1], Command = Command.Leave, }, _playerToParticipantMap[message[1]]); break; case ANSWER_COMMAND: // The participant sent a message to answer a question. OnAnswerReceived( new HostCommandData { PlayerName = message[1], Command = Command.Answer, Data = int.Parse(message[2]) }, _playerToParticipantMap[message[1]]); break; } }); }