mirror of
https://github.com/Jackzmc/sourcemod-plugins.git
synced 2025-05-09 04:23:20 +00:00
Hopefully improve permission system
This commit is contained in:
parent
3eab1a8fa4
commit
f05d935e9c
2 changed files with 48 additions and 44 deletions
Binary file not shown.
|
@ -6,7 +6,6 @@
|
||||||
#define PLUGIN_VERSION "1.0"
|
#define PLUGIN_VERSION "1.0"
|
||||||
|
|
||||||
#include <sourcemod>
|
#include <sourcemod>
|
||||||
#include <sdktools>
|
|
||||||
#include <sdkhooks>
|
#include <sdkhooks>
|
||||||
#include <left4dhooks>
|
#include <left4dhooks>
|
||||||
#include <jutils.inc>
|
#include <jutils.inc>
|
||||||
|
@ -80,19 +79,6 @@ public void OnPluginStart() {
|
||||||
}
|
}
|
||||||
LoadTranslations("common.phrases");
|
LoadTranslations("common.phrases");
|
||||||
|
|
||||||
Handle hConfig = LoadGameConfigFile("l4d2tools");
|
|
||||||
if(hConfig == INVALID_HANDLE) SetFailState("Could not load l4d2tools gamedata.");
|
|
||||||
StartPrepSDKCall(SDKCall_Player);
|
|
||||||
PrepSDKCall_SetFromConf(hConfig, SDKConf_Signature, "TakeOverBot");
|
|
||||||
hTakeOverBot = EndPrepSDKCall();
|
|
||||||
StartPrepSDKCall(SDKCall_Player);
|
|
||||||
PrepSDKCall_SetFromConf(hConfig, SDKConf_Signature, "GoAwayFromKeyboard");
|
|
||||||
hGoAwayFromKeyboard = EndPrepSDKCall();
|
|
||||||
CloseHandle(hConfig);
|
|
||||||
if(hTakeOverBot == INVALID_HANDLE || hGoAwayFromKeyboard == INVALID_HANDLE) {
|
|
||||||
SetFailState("One of 3 signatures is invalid");
|
|
||||||
}
|
|
||||||
|
|
||||||
hLaserNotice = CreateConVar("sm_laser_use_notice", "1.0", "Enable notification of a laser box being used", FCVAR_NONE, true, 0.0, true, 1.0);
|
hLaserNotice = CreateConVar("sm_laser_use_notice", "1.0", "Enable notification of a laser box being used", FCVAR_NONE, true, 0.0, true, 1.0);
|
||||||
hFinaleTimer = CreateConVar("sm_time_finale", "0.0", "Record the time it takes to complete finale. 0 -> OFF, 1 -> Gauntlets Only, 2 -> All finales", FCVAR_NONE, true, 0.0, true, 2.0);
|
hFinaleTimer = CreateConVar("sm_time_finale", "0.0", "Record the time it takes to complete finale. 0 -> OFF, 1 -> Gauntlets Only, 2 -> All finales", FCVAR_NONE, true, 0.0, true, 2.0);
|
||||||
hFFNotice = CreateConVar("sm_ff_notice", "0.0", "Notify players if a FF occurs. 0 -> Disabled, 1 -> In chat, 2 -> In Hint text", FCVAR_NONE, true, 0.0, true, 2.0);
|
hFFNotice = CreateConVar("sm_ff_notice", "0.0", "Notify players if a FF occurs. 0 -> Disabled, 1 -> In chat, 2 -> In Hint text", FCVAR_NONE, true, 0.0, true, 2.0);
|
||||||
|
@ -129,6 +115,7 @@ public void OnPluginStart() {
|
||||||
HookEvent("bot_player_replace", Event_BotPlayerSwap);
|
HookEvent("bot_player_replace", Event_BotPlayerSwap);
|
||||||
HookEvent("player_first_spawn", Event_PlayerFirstSpawn);
|
HookEvent("player_first_spawn", Event_PlayerFirstSpawn);
|
||||||
HookEvent("weapon_drop", Event_WeaponDrop);
|
HookEvent("weapon_drop", Event_WeaponDrop);
|
||||||
|
HookEvent("player_disconnect", Event_PlayerDisconnect);
|
||||||
|
|
||||||
AutoExecConfig(true, "l4d2_tools");
|
AutoExecConfig(true, "l4d2_tools");
|
||||||
|
|
||||||
|
@ -177,32 +164,35 @@ public void OnClientConnected(int client) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
stock void PrintChatToAdmins(const char[] format, any ...) {
|
// Returns -1 if not allowed, or their previous index
|
||||||
char buffer[254];
|
int GetAllowedPlayerIndex(const char[] authid2) {
|
||||||
VFormat(buffer, sizeof(buffer), format, 2);
|
int index;
|
||||||
for(int i = 1; i < MaxClients; i++) {
|
return SteamIDs.GetValue(authid2, index) ? index : -1;
|
||||||
if(IsClientConnected(i) && IsClientInGame(i)) {
|
|
||||||
AdminId admin = GetUserAdmin(i);
|
|
||||||
if(admin != INVALID_ADMIN_ID) {
|
|
||||||
PrintToChat(i, "%s", buffer);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
PrintToServer("%s", buffer);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void OnClientPostAdminCheck(int client) {
|
public void OnClientPostAdminCheck(int client) {
|
||||||
if(!IsFakeClient(client)) {
|
if(!IsFakeClient(client)) {
|
||||||
static char auth[32];
|
if(reserveMode == Reserve_AdminOnly && GetUserAdmin(client) == INVALID_ADMIN_ID) {
|
||||||
GetClientAuthId(client, AuthId_Steam2, auth, sizeof(auth));
|
static char auth[32];
|
||||||
if(reserveMode == Reserve_Private || (reserveMode == Reserve_AdminOnly && GetUserAdmin(client) == INVALID_ADMIN_ID)) {
|
GetClientAuthId(client, AuthId_Steam2, auth, sizeof(auth));
|
||||||
int index;
|
if(GetAllowedPlayerIndex(auth) == -1) {
|
||||||
if(!SteamIDs.GetValue(auth, index)) {
|
|
||||||
KickClient(client, "Sorry, server is reserved");
|
KickClient(client, "Sorry, server is reserved");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void OnClientAuthorized(int client, const char[] auth) {
|
||||||
|
if(IsFakeClient(client)) return;
|
||||||
|
if(reserveMode == Reserve_Private) {
|
||||||
|
if(GetAllowedPlayerIndex(auth) == -1) {
|
||||||
|
KickClient(client, "Sorry, server is reserved");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Don't insert id here if admin only, let admin check do that
|
||||||
|
if(reserveMode != Reserve_AdminOnly) {
|
||||||
SteamIDs.SetValue(auth, client);
|
SteamIDs.SetValue(auth, client);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -213,26 +203,31 @@ public Action Command_SetServerPermissions(int client, int args) {
|
||||||
GetCmdArg(1, arg1, sizeof(arg1));
|
GetCmdArg(1, arg1, sizeof(arg1));
|
||||||
if(StrEqual(arg1, "public", false)) {
|
if(StrEqual(arg1, "public", false)) {
|
||||||
reserveMode = Reserve_None;
|
reserveMode = Reserve_None;
|
||||||
}else if(StrContains(arg1, "noti", false) > -1) {
|
}else if(StrContains(arg1, "noti", false) > -1 || StrContains(arg1, "watch", false) > -1) {
|
||||||
reserveMode = Reserve_Watch;
|
reserveMode = Reserve_Watch;
|
||||||
}else if(StrContains(arg1, "admin", false) > -1) {
|
}else if(StrContains(arg1, "admin", false) > -1) {
|
||||||
reserveMode = Reserve_AdminOnly;
|
reserveMode = Reserve_AdminOnly;
|
||||||
}else if(StrEqual(arg1, "private", false)) {
|
|
||||||
reserveMode = Reserve_Private;
|
|
||||||
static char auth[32];
|
|
||||||
for(int i = 1; i <= MaxClients; i++) {
|
for(int i = 1; i <= MaxClients; i++) {
|
||||||
if(IsClientConnected(i) && IsClientInGame(i) && !IsFakeClient(i)) {
|
if(IsClientConnected(i) && IsClientInGame(i) && !IsFakeClient(i)) {
|
||||||
GetClientAuthId(i, AuthId_Steam2, auth, sizeof(auth));
|
GetClientAuthId(i, AuthId_Steam2, arg1, sizeof(arg1));
|
||||||
SteamIDs.SetValue(auth, i);
|
SteamIDs.SetValue(arg1, i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}else if(StrEqual(arg1, "private", false)) {
|
||||||
|
reserveMode = Reserve_Private;
|
||||||
|
for(int i = 1; i <= MaxClients; i++) {
|
||||||
|
if(IsClientConnected(i) && IsClientInGame(i) && !IsFakeClient(i)) {
|
||||||
|
GetClientAuthId(i, AuthId_Steam2, arg1, sizeof(arg1));
|
||||||
|
SteamIDs.SetValue(arg1, i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}else {
|
}else {
|
||||||
ReplyToCommand(client, "Usage: sm_reserve [public/notify/admin/private] or no arguments to view current reservation.");
|
ReplyToCommand(client, "Usage: sm_reserve [public/notify/admin/private] or no arguments to view current reservation.");
|
||||||
return Plugin_Handled;
|
return Plugin_Handled;
|
||||||
}
|
}
|
||||||
PrintToChatAll("Server is now %s.", ReserveLevels[reserveMode]);
|
PrintChatToAdmins("Server access changed to %s", ReserveLevels[reserveMode]);
|
||||||
} else {
|
} else {
|
||||||
ReplyToCommand(client, "Server is currently %s", ReserveLevels[reserveMode]);
|
ReplyToCommand(client, "Server access level is currently %s", ReserveLevels[reserveMode]);
|
||||||
}
|
}
|
||||||
return Plugin_Handled;
|
return Plugin_Handled;
|
||||||
}
|
}
|
||||||
|
@ -245,14 +240,15 @@ public Action Timer_CheckPlayerPings(Handle timer) {
|
||||||
if(IsClientConnected(i) && IsClientInGame(i) && !IsFakeClient(i) && IsPlayerAlive(i) && GetClientTeam(i) > 1) {
|
if(IsClientConnected(i) && IsClientInGame(i) && !IsFakeClient(i) && IsPlayerAlive(i) && GetClientTeam(i) > 1) {
|
||||||
int ping = GetEntProp(GetPlayerResourceEntity(), Prop_Send, "m_iPing", _, i);
|
int ping = GetEntProp(GetPlayerResourceEntity(), Prop_Send, "m_iPing", _, i);
|
||||||
if(isHighPingIdle[i] && ping <= hPingDropThres.IntValue) {
|
if(isHighPingIdle[i] && ping <= hPingDropThres.IntValue) {
|
||||||
SDKCall(hTakeOverBot, i);
|
L4D_TakeOverBot(i);
|
||||||
isHighPingIdle[i] = false;
|
isHighPingIdle[i] = false;
|
||||||
|
iHighPingCount[i] = 0;
|
||||||
}else if(ping > hPingDropThres.IntValue) {
|
}else if(ping > hPingDropThres.IntValue) {
|
||||||
if(iHighPingCount[i]++ > 2) {
|
if(iHighPingCount[i]++ > 2) {
|
||||||
PrintToChat(i, "Due to your high ping (%d ms) you have been moved to AFK.", ping);
|
PrintToChat(i, "Due to your high ping (%d ms), you have been moved to AFK.", ping);
|
||||||
PrintToChat(i, "You will be automatically switched back once your ping restores");
|
PrintToChat(i, "You will be automatically switched back once your ping restores");
|
||||||
//PrintToChat(i, "Type /pingignore to disable this feature.");
|
//PrintToChat(i, "Type /pingignore to disable this feature.");
|
||||||
SDKCall(hGoAwayFromKeyboard, i);
|
L4D_ReplaceWithBot(i);
|
||||||
isHighPingIdle[i] = true;
|
isHighPingIdle[i] = true;
|
||||||
iHighPingCount[i] = 0;
|
iHighPingCount[i] = 0;
|
||||||
}
|
}
|
||||||
|
@ -280,7 +276,7 @@ public Action Command_RespawnAll(int client, int args) {
|
||||||
}
|
}
|
||||||
public Action Command_SwapPlayer(int client, int args) {
|
public Action Command_SwapPlayer(int client, int args) {
|
||||||
if(args < 1) {
|
if(args < 1) {
|
||||||
ReplyToCommand(client, "Usage: sm_swap <player> [player or yourself] [silent]");
|
ReplyToCommand(client, "Usage: sm_swap <player> [another player (default: self)] [\"silent\"]");
|
||||||
}else{
|
}else{
|
||||||
char arg1[64], arg2[64], arg3[8];
|
char arg1[64], arg2[64], arg3[8];
|
||||||
GetCmdArg(1, arg1, sizeof(arg1));
|
GetCmdArg(1, arg1, sizeof(arg1));
|
||||||
|
@ -621,23 +617,31 @@ public Action Cmd_SetSurvivor(int client, int args) {
|
||||||
return Plugin_Handled;
|
return Plugin_Handled;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Hide MOTD
|
||||||
public Action VGUIMenu(UserMsg msg_id, Handle bf, const int[] players, int playersNum, bool reliable, bool init) {
|
public Action VGUIMenu(UserMsg msg_id, Handle bf, const int[] players, int playersNum, bool reliable, bool init) {
|
||||||
static char buffer[5];
|
static char buffer[5];
|
||||||
BfReadString(bf, buffer, sizeof(buffer));
|
BfReadString(bf, buffer, sizeof(buffer));
|
||||||
return strcmp(buffer, "info") == 0 ? Plugin_Handled : Plugin_Continue;
|
return strcmp(buffer, "info") == 0 ? Plugin_Handled : Plugin_Continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OnClientPutInServer(int client) {
|
public void OnClientPutInServer(int client) {
|
||||||
if(!IsFakeClient(client))
|
if(!IsFakeClient(client))
|
||||||
SDKHook(client, SDKHook_WeaponEquip, Event_OnWeaponEquip);
|
SDKHook(client, SDKHook_WeaponEquip, Event_OnWeaponEquip);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OnClientDisconnect(int client) {
|
public void OnClientDisconnect(int client) {
|
||||||
|
isHighPingIdle[client] = false;
|
||||||
|
iHighPingCount[client] = 0;
|
||||||
if(IsClientConnected(client) && IsClientInGame(client) && botDropMeleeWeapon[client] > -1) {
|
if(IsClientConnected(client) && IsClientInGame(client) && botDropMeleeWeapon[client] > -1) {
|
||||||
float pos[3];
|
float pos[3];
|
||||||
GetClientAbsOrigin(client, pos);
|
GetClientAbsOrigin(client, pos);
|
||||||
TeleportEntity(botDropMeleeWeapon[client], pos, NULL_VECTOR, NULL_VECTOR);
|
TeleportEntity(botDropMeleeWeapon[client], pos, NULL_VECTOR, NULL_VECTOR);
|
||||||
botDropMeleeWeapon[client] = -1;
|
botDropMeleeWeapon[client] = -1;
|
||||||
}
|
}
|
||||||
if(!IsFakeClient(client)) {
|
}
|
||||||
|
public void Event_PlayerDisconnect(Event event, const char[] name, bool dontBroadcast) {
|
||||||
|
int client = GetClientOfUserId(event.GetInt("userid"));
|
||||||
|
if(client && !IsFakeClient(client)) {
|
||||||
static char auth[32];
|
static char auth[32];
|
||||||
GetClientAuthId(client, AuthId_Steam2, auth, sizeof(auth));
|
GetClientAuthId(client, AuthId_Steam2, auth, sizeof(auth));
|
||||||
SteamIDs.Remove(auth);
|
SteamIDs.Remove(auth);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue