EmilZach / Sentence-Crusher

A Python game for crushing sentences.
0 stars 1 forks source link

Synchronization between client and server - files. #15

Closed Arxcis closed 8 years ago

Arxcis commented 8 years ago

What if I get a highscore while I am offline. I want the game to be able to push my new highscore, when internet is back up. I want see global highscore-lists on my client , even if I am offline.

EmilZach commented 8 years ago

Something that's possible is to save the highscore when you don't have internet, and when you start the game while you have internet, check if it is really a highscore in that level and if it is, push it to the server.

Arxcis commented 8 years ago

Yes that could work.

Another solution would be to send levelhistory to the server right after player have picked a level. Then you have 2 dictionaries on the server, 1 with client history , 1 with _ server history. Then you run a merge-function on the server which basically makes them identical to each other. And then you send client_history back to client, which stores the new history in its files.

  1. mar. 2016 2.08 p.m. skrev "Emil Teigland Zachariassen" < notifications@github.com>:

Something that's possible is to save the highscore when you don't have internet, and when you start the game while you have internet, check if it is really a highscore in that level and if it is, push it to the server.

— You are receiving this because you authored the thread. Reply to this email directly or view it on GitHub https://github.com/EmilZach/Sentence-Crusher/issues/15#issuecomment-202859437

Arxcis commented 8 years ago

Here is some pseudo - code that could work:

  1. Player picks level.
  2. Client reads level_history and stores it in a dictionary.
  3. Client sends level_history to the server.
  4. Server recieves client_level_history, and reads server_level_history into its own dictinary.
  5. Server launches the following synchronization-function.

\ For every key in server_history: ** If key is not in client_history: Store server- key + data in client_history.

For every key in client_history: If key is not in server_history Store client key + data in server_history.

     **Else if client_history[key][points] == server_history[key][points]:**
                   Do nothing

      **Else if client_history[key][points]  >  server_history[key][points]:**
                    Store client - key + data   in server_history.

      **Else if client_history[key][points]  <   server_history[key][points]:**
                   Store server-key + data in client_history
  1. Server sends the possibly modified client_history back to client.
  2. Client recieves and stores the new client_history in its respective file.
  3. WINNING!
EmilZach commented 8 years ago

That could work, and since you have aleardy made pseudocode, maybe we should go for your solution. :-)

Arxcis commented 8 years ago

Unecessary if we only have storage.py on server.