From 85c0fc0b72fe15a5d012b206c8e75f955472f71e Mon Sep 17 00:00:00 2001 From: wh_zcy Date: Thu, 18 Aug 2022 11:30:15 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E6=9C=AC=E6=9C=8D?= =?UTF-8?q?=E5=9C=A8=E7=BA=BF=E7=94=A8=E6=88=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmd/v2/ui/protocol.go | 9 +++++++++ comm/const.go | 4 ++++ comm/imodule.go | 2 ++ modules/user/api_login.go | 2 +- modules/user/model_session.go | 20 +++++++------------- modules/user/module.go | 7 ++++++- 6 files changed, 29 insertions(+), 15 deletions(-) diff --git a/cmd/v2/ui/protocol.go b/cmd/v2/ui/protocol.go index 73c004561..798cc08ba 100644 --- a/cmd/v2/ui/protocol.go +++ b/cmd/v2/ui/protocol.go @@ -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: "好友列表", diff --git a/comm/const.go b/comm/const.go index 84b49b34b..737f4c4fb 100644 --- a/comm/const.go +++ b/comm/const.go @@ -20,6 +20,10 @@ const ( Service_Mainte = "mainte" ) +const ( + RDS_SESSION = "online" +) + //ERR const ( MainTypeNotify = "notify" //通知 diff --git a/comm/imodule.go b/comm/imodule.go index 87607355f..744db949a 100644 --- a/comm/imodule.go +++ b/comm/imodule.go @@ -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 { diff --git a/modules/user/api_login.go b/modules/user/api_login.go index 4101f0a08..fa6503ede 100644 --- a/modules/user/api_login.go +++ b/modules/user/api_login.go @@ -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(), diff --git a/modules/user/model_session.go b/modules/user/model_session.go index 040928571..a99ea4f54 100644 --- a/modules/user/model_session.go +++ b/modules/user/model_session.go @@ -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 } diff --git a/modules/user/module.go b/modules/user/module.go index 63f5a405b..66ded5750 100644 --- a/modules/user/module.go +++ b/modules/user/module.go @@ -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 } //查询用户属性值 例如 金币 经验 From 51d0f01383971654865684bfea7ecdf938ab90c3 Mon Sep 17 00:00:00 2001 From: wh_zcy Date: Thu, 18 Aug 2022 11:30:38 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E5=9C=A8=E7=BA=BF?= =?UTF-8?q?=E5=A5=BD=E5=8F=8B=E6=90=9C=E7=B4=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmd/v2/ui/views/friend_randlist.go | 24 +++++++++++++++++++ modules/friend/api.go | 1 + modules/friend/api_randlist.go | 38 ++++++++++++++++++++++++++---- 3 files changed, 59 insertions(+), 4 deletions(-) create mode 100644 cmd/v2/ui/views/friend_randlist.go diff --git a/cmd/v2/ui/views/friend_randlist.go b/cmd/v2/ui/views/friend_randlist.go new file mode 100644 index 000000000..0a73b0570 --- /dev/null +++ b/cmd/v2/ui/views/friend_randlist.go @@ -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 +} diff --git a/modules/friend/api.go b/modules/friend/api.go index 5e8135c47..a68d31d00 100644 --- a/modules/friend/api.go +++ b/modules/friend/api.go @@ -18,6 +18,7 @@ const ( FriendSubTypeZan = "zan" FriendSubTypeZanreceive = "zanreceive" FriendSubTypeZanList = "zanlist" + FriendSubTypeRandList = "randlist" ) type apiComp struct { diff --git a/modules/friend/api_randlist.go b/modules/friend/api_randlist.go index 0a65574cc..8bd9140be 100644 --- a/modules/friend/api_randlist.go +++ b/modules/friend/api_randlist.go @@ -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 }