nurselaine / typeracer

Typeracer Game
2 stars 1 forks source link

Not appending to database in server.java #8

Closed michael-torkaman closed 8 months ago

michael-torkaman commented 8 months ago

not appending to user_database.txt properly. need to write to new line. on next run of server. server crashes. removing the empty lines at end of file fixes problem. Need to either correct how server reads from file. or correct how server writes to file. correcting both would be the best case. read correctly and write correctly.

nurselaine commented 8 months ago

This is what my user database file looks like when I create a new user profile. It appears to be making a new line each time it writes to the file.

Screenshot 2024-02-27 005949
michael-torkaman commented 8 months ago

yeah im investigating it. currently. Thank you for the output. for me it was writing it to the same line and creating a a new line underneath it which i dont know how that is possible but will fix it in a moment!

nurselaine commented 8 months ago

that's very strange. I can look into it. maybe I added something into the last code I pushed up

michael-torkaman commented 8 months ago

Im pretty sure a big part of it is the changes i added to the file paths. because i tried to touch as little code that you wrote as possible. there is probably some logic somewhere that breaks when i changed the file path scheme. If the filepaths are changed to the windows ones the problem will go away.

nurselaine commented 8 months ago

I want to say my code has a good amount of bugs so wouldn't blame you for running into issues lol. Change whatever you think would be for the best.

michael-torkaman commented 8 months ago

Screenshot from 2024-02-27 01-20-37 this is my user_database file after creating one user. it adds it to the end of the last user created and then adds a new line at the end of the file which is beyond me. And no the code is pretty solid. Its just multi threading is confusing and multi threading on a collaborative project where we are all experimenting is even more confusing. When it works it works. just need the game logic. and ironing out the bugs and we are out of the woods.

nurselaine commented 8 months ago

I'll look into this more. will try to reproduce this bug but yes I agree its really hard with multi-threading. I don't know how to use my debugger with threads

michael-torkaman commented 8 months ago

simple fix. issue closed. needed to remove a "\n" from the end of the saveUserCredentials() in ClientHandler.java fixed it. added a line to throw an exception when loading the database in server.java just in case. but should be removed later on.