1.1 --- a/plugins/reservedslots.sp Thu Oct 20 21:39:57 2011 -0400
1.2 +++ b/plugins/reservedslots.sp Thu Oct 20 21:42:18 2011 -0400
1.3 @@ -55,6 +55,10 @@
1.4 new Handle:sm_reserve_maxadmins;
1.5 new Handle:sm_reserve_kicktype;
1.6
1.7 +new g_SDKVersion;
1.8 +new g_SourceTV = -1;
1.9 +new g_Replay = -1;
1.10 +
1.11 enum KickType
1.12 {
1.13 Kick_HighestPing,
1.14 @@ -73,14 +77,31 @@
1.15 sm_reserve_maxadmins = CreateConVar("sm_reserve_maxadmins", "1", "Maximum amount of admins to let in the server with reserve type 2", 0, true, 0.0);
1.16 sm_reserve_kicktype = CreateConVar("sm_reserve_kicktype", "0", "How to select a client to kick (if appropriate)", 0, true, 0.0, true, 2.0);
1.17
1.18 - HookConVarChange(sm_reserved_slots, SlotsChanged);
1.19 - HookConVarChange(sm_hide_slots, SlotsChanged);
1.20 + HookConVarChange(sm_reserved_slots, SlotCountChanged);
1.21 + HookConVarChange(sm_hide_slots, SlotHideChanged);
1.22 +
1.23 + g_SDKVersion = GuessSDKVersion();
1.24 +
1.25 + if (g_SDKVersion == SOURCE_SDK_EPISODE2VALVE)
1.26 + {
1.27 + for (new i = 1; i <= MaxClients; i++)
1.28 + {
1.29 + if (IsClientSourceTV(i))
1.30 + {
1.31 + g_SourceTV = i;
1.32 + }
1.33 + else if (IsClientReplay(i))
1.34 + {
1.35 + g_Replay = i;
1.36 + }
1.37 + }
1.38 + }
1.39 }
1.40
1.41 public OnPluginEnd()
1.42 {
1.43 /* If the plugin has been unloaded, reset visiblemaxplayers. In the case of the server shutting down this effect will not be visible */
1.44 - SetConVarInt(sv_visiblemaxplayers, MaxClients);
1.45 + ResetVisibleMax();
1.46 }
1.47
1.48 public OnMapStart()
1.49 @@ -118,6 +139,18 @@
1.50
1.51 public OnClientPostAdminCheck(client)
1.52 {
1.53 + if (g_SDKVersion == SOURCE_SDK_EPISODE2VALVE)
1.54 + {
1.55 + if (IsClientSourceTV(client))
1.56 + {
1.57 + g_SourceTV = client;
1.58 + }
1.59 + else if (IsClientReplay(client))
1.60 + {
1.61 + g_Replay = client;
1.62 + }
1.63 + }
1.64 +
1.65 new reserved = GetConVarInt(sm_reserved_slots);
1.66
1.67 if (reserved > 0)
1.68 @@ -198,6 +231,18 @@
1.69
1.70 public OnClientDisconnect_Post(client)
1.71 {
1.72 + if (g_SDKVersion == SOURCE_SDK_EPISODE2VALVE)
1.73 + {
1.74 + if (client == g_SourceTV)
1.75 + {
1.76 + g_SourceTV = -1;
1.77 + }
1.78 + else if (client == g_Replay)
1.79 + {
1.80 + g_Replay = -1;
1.81 + }
1.82 + }
1.83 +
1.84 if (GetConVarBool(sm_hide_slots))
1.85 {
1.86 SetVisibleMaxSlots(GetClientCount(false), MaxClients - GetConVarInt(sm_reserved_slots));
1.87 @@ -210,12 +255,30 @@
1.88 }
1.89 }
1.90
1.91 -public SlotsChanged(Handle:convar, const String:oldValue[], const String:newValue[])
1.92 +public SlotCountChanged(Handle:convar, const String:oldValue[], const String:newValue[])
1.93 {
1.94 /* Reserved slots or hidden slots have been disabled - reset sv_visiblemaxplayers */
1.95 - if (StringToInt(newValue) == 0)
1.96 + new slotcount = GetConVarInt(convar);
1.97 + if (slotcount == 0)
1.98 + {
1.99 + ResetVisibleMax();
1.100 + }
1.101 + else if (GetConVarBool(sm_hide_slots))
1.102 {
1.103 - SetConVarInt(sv_visiblemaxplayers, MaxClients);
1.104 + SetVisibleMaxSlots(GetClientCount(false), MaxClients - slotcount);
1.105 + }
1.106 +}
1.107 +
1.108 +public SlotHideChanged(Handle:convar, const String:oldValue[], const String:newValue[])
1.109 +{
1.110 + /* Reserved slots or hidden slots have been disabled - reset sv_visiblemaxplayers */
1.111 + if (!GetConVarBool(convar))
1.112 + {
1.113 + ResetVisibleMax();
1.114 + }
1.115 + else
1.116 + {
1.117 + SetVisibleMaxSlots(GetClientCount(false), MaxClients - GetConVarInt(sm_reserved_slots));
1.118 }
1.119 }
1.120
1.121 @@ -230,9 +293,27 @@
1.122 num = limit;
1.123 }
1.124
1.125 + if (g_SDKVersion == SOURCE_SDK_EPISODE2VALVE)
1.126 + {
1.127 + if (g_SourceTV > -1)
1.128 + {
1.129 + --num;
1.130 + }
1.131 +
1.132 + if (g_Replay > -1)
1.133 + {
1.134 + --num;
1.135 + }
1.136 + }
1.137 +
1.138 SetConVarInt(sv_visiblemaxplayers, num);
1.139 }
1.140
1.141 +ResetVisibleMax()
1.142 +{
1.143 + SetConVarInt(sv_visiblemaxplayers, -1);
1.144 +}
1.145 +
1.146 SelectKickClient()
1.147 {
1.148 new KickType:type = KickType:GetConVarInt(sm_reserve_kicktype);