public static void CommandHandler(string command, string json, Socket socket = null)
        {
            switch (command)
            {
            case string a when a.Contains("GetServers"):
                GetServersService getServers = new GetServersService();

                getServers.GetServers(socket, command);
                break;

            case string b when b.Contains("Login"):
                LoginService loginService = new LoginService();

                loginService.LoginAsync(socket, command, json);
                break;

            case string b when b.Contains("GetInventory"):
                GetInventoryService getInventory = new GetInventoryService();

                getInventory.InventoryAsync(socket, command, json, false);
                break;

            case string b when b.Contains("GetEquipmentInventory"):
                GetInventoryService getEquipmentInventory = new GetInventoryService();

                getEquipmentInventory.InventoryAsync(socket, command, json, true);
                break;

            case string b when b.Contains("WearCommand"):
                WearCommandService wearCommandService = new WearCommandService();

                wearCommandService.WearCommand(socket, command, json);
                break;
            }
        }
Esempio n. 2
0
        private async Task <string> WearCommandResult(string userData, Socket socket)
        {
            var itemRequestResult = JsonConvert.DeserializeObject <ItemRequestResultModel>(userData);

            var collection = DbConnect.db_link.GetCollection <BsonDocument>("characters");

            var builder = Builders <BsonDocument> .Filter;

            var filter = builder.Eq("_id", ObjectId.Parse(itemRequestResult.characterId));

            var character = await collection.Find(filter).FirstOrDefaultAsync();

            collection = DbConnect.db_link.GetCollection <BsonDocument>("characterinventoryitemschemas");

            filter = builder.Eq("_id", ObjectId.Parse(itemRequestResult.itemId)) & builder.Eq("characterId", itemRequestResult.characterId);
            // шмотка действительно есть ли у персонажа
            var itemFromPlayer = await collection.Find(filter).FirstOrDefaultAsync();

            var parsedJsonItemFromPlayer = DbConnect.JsonParser(itemFromPlayer, false);
            var parsedJsonCharacter      = DbConnect.JsonParser(character, true);

            var item          = JsonConvert.DeserializeObject <ItemModel>(parsedJsonItemFromPlayer);
            var baseCharacter = JsonConvert.DeserializeObject <BaseCharacterModel>(parsedJsonCharacter);

            // если в бд есть запись
            if (itemFromPlayer != null)
            {
                if (item.baseItem.itemLvl <= baseCharacter.characterLvl)
                {
                    if (item.baseItem.characterClassId == baseCharacter.characterClassId)
                    {
                        // TODO переделать под запрос с 45 строкой
                        filter = builder.Eq("itemEquipmentPlace", item.baseItem.itemType) & builder.Eq("characterId", baseCharacter._id);
                        var itemEquiped = await collection.Find(filter).FirstOrDefaultAsync();

                        if (itemEquiped != null)
                        {
                            var updateEquipedItem = Builders <BsonDocument> .Update.Unset("itemEquipmentPlace");

                            var resultUpdateEquipedItem = await collection.UpdateOneAsync(filter, updateEquipedItem);
                        }

                        var updateItemFromPlayer = Builders <BsonDocument> .Update.Set("itemEquipmentPlace", item.baseItem.itemType);

                        var resultUpdateItemFromPlayer = await collection.UpdateOneAsync(filter, updateItemFromPlayer);

                        GetInventoryService getInventory = new GetInventoryService();
                        //должны отдать новый слепок героя
                        return(await getInventory.InventoryResult("{\"_id\" : \"" + baseCharacter._id + "\"}", false));
                    }
                    else
                    {
                        return("{\"result\":\"ERROR\",\"description\":\"#ItemWearErrorClass\"}");
                    }
                }
                else
                {
                    return("{\"result\":\"ERROR\",\"description\":\"#ItemWearErrorLevel\"}");
                }
            }
            else
            {
                return("{\"result\":\"ERROR\",\"description\":\"#InvalidData\"}");
            }
        }