feat(global): 添加时间轮支持并优化玩家登录逻辑,移除冗余地图ID检查
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"reflect"
|
"reflect"
|
||||||
|
|
||||||
|
"github.com/antlabs/cronex"
|
||||||
"github.com/gogf/gf/v2/os/glog"
|
"github.com/gogf/gf/v2/os/glog"
|
||||||
"github.com/gogf/gf/v2/util/gconv"
|
"github.com/gogf/gf/v2/util/gconv"
|
||||||
"github.com/yitter/idgenerator-go/idgen"
|
"github.com/yitter/idgenerator-go/idgen"
|
||||||
@@ -17,6 +18,8 @@ var (
|
|||||||
CmdCache = &utils.SyncMap[uint32, reflect.Value]{} //命令缓存
|
CmdCache = &utils.SyncMap[uint32, reflect.Value]{} //命令缓存
|
||||||
|
|
||||||
Loger = glog.New()
|
Loger = glog.New()
|
||||||
|
Cron = cronex.New() //时间轮
|
||||||
|
|
||||||
)
|
)
|
||||||
var Filter *sensitive.Manager
|
var Filter *sensitive.Manager
|
||||||
|
|
||||||
@@ -39,6 +42,7 @@ func init() {
|
|||||||
sensitive.StoreOption{Type: sensitive.StoreMemory}, // 基于内存
|
sensitive.StoreOption{Type: sensitive.StoreMemory}, // 基于内存
|
||||||
sensitive.FilterOption{Type: sensitive.FilterDfa}, // 基于DFA算法
|
sensitive.FilterOption{Type: sensitive.FilterDfa}, // 基于DFA算法
|
||||||
)
|
)
|
||||||
|
Cron.Start()
|
||||||
|
|
||||||
// if err != nil {
|
// if err != nil {
|
||||||
// log.Fatalf("敏感词服务启动失败, err:%v", err)
|
// log.Fatalf("敏感词服务启动失败, err:%v", err)
|
||||||
|
|||||||
1
common/utils/cronex
Submodule
1
common/utils/cronex
Submodule
Submodule common/utils/cronex added at 88109676e3
7
go.work
7
go.work
@@ -1,4 +1,6 @@
|
|||||||
go 1.19
|
go 1.20
|
||||||
|
|
||||||
|
toolchain go1.21.4
|
||||||
|
|
||||||
use (
|
use (
|
||||||
./common
|
./common
|
||||||
@@ -8,13 +10,14 @@ use (
|
|||||||
./common/cool
|
./common/cool
|
||||||
./common/utils/bitset
|
./common/utils/bitset
|
||||||
./common/utils/bytearray
|
./common/utils/bytearray
|
||||||
|
./common/utils/cronex
|
||||||
./common/utils/event
|
./common/utils/event
|
||||||
./common/utils/go-jsonrpc
|
./common/utils/go-jsonrpc
|
||||||
|
./common/utils/go-sensitive-word-1.3.3
|
||||||
./common/utils/goja
|
./common/utils/goja
|
||||||
./common/utils/log
|
./common/utils/log
|
||||||
./common/utils/sturc
|
./common/utils/sturc
|
||||||
./common/utils/xml
|
./common/utils/xml
|
||||||
./common/utils/go-sensitive-word-1.3.3
|
|
||||||
./logic
|
./logic
|
||||||
./login
|
./login
|
||||||
./modules
|
./modules
|
||||||
|
|||||||
@@ -60,13 +60,6 @@ func (h *Controller) Login(data *login.InInfo, c *player.Conn) (result *login.Ou
|
|||||||
}()
|
}()
|
||||||
|
|
||||||
}
|
}
|
||||||
if t.Info.MapID > 10000 {
|
|
||||||
t.Info.MapID = 1
|
|
||||||
|
|
||||||
}
|
|
||||||
if t.IsNewPlayer() {
|
|
||||||
t.Info.MapID = 515
|
|
||||||
}
|
|
||||||
|
|
||||||
t.CompleteLogin() //通知客户端登录成功
|
t.CompleteLogin() //通知客户端登录成功
|
||||||
|
|
||||||
|
|||||||
@@ -6,6 +6,9 @@ require github.com/lunixbochs/struc v0.0.0-20241101090106-8d528fa2c543
|
|||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/BurntSushi/toml v1.4.0 // indirect
|
github.com/BurntSushi/toml v1.4.0 // indirect
|
||||||
|
github.com/antlabs/cronex v0.0.5 // indirect
|
||||||
|
github.com/antlabs/stl v0.0.2 // indirect
|
||||||
|
github.com/antlabs/timer v0.1.4 // indirect
|
||||||
github.com/butoften/array v1.0.9 // indirect
|
github.com/butoften/array v1.0.9 // indirect
|
||||||
github.com/cespare/xxhash/v2 v2.3.0 // indirect
|
github.com/cespare/xxhash/v2 v2.3.0 // indirect
|
||||||
github.com/clbanning/mxj/v2 v2.7.0 // indirect
|
github.com/clbanning/mxj/v2 v2.7.0 // indirect
|
||||||
|
|||||||
@@ -1,5 +1,11 @@
|
|||||||
github.com/BurntSushi/toml v1.4.0 h1:kuoIxZQy2WRRk1pttg9asf+WVv6tWQuBNVmK8+nqPr0=
|
github.com/BurntSushi/toml v1.4.0 h1:kuoIxZQy2WRRk1pttg9asf+WVv6tWQuBNVmK8+nqPr0=
|
||||||
github.com/BurntSushi/toml v1.4.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho=
|
github.com/BurntSushi/toml v1.4.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho=
|
||||||
|
github.com/antlabs/cronex v0.0.5 h1:n8vE2QVNc7ghd3NZpcC0OpLFtJZcNCgtDNwwA354has=
|
||||||
|
github.com/antlabs/cronex v0.0.5/go.mod h1:g0KFeHNmsKMC6zhpiHKQcdSat93uAg5iIIrmncalyn8=
|
||||||
|
github.com/antlabs/stl v0.0.2 h1:sna1AXR5yIkNE9lWhCcKbheFJSVfCa3vugnGyakI79s=
|
||||||
|
github.com/antlabs/stl v0.0.2/go.mod h1:kKrO4xrn9cfS1mJVo+/BqePZjAYMXqD0amGF2Ouq7ac=
|
||||||
|
github.com/antlabs/timer v0.1.4 h1:MHdE00MDnNfhJCmqSOdLXs35uGNwfkMwfbynxrGmQ1c=
|
||||||
|
github.com/antlabs/timer v0.1.4/go.mod h1:mpw4zlD5KVjstEyUDp43DGLWsY076Mdo4bS78NTseRE=
|
||||||
github.com/badu/bus v1.0.3 h1:MViRRyuFraixfaI2rfAqrkQao7ZilyFz6HacbmPk1aE=
|
github.com/badu/bus v1.0.3 h1:MViRRyuFraixfaI2rfAqrkQao7ZilyFz6HacbmPk1aE=
|
||||||
github.com/badu/bus v1.0.3/go.mod h1:77qc3Fi2qSUoakSR34PIWrTHB6gM2NJKceRsYUbx41Q=
|
github.com/badu/bus v1.0.3/go.mod h1:77qc3Fi2qSUoakSR34PIWrTHB6gM2NJKceRsYUbx41Q=
|
||||||
github.com/butoften/array v1.0.9 h1:/kPHAc+fHz72u5B23p2W1RzIoT2eOYvhsY0tKMvsHEc=
|
github.com/butoften/array v1.0.9 h1:/kPHAc+fHz72u5B23p2W1RzIoT2eOYvhsY0tKMvsHEc=
|
||||||
|
|||||||
@@ -120,8 +120,6 @@ func WithConn(c *Conn) PlayerOption {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
func (p *Player) GetAction() {
|
func (p *Player) GetAction() {
|
||||||
|
|
||||||
return
|
return
|
||||||
@@ -316,7 +314,6 @@ func (p *Player) Save() {
|
|||||||
return
|
return
|
||||||
|
|
||||||
}
|
}
|
||||||
//glog.Debug(context.Background(), p.Info.UserID, "断开连接")
|
|
||||||
|
|
||||||
LeaveMap(p)
|
LeaveMap(p)
|
||||||
close(p.StopChan) //停止刷怪
|
close(p.StopChan) //停止刷怪
|
||||||
@@ -335,6 +332,12 @@ func (p *Player) Save() {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 是否可以获得经验
|
||||||
|
func (p *Player) CanGetExp() bool {
|
||||||
|
ttt := p.Info.TimeLimit - p.Info.TimeToday
|
||||||
|
return (uint32(time.Now().Unix()) - uint32(p.Onlinetime)) <= ttt
|
||||||
|
}
|
||||||
|
|
||||||
// IsLoggedIn 检查是否已登录
|
// IsLoggedIn 检查是否已登录
|
||||||
func (lw *Player) IsLoggedIn() bool {
|
func (lw *Player) IsLoggedIn() bool {
|
||||||
lw.mu.Lock()
|
lw.mu.Lock()
|
||||||
@@ -389,7 +392,13 @@ func (lw *Player) WaitForLoginWithCtx(ctx context.Context) error {
|
|||||||
func (lw *Player) CompleteLogin() {
|
func (lw *Player) CompleteLogin() {
|
||||||
lw.mu.Lock()
|
lw.mu.Lock()
|
||||||
defer lw.mu.Unlock()
|
defer lw.mu.Unlock()
|
||||||
|
if lw.Info.MapID > 10000 { //如果位于基地,就重置到传送仓
|
||||||
|
lw.Info.MapID = 1
|
||||||
|
|
||||||
|
}
|
||||||
|
if lw.IsNewPlayer() { //重置新手地图
|
||||||
|
lw.Info.MapID = 515
|
||||||
|
}
|
||||||
if !lw.IsLogin {
|
if !lw.IsLogin {
|
||||||
lw.IsLogin = true
|
lw.IsLogin = true
|
||||||
close(lw.loginChan) // 关闭通道以通知所有等待者
|
close(lw.loginChan) // 关闭通道以通知所有等待者
|
||||||
|
|||||||
Reference in New Issue
Block a user