Game server architecture design details

Preface

Generally speaking, people who start making games in the industry add and modify functions on ready-made codes. They rarely have the opportunity to complete the design of a game server by themselves. Some small companies may have such an opportunity, and generally they will find ready-made codes to develop directly. . In order to cultivate internal strength, how to make a game server by yourself? Let’s discuss it a little today

1. Server architecture

To raise a tall building from the ground, you must first make the skeleton and lay the foundation before you can raise the tall building. Therefore, you need to design the structure before starting. Students with a little experience will know how to do this.

The target this time is a card server, so the design is as follows.

Explain the responsibilities of each server and middleware

Not much to say about client, it represents the client, which can be a client developed by various technologies.

Gate serves as a gateway server and is also a place for load balancing. Players can choose the server to log in to, log in and create a corner here.

Room is also a battle server. Players will be sent to the Room server after matching the battle, and then return to the Game after the battle.

Game is where the main business logic occurs, such as card acquisition, card deck creation, upgrades and other main logic.

2 Basis for technology selection

The selection of server technology is basically based on your own language experience, choosing the language you are most proficient in, and then choosing the corresponding implementation.

In the years when mobile games were most popular, we saw many servers written in PHP.

Many old game companies will choose C++ because it is a legacy of history, because those old guys can only use C++, but now many companies use Java, Golang

Waiting for a new generation of programming language, high production efficiency and convenient recruitment.

Because I have been using Java for so many years. Although I have written C++ for a few years, I still don’t like it very much and I am not proficient in it. It can be said that Java is my native language.

3 Java server technology

3.1 Communication framework: websocket

The choice of websocket here is mainly because we want to make a card web game. This is a requirement of Party A, so we definitely choose to use websocket for communication.

Of course, if you are making mobile games, you can switch the communication protocol yourself, such as TCP, UDP. Netty is the first choice for efficient network communication framework in Java.

Netty has good support for tcp and udp

3.2 Framework series: springboot, spring data jpa, spring security

Those who do Java cannot avoid Spring. Springboot is now the most convenient development framework. There is no hesitation in choosing the Springboot series for the entire framework.

Spring data Jpa is very convenient to operate the database. For complex Sql, template can be used directly to improve production efficiency. You can choose mybatis and I won’t despise you, I don’t like it.

Spring Security is used to control access to the GM interface. As long as you add a package and configure it simply, you can control permissions. Don't think too much, just rush.

3.3 Component series: easyexcel, dubbo, jetcache, akka, fastjson, protobuf

EasyExcel is used to load basic data Excel. It reads Excel into memory, which is efficient and saves trouble. The most important thing is that Excel is very friendly to planning and programming, and it is easy to find problems.

Dubbo is used to make remote calls between servers. It is simple and direct, and does not require configuration.

Jetcache is mainly used as a cache, because the game has a lot of database access, and if there is no layer of cache, it will put a lot of pressure on the database.

Akka is mainly used in room servers. Each room corresponds to one actor. There is no need to consider multi-threading issues. It is simple and violent.

Fastjson is used for serialization when accessing redis, and can save some ranking data for easy sorting.

protobuf is used to communicate with the client, which is efficient, trouble-free and versatile.

3.4 Middleware: mysql, redis

Mysql is used for player data persistence. Most game companies use this. In fact, it is good to use MongoDB here. I am too lazy to switch. The main reason is that it is more convenient to upgrade the business later. I haven’t tried it with MongoDB yet.

Redis is basically mainly used to solve caching problems and cross-server data problems. In short, it should be useful.

3.5 Container components: docker docker-compose

It’s the 21st century, so of course it’s time to use containers. Docker and docker-compose are perfect for games, simple and trouble-free.

It’s also worry-free for operation and maintenance, getting the best of both worlds.

4. Summary

The design of game architecture is actually not that difficult. They are all common architectures in the industry. It’s just that you need to master the implementation details yourself. If you pay more attention to your work, I believe you can figure it out in a few years in the game industry.

There is no perfect way to build a mountain when encountering a mountain or to build a bridge when encountering water. Solve the primary contradiction first and then resolve the secondary contradiction.

Take off first, then adjust your posture, and rush.

Guess you like

Origin blog.csdn.net/perfect2011/article/details/132812689