Skip to content
This repository was archived by the owner on Jul 8, 2023. It is now read-only.

Commit bddf089

Browse files
committed
Merge branch 'tournament'
2 parents b3a5af1 + a02ffe8 commit bddf089

File tree

2 files changed

+32
-10
lines changed

2 files changed

+32
-10
lines changed

project/main.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,20 @@ def parse_args_and_set_up_settings():
2828
default=settings.WAITING_GAME_TIMEOUT_MINUTES,
2929
help='How much minutes bot will looking for the game. If game is not started in timeout, script will be ended. Default is {0}'.format(settings.WAITING_GAME_TIMEOUT_MINUTES))
3030

31-
parser.add_option('--tournament',
32-
dest='is_tournament',
33-
action='store_true',
34-
help='If present bot will be run in tournament mode')
31+
parser.add_option('-c', '--championship',
32+
type='string',
33+
help='Tournament lobby to play.')
3534

3635
opts, _ = parser.parse_args()
3736

3837
settings.USER_ID = opts.user_id
3938
settings.GAME_TYPE = opts.game_type
4039
settings.LOBBY = opts.lobby
4140
settings.WAITING_GAME_TIMEOUT_MINUTES = opts.timeout
42-
settings.IS_TOURNAMENT = opts.is_tournament
41+
42+
if opts.championship:
43+
settings.IS_TOURNAMENT = True
44+
settings.LOBBY = opts.championship
4345

4446
def main():
4547
parse_args_and_set_up_settings()

project/tenhou/client.py

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,21 +42,38 @@ def authenticate(self):
4242
self._send_message('<AUTH val="{0}"/>'.format(auth_token))
4343
self._send_message(self._pxr_tag())
4444

45-
message = self._read_message()
46-
if '<ln' in message:
45+
# sometimes tenhou send an empty tag after authentication (in tournament mode)
46+
# and bot thinks that he was not auth
47+
# to prevent it lets wait a little
48+
# and read a group of tags
49+
sleep(3)
50+
authenticated = False
51+
messages = self._get_multiple_messages()
52+
for message in messages:
53+
if '<ln' in message:
54+
authenticated = True
55+
56+
if authenticated:
4757
self._send_keep_alive_ping()
4858
logger.info('Successfully authenticated')
4959
return True
5060
else:
61+
logger.info('Failed to authenticate')
5162
return False
5263

5364
def start_the_game(self):
5465
log_link = ''
5566

5667
if settings.LOBBY != '0':
57-
logger.info('Go to the {0} lobby'.format(settings.LOBBY))
58-
self._send_message('<CHAT text="{0}" />'.format(quote('/lobby {0}'.format(settings.LOBBY))))
59-
sleep(5)
68+
if settings.IS_TOURNAMENT:
69+
logger.info('Go to the tournament lobby: {0}'.format(settings.LOBBY))
70+
self._send_message('<CS lobby="{0}" />'.format(settings.LOBBY))
71+
sleep(2)
72+
self._send_message('<DATE />')
73+
else:
74+
logger.info('Go to the lobby: {0}'.format(settings.LOBBY))
75+
self._send_message('<CHAT text="{0}" />'.format(quote('/lobby {0}'.format(settings.LOBBY))))
76+
sleep(2)
6077

6178
game_type = '{0},{1}'.format(settings.LOBBY, settings.GAME_TYPE)
6279

@@ -281,6 +298,9 @@ def send_request():
281298

282299
def _pxr_tag(self):
283300
# I have no idea why we need to send it, but better to do it
301+
if settings.IS_TOURNAMENT:
302+
return '<PXR V="-1" />'
303+
284304
if settings.USER_ID == 'NoName':
285305
return '<PXR V="1" />'
286306
else:

0 commit comments

Comments
 (0)