The preprocessing process of the client message in the agent.
Agent-defined three types of requests:
//api.go
var RCode = map[int16]string{
0: "heart_beat_req", // 心跳包..
1: "heart_beat_ack", // 心跳包回复
10: "user_login_req", // 登陆
11: "user_login_succeed_ack", // 登陆成功
12: "user_login_faild_ack", // 登陆失败
13: "client_error_ack", // 客户端错误
30: "get_seed_req", // socket通信加密使用
31: "get_seed_ack", // socket通信加密使用
}
The above paragraph is intercepted in Api.go, which defines the protocol number and the name of the corresponding message.
End With Req is the request, and the ACK ends with a reply.
'//api.go
var handlers map[int16]func (*session, *packet. Packet) []byte
Func init () {
handlers = Map[int16]func (*session, *packet. Packet) []byte{
0:p_heart_beat_req,
10:p_user_login_req,
30:p_get_seed_req,
}
}
`
Or in Api.go, the processing method corresponding to the request is defined, and these methods are recorded in the handlers. The definition of the method is in file Client_handler/handle.go.
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Gonet2 Game Server Framework Parsing agent (3)