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

feat: in-house queue system #279

Closed
wants to merge 6 commits into from
Closed

feat: in-house queue system #279

wants to merge 6 commits into from

Conversation

D4isDAVID
Copy link
Member

Description

Adds an in-house queue system.

The system includes:

  • An adaptive card showing where the player is in the queue from start to finish.
  • Configurable sub-queues/priority queues.
  • Player timeouts:
    • When a player disconnects while in queue, wait a configurable amount of seconds for the player to connect back before removing from the queue.
    • When a player disconnects after being let into the server but before firing the playerJoining event (meaning while the player was downloading the server), wait a configurable amount of seconds for the player to connect back before removing.

Some parts of the code may look weird/unnecessary as I've attempted to make it as performant as I can.
I've tested this as much as I can but this still requires further testing for race conditions, edge cases, and other unexpected things that I'm not able to test by myself.

Adaptive card preview:
image

Checklist

  • I have personally loaded this code into an updated Qbox project and checked all of its functionality.
  • My code fits the style guidelines.
  • My PR fits the contribution guidelines.

Comment on lines +13 to +19
lib.print.info('Preventing hardcap from starting...')
CancelEvent()
end
end)

if GetResourceState('hardcap'):find('start') then
lib.print.info('Stopping hardcap...')
Copy link
Member

Choose a reason for hiding this comment

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

Should these be debug prints instead of info?

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't think so, the average user may be confused on why hardcap was stopped.

Comment on lines +59 to +60
self.size -= 1
totalSize -= 1
Copy link
Member

Choose a reason for hiding this comment

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

What is the difference between self.size and totalSize?

Copy link
Member Author

Choose a reason for hiding this comment

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

self.size is the size of the sub-queue of the player and totalSize is the total size of all queues combined. I created totalSize instead of a calculate function to not have to calculate the value all the time for all players every second.

function prototype.enqueue(self, license)
self.size += 1
totalSize += 1
self.positions[license] = self.size
Copy link
Member

Choose a reason for hiding this comment

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

What alternatives were considered for the queue data structure here?

What are the tradeoffs of having the map being size to license rather than license to size? What are the tradeoffs to storing both maps? What are the access patterns? How often are we asking for the first player in line vs asking what position in line x player is in?

Copy link
Member Author

@D4isDAVID D4isDAVID Dec 10, 2023

Choose a reason for hiding this comment

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

The tradeoff of having license to position is that a less performant loop has to be done when a player is removed from the queue, but the tradeoff of having only position to license is that each time we want to know the position of a player we need to loop. Meaning either we use license to pos and make a less performant loop every time a player disconnects (since it's done through lua), or we use pos to license/source and make a more performant loop every time a player disconnects (I've imagined that table.remove would be used since iirc it uses a C loop which should be faster) but then to get players updated on their position the map would be looped through every second for every player.

I've mapped it license to position because the way I've imagined it is that each player knows their position in the queue and nothing more. I think the only good reason to store position to license/source would be if we need to reveal to another player or an external API what the player in a certain position is, but at the moment the queue does neither, so no reason to store that information currently.

Since the player is updated on their status every second, the position of the player in the queue has to be known every second, but currently it is never asked in what position in line another player is.

server/queue.lua Outdated Show resolved Hide resolved
server/queue.lua Outdated Show resolved Hide resolved
config/server.lua Outdated Show resolved Hide resolved
config/server.lua Outdated Show resolved Hide resolved
config/server.lua Outdated Show resolved Hide resolved
@D4isDAVID
Copy link
Member Author

Closing to break up into smaller PRs

@D4isDAVID D4isDAVID closed this Dec 13, 2023
This was referenced Dec 13, 2023
@D4isDAVID D4isDAVID deleted the feature/queue branch December 27, 2023 19:08
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.

None yet

3 participants