From 7fe93f2bb2431a90fdc9f4fad3429b51c07b4851 Mon Sep 17 00:00:00 2001 From: wh_zcy Date: Tue, 18 Oct 2022 17:56:08 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A5=BD=E5=8F=8B=E8=B7=A8=E6=9C=8D=E5=A4=84?= =?UTF-8?q?=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmd/v2/ui/protocol.go | 9 ++++++++ cmd/v2/ui/views/hero_info.go | 42 +++++++++++++++++++++++++++++++++++ comm/imodule.go | 2 ++ modules/friend/api_list.go | 10 ++++----- modules/user/model_session.go | 6 ++++- modules/user/module.go | 37 ++++++++++++++++++++++++++++++ 6 files changed, 100 insertions(+), 6 deletions(-) create mode 100644 cmd/v2/ui/views/hero_info.go diff --git a/cmd/v2/ui/protocol.go b/cmd/v2/ui/protocol.go index 954a83dc8..5b0478e20 100644 --- a/cmd/v2/ui/protocol.go +++ b/cmd/v2/ui/protocol.go @@ -64,6 +64,7 @@ var ( ff(comm.ModuleHero, hero.StrengthenUplv): &formview.HeroStrengthenUplvView{}, ff(comm.ModuleHero, hero.StrengthenUpStar): &formview.HeroStrengthenUpStarView{}, ff(comm.ModuleHero, hero.DrawCard): &formview.HeroZhaomuView{}, + ff(comm.ModuleHero, "info"): &formview.HeroInfoView{}, //equip ff(comm.ModuleEquipment, "getlist"): &formview.EquipListView{}, ff(comm.ModuleEquipment, "equip"): &formview.EquipUpDownView{}, @@ -154,6 +155,7 @@ var ( ff(comm.ModuleHero, hero.StrengthenUplv), ff(comm.ModuleHero, hero.StrengthenUpStar), ff(comm.ModuleHero, hero.DrawCard), + ff(comm.ModuleHero, "info"), }, "equipment": { ff(comm.ModuleEquipment, "getlist"), @@ -470,6 +472,13 @@ var ( SubType: hero.DrawCard, Enabled: true, }, + ff(comm.ModuleHero, "info"): { + NavLabel: "英雄信息", + Desc: "英雄信息", + MainType: string(comm.ModuleHero), + SubType: "info", + Enabled: true, + }, //equipment string(comm.ModuleEquipment): { NavLabel: "装备", diff --git a/cmd/v2/ui/views/hero_info.go b/cmd/v2/ui/views/hero_info.go new file mode 100644 index 000000000..c75dd41ed --- /dev/null +++ b/cmd/v2/ui/views/hero_info.go @@ -0,0 +1,42 @@ +package formview + +import ( + "go_dreamfactory/cmd/v2/model" + "go_dreamfactory/cmd/v2/service" + "go_dreamfactory/pb" + + "fyne.io/fyne/v2" + "fyne.io/fyne/v2/widget" + "github.com/sirupsen/logrus" +) + +type HeroInfoView struct { + BaseformView +} + +func (this *HeroInfoView) CreateView(t *model.TestCase) fyne.CanvasObject { + uidEntry := widget.NewEntry() + uidEntry.PlaceHolder = "玩家ID" + + heroIdEntry := widget.NewEntry() + heroIdEntry.PlaceHolder = "英雄ObjID" + + this.form.AppendItem(widget.NewFormItem("UID", uidEntry)) + this.form.AppendItem(widget.NewFormItem("HeroObjID", heroIdEntry)) + + this.form.OnSubmit = func() { + if err := service.GetPttService().SendToClient( + t.MainType, + t.SubType, + &pb.HeroInfoReq{ + Uid: uidEntry.Text, + HeroId: heroIdEntry.Text, + }, + ); err != nil { + logrus.Error(err) + return + } + + } + return this.form +} diff --git a/comm/imodule.go b/comm/imodule.go index 7218c5723..e98a47d0e 100644 --- a/comm/imodule.go +++ b/comm/imodule.go @@ -89,6 +89,8 @@ type ( UserOnlineList() ([]*pb.CacheUser, error) // 跨服在线玩家列表 CrossUserOnlineList() ([]*pb.CacheUser, error) + // 跨服用户会话 + CrossUserSession(uid string) *pb.CacheUser // 跨服搜索玩家 CrossSearchUser(nickname string) ([]*pb.DBUser, error) } diff --git a/modules/friend/api_list.go b/modules/friend/api_list.go index d0bc1915a..86ad2055c 100644 --- a/modules/friend/api_list.go +++ b/modules/friend/api_list.go @@ -15,14 +15,14 @@ func (this *apiComp) ListCheck(session comm.IUserSession, req *pb.FriendListReq) //好友列表 func (this *apiComp) List(session comm.IUserSession, req *pb.FriendListReq) (code pb.ErrorCode, data proto.Message) { var ( - self *pb.DBFriend - Resp *pb.FriendListResp - list []*pb.FriendBase + self *pb.DBFriend + Resp *pb.FriendListResp + list []*pb.FriendBase ) defer func() { Resp = &pb.FriendListResp{ - List: list, + List: list, } err := session.SendMsg(string(this.moduleFriend.GetType()), FriendSubTypeList, Resp) if err != nil { @@ -46,7 +46,7 @@ func (this *apiComp) List(session comm.IUserSession, req *pb.FriendListReq) (cod } // 判断用户在线状态 - us := this.moduleFriend.ModuleUser.GetUserSession(userId) + us := this.moduleFriend.ModuleUser.CrossUserSession(userId) if us != nil { base.OfflineTime = 0 //在线 } diff --git a/modules/user/model_session.go b/modules/user/model_session.go index 84841e605..5f345ea52 100644 --- a/modules/user/model_session.go +++ b/modules/user/model_session.go @@ -8,6 +8,8 @@ import ( "go_dreamfactory/modules" "go_dreamfactory/pb" "go_dreamfactory/sys/db" + + "go.mongodb.org/mongo-driver/mongo" ) type ModelSession struct { @@ -33,7 +35,9 @@ func (this *ModelSession) Start() (err error) { func (this *ModelSession) getUserSession(uid string) (user *pb.CacheUser) { user = &pb.CacheUser{} if err := this.GetListObj(comm.RDS_SESSION, uid, user); err != nil { - this.module.Errorln(err) + if err != mongo.ErrNoDocuments { + this.module.Errorln(err) + } return nil } return user diff --git a/modules/user/module.go b/modules/user/module.go index 04fe3085d..2b3fba60e 100644 --- a/modules/user/module.go +++ b/modules/user/module.go @@ -17,6 +17,7 @@ import ( "github.com/pkg/errors" "go.mongodb.org/mongo-driver/bson" + "go.mongodb.org/mongo-driver/mongo" ) const ( @@ -24,6 +25,8 @@ const ( Rpc_GetAllOnlineUser string = "Rpc_GetAllOnlineUser" // 跨服用户 Rpc_GetCrossUser string = "Rpc_GetCrossUser" + // 跨服用户会话 + Rpc_GetCrossUserSession string = "Rpc_GetCrossUserSession" // 搜索用户 Rpc_QueryUser = "Rpc_QueryUser" ) @@ -61,6 +64,7 @@ func (this *User) Start() (err error) { event.RegisterGO(comm.EventUserOffline, this.CleanSession) this.service.RegisterFunctionName(Rpc_GetAllOnlineUser, this.RpcGetAllOnlineUser) this.service.RegisterFunctionName(Rpc_GetCrossUser, this.RpcGetCrossUser) + this.service.RegisterFunctionName(Rpc_GetCrossUserSession, this.RpcGetCrossUserSession) this.service.RegisterFunctionName(Rpc_QueryUser, this.RpcQueryUser) return } @@ -121,9 +125,25 @@ func (this *User) CrossUserOnlineList() ([]*pb.CacheUser, error) { reply := &pb.UserOnlineResp{} err := this.service.AcrossClusterRpcCall(context.Background(), this.GetCrossTag(), comm.Service_Worker, Rpc_GetAllOnlineUser, nil, reply) + if err != nil { + log.Errorf("Rpc_GetAllOnlineUser err:%v", err) + return nil, err + } return reply.Users, err } +// 跨服玩家会话 +func (this *User) CrossUserSession(uid string) *pb.CacheUser { + cacheUser := &pb.CacheUser{} + err := this.service.AcrossClusterRpcCall(context.Background(), this.GetCrossTag(), + comm.Service_Worker, Rpc_GetCrossUserSession, &pb.UIdReq{Uid: uid}, cacheUser) + if err != nil { + log.Errorf("Rpc_GetCrossUserSession err:%v", err) + return nil + } + return cacheUser +} + //跨服搜索用户 func (this *User) CrossSearchUser(nickName string) ([]*pb.DBUser, error) { name := strings.TrimSpace(nickName) @@ -344,6 +364,23 @@ func (this *User) RpcGetCrossUser(ctx context.Context, req *pb.UIdReq, reply *pb return nil } +func (this *User) RpcGetCrossUserSession(ctx context.Context, req *pb.UIdReq, reply *pb.CacheUser) error { + conn, err := db.Local() + if err != nil { + log.Errorf("cross db err: %v", err) + return err + } + model := db.NewDBModel(comm.TableSession, 0, conn) + if err := model.GetListObj(comm.RDS_SESSION, req.Uid, reply); err != nil { + if err != mongo.ErrNoDocuments { + log.Errorf("%v", err) + } + return nil + } + + return nil +} + func (this *User) RpcQueryUser(ctx context.Context, req *pb.NameReq, reply *pb.UserDataListResp) error { // 区服列表 for _, tag := range db.GetServerTags() {