hi hplus! I don't know if you remember me or not.. I was a big time user of this forum a decade ago and learned A LOT from you personally here in the multiplayer forum. I have since been a developer in the business space and am now finally returning to games. I just wanted to say thank you for all the help you gave me all those years ago. It truly made an impact in my life.
"Games where this works really well are games like Farmville or Backyard Monsters or such, where the player really is only doing their own thing, and the only need for the back-end is to validate what the player has done, record the state of started work/timers, and such."
This sounds very much like the requirements of the MVP of my game. The client just needs to have an authoritative server to tell it which cards it owns, which decks it has, send it the resources for those decks, social aspects (friends lists, news feed, eventually it would have messaging), etc.
Once the MVP is proven, we would add a 'VS' mode where 2 players could interact with each other in a turn-based way.
Back in the day when I was learning about the architecture for MMOs here, I remember what you had told me about how it worked at the game you were building at that time, I think it was Second Life? You had told me the best architecture is to have distributed services. I have found that to be true in the business world as well.
I was thinking that a good approach to tackling this problem is to start off with a simple web server, and then later, when 2 player VS mode was needed, expand into a TCP connection / stateful game server using some sort of methodology like RPCs or such. UDP wouldn't be needed here as the game is nowhere near real-time and there are no physics interactions in the game outside of animations and such which can be run client side as they don't impact the state of the game and so don't require server authorization.
This approach seems like it would allow me to organically grow the application as needed as well as distribute the work to separate services which would hand over sessions to each other behind the scenes. The Web API could tell the stateful game server a session was coming his way and the clients could then connect with their session ID's to a warmed up game server.
Do you think this approach would lead me to paint my self in a corner, or does it seem sane? I don't want to build a stateful game server from the beginning as it may be overkill. The MVP may not even take off, or it may take off in a different direction altogether and it seems easy enough to add stateful ness later. But, I've only been back in game development for 6 months now, and haven't done serious networking in a game yet since 10 years ago...
Thanks again man!
Yes, there are games that use web APIs.
Games where this works really well are games like Farmville or Backyard Monsters or such, where the player really is only doing their own thing, and the only need for the back-end is to validate what the player has done, record the state of started work/timers, and such.
If you are doing interaction with other users, POST/GET is a little more iffy. You CAN build a reasonably real-time system based on long polling ("comet" style with AJAX) if you have the ability to suspend a current request on the server, and unblock/return it once there's data, or once enough time has passed (10 seconds or whatever.)
However, this is, shall we say, decidedly "ghetto" networking, and the crossbar to figure out "what is there for this user" and then getting that information to the appropriate server where the user's request is waiting to be unblocked is fragile, and full of race conditions.
If your game is small enough to only ever need one server, then the "A did a thing, so B needs to know about it" isn't so bad, but when you scale across multiple machines, HTTP gets in the way something fierce.
In fact, you're probably better off to just chuck the game state and outgoing messages into a database, and have the user poll every 5 seconds, and polling will return whatever was sent in the last 30 seconds, and purge anything older than that, from the database.
This is highly inefficient, and delays all incoming messages by 5 seconds, but at least it can be made robust.
If you have to run in a web browser, I would suggest perhaps web sockets (something like socket.io) because there at least you have a persistent connection to the server, and thus the mapping from "user id" to "server that currently knows how to send data to that user" can be somewhat less ephemeral.
You'd have some registry of where the connection for each user is, and some ability for processes on different machines (or just different processes on the same machine) to find each other.
Erlang is great for this, btw, but if you have to do it in C#, then that can be done.
If you're building a native client (PC game, console, or mobile,) then you're probably slightly better off just using TCP, or, if timing is super important, using UDP with some method to deal with unreliable messages.
The web stack makes it possible to build highly scalable infrastructure if your goals are de-centralized document editing/access, large document transfers, and high latency updates.
Games have different goals.