I wrote some code that reads the output of the rcon users
command on the CS 1.6 console. It then notifies me of any players that are not in my whitelist.csv or are in my blacklist. The program requires 3 files as inputs:
- A text file containing the raw output of the
rcon users
command on CS 1.6 console. - A CSV file containing the SteamID and name of the white-listed players.
- A CSV file containing the SteamID and name of the black-listed players.
#!/usr/bin/env python3
import csv
import re
class WhiteListVerifier:
"""
Class to check if non-white-listed players are playing CS.
"""
def __init__(self, users_filepath, whitelist_filepath, blacklist_filepath):
"""
Get filepaths and load the following files: users file , whitelist file and blacklist file
users_filepath: Path to a text file which contains the raw output of the 'rcon users' in the in-game console.
whitelist_filepath: Path to a csv file which contains Steam IDs and player-names of the white-listed players.
blacklist_filepath: Path to a csv file which contains Steam IDs, player-names and alert-message for the black-listed players.
"""
with open(users_filepath) as f:
self.users_rawcontents = f.read()
self.whitelist = list(csv.DictReader(open(whitelist_filepath)))
self.blacklist = list(csv.DictReader(open(blacklist_filepath)))
def get_playername(self, steamid, player_records):
"""
Function to return name of a person if steamid exits in given records
and return 'Unknown' otherwise.
"""
for player in player_records:
if steamid == player['Steam_ID']:
return player['Player_Name']
return 'Unknown'
def get_active_users_steamids(self):
"""
Function to extract the Steam IDs using output of 'rcon users' command.
"""
active_users_steamids = re.findall(r'STEAM_[0-5]:[01]:\d+', self.users_rawcontents)
return active_users_steamids
def verify_steamids(self):
"""
Function to alert if people other than the ones mentioned in the whitelist are playing.
"""
active_users_steamids = self.get_active_users_steamids()
num_nonwhitelisted_users = 0
for active_user in active_users_steamids:
player = self.get_playername(active_user, self.whitelist)
if player is 'Unknown':
num_nonwhitelisted_users += 1
nonwhitelisted_playername = self.get_playername(active_user, self.blacklist)
print('-- nonwhitelisted player: '+str(nonwhitelisted_playername))
print('>> Total number of non-whitelisted players: '+str(num_nonwhitelisted_users))
if __name__ == '__main__':
checker = WhiteListVerifier('data/users.txt', 'data/whitelist.csv', 'data/blacklist.csv')
checker.verify_steamids()