boskee / Minecraft

Simple Minecraft-inspired program using Python and Pyglet
MIT License
207 stars 33 forks source link

Player ins't a Player object in save_player method #83

Closed arruda closed 9 years ago

arruda commented 9 years ago

This seems to be a bit of a problem, I'm running the server and the client, and right at the server start it crashes because it tries to save a player accessing it's position and momentum to the SQLite DB, but what you have as a player in this method is not a Player instance but the ThreadedTCPRequestHandler.

I don't know what is the best approach for a game development, but if it were to make it easier to work with the player in server side, then I believe it would be a nice idea to "convert" the ThrededTCPRequestHandler to a Player object then convert it back when the server finished doing whatever it needed. Or maybe just adding a Player instance as an attribute to the ThededTCPRequestHandler.

What do you guys think?

Jimx- commented 9 years ago

Actually Player object is only used in the client, the server saves momentum, position and inventory directly in the ThreadedTCPRequestHandler instance. When a player tries to login, server will call load_player, in which position and momentum are loaded and set. It turns out that I carelessly forgot to set initial values on the player's first login. Thanks for reporting this bug!

arruda commented 9 years ago

I was thinking about a ORM approach to the SQLite DB, wouldn't it be better, and easier to maintain? like https://github.com/coleifer/peewee. So there would be a Player model in serverside, what do you think?

Jimx- commented 9 years ago

There is already an ORM approach(incomplete) in sqlserver-dev branch. Maybe we can try to merge it into the master branch?