コード例 #1
0
ファイル: search.cpp プロジェクト: SnakekillerX/darkstar
void search_config_read(const int8* file)
{
	int8 line[1024], w1[1024], w2[1024];
	FILE* fp;

	fp = fopen(file,"r");
	if( fp == NULL )
	{
		ShowError("configuration file not found at: %s\n", file);
		return;
	}

	while( fgets(line, sizeof(line), fp) )
	{
		int8* ptr;

        if( line[0] == '#' )
			continue;
		if( sscanf(line, "%[^:]: %[^\t\r\n]", w1, w2) < 2 )
			continue;

		//Strip trailing spaces
		ptr = w2 + strlen(w2);
		while (--ptr >= w2 && *ptr == ' ');
		ptr++;
		*ptr = '\0';
		
		if (strcmp(w1,"mysql_host") == 0)
		{
			search_config.mysql_host = aStrdup(w2);
		}
		else if (strcmp(w1,"mysql_login") == 0)
		{
			search_config.mysql_login = aStrdup(w2);
		}
		else if (strcmp(w1,"mysql_password") == 0)
		{
			search_config.mysql_password = aStrdup(w2);
		}
		else if (strcmp(w1,"mysql_port") == 0)
		{
			search_config.mysql_port = atoi(w2);
		}
		else if (strcmp(w1,"mysql_database") == 0)
		{
			search_config.mysql_database = aStrdup(w2);
		}
		else
		{
			ShowWarning(CL_YELLOW"Unknown setting '%s' in file %s\n" CL_RESET, w1, file);
		}
	}
	fclose(fp);
}
コード例 #2
0
ファイル: npc_chat.c プロジェクト: Celso1415/Fusion
/**
 * define/compile a new pattern
 */
void npc_chat_def_pattern (struct npc_data *nd, int setid, const char *pattern, const char *label)
{
	const char *err;
	int erroff;
	struct pcrematch_set *s = lookup_pcreset (nd, setid);
	struct pcrematch_entry *e = create_pcrematch_entry (s);
	e->pattern = aStrdup (pattern);
	e->label = aStrdup (label);
	e->pcre_ = pcre_compile (pattern, PCRE_CASELESS, &err, &erroff, NULL);
	e->pcre_extra_ = pcre_study (e->pcre_, 0, &err);
}
コード例 #3
0
ファイル: mapreg.c プロジェクト: Chocolate31/eamod
/// Modifies the value of a string variable.
bool mapreg_setregstr(int uid, const char* str)
{
	int num = (uid & 0x00ffffff);
	int i   = (uid & 0xff000000) >> 24;
	const char* name = get_str(num);
	
	if( str == NULL || *str == 0 )
	{
		if(name[1] != '@') {
			if( SQL_ERROR == Sql_Query(mmysql_handle, "DELETE FROM `%s` WHERE `varname`='%s' AND `index`='%d'", mapreg_table, name, i) )
				Sql_ShowDebug(mmysql_handle);
		}
		idb_remove(mapregstr_db,uid);
	}
	else
	{
		if (idb_put(mapregstr_db,uid, aStrdup(str)))
			mapreg_dirty = true;
		else if(name[1] != '@') { //put returned null, so we must insert.
			// Someone is causing a database size infinite increase here without name[1] != '@' [Lance]
			char tmp_str[32*2+1];
			char tmp_str2[255*2+1];
			Sql_EscapeStringLen(mmysql_handle, tmp_str, name, strnlen(name, 32));
			Sql_EscapeStringLen(mmysql_handle, tmp_str2, str, strnlen(str, 255));
			if( SQL_ERROR == Sql_Query(mmysql_handle, "INSERT INTO `%s`(`varname`,`index`,`value`) VALUES ('%s','%d','%s')", mapreg_table, tmp_str, i, tmp_str2) )
				Sql_ShowDebug(mmysql_handle);
		}
	}

	return true;
}
コード例 #4
0
ファイル: search.cpp プロジェクト: SnakekillerX/darkstar
void login_config_read(const int8* file)
{
	int8 line[1024], w1[1024], w2[1024];
	FILE* fp;

	fp = fopen(file, "r");
	if (fp == NULL)
	{
		ShowError("configuration file not found at: %s\n", file);
		return;
	}

	while (fgets(line, sizeof(line), fp))
	{
		int8* ptr;

		if (line[0] == '#')
			continue;
		if (sscanf(line, "%[^:]: %[^\t\r\n]", w1, w2) < 2)
			continue;

		//Strip trailing spaces
		ptr = w2 + strlen(w2);
		while (--ptr >= w2 && *ptr == ' ');
		ptr++;
		*ptr = '\0';

		if (strcmp(w1, "search_server_port") == 0)
		{
			login_config.search_server_port = aStrdup(w2);
		}
	}
	fclose(fp);
}
コード例 #5
0
ファイル: sysinfo.c プロジェクト: Chocolate31/eamod
/**
 * Retrieves the current Git revision.
 *
 * @param out[out] a string pointer to return the value (to be aFree()'d.)
 * @retval true  if a revision was correctly detected.
 * @retval false if no revision was detected. out is set to NULL in this case.
 */
bool sysinfo_git_get_revision(char **out) {
	// Only include Git support if we detected it, or we're on MSVC
#if !defined(SYSINFO_VCSTYPE) || SYSINFO_VCSTYPE == VCSTYPE_GIT || SYSINFO_VCSTYPE == VCSTYPE_UNKNOWN
	FILE *fp;
	char ref[128], filepath[128], line[128];

	strcpy(ref, "HEAD");

	while (*ref) {
		snprintf(filepath, sizeof(filepath), ".git/%s", ref);
		if ((fp = fopen(filepath, "r")) != NULL) {
			if (fgets(line, sizeof(line)-1, fp) == NULL) {
				fclose(fp);
				break;
			}
			fclose(fp);
			if (sscanf(line, "ref: %127[^\n]", ref) == 1) {
				continue;
			} else if (sscanf(line, "%127[a-f0-9]", ref) == 1 && strlen(ref) == 40) {
				if (*out != NULL)
					aFree(*out);
				*out = aStrdup(ref);
			}
		}
		break;
	}
	if (*out != NULL)
		return true;
#else
	if (*out != NULL)
		aFree(*out);
	*out = NULL;
#endif
	return false;
}
コード例 #6
0
ファイル: login.cpp プロジェクト: jono659/enko
int32 version_info_read(const char *fileName)
{
    char line[1024], w1[1024], w2[1024];
    FILE *fp;

    fp = fopen(fileName, "r");
    if (fp == nullptr)
    {
        ShowError("version info file not found at: %s\n", fileName);
        return 1;
    }

    while (fgets(line, sizeof(line), fp))
    {
        char* ptr;

        if (line[0] == '#')
            continue;
        if (sscanf(line, "%[^:]: %[^\t\r\n]", w1, w2) < 2)
            continue;

        //Strip trailing spaces
        ptr = w2 + strlen(w2);
        while (--ptr >= w2 && *ptr == ' ');
        ptr++;
        *ptr = '\0';

        if (strcmp(w1, "Min_Client_Ver") == 0)
        {
            version_info.Min_Client_Ver = aStrdup(w2);
        }
    }
    fclose(fp);
    return 0;
}
コード例 #7
0
ファイル: HPMmap.c プロジェクト: 3298021/Hercules
/**
 * Adds a new group permission to the HPM-provided list
 **/
void HPM_map_add_group_permission(unsigned int pluginID, char *name, unsigned int *mask) {
	unsigned char index = pcg->HPMpermissions_count;

	RECREATE(pcg->HPMpermissions, struct pc_groups_new_permission, ++pcg->HPMpermissions_count);

	pcg->HPMpermissions[index].pID = pluginID;
	pcg->HPMpermissions[index].name = aStrdup(name);
	pcg->HPMpermissions[index].mask = mask;
}
コード例 #8
0
ファイル: mapreg_txt.c プロジェクト: Drakkus/eamod
/// Modifies the value of a string variable.
bool mapreg_setregstr(int uid, const char* str)
{
	if( str == NULL || *str == 0 )
		idb_remove(mapregstr_db,uid);
	else
		idb_put(mapregstr_db,uid,aStrdup(str));

	mapreg_dirty = true;
	return true;
}
コード例 #9
0
ファイル: plugins.c プロジェクト: itaka/hurricane
int register_plugin_func(char* name)
{
	Plugin_Event_List* evl;
	if( name ){
		//ShowDebug("register_plugin_func(%s)\n", name);
		CREATE(evl, Plugin_Event_List, 1);
		evl->next = event_head;
		evl->name = aStrdup(name);
		evl->events = NULL;
		event_head = evl;
	}
	return 0;
}
コード例 #10
0
ファイル: HPM.c プロジェクト: DeepBugs/Hercules
struct hplugin *hplugin_load(const char* filename) {
	struct hplugin *plugin;
	struct hplugin_info *info;
	struct HPMi_interface **HPMi;
	bool anyEvent = false;
	void **import_symbol_ref;
	int *HPMDataCheckVer;
	unsigned int *HPMDataCheckLen;
	struct s_HPMDataCheck *HPMDataCheck;
	const char *(*HPMLoadEvent)(int server_type);

	if( HPM->exists(filename) ) {
		ShowWarning("HPM:plugin_load: attempting to load duplicate '"CL_WHITE"%s"CL_RESET"', skipping...\n", filename);
		return NULL;
	}

	plugin = HPM->create();

