Exemple #1
0
        /// <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);
        }
Exemple #2
0
        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);
        }
Exemple #3
0
 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);
     }
 }
Exemple #4
0
 /// <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()
 };
Exemple #5
0
        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);
        }
Exemple #6
0
        public void UpdateStats(ZGame game)
        {
            var title = _GetTitleByGame(game);

            _StatsRichPresence.Assets.LargeImageText = title;
            _StatsRichPresence.Assets.LargeImageKey  = _GetLargeImageKeyByGame(game);

            _pagePresence = _StatsRichPresence;
        }
Exemple #7
0
        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();
        }
Exemple #9
0
        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;
        }
Exemple #10
0
        /// <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));
        }
Exemple #11
0
        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);
        }
Exemple #12
0
 public string GetGameModeNameByKey(ZGame game, string gameModeKey)
 {
     try
     {
         return(_GetJToken(game)[gameModeKey].ToObject <string>());
     }
     catch (Exception)
     {
         return(ZStringConstants.NotAvailable);
     }
 }
Exemple #13
0
        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();
            }
        }
Exemple #14
0
        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());
        }
Exemple #15
0
        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();
            }
        }
Exemple #16
0
        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);
        }
Exemple #17
0
 public static IZServersListParser CreateServersListInfoParser(uint myId, ZGame gameContext, ZLogger logger) => new ZServersListParser(myId, gameContext, logger);
Exemple #18
0
 private string _GetTitleByGame(ZGame game) => _BFTitles[(int)game];
Exemple #19
0
        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);
        }
Exemple #20
0
 /// <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 }
 };
Exemple #21
0
 private static string _GetLargeImageKeyByGame(ZGame game) => $"{game.ToString().ToLower()}_large_logo";
Exemple #22
0
 /// <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 }
 };
Exemple #23
0
		void SetGameEnv( ZGame* GameEnv ) { this->GameEnv = GameEnv; }
Exemple #24
0
 private IZServersListService _BuildServerListService(ZGame game)
 => new ZServersListService(Connection.GetCurrentUserInfo().UserId, game);
Exemple #25
0
        private async Task <ZStatsBase> _GetStatsImpl(ZGame game)
        {
            var result = await _statsService.GetStatsAsync(game);

            return(result);
        }
Exemple #26
0
        /// <inheritdoc />
        public void InjectDll(ZGame game, IEnumerable <string> paths)
        {
            ZConnectionHelper.MakeSureConnection();

            _injector.Inject(game, paths);
        }
Exemple #27
0
 private GameSetting _GetGameSettings(ZGame target)
 => _settingsService
 .GetGameSettings()
 .Settings[(int)target];