/// <inheritdoc /> public IZServersListService CreateServersListService(ZGame game) { ZConnectionHelper.MakeSureConnection(); if (_config == null) { throw new InvalidOperationException("You cannot create a service until the api is configured."); } if (game == ZGame.None) { throw new InvalidEnumArgumentException(nameof(game), (int)game, typeof(ZGame)); } if (_lastCreatedServerListInstance != null && _lastCreatedServerListInstance.CanUse) { _lastCreatedServerListInstance.StopReceiving(); } var service = _BuildServerListService(game); _lastCreatedServerListInstance = service; return(service); }
public ZServerBase BuildServerModel(ZGame game, uint serverId) { ZServerBase model = null; switch (game) { case ZGame.BF3: model = new ZBF3Server() { Id = serverId }; break; case ZGame.BF4: model = new ZBF4Server() { Id = serverId }; break; case ZGame.BFH: model = new ZBFHServer() { Id = serverId }; break; } model.Game = game; return(model); }
public async void Inject(ZGame game, IEnumerable <string> dllPaths) { foreach (var dllPath in dllPaths) { var request = ZRequestFactory.CreateDllInjectRequest(game, dllPath); var response = await ZRouter.GetResponseAsync(request); } }
/// <summary> /// Creates an instance of <see cref="ZRequest"/> for <see cref="ZCommand.Inject"/> /// </summary> /// <param name="game">The target game</param> /// <param name="dllPath">The path to dll to inject</param> /// <returns>An instance of <see cref="ZRequest"/> for <see cref="ZCommand.Inject"/></returns> public static ZRequest CreateDllInjectRequest(ZGame game, string dllPath) => new ZRequest { RequestCommand = ZCommand.Inject, Method = ZRequestMethod.Get, RequestPayload = new[] { (byte)game } .Concat(ZBitConverter.Convert(dllPath)) .ToArray() };
private ZMapRotation BuildMapRotation(ZGame game, IDictionary <string, string> attributes) { var rotation = new ZMapRotation(null); // parse available map list var mapList = _ParseMapList(attributes["maps"], game); // get current and next maps var mapRotationIndexes = _ParseMapIndexes(attributes.ContainsKey("mapsinfo") ? attributes["mapsinfo"] : string.Empty); var currentMap = new ZMap { Name = attributes.ContainsKey("level") ? _mapConverter.GetMapNameByKey(game, attributes["level"]) : ZStringConstants.NotAvailable, GameModeName = attributes.ContainsKey("levellocation") ? _gameModeConverter.GetGameModeNameByKey(game, attributes["levellocation"]) : ZStringConstants.NotAvailable, Role = ZMapRole.Current }; rotation.Current = currentMap; // check if we can get access to next map in maps list rotation if (mapRotationIndexes != null) { var nextMapIndex = mapRotationIndexes.Last(); if (nextMapIndex <= mapList.Count - 1) { var nextMap = mapList[nextMapIndex]; nextMap.Role = ZMapRole.Next; rotation.Next = nextMap; } } // check if we can get access to current map in maps list rotation var map = mapList.FirstOrDefault( m => m.Name == currentMap.Name && m.GameModeName == currentMap.GameModeName); if (map == null) { mapList.Add(currentMap); } else { map.Role = ZMapRole.Current; } rotation.Rotation = new ObservableCollection <ZMap>(mapList); // remove used keys attributes.Remove("maps"); attributes.Remove("mapsinfo"); attributes.Remove("level"); attributes.Remove("levellocation"); return(rotation); }
public void UpdateStats(ZGame game) { var title = _GetTitleByGame(game); _StatsRichPresence.Assets.LargeImageText = title; _StatsRichPresence.Assets.LargeImageKey = _GetLargeImageKeyByGame(game); _pagePresence = _StatsRichPresence; }
public ZServersListParser(uint myId, ZGame gameContext, ZLogger logger) { _cache = new Queue <ZPacket[]>(5); _mapConverter = new ZMapNameConverter(); _gameModeConverter = new ZGameModesConverter(); _myId = myId; _gameContext = gameContext; _logger = logger; }
public ZServersListService(uint myId, ZGame game) { _logger = ZLogger.Instance; _parser = ZParsersFactory.CreateServersListInfoParser(myId, game, _logger); _parser.ResultCallback = _ActionHandler; _gameContext = game; _collectionWrapper = new ZCollectionWrapper(new ObservableCollection <ZServerBase>()); _changesMapper = new ZChangesMapper(); }
public void UpdateSingle(ZGame game, ZPlayMode mode) { _SingleRichPresence.Assets.LargeImageKey = _GetLargeImageKeyByGame(game); _SingleRichPresence.Assets.LargeImageText = _GetTitleByGame(game); _SingleRichPresence.Details = mode == ZPlayMode.Singleplayer ? "Singleplayer" : "Playground"; _SingleRichPresence.Timestamps = Timestamps.Now; _gamePresence = _SingleRichPresence; _gamePresenceToggle = true; }
/// <inheritdoc /> public Task <ZStatsBase> GetStatsAsync(ZGame game) { ZConnectionHelper.MakeSureConnection(); if (game == ZGame.BFH) { throw new NotSupportedException("Stats not implemented for Battlefield Hardline."); } return(_GetStatsImpl(game)); }
internal static async Task _MultiplayerHandler(ZGame game) { // build the server list service instance var serverListService = _zloApi.CreateServersListService(game); var resetEvent = new ManualResetEvent(false); // configure server list service serverListService.InitialSizeReached += (s, e) => { resetEvent.Set(); serverListService.StopReceiving(); }; serverListService.StartReceiving(); // wait to server list full load resetEvent.WaitOne(); // draw servers table const string straightLine = "_______________________________________________________________________________________"; // configure console Console.ForegroundColor = ConsoleColor.DarkYellow; Console.WriteLine("\n {0,88} \n {1,5} {2,50}| {3,30}| \n {4,88}", straightLine, "ID:", "ServerName", "Map:", straightLine); foreach (var item in serverListService.ServersCollection) { Console.WriteLine("{0,5}| {1,50}| {2,30}|", item.Id, item.Name, item.MapRotation.Current.Name); } Console.Write($"{straightLine} \n \nTo join, Enter a server ID: "); #region Get target server Id // get user input var serverIdUserInput = Console.ReadLine(); // validate input if (!uint.TryParse(serverIdUserInput, out var targetServerId)) { throw new InvalidOperationException("Invalid input!"); } #endregion // add some space between user input and game log Console.ForegroundColor = ConsoleColor.Gray; Console.WriteLine(); // create game var gameProcess = await _gameFactory.CreateMultiAsync(new ZMultiParams { Game = game, ServerId = targetServerId }); // run and track game pipe await _RunAndTrack(gameProcess); }
public string GetGameModeNameByKey(ZGame game, string gameModeKey) { try { return(_GetJToken(game)[gameModeKey].ToObject <string>()); } catch (Exception) { return(ZStringConstants.NotAvailable); } }
private JToken _GetJToken(ZGame game) { switch (game) { case ZGame.BF3: return(_jBF3GameModeDictionary); case ZGame.BF4: return(_jBF4GameModeDictionary); case ZGame.BFH: return(_jBFHGameModeDictionary); case ZGame.None: default: throw new Exception(); } }
private List <ZMap> _ParseMapList(string mapString, ZGame game) { // parse map list rotation var maps = mapString.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries) // get map name and gameMode string like key,value .Select(str => str.Split(',')) // get arrays where 0 index as Key + 1 index as Value .Where(a => a.Length > 1) // drop not full pairs .Select(a => new ZMap { Name = _mapConverter.GetMapNameByKey(game, a[__mapNameIndex]), GameModeName = _gameModeConverter.GetGameModeNameByKey(game, a[__gameModeIndex]), Role = ZMapRole.Other }); // select maps return(maps.ToList()); }
private IZGameProcess _createRunGame(ZInstalledGame target, string command, ZGame game, ZGameArchitecture architecture) { switch (game) { case ZGame.BF3: return(new ZGameProcess(command, target, "venice_snowroller", "bf3")); case ZGame.BF4: return(new ZGameProcess(command, target, "warsaw_snowroller", architecture == ZGameArchitecture.x64 ? "bf4" : "bf4_x86")); case ZGame.BFH: return(new ZGameProcess(command, target, "omaha_snowroller", architecture == ZGameArchitecture.x64 ? "bfh" : "bfh_x86")); case ZGame.None: default: throw new Exception(); } }
public async Task <ZStatsBase> GetStatsAsync(ZGame game) { ZStatsBase stats = null; var request = ZRequestFactory.CreateStatsRequest(game); var response = await ZRouter.GetResponseAsync(request); if (response.StatusCode != ZResponseStatusCode.Ok) { _logger.Error($"Request fail {request}"); } else { switch (game) { case ZGame.BF3: stats = _parser.ParseBF3Stats(response.ResponsePackets); break; case ZGame.BF4: stats = _parser.ParseBF4Stats(response.ResponsePackets); break; } } return(stats); }
public static IZServersListParser CreateServersListInfoParser(uint myId, ZGame gameContext, ZLogger logger) => new ZServersListParser(myId, gameContext, logger);
private string _GetTitleByGame(ZGame game) => _BFTitles[(int)game];
private ZAttributesBase BuildAttributes(IDictionary <string, string> attributes, ZGame game) { ZAttributesBase attributesModel = null; switch (game) { case ZGame.BF3: attributesModel = new ZBF3Attributes(attributes); break; case ZGame.BF4: attributesModel = new ZBF4Attributes(attributes); break; case ZGame.BFH: attributesModel = new ZBFHAttributes(attributes); break; } return(attributesModel); }
/// <summary> /// Creates an instance of <see cref="ZRequest"/> for <see cref="ZCommand.Stats"/> /// </summary> /// <param name="game">The target game</param> /// <returns>An instance of <see cref="ZRequest"/> for <see cref="ZCommand.Stats"/></returns> public static ZRequest CreateStatsRequest(ZGame game) => new ZRequest { RequestCommand = ZCommand.Stats, Method = ZRequestMethod.Get, RequestPayload = new[] { (byte)game } };
private static string _GetLargeImageKeyByGame(ZGame game) => $"{game.ToString().ToLower()}_large_logo";
/// <summary> /// Creates an instance of <see cref="ZRequest"/> for <see cref="ZCommand.ServerList"/> to Close Stream /// </summary> /// <param name="game">The target game</param> /// <returns>An instance of <see cref="ZRequest"/> for <see cref="ZCommand.ServerList"/></returns> public static ZRequest CreateServerListCloseStreamRequest(ZGame game) => new ZRequest { RequestCommand = ZCommand.ServerList, Method = ZRequestMethod.Put, RequestPayload = new byte[] { 1, (byte)game } };
void SetGameEnv( ZGame* GameEnv ) { this->GameEnv = GameEnv; }
private IZServersListService _BuildServerListService(ZGame game) => new ZServersListService(Connection.GetCurrentUserInfo().UserId, game);
private async Task <ZStatsBase> _GetStatsImpl(ZGame game) { var result = await _statsService.GetStatsAsync(game); return(result); }
/// <inheritdoc /> public void InjectDll(ZGame game, IEnumerable <string> paths) { ZConnectionHelper.MakeSureConnection(); _injector.Inject(game, paths); }
private GameSetting _GetGameSettings(ZGame target) => _settingsService .GetGameSettings() .Settings[(int)target];