示例#1
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);
        }
示例#2
0
        public void ParsePlayers(uint id, ZServerBase model, BinaryReader reader)
        {
            //model.Id = reader.ReadZUInt32();

            var playerList = new ObservableCollection <ZPlayer>();
            var arrLen     = reader.ReadByte();

            for (byte i = 0; i < arrLen; i++)
            {
                var player = new ZPlayer
                {
                    Slot = reader.ReadByte(),
                    Id   = reader.ReadZUInt32(),
                    Name = reader.ReadZString(),
                    Role = ZPlayerRole.Other
                };

                playerList.Add(player);
            }

            var myPlayer = playerList.FirstOrDefault(p => p.Id == id);

            if (myPlayer != null)
            {
                myPlayer.Role = ZPlayerRole.IAm;
            }

            model.Players = playerList;
            model.CurrentPlayersNumber = (byte)playerList.Count;
        }
示例#3
0
        private void _ActionHandler(ZServerBase model, ZServerParserAction action)
        {
            switch (action)
            {
            case ZServerParserAction.Add:
                _AddActionHandler(model);
                _initialCount++;

                break;

            case ZServerParserAction.PlayersList:
                _PlayerListActionHandler(model);

                _initialCountPlayerList++;

                break;

            case ZServerParserAction.Remove:
                _RemoveActionHandler(model);

                break;

            case ZServerParserAction.Ignore:
            default:
                break;
            }

            if (_initialCountPlayerList >= _initialCount)
            {
                _OnInitialSizeReached();
            }
        }
示例#4
0
        public void UpdateServer(ZServerBase server)
        {
            _ServerRichPresence.Assets.LargeImageKey  = _GetLargeImageKeyByGame(server.Game);
            _ServerRichPresence.Assets.LargeImageText = _GetTitleByGame(server.Game);
            _ServerRichPresence.Details    = server.Name;
            _ServerRichPresence.Timestamps = Timestamps.Now;

            _gamePresence       = _ServerRichPresence;
            _gamePresenceToggle = true;
        }
示例#5
0
        private void _RemoveActionHandler(ZServerBase model)
        {
            var item = _collectionWrapper.Collection.FirstOrDefault(s => s.Id == model.Id);

            if (item != null)
            {
                _collectionWrapper.Remove(item);
            }
            else
            {
                _logger.Warning($"Server remove request for id: {model.Id} not found this server.", true);
            }
        }
示例#6
0
        private void _PlayerListActionHandler(ZServerBase model)
        {
            var target = _collectionWrapper.Collection.FirstOrDefault(s => s.Id == model.Id);

            if (target != null)
            {
                ZSynchronizationWrapper.Send <object>(o => _changesMapper.MapCollection(model.Players, target.Players));

                target.CurrentPlayersNumber = model.CurrentPlayersNumber;
                target.UpdateByName("CurrentPlayersNumber");
            }
            else
            {
                _logger.Warning($"Parsed players for server id: {model.Id} not found this server.", true);
            }
        }
示例#7
0
        private void _AddActionHandler(ZServerBase model)
        {
            var target = _collectionWrapper.Collection.FirstOrDefault(s => s.Id == model.Id);

            if (target != null)
            {
                ZSynchronizationWrapper.Send <object>(o =>
                {
                    var source = model;

                    _changesMapper.MapCollection(source.MapRotation.Rotation, target.MapRotation.Rotation);

                    _changesMapper.MapChanges(source.MapRotation, target.MapRotation);
                    _changesMapper.MapChanges(source, target);

                    target.UpdateAll();
                });
            }
            else
            {
                _collectionWrapper.Add(model);
            }
        }
示例#8
0
        public void ParseIntoServerModel(ZServerBase model, BinaryReader reader)
        {
            // at first parse bytes from reader
            // parse some basic info
            //model.Id = reader.ReadZUInt32();
            model.Ip   = UIntToIPAddress.Convert(reader.ReadZUInt32());
            model.Port = reader.ReadZUInt16();

            // skip block
            reader.SkipBytes(6); // skip 6 bytes [ INIP=4byte; INPORT=2byte; ]

            // parse attributes
            var attributeCount      = reader.ReadByte();
            var attributeDictionary = new Dictionary <string, string>(attributeCount);

            for (var i = 0; i < attributeCount; ++i)
            {
                var key   = reader.ReadZString().ToLowerInvariant();
                var value = reader.ReadZString();

                attributeDictionary.Add(key, value);
            }

            // parse some basic info
            model.Name    = reader.ReadZString();
            model.Players = new ObservableCollection <ZPlayer>();

            // skip block
            reader.SkipBytes(17); // skip 17 bytes [ GameSet=4bytes; ServerState=1byte; IGNO=1byte; MaxPlayers=1byte; NNAT=8bytes; NRES=1byte; NTOP=1byte; ]
            reader.SkipZString(); // skip string [ PGID=String; ]
            reader.SkipBytes(6);  // skip 6 bytes [ PRES=1byte; SlotCapacity=1byte; SEED=4bytes; ]
            reader.SkipZString(); // skip string [ UUID=String; ]
            reader.SkipBytes(1);  // skip 1 byte [ VOIP=1byte; ]
            reader.SkipZString(); // skip string [ VSTR=String; ]

            // parse game-specific data
            switch (model.Game)
            {
            case ZGame.BF3:
                // parse specific data
                model.PlayersCapacity = reader.ReadByte();

                // skip block
                reader.SkipBytes(4);     // skip 4 bytes [TOTAL_SLOTS_NUMBER=4bytes]

                break;

            case ZGame.BF4:
            case ZGame.BFH:
                // skip block
                reader.SkipBytes(4);

                // parse specific data
                model.PlayersCapacity = reader.ReadByte();

                // skip block
                reader.SkipBytes(1);     // skip 1 byte [ PRIVATE_SLOTS=1byte; ]

                // parse specific data
                model.SpectatorsCapacity = reader.ReadByte();

                // skip block
                //reader.SkipBytes(2);  // skip 1 byte [ PRIVATE_SPEC_SLOTS=1byte; GMRG=1byte; ]
                //var skipLength = reader.ReadByte(); // skip more data [ RNFO=bigData; ]
                //for (var i = 0; i < skipLength; ++i)
                //{
                //    reader.SkipZString();
                //    reader.SkipBytes(4);

                //    var skipLength2 = reader.ReadByte();
                //    for (var j = 0; j < skipLength2; j++)
                //    {
                //        reader.SkipZString();
                //        reader.SkipZString();
                //    }
                //}
                //reader.SkipZString();

                break;

            case ZGame.None:
            default:
                throw new ArgumentOutOfRangeException();
            }

            // parse already received data
            // normalize the obtained attributes, because some keys can be split into several parts
            // like mapsinfo1 ... and mapsinfo2 ... mapsinfoN ...
            var normalizedAttributes = _NormalizeAttributes(attributeDictionary);

            // build server attributes from normalized dictionary
            model.Attributes = BuildAttributes(normalizedAttributes, model.Game);

            // build server settings from normalized dictionary
            model.Settings = BuildSettings(normalizedAttributes);

            // build map rotation from normalized dictionary
            model.MapRotation = BuildMapRotation(model.Game, normalizedAttributes);
        }
示例#9
0
 public void Remove(ZServerBase item) =>
 ZSynchronizationWrapper.Send <ZServerBase>((s) => Collection.Remove(s), item);
示例#10
0
 public void Add(ZServerBase item) => ZSynchronizationWrapper.Send <ZServerBase>((s) => Collection.Add(s), item);