diff --git a/cmd/v2/resources/config.yaml b/cmd/v2/resources/config.yaml index c53bb3846..7003e83e5 100644 --- a/cmd/v2/resources/config.yaml +++ b/cmd/v2/resources/config.yaml @@ -9,7 +9,7 @@ services: name: 赵长远 url: ws://10.0.0.238:7891/gateway - service: - sid: 3 + sid: "df01" name: 内网 url: ws://10.0.0.9:7891/gateway - service: diff --git a/cmd/v2/ui/app_gen.go b/cmd/v2/ui/app_gen.go index 283dfc847..f0b3a06ef 100644 --- a/cmd/v2/ui/app_gen.go +++ b/cmd/v2/ui/app_gen.go @@ -38,20 +38,16 @@ func (this *appGen) LazyInit(obs observer.Observer) error { serverAddr := widget.NewEntry() serverAddr.PlaceHolder = "服务器地址" - serverAddr.Text = gt.ServerAddr projectDir := widget.NewEntry() projectDir.PlaceHolder = "项目目录" - projectDir.Text = gt.ProjectDir //"E:\\projects\\workspace\\go_dreamfactory" workDir := widget.NewEntry() workDir.PlaceHolder = "LuBan目录" - workDir.Text = gt.WorkDir // "E:\\svn\\dreamworks\\client\\dreamworks\\ExcelFile" // client client := widget.NewEntry() client.PlaceHolder = "配置Luban Client.exe路径" - client.Text = gt.Client //"\\Luban.Client\\Luban.Client.exe" //define define := widget.NewEntry() @@ -74,7 +70,14 @@ func (this *appGen) LazyInit(obs observer.Observer) error { genTypeText = s }) genType.PlaceHolder = "生成类型" - genType.Selected = gt.GenType + + if gt != nil { + serverAddr.Text = gt.ServerAddr //10.0.1.11 + projectDir.Text = gt.ProjectDir //"E:\\projects\\workspace\\go_dreamfactory" + workDir.Text = gt.WorkDir // "E:\\svn\\dreamworks\\client\\dreamworks\\ExcelFile" + client.Text = gt.Client //"\\Luban.Client\\Luban.Client.exe" + genType.Selected = gt.GenType + } form := widget.NewForm( widget.NewFormItem("服务地址", serverAddr), diff --git a/modules/comp_configure.go b/modules/comp_configure.go index 6ec99b3df..9ecd17246 100644 --- a/modules/comp_configure.go +++ b/modules/comp_configure.go @@ -61,9 +61,11 @@ func (this *MCompConfigure) GetGlobalConf() *cfg.GameGlobalData { ) if v, err := this.GetConfigure(game_global); err != nil { log.Errorf("get global conf err:%v", err) + return nil } else { if configure, ok = v.(*cfg.GameGlobal); !ok { log.Errorf("%T no is *cfg.Game_global", v) + return nil } } return configure.GetDataList()[0] // 返回对象信息 diff --git a/modules/friend/api_addblack.go b/modules/friend/api_addblack.go index 06c0613cf..527f201eb 100644 --- a/modules/friend/api_addblack.go +++ b/modules/friend/api_addblack.go @@ -21,6 +21,12 @@ func (this *apiComp) Addblack(session comm.IUserSession, req *pb.FriendAddBlackR return } + globalCnf := this.moduleFriend.configure.GetGlobalConf() + if globalCnf == nil { + code = pb.ErrorCode_ConfigNoFound + return + } + var ( err error self *pb.DBFriend @@ -70,7 +76,7 @@ func (this *apiComp) Addblack(session comm.IUserSession, req *pb.FriendAddBlackR } // 判断是否黑名单人数已满 - if len(self.BlackIds) >= int(this.moduleFriend.configure.GetGlobalConf().FriendBlack) { + if len(self.BlackIds) >= int(globalCnf.FriendBlack) { code = pb.ErrorCode_FriendBlackMax return } diff --git a/modules/friend/api_apply.go b/modules/friend/api_apply.go index 388b3bf84..80e05d166 100644 --- a/modules/friend/api_apply.go +++ b/modules/friend/api_apply.go @@ -21,6 +21,12 @@ func (this *apiComp) Apply(session comm.IUserSession, req *pb.FriendApplyReq) (c if code = this.ApplyCheck(session, req); code != pb.ErrorCode_Success { return } + + globalCnf := this.moduleFriend.configure.GetGlobalConf() + if globalCnf == nil { + code = pb.ErrorCode_ConfigNoFound + return + } var ( err error @@ -63,13 +69,13 @@ func (this *apiComp) Apply(session comm.IUserSession, req *pb.FriendApplyReq) (c } //判断是否超过最大好友数量 - if len(self.FriendIds) >= int(this.moduleFriend.configure.GetGlobalConf().FriendMaxnum) { + if len(self.FriendIds) >= int(globalCnf.FriendMaxnum) { code = pb.ErrorCode_FriendSelfMax return } //判断对方是否也超过最大好友数量 - if len(target.FriendIds) >= int(this.moduleFriend.configure.GetGlobalConf().FriendMaxnum) { + if len(target.FriendIds) >= int(globalCnf.FriendMaxnum) { code = pb.ErrorCode_FriendTargetMax return } diff --git a/modules/friend/api_randlist.go b/modules/friend/api_randlist.go index 74f029ce5..230063655 100644 --- a/modules/friend/api_randlist.go +++ b/modules/friend/api_randlist.go @@ -1,6 +1,7 @@ package friend import ( + "fmt" "go_dreamfactory/comm" "go_dreamfactory/pb" "go_dreamfactory/utils" @@ -23,6 +24,14 @@ func (this *apiComp) Randlist(session comm.IUserSession, req *pb.FriendRandlistR return } + // 只随机选择5个在线玩家 + // var randOnlineUsers []string + if len(cu) > 5 { + fmt.Println(utils.Numbers(0, len(cu), 5)) + + } + + // 当前玩家好友数据 self = this.moduleFriend.modelFriend.GetFriend(session.GetUserId()) if self == nil { code = pb.ErrorCode_FriendSelfNoData @@ -30,32 +39,37 @@ func (this *apiComp) Randlist(session comm.IUserSession, req *pb.FriendRandlistR } 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 - // } + + // 判断当前在线好友是否在自己的申请列表中,如果存在也过滤掉 + target := this.moduleFriend.modelFriend.GetFriend(v.Uid) + if target == nil { + continue + } + + // 获取在线好友的信息 user := this.moduleFriend.ModuleUser.GetUser(v.Uid) if user == nil { continue } base := &pb.FriendBase{ - UserId: user.Uid, - NickName: user.Name, - Level: user.Lv, + UserId: user.Uid, + NickName: user.Name, + Level: user.Lv, + OfflineTime: user.Offlinetime, } - // 判断是否在自己的申请列表中 - target := this.moduleFriend.modelFriend.GetFriend(v.Uid) - if target == nil { - continue - } + // 申请过的在线好友,设置申请状态 if _, ok := utils.Findx(target.ApplyIds, self.Uid); ok { base.IsApplied = true } diff --git a/modules/friend/api_zan.go b/modules/friend/api_zan.go index 630396200..bf8fb332c 100644 --- a/modules/friend/api_zan.go +++ b/modules/friend/api_zan.go @@ -27,6 +27,12 @@ func (this *apiComp) Zan(session comm.IUserSession, req *pb.FriendZanReq) (code selfId string ) + globalCnf := this.moduleFriend.configure.GetGlobalConf() + if globalCnf == nil { + code = pb.ErrorCode_ConfigNoFound + return + } + selfId = session.GetUserId() // 不能给自己点赞 @@ -49,7 +55,7 @@ func (this *apiComp) Zan(session comm.IUserSession, req *pb.FriendZanReq) (code } if _, ok := utils.Find(target.ZanIds, selfId); !ok { - + pointTotal += 1 target.ZanIds = append(target.ZanIds, selfId) //设置被点赞玩家 @@ -70,7 +76,7 @@ func (this *apiComp) Zan(session comm.IUserSession, req *pb.FriendZanReq) (code } // 今日送出的友情点是否达到上限 - if ue.FriendPointOD >= this.moduleFriend.configure.GetGlobalConf().FriendMaxsendnum { + if ue.FriendPointOD >= globalCnf.FriendMaxsendnum { code = pb.ErrorCode_FriendPointLimit return } diff --git a/modules/friend/api_zanreceive.go b/modules/friend/api_zanreceive.go index 20fc771b0..84a216162 100644 --- a/modules/friend/api_zanreceive.go +++ b/modules/friend/api_zanreceive.go @@ -22,6 +22,12 @@ func (this *apiComp) Zanreceive(session comm.IUserSession, req *pb.FriendZanrece return } + globalCnf := this.moduleFriend.configure.GetGlobalConf() + if globalCnf == nil { + code = pb.ErrorCode_ConfigNoFound + return + } + var ( self *pb.DBFriend err error @@ -35,7 +41,6 @@ func (this *apiComp) Zanreceive(session comm.IUserSession, req *pb.FriendZanrece var ( pointTotal int32 // 累计友情值 - ) // 是否已领取点赞 @@ -63,7 +68,7 @@ func (this *apiComp) Zanreceive(session comm.IUserSession, req *pb.FriendZanrece } // 今日获赠的友情点是否达到上限 - if ue.FriendPointID >= int32(this.moduleFriend.configure.GetGlobalConf().FriendMaxgetnum) { + if ue.FriendPointID >= int32(globalCnf.FriendMaxgetnum) { code = pb.ErrorCode_FriendPointLimit return } diff --git a/utils/random.go b/utils/random.go index 4251724e6..ff865793d 100644 --- a/utils/random.go +++ b/utils/random.go @@ -5,6 +5,8 @@ import ( "math/rand" "strings" "time" + + "github.com/Pallinder/go-randomdata" ) func GenValidateCode(width int) string { @@ -18,3 +20,38 @@ func GenValidateCode(width int) string { } return sb.String() } + +// 随机一组随机数 +// number >= start and < end num 随机数个数 +func Numbers(start, end, num int) []int { + if end-start < 0 || num > (end-start) { + return nil + } + + if end-start == 1 { + n := randomdata.Number(start, end) + return []int{n} + } + + var i int + arr := make([]int, num) + boo := make(map[int]int) + for { + if i == num { + break + } + + var n int + n = randomdata.Number(start, end) + if _, ok := boo[n]; ok { + // 重新生成 + n = randomdata.Number(start, end) + continue + } + boo[n] = i + arr[i] = n + i++ + } + + return arr +} diff --git a/utils/utils_test.go b/utils/utils_test.go index 664150a53..954317870 100644 --- a/utils/utils_test.go +++ b/utils/utils_test.go @@ -20,3 +20,7 @@ func TestSubTime(t *testing.T) { func TestRandom(t *testing.T) { fmt.Println(utils.GenValidateCode(6)) } + +func TestNumber(t *testing.T) { + fmt.Println(utils.Numbers(5, 10, 5)) +}