Skip to content

Commit 6780fbd

Browse files
Addlibsqaisjp
authored andcommitted
Fix inconsistencies in reading userdata in Player functions (#308)
Restrict these functions to console or player: * getPlayerName * getPlayerIP * getPlayerAccount Restrict these to player only: * SetPlayerName * RedirectPlayer
1 parent 50082a0 commit 6780fbd

File tree

1 file changed

+36
-21
lines changed

1 file changed

+36
-21
lines changed

Server/mods/deathmatch/logic/luadefs/CLuaPlayerDefs.cpp

Lines changed: 36 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -223,21 +223,26 @@ int CLuaPlayerDefs::CanPlayerUseFunction(lua_State* luaVM)
223223
int CLuaPlayerDefs::GetPlayerName(lua_State* luaVM)
224224
{
225225
// string getPlayerName ( player thePlayer )
226-
CElement* pElement;
226+
CElement* pElement; // player or console
227227

228228
CScriptArgReader argStream(luaVM);
229229
argStream.ReadUserData(pElement);
230230

231231
if (!argStream.HasErrors())
232232
{
233-
SString strNick;
234-
if (CStaticFunctionDefinitions::GetPlayerName(pElement, strNick))
233+
if (IS_PLAYER(pElement) || IS_CONSOLE(pElement))
235234
{
236-
lua_pushstring(luaVM, strNick);
237-
return 1;
235+
SString strNick;
236+
if (CStaticFunctionDefinitions::GetPlayerName(pElement, strNick))
237+
{
238+
lua_pushstring(luaVM, strNick);
239+
return 1;
240+
}
238241
}
242+
else
243+
argStream.SetTypeError("player or console", 1);
239244
}
240-
else
245+
if (argStream.HasErrors())
241246
m_pScriptDebugging->LogCustom(luaVM, argStream.GetFullErrorMessage());
242247

243248
lua_pushboolean(luaVM, false);
@@ -247,21 +252,26 @@ int CLuaPlayerDefs::GetPlayerName(lua_State* luaVM)
247252
int CLuaPlayerDefs::GetPlayerIP(lua_State* luaVM)
248253
{
249254
// string getPlayerIP ( player thePlayer )
250-
CElement* pElement;
255+
CElement* pElement; // player or console
251256

252257
CScriptArgReader argStream(luaVM);
253258
argStream.ReadUserData(pElement);
254259

255260
if (!argStream.HasErrors())
256261
{
257-
SString strIP;
258-
if (CStaticFunctionDefinitions::GetPlayerIP(pElement, strIP))
262+
if (IS_PLAYER(pElement) || IS_CONSOLE(pElement))
259263
{
260-
lua_pushstring(luaVM, strIP);
261-
return 1;
264+
SString strIP;
265+
if (CStaticFunctionDefinitions::GetPlayerIP(pElement, strIP))
266+
{
267+
lua_pushstring(luaVM, strIP);
268+
return 1;
269+
}
262270
}
271+
else
272+
argStream.SetTypeError("player or console", 1);
263273
}
264-
else
274+
if (argStream.HasErrors())
265275
m_pScriptDebugging->LogCustom(luaVM, argStream.GetFullErrorMessage());
266276

267277
lua_pushboolean(luaVM, false);
@@ -292,21 +302,26 @@ int CLuaPlayerDefs::GetPlayerVersion(lua_State* luaVM)
292302
int CLuaPlayerDefs::GetPlayerAccount(lua_State* luaVM)
293303
{
294304
// account getPlayerAccount ( player thePlayer )
295-
CElement* pElement;
305+
CElement* pElement; // player or console
296306

297307
CScriptArgReader argStream(luaVM);
298308
argStream.ReadUserData(pElement);
299309

300310
if (!argStream.HasErrors())
301311
{
302-
CAccount* pAccount = CStaticFunctionDefinitions::GetPlayerAccount(pElement);
303-
if (pAccount)
312+
if (IS_PLAYER(pElement) || IS_CONSOLE(pElement))
304313
{
305-
lua_pushaccount(luaVM, pAccount);
306-
return 1;
314+
CAccount* pAccount = CStaticFunctionDefinitions::GetPlayerAccount(pElement);
315+
if (pAccount)
316+
{
317+
lua_pushaccount(luaVM, pAccount);
318+
return 1;
319+
}
307320
}
321+
else
322+
argStream.SetTypeError("player or console", 1);
308323
}
309-
else
324+
if (argStream.HasErrors())
310325
m_pScriptDebugging->LogCustom(luaVM, argStream.GetFullErrorMessage());
311326

312327
lua_pushboolean(luaVM, false);
@@ -316,8 +331,8 @@ int CLuaPlayerDefs::GetPlayerAccount(lua_State* luaVM)
316331
int CLuaPlayerDefs::SetPlayerName(lua_State* luaVM)
317332
{
318333
// bool setPlayerName ( player thePlayer, string newName )
319-
CElement* pElement;
320-
SString strName;
334+
CPlayer* pElement;
335+
SString strName;
321336

322337
CScriptArgReader argStream(luaVM);
323338
argStream.ReadUserData(pElement);
@@ -1118,7 +1133,7 @@ int CLuaPlayerDefs::SetPlayerBlurLevel(lua_State* luaVM)
11181133

11191134
int CLuaPlayerDefs::RedirectPlayer(lua_State* luaVM)
11201135
{
1121-
CElement* pElement;
1136+
CPlayer* pElement;
11221137
SString strHost;
11231138
unsigned short usPort;
11241139
SString strPassword;

0 commit comments

Comments
 (0)