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 } //查询用户属性值 例如 金币 经验