go_dreamfactory/cmd/robot/user.go
2022-06-08 10:32:52 +08:00

61 lines
1.0 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package robot
import (
"go_dreamfactory/comm"
"go_dreamfactory/pb"
"log"
)
func (r *Robot) handleUserMsg(msg *pb.UserMessage) {
switch msg.SubType {
case "login":
r.handleLogin(msg)
case "create":
r.handleCreateUser(msg)
}
}
//处理登录响应数据
func (r *Robot) handleLogin(msg *pb.UserMessage) {
rsp := &pb.UserLoginResp{}
if !comm.ProtoDecode(msg, rsp) {
return
}
printReply(msg, rsp)
//是否有登录数据返回
if rsp != nil {
r.user = rsp.Data
r.onUserLoaded()
} else {
r.AccountRegister() //请求Http接口模拟创建新账号
}
}
//创角
func (r *Robot) CreateUser(NickName string) {
req := &pb.UserCreateReq{
NickName: NickName,
}
head := &pb.UserMessage{
MainType: "user",
SubType: "create",
}
defer traceFunc(head.MainType, head.SubType, r.user.UserData.GetUserId(), req)
err := r.SendToClient(head, req)
if err != nil {
log.Fatal(err)
}
}
func (r *Robot) handleCreateUser(msg *pb.UserMessage) {
rsp := &pb.UserCreateRsp{}
if !comm.ProtoDecode(msg, rsp) {
return
}
printReply(msg, rsp)
}