/hk4e

『原神』 Game Server But Golang Ver.

Primary LanguageGoApache License 2.0Apache-2.0

hk4e

中文


What's this

A Genshin Impact game server written in Golang.

This project aims to build a high performance ARPG game server, instead of supporting all in-game features

The network protocols and configuration tables are mainly from version 3.2, so we suggest you to use a v3.2 client, although it is not necessary

Download version 3.2.0 from miHoYo

You need to use an https proxy and a patch to use it. Grasscutter is a good example.

You can use a newer patch to avoid using https proxies. It supports custom keys and multiple servers. Special thanks to Jx2f/mhypbase

Features

  • Native high-availability cluster architecture. Crashes on any node servers won't affect the whole system. So it is highly extendable
  • Player-level non-status game server. Non-lock single thread structure. Easy to develope. And fully-featured player data exchanger(Memory<->Cache<->Database), say goodbye to
  • synchronization-blocked database access
  • Grand new cross-server player migration
  • Gateway server side client protocol proxy conversion. Never worry about code changes caused by confusions of message number and protocol number
  • Fully-featured key exchanging strategy with enhanced security, instead of using an existing random seed with an XOR key file all day long

Compile and working environment

  • Go >= 1.18
  • Protoc >= 3.21
  • Protoc Gen Go >= 1.28
  • Docker >= 20.10
  • Docker Compose >= 1.29

This project is built without CGO. Both Windows and Linux systems can compile and run it. While you need to use CGO on MacOS since it hasn't impleted unix.Gettid

Get start

  • Install on first launch
make dev_tool
  • Generate protocol
make gen_natsrpc      # Generate natsrpc protocol
make gen_proto        # Generate client protocol
make gen_client_proto # Generate client proxy protocol(not very necessary, for further informations: gate/client_proto/README.md)
  • Compile
make build         # Compile server to binary file
make docker_config # Copy files like config templates, etc.
make docker_build  # Build a Docker image
  • Launch
cd docker
# Checkout all configurations before launch(e.g. docker/node/bin/application.toml)
docker-compose up -d # Launch server

Third-party dependencies

  • mongodb
  • nats-server
  • redis

Server components

  • node Node server (Single node, with status)
  • dispatch Login server (Multi nodes, without status)
  • gate Gateway server (Multi nodes, with status)
  • anticheat Anti-cheat server (Multi nodes, with status STILL UNDER CONSTRUCTION)
  • pathfinding Path-finding server (Multi nodes, without status STILL UNDER CONSTRUCTION)
  • gs Game server (Multi nodes, with status)
  • gm Game menagement server (Single node, without status)

Misc

  • You need to add the following environment variable to run as standalone server
GOLANG_PROTOBUF_REGISTRATION_CONFLICT=ignore

Code submission specifications

  • You MUST run go fmt before commit
  • Please ignore directory gdconf when running global formatting. These are config tables, including lots of json, loa, txt files
  • Add a space between // and your comments when writing inline comments
  • Split standard packages, local packages and third-party packages with linebreaks