leaf download address: https://github.com/name5566/leaf
leafserver download address: https://codeload.github.com/name5566/leafserver
Catalog description
leaf/chanrpc provides a channel-based RPC mechanism for communication between game server modules
leaf/db database related, currently supports MongoDB
leaf/gate gateway module, responsible for game client access
leaf/go is used to create goroutines that can be managed by Leaf
leaf/log log related
Leaf/network is related to the network. It uses the TCP protocol and can customize the message format. Currently, Leaf provides message formats based on protobuf and JSON.
leaf/recordfile is used to manage game data
leaf/timer timer related
leaf/util auxiliary library
Configuration file method
In leafserver/bin/conf/server.json, leaf can support both tcp and websocket, of course you need to be able to configure it
{
"LogLevel": "debug", log printing level
"LogPath": "", log printing path
"TCPAddr": "127.0.0.1:3563", tcp parameter setting
"MaxConnNum": 20000 Maximum number of connections
}
Package startup service
leafserver needs to include leaf and websocket. For the address of the package, see the import path. Thanks to the person who led the way in writing the reference. Mom no longer has to worry that I can’t find the address to download the package
After running and saving without errors, the go build command generates one. exe executable file, copy it to the leafserver/bin directory, run it, the following prompt will appear, everything is ok,
Interpret the main of this official website
First look at main.go, en…. Simple and clear, not bb
import lconf "github.com/name5566/leaf/conf"
func main() {
//-----------Load bin/conf/server/server.json into leafconf
lconf.LogLevel = conf.Server.LogLevel
lconf.LogPath = conf.Server.LogPath
lconf.LogFlag = conf.LogFlag
lconf.COnsolePort= conf.Server.ConsolePort
lconf.ProfilePath = conf.Server.ProfilePath
//Run the module
leaf.Run(
game.Module,
gate.Module,
login.Module,
)
}
Here are three modules: game, gate, and login registered in order. Each module needs to implement the interface:
type Module interface {
OnInit()
OnDestroy()
Run(closeSig chan bool)
}
Another thing to note is that pasting someone else’s paragraph
Unlike some web servers, most of the data running by Leaf is in the memory. Although the Mongo module is provided, the data for real-time interaction is generally stored in the memory. Mongo is just for persisting some user data. This is very different from some stateless web servers that rely on databases for data interaction.
How to use this server, let’s listen to the explanation next time