Game server design Unity3d + photon + grpc + nodejs + postgis/postgresql

Unity3d + photon + grpc + nodejs + postgis/postgresql game server design

Game type: MMORPG

If you want to use grpc to replace photon to complete the communication (long link is replaced with short link), you can refer to this blog:
Unity + Grpc + protobuf + C# Detailed usage process

Due to the lack of design experience in the game network layer, the team adopted photon, a commonly used server on the market.

Specific to the language: unity3d uses c#, android uses java, and photon uses c#.

When doing technical selection, I thought about it for a long time and wanted to unify the foundation of the technology. That is to say, the server side also uses c#. I tried c# and wrote a few small demos. I felt that I still lack the necessary skills, so I chose a familiar tool. node.js.

Since photon is the main core of c#, I also choose the network layer protocol between photon and node.js. I searched the Internet and found that grpc is good. Then I wrote a demo that can communicate with each other, so I decided to use node.js + grpc is used as the core of the project.

Plan the overall structure of the project as shown below:

Insert picture description here

pikachu-net is a game server with photon as the core. It manages the connections of all unity3d clients. It is stateful in the form of persistent connections. All business-related requests will be forwarded to pikachu-node, such as login, registration, etc.

pikachu-node, mainly business processing logic, can log in to games, etc. Use grpc to connect between pikachu-net and pikachu-node. pikachu-node is made into a stateless service, so it can be deployed as a cluster.

Let's talk about the implementation of pikachu-node in detail:

Since the game is related to geographic location, postgis/postgresql is used, and node.js uses knex.js as the connection tool.

There is no experience in integrating multiple services of grpc on the market, so referring to the express middleware design concept, I design a grpc framework of node.js to organize the code structure.

In node.js, grpc does not use the static compilation mode, but directly loads the proto file for processing.

Code management uses the oschina git private library. The server uses Alibaba Cloud, and the system is Windows. There is no way that photon can only be deployed on Windows.

At the beginning of the deployment code, I used ftp to copy and found it too uncomfortable. So I wrote a publishing service with webhook and express of oschina git. When my code is pushed to git, it will automatically update the code and restart the service. It turns out that this work is too wise and saves a lot of time.

The code services of node.js are managed by pm2.

Afterwards, the log viewing is also a problem. Because there is no ssh on windows, you can only use remote login to view. The current win has only one user, so two people cannot be online at the same time. The new one will kick the old one offline. This is how annoying. Every time I check the log, I can only ask me to view it, so I developed a simple web version of the log viewing page with express + socket.io. The world is quiet now.

Pikachu-net is compiled locally every time, and then uploaded to the server. Later, I also added this to the publishing service, and then I can push the code and restart the service directly.

Later planning:

Database management needs to be done, because the database fields are currently created manually, if you want to deploy a test environment, it is very difficult.

If you want to use grpc to replace photon to complete the communication, you can refer to this blog:
Unity + Grpc + protobuf + C# Detailed usage process

Guess you like

Origin blog.csdn.net/qq_43505432/article/details/110221366