Original Post
I'm starting to work on an HTML/Javascript game for Facebook with a friend. The game requires a database as it's essentially a non-realtime MMO where all the players are participating in one world and can interact. We plan to use PHP or Ruby as our backend for all database interaction and actual game logic, so I'm trying to get a feel for whether there are libraries out there that already solve some of this or patterns we should be following while implementing the system ourselves.
Currently I've done a little investigation and not found any existing libraries. I started writing my own system, but I'm not sure it's the right approach. Essentially I have a single file that can have data posted to it from Javascript. For example, if I wanted to buy an item, the Javascript would look like this:
$.post('http://mydomain.com/transact.php', { method: 'BuyItem', user: 1, item: 3, quantity: 1 }, function(data) { /* handle response */ });
The "method" is matched with a PHP class so that I can instantiate the class and pass it the rest of the data to handle the response, in this case ensuring the user can afford the item and if so purchasing the item. In this system I would then continue to add new classes that represent each action or set of actions such as selling items, traveling, and so on.
Does that sound like a sane approach for keeping all game logic on the server? Is there a more "standard" way to handle such interactions between Javascript and a server side language like PHP or Ruby? Is there an existing solution out there that will save me a lot of time and frustration?
Thanks in advance.
Currently I've done a little investigation and not found any existing libraries. I started writing my own system, but I'm not sure it's the right approach. Essentially I have a single file that can have data posted to it from Javascript. For example, if I wanted to buy an item, the Javascript would look like this:
$.post('http://mydomain.com/transact.php', { method: 'BuyItem', user: 1, item: 3, quantity: 1 }, function(data) { /* handle response */ });
The "method" is matched with a PHP class so that I can instantiate the class and pass it the rest of the data to handle the response, in this case ensuring the user can afford the item and if so purchasing the item. In this system I would then continue to add new classes that represent each action or set of actions such as selling items, traveling, and so on.
Does that sound like a sane approach for keeping all game logic on the server? Is there a more "standard" way to handle such interactions between Javascript and a server side language like PHP or Ruby? Is there an existing solution out there that will save me a lot of time and frustration?
Thanks in advance.