-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add kick_survivor.py example (#6)
Co-authored-by: thegamecracks <61257169+thegamecracks@users.noreply.github.com>
- Loading branch information
1 parent
ae821eb
commit 4d820ef
Showing
1 changed file
with
27 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
"""Connects to an RCON server and kicks players with "Survivor" as their name.""" | ||
import asyncio | ||
import math | ||
import re | ||
|
||
import berconpy as rcon | ||
|
||
IP_ADDR = "XXX.XXX.XXX.XXX" | ||
PORT = 9999 | ||
PASSWORD = "ASCII_PASSWORD" | ||
|
||
client = rcon.AsyncRCONClient() | ||
|
||
|
||
@client.dispatch.on_player_connect | ||
async def on_player_connect(player: rcon.Player): | ||
if re.match(r"Survivor(?: \(\d+\))?", player.name) is not None: | ||
await player.kick("Name 'Survivor' not allowed") | ||
|
||
|
||
async def main(): | ||
async with client.connect(IP_ADDR, PORT, PASSWORD): | ||
await asyncio.sleep(math.inf) | ||
|
||
|
||
if __name__ == "__main__": | ||
asyncio.run(main()) |