Example #1
0
int CConfigInt::GetValue()
{
    if (HasToRefresh())
        m_Value = GetConfigInt(GetSection(), GetKey(), m_Default);
    
    return m_Value;
}
Example #2
0
static int GetConfigRefreshTime()
{
    const int DefaultRefreshTime = 60;
    static int RefreshTime = 0;
    if (RefreshTime == 0)
        RefreshTime = GetConfigInt(
            GeneralConfigSection, "RefreshTime", DefaultRefreshTime);
    
    return RefreshTime;
}
Example #3
0
bool CSmartServer::InitCommandReceiver()
{
	ushort usPort  = 0;
	string sBindAddress;

	GetConfigInt(ECO_BIND_PORT, usPort);
	ASSERTE(usPort);
	GetConfigString(ECO_BIND_ADDRESS, sBindAddress);
	ASSERTE(!sBindAddress.empty());

	bool bResult = Start(usPort, sBindAddress);
	return bResult;
}
Example #4
0
/*
 * CommLoadSettings:  Load comm parameters from INI file.
 *  If use_defaults is False, try to load fonts from INI file.
 *  Otherwise use default comm settings.
 */
void CommLoadSettings(void)
{
   config.comm.timeout = GetConfigInt(comm_section, INIRedialDelay, DefaultRedialDelay, ini_file);

   GetPrivateProfileString(comm_section, INIHostname, DefaultHostname, 
			   inihost, MAXHOST, ini_file);
   GetPrivateProfileString(comm_section, INIDomainFormat, DefaultDomainFormat, 
			   config.comm.domainformat, MAXHOST, ini_file);
   if (!strstr(config.comm.domainformat, "%d"))
      strcpy(config.comm.domainformat, DefaultDomainFormat);
   config.comm.server_num = GetConfigInt(comm_section, INIServerNum, DefaultServerNum, ini_file);

   // We read the DomainFormat INI value (which we don't write into the INI)
   // and we set the hostname from that and the specified server number.
   //
   // A Meridian Service Provider other than NDS can supply another
   // value for DomainFormat in either the code (DefaultDomainFormat)
   // or by setting Domain=msp%d.foobar.co.sw in the INI.
   // We require there to be one %d in the format somewhere.
   //
   ConfigSetServerNameByNumber(config.comm.server_num);

   // What's the default port number we should connect to?  This varies by server number.
   config.comm.sockport = GetConfigInt(comm_section, INISockPort, -1, ini_file);

   if (config.comm.sockport == -1)
   {
      // We have no socket number set in the .ini file.
      config.comm.constant_port = False;
      ConfigSetSocketPortByNumber(config.comm.server_num);
   }
   else
   {
      config.comm.constant_port = True;
   }

}
Example #5
0
int ConfigTool::GetConfigInt(const char* config_key, const char *prefix)
{
	int value=0;

	CombinedKey(config_key, prefix);

	if(the_map.count(cfg_key)>0)
	{
		const char *val=the_map[cfg_key].c_str();
		if(IfNumChar(val[0])) value=atoi(the_map[cfg_key].c_str());
		else value=GetConfigInt(val); //else we search other gobal key without current prefix
	}
	else
	{
		printf("Config key \"%s\" missing!\n", cfg_key);
		exit(-1);
	}

	return value;
}
Example #6
0
void WindowSettingsLoad(WINDOWPLACEMENT *w)
{
   RECT *r = &w->rcNormalPosition;
   int def_x, def_y, def_width, def_height;

   // When no INI file exists, we need to give a default position for the maximized window.
   // We need to place the window so that its border is off the screen; this is the
   // default Windows behavior.
   def_x = - GetSystemMetrics(SM_CXFRAME);
   def_y = - GetSystemMetrics(SM_CYFRAME);

   // Try to make client window optimally sized, but also fit to screen
   def_width  = min(MAIN_DEF_WIDTH, GetSystemMetrics(SM_CXSCREEN));
   def_height = min(MAIN_DEF_HEIGHT, GetSystemMetrics(SM_CYSCREEN));

   r->left   = GetConfigInt(window_section, INILeft, MAIN_DEF_LEFT, ini_file);
   r->right  = GetConfigInt(window_section, INIRight, MAIN_DEF_LEFT + def_width, ini_file);
   r->top    = GetConfigInt(window_section, INITop, MAIN_DEF_TOP, ini_file);
   r->bottom = GetConfigInt(window_section, INIBottom, MAIN_DEF_TOP + def_height, ini_file);
   w->ptMaxPosition.x = GetConfigInt(window_section, INIMaxX, def_x, ini_file);
   w->ptMaxPosition.y = GetConfigInt(window_section, INIMaxY, def_y, ini_file);
   w->showCmd = GetConfigInt(window_section, INIShow, SW_SHOWNORMAL, ini_file);
}
Example #7
0
int main( int argc, char** argv )
{
    InitTests(argc, argv);

    Describe("Config module")
        .use(dummyExceptionSandbox)

        .it("can be initialized empty.", [](){

            Require(InitConfig(0, NULL) == true);
            DestroyConfig();
        })

        .it("has a proper destructor.", [](){

            const char* argv[] = {"", "--aaa=bbb"};

            {
                Require(InitConfig(2, argv) == true);
                ConfigScope scope;
                Require(strcmp(GetConfigString("aaa",""), "bbb") == 0);
            }

            {
                Require(InitConfig(0, NULL) == true);
                ConfigScope scope;
                Require(GetConfigString("aaa",NULL) == NULL);
            }
        })

        .it("can parse arguments.", [](){

            const char* argv[] = {"", "--aaa=bbb", "--foo=bar", "--ccc=ddd"};

            Require(InitConfig(4, argv) == true);
            ConfigScope scope;

            Require(strcmp(GetConfigString("foo",""), "bar") == 0);
            Require(strcmp(GetConfigString("foo","yyy"), "bar") == 0);
            Require(strcmp(GetConfigString("foo",NULL), "bar") == 0);
            Require(strcmp(GetConfigString("xxx",""), "") == 0);
            Require(strcmp(GetConfigString("xxx","yyy"), "yyy") == 0);
            Require(GetConfigString("xxx",NULL) == NULL);
        })

        .it("can convert integer values.", [](){

            const char* argv[] = {"", "--aaa=42", "--bbb=1.1", "--ccc=1.9"};

            Require(InitConfig(4, argv) == true);
            ConfigScope scope;

            Require(GetConfigInt("aaa", 0) == 42);
            Require(GetConfigInt("bbb", 0) == 1);
            Require(GetConfigInt("ccc", 0) == 1);
            Require(GetConfigInt("xxx", 0) == 0);
        })

        .it("can convert floating point values.", [](){

            const char* argv[] = {"", "--aaa=42", "--bbb=1.1", "--ccc=1.9"};

            Require(InitConfig(4, argv) == true);
            ConfigScope scope;

            Require(GetConfigFloat("aaa", 0) == 42);
            Require(GetConfigFloat("bbb", 0) == 1.1f);
            Require(GetConfigFloat("ccc", 0) == 1.9f);
            Require(GetConfigFloat("xxx", 0.1f) == 0.1f);
        })

        .it("can convert boolean values.", [](){

            const char* argv[] = {
                "",
                "--aaa=42",
                "--bbb=1.1",
                "--ccc=1.9",
                "--ddd=0",
                "--eee=0.0",
                "--fff=true",
                "--ggg=false",
                "--hhh=yes",
                "--jjj=no"};

            Require(InitConfig(10, argv) == true);
            ConfigScope scope;

            Require(GetConfigBool("aaa", false) == true);
            Require(GetConfigBool("bbb", false) == true);
            Require(GetConfigBool("ccc", false) == true);
            Require(GetConfigBool("ddd", true) == false);
            Require(GetConfigBool("eee", true) == false);
            Require(GetConfigBool("fff", false) == true);
            Require(GetConfigBool("ggg", true) == false);
            Require(GetConfigBool("hhh", false) == true);
            Require(GetConfigBool("jjj", true) == false);

            Require(GetConfigBool("xxx", true) == true);
            Require(GetConfigBool("xxx", false) == false);
        })

        .it("can parse ini files.", [](){

            const char* argv[] = {"", "--config=config/Test.ini"};

            Require(InitConfig(2, argv) == true);
            ConfigScope scope;

            Require(GetConfigString("config", NULL) == NULL);
            Require(strcmp(GetConfigString("aaa", ""), "bbb") == 0);
            Require(strcmp(GetConfigString("foo.bar", ""), "baz") == 0);
            Require(strcmp(GetConfigString("foo.hello", ""), "Hello World") == 0);
        });

    return RunTests();
}
Example #8
0
int GetTimeSettings(void)
{
 return GetConfigInt(misc_section, INIDownload, 0, ini_file);

}
Example #9
0
/* 
 * TimeSettingsLoad:  Load last download time from INI file
 */
