From 4e797db10544de96d29d464d2a8015d1fba05393 Mon Sep 17 00:00:00 2001 From: marqdevx Date: Fri, 1 Mar 2024 22:59:32 +0100 Subject: [PATCH] Re-add new features after rebase --- src/adminsystem.cpp | 816 ++++++++++++++----------------- src/adminsystem.h | 1 + src/commands.cpp | 284 ++++++++--- src/cs2_sdk/entity/cbaseentity.h | 1 + src/cs2fixes.cpp | 2 +- 5 files changed, 567 insertions(+), 537 deletions(-) diff --git a/src/adminsystem.cpp b/src/adminsystem.cpp index 37b8da9d..254d8e7b 100644 --- a/src/adminsystem.cpp +++ b/src/adminsystem.cpp @@ -106,33 +106,62 @@ CON_COMMAND_F(c_reload_admins, "Reload admin config", FCVAR_SPONLY | FCVAR_LINKE Message("Admins reloaded\n"); } -CON_COMMAND_F(c_reload_infractions, "Reload infractions file", FCVAR_SPONLY | FCVAR_LINKED_CONCOMMAND) +CON_COMMAND_CHAT(rcon, "fake rcon") { - if (!g_pAdminSystem->LoadInfractions()) + if (!g_bEnableRcon) + return; + + if (!player) return; - for (int i = 0; i < gpGlobals->maxClients; i++) + int iCommandPlayer = player->GetPlayerSlot(); + + ZEPlayer *pPlayer = g_playerManager->GetPlayer(iCommandPlayer); + + if (!pPlayer->IsAdminFlagSet(ADMFLAG_BAN)) { - ZEPlayer* pPlayer = g_playerManager->GetPlayer(i); + ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX"You don't have access to this command."); + return; + } - if (!pPlayer || pPlayer->IsFakeClient()) - continue; + char buf[MAX_PATH]; + V_snprintf(buf, sizeof(buf), ""); + char last_arg[MAX_PATH]; + V_snprintf(last_arg, sizeof(last_arg), ""); - pPlayer->CheckInfractions(); + for (int i = 1; i < args.ArgC(); i++){ + V_snprintf(last_arg, sizeof(last_arg), "%s", buf); + V_snprintf(buf, sizeof(buf), "%s %s",last_arg, args[i]); } - Message("Infractions reloaded\n"); + ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX"Command sent: \04%s", buf); + g_pEngineServer2->ServerCommand(buf); } -CON_COMMAND_CHAT_FLAGS(ban, " - ban a player", ADMFLAG_BAN) +CON_COMMAND_CHAT(ban, "ban a player") { + if(!g_bEnableBan) + return; + + if (!player) + return; + + int iCommandPlayer = player->GetPlayerSlot(); + + ZEPlayer *pPlayer = g_playerManager->GetPlayer(iCommandPlayer); + + if (!pPlayer->IsAdminFlagSet(ADMFLAG_BAN)) + { + ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX"You don't have access to this command."); + return; + } + if (args.ArgC() < 3) { - ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX "Usage: !ban "); + ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX"Usage: !ban "); return; } - int iCommandPlayer = player ? player->GetPlayerSlot() : -1; int iNumClients = 0; int pSlot[MAXPLAYERS]; @@ -148,14 +177,16 @@ CON_COMMAND_CHAT_FLAGS(ban, " - ban a player", ADM return; } - int iDuration = V_StringToInt32(args[2], -1); + char* end; + int iDuration = strtol(args[2], &end, 10); - if (iDuration == -1) + if (*end) { ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX"Invalid duration."); return; } - CCSPlayerController* pTarget = CCSPlayerController::FromSlot(pSlot[0]); + + CBasePlayerController* pTarget = (CBasePlayerController*)g_pEntitySystem->GetBaseEntity((CEntityIndex)(pSlot[0] + 1)); if (!pTarget) return; @@ -165,168 +196,74 @@ CON_COMMAND_CHAT_FLAGS(ban, " - ban a player", ADM if (pTargetPlayer->IsFakeClient()) return; - if (!pTargetPlayer->IsAuthenticated()) - { - ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX "%s is not yet authenticated, consider kicking instead or please wait a moment and try again.", pTarget->GetPlayerName()); - return; - } - CInfractionBase *infraction = new CBanInfraction(iDuration, pTargetPlayer->GetSteamId64()); g_pAdminSystem->AddInfraction(infraction); infraction->ApplyInfraction(pTargetPlayer); g_pAdminSystem->SaveInfractions(); - const char *pszCommandPlayerName = player ? player->GetPlayerName() : "Console"; - - ClientPrintAll(HUD_PRINTTALK, CHAT_PREFIX ADMIN_PREFIX "banned %s for %i minutes.", pszCommandPlayerName, pTarget->GetPlayerName(), iDuration); - - if (iDuration > 0) - { - char szAction[64]; - V_snprintf(szAction, sizeof(szAction), " for %i minutes", iDuration); - PrintSingleAdminAction(pszCommandPlayerName, pTarget->GetPlayerName(), "banned", szAction); - } - else - { - PrintSingleAdminAction(pszCommandPlayerName, pTarget->GetPlayerName(), "permanently banned"); - } + ClientPrintAll(HUD_PRINTTALK, CHAT_PREFIX ADMIN_PREFIX "banned %s for %i minutes.", player->GetPlayerName(), pTarget->GetPlayerName(), iDuration); } -CON_COMMAND_CHAT_FLAGS(mute, " - mutes a player", ADMFLAG_CHAT) +CON_COMMAND_CHAT(unban, "unbans a player") { - if (args.ArgC() < 3) - { - ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX "Usage: !mute "); + if(!g_bEnableBan) return; - } - - int iCommandPlayer = player ? player->GetPlayerSlot() : -1; - int iNumClients = 0; - int pSlot[MAXPLAYERS]; - - ETargetType nType = g_playerManager->TargetPlayerString(iCommandPlayer, args[1], iNumClients, pSlot); - if (!iNumClients) - { - ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX "Target not found."); + if (!player) return; - } - int iDuration = V_StringToInt32(args[2], -1); + int iCommandPlayer = player->GetPlayerSlot(); + + ZEPlayer *pPlayer = g_playerManager->GetPlayer(iCommandPlayer); - if (iDuration < 0) + if (!pPlayer->IsAdminFlagSet(ADMFLAG_BAN)) { - ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX "Invalid duration."); + ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX"You don't have access to this command."); return; } - if (iDuration == 0 && nType >= ETargetType::ALL) + if (args.ArgC() < 2) { - ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX "You may only permanently mute individuals."); + ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX "Usage: !unban "); return; } + + uint64 targetSteamID = V_StringToUint64(args[1], -1); - const char *pszCommandPlayerName = player ? player->GetPlayerName() : "Console"; - - char szAction[64]; - V_snprintf(szAction, sizeof(szAction), " for %i minutes", iDuration); - - for (int i = 0; i < iNumClients; i++) - { - CCSPlayerController* pTarget = CCSPlayerController::FromSlot(pSlot[i]); - - if (!pTarget) - continue; - - ZEPlayer* pTargetPlayer = g_playerManager->GetPlayer(pSlot[i]); - - if (pTargetPlayer->IsFakeClient()) - continue; - - if (!pTargetPlayer->IsAuthenticated()) - { - ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX "%s is not yet authenticated, please wait a moment and try again.", pTarget->GetPlayerName()); - continue; - } - - CInfractionBase* infraction = new CMuteInfraction(iDuration, pTargetPlayer->GetSteamId64()); - - // We're overwriting the infraction, so remove the previous one first - g_pAdminSystem->FindAndRemoveInfraction(pTargetPlayer, CInfractionBase::Mute); - g_pAdminSystem->AddInfraction(infraction); - infraction->ApplyInfraction(pTargetPlayer); - g_pAdminSystem->SaveInfractions(); - - if (iDuration > 0) - PrintSingleAdminAction(pszCommandPlayerName, pTarget->GetPlayerName(), "muted", szAction); - else - PrintSingleAdminAction(pszCommandPlayerName, pTarget->GetPlayerName(), "permanently muted"); + if(g_pAdminSystem->FindAndRemoveInfraction(targetSteamID, CInfractionBase::Ban)){ + ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX "SeeamID %llu unbanned.", targetSteamID); + }else{ + ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX "SeeamID %llu is not banned.", targetSteamID); } - - g_pAdminSystem->SaveInfractions(); - - PrintMultiAdminAction(nType, pszCommandPlayerName, "muted", szAction); + + return; } -CON_COMMAND_CHAT_FLAGS(unmute, " - unmutes a player", ADMFLAG_CHAT) +CON_COMMAND_CHAT(gag, "gag a player") { - if (args.ArgC() < 2) - { - ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX "Usage: !unmute "); + if(!g_bEnableGag) return; - } - - int iCommandPlayer = player ? player->GetPlayerSlot() : -1; - int iNumClients = 0; - int pSlot[MAXPLAYERS]; - ETargetType nType = g_playerManager->TargetPlayerString(iCommandPlayer, args[1], iNumClients, pSlot); - - if (!iNumClients) - { - ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX "Target not found."); + if (!player) return; - } - - const char *pszCommandPlayerName = player ? player->GetPlayerName() : "Console"; - - for (int i = 0; i < iNumClients; i++) - { - CCSPlayerController* pTarget = CCSPlayerController::FromSlot(pSlot[i]); - if (!pTarget) - continue; - - ZEPlayer *pTargetPlayer = g_playerManager->GetPlayer(pSlot[i]); - - if (pTargetPlayer->IsFakeClient()) - continue; + int iCommandPlayer = player->GetPlayerSlot(); - if (!g_pAdminSystem->FindAndRemoveInfraction(pTargetPlayer, CInfractionBase::Mute) && nType < ETargetType::ALL) - { - ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX "%s is not muted.", pTarget->GetPlayerName()); - continue; - } + ZEPlayer *pPlayer = g_playerManager->GetPlayer(player->GetPlayerSlot()); - if (nType < ETargetType::ALL) - PrintSingleAdminAction(pszCommandPlayerName, pTarget->GetPlayerName(), "unmuted"); + if (!pPlayer->IsAdminFlagSet(ADMFLAG_BAN)) + { + ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX "You don't have access to this command."); + return; } - g_pAdminSystem->SaveInfractions(); - - PrintMultiAdminAction(nType, pszCommandPlayerName, "unmuted"); -} - -CON_COMMAND_CHAT_FLAGS(gag, " - gag a player", ADMFLAG_CHAT) -{ if (args.ArgC() < 3) { ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX "Usage: !gag "); return; } - int iCommandPlayer = player ? player->GetPlayerSlot() : -1; int iNumClients = 0; int pSlot[MAXPLAYERS]; @@ -338,28 +275,18 @@ CON_COMMAND_CHAT_FLAGS(gag, " - gag a player", AD return; } - int iDuration = V_StringToInt32(args[2], -1); + char *end; + int iDuration = strtol(args[2], &end, 10); - if (iDuration < 0) + if (*end) { ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX "Invalid duration."); return; } - if (iDuration == 0 && nType >= ETargetType::ALL) - { - ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX "You may only permanently gag individuals."); - return; - } - - const char *pszCommandPlayerName = player ? player->GetPlayerName() : "Console"; - - char szAction[64]; - V_snprintf(szAction, sizeof(szAction), " for %i minutes", iDuration); - for (int i = 0; i < iNumClients; i++) { - CCSPlayerController* pTarget = CCSPlayerController::FromSlot(pSlot[i]); + CBasePlayerController *pTarget = (CBasePlayerController *)g_pEntitySystem->GetBaseEntity((CEntityIndex)(pSlot[i] + 1)); if (!pTarget) continue; @@ -369,12 +296,6 @@ CON_COMMAND_CHAT_FLAGS(gag, " - gag a player", AD if (pTargetPlayer->IsFakeClient()) continue; - if (!pTargetPlayer->IsAuthenticated()) - { - ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX "%s is not yet authenticated, please wait a moment and try again.", pTarget->GetPlayerName()); - continue; - } - CInfractionBase *infraction = new CGagInfraction(iDuration, pTargetPlayer->GetSteamId64()); // We're overwriting the infraction, so remove the previous one first @@ -382,29 +303,50 @@ CON_COMMAND_CHAT_FLAGS(gag, " - gag a player", AD g_pAdminSystem->AddInfraction(infraction); infraction->ApplyInfraction(pTargetPlayer); - if (nType >= ETargetType::ALL) - continue; - - if (iDuration > 0) - PrintSingleAdminAction(pszCommandPlayerName, pTarget->GetPlayerName(), "gagged", szAction); - else - PrintSingleAdminAction(pszCommandPlayerName, pTarget->GetPlayerName(), "permanently gagged"); + if (nType < ETargetType::ALL) + ClientPrintAll(HUD_PRINTTALK, CHAT_PREFIX ADMIN_PREFIX "gagged %s for %i minutes.", player->GetPlayerName(), pTarget->GetPlayerName(), iDuration); } g_pAdminSystem->SaveInfractions(); - PrintMultiAdminAction(nType, pszCommandPlayerName, "gagged", szAction); + switch (nType) + { + case ETargetType::ALL: + ClientPrintAll(HUD_PRINTTALK, CHAT_PREFIX ADMIN_PREFIX "gagged everyone for %i minutes.", player->GetPlayerName(), iDuration); + break; + case ETargetType::T: + ClientPrintAll(HUD_PRINTTALK, CHAT_PREFIX ADMIN_PREFIX "gagged terrorists for %i minutes.", player->GetPlayerName(), iDuration); + break; + case ETargetType::CT: + ClientPrintAll(HUD_PRINTTALK, CHAT_PREFIX ADMIN_PREFIX "gagged counter-terrorists for %i minutes.", player->GetPlayerName(), iDuration); + break; + } } -CON_COMMAND_CHAT_FLAGS(ungag, " - ungags a player", ADMFLAG_CHAT) +CON_COMMAND_CHAT(ungag, "ungags a player") { + if(!g_bEnableGag) + return; + + if (!player) + return; + + int iCommandPlayer = player->GetPlayerSlot(); + + ZEPlayer *pPlayer = g_playerManager->GetPlayer(player->GetPlayerSlot()); + + if (!pPlayer->IsAdminFlagSet(ADMFLAG_UNBAN)) + { + ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX "You don't have access to this command."); + return; + } + if (args.ArgC() < 2) { ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX "Usage: !ungag "); return; } - int iCommandPlayer = player ? player->GetPlayerSlot() : -1; int iNumClients = 0; int pSlot[MAXPLAYERS]; @@ -416,11 +358,9 @@ CON_COMMAND_CHAT_FLAGS(ungag, " - ungags a player", ADMFLAG_CHAT) return; } - const char *pszCommandPlayerName = player ? player->GetPlayerName() : "Console"; - for (int i = 0; i < iNumClients; i++) { - CCSPlayerController* pTarget = CCSPlayerController::FromSlot(pSlot[i]); + CBasePlayerController *pTarget = (CBasePlayerController *)g_pEntitySystem->GetBaseEntity((CEntityIndex)(pSlot[i] + 1)); if (!pTarget) continue; @@ -437,23 +377,49 @@ CON_COMMAND_CHAT_FLAGS(ungag, " - ungags a player", ADMFLAG_CHAT) } if (nType < ETargetType::ALL) - PrintSingleAdminAction(pszCommandPlayerName, pTarget->GetPlayerName(), "ungagged"); + ClientPrintAll(HUD_PRINTTALK, CHAT_PREFIX ADMIN_PREFIX "ungagged %s.", player->GetPlayerName(), pTarget->GetPlayerName()); } g_pAdminSystem->SaveInfractions(); - PrintMultiAdminAction(nType, pszCommandPlayerName, "ungagged"); + switch (nType) + { + case ETargetType::ALL: + ClientPrintAll(HUD_PRINTTALK, CHAT_PREFIX ADMIN_PREFIX "ungagged everyone.", player->GetPlayerName()); + break; + case ETargetType::T: + ClientPrintAll(HUD_PRINTTALK, CHAT_PREFIX ADMIN_PREFIX "ungagged terrorists.", player->GetPlayerName()); + break; + case ETargetType::CT: + ClientPrintAll(HUD_PRINTTALK, CHAT_PREFIX ADMIN_PREFIX "ungagged counter-terrorists.", player->GetPlayerName()); + break; + } } -CON_COMMAND_CHAT_FLAGS(kick, " - kick a player", ADMFLAG_KICK) +CON_COMMAND_CHAT(kick, "kick a player") { + if(!g_bEnableKick) + return; + + if (!player) + return; + + int iCommandPlayer = player->GetPlayerSlot(); + + ZEPlayer* pPlayer = g_playerManager->GetPlayer(player->GetPlayerSlot()); + + if (!pPlayer->IsAdminFlagSet(ADMFLAG_KICK)) + { + ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX"You don't have access to this command."); + return; + } + if (args.ArgC() < 2) { - ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX "Usage: !kick "); + ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX"Usage: !kick "); return; } - int iCommandPlayer = player ? player->GetPlayerSlot() : -1; int iNumClients = 0; int pSlot[MAXPLAYERS]; @@ -465,11 +431,9 @@ CON_COMMAND_CHAT_FLAGS(kick, " - kick a player", ADMFLAG_KICK) return; } - const char *pszCommandPlayerName = player ? player->GetPlayerName() : "Console"; - for (int i = 0; i < iNumClients; i++) { - CCSPlayerController* pTarget = CCSPlayerController::FromSlot(pSlot[i]); + CBasePlayerController* pTarget = (CBasePlayerController*)g_pEntitySystem->GetBaseEntity((CEntityIndex)(pSlot[i] + 1)); if (!pTarget) continue; @@ -478,57 +442,34 @@ CON_COMMAND_CHAT_FLAGS(kick, " - kick a player", ADMFLAG_KICK) g_pEngineServer2->DisconnectClient(pTargetPlayer->GetPlayerSlot(), NETWORK_DISCONNECT_KICKED); - PrintSingleAdminAction(pszCommandPlayerName, pTarget->GetPlayerName(), "kicked"); + ClientPrintAll(HUD_PRINTTALK, CHAT_PREFIX ADMIN_PREFIX "kicked %s.", player->GetPlayerName(), pTarget->GetPlayerName()); } } -CON_COMMAND_CHAT_FLAGS(slay, " - slay a player", ADMFLAG_SLAY) +CON_COMMAND_CHAT(slay, "slay a player") { - if (args.ArgC() < 2) - { - ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX "Usage: !slay "); + if(!g_bEnableSlay) return; - } - - int iCommandPlayer = player ? player->GetPlayerSlot() : -1; - int iNumClients = 0; - int pSlots[MAXPLAYERS]; - - ETargetType nType = g_playerManager->TargetPlayerString(iCommandPlayer, args[1], iNumClients, pSlots); - if (!iNumClients) - { - ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX"Target not found."); + if (!player) return; - } - - const char *pszCommandPlayerName = player ? player->GetPlayerName() : "Console"; - - for (int i = 0; i < iNumClients; i++) - { - CCSPlayerController* pTarget = CCSPlayerController::FromSlot(pSlots[i]); - if (!pTarget) - continue; + int iCommandPlayer = player->GetPlayerSlot(); - pTarget->GetPawn()->CommitSuicide(false, true); + ZEPlayer *pPlayer = g_playerManager->GetPlayer(player->GetPlayerSlot()); - if (nType < ETargetType::ALL) - PrintSingleAdminAction(pszCommandPlayerName, pTarget->GetPlayerName(), "slayed"); + if (!pPlayer->IsAdminFlagSet(ADMFLAG_SLAY)) + { + ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX"You don't have access to this command."); + return; } - PrintMultiAdminAction(nType, pszCommandPlayerName, "slayed"); -} - -CON_COMMAND_CHAT_FLAGS(slap, " [damage] - slap a player", ADMFLAG_SLAY) -{ if (args.ArgC() < 2) { - ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX "Usage: !slap "); + ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX"Usage: !slay "); return; } - int iCommandPlayer = player ? player->GetPlayerSlot() : -1; int iNumClients = 0; int pSlots[MAXPLAYERS]; @@ -536,12 +477,10 @@ CON_COMMAND_CHAT_FLAGS(slap, " [damage] - slap a player", ADMFLAG_SLAY) if (!iNumClients) { - ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX "Target not found."); + ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX"Target not found."); return; } - const char *pszCommandPlayerName = player ? player->GetPlayerName() : "Console"; - for (int i = 0; i < iNumClients; i++) { CBasePlayerController *pTarget = (CBasePlayerController *)g_pEntitySystem->GetBaseEntity((CEntityIndex)(pSlots[i] + 1)); @@ -549,36 +488,41 @@ CON_COMMAND_CHAT_FLAGS(slap, " [damage] - slap a player", ADMFLAG_SLAY) if (!pTarget) continue; - CBasePlayerPawn *pPawn = pTarget->m_hPawn(); - - if (!pPawn) - continue; - - // Taken directly from sourcemod - Vector velocity = pPawn->m_vecAbsVelocity; - velocity.x += ((rand() % 180) + 50) * (((rand() % 2) == 1) ? -1 : 1); - velocity.y += ((rand() % 180) + 50) * (((rand() % 2) == 1) ? -1 : 1); - velocity.z += rand() % 200 + 100; - pPawn->SetAbsVelocity(velocity); - - int iDamage = V_StringToInt32(args[2], 0); - - if (iDamage > 0) - pPawn->TakeDamage(iDamage); + pTarget->GetPawn()->CommitSuicide(false, true); if (nType < ETargetType::ALL) - PrintSingleAdminAction(pszCommandPlayerName, pTarget->GetPlayerName(), "slapped"); + ClientPrintAll(HUD_PRINTTALK, CHAT_PREFIX ADMIN_PREFIX "slayed %s.", player->GetPlayerName(), pTarget->GetPlayerName()); } - PrintMultiAdminAction(nType, pszCommandPlayerName, "slapped"); + switch (nType) + { + case ETargetType::ALL: + ClientPrintAll(HUD_PRINTTALK, CHAT_PREFIX ADMIN_PREFIX "slayed everyone.", player->GetPlayerName()); + break; + case ETargetType::T: + ClientPrintAll(HUD_PRINTTALK, CHAT_PREFIX ADMIN_PREFIX "slayed terrorists.", player->GetPlayerName()); + break; + case ETargetType::CT: + ClientPrintAll(HUD_PRINTTALK, CHAT_PREFIX ADMIN_PREFIX "slayed counter-terrorists.", player->GetPlayerName()); + break; + } } -CON_COMMAND_CHAT_FLAGS(goto, " - teleport to a player", ADMFLAG_SLAY) +CON_COMMAND_CHAT(goto, "teleport to a player") { - // Only players can use this command at all + if(!g_bEnableTeleport) + return; + if (!player) + return; + + int iCommandPlayer = player->GetPlayerSlot(); + + ZEPlayer *pPlayer = g_playerManager->GetPlayer(player->GetPlayerSlot()); + + if (!pPlayer->IsAdminFlagSet(ADMFLAG_SLAY)) { - ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX "You cannot use this command from the server console."); + ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX "You don't have access to this command."); return; } @@ -591,7 +535,7 @@ CON_COMMAND_CHAT_FLAGS(goto, " - teleport to a player", ADMFLAG_SLAY) int iNumClients = 0; int pSlots[MAXPLAYERS]; - if (g_playerManager->TargetPlayerString(player->GetPlayerSlot(), args[1], iNumClients, pSlots) != ETargetType::PLAYER || iNumClients > 1) + if (g_playerManager->TargetPlayerString(iCommandPlayer, args[1], iNumClients, pSlots) != ETargetType::PLAYER || iNumClients > 1) { ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX "Target too ambiguous."); return; @@ -605,7 +549,7 @@ CON_COMMAND_CHAT_FLAGS(goto, " - teleport to a player", ADMFLAG_SLAY) for (int i = 0; i < iNumClients; i++) { - CCSPlayerController* pTarget = CCSPlayerController::FromSlot(pSlots[i]); + CBasePlayerController *pTarget = (CBasePlayerController *)g_pEntitySystem->GetBaseEntity((CEntityIndex)(pSlots[i] + 1)); if (!pTarget) continue; @@ -614,15 +558,25 @@ CON_COMMAND_CHAT_FLAGS(goto, " - teleport to a player", ADMFLAG_SLAY) player->GetPawn()->Teleport(&newOrigin, nullptr, nullptr); - PrintSingleAdminAction(player->GetPlayerName(), pTarget->GetPlayerName(), "teleported to"); + ClientPrintAll(HUD_PRINTTALK, CHAT_PREFIX ADMIN_PREFIX "Teleported to %s.", pTarget->GetPlayerName()); } } -CON_COMMAND_CHAT_FLAGS(bring, " - bring a player", ADMFLAG_SLAY) +CON_COMMAND_CHAT(bring, "bring a player") { + if(!g_bEnableTeleport) + return; + if (!player) + return; + + int iCommandPlayer = player->GetPlayerSlot(); + + ZEPlayer *pPlayer = g_playerManager->GetPlayer(player->GetPlayerSlot()); + + if (!pPlayer->IsAdminFlagSet(ADMFLAG_SLAY)) { - ClientPrint(player, HUD_PRINTCONSOLE, CHAT_PREFIX "You cannot use this command from the server console."); + ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX "You don't have access to this command."); return; } @@ -635,7 +589,7 @@ CON_COMMAND_CHAT_FLAGS(bring, " - bring a player", ADMFLAG_SLAY) int iNumClients = 0; int pSlots[MAXPLAYERS]; - ETargetType nType = g_playerManager->TargetPlayerString(player->GetPlayerSlot(), args[1], iNumClients, pSlots); + ETargetType nType = g_playerManager->TargetPlayerString(iCommandPlayer, args[1], iNumClients, pSlots); if (!iNumClients) { @@ -645,7 +599,7 @@ CON_COMMAND_CHAT_FLAGS(bring, " - bring a player", ADMFLAG_SLAY) for (int i = 0; i < iNumClients; i++) { - CCSPlayerController* pTarget = CCSPlayerController::FromSlot(pSlots[i]); + CBasePlayerController *pTarget = (CBasePlayerController *)g_pEntitySystem->GetBaseEntity((CEntityIndex)(pSlots[i] + 1)); if (!pTarget) continue; @@ -655,21 +609,47 @@ CON_COMMAND_CHAT_FLAGS(bring, " - bring a player", ADMFLAG_SLAY) pTarget->GetPawn()->Teleport(&newOrigin, nullptr, nullptr); if (nType < ETargetType::ALL) - PrintSingleAdminAction(player->GetPlayerName(), pTarget->GetPlayerName(), "brought"); + ClientPrintAll(HUD_PRINTTALK, CHAT_PREFIX ADMIN_PREFIX "brought %s.", player->GetPlayerName(), pTarget->GetPlayerName()); } - PrintMultiAdminAction(nType, player->GetPlayerName(), "brought"); + switch (nType) + { + case ETargetType::ALL: + ClientPrintAll(HUD_PRINTTALK, CHAT_PREFIX ADMIN_PREFIX "brought everyone.", player->GetPlayerName()); + break; + case ETargetType::T: + ClientPrintAll(HUD_PRINTTALK, CHAT_PREFIX ADMIN_PREFIX "brought terrorists.", player->GetPlayerName()); + break; + case ETargetType::CT: + ClientPrintAll(HUD_PRINTTALK, CHAT_PREFIX ADMIN_PREFIX "brought counter-terrorists.", player->GetPlayerName()); + break; + } } -CON_COMMAND_CHAT_FLAGS(setteam, " - set a player's team", ADMFLAG_SLAY) +CON_COMMAND_CHAT(setteam, "set a player's team") { + if(!g_bEnableTeamControl) + return; + + if (!player) + return; + + int iCommandPlayer = player->GetPlayerSlot(); + + ZEPlayer *pPlayer = g_playerManager->GetPlayer(player->GetPlayerSlot()); + + if (!pPlayer->IsAdminFlagSet(ADMFLAG_SLAY)) + { + ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX "You don't have access to this command."); + return; + } + if (args.ArgC() < 3) { ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX "Usage: !setteam "); return; } - int iCommandPlayer = player ? player->GetPlayerSlot() : -1; int iNumClients = 0; int pSlots[MAXPLAYERS]; @@ -689,34 +669,45 @@ CON_COMMAND_CHAT_FLAGS(setteam, " - set a player's team", ADM return; } - const char *pszCommandPlayerName = player ? player->GetPlayerName() : "Console"; - - constexpr const char *teams[] = {"none", "spectators", "terrorists", "counter-terrorists"}; - - char szAction[64]; - V_snprintf(szAction, sizeof(szAction), " to %s", teams[iTeam]); - for (int i = 0; i < iNumClients; i++) { - CCSPlayerController* pTarget = CCSPlayerController::FromSlot(pSlots[i]); + CCSPlayerController *pTarget = (CCSPlayerController *)g_pEntitySystem->GetBaseEntity((CEntityIndex)(pSlots[i] + 1)); if (!pTarget) continue; - pTarget->SwitchTeam(iTeam); + pTarget->ChangeTeam(iTeam); if (nType < ETargetType::ALL) - PrintSingleAdminAction(pszCommandPlayerName, pTarget->GetPlayerName(), "moved", szAction); + ClientPrintAll(HUD_PRINTTALK, CHAT_PREFIX ADMIN_PREFIX "moved %s to team %i.", player->GetPlayerName(), pTarget->GetPlayerName(), iTeam); } - PrintMultiAdminAction(nType, pszCommandPlayerName, "moved", szAction); + switch (nType) + { + case ETargetType::ALL: + ClientPrintAll(HUD_PRINTTALK, CHAT_PREFIX ADMIN_PREFIX "moved everyone to team %i.", iTeam); + break; + case ETargetType::T: + ClientPrintAll(HUD_PRINTTALK, CHAT_PREFIX ADMIN_PREFIX "moved terrorists to team %i.", iTeam); + break; + case ETargetType::CT: + ClientPrintAll(HUD_PRINTTALK, CHAT_PREFIX ADMIN_PREFIX "moved counter-terrorists to team %i.", iTeam); + break; + } } -CON_COMMAND_CHAT_FLAGS(noclip, "- toggle noclip on yourself", ADMFLAG_SLAY | ADMFLAG_CHEATS) +CON_COMMAND_CHAT(noclip, "toggle noclip on yourself") { - if (!player) + if (!player && practiceMode) + return; + + int iCommandPlayer = player->GetPlayerSlot(); + + ZEPlayer *pPlayer = g_playerManager->GetPlayer(iCommandPlayer); + + if (!pPlayer->IsAdminFlagSet(ADMFLAG_SLAY)) { - ClientPrint(player, HUD_PRINTCONSOLE, CHAT_PREFIX "You cannot use this command from the server console."); + ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX "You don't have access to this command."); return; } @@ -731,222 +722,80 @@ CON_COMMAND_CHAT_FLAGS(noclip, "- toggle noclip on yourself", ADMFLAG_SLAY | ADM return; } - if (pPawn->m_nActualMoveType() == MOVETYPE_NOCLIP) + if (pPawn->m_MoveType() == MOVETYPE_NOCLIP) { - pPawn->SetMoveType(MOVETYPE_WALK); + pPawn->m_MoveType = MOVETYPE_WALK; ClientPrintAll(HUD_PRINTTALK, CHAT_PREFIX ADMIN_PREFIX "exited noclip.", player->GetPlayerName()); } else { - pPawn->SetMoveType(MOVETYPE_NOCLIP); + pPawn->m_MoveType = MOVETYPE_NOCLIP; ClientPrintAll(HUD_PRINTTALK, CHAT_PREFIX ADMIN_PREFIX "entered noclip.", player->GetPlayerName()); } } - - -CON_COMMAND_CHAT_FLAGS(entfire, " [parameter] - fire outputs at entities", ADMFLAG_RCON) +/* +CON_COMMAND_CHAT(map, "change map") { - if (args.ArgC() < 3) - { - ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX "Usage: !entfire "); + if (!player) return; - } - - int iFoundEnts = 0; - - Z_CBaseEntity *pTarget = nullptr; - - // The idea here is to only use one of the targeting modes at once, prioritizing !picker then targetname/!self then classname - // Try picker first, FindEntityByName can also take !picker but it always uses player 0 so we have to do this ourselves - if (player && !V_strcmp("!picker", args[1])) - { - pTarget = UTIL_FindPickerEntity(player); - - if (pTarget) - { - pTarget->AcceptInput(args[2], args[3], player, player); - iFoundEnts++; - } - } - - // !self would resolve to the player controller, so here's a convenient alias to get the pawn instead - if (player && !V_strcmp("!selfpawn", args[1])) - { - pTarget = player->GetPawn(); - - if (pTarget) - { - pTarget->AcceptInput(args[2], args[3], player, player); - iFoundEnts++; - } - } - - if (!iFoundEnts) - { - while (pTarget = UTIL_FindEntityByName(pTarget, args[1], player)) - { - pTarget->AcceptInput(args[2], args[3], player, player); - iFoundEnts++; - } - } - if (!iFoundEnts) - { - while (pTarget = UTIL_FindEntityByClassname(pTarget, args[1])) - { - pTarget->AcceptInput(args[2], args[3], player, player); - iFoundEnts++; - } - } + int iCommandPlayer = player->GetPlayerSlot(); - if (!iFoundEnts) - ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX "Target not found."); - else - ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX "Input successful on %i entities.", iFoundEnts); -} + ZEPlayer *pPlayer = g_playerManager->GetPlayer(iCommandPlayer); -CON_COMMAND_CHAT_FLAGS(entfirepawn, " [parameter] - fire outputs at player pawns", ADMFLAG_RCON) -{ - if (args.ArgC() < 3) + if (!pPlayer->IsAdminFlagSet(ADMFLAG_CHANGEMAP)) { - ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX "Usage: !entfirepawn "); + ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX"You don't have access to this command."); return; } - int iCommandPlayer = player ? player->GetPlayerSlot() : -1; - int iNumClients = 0; - int pSlots[MAXPLAYERS]; - - ETargetType nType = g_playerManager->TargetPlayerString(iCommandPlayer, args[1], iNumClients, pSlots); - - if (!iNumClients) + if (args.ArgC() < 2) { - ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX "Target not found."); + ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX"Usage: !map "); return; } - int iFoundEnts = 0; - - for (int i = 0; i < iNumClients; i++) - { - CCSPlayerController *pTarget = CCSPlayerController::FromSlot(pSlots[i]); - - if (!pTarget || !pTarget->GetPawn()) - continue; - - pTarget->GetPawn()->AcceptInput(args[2], args[3], player, player); - iFoundEnts++; - } - - ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX "Input successful on %i player pawns.", iFoundEnts); -} - -CON_COMMAND_CHAT_FLAGS(entfirecontroller, " [parameter] - fire outputs at player controllers", ADMFLAG_RCON) -{ - if (args.ArgC() < 3) + if (!g_pEngineServer2->IsMapValid(args[1])) { - ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX "Usage: !entfirecontroller "); + ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX"Invalid map specified."); return; } - int iCommandPlayer = player ? player->GetPlayerSlot() : -1; - int iNumClients = 0; - int pSlots[MAXPLAYERS]; - - ETargetType nType = g_playerManager->TargetPlayerString(iCommandPlayer, args[1], iNumClients, pSlots); - - if (!iNumClients) - { - ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX "Target not found."); - return; - } + ClientPrintAll(HUD_PRINTTALK, CHAT_PREFIX"Changing map to %s...", args[1]); - int iFoundEnts = 0; + char buf[MAX_PATH]; + V_snprintf(buf, sizeof(buf), "changelevel %s", args[1]); - for (int i = 0; i < iNumClients; i++) + new CTimer(5.0f, false, false, [buf]() { - CCSPlayerController *pTarget = CCSPlayerController::FromSlot(pSlots[i]); - - if (!pTarget) - continue; - - pTarget->AcceptInput(args[2], args[3], player, player); - iFoundEnts++; - } - - ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX "Input successful on %i player controllers.", iFoundEnts); + g_pEngineServer2->ServerCommand(buf); + }); } - -CON_COMMAND_CHAT_FLAGS(hsay, " - say something as a hud hint", ADMFLAG_CHAT) +*/ +CON_COMMAND_CHAT(hsay, "say something as a hud hint") { - if (args.ArgC() < 2) - { - ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX "Usage: !hsay "); + if (!player) return; - } - ClientPrintAll(HUD_PRINTCENTER, "%s", args.ArgS()); -} + int iCommandPlayer = player->GetPlayerSlot(); -CON_COMMAND_CHAT_FLAGS(rcon, " - send a command to server console", ADMFLAG_RCON) -{ - if (!player) - { - ClientPrint(player, HUD_PRINTCONSOLE, CHAT_PREFIX "You are already on the server console."); - return; - } + ZEPlayer *pPlayer = g_playerManager->GetPlayer(iCommandPlayer); - if (args.ArgC() < 2) + if (!pPlayer->IsAdminFlagSet(ADMFLAG_CHAT)) { - ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX "Usage: !rcon "); + ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX "You don't have access to this command."); return; } - g_pEngineServer2->ServerCommand(args.ArgS()); -} - -CON_COMMAND_CHAT_FLAGS(extend, " - extend current map (negative value reduces map duration)", ADMFLAG_CHANGEMAP) -{ if (args.ArgC() < 2) { - ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX "Usage: !extend "); + ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX "Usage: !hsay "); return; } - int iExtendTime = V_StringToInt32(args[1], 0); - - ConVar* cvar = g_pCVar->GetConVar(g_pCVar->FindConVar("mp_timelimit")); - - // CONVAR_TODO - // HACK: values is actually the cvar value itself, hence this ugly cast. - float flTimelimit = *(float *)&cvar->values; - - if (gpGlobals->curtime - g_pGameRules->m_flGameStartTime > flTimelimit * 60) - flTimelimit = (gpGlobals->curtime - g_pGameRules->m_flGameStartTime) / 60.0f + iExtendTime; - else - { - if (flTimelimit == 1) - flTimelimit = 0; - flTimelimit += iExtendTime; - } - - if (flTimelimit <= 0) - flTimelimit = 1; - - // CONVAR_TODO - char buf[32]; - V_snprintf(buf, sizeof(buf), "mp_timelimit %.6f", flTimelimit); - g_pEngineServer2->ServerCommand(buf); - - const char* pszCommandPlayerName = player ? player->GetPlayerName() : "Console"; - - if (iExtendTime < 0) - ClientPrintAll(HUD_PRINTTALK, CHAT_PREFIX ADMIN_PREFIX "shortened map time %i minutes.", pszCommandPlayerName, iExtendTime * -1); - else - ClientPrintAll(HUD_PRINTTALK, CHAT_PREFIX ADMIN_PREFIX "extended map time %i minutes.", pszCommandPlayerName, iExtendTime); + ClientPrintAll(HUD_PRINTCENTER, "%s", args.ArgS()); } - bool CAdminSystem::LoadAdmins() { m_vecAdmins.Purge(); @@ -1008,7 +857,7 @@ bool CAdminSystem::LoadInfractions() for (KeyValues* pKey = pKV->GetFirstSubKey(); pKey; pKey = pKey->GetNextKey()) { uint64 iSteamId = pKey->GetUint64("steamid", -1); - time_t iEndTime = pKey->GetUint64("endtime", -1); + int iEndTime = pKey->GetInt("endtime", -1); int iType = pKey->GetInt("type", -1); if (iSteamId == -1) @@ -1032,13 +881,13 @@ bool CAdminSystem::LoadInfractions() switch (iType) { case CInfractionBase::Ban: - AddInfraction(new CBanInfraction(iEndTime, iSteamId, true)); + AddInfraction(new CBanInfraction(iEndTime, iSteamId)); break; case CInfractionBase::Mute: - AddInfraction(new CMuteInfraction(iEndTime, iSteamId, true)); + AddInfraction(new CMuteInfraction(iEndTime, iSteamId)); break; case CInfractionBase::Gag: - AddInfraction(new CGagInfraction(iEndTime, iSteamId, true)); + AddInfraction(new CGagInfraction(iEndTime, iSteamId)); break; default: Warning("Invalid infraction type %d\n", iType); @@ -1056,7 +905,7 @@ void CAdminSystem::SaveInfractions() FOR_EACH_VEC(m_vecInfractions, i) { - time_t timestamp = m_vecInfractions[i]->GetTimestamp(); + int timestamp = m_vecInfractions[i]->GetTimestamp(); if (timestamp != 0 && timestamp < std::time(0)) continue; @@ -1064,7 +913,7 @@ void CAdminSystem::SaveInfractions() V_snprintf(buf, sizeof(buf), "%d", i); pSubKey = new KeyValues(buf); pSubKey->AddUint64("steamid", m_vecInfractions[i]->GetSteamId64()); - pSubKey->AddUint64("endtime", m_vecInfractions[i]->GetTimestamp()); + pSubKey->AddInt("endtime", m_vecInfractions[i]->GetTimestamp()); pSubKey->AddInt("type", m_vecInfractions[i]->GetType()); pKV->AddSubKey(pSubKey); @@ -1091,7 +940,8 @@ bool CAdminSystem::ApplyInfractions(ZEPlayer *player) { // Because this can run without the player being authenticated, and the fact that we're applying a ban/mute here, // we can immediately just use the steamid we got from the connecting player. - uint64 iSteamID = player->IsAuthenticated() ? player->GetSteamId64() : player->GetUnauthenticatedSteamId64(); + uint64 iSteamID = player->IsAuthenticated() ? + player->GetSteamId64() : g_pEngineServer2->GetClientSteamID(player->GetPlayerSlot())->ConvertToUint64(); // We're only interested in infractions concerning this player if (m_vecInfractions[i]->GetSteamId64() != iSteamID) @@ -1100,7 +950,7 @@ bool CAdminSystem::ApplyInfractions(ZEPlayer *player) // Undo the infraction just briefly while checking if it ran out m_vecInfractions[i]->UndoInfraction(player); - time_t timestamp = m_vecInfractions[i]->GetTimestamp(); + int timestamp = m_vecInfractions[i]->GetTimestamp(); if (timestamp != 0 && timestamp <= std::time(0)) { m_vecInfractions.Remove(i); @@ -1133,6 +983,21 @@ bool CAdminSystem::FindAndRemoveInfraction(ZEPlayer *player, CInfractionBase::EI return false; } +bool CAdminSystem::FindAndRemoveInfraction(uint64 iSteamID, CInfractionBase::EInfractionType type) +{ + FOR_EACH_VEC(m_vecInfractions, i) + { + if (m_vecInfractions[i]->GetSteamId64() == iSteamID && m_vecInfractions[i]->GetType() == type) + { + m_vecInfractions.Remove(i); + + return true; + } + } + + return false; +} + CAdmin *CAdminSystem::FindAdmin(uint64 iSteamID) { FOR_EACH_VEC(m_vecAdmins, i) @@ -1189,15 +1054,15 @@ void CGagInfraction::UndoInfraction(ZEPlayer *player) player->SetGagged(false); } - -CON_COMMAND_CHAT(pracc, "Practice mode") +//CS2Scrim custom commands +CON_COMMAND_CHAT(scrim, "Scrim mode") { - if(!g_bEnablePractice) + if (!g_bEnableScrim) return; if (!player) return; - + int iCommandPlayer = player->GetPlayerSlot(); ZEPlayer *pPlayer = g_playerManager->GetPlayer(player->GetPlayerSlot()); @@ -1207,24 +1072,29 @@ CON_COMMAND_CHAT(pracc, "Practice mode") ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX "You don't have access to this command."); return; } + + print_coaches(); - practiceMode = true; - + practiceMode = false; + char buf[256]; //V_snprintf(buf, sizeof(buf), "exec %s", args[1]); - g_pEngineServer2->ServerCommand("exec pracc"); + g_pEngineServer2->ServerCommand("exec scrim"); - ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX"Practice mode loaded"); - //ClientPrintAll(HUD_PRINTTALK, CHAT_PREFIX"Available commands: \4.pause\1, \4.unpause\1"); + ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX"Scrim mode loaded, mr24"); + ClientPrintAll(HUD_PRINTTALK, CHAT_PREFIX"Available commands: \4.pause\1, \4.unpause\1"); //ClientPrintAll(HUD_PRINTTALK, CHAT_PREFIX"Admin commands: \4.pracc\1, \4.scrim\1, \4.record\1, \4.stoprecord\1, \4.map\1"); } -CON_COMMAND_CHAT(scrim, "Scrim mode") +CON_COMMAND_CHAT(pracc, "Practice mode") { - if (!player) + if(!g_bEnablePractice) return; + if (!player) + return; + int iCommandPlayer = player->GetPlayerSlot(); ZEPlayer *pPlayer = g_playerManager->GetPlayer(player->GetPlayerSlot()); @@ -1234,24 +1104,24 @@ CON_COMMAND_CHAT(scrim, "Scrim mode") ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX "You don't have access to this command."); return; } - - print_coaches(); - practiceMode = false; - + practiceMode = true; + char buf[256]; //V_snprintf(buf, sizeof(buf), "exec %s", args[1]); - g_pEngineServer2->ServerCommand("exec scrim"); + g_pEngineServer2->ServerCommand("exec pracc"); - ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX"Scrim mode loaded, mr24"); + ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX"Practice mode loaded"); ClientPrintAll(HUD_PRINTTALK, CHAT_PREFIX"Available commands: \4.pause\1, \4.unpause\1"); //ClientPrintAll(HUD_PRINTTALK, CHAT_PREFIX"Admin commands: \4.pracc\1, \4.scrim\1, \4.record\1, \4.stoprecord\1, \4.map\1"); } - CON_COMMAND_CHAT(forceunpause, "Force unpause") { + if(!g_bEnablePause) + return; + if (!player) return; @@ -1273,11 +1143,20 @@ CON_COMMAND_CHAT(forceunpause, "Force unpause") g_pEngineServer2->ServerCommand("mp_unpause_match"); } - -CON_COMMAND_CHAT_FLAGS(map, " - change map", ADMFLAG_BAN) +CON_COMMAND_CHAT(map, "change map") { + if (!player) + return; + int iCommandPlayer = player->GetPlayerSlot(); + ZEPlayer *pPlayer = g_playerManager->GetPlayer(iCommandPlayer); + + if (!pPlayer->IsAdminFlagSet(ADMFLAG_CHANGEMAP)) + { + ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX"You don't have access to this command."); + return; + } if (args.ArgC() < 2) { @@ -1291,6 +1170,9 @@ CON_COMMAND_CHAT_FLAGS(map, " - change map", ADMFLAG_BAN) return; } */ + //V_strncpy + V_snprintf(level_name, sizeof(level_name), "%s", args[1]); + char buf[MAX_PATH]; V_snprintf(buf, sizeof(buf), "changelevel de_%s", args[1]); @@ -1307,9 +1189,12 @@ CON_COMMAND_CHAT_FLAGS(map, " - change map", ADMFLAG_BAN) CON_COMMAND_CHAT(restore, "Restore round") { + if (!g_bEnableRestore) + return; + if (!player) return; - + int iCommandPlayer = player->GetPlayerSlot(); ZEPlayer *pPlayer = g_playerManager->GetPlayer(player->GetPlayerSlot()); @@ -1345,12 +1230,17 @@ CON_COMMAND_CHAT(restore, "Restore round") ClientPrintAll(HUD_PRINTTALK, CHAT_PREFIX"\4Restored round \3%i", nRounds); + half_last_round = false; //If not set to false, coach will be on the wrong team if it is the last round of the first half + g_pEngineServer2->ServerCommand(buf); } char demoName[128]; CON_COMMAND_CHAT(record, "Record demo") { + if (!g_bEnableRecord) + return; + if (!player) return; @@ -1373,7 +1263,8 @@ CON_COMMAND_CHAT(record, "Record demo") std::localtime(&result); std::strftime(actualTime, sizeof(actualTime), "%d%B_%H-%M", std::localtime(&result)); - V_snprintf(actualMap,MAX_PATH, "%s", gpGlobals->mapname); + V_snprintf(actualMap,MAX_PATH, "unknownMap"); + if(level_name != "")V_snprintf(actualMap,MAX_PATH, "%s", level_name); V_snprintf(demoName, MAX_PATH, "%s_%s", actualTime, actualMap); V_snprintf(buf, MAX_PATH, "tv_record gotv/%s", demoName); @@ -1396,6 +1287,9 @@ CON_COMMAND_CHAT(record, "Record demo") CON_COMMAND_CHAT(stoprecord, "Stop demo recording") { + if (!g_bEnableRecord) + return; + if (!player) return; diff --git a/src/adminsystem.h b/src/adminsystem.h index d0bf7f1f..631819cd 100644 --- a/src/adminsystem.h +++ b/src/adminsystem.h @@ -148,6 +148,7 @@ class CAdminSystem void SaveInfractions(); bool ApplyInfractions(ZEPlayer *player); bool FindAndRemoveInfraction(ZEPlayer *player, CInfractionBase::EInfractionType type); + bool FindAndRemoveInfraction(uint64 iSteamID, CInfractionBase::EInfractionType type); CAdmin *FindAdmin(uint64 iSteamID); uint64 ParseFlags(const char* pszFlags); diff --git a/src/commands.cpp b/src/commands.cpp index efb93d6c..4c212dbe 100644 --- a/src/commands.cpp +++ b/src/commands.cpp @@ -47,7 +47,6 @@ extern IVEngineServer2* g_pEngineServer2; extern bool practiceMode; extern bool no_flash_mode; -CUtlVector coaches; WeaponMapEntry_t WeaponMap[] = { {{"bizon"}, "weapon_bizon", "PP-Bizon", 1400, 26, GEAR_SLOT_RIFLE}, @@ -379,18 +378,195 @@ FAKE_BOOL_CVAR(cs2scrim_scrim, "Whether to enable coach", g_bEnableScrim, true, FAKE_BOOL_CVAR(cs2scrim_admin_slay, "Whether to enable coach", g_bEnableSlay, true, false) FAKE_BOOL_CVAR(cs2scrim_admin_team, "Whether to enable coach", g_bEnableTeamControl, true, false) FAKE_BOOL_CVAR(cs2scrim_admin_teleport, "Whether to enable coach", g_bEnableTeleport, true, false) +/* Player commands */ +CON_COMMAND_CHAT(myuid, "test") +{ + if (!player) + return; -CON_COMMAND_CHAT(noflash, "noflash"){ + int iPlayer = player->GetPlayerSlot(); - if (!player || !g_bEnablePractice || !practiceMode) + ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX "Your userid is %i, slot: %i, retrieved slot: %i", g_pEngineServer2->GetPlayerUserId(iPlayer).Get(), iPlayer, g_playerManager->GetSlotFromUserId(g_pEngineServer2->GetPlayerUserId(iPlayer).Get())); +} + + +CON_COMMAND_CHAT(noflash, "noflash"){ return; + if (!player) + return; + no_flash_mode = !no_flash_mode; ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX "Flash mode set to \04%i", no_flash_mode); } +bool match_paused = false; +bool ct_ready = true; +bool t_ready = true; + +CON_COMMAND_CHAT(pause, "Request pause") +{ + if(!g_bEnablePause) + return; + + if (!player) + return; + + int iPlayer = player->GetPlayerSlot(); + + CBasePlayerController* pPlayer = (CBasePlayerController*)g_pEntitySystem->GetBaseEntity((CEntityIndex)(player->GetPlayerSlot() + 1)); + + g_pEngineServer2->ServerCommand("mp_pause_match"); + + ClientPrintAll(HUD_PRINTTALK, CHAT_PREFIX"%s requested a pause", player->GetPlayerName()); + + match_paused = true; + ct_ready = false; + t_ready = false; +} + +CON_COMMAND_CHAT(unpause, "Request unpause") +{ + if(!g_bEnablePause) + return; + + if (!player) + return; + + if(!match_paused) + return; + + CBasePlayerController* pPlayer = (CBasePlayerController*)g_pEntitySystem->GetBaseEntity((CEntityIndex)(player->GetPlayerSlot() + 1)); + + int teamSide = pPlayer->m_iTeamNum(); + if( teamSide == CS_TEAM_T && !t_ready){ + t_ready = true; + }else if( teamSide == CS_TEAM_CT && !ct_ready){ + ct_ready = true; + } + + if(ct_ready && !t_ready){ + ClientPrintAll(HUD_PRINTTALK, CHAT_PREFIX"CT ready, type .unpause"); + return; + }else if(!ct_ready && t_ready){ + ClientPrintAll(HUD_PRINTTALK, CHAT_PREFIX"T ready, type .unpause"); + return; + } + + match_paused = false; + ClientPrintAll(HUD_PRINTTALK, CHAT_PREFIX"Match \2unpaused"); + g_pEngineServer2->ServerCommand("mp_unpause_match"); +} + +CON_COMMAND_CHAT(spawn, "teleport to desired spawn") +{ + if (!g_bEnablePraccSpawn) + return; + + if (!player) + return; + + if (!practiceMode){ + ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX"Only available on practice mode"); + return; + } + + if (args.ArgC() < 2) + { + ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX "Usage: !spawn "); + return; + } + + char teamName[256]; + int target_team_number = CS_TEAM_NONE; + + if(args.ArgC() > 2){ + char team_id_input[256]; + V_snprintf(team_id_input, sizeof(team_id_input), "%s", args[2]); + ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX"%s ", args[2]); + if((std::string)team_id_input == "t"){ + target_team_number = CS_TEAM_T; + }else if((std::string)team_id_input == "ct"){ + target_team_number = CS_TEAM_CT; + }else{ + ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX"Usage: !spawn "); + } + }else{ + target_team_number = player->m_iTeamNum; + } + + if(target_team_number == CS_TEAM_SPECTATOR){ + ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX"You cannot teleport in spectator!"); + return; + } + if(target_team_number == CS_TEAM_SPECTATOR){ + ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX"You cannot teleport in spectator!"); + return; + } + if(target_team_number == CS_TEAM_T){ + V_snprintf(teamName, sizeof(teamName), "info_player_terrorist"); + }else{ + V_snprintf(teamName, sizeof(teamName), "info_player_counterterrorist"); + } + + //Count spawnpoints (info_player_counterterrorist & info_player_terrorist) + SpawnPoint* spawn = nullptr; + CUtlVector spawns; + + int minimum_priority = 1; + while (nullptr != (spawn = (SpawnPoint*)UTIL_FindEntityByClassname(spawn, teamName))) + { + if (spawn->m_bEnabled() && spawn->m_iPriority() < minimum_priority) + { + minimum_priority = spawn->m_iPriority(); + // ClientPrint(player, HUD_PRINTTALK, "Spawn %i: %f / %f / %f", spawns.Count(), spawn->GetAbsOrigin().x, spawn->GetAbsOrigin().y, spawn->GetAbsOrigin().z); + //spawns.AddToTail(spawn); + } + } + + while (nullptr != (spawn = (SpawnPoint*)UTIL_FindEntityByClassname(spawn, teamName))) + { + if (spawn->m_bEnabled() && spawn->m_iPriority() == minimum_priority) + { + // ClientPrint(player, HUD_PRINTTALK, "Spawn %i: %f / %f / %f", spawns.Count(), spawn->GetAbsOrigin().x, spawn->GetAbsOrigin().y, spawn->GetAbsOrigin().z); + spawns.AddToTail(spawn); + } + } + + //Pick and get position of random spawnpoint + //Spawns selection from 1 to spawns.Count() + int targetSpawn = atoi(args[1]) - 1; + if (targetSpawn < 0) targetSpawn = 0; + + int spawnIndex = targetSpawn % spawns.Count(); + Vector spawnpos = spawns[spawnIndex]->GetAbsOrigin(); + int spawn_priority = spawns[spawnIndex]->m_iPriority(); + + //Here's where the mess starts + CBasePlayerPawn *pPawn = player->GetPawn(); + if (!pPawn) + { + return; + } + if (pPawn->m_iHealth() <= 0) + { + ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX"You cannot teleport when dead!"); + return; + } + + int totalSpawns = spawns.Count(); + + pPawn->SetAbsOrigin(spawnpos); + + ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX"You have been teleported to spawn. %i/%i priority:%i", spawnIndex +1, totalSpawns, spawn_priority); +} + +CUtlVector coaches; + void print_coaches(){ + if (!g_bEnableCoach) + return; if (coaches.Count() < 1) return; ClientPrintAll(HUD_PRINTTALK, CHAT_PREFIX"\5%i \1active \5coaches", coaches.Count()); @@ -401,6 +577,9 @@ void print_coaches(){ CON_COMMAND_CHAT(coach, "Request slot coach") { + if(!g_bEnableCoach) + return; + if (!player) return; @@ -418,27 +597,48 @@ CON_COMMAND_CHAT(coach, "Request slot coach") coaches.AddToTail(player); - ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX "Coach enabled, type \4.uncoach \1to cancel"); - print_coaches(); + int target_team_number = CS_TEAM_SPECTATOR; + + if(args.ArgC() > 1){ + char team_id_input[256]; + V_snprintf(team_id_input, sizeof(team_id_input), "%s", args[1]); + if((std::string)team_id_input == "t"){ + target_team_number = CS_TEAM_T; + }else if((std::string)team_id_input == "ct"){ + target_team_number = CS_TEAM_CT; + }else{ + ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX"Usage: .coach "); + } + }else{ + ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX "Coach enabled, type \4.uncoach \1to cancel"); + ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX "You are on spectator mode, choose \4.ct \1or \4.t"); + } + + print_coaches(); CHandle hController = player->GetHandle(); // Gotta do this on the next frame... - new CTimer(0.0f, false, [hController]() + new CTimer(0.0f, false, [hController, target_team_number]() { CCSPlayerController *pController = hController.Get(); if (!pController) return -1.0f; - + + pController->ChangeTeam(target_team_number); pController->m_szClan = "Coaching:"; return -1.0f; }); } +//Todo, unify different aliases CON_COMMAND_CHAT(uncoach, "Undo slot coach") { + if(!g_bEnableCoach) + return; + if (!player) return; @@ -462,66 +662,6 @@ CON_COMMAND_CHAT(uncoach, "Undo slot coach") ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX "You haven't set as \4coach\1 yet"); } - -bool match_paused = false; -bool ct_ready = true; -bool t_ready = true; - -CON_COMMAND_CHAT(pause, "Request pause") -{ - if(!g_bEnablePause) - return; - - if (!player) - return; - - int iPlayer = player->GetPlayerSlot(); - - CBasePlayerController* pPlayer = (CBasePlayerController*)g_pEntitySystem->GetBaseEntity((CEntityIndex)(player->GetPlayerSlot() + 1)); - - g_pEngineServer2->ServerCommand("mp_pause_match"); - - ClientPrintAll(HUD_PRINTTALK, CHAT_PREFIX"%s requested a pause", player->GetPlayerName()); - - match_paused = true; - ct_ready = false; - t_ready = false; -} - -CON_COMMAND_CHAT(unpause, "Request unpause") -{ - if(!g_bEnablePause) - return; - - if (!player) - return; - - if(!match_paused) - return; - - CBasePlayerController* pPlayer = (CBasePlayerController*)g_pEntitySystem->GetBaseEntity((CEntityIndex)(player->GetPlayerSlot() + 1)); - - int teamSide = pPlayer->m_iTeamNum(); - if( teamSide == CS_TEAM_T && !t_ready){ - t_ready = true; - }else if( teamSide == CS_TEAM_CT && !ct_ready){ - ct_ready = true; - } - - if(ct_ready && !t_ready){ - ClientPrintAll(HUD_PRINTTALK, CHAT_PREFIX"CT ready, type .unpause"); - return; - }else if(!ct_ready && t_ready){ - ClientPrintAll(HUD_PRINTTALK, CHAT_PREFIX"T ready, type .unpause"); - return; - } - - match_paused = false; - ClientPrintAll(HUD_PRINTTALK, CHAT_PREFIX"Match \2unpaused"); - g_pEngineServer2->ServerCommand("mp_unpause_match"); -} - - CON_COMMAND_CHAT(ct, "Switch to CT side") { if (!player || !g_bEnablePractice) @@ -589,13 +729,7 @@ CON_COMMAND_CHAT(last, "Teleport to the last thrown grenade") return; } - ZEPlayer *pPlayer = g_playerManager->GetPlayer(player->GetPlayerSlot()); - - if(pPlayer->lastThrow_position.x == 0 && pPlayer->lastThrow_position.y == 0 && pPlayer->lastThrow_position.z== 0){ - ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX "No saved thrown yet"); - return; - } - + player->GetPawn()->Teleport(&pPlayer->lastThrow_position, &pPlayer->lastThrow_rotation, nullptr); -} +} \ No newline at end of file diff --git a/src/cs2_sdk/entity/cbaseentity.h b/src/cs2_sdk/entity/cbaseentity.h index f9224ee3..3dc2380b 100644 --- a/src/cs2_sdk/entity/cbaseentity.h +++ b/src/cs2_sdk/entity/cbaseentity.h @@ -212,4 +212,5 @@ class SpawnPoint : public Z_CBaseEntity DECLARE_SCHEMA_CLASS(SpawnPoint); SCHEMA_FIELD(bool, m_bEnabled); + SCHEMA_FIELD(int, m_iPriority); }; \ No newline at end of file diff --git a/src/cs2fixes.cpp b/src/cs2fixes.cpp index ac556dd7..f5b72bf5 100644 --- a/src/cs2fixes.cpp +++ b/src/cs2fixes.cpp @@ -614,7 +614,7 @@ const char *CS2Fixes::GetLicense() const char *CS2Fixes::GetVersion() { - return "1.0.4"; + return "1.0.4-beta"; } const char *CS2Fixes::GetDate()