@@ -93,7 +93,42 @@ def connect(
9393 rlbot_server_ip = rlbot_server_ip ,
9494 rlbot_server_port = rlbot_server_port or self .rlbot_server_port ,
9595 )
96- self .rlbot_interface .run (background_thread = True )
96+
97+ def run (self , * , background_thread : bool = False ):
98+ """
99+ Handle incoming messages until disconnected.
100+
101+ - background_thread: If `True`, a background thread will be started to process messages.
102+ """
103+ self .rlbot_interface .run (background_thread = background_thread )
104+
105+ def connect_and_run (
106+ self ,
107+ * ,
108+ wants_match_communications : bool ,
109+ wants_ball_predictions : bool ,
110+ close_between_matches : bool = True ,
111+ rlbot_server_ip : str = RLBOT_SERVER_IP ,
112+ rlbot_server_port : Optional [int ] = None ,
113+ background_thread : bool = False ,
114+ ):
115+ """
116+ Connects to the RLBot server specifying the given settings.
117+
118+ - wants_match_communications: Whether match communication messages should be sent to this process.
119+ - wants_ball_predictions: Whether ball prediction messages should be sent to this process.
120+ - close_between_matches: Whether RLBot should close this connection between matches, specifically upon
121+ `StartMatch` and `StopMatch` messages, since RLBot does not actually detect the ending of matches.
122+ - background_thread: If `True`, a background thread will be started to process messages.
123+ """
124+ self .connect (
125+ wants_match_communications = wants_match_communications ,
126+ wants_ball_predictions = wants_ball_predictions ,
127+ close_between_matches = close_between_matches ,
128+ rlbot_server_ip = rlbot_server_ip ,
129+ rlbot_server_port = rlbot_server_port ,
130+ )
131+ self .run (background_thread = background_thread )
97132
98133 def wait_for_first_packet (self ):
99134 while self .packet is None or self .packet .match_info .match_phase in {
@@ -118,10 +153,11 @@ def start_match(
118153 self .ensure_server_started ()
119154
120155 if not self .rlbot_interface .is_connected :
121- self .connect (
156+ self .connect_and_run (
122157 wants_match_communications = False ,
123158 wants_ball_predictions = False ,
124159 close_between_matches = False ,
160+ background_thread = True ,
125161 )
126162
127163 self .rlbot_interface .start_match (config )
0 commit comments