55from utils import success , send
66import bascenev1 as bs
77import babase as ba
8- from clients import Client , get_clients , get_client
8+ from clients import Client , Player , get_client
99
1010# =================== #
1111# USER COMMANDS #
1212# =================== #
1313@on_command (name = "/list" , aliases = ["/ls" ])
1414def list (client : Client ):
15- """ shows the client a list of clients. """
16- clients = get_clients ()
17- heads = u"{0:^16}{1:^16}"
15+ """ shows the client, a list of players. """
16+ heads = u"{0:^16}{1:^14}{2:^12}"
1817 sep = "\n ------------------------------------------------------\n "
19- string = heads .format ("Name" , "Client ID" ) + sep
20- for i in clients :
21- string += heads .format (i . name , i . client_id ) + "\n "
18+ string = heads .format ("Name" , "Client ID" , "Index ID" ) + sep
19+ for index , player in enumerate ( bs . get_foreground_host_session (). sessionplayers ) :
20+ string += heads .format (player . getname ( True , False ), player . inputdevice . client_id , index ) + "\n "
2221 client .success (string )
2322
2423@on_command (name = "/pb" , aliases = ["/ac" , "/id" ])
25- def show_account_id (client : Client , args : list [ str ] ):
24+ def show_account_id (client : Client , target : Client ):
2625 """Shows the client's or target's account ID."""
27- target = get_client ( int ( args [ 0 ])) if args else client
26+ target = target or client
2827 client .send (target .account_id , sender = f"{ target .name } 's ID" )
2928
3029@on_command (name = "/pm" , aliases = ["/dm" ], usage = "/pm <client id> <message>" )
31- def private_message (client : Client , args : list [str ]):
32- """Sends a private message to another client."""
33- target = int (args [0 ])
34- target = get_client (target )
30+ def private_message (client : Client , target : Client ):
31+ """Sends a private message to target client."""
3532 message = " " .join (args [1 :])
3633 name = f"{ client .name } (pvt)"
3734 target .send (message , sender = name )
@@ -48,10 +45,33 @@ def end_game(client: Client):
4845 activity .end_game ()
4946 success (f"{ client .name } ended the game" )
5047
51- @on_command (name = "/kill" , authority = Authority .ADMIN , usage = "/kill <client_id >" )
52- def kill_player (client : Client , args : list [ str ] ):
48+ @on_command (name = "/kill" , authority = Authority .ADMIN , usage = "/kill <index id >" )
49+ def kill_player (client : Client , player : Player ):
5350 """Kill target player"""
54- get_client (int (args [0 ])).player .kill ()
51+ player .kill ()
52+
53+ @on_command (name = "/freeze" , authority = Authority .ADMIN , usage = "/freeze <index id>" )
54+ def freeze_player (client : Client , player : Player ):
55+ """Freeze target player"""
56+ player .freeze ()
57+
58+ @on_command (name = "/thaw" , authority = Authority .ADMIN , usage = "/thaw <index id>" )
59+ def thaw_player (client : Client , player : Player ):
60+ """thaw the freezed target player"""
61+ player .thaw ()
62+
63+ @on_command (name = "/remove" , aliases = ["/rm" ], authority = Authority .ADMIN , usage = "/remove <index id>" )
64+ def remove_player (client : Client , player : Player ):
65+ """Remove player from game"""
66+ player .remove ()
67+ client .success (f"Removed { player .name } " )
68+
69+ @on_command (name = "/info" , aliases = ["/gp" , "/profiles" , "/pf" ], authority = Authority .ADMIN , usage = "/info <index id>" )
70+ def show_profiles (client : Client , player : Player ):
71+ """Show player profiles"""
72+ profiles = player .profiles ()
73+ for index , profile in enumerate (profiles , start = 1 ):
74+ client .send (f"{ profile } " , sender = f"{ index } " )
5575
5676@on_command (name = "/say" , authority = Authority .ADMIN , usage = "/say <message>" )
5777def server_say (client : Client , args : list [str ]):
@@ -67,22 +87,15 @@ def server_say(client: Client, args: list[str]):
6787 send (message )
6888
6989@on_command (name = "/kick" , authority = Authority .ADMIN , usage = "/kick <client id>" )
70- def kick_player (client : Client , args : list [ str ] ):
90+ def kick_player (client : Client , target : Client ):
7191 """Kicks a player from the server."""
72- if target := get_client ( args [ 0 ]) :
92+ if target :
7393 if target .authority < client .authority :
7494 target .kick ()
7595 client .success (f"kicked { target .name } " )
7696 else :
7797 client .error (f"Cannot kick { target .name } (higher authority)" )
7898
79- @on_command (name = "/info" , aliases = ["/gp" , "/profiles" , "/pf" ], authority = Authority .ADMIN , usage = "/info <client_id>" )
80- def show_profiles (client : Client , args : list [str ]):
81- """Show player profiles"""
82- profiles = get_client (int (args [0 ])).player .profiles ()
83- for index , profile in enumerate (profiles , start = 1 ):
84- client .send (f"{ profile } " , sender = f"{ index } " )
85-
8699@on_command (name = "/resume" , authority = Authority .ADMIN )
87100def resume_game (client : Client ):
88101 """Resume paused game"""
@@ -113,24 +126,15 @@ def set_max_players(client: Client, args: list[str]):
113126 bs .get_foreground_host_session ().max_players = limit
114127 client .success (f"Limit set to { limit } " )
115128
116- @on_command (name = "/remove" , aliases = ["/rm" ], authority = Authority .ADMIN , usage = "/remove <client_id>" )
117- def remove_player (client : Client , args : list [str ]):
118- """Remove player from game"""
119- target = get_client (int (args [0 ]))
120- if not target .in_lobby :
121- target .player .remove ()
122- client .success (f"Removed { target .name } " )
123-
124129@on_command (name = "/spectator" , aliases = ["/lobby" ], authority = Authority .ADMIN )
125130def toggle_spectators (client : Client ):
126131 """Toggle spectator mode"""
127132 status = "allowed" if bs .storage .config .toggle (Utility .SPECTATOR ) else "disallowed"
128133 success (f"{ client .name } has { status } spectators" )
129134
130135@on_command (name = "/mute" , authority = Authority .ADMIN , usage = "/mute <client_id>" )
131- def mute_player (client : Client , args : list [ str ] ):
136+ def mute_player (client : Client , target : Client ):
132137 """Mute player"""
133- target = get_client (int (args [0 ]))
134138 if target .authority < client .authority :
135139 if target .mute ():
136140 client .success (f"Muted { target .name } " )
@@ -140,9 +144,8 @@ def mute_player(client: Client, args: list[str]):
140144
141145
142146@on_command (name = "/unmute" , authority = Authority .ADMIN , usage = "/unmute <client_id>" )
143- def unmute_player (client : Client , args : list [ str ] ):
147+ def unmute_player (client : Client , target : Client ):
144148 """Unmute player"""
145- target = get_client (int (args [0 ]))
146149 if target .unmute ():
147150 client .success (f"Unmuted { target .name } " )
148151 target .success (f"You've been unmuted by { client .name } " )
@@ -161,18 +164,17 @@ def set_teams_playlist(client: Client):
161164# LEADER COMMANDS #
162165# =================== #
163166
164- @on_command (name = "/ban" , authority = Authority .LEADER , usage = "/ban <client_id >" )
165- def ban_player (client : Client , args : list [ str ] ):
167+ @on_command (name = "/ban" , authority = Authority .LEADER , usage = "/ban <account_id >" )
168+ def ban_player (client : Client , account_id : str ):
166169 """Ban player"""
167- target = get_client (int (args [0 ]))
168- bs .storage .roles .add (Role .BANLIST , target .account_id )
169- client .success (f"Banned { target .name } " )
170+ bs .storage .roles .add (Role .BANLIST , account_id )
171+ client .success (f"Banned { account_id } " )
170172
171173@on_command (name = "/unban" , authority = Authority .LEADER , usage = "/unban <account_id>" )
172- def unban_player (client : Client , args : list [ str ] ):
174+ def unban_player (client : Client , account_id : str ):
173175 """Unban account"""
174- bs .storage .roles .remove (Role .BANLIST , args [ 0 ] )
175- client .success (f"Unbanned { args [ 0 ] } " )
176+ bs .storage .roles .remove (Role .BANLIST , account_id )
177+ client .success (f"Unbanned { account_id } " )
176178
177179@on_command (name = "/whitelist" , aliases = ["/wl" ], authority = Authority .LEADER )
178180def toggle_whitelist (client : Client ):
@@ -181,27 +183,25 @@ def toggle_whitelist(client: Client):
181183 success (f"{ client .name } has { status } whitelist" )
182184
183185@on_command (name = "/addwl" , authority = Authority .LEADER , usage = "/addwl <account_id>" )
184- def add_to_whitelist (client : Client , args : list [ str ] ):
186+ def add_to_whitelist (client : Client , account_id : str ):
185187 """Add to whitelist"""
186- bs .storage .roles .add (Role .WHITELIST , args [ 0 ] )
187- client .success (f"Whitelisted { args [ 0 ] } " )
188+ bs .storage .roles .add (Role .WHITELIST , account_id )
189+ client .success (f"Whitelisted { account_id } " )
188190
189191@on_command (name = "/removewl" , aliases = ["/rmwl" ], authority = Authority .LEADER , usage = "/removewl <account_id>" )
190- def remove_from_whitelist (client : Client , args : list [ str ] ):
192+ def remove_from_whitelist (client : Client , account_id : str ):
191193 """Remove from whitelist"""
192- bs .storage .roles .remove (Role .WHITELIST , args [ 0 ] )
193- client .success (f"Removed { args [ 0 ] } from whitelist" )
194+ bs .storage .roles .remove (Role .WHITELIST , account_id )
195+ client .success (f"Removed { account_id } from whitelist" )
194196
195197@on_command (name = "/admin" , authority = Authority .LEADER , usage = "/admin <client_id>" )
196- def add_admin (client : Client , args : list [ str ] ):
198+ def add_admin (client : Client , target : Client ):
197199 """Add admin"""
198- target = get_client (int (args [0 ]))
199200 bs .storage .roles .add (Role .ADMIN , target .account_id )
200201 client .success (f"Added { target .name } as admin" )
201202
202203@on_command (name = "/rmadmin" , authority = Authority .LEADER , usage = "/rmadmin <client_id>" )
203- def remove_admin (client : Client , args : list [ str ] ):
204+ def remove_admin (client : Client , target : Client ):
204205 """Remove admin"""
205- target = get_client (int (args [0 ]))
206206 bs .storage .roles .remove (Role .ADMIN , target .account_id )
207207 client .success (f"Removed { target .name } as admin" )
0 commit comments