优化全局配置

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: 赵长远
url: ws://10.0.0.238:7891/gateway
- service:
sid: 3
sid: "df01"
name: 内网
url: ws://10.0.0.9:7891/gateway
- service:

View File

@ -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 = "生成类型"
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),

View File

@ -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] // 返回对象信息

View File

@ -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
}

View File

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

View File

@ -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,16 +39,24 @@ 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
@ -49,13 +66,10 @@ func (this *apiComp) Randlist(session comm.IUserSession, req *pb.FriendRandlistR
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
}

View File

@ -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()
// 不能给自己点赞
@ -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
}

View File

@ -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
}

View File

@ -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
}

View File

@ -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))
}