bool mySqlGetCommanders(MySQL *self, Commander **commanders) { MYSQL_ROW row; dbg("mySqlGetCommanders count: %d", mysql_num_rows(self->result)); for (int i = 0; (row = mysql_fetch_row(self->result)); i++) { Commander *curCommander = commanders[i]; commanderInit(curCommander); curCommander->mapId = strtol(row[MYSQL_COMMANDER_FIELD_map_id], NULL, 10); curCommander->pcId = strtoll(row[MYSQL_COMMANDER_FIELD_commander_id], NULL, 10); curCommander->commanderId = strtoll(row[MYSQL_COMMANDER_FIELD_commander_id], NULL, 10); curCommander->socialInfoId = strtoll(row[MYSQL_COMMANDER_FIELD_commander_id], NULL, 10); strncpy(curCommander->name, row[MYSQL_COMMANDER_FIELD_commanderName], sizeof(curCommander->name)); curCommander->jobId = strtol(row[MYSQL_COMMANDER_FIELD_job_id], NULL, 10); curCommander->classId = strtol(row[MYSQL_COMMANDER_FIELD_class_id], NULL, 10); curCommander->hairId = strtol(row[MYSQL_COMMANDER_FIELD_hair_id], NULL, 10); curCommander->gender = strtol(row[MYSQL_COMMANDER_FIELD_gender], NULL, 10); curCommander->level = strtol(row[MYSQL_COMMANDER_FIELD_level], NULL, 10); } return true; }
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->barrackPos = PositionXYZ_decl( strtof(row[MYSQL_COMMANDER_barrack_position_x], NULL), strtof(row[MYSQL_COMMANDER_barrack_position_y], NULL), strtof(row[MYSQL_COMMANDER_barrack_position_z], NULL) ); /* curCommander->dir = PositionXZ_decl( strtof(row[MYSQL_COMMANDER_direction_x], NULL), strtof(row[MYSQL_COMMANDER_direction_y], 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; /** TODO : Get maxHP from MYSQL */ curCommander->currentSP = strtol(row[MYSQL_COMMANDER_mp], NULL, 10); curCommander->maxSP = curCommander->currentSP; /** 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 (ItemEquipmentSlot_t slot = 0; slot < EQSLOT_COUNT; slot++) { MySqlCommanderEnumField field = MYSQL_COMMANDER_eqslot_head_top + slot; ItemId_t itemId = strtol(row[field], NULL, 10); curCommander->inventory.equippedItems[slot] = itemFactoryCreateEquipable(itemId, 1, slot); } } return true; }
void systemTask(void *arg) { bool pass = true; //Init the high-levels modules systemInit(); #ifndef USE_UART_CRTP #ifdef UART_OUTPUT_TRACE_DATA debugInitTrace(); #endif #ifdef HAS_UART uartInit(); #endif #endif //ndef USE_UART_CRTP commInit(); DEBUG_PRINT("Crazyflie is up and running!\n"); DEBUG_PRINT("Build %s:%s (%s) %s\n", V_SLOCAL_REVISION, V_SREVISION, V_STAG, (V_MODIFIED) ? "MODIFIED" : "CLEAN"); DEBUG_PRINT("I am 0x%X%X%X and I have %dKB of flash!\n", *((int* )(0x1FFFF7E8 + 8)), *((int* )(0x1FFFF7E8 + 4)), *((int* )(0x1FFFF7E8 + 0)), *((short* )(0x1FFFF7E0))); commanderInit(); stabilizerInit(); //Test the modules pass &= systemTest(); pass &= commTest(); pass &= commanderTest(); pass &= stabilizerTest(); //Start the firmware if (pass) { systemStart(); ledseqRun(LED_RED, seq_alive); ledseqRun(LED_GREEN, seq_testPassed); } else { if (systemTest()) { while (1) { ledseqRun(LED_RED, seq_testPassed); //Red passed == not passed! vTaskDelay(M2T(2000) ); } } else { ledInit(); ledSet(LED_RED, true); } } workerLoop(); //Should never reach this point! while (1) vTaskDelay(portMAX_DELAY); }
bool sessionInit(Session *self, RouterId_t routerId, uint8_t *sessionKey) { // Define a valid socket session socketSessionInit(&self->socket, SOCKET_SESSION_UNDEFINED_ACCOUNT, routerId, SOCKET_SESSION_UNDEFINED_MAP, sessionKey, false); // Initialize a dummy commander info Commander commander; commanderInit(&commander); gameSessionInit(&self->game, &commander); return true; }
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); }
void systemTask(void *arg) { bool pass = true; ledInit(); ledSet(CHG_LED, 1); uartInit(); //Init the high-levels modules systemInit(); #ifndef USE_RADIOLINK_CRTP #ifdef UART_OUTPUT_TRACE_DATA //debugInitTrace(); #endif #ifdef ENABLE_UART // uartInit(); #endif #endif //ndef USE_RADIOLINK_CRTP commInit(); DEBUG_PRINT("----------------------------\n"); DEBUG_PRINT("Crazyflie is up and running!\n"); DEBUG_PRINT("Build %s:%s (%s) %s\n", V_SLOCAL_REVISION, V_SREVISION, V_STAG, (V_MODIFIED)?"MODIFIED":"CLEAN"); DEBUG_PRINT("I am 0x%X%X%X and I have %dKB of flash!\n", *((int*)(MCU_ID_ADDRESS+8)), *((int*)(MCU_ID_ADDRESS+4)), *((int*)(MCU_ID_ADDRESS+0)), *((short*)(MCU_FLASH_SIZE_ADDRESS))); commanderInit(); stabilizerInit(); expbrdInit(); memInit(); //Test the modules pass &= systemTest(); pass &= configblockTest(); pass &= commTest(); pass &= commanderTest(); pass &= stabilizerTest(); pass &= expbrdTest(); pass &= memTest(); //Start the firmware if(pass) { selftestPassed = 1; systemStart(); ledseqRun(SYS_LED, seq_alive); ledseqRun(LINK_LED, seq_testPassed); } else { selftestPassed = 0; if (systemTest()) { while(1) { ledseqRun(SYS_LED, seq_testPassed); //Red passed == not passed! vTaskDelay(M2T(2000)); // System can be forced to start by setting the param to 1 from the cfclient if (selftestPassed) { DEBUG_PRINT("Start forced.\n"); systemStart(); break; } } } else { ledInit(); ledSet(SYS_LED, true); } } DEBUG_PRINT("Free heap: %d bytes\n", xPortGetFreeHeapSize()); workerLoop(); //Should never reach this point! while(1) vTaskDelay(portMAX_DELAY); }
void systemTask(void *arg) { bool pass = true; ledInit(); ledSet(CHG_LED, 1); #ifdef DEBUG_QUEUE_MONITOR queueMonitorInit(); #endif #ifdef ENABLE_UART1 uart1Init(); #endif #ifdef ENABLE_UART2 uart2Init(); #endif //Init the high-levels modules systemInit(); commInit(); commanderInit(); StateEstimatorType estimator = anyEstimator; deckInit(); estimator = deckGetRequiredEstimator(); stabilizerInit(estimator); if (deckGetRequiredLowInterferenceRadioMode()) { platformSetLowInterferenceRadioMode(); } soundInit(); memInit(); #ifdef PROXIMITY_ENABLED proximityInit(); #endif //Test the modules pass &= systemTest(); pass &= configblockTest(); pass &= commTest(); pass &= commanderTest(); pass &= stabilizerTest(); pass &= deckTest(); pass &= soundTest(); pass &= memTest(); pass &= watchdogNormalStartTest(); //Start the firmware if(pass) { selftestPassed = 1; systemStart(); soundSetEffect(SND_STARTUP); ledseqRun(SYS_LED, seq_alive); ledseqRun(LINK_LED, seq_testPassed); } else { selftestPassed = 0; if (systemTest()) { while(1) { ledseqRun(SYS_LED, seq_testPassed); //Red passed == not passed! vTaskDelay(M2T(2000)); // System can be forced to start by setting the param to 1 from the cfclient if (selftestPassed) { DEBUG_PRINT("Start forced.\n"); systemStart(); break; } } } else { ledInit(); ledSet(SYS_LED, true); } } DEBUG_PRINT("Free heap: %d bytes\n", xPortGetFreeHeapSize()); workerLoop(); //Should never reach this point! while(1) vTaskDelay(portMAX_DELAY); }
void systemTask(void *arg) { bool pass = true; ledInit(); ledSet(CHG_LED, 1); #ifdef DEBUG_QUEUE_MONITOR queueMonitorInit(); #endif #ifdef PLATFORM_CF1 uartInit(); #endif #ifdef ENABLE_UART1 uart1Init(); #endif #ifdef ENABLE_UART2 uart2Init(); #endif //Init the high-levels modules systemInit(); #ifndef USE_RADIOLINK_CRTP #ifdef UART_OUTPUT_TRACE_DATA //debugInitTrace(); #endif #ifdef ENABLE_UART // uartInit(); #endif #endif //ndef USE_RADIOLINK_CRTP commInit(); commanderInit(); stabilizerInit(); #ifdef PLATFORM_CF2 deckInit(); #endif soundInit(); memInit(); #ifdef PROXIMITY_ENABLED proximityInit(); #endif //Test the modules pass &= systemTest(); pass &= configblockTest(); pass &= commTest(); pass &= commanderTest(); pass &= stabilizerTest(); #ifdef PLATFORM_CF2 pass &= deckTest(); #endif pass &= soundTest(); pass &= memTest(); pass &= watchdogNormalStartTest(); //Start the firmware if(pass) { selftestPassed = 1; systemStart(); soundSetEffect(SND_STARTUP); ledseqRun(SYS_LED, seq_alive); ledseqRun(LINK_LED, seq_testPassed); } else { selftestPassed = 0; if (systemTest()) { while(1) { ledseqRun(SYS_LED, seq_testPassed); //Red passed == not passed! vTaskDelay(M2T(2000)); // System can be forced to start by setting the param to 1 from the cfclient if (selftestPassed) { DEBUG_PRINT("Start forced.\n"); systemStart(); break; } } } else { ledInit(); ledSet(SYS_LED, true); } } DEBUG_PRINT("Free heap: %d bytes\n", xPortGetFreeHeapSize()); workerLoop(); //Should never reach this point! while(1) vTaskDelay(portMAX_DELAY); }