Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # a noble start!
- make server socket (say which port to accept connections on) for clients
- make server socket for info providers
- make a list of challenged data-providers
- make a list of accepted data-providers
- make a list of clients
- make a list of ALL SOCKETS. Server sockets, clients, data providers,
- *everything*.
- make some sort of efficient data structure to keep spawn info in. Big enough to
- keep the last <maximum pokemon spawn duration> minutes of spawns logged.
- make an associative data structure associating clients with subscriptions and
- how up-to-date they are on each pokemon type.
- in a loop as long as the server runs...
- wait until something new happens with ALL SOCKETS.
- # A socket represents an endpoint of a connection. This can be what is
- # called a "server" socket (represents the "us" end of a connection) or what's
- # just called a plain old "socket" (represents the "them" end of a
- # connection). There should be functions that let you "wait" on a list of
- # sockets (that is, the function will block until any of them have something
- # new). In classic unix sockets, this is called select()
- # https://en.wikipedia.org/wiki/Berkeley_sockets#Socket_API_functions
- # Okay, so we know something has happened now! It might be a new client
- # giving us data, or it might be a new client to give data to. Or a client
- # might have disconnected.
- Check for disconnected sockets. Remove them from their associated lists and
- ALL SOCKETS, as well as the associative data structure.
- Check for new data-providers, challenge them, and add them to the challenged
- list (and the list of ALL SOCKETS).
- Check for a response from data-providers that have been challenged.
- if they succeeded, then
- move them to the list of accepted data-providers and tell them about our
- subscriptions (the kinds of pokemon we wanna see).
- otherwise
- throw them away (close the connection, remove them from ALL SOCKETS and
- the challenged data-providers).
- Of course, if they haven't answered, don't do anything.
- Check for new clients and happily add any newbies to the list of clients
- (and the list of ALL SOCKETS).
- Check if accepted data-providers have any new info, if so, store
- it. Optionally, if we wanna do a lot of analysis, store it in a database as
- well. Feel free to overwrite data older than <maximum pokemon spawn
- duration> in our shorter-term data structure. Send all new data to all
- clients according to their subscriptions (if they don't have one, don't send
- anything) and update how up-to-date they are for each pokemon type.
- Check if clients have any subscription info to give and update it if they
- do. For each new pokemon they're subscribed to, bring them up-to-date.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement