Skip to content

Commit 1e3c7c9

Browse files
authored
Race Condition for Language Target When Formatting with %l (#1133)
1 parent 48c9828 commit 1e3c7c9

File tree

4 files changed

+10
-2
lines changed

4 files changed

+10
-2
lines changed

amxmodx/CLang.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -626,3 +626,8 @@ void CLangMngr::SetDefLang(int id)
626626
{
627627
m_CurGlobId = id;
628628
}
629+
630+
void CLangMngr::SetFmtLang(int id)
631+
{
632+
m_CurFmtId = id;
633+
}

amxmodx/CLang.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ class CLangMngr : public ITextListener_INI
130130

131131
// Current global client-id for functions like client_print with first parameter 0
132132
int m_CurGlobId;
133+
int m_CurFmtId;
133134
public:
134135
// Merge a definitions file
135136
int MergeDefinitionFile(const char *file);
@@ -156,8 +157,10 @@ class CLangMngr : public ITextListener_INI
156157

157158
// When a language id in a format string in FormatAmxString is LANG_PLAYER, the glob id decides which language to take.
158159
void SetDefLang(int id);
160+
void SetFmtLang(int id);
159161

160162
inline int GetDefLang() const { return m_CurGlobId; }
163+
inline int GetFmtLang() const { return m_CurFmtId; }
161164

162165
// Reset
163166
void Clear();

amxmodx/amxmodx.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4625,7 +4625,7 @@ static cell AMX_NATIVE_CALL LookupLangKey(AMX *amx, cell *params)
46254625
// SetGlobalTransTarget(client)
46264626
static cell AMX_NATIVE_CALL SetGlobalTransTarget(AMX *amx, cell *params)
46274627
{
4628-
g_langMngr.SetDefLang(params[1]);
4628+
g_langMngr.SetFmtLang(params[1]);
46294629

46304630
return 1;
46314631
};

amxmodx/format.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -693,7 +693,7 @@ size_t atcprintf(D *buffer, size_t maxlen, const S *format, AMX *amx, cell *para
693693
else
694694
{
695695
CHECK_ARGS(0);
696-
lang = playerlang(g_langMngr.GetDefLang());
696+
lang = playerlang(g_langMngr.GetFmtLang());
697697
}
698698
const char *key = get_amxstring(amx, params[arg++], 3, len);
699699
const char *def = translate(amx, lang, key);

0 commit comments

Comments
 (0)