Reference<Task*> BountyHunterDroid::performAction(int action, SceneObject* droidObject, CreatureObject* player, MissionObject* mission) { if (droidObject == NULL || player == NULL || mission == NULL) { player->sendSystemMessage("@mission/mission_generic:bounty_no_ability"); // You do not understand how to use this item. return NULL; } Reference<Task*> task = NULL; Locker playerLock(player); switch (action) { case CALLDROID: task = callArakydDroid(droidObject, player, mission); break; case TRANSMITBIOLOGICALSIGNATURE: task = transmitBiologicalSignature(droidObject, player, mission); break; case FINDTARGET: task = findTarget(droidObject, player, mission, false); break; case FINDANDTRACKTARGET: task = findTarget(droidObject, player, mission, true); break; default: player->sendSystemMessage("@mission/mission_generic:bounty_no_ability"); // You do not understand how to use this item. break; } return task; }
int main(int argc, char * argv[]) { Util::Config conf(argv[0], PACKAGE_VERSION); mistIn conv(&conf); if (conf.parseArgs(argc, argv)) { IPC::semaphore playerLock(std::string("/lock_" + conf.getString("streamname")).c_str(), O_CREAT | O_RDWR, ACCESSPERMS, 1); if (!playerLock.tryWait()){ DEBUG_MSG(DLVL_DEVEL, "A player for stream %s is already running", conf.getString("streamname").c_str()); return 1; } conf.activate(); while (conf.is_active){ int pid = fork(); if (pid == 0){ playerLock.close(); return conv.run(); } if (pid == -1){ DEBUG_MSG(DLVL_FAIL, "Unable to spawn player process"); playerLock.post(); return 2; } //wait for the process to exit int status; while (waitpid(pid, &status, 0) != pid && errno == EINTR) continue; //clean up the semaphore by waiting for it, if it's non-zero IPC::semaphore waiting(std::string("/wait_" + conf.getString("streamname")).c_str(), O_CREAT | O_RDWR, ACCESSPERMS, 0); if (!waiting){ DEBUG_MSG(DLVL_FAIL, "Failed to open semaphore - cancelling"); return -1; } int sem_val = waiting.getVal(); while (sem_val){ waiting.wait(); sem_val = waiting.getVal(); } waiting.close(); //if the exit was clean, don't restart it if (WIFEXITED(status) && (WEXITSTATUS(status) == 0)){ DEBUG_MSG(DLVL_MEDIUM, "Finished player succesfully"); break; } if (DEBUG >= DLVL_DEVEL){ DEBUG_MSG(DLVL_DEVEL, "Player exited with errors - stopping because this is a development build."); break; } } playerLock.post(); playerLock.close(); } return 0; }