I'm trying to make sure particular SteamIDs won't connect to my server. There're some conditions and custom disconnect message, so using stock ban system is not an option.
The best way would be just refusing connection
Syntax: Select all
from listeners import OnClientConnect
@OnClientConnect
def listener_on_client_connect(
allow_connect, index, name, address, reject_message, max_reject_len):
allow_connect.set_bool(False)
reject_message.set_string_array("Another time")
But OnClientConnect doesn't provide any sort of SteamID-related info, because, as far as I know, SteamID might be unknown at that time.
Then most obvious choice would be OnNetworkidValidated:
Syntax: Select all
from filters.players import PlayerIter
from listeners import OnNetworkidValidated
BANNED_STEAMID = "[U:1:66103826]"
@OnNetworkidValidated
def listener_on_networkid_validated(user_name, networkid):
if networkid != BANNED_STEAMID:
return
for player in PlayerIter():
if player.steamid == networkid:
break
else:
return
player.kick("Another time")
However, suprisingly I realized that OnNetworkidValidated is not the first listener to fire. OnClientActive happens (or at least can happen) way before OnNetworkidValidated does:
Syntax: Select all
from listeners import OnClientActive
from players.entity import Player
BANNED_STEAMID = "[U:1:66103826]"
@OnClientActive
def listener_on_client_active(index):
player = Player(index)
if player.steamid != BANNED_STEAMID:
return
player.kick("Another time")
What is more, I tested on a listen server, and sometimes OnNetworkidValidated didn't fire at all. Or it could fire when the player is already able to see server's MoTD.
So, I have several questions.
#1. What is the best way to disconnect player by their SteamID as early as possible? Preferably without them downloading the map and other resources, and preferably without "Player iPlayer has joined the server" - though the latter message can be disabled separately.
#2. What exactly OnNetworkidValidated is? Is this related to some separate verification process with SRCDS communicating with Steam? If so, if I check player's SteamID before it has been validated, is there's any chance that this SteamID was faked?
#3. Maybe there's another way to do this - hook some function that checks if player is banned via banid and apply our own checks?
P.S. As a reference, I tested the following code 2 times on a listen server (Windows, CS:S)
Syntax: Select all
from time import strftime
from core import echo_console
from listeners import OnClientActive
from listeners import OnClientConnect
from listeners import OnClientFullyConnect
from listeners import OnClientPutInServer
from listeners import OnNetworkidValidated
@OnClientActive
def listener_on_client_active(*args):
echo_console("OnClientActive at {}".format(strftime('%X')))
@OnClientConnect
def listener_on_client_connect(*args):
echo_console("OnClientConnect at {}".format(strftime('%X')))
@OnClientFullyConnect
def listener_on_client_fully_connect(*args):
echo_console("OnClientFullyConnect at {}".format(strftime('%X')))
@OnClientPutInServer
def listener_on_client_put_in_server(*args):
echo_console("OnClientPutInServer at {}".format(strftime('%X')))
@OnNetworkidValidated
def listener_on_networkid_validated(user_name, networkid):
echo_console("OnNetworkidValidated at {}".format(strftime('%X')))
First test:
Code: Select all
OnClientConnect at 21:42:54
OnNetworkidValidated at 21:42:55
OnClientPutInServer at 21:42:55
OnClientActive at 21:42:55
Second test:
Code: Select all
OnClientConnect at 21:44:15
OnClientPutInServer at 21:44:15
OnClientActive at 21:44:15
OnNetworkidValidated at 21:44:17
OnClientFullyConnect didn't fire at all.