public void ValidVersion_ReturnsFalseIfVersionNotRegistered() { SetDebug(false); Versioned.Setup(false); Versioned.RegisterVersion(new Version(3, 1, 0, 0), DateTime.MinValue, ReleaseMode.Live); Versioned.Register <TestTypeBase>(); var val = Versioned.ValidVersion(new Version(3, 1, 0, 1)); Assert.False(val); }
public void ValidVersion_WorksProperlyForDeveloperMode() { SetDebug(true); Versioned.Setup(false); Versioned.RegisterVersion(new Version(3, 1, 0, 0), DateTime.MinValue, ReleaseMode.Live); Versioned.RegisterVersion(new Version(3, 1, 0, 1), DateTime.MinValue, ReleaseMode.Test); Versioned.Register <TestTypeBase>(); var val = Versioned.ValidVersion(new Version(3, 1, 0, 1)); Assert.True(val); }
public GameEngine(Game def, string nickname, bool specator, string password = "", bool isLocal = false) { History = new JodsEngineHistory(def.Id); if (Program.IsHost) { History.Name = Program.CurrentOnlineGameName; } ReplayWriter = new ReplayWriter(); LoadedCards = new ObservableDeck(); LoadedCards.Sections = new ObservableCollection <ObservableSection>(); DeckStats = new DeckStatsViewModel(); Spectator = specator; Program.GameMess.Clear(); if (def.ScriptVersion.Equals(new Version(0, 0, 0, 0))) { Program.GameMess.Warning("This game doesn't have a Script Version specified. Please contact the game developer.\n\n\nYou can get in contact of the game developer here {0}", def.GameUrl); def.ScriptVersion = new Version(3, 1, 0, 0); } if (Versioned.ValidVersion(def.ScriptVersion) == false) { Program.GameMess.Warning( "Can't find API v{0}. Loading the latest version.\n\nIf you have problems, get in contact of the developer of the game to get an update.\nYou can get in contact of them here {1}", def.ScriptVersion, def.GameUrl); def.ScriptVersion = Versioned.LowestVersion; } else { var vmeta = Versioned.GetVersion(def.ScriptVersion); if (vmeta.DeleteDate <= DateTime.Now) { Program.GameMess.Warning("This game requires an API version {0} which is no longer supported by OCTGN.\nYou can still play, however some aspects of the game may no longer function as expected, and it may be removed at any time.\nYou may want to contact the developer of this game and ask for an update.\n\nYou can find more information about this game at {1}." , def.ScriptVersion, def.GameUrl); } } //Program.ChatLog.ClearEvents(); IsLocal = isLocal; this.Password = password; Definition = def; _table = new Table(def.Table); if (def.Phases != null) { byte PhaseId = 1; _allPhases = def.Phases.Select(x => new Phase(PhaseId++, x)).ToList(); } GlobalVariables = new Dictionary <string, string>(); foreach (var varDef in def.GlobalVariables) { GlobalVariables.Add(varDef.Key, varDef.Value.Value); } ScriptApi = Versioned.Get <ScriptApi>(Definition.ScriptVersion); this.Nickname = nickname; while (String.IsNullOrWhiteSpace(this.Nickname)) { this.Nickname = Prefs.Nickname; if (string.IsNullOrWhiteSpace(this.Nickname)) { this.Nickname = Randomness.GrabRandomNounWord() + new Random().Next(30); } var retNick = this.Nickname; Application.Current.Dispatcher.Invoke(() => { var i = new InputDlg("Choose a nickname", "Choose a nickname", Nickname); retNick = i.GetString(); }); this.Nickname = retNick; } // Init fields CurrentUniqueId = 1; TurnNumber = 0; if (Definition.GameBoards.ContainsKey("")) { GameBoard = Definition.GameBoards[""]; } ActivePlayer = null; foreach (var size in Definition.CardSizes) { var front = ImageUtils.CreateFrozenBitmap(new Uri(size.Value.Front)); var back = ImageUtils.CreateFrozenBitmap(new Uri(size.Value.Back)); _cardFrontsBacksCache.Add(size.Value.Name, new Tuple <BitmapImage, BitmapImage>(front, back)); } Application.Current.Dispatcher.Invoke(new Action(() => { // clear any existing players Play.Player.All.Clear(); Player.Spectators.Clear(); // Create the global player, if any if (Definition.GlobalPlayer != null) { Play.Player.GlobalPlayer = new Play.Player(Definition, IsReplay); } // Create the local player Play.Player.LocalPlayer = new Player(Definition, this.Nickname, Program.UserId, 255, Crypto.ModExp(Prefs.PrivateKey), specator, true, IsReplay); })); }
public GameEngine(ReplayEngine replayEngine, Game def, string nickname) { ReplayEngine = replayEngine; IsReplay = true; LoadedCards = new ObservableDeck(); LoadedCards.Sections = new ObservableCollection <ObservableSection>(); DeckStats = new DeckStatsViewModel(); Spectator = false; Program.GameMess.Clear(); if (def.ScriptVersion.Equals(new Version(0, 0, 0, 0))) { Program.GameMess.Warning("This game doesn't have a Script Version specified. Please contact the game developer.\n\n\nYou can get in contact of the game developer here {0}", def.GameUrl); def.ScriptVersion = new Version(3, 1, 0, 0); } if (Versioned.ValidVersion(def.ScriptVersion) == false) { Program.GameMess.Warning( "Can't find API v{0}. Loading the latest version.\n\nIf you have problems, get in contact of the developer of the game to get an update.\nYou can get in contact of them here {1}", def.ScriptVersion, def.GameUrl); def.ScriptVersion = Versioned.LowestVersion; } else { var vmeta = Versioned.GetVersion(def.ScriptVersion); if (vmeta.DeleteDate <= DateTime.Now) { Program.GameMess.Warning("This game requires an API version {0} which is no longer supported by OCTGN.\nYou can still play, however some aspects of the game may no longer function as expected, and it may be removed at any time.\nYou may want to contact the developer of this game and ask for an update.\n\nYou can find more information about this game at {1}." , def.ScriptVersion, def.GameUrl); } } //Program.ChatLog.ClearEvents(); IsLocal = true; Definition = def; Password = string.Empty; _table = new Table(def.Table); if (def.Phases != null) { byte PhaseId = 1; _allPhases = def.Phases.Select(x => new Phase(PhaseId++, x)).ToList(); } GlobalVariables = new Dictionary <string, string>(); foreach (var varDef in def.GlobalVariables) { GlobalVariables.Add(varDef.Name, varDef.DefaultValue); } ScriptApi = Versioned.Get <ScriptApi>(Definition.ScriptVersion); this.Nickname = nickname; // Load all game markers foreach (DataNew.Entities.Marker m in Definition.GetAllMarkers()) { if (!_markersById.ContainsKey(m.Id)) { _markersById.Add(m.Id, m); } } // Init fields CurrentUniqueId = 1; TurnNumber = 0; GameBoard = Definition.GameBoards["Default"]; ActivePlayer = null; foreach (var size in Definition.CardSizes) { var front = ImageUtils.CreateFrozenBitmap(new Uri(size.Value.Front)); var back = ImageUtils.CreateFrozenBitmap(new Uri(size.Value.Back)); _cardFrontsBacksCache.Add(size.Key, new Tuple <BitmapImage, BitmapImage>(front, back)); } Application.Current.Dispatcher.Invoke(new Action(() => { // clear any existing players Play.Player.All.Clear(); Player.Spectators.Clear(); // Create the global player, if any if (Definition.GlobalPlayer != null) { Play.Player.GlobalPlayer = new Play.Player(Definition, IsReplay); } // Create the local player Play.Player.LocalPlayer = new Player(Definition, this.Nickname, Program.UserId, 255, Crypto.ModExp(Prefs.PrivateKey), false, true, IsReplay); IsConnected = true; })); }
public GameEngine(Game def, string nickname, bool specator, string password = "", bool isLocal = false) { Spectator = specator; Program.GameMess.Clear(); if (Versioned.ValidVersion(def.ScriptVersion) == false) { Program.GameMess.Warning( "Can't find API v{0}. Loading the latest version.\n\nIf you have problems, get in contact of the developer of the game to get an update.\nYou can get in contact of them here {1}", def.ScriptVersion, def.GameUrl); def.ScriptVersion = Versioned.LatestVersion; } //Program.ChatLog.ClearEvents(); IsLocal = isLocal; this.Password = password; _definition = def; _table = new Table(def.Table); Variables = new Dictionary <string, int>(); foreach (var varDef in def.Variables.Where(v => v.Global)) { Variables.Add(varDef.Name, varDef.Default); } GlobalVariables = new Dictionary <string, string>(); foreach (var varDef in def.GlobalVariables) { GlobalVariables.Add(varDef.Name, varDef.DefaultValue); } ScriptApi = Versioned.Get <ScriptApi>(Definition.ScriptVersion); this.Nickname = nickname; while (String.IsNullOrWhiteSpace(this.Nickname)) { this.Nickname = Prefs.Nickname; if (string.IsNullOrWhiteSpace(this.Nickname)) { this.Nickname = Skylabs.Lobby.Randomness.GrabRandomNounWord() + new Random().Next(30); } var retNick = this.Nickname; Program.Dispatcher.Invoke(new Action(() => { var i = new InputDlg("Choose a nickname", "Choose a nickname", this.Nickname); retNick = i.GetString(); })); this.Nickname = retNick; } // Load all game markers foreach (DataNew.Entities.Marker m in Definition.GetAllMarkers()) { if (!_markersById.ContainsKey(m.Id)) { _markersById.Add(m.Id, m); } } // Init fields CurrentUniqueId = 1; TurnNumber = 0; TurnPlayer = null; foreach (var size in Definition.CardSizes) { var front = ImageUtils.CreateFrozenBitmap(new Uri(size.Value.Front)); var back = ImageUtils.CreateFrozenBitmap(new Uri(size.Value.Back)); _cardFrontsBacksCache.Add(size.Key, new Tuple <BitmapImage, BitmapImage>(front, back)); } Application.Current.Dispatcher.Invoke(new Action(() => { // clear any existing players Play.Player.All.Clear(); Player.Spectators.Clear(); // Create the global player, if any if (Definition.GlobalPlayer != null) { Play.Player.GlobalPlayer = new Play.Player(Definition); } // Create the local player Play.Player.LocalPlayer = new Play.Player(Definition, this.Nickname, 255, Crypto.ModExp(Prefs.PrivateKey), specator, true); })); }