44import aiohttp
55from loguru import logger
66
7- import sc2
87from sc2 .client import Client
8+ from sc2 .main import _play_game
9+ from sc2 .portconfig import Portconfig
910from sc2 .protocol import ConnectionAlreadyClosedError
1011
1112
@@ -41,7 +42,7 @@ def run_ladder_game(bot):
4142 else :
4243 ports = [lan_port + p for p in range (1 , 6 )]
4344
44- portconfig = sc2 . portconfig . Portconfig ()
45+ portconfig = Portconfig ()
4546 portconfig .server = [ports [1 ], ports [2 ]]
4647 portconfig .players = [[ports [3 ], ports [4 ]]]
4748
@@ -56,10 +57,11 @@ def run_ladder_game(bot):
5657# Modified version of sc2.main._join_game to allow custom host and port, and to not spawn an additional sc2process (thanks to alkurbatov for fix)
5758async def join_ladder_game (host , port , players , realtime , portconfig , save_replay_as = None , game_time_limit = None ):
5859 ws_url = f"ws://{ host } :{ port } /sc2api"
60+ # pyrefly: ignore
5961 ws_connection = await aiohttp .ClientSession ().ws_connect (ws_url , timeout = 120 )
6062 client = Client (ws_connection )
6163 try :
62- result = await sc2 . main . _play_game (players [0 ], client , realtime , portconfig , game_time_limit )
64+ result = await _play_game (players [0 ], client , realtime , portconfig , game_time_limit )
6365 if save_replay_as is not None :
6466 await client .save_replay (save_replay_as )
6567 # await client.leave()
@@ -68,6 +70,6 @@ async def join_ladder_game(host, port, players, realtime, portconfig, save_repla
6870 logger .error ("Connection was closed before the game ended" )
6971 return None
7072 finally :
71- ws_connection .close ()
73+ await ws_connection .close ()
7274
7375 return result
0 commit comments