Advertisement
Guest User

sudocode

a guest
Sep 29th, 2016
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.80 KB | None | 0 0
  1. # a noble start!
  2. make server socket (say which port to accept connections on) for clients
  3. make server socket for info providers
  4. make a list of challenged data-providers
  5. make a list of accepted data-providers
  6. make a list of clients
  7. make a list of ALL SOCKETS. Server sockets, clients, data providers,
  8. *everything*.
  9.  
  10. make some sort of efficient data structure to keep spawn info in. Big enough to
  11. keep the last <maximum pokemon spawn duration> minutes of spawns logged.
  12.  
  13. make an associative data structure associating clients with subscriptions and
  14. how up-to-date they are on each pokemon type.
  15.  
  16. in a loop as long as the server runs...
  17. wait until something new happens with ALL SOCKETS.
  18. # A socket represents an endpoint of a connection. This can be what is
  19. # called a "server" socket (represents the "us" end of a connection) or what's
  20. # just called a plain old "socket" (represents the "them" end of a
  21. # connection). There should be functions that let you "wait" on a list of
  22. # sockets (that is, the function will block until any of them have something
  23. # new). In classic unix sockets, this is called select()
  24. # https://en.wikipedia.org/wiki/Berkeley_sockets#Socket_API_functions
  25.  
  26. # Okay, so we know something has happened now! It might be a new client
  27. # giving us data, or it might be a new client to give data to. Or a client
  28. # might have disconnected.
  29.  
  30. Check for disconnected sockets. Remove them from their associated lists and
  31. ALL SOCKETS, as well as the associative data structure.
  32.  
  33. Check for new data-providers, challenge them, and add them to the challenged
  34. list (and the list of ALL SOCKETS).
  35.  
  36. Check for a response from data-providers that have been challenged.
  37. if they succeeded, then
  38. move them to the list of accepted data-providers and tell them about our
  39. subscriptions (the kinds of pokemon we wanna see).
  40. otherwise
  41. throw them away (close the connection, remove them from ALL SOCKETS and
  42. the challenged data-providers).
  43. Of course, if they haven't answered, don't do anything.
  44.  
  45. Check for new clients and happily add any newbies to the list of clients
  46. (and the list of ALL SOCKETS).
  47.  
  48. Check if accepted data-providers have any new info, if so, store
  49. it. Optionally, if we wanna do a lot of analysis, store it in a database as
  50. well. Feel free to overwrite data older than <maximum pokemon spawn
  51. duration> in our shorter-term data structure. Send all new data to all
  52. clients according to their subscriptions (if they don't have one, don't send
  53. anything) and update how up-to-date they are for each pokemon type.
  54.  
  55. Check if clients have any subscription info to give and update it if they
  56. do. For each new pokemon they're subscribed to, bring them up-to-date.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement