优化全局配置

This commit is contained in:
wh_zcy 2022-08-19 12:06:04 +08:00
parent 703039326e
commit f05347cc2f
10 changed files with 107 additions and 24 deletions

View File

@ -9,7 +9,7 @@ services:
name: 赵长远 name: 赵长远
url: ws://10.0.0.238:7891/gateway url: ws://10.0.0.238:7891/gateway
- service: - service:
sid: 3 sid: "df01"
name: 内网 name: 内网
url: ws://10.0.0.9:7891/gateway url: ws://10.0.0.9:7891/gateway
- service: - service:

View File

@ -38,20 +38,16 @@ func (this *appGen) LazyInit(obs observer.Observer) error {
serverAddr := widget.NewEntry() serverAddr := widget.NewEntry()
serverAddr.PlaceHolder = "服务器地址" serverAddr.PlaceHolder = "服务器地址"
serverAddr.Text = gt.ServerAddr
projectDir := widget.NewEntry() projectDir := widget.NewEntry()
projectDir.PlaceHolder = "项目目录" projectDir.PlaceHolder = "项目目录"
projectDir.Text = gt.ProjectDir //"E:\\projects\\workspace\\go_dreamfactory"
workDir := widget.NewEntry() workDir := widget.NewEntry()
workDir.PlaceHolder = "LuBan目录" workDir.PlaceHolder = "LuBan目录"
workDir.Text = gt.WorkDir // "E:\\svn\\dreamworks\\client\\dreamworks\\ExcelFile"
// client // client
client := widget.NewEntry() client := widget.NewEntry()
client.PlaceHolder = "配置Luban Client.exe路径" client.PlaceHolder = "配置Luban Client.exe路径"
client.Text = gt.Client //"\\Luban.Client\\Luban.Client.exe"
//define //define
define := widget.NewEntry() define := widget.NewEntry()
@ -74,7 +70,14 @@ func (this *appGen) LazyInit(obs observer.Observer) error {
genTypeText = s genTypeText = s
}) })
genType.PlaceHolder = "生成类型" genType.PlaceHolder = "生成类型"
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 genType.Selected = gt.GenType
}
form := widget.NewForm( form := widget.NewForm(
widget.NewFormItem("服务地址", serverAddr), widget.NewFormItem("服务地址", serverAddr),

View File

@ -61,9 +61,11 @@ func (this *MCompConfigure) GetGlobalConf() *cfg.GameGlobalData {
) )
if v, err := this.GetConfigure(game_global); err != nil { if v, err := this.GetConfigure(game_global); err != nil {
log.Errorf("get global conf err:%v", err) log.Errorf("get global conf err:%v", err)
return nil
} else { } else {
if configure, ok = v.(*cfg.GameGlobal); !ok { if configure, ok = v.(*cfg.GameGlobal); !ok {
log.Errorf("%T no is *cfg.Game_global", v) log.Errorf("%T no is *cfg.Game_global", v)
return nil
} }
} }
return configure.GetDataList()[0] // 返回对象信息 return configure.GetDataList()[0] // 返回对象信息

View File

@ -21,6 +21,12 @@ func (this *apiComp) Addblack(session comm.IUserSession, req *pb.FriendAddBlackR
return return
} }
globalCnf := this.moduleFriend.configure.GetGlobalConf()
if globalCnf == nil {
code = pb.ErrorCode_ConfigNoFound
return
}
var ( var (
err error err error
self *pb.DBFriend 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 code = pb.ErrorCode_FriendBlackMax
return return
} }

View File

@ -22,6 +22,12 @@ func (this *apiComp) Apply(session comm.IUserSession, req *pb.FriendApplyReq) (c
return return
} }
globalCnf := this.moduleFriend.configure.GetGlobalConf()
if globalCnf == nil {
code = pb.ErrorCode_ConfigNoFound
return
}
var ( var (
err error err error
self *pb.DBFriend self *pb.DBFriend
@ -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 code = pb.ErrorCode_FriendSelfMax
return return
} }
//判断对方是否也超过最大好友数量 //判断对方是否也超过最大好友数量
if len(target.FriendIds) >= int(this.moduleFriend.configure.GetGlobalConf().FriendMaxnum) { if len(target.FriendIds) >= int(globalCnf.FriendMaxnum) {
code = pb.ErrorCode_FriendTargetMax code = pb.ErrorCode_FriendTargetMax
return return
} }

View File

@ -1,6 +1,7 @@
package friend package friend
import ( import (
"fmt"
"go_dreamfactory/comm" "go_dreamfactory/comm"
"go_dreamfactory/pb" "go_dreamfactory/pb"
"go_dreamfactory/utils" "go_dreamfactory/utils"
@ -23,6 +24,14 @@ func (this *apiComp) Randlist(session comm.IUserSession, req *pb.FriendRandlistR
return return
} }
// 只随机选择5个在线玩家
// var randOnlineUsers []string
if len(cu) > 5 {
fmt.Println(utils.Numbers(0, len(cu), 5))
}
// 当前玩家好友数据
self = this.moduleFriend.modelFriend.GetFriend(session.GetUserId()) self = this.moduleFriend.modelFriend.GetFriend(session.GetUserId())
if self == nil { if self == nil {
code = pb.ErrorCode_FriendSelfNoData code = pb.ErrorCode_FriendSelfNoData
@ -30,16 +39,24 @@ func (this *apiComp) Randlist(session comm.IUserSession, req *pb.FriendRandlistR
} }
var userList []*pb.FriendBase var userList []*pb.FriendBase
for _, v := range cu { for _, v := range cu {
// 将自己从在线玩家中过滤掉
if v.Uid == session.GetUserId() { if v.Uid == session.GetUserId() {
continue continue
} }
// 将自己的好友从在线玩家中过滤掉
if _, ok := utils.Findx(self.FriendIds, v.Uid); ok { if _, ok := utils.Findx(self.FriendIds, v.Uid); ok {
continue 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) user := this.moduleFriend.ModuleUser.GetUser(v.Uid)
if user == nil { if user == nil {
continue continue
@ -49,13 +66,10 @@ func (this *apiComp) Randlist(session comm.IUserSession, req *pb.FriendRandlistR
UserId: user.Uid, UserId: user.Uid,
NickName: user.Name, NickName: user.Name,
Level: user.Lv, 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 { if _, ok := utils.Findx(target.ApplyIds, self.Uid); ok {
base.IsApplied = true base.IsApplied = true
} }

View File

@ -27,6 +27,12 @@ func (this *apiComp) Zan(session comm.IUserSession, req *pb.FriendZanReq) (code
selfId string selfId string
) )
globalCnf := this.moduleFriend.configure.GetGlobalConf()
if globalCnf == nil {
code = pb.ErrorCode_ConfigNoFound
return
}
selfId = session.GetUserId() selfId = session.GetUserId()
// 不能给自己点赞 // 不能给自己点赞
@ -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 code = pb.ErrorCode_FriendPointLimit
return return
} }

View File

@ -22,6 +22,12 @@ func (this *apiComp) Zanreceive(session comm.IUserSession, req *pb.FriendZanrece
return return
} }
globalCnf := this.moduleFriend.configure.GetGlobalConf()
if globalCnf == nil {
code = pb.ErrorCode_ConfigNoFound
return
}
var ( var (
self *pb.DBFriend self *pb.DBFriend
err error err error
@ -35,7 +41,6 @@ func (this *apiComp) Zanreceive(session comm.IUserSession, req *pb.FriendZanrece
var ( var (
pointTotal int32 // 累计友情值 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 code = pb.ErrorCode_FriendPointLimit
return return
} }

View File

@ -5,6 +5,8 @@ import (
"math/rand" "math/rand"
"strings" "strings"
"time" "time"
"github.com/Pallinder/go-randomdata"
) )
func GenValidateCode(width int) string { func GenValidateCode(width int) string {
@ -18,3 +20,38 @@ func GenValidateCode(width int) string {
} }
return sb.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
}

View File

@ -20,3 +20,7 @@ func TestSubTime(t *testing.T) {
func TestRandom(t *testing.T) { func TestRandom(t *testing.T) {
fmt.Println(utils.GenValidateCode(6)) fmt.Println(utils.GenValidateCode(6))
} }
func TestNumber(t *testing.T) {
fmt.Println(utils.Numbers(5, 10, 5))
}