public RoomData() { ID = ""; Password = ""; Owner = new PlayerData(); Players = new List<PlayerData>(); GameStarted = false; }
public Player(string playerName, IWebSocketConnection socket, Settings settings) { Settings = settings; Socket = socket; Data = new PlayerData(); Data.Name = playerName; Data.ID = Guid.NewGuid().ToString(); socket.OnClose += () => { if (OnConnectionClosed != null) OnConnectionClosed(this, new PlayerConnectionClosed(this, PlayerCloseReason.Disconnected)); }; socket.OnMessage += (json) => OnRecieveMessage(json); socket.OnBinary += (bytes) => OnRecieveMessage(Encoding.UTF8.GetString(bytes)); }
public RequestRoomList(PlayerData playerInfo) { }
public LeaveRoom(PlayerData playerInfo) { }
public void UpdatePlayerInfo(PlayerData playerData) { var message = new ServerMessage.UpdatePlayerInfo(playerData); Socket.Send(message.AsJson()); }
public UpdatePlayerInfo(PlayerData playerData) { PlayerData = playerData; }
public SendChoices(PlayerData creator, List<AnswerData> choices) { Creator = creator; Choices = choices; }
public bool HasPlayer(PlayerData player) { return Players.Exists(x => x.Data.ID == player.ID); }
void EchoActionToAll(PlayerData actor, PlayerAction action) { Logger.Log(this, "{0} ({1})", actor.Name, action); Players.ForEach(x => x.SendAction(actor, action, PlayerActionContext.Room)); }
// Replaces any tokens such as "random player name" appropriately replaced. public string ReplaceTokens(PlayerData player, List<PlayerData> players) { // TODO: Move somewhere more appropriate. var tokenPlayerName = "<RANDOM_PLAYER_NAME>"; if (Text.Contains(tokenPlayerName)) { // Replace with random player that isn't this player var playersExceptOwner = players.Where(x => x != player).ToList(); var rnd = new Random().Next(playersExceptOwner.Count); Text = Text.Replace(tokenPlayerName, playersExceptOwner[rnd].Name.ToLower()); } return Text; }
public AnswerData(PlayerData author, string answer) : this() { Author = author; Answer = answer; }
public AnswerData() { Author = new PlayerData(); Answer = string.Empty; Choosers = new List<PlayerData>(); }
public void NotifyPlayerGameAction(PlayerData actor, GamePlayerAction action) { var message = new ServerMessage.Game.PlayerAction(actor, action); Socket.Send(message.AsJson()); }
public void SendChoices(PlayerData creator, List<AnswerData> answers) { var message = new ServerMessage.Game.SendChoices(creator, answers); Socket.Send(message.AsJson()); }
public void SendChat(PlayerData player, string chat) { var message = new ServerMessage.NotifyChatMessage(player, chat); Socket.Send(message.AsJson()); }
Room FindRoomContainingPlayer(PlayerData player) { return Rooms.Find(x => x.HasPlayer(player)); }
public void Leave(PlayerData leavingPlayer, RoomLeaveReason reason = RoomLeaveReason.Normal) { var player = Players.Find(x => x.Data.ID == leavingPlayer.ID); player.SendRoomLeaveReason(reason); OnPlayerConnectionClosed(this, new PlayerConnectionClosed(player, PlayerCloseReason.Left)); }
public DrawingData(PlayerData creator, byte[] image, PromptData prompt) { Creator = creator; Image = Convert.ToBase64String(image); Prompt = prompt; }
bool IsOwner(PlayerData player) { return Owner.Data.ID == player.ID; }
public SendAction(PlayerData player, GameAction action) { Player = player; Action = action; }
public NotifyPlayerAction(PlayerData player, PlayerAction action, PlayerActionContext context) { Player = player; Action = action; Context = context; }
public CreateRoom(PlayerData playerInfo, string password) { Password = password; }
public PlayerAction(PlayerData actor, GamePlayerAction action) { Actor = actor; Action = action; }
public JoinRoom(PlayerData playerInfo, string roomId, string password = "") { RoomId = roomId; Password = password; }
public NotifyChatMessage(PlayerData player, string message) { Player = player; Message = message; }
/// <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()); }