예제 #1
0
bool mySqlCommanderInsert(MySQL *self, uint64_t accountId, Commander *commanderToCreate) {

    MYSQL_ROW row;
    bool status = false;
    uint32_t commanderId;

    if (mySqlQuery(self,
                   "CALL createCommander(%llu, '%s', %d, %d, %d, %d, %d, %d, %f, %f, %f, %f, %f);"
                   , accountId, commanderToCreate->name, commanderToCreate->level
                   , commanderToCreate->gender, commanderToCreate->jobId, commanderToCreate->classId
                   , commanderToCreate->hairId, commanderToCreate->mapId, commanderToCreate->pos.x
                   , commanderToCreate->pos.y, commanderToCreate->pos.z, commanderToCreate->currentHP
                   , commanderToCreate->currentStamina
                   )) {
        error("SQL Error : %s" , mysql_error(self->handle));
        goto cleanup;
    }

    // Check query results
    if (mySqlQuery(self, "SELECT @flag;")) {
        error("SQL Error : %s" , mysql_error(self->handle));
        goto cleanup;
    }

    if (mysql_num_rows(self->result) == 0) {
        error("MySQL: Procedure createCommander() didn't return value");
        goto cleanup;
    }

    row = mysql_fetch_row(self->result);
    commanderId = strtol(row[0], NULL, 10);

    // CommanderId = -1 == NAME ALREADY EXIST
    // CommanderId = -2 == SQL EXCEPTION
    // CommanderId =  0 == Not used
    // CommanderId > 0 = Commander ID

    if (commanderId < 1) {
        error("There was an error in MySQL creating a commander.");
        goto cleanup;
    }

    commanderToCreate->commanderId = commanderId;

    status = true;

cleanup:
    return status;
}
예제 #2
0
bool mySqlCommanderFlush(MySQL *self, Commander *commander) {

    bool status = false;
    MYSQL_ROW count;

    // flush the commander
    if (mySqlQuery(self, "SELECT count(*) FROM commanders WHERE commander_id = %u", commander->commanderId)) {
        error("SQL Error : %s" , mysql_error(self->handle));
        goto cleanup;
    }

    count = mysql_fetch_row(self->result);

    if (atoi(count[0]) == 0) {
        // insert the commander
        if (!(mySqlCommanderInsert(self, commander))) {
            error("Cannot insert a new commander.");
            goto cleanup;
        }
    }
    else {
        if (!(mySqlCommanderUpdate(self, commander->commanderId, commander))) {
            error("Cannot update the commander '%llx'.", commander->accountId);
            goto cleanup;
        }
    }

    status = true;
cleanup:

    return status;
}
예제 #3
0
bool mySqlRequestCommandersByAccountId(MySQL *self, uint64_t accountId, size_t *commandersCount) {

    bool status = false;
	char query[MAX_QUERY_SIZE] = "SELECT ";

	for (MySqlCommanderEnumField field = 0; field < MYSQL_COMMANDER_COUNT; field++) {
        snprintf(query, sizeof(query), "%s%s, ", query, mySqlCommanderStrFields[field]);
        if (field == MYSQL_COMMANDER_COUNT - 1) {
            // No comma for the last field
            query[strlen(query) - strlen(", ")] = ' ';
        }
	}

	snprintf(query, sizeof(query), "%s FROM commanders ", query);
	snprintf(query, sizeof(query), "%s WHERE %s = %s AND %s = 'n'", query,
        mySqlCommanderStrFields[MYSQL_COMMANDER_account_id],
        mySqlCommanderTypeFields[MYSQL_COMMANDER_account_id],
        mySqlCommanderStrFields[MYSQL_COMMANDER_is_deleted]
    );

    // Check if current commander exists
    if (mySqlQuery(self, query, accountId)) {
        error("SQL Error : %s" , mysql_error(self->handle));
        goto cleanup;
    }

    *commandersCount = mysql_num_rows(self->result);
    status = true;

cleanup:
    return status;
}
예제 #4
0
파일: mysql_item.c 프로젝트: gastonb/R1EMU
bool mySqlRequestItems(MySQL *self, uint64_t commanderId, size_t *_itemsCount) {

    bool status = false;
    size_t itemsCount = 0;

    // check if current commander exists
    if (mySqlQuery(self, "SELECT "
        " "  MYSQL_ITEM_FIELD_item_id_str
        ", " MYSQL_ITEM_FIELD_item_type_str
        ", " MYSQL_ITEM_FIELD_amount_str
        ", " MYSQL_ITEM_FIELD_position_in_inventory_str
        " FROM items "
        "WHERE commander_id = '%llu' "
        "ORDER BY position_in_inventory ASC ",
        commanderId))
    {
        error("SQL Error : %s" , mysql_error(self->handle));
        goto cleanup;
    }

    itemsCount = mysql_num_rows(self->result);

    dbg("items found in commander %d", itemsCount);

    *_itemsCount = itemsCount;
    status = true;

cleanup:
    return status;
}
예제 #5
0
파일: mysql_item.c 프로젝트: gastonb/R1EMU
bool mySqlGetSlotItemIds(MySQL *self, uint64_t commanderId, uint64_t *slotItemIds) {
    bool status = false;
    MYSQL_ROW row;


    dbg("yoquese");

    dbg("slotItemIds[0] %d", slotItemIds[0]);
    dbg("slotItemIds[1] %d", slotItemIds[1]);

    // check if current commander exists
    if (mySqlQuery(self, "SELECT "
        " " MYSQL_SLOT_FIELD_eqslot_head_top_str
        ", " MYSQL_SLOT_FIELD_eqslot_head_middle_str
        ", " MYSQL_SLOT_FIELD_eqslot_unkown_1_str
        ", " MYSQL_SLOT_FIELD_eqslot_body_armor_str
        ", " MYSQL_SLOT_FIELD_eqslot_gloves_str
        ", " MYSQL_SLOT_FIELD_eqslot_boots_str
        ", " MYSQL_SLOT_FIELD_eqslot_helmet_str
        ", " MYSQL_SLOT_FIELD_eqslot_bracelet_str
        ", " MYSQL_SLOT_FIELD_eqslot_weapon_str
        ", " MYSQL_SLOT_FIELD_eqslot_shield_str
        ", " MYSQL_SLOT_FIELD_eqslot_costume_str
        ", " MYSQL_SLOT_FIELD_eqslot_unkown_3_str
        ", " MYSQL_SLOT_FIELD_eqslot_unkown_4_str
        ", " MYSQL_SLOT_FIELD_eqslot_unkown_5_str
        ", " MYSQL_SLOT_FIELD_eqslot_leg_armor_str
        ", " MYSQL_SLOT_FIELD_eqslot_unkown_6_str
        ", " MYSQL_SLOT_FIELD_eqslot_unkown_7_str
        ", " MYSQL_SLOT_FIELD_eqslot_ring_left_str
        ", " MYSQL_SLOT_FIELD_eqslot_ring_right_str
        ", " MYSQL_SLOT_FIELD_eqslot_necklace_str
        " FROM commander_slots "
        "WHERE commander_id = '%llu' "
        "LIMIT 1 ",
        commanderId))
    {
        error("SQL Error : %s" , mysql_error(self->handle));
        goto cleanup;
    }

    if (mysql_num_rows(self->result) != 1) {
        error("No data found in commander_slots for commanderId: %d", commanderId);
        goto cleanup;
    }

    row = mysql_fetch_row(self->result);

    for (int eqSlotIndex; eqSlotIndex < EQSLOT_Count; eqSlotIndex++) {
        slotItemIds[eqSlotIndex] = strtoull(row[eqSlotIndex], NULL, 10);
    }

    status = true;

cleanup:
    return status;
}
예제 #6
0
static bool mySqlRequestItemsCommonData(MySQL *self, size_t *rowsCount) {

    bool status = false;

    if (mySqlQuery(self, "SELECT ClassID, ItemType FROM items_all")) {
        error("SQL Error : %s" , mysql_error(self->handle));
        goto cleanup;
    }

    *rowsCount = mysql_num_rows(self->result);

    status = true;

cleanup:
    return status;
}
예제 #7
0
bool MySqlCommanderDelete(MySQL *self, uint64_t commanderId) {

    bool status = false;

// Insert a new commander
    if (mySqlQuery(self, "DELETE FROM commanders "
       "WHERE commander_id = '%llu'",
       commanderId))
    {
        error("SQL Error : %s" , mysql_error(self->handle));
        goto cleanup;
    }

    status = true;

cleanup:
    return status;
}
예제 #8
0
bool MySqlCommanderDelete(MySQL *self, CommanderId_t commanderId) {

    bool status = false;
	char query[MAX_QUERY_SIZE] = "DELETE FROM commanders";

    snprintf(query, sizeof(query), "%s WHERE %s = %s", query,
        mySqlCommanderStrFields[MYSQL_COMMANDER_commander_id],
        mySqlCommanderTypeFields[MYSQL_COMMANDER_commander_id]);

    if (mySqlQuery(self, query, commanderId)) {
        error("SQL Error : %s" , mysql_error(self->handle));
        goto cleanup;
    }

    status = true;

cleanup:
    return status;
}
예제 #9
0
bool mySqlRequestCommandersByAccountId(MySQL *self, uint64_t accountId, size_t *_commandersCount) {

    bool status = false;
    size_t commandersCount = 0;

    // check if current commander exists
    if (mySqlQuery(self, "SELECT "
        " "  MYSQL_COMMANDER_FIELD_commander_id_str
        ", " MYSQL_COMMANDER_FIELD_commanderName_str
        ", " MYSQL_COMMANDER_FIELD_time_deleted_str
        ", " MYSQL_COMMANDER_FIELD_level_str
        ", " MYSQL_COMMANDER_FIELD_exp_str
        ", " MYSQL_COMMANDER_FIELD_gender_str
        ", " MYSQL_COMMANDER_FIELD_job_id_str
        ", " MYSQL_COMMANDER_FIELD_class_id_str
        ", " MYSQL_COMMANDER_FIELD_hair_id_str
        ", " MYSQL_COMMANDER_FIELD_map_id_str
        ", " MYSQL_COMMANDER_FIELD_position_x_str
        ", " MYSQL_COMMANDER_FIELD_position_y_str
        ", " MYSQL_COMMANDER_FIELD_position_z_str
        ", " MYSQL_COMMANDER_FIELD_hp_str
        ", " MYSQL_COMMANDER_FIELD_mp_str
        " FROM commanders "
        "WHERE account_id = '%llu' "
        "AND is_deleted = 'n' ",
        accountId))
    {
        error("SQL Error : %s" , mysql_error(self->handle));
        goto cleanup;
    }

    commandersCount = mysql_num_rows(self->result);

    dbg("commanders found in account %d", commandersCount);

    *_commandersCount = commandersCount;
    status = true;

cleanup:
    return status;
}
예제 #10
0
bool mySqlCommanderInsert(MySQL *self, Commander *commander) {

    bool status = false;

    // Insert a new commander
	char query[MAX_QUERY_SIZE] = "INSERT INTO commanders SET ";

	for (MySqlCommanderEnumField field = 0; field < MYSQL_COMMANDER_COUNT; field++) {

        // Exceptions :
        if (field == MYSQL_COMMANDER_commander_id
         || field == MYSQL_COMMANDER_is_deleted
         || field == MYSQL_COMMANDER_time_deleted) {
            continue;
        }

        snprintf(query, sizeof(query), "%s%s = %s, ", query,
        mySqlCommanderStrFields[field], mySqlCommanderTypeFields[field]);

        if (field == MYSQL_COMMANDER_COUNT - 1) {
            // No comma for the last field
            query[strlen(query) - strlen(", ")] = ' ';
        }
	}

    // Insert a new commander
    if (mySqlQuery(self, query,
        commander->accountId,
        commander->commanderName,
        commander->level,
        commander->currentXP,
        commander->gender,
        commander->jobId,
        commander->classId,
        commander->hairId,
        commander->mapId,
        commander->pos.x,
        commander->pos.y,
        commander->pos.z,
        commander->currentHP,
        commander->currentSP,
        itemGetId((Item *) commander->inventory.equippedItems[EQSLOT_HAT]),
        itemGetId((Item *) commander->inventory.equippedItems[EQSLOT_HAT_L]),
        itemGetId((Item *) commander->inventory.equippedItems[EQSLOT_UNKOWN1]),
        itemGetId((Item *) commander->inventory.equippedItems[EQSLOT_BODY_ARMOR]),
        itemGetId((Item *) commander->inventory.equippedItems[EQSLOT_GLOVES]),
        itemGetId((Item *) commander->inventory.equippedItems[EQSLOT_BOOTS]),
        itemGetId((Item *) commander->inventory.equippedItems[EQSLOT_HELMET]),
        itemGetId((Item *) commander->inventory.equippedItems[EQSLOT_BRACELET]),
        itemGetId((Item *) commander->inventory.equippedItems[EQSLOT_WEAPON]),
        itemGetId((Item *) commander->inventory.equippedItems[EQSLOT_SHIELD]),
        itemGetId((Item *) commander->inventory.equippedItems[EQSLOT_COSTUME]),
        itemGetId((Item *) commander->inventory.equippedItems[EQSLOT_UNKOWN3]),
        itemGetId((Item *) commander->inventory.equippedItems[EQSLOT_UNKOWN4]),
        itemGetId((Item *) commander->inventory.equippedItems[EQSLOT_UNKOWN5]),
        itemGetId((Item *) commander->inventory.equippedItems[EQSLOT_LEG_ARMOR]),
        itemGetId((Item *) commander->inventory.equippedItems[EQSLOT_UNKOWN6]),
        itemGetId((Item *) commander->inventory.equippedItems[EQSLOT_UNKOWN7]),
        itemGetId((Item *) commander->inventory.equippedItems[EQSLOT_RING_LEFT]),
        itemGetId((Item *) commander->inventory.equippedItems[EQSLOT_RING_RIGHT]),
        itemGetId((Item *) commander->inventory.equippedItems[EQSLOT_NECKLACE])))
    {
        error("SQL Error : %s" , mysql_error(self->handle));
        goto cleanup;
    }

    commander->commanderId = mysql_insert_id(self->handle);
    // TODO : check last insert id

    status = true;

cleanup:
    return status;
}