	if (!(plugin->dll = plugin_open(filename))) {
		char buf[1024];
		ShowFatalError("HPM:plugin_load: failed to load '"CL_WHITE"%s"CL_RESET"' (error: %s)!\n", filename, plugin_geterror(buf));
		exit(EXIT_FAILURE);
	}

	if( !( info = plugin_import(plugin->dll, "pinfo",struct hplugin_info*) ) ) {
		ShowFatalError("HPM:plugin_load: failed to retrieve 'plugin_info' for '"CL_WHITE"%s"CL_RESET"'!\n", filename);
		exit(EXIT_FAILURE);
	}

	if( !(info->type & SERVER_TYPE) ) {
		HPM->unload(plugin);
		return NULL;
	}

	if( !HPM->iscompatible(info->req_version) ) {
		ShowFatalError("HPM:plugin_load: '"CL_WHITE"%s"CL_RESET"' incompatible version '%s' -> '%s'!\n", filename, info->req_version, HPM_VERSION);
		exit(EXIT_FAILURE);
	}

	plugin->info = info;
	plugin->filename = aStrdup(filename);

	if( !( import_symbol_ref = plugin_import(plugin->dll, "import_symbol",void **) ) ) {
		ShowFatalError("HPM:plugin_load: failed to retrieve 'import_symbol' for '"CL_WHITE"%s"CL_RESET"'!\n", filename);
		exit(EXIT_FAILURE);
	}
コード例 #11
0
ファイル: mapreg_sql.c プロジェクト: dbrocom/syncragnarok
/// Loads permanent variables from database
static void script_load_mapreg(void)
{
	/*
	        0        1       2
	   +-------------------------+
	   | varname | index | value |
	   +-------------------------+
	                                */
	SqlStmt* stmt = SqlStmt_Malloc(mmysql_handle);
	char varname[32+1];
	int index;
	char value[255+1];
	uint32 length;

	if ( SQL_ERROR == SqlStmt_Prepare(stmt, "SELECT `varname`, `index`, `value` FROM `%s`", mapreg_table)
	  || SQL_ERROR == SqlStmt_Execute(stmt)
	  ) {
		SqlStmt_ShowDebug(stmt);
		SqlStmt_Free(stmt);
		return;
	}

	SqlStmt_BindColumn(stmt, 0, SQLDT_STRING, &varname[0], sizeof(varname), &length, NULL);
	SqlStmt_BindColumn(stmt, 1, SQLDT_INT, &index, 0, NULL, NULL);
	SqlStmt_BindColumn(stmt, 2, SQLDT_STRING, &value[0], sizeof(value), NULL, NULL);
	
	while ( SQL_SUCCESS == SqlStmt_NextRow(stmt) )
	{
		int s = add_str(varname);
		int i = index;

		if( varname[length-1] == '$' )
			idb_put(mapregstr_db, (i<<24)|s, aStrdup(value));
		else
		{
			idb_put(mapreg_db, (i<<24)|s, (void *)atoi(value));
			if( !strcmp(varname, "$Region") && i > 0 && i < MAX_REGIONS )
				region[i].guild_id = atoi(value); // Regional Control
		}
	}
	
	SqlStmt_Free(stmt);

	mapreg_dirty = false;
}
コード例 #12
0
ファイル: sqldbs.c プロジェクト: Lilystar/Auriga
/*==========================================
 * 接続
 *------------------------------------------
 */
bool sqldbs_connect(struct sqldbs_handle *hd, const char *host, const char *user, const char *passwd,
	const char *db, unsigned short port, const char *charset, int keepalive, const char *tag)
{
	if(hd == NULL)
		return false;

	hd->result = NULL;
	hd->transaction_count = 0;
	hd->tag = NULL;

	if(mysql_init(&hd->handle) == NULL) {
		printf("Database Server Out of Memory\n");
		return false;
	}

	printf("Connecting Database Server -> %s@%s:%d/%s", user, host, port, db);
	if(charset && *charset) {
		mysql_options(&hd->handle, MYSQL_SET_CHARSET_NAME, charset);
		printf(" (charset: %s)", charset);
	}
	printf("\n  ... ");

	if(!mysql_real_connect(&hd->handle, host, user, passwd, db, port, NULL, 0)) {
		printf("%s\n", mysql_error(&hd->handle));
		return false;
	}
	printf("connect success!\n");

	if(charset && *charset) {
		sqldbs_query(hd, "SET NAMES %s", charset);
	}

	printf("MySQL Server version %s\n", mysql_get_server_info(&hd->handle));

	if(keepalive > 0) {
		add_timer_func_list(sqldbs_keepalive_timer);
		add_timer_interval(gettick() + keepalive * 1000, sqldbs_keepalive_timer, 0, hd, keepalive * 1000);
		printf("MySQL keepalive timer set: interval = %d (sec)\n", keepalive);
	}

	if(tag)
		hd->tag = (char *)aStrdup(tag);

	return true;
}
コード例 #13
0
ファイル: sqldbs.c プロジェクト: Lilystar/Auriga
/*==========================================
 * 単純なプリペアドステートメントのクエリ準備
 *------------------------------------------
 */
bool sqldbs_stmt_simpleprepare(struct sqldbs_stmt *st, const char *query)
{
	nullpo_retr(false, st);

	// 初期化
	st->bind_params  = false;
	st->bind_columns = false;

	if(st->query) {
		aFree(st->query);
	}
	st->query = (char *)aStrdup(query);

	if( mysql_stmt_prepare(st->stmt, query, strlen(query)) )
	{
		printf("DB server Error - %s\n  %s\n\n", mysql_stmt_error(st->stmt), query);
		return false;
	}

	return true;
}
コード例 #14
0
ファイル: mapreg_txt.c プロジェクト: Drakkus/eamod
/// Loads permanent variables from savefile
static void script_load_mapreg(void)
{
	FILE* fp;
	char line[1024];

	fp = fopen(mapreg_txt,"rt");
	if( fp == NULL )
		return;

	while( fgets(line,sizeof(line),fp) )
	{
		char varname[32+1];
		char value[255+1];
		int n,s,i;

		// read name and index
		if( sscanf(line, "%32[^,],%d\t%n", varname,&i,&n) != 2 &&
			(i = 0, sscanf(line,"%[^\t]\t%n", varname,&n) != 1) )
			continue;

		// read value
		if( sscanf(line + n, "%[^\n\r]", value) != 1 )
		{
			ShowError("%s: %s broken data !\n", mapreg_txt, varname);
			continue;
		}

		s = add_str(varname);
		if( varname[strlen(varname)-1] == '$' )
			idb_put(mapregstr_db, (i<<24)|s, aStrdup(value));
		else
			idb_put(mapreg_db, (i<<24)|s, (void*)atoi(value));
	}
	fclose(fp);

	mapreg_dirty = false;
}
コード例 #15
0
int do_init(int argc, char** argv)
{
	FILE *list;
	char line[1024];
	struct map_data map;
	char name[MAP_NAME_LENGTH_EXT];

	grf_list_file = aStrdup("conf/grf-files.txt");
	map_list_file = aStrdup("db/map_index.txt");
	/* setup pre-defined, #define-dependant */
	map_cache_file = aStrdup("db/map_cache.dat");

	cmdline->exec(argc, argv, CMDLINE_OPT_PREINIT);
	cmdline->exec(argc, argv, CMDLINE_OPT_NORMAL);

	ShowStatus("Initializing grfio with %s\n", grf_list_file);
	grfio_init(grf_list_file);

	// Attempt to open the map cache file and force rebuild if not found
	ShowStatus("Opening map cache: %s\n", map_cache_file);
	if(!rebuild) {
		map_cache_fp = fopen(map_cache_file, "rb");
		if(map_cache_fp == NULL) {
			ShowNotice("Existing map cache not found, forcing rebuild mode\n");
			rebuild = 1;
		} else
			fclose(map_cache_fp);
	}
	if(rebuild)
		map_cache_fp = fopen(map_cache_file, "w+b");
	else
		map_cache_fp = fopen(map_cache_file, "r+b");
	if(map_cache_fp == NULL) {
		ShowError("Failure when opening map cache file %s\n", map_cache_file);
		exit(EXIT_FAILURE);
	}

	// Open the map list
	ShowStatus("Opening map list: %s\n", map_list_file);
	list = fopen(map_list_file, "r");
	if(list == NULL) {
		ShowError("Failure when opening maps list file %s\n", map_list_file);
		exit(EXIT_FAILURE);
	}

	// Initialize the main header
	if(rebuild) {
		header.file_size = sizeof(struct main_header);
		header.map_count = 0;
	} else {
		if(fread(&header, sizeof(struct main_header), 1, map_cache_fp) != 1){ printf("An error as occured while reading map_cache_fp \n"); }
		header.file_size = GetULong((unsigned char *)&(header.file_size));
		header.map_count = GetUShort((unsigned char *)&(header.map_count));
	}

	// Read and process the map list
	while(fgets(line, sizeof(line), list))
	{
		if(line[0] == '/' && line[1] == '/')
			continue;

		if(sscanf(line, "%15s", name) < 1)
			continue;

		if(strcmp("map:", name) == 0 && sscanf(line, "%*s %15s", name) < 1)
			continue;

		name[MAP_NAME_LENGTH_EXT-1] = '\0';
		remove_extension(name);
		if (find_map(name)) {
			ShowInfo("Map '"CL_WHITE"%s"CL_RESET"' already in cache.\n", name);
		} else if(!read_map(name, &map)) {
			ShowError("Map '"CL_WHITE"%s"CL_RESET"' not found!\n", name);
		} else if (!cache_map(name, &map)) {
			ShowError("Map '"CL_WHITE"%s"CL_RESET"' failed to cache (write error).\n", name);
		} else {
			ShowInfo("Map '"CL_WHITE"%s"CL_RESET"' successfully cached.\n", name);
		}
	}

	ShowStatus("Closing map list: %s\n", map_list_file);
	fclose(list);

	// Write the main header and close the map cache
	ShowStatus("Closing map cache: %s\n", map_cache_file);
	fseek(map_cache_fp, 0, SEEK_SET);
	fwrite(&header, sizeof(struct main_header), 1, map_cache_fp);
	fclose(map_cache_fp);

	ShowStatus("Finalizing grfio\n");
	grfio_final();

	ShowInfo("%d maps now in cache\n", header.map_count);

	aFree(grf_list_file);
	aFree(map_list_file);
	aFree(map_cache_file);

	return 0;
}
コード例 #16
0
/**
 * --map-cache handler
 *
 * Overrides the default map cache filename.
 * @see cmdline->exec
 */
static CMDLINEARG(mapcache)
{
	aFree(map_cache_file);
	map_cache_file = aStrdup(params);
	return true;
}
コード例 #17
0
/**
 * --map-list handler
 *
 * Overrides the default map list filename.
 * @see cmdline->exec
 */
static CMDLINEARG(maplist)
{
	aFree(map_list_file);
	map_list_file = aStrdup(params);
	return true;
}
コード例 #18
0
/**
 * --grf-list handler
 *
 * Overrides the default grf list filename.
 * @see cmdline->exec
 */
static CMDLINEARG(grflist)
{
	aFree(grf_list_file);
	grf_list_file = aStrdup(params);
	return true;
}
コード例 #19
0
ファイル: login.cpp プロジェクト: jono659/enko
int32 login_config_read(const char *cfgName)
{
    char line[1024], w1[1024], w2[1024];
    FILE *fp;

    fp = fopen(cfgName, "r");
    if (fp == nullptr)
    {
        ShowError("login configuration file not found at: %s\n", cfgName);
        return 1;
    }

    while (fgets(line, sizeof(line), fp))
    {
        char* ptr;

        if (line[0] == '#')
            continue;
        if (sscanf(line, "%[^:]: %[^\t\r\n]", w1, w2) < 2)
            continue;

        //Strip trailing spaces
        ptr = w2 + strlen(w2);
        while (--ptr >= w2 && *ptr == ' ');
        ptr++;
        *ptr = '\0';

        if (strcmpi(w1, "timestamp_format") == 0)
        {
            strncpy(timestamp_format, w2, 19);
        }
        else if (strcmpi(w1, "stdout_with_ansisequence") == 0)
        {
            stdout_with_ansisequence = config_switch(w2);
        }
        else if (strcmpi(w1, "console_silent") == 0)
        {
            ShowInfo("Console Silent Setting: %d\n", atoi(w2));
            msg_silent = atoi(w2);
        }
        else if (strcmp(w1, "mysql_host") == 0)
        {
            login_config.mysql_host = aStrdup(w2);
        }
        else if (strcmp(w1, "mysql_login") == 0)
        {
            login_config.mysql_login = aStrdup(w2);
        }
        else if (strcmp(w1, "mysql_password") == 0)
        {
            login_config.mysql_password = aStrdup(w2);
        }
        else if (strcmp(w1, "mysql_port") == 0)
        {
            login_config.mysql_port = atoi(w2);
        }
        else if (strcmp(w1, "mysql_database") == 0)
        {
            login_config.mysql_database = aStrdup(w2);
        }
        else if (strcmp(w1, "search_server_port") == 0)
        {
            login_config.search_server_port = atoi(w2);
        }
        else if (strcmp(w1, "expansions") == 0)
        {
            login_config.expansions = atoi(w2);
        }
        else if (strcmp(w1, "servername") == 0)
        {
            login_config.servername = aStrdup(w2);
        }
        else if (strcmpi(w1, "import") == 0)
        {
            login_config_read(w2);
        }
        else if (strcmp(w1, "msg_server_port") == 0)
        {
            login_config.msg_server_port = atoi(w2);
        }
        else if (strcmp(w1, "msg_server_ip") == 0)
        {
            login_config.msg_server_ip = aStrdup(w2);
        }
        else
        {
            ShowWarning("Unknown setting '%s' in file %s\n", w1, cfgName);
        }
    }

    fclose(fp);
    return 0;
}
コード例 #20
0
ファイル: sysinfo.c プロジェクト: Chocolate31/eamod
/**
 * Retrieves the Operating System version (Windows only).
 *
 * Once retrieved, the version string is stored into sysinfo->p->osversion.
 */
void sysinfo_osversion_retrieve(void) {
	OSVERSIONINFOEX osvi;
	StringBuf buf;
	ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX));
	StrBuf->Init(&buf);

	osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);

	if (sysinfo->p->osversion != NULL) {
		aFree(sysinfo->p->osversion);
		sysinfo->p->osversion = NULL;
	}

	/*
	 * #pragma rantmode (on)
	 * Some engineer at Microsoft moronically decided that, since some applications use this information to do version checks and refuse to
	 * run if they detect a new, unknown version of Windows, now nobody will be able to rely on this information anymore, not even those who
	 * need it for reporting or logging.
	 * The correct fix was to let those applications break, and their developer fix them (and in the meanwhile let the users use the
	 * Compatibility settings to run them) but no, they decided they'd deprecate the API, and make it lie for those who use it, reporting
	 * windows 8 even if they're running on 8.1 or newer.
	 * The API wasn't broken, applications were. Now we have broken applications, and a broken API. Great move, Microsoft.  Oh right,
	 * there's the Version API helper functions. Or maybe not, since you can only do 'are we running on at least version X?' checks with
	 * those, it's not what we need.
	 * You know what? I'll just silence your deprecation warning for the time being. Maybe by the time you release the next version of
	 * Windows, you'll have provided a less crippled API or something.
	 * #pragma rantmode (off)
	 */
