@@ -94,6 +94,42 @@ def connect(
9494 rlbot_server_port = rlbot_server_port or self .rlbot_server_port ,
9595 )
9696
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 )
132+
97133 def wait_for_first_packet (self ):
98134 while self .packet is None or self .packet .match_info .match_phase in {
99135 flat .MatchPhase .Inactive ,
@@ -117,12 +153,12 @@ def start_match(
117153 self .ensure_server_started ()
118154
119155 if not self .rlbot_interface .is_connected :
120- self .connect (
156+ self .connect_and_run (
121157 wants_match_communications = False ,
122158 wants_ball_predictions = False ,
123159 close_between_matches = False ,
160+ background_thread = True ,
124161 )
125- self .rlbot_interface .run (background_thread = True )
126162
127163 self .rlbot_interface .start_match (config )
128164
@@ -136,7 +172,7 @@ def start_match(
136172
137173 def disconnect (self ):
138174 """
139- Disconnect from the RLBotServer.
175+ Disconnect from RLBotServer.
140176 Note that the server will continue running as long as Rocket League does.
141177 """
142178 self .rlbot_interface .disconnect ()
@@ -167,8 +203,8 @@ def shut_down(self, use_force_if_necessary: bool = True):
167203
168204 self .logger .info ("Shutting down RLBot..." )
169205
170- # In theory this is all we need for the server to cleanly shut itself down
171206 try :
207+ # In theory this is all we need for the server to cleanly shut itself down
172208 self .rlbot_interface .stop_match (shutdown_server = True )
173209 except BrokenPipeError :
174210 match gateway .find_server_process (self .main_executable_name )[0 ]:
0 commit comments