/// <summary> /// Constructs lobby data /// </summary> /// <param name="lobbyCode">Lobby code</param> /// <param name="name">Lobby name</param> /// <param name="gameMode">Game mode</param> /// <param name="isPrivate">Is lobby private</param> /// <param name="minimalUserCount">Minimal user count in lobby</param> /// <param name="maximalUserCount">Maximal user count in lobby</param> /// <param name="isStartingGameAutomatically">Is starting game automatically in lobby</param> /// <param name="gameModeRules">Game mode rules</param> /// <param name="userCount">User count in lobby</param> public LobbyData(string lobbyCode, string name, string gameMode, bool isPrivate, uint minimalUserCount, uint maximalUserCount, bool isStartingGameAutomatically, IReadOnlyDictionary <string, object> gameModeRules, uint userCount) { if (gameModeRules == null) { throw new ArgumentNullException(nameof(gameModeRules)); } if (!Protection.IsValid(gameModeRules)) { throw new ArgumentException($"\"Game mode rules is not valid.", nameof(gameModeRules)); } if (string.IsNullOrWhiteSpace(gameMode)) { throw new ArgumentException($"Game mode is unknown.", nameof(gameMode)); } LobbyCode = lobbyCode ?? throw new ArgumentNullException(nameof(lobbyCode)); Name = name ?? throw new ArgumentNullException(nameof(name)); GameMode = gameMode; IsPrivate = isPrivate; MinimalUserCount = minimalUserCount; MaximalUserCount = maximalUserCount; IsStartingGameAutomatically = isStartingGameAutomatically; GameModeRules = new Dictionary <string, object>(); foreach (KeyValuePair <string, object> game_mode_rule in gameModeRules) { if (game_mode_rule.Value == null) { throw new ArgumentException($"Value of game mode rule key \"{ game_mode_rule.Key }\" is null.", nameof(gameModeRules)); } GameModeRules.Add(game_mode_rule.Key, game_mode_rule.Value); } UserCount = userCount; }
/// <summary> /// Constructs a client tick message /// </summary> /// <param name="entities">Entities (optional)</param> /// <param name="hits">Hits (optional)</param> public ClientTickMessageData(IEnumerable <IEntityDelta> entities = null, IEnumerable <IHit> hits = null) : base(Naming.GetMessageTypeNameFromMessageDataType <ClientTickMessageData>()) { if ((entities != null) && !Protection.IsValid(entities)) { throw new ArgumentException("Entities contains invalid entities.", nameof(entities)); } if ((hits != null) && !Protection.IsValid(hits)) { throw new ArgumentException("Hits contains invalid hits.", nameof(hits)); } if (entities != null) { Entities = new List <EntityData>(); foreach (IEntityDelta entity in entities) { Entities.Add(new EntityData(entity.GUID, entity.EntityType, entity.GameColor, entity.IsSpectating, entity.Position, entity.Rotation, entity.Velocity, entity.AngularVelocity, entity.Actions, entity.IsResyncRequested)); } } if (hits != null) { foreach (IHit hit in hits) { if (hit.Issuer != null) { throw new ArgumentException("Hits can't specify issuers", nameof(hits)); } Hits = Hits ?? new List <ClientHitData>(); Hits.Add(new ClientHitData(hit)); } } }
/// <summary> /// Sets the new game actions of game entity /// </summary> /// <param name="newActions">New game entity game actions</param> /// <param name="isValueFromClient">Is value from client</param> /// <returns>Number of actions set</returns> public uint SetActions(IEnumerable <string> newActions, bool isValueFromClient) { if (!Protection.IsValid(newActions)) { throw new ArgumentException("Game actions can't contain invalid actions.", nameof(newActions)); } uint ret = 0U; if (isValueFromClient) { if (AreClientActionsSet) { ret = SetActionsInternally(newActions); } else { if (Actions is HashSet <string> actions) { AreClientActionsSet = actions.SetEquals(newActions); } else { HashSet <string> current_actions = new HashSet <string>(Actions); AreClientActionsSet = current_actions.SetEquals(newActions); current_actions.Clear(); } } } else { AreClientActionsSet = false; ret = SetActionsInternally(newActions); } return(ret); }
/// <summary> /// Constructs a server tick message /// </summary> /// <param name="time">Time</param> /// <param name="entityDeltas">Entities to update</param> /// <param name="hits">Hits</param> public ServerTickMessageData(double time, IEnumerable <IEntityDelta> entityDeltas, IEnumerable <IHit> hits) : base(Naming.GetMessageTypeNameFromMessageDataType <ServerTickMessageData>()) { if (time < 0.0) { throw new ArgumentException("Time must be positive.", nameof(time)); } if (entityDeltas == null) { throw new ArgumentNullException(nameof(entityDeltas)); } if (!Protection.IsValid(entityDeltas)) { throw new ArgumentException("Entity deltas contain invalid entity deltas.", nameof(entityDeltas)); } if ((hits != null) && !Protection.IsValid(hits)) { throw new ArgumentException("Hits contain invalid hits.", nameof(hits)); } Time = time; Entities = new List <EntityData>(); foreach (IEntityDelta entity_delta in entityDeltas) { Entities.Add(new EntityData(entity_delta.GUID, entity_delta.EntityType, entity_delta.GameColor, entity_delta.IsSpectating, entity_delta.Position, entity_delta.Rotation, entity_delta.Velocity, entity_delta.AngularVelocity, entity_delta.Actions, entity_delta.IsResyncRequested)); } if (hits != null) { foreach (IHit hit in hits) { Hits = Hits ?? new List <ServerHitData>(); Hits.Add(new ServerHitData(hit)); } } }
/// <summary> /// Constructs a list available game mode results message /// </summary> /// <param name="gameModes"></param> public ListAvailableGameModeResultsMessageData(IEnumerable <string> gameModes) : base(Naming.GetMessageTypeNameFromMessageDataType <ListAvailableGameModeResultsMessageData>()) { if (!Protection.IsValid(gameModes)) { throw new ArgumentException("Game modes are not valid.", nameof(gameModes)); } GameModes = new List <string>(gameModes); }
/// <summary> /// Constructs game message data /// </summary> /// <param name="type">Game message type</param> /// <param name="data">Game message data</param> public GameMessageData(string type, T data) : base(type) { if (data == null) { throw new ArgumentNullException(nameof(data)); } if (!Protection.IsValid(data)) { throw new ArgumentException("Data is not valid.", nameof(data)); } Data = data; }
/// <summary> /// Constructs a message that contains a result set for listing lobbies /// </summary> /// <param name="lobbies">Lobbies</param> public ListLobbyResultsMessageData(IEnumerable <ILobbyView> lobbies) : base(Naming.GetMessageTypeNameFromMessageDataType <ListLobbyResultsMessageData>()) { if (!Protection.IsValid(lobbies)) { throw new ArgumentException($"Lobbies are not valid.", nameof(lobbies)); } Lobbies = new List <LobbyData>(); foreach (ILobbyView lobby in lobbies) { Lobbies.Add(new LobbyData(lobby.LobbyCode, lobby.Name, lobby.GameMode, lobby.IsPrivate, lobby.MinimalUserCount, lobby.MaximalUserCount, lobby.IsStartingGameAutomatically, lobby.GameModeRules, lobby.UserCount)); } }
/// <summary> /// Constructs lobby rules data /// </summary> /// <param name="lobbyCode">Lobby code</param> /// <param name="name">Lobby name</param> /// <param name="gameMode">Game mode</param> /// <param name="isPrivate">Is lobby private</param> /// <param name="minimalUserCount">Minimal user count in lobby</param> /// <param name="maximalUserCount">Maximal user count in lobby</param> /// <param name="isStartingGameAutomatically">Is starting game automatically in lobby</param> /// <param name="gameModeRules">Game mode rules</param> public LobbyRulesData(string lobbyCode, string name, string gameMode, bool isPrivate, uint minimalUserCount, uint maximalUserCount, bool isStartingGameAutomatically, Dictionary <string, object> gameModeRules) { if (gameModeRules == null) { throw new ArgumentNullException(nameof(gameModeRules)); } if (!Protection.IsValid(gameModeRules.Values)) { throw new ArgumentException($"Game mode rules are not value.", nameof(gameModeRules)); } if (string.IsNullOrWhiteSpace(gameMode)) { throw new ArgumentException($"Game mode is unknown.", nameof(gameMode)); } LobbyCode = lobbyCode ?? throw new ArgumentNullException(nameof(lobbyCode)); Name = name ?? throw new ArgumentNullException(nameof(name)); GameMode = gameMode; IsPrivate = isPrivate; MinimalUserCount = minimalUserCount; MaximalUserCount = maximalUserCount; IsStartingGameAutomatically = isStartingGameAutomatically; GameModeRules = gameModeRules; }