void OnServerNotifyPlayerAction(ServerMessage.NotifyPlayerAction message) { if (message.Context == PlayerActionContext.Room) { AddMessage(StringFormatter.FormatPlayerAction(message, Client.Connection.Player)); } }
public static string FormatPlayerAction(ServerMessage.NotifyPlayerAction message, PlayerData player) { // Determine if message is about self. string owner = message.Player.ID == player.ID ? "You" : message.Player.Name; bool isAboutSelf = message.Player.ID == player.ID; switch (message.Action) { case PlayerAction.None: break; case PlayerAction.Connected: return(string.Format("{0} connected.", owner)); case PlayerAction.Disconnected: return(string.Format("{0} disconnected.", owner)); case PlayerAction.Kicked: break; case PlayerAction.Joined: return(string.Format("{0} joined the room.", owner)); case PlayerAction.Left: return(string.Format("{0} left.", owner)); case PlayerAction.PromotedToOwner: if (isAboutSelf) { return(string.Format("{0} are now the room owner.", owner)); } else { return(string.Format("{0} is now the room owner.", owner)); } default: break; } return(""); }
/// <summary> /// Sends a message to the player about a particular action. /// </summary> /// <param name="actor">The player that committed the action.</param> /// <param name="action">The type of action.</param> public void SendAction(PlayerData actor, PlayerAction action, PlayerActionContext context) { var message = new ServerMessage.NotifyPlayerAction(actor, action, context); Socket.Send(message.AsJson()); }