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

Commit

Permalink
Merge branch 'tournament'
Browse files Browse the repository at this point in the history
  • Loading branch information
Nihisil committed Jun 29, 2016
2 parents b3a5af1 + a02ffe8 commit bddf089
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 10 deletions.
12 changes: 7 additions & 5 deletions project/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,20 @@ def parse_args_and_set_up_settings():
default=settings.WAITING_GAME_TIMEOUT_MINUTES,
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))

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

opts, _ = parser.parse_args()

settings.USER_ID = opts.user_id
settings.GAME_TYPE = opts.game_type
settings.LOBBY = opts.lobby
settings.WAITING_GAME_TIMEOUT_MINUTES = opts.timeout
settings.IS_TOURNAMENT = opts.is_tournament

if opts.championship:
settings.IS_TOURNAMENT = True
settings.LOBBY = opts.championship

def main():
parse_args_and_set_up_settings()
Expand Down
30 changes: 25 additions & 5 deletions project/tenhou/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,21 +42,38 @@ def authenticate(self):
self._send_message('<AUTH val="{0}"/>'.format(auth_token))
self._send_message(self._pxr_tag())

message = self._read_message()
if '<ln' in message:
# sometimes tenhou send an empty tag after authentication (in tournament mode)
# and bot thinks that he was not auth
# to prevent it lets wait a little
# and read a group of tags
sleep(3)
authenticated = False
messages = self._get_multiple_messages()
for message in messages:
if '<ln' in message:
authenticated = True

if authenticated:
self._send_keep_alive_ping()
logger.info('Successfully authenticated')
return True
else:
logger.info('Failed to authenticate')
return False

def start_the_game(self):
log_link = ''

if settings.LOBBY != '0':
logger.info('Go to the {0} lobby'.format(settings.LOBBY))
self._send_message('<CHAT text="{0}" />'.format(quote('/lobby {0}'.format(settings.LOBBY))))
sleep(5)
if settings.IS_TOURNAMENT:
logger.info('Go to the tournament lobby: {0}'.format(settings.LOBBY))
self._send_message('<CS lobby="{0}" />'.format(settings.LOBBY))
sleep(2)
self._send_message('<DATE />')
else:
logger.info('Go to the lobby: {0}'.format(settings.LOBBY))
self._send_message('<CHAT text="{0}" />'.format(quote('/lobby {0}'.format(settings.LOBBY))))
sleep(2)

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

Expand Down Expand Up @@ -281,6 +298,9 @@ def send_request():

def _pxr_tag(self):
# I have no idea why we need to send it, but better to do it
if settings.IS_TOURNAMENT:
return '<PXR V="-1" />'

if settings.USER_ID == 'NoName':
return '<PXR V="1" />'
else:
Expand Down

0 comments on commit bddf089

Please sign in to comment.