예제 #1
0
bool mySqlGetCommanders(MySQL *self, char *familyName, Commander **commanders) {

    MYSQL_ROW row;

    for (int i = 0; (row = mysql_fetch_row(self->result)); i++) {

        Commander *curCommander = commanders[i];
        commanderInit(curCommander);

        strncpy(curCommander->familyName, familyName, sizeof(curCommander->familyName));
        strncpy(curCommander->commanderName, row[MYSQL_COMMANDER_commander_name], sizeof(curCommander->commanderName));
        curCommander->accountId = strtol(row[MYSQL_COMMANDER_account_id], NULL, 10);
        curCommander->classId = strtol(row[MYSQL_COMMANDER_class_id], NULL, 10);
        curCommander->jobId = strtol(row[MYSQL_COMMANDER_job_id], NULL, 10);
        curCommander->gender = strtol(row[MYSQL_COMMANDER_gender], NULL, 10);
        curCommander->level = strtol(row[MYSQL_COMMANDER_level], NULL, 10);
        curCommander->hairId = strtol(row[MYSQL_COMMANDER_hair_id], NULL, 10);
        curCommander->pose = 0; // IDLE
        curCommander->pos = PositionXYZ_decl(
            strtof(row[MYSQL_COMMANDER_position_x], NULL),
            strtof(row[MYSQL_COMMANDER_position_y], NULL),
            strtof(row[MYSQL_COMMANDER_position_z], NULL)
        );
        curCommander->currentXP = strtol(row[MYSQL_COMMANDER_exp], NULL, 10);
        curCommander->maxXP = 1337; /** TODO : Get max XP from XP tables */
        curCommander->pcId = rand(); /** TODO : Get unique PCID */
        curCommander->socialInfoId = strtoll(row[MYSQL_COMMANDER_commander_id], NULL, 10); /** TODO : Get socialInfoId from MYSQL */
        curCommander->commanderId = strtoll(row[MYSQL_COMMANDER_commander_id], NULL, 10);
        curCommander->currentHP = strtol(row[MYSQL_COMMANDER_hp], NULL, 10);
        curCommander->maxHP = curCommander->currentHP + 100; /** TODO : Get maxHP from MYSQL */
        curCommander->currentSP = strtol(row[MYSQL_COMMANDER_mp], NULL, 10);
        curCommander->maxSP = curCommander->currentSP + 100; /** TODO : Get maxHP from MYSQL */
        curCommander->currentStamina = 25000; /** TODO : Get currentStamina from MYSQL */
        curCommander->maxStamina = curCommander->currentStamina; /** TODO : Get maxStamina from MYSQL */
        curCommander->mapId = strtol(row[MYSQL_COMMANDER_map_id], NULL, 10);

        // load equipped items

        for (int i = 0; i < EQSLOT_COUNT; i++) {
            MySqlCommanderEnumField field = MYSQL_COMMANDER_eqslot_head_top + i;
            ItemId_t itemId = strtol(row[field], NULL, 10);
            curCommander->inventory.equippedItems[i] = (ItemEquipable *) itemFactoryCreate(itemId, 1);
        }

    }

    return true;
}
예제 #2
0
파일: admin_cmd.c 프로젝트: eduardjr/R1EMU
void adminCmdSpawnPc(Worker *self, Session *session, char *args, zmsg_t *replyMsg) {

    // add a fake commander with a fake account
    Commander fakePc;
    commanderInit(&fakePc);

    fakePc.pos = session->game.commanderSession.currentCommander->pos;
    fakePc.dir = session->game.commanderSession.currentCommander->dir;
    fakePc.accountId = r1emuGenerateRandom64(&self->seed);
    fakePc.socialInfoId = r1emuGenerateRandom64(&self->seed);
    fakePc.pcId = r1emuGenerateRandom(&self->seed);
    fakePc.commanderId = r1emuGenerateRandom64(&self->seed);
    snprintf(fakePc.familyName, sizeof(fakePc.familyName), "PcID_%x", fakePc.pcId);
    snprintf(fakePc.commanderName, sizeof(fakePc.commanderName),
             "AccountID_%llx", fakePc.accountId);

    // register the fake socket session
    SocketSession fakeSocketSession;
    uint32_t sessionKey = r1emuGenerateRandom(&self->seed);
    uint8_t sessionKeyStr[SOCKET_SESSION_ID_SIZE];

    socketSessionGenSessionKey((uint8_t *)&sessionKey, sessionKeyStr);
    sprintf(sessionKeyStr, "%.08x", sessionKey);
    socketSessionInit(&fakeSocketSession, fakePc.accountId, self->info.routerId, session->socket.mapId,
                      sessionKeyStr, true);

    RedisSocketSessionKey socketKey = {
        .routerId = self->info.routerId,
        .sessionKey = sessionKeyStr
    };

    redisUpdateSocketSession(self->redis, &socketKey, &fakeSocketSession);

    // register the fake game session
    GameSession fakeGameSession;
    gameSessionInit(&fakeGameSession, &fakePc);
    accountSessionInit(&fakeGameSession.accountSession, "DummyPC", sessionKeyStr, ACCOUNT_SESSION_PRIVILEGES_ADMIN);

    RedisGameSessionKey gameKey = {
        .routerId  = fakeSocketSession.routerId,
        .mapId     = fakeSocketSession.mapId,
        .accountId = fakeSocketSession.accountId
    };

    redisUpdateGameSession(self->redis, &gameKey, sessionKeyStr, &fakeGameSession);
    info("Fake PC spawned.(SocketID=%s, SocialID=%I64x, AccID=%I64x, PcID=%x, CommID=%I64x)",
         sessionKeyStr, fakePc.socialInfoId, fakePc.accountId, fakePc.pcId, fakePc.commanderId);

    GameEventEnterPc event = {
        .updatePosEvent = {
            .mapId = fakeSocketSession.mapId,
            .commander = fakePc
        }
    };

    workerDispatchEvent(self, sessionKeyStr, EVENT_TYPE_ENTER_PC, &event, sizeof(event));
}

