static void GameCallback(void *data, QString &selection) { GameData *ddata = (GameData *)data; QString sel = selection.toLower(); (void)ddata; if (sel == "game_settings") { MythGameGeneralSettings settings; settings.exec(); } if (sel == "game_players") { MythGamePlayerEditor mgpe; mgpe.exec(); } else if (sel == "search_for_games") { GameHandler::processAllGames(); } if (sel == "clear_game_data") { GameHandler *handler = new GameHandler(); handler->clearAllGameData(); } }
GameHandler* GameHandler::GetHandler(RomInfo *rominfo) { if (!rominfo) return NULL; for (int x = 0; x < handlers->size(); x++) { GameHandler *handler = handlers->at(x); if (handler) { if (rominfo->System() == handler->SystemName()) return handler; } } return NULL; }
GameHandler* GameHandler::GetHandlerByName(QString systemname) { if (systemname.isEmpty() || systemname.isNull()) return NULL; for (int x = 0; x < handlers->size(); x++) { GameHandler *handler = handlers->at(x); if (handler) { if (handler->SystemName() == systemname) return handler; } } return NULL; }
void GameHandler::processAllGames(void) { checkHandlers(); QStringList updatelist; for (int x = 0; x < handlers->size(); x++) { GameHandler *handler = handlers->at(x); if (handler) { updateSettings(handler); handler->processGames(handler); if (handler->needRebuild()) updatelist.append(handler->GameType()); } } if (!updatelist.isEmpty()) UpdateGameCounts(updatelist); }
void GameHandler::Launchgame(RomInfo *romdata, QString systemname) { GameHandler *handler; if (!systemname.isEmpty() && !systemname.isNull()) { handler = GetHandlerByName(systemname); } else if (!(handler = GetHandler(romdata))) { // Couldn't get handler so abort. return; } QString exec = handler->SystemCmdLine(); if (exec.isEmpty()) return; if (handler->GameType() != "PC") { QString arg = "\"" + romdata->Rompath() + "/" + romdata->Romname() + "\""; // If they specified a %s in the commandline place the romname // in that location, otherwise tack it on to the end of // the command. if (exec.contains("%s") || handler->SpanDisks()) { exec = exec.replace(QRegExp("%s"),arg); if (handler->SpanDisks()) { QRegExp rxp = QRegExp( "%d[0-4]", Qt::CaseSensitive, QRegExp::RegExp); if (exec.contains(rxp)) { if (romdata->DiskCount() > 1) { // Chop off the extension, . and last character of the name which we are assuming is the disk # QString basename = romdata->Romname().left(romdata->Romname().length() - (romdata->getExtension().length() + 2)); QString extension = romdata->getExtension(); QString rom; QString diskid[] = { "%d0", "%d1", "%d2", "%d3", "%d4", "%d5", "%d6" }; for (int disk = 1; disk <= romdata->DiskCount(); disk++) { rom = QString("\"%1/%2%3.%4\"") .arg(romdata->Rompath()) .arg(basename) .arg(disk) .arg(extension); exec = exec.replace(QRegExp(diskid[disk]),rom); } } else { // If there is only one disk make sure we replace %d1 just like %s exec = exec.replace(QRegExp("%d1"),arg); } } } } else { exec = exec + " \"" + romdata->Rompath() + "/" + romdata->Romname() + "\""; } } QString savedir = QDir::current().path(); QDir d; if (!handler->SystemWorkingPath().isEmpty()) { if (!d.cd(handler->SystemWorkingPath())) { LOG(VB_GENERAL, LOG_ERR, LOC + QString("Failed to change to specified Working Directory: %1") .arg(handler->SystemWorkingPath())); } } LOG(VB_GENERAL, LOG_INFO, LOC + QString("Launching Game : %1 : %2") .arg(handler->SystemName()) .arg(exec)); GetMythUI()->AddCurrentLocation(QString("MythGame %1 ( %2 )").arg(handler->SystemName()).arg(exec)); QStringList cmdlist = exec.split(";"); if (cmdlist.count() > 0) { for (QStringList::Iterator cmd = cmdlist.begin(); cmd != cmdlist.end(); ++cmd ) { LOG(VB_GENERAL, LOG_INFO, LOC + QString("Executing : %1").arg(*cmd)); myth_system(*cmd, kMSProcessEvents); } } else { LOG(VB_GENERAL, LOG_INFO, LOC + QString("Executing : %1").arg(exec)); myth_system(exec, kMSProcessEvents); } GetMythUI()->RemoveCurrentLocation(); (void)d.cd(savedir); }
void CharServerHandler::handleMessage(Net::MessageIn &msg) { switch (msg.getId()) { case SMSG_CHAR_LOGIN: { msg.skip(2); // Length word msg.skip(20); // Unused // Derive number of characters from message length const int count = (msg.getLength() - 24) / 106; for (int i = 0; i < count; ++i) { Net::Character *character = new Net::Character; readPlayerData(msg, character); mCharacters.push_back(character); logger->log("CharServer: Player: %s (%d)", character->dummy->getName().c_str(), character->slot); } Client::setState(STATE_CHAR_SELECT); } break; case SMSG_CHAR_LOGIN_ERROR: switch (msg.readInt8()) { case 0: errorMessage = _("Access denied. Most likely, there are " "too many players on this server."); break; case 1: errorMessage = _("Cannot use this ID."); break; default: errorMessage = _("Unknown char-server failure."); break; } Client::setState(STATE_ERROR); break; case SMSG_CHAR_CREATE_SUCCEEDED: { Net::Character *character = new Net::Character; readPlayerData(msg, character); mCharacters.push_back(character); updateCharSelectDialog(); // Close the character create dialog if (mCharCreateDialog) { mCharCreateDialog->scheduleDelete(); mCharCreateDialog = 0; } } break; case SMSG_CHAR_CREATE_FAILED: new OkDialog(_("Error"), _("Failed to create character. Most " "likely the name is already taken.")); if (mCharCreateDialog) mCharCreateDialog->unlock(); break; case SMSG_CHAR_DELETE_SUCCEEDED: delete mSelectedCharacter; mCharacters.remove(mSelectedCharacter); mSelectedCharacter = 0; updateCharSelectDialog(); unlockCharSelectDialog(); new OkDialog(_("Info"), _("Character deleted.")); break; case SMSG_CHAR_DELETE_FAILED: unlockCharSelectDialog(); new OkDialog(_("Error"), _("Failed to delete character.")); break; case SMSG_CHAR_MAP_INFO: { msg.skip(4); // CharID, must be the same as player_node->charID GameHandler *gh = static_cast<GameHandler*>(Net::getGameHandler()); gh->setMap(msg.readString(16)); mapServer.hostname = ipToString(msg.readInt32()); mapServer.port = msg.readInt16(); // Prevent the selected local player from being deleted player_node = mSelectedCharacter->dummy; PlayerInfo::setBackend(mSelectedCharacter->data); mSelectedCharacter->dummy = 0; delete_all(mCharacters); mCharacters.clear(); updateCharSelectDialog(); mNetwork->disconnect(); Client::setState(STATE_CONNECT_GAME); } break; case SMSG_CHANGE_MAP_SERVER: { GameHandler *gh = static_cast<GameHandler*>(Net::getGameHandler()); gh->setMap(msg.readString(16)); int x = msg.readInt16(); int y = msg.readInt16(); mapServer.hostname = ipToString(msg.readInt32()); mapServer.port = msg.readInt16(); mNetwork->disconnect(); Client::setState(STATE_CHANGE_MAP); player_node->setTileCoords(x, y); player_node->setMap(0); } break; } }
void CharServerHandler::handleMessage(Net::MessageIn &msg) { switch (msg.getId()) { case SMSG_CHAR_LOGIN: processCharLogin(msg); break; case SMSG_CHAR_LOGIN_ERROR: processCharLoginError(msg); break; case SMSG_CHAR_CREATE_SUCCEEDED: processCharCreate(msg, false); break; case SMSG_CHAR_CREATE_SUCCEEDED2: processCharCreate(msg, true); break; case SMSG_CHAR_CREATE_FAILED: processCharCreateFailed(msg); break; case SMSG_CHAR_DELETE_SUCCEEDED: processCharDelete(msg); break; case SMSG_CHAR_DELETE_FAILED: processCharDeleteFailed(msg); break; case SMSG_CHAR_MAP_INFO: { // msg.skip(4); // CharID, must be the same as player_node->charID PlayerInfo::setCharId(msg.readInt32()); GameHandler *gh = static_cast<GameHandler*>(Net::getGameHandler()); gh->setMap(msg.readString(16)); if (config.getBoolValue("usePersistentIP")) { msg.readInt32(); mapServer.hostname = Client::getServerName(); } else { mapServer.hostname = ipToString(msg.readInt32()); } mapServer.port = msg.readInt16(); // Prevent the selected local player from being deleted player_node = mSelectedCharacter->dummy; PlayerInfo::setBackend(mSelectedCharacter->data); mSelectedCharacter->dummy = nullptr; delete_all(mCharacters); mCharacters.clear(); updateCharSelectDialog(); if (mNetwork) mNetwork->disconnect(); Client::setState(STATE_CONNECT_GAME); } break; case SMSG_CHANGE_MAP_SERVER: { GameHandler *gh = static_cast<GameHandler*>(Net::getGameHandler()); if (!gh || !mNetwork) return; gh->setMap(msg.readString(16)); int x = msg.readInt16(); int y = msg.readInt16(); mapServer.hostname = ipToString(msg.readInt32()); mapServer.port = msg.readInt16(); mNetwork->disconnect(); Client::setState(STATE_CHANGE_MAP); if (player_node) { player_node->setTileCoords(x, y); player_node->setMap(nullptr); } } break; default: break; } }