#pragma warning (push)
#pragma warning (disable : 4996)
	if (!GetVersionEx((OSVERSIONINFO*) &osvi)) {
		sysinfo->p->osversion = aStrdup("Unknown Version");
		return;
	}
#pragma warning (pop)

	if (VER_PLATFORM_WIN32_NT == osvi.dwPlatformId // Windows NT Family
	 && ((osvi.dwMajorVersion > 4 && osvi.dwMajorVersion < 6) || (osvi.dwMajorVersion == 6 && osvi.dwMinorVersion <= 3)) // Between XP and 8.1
	) {
		if (osvi.dwMajorVersion == 6 && osvi.dwMinorVersion <= 3) { // Between Vista and 8.1
			PGPI pGPI;
			DWORD dwType;
			if (osvi.dwMinorVersion == 0) {
				StrBuf->AppendStr(&buf, osvi.wProductType == VER_NT_WORKSTATION ? "Windows Vista" : "Windows Server 2008");
			} else if (osvi.dwMinorVersion == 1) {
				StrBuf->AppendStr(&buf, osvi.wProductType == VER_NT_WORKSTATION ? "Windows 7" : "Windows Server 2008 R2");
			} else {
				// If it's 2, it can be Windows 8, or any newer version (8.1 at the time of writing this) -- see above for the reason.
				switch (osvi.dwMinorVersion) {
				case 2:
					{
						ULONGLONG mask = 0;
						OSVERSIONINFOEX osvi2;
						ZeroMemory(&osvi2, sizeof(OSVERSIONINFOEX));
						osvi2.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
						osvi2.dwMajorVersion = 6;
						osvi2.dwMinorVersion = 2;
						VER_SET_CONDITION(mask, VER_MAJORVERSION, VER_LESS_EQUAL);
						VER_SET_CONDITION(mask, VER_MINORVERSION, VER_LESS_EQUAL);
						if (VerifyVersionInfo(&osvi2, VER_MAJORVERSION | VER_MINORVERSION, mask)) {
							StrBuf->AppendStr(&buf, osvi.wProductType == VER_NT_WORKSTATION ? "Windows 8" : "Windows Server 2012");
							break;
						}
					}
				case 3:
					StrBuf->AppendStr(&buf, osvi.wProductType == VER_NT_WORKSTATION ? "Windows 8.1" : "Windows Server 2012 R2");
				}
			}

			pGPI = (PGPI) GetProcAddress(GetModuleHandle(TEXT("kernel32.dll")), "GetProductInfo");

			pGPI(osvi.dwMajorVersion, osvi.dwMinorVersion, 0, 0, &dwType);

			switch (dwType) {
				case msPRODUCT_ULTIMATE:
				case msPRODUCT_ULTIMATE_N:
					StrBuf->AppendStr(&buf, " Ultimate");
					break;
				case msPRODUCT_PROFESSIONAL:
				case msPRODUCT_PROFESSIONAL_N:
				case msPRODUCT_PROFESSIONAL_WMC:
					StrBuf->AppendStr(&buf, " Professional");
					break;
				case msPRODUCT_HOME_PREMIUM:
				case msPRODUCT_HOME_PREMIUM_N:
					StrBuf->AppendStr(&buf, " Home Premium");
					break;
				case msPRODUCT_HOME_BASIC:
				case msPRODUCT_HOME_BASIC_N:
					StrBuf->AppendStr(&buf, " Home Basic");
					break;
				case msPRODUCT_ENTERPRISE:
				case msPRODUCT_ENTERPRISE_N:
				case msPRODUCT_ENTERPRISE_SERVER:
				case msPRODUCT_ENTERPRISE_SERVER_CORE:
				case msPRODUCT_ENTERPRISE_SERVER_IA64:
				case msPRODUCT_ENTERPRISE_SERVER_V:
				case msPRODUCT_ENTERPRISE_SERVER_CORE_V:
				case msPRODUCT_ENTERPRISE_EVALUATION:
				case msPRODUCT_ENTERPRISE_N_EVALUATION:
					StrBuf->AppendStr(&buf, " Enterprise");
					break;
				case msPRODUCT_BUSINESS:
				case msPRODUCT_BUSINESS_N:
					StrBuf->AppendStr(&buf, " Business");
					break;
				case msPRODUCT_STARTER:
				case msPRODUCT_STARTER_N:
					StrBuf->AppendStr(&buf, " Starter");
					break;
				case msPRODUCT_CLUSTER_SERVER:
				case msPRODUCT_CLUSTER_SERVER_V:
					StrBuf->AppendStr(&buf, " Cluster Server");
					break;
				case msPRODUCT_DATACENTER_SERVER:
				case msPRODUCT_DATACENTER_SERVER_CORE:
				case msPRODUCT_DATACENTER_SERVER_V:
				case msPRODUCT_DATACENTER_SERVER_CORE_V:
				case msPRODUCT_DATACENTER_EVALUATION_SERVER:
					StrBuf->AppendStr(&buf, " Datacenter");
					break;
				case msPRODUCT_SMALLBUSINESS_SERVER:
				case msPRODUCT_SMALLBUSINESS_SERVER_PREMIUM:
				case msPRODUCT_SMALLBUSINESS_SERVER_PREMIUM_CORE:
					StrBuf->AppendStr(&buf, " Small Business Server");
					break;
				case PRODUCT_STANDARD_SERVER:
				case PRODUCT_STANDARD_SERVER_CORE:
				case msPRODUCT_STANDARD_SERVER_V:
				case msPRODUCT_STANDARD_SERVER_CORE_V:
				case msPRODUCT_STANDARD_EVALUATION_SERVER:
					StrBuf->AppendStr(&buf, " Standard");
					break;
				case msPRODUCT_WEB_SERVER:
				case msPRODUCT_WEB_SERVER_CORE:
					StrBuf->AppendStr(&buf, " Web Server");
					break;
				case msPRODUCT_STORAGE_EXPRESS_SERVER:
				case msPRODUCT_STORAGE_STANDARD_SERVER:
				case msPRODUCT_STORAGE_WORKGROUP_SERVER:
				case msPRODUCT_STORAGE_ENTERPRISE_SERVER:
				case msPRODUCT_STORAGE_EXPRESS_SERVER_CORE:
				case msPRODUCT_STORAGE_STANDARD_SERVER_CORE:
				case msPRODUCT_STORAGE_WORKGROUP_SERVER_CORE:
				case msPRODUCT_STORAGE_ENTERPRISE_SERVER_CORE:
				case msPRODUCT_STORAGE_WORKGROUP_EVALUATION_SERVER:
				case msPRODUCT_STORAGE_STANDARD_EVALUATION_SERVER:
					StrBuf->AppendStr(&buf, " Storage Server");
					break;
				case msPRODUCT_HOME_SERVER:
				case msPRODUCT_SERVER_FOR_SMALLBUSINESS:
				case msPRODUCT_MEDIUMBUSINESS_SERVER_MANAGEMENT:
				case msPRODUCT_MEDIUMBUSINESS_SERVER_SECURITY:
				case msPRODUCT_MEDIUMBUSINESS_SERVER_MESSAGING:
				case msPRODUCT_SERVER_FOR_SMALLBUSINESS_V:
				case msPRODUCT_SERVER_FOUNDATION:
				case msPRODUCT_HOME_PREMIUM_SERVER:
				case msPRODUCT_HYPERV:
				case msPRODUCT_SB_SOLUTION_SERVER:
				case msPRODUCT_SERVER_FOR_SB_SOLUTIONS:
				case msPRODUCT_STANDARD_SERVER_SOLUTIONS:
				case msPRODUCT_STANDARD_SERVER_SOLUTIONS_CORE:
				case msPRODUCT_SB_SOLUTION_SERVER_EM:
				case msPRODUCT_SERVER_FOR_SB_SOLUTIONS_EM:
				case msPRODUCT_SOLUTION_EMBEDDEDSERVER:
				case msPRODUCT_ESSENTIALBUSINESS_SERVER_MGMT:
				case msPRODUCT_ESSENTIALBUSINESS_SERVER_ADDL:
				case msPRODUCT_ESSENTIALBUSINESS_SERVER_MGMTSVC:
				case msPRODUCT_ESSENTIALBUSINESS_SERVER_ADDLSVC:
				case msPRODUCT_MULTIPOINT_STANDARD_SERVER:
				case msPRODUCT_MULTIPOINT_PREMIUM_SERVER:
					StrBuf->AppendStr(&buf, " Server (other)");
					break;
				case msPRODUCT_CORE_N:
				case msPRODUCT_CORE_COUNTRYSPECIFIC:
				case msPRODUCT_CORE_SINGLELANGUAGE:
				case msPRODUCT_CORE:
					StrBuf->AppendStr(&buf, " Workstation (other)");
					break;
			}

		} else if (osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 2) { // XP x64 and Server 2003
			if (osvi.wProductType == VER_NT_WORKSTATION) {
				StrBuf->AppendStr(&buf, "Windows XP Professional");
			} else {
				if (GetSystemMetrics(msSM_SERVERR2))
					StrBuf->AppendStr(&buf, "Windows Server 2003 R2");
				else if (osvi.wSuiteMask & msVER_SUITE_STORAGE_SERVER)
					StrBuf->AppendStr(&buf, "Windows Storage Server 2003");
				else if (osvi.wSuiteMask & msVER_SUITE_WH_SERVER)
					StrBuf->AppendStr(&buf, "Windows Home Server");
				else
					StrBuf->AppendStr(&buf, "Windows Server 2003");

				// Test for the server type.
				if (osvi.wSuiteMask & msVER_SUITE_COMPUTE_SERVER)
					StrBuf->AppendStr(&buf, " Compute Cluster");
				else if (osvi.wSuiteMask & VER_SUITE_DATACENTER)
					StrBuf->AppendStr(&buf, " Datacenter");
				else if (osvi.wSuiteMask & VER_SUITE_ENTERPRISE)
					StrBuf->AppendStr(&buf, " Enterprise");
				else if (osvi.wSuiteMask & msVER_SUITE_BLADE)
					StrBuf->AppendStr(&buf, " Web");
				else
					StrBuf->AppendStr(&buf, " Standard");
			}
		} else if (osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 1) { // XP
			StrBuf->AppendStr(&buf, "Windows XP");
			if (osvi.wSuiteMask & VER_SUITE_EMBEDDEDNT)
				StrBuf->AppendStr(&buf, " Embedded");
			else if (osvi.wSuiteMask & VER_SUITE_PERSONAL)
				StrBuf->AppendStr(&buf, " Home");
			else
				StrBuf->AppendStr(&buf, " Professional");
		} else if (osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 0) { // 2000
			StrBuf->AppendStr(&buf, "Windows 2000");

			if (osvi.wProductType == VER_NT_WORKSTATION)
				StrBuf->AppendStr(&buf, " Professional");
			else if (osvi.wSuiteMask & VER_SUITE_DATACENTER)
				StrBuf->AppendStr(&buf, " Datacenter Server");
			else if (osvi.wSuiteMask & VER_SUITE_ENTERPRISE)
				StrBuf->AppendStr(&buf, " Advanced Server");
			else
				StrBuf->AppendStr(&buf, " Server");
		} else {
			StrBuf->Printf(&buf, "Unknown Windows version %d.%d", osvi.dwMajorVersion, osvi.dwMinorVersion);
		}
	}

	// Include service pack (if any) and build number.

	if (strlen(osvi.szCSDVersion) > 0) {
		StrBuf->Printf(&buf, " %s", osvi.szCSDVersion);
	}

	StrBuf->Printf(&buf, " (build %d)", osvi.dwBuildNumber);

	sysinfo->p->osversion = aStrdup(StrBuf->Value(&buf));

	StrBuf->Destroy(&buf);
	return;
}
コード例 #21
0
ファイル: channel.c プロジェクト: Chocolate31/eamod
void channel_message(struct map_session_data *sd, const char* channel, const char* message)
{
	struct channel_data *cd;
	char output[CHAT_SIZE_MAX];
	struct map_session_data *p_sd;

	if( !sd || !message || !*message || strlen(message) < 1 )
		return;

	if( (cd = (struct channel_data *)strdb_get(channel_db, channel)) == NULL )
	{
		clif_displaymessage(sd->fd, msg_txt(805));
		clif_displaymessage(sd->fd, msg_txt(815));
		return;
	}

	if( channel_slot_get(sd,cd) < 0 )
	{
		clif_displaymessage(sd->fd, msg_txt(816));
		return;
	}

	if( message[0] == '|' && strlen(message) >= 4 && message[3] == '.' )
		message += 3;

	if( message[0] == '.' )
	{ // Channel commands
		size_t len = strlen(message);
		char* option_text;

		if( !strncasecmp(message, ".item ", 6) && len > 0 && cd->type == CHN_VENDING && server_channel[CHN_VENDING] && vendingbot_timer < gettick() )
		{
			struct map_session_data *pl_sd, *b_sd[MAX_SEARCH];
			struct s_mapiterator* iter;
			struct item_data *item_array[MAX_SEARCH];
			int total[MAX_SEARCH], amount[MAX_SEARCH];
			unsigned int MinPrice[MAX_SEARCH], MaxPrice[MAX_SEARCH];
			int i, j, count = 1;

			option_text = (char *)message + 6;

			if( (item_array[0] = itemdb_exists(atoi(option_text))) == NULL )
				count = itemdb_searchname_array(item_array, MAX_SEARCH, option_text);

			if( count < 1 )
			{
				clif_displaymessage(sd->fd, msg_txt(19));
				return;
			}

			if( count > MAX_SEARCH ) count = MAX_SEARCH;
			for( i = 0; i < MAX_SEARCH; i++ )
			{
				total[i] = amount[i] = MaxPrice[i] = 0;
				MinPrice[i] = battle_config.vending_max_value + 1;
				b_sd[i] = NULL;
			}

			iter = mapit_getallusers();
			for( pl_sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); pl_sd = (TBL_PC*)mapit_next(iter) )
			{
				if( !pl_sd->vender_id )
					continue;

				for( i = 0; i < pl_sd->vend_num; i++ )
				{ // Searching in the Vending List
					for( j = 0; j < count; j++ )
					{ // Compares with each search result
						if( pl_sd->status.cart[pl_sd->vending[i].index].nameid != item_array[j]->nameid )
							continue;

						amount[j] += pl_sd->vending[i].amount;
						total[j]++;

						if( pl_sd->vending[i].value < MinPrice[j] )
						{ // Best Price
							MinPrice[j] = pl_sd->vending[i].value;
							b_sd[j] = pl_sd;
						}
						if( pl_sd->vending[i].value > MaxPrice[j] )
							MaxPrice[j] = pl_sd->vending[i].value;
					}
				}
			}
			mapit_free(iter);

			for( i = 0; i < count; i++ )
			{
				if( total[i] > 0 && b_sd[i] != NULL )
				{
					sprintf(output, msg_txt(829), server_channel[CHN_VENDING]->name, item_array[i]->jname, MinPrice[i], b_sd[i]->status.name, map[b_sd[i]->bl.m].name, b_sd[i]->bl.x, b_sd[i]->bl.y, MaxPrice[i], total[i], amount[i]);
					clif_channel_message(cd, output, -1);
				}
			}
			vendingbot_timer = gettick() + 5000; // 5 Seconds Protection from flood
		}
		else if( !strncasecmp(message, ".exit", 5) )
			channel_leave(sd, cd->name, true);
		else if( cd->op != sd->bl.id && pc_has_permission(sd,PC_PERM_CHANNEL_OPERATOR) )
			return;
		else if( !strncasecmp(message, ".invite ", 8) && len > 11 )
		{ // Invite a User to the Channel
			option_text = (char *)message + 8;
			if( (p_sd = map_nick2sd(option_text)) == NULL )
				clif_displaymessage(sd->fd, msg_txt(893));
			else if( p_sd == sd )
				clif_displaymessage(sd->fd, msg_txt(894));
			else if( p_sd->state.noask )
				clif_displaymessage(sd->fd, msg_txt(700));
			else if( channel_slot_get(p_sd, cd) >= 0 )
				clif_displaymessage(sd->fd, msg_txt(895));
			else if( p_sd->channel_invite_timer != INVALID_TIMER )
				clif_displaymessage(sd->fd, msg_txt(897));
			else
			{
				sprintf(output, msg_txt(896), cd->name, sd->status.name, p_sd->status.name);
				clif_channel_message(cd, output, -1); // Notify about the invitation to the Channel

				sprintf(output, msg_txt(898), sd->status.name, cd->name);
				clif_disp_onlyself(p_sd, output, strlen(output)); // Notify Player

				p_sd->channel_invite_timer = add_timer(gettick() + 30000, channel_invite_timer, p_sd->bl.id, (intptr_t)aStrdup(cd->name));
			}
		}
		else if( !strncasecmp(message, ".kick ", 6) && len > 9 )
		{ // Kick Users
			option_text = (char *)message + 6;
			if( (p_sd = map_nick2sd(option_text)) == NULL || channel_slot_get(p_sd, cd) < 0 )
				clif_displaymessage(sd->fd, msg_txt(817));
			else if( p_sd == sd )
				clif_displaymessage(sd->fd, msg_txt(818));
			else
			{
				channel_leave(p_sd, cd->name, false);
				sprintf(output, msg_txt(819), cd->name, p_sd->status.name);
				clif_channel_message(cd, output, -1);
				p_sd->canjoinchn_tick = gettick() + 10000;
			}
		}
		else if( !strncasecmp(message, ".color ", 7) && len > 7 )
		{ // Set Chat Room Color
			short color = atoi(message + 7);
			if( color < 1 || color > 39 )
				clif_displaymessage(sd->fd, msg_txt(830));
			else
			{
				cd->color = channel_color[color - 1];
				sprintf(output, msg_txt(831), cd->name);
				clif_channel_message(cd, output, -1);
			}
		}
		else if( !strncasecmp(message, ".op ", 4) && len > 7 )
		{
			option_text = (char *)message + 4;
			if( cd->type != CHN_USER )
				clif_displaymessage(sd->fd, msg_txt(875));
			else if( (p_sd = map_nick2sd(option_text)) == NULL || channel_slot_get(p_sd, cd) < 0 )
				clif_displaymessage(sd->fd, msg_txt(817));
			else if( p_sd == sd )
				clif_displaymessage(sd->fd, msg_txt(832));
			else
			{
				cd->op = p_sd->bl.id;
				sprintf(output, msg_txt(833), cd->name, p_sd->status.name);
				clif_channel_message(cd, output, -1);
			}
		}
		else if( !strncasecmp(message, ".pass ", 6) && len > 6 )
		{
			option_text = trim((char *)message + 6);
			if( cd->type != CHN_USER )
				clif_displaymessage(sd->fd, msg_txt(875));
			else if( !strcmpi(option_text, "off") )
			{
				memset(cd->pass, '\0', sizeof(cd->pass));
				sprintf(output, msg_txt(834), cd->name);
				clif_channel_message(cd, output, -1);
			}
			else if( strlen(option_text) > 1 && strlen(option_text) < NAME_LENGTH )
			{
				safestrncpy(cd->pass, option_text, sizeof(cd->pass));
				sprintf(output, msg_txt(835), cd->name);
				clif_channel_message(cd, output, -1);
			}
			else
				clif_displaymessage(sd->fd, msg_txt(836));
		}
		else if( !strncasecmp(message, ".close", 6) )
		{
			if( cd->type != CHN_USER )
				clif_displaymessage(sd->fd, msg_txt(875));
			else
				channel_close(cd);
		}
		else if( !strncasecmp(message, ".list", 6) )
		{
			DBIterator* iter = db_iterator(cd->users_db);
			clif_displaymessage(sd->fd, msg_txt(837));
			for( p_sd = (struct map_session_data *)dbi_first(iter); dbi_exists(iter); p_sd = (struct map_session_data *)dbi_next(iter) )
				clif_displaymessage(sd->fd, p_sd->status.name);
			dbi_destroy(iter);
			clif_displaymessage(sd->fd, msg_txt(838));
		}
		else if( !strncasecmp(message, ".help", 5) )
		{ // Command List
			clif_displaymessage(sd->fd, msg_txt(839));
			clif_displaymessage(sd->fd, msg_txt(840));
			clif_displaymessage(sd->fd, msg_txt(841));
			clif_displaymessage(sd->fd, msg_txt(842));
			clif_displaymessage(sd->fd, msg_txt(843));
			clif_displaymessage(sd->fd, msg_txt(844));
			clif_displaymessage(sd->fd, msg_txt(845));
			clif_displaymessage(sd->fd, msg_txt(846));
		}
		else
			clif_displaymessage(sd->fd, msg_txt(847));

		return;
	}

	snprintf(output, sizeof(output), "%s : [%s] %s", cd->name, sd->status.name, message);
	clif_channel_message(cd, output, -1);
}
コード例 #22
0
ファイル: mempool.c プロジェクト: Mateuus/brathena-1
mempool mempool_create(const char *name,
                       uint64 elem_size,
                       uint64 initial_count,
                       uint64 realloc_count,
                       memPoolOnNodeAllocationProc onNodeAlloc,
                       memPoolOnNodeDeallocationProc onNodeDealloc)
{
    //..
    uint64 realloc_thresh;
    mempool pool;
    pool = (mempool)aCalloc(1,  sizeof(struct mempool));

    if(pool == NULL) {
        ShowFatalError(read_message("Source.common.mempool_create"), sizeof(struct mempool));
        exit(EXIT_FAILURE);
    }

    // Check minimum initial count / realloc count requirements.
    if(initial_count < 50)
        initial_count = 50;
    if(realloc_count < 50)
        realloc_count = 50;

    // Set Reallocation threshold to 5% of realloc_count, at least 10.
    realloc_thresh = (realloc_count/100)*5; //
    if(realloc_thresh < 10)
        realloc_thresh = 10;

    // Initialize members..
    pool->name = aStrdup(name);
    pool->elem_size = ALIGN_TO_16(elem_size);
    pool->elem_realloc_step = realloc_count;
    pool->elem_realloc_thresh = realloc_thresh;
    pool->onalloc = onNodeAlloc;
    pool->ondealloc = onNodeDealloc;

    InitializeSpinLock(&pool->segmentLock);
    InitializeSpinLock(&pool->nodeLock);

    // Initial Statistic values:
    pool->num_nodes_total = 0;
    pool->num_nodes_free = 0;
    pool->num_segments = 0;
    pool->num_bytes_total = 0;
    pool->peak_nodes_used = 0;
    pool->num_realloc_events = 0;

    //
#ifdef MEMPOOL_DEBUG
    ShowDebug(read_message("Source.common.mempool_create"), pool->name,  pool->elem_size,  initial_count,  pool->elem_realloc_step);
#endif

    // Allocate first segment directly :)
    segment_allocate_add(pool, initial_count);


    // Add Pool to the global pool list
    EnterSpinLock(&l_mempoolListLock);
    pool->next = l_mempoolList;
    l_mempoolList = pool;
    LeaveSpinLock(&l_mempoolListLock);


    return pool;
}//end: mempool_create()
コード例 #23
0
ファイル: plugins.c プロジェクト: itaka/hurricane
Plugin* plugin_open(const char* filename)
{
	Plugin* plugin;
	Plugin_Info* info;
	Plugin_Event_Table* events;
	void** procs;
	int init_flag = 1;

	//ShowDebug("plugin_open(%s)\n", filename);
	
	// Check if the plugin has been loaded before
	plugin = plugin_head;
	while (plugin) {
		// returns handle to the already loaded plugin
		if( plugin->state && strcmpi(plugin->filename, filename) == 0 ){
			ShowWarning("plugin_open: not loaded (duplicate) : '"CL_WHITE"%s"CL_RESET"'\n", filename);
			return plugin;
		}
		plugin = plugin->next;
	}

	CREATE(plugin, Plugin, 1);
	plugin->state = -1;	// not loaded

	plugin->dll = DLL_OPEN(filename);
	if( !plugin->dll ){
		ShowWarning("plugin_open: not loaded (invalid file) : '"CL_WHITE"%s"CL_RESET"'\n", filename);
		plugin_unload(plugin);
		return NULL;
	}

	// Retrieve plugin information
	plugin->state = 0;	// initialising
	info = (Plugin_Info*)DLL_SYM(plugin->dll, "plugin_info");
	// For high priority plugins (those that are explicitly loaded from the conf file)
	// we'll ignore them even (could be a 3rd party dll file)
	if( !info )
	{// foreign plugin
		//ShowDebug("plugin_open: plugin_info not found\n");
		if( load_priority == 0 )
		{// not requested
			//ShowDebug("plugin_open: not loaded (not requested) : '"CL_WHITE"%s"CL_RESET"'\n", filename);
			plugin_unload(plugin);
			return NULL;
		}
	} else if( !plugin_iscompatible(info->req_version) )
	{// incompatible version
		ShowWarning("plugin_open: not loaded (incompatible version '%s' -> '%s') : '"CL_WHITE"%s"CL_RESET"'\n", info->req_version, PLUGIN_VERSION, filename);
		plugin_unload(plugin);
		return NULL;
	} else if( (info->type != PLUGIN_ALL && info->type != PLUGIN_CORE && info->type != SERVER_TYPE) ||
		(info->type == PLUGIN_CORE && SERVER_TYPE != PLUGIN_LOGIN && SERVER_TYPE != PLUGIN_CHAR && SERVER_TYPE != PLUGIN_MAP) )
	{// not for this server
		//ShowDebug("plugin_open: not loaded (incompatible) : '"CL_WHITE"%s"CL_RESET"'\n", filename);
		plugin_unload(plugin);
		return NULL;
	}

	plugin->info = ( info != NULL ? info : &default_info );
	plugin->filename = aStrdup(filename);

	// Initialise plugin call table (For exporting procedures)
	procs = (void**)DLL_SYM(plugin->dll, "plugin_call_table");
	if( procs )
		*procs = plugin_call_table;
	//else ShowDebug("plugin_open: plugin_call_table not found\n");

	// Register plugin events
	events = (Plugin_Event_Table*)DLL_SYM(plugin->dll, "plugin_event_table");
	if( events ){
		int i = 0;
		//ShowDebug("plugin_open: parsing plugin_event_table\n");
		while( events[i].func_name ){
			if( strcmpi(events[i].event_name, EVENT_PLUGIN_TEST) == 0 ){
				Plugin_Test_Func* test_func;
				test_func = (Plugin_Test_Func*)DLL_SYM(plugin->dll, events[i].func_name);
				//ShowDebug("plugin_open: invoking "EVENT_PLUGIN_TEST" with %s()\n", events[i].func_name);
				if( test_func && test_func() == 0 ){
					// plugin has failed test, disabling
					//ShowDebug("plugin_open: disabled (failed test) : %s\n", filename);
					init_flag = 0;
				}
			} else {
				Plugin_Event_Func* func;
				func = (Plugin_Event_Func*)DLL_SYM(plugin->dll, events[i].func_name);
				if (func)
					register_plugin_event(func, events[i].event_name);
			}
			i++;
		}
	}
	//else ShowDebug("plugin_open: plugin_event_table not found\n");

	plugin->next = plugin_head;
	plugin_head = plugin;

	plugin->state = init_flag;	// fully loaded
	ShowStatus("Done loading plugin '"CL_WHITE"%s"CL_RESET"'\n", (info) ? plugin->info->name : filename);

	return plugin;
}
コード例 #24
0
ファイル: pc_groups.c プロジェクト: Abunay01/Cronus
/**
 * Loads group configuration from config file into memory.
 * @private
 */
static void read_config(void) {
	config_t pc_group_config;
	config_setting_t *groups = NULL;
	const char *config_filename = "conf/groups.conf"; // FIXME hardcoded name
	int group_count = 0;
	
	if (conf_read_file(&pc_group_config, config_filename))
		return;

	groups = config_lookup(&pc_group_config, "groups");

	if (groups != NULL) {
		GroupSettings *group_settings = NULL;
		DBIterator *iter = NULL;
		int i, loop = 0;

		group_count = config_setting_length(groups);
		for (i = 0; i < group_count; ++i) {
			int id = 0, level = 0;
			const char *groupname = NULL;
			int log_commands = 0;
			config_setting_t *group = config_setting_get_elem(groups, i);

			if (!config_setting_lookup_int(group, "id", &id)) {
				ShowConfigWarning(group, "pc_groups:read_config: \"groups\" list member #%d has undefined id, removing...", i);
				config_setting_remove_elem(groups, i);
				--i;
				--group_count;
				continue;
			}

			if (pc_group_exists(id)) {
				ShowConfigWarning(group, "pc_groups:read_config: duplicate group id %d, removing...", i);
				config_setting_remove_elem(groups, i);
				--i;
				--group_count;
				continue;
			}

			config_setting_lookup_int(group, "level", &level);
			config_setting_lookup_bool(group, "log_commands", &log_commands);

			if (!config_setting_lookup_string(group, "name", &groupname)) {
				char temp[20];
				config_setting_t *name = NULL;
				snprintf(temp, sizeof(temp), "Group %d", id);
				if ((name = config_setting_add(group, "name", CONFIG_TYPE_STRING)) == NULL ||
				    !config_setting_set_string(name, temp)) {
					ShowError("pc_groups:read_config: failed to set missing group name, id=%d, skipping... (%s:%d)\n",
					          id, config_setting_source_file(group), config_setting_source_line(group));
					--i;
					--group_count;
					continue;
				}
				config_setting_lookup_string(group, "name", &groupname); // Retrieve the pointer
			}

			if (name2group(groupname) != NULL) {
				ShowConfigWarning(group, "pc_groups:read_config: duplicate group name %s, removing...", groupname);
				config_setting_remove_elem(groups, i);
				--i;
				--group_count;
				continue;
			}

			CREATE(group_settings, GroupSettings, 1);
			group_settings->id = id;
			group_settings->level = level;
			group_settings->name = aStrdup(groupname);
			group_settings->log_commands = (bool)log_commands;
			group_settings->inherit = config_setting_get_member(group, "inherit");
			group_settings->commands = config_setting_get_member(group, "commands");
			group_settings->permissions = config_setting_get_member(group, "permissions");
			group_settings->inheritance_done = false;
			group_settings->root = group;
			group_settings->index = i;

			strdb_put(pc_groupname_db, groupname, group_settings);
			idb_put(pc_group_db, id, group_settings);
			
		}
		group_count = config_setting_length(groups); // Save number of groups
		assert(group_count == db_size(pc_group_db));
		
		// Check if all commands and permissions exist
		iter = db_iterator(pc_group_db);
		for (group_settings = dbi_first(iter); dbi_exists(iter); group_settings = dbi_next(iter)) {
			config_setting_t *commands = group_settings->commands, *permissions = group_settings->permissions;
			int count = 0, i;

			// Make sure there is "commands" group
			if (commands == NULL)
				commands = group_settings->commands = config_setting_add(group_settings->root, "commands", CONFIG_TYPE_GROUP);
			count = config_setting_length(commands);

			for (i = 0; i < count; ++i) {
				config_setting_t *command = config_setting_get_elem(commands, i);
				const char *name = config_setting_name(command);
				if (!atcommand->exists(name)) {
					ShowConfigWarning(command, "pc_groups:read_config: non-existent command name '%s', removing...", name);
					config_setting_remove(commands, name);
					--i;
					--count;
				}
			}

			// Make sure there is "permissions" group
			if (permissions == NULL)
				permissions = group_settings->permissions = config_setting_add(group_settings->root, "permissions", CONFIG_TYPE_GROUP);
			count = config_setting_length(permissions);

			for(i = 0; i < count; ++i) {
				config_setting_t *permission = config_setting_get_elem(permissions, i);
				const char *name = config_setting_name(permission);
				int j;

				ARR_FIND(0, ARRAYLENGTH(pc_g_permission_name), j, strcmp(pc_g_permission_name[j].name, name) == 0);
				if (j == ARRAYLENGTH(pc_g_permission_name)) {
					ShowConfigWarning(permission, "pc_groups:read_config: non-existent permission name '%s', removing...", name);
					config_setting_remove(permissions, name);
					--i;
					--count;
				}
			}
		}
		dbi_destroy(iter);

		// Apply inheritance
		i = 0; // counter for processed groups
		while (i < group_count) {
			iter = db_iterator(pc_group_db);
			for (group_settings = dbi_first(iter); dbi_exists(iter); group_settings = dbi_next(iter)) {
				config_setting_t *inherit = NULL,
				                 *commands = group_settings->commands,
					             *permissions = group_settings->permissions;
				int j, inherit_count = 0, done = 0;
				
				if (group_settings->inheritance_done) // group already processed
					continue; 

				if ((inherit = group_settings->inherit) == NULL ||
				    (inherit_count = config_setting_length(inherit)) <= 0) { // this group does not inherit from others
					++i;
					group_settings->inheritance_done = true;
					continue;
				}
				
				for (j = 0; j < inherit_count; ++j) {
					GroupSettings *inherited_group = NULL;
					const char *groupname = config_setting_get_string_elem(inherit, j);

					if (groupname == NULL) {
						ShowConfigWarning(inherit, "pc_groups:read_config: \"inherit\" array member #%d is not a name, removing...", j);
						config_setting_remove_elem(inherit,j);
						continue;
					}
					if ((inherited_group = name2group(groupname)) == NULL) {
						ShowConfigWarning(inherit, "pc_groups:read_config: non-existent group name \"%s\", removing...", groupname);
						config_setting_remove_elem(inherit,j);
						continue;
					}
					if (!inherited_group->inheritance_done)
						continue; // we need to do that group first

					// Copy settings (commands/permissions) that are not defined yet
					if (inherited_group->commands != NULL) {
						int i = 0, commands_count = config_setting_length(inherited_group->commands);
						for (i = 0; i < commands_count; ++i)
							config_setting_copy(commands, config_setting_get_elem(inherited_group->commands, i));
					}

					if (inherited_group->permissions != NULL) {
						int i = 0, permissions_count = config_setting_length(inherited_group->permissions);
						for (i = 0; i < permissions_count; ++i)
							config_setting_copy(permissions, config_setting_get_elem(inherited_group->permissions, i));
					}

					++done; // copied commands and permissions from one of inherited groups
				}
				
				if (done == inherit_count) { // copied commands from all of inherited groups
					++i;
					group_settings->inheritance_done = true; // we're done with this group
				}
			}
			dbi_destroy(iter);

			if (++loop > group_count) {
				ShowWarning("pc_groups:read_config: Could not process inheritance rules, check your config '%s' for cycles...\n",
				            config_filename);
				break;
			}
		} // while(i < group_count)
		
		// Pack permissions into GroupSettings.e_permissions for faster checking
		iter = db_iterator(pc_group_db);
		for (group_settings = dbi_first(iter); dbi_exists(iter); group_settings = dbi_next(iter)) {
			config_setting_t *permissions = group_settings->permissions;
			int i, count = config_setting_length(permissions);

			for (i = 0; i < count; ++i) {
				config_setting_t *perm = config_setting_get_elem(permissions, i);
				const char *name = config_setting_name(perm);
				int val = config_setting_get_bool(perm);
				int j;

				if (val == 0) // does not have this permission
					continue;
				ARR_FIND(0, ARRAYLENGTH(pc_g_permission_name), j, strcmp(pc_g_permission_name[j].name, name) == 0);
				group_settings->e_permissions |= pc_g_permission_name[j].permission;
			}
		}
		dbi_destroy(iter);

		// Atcommand permissions are processed by atcommand module.
		// Fetch all groups and relevant config setting and send them
		// to atcommand->load_group() for processing.
		if (group_count > 0) {
			int i = 0;
			GroupSettings **groups = NULL;
			config_setting_t **commands = NULL;
			CREATE(groups, GroupSettings*, group_count);
			CREATE(commands, config_setting_t*, group_count);
			iter = db_iterator(pc_group_db);
			for (group_settings = dbi_first(iter); dbi_exists(iter); group_settings = dbi_next(iter)) {
				groups[i] = group_settings;
				commands[i] = group_settings->commands;
				i++;
			}
			atcommand->load_groups(groups, commands, group_count);
			dbi_destroy(iter);
			aFree(groups);
			aFree(commands);
		}
	}

	ShowStatus("Done reading '"CL_WHITE"%d"CL_RESET"' groups in '"CL_WHITE"%s"CL_RESET"'.\n", group_count, config_filename);

	// All data is loaded now, discard config
	config_destroy(&pc_group_config);
}
コード例 #25
0
ファイル: map.cpp プロジェクト: Elkazan/darkstar
int32 map_config_read(const int8* cfgName)
{
    int8 line[1024], w1[1024], w2[1024];
    FILE* fp;

    fp = fopen(cfgName, "r");
    if (fp == nullptr)
    {
        ShowError("Map configuration file not found at: %s\n", cfgName);
        return 1;
    }

    while (fgets(line, sizeof(line), fp))
    {
        int8* ptr;

        if (line[0] == '#')
        {
            continue;
        }
        if (sscanf(line, "%[^:]: %[^\t\r\n]", w1, w2) < 2)
        {
            continue;
        }

        //Strip trailing spaces
        ptr = w2 + strlen(w2);
        while (--ptr >= w2 && *ptr == ' ');
        ptr++;
        *ptr = '\0';

        if (strcmpi(w1, "timestamp_format") == 0)
        {
            strncpy(timestamp_format, w2, 20);
        }
        else if (strcmpi(w1, "stdout_with_ansisequence") == 0)
        {
            stdout_with_ansisequence = config_switch(w2);
        }
        else if (strcmpi(w1, "console_silent") == 0)
        {
            ShowInfo("Console Silent Setting: %d", atoi(w2));
            msg_silent = atoi(w2);
        }
        else if (strcmpi(w1, "map_port") == 0)
        {
            map_config.usMapPort = (atoi(w2));
        }
        else if (strcmp(w1, "buff_maxsize") == 0)
        {
            map_config.buffer_size = atoi(w2);
        }
        else if (strcmp(w1, "max_time_lastupdate") == 0)
        {
            map_config.max_time_lastupdate = atoi(w2);
        }
        else if (strcmp(w1, "vanadiel_time_offset") == 0)
        {
            map_config.vanadiel_time_offset = atoi(w2);
        }
        else if (strcmp(w1, "lightluggage_block") == 0)
        {
            map_config.lightluggage_block = atoi(w2);
        }
        else if (strcmp(w1, "exp_rate") == 0)
        {
            map_config.exp_rate = atof(w2);
        }
        else if (strcmp(w1, "exp_loss_rate") == 0)
        {
            map_config.exp_loss_rate = atof(w2);
        }
        else if (strcmp(w1, "exp_party_gap_penalties") == 0)
        {
            map_config.exp_party_gap_penalties = atof(w2);
        }
        else if (strcmp(w1, "fov_party_gap_penalties") == 0)
        {
            map_config.fov_party_gap_penalties = atof(w2);
        }
        else if (strcmp(w1, "fov_allow_alliance") == 0)
        {
            map_config.fov_allow_alliance = atof(w2);
        }
        else if (strcmp(w1, "mob_tp_multiplier") == 0)
        {
            map_config.mob_tp_multiplier = atof(w2);
        }
        else if (strcmp(w1, "player_tp_multiplier") == 0)
        {
            map_config.player_tp_multiplier = atof(w2);
        }
        else if (strcmp(w1, "nm_hp_multiplier") == 0)
        {
            map_config.nm_hp_multiplier = atof(w2);
        }
        else if (strcmp(w1, "mob_hp_multiplier") == 0)
        {
            map_config.mob_hp_multiplier = atof(w2);
        }
        else if (strcmp(w1, "player_hp_multiplier") == 0)
        {
            map_config.player_hp_multiplier = atof(w2);
        }
        else if (strcmp(w1, "nm_mp_multiplier") == 0)
        {
            map_config.nm_mp_multiplier = atof(w2);
        }
        else if (strcmp(w1, "mob_mp_multiplier") == 0)
        {
            map_config.mob_mp_multiplier = atof(w2);
        }
        else if (strcmp(w1, "player_mp_multiplier") == 0)
        {
            map_config.player_mp_multiplier = atof(w2);
        }
        else if (strcmp(w1, "sj_mp_divisor") == 0)
        {
            map_config.sj_mp_divisor = atof(w2);
        }
        else if (strcmp(w1, "nm_stat_multiplier") == 0)
        {
            map_config.nm_stat_multiplier = atof(w2);
        }
        else if (strcmp(w1, "mob_stat_multiplier") == 0)
        {
            map_config.mob_stat_multiplier = atof(w2);
        }
        else if (strcmp(w1, "player_stat_multiplier") == 0)
        {
            map_config.player_stat_multiplier = atof(w2);
        }
        else if (strcmp(w1, "drop_rate_multiplier") == 0)
        {
            map_config.drop_rate_multiplier = atof(w2);
        }
        else if (strcmp(w1, "all_mobs_gil_bonus") == 0)
        {
            map_config.all_mobs_gil_bonus = atoi(w2);
        }
        else if (strcmp(w1, "max_gil_bonus") == 0)
        {
            map_config.max_gil_bonus = atoi(w2);
        }
        else if (strcmp(w1, "exp_retain") == 0)
        {
            map_config.exp_retain = dsp_cap(atof(w2), 0.0f, 1.0f);
        }
        else if (strcmp(w1, "exp_loss_level") == 0)
        {
            map_config.exp_loss_level = atoi(w2);
        }
        else if (strcmp(w1, "level_sync_enable") == 0)
        {
            map_config.level_sync_enable = atoi(w2);
        }
        else if (strcmp(w1, "all_jobs_widescan") == 0)
        {
            map_config.all_jobs_widescan = atoi(w2);
        }
        else if (strcmp(w1, "speed_mod") == 0)
        {
            map_config.speed_mod = atoi(w2);
        }
        else if (strcmp(w1, "mob_speed_mod") == 0)
        {
            map_config.mob_speed_mod = atoi(w2);
        }
        else if (strcmp(w1, "skillup_chance_multiplier") == 0)
        {
            map_config.skillup_chance_multiplier = atof(w2);
        }
        else if (strcmp(w1, "craft_chance_multiplier") == 0)
        {
            map_config.craft_chance_multiplier = atof(w2);
        }
        else if (strcmp(w1, "skillup_amount_multiplier") == 0)
        {
            map_config.skillup_amount_multiplier = atof(w2);
        }
        else if (strcmp(w1, "craft_amount_multiplier") == 0)
        {
            map_config.craft_amount_multiplier = atof(w2);
        }
        else if (strcmp(w1, "craft_day_matters") == 0)
        {
            map_config.craft_day_matters = atof(w2);
        }
        else if (strcmp(w1, "craft_moonphase_matters") == 0)
        {
            map_config.craft_moonphase_matters = atof(w2);
        }
        else if (strcmp(w1, "craft_direction_matters") == 0)
        {
            map_config.craft_direction_matters = atof(w2);
        }
        else if (strcmp(w1, "mysql_host") == 0)
        {
            map_config.mysql_host = aStrdup(w2);
        }
        else if (strcmp(w1, "mysql_login") == 0)
        {
            map_config.mysql_login = aStrdup(w2);
        }
        else if (strcmp(w1, "mysql_password") == 0)
        {
            map_config.mysql_password = aStrdup(w2);
        }
        else if (strcmp(w1, "mysql_port") == 0)
        {
            map_config.mysql_port = atoi(w2);
        }
        else if (strcmp(w1, "mysql_database") == 0)
        {
            map_config.mysql_database = aStrdup(w2);
        }
        else if (strcmpi(w1, "import") == 0)
        {
            map_config_read(w2);
        }
        else if (strcmpi(w1, "newstyle_skillups") == 0)
        {
            map_config.newstyle_skillups = atoi(w2);
        }
        else if (strcmp(w1, "Battle_cap_tweak") == 0)
        {
            map_config.Battle_cap_tweak = atoi(w2);
        }
        else if (strcmp(w1, "CoP_Battle_cap") == 0)
        {
            map_config.CoP_Battle_cap = atoi(w2);
        }
        else if (strcmp(w1, "max_merit_points") == 0)
        {
            map_config.max_merit_points = atoi(w2);
        }
        else if (strcmp(w1, "yell_cooldown") == 0)
        {
            map_config.yell_cooldown = atoi(w2);
        }
        else if (strcmp(w1, "audit_chat") == 0)
        {
            map_config.audit_chat = atoi(w2);
        }
        else if (strcmp(w1, "audit_say") == 0)
        {
            map_config.audit_say = atoi(w2);
        }
        else if (strcmp(w1, "audit_shout") == 0)
        {
            map_config.audit_shout = atoi(w2);
        }
        else if (strcmp(w1, "audit_tell") == 0)
        {
            map_config.audit_tell = atoi(w2);
        }
        else if (strcmp(w1, "audit_yell") == 0)
        {
            map_config.audit_yell = atoi(w2);
        }
        else if (strcmp(w1, "audit_linkshell") == 0)
        {
            map_config.audit_linkshell = atoi(w2);
        }
        else if (strcmp(w1, "audit_party") == 0)
        {
            map_config.audit_party = atoi(w2);
        }
        else if (strcmp(w1, "msg_server_port") == 0)
        {
            map_config.msg_server_port = atoi(w2);
        }
        else if (strcmp(w1, "msg_server_ip") == 0)
        {
            map_config.msg_server_ip = aStrdup(w2);
        }
        else
        {
            ShowWarning(CL_YELLOW"Unknown setting '%s' in file %s\n" CL_RESET, w1, cfgName);
        }
    }

    fclose(fp);

    // Load the English server message..
    fp = fopen("./conf/server_message.conf", "rb");
    if (fp == nullptr)
    {
        ShowError("Could not read English server message from: ./conf/server_message.conf\n");
        return 1;
    }

    while (fgets(line, sizeof(line), fp))
    {
        string_t sline(line);
        map_config.server_message += sline;
    }

    fclose(fp);

    // Load the French server message..
    fp = fopen("./conf/server_message_fr.conf", "rb");
    if (fp == nullptr)
    {
        ShowError("Could not read English server message from: ./conf/server_message_fr.conf\n");
        return 1;
    }

    while (fgets(line, sizeof(line), fp))
    {
        string_t sline(line);
        map_config.server_message_fr += sline;
    }

    fclose(fp);

    // Ensure both messages have nullptr terminates..
    if (map_config.server_message.at(map_config.server_message.length() - 1) != 0x00)
    {
        map_config.server_message += (char)0x00;
    }
    if (map_config.server_message_fr.at(map_config.server_message_fr.length() - 1) != 0x00)
    {
        map_config.server_message_fr += (char)0x00;
    }

    return 0;
}
コード例 #26
0
ファイル: map.cpp プロジェクト: Laterus/Darkstar-Linux-Fork
int32 map_config_read(const int8* cfgName)
{
    int8 line[1024], w1[1024], w2[1024];
    FILE* fp;

    fp = fopen(cfgName,"r");
    if( fp == NULL )
    {
        ShowError("Map configuration file not found at: %s\n", cfgName);
        return 1;
    }

    while( fgets(line, sizeof(line), fp) )
    {
        int8* ptr;

        if( line[0] == '#' )
            continue;
        if( sscanf(line, "%[^:]: %[^\t\r\n]", w1, w2) < 2 )
            continue;

        //Strip trailing spaces
        ptr = w2 + strlen(w2);
        while (--ptr >= w2 && *ptr == ' ');
        ptr++;
        *ptr = '\0';

        if(strcmpi(w1,"timestamp_format") == 0)
        {
            strncpy(timestamp_format, w2, 20);
        }
        else if(strcmpi(w1,"stdout_with_ansisequence") == 0)
        {
            stdout_with_ansisequence = config_switch(w2);
        }
        else if(strcmpi(w1,"console_silent") == 0)
        {
            ShowInfo("Console Silent Setting: %d", atoi(w2));
            msg_silent = atoi(w2);
        }
        else if (strcmpi(w1,"map_port") == 0)
        {
            map_config.usMapPort = (atoi(w2));
        }
        else if (strcmp(w1,"buff_maxsize") == 0)
        {
            map_config.buffer_size = atoi(w2);
        }
        else if (strcmp(w1,"max_time_lastupdate") == 0)
        {
            map_config.max_time_lastupdate = atoi(w2);
        }
        else if (strcmp(w1,"vanadiel_time_offset") == 0)
        {
            map_config.vanadiel_time_offset = atoi(w2);
        }
        else if (strcmp(w1,"lightluggage_block") == 0)
        {
            map_config.lightluggage_block = atoi(w2);
        }
        else if (strcmp(w1,"mysql_host") == 0)
        {
            map_config.mysql_host = aStrdup(w2);
        }
        else if (strcmp(w1,"mysql_login") == 0)
        {
            map_config.mysql_login = aStrdup(w2);
        }
        else if (strcmp(w1,"mysql_password") == 0)
        {
            map_config.mysql_password = aStrdup(w2);
        }
        else if (strcmp(w1,"mysql_port") == 0)
        {
            map_config.mysql_port = atoi(w2);
        }
        else if (strcmp(w1,"mysql_database") == 0)
        {
            map_config.mysql_database = aStrdup(w2);
        }
        else if (strcmpi(w1,"server_message") == 0)
        {
            map_config.server_message = aStrdup(w2);

            uint32 length = (uint32)strlen(map_config.server_message);

            for(uint32 count = 0; count < length; ++count)
            {
                if (RBUFW(map_config.server_message, count) == 0x6E5C) //  \n = 0x6E5C in hex
                {
                    WBUFW(map_config.server_message, count) =  0x0A0D;
                }
            }
        }
        else if (strcmpi(w1,"import") == 0)
        {
            map_config_read(w2);
        }
        else
        {
            ShowWarning(CL_YELLOW"Unknown setting '%s' in file %s\n"CL_RESET, w1, cfgName);
        }
    }

    fclose(fp);
    return 0;
}