void adminCmdAddItem(Worker *self, Session *session, char *args, zmsg_t *replyMsg) {

    Item *newItem = NULL;

    ItemId_t itemId = strtol(args, &args, 10);
    args++;
    ItemAmount_t amount = strtol(args, &args, 10);
    amount = amount ? amount : 1;

    // Create new item
    if (!(newItem = itemFactoryCreate(itemId, amount))) {
        error("Item ID = %d is invalid.", itemId);
        return;
    }

    Inventory *inventory = &session->game.commanderSession.currentCommander->inventory;
    inventoryAddItem(inventory, newItem);

    ItemCategory_t itemCategory = itemGetCategory(newItem);
    ActorId_t actorId = actorGetUId(newItem);

    dbg("itemCategory %d", itemCategory);

    ItemInventoryIndex_t inventoryIndex = inventoryGetBagIndexByActorId(inventory, itemCategory, actorId);

    dbg("inventoryIndex %d", inventoryIndex);
    zoneBuilderItemAdd(newItem, inventoryIndex, INVENTORY_ADD_PICKUP, replyMsg);
}

void adminCmdAddSkill(Worker *self, Session *session, char *args, zmsg_t *replyMsg) {

    SkillId_t skillId = strtol(args, &args, 10);
    args++;
    SkillLevel_t level = strtol(args, &args, 10);
    skillId = skillId ? skillId : 40001; // Heal
    level = level ? level : 1;

    SkillsManager *skillsManager = &session->game.commanderSession.currentCommander->skillsManager;

    /*
    Item *newItem = itemFactoryCreate(itemId, amount);
    skillsManagerAddskill(skillsManager, newItem);

    ItemCategory_t itemCategory = itemGetCategory(newItem);
    ActorId_t actorId = actorGetUId(newItem);

    dbg("itemCategory %d", itemCategory);

    ItemInventoryIndex_t inventoryIndex = inventoryGetBagIndexByActorId(inventory, itemCategory, actorId);

    dbg("inventoryIndex %d", inventoryIndex);
    */
    zoneBuilderSkillAdd(skillId, replyMsg);
}