l4d_reservetheserver: Add check for valid admin

This commit is contained in:
Jackzie 2021-04-24 13:46:24 -05:00
parent 1369a84a09
commit a06645cd4a
No known key found for this signature in database
GPG key ID: 1E834FE36520537A
2 changed files with 33 additions and 53 deletions

Binary file not shown.

View file

@ -69,23 +69,24 @@ public void OnMapStart() {
} }
public Action Command_MakeReservation(int client, int args) { public Action Command_MakeReservation(int client, int args) {
int isAdminOnline = 0, notConnected = 0, iMaxClients = MaxClients; bool isAdminOnline, isServerEmpty = true;
for (int iClient = 1; iClient <= iMaxClients; iClient++) { if(client > 0) {
if (IsClientConnected (iClient) && IsClientInGame (iClient)) { for (int i = 1; i <= MaxClients; i++) {
AdminId admin = GetUserAdmin(iClient); if (IsClientConnected(i) && IsClientInGame(i)) {
if (GetAdminImmunityLevel(admin) >= PluginCvarImmuneLevel.IntValue) { AdminId admin = GetUserAdmin(i);
isAdminOnline = 1; if (admin != INVALID_ADMIN_ID && GetAdminImmunityLevel(admin) >= PluginCvarImmuneLevel.IntValue) {
isAdminOnline = true;
break; break;
} }
if(isServerEmpty) isServerEmpty = false;
} }
else notConnected++;
} }
}
//If there is no admins playing OR request is from server itself then reserve:
if(!isAdminOnline) if(!isAdminOnline)
{ {
LogMessage("Received server reservation request."); LogMessage("Received server reservation request.");
if(notConnected < iMaxClients) if(!isServerEmpty) {
{
if(GetConVarInt(PluginCvarMode) == 1) if(GetConVarInt(PluginCvarMode) == 1)
{ {
doRestartMap = true; doRestartMap = true;
@ -100,97 +101,77 @@ public Action Command_MakeReservation(int client, int args) {
PrintToChatAll(MESSAGE_FOR_PLAYERS_LINE4); PrintToChatAll(MESSAGE_FOR_PLAYERS_LINE4);
CreateTimer(5.0, FreeTheServer); CreateTimer(5.0, FreeTheServer);
} } else if(GetConVarInt(PluginCvarMode) == 1) {
else if(GetConVarInt(PluginCvarMode)==1)
{
DisconnectFromMatchmaking(); DisconnectFromMatchmaking();
ReloadMap(); ReloadMap();
} }
} }
else else
ReplyToCommand(client, "Server reservation request denied - admin is online!"); ReplyToCommand(client, "Server reservation request denied - admin is online!");
return Plugin_Handled; return Plugin_Handled;
} }
public Action Command_CancelReservation(int client, int args) public Action Command_CancelReservation(int client, int args) {
{
CreateTimer(0.1, MakeServerPublic); CreateTimer(0.1, MakeServerPublic);
} }
public Action FreeTheServer(Handle timer) public Action FreeTheServer(Handle timer) {
{
CallLobbyVote(); CallLobbyVote();
PassVote(); PassVote();
if(GetConVarInt(PluginCvarMode)==1) if(GetConVarInt(PluginCvarMode) == 1) {
{
DisconnectFromMatchmaking(); DisconnectFromMatchmaking();
} }
} }
public Action MakeServerPublic(Handle timer) public Action MakeServerPublic(Handle timer) {
{
ConnectToMatchmaking(); ConnectToMatchmaking();
int notConnected = 0, iMaxClients = MaxClients; int notConnected = 0;
for (int iClient = 1; iClient <= iMaxClients; iClient++) for (int i = 1; i <= MaxClients; i++)
{ {
if (IsClientConnected (iClient) && IsClientInGame (iClient)) if (IsClientConnected (i) && IsClientInGame (i))
break; break;
else else
notConnected++; notConnected++;
} }
if(notConnected==iMaxClients) if(notConnected == MaxClients)
ReloadMap(); ReloadMap();
if(HibernationCvarValue != 0 && GetConVarInt(HibernationCvar) == 0) if(HibernationCvarValue != 0 && GetConVarInt(HibernationCvar) == 0)
SetConVarInt(HibernationCvar, 1); SetConVarInt(HibernationCvar, 1);
} }
public Action MapReloadCheck(Handle timer) public Action MapReloadCheck(Handle timer) {
{ if (!isMapChange && doRestartMap) {
if (isMapChange)
return;
if(doRestartMap == true)
{
doRestartMap = false; doRestartMap = false;
ReloadMap(); ReloadMap();
} }
} }
void CallLobbyVote() void CallLobbyVote() {
{ for (int iClient = 1; iClient <= MaxClients; iClient++) {
for (int iClient = 1; iClient <= MaxClients; iClient++) if (IsClientConnected (iClient) && IsClientInGame (iClient)) {
{
if (IsClientConnected (iClient) && IsClientInGame (iClient))
{
FakeClientCommand (iClient, "callvote returntolobby"); FakeClientCommand (iClient, "callvote returntolobby");
} }
} }
} }
void PassVote() void PassVote() {
{ for(int iClient = 1; iClient <= MaxClients; iClient++) {
for(int iClient = 1; iClient <= MaxClients; iClient++) if (IsClientConnected (iClient) && IsClientInGame (iClient)) {
{
if (IsClientConnected (iClient) && IsClientInGame (iClient))
{
FakeClientCommand(iClient, "Vote Yes"); FakeClientCommand(iClient, "Vote Yes");
} }
} }
} }
void ReloadMap() void ReloadMap() {
{
GetCurrentMap(CurrentMapString, sizeof(CurrentMapString)); GetCurrentMap(CurrentMapString, sizeof(CurrentMapString));
ServerCommand("map %s", CurrentMapString); ServerCommand("map %s", CurrentMapString);
} }
void DisconnectFromMatchmaking() void DisconnectFromMatchmaking() {
{
GetConVarString(PluginCvarSearchKey, PluginSearchKeyString, sizeof(PluginSearchKeyString)); GetConVarString(PluginCvarSearchKey, PluginSearchKeyString, sizeof(PluginSearchKeyString));
SetConVarInt(SteamGroupExclusiveCvar, 1); SetConVarInt(SteamGroupExclusiveCvar, 1);
SetConVarString(SearchKeyCvar, PluginSearchKeyString); SetConVarString(SearchKeyCvar, PluginSearchKeyString);
@ -202,8 +183,7 @@ void DisconnectFromMatchmaking()
CreateTimer(GetConVarFloat(PluginCvarTimeout), MakeServerPublic); CreateTimer(GetConVarFloat(PluginCvarTimeout), MakeServerPublic);
} }
void ConnectToMatchmaking() void ConnectToMatchmaking() {
{
SetConVarInt(SteamGroupExclusiveCvar, 0); SetConVarInt(SteamGroupExclusiveCvar, 0);
SetConVarString(SearchKeyCvar, ""); SetConVarString(SearchKeyCvar, "");
} }