Various things:
- Fixed inline translations when using %T - "Improved" caching of server language - Renamed Translator::GetServerLanguageCode() to GetServerLanguage() - Added some more comments to sm_globals.h - Natives folder in project file mysteriously was moved inside Interfaces, so moved it back o_O - DS hates empty if statements :o --HG-- extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%40675
This commit is contained in:
		
							parent
							
								
									5ee48f60a2
								
							
						
					
					
						commit
						e677d5d5de
					
				| @ -47,13 +47,13 @@ void CoreConfig::OnRootConsoleCommand(const char *command, unsigned int argcount | |||||||
| 
 | 
 | ||||||
| 		char error[255]; | 		char error[255]; | ||||||
| 
 | 
 | ||||||
| 		ConfigResult err = SetConfigOption(option, value, ConfigSource_Console, error, sizeof(error)); | 		ConfigResult res = SetConfigOption(option, value, ConfigSource_Console, error, sizeof(error)); | ||||||
| 
 | 
 | ||||||
| 		if (err == ConfigResult_Reject) | 		if (res == ConfigResult_Reject) | ||||||
| 		{ | 		{ | ||||||
| 			g_RootMenu.ConsolePrint("Could not set config option \"%s\" to \"%s\" (%s)", option, value, error); | 			g_RootMenu.ConsolePrint("[SM] Could not set config option \"%s\" to \"%s\" (%s)", option, value, error); | ||||||
| 		} else if (err == ConfigResult_Ignore) { | 		} else if (res == ConfigResult_Ignore) { | ||||||
| 			g_RootMenu.ConsolePrint("No such config option \"%s\" exists.", option); | 			g_RootMenu.ConsolePrint("[SM] No such config option \"%s\" exists.", option); | ||||||
| 		} else { | 		} else { | ||||||
| 			g_RootMenu.ConsolePrint("Config option \"%s\" successfully set to \"%s.\"", option, value); | 			g_RootMenu.ConsolePrint("Config option \"%s\" successfully set to \"%s.\"", option, value); | ||||||
| 		} | 		} | ||||||
| @ -82,8 +82,7 @@ void CoreConfig::Initialize() | |||||||
| 	g_LibSys.PathFormat(filePath, sizeof(filePath), "%s/%s", g_SourceMod.GetModPath(), corecfg); | 	g_LibSys.PathFormat(filePath, sizeof(filePath), "%s/%s", g_SourceMod.GetModPath(), corecfg); | ||||||
| 
 | 
 | ||||||
| 	/* Parse config file */ | 	/* Parse config file */ | ||||||
| 	if ((err=g_TextParser.ParseFile_SMC(filePath, this, NULL, NULL)) | 	if ((err=g_TextParser.ParseFile_SMC(filePath, this, NULL, NULL)) != SMCParse_Okay) | ||||||
| 		!= SMCParse_Okay) |  | ||||||
| 	{ | 	{ | ||||||
|  		/* :TODO: This won't actually log or print anything :( - So fix that somehow */ |  		/* :TODO: This won't actually log or print anything :( - So fix that somehow */ | ||||||
| 		const char *error = g_TextParser.GetSMCErrorString(err); | 		const char *error = g_TextParser.GetSMCErrorString(err); | ||||||
|  | |||||||
| @ -34,10 +34,11 @@ ConfigResult Logger::OnSourceModConfigChanged(const char *key, | |||||||
| { | { | ||||||
| 	if (strcasecmp(key, "Logging") == 0) | 	if (strcasecmp(key, "Logging") == 0) | ||||||
| 	{ | 	{ | ||||||
| 		bool state = true; | 		bool state; | ||||||
| 
 | 
 | ||||||
| 		if (strcasecmp(value, "on") == 0) | 		if (strcasecmp(value, "on") == 0) | ||||||
| 		{ | 		{ | ||||||
|  | 			state = true; | ||||||
| 		} else if (strcasecmp(value, "off") == 0) { | 		} else if (strcasecmp(value, "off") == 0) { | ||||||
| 			state = false; | 			state = false; | ||||||
| 		} else { | 		} else { | ||||||
| @ -47,12 +48,7 @@ ConfigResult Logger::OnSourceModConfigChanged(const char *key, | |||||||
| 
 | 
 | ||||||
| 		if (source == ConfigSource_Console) | 		if (source == ConfigSource_Console) | ||||||
| 		{ | 		{ | ||||||
| 			if (state && !m_Active) | 			state ? EnableLogging() : DisableLogging(); | ||||||
| 			{ |  | ||||||
| 				EnableLogging(); |  | ||||||
| 			} else if (!state && m_Active) { |  | ||||||
| 				DisableLogging(); |  | ||||||
| 			} |  | ||||||
| 		} else { | 		} else { | ||||||
| 			m_InitialState = state; | 			m_InitialState = state; | ||||||
| 		} | 		} | ||||||
| @ -412,7 +408,7 @@ void Logger::EnableLogging() | |||||||
| 		return; | 		return; | ||||||
| 	} | 	} | ||||||
| 	m_Active = true; | 	m_Active = true; | ||||||
| 	LogMessage("Logging enabled manually by user."); | 	LogMessage("[SM] Logging enabled manually by user."); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void Logger::DisableLogging() | void Logger::DisableLogging() | ||||||
| @ -421,7 +417,7 @@ void Logger::DisableLogging() | |||||||
| 	{ | 	{ | ||||||
| 		return; | 		return; | ||||||
| 	} | 	} | ||||||
| 	LogMessage("Logging disabled manually by user."); | 	LogMessage("[SM] Logging disabled manually by user."); | ||||||
| 	m_Active = false; | 	m_Active = false; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -580,11 +580,11 @@ const char *CPhraseFile::GetFilename() | |||||||
|  ** MAIN TRANSLATOR CODE ** |  ** MAIN TRANSLATOR CODE ** | ||||||
|  **************************/ |  **************************/ | ||||||
| 
 | 
 | ||||||
| Translator::Translator() | Translator::Translator() : m_ServerLang(LANGUAGE_ENGLISH) | ||||||
| { | { | ||||||
| 	m_pStringTab = new BaseStringTable(2048); | 	m_pStringTab = new BaseStringTable(2048); | ||||||
| 	m_pLCodeLookup = sm_trie_create(); | 	m_pLCodeLookup = sm_trie_create(); | ||||||
| 	strncopy(m_ServerLangCode, "en", sizeof(m_ServerLangCode)); | 	strncopy(m_InitialLang, "en", sizeof(m_InitialLang)); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| Translator::~Translator() | Translator::~Translator() | ||||||
| @ -620,9 +620,11 @@ ConfigResult Translator::OnSourceModConfigChanged(const char *key, | |||||||
| 				UTIL_Format(error, maxlength, "Language code \"%s\" is not registered", value); | 				UTIL_Format(error, maxlength, "Language code \"%s\" is not registered", value); | ||||||
| 				return ConfigResult_Reject; | 				return ConfigResult_Reject; | ||||||
| 			} | 			} | ||||||
| 		} |  | ||||||
| 
 | 
 | ||||||
| 		strncopy(m_ServerLangCode, value, sizeof(m_ServerLangCode)); | 			m_ServerLang = index; | ||||||
|  | 		} else { | ||||||
|  | 			strncopy(m_InitialLang, value, sizeof(m_InitialLang)); | ||||||
|  | 		} | ||||||
| 
 | 
 | ||||||
| 		return ConfigResult_Accept; | 		return ConfigResult_Accept; | ||||||
| 	} | 	} | ||||||
| @ -712,6 +714,18 @@ void Translator::RebuildLanguageDatabase(const char *lang_header_file) | |||||||
| 		g_Logger.LogError("[SM] Parse error (line %d, column %d): %s", line, col, str_err); | 		g_Logger.LogError("[SM] Parse error (line %d, column %d): %s", line, col, str_err); | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
|  | 	void *serverLang; | ||||||
|  | 
 | ||||||
|  | 	if (!sm_trie_retrieve(m_pLCodeLookup, m_InitialLang, &serverLang)) | ||||||
|  | 	{ | ||||||
|  | 		g_Logger.LogError("Server language was set to bad language \"%s\" -- reverting to English", m_InitialLang); | ||||||
|  | 
 | ||||||
|  | 		strncopy(m_InitialLang, "en", sizeof(m_InitialLang)); | ||||||
|  | 		m_ServerLang = LANGUAGE_ENGLISH; | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	m_ServerLang = reinterpret_cast<unsigned int>(serverLang); | ||||||
|  | 
 | ||||||
| 	if (!m_Languages.size()) | 	if (!m_Languages.size()) | ||||||
| 	{ | 	{ | ||||||
| 		g_Logger.LogError("[SM] Fatal error, no languages found! Translation will not work."); | 		g_Logger.LogError("[SM] Fatal error, no languages found! Translation will not work."); | ||||||
| @ -829,15 +843,11 @@ TransError Translator::CoreTrans(int client, | |||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	/* Using server lang temporarily until client lang stuff is implemented */ | 	/* Using server lang temporarily until client lang stuff is implemented */ | ||||||
| 	unsigned int serverLang; | 	unsigned int serverLang = GetServerLanguage(); | ||||||
| 	if (!sm_trie_retrieve(m_pLCodeLookup, m_ServerLangCode, (void **)&serverLang)) |  | ||||||
| 	{ |  | ||||||
| 		return Trans_BadLanguage; |  | ||||||
| 	} |  | ||||||
| 
 | 
 | ||||||
| 	Translation trans; | 	Translation trans; | ||||||
| 	TransError err; | 	TransError err; | ||||||
| 	if ((err=g_pCorePhrases->GetTranslation(phrase, serverLang, &trans)) != Trans_Okay) | 	if ((err=g_pCorePhrases->GetTranslation(phrase, m_ServerLang, &trans)) != Trans_Okay) | ||||||
| 	{ | 	{ | ||||||
| 		return err; | 		return err; | ||||||
| 	} | 	} | ||||||
| @ -852,20 +862,7 @@ TransError Translator::CoreTrans(int client, | |||||||
| 	return Trans_Okay; | 	return Trans_Okay; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| unsigned int Translator::GetServerLanguageCode() | unsigned int Translator::GetServerLanguage() | ||||||
| { | { | ||||||
| 	void *serverLang; | 	return m_ServerLang; | ||||||
| 
 |  | ||||||
| 	/* :TODO: there is absolutely no reason this shouldn't be cached
 |  | ||||||
| 	 * I don't even know why it was returning a string originally |  | ||||||
| 	 */ |  | ||||||
| 
 |  | ||||||
| 	if (!sm_trie_retrieve(m_pLCodeLookup, m_ServerLangCode, &serverLang)) |  | ||||||
| 	{ |  | ||||||
| 		g_Logger.LogError("Server language was set to bad language \"%s\" -- reverting to English", m_ServerLangCode); |  | ||||||
| 		strncopy(m_ServerLangCode, "en", sizeof(m_ServerLangCode)); |  | ||||||
| 		return LANGUAGE_ENGLISH; |  | ||||||
| 	} |  | ||||||
| 
 |  | ||||||
| 	return (unsigned int)serverLang; |  | ||||||
| } | } | ||||||
|  | |||||||
| @ -127,7 +127,7 @@ public: | |||||||
| 						 const char *phrase,  | 						 const char *phrase,  | ||||||
| 						 void **params,  | 						 void **params,  | ||||||
| 						 size_t *outlen=NULL); | 						 size_t *outlen=NULL); | ||||||
| 	unsigned int GetServerLanguageCode(); | 	unsigned int GetServerLanguage(); | ||||||
| private: | private: | ||||||
| 	bool AddLanguage(const char *langcode, const char *description); | 	bool AddLanguage(const char *langcode, const char *description); | ||||||
| private: | private: | ||||||
| @ -137,7 +137,8 @@ private: | |||||||
| 	Trie *m_pLCodeLookup; | 	Trie *m_pLCodeLookup; | ||||||
| 	bool m_InLanguageSection; | 	bool m_InLanguageSection; | ||||||
| 	String m_CustomError; | 	String m_CustomError; | ||||||
| 	char m_ServerLangCode[3]; | 	unsigned int m_ServerLang; | ||||||
|  | 	char m_InitialLang[3]; | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| extern CPhraseFile *g_pCorePhrases; | extern CPhraseFile *g_pCorePhrases; | ||||||
|  | |||||||
| @ -457,94 +457,6 @@ | |||||||
| 				RelativePath="..\..\public\IUserMessages.h" | 				RelativePath="..\..\public\IUserMessages.h" | ||||||
| 				> | 				> | ||||||
| 			</File> | 			</File> | ||||||
| 			<Filter |  | ||||||
| 				Name="Natives" |  | ||||||
| 				> |  | ||||||
| 				<File |  | ||||||
| 					RelativePath="..\smn_admin.cpp" |  | ||||||
| 					> |  | ||||||
| 				</File> |  | ||||||
| 				<File |  | ||||||
| 					RelativePath="..\smn_bitbuffer.cpp" |  | ||||||
| 					> |  | ||||||
| 				</File> |  | ||||||
| 				<File |  | ||||||
| 					RelativePath="..\smn_console.cpp" |  | ||||||
| 					> |  | ||||||
| 				</File> |  | ||||||
| 				<File |  | ||||||
| 					RelativePath="..\smn_core.cpp" |  | ||||||
| 					> |  | ||||||
| 				</File> |  | ||||||
| 				<File |  | ||||||
| 					RelativePath="..\smn_datapacks.cpp" |  | ||||||
| 					> |  | ||||||
| 				</File> |  | ||||||
| 				<File |  | ||||||
| 					RelativePath="..\smn_entities.cpp" |  | ||||||
| 					> |  | ||||||
| 				</File> |  | ||||||
| 				<File |  | ||||||
| 					RelativePath="..\smn_events.cpp" |  | ||||||
| 					> |  | ||||||
| 				</File> |  | ||||||
| 				<File |  | ||||||
| 					RelativePath="..\smn_fakenatives.cpp" |  | ||||||
| 					> |  | ||||||
| 				</File> |  | ||||||
| 				<File |  | ||||||
| 					RelativePath="..\smn_filesystem.cpp" |  | ||||||
| 					> |  | ||||||
| 				</File> |  | ||||||
| 				<File |  | ||||||
| 					RelativePath="..\smn_float.cpp" |  | ||||||
| 					> |  | ||||||
| 				</File> |  | ||||||
| 				<File |  | ||||||
| 					RelativePath="..\smn_functions.cpp" |  | ||||||
| 					> |  | ||||||
| 				</File> |  | ||||||
| 				<File |  | ||||||
| 					RelativePath="..\smn_halflife.cpp" |  | ||||||
| 					> |  | ||||||
| 				</File> |  | ||||||
| 				<File |  | ||||||
| 					RelativePath="..\smn_handles.cpp" |  | ||||||
| 					> |  | ||||||
| 				</File> |  | ||||||
| 				<File |  | ||||||
| 					RelativePath="..\smn_keyvalues.cpp" |  | ||||||
| 					> |  | ||||||
| 				</File> |  | ||||||
| 				<File |  | ||||||
| 					RelativePath="..\smn_lang.cpp" |  | ||||||
| 					> |  | ||||||
| 				</File> |  | ||||||
| 				<File |  | ||||||
| 					RelativePath="..\smn_player.cpp" |  | ||||||
| 					> |  | ||||||
| 				</File> |  | ||||||
| 				<File |  | ||||||
| 					RelativePath="..\smn_sorting.cpp" |  | ||||||
| 					> |  | ||||||
| 				</File> |  | ||||||
| 				<File |  | ||||||
| 					RelativePath="..\smn_string.cpp" |  | ||||||
| 					> |  | ||||||
| 				</File> |  | ||||||
| 				<File |  | ||||||
| 					RelativePath="..\smn_textparse.cpp" |  | ||||||
| 					> |  | ||||||
| 				</File> |  | ||||||
| 				<File |  | ||||||
| 					RelativePath="..\smn_timers.cpp" |  | ||||||
| 					> |  | ||||||
| 				</File> |  | ||||||
| 				<File |  | ||||||
| 					RelativePath="..\smn_usermsgs.cpp" |  | ||||||
| 					> |  | ||||||
| 				</File> |  | ||||||
| 			</Filter> |  | ||||||
| 		</Filter> | 		</Filter> | ||||||
| 		<Filter | 		<Filter | ||||||
| 			Name="Systems" | 			Name="Systems" | ||||||
| @ -790,6 +702,94 @@ | |||||||
| 				> | 				> | ||||||
| 			</File> | 			</File> | ||||||
| 		</Filter> | 		</Filter> | ||||||
|  | 		<Filter | ||||||
|  | 			Name="Natives" | ||||||
|  | 			> | ||||||
|  | 			<File | ||||||
|  | 				RelativePath="..\smn_admin.cpp" | ||||||
|  | 				> | ||||||
|  | 			</File> | ||||||
|  | 			<File | ||||||
|  | 				RelativePath="..\smn_bitbuffer.cpp" | ||||||
|  | 				> | ||||||
|  | 			</File> | ||||||
|  | 			<File | ||||||
|  | 				RelativePath="..\smn_console.cpp" | ||||||
|  | 				> | ||||||
|  | 			</File> | ||||||
|  | 			<File | ||||||
|  | 				RelativePath="..\smn_core.cpp" | ||||||
|  | 				> | ||||||
|  | 			</File> | ||||||
|  | 			<File | ||||||
|  | 				RelativePath="..\smn_datapacks.cpp" | ||||||
|  | 				> | ||||||
|  | 			</File> | ||||||
|  | 			<File | ||||||
|  | 				RelativePath="..\smn_entities.cpp" | ||||||
|  | 				> | ||||||
|  | 			</File> | ||||||
|  | 			<File | ||||||
|  | 				RelativePath="..\smn_events.cpp" | ||||||
|  | 				> | ||||||
|  | 			</File> | ||||||
|  | 			<File | ||||||
|  | 				RelativePath="..\smn_fakenatives.cpp" | ||||||
|  | 				> | ||||||
|  | 			</File> | ||||||
|  | 			<File | ||||||
|  | 				RelativePath="..\smn_filesystem.cpp" | ||||||
|  | 				> | ||||||
|  | 			</File> | ||||||
|  | 			<File | ||||||
|  | 				RelativePath="..\smn_float.cpp" | ||||||
|  | 				> | ||||||
|  | 			</File> | ||||||
|  | 			<File | ||||||
|  | 				RelativePath="..\smn_functions.cpp" | ||||||
|  | 				> | ||||||
|  | 			</File> | ||||||
|  | 			<File | ||||||
|  | 				RelativePath="..\smn_halflife.cpp" | ||||||
|  | 				> | ||||||
|  | 			</File> | ||||||
|  | 			<File | ||||||
|  | 				RelativePath="..\smn_handles.cpp" | ||||||
|  | 				> | ||||||
|  | 			</File> | ||||||
|  | 			<File | ||||||
|  | 				RelativePath="..\smn_keyvalues.cpp" | ||||||
|  | 				> | ||||||
|  | 			</File> | ||||||
|  | 			<File | ||||||
|  | 				RelativePath="..\smn_lang.cpp" | ||||||
|  | 				> | ||||||
|  | 			</File> | ||||||
|  | 			<File | ||||||
|  | 				RelativePath="..\smn_player.cpp" | ||||||
|  | 				> | ||||||
|  | 			</File> | ||||||
|  | 			<File | ||||||
|  | 				RelativePath="..\smn_sorting.cpp" | ||||||
|  | 				> | ||||||
|  | 			</File> | ||||||
|  | 			<File | ||||||
|  | 				RelativePath="..\smn_string.cpp" | ||||||
|  | 				> | ||||||
|  | 			</File> | ||||||
|  | 			<File | ||||||
|  | 				RelativePath="..\smn_textparse.cpp" | ||||||
|  | 				> | ||||||
|  | 			</File> | ||||||
|  | 			<File | ||||||
|  | 				RelativePath="..\smn_timers.cpp" | ||||||
|  | 				> | ||||||
|  | 			</File> | ||||||
|  | 			<File | ||||||
|  | 				RelativePath="..\smn_usermsgs.cpp" | ||||||
|  | 				> | ||||||
|  | 			</File> | ||||||
|  | 		</Filter> | ||||||
| 	</Files> | 	</Files> | ||||||
| 	<Globals> | 	<Globals> | ||||||
| 	</Globals> | 	</Globals> | ||||||
|  | |||||||
| @ -28,19 +28,22 @@ using namespace SourcePawn; | |||||||
| using namespace SourceMod; | using namespace SourceMod; | ||||||
| 
 | 
 | ||||||
| /**
 | /**
 | ||||||
|  * @brief Lists error codes possible from attempting to set a core configuration option. |  * @brief Lists result codes possible from attempting to set a core configuration option. | ||||||
|  */ |  */ | ||||||
| enum ConfigResult | enum ConfigResult | ||||||
| { | { | ||||||
| 	ConfigResult_Accept = 0, | 	ConfigResult_Accept = 0,	/**< Config option was successfully set */ | ||||||
| 	ConfigResult_Reject = 1, | 	ConfigResult_Reject = 1,	/**< Config option was given an invalid value and was rejected */ | ||||||
| 	ConfigResult_Ignore = 2 | 	ConfigResult_Ignore = 2		/**< Config option was invalid, but ignored */ | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
|  | /**
 | ||||||
|  |  * @brief Lists possible sources of a config option change | ||||||
|  |  */ | ||||||
| enum ConfigSource | enum ConfigSource | ||||||
| { | { | ||||||
| 	ConfigSource_File = 0, | 	ConfigSource_File = 0,		/**< Config option was set from config file (core.cfg) */ | ||||||
| 	ConfigSource_Console = 1, | 	ConfigSource_Console = 1,	/**< Config option was set from console command (sm config) */ | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| /** 
 | /** 
 | ||||||
|  | |||||||
| @ -73,9 +73,9 @@ size_t Translate(char *buffer, size_t maxlen, IPluginContext *pCtx, const char * | |||||||
| try_serverlang: | try_serverlang: | ||||||
| 	if (target == LANG_SERVER) | 	if (target == LANG_SERVER) | ||||||
| 	{ | 	{ | ||||||
| 		langid = g_Translator.GetServerLanguageCode(); | 		langid = g_Translator.GetServerLanguage(); | ||||||
|  	} else if ((target >= 1) && (target <= g_Players.GetMaxClients())) { |  	} else if ((target >= 1) && (target <= g_Players.GetMaxClients())) { | ||||||
| 		langid = g_Translator.GetServerLanguageCode(); | 		langid = g_Translator.GetServerLanguage(); | ||||||
| 	} else { | 	} else { | ||||||
| 		pCtx->ThrowNativeErrorEx(SP_ERROR_PARAM, "Translation failed: invalid client index %d", target); | 		pCtx->ThrowNativeErrorEx(SP_ERROR_PARAM, "Translation failed: invalid client index %d", target); | ||||||
| 		goto error_out; | 		goto error_out; | ||||||
| @ -736,9 +736,11 @@ reswitch: | |||||||
| 				char *key; | 				char *key; | ||||||
| 				bool error; | 				bool error; | ||||||
| 				size_t res; | 				size_t res; | ||||||
| 				cell_t target = params[arg++]; | 				cell_t *target; | ||||||
|  | 				pCtx->LocalToPhysAddr(params[arg++], &target); | ||||||
| 				pCtx->LocalToString(params[arg++], &key); | 				pCtx->LocalToString(params[arg++], &key); | ||||||
| 				res = Translate(buf_p, llen, pCtx, key, target, params, &arg, &error); | 				printf("target = %d\n", target); | ||||||
|  | 				res = Translate(buf_p, llen, pCtx, key, *target, params, &arg, &error); | ||||||
| 				if (error) | 				if (error) | ||||||
| 				{ | 				{ | ||||||
| 					return 0; | 					return 0; | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user