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
4 changes: 4 additions & 0 deletions Server/mods/deathmatch/acl.xml
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@
<right name="function.setServerConfigSetting" access="false" />
<right name="function.updateResourceACLRequest" access="false" />
<right name="function.shutdown" access="false" />
<right name="function.setPlayerDebugViewActive" access="false" />
<right name="function.setPlayerDebugViewMode" access="false" />
</acl>
<acl name="Moderator">
<right name="general.ModifyOtherObjects" access="false" />
Expand Down Expand Up @@ -229,6 +231,8 @@
<right name="function.setServerConfigSetting" access="true" />
<right name="function.updateResourceACLRequest" access="true" />
<right name="function.shutdown" access="true" />
<right name="function.setPlayerDebugViewActive" access="true" />
<right name="function.setPlayerDebugViewMode" access="true" />
</acl>
<acl name="RPC">
<right name="function.callRemote" access="true" />
Expand Down
27 changes: 22 additions & 5 deletions Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3050,8 +3050,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 +3066,25 @@ bool CStaticFunctionDefinitions::SetPlayerDebuggerVisible(CElement* pElement, bo
return false;
}

bool CStaticFunctionDefinitions::SetPlayerDebuggerMode(CElement* pElement, unsigned int iMode)
{
assert(pElement);

if (iMode >= 0 && iMode <= 3)
{
RUN_CHILDREN(SetPlayerDebuggerMode(*iter, iMode));

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

return pPlayer->SetScriptDebugLevel(iMode);
}
}

return false;
}

bool CStaticFunctionDefinitions::SetPlayerWantedLevel(CElement* pElement, unsigned int uiLevel)
{
assert(pElement);
Expand Down Expand Up @@ -11234,7 +11251,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 +11424,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
1 change: 1 addition & 0 deletions Server/mods/deathmatch/logic/CStaticFunctionDefinitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,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 SetPlayerDebuggerMode(CElement* pElement, unsigned int iMode);
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
63 changes: 60 additions & 3 deletions Server/mods/deathmatch/logic/luadefs/CLuaPlayerDefs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ void CLuaPlayerDefs::LoadFunctions()
{"setPlayerName", SetPlayerName},
{"detonateSatchels", DetonateSatchels},
{"takePlayerScreenShot", TakePlayerScreenShot},
{"setPlayerDebugViewActive", SetPlayerDebugViewActive},
{"setPlayerDebugViewMode", SetPlayerDebugViewMode},

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

lua_classfunction(luaVM, "isMapForced", "isPlayerMapForced");
lua_classfunction(luaVM, "isMuted", "isPlayerMuted");
Expand Down Expand Up @@ -231,7 +235,7 @@ int CLuaPlayerDefs::CanPlayerUseFunction(lua_State* luaVM)
int CLuaPlayerDefs::GetPlayerName(lua_State* luaVM)
{
// string getPlayerName ( player thePlayer )
CElement* pElement; // player or console
CElement* pElement; // player or console
knitz12 marked this conversation as resolved.
Show resolved Hide resolved

CScriptArgReader argStream(luaVM);
argStream.ReadUserData(pElement);
Expand Down Expand Up @@ -260,7 +264,7 @@ int CLuaPlayerDefs::GetPlayerName(lua_State* luaVM)
int CLuaPlayerDefs::GetPlayerIP(lua_State* luaVM)
{
// string getPlayerIP ( player thePlayer )
CElement* pElement; // player or console
CElement* pElement; // player or console
knitz12 marked this conversation as resolved.
Show resolved Hide resolved

CScriptArgReader argStream(luaVM);
argStream.ReadUserData(pElement);
Expand Down Expand Up @@ -310,7 +314,7 @@ int CLuaPlayerDefs::GetPlayerVersion(lua_State* luaVM)
int CLuaPlayerDefs::GetPlayerAccount(lua_State* luaVM)
{
// account getPlayerAccount ( player thePlayer )
CElement* pElement; // player or console
CElement* pElement; // player or console
knitz12 marked this conversation as resolved.
Show resolved Hide resolved

CScriptArgReader argStream(luaVM);
argStream.ReadUserData(pElement);
Expand Down Expand Up @@ -941,6 +945,59 @@ int CLuaPlayerDefs::TakePlayerScreenShot(lua_State* luaVM)
return 1;
}

int CLuaPlayerDefs::SetPlayerDebugViewActive(lua_State* luaVM)
{
CElement* pElement;
bool bActive;

CScriptArgReader argStream(luaVM);
argStream.ReadUserData(pElement);
argStream.ReadBool(bActive);

if (!argStream.HasErrors())
{
if (CStaticFunctionDefinitions::SetPlayerDebuggerVisible(pElement, bActive))
{
lua_pushboolean(luaVM, true);
return 1;
}
}
else
m_pScriptDebugging->LogCustom(luaVM, argStream.GetFullErrorMessage());

lua_pushboolean(luaVM, false);
return 1;
}

int CLuaPlayerDefs::SetPlayerDebugViewMode(lua_State* luaVM)
{
CElement* pElement;
unsigned int iMode;
knitz12 marked this conversation as resolved.
Show resolved Hide resolved

CScriptArgReader argStream(luaVM);
argStream.ReadUserData(pElement);
argStream.ReadNumber(iMode);

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

if (!argStream.HasErrors())
knitz12 marked this conversation as resolved.
Show resolved Hide resolved
{
if (CStaticFunctionDefinitions::SetPlayerDebuggerMode(pElement, iMode))
{
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
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 @@ -64,6 +64,8 @@ class CLuaPlayerDefs : public CLuaDefs
LUA_DECLARE(SetPlayerName);
LUA_DECLARE(DetonateSatchels);
LUA_DECLARE(TakePlayerScreenShot);
LUA_DECLARE(SetPlayerDebugViewActive);
LUA_DECLARE(SetPlayerDebugViewMode);

// 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