Blame view

actions/RoleAction.go 1.07 KB
9644352a   zhangqijia   登录服改为http,游戏服改为长连...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
  package actions
  
  import (
  	"github.com/golang/protobuf/proto"
  	"pro2d/components/net"
  	"pro2d/conf"
  	"pro2d/models"
  	"pro2d/protos/pb"
  	"pro2d/utils"
  )
  
  func HeartRpc(msg *net.MsgPkg) (int32, proto.Message)   {
  	return 0, nil
  }
  
  func CreateRpc(msg *net.MsgPkg) (int32, proto.Message)   {
  	req := pb.CreateReq{}
  	if err := proto.Unmarshal(msg.Body, &req); err != nil {
  		utils.Sugar.Errorf("CreateRpc err: %v", err)
  		return 1, nil
  	}
  	role := models.RoleExistByUid(req.Uid)
  	if role != nil {
  		return 2, nil
  	}
  
  	roleId := conf.SnowFlack.NextVal()
  	role = models.NewRole(roleId)
  	if _, err := role.Create(); err != nil {
  		utils.Sugar.Errorf("CreateRpc role create err: %v", err)
  		return 3, nil
  	}
  	return 0, nil
  }
  
  func  LoginRpc(msg *net.MsgPkg) (int32, proto.Message)  {
  	req := pb.LoginReq{}
  	if err := proto.Unmarshal(msg.Body, &req); err != nil {
  		utils.Sugar.Errorf("loginRpc err: %v", err)
  		return 1, nil
  	}
  
  	role := models.RoleExistByUid(req.Uid)
  	if role == nil {
  		return 2, nil
  	}
  
  	return 0, &pb.RoleRsp{
  		Role:   role.Role,
  		Hero:   nil,
  		Team:   nil,
  		Equips: nil,
  	}
  }