void TimeSettingsLoad(void)
{
   config.download_time = GetConfigInt(misc_section, INIDownload, 0, ini_file);
}
Example #10
0
/*
 * ConfigLoad:  Load user configuration from INI file.  If entries not present
 *   in INI file, assign defaults.
 */
void ConfigLoad(void)
{
   int index = 0;
   char *start, *ptr;
   char ignore_string[MAX_IGNORE_LIST * (MAX_CHARNAME + 1) + 1];
   
   config.save_settings = GetConfigInt(misc_section, INISaveOnExit, True, ini_file);
   config.play_music    = GetConfigInt(misc_section, INIPlayMusic, True, ini_file);
   config.play_sound    = GetConfigInt(misc_section, INIPlaySound, True, ini_file);
   config.music_volume    = GetConfigInt(misc_section, INIMusicVolume, 100, ini_file);
   config.sound_volume    = GetConfigInt(misc_section, INISoundVolume, 100, ini_file);
   config.play_loop_sounds    = GetConfigInt(misc_section, INIPlayLoopSounds, True, ini_file);
   config.play_random_sounds    = GetConfigInt(misc_section, INIPlayRandomSounds, True, ini_file);
   config.large_area    = GetConfigInt(misc_section, INIArea, False, ini_file);
   gLargeArea = config.large_area;
   // Animation option removed 3/4/97 to fix movement bug
#ifndef NODPRINTFS
   config.animate       = GetConfigInt(misc_section, INIAnimate, True, ini_file);
#else
   config.animate       = True;
#endif
   config.ini_version   = GetConfigInt(misc_section, INIVersion, 0, ini_file);
   config.default_browser = GetConfigInt(misc_section, INIDefaultBrowser, True, ini_file);
   GetPrivateProfileString(misc_section, INIUserName, "", 
			   config.username, MAXUSERNAME, ini_file); 
   GetPrivateProfileString(misc_section, INIBrowser, "", 
			   config.browser, MAX_PATH, ini_file); 
   
   config.draw_names   = GetConfigInt(users_section, INIDrawNames, True, ini_file);
   config.ignore_all   = GetConfigInt(users_section, INIIgnoreAll, False, ini_file);
   config.no_broadcast = GetConfigInt(users_section, ININoBroadcast, False, ini_file);

   GetPrivateProfileString(users_section, INIIgnoreList, "", 
                           ignore_string, sizeof(ignore_string), ini_file);
   memset(config.ignore_list, 0, sizeof(config.ignore_list));
   // Parse ignore string: usernames separated by commas
   start = ignore_string;
   ptr = start;
   while (index < MAX_IGNORE_LIST && *ptr != 0) {
     if (*ptr == ',') {
       *ptr = 0;
       strncpy(config.ignore_list[index], start, MAX_CHARNAME);
       start = ptr + 1;
       ++index;
     }
     ++ptr;
   }
   
   config.scroll_lock  = GetConfigInt(interface_section, INIScrollLock, False, ini_file);
   config.drawmap      = GetConfigInt(interface_section, INIDrawMap, True, ini_file);
   config.tooltips     = GetConfigInt(interface_section, INITooltips, True, ini_file);
   config.inventory_num= GetConfigInt(interface_section, INIInventory, True, ini_file);
   config.aggressive   = GetConfigInt(interface_section, INIAggressive, False, ini_file);
   config.bounce       = GetConfigInt(interface_section, INIBounce, True, ini_file);
   config.toolbar      = GetConfigInt(interface_section, INIToolbar, True, ini_file);
   config.pain         = GetConfigInt(interface_section, INIPainFX, True, ini_file);
   config.weather      = GetConfigInt(interface_section, INIWeatherFX, False, ini_file);
   config.antiprofane  = GetConfigInt(interface_section, INIAntiProfane, True, ini_file);
   config.ignoreprofane = GetConfigInt(interface_section, INIIgnoreProfane, False, ini_file);
   config.extraprofane = GetConfigInt(interface_section, INIExtraProfane, False, ini_file);
   config.lagbox       = GetConfigInt(interface_section, INILagbox, True, ini_file);
   config.halocolor    = GetConfigInt(interface_section, INIHaloColor, 0, ini_file);
   config.colorcodes   = GetConfigInt(interface_section, INIColorCodes, True, ini_file);
   config.map_annotations = GetConfigInt(interface_section, INIMapAnnotations, True, ini_file);

   config.guest        = GetConfigInt(misc_section, INIGuest, False, ini_file);
   config.server_low   = GetConfigInt(misc_section, INIServerLow, 0, ini_file);
   config.server_high  = GetConfigInt(misc_section, INIServerHigh, 0, ini_file);
   config.server_guest = GetConfigInt(misc_section, INIServerGuest, 0, ini_file);
   config.lastPasswordChange = GetConfigInt(misc_section, INILastPass, 0, ini_file);

   /* charlie: 
		This works like this , the balance is a % between 10%-90% which controls how much of the memory
		goes to which cache, so a value of 70% means that 70% of the cache memory goes to the 
		object cache, the remaining 30% to the grid cache anything over 90% is clamped, as is
		anything below 10%
	*/

   config.CacheBalance   = GetConfigInt(misc_section, INICacheBalance,        70, ini_file);
   config.ObjectCacheMin = GetConfigInt(misc_section, INIObjectCacheMin, 6000000, ini_file);
   config.GridCacheMin = GetConfigInt(misc_section, INIGridCacheMin,   4000000, ini_file);

   if( config.CacheBalance < 10 ) config.CacheBalance = 10 ;
   if( config.CacheBalance > 90 ) config.CacheBalance = 90 ;

   config.soundLibrary = GetConfigInt(misc_section, INISoundLibrary, LIBRARY_MSS, ini_file);

#ifdef NODPRINTFS
   config.debug    = False;
   config.security = True;
   config.showMapBlocking = FALSE;
   config.showFPS = FALSE;
   config.showUnseenWalls = FALSE;
   config.showUnseenMonsters = FALSE;
   config.avoidDownloadAskDialog = FALSE;
   config.maxFPS = FALSE;
   config.clearCache = FALSE;
#else
   config.debug				= GetConfigInt(special_section, INIDebug, False, ini_file);
   config.security			= GetConfigInt(special_section, INISecurity, True, ini_file);
   config.showMapBlocking	= GetConfigInt(special_section, INIShowMapBlocking, 0, ini_file);
   config.showFPS			= GetConfigInt(special_section, INIShowFPS, 0, ini_file);
   config.showUnseenWalls	= GetConfigInt(special_section, INIShowUnseenWalls, 0, ini_file);
   config.showUnseenMonsters = GetConfigInt(special_section, INIShowUnseenMonsters, 0, ini_file);
   config.avoidDownloadAskDialog = GetConfigInt(special_section, INIAvoidDownloadAskDialog, 0, ini_file);
   config.maxFPS			= GetConfigInt(special_section, INIMaxFPS, 70, ini_file);
   config.clearCache		= GetConfigInt(special_section, INIClearCache, False, ini_file);
   //config.quickstart = GetConfigInt(special_section, INIQuickStart, 0, ini_file);
#endif

   config.timeout	= GetConfigInt(misc_section, INITimeout, DefaultTimeout, ini_file);
   config.technical = GetConfigInt(special_section, INITechnical, False, ini_file);

   TimeSettingsLoad();
}
Example #11
0
void InitWindow()
{
    const int width  = GetConfigInt("window.width",  640);
    const int height = GetConfigInt("window.height", 480);
    const char* title = GetConfigString("window.title", "Konstrukt");

    const bool debug = GetConfigBool("opengl.debug", false);
    const bool vsync = GetConfigBool("opengl.vsync", true);

    LogInfo("Compiled with GLFW %d.%d.%d",
             GLFW_VERSION_MAJOR,
             GLFW_VERSION_MINOR,
             GLFW_VERSION_REVISION);
    LogInfo("Using GLFW %s", glfwGetVersionString());

    assert(g_Window == NULL);
    glfwSetErrorCallback(OnGLFWError);
    if(!glfwInit())
        FatalError("GLFW init failed.");

    glfwDefaultWindowHints();
    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);
    glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
    glfwWindowHint(GLFW_DEPTH_BITS, GetConfigInt("opengl.depth-bits", 24));
    glfwWindowHint(GLFW_STENCIL_BITS, 0);
    glfwWindowHint(GLFW_SAMPLES, GetConfigInt("opengl.samples", 0));
    glfwWindowHint(GLFW_SRGB_CAPABLE, GL_TRUE);
    glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, debug ? GL_TRUE : GL_FALSE);

    g_Window = glfwCreateWindow(width, height, title, NULL, NULL);
    if(!g_Window)
        FatalError("Window creation failed.");

    glfwGetWindowSize(g_Window, &g_WindowWidth, &g_WindowHeight);
    glfwGetFramebufferSize(g_Window, &g_FramebufferWidth, &g_FramebufferHeight);

    glfwMakeContextCurrent(g_Window);

    if(!flextInit(g_Window))
        FatalError("Failed to load OpenGL extensions.");

    LogInfo("Using OpenGL %s\n"
            "Vendor: %s\n"
            "Renderer: %s\n"
            "GLSL: %s",
            glGetString(GL_VERSION),
            glGetString(GL_VENDOR),
            glGetString(GL_RENDERER),
            glGetString(GL_SHADING_LANGUAGE_VERSION));

    if(vsync)
    {
        if(glfwExtensionSupported("GLX_EXT_swap_control_tear") ||
           glfwExtensionSupported("WGL_EXT_swap_control_tear"))
            glfwSwapInterval(-1); // enable vsync (allow the driver to swap even if a frame arrives a little bit late)
        else
            glfwSwapInterval(1); // enable vsync
    }
    else
    {
        glfwSwapInterval(0); // disable vsync
    }

    glfwSetInputMode(g_Window, GLFW_CURSOR, GLFW_CURSOR_NORMAL);
    glfwSetInputMode(g_Window, GLFW_STICKY_KEYS, GL_FALSE);
    glfwSetInputMode(g_Window, GLFW_STICKY_MOUSE_BUTTONS, GL_FALSE);

    if(debug)
    {
        if(!FLEXT_ARB_debug_output)
            FatalError("Debug output requested, but it's not supported!");

        glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB);
        glDebugMessageCallbackARB(OnDebugEvent, NULL);
        LogInfo("Debug output supported! You may receive debug messages from your OpenGL driver.");
    }

    glfwSetWindowSizeCallback(g_Window, OnWindowResize);
    glfwSetFramebufferSizeCallback(g_Window, OnFramebufferResize);
    glfwSetMouseButtonCallback(g_Window, OnMouseButtonAction);
    glfwSetScrollCallback(g_Window, OnMouseScroll);
    glfwSetCursorPosCallback(g_Window, OnCursorMove);
    glfwSetKeyCallback(g_Window, OnKeyAction);
}