void MultiAgentEnvironment::initialize( const char* base_path, const char* environment_instance_name, const char* config_filename ) { #ifdef TRACE cout << "> Loading Environment '" << m_EnvironmentInstanceName.c_str() << "' ..." << endl; #endif m_BasePath = base_path; qDebug() << "Base path:" << getBasePath(); m_PcMAE.setParent( this ); if (m_PcMAE.load( "EnvironmentInstance", environment_instance_name )) { m_MultiAgentEnvironment = reinterpret_cast<AbstractMultiAgentEnvironmentInstance*>(m_PcMAE.get()); m_MultiAgentEnvironment->setParentEnvironment( this ); m_Name = m_MultiAgentEnvironment->getName(); } if (m_MultiAgentEnvironment) { // cout << "Init env with config file: " << config_filename << endl; m_MultiAgentEnvironment->initialize( config_filename ); onInitialize(); loadParameters(); } }
void InitProgramInfo(char *argv0, char *userdata_subdir, char *userdata_subdir_unix, char *program_title, char *window_title, char *icon_title, char *x11_icon_filename, char *x11_iconmask_filename, char *sdl_icon_filename, char *msdos_cursor_filename, char *cookie_prefix, char *filename_prefix, int program_version) { program.command_basepath = getBasePath(argv0); program.command_basename = getBaseName(argv0); program.userdata_subdir = userdata_subdir; program.userdata_subdir_unix = userdata_subdir_unix; program.userdata_path = getUserGameDataDir(); program.program_title = program_title; program.window_title = window_title; program.icon_title = icon_title; program.x11_icon_filename = x11_icon_filename; program.x11_iconmask_filename = x11_iconmask_filename; program.sdl_icon_filename = sdl_icon_filename; program.msdos_cursor_filename = msdos_cursor_filename; program.cookie_prefix = cookie_prefix; program.filename_prefix = filename_prefix; program.version_major = VERSION_MAJOR(program_version); program.version_minor = VERSION_MINOR(program_version); program.version_patch = VERSION_PATCH(program_version); program.error_filename = getErrorFilename(ERROR_BASENAME); program.error_file = stderr; }
void c3_exercise_1::loadTextures(std::array<GLuint, 2> &textures, GLuint shaderProgram) { glGenTextures(2, textures.data()); int width, height; unsigned char *image; std::string basePath = getBasePath(); std::string kittenTexPath = basePath + "Content\\sample.png"; std::string puppyTexPath = basePath + "Content\\sample2.png"; glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, textures[0]); image = SOIL_load_image(kittenTexPath.c_str(), &width, &height, 0, SOIL_LOAD_RGB); printf("%s\n", SOIL_last_result()); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, image); SOIL_free_image_data(image); glUniform1i(glGetUniformLocation(shaderProgram, "texKitten"), 0); setTextureParameters(); glActiveTexture(GL_TEXTURE1); glBindTexture(GL_TEXTURE_2D, textures[1]); image = SOIL_load_image(puppyTexPath.c_str(), &width, &height, 0, SOIL_LOAD_RGB); printf("%s\n", SOIL_last_result()); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, image); SOIL_free_image_data(image); glUniform1i(glGetUniformLocation(shaderProgram, "texPuppy"), 1); setTextureParameters(); }
int dirExists(char *dname, int create) { char realName[128] = {""}; #ifdef XBOX getBasePath(realName, dname, 0); return CreateDirectory(realName, NULL); #else DIR *fd1 = NULL; int fd2 = -1; strncpy(realName, dname, 128); fd1 = opendir(realName); if(fd1 != NULL) { closedir(fd1); return 1; } if(create) { fd2 = MKDIR(realName); if(fd2 < 0) { return 0; } #ifdef DARWIN chmod(realName, 0777); #endif return 1; } #endif return 0; }
ConfigurationManager::ConfigurationManager(std::string configFile) : persistenceManager(NULL), storage(NULL) { configBasePath = getBasePath(configFile); configFileName = getFileName(configFile); persistenceManager = new FilePersistenceManager(configBasePath, false); if(!persistenceManager) { LOG_ERROR("failed to create file persistence manager for path "<<configBasePath) throw std::runtime_error("failed to create file persistence manager"); } storage = persistenceManager->retrieveKeyValueStorage("", configFileName); if(!storage) { persistenceManager->close(); delete persistenceManager; LOG_ERROR("failed to retrieve storage for configuration file "<<configFile) throw std::runtime_error("failed to retrieve storage for configuration file"); } entries = new EntriesMap(); retrieveEntries(); workingDir = retrieveAsPath("general", "working-dir"); //HC }
CLog::CLog() : enabled(false), file(0) { m_write = new boost::recursive_mutex(); // Get base path. homepath = getBasePath(); }
void Menu() { int done = 0; int ctrl = 0; // Set video mode based on aspect ratio if(CONF_GetAspectRatio() == CONF_ASPECT_16_9) isWide = 1; setVideoMode(); drawLogo(); dListTotal = findPaks(); dListCurrentPosition = 0; if(dListTotal != 1) { sortList(); getAllLogs(); initMenu(1); drawMenu(); pControl = ControlMenu; while(!done) { ctrl = Control(); switch(ctrl) { case 1: case 2: done = 1; break; case 3: drawLogs(); break; case -1: drawMenu(); break; case -2: // BGM player isn't supported break; } } freeAllLogs(); termMenu(); if(ctrl == 2) { if (filelist) { free(filelist); filelist = NULL; } borExit(0); } } getBasePath(packfile, filelist[dListCurrentPosition+dListScrollPosition].filename, 1); free(filelist); }
CLog::CLog() : enabled(false), file(0) { #ifndef NO_BOOST m_write = new boost::recursive_mutex(); #endif // Get base path. homepath = getBasePath(); }
CLog::CLog(const CString& _file, bool _enabled) : enabled(_enabled), filename(_file), file(0) { m_write = new boost::recursive_mutex(); // Get base path. homepath = getBasePath(); // Open the file now. if (enabled) file = fopen((homepath + filename).text(), "a"); if (0 == file) enabled = false; }
std::string getFolder(std::string key) { std::string default_value = getBasePath().string(); if (key == "certificate-path") { default_value = CERT_FOLDER; } else if (key == "module-path") { default_value = MODULE_FOLDER; } else if (key == "web-path") { default_value = WEB_FOLDER; } else if (key == "scripts") { default_value = SCRIPTS_FOLDER; } else if (key == CACHE_FOLDER_KEY) { default_value = DEFAULT_CACHE_PATH; } else if (key == CRASH_ARCHIVE_FOLDER_KEY) { default_value = CRASH_ARCHIVE_FOLDER; } else if (key == "base-path") { default_value = getBasePath().string(); } else if (key == "temp") { default_value = getTempPath().string(); } else if (key == "shared-path" || key == "base-path" || key == "exe-path") { default_value = getBasePath().string(); } #ifdef WIN32 else if (key == "common-appdata") { wchar_t buf[MAX_PATH + 1]; if (_SHGetSpecialFolderPath(NULL, buf, CSIDL_COMMON_APPDATA, FALSE)) default_value = utf8::cvt<std::string>(buf); else default_value = getBasePath().string(); } #else else if (key == "etc") { default_value = "/etc"; } #endif return default_value; }
void charicon::setIcon(QString character) { m_character = character; QString path = getCharPath(character) + "char_icon.png"; //LEGACY SUPPORT, for ao classic filestructure QString legacy_path = getBasePath() + "misc/DemoThings/" + character + "_char_icon.png"; //we also need a lowercase version for the legacy support. again because of inconsistent naming QString legacy_path_lower = getBasePath() + "misc/DemoThings/" + character.toLower() + "_char_icon.png"; if (fileExists(path, true)) { this->setStyleSheet("border-image:url(" + path + ")"); this->show(); } else if (fileExists(legacy_path, true)) { this->setStyleSheet("border-image:url(" + legacy_path + ")"); this->show(); } else if (fileExists(legacy_path_lower, true)) { this->setStyleSheet("border-image:url(" + legacy_path_lower + ")"); this->show(); } //if the char icon could not be found we add a neat text label to help the user :) else { this->setText(character); this->show(); } }
void InviwoApplication::printApplicationInfo() { LogInfoCustom("InviwoInfo", "Inviwo Version: " << IVW_VERSION); LogInfoCustom("InviwoInfo", "Base Path: " << getBasePath()); std::string config = ""; #ifdef CMAKE_GENERATOR config += std::string(CMAKE_GENERATOR); #endif #if defined(CMAKE_BUILD_TYPE) config += " [" + std::string(CMAKE_BUILD_TYPE) + "]"; #elif defined(CMAKE_INTDIR) config += " [" + std::string(CMAKE_INTDIR) + "]"; #endif if (config != "") LogInfoCustom("InviwoInfo", "Config: " << config); }
/* * The initialization routine is responsible for delegating the necessary * initialization options to QGis Core. It is a replacement routine of the * original initialization routine. */ static inline void RFGisInitialization (const QString & prefix_path, const QString & plugin_path) { // The prefix path is responsible for recognizing where libraries are // put. In normal circumstances, the configure script will set this on // our config.h, however, if for some reason this isn't the proper // location, it can be overriden using the --prefix-path option. // Besides the prefix path, it is feasible to require the need of the // plugin path to be specified. Normally, the plugin path is determined // using the configure script, however, this might need to be overridden. // Due to the dependent layout of initialization, the first thing set is the // QgsProviderRegistry. qDebug() << "Plugin Path: " << plugin_path << "\n"; qDebug() << "Prefix Path: " << prefix_path << "\n"; QgsProviderRegistry::instance (plugin_path); QgsApplication::setPrefixPath (prefix_path); QgsApplication::setPluginPath (plugin_path); QStringList svgPaths; #if defined (ANDROID) QgsApplication::setPkgDataPath (prefix_path + "/files"); svgPaths << (prefix_path + "/files/application"); #else QgsApplication::setPkgDataPath (prefix_path); svgPaths << prefix_path; #if defined (HAVE_GETPID) && HAVE_GETPID == 1 QString basePath = getBasePath(); qDebug() << "BasePath: " + basePath; svgPaths << basePath; #endif QDir dir; svgPaths << dir.absolutePath(); #endif QgsApplication::setDefaultSvgPaths (svgPaths); QgsMapLayerRegistry::instance (); RFGisWorker::instance (); }
void ReadiumJSApi::digInto(const NavigationList& list, TOCEntry& rOut) { std::string sBaseUrl = getBasePath(); // fast fix int iTrimLen = sBaseUrl.length(); for (NavigationList::const_iterator v = list.begin(); v != list.end(); ++v) { NavigationPoint* pt = dynamic_cast<NavigationPoint*>(v->get()); std::string sTitle = pt->Title().c_str(); std::string sPath = pt->AbsolutePath(pkg).c_str(); if (0 == sPath.find(sBaseUrl)) { sPath = sPath.substr(iTrimLen, sPath.length()); } rOut.arrChildren.push_back(TOCEntry(sTitle, sPath)); const NavigationList& list = pt->Children(); digInto(list, (rOut.arrChildren.back()) ); } }
s_screen *getPreview(char *filename) { int width = factor == 4 ? 640 : (factor == 2 ? 320 : 160); int height = factor == 4 ? 480 : (factor == 2 ? 240 : 120); s_screen *title = NULL; s_screen *scale = NULL; // Grab current path and filename getBasePath(packfile, filename, 1); // Create & Load & Scale Image return NULL; //if(!loadscreen("data/bgs/title.gif", packfile, realPal, PIXEL_8, &title)) return NULL; if((scale = allocscreen(width, height, title->pixelformat)) == NULL) return NULL; scalescreen(scale, title); // Free Images and Terminate FileCaching freescreen(&title); // ScreenShots within Menu will be saved as "Menu" strncpy(packfile,"Menu.ext",128); return scale; }
int runtime (int argc, char * argv[]) { QApplication app(argc, argv); qmlRegisterType <RFGisQMLMap> ("RFGis", 1, 0, "Map"); #if !defined (ANDROID) setenv ("AUTOCONF_PROJECT_CODE_PATH", PROJECT_CODE_PATH, 1); #else char *android_argv[3]; android_argv[0] = argv[0]; QString prefix_path = "--prefix-path=" % QString(getenv("PREFIX_PATH")); QString plugin_path = "--plugin-path=" % QString(getenv("PLUGIN_PATH")); QString app_path = QString(getenv("PREFIX_PATH")) % "/files/application"; qDebug() << "Prefix Path: " << prefix_path; qDebug() << "Plugin Path: " << plugin_path; qDebug() << "Application: " << app_path; char *alloca_prefix = new char[prefix_path.size () + 1]; char *alloca_plugin = new char[plugin_path.size () + 1]; char *alloca_app = new char[app_path.size () + 1]; memset (alloca_prefix, 0, prefix_path.size () + 1); memset (alloca_plugin, 0, plugin_path.size () + 1); memset (alloca_app, 0, app_path.size () + 1); QByteArray prefix_ba = prefix_path.toUtf8(); QByteArray plugin_ba = plugin_path.toUtf8(); QByteArray app_ba = app_path.toUtf8(); memcpy(alloca_prefix, prefix_ba.constData (), prefix_path.size ()); memcpy(alloca_plugin, plugin_ba.constData (), plugin_path.size ()); memcpy(alloca_app, app_ba.constData (), app_path.size ()); qDebug() << "Allocated Prefix" << QString(alloca_prefix); qDebug() << "Allocated Plugin" << QString(alloca_plugin); qDebug() << "Allocated Application" << QString(alloca_app); android_argv[1] = alloca_prefix; android_argv[2] = alloca_plugin; setenv ("AUTOCONF_PROJECT_CODE_PATH", alloca_app, 1); #endif Py_Initialize(); #if !defined (ANDROID) PySys_SetArgv(argc, argv); #else PySys_SetArgv(3, android_argv); #endif QString python_path = QString(getenv("PYTHONPATH")); #if defined (HAVE_GETPID) && !defined (ANDROID) && HAVE_GETPID == 1 if (python_path.size ()) { python_path += ":" + getBasePath(); } else { python_path = getBasePath(); } #endif if (python_path.size ()) python_path += ":"; python_path += "."; char *python_path_buffer = 0; char path_object_name[5]; qDebug() << "Additional python path: " << python_path; memcpy(path_object_name, "path", 5); PyObject *sys_path = PySys_GetObject(path_object_name); if (sys_path != 0) { QStringList paths_list = python_path.split(':'); for (int i = 0; i < paths_list.size(); ++i) { char *buffer = 0; QByteArray b_path = paths_list[i].toLatin1(); const char *path = b_path.data(); size_t len = strlen(path) + 1; buffer = new char[len]; memcpy(buffer, path, len); PyList_Append(sys_path, PyString_FromString(buffer)); delete buffer; } } else { QByteArray b_path = python_path.toLatin1(); const char *path = b_path.data(); size_t len = strlen(path) + 1; python_path_buffer = new char[len]; memcpy(python_path_buffer, path, len); PySys_SetPath(python_path_buffer); } PyEval_InitThreads(); preConfigure (); qDebug() << "Preconfiguration Finished"; RFGisConfigure config; RFGisInitialization (config.prefix_path (), config.plugin_path ()); configure (); #if defined (ANDROID) run_interactivenetconsole (); #endif int code = app.exec (); rfgisExit(code); return code; }
int LoadGLTextures(const aiScene* scene) { ILboolean success; /* Before calling ilInit() version should be checked. */ if (ilGetInteger(IL_VERSION_NUM) < IL_VERSION) { ILint test = ilGetInteger(IL_VERSION_NUM); /// wrong DevIL version /// std::string err_msg = "Wrong DevIL version. Old devil.dll in system32/SysWow64?"; char* cErr_msg = (char *) err_msg.c_str(); abortGLInit(cErr_msg); return -1; } ilInit(); /* Initialization of DevIL */ if (scene->HasTextures()) abortGLInit("Support for meshes with embedded textures is not implemented"); /* getTexture Filenames and Numb of Textures */ for (unsigned int m=0; m<scene->mNumMaterials; m++) { int texIndex = 0; aiReturn texFound = AI_SUCCESS; aiString path; // filename while (texFound == AI_SUCCESS) { texFound = scene->mMaterials[m]->GetTexture(aiTextureType_DIFFUSE, texIndex, &path); textureIdMap[path.data] = NULL; //fill map with textures, pointers still NULL yet texIndex++; } } int numTextures = textureIdMap.size(); /* array with DevIL image IDs */ ILuint* imageIds = NULL; imageIds = new ILuint[numTextures]; /* generate DevIL Image IDs */ ilGenImages(numTextures, imageIds); /* Generation of numTextures image names */ /* create and fill array with GL texture ids */ textureIds = new GLuint[numTextures]; glGenTextures(numTextures, textureIds); /* Texture name generation */ /* define texture path */ //std::string texturepath = "../../../test/models/Obj/"; /* get iterator */ std::map<std::string, GLuint*>::iterator itr = textureIdMap.begin(); std::string basepath = getBasePath(modelpath); for (int i=0; i<numTextures; i++) { //save IL image ID std::string filename = (*itr).first; // get filename (*itr).second = &textureIds[i]; // save texture id for filename in map itr++; // next texture ilBindImage(imageIds[i]); /* Binding of DevIL image name */ std::string fileloc = basepath + filename; /* Loading of image */ success = ilLoadImage(fileloc.c_str()); if (success) /* If no error occured: */ { success = ilConvertImage(IL_RGB, IL_UNSIGNED_BYTE); /* Convert every colour component into unsigned byte. If your image contains alpha channel you can replace IL_RGB with IL_RGBA */ if (!success) { /* Error occured */ abortGLInit("Couldn't convert image"); return -1; } //glGenTextures(numTextures, &textureIds[i]); /* Texture name generation */ glBindTexture(GL_TEXTURE_2D, textureIds[i]); /* Binding of texture name */ //redefine standard texture values glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); /* We will use linear interpolation for magnification filter */ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); /* We will use linear interpolation for minifying filter */ glTexImage2D(GL_TEXTURE_2D, 0, ilGetInteger(IL_IMAGE_BPP), ilGetInteger(IL_IMAGE_WIDTH), ilGetInteger(IL_IMAGE_HEIGHT), 0, ilGetInteger(IL_IMAGE_FORMAT), GL_UNSIGNED_BYTE, ilGetData()); /* Texture specification */ } else { /* Error occured */ MessageBox(NULL, ("Couldn't load Image: " + fileloc).c_str() , "ERROR", MB_OK | MB_ICONEXCLAMATION); } } ilDeleteImages(numTextures, imageIds); /* Because we have already copied image data into texture data we can release memory used by image. */ //Cleanup delete [] imageIds; imageIds = NULL; //return success; return TRUE; }
std::string InviwoApplication::getPath(PathType pathType, const std::string& suffix, const bool& createFolder) { std::string result = getBasePath(); switch (pathType) { case inviwo::InviwoApplication::PATH_DATA: result += "/data"; break; case inviwo::InviwoApplication::PATH_VOLUMES: result += "/data/volumes"; break; case inviwo::InviwoApplication::PATH_MODULES: result += "/modules"; break; case inviwo::InviwoApplication::PATH_WORKSPACES: result += "/data/workspaces"; break; case inviwo::InviwoApplication::PATH_PORTINSPECTORS: result += "/data/workspaces/portinspectors"; break; case inviwo::InviwoApplication::PATH_SCRIPTS: result += "/data/scripts"; break; case inviwo::InviwoApplication::PATH_IMAGES: result += "/data/images"; break; case inviwo::InviwoApplication::PATH_DATABASES: result += "/data/databases"; break; case inviwo::InviwoApplication::PATH_RESOURCES: result += "/resources"; break; case inviwo::InviwoApplication::PATH_TRANSFERFUNCTIONS: result += "/data/transferfunctions"; break; case inviwo::InviwoApplication::PATH_SETTINGS: result = filesystem::getInviwoUserSettingsPath(); break; case inviwo::InviwoApplication::PATH_HELP: result += "/data/help"; break; default: break; } if (createFolder) { filesystem::createDirectoryRecursively(result); } return result + suffix; }
void Lobby::LoadFavorites() { if (fileExists((getBasePath() + "favorites.txt"), true)) favoritefile.setFileName(getBasePath() + "favorites.txt"); //legacy support, the new name is favorites.txt else if (fileExists((getBasePath() + "serverlist.txt"), true)) favoritefile.setFileName(getBasePath() + "serverlist.txt"); else { callError("could not find \"favorites.txt\" "); return; } if (!favoritefile.open(QIODevice::ReadOnly)) { callError("failed to read \"favorites.txt\""); } QTextStream in(&favoritefile); QVector<server_type> temp_servers; for(int line_count{0}; ; ++line_count) { if (in.atEnd()) break; QString line = in.readLine(); QStringList line_contents = line.split(":"); //we check if the line is valid first if (line_contents.size() == 3) { server_type serv; serv.name = line_contents.at(2); serv.ip = line_contents.at(0); serv.port = line_contents.at(1).toInt(); temp_servers.insert(line_count, serv); favoriteservers = temp_servers; //favoriteservers.insert(line_count, serv); } else { //QString str_line = QString::number(line_count + 1); //bad servers already show up as !MISCONFIGURED! we dont need this dumb error >:v( //callError("favorites.txt appears to be misconfigured on line " + str_line + ". Expected <ip>:<port>:<name> format."); server_type serv; serv.name = "!MISCONFIGURED!"; serv.ip = ""; serv.port = 0; temp_servers.insert(line_count, serv); favoriteservers = temp_servers; } if (in.atEnd()) break; } favoritefile.close(); }
int main(int argc, char *argv[]) { // Shut down the server if we get a kill signal. signal( SIGINT, (sighandler_t) shutdownServer ); signal( SIGTERM, (sighandler_t) shutdownServer ); // Grab the base path to the server executable. getBasePath(); // Initialize data directory. filesystem[0].addDir("global"); filesystem[1].addDir("global/heads"); filesystem[2].addDir("global/bodies"); filesystem[3].addDir("global/swords"); filesystem[4].addDir("global/shields"); // Definitions CSocket playerSock, playerSockOld, serverSock; playerList.clear(); serverList.clear(); // Load Settings settings = new CSettings(homepath + "settings.ini"); if (!settings->isOpened()) { serverlog.out( "[Error] Could not load settings.\n" ); return ERR_SETTINGS; } // Load ip bans. ipBans = CString::loadToken(homepath + "ipbans.txt", "\n", true); serverlog.out("Loaded following IP bans:\n"); for (std::vector<CString>::iterator i = ipBans.begin(); i != ipBans.end(); ++i) serverlog.out("\t%s\n", i->text()); // Load server types. serverTypes = CString::loadToken("servertypes.txt", "\n", true); // Server sock. serverSock.setType( SOCKET_TYPE_SERVER ); serverSock.setProtocol( SOCKET_PROTOCOL_TCP ); serverSock.setDescription( "serverSock" ); CString serverInterface = settings->getStr("gserverInterface"); if (serverInterface == "AUTO") serverInterface.clear(); if ( serverSock.init( (serverInterface.isEmpty() ? 0 : serverInterface.text()), settings->getStr("gserverPort").text() ) ) { serverlog.out( "[Error] Could not initialize sockets.\n" ); return ERR_LISTEN; } // Player sock. playerSock.setType( SOCKET_TYPE_SERVER ); playerSock.setProtocol( SOCKET_PROTOCOL_TCP ); playerSock.setDescription( "playerSock" ); CString playerInterface = settings->getStr("clientInterface"); if (playerInterface == "AUTO") playerInterface.clear(); if ( playerSock.init( (playerInterface.isEmpty() ? 0 : playerInterface.text()), settings->getStr("clientPort").text() ) ) { serverlog.out( "[Error] Could not initialize sockets.\n" ); return ERR_LISTEN; } // Player sock. playerSockOld.setType( SOCKET_TYPE_SERVER ); playerSockOld.setProtocol( SOCKET_PROTOCOL_TCP ); playerSockOld.setDescription( "playerSockOld" ); if ( playerSockOld.init( (playerInterface.isEmpty() ? 0 : playerInterface.text()), settings->getStr("clientPortOld").text() ) ) { serverlog.out( "[Error] Could not initialize sockets.\n" ); return ERR_LISTEN; } // Connect sockets. if ( serverSock.connect() || playerSock.connect() || playerSockOld.connect() ) { serverlog.out( "[Error] Could not connect sockets.\n" ); return ERR_SOCKETS; } // MySQL-Connect #ifndef NO_MYSQL mySQL = new CMySQL(settings->getStr("server").text(), settings->getStr("user").text(), settings->getStr("password").text(), settings->getStr("database").text(), settings->getStr("sockfile").text()); vBmySQL = new CMySQL(settings->getStr("server").text(), settings->getStr("vbuser").text(), settings->getStr("vbpassword").text(), settings->getStr("vbdatabase").text(), settings->getStr("sockfile").text()); if (!mySQL->ping()) { serverlog.out( "[Error] No response from MySQL.\n" ); return ERR_MYSQL; } // Truncate servers table from MySQL. CString query; query << "TRUNCATE TABLE " << settings->getStr("serverlist"); mySQL->add_simple_query(query); query = CString("TRUNCATE TABLE ") << settings->getStr("securelogin"); mySQL->add_simple_query(query); mySQL->update(); #endif // Create Packet-Functions createPLFunctions(); createSVFunctions(); // Flavor text serverlog.out( CString() << "Graal Reborn - List Server V2\n" << "List server started..\n" << "Client port: " << CString(settings->getInt("clientport")) << "\n" << "GServer port: " << CString(settings->getInt("gserverport")) << "\n" ); #ifdef NO_MYSQL // Notify the user that they are running in No MySQL mode serverlog.out( CString() << "Running in No MySQL mode, all account and guild checks are disabled.\n"); #endif // Main Loop time_t t5min = time(0); while (running) { // Make sure MySQL is active #ifndef NO_MYSQL if (!mySQL->ping()) serverlog.out( "[Error] No response from MySQL.\n" ); mySQL->update(); #endif // Accept New Connections acceptSock(playerSock, SOCK_PLAYER); acceptSock(playerSockOld, SOCK_PLAYEROLD); acceptSock(serverSock, SOCK_SERVER); // Player Sockets for ( std::vector<TPlayer*>::iterator iter = playerList.begin(); iter != playerList.end(); ) { TPlayer* player = (TPlayer*)*iter; if ( player->doMain() == false ) { player->sendCompress(); delete player; iter = playerList.erase( iter ); } else ++iter; } // Server Sockets for ( std::vector<TServer*>::iterator iter = serverList.begin(); iter != serverList.end() ; ) { TServer* server = (TServer*)*iter; if (server == 0) { serverlog.out(CString() << "Server disconnected: [Orphaned server]\n"); iter = serverList.erase(iter); continue; } // Check for a timed out server. if ((int)server->getLastData() >= 300) { serverlog.out(CString() << "Server disconnected: " << server->getName() << " [Timed out]\n"); server->sendCompress(); delete server; iter = serverList.erase(iter); continue; } // Execute server stuff. if (server->doMain() == false) { serverlog.out(CString() << "Server disconnected: " << server->getName() << "\n"); server->sendCompress(); delete server; iter = serverList.erase(iter); continue; } ++iter; } // Every 5 minutes... // Reload ip bans. // Resync the file system. if ((int)difftime(time(0), t5min) > (5*60)) { ipBans = CString::loadToken("ipbans.txt", "\n", true); serverTypes = CString::loadToken("servertypes.txt", "\n", true); for (int i = 0; i < 5; ++i) filesystem[i].resync(); t5min = time(0); } // Wait wait(100); } // Remove all servers. // This guarantees the server deconstructors are called. for ( std::vector<TServer*>::iterator iter = serverList.begin(); iter != serverList.end() ; ) { TServer* server = (TServer*)*iter; delete server; iter = serverList.erase( iter ); } return ERR_SUCCESS; }