Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Start games automatically #523

Open
wants to merge 64 commits into
base: master
Choose a base branch
from

Conversation

glbert-does
Copy link
Member

@glbert-does glbert-does commented Nov 1, 2023

closes #491, rebased from #527

with this pull request, we try to use the lichess bulk pairing api to create games and start clocks automatically at the scheduled time. here is how it is supposed to work:

  • new league setting start_games. if this is set to true,
  • players can confirm the time they have scheduled for.
  • if the scheduled time changes, players need to confirm again.
  • every */5 minutes scheduled games 30 seconds to 5:30 in the future are started (if both players confirmed that is), clocks are set to start in 6 minutes. lichess sends a message pointing to the game using the account that did the apicall.
  • in practice this should mean that games scheduled for "nice" numbers like :00 or :30 are started five minutes before they are scheduled, and the clocks are started one minute after the game is scheduled.
  • players cannot claim a win (yay!), but they can abort a game. which should help if an opponent does not show up. potentially, we could disallow early draws (move 30), but i don't think this would do much other than annoy players.

at least the following things are potential problems:

  • the account doing the bulk pairing needs a token with challenge:bulk scope. i believe in our case this would be lichess.org/@/lichess4545 – i assume the token currently used might not have that yet.
  • if we do not have a valid token for a player, or the account is closed, lichess returns an error and lists the token(s) in question, without starting any games. i try to handle this, but it is rather not elegant. i assume there should be a better way than to use regexp on the error message. should work better now.
  • after 20 minutes, we used to check whether games have started by simply checking for a game id. this is not enough anymore, i now try to check in the move list whether more than one move was made. at this point i have tested this a lot of times, and everything seems to be working as expected.
  • the page to confirm scheduled times is rather ... bad. i did not put too much work into it, because i assume long term we will create a way to confirm times via slack.

i tried to test a lot of stuff, but it is difficult to get it anywhere close to what it would look like in prod.

@glbert-does
Copy link
Member Author

glbert-does commented Nov 1, 2023

todo:

  • the lichess response to a successful pairing could be used to set the gameid
  • improve error handling
  • potentially, if lichess rejects a token, we should invalidate it on our end
  • we should probably notify players about a started game on slack as well.
  • we now hit update_lichess_presence way harder, since we cannot stop once a gamelink is set. maybe we can check games for moves earlier to reduce this.

@glbert-does
Copy link
Member Author

glbert-does commented Nov 14, 2023

most of the important todos are done. there's a couple nice-to-haves as well:

  1. as mentioned, a way to confirm a scheduled time via slack (or rather the api endpoint to do so – edit: api endpoint was added to update_pairing, so i'll mark this done, even though the chesster part of it is still missing)
  2. when a token was declined by lichess, it would be nice to force the player to get a new one, e.g. by logging them out (edit: this can potentially be done by changing their password via User.objects.get(username=[username]).set_password("whatever") - not sure if this would work for our oauth based system; also not certain it is worth it doing this at all. it's mostly the problem of the player.
    edit to the edit: probably better to implement in middleware.py)
  3. possibly, whether a time was confirmed should be shown on the pairings page
  4. potentially, it could be nice to have at least the time for starting the clocks be a league setting
  5. maybe whether the clocks will be started at all could be a league setting too

@glbert-does
Copy link
Member Author

now rebased on the django_update / django 4.2 branch. will get to your comments tomorrow/the day after.

@nicwest
Copy link

nicwest commented Dec 21, 2024

Screenshot 2024-12-21 at 13 12 30

Comment on lines +369 to +370
scheduled_time__lt=timezone.now() + timedelta(minutes=5, seconds=30),
scheduled_time__gt=timezone.now() + timedelta(seconds=30),
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can I just check these times are correct? we are looking for games starting in the range now + 30s to now + 5m30s. would it also not be a good idea to pick up games in the past as well?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can I just check these times are correct?

tl;dr: yes, i did break my pretty little head about those times, and i picked those on purpose. no, i do not think i necessarily picked the best choice.

would it also not be a good idea to pick up games in the past as well?

i thought about it, but i am honestly not sure. there is a lot of weird stuff that could happen i think. for example, players play a game that is not picked up for some reason and before the mods can add the gamelink, heltour starts a new game for them. that wouldn't be the end of the world of course. but if the game is ongoing, it might distract them.
or maybe players manage to somehow schedule a game for a time that already happened by accident. i think chesster would not allow this, but mods can manually schedule games, and there's less checking there. would still not be the end of the world of course.

at the same time, i do not really see the point in automatically starting games that should have happened a while ago. if the game did not start, or heltour thinks the game did not start, there might be a reason for that, and it might be better to not start it automatically.

anyway, the logic about all time points is definitely debatable. some people might be pissed about games starting 5 minutes early, prohibiting them to play some last minute blitz. same with the question of when exactly to start the clock. currently it's 6 minutes after the game was started, which will be 1 minute after the game was scheduled for most people.

i am absolutely happy to discuss these times, i am not at all confident that i picked the best options. very glad you looked at it.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That all sounds reasonable, and it can all be adjusted later if needed.

@glbert-does
Copy link
Member Author

glbert-does commented Jan 18, 2025

at this point everything i was able to think of is implemented on the heltour side. the only "nice to have" that isn't implemented is logging users out if the token is not valid anymore. but the more i think about that, the less i think it's necessary.

a chesster command for confirming game times is indeed missing, but i do not consider that to be "on the heltour side".

also, i am sure others will have ideas about parts of this feature that might be missing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Start games automatically
2 participants