|
12 | 12 | from BF2AutoSpectator.common.exceptions import SpawnCoordinatesNotAvailableException |
13 | 13 | from BF2AutoSpectator.common.logger import logger |
14 | 14 | from BF2AutoSpectator.common.utility import is_responding_pid, find_window_by_title, taskkill_pid, init_pytesseract |
15 | | -from BF2AutoSpectator.game import GameInstanceManager |
| 15 | +from BF2AutoSpectator.game import GameInstanceManager, GameMessage |
16 | 16 | from BF2AutoSpectator.remote import ControllerClient, GamePhase, OBSClient |
17 | 17 | from BF2AutoSpectator.global_state import GlobalState |
18 | 18 |
|
@@ -367,41 +367,39 @@ def run(): |
367 | 367 |
|
368 | 368 | continue |
369 | 369 |
|
370 | | - # Make sure we are still in the game |
371 | 370 | if gim.is_game_message_visible(): |
372 | 371 | logger.debug('Game message present, ocr-ing message') |
373 | | - game_message = gim.ocr_game_message() |
| 372 | + game_message, raw_message = gim.get_game_message() |
374 | 373 |
|
375 | | - if 'full' in game_message: |
| 374 | + if game_message is GameMessage.ServerFull: |
376 | 375 | logger.warning('Server full, trying to rejoin in 20 seconds') |
377 | 376 | gis.set_spectator_on_server(False) |
378 | 377 | time.sleep(20) |
379 | | - elif 'kicked' in game_message: |
| 378 | + elif game_message is GameMessage.Kicked: |
380 | 379 | logger.warning('Got kicked, trying to rejoin') |
381 | 380 | gis.set_spectator_on_server(False) |
382 | | - elif 'banned' in game_message and not (gis.halted() and not gs.halted()): |
| 381 | + elif game_message is GameMessage.Banned and not (gis.halted() and not gs.halted()): |
383 | 382 | logger.critical('Got banned, contact server admin') |
384 | 383 | gis.set_spectator_on_server(False) |
385 | 384 | gis.set_halted(True) |
386 | 385 | gs.set_halted(True) |
387 | | - elif 'connection' in game_message and 'lost' in game_message or \ |
388 | | - 'failed to connect' in game_message: |
389 | | - logger.error('Connection lost, trying to reconnect') |
| 386 | + elif game_message is GameMessage.ConnectionLost or game_message is GameMessage.ConnectionFailed: |
| 387 | + logger.error('Connection lost/failed, trying to reconnect') |
390 | 388 | gis.set_spectator_on_server(False) |
391 | | - elif 'modified content' in game_message: |
| 389 | + elif game_message is GameMessage.ModifiedContent: |
392 | 390 | logger.warning('Got kicked for modified content, trying to rejoin') |
393 | 391 | gis.set_spectator_on_server(False) |
394 | | - elif 'invalid ip address' in game_message: |
| 392 | + elif game_message is GameMessage.InvalidIP: |
395 | 393 | logger.error('Join by ip dialogue bugged, restart required') |
396 | 394 | gis.set_error_restart_required(True) |
397 | | - elif 'error reading from the server' in game_message: |
| 395 | + elif game_message is GameMessage.ReadError: |
398 | 396 | logger.error('Error reading from GameSpy-ish backend, restart required') |
399 | 397 | gis.set_error_restart_required(True) |
400 | | - elif 'server has refused the connection' in game_message: |
| 398 | + elif game_message is GameMessage.ConnectionRefused: |
401 | 399 | logger.error('Failed to connect to GameSpy-ish backend, restart required') |
402 | 400 | gis.set_error_restart_required(True) |
403 | 401 | elif not (gis.halted() and not gs.halted()): |
404 | | - logger.critical(f'Unhandled game message: {game_message}') |
| 402 | + logger.critical(f'Unhandled game message: {raw_message}') |
405 | 403 | gis.set_spectator_on_server(False) |
406 | 404 | gis.set_halted(True) |
407 | 405 | gs.set_halted(True) |
|
0 commit comments