好友跨服处理

This commit is contained in:
wh_zcy 2022-10-18 17:56:08 +08:00
parent dbccb138d9
commit 7fe93f2bb2
6 changed files with 100 additions and 6 deletions

View File

@ -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: "装备",

View File

@ -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
}

View File

@ -89,6 +89,8 @@ type (
UserOnlineList() ([]*pb.CacheUser, error)
// 跨服在线玩家列表
CrossUserOnlineList() ([]*pb.CacheUser, error)
// 跨服用户会话
CrossUserSession(uid string) *pb.CacheUser
// 跨服搜索玩家
CrossSearchUser(nickname string) ([]*pb.DBUser, error)
}

View File

@ -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 //在线
}

View File

@ -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

View File

@ -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() {