Skip to content

Commit

Permalink
Updated isAdmin check, added VERY-DANGEROUS-DO-NOT-USE-IT-EVER launch pm
Browse files Browse the repository at this point in the history
  • Loading branch information
Vaker committed Dec 10, 2018
1 parent b6c84b0 commit 1872d59
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 12 deletions.
30 changes: 19 additions & 11 deletions ZomBerry/Addons/scripts/5_Mission/ZomBerry.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,15 @@ class ZomberryBase {
adminList = GetConfig().ConfigureAdmins();
}

bool isAdmin() {
return isAdmin;
bool IsAdmin(string plyUID = "") {
string tmpStr = "";
if (!GetGame().IsMultiplayer() || GetGame().IsClient()) return isAdmin;
if (adminList.Find(plyUID) != -1) return true;

if (GetCLIParam("zbryGiveAdminRightsToEveryone", tmpStr)) {
if (tmpStr == "true") return true;
}
return false;
}

void AdminAuth( CallType type, ref ParamsReadContext ctx, ref PlayerIdentity sender, ref Object target ) {
Expand All @@ -70,7 +77,7 @@ class ZomberryBase {
}

if ( type == CallType.Server ) {
if (adminList.Find(sender.GetId()) != -1) {
if (IsAdmin(sender.GetId())) {
GetRPCManager().SendRPC( "ZomBerryAT", "AdminAuth", new Param2< bool, string >( false, g_zbryVer ), true, sender );
Log( "ZomBerryDbg", "Auth respond to admin " + sender.GetName() + " (" + sender.GetId() + ")");
if (authInfo.param2 != g_zbryVer) {
Expand Down Expand Up @@ -106,16 +113,17 @@ class ZomberryBase {
bool plyAdmin;

if ( type == CallType.Server && GetGame().IsServer() ) {
if (adminList.Find(sender.GetId()) != -1) {
if (IsAdmin(sender.GetId())) {
GetGame().GetPlayers(players);

for (int i = 0; i < players.Count(); ++i) {
player = PlayerBase.Cast(players.Get(i));
plyId = player.GetIdentity().GetPlayerId();
plyName = player.GetIdentity().GetName();
plyAdmin = (adminList.Find(player.GetIdentity().GetId()) != -1);
plyAdmin = IsAdmin(player.GetIdentity().GetId());

if (player.GetItemInHands()) {plyName += (" [" + player.GetItemInHands().GetInventoryItemType().GetName() + "]")}
if (player.GetItemInHands() && !player.GetCommand_Vehicle()) {plyName += (" [" + player.GetItemInHands().GetInventoryItemType().GetName() + "]")}
if (player.GetCommand_Vehicle()) {plyName += (" [" + player.GetCommand_Vehicle().GetTransport().GetDisplayName() + "]")}

plyData = new ZBerryPlayer(plyId, plyName, plyAdmin, player.GetPosition());
playerListS.Insert(plyData);
Expand Down Expand Up @@ -143,7 +151,7 @@ class ZomberryBase {
ref ZBerryCategoryArray catList;

if ( type == CallType.Server && GetGame().IsServer() ) {
if (adminList.Find(sender.GetId()) != -1) {
if (IsAdmin(sender.GetId())) {
catList = GetZomberryCmdAPI().GetList();

GetRPCManager().SendRPC( "ZomBerryAT", "SyncFunctions", new Param1<ref ZBerryCategoryArray> (catList), true, sender );
Expand All @@ -170,7 +178,7 @@ class ZomberryBase {
int targetId = funcParam.param3;
if ( type == CallType.Server && GetGame().IsServer() ) {
PlayerIdentity targetIdent = ZBGetPlayerById(targetId).GetIdentity();
if (adminList.Find(sender.GetId()) != -1) {
if (IsAdmin(sender.GetId())) {
GetGame().GameScript.CallFunctionParams( GetZomberryCmdAPI().GetFunc(funcParam.param1).GetInstance(), funcParam.param1, NULL, funcParam );
if (targetId != funcParam.param2) {
Log( "ZomBerryAdmin", "" + sender.GetName() + " (" + sender.GetId() + ") executed " + funcParam.param1 + " on target " + targetIdent.GetName() + " (" + targetIdent.GetId() + ")");
Expand All @@ -196,7 +204,7 @@ class ZomberryBase {
if ( !ctx.Read( tgtParam ) ) return;

if ( type == CallType.Server && GetGame().IsServer() ) {
if (adminList.Find(sender.GetId()) != -1) {
if (IsAdmin(sender.GetId())) {
if (tgtParam.param4) {
item = ItemBase.Cast(ZBGetPlayerById(tgtParam.param2).GetInventory().CreateInInventory(tgtParam.param1));
item.SetQuantity(item.GetQuantityMax());
Expand Down Expand Up @@ -234,7 +242,7 @@ class ZomberryBase {
PlayerBase adminPly = ZBGetPlayerById(adminId);

if ( type == CallType.Server && GetGame().IsServer() ) {
if (adminList.Find(sender.GetId()) != -1) {
if (IsAdmin(sender.GetId())) {
if (!adminPly.GetCommand_Vehicle()) {
adminPly.SetPosition(reqpos);
Log( "ZomBerryAdmin", "" + sender.GetName() + " (" + sender.GetId() + ") teleported to position " + reqpos.ToString());
Expand Down Expand Up @@ -321,7 +329,7 @@ modded class MissionGameplay {
case ZomberryBase.GetConfig().GetMenuKey(): {
if (GetZomberryMenu().GetLayoutRoot().IsVisible()) { //TODO Fix: Might become NULL
UIMgr.HideScriptedMenu( GetZomberryMenu() );
} else if (!UIMgr.IsMenuOpen(MENU_INGAME) && !UIMgr.IsMenuOpen(MENU_INVENTORY) && !UIMgr.IsMenuOpen(MENU_CHAT_INPUT) && GetZomberryBase().isAdmin()) {
} else if (!UIMgr.IsMenuOpen(MENU_INGAME) && !UIMgr.IsMenuOpen(MENU_INVENTORY) && !UIMgr.IsMenuOpen(MENU_CHAT_INPUT) && GetZomberryBase().IsAdmin()) {
UIMgr.ShowScriptedMenu( GetZomberryMenu() , NULL );
}
break;
Expand Down
2 changes: 1 addition & 1 deletion ZomBerry/Addons/scripts/5_Mission/ZomBerryCommands.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class ZomberryCmdAPI {
}

void Debug() {
ZomberryBase.Log( "ZomBerryCmdAPIDbg", "Logging entire commands list:");
ZomberryBase.Log( "ZomBerryCmdAPIDbg", "Logging entire commands list to script.log");
for (int i = 0; i < m_oCategoryList.Count(); ++i) { //Full list breakdown
ref ZBerryCategory catEntry = m_oCategoryList.Get(i);
catEntry.Debug();
Expand Down
7 changes: 7 additions & 0 deletions ZomBerry/Addons/scripts/5_Mission/ZomBerryConfig.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,13 @@ class ZomberryConfig {
ref TStringArray adminList = new TStringArray;
string temp_path;

if (GetCLIParam("zbryGiveAdminRightsToEveryone", temp_path)) {
if (temp_path == "true") {
ZomberryBase.Log( "ZomBerryConfig", "WARN: WARNING! EVERY PLAYER JOINED TO THIS SERVER WILL HAVE FULL ADMIN RIGHTS DUE TO '-zbryGiveAdminRightsToEveryone=true' LAUNCH PARAMETER!" );
return {};
}
}

if (!GetCLIParam("zbryDir", temp_path)) {
temp_path = "$CurrentDir:\\" + g_Game.GetMissionPath();
temp_path.Replace("mission.c", "");
Expand Down

0 comments on commit 1872d59

Please sign in to comment.