This commit is contained in:
liwei 2022-08-18 11:33:21 +08:00
commit 34bc631c9c
9 changed files with 88 additions and 19 deletions

View File

@ -63,6 +63,7 @@ var (
ff(comm.ModuleFriend, friend.FriendSubTypeDelBlack): &formview.FriendDelblackView{},
ff(comm.ModuleFriend, friend.FriendSubTypeSearch): &formview.FriendSearchView{},
ff(comm.ModuleFriend, friend.FriendSubTypeZanList): &formview.FriendZanView{},
ff(comm.ModuleFriend, friend.FriendSubTypeRandList): &formview.FriendRandListView{},
// shop
ff(comm.ModuleShop, "getlist"): &formview.ShopListView{},
ff(comm.ModuleShop, "buy"): &formview.ShopBuyView{},
@ -132,6 +133,7 @@ var (
ff(comm.ModuleFriend, friend.FriendSubTypeDelBlack),
ff(comm.ModuleFriend, friend.FriendSubTypeSearch),
ff(comm.ModuleFriend, friend.FriendSubTypeZanList),
ff(comm.ModuleFriend, friend.FriendSubTypeRandList),
},
"shop": {
ff(comm.ModuleShop, "getlist"),
@ -365,6 +367,13 @@ var (
MainType: string(comm.ModuleFriend),
Enabled: true,
},
ff(comm.ModuleFriend, friend.FriendSubTypeRandList): {
NavLabel: "在线玩家",
Desc: "在线玩家列表",
MainType: string(comm.ModuleFriend),
SubType: friend.FriendSubTypeRandList,
Enabled: true,
},
ff(comm.ModuleFriend, friend.FriendSubTypeList): {
NavLabel: "好友列表",
Desc: "好友列表",

View File

@ -0,0 +1,24 @@
package formview
import (
"go_dreamfactory/cmd/v2/model"
"go_dreamfactory/cmd/v2/service"
"go_dreamfactory/pb"
"fyne.io/fyne/v2"
"github.com/sirupsen/logrus"
)
type FriendRandListView struct {
BaseformView
}
func (this *FriendRandListView) CreateView(t *model.TestCase) fyne.CanvasObject {
this.form.OnSubmit = func() {
if err := service.GetPttService().SendToClient(t.MainType, t.SubType,
&pb.FriendOnlineReq{}); err != nil {
logrus.Error(err)
}
}
return this.form
}

View File

@ -20,6 +20,10 @@ const (
Service_Mainte = "mainte"
)
const (
RDS_SESSION = "online"
)
//ERR
const (
MainTypeNotify = "notify" //通知

View File

@ -74,6 +74,8 @@ type (
GetUserExpand(uid string) (result *pb.DBUserExpand, err error)
//更新用户expand
ChangeUserExpand(uid string, value map[string]interface{}) error
// 本服在线玩家列表
UserOnlineList() ([]*pb.CacheUser, error)
}
//武器模块
IEquipment interface {

View File

@ -18,6 +18,7 @@ const (
FriendSubTypeZan = "zan"
FriendSubTypeZanreceive = "zanreceive"
FriendSubTypeZanList = "zanlist"
FriendSubTypeRandList = "randlist"
)
type apiComp struct {

View File

@ -3,6 +3,7 @@ package friend
import (
"go_dreamfactory/comm"
"go_dreamfactory/pb"
"go_dreamfactory/utils"
"google.golang.org/protobuf/proto"
)
@ -16,6 +17,11 @@ func (this *apiComp) Randlist(session comm.IUserSession, req *pb.FriendOnlineReq
self *pb.DBFriend
)
//在线玩家
cu, err := this.moduleFriend.ModuleUser.UserOnlineList()
if err != nil {
code = pb.ErrorCode_DBError
return
}
self = this.moduleFriend.modelFriend.GetFriend(session.GetUserId())
if self == nil {
@ -23,11 +29,35 @@ func (this *apiComp) Randlist(session comm.IUserSession, req *pb.FriendOnlineReq
return
}
// 好友列表
// self.FriendIds
var userList []*pb.FriendBase
for _, v := range cu {
if v.Uid == session.GetUserId() {
continue
}
if _, ok := utils.Findx(self.FriendIds, v.Uid); ok {
continue
}
if _, ok := utils.Findx(self.ApplyIds, v.Uid); ok {
continue
}
user := this.moduleFriend.ModuleUser.GetUser(v.Uid)
if user == nil {
continue
}
userList = append(userList, &pb.FriendBase{
UserId: user.Uid,
NickName: user.Name,
Level: user.Lv,
})
}
// 已申请的好友
// self.ApplyIds
rsp := &pb.FriendOnlineResp{
List: userList,
}
if err := session.SendMsg(string(this.moduleFriend.GetType()), FriendSubTypeRandList, rsp); err != nil {
code = pb.ErrorCode_SystemError
return
}
return
}

View File

@ -80,7 +80,7 @@ func (this *apiComp) Login(session comm.IUserSession, req *pb.UserLoginReq) (cod
}
//缓存user session
err = this.module.modelSession.AddList("online", user.Uid, map[string]interface{}{
err = this.module.modelSession.AddList(comm.RDS_SESSION, user.Uid, map[string]interface{}{
"uid": user.Uid,
"sessionId": session.GetSessionId(),
"serviceTag": session.GetServiecTag(),

View File

@ -3,6 +3,7 @@ package user
import (
"go_dreamfactory/comm"
"go_dreamfactory/lego/core"
"go_dreamfactory/lego/sys/log"
"go_dreamfactory/modules"
"go_dreamfactory/pb"
)
@ -20,18 +21,11 @@ func (this *ModelSession) Init(service core.IService, module core.IModule, comp
}
//获取用户
func (this *ModelSession) getUserSession(uid string) (cuser *pb.CacheUser) {
var sl []*pb.CacheUser
if err := this.GetList("online", sl); err != nil {
this.module.Errorf("GetUserSession err:%v", err)
return
func (this *ModelSession) getUserSession(uid string) (user *pb.CacheUser) {
user = &pb.CacheUser{}
if err := this.GetListObj(comm.RDS_SESSION, uid, user); err != nil {
log.Errorf("getUserSession err:%v", err)
return nil
}
for _, v := range sl {
if v.Uid == uid {
return v
}
}
return
return user
}

View File

@ -76,7 +76,12 @@ func (this *User) CleanSession(session comm.IUserSession) {
}
// 在线玩家列表
func (this *User) UserOnline() {
func (this *User) UserOnlineList() ([]*pb.CacheUser, error) {
var cache []*pb.CacheUser
if err := this.modelSession.GetList(comm.RDS_SESSION, &cache); err != nil {
return nil, err
}
return cache, nil
}
//查询用户属性值 例如 金币 经验