update login
This commit is contained in:
parent
6e9bad8887
commit
d4fa18143a
552
bin/json/tbhero.json
Normal file
552
bin/json/tbhero.json
Normal file
@ -0,0 +1,552 @@
|
||||
[
|
||||
{
|
||||
"id": "11001",
|
||||
"name": "阿宝",
|
||||
"star": 4,
|
||||
"color": 3,
|
||||
"chengwei": 3,
|
||||
"zhongzu": 1,
|
||||
"job": 1,
|
||||
"type": 1,
|
||||
"prefab": "Person/11001.prefab",
|
||||
"icon": "11001",
|
||||
"sound": "121323",
|
||||
"tujing": "[1]",
|
||||
"hpgrow": "57.4",
|
||||
"atkgrow": "7.2",
|
||||
"defgrow": "5.6",
|
||||
"speedgrow": "2",
|
||||
"hp": "576",
|
||||
"atk": "73",
|
||||
"def": "57",
|
||||
"speed": "174",
|
||||
"intr": "",
|
||||
"events": "EventDataSet/Hero_11001.asset",
|
||||
"cite": ""
|
||||
},
|
||||
{
|
||||
"id": "11002",
|
||||
"name": "原始人",
|
||||
"star": 5,
|
||||
"color": 4,
|
||||
"chengwei": 3,
|
||||
"zhongzu": 1,
|
||||
"job": 1,
|
||||
"type": 1,
|
||||
"prefab": "Person/11002.prefab",
|
||||
"icon": "11002",
|
||||
"sound": "11002",
|
||||
"tujing": "[1]",
|
||||
"hpgrow": "82.9",
|
||||
"atkgrow": "9.4",
|
||||
"defgrow": "5.8",
|
||||
"speedgrow": "2",
|
||||
"hp": "830",
|
||||
"atk": "95",
|
||||
"def": "59",
|
||||
"speed": "193",
|
||||
"intr": "",
|
||||
"events": "EventDataSet/Hero_11002.asset",
|
||||
"cite": ""
|
||||
},
|
||||
{
|
||||
"id": "11003",
|
||||
"name": "波比",
|
||||
"star": 5,
|
||||
"color": 4,
|
||||
"chengwei": 3,
|
||||
"zhongzu": 1,
|
||||
"job": 1,
|
||||
"type": 1,
|
||||
"prefab": "Person/11003.prefab",
|
||||
"icon": "11003",
|
||||
"sound": "11003",
|
||||
"tujing": "[1]",
|
||||
"hpgrow": "82.9",
|
||||
"atkgrow": "9.4",
|
||||
"defgrow": "5.8",
|
||||
"speedgrow": "2",
|
||||
"hp": "830",
|
||||
"atk": "95",
|
||||
"def": "59",
|
||||
"speed": "193",
|
||||
"intr": "",
|
||||
"events": "EventDataSet/Hero_11003.asset",
|
||||
"cite": ""
|
||||
},
|
||||
{
|
||||
"id": "11004",
|
||||
"name": "布兰",
|
||||
"star": 5,
|
||||
"color": 4,
|
||||
"chengwei": 3,
|
||||
"zhongzu": 1,
|
||||
"job": 1,
|
||||
"type": 1,
|
||||
"prefab": "11004",
|
||||
"icon": "11004",
|
||||
"sound": "11004",
|
||||
"tujing": "[1]",
|
||||
"hpgrow": "82.9",
|
||||
"atkgrow": "9.4",
|
||||
"defgrow": "5.8",
|
||||
"speedgrow": "2",
|
||||
"hp": "830",
|
||||
"atk": "95",
|
||||
"def": "59",
|
||||
"speed": "193",
|
||||
"intr": "",
|
||||
"events": "hero_2011",
|
||||
"cite": ""
|
||||
},
|
||||
{
|
||||
"id": "11005",
|
||||
"name": "无牙仔",
|
||||
"star": 4,
|
||||
"color": 3,
|
||||
"chengwei": 3,
|
||||
"zhongzu": 1,
|
||||
"job": 1,
|
||||
"type": 1,
|
||||
"prefab": "Person/11001.prefab",
|
||||
"icon": "11005",
|
||||
"sound": "121323",
|
||||
"tujing": "[1]",
|
||||
"hpgrow": "57.4",
|
||||
"atkgrow": "7.2",
|
||||
"defgrow": "5.6",
|
||||
"speedgrow": "2",
|
||||
"hp": "576",
|
||||
"atk": "73",
|
||||
"def": "57",
|
||||
"speed": "174",
|
||||
"intr": "",
|
||||
"events": "EventDataSet/Hero_11001.asset",
|
||||
"cite": ""
|
||||
},
|
||||
{
|
||||
"id": "11006",
|
||||
"name": "亚丝翠",
|
||||
"star": 5,
|
||||
"color": 4,
|
||||
"chengwei": 3,
|
||||
"zhongzu": 1,
|
||||
"job": 1,
|
||||
"type": 1,
|
||||
"prefab": "11006",
|
||||
"icon": "11006",
|
||||
"sound": "11006",
|
||||
"tujing": "[1]",
|
||||
"hpgrow": "82.9",
|
||||
"atkgrow": "9.4",
|
||||
"defgrow": "5.8",
|
||||
"speedgrow": "2",
|
||||
"hp": "830",
|
||||
"atk": "95",
|
||||
"def": "59",
|
||||
"speed": "193",
|
||||
"intr": "",
|
||||
"events": "hero_2011",
|
||||
"cite": ""
|
||||
},
|
||||
{
|
||||
"id": "11009",
|
||||
"name": "希卡普",
|
||||
"star": 4,
|
||||
"color": 3,
|
||||
"chengwei": 4,
|
||||
"zhongzu": 2,
|
||||
"job": 2,
|
||||
"type": 1,
|
||||
"prefab": "11009",
|
||||
"icon": "11009",
|
||||
"sound": "11009",
|
||||
"tujing": "[1]",
|
||||
"hpgrow": "38.6",
|
||||
"atkgrow": "10.5",
|
||||
"defgrow": "5.7",
|
||||
"speedgrow": "2",
|
||||
"hp": "389",
|
||||
"atk": "106",
|
||||
"def": "58",
|
||||
"speed": "165",
|
||||
"intr": "",
|
||||
"events": "EventDataSet/Hero_11009.asset",
|
||||
"cite": ""
|
||||
},
|
||||
{
|
||||
"id": "22002",
|
||||
"name": "沈王爷青春版",
|
||||
"star": 5,
|
||||
"color": 4,
|
||||
"chengwei": 4,
|
||||
"zhongzu": 2,
|
||||
"job": 2,
|
||||
"type": 1,
|
||||
"prefab": "22002",
|
||||
"icon": "22002",
|
||||
"sound": "22002",
|
||||
"tujing": "[1]",
|
||||
"hpgrow": "55.6",
|
||||
"atkgrow": "13.6",
|
||||
"defgrow": "5.9",
|
||||
"speedgrow": "2",
|
||||
"hp": "561",
|
||||
"atk": "137",
|
||||
"def": "60",
|
||||
"speed": "183",
|
||||
"intr": "",
|
||||
"events": "hero_2011",
|
||||
"cite": ""
|
||||
},
|
||||
{
|
||||
"id": "90001",
|
||||
"name": "邪恶阿宝",
|
||||
"star": 4,
|
||||
"color": 3,
|
||||
"chengwei": 3,
|
||||
"zhongzu": 1,
|
||||
"job": 1,
|
||||
"type": 1,
|
||||
"prefab": "Person/90001.prefab",
|
||||
"icon": "90001",
|
||||
"sound": "90001",
|
||||
"tujing": "[1]",
|
||||
"hpgrow": "57.4",
|
||||
"atkgrow": "7.2",
|
||||
"defgrow": "5.6",
|
||||
"speedgrow": "2",
|
||||
"hp": "576",
|
||||
"atk": "73",
|
||||
"def": "57",
|
||||
"speed": "174",
|
||||
"intr": "",
|
||||
"events": "hero_90001",
|
||||
"cite": "11001"
|
||||
},
|
||||
{
|
||||
"id": "11011",
|
||||
"name": "浣熊",
|
||||
"star": 4,
|
||||
"color": 3,
|
||||
"chengwei": 4,
|
||||
"zhongzu": 2,
|
||||
"job": 2,
|
||||
"type": 1,
|
||||
"prefab": "11011",
|
||||
"icon": "11011",
|
||||
"sound": "11011",
|
||||
"tujing": "[1]",
|
||||
"hpgrow": "38.6",
|
||||
"atkgrow": "10.5",
|
||||
"defgrow": "5.7",
|
||||
"speedgrow": "2",
|
||||
"hp": "389",
|
||||
"atk": "106",
|
||||
"def": "58",
|
||||
"speed": "165",
|
||||
"intr": "",
|
||||
"events": "EventDataSet/Hero_11011.asset",
|
||||
"cite": ""
|
||||
},
|
||||
{
|
||||
"id": "11008",
|
||||
"name": "悍娇虎",
|
||||
"star": 5,
|
||||
"color": 4,
|
||||
"chengwei": 4,
|
||||
"zhongzu": 2,
|
||||
"job": 2,
|
||||
"type": 1,
|
||||
"prefab": "11008",
|
||||
"icon": "11008",
|
||||
"sound": "11008",
|
||||
"tujing": "[1]",
|
||||
"hpgrow": "55.6",
|
||||
"atkgrow": "13.6",
|
||||
"defgrow": "5.9",
|
||||
"speedgrow": "2",
|
||||
"hp": "561",
|
||||
"atk": "137",
|
||||
"def": "60",
|
||||
"speed": "183",
|
||||
"intr": "",
|
||||
"events": "hero_2011",
|
||||
"cite": ""
|
||||
},
|
||||
{
|
||||
"id": "11017",
|
||||
"name": "冰霜杰克",
|
||||
"star": 5,
|
||||
"color": 4,
|
||||
"chengwei": 4,
|
||||
"zhongzu": 2,
|
||||
"job": 2,
|
||||
"type": 1,
|
||||
"prefab": "11017",
|
||||
"icon": "11017",
|
||||
"sound": "11017",
|
||||
"tujing": "[1]",
|
||||
"hpgrow": "55.6",
|
||||
"atkgrow": "13.6",
|
||||
"defgrow": "5.9",
|
||||
"speedgrow": "2",
|
||||
"hp": "561",
|
||||
"atk": "137",
|
||||
"def": "60",
|
||||
"speed": "183",
|
||||
"intr": "",
|
||||
"events": "EventDataSet/Hero_11017.asset",
|
||||
"cite": ""
|
||||
},
|
||||
{
|
||||
"id": "11018",
|
||||
"name": "睡神",
|
||||
"star": 5,
|
||||
"color": 4,
|
||||
"chengwei": 4,
|
||||
"zhongzu": 2,
|
||||
"job": 2,
|
||||
"type": 1,
|
||||
"prefab": "11018",
|
||||
"icon": "11018",
|
||||
"sound": "11018",
|
||||
"tujing": "[1]",
|
||||
"hpgrow": "55.6",
|
||||
"atkgrow": "13.6",
|
||||
"defgrow": "5.9",
|
||||
"speedgrow": "2",
|
||||
"hp": "561",
|
||||
"atk": "137",
|
||||
"def": "60",
|
||||
"speed": "183",
|
||||
"intr": "",
|
||||
"events": "EventDataSet/Hero_11018.asset",
|
||||
"cite": ""
|
||||
},
|
||||
{
|
||||
"id": "11019",
|
||||
"name": "莫甘娜",
|
||||
"star": 5,
|
||||
"color": 4,
|
||||
"chengwei": 4,
|
||||
"zhongzu": 2,
|
||||
"job": 2,
|
||||
"type": 1,
|
||||
"prefab": "11019",
|
||||
"icon": "11019",
|
||||
"sound": "11019",
|
||||
"tujing": "[1]",
|
||||
"hpgrow": "55.6",
|
||||
"atkgrow": "13.6",
|
||||
"defgrow": "5.9",
|
||||
"speedgrow": "2",
|
||||
"hp": "561",
|
||||
"atk": "137",
|
||||
"def": "60",
|
||||
"speed": "183",
|
||||
"intr": "",
|
||||
"events": "EventDataSet/Hero_11019.asset",
|
||||
"cite": ""
|
||||
},
|
||||
{
|
||||
"id": "11020",
|
||||
"name": "莫甘娜二阶段",
|
||||
"star": 5,
|
||||
"color": 4,
|
||||
"chengwei": 4,
|
||||
"zhongzu": 2,
|
||||
"job": 2,
|
||||
"type": 1,
|
||||
"prefab": "11020",
|
||||
"icon": "11020",
|
||||
"sound": "11020",
|
||||
"tujing": "[1]",
|
||||
"hpgrow": "55.6",
|
||||
"atkgrow": "13.6",
|
||||
"defgrow": "5.9",
|
||||
"speedgrow": "2",
|
||||
"hp": "561",
|
||||
"atk": "137",
|
||||
"def": "60",
|
||||
"speed": "183",
|
||||
"intr": "",
|
||||
"events": "EventDataSet/Hero_11020.asset",
|
||||
"cite": ""
|
||||
},
|
||||
{
|
||||
"id": "11021",
|
||||
"name": "莫甘娜巨怪",
|
||||
"star": 5,
|
||||
"color": 4,
|
||||
"chengwei": 4,
|
||||
"zhongzu": 2,
|
||||
"job": 2,
|
||||
"type": 1,
|
||||
"prefab": "11021",
|
||||
"icon": "11021",
|
||||
"sound": "11021",
|
||||
"tujing": "[1]",
|
||||
"hpgrow": "55.6",
|
||||
"atkgrow": "13.6",
|
||||
"defgrow": "5.9",
|
||||
"speedgrow": "2",
|
||||
"hp": "561",
|
||||
"atk": "137",
|
||||
"def": "60",
|
||||
"speed": "183",
|
||||
"intr": "",
|
||||
"events": "EventDataSet/Hero_11021.asset",
|
||||
"cite": ""
|
||||
},
|
||||
{
|
||||
"id": "11099",
|
||||
"name": "触手",
|
||||
"star": 5,
|
||||
"color": 4,
|
||||
"chengwei": 4,
|
||||
"zhongzu": 2,
|
||||
"job": 2,
|
||||
"type": 1,
|
||||
"prefab": "11099",
|
||||
"icon": "11099",
|
||||
"sound": "11099",
|
||||
"tujing": "[1]",
|
||||
"hpgrow": "55.6",
|
||||
"atkgrow": "13.6",
|
||||
"defgrow": "5.9",
|
||||
"speedgrow": "2",
|
||||
"hp": "561",
|
||||
"atk": "137",
|
||||
"def": "60",
|
||||
"speed": "183",
|
||||
"intr": "",
|
||||
"events": "EventDataSet/Hero_11099.asset",
|
||||
"cite": ""
|
||||
},
|
||||
{
|
||||
"id": "12001",
|
||||
"name": "黑化阿宝",
|
||||
"star": 5,
|
||||
"color": 4,
|
||||
"chengwei": 4,
|
||||
"zhongzu": 2,
|
||||
"job": 2,
|
||||
"type": 1,
|
||||
"prefab": "Person/12001.prefab",
|
||||
"icon": "12001",
|
||||
"sound": "121323",
|
||||
"tujing": "[1]",
|
||||
"hpgrow": "57.4",
|
||||
"atkgrow": "7.2",
|
||||
"defgrow": "5.6",
|
||||
"speedgrow": "2",
|
||||
"hp": "576",
|
||||
"atk": "73",
|
||||
"def": "57",
|
||||
"speed": "174",
|
||||
"intr": "",
|
||||
"events": "EventDataSet/Hero_12001.asset",
|
||||
"cite": ""
|
||||
},
|
||||
{
|
||||
"id": "12003",
|
||||
"name": "黑化包比",
|
||||
"star": 5,
|
||||
"color": 4,
|
||||
"chengwei": 4,
|
||||
"zhongzu": 2,
|
||||
"job": 2,
|
||||
"type": 1,
|
||||
"prefab": "Person/11003.prefab",
|
||||
"icon": "12003",
|
||||
"sound": "12003",
|
||||
"tujing": "[1]",
|
||||
"hpgrow": "82.9",
|
||||
"atkgrow": "9.4",
|
||||
"defgrow": "5.8",
|
||||
"speedgrow": "2",
|
||||
"hp": "830",
|
||||
"atk": "95",
|
||||
"def": "59",
|
||||
"speed": "193",
|
||||
"intr": "",
|
||||
"events": "EventDataSet/Hero_11003.asset",
|
||||
"cite": "11003"
|
||||
},
|
||||
{
|
||||
"id": "12009",
|
||||
"name": "黑化希卡普",
|
||||
"star": 5,
|
||||
"color": 4,
|
||||
"chengwei": 4,
|
||||
"zhongzu": 2,
|
||||
"job": 2,
|
||||
"type": 1,
|
||||
"prefab": "12009",
|
||||
"icon": "11009",
|
||||
"sound": "11009",
|
||||
"tujing": "[1]",
|
||||
"hpgrow": "38.6",
|
||||
"atkgrow": "10.5",
|
||||
"defgrow": "5.7",
|
||||
"speedgrow": "2",
|
||||
"hp": "389",
|
||||
"atk": "106",
|
||||
"def": "58",
|
||||
"speed": "165",
|
||||
"intr": "",
|
||||
"events": "EventDataSet/Hero_11009.asset",
|
||||
"cite": ""
|
||||
},
|
||||
{
|
||||
"id": "12017",
|
||||
"name": "黑化杰克",
|
||||
"star": 5,
|
||||
"color": 4,
|
||||
"chengwei": 4,
|
||||
"zhongzu": 2,
|
||||
"job": 2,
|
||||
"type": 1,
|
||||
"prefab": "12017",
|
||||
"icon": "12017",
|
||||
"sound": "12017",
|
||||
"tujing": "[1]",
|
||||
"hpgrow": "55.6",
|
||||
"atkgrow": "13.6",
|
||||
"defgrow": "5.9",
|
||||
"speedgrow": "2",
|
||||
"hp": "561",
|
||||
"atk": "137",
|
||||
"def": "60",
|
||||
"speed": "183",
|
||||
"intr": "",
|
||||
"events": "EventDataSet/Hero_11017.asset",
|
||||
"cite": ""
|
||||
},
|
||||
{
|
||||
"id": "12018",
|
||||
"name": "黑化睡神",
|
||||
"star": 5,
|
||||
"color": 4,
|
||||
"chengwei": 4,
|
||||
"zhongzu": 2,
|
||||
"job": 2,
|
||||
"type": 1,
|
||||
"prefab": "12018",
|
||||
"icon": "12018",
|
||||
"sound": "12018",
|
||||
"tujing": "[1]",
|
||||
"hpgrow": "55.6",
|
||||
"atkgrow": "13.6",
|
||||
"defgrow": "5.9",
|
||||
"speedgrow": "2",
|
||||
"hp": "561",
|
||||
"atk": "137",
|
||||
"def": "60",
|
||||
"speed": "183",
|
||||
"intr": "",
|
||||
"events": "EventDataSet/Hero_11018.asset",
|
||||
"cite": "11018"
|
||||
}
|
||||
]
|
@ -1,47 +1,55 @@
|
||||
package robot
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"go_dreamfactory/comm"
|
||||
"go_dreamfactory/pb"
|
||||
"go_dreamfactory/utils"
|
||||
"log"
|
||||
"time"
|
||||
|
||||
jsoniter "github.com/json-iterator/go"
|
||||
"github.com/nacos-group/nacos-sdk-go/util"
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
func (r *Robot) handleLogin(msg *pb.UserMessage) {
|
||||
switch msg.SubType {
|
||||
case "login":
|
||||
handleLogin(r, msg)
|
||||
default:
|
||||
log.Fatal("methodName no exist")
|
||||
}
|
||||
type LoginParam struct {
|
||||
Account string `json:"account"`
|
||||
ServerId int `json:"serverId"`
|
||||
TimeStamp int64 `json:"timestamp"`
|
||||
}
|
||||
|
||||
//处理接口响应数据
|
||||
func handleLogin(r *Robot, msg *pb.UserMessage) {
|
||||
rsp := &pb.UserLoginResp{}
|
||||
if !comm.ProtoDecode(msg, rsp) {
|
||||
return
|
||||
}
|
||||
log.Printf("to client: %v", rsp.Data)
|
||||
func (r *Robot) BuildSecStr() string {
|
||||
jsonByte, _ := jsoniter.Marshal(&LoginParam{
|
||||
Account: r.Opts.Account,
|
||||
ServerId: r.Opts.ServerId,
|
||||
TimeStamp: time.Now().Unix(),
|
||||
})
|
||||
jsonBase64 := utils.Base64Encode(jsonByte)
|
||||
log.Printf("client base64:%s", jsonBase64)
|
||||
clientMd5key := util.Md5(jsonBase64)
|
||||
log.Printf("client md5:%s", clientMd5key)
|
||||
return fmt.Sprintf("CE:%s%s", clientMd5key, jsonBase64)
|
||||
}
|
||||
|
||||
//处理登录请求
|
||||
func (r *Robot) AccountLogin() {
|
||||
//登录
|
||||
sec := r.BuildSecStr()
|
||||
log.Printf("client secret key:%s", sec)
|
||||
loginReg := &pb.UserLoginReq{
|
||||
Name: r.Opts.Account,
|
||||
Sec: sec,
|
||||
}
|
||||
|
||||
head := &pb.UserMessage{
|
||||
MainType: "login",
|
||||
MainType: "user",
|
||||
SubType: "login",
|
||||
}
|
||||
if comm.ProtoEncode(loginReg, head) {
|
||||
data, _ := proto.Marshal(head)
|
||||
err := r.SendToClient(data)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
log.Fatalf("send err:%v", err)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -5,6 +5,8 @@ type Options struct {
|
||||
RegUrl string //账号注册接口地址
|
||||
Account string //玩家账号
|
||||
Create bool
|
||||
Secretkey string //秘钥串
|
||||
ServerId int
|
||||
}
|
||||
|
||||
func DefaultOpts() *Options {
|
||||
@ -12,6 +14,7 @@ func DefaultOpts() *Options {
|
||||
WsUrl: "ws://localhost:7891/gateway",
|
||||
RegUrl: "http://localhost:8000/register",
|
||||
Create: false,
|
||||
ServerId: 1,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -39,7 +39,6 @@ func (r *Robot) Run() {
|
||||
if r.Opts.Create { //创建新用户
|
||||
r.AccountRegister()
|
||||
} else {
|
||||
//login user
|
||||
r.AccountLogin()
|
||||
}
|
||||
|
||||
@ -62,10 +61,9 @@ func (r *Robot) Run() {
|
||||
select {}
|
||||
}
|
||||
|
||||
//模块处理
|
||||
func (r *Robot) handleMsg(msg *pb.UserMessage) {
|
||||
switch msg.MainType {
|
||||
case "login":
|
||||
r.handleLogin(msg)
|
||||
case "user":
|
||||
r.handleUserMsg(msg)
|
||||
default:
|
||||
@ -73,6 +71,7 @@ func (r *Robot) handleMsg(msg *pb.UserMessage) {
|
||||
}
|
||||
}
|
||||
|
||||
//在这里添加玩家成功登录以后的测试方法
|
||||
func (r *Robot) onUserLoaded() {
|
||||
|
||||
}
|
||||
@ -103,13 +102,14 @@ func (r *Robot) AccountRegister() {
|
||||
err = jsoniter.Unmarshal(body, regRsp)
|
||||
|
||||
if regRsp.Code == pb.ErrorCode_Success { //注册成功
|
||||
|
||||
//登录
|
||||
loginReg := &pb.UserLoginReq{
|
||||
Name: regReq.Account,
|
||||
Sec: r.BuildSecStr(),
|
||||
}
|
||||
|
||||
head := &pb.UserMessage{
|
||||
MainType: "login",
|
||||
MainType: "user",
|
||||
SubType: "login",
|
||||
}
|
||||
if comm.ProtoEncode(loginReg, head) {
|
||||
|
@ -3,37 +3,40 @@ package robot
|
||||
import (
|
||||
"go_dreamfactory/comm"
|
||||
"go_dreamfactory/pb"
|
||||
|
||||
"github.com/liwei1dao/lego/sys/log"
|
||||
"log"
|
||||
)
|
||||
|
||||
func (r *Robot) handleUserMsg(msg *pb.UserMessage) {
|
||||
|
||||
switch msg.SubType {
|
||||
//创建账号
|
||||
case "login":
|
||||
handleLogin(r, msg)
|
||||
case "create":
|
||||
case "load":
|
||||
|
||||
handleCreateUser(r, msg)
|
||||
}
|
||||
|
||||
//加载玩家数据
|
||||
if msg.SubType == "load" {
|
||||
rsp := &pb.UserLoadRsp{}
|
||||
}
|
||||
|
||||
//处理登录响应数据
|
||||
func handleLogin(r *Robot, msg *pb.UserMessage) {
|
||||
rsp := &pb.UserLoginResp{}
|
||||
if !comm.ProtoDecode(msg, rsp) {
|
||||
log.Fatal("load user err")
|
||||
return
|
||||
}
|
||||
log.Printf("登录返回: %v", rsp)
|
||||
|
||||
if rsp.Data.UserData.UserId != "" {
|
||||
//是否有登录数据返回
|
||||
if rsp != nil {
|
||||
r.onUserLoaded()
|
||||
} else {
|
||||
log.Debugf("%s不存在", r.Opts.Account)
|
||||
//创建
|
||||
|
||||
}
|
||||
|
||||
r.AccountRegister() //请求Http接口,模拟创建新账号
|
||||
}
|
||||
}
|
||||
|
||||
func handleCreateUser(r *Robot, msg *pb.UserMessage) {
|
||||
|
||||
}
|
||||
|
||||
//创角色
|
||||
func (r *Robot) CreateUser() {
|
||||
|
||||
}
|
||||
|
@ -16,7 +16,7 @@ const (
|
||||
const (
|
||||
SM_GateModule core.M_Modules = "gateway" //gate模块 网关服务模块
|
||||
SM_WebModule core.M_Modules = "web" //web模块
|
||||
SM_LoginModule core.M_Modules = "user" //用户模块
|
||||
SM_UserModule core.M_Modules = "user" //用户模块
|
||||
SM_PackModule core.M_Modules = "pack" //背包模块
|
||||
)
|
||||
|
||||
@ -30,6 +30,10 @@ const ( //Rpc
|
||||
Rpc_GatewayAgentClose core.Rpc_Key = "Rpc_GatewayAgentClose" //代理关闭 关闭用户连接
|
||||
)
|
||||
|
||||
const (
|
||||
Event_UserLogin core.Event_Key = "Event_UserLogin" //登录事件
|
||||
)
|
||||
|
||||
type ISC_GateRouteComp interface {
|
||||
core.IServiceComp
|
||||
RegisterRoute(methodName string, comp reflect.Value, msg reflect.Type, fn reflect.Method)
|
||||
|
@ -48,7 +48,7 @@ func (this *UserSession) Build(uid string) (err error) {
|
||||
UserSessionId: this.SessionId,
|
||||
UserId: uid,
|
||||
}, reply); err != nil {
|
||||
log.Errorf("UserSession:%s UserId:%d Build:%s err:%v", this.SessionId, this.UserId, err)
|
||||
log.Errorf("UserSession:%s UserId:%s Build:%s err:%v", this.SessionId, this.UserId, err)
|
||||
}
|
||||
return
|
||||
}
|
||||
@ -58,7 +58,7 @@ func (this *UserSession) UnBuild(ServiceMethod string, msg proto.Message) (err e
|
||||
if err := this.service.RpcCallById(this.GatewayServiceId, string(Rpc_GatewayAgentUnBuild), context.Background(), &pb.AgentUnBuildReq{
|
||||
UserSessionId: this.SessionId,
|
||||
}, reply); err != nil {
|
||||
log.Errorf("UserSession:%s UserId:%d UnBuild err:%v", this.SessionId, this.UserId, err)
|
||||
log.Errorf("UserSession:%s UserId:%s UnBuild err:%v", this.SessionId, this.UserId, err)
|
||||
}
|
||||
return
|
||||
}
|
||||
@ -74,7 +74,7 @@ func (this *UserSession) SendMsg(mainType, subType string, code pb.ErrorCode, ms
|
||||
Code: code,
|
||||
Data: data,
|
||||
}, reply); err != nil {
|
||||
log.Errorf("UserSession:%s UserId:%d SendMsg:%s err:%v", this.SessionId, this.UserId, mainType, err)
|
||||
log.Errorf("UserSession:%s UserId:%s SendMsg:%s err:%v", this.SessionId, this.UserId, mainType, err)
|
||||
}
|
||||
return
|
||||
}
|
||||
@ -89,5 +89,5 @@ func (this *UserSession) Close() (err error) {
|
||||
}
|
||||
|
||||
func (this *UserSession) ToString() string {
|
||||
return fmt.Sprintf("SessionId:%s UserId:%d GatewayServiceId:%s", this.SessionId, this.UserId, this.GatewayServiceId)
|
||||
return fmt.Sprintf("SessionId:%s UserId:%s GatewayServiceId:%s", this.SessionId, this.UserId, this.GatewayServiceId)
|
||||
}
|
||||
|
3
go.mod
3
go.mod
@ -10,6 +10,7 @@ require (
|
||||
github.com/spf13/cobra v1.2.1
|
||||
github.com/spf13/pflag v1.0.5
|
||||
github.com/stretchr/testify v1.7.1
|
||||
github.com/tidwall/gjson v1.14.1
|
||||
go.mongodb.org/mongo-driver v1.5.1
|
||||
google.golang.org/protobuf v1.28.0
|
||||
)
|
||||
@ -98,6 +99,8 @@ require (
|
||||
github.com/soheilhy/cmux v0.1.5 // indirect
|
||||
github.com/templexxx/cpufeat v0.0.0-20180724012125-cef66df7f161 // indirect
|
||||
github.com/templexxx/xor v0.0.0-20191217153810-f85b25db303b // indirect
|
||||
github.com/tidwall/match v1.1.1 // indirect
|
||||
github.com/tidwall/pretty v1.2.0 // indirect
|
||||
github.com/tinylib/msgp v1.1.6 // indirect
|
||||
github.com/tjfoc/gmsm v1.4.1 // indirect
|
||||
github.com/toolkits/concurrent v0.0.0-20150624120057-a4371d70e3e3 // indirect
|
||||
|
7
go.sum
7
go.sum
@ -783,8 +783,13 @@ github.com/templexxx/cpufeat v0.0.0-20180724012125-cef66df7f161 h1:89CEmDvlq/F7S
|
||||
github.com/templexxx/cpufeat v0.0.0-20180724012125-cef66df7f161/go.mod h1:wM7WEvslTq+iOEAMDLSzhVuOt5BRZ05WirO+b09GHQU=
|
||||
github.com/templexxx/xor v0.0.0-20191217153810-f85b25db303b h1:fj5tQ8acgNUr6O8LEplsxDhUIe2573iLkJc+PqnzZTI=
|
||||
github.com/templexxx/xor v0.0.0-20191217153810-f85b25db303b/go.mod h1:5XA7W9S6mni3h5uvOC75dA3m9CCCaS83lltmc0ukdi4=
|
||||
github.com/tidwall/pretty v1.0.0 h1:HsD+QiTn7sK6flMKIvNmpqz1qrpP3Ps6jOKIKMooyg4=
|
||||
github.com/tidwall/gjson v1.14.1 h1:iymTbGkQBhveq21bEvAQ81I0LEBork8BFe1CUZXdyuo=
|
||||
github.com/tidwall/gjson v1.14.1/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
|
||||
github.com/tidwall/match v1.1.1 h1:+Ho715JplO36QYgwN9PGYNhgZvoUSc9X2c80KVTi+GA=
|
||||
github.com/tidwall/match v1.1.1/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM=
|
||||
github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk=
|
||||
github.com/tidwall/pretty v1.2.0 h1:RWIZEg2iJ8/g6fDDYzMpobmaoGh5OLl4AXtGUGPcqCs=
|
||||
github.com/tidwall/pretty v1.2.0/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU=
|
||||
github.com/tinylib/msgp v1.1.6 h1:i+SbKraHhnrf9M5MYmvQhFnbLhAXSDWF8WWsuyRdocw=
|
||||
github.com/tinylib/msgp v1.1.6/go.mod h1:75BAfg2hauQhs3qedfdDZmWAPcFMAvJE5b9rGOMufyw=
|
||||
github.com/tjfoc/gmsm v1.4.1 h1:aMe1GlZb+0bLjn+cKTPEvvn9oUEBlJitaZiiBwsbgho=
|
||||
|
@ -52,19 +52,19 @@ func (this *Agent) readLoop() {
|
||||
locp:
|
||||
for {
|
||||
if _, data, err = this.wsConn.ReadMessage(); err != nil {
|
||||
log.Errorf("agent:%s uId:%d ReadMessage err:%v", this.sessionId, this.uId, err)
|
||||
log.Errorf("agent:%s uId:%s ReadMessage err:%v", this.sessionId, this.uId, err)
|
||||
go this.Close()
|
||||
break locp
|
||||
}
|
||||
if err = proto.Unmarshal(data, msg); err != nil {
|
||||
log.Errorf("agent:%s uId:%d Unmarshal err:%v", this.sessionId, this.uId, err)
|
||||
log.Errorf("agent:%s uId:%s Unmarshal err:%v", this.sessionId, this.uId, err)
|
||||
go this.Close()
|
||||
break locp
|
||||
} else {
|
||||
this.messageDistribution(msg)
|
||||
}
|
||||
}
|
||||
log.Debugf("agent:%s uId:%d readLoop end!", this.sessionId, this.uId)
|
||||
log.Debugf("agent:%s uId:%s readLoop end!", this.sessionId, this.uId)
|
||||
}
|
||||
|
||||
func (this *Agent) writeLoop() {
|
||||
@ -90,7 +90,7 @@ locp:
|
||||
}
|
||||
}
|
||||
}
|
||||
log.Debugf("agent:%s uId:%d writeLoop end!", this.sessionId, this.uId)
|
||||
log.Debugf("agent:%s uId:%s writeLoop end!", this.sessionId, this.uId)
|
||||
}
|
||||
|
||||
func (this *Agent) SessionId() string {
|
||||
@ -135,7 +135,7 @@ func (this *Agent) Close() {
|
||||
//分发用户消息
|
||||
func (this *Agent) messageDistribution(msg *pb.UserMessage) {
|
||||
reply := &pb.RPCMessageReply{}
|
||||
log.Debugf("agent:%s uId:%d MessageDistribution msg:%s.%s", this.sessionId, this.uId, msg.MainType, msg.SubType)
|
||||
log.Debugf("agent:%s uId:%s MessageDistribution msg:%s.%s", this.sessionId, this.uId, msg.MainType, msg.SubType)
|
||||
if err := this.gateway.Service().RpcCallByType("worker", string(comm.Rpc_GatewayRoute), context.Background(), &pb.AgentMessage{
|
||||
Ip: this.IP(),
|
||||
UserSessionId: this.sessionId,
|
||||
@ -144,8 +144,8 @@ func (this *Agent) messageDistribution(msg *pb.UserMessage) {
|
||||
Method: fmt.Sprintf("%s.%s", msg.MainType, msg.SubType),
|
||||
Message: msg.Data,
|
||||
}, reply); err != nil {
|
||||
log.Errorf("agent:%s uId:%d MessageDistribution err:%v", this.sessionId, this.uId, err)
|
||||
log.Errorf("agent:%s uId:%s MessageDistribution err:%v", this.sessionId, this.uId, err)
|
||||
} else {
|
||||
log.Debugf("agent:%s uId:%d MessageDistribution reply:%v", this.sessionId, this.uId, reply)
|
||||
log.Debugf("agent:%s uId:%s MessageDistribution reply:%v", this.sessionId, this.uId, reply)
|
||||
}
|
||||
}
|
||||
|
@ -64,6 +64,6 @@ func (this *Gateway) Connect(a IAgent) {
|
||||
|
||||
//有新的连接对象进入
|
||||
func (this *Gateway) DisConnect(a IAgent) {
|
||||
log.Debugf("[Module.Gateway] have disConnect:Ip[%s] SessionId:[%s] uid:[%d]", a.IP(), a.SessionId(), a.UserId())
|
||||
log.Debugf("[Module.Gateway] have disConnect:Ip[%s] SessionId:[%s] uid:[%s]", a.IP(), a.SessionId(), a.UserId())
|
||||
this.agentmgr_comp.DisConnect(a)
|
||||
}
|
||||
|
@ -2,16 +2,18 @@ package user
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"encoding/base64"
|
||||
"go_dreamfactory/comm"
|
||||
"go_dreamfactory/modules"
|
||||
"go_dreamfactory/pb"
|
||||
"go_dreamfactory/sys/cache"
|
||||
"go_dreamfactory/sys/db"
|
||||
"go_dreamfactory/utils"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/liwei1dao/lego/sys/event"
|
||||
"github.com/liwei1dao/lego/sys/log"
|
||||
"github.com/tidwall/gjson"
|
||||
"go.mongodb.org/mongo-driver/mongo"
|
||||
)
|
||||
|
||||
@ -19,63 +21,76 @@ type LoginComp struct {
|
||||
modules.MComp_GateComp
|
||||
}
|
||||
|
||||
func DecodeUserData(base64Str string) *pb.DB_UserData {
|
||||
//解码
|
||||
dec, err := base64.StdEncoding.DecodeString(base64Str[35:])
|
||||
if err != nil {
|
||||
log.Errorf("base64 decode err %v", err)
|
||||
return nil
|
||||
}
|
||||
now := time.Now().Unix()
|
||||
jsonRet := gjson.Parse(string(dec))
|
||||
serverId := jsonRet.Get("serverId").Int()
|
||||
timestamp := jsonRet.Get("timestamp").Int()
|
||||
if now-time.Unix(timestamp, 0).Unix() > 100 {
|
||||
return nil
|
||||
}
|
||||
account := jsonRet.Get("account").String()
|
||||
return &pb.DB_UserData{
|
||||
ServerId: int32(serverId),
|
||||
Account: account,
|
||||
}
|
||||
}
|
||||
|
||||
//登录
|
||||
func (this *LoginComp) Login(ctx context.Context, session comm.IUserSession, req *pb.UserLoginReq) error {
|
||||
log.Debugf("User - Login: session:%v rsp:%v", session.ToString(), req)
|
||||
|
||||
var code pb.ErrorCode = pb.ErrorCode_Success
|
||||
rsp := &pb.UserLoginResp{}
|
||||
secStr := req.Sec
|
||||
|
||||
if !strings.HasPrefix(secStr, "CE:") || len(secStr) < 35 {
|
||||
session.SendMsg("user", "login", pb.ErrorCode_SecKey, rsp)
|
||||
if !utils.ValidSecretKey(req.Sec) {
|
||||
session.SendMsg("user", "login", pb.ErrorCode_SecKeyInvalid, nil)
|
||||
return nil
|
||||
}
|
||||
|
||||
clientMd5Key := strings.TrimPrefix(secStr, "CE:")
|
||||
rawmsg := secStr[35:]
|
||||
serverMd5Key := utils.MD5Str(rawmsg)
|
||||
s := fmt.Sprintf("%x", serverMd5Key)
|
||||
if !strings.EqualFold(strings.ToLower(s), strings.ToLower(clientMd5Key)) {
|
||||
session.SendMsg("user", "login", pb.ErrorCode_SecKeyInvalid, rsp)
|
||||
return nil
|
||||
}
|
||||
account := ""
|
||||
db_user, err := db.Defsys.User_FindUserByAccount(account)
|
||||
user := DecodeUserData(req.Sec)
|
||||
|
||||
db_user, err := db.Defsys.User_FindUserByAccount(user)
|
||||
if err != nil {
|
||||
if err != mongo.ErrNoDocuments {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if db_user.UserId == "" {
|
||||
db_user.Account = account
|
||||
err = db.Defsys.User_CreateUser(db_user)
|
||||
//如果是新玩家,创建一条基础的数据,页面会引导进入创角页面
|
||||
if db_user == nil {
|
||||
err = db.Defsys.User_CreateUser(user)
|
||||
if err != nil {
|
||||
log.Errorf("User_CreateUser err %v", err)
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
session.Build(db_user.UserId)
|
||||
session.Build(user.UserId)
|
||||
|
||||
cache_user := &pb.Cache_UserData{
|
||||
SessionId: session.GetSessionId(),
|
||||
GatewayServiceId: session.GetGatewayServiceId(),
|
||||
UserData: db_user,
|
||||
}
|
||||
err = cache.Defsys.User_UpdateUser(cache_user)
|
||||
err = cache.Defsys.Update(cache_user)
|
||||
if err != nil {
|
||||
log.Errorf("update cache err:%v", err)
|
||||
return err
|
||||
}
|
||||
|
||||
session.SendMsg("user", "login", code, &pb.UserLoginResp{
|
||||
err = session.SendMsg("user", "login", code, &pb.UserLoginResp{
|
||||
Data: &pb.Cache_UserData{
|
||||
UserData: &pb.DB_UserData{
|
||||
UserId: db_user.UserId,
|
||||
},
|
||||
UserData: db_user,
|
||||
},
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
event.TriggerEvent(comm.Event_UserLogin, db_user.UserId)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -15,13 +15,21 @@ func NewModule() core.IModule {
|
||||
type User struct {
|
||||
modules.ModuleBase
|
||||
login_comp *LoginComp
|
||||
user_comp *UserComp
|
||||
}
|
||||
|
||||
func (this *User) GetType() core.M_Modules {
|
||||
return comm.SM_LoginModule
|
||||
return comm.SM_UserModule
|
||||
}
|
||||
|
||||
func (this *User) Init(service core.IService, module core.IModule, options core.IModuleOptions) (err error) {
|
||||
err = this.ModuleBase.Init(service, module, options)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func (this *User) OnInstallComp() {
|
||||
this.ModuleBase.OnInstallComp()
|
||||
this.login_comp = this.RegisterComp(new(LoginComp)).(*LoginComp)
|
||||
this.user_comp = this.RegisterComp(new(UserComp)).(*UserComp)
|
||||
}
|
||||
|
@ -5,13 +5,23 @@ import (
|
||||
"go_dreamfactory/comm"
|
||||
"go_dreamfactory/modules"
|
||||
"go_dreamfactory/pb"
|
||||
|
||||
"github.com/liwei1dao/lego/core"
|
||||
)
|
||||
|
||||
type UserComp struct {
|
||||
modules.MComp_GateComp
|
||||
module *User
|
||||
}
|
||||
|
||||
func (this *UserComp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
|
||||
this.MComp_GateComp.Init(service, module, comp, options)
|
||||
this.module = module.(*User)
|
||||
return
|
||||
}
|
||||
|
||||
//创角
|
||||
func (this *UserComp) CreateUser(ctx context.Context, session comm.IUserSession, req *pb.UserLoginReq) error {
|
||||
func (this *UserComp) Create(ctx context.Context, session comm.IUserSession, req *pb.UserCreateReq) error {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@ -11,6 +11,5 @@ message DB_UserData {
|
||||
string UserId = 1; //tags:{bson:"_id"}动态Id
|
||||
string account = 2;
|
||||
string NiceName = 3;
|
||||
string Email = 4;
|
||||
string Password = 5;
|
||||
int32 ServerId = 4;
|
||||
}
|
@ -28,9 +28,8 @@ message UserLoadRsp {
|
||||
//创角
|
||||
message UserCreateReq{
|
||||
string NickName = 1;//昵称
|
||||
int32 gender = 2; //性别
|
||||
}
|
||||
|
||||
message UserCreateRsp{
|
||||
|
||||
string NickName = 1;
|
||||
}
|
@ -91,8 +91,7 @@ type DB_UserData struct {
|
||||
UserId string `protobuf:"bytes,1,opt,name=UserId,proto3" json:"UserId,omitempty" bson:"_id"` //tags:{bson:"_id"}动态Id
|
||||
Account string `protobuf:"bytes,2,opt,name=account,proto3" json:"account,omitempty"`
|
||||
NiceName string `protobuf:"bytes,3,opt,name=NiceName,proto3" json:"NiceName,omitempty"`
|
||||
Email string `protobuf:"bytes,4,opt,name=Email,proto3" json:"Email,omitempty"`
|
||||
Password string `protobuf:"bytes,5,opt,name=Password,proto3" json:"Password,omitempty"`
|
||||
ServerId int32 `protobuf:"varint,4,opt,name=ServerId,proto3" json:"ServerId,omitempty"`
|
||||
}
|
||||
|
||||
func (x *DB_UserData) Reset() {
|
||||
@ -148,18 +147,11 @@ func (x *DB_UserData) GetNiceName() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *DB_UserData) GetEmail() string {
|
||||
func (x *DB_UserData) GetServerId() int32 {
|
||||
if x != nil {
|
||||
return x.Email
|
||||
return x.ServerId
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *DB_UserData) GetPassword() string {
|
||||
if x != nil {
|
||||
return x.Password
|
||||
}
|
||||
return ""
|
||||
return 0
|
||||
}
|
||||
|
||||
var File_user_db_proto protoreflect.FileDescriptor
|
||||
@ -174,17 +166,15 @@ var file_user_db_proto_rawDesc = []byte{
|
||||
0x77, 0x61, 0x79, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x49, 0x64, 0x12, 0x28, 0x0a, 0x08,
|
||||
0x55, 0x73, 0x65, 0x72, 0x44, 0x61, 0x74, 0x61, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0c,
|
||||
0x2e, 0x44, 0x42, 0x5f, 0x55, 0x73, 0x65, 0x72, 0x44, 0x61, 0x74, 0x61, 0x52, 0x08, 0x55, 0x73,
|
||||
0x65, 0x72, 0x44, 0x61, 0x74, 0x61, 0x22, 0x8d, 0x01, 0x0a, 0x0b, 0x44, 0x42, 0x5f, 0x55, 0x73,
|
||||
0x65, 0x72, 0x44, 0x61, 0x74, 0x61, 0x12, 0x16, 0x0a, 0x06, 0x55, 0x73, 0x65, 0x72, 0x49, 0x64,
|
||||
0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x55, 0x73, 0x65, 0x72, 0x49, 0x64, 0x12, 0x18,
|
||||
0x0a, 0x07, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52,
|
||||
0x07, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x12, 0x1a, 0x0a, 0x08, 0x4e, 0x69, 0x63, 0x65,
|
||||
0x4e, 0x61, 0x6d, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x4e, 0x69, 0x63, 0x65,
|
||||
0x4e, 0x61, 0x6d, 0x65, 0x12, 0x14, 0x0a, 0x05, 0x45, 0x6d, 0x61, 0x69, 0x6c, 0x18, 0x04, 0x20,
|
||||
0x01, 0x28, 0x09, 0x52, 0x05, 0x45, 0x6d, 0x61, 0x69, 0x6c, 0x12, 0x1a, 0x0a, 0x08, 0x50, 0x61,
|
||||
0x73, 0x73, 0x77, 0x6f, 0x72, 0x64, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x50, 0x61,
|
||||
0x73, 0x73, 0x77, 0x6f, 0x72, 0x64, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06,
|
||||
0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
|
||||
0x65, 0x72, 0x44, 0x61, 0x74, 0x61, 0x22, 0x77, 0x0a, 0x0b, 0x44, 0x42, 0x5f, 0x55, 0x73, 0x65,
|
||||
0x72, 0x44, 0x61, 0x74, 0x61, 0x12, 0x16, 0x0a, 0x06, 0x55, 0x73, 0x65, 0x72, 0x49, 0x64, 0x18,
|
||||
0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x55, 0x73, 0x65, 0x72, 0x49, 0x64, 0x12, 0x18, 0x0a,
|
||||
0x07, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07,
|
||||
0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x12, 0x1a, 0x0a, 0x08, 0x4e, 0x69, 0x63, 0x65, 0x4e,
|
||||
0x61, 0x6d, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x4e, 0x69, 0x63, 0x65, 0x4e,
|
||||
0x61, 0x6d, 0x65, 0x12, 0x1a, 0x0a, 0x08, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x49, 0x64, 0x18,
|
||||
0x04, 0x20, 0x01, 0x28, 0x05, 0x52, 0x08, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x49, 0x64, 0x42,
|
||||
0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
|
||||
}
|
||||
|
||||
var (
|
||||
|
@ -263,7 +263,6 @@ type UserCreateReq struct {
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
NickName string `protobuf:"bytes,1,opt,name=NickName,proto3" json:"NickName,omitempty"` //昵称
|
||||
Gender int32 `protobuf:"varint,2,opt,name=gender,proto3" json:"gender,omitempty"` //性别
|
||||
}
|
||||
|
||||
func (x *UserCreateReq) Reset() {
|
||||
@ -305,17 +304,12 @@ func (x *UserCreateReq) GetNickName() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *UserCreateReq) GetGender() int32 {
|
||||
if x != nil {
|
||||
return x.Gender
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
type UserCreateRsp struct {
|
||||
state protoimpl.MessageState
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
NickName string `protobuf:"bytes,1,opt,name=NickName,proto3" json:"NickName,omitempty"`
|
||||
}
|
||||
|
||||
func (x *UserCreateRsp) Reset() {
|
||||
@ -350,6 +344,13 @@ func (*UserCreateRsp) Descriptor() ([]byte, []int) {
|
||||
return file_user_msg_proto_rawDescGZIP(), []int{6}
|
||||
}
|
||||
|
||||
func (x *UserCreateRsp) GetNickName() string {
|
||||
if x != nil {
|
||||
return x.NickName
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
var File_user_msg_proto protoreflect.FileDescriptor
|
||||
|
||||
var file_user_msg_proto_rawDesc = []byte{
|
||||
@ -370,14 +371,14 @@ var file_user_msg_proto_rawDesc = []byte{
|
||||
0x64, 0x65, 0x52, 0x04, 0x43, 0x6f, 0x64, 0x65, 0x22, 0x32, 0x0a, 0x0b, 0x55, 0x73, 0x65, 0x72,
|
||||
0x4c, 0x6f, 0x61, 0x64, 0x52, 0x73, 0x70, 0x12, 0x23, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, 0x18,
|
||||
0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0f, 0x2e, 0x43, 0x61, 0x63, 0x68, 0x65, 0x5f, 0x55, 0x73,
|
||||
0x65, 0x72, 0x44, 0x61, 0x74, 0x61, 0x52, 0x04, 0x64, 0x61, 0x74, 0x61, 0x22, 0x43, 0x0a, 0x0d,
|
||||
0x65, 0x72, 0x44, 0x61, 0x74, 0x61, 0x52, 0x04, 0x64, 0x61, 0x74, 0x61, 0x22, 0x2b, 0x0a, 0x0d,
|
||||
0x55, 0x73, 0x65, 0x72, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x52, 0x65, 0x71, 0x12, 0x1a, 0x0a,
|
||||
0x08, 0x4e, 0x69, 0x63, 0x6b, 0x4e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52,
|
||||
0x08, 0x4e, 0x69, 0x63, 0x6b, 0x4e, 0x61, 0x6d, 0x65, 0x12, 0x16, 0x0a, 0x06, 0x67, 0x65, 0x6e,
|
||||
0x64, 0x65, 0x72, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x06, 0x67, 0x65, 0x6e, 0x64, 0x65,
|
||||
0x72, 0x22, 0x0f, 0x0a, 0x0d, 0x55, 0x73, 0x65, 0x72, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x52,
|
||||
0x73, 0x70, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74,
|
||||
0x6f, 0x33,
|
||||
0x08, 0x4e, 0x69, 0x63, 0x6b, 0x4e, 0x61, 0x6d, 0x65, 0x22, 0x2b, 0x0a, 0x0d, 0x55, 0x73, 0x65,
|
||||
0x72, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x52, 0x73, 0x70, 0x12, 0x1a, 0x0a, 0x08, 0x4e, 0x69,
|
||||
0x63, 0x6b, 0x4e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x4e, 0x69,
|
||||
0x63, 0x6b, 0x4e, 0x61, 0x6d, 0x65, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06,
|
||||
0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
|
||||
}
|
||||
|
||||
var (
|
||||
|
17
sys/cache/user.go
vendored
17
sys/cache/user.go
vendored
@ -3,6 +3,8 @@ package cache
|
||||
import (
|
||||
"fmt"
|
||||
"go_dreamfactory/pb"
|
||||
|
||||
"github.com/liwei1dao/lego/sys/log"
|
||||
)
|
||||
|
||||
const ( //Redis
|
||||
@ -10,10 +12,21 @@ const ( //Redis
|
||||
)
|
||||
|
||||
type IUser interface {
|
||||
User_UpdateUser(data *pb.Cache_UserData) (err error)
|
||||
Update(data *pb.Cache_UserData) (err error)
|
||||
Get(userId string) *pb.Cache_UserData
|
||||
}
|
||||
|
||||
func (this *Cache) User_UpdateUser(data *pb.Cache_UserData) (err error) {
|
||||
func (this *Cache) Update(data *pb.Cache_UserData) (err error) {
|
||||
err = this.redis.Set(fmt.Sprintf(Redis_UserCache, data.UserData.UserId), data, -1)
|
||||
return
|
||||
}
|
||||
|
||||
func (this *Cache) Get(userId string) *pb.Cache_UserData {
|
||||
var user *pb.Cache_UserData
|
||||
err := this.redis.Get(fmt.Sprintf(Redis_UserCache, userId), &user)
|
||||
if err != nil {
|
||||
log.Errorf("get user cache err:%v", err)
|
||||
return nil
|
||||
}
|
||||
return user
|
||||
}
|
||||
|
8
sys/cache/user_test.go
vendored
8
sys/cache/user_test.go
vendored
@ -1,6 +1,7 @@
|
||||
package cache
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"go_dreamfactory/pb"
|
||||
"log"
|
||||
"testing"
|
||||
@ -33,6 +34,11 @@ func TestUpdateUser(t *testing.T) {
|
||||
Account: "aaa",
|
||||
},
|
||||
}
|
||||
err := cache.User_UpdateUser(user)
|
||||
err := cache.Update(user)
|
||||
require.Nil(t, err)
|
||||
}
|
||||
|
||||
func TestGetUser(t *testing.T) {
|
||||
c := cache.Get("62157")
|
||||
fmt.Println(c)
|
||||
}
|
||||
|
79
sys/configure/structs/MyBean.Hero.go
Normal file
79
sys/configure/structs/MyBean.Hero.go
Normal file
@ -0,0 +1,79 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// This code was generated by a tool.
|
||||
// Changes to this file may cause incorrect behavior and will be lost if
|
||||
// the code is regenerated.
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
package cfg
|
||||
|
||||
import "errors"
|
||||
|
||||
type MyBeanHero struct {
|
||||
Id string
|
||||
Name string
|
||||
Star int32
|
||||
Color int32
|
||||
Chengwei int32
|
||||
Zhongzu int32
|
||||
Job int32
|
||||
Type int32
|
||||
Prefab string
|
||||
Icon string
|
||||
Sound string
|
||||
Tujing string
|
||||
Hpgrow string
|
||||
Atkgrow string
|
||||
Defgrow string
|
||||
Speedgrow string
|
||||
Hp string
|
||||
Atk string
|
||||
Def string
|
||||
Speed string
|
||||
Intr string
|
||||
Events string
|
||||
Cite string
|
||||
}
|
||||
|
||||
const TypeId_MyBeanHero = 1050121004
|
||||
|
||||
func (*MyBeanHero) GetTypeId() int32 {
|
||||
return 1050121004
|
||||
}
|
||||
|
||||
func (_v *MyBeanHero)Deserialize(_buf map[string]interface{}) (err error) {
|
||||
{ var _ok_ bool; if _v.Id, _ok_ = _buf["id"].(string); !_ok_ { err = errors.New("id error"); return } }
|
||||
{ var _ok_ bool; if _v.Name, _ok_ = _buf["name"].(string); !_ok_ { err = errors.New("name error"); return } }
|
||||
{ var _ok_ bool; var _tempNum_ float64; if _tempNum_, _ok_ = _buf["star"].(float64); !_ok_ { err = errors.New("star error"); return }; _v.Star = int32(_tempNum_) }
|
||||
{ var _ok_ bool; var _tempNum_ float64; if _tempNum_, _ok_ = _buf["color"].(float64); !_ok_ { err = errors.New("color error"); return }; _v.Color = int32(_tempNum_) }
|
||||
{ var _ok_ bool; var _tempNum_ float64; if _tempNum_, _ok_ = _buf["chengwei"].(float64); !_ok_ { err = errors.New("chengwei error"); return }; _v.Chengwei = int32(_tempNum_) }
|
||||
{ var _ok_ bool; var _tempNum_ float64; if _tempNum_, _ok_ = _buf["zhongzu"].(float64); !_ok_ { err = errors.New("zhongzu error"); return }; _v.Zhongzu = int32(_tempNum_) }
|
||||
{ var _ok_ bool; var _tempNum_ float64; if _tempNum_, _ok_ = _buf["job"].(float64); !_ok_ { err = errors.New("job error"); return }; _v.Job = int32(_tempNum_) }
|
||||
{ var _ok_ bool; var _tempNum_ float64; if _tempNum_, _ok_ = _buf["type"].(float64); !_ok_ { err = errors.New("type error"); return }; _v.Type = int32(_tempNum_) }
|
||||
{ var _ok_ bool; if _v.Prefab, _ok_ = _buf["prefab"].(string); !_ok_ { err = errors.New("prefab error"); return } }
|
||||
{ var _ok_ bool; if _v.Icon, _ok_ = _buf["icon"].(string); !_ok_ { err = errors.New("icon error"); return } }
|
||||
{ var _ok_ bool; if _v.Sound, _ok_ = _buf["sound"].(string); !_ok_ { err = errors.New("sound error"); return } }
|
||||
{ var _ok_ bool; if _v.Tujing, _ok_ = _buf["tujing"].(string); !_ok_ { err = errors.New("tujing error"); return } }
|
||||
{ var _ok_ bool; if _v.Hpgrow, _ok_ = _buf["hpgrow"].(string); !_ok_ { err = errors.New("hpgrow error"); return } }
|
||||
{ var _ok_ bool; if _v.Atkgrow, _ok_ = _buf["atkgrow"].(string); !_ok_ { err = errors.New("atkgrow error"); return } }
|
||||
{ var _ok_ bool; if _v.Defgrow, _ok_ = _buf["defgrow"].(string); !_ok_ { err = errors.New("defgrow error"); return } }
|
||||
{ var _ok_ bool; if _v.Speedgrow, _ok_ = _buf["speedgrow"].(string); !_ok_ { err = errors.New("speedgrow error"); return } }
|
||||
{ var _ok_ bool; if _v.Hp, _ok_ = _buf["hp"].(string); !_ok_ { err = errors.New("hp error"); return } }
|
||||
{ var _ok_ bool; if _v.Atk, _ok_ = _buf["atk"].(string); !_ok_ { err = errors.New("atk error"); return } }
|
||||
{ var _ok_ bool; if _v.Def, _ok_ = _buf["def"].(string); !_ok_ { err = errors.New("def error"); return } }
|
||||
{ var _ok_ bool; if _v.Speed, _ok_ = _buf["speed"].(string); !_ok_ { err = errors.New("speed error"); return } }
|
||||
{ var _ok_ bool; if _v.Intr, _ok_ = _buf["intr"].(string); !_ok_ { err = errors.New("intr error"); return } }
|
||||
{ var _ok_ bool; if _v.Events, _ok_ = _buf["events"].(string); !_ok_ { err = errors.New("events error"); return } }
|
||||
{ var _ok_ bool; if _v.Cite, _ok_ = _buf["cite"].(string); !_ok_ { err = errors.New("cite error"); return } }
|
||||
return
|
||||
}
|
||||
|
||||
func DeserializeMyBeanHero(_buf map[string]interface{}) (*MyBeanHero, error) {
|
||||
v := &MyBeanHero{}
|
||||
if err := v.Deserialize(_buf); err == nil {
|
||||
return v, nil
|
||||
} else {
|
||||
return nil, err
|
||||
}
|
||||
}
|
@ -13,6 +13,7 @@ type JsonLoader func(string) ([]map[string]interface{}, error)
|
||||
type Tables struct {
|
||||
TbRewards *TbRewards
|
||||
TbItem *TbItem
|
||||
TbHero *TbHero
|
||||
}
|
||||
|
||||
func NewTables(loader JsonLoader) (*Tables, error) {
|
||||
@ -32,5 +33,11 @@ func NewTables(loader JsonLoader) (*Tables, error) {
|
||||
if tables.TbItem, err = NewTbItem(buf) ; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if buf, err = loader("tbhero") ; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if tables.TbHero, err = NewTbHero(buf) ; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return tables, nil
|
||||
}
|
||||
|
42
sys/configure/structs/TbHero.go
Normal file
42
sys/configure/structs/TbHero.go
Normal file
@ -0,0 +1,42 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// This code was generated by a tool.
|
||||
// Changes to this file may cause incorrect behavior and will be lost if
|
||||
// the code is regenerated.
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
package cfg
|
||||
|
||||
type TbHero struct {
|
||||
_dataMap map[string]*MyBeanHero
|
||||
_dataList []*MyBeanHero
|
||||
}
|
||||
|
||||
func NewTbHero(_buf []map[string]interface{}) (*TbHero, error) {
|
||||
_dataList := make([]*MyBeanHero, 0, len(_buf))
|
||||
dataMap := make(map[string]*MyBeanHero)
|
||||
for _, _ele_ := range _buf {
|
||||
if _v, err2 := DeserializeMyBeanHero(_ele_); err2 != nil {
|
||||
return nil, err2
|
||||
} else {
|
||||
_dataList = append(_dataList, _v)
|
||||
dataMap[_v.Id] = _v
|
||||
}
|
||||
}
|
||||
return &TbHero{_dataList:_dataList, _dataMap:dataMap}, nil
|
||||
}
|
||||
|
||||
func (table *TbHero) GetDataMap() map[string]*MyBeanHero {
|
||||
return table._dataMap
|
||||
}
|
||||
|
||||
func (table *TbHero) GetDataList() []*MyBeanHero {
|
||||
return table._dataList
|
||||
}
|
||||
|
||||
func (table *TbHero) Get(key string) *MyBeanHero {
|
||||
return table._dataMap[key]
|
||||
}
|
||||
|
||||
|
@ -14,20 +14,21 @@ const ( //Redis
|
||||
)
|
||||
|
||||
type IUser interface {
|
||||
User_FindUserByAccount(account string) (*pb.DB_UserData, error)
|
||||
User_FindUserByAccount(user *pb.DB_UserData) (*pb.DB_UserData, error)
|
||||
User_FindUserById(id string) (*pb.DB_UserData, error)
|
||||
User_CreateUser(user *pb.DB_UserData) error
|
||||
User_UpdateUser(data *pb.DB_UserData) (err error)
|
||||
}
|
||||
|
||||
func (this *DB) User_FindUserByAccount(account string) (*pb.DB_UserData, error) {
|
||||
func (this *DB) User_FindUserByAccount(user *pb.DB_UserData) (*pb.DB_UserData, error) {
|
||||
filter := bson.D{
|
||||
{"account", account},
|
||||
{"serverid", user.ServerId},
|
||||
{"account", user.Account},
|
||||
}
|
||||
sr := this.mgo.FindOne(DB_UserTable, filter)
|
||||
user := &pb.DB_UserData{}
|
||||
err := sr.Decode(user)
|
||||
return user, err
|
||||
var nd *pb.DB_UserData
|
||||
err := sr.Decode(&nd)
|
||||
return nd, err
|
||||
}
|
||||
|
||||
func (this *DB) User_FindUserById(id string) (*pb.DB_UserData, error) {
|
||||
@ -53,7 +54,6 @@ func (this *DB) User_UpdateUser(data *pb.DB_UserData) (err error) {
|
||||
bson.M{"_id": data.UserId},
|
||||
bson.M{"$set": bson.M{
|
||||
"niceName": data.NiceName,
|
||||
"email": data.Email,
|
||||
}},
|
||||
options.FindOneAndUpdate().SetUpsert(false).SetReturnDocument(options.After),
|
||||
).Decode(data)
|
||||
|
@ -30,7 +30,7 @@ func TestCreate(t *testing.T) {
|
||||
user := &pb.DB_UserData{
|
||||
Account: "legu3",
|
||||
NiceName: "乐谷3",
|
||||
Email: "1111@legu.com",
|
||||
ServerId: 1,
|
||||
}
|
||||
|
||||
err := db.User_CreateUser(user)
|
||||
@ -38,23 +38,23 @@ func TestCreate(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestFindOne(t *testing.T) {
|
||||
user, err := db.User_FindUserById("")
|
||||
user, err := db.User_FindUserById("629eb3f4132dc4bb26139659")
|
||||
require.Nil(t, err)
|
||||
assert.Equal(t, "legu1", user.Account)
|
||||
assert.Equal(t, "legu3", user.Account)
|
||||
|
||||
user2, err := db.User_FindUserByAccount("legu1")
|
||||
// user.ServerId = 2
|
||||
user2, err := db.User_FindUserByAccount(user)
|
||||
require.Nil(t, err)
|
||||
assert.Equal(t, "legu1", user2.Account)
|
||||
|
||||
assert.Equal(t, "legu3", user2.Account)
|
||||
assert.Equal(t, int32(1), user2.ServerId)
|
||||
}
|
||||
|
||||
func TestUpdate(t *testing.T) {
|
||||
user := &pb.DB_UserData{
|
||||
UserId: primitive.NewObjectID().String(),
|
||||
Email: "new@qq.com",
|
||||
UserId: primitive.NewObjectID().Hex(),
|
||||
}
|
||||
err := db.User_UpdateUser(user)
|
||||
require.Nil(t, err)
|
||||
|
||||
assert.Equal(t, "new@qq.com", user.Email)
|
||||
assert.Equal(t, "NiceName", "")
|
||||
}
|
||||
|
37
utils/base64.go
Normal file
37
utils/base64.go
Normal file
@ -0,0 +1,37 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"strings"
|
||||
|
||||
"github.com/liwei1dao/lego/sys/log"
|
||||
)
|
||||
|
||||
func Base64Encode(data []byte) string {
|
||||
return base64.StdEncoding.EncodeToString(data)
|
||||
}
|
||||
|
||||
func Base64Decode(data string) string {
|
||||
b, err := base64.StdEncoding.DecodeString(data)
|
||||
if err != nil {
|
||||
log.Errorf("base64 decode", err)
|
||||
return ""
|
||||
}
|
||||
return string(b)
|
||||
}
|
||||
|
||||
func ValidSecretKey(secStr string) bool {
|
||||
if !strings.HasPrefix(secStr, "CE:") || len(secStr) < 35 {
|
||||
return false
|
||||
}
|
||||
|
||||
clientMd5Key := secStr[3:35]
|
||||
rawmsg := secStr[35:]
|
||||
log.Debugf("data base: %s", rawmsg)
|
||||
serverMd5Key := MD5Str(rawmsg)
|
||||
// s := fmt.Sprintf("%x", serverMd5Key)
|
||||
if !strings.EqualFold(strings.ToLower(serverMd5Key), strings.ToLower(clientMd5Key)) {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
Loading…
Reference in New Issue
Block a user