1.1 --- a/core/smn_banning.cpp Fri Sep 14 02:20:23 2007 +0000
1.2 +++ b/core/smn_banning.cpp Fri Sep 14 03:01:14 2007 +0000
1.3 @@ -54,7 +54,7 @@
1.4 {
1.5 g_pOnBanClient = g_Forwards.CreateForward(
1.6 "OnBanClient",
1.7 - ET_Ignore,
1.8 + ET_Event,
1.9 7,
1.10 NULL,
1.11 Param_Cell,
1.12 @@ -66,7 +66,7 @@
1.13 Param_Cell);
1.14 g_pOnBanIdentity = g_Forwards.CreateForward(
1.15 "OnBanIdentity",
1.16 - ET_Ignore,
1.17 + ET_Event,
1.18 6,
1.19 NULL,
1.20 Param_String,
1.21 @@ -77,7 +77,7 @@
1.22 Param_Cell);
1.23 g_pOnRemoveBan = g_Forwards.CreateForward(
1.24 "OnRemoveBan",
1.25 - ET_Ignore,
1.26 + ET_Event,
1.27 4,
1.28 NULL,
1.29 Param_String,
1.30 @@ -122,6 +122,7 @@
1.31 strncopy(identity, r_identity, sizeof(identity));
1.32 UTIL_ReplaceAll(identity, sizeof(identity), ";", "");
1.33
1.34 + cell_t handled = 0;
1.35 if (ban_cmd[0] != '\0' && g_pOnBanIdentity->GetFunctionCount() > 0)
1.36 {
1.37 g_pOnBanIdentity->PushString(identity);
1.38 @@ -130,45 +131,48 @@
1.39 g_pOnBanIdentity->PushString(ban_reason);
1.40 g_pOnBanIdentity->PushString(ban_cmd);
1.41 g_pOnBanIdentity->PushCell(ban_source);
1.42 - g_pOnBanIdentity->Execute(NULL);
1.43 + g_pOnBanIdentity->Execute(&handled);
1.44 }
1.45
1.46 - bool write_ban = ((ban_flags & BANFLAG_NOWRITE) != BANFLAG_NOWRITE);
1.47 -
1.48 - char command[256];
1.49 - if (ban_by_ip)
1.50 + if (!handled)
1.51 {
1.52 - UTIL_Format(
1.53 - command,
1.54 - sizeof(command),
1.55 - "addip %d %s\n",
1.56 - ban_time,
1.57 - identity);
1.58 - engine->ServerCommand(command);
1.59 + bool write_ban = ((ban_flags & BANFLAG_NOWRITE) != BANFLAG_NOWRITE);
1.60
1.61 - if (write_ban && ban_time == 0)
1.62 + char command[256];
1.63 + if (ban_by_ip)
1.64 {
1.65 - engine->ServerCommand("writeip\n");
1.66 + UTIL_Format(
1.67 + command,
1.68 + sizeof(command),
1.69 + "addip %d %s\n",
1.70 + ban_time,
1.71 + identity);
1.72 + engine->ServerCommand(command);
1.73 +
1.74 + if (write_ban && ban_time == 0)
1.75 + {
1.76 + engine->ServerCommand("writeip\n");
1.77 + }
1.78 }
1.79 - }
1.80 - else if (!g_HL2.IsLANServer())
1.81 - {
1.82 - UTIL_Format(
1.83 - command,
1.84 - sizeof(command),
1.85 - "banid %d %s\n",
1.86 - ban_time,
1.87 - identity);
1.88 - engine->ServerCommand(command);
1.89 -
1.90 - if (write_ban && ban_time == 0)
1.91 + else if (!g_HL2.IsLANServer())
1.92 {
1.93 - engine->ServerCommand("writeid\n");
1.94 + UTIL_Format(
1.95 + command,
1.96 + sizeof(command),
1.97 + "banid %d %s\n",
1.98 + ban_time,
1.99 + identity);
1.100 + engine->ServerCommand(command);
1.101 +
1.102 + if (write_ban && ban_time == 0)
1.103 + {
1.104 + engine->ServerCommand("writeid\n");
1.105 + }
1.106 }
1.107 - }
1.108 - else
1.109 - {
1.110 - return 0;
1.111 + else
1.112 + {
1.113 + return 0;
1.114 + }
1.115 }
1.116
1.117 return 1;
1.118 @@ -195,35 +199,42 @@
1.119 strncopy(identity, r_identity, sizeof(identity));
1.120 UTIL_ReplaceAll(identity, sizeof(identity), ";", "");
1.121
1.122 + cell_t handled = 0;
1.123 if (ban_cmd[0] != '\0' && g_pOnRemoveBan->GetFunctionCount() > 0)
1.124 {
1.125 g_pOnRemoveBan->PushString(identity);
1.126 g_pOnRemoveBan->PushCell(ban_flags);
1.127 g_pOnRemoveBan->PushString(ban_cmd);
1.128 g_pOnRemoveBan->PushCell(ban_source);
1.129 - g_pOnRemoveBan->Execute(NULL);
1.130 + g_pOnRemoveBan->Execute(&handled);
1.131 }
1.132
1.133 char command[256];
1.134 if (ban_by_ip)
1.135 {
1.136 - UTIL_Format(
1.137 - command,
1.138 - sizeof(command),
1.139 - "removeip %s\n",
1.140 - identity);
1.141 - engine->ServerCommand(command);
1.142 - engine->ServerCommand("writeip\n");
1.143 + if (!handled)
1.144 + {
1.145 + UTIL_Format(
1.146 + command,
1.147 + sizeof(command),
1.148 + "removeip %s\n",
1.149 + identity);
1.150 + engine->ServerCommand(command);
1.151 + engine->ServerCommand("writeip\n");
1.152 + }
1.153 }
1.154 else if (!g_HL2.IsLANServer())
1.155 {
1.156 - UTIL_Format(
1.157 - command,
1.158 - sizeof(command),
1.159 - "removeid %s\n",
1.160 - identity);
1.161 - engine->ServerCommand(command);
1.162 - engine->ServerCommand("writeid\n");
1.163 + if (!handled)
1.164 + {
1.165 + UTIL_Format(
1.166 + command,
1.167 + sizeof(command),
1.168 + "removeid %s\n",
1.169 + identity);
1.170 + engine->ServerCommand(command);
1.171 + engine->ServerCommand("writeid\n");
1.172 + }
1.173 }
1.174 else
1.175 {
1.176 @@ -293,6 +304,7 @@
1.177 return pContext->ThrowNativeError("No valid ban method flags specified");
1.178 }
1.179
1.180 + cell_t handled = 0;
1.181 if (ban_cmd[0] != '\0' && g_pOnBanClient->GetFunctionCount() > 0)
1.182 {
1.183 g_pOnBanClient->PushCell(client);
1.184 @@ -302,7 +314,7 @@
1.185 g_pOnBanClient->PushString(kick_message);
1.186 g_pOnBanClient->PushString(ban_cmd);
1.187 g_pOnBanClient->PushCell(ban_source);
1.188 - g_pOnBanClient->Execute(NULL);
1.189 + g_pOnBanClient->Execute(&handled);
1.190 }
1.191
1.192 /* Sanitize the kick message */
1.193 @@ -311,61 +323,68 @@
1.194 kick_message = "Kicked";
1.195 }
1.196
1.197 - if ((ban_flags & BANFLAG_IP) == BANFLAG_IP)
1.198 + if (!handled)
1.199 {
1.200 - /* Get the IP address and strip the port */
1.201 - char ip[24], *ptr;
1.202 - strncopy(ip, pPlayer->GetIPAddress(), sizeof(ip));
1.203 - if ((ptr = strchr(ip, ':')) != NULL)
1.204 + if ((ban_flags & BANFLAG_IP) == BANFLAG_IP)
1.205 {
1.206 - *ptr = '\0';
1.207 - }
1.208 -
1.209 - /* Tell the server to ban the ip */
1.210 - char command[256];
1.211 - UTIL_Format(
1.212 - command,
1.213 - sizeof(command),
1.214 - "addip %d %s\n",
1.215 - ban_time,
1.216 - ip);
1.217 -
1.218 - /* Kick, then ban */
1.219 - if ((ban_flags & BANFLAG_NOKICK) != BANFLAG_NOKICK)
1.220 + /* Get the IP address and strip the port */
1.221 + char ip[24], *ptr;
1.222 + strncopy(ip, pPlayer->GetIPAddress(), sizeof(ip));
1.223 + if ((ptr = strchr(ip, ':')) != NULL)
1.224 + {
1.225 + *ptr = '\0';
1.226 + }
1.227 +
1.228 + /* Tell the server to ban the ip */
1.229 + char command[256];
1.230 + UTIL_Format(
1.231 + command,
1.232 + sizeof(command),
1.233 + "addip %d %s\n",
1.234 + ban_time,
1.235 + ip);
1.236 +
1.237 + /* Kick, then ban */
1.238 + if ((ban_flags & BANFLAG_NOKICK) != BANFLAG_NOKICK)
1.239 + {
1.240 + pClient->Disconnect("%s", kick_message);
1.241 + }
1.242 + engine->ServerCommand(command);
1.243 +
1.244 + /* Physically write the ban */
1.245 + if ((ban_time == 0) && ((ban_flags & BANFLAG_NOWRITE) != BANFLAG_NOWRITE))
1.246 + {
1.247 + engine->ServerCommand("writeip\n");
1.248 + }
1.249 + }
1.250 + else if ((ban_flags & BANFLAG_AUTHID) == BANFLAG_AUTHID)
1.251 {
1.252 - pClient->Disconnect("%s", kick_message);
1.253 - }
1.254 - engine->ServerCommand(command);
1.255 + /* Tell the server to ban the auth string */
1.256 + char command[256];
1.257 + UTIL_Format(
1.258 + command,
1.259 + sizeof(command),
1.260 + "banid %d %s\n",
1.261 + ban_time,
1.262 + pPlayer->GetAuthString());
1.263 +
1.264 + /* Kick, then ban */
1.265 + if ((ban_flags & BANFLAG_NOKICK) != BANFLAG_NOKICK)
1.266 + {
1.267 + pClient->Disconnect("%s", kick_message);
1.268 + }
1.269 + engine->ServerCommand(command);
1.270
1.271 - /* Physically write the ban */
1.272 - if ((ban_time == 0) && ((ban_flags & BANFLAG_NOWRITE) != BANFLAG_NOWRITE))
1.273 - {
1.274 - engine->ServerCommand("writeip\n");
1.275 - }
1.276 - }
1.277 - else if ((ban_flags & BANFLAG_AUTHID) == BANFLAG_AUTHID)
1.278 + /* Physically write the ban if it's permanent */
1.279 + if ((ban_time == 0) && ((ban_flags & BANFLAG_NOWRITE) != BANFLAG_NOWRITE))
1.280 + {
1.281 + engine->ServerCommand("writeid\n");
1.282 + }
1.283 + }
1.284 + }
1.285 + else if ((ban_flags & BANFLAG_NOKICK) != BANFLAG_NOKICK)
1.286 {
1.287 - /* Tell the server to ban the auth string */
1.288 - char command[256];
1.289 - UTIL_Format(
1.290 - command,
1.291 - sizeof(command),
1.292 - "banid %d %s\n",
1.293 - ban_time,
1.294 - pPlayer->GetAuthString());
1.295 -
1.296 - /* Kick, then ban */
1.297 - if ((ban_flags & BANFLAG_NOKICK) != BANFLAG_NOKICK)
1.298 - {
1.299 - pClient->Disconnect("%s", kick_message);
1.300 - }
1.301 - engine->ServerCommand(command);
1.302 -
1.303 - /* Physically write the ban if it's permanent */
1.304 - if ((ban_time == 0) && ((ban_flags & BANFLAG_NOWRITE) != BANFLAG_NOWRITE))
1.305 - {
1.306 - engine->ServerCommand("writeid\n");
1.307 - }
1.308 + pClient->Disconnect("%s", kick_message);
1.309 }
1.310
1.311