package smithy import ( "go_dreamfactory/comm" "go_dreamfactory/pb" "go_dreamfactory/utils" "google.golang.org/protobuf/proto" ) //参数校验 func (this *apiComp) GetRandUserCheck(session comm.IUserSession, req *pb.SmithyGetRandUserReq) (code pb.ErrorCode) { return } /// 获取一些玩家数据 func (this *apiComp) GetRandUser(session comm.IUserSession, req *pb.SmithyGetRandUserReq) (code pb.ErrorCode, data proto.Message) { code = this.GetRandUserCheck(session, req) if code != pb.ErrorCode_Success { return // 参数校验失败直接返回 } cu, err := this.module.ModuleUser.UserOnlineList() if err != nil { code = pb.ErrorCode_DBError return } var randOnlineUsers []string if len(cu) > 5 { randArr := utils.Numbers(0, len(cu), 5) for _, v := range randArr { if cu[v] != nil { randOnlineUsers = append(randOnlineUsers, cu[v].Uid) } } } session.SendMsg(string(this.module.GetType()), SmithyGetRandUserResp, &pb.SmithyGetRandUserResp{User: randOnlineUsers}) return }