Exemplo n.º 1
0
        private DBPlayer ParseAsPlayer(JsonObject playerObj)
        {
            foreach (String requiredField in _PlayerFields.Values.Select(f => f.Name))
            {
                if (!playerObj.ContainsKey(requiredField))
                {
                    return(null);
                }
            }

            DBPlayer inst = new DBPlayer()
            {
                DBPlayerId    = playerObj["DBPlayerId"],
                CharacterName = playerObj["CharacterName"],
                SteamId       = playerObj["SteamId"],
                LastLoggedIn  = playerObj["LastLoggedIn"],
                Created       = playerObj["Created"],
                Items         = new List <DBItem>()
            };

            if (playerObj["Items"].JsonType != JsonType.Array)
            {
                return(null);
            }

            foreach (JsonValue itemVal in playerObj["Items"])
            {
                if (itemVal is JsonObject itemObj)
                {
                    DBItem item = ParseAsItem(itemObj);
                    if (item == null)
                    {
                        return(null);//TODO: Check Configs.JsonStrictParsing
                    }
                    inst.Items.Add(item);
                }
            }

            return(inst);
        }
Exemplo n.º 2
0
        private DBItem ParseAsItem(JsonObject itemObj)
        {
            foreach (String requiredField in _ItemFields.Values.Select(f => f.Name))
            {
                if (!itemObj.ContainsKey(requiredField))
                {
                    return(null);
                }
            }

            DBItem item = new DBItem()
            {
                DbItemId   = _ItemCounter++,
                ItemName   = itemObj["ItemName"],
                PlayerId   = itemObj["PlayerId"],
                StackCount = itemObj["StackCount"],
                Quality    = itemObj["Quality"],
                Variant    = itemObj["Variant"]
            };

            return(item);
        }