kagtcprlib.client¶
Module client contains the Client class, used to create a TCPR connection to KAG. It also contains several useful utility functions for working with clients and config files.
Functions
load_clients_from_config_file (config_file_path) |
Loads a config toml file from the given path. |
run_clients (clients) |
Utility function to run all the given clients. |
Classes
Client ([nickname, host, port, rcon_password]) |
Encapsulates a TCPR connection to a specific KAG server. |
-
class
kagtcprlib.client.
Client
(nickname='client', host='localhost', port=50301, rcon_password='example')[source]¶ Bases:
object
Encapsulates a TCPR connection to a specific KAG server. The way to use a Client is to create one, add some handlers to it, and then call the client’s connect() method. Handlers are instances of kagtcprlib.handlers.BaseHandler.
Parameters: - nickname (str) – A unique nickname for the client
- host (str) – The IP address of the server
- port (int) – The server’s RCON port
- rcon_password (str) – The RCON password for the server
-
_handle_line
(line)[source]¶ Handles an incoming line from the TCPR connection, running any matching handlers.
Parameters: line (str) – The line received Returns: A list of messages to send back to KAG Return type: list(str)
-
_split_line
(line)[source]¶ Splits the line into timestamp and content.
Parameters: line (str) – Line received from KAG Returns: timestamp, content Return type: (str, str)
-
add_handler
(handler)[source]¶ Adds a new handler to the client. Handlers may be functions or instances of a Handler class.
Parameters: handler (Handler) – The handler to add
-
connect
()[source]¶ Connects to KAG and handles all TCPR lines received. Blocks until the server closes the connection.
-
connect_forever_in_thread
()[source]¶ Creates a daemon thread which runs the client, forever calling it’s connect method
Returns: the thread created Return type: threading.Thread
-
get_handler
(handler_type)[source]¶ Returns the first handler of the given type.
Parameters: handler_type (type) – The class of the handler
-
kagtcprlib.client.
load_clients_from_config_file
(config_file_path)[source]¶ Loads a config toml file from the given path. Returns a list of clients created using the parameters in the config file.
Parameters: config_file_path (str) – Path to the config .toml file Returns: List of Client instances Return type: list(Client)