Apply general optimizations in adminslots plugin (bug 5831, r=arkshine)

Former-commit-id: 1ea1766188a73cb80a50396fb2b88e11c88bc1e1
This commit is contained in:
connorr 2013-08-05 18:26:57 +02:00
parent 2385dd3972
commit 16b2721c2a

View File

@ -37,6 +37,8 @@
new g_ResPtr new g_ResPtr
new g_HidePtr new g_HidePtr
new g_sv_visiblemaxplayers
new g_maxplayers
public plugin_init() public plugin_init()
{ {
@ -45,6 +47,8 @@ public plugin_init()
register_dictionary("common.txt") register_dictionary("common.txt")
g_ResPtr = register_cvar("amx_reservation", "0") g_ResPtr = register_cvar("amx_reservation", "0")
g_HidePtr = register_cvar("amx_hideslots", "0") g_HidePtr = register_cvar("amx_hideslots", "0")
g_sv_visiblemaxplayers = get_cvar_pointer("sv_visiblemaxplayers")
g_maxplayers = get_maxplayers()
} }
public plugin_cfg() public plugin_cfg()
@ -54,54 +58,43 @@ public plugin_cfg()
public MapLoaded() public MapLoaded()
{ {
if (!get_pcvar_num(g_HidePtr)) if (get_pcvar_num(g_HidePtr))
return {
setVisibleSlots(get_playersnum(1), g_maxplayers - get_pcvar_num(g_ResPtr))
new maxplayers = get_maxplayers() }
new players = get_playersnum(1)
new limit = maxplayers - get_pcvar_num(g_ResPtr)
setVisibleSlots(players, maxplayers, limit)
} }
public client_authorized(id) public client_authorized(id)
{ {
new maxplayers = get_maxplayers()
new players = get_playersnum(1) new players = get_playersnum(1)
new limit = maxplayers - get_pcvar_num(g_ResPtr) new limit = g_maxplayers - get_pcvar_num(g_ResPtr)
if (access(id, ADMIN_RESERVATION) || (players <= limit)) if (access(id, ADMIN_RESERVATION) || (players <= limit))
{ {
if (get_pcvar_num(g_HidePtr) == 1) if (get_pcvar_num(g_HidePtr))
setVisibleSlots(players, maxplayers, limit) setVisibleSlots(players, limit)
return PLUGIN_CONTINUE return
} }
new lReason[64] server_cmd("kick #%d ^"%L^"", get_user_userid(id), id, "DROPPED_RES")
format(lReason, 63, "%L", id, "DROPPED_RES")
server_cmd("kick #%d ^"%s^"", get_user_userid(id), lReason)
return PLUGIN_HANDLED
} }
public client_disconnect(id) public client_disconnect(id)
{ {
if (!get_pcvar_num(g_HidePtr)) if (get_pcvar_num(g_HidePtr))
return PLUGIN_CONTINUE {
setVisibleSlots(get_playersnum(1) - 1, g_maxplayers - get_pcvar_num(g_ResPtr))
new maxplayers = get_maxplayers() }
setVisibleSlots(get_playersnum(1) - 1, maxplayers, maxplayers - get_pcvar_num(g_ResPtr))
return PLUGIN_CONTINUE
} }
setVisibleSlots(players, maxplayers, limit) setVisibleSlots(players, limit)
{ {
new num = players + 1 new num = players + 1
if (players == maxplayers) if (players == g_maxplayers)
num = maxplayers num = g_maxplayers
else if (players < limit) else if (players < limit)
num = limit num = limit
set_cvar_num("sv_visiblemaxplayers", num) set_pcvar_num(g_sv_visiblemaxplayers, num)
} }