Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add set/getPlayerScriptDebugLevel #826

Merged
merged 11 commits into from
Sep 2, 2019
2 changes: 2 additions & 0 deletions Server/mods/deathmatch/acl.xml
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@
<right name="function.setServerConfigSetting" access="false" />
<right name="function.updateResourceACLRequest" access="false" />
<right name="function.shutdown" access="false" />
<right name="function.setPlayerScriptDebugLevel" access="false" />
</acl>
<acl name="Moderator">
<right name="general.ModifyOtherObjects" access="false" />
Expand Down Expand Up @@ -229,6 +230,7 @@
<right name="function.setServerConfigSetting" access="true" />
<right name="function.updateResourceACLRequest" access="true" />
<right name="function.shutdown" access="true" />
<right name="function.setPlayerScriptDebugLevel" access="true" />
</acl>
<acl name="RPC">
<right name="function.callRemote" access="true" />
Expand Down
38 changes: 33 additions & 5 deletions Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1864,6 +1864,14 @@ const SString& CStaticFunctionDefinitions::GetPlayerVersion(CPlayer* pPlayer)
return pPlayer->GetPlayerVersion();
}

bool CStaticFunctionDefinitions::GetPlayerDebuggerLevel(CPlayer* pPlayer, unsigned int& uiLevel)
knitz12 marked this conversation as resolved.
Show resolved Hide resolved
{
assert(pPlayer);

uiLevel = pPlayer->GetScriptDebugLevel();
return true;
}

