From 8d983031318209d7e26d72354aada45ef9c1d251 Mon Sep 17 00:00:00 2001 From: zqj <582132116@qq.com> Date: Wed, 23 Mar 2022 17:39:46 +0800 Subject: [PATCH] loginReq uid -> token; model is ISchema --- cmd/gameserver/action/RoleAction.go | 8 ++------ cmd/gameserver/action/protocode.go | 2 +- cmd/gameserver/agent.go | 47 +++++++++++++++++++++++++++++++++++++---------- cmd/gameserver/game.go | 2 +- cmd/gameserver/plugin/plugin.go | 2 +- cmd/httpserver/http.go | 2 ++ cmd/test/client.go | 2 +- common/components/icompontents.go | 1 + common/db/mongoproxy/mongo.go | 8 ++++++++ common/db/mongoproxy/mongoplugin.go | 8 ++++++++ conf/conf.yaml | 2 +- models/account.go | 5 +++-- models/equip.go | 5 +++-- models/hero.go | 23 ++++++----------------- models/init.go | 10 ++++++++-- models/prop.go | 5 +++-- models/role.go | 145 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------------------------------------- models/role_test.go | 22 +++++++++++++++++++--- models/schema.go | 4 ++++ models/team.go | 8 +++----- pb/game.pb.go | 155 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------------------------------------------------- pb/models.pb.go | 43 ++++++++++++++++++++++++++++++++++++------- pb/protocode.pb.go | 33 ++++++++++++++++++--------------- protos | 2 +- 24 files changed, 376 insertions(+), 168 deletions(-) diff --git a/cmd/gameserver/action/RoleAction.go b/cmd/gameserver/action/RoleAction.go index 79638cc..fd0f3c6 100644 --- a/cmd/gameserver/action/RoleAction.go +++ b/cmd/gameserver/action/RoleAction.go @@ -31,6 +31,7 @@ func CreateRpc(msg components.IMessage) (int32, interface{}) { logger.Error("CreateRpc role create err: %v", err) return 3, nil } + role.InitRole() return 0, nil } @@ -48,10 +49,5 @@ func LoginRpc(msg components.IMessage) (int32, interface{}) { } role.SetProperty("Device", req.Device) - return 0, &pb.RoleRsp{ - Role: role.Role, - Hero: role.GetAllHero(), - Team: role.Teams.Team, - Equips: []*pb.Equipment{role.Equip.Equip}, - } + return 0, role } diff --git a/cmd/gameserver/action/protocode.go b/cmd/gameserver/action/protocode.go index 460699e..af9ecde 100644 --- a/cmd/gameserver/action/protocode.go +++ b/cmd/gameserver/action/protocode.go @@ -13,4 +13,4 @@ func GetActionMap() map[interface{}]interface{} { am[uint32(pb.ProtoCode_CreateReq)] = CreateRpc return am -} +} \ No newline at end of file diff --git a/cmd/gameserver/agent.go b/cmd/gameserver/agent.go index 4d9cca6..2058878 100644 --- a/cmd/gameserver/agent.go +++ b/cmd/gameserver/agent.go @@ -3,10 +3,12 @@ package main import ( "github.com/golang/protobuf/proto" "math" + "pro2d/cmd/gameserver/action" "pro2d/common" "pro2d/common/components" "pro2d/common/logger" "pro2d/models" + "pro2d/pb" "pro2d/utils" "sync" "sync/atomic" @@ -38,8 +40,38 @@ func (c *Agent) OnConnection(conn components.IConnection) { c.IConnection = conn } +func (c *Agent) OnLogin(msg components.IMessage) { + //第一次登录 + errCode, irole := action.LoginRpc(msg) + if errCode != 0 { + c.Send(errCode, msg.GetHeader().GetMsgID(), nil) + return + } + + role := irole.(*models.RoleModel) + protoMsg := &pb.RoleRsp{ + Role: role.Role, + Hero: role.GetAllHero(), + Team: role.GetAllTeam(), + } + rsp, err := proto.Marshal(protoMsg) + if err != nil { + c.Send(-100, msg.GetHeader().GetMsgID(), nil) + return + } + c.Send(errCode, msg.GetHeader().GetMsgID(), rsp) + //登录成功,存储agent role + c.Role = role +} + func (c *Agent) OnMessage(msg components.IMessage) { atomic.StoreInt64(&c.lastHeartCheckTime, utils.Timex()) + + if msg.GetHeader().GetMsgID() == uint32(pb.ProtoCode_LoginReq) { + c.OnLogin(msg) + return + } + md := c.Server.GetAction(msg.GetHeader().GetMsgID()) if md == nil { logger.Debug("cmd: %d, handler is nil", msg.GetHeader().GetMsgID()) @@ -50,24 +82,18 @@ func (c *Agent) OnMessage(msg components.IMessage) { f := md.(func (msg components.IMessage) (int32, interface{})) errCode, protoMsg := f(msg) + if protoMsg == nil { + c.Send(errCode, msg.GetHeader().GetMsgID(), nil) return } rsp, err := proto.Marshal(protoMsg.(proto.Message)) if err != nil { - conn := msg.GetSession() - if conn != nil { - conn.Send(-100, msg.GetHeader().GetMsgID(), nil) - } - return - } - conn := msg.GetSession() - if conn != nil { - conn.Send(errCode, msg.GetHeader().GetMsgID(), rsp) + c.Send(-100, msg.GetHeader().GetMsgID(), nil) return } - logger.Error("protocol not handler: %d", msg.GetHeader().GetMsgID()) + c.Send(errCode, msg.GetHeader().GetMsgID(), rsp) } func (c *Agent) OnTimer() { @@ -91,6 +117,7 @@ func (c *Agent) OnClose() { } func (c *Agent) Close() { + c.Role = nil agentPool.Put(c) if c.Role == nil { diff --git a/cmd/gameserver/game.go b/cmd/gameserver/game.go index 5df7f7f..dce6b1a 100644 --- a/cmd/gameserver/game.go +++ b/cmd/gameserver/game.go @@ -38,7 +38,7 @@ func NewGameServer(sconf *common.SConf) (*GameServer, error) { if err != nil { return nil, err } - models.InitModels() + models.InitGameModels() //Etcd 初始化 s.EtcdClient, err = etcd.NewEtcdClient(common.GlobalConf.Etcd) diff --git a/cmd/gameserver/plugin/plugin.go b/cmd/gameserver/plugin/plugin.go index c03c3f1..db835e2 100644 --- a/cmd/gameserver/plugin/plugin.go +++ b/cmd/gameserver/plugin/plugin.go @@ -37,7 +37,7 @@ func LoginRpc(msg components.IMessage) (int32, interface{}) { return 0, &pb.RoleRsp{ Role: role.Role, Hero: role.GetAllHero(), - Team: role.Teams.Team, + Team: role.GetAllTeam(), Equips: []*pb.Equipment{role.Equip.Equip}, } } diff --git a/cmd/httpserver/http.go b/cmd/httpserver/http.go index 01c36b6..0410eb2 100644 --- a/cmd/httpserver/http.go +++ b/cmd/httpserver/http.go @@ -9,6 +9,7 @@ import ( "pro2d/common/db/mongoproxy" "pro2d/common/etcd" "pro2d/common/logger" + "pro2d/models" "syscall" ) @@ -30,6 +31,7 @@ func (s *AccountServer) Init() error { if err != nil { return err } + models.InitGameModels() //Etcd 初始化 s.EtcdClient, err = etcd.NewEtcdClient(common.GlobalConf.Etcd) diff --git a/cmd/test/client.go b/cmd/test/client.go index a1276ad..e9b7029 100644 --- a/cmd/test/client.go +++ b/cmd/test/client.go @@ -19,7 +19,7 @@ func main() { } loginReq := &pb.LoginReq{ - Uid: "141815055745814528", + Token: "141815055745814528", Device: "123123", } l, _ :=proto.Marshal(loginReq) diff --git a/common/components/icompontents.go b/common/components/icompontents.go index 9672276..df25d4d 100644 --- a/common/components/icompontents.go +++ b/common/components/icompontents.go @@ -101,6 +101,7 @@ type ( CreateTable() error Create() (interface{}, error) + Save() error Load() error FindOne() error UpdateProperty(key string, val interface{}) error diff --git a/common/db/mongoproxy/mongo.go b/common/db/mongoproxy/mongo.go index 547ab34..01c9ac9 100644 --- a/common/db/mongoproxy/mongo.go +++ b/common/db/mongoproxy/mongo.go @@ -49,6 +49,14 @@ func (m *MgoColl) Create() (interface{}, error){ return m.coll.InsertOne(context.TODO(), m.Schema.GetSchema()) } +func (m *MgoColl) Save() error{ + _, err := m.coll.UpdateOne(context.TODO(), m.Schema.GetPri(), m.Schema.GetSchema()) + if err != nil { + return err + } + return nil +} + func (m *MgoColl) Load() error{ r := m.coll.FindOne(context.TODO(), m.Schema.GetPri()) err := r.Decode(m.Schema.GetSchema()) diff --git a/common/db/mongoproxy/mongoplugin.go b/common/db/mongoproxy/mongoplugin.go index a9056f3..edecc5b 100644 --- a/common/db/mongoproxy/mongoplugin.go +++ b/common/db/mongoproxy/mongoplugin.go @@ -71,6 +71,14 @@ func FindOne(pri interface{}, schema interface{}) error { return r.Decode(schema) } +func FindMany(coll string, key string, val interface{}, schema interface{}) error { + r, err := mongoDatabase.Collection(coll).Find(context.TODO(), bson.M{key:val}) + if err != nil { + return err + } + return r.All(context.TODO(), schema) +} + func GetBsonD(key string, value interface{}) interface{} { return bson.D{ {key, value}} } diff --git a/conf/conf.yaml b/conf/conf.yaml index 2ca90d5..5e1218e 100644 --- a/conf/conf.yaml +++ b/conf/conf.yaml @@ -28,7 +28,7 @@ server_account: dbname: "account" server_game: - id: "1" + id: "2" name: "game" ip: "192.168.0.206" port: 8850 diff --git a/models/account.go b/models/account.go index affd5d9..f8542da 100644 --- a/models/account.go +++ b/models/account.go @@ -1,11 +1,12 @@ package models import ( + "pro2d/common/components" "pro2d/pb" ) type AccountModel struct { - *Schema + components.ISchema *pb.Account } @@ -24,7 +25,7 @@ func NewAccount(phone string) *AccountModel { } account := &AccountModel{ - Schema: NewSchema(phone, ac), + ISchema: NewSchema(phone, ac), Account: ac, } diff --git a/models/equip.go b/models/equip.go index d19a403..a1262a5 100644 --- a/models/equip.go +++ b/models/equip.go @@ -1,11 +1,12 @@ package models import ( + "pro2d/common/components" "pro2d/pb" ) type EquipModel struct { - *Schema + components.ISchema Equip *pb.Equipment } @@ -14,7 +15,7 @@ func NewEquip(id string) *EquipModel { Id: id, } m := &EquipModel{ - Schema: NewSchema(id, data), + ISchema: NewSchema(id, data), Equip: data, } diff --git a/models/hero.go b/models/hero.go index ddf244b..5af70af 100644 --- a/models/hero.go +++ b/models/hero.go @@ -1,30 +1,19 @@ package models import ( + "pro2d/common/components" "pro2d/pb" ) type HeroModel struct { - *Schema + components.ISchema Hero *pb.Hero } -type HeroMap map[string]*HeroModel - -func GetHeros(hm HeroMap) map[string]*pb.Hero { - h := make(map[string]*pb.Hero) - for k, v := range hm { - h[k] = v.Hero - } - return h -} - -func NewHero(id string) *HeroModel { - h := &pb.Hero{ - Id: id, - } +type HeroMap map[string]components.ISchema +func NewHero(hero *pb.Hero) *HeroModel { m := &HeroModel{ - Schema: NewSchema(id, h), - Hero: h, + ISchema: NewSchema(hero.Id, hero), + Hero: hero, } return m } diff --git a/models/init.go b/models/init.go index 49b483c..8c194f3 100644 --- a/models/init.go +++ b/models/init.go @@ -5,9 +5,15 @@ import ( "pro2d/pb" ) -func InitModels() { - var schema []interface{} = []interface{}{ +func InitAccountModels() { + var schema = []interface{}{ pb.Account{}, + } + mongoproxy.InitDoc(schema...) +} + +func InitGameModels() { + var schema = []interface{}{ pb.Equipment{}, pb.Hero{}, pb.Prop{}, diff --git a/models/prop.go b/models/prop.go index b46c5a4..f5e54d7 100644 --- a/models/prop.go +++ b/models/prop.go @@ -1,11 +1,12 @@ package models import ( + "pro2d/common/components" "pro2d/pb" ) type PropModel struct { - *Schema + components.ISchema Prop *pb.Prop } @@ -14,7 +15,7 @@ func NewProp(id string) *PropModel { Id: id, } m := &PropModel{ - Schema: NewSchema(id, data), + ISchema: NewSchema(id, data), Prop: data, } diff --git a/models/role.go b/models/role.go index a42b288..902a2d4 100644 --- a/models/role.go +++ b/models/role.go @@ -1,8 +1,8 @@ package models import ( - "fmt" "pro2d/common" + "pro2d/common/components" "pro2d/common/db/mongoproxy" "pro2d/common/logger" "pro2d/pb" @@ -11,11 +11,10 @@ import ( ) type RoleModel struct { - *Schema + components.ISchema Role *pb.Role Heros HeroMap - Teams *TeamModel - Equip *EquipModel + Teams TeamMap Prop *PropModel lastSaveTs int64 @@ -31,11 +30,10 @@ func RoleExistByUid(uid string) *RoleModel { r := &RoleModel{ - Schema: NewSchema(data.Id, data), + ISchema: NewSchema(data.Id, data), Role: data, Heros: make(HeroMap), - Teams: new(TeamModel), - Equip: new(EquipModel), + Teams: make(TeamMap), Prop: new(PropModel), } r.LoadAll() @@ -45,72 +43,127 @@ func RoleExistByUid(uid string) *RoleModel { func NewRole(id string) *RoleModel { data := &pb.Role{Id: id} m := &RoleModel{ - Schema: NewSchema(id, data), + ISchema: NewSchema(id, data), Role: data, Heros: make(HeroMap), - Teams: new(TeamModel), - Equip: new(EquipModel), - Prop: new(PropModel), + Teams: make(TeamMap), } return m } -func (m *RoleModel) LoadHero() { - m.Heros["test"] = NewHero("") - m.Heros["test"].Hero = &pb.Hero{ - Id: "1", +func (m *RoleModel) InitRole() { + //init hero + h1 := pb.Hero{ + Id: common.SnowFlack.NextValStr(), RoleId: m.Role.Id, Type: 1, Level: 1, ReinCount: 0, ReinPoint: 0, - Equipments: "123123", + Equipments: "", } + m.AddHero(&h1) + + h2 := h1 + h2.Id = common.SnowFlack.NextValStr() + h2.Type = 2 + m.AddHero(&h2) + + h3 := h1 + h3.Id = common.SnowFlack.NextValStr() + h3.Type = 3 + m.AddHero(&h3) + + h4 := h1 + h4.Id = common.SnowFlack.NextValStr() + h4.Type = 4 + m.AddHero(&h4) + + //init team + t1 := pb.Team{ + Id: common.SnowFlack.NextValStr(), + RoleId: m.Role.Id, + HeroId1: h1.Id, + HeroId2: h2.Id, + HeroId3: h3.Id, + } + m.AddTeam(&t1) + + t2 := t1 + t2.Id = common.SnowFlack.NextValStr() + m.AddTeam(&t2) + + t3 := t1 + t3.Id = common.SnowFlack.NextValStr() + m.AddTeam(&t3) + + t4 := t1 + t4.Id = common.SnowFlack.NextValStr() + m.AddTeam(&t4) } -func (m *RoleModel) LoadTeams() { - m.Teams = NewTeam("0") - m.Teams.Team = &pb.Team{ - Id: "1", - HeroIds: "1", +func (m *RoleModel) LoadHero() { + heros := make([]*pb.Hero, 10) + err := mongoproxy.FindMany("hero", "role_id", m.Role.Id, &heros) + if err != nil { + logger.Error(err) + return + } + for _, hero := range heros { + m.Heros[hero.Id] = NewHero(hero) } } -func (m *RoleModel) LoadEquips() { - m.Equip = NewEquip("0") - m.Equip.Equip = &pb.Equipment{ - Id: "0", - RoleId: m.Role.Id, - Type: 0, - Equip: false, - EnhanceLevel: false, +func (m *RoleModel) LoadTeams() { + teams := make([]*pb.Team, 4) + err := mongoproxy.FindMany("hero", "role_id", m.Role.Id, &teams) + if err != nil { + logger.Error(err) + return + } + for _, team:= range teams { + m.Teams[team.Id] = NewTeam(team) } } func (m *RoleModel) LoadAll() { m.LoadHero() m.LoadTeams() - m.LoadEquips() } func (m *RoleModel) updateProperty(property map[string]interface{}) { } -func (m *RoleModel) AddHero(hero *pb.Hero) { - h := NewHero(hero.Id) - h.Hero = hero - h.Create() - m.Heros[fmt.Sprintf("%s%s", m.Role.Id, h.Hero.Id)] = h -} - func (m *RoleModel) GetAllHero() []*pb.Hero { var h []*pb.Hero for _, hero := range m.Heros { - h = append(h, hero.Hero) + h = append(h, hero.(*HeroModel).Hero) } return h } +func (m *RoleModel) GetAllTeam() []*pb.Team{ + var t []*pb.Team + for _, team := range m.Teams{ + t = append(t, team.Team) + } + return t +} + + +func (m *RoleModel) AddHero(hero *pb.Hero) { + h := NewHero(hero) + h .Create() + m.Heros[hero.Id] = h +} + +func (m *RoleModel) AddTeam(team *pb.Team) { + t := NewTeam(team) + t.Create() + m.Teams[team.Id] = t +} + + func (m *RoleModel) OnRecoverTimer(now int64) { m.saveRoleData(now) } @@ -126,4 +179,20 @@ func (m *RoleModel) saveRoleData(now int64) { } atomic.StoreInt64(&m.lastSaveTs, now) m.Update() + + tbObjs := []components.ISchema{} + for _, tbObj := range tbObjs { + if tbObj != nil { + tbObj.Update() + } + } + + //mpObjs := []interface{}{m.Heros, m.Teams} + //for _, mpObj := range mpObjs { + // for _, v := range mpObj.(map[string]components.ISchema) { + // if v != nil { + // v.Update() + // } + // } + //} } \ No newline at end of file diff --git a/models/role_test.go b/models/role_test.go index 7627d4c..3cce8ba 100644 --- a/models/role_test.go +++ b/models/role_test.go @@ -6,12 +6,11 @@ import ( "pro2d/common/db/mongoproxy" "pro2d/common/logger" "pro2d/pb" - "pro2d/utils" "testing" ) func TestNewRole(t *testing.T) { - err := mongoproxy.ConnectMongo(common.GlobalConf.MongoConf) + err := mongoproxy.ConnectMongo(common.GlobalConf.GameConf.MongoConf) if err != nil { logger.Error(err) return @@ -45,8 +44,25 @@ func TestNewRole(t *testing.T) { } func TestRoleIndex(t *testing.T) { - coll, keys := utils.FindIndex(pb.Role{}) + coll, keys := mongoproxy.FindIndex(pb.Role{}) for _, index := range keys { logger.Debug("coll: %s, key: %s", coll, index) } +} + +func TestRoleModel_AddHero(t *testing.T) { + err := mongoproxy.ConnectMongo(common.GlobalConf.GameConf.MongoConf) + if err != nil { + logger.Error(err) + return + } + + var uid = "141815055745814528" + role := RoleExistByUid(uid) + if role == nil { + logger.Error("role not exist") + return + } + + role.InitRole() } \ No newline at end of file diff --git a/models/schema.go b/models/schema.go index 6c55601..a743b2d 100644 --- a/models/schema.go +++ b/models/schema.go @@ -97,6 +97,10 @@ func (s *Schema) Create() error { return err } +func (s *Schema) Save() error { + return s.db.Save() +} + func (s *Schema) Update() { if s.cacheFields != nil { s.db.UpdateProperties(s.cacheFields) diff --git a/models/team.go b/models/team.go index c87eec0..a2ec046 100644 --- a/models/team.go +++ b/models/team.go @@ -4,17 +4,15 @@ import ( "pro2d/pb" ) +type TeamMap map[string]*TeamModel type TeamModel struct { *Schema Team *pb.Team } -func NewTeam(id string) *TeamModel { - data := &pb.Team{ - Id: id, - } +func NewTeam(data *pb.Team) *TeamModel { m := &TeamModel{ - Schema: NewSchema(id, data), + Schema: NewSchema(data.Id, data), Team: data, } diff --git a/pb/game.pb.go b/pb/game.pb.go index 694a8c3..37587e6 100644 --- a/pb/game.pb.go +++ b/pb/game.pb.go @@ -67,6 +67,53 @@ func (x *HeartReq) GetCode() int64 { return 0 } +type HeartRsp struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Code int64 `protobuf:"varint,1,opt,name=code,proto3" json:"code,omitempty"` +} + +func (x *HeartRsp) Reset() { + *x = HeartRsp{} + if protoimpl.UnsafeEnabled { + mi := &file_game_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *HeartRsp) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*HeartRsp) ProtoMessage() {} + +func (x *HeartRsp) ProtoReflect() protoreflect.Message { + mi := &file_game_proto_msgTypes[1] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use HeartRsp.ProtoReflect.Descriptor instead. +func (*HeartRsp) Descriptor() ([]byte, []int) { + return file_game_proto_rawDescGZIP(), []int{1} +} + +func (x *HeartRsp) GetCode() int64 { + if x != nil { + return x.Code + } + return 0 +} + //ResponseCmd RoleRsp type LoginReq struct { state protoimpl.MessageState @@ -80,7 +127,7 @@ type LoginReq struct { func (x *LoginReq) Reset() { *x = LoginReq{} if protoimpl.UnsafeEnabled { - mi := &file_game_proto_msgTypes[1] + mi := &file_game_proto_msgTypes[2] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -93,7 +140,7 @@ func (x *LoginReq) String() string { func (*LoginReq) ProtoMessage() {} func (x *LoginReq) ProtoReflect() protoreflect.Message { - mi := &file_game_proto_msgTypes[1] + mi := &file_game_proto_msgTypes[2] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -106,7 +153,7 @@ func (x *LoginReq) ProtoReflect() protoreflect.Message { // Deprecated: Use LoginReq.ProtoReflect.Descriptor instead. func (*LoginReq) Descriptor() ([]byte, []int) { - return file_game_proto_rawDescGZIP(), []int{1} + return file_game_proto_rawDescGZIP(), []int{2} } func (x *LoginReq) GetToken() string { @@ -135,7 +182,7 @@ type CreateReq struct { func (x *CreateReq) Reset() { *x = CreateReq{} if protoimpl.UnsafeEnabled { - mi := &file_game_proto_msgTypes[2] + mi := &file_game_proto_msgTypes[3] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -148,7 +195,7 @@ func (x *CreateReq) String() string { func (*CreateReq) ProtoMessage() {} func (x *CreateReq) ProtoReflect() protoreflect.Message { - mi := &file_game_proto_msgTypes[2] + mi := &file_game_proto_msgTypes[3] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -161,7 +208,7 @@ func (x *CreateReq) ProtoReflect() protoreflect.Message { // Deprecated: Use CreateReq.ProtoReflect.Descriptor instead. func (*CreateReq) Descriptor() ([]byte, []int) { - return file_game_proto_rawDescGZIP(), []int{2} + return file_game_proto_rawDescGZIP(), []int{3} } func (x *CreateReq) GetUid() string { @@ -183,16 +230,15 @@ type RoleRsp struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - Role *Role `protobuf:"bytes,2,opt,name=role,proto3" json:"role,omitempty"` - Hero []*Hero `protobuf:"bytes,3,rep,name=hero,proto3" json:"hero,omitempty"` - Team *Team `protobuf:"bytes,4,opt,name=team,proto3" json:"team,omitempty"` - Equips []*Equipment `protobuf:"bytes,5,rep,name=equips,proto3" json:"equips,omitempty"` + Role *Role `protobuf:"bytes,2,opt,name=role,proto3" json:"role,omitempty"` + Hero []*Hero `protobuf:"bytes,3,rep,name=hero,proto3" json:"hero,omitempty"` + Team []*Team `protobuf:"bytes,4,rep,name=team,proto3" json:"team,omitempty"` } func (x *RoleRsp) Reset() { *x = RoleRsp{} if protoimpl.UnsafeEnabled { - mi := &file_game_proto_msgTypes[3] + mi := &file_game_proto_msgTypes[4] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -205,7 +251,7 @@ func (x *RoleRsp) String() string { func (*RoleRsp) ProtoMessage() {} func (x *RoleRsp) ProtoReflect() protoreflect.Message { - mi := &file_game_proto_msgTypes[3] + mi := &file_game_proto_msgTypes[4] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -218,7 +264,7 @@ func (x *RoleRsp) ProtoReflect() protoreflect.Message { // Deprecated: Use RoleRsp.ProtoReflect.Descriptor instead. func (*RoleRsp) Descriptor() ([]byte, []int) { - return file_game_proto_rawDescGZIP(), []int{3} + return file_game_proto_rawDescGZIP(), []int{4} } func (x *RoleRsp) GetRole() *Role { @@ -235,20 +281,13 @@ func (x *RoleRsp) GetHero() []*Hero { return nil } -func (x *RoleRsp) GetTeam() *Team { +func (x *RoleRsp) GetTeam() []*Team { if x != nil { return x.Team } return nil } -func (x *RoleRsp) GetEquips() []*Equipment { - if x != nil { - return x.Equips - } - return nil -} - var File_game_proto protoreflect.FileDescriptor var file_game_proto_rawDesc = []byte{ @@ -256,6 +295,8 @@ var file_game_proto_rawDesc = []byte{ 0x6d, 0x65, 0x1a, 0x0c, 0x6d, 0x6f, 0x64, 0x65, 0x6c, 0x73, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x1e, 0x0a, 0x08, 0x48, 0x65, 0x61, 0x72, 0x74, 0x52, 0x65, 0x71, 0x12, 0x12, 0x0a, 0x04, 0x63, 0x6f, 0x64, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x04, 0x63, 0x6f, 0x64, 0x65, + 0x22, 0x1e, 0x0a, 0x08, 0x48, 0x65, 0x61, 0x72, 0x74, 0x52, 0x73, 0x70, 0x12, 0x12, 0x0a, 0x04, + 0x63, 0x6f, 0x64, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x04, 0x63, 0x6f, 0x64, 0x65, 0x22, 0x38, 0x0a, 0x08, 0x4c, 0x6f, 0x67, 0x69, 0x6e, 0x52, 0x65, 0x71, 0x12, 0x14, 0x0a, 0x05, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x12, 0x16, 0x0a, 0x06, 0x64, 0x65, 0x76, 0x69, 0x63, 0x65, 0x18, 0x02, 0x20, 0x01, @@ -263,18 +304,15 @@ var file_game_proto_rawDesc = []byte{ 0x65, 0x61, 0x74, 0x65, 0x52, 0x65, 0x71, 0x12, 0x10, 0x0a, 0x03, 0x75, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x75, 0x69, 0x64, 0x12, 0x16, 0x0a, 0x06, 0x64, 0x65, 0x76, 0x69, 0x63, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x64, 0x65, 0x76, 0x69, 0x63, - 0x65, 0x22, 0x9a, 0x01, 0x0a, 0x07, 0x52, 0x6f, 0x6c, 0x65, 0x52, 0x73, 0x70, 0x12, 0x20, 0x0a, - 0x04, 0x72, 0x6f, 0x6c, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0c, 0x2e, 0x6d, 0x6f, - 0x64, 0x65, 0x6c, 0x73, 0x2e, 0x52, 0x6f, 0x6c, 0x65, 0x52, 0x04, 0x72, 0x6f, 0x6c, 0x65, 0x12, - 0x20, 0x0a, 0x04, 0x68, 0x65, 0x72, 0x6f, 0x18, 0x03, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0c, 0x2e, - 0x6d, 0x6f, 0x64, 0x65, 0x6c, 0x73, 0x2e, 0x48, 0x65, 0x72, 0x6f, 0x52, 0x04, 0x68, 0x65, 0x72, - 0x6f, 0x12, 0x20, 0x0a, 0x04, 0x74, 0x65, 0x61, 0x6d, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0b, 0x32, - 0x0c, 0x2e, 0x6d, 0x6f, 0x64, 0x65, 0x6c, 0x73, 0x2e, 0x54, 0x65, 0x61, 0x6d, 0x52, 0x04, 0x74, - 0x65, 0x61, 0x6d, 0x12, 0x29, 0x0a, 0x06, 0x65, 0x71, 0x75, 0x69, 0x70, 0x73, 0x18, 0x05, 0x20, - 0x03, 0x28, 0x0b, 0x32, 0x11, 0x2e, 0x6d, 0x6f, 0x64, 0x65, 0x6c, 0x73, 0x2e, 0x45, 0x71, 0x75, - 0x69, 0x70, 0x6d, 0x65, 0x6e, 0x74, 0x52, 0x06, 0x65, 0x71, 0x75, 0x69, 0x70, 0x73, 0x42, 0x0a, - 0x5a, 0x08, 0x2e, 0x2e, 0x2f, 0x70, 0x62, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, - 0x6f, 0x33, + 0x65, 0x22, 0x6f, 0x0a, 0x07, 0x52, 0x6f, 0x6c, 0x65, 0x52, 0x73, 0x70, 0x12, 0x20, 0x0a, 0x04, + 0x72, 0x6f, 0x6c, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0c, 0x2e, 0x6d, 0x6f, 0x64, + 0x65, 0x6c, 0x73, 0x2e, 0x52, 0x6f, 0x6c, 0x65, 0x52, 0x04, 0x72, 0x6f, 0x6c, 0x65, 0x12, 0x20, + 0x0a, 0x04, 0x68, 0x65, 0x72, 0x6f, 0x18, 0x03, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0c, 0x2e, 0x6d, + 0x6f, 0x64, 0x65, 0x6c, 0x73, 0x2e, 0x48, 0x65, 0x72, 0x6f, 0x52, 0x04, 0x68, 0x65, 0x72, 0x6f, + 0x12, 0x20, 0x0a, 0x04, 0x74, 0x65, 0x61, 0x6d, 0x18, 0x04, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0c, + 0x2e, 0x6d, 0x6f, 0x64, 0x65, 0x6c, 0x73, 0x2e, 0x54, 0x65, 0x61, 0x6d, 0x52, 0x04, 0x74, 0x65, + 0x61, 0x6d, 0x42, 0x0a, 0x5a, 0x08, 0x2e, 0x2e, 0x2f, 0x70, 0x62, 0x3b, 0x70, 0x62, 0x62, 0x06, + 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -289,27 +327,26 @@ func file_game_proto_rawDescGZIP() []byte { return file_game_proto_rawDescData } -var file_game_proto_msgTypes = make([]protoimpl.MessageInfo, 4) +var file_game_proto_msgTypes = make([]protoimpl.MessageInfo, 5) var file_game_proto_goTypes = []interface{}{ (*HeartReq)(nil), // 0: game.HeartReq - (*LoginReq)(nil), // 1: game.LoginReq - (*CreateReq)(nil), // 2: game.CreateReq - (*RoleRsp)(nil), // 3: game.RoleRsp - (*Role)(nil), // 4: models.Role - (*Hero)(nil), // 5: models.Hero - (*Team)(nil), // 6: models.Team - (*Equipment)(nil), // 7: models.Equipment + (*HeartRsp)(nil), // 1: game.HeartRsp + (*LoginReq)(nil), // 2: game.LoginReq + (*CreateReq)(nil), // 3: game.CreateReq + (*RoleRsp)(nil), // 4: game.RoleRsp + (*Role)(nil), // 5: models.Role + (*Hero)(nil), // 6: models.Hero + (*Team)(nil), // 7: models.Team } var file_game_proto_depIdxs = []int32{ - 4, // 0: game.RoleRsp.role:type_name -> models.Role - 5, // 1: game.RoleRsp.hero:type_name -> models.Hero - 6, // 2: game.RoleRsp.team:type_name -> models.Team - 7, // 3: game.RoleRsp.equips:type_name -> models.Equipment - 4, // [4:4] is the sub-list for method output_type - 4, // [4:4] is the sub-list for method input_type - 4, // [4:4] is the sub-list for extension type_name - 4, // [4:4] is the sub-list for extension extendee - 0, // [0:4] is the sub-list for field type_name + 5, // 0: game.RoleRsp.role:type_name -> models.Role + 6, // 1: game.RoleRsp.hero:type_name -> models.Hero + 7, // 2: game.RoleRsp.team:type_name -> models.Team + 3, // [3:3] is the sub-list for method output_type + 3, // [3:3] is the sub-list for method input_type + 3, // [3:3] is the sub-list for extension type_name + 3, // [3:3] is the sub-list for extension extendee + 0, // [0:3] is the sub-list for field type_name } func init() { file_game_proto_init() } @@ -332,7 +369,7 @@ func file_game_proto_init() { } } file_game_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*LoginReq); i { + switch v := v.(*HeartRsp); i { case 0: return &v.state case 1: @@ -344,7 +381,7 @@ func file_game_proto_init() { } } file_game_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*CreateReq); i { + switch v := v.(*LoginReq); i { case 0: return &v.state case 1: @@ -356,6 +393,18 @@ func file_game_proto_init() { } } file_game_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*CreateReq); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_game_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*RoleRsp); i { case 0: return &v.state @@ -374,7 +423,7 @@ func file_game_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_game_proto_rawDesc, NumEnums: 0, - NumMessages: 4, + NumMessages: 5, NumExtensions: 0, NumServices: 0, }, diff --git a/pb/models.pb.go b/pb/models.pb.go index 5220f0b..b2b9137 100644 --- a/pb/models.pb.go +++ b/pb/models.pb.go @@ -318,7 +318,10 @@ type Team struct { unknownFields protoimpl.UnknownFields Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty" index:"unique" pri:"1"` // @inject_tag: index:"unique" pri:"1" - HeroIds string `protobuf:"bytes,2,opt,name=hero_ids,json=heroIds,proto3" json:"hero_ids,omitempty"` + RoleId string `protobuf:"bytes,2,opt,name=role_id,json=roleId,proto3" json:"role_id,omitempty"` + HeroId1 string `protobuf:"bytes,3,opt,name=hero_id1,json=heroId1,proto3" json:"hero_id1,omitempty"` + HeroId2 string `protobuf:"bytes,4,opt,name=hero_id2,json=heroId2,proto3" json:"hero_id2,omitempty"` + HeroId3 string `protobuf:"bytes,5,opt,name=hero_id3,json=heroId3,proto3" json:"hero_id3,omitempty"` } func (x *Team) Reset() { @@ -360,9 +363,30 @@ func (x *Team) GetId() string { return "" } -func (x *Team) GetHeroIds() string { +func (x *Team) GetRoleId() string { if x != nil { - return x.HeroIds + return x.RoleId + } + return "" +} + +func (x *Team) GetHeroId1() string { + if x != nil { + return x.HeroId1 + } + return "" +} + +func (x *Team) GetHeroId2() string { + if x != nil { + return x.HeroId2 + } + return "" +} + +func (x *Team) GetHeroId3() string { + if x != nil { + return x.HeroId3 } return "" } @@ -526,10 +550,15 @@ var file_models_proto_rawDesc = []byte{ 0x4c, 0x65, 0x76, 0x65, 0x6c, 0x22, 0x2c, 0x0a, 0x04, 0x50, 0x72, 0x6f, 0x70, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x12, 0x14, 0x0a, 0x05, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x52, 0x05, 0x63, 0x6f, - 0x75, 0x6e, 0x74, 0x22, 0x31, 0x0a, 0x04, 0x54, 0x65, 0x61, 0x6d, 0x12, 0x0e, 0x0a, 0x02, 0x69, - 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x12, 0x19, 0x0a, 0x08, 0x68, - 0x65, 0x72, 0x6f, 0x5f, 0x69, 0x64, 0x73, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x68, - 0x65, 0x72, 0x6f, 0x49, 0x64, 0x73, 0x22, 0xdf, 0x01, 0x0a, 0x04, 0x52, 0x6f, 0x6c, 0x65, 0x12, + 0x75, 0x6e, 0x74, 0x22, 0x80, 0x01, 0x0a, 0x04, 0x54, 0x65, 0x61, 0x6d, 0x12, 0x0e, 0x0a, 0x02, + 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x12, 0x17, 0x0a, 0x07, + 0x72, 0x6f, 0x6c, 0x65, 0x5f, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x72, + 0x6f, 0x6c, 0x65, 0x49, 0x64, 0x12, 0x19, 0x0a, 0x08, 0x68, 0x65, 0x72, 0x6f, 0x5f, 0x69, 0x64, + 0x31, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x68, 0x65, 0x72, 0x6f, 0x49, 0x64, 0x31, + 0x12, 0x19, 0x0a, 0x08, 0x68, 0x65, 0x72, 0x6f, 0x5f, 0x69, 0x64, 0x32, 0x18, 0x04, 0x20, 0x01, + 0x28, 0x09, 0x52, 0x07, 0x68, 0x65, 0x72, 0x6f, 0x49, 0x64, 0x32, 0x12, 0x19, 0x0a, 0x08, 0x68, + 0x65, 0x72, 0x6f, 0x5f, 0x69, 0x64, 0x33, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x68, + 0x65, 0x72, 0x6f, 0x49, 0x64, 0x33, 0x22, 0xdf, 0x01, 0x0a, 0x04, 0x52, 0x6f, 0x6c, 0x65, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x12, 0x10, 0x0a, 0x03, 0x75, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x75, 0x69, 0x64, 0x12, 0x16, 0x0a, 0x06, 0x64, 0x65, 0x76, 0x69, 0x63, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, diff --git a/pb/protocode.pb.go b/pb/protocode.pb.go index 9b627d6..a7f1138 100644 --- a/pb/protocode.pb.go +++ b/pb/protocode.pb.go @@ -25,9 +25,10 @@ type ProtoCode int32 const ( ProtoCode_UNKNOWN ProtoCode = 0 ProtoCode_HeartReq ProtoCode = 1 - ProtoCode_LoginReq ProtoCode = 2 - ProtoCode_CreateReq ProtoCode = 3 - ProtoCode_RoleRsp ProtoCode = 4 + ProtoCode_HeartRsp ProtoCode = 2 + ProtoCode_LoginReq ProtoCode = 3 + ProtoCode_CreateReq ProtoCode = 4 + ProtoCode_RoleRsp ProtoCode = 5 ) // Enum value maps for ProtoCode. @@ -35,16 +36,18 @@ var ( ProtoCode_name = map[int32]string{ 0: "UNKNOWN", 1: "HeartReq", - 2: "LoginReq", - 3: "CreateReq", - 4: "RoleRsp", + 2: "HeartRsp", + 3: "LoginReq", + 4: "CreateReq", + 5: "RoleRsp", } ProtoCode_value = map[string]int32{ "UNKNOWN": 0, "HeartReq": 1, - "LoginReq": 2, - "CreateReq": 3, - "RoleRsp": 4, + "HeartRsp": 2, + "LoginReq": 3, + "CreateReq": 4, + "RoleRsp": 5, } ) @@ -79,14 +82,14 @@ var File_protocode_proto protoreflect.FileDescriptor var file_protocode_proto_rawDesc = []byte{ 0x0a, 0x0f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x63, 0x6f, 0x64, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, - 0x6f, 0x12, 0x09, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x63, 0x6f, 0x64, 0x65, 0x2a, 0x50, 0x0a, 0x09, + 0x6f, 0x12, 0x09, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x63, 0x6f, 0x64, 0x65, 0x2a, 0x5e, 0x0a, 0x09, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x43, 0x6f, 0x64, 0x65, 0x12, 0x0b, 0x0a, 0x07, 0x55, 0x4e, 0x4b, 0x4e, 0x4f, 0x57, 0x4e, 0x10, 0x00, 0x12, 0x0c, 0x0a, 0x08, 0x48, 0x65, 0x61, 0x72, 0x74, 0x52, - 0x65, 0x71, 0x10, 0x01, 0x12, 0x0c, 0x0a, 0x08, 0x4c, 0x6f, 0x67, 0x69, 0x6e, 0x52, 0x65, 0x71, - 0x10, 0x02, 0x12, 0x0d, 0x0a, 0x09, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x52, 0x65, 0x71, 0x10, - 0x03, 0x12, 0x0b, 0x0a, 0x07, 0x52, 0x6f, 0x6c, 0x65, 0x52, 0x73, 0x70, 0x10, 0x04, 0x42, 0x0a, - 0x5a, 0x08, 0x2e, 0x2e, 0x2f, 0x70, 0x62, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, - 0x6f, 0x33, + 0x65, 0x71, 0x10, 0x01, 0x12, 0x0c, 0x0a, 0x08, 0x48, 0x65, 0x61, 0x72, 0x74, 0x52, 0x73, 0x70, + 0x10, 0x02, 0x12, 0x0c, 0x0a, 0x08, 0x4c, 0x6f, 0x67, 0x69, 0x6e, 0x52, 0x65, 0x71, 0x10, 0x03, + 0x12, 0x0d, 0x0a, 0x09, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x52, 0x65, 0x71, 0x10, 0x04, 0x12, + 0x0b, 0x0a, 0x07, 0x52, 0x6f, 0x6c, 0x65, 0x52, 0x73, 0x70, 0x10, 0x05, 0x42, 0x0a, 0x5a, 0x08, + 0x2e, 0x2e, 0x2f, 0x70, 0x62, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( diff --git a/protos b/protos index f725ea2..c9c5e84 160000 --- a/protos +++ b/protos @@ -1 +1 @@ -Subproject commit f725ea29c1806f14c15502406a83b4269193f76b +Subproject commit c9c5e84cc702b2f2defa023fd65100176d5c60fd -- libgit2 0.21.2