🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

What is actually needed to build a live service online game

Started by
5 comments, last by frob 1 year, 11 months ago

Hi everyone,

I would like to know what is actually needed in terms of technology to build an online game.
I'm asking this because I've seen a lot of different solutions, but I can't seem to figure out what to use and when.

So for example I would like to make an online game similar to the old pokemon games.
Things I would like to have are the following

Login/Register - People need to be able to create a account login etc.
Multiple server worlds - This would represent the world the players are in something like World - 1
Chat - That would reach out over all worlds.

I've had some experience messing around with all of these things but still, I never seem to be satisfied with the result.
In terms of technologies, I would like to use Unity & regular C# as backend.

These are some questions I can't seem to wrap my head around?

1 - I've made an API with .net core and a login system, so my client logs in and receives an authentication token.
Now I would like my user to pick a world where he should connect to a game server, how should the game server be aware of his authentication code? Should the API have a connection to the world?

2 - A user is walking around in my game server and he picks up an item, it's added to his inventory and now I would like to inform the database this user has an item, and right now I'm using .net core for that with the EntityFramework which I would like to remain using. Would the server make a call to the .net core API as well?

It would be really helpful if anyone could share maybe a diagram of how to flow should be with the connections.

Thank you already in advanced

None

Advertisement

Applefruit said:
I would like to know what is actually needed in terms of technology to build an online game.

The barest bare minimum, you need a computer with a publicly reachable IP address. Anything you implement beyond that is good, but not essential.

What you decide to implement beyond that is a matter of scope and scale. You can build enormous infrastructure on the backend, you can build tiny services, you can build anything in between.

Businesses usually rely on major providers and libraries so they don't need to spend their time and effort re-inventing the wheel.

Applefruit said:
1 - I've made an API with .net core and a login system, so my client logs in and receives an authentication token. Now I would like my user to pick a world where he should connect to a game server, how should the game server be aware of his authentication code? Should the API have a connection to the world?

So you'll need game servers, whatever that means in the context of your game. For small hobby projects there's nothing wrong with it being in a single program. For larger projects that need to scale up with more users, it can mean that you have dedicated instances or instances on AWS or Google Cloud or a Kubernetes cluster or something else.

Assuming they're built as different servers, your game servers will contact your authentication server, and using a secure connection (often established with a shared secret between servers) verify that the authentication token is valid. There are a bunch of ‘best practices’ to keep the tokens safe and secure, like not basing them on any real information like account IDs and passwords, expiring them rapidly or making them single use, etc. Ultimately one of your servers issues a token to the client over a secure connection, the client gives the token to another server over a different secure connection, the new server verifies the token's validity, and the connection is verified.

As for how you pick the worlds and server, you'll need something that serves as a hub for when players enter and figure out what games are available. It could be the same service the client sees to log in, or it could be some other service you run. It will need to do something to coordinate what games you have available, possibly spawning or making available game servers, possibly connecting to matchmaking, or doing whatever additional work your game design needs.

There is no universal standard, but there are a bunch of common solutions. If you were using a game engine like Unity or Unreal I'd recommend reviewing systems based on the interfaces they provide, but as you're rolling your own code yourself, you'll be on your own there.

Applefruit said:
2 - A user is walking around in my game server and he picks up an item, it's added to his inventory and now I would like to inform the database this user has an item, and right now I'm using .net core for that with the EntityFramework which I would like to remain using. Would the server make a call to the .net core API as well?

Again, it depends. Often it is done periodically to avoid the costs of frequent writes, and ultimately the details depend on the game design and the system.

For a small game with a very small, non-scaling server, you could write to it directly from your server program. This won't scale, but for a hobby project that will never be commercial and must be low cost, it can be the best solution.

For many games there are several servers and services involved. The game server (not the clients) handle the processing of users running around in the world doing whatever they do. Never trust the client, validate everything on the servers. Depending on the nature of the interaction, you'll have the game server notify the account server to update the account data. If it's a transaction, such as two players exchanging money for goods, you'll need to use a little bit of locking to ensure the transaction is valid for both players and submitted simultaneously. It is a solved problem in databases, there are things like “ACID” guarantees and transactional boundaries, but you as the programmer need to write code that follows the rules.

The game server would write that data out to the data backend periodically often at regular intervals during gameplay, and also at special events like special transactions, high value loot drops, and logging out. Details depend entirely on what the game and implementation need. Some only write the information out after a match is complete. Others write information frequently as the player takes actions on the world.

Note that there are a bunch of existing systems and services out there that provide their own variations of all the technology you've asked about. As you're already in .net, you might consider Microsoft's PlayFab SDK. Or you might prefer GameSparks if you're using Amazon services. Or Firebase if you're using Google services. Or Braincloud, or Loot Locker, or Photon Cloud or so many others. They do the account handling including verification, account recovery, and authentication with major services like through Google / Gmail or through Steam or through Facebook. They handle storage of the data for the account and the individual game. They also have options that allow them to scale with large user counts, or to stay small. Each one has their own pros and cons, and their own fee schedules.

Using an existing library won't get you custom internals, but they're already built and debugged and many game companies already rely on them. If your goal is to write games and you want something that scales, it is often faster and easier to rely on their solutions instead of rolling your own.

As @frob said, it varies greatly.

There are different levels of platforms and libraries available. Something like Google Firebase or Google App Engine (and the similar offerings from other vendors) will attempt to “do more” for you, as long as you live within its ecosystem. Other things, like Amazon EC2 (and the similar offerings from other vendors) will mainly provide “servers and databases” and it's up to you to fill in the blanks.

That being said, if your game needs to scale (which may not be a requirement!) you'll want some set of servers that run “game server stuff" (replicating traffic to other users, verifying or simulating game physics, etc.) Each of those need some public route to it – typically, some connection through some kind of NAT gateway. (On Amazon, you'll want a Network Load Balancer.) Probably using UDP, but could be using TCP, depending on your specific game.

You'll want some service for login and authentication. Maybe this is a simple service that just delegates to some kind of oauth sign-in, like “sign in with Facebook.” Maybe you use some service like Steam or Epic Game Services.

You'll want some registry that knows which game servers are available to join. Typically, each game server will register itself with the registry, by occasionally sending an “I'm available” message to that service, and the service timing out hosts that haven't pinged in a while. This connection can often be private, inside the firewall, and doesn't need a public connection. Unless you use something like Steam, where the registry is not under your control.

When logging in, the login service can use an internal service endpoint on the registry, to figure out what available servers there are, and assign the player to one.

When the player “picks something up,” and “puts it in inventory,” you will typically want those decisions to be made on the game server, unless you don't care about cheating, item duplication, and so on. The game servers will also have a connection to some database, that can update records for the players state and inventory. That database, in turn, should not be visible to the external world – let the game servers do all the necessary validation and decision making to update your state. (The login service may also need to talk to that database, and perhaps also the registry, depending on your specific needs. Consider a player logging in from two separate devices at the same time, for example! What should happen? )

A very basic, standard, architecture, looks something like:

Now, if you use Epic Game Services, or Steam, or something else, they will fill in certain parts of this. I highly recommend checking that out!

The “Server” runs code related to your gameplay. The “login” runs code related to accounts, and may issue a signed token that the “server” can know to use. The “registry” knows which “servers” are available, The “database” should be obvious :-) Although the “servers” don't update the database with every movement for every player – important transactions (trades, wins, etc) are probably synchronous, but other state is probably only checkpointed infrequently, to reduce load. And, finally, the NLB is the NAT gateway that your host/cloud provider provides, which exposes the services on the back end to the greater internet.

Note that all of these (including “game server”) likely are “services” rather than “machine instances” – you can run many “game servers” on a single “machine instance” in most cases. Managing the physical infrastructure (or, more likely, virtual infrastructure – cloud!) is a separate layer, where you call the host/cloud providers API. Or go into your data center and screw machines into racks and plug in cables; who knows, maybe that's what you enjoy? :-D

enum Bool { True, False, FileNotFound };

For my Online top down shooter I built back in 2015. I simply had clients and servers to distribute to players. The trick is, you need a master server that only the developer has and it should have a static IP address. All servers and clients connect to the master server. The master servers job will be to tell clients of the server IPs.

So In my case, all I needed was one computer to run it. It was up to the players to make servers.

Game Dev since 2004

So is there any way for online soccer game?

@latoyacain Please do not hijack old threads. If you have a question or discussion idea about a soccer game, create a new discussion topic.

This topic is closed to new replies.

Advertisement