bool CStaticFunctionDefinitions::SetPlayerName(CElement* pElement, const char* szName)
{
assert(pElement);
Expand Down Expand Up @@ -3050,8 +3058,6 @@ bool CStaticFunctionDefinitions::TakePlayerScreenShot(CElement* pElement, uint u

bool CStaticFunctionDefinitions::SetPlayerDebuggerVisible(CElement* pElement, bool bVisible)
{
// * Not used by scripts

assert(pElement);
RUN_CHILDREN(SetPlayerDebuggerVisible(*iter, bVisible))

Expand All @@ -3068,6 +3074,28 @@ bool CStaticFunctionDefinitions::SetPlayerDebuggerVisible(CElement* pElement, bo
return false;
}

bool CStaticFunctionDefinitions::SetPlayerDebuggerLevel(CElement* pElement, unsigned int uiLevel)
knitz12 marked this conversation as resolved.
Show resolved Hide resolved
{
assert(pElement);

if (uiLevel >= 0 && uiLevel <= 3)
{
RUN_CHILDREN(SetPlayerDebuggerLevel(*iter, uiLevel));
knitz12 marked this conversation as resolved.
Show resolved Hide resolved

if (IS_PLAYER(pElement))
{
CPlayer* pPlayer = static_cast<CPlayer*>(pElement);

if (pPlayer->SetScriptDebugLevel(uiLevel))
{
return SetPlayerDebuggerVisible(pElement, uiLevel != 0);
}
}
}

return false;
}

bool CStaticFunctionDefinitions::SetPlayerWantedLevel(CElement* pElement, unsigned int uiLevel)
{
assert(pElement);
Expand Down Expand Up @@ -11234,7 +11262,7 @@ CBan* CStaticFunctionDefinitions::BanPlayer(CPlayer* pPlayer, bool bIP, bool bUs
// Call the event
CLuaArguments Arguments;
Arguments.PushBan(pBan);

patrikjuvonen marked this conversation as resolved.
Show resolved Hide resolved
if (pResponsible)
Arguments.PushElement(pResponsible);

Expand Down Expand Up @@ -11407,10 +11435,10 @@ CBan* CStaticFunctionDefinitions::AddBan(SString strIP, SString strUsername, SSt
// Call the event
CLuaArguments Arguments;
Arguments.PushBan(pBan);

patrikjuvonen marked this conversation as resolved.
Show resolved Hide resolved
if (pResponsible)
Arguments.PushElement(pResponsible);

patrikjuvonen marked this conversation as resolved.
Show resolved Hide resolved
// A script can call kickPlayer in the onPlayerBan event, which would
// show him the 'kicked' message instead of our 'banned' message.
const bool bLeavingServer = pPlayer->IsLeavingServer();
Expand Down
2 changes: 2 additions & 0 deletions Server/mods/deathmatch/logic/CStaticFunctionDefinitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ class CStaticFunctionDefinitions
static bool GetPlayerIP(CElement* pElement, SString& strOutIP);
static CAccount* GetPlayerAccount(CElement* pElement);
static const SString& GetPlayerVersion(CPlayer* pPlayer);
static bool GetPlayerDebuggerLevel(CPlayer* pPlayer, unsigned int& uiLevel);
knitz12 marked this conversation as resolved.
Show resolved Hide resolved

// Player set functions
static bool SetPlayerMoney(CElement* pElement, long lMoney, bool bInstant);
Expand All @@ -132,6 +133,7 @@ class CStaticFunctionDefinitions
static bool TakePlayerMoney(CElement* pElement, long lMoney);
static bool ShowPlayerHudComponent(CElement* pElement, eHudComponent component, bool bShow);
static bool SetPlayerDebuggerVisible(CElement* pElement, bool bVisible);
static bool SetPlayerDebuggerLevel(CElement* pElement, unsigned int uiLevel);
knitz12 marked this conversation as resolved.
Show resolved Hide resolved
static bool SetPlayerWantedLevel(CElement* pElement, unsigned int iLevel);
static bool ForcePlayerMap(CElement* pElement, bool bVisible);
static bool SetPlayerNametagText(CElement* pElement, const char* szText);
Expand Down
76 changes: 76 additions & 0 deletions Server/mods/deathmatch/logic/luadefs/CLuaPlayerDefs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ void CLuaPlayerDefs::LoadFunctions()
{"getPlayerACInfo", GetPlayerACInfo},
{"resendPlayerModInfo", ResendPlayerModInfo},
{"resendPlayerACInfo", ResendPlayerACInfo},
{"getPlayerScriptDebugLevel", GetPlayerScriptDebugLevel},

// Player set funcs
{"setPlayerMoney", SetPlayerMoney},
Expand All @@ -63,6 +64,7 @@ void CLuaPlayerDefs::LoadFunctions()
{"setPlayerName", SetPlayerName},
{"detonateSatchels", DetonateSatchels},
{"takePlayerScreenShot", TakePlayerScreenShot},
{"setPlayerScriptDebugLevel", SetPlayerScriptDebugLevel},

// All seeing eye
{"getPlayerAnnounceValue", GetPlayerAnnounceValue},
Expand Down Expand Up @@ -151,6 +153,7 @@ void CLuaPlayerDefs::AddClass(lua_State* luaVM)
lua_classfunction(luaVM, "setCameraMatrix", "setCameraMatrix");
lua_classfunction(luaVM, "setCameraInterior", "setCameraInterior");
lua_classfunction(luaVM, "setCameraTarget", "setCameraTarget");
lua_classfunction(luaVM, "setScriptDebugLevel", "setPlayerScriptDebugLevel");

lua_classfunction(luaVM, "isMapForced", "isPlayerMapForced");
lua_classfunction(luaVM, "isMuted", "isPlayerMuted");
Expand All @@ -173,6 +176,7 @@ void CLuaPlayerDefs::AddClass(lua_State* luaVM)
lua_classfunction(luaVM, "getCameraInterior", "getCameraInterior");
lua_classfunction(luaVM, "getCameraMatrix", "getCameraMatrix");
lua_classfunction(luaVM, "getCameraTarget", "getCameraTarget");
lua_classfunction(luaVM, "getScriptDebugLevel", "getPlayerScriptDebugLevel");

lua_classvariable(luaVM, "account", NULL, "getPlayerAccount");
lua_classvariable(luaVM, "cameraInterior", "setCameraInterior", "getCameraInterior");
Expand All @@ -195,6 +199,7 @@ void CLuaPlayerDefs::AddClass(lua_State* luaVM)
lua_classvariable(luaVM, "mapForced", "forcePlayerMap", "isPlayerMapForced");
lua_classvariable(luaVM, "nametagText", "setPlayerNametagText", "getPlayerNametagText");
lua_classvariable(luaVM, "nametagShowing", "setPlayerNametagShowing", "isPlayerNametagShowing");
lua_classvariable(luaVM, "scriptDebugLevel", "setPlayerScriptDebugLevel", "getPlayerScriptDebugLevel");
// lua_classvariable ( luaVM, "nametagColor", "setPlayerNametagColor", "getPlayerNametagColor", CLuaPlayerDefs::SetPlayerNametagColor,
// OOP_GetPlayerNametagColor ); lua_classvariable ( luaVM, "announceValue", "setPlayerAnnounceValue", "getPlayerAnnounceValue",
// CLuaPlayerDefs::SetPlayerAnnounceValue, OOP_GetPlayerAnnounceValue ); // .announceValue[key]=value lua_classvariable ( luaVM, "hudComponent",
Expand Down Expand Up @@ -941,6 +946,52 @@ int CLuaPlayerDefs::TakePlayerScreenShot(lua_State* luaVM)
return 1;
}

int CLuaPlayerDefs::SetPlayerScriptDebugLevel(lua_State* luaVM)
{
CElement* pElement;
unsigned int uiMode;
bool bHideDebugger = false;

CScriptArgReader argStream(luaVM);
argStream.ReadUserData(pElement);
if (argStream.NextIsBool())
{
bool bTemp;

argStream.ReadBool(bTemp);

if (bTemp)
{
argStream.SetCustomError("You can only pass false to hide the debug window or a level (0-3)");
}
else
bHideDebugger = true;
}
else
{
argStream.ReadNumber(uiMode);

if (uiMode < 0 || uiMode > 3)
{
argStream.SetCustomError("Invalid level (0-3)");
}
}

if (!argStream.HasErrors())
knitz12 marked this conversation as resolved.
Show resolved Hide resolved
{
if (CStaticFunctionDefinitions::SetPlayerDebuggerLevel(pElement, bHideDebugger ? 0 : uiMode))
knitz12 marked this conversation as resolved.
Show resolved Hide resolved
{
lua_pushboolean(luaVM, true);
return 1;
}
}
else
m_pScriptDebugging->LogCustom(luaVM, argStream.GetFullErrorMessage());

lua_pushboolean(luaVM, false);
return 1;
}

int CLuaPlayerDefs::SetPlayerWantedLevel(lua_State* luaVM)
{
CElement* pElement;
Expand Down Expand Up @@ -1431,6 +1482,31 @@ int CLuaPlayerDefs::ResendPlayerACInfo(lua_State* luaVM)
return 1;
}

int CLuaPlayerDefs::GetPlayerScriptDebugLevel(lua_State* luaVM)
{
// int getPlayerScriptDebugLevel ( player thePlayer )
CPlayer* pPlayer;

CScriptArgReader argStream(luaVM);
argStream.ReadUserData(pPlayer);

if (!argStream.HasErrors())
knitz12 marked this conversation as resolved.
Show resolved Hide resolved
{
unsigned int uiLevel;

if (CStaticFunctionDefinitions::GetPlayerDebuggerLevel(pPlayer, uiLevel))
knitz12 marked this conversation as resolved.
Show resolved Hide resolved
{
lua_pushnumber(luaVM, uiLevel);
return 1;
}
}
else
m_pScriptDebugging->LogCustom(luaVM, argStream.GetFullErrorMessage());

lua_pushboolean(luaVM, false);
return 1;
}

int CLuaPlayerDefs::BindKey(lua_State* luaVM)
{
CPlayer* pPlayer;
Expand Down
4 changes: 3 additions & 1 deletion Server/mods/deathmatch/logic/luadefs/CLuaPlayerDefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class CLuaPlayerDefs : public CLuaDefs
LUA_DECLARE(GetPlayerAccount);
LUA_DECLARE(GetPlayerVersion);
LUA_DECLARE(GetPlayerACInfo);
LUA_DECLARE(GetPlayerScriptDebugLevel);

// Player set functions
LUA_DECLARE(SetPlayerMoney);
Expand All @@ -64,6 +65,7 @@ class CLuaPlayerDefs : public CLuaDefs
LUA_DECLARE(SetPlayerName);
LUA_DECLARE(DetonateSatchels);
LUA_DECLARE(TakePlayerScreenShot);
LUA_DECLARE(SetPlayerScriptDebugLevel);

// All seeing eye
LUA_DECLARE(GetPlayerAnnounceValue);
Expand Down Expand Up @@ -99,4 +101,4 @@ class CLuaPlayerDefs : public CLuaDefs
// Admin funcs
LUA_DECLARE(KickPlayer);
LUA_DECLARE(BanPlayer);
};
};
patrikjuvonen marked this conversation as resolved.
Show resolved Hide resolved