合并杂项功能服务器节点到multi服务器节点
This commit is contained in:
1 parent
64699c23d7
commit
6cca998915
42 files changed
+344
-647
No files matched your search
@@ -26,15 +26,13 @@ docker_clean:
|
||||
rm -rf ./docker/node/bin/node
|
||||
rm -rf ./docker/dispatch/bin/dispatch
|
||||
rm -rf ./docker/gate/bin/gate
|
||||
rm -rf ./docker/anticheat/bin/anticheat
|
||||
rm -rf ./docker/pathfinding/bin/pathfinding
|
||||
rm -rf ./docker/multi/bin/multi
|
||||
rm -rf ./docker/gs/bin/gs
|
||||
rm -rf ./docker/gm/bin/gm
|
||||
docker rmi flswld/node:$(VERSION)
|
||||
docker rmi flswld/dispatch:$(VERSION)
|
||||
docker rmi flswld/gate:$(VERSION)
|
||||
docker rmi flswld/anticheat:$(VERSION)
|
||||
docker rmi flswld/pathfinding:$(VERSION)
|
||||
docker rmi flswld/multi:$(VERSION)
|
||||
docker rmi flswld/gs:$(VERSION)
|
||||
docker rmi flswld/gm:$(VERSION)
|
||||
|
||||
@@ -45,8 +43,7 @@ docker_config:
|
||||
mkdir -p ./docker/node/bin && cp -rf ./cmd/node/* ./docker/node/bin/ && rm -rf ./docker/node/bin/*.go
|
||||
mkdir -p ./docker/dispatch/bin && cp -rf ./cmd/dispatch/* ./docker/dispatch/bin/ && rm -rf ./docker/dispatch/bin/*.go
|
||||
mkdir -p ./docker/gate/bin && cp -rf ./cmd/gate/* ./docker/gate/bin/ && rm -rf ./docker/gate/bin/*.go
|
||||
mkdir -p ./docker/anticheat/bin && cp -rf ./cmd/anticheat/* ./docker/anticheat/bin/ && rm -rf ./docker/anticheat/bin/*.go
|
||||
mkdir -p ./docker/pathfinding/bin && cp -rf ./cmd/pathfinding/* ./docker/pathfinding/bin/ && rm -rf ./docker/pathfinding/bin/*.go
|
||||
mkdir -p ./docker/multi/bin && cp -rf ./cmd/multi/* ./docker/multi/bin/ && rm -rf ./docker/multi/bin/*.go
|
||||
mkdir -p ./docker/gs/bin && cp -rf ./cmd/gs/* ./docker/gs/bin/ && rm -rf ./docker/gs/bin/*.go
|
||||
mkdir -p ./docker/gm/bin && cp -rf ./cmd/gm/* ./docker/gm/bin/ && rm -rf ./docker/gm/bin/*.go
|
||||
|
||||
@@ -56,15 +53,13 @@ docker_build:
|
||||
mkdir -p ./docker/node/bin && cp -rf ./bin/node ./docker/node/bin/
|
||||
mkdir -p ./docker/dispatch/bin && cp -rf ./bin/dispatch ./docker/dispatch/bin/
|
||||
mkdir -p ./docker/gate/bin && cp -rf ./bin/gate ./docker/gate/bin/
|
||||
mkdir -p ./docker/anticheat/bin && cp -rf ./bin/anticheat ./docker/anticheat/bin/
|
||||
mkdir -p ./docker/pathfinding/bin && cp -rf ./bin/pathfinding ./docker/pathfinding/bin/
|
||||
mkdir -p ./docker/multi/bin && cp -rf ./bin/multi ./docker/multi/bin/
|
||||
mkdir -p ./docker/gs/bin && cp -rf ./bin/gs ./docker/gs/bin/
|
||||
mkdir -p ./docker/gm/bin && cp -rf ./bin/gm ./docker/gm/bin/
|
||||
docker build -t flswld/node:$(VERSION) ./docker/node
|
||||
docker build -t flswld/dispatch:$(VERSION) ./docker/dispatch
|
||||
docker build -t flswld/gate:$(VERSION) ./docker/gate
|
||||
docker build -t flswld/anticheat:$(VERSION) ./docker/anticheat
|
||||
docker build -t flswld/pathfinding:$(VERSION) ./docker/pathfinding
|
||||
docker build -t flswld/multi:$(VERSION) ./docker/multi
|
||||
docker build -t flswld/gs:$(VERSION) ./docker/gs
|
||||
docker build -t flswld/gm:$(VERSION) ./docker/gm
|
||||
|
||||
|
||||
+5
-6
@@ -10,7 +10,7 @@
|
||||
|
||||
[Download version 3.2.0 from miHoYo](https://autopatchhk.yuanshen.com/client_app/download/pc_zip/20221024103618_h2e3o3zijYKEqHnQ/GenshinImpact_3.2.0.zip)
|
||||
|
||||
#### You need to use an https proxy and a patch to use it. Grasscutter is a good example.
|
||||
#### You need to use a https proxy and a patch to use it. Grasscutter is a good example.
|
||||
|
||||
#### You can use a newer patch to avoid using https proxies. It supports custom keys and multiple servers. Special thanks to [Jx2f/mhypbase](https://github.com/Jx2f/mhypbase)
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
|
||||
* Native high-availability cluster architecture. Crashes on any node servers won't affect the whole system. So it is
|
||||
highly extendable
|
||||
* Player-level non-status game server. Non-lock single thread structure. Easy to develope. And fully-featured player
|
||||
* Player-level non-status game server. Non-lock single thread structure. Easy to develop. And fully-featured player
|
||||
data exchanger(`Memory<->Cache<->Database`), say goodbye to
|
||||
* synchronization-blocked database access
|
||||
* Grand new cross-server player migration
|
||||
@@ -48,7 +48,7 @@ make dev_tool
|
||||
```shell
|
||||
make gen_natsrpc # Generate natsrpc protocol
|
||||
make gen_proto # Generate client protocol
|
||||
make gen_client_proto # Generate client proxy protocol(not very necessary, for further informations: gate/client_proto/README.md)
|
||||
make gen_client_proto # Generate client proxy protocol(not very necessary, for further information: gate/client_proto/README.md)
|
||||
```
|
||||
|
||||
* Compile
|
||||
@@ -78,10 +78,9 @@ docker-compose up -d # Launch server
|
||||
* `node` Node server (Single node, with status)
|
||||
* `dispatch` Login server (Multi nodes, without status)
|
||||
* `gate` Gateway server (Multi nodes, with status)
|
||||
* `anticheat` Anti-cheat server (Multi nodes, with status **STILL UNDER CONSTRUCTION**)
|
||||
* `pathfinding` Path-finding server (Multi nodes, without status **STILL UNDER CONSTRUCTION**)
|
||||
* `multi` Multi-function server (Multi nodes, with status **STILL UNDER CONSTRUCTION**)
|
||||
* `gs` Game server (Multi nodes, with status)
|
||||
* `gm` Game menagement server (Single node, without status)
|
||||
* `gm` Game management server (Single node, without status)
|
||||
|
||||
#### Misc
|
||||
|
||||
|
||||
@@ -76,8 +76,7 @@ docker-compose up -d # 启动服务器
|
||||
* node 节点服务器 (仅单节点 有状态)
|
||||
* dispatch 登录服务器 (可多节点 无状态)
|
||||
* gate 网关服务器 (可多节点 有状态)
|
||||
* anticheat 反作弊服务器 (可多节点 有状态 尚不完善非必要启动)
|
||||
* pathfinding 寻路服务器 (可多节点 无状态 尚不完善非必要启动)
|
||||
* multi 多功能服务器 (可多节点 有状态 尚不完善非必要启动)
|
||||
* gs 游戏服务器 (可多节点 有状态)
|
||||
* gm 游戏管理服务器 (仅单节点 无状态)
|
||||
|
||||
|
||||
@@ -1,92 +0,0 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"context"
|
||||
_ "net/http/pprof"
|
||||
"os"
|
||||
"os/signal"
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
"hk4e/anticheat/handle"
|
||||
"hk4e/common/config"
|
||||
"hk4e/common/mq"
|
||||
"hk4e/common/rpc"
|
||||
"hk4e/gdconf"
|
||||
"hk4e/node/api"
|
||||
"hk4e/pkg/logger"
|
||||
)
|
||||
|
||||
var APPID string
|
||||
var APPVERSION string
|
||||
|
||||
func Run(ctx context.Context, configFile string) error {
|
||||
config.InitConfig(configFile)
|
||||
|
||||
// natsrpc client
|
||||
discoveryClient, err := rpc.NewDiscoveryClient()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// 注册到节点服务器
|
||||
rsp, err := discoveryClient.RegisterServer(context.TODO(), &api.RegisterServerReq{
|
||||
ServerType: api.ANTICHEAT,
|
||||
AppVersion: APPVERSION,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
APPID = rsp.GetAppId()
|
||||
go func() {
|
||||
ticker := time.NewTicker(time.Second * 15)
|
||||
for {
|
||||
<-ticker.C
|
||||
_, err := discoveryClient.KeepaliveServer(context.TODO(), &api.KeepaliveServerReq{
|
||||
ServerType: api.ANTICHEAT,
|
||||
AppId: APPID,
|
||||
})
|
||||
if err != nil {
|
||||
logger.Error("keepalive error: %v", err)
|
||||
}
|
||||
}
|
||||
}()
|
||||
defer func() {
|
||||
_, _ = discoveryClient.CancelServer(context.TODO(), &api.CancelServerReq{
|
||||
ServerType: api.ANTICHEAT,
|
||||
AppId: APPID,
|
||||
})
|
||||
}()
|
||||
|
||||
logger.InitLogger("anticheat_" + APPID)
|
||||
logger.Warn("anticheat start, appid: %v", APPID)
|
||||
defer func() {
|
||||
logger.CloseLogger()
|
||||
}()
|
||||
|
||||
gdconf.InitGameDataConfig()
|
||||
|
||||
messageQueue := mq.NewMessageQueue(api.ANTICHEAT, APPID, discoveryClient)
|
||||
defer messageQueue.Close()
|
||||
|
||||
handle.NewHandle(messageQueue)
|
||||
|
||||
c := make(chan os.Signal, 1)
|
||||
signal.Notify(c, syscall.SIGHUP, syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT)
|
||||
for {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return nil
|
||||
case s := <-c:
|
||||
logger.Warn("get a signal %s", s.String())
|
||||
switch s {
|
||||
case syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT:
|
||||
logger.Warn("anticheat exit, appid: %v", APPID)
|
||||
return nil
|
||||
case syscall.SIGHUP:
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+1
-2
@@ -25,9 +25,8 @@ func main() {
|
||||
NodeCmd(),
|
||||
DispatchCmd(),
|
||||
GateCmd(),
|
||||
AnticheatCmd(),
|
||||
PathfindingCmd(),
|
||||
GSCmd(),
|
||||
MultiCmd(),
|
||||
GMCmd(),
|
||||
)
|
||||
|
||||
|
||||
@@ -3,17 +3,17 @@ package main
|
||||
import (
|
||||
"context"
|
||||
|
||||
"hk4e/anticheat/app"
|
||||
"hk4e/multi/app"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
func AnticheatCmd() *cobra.Command {
|
||||
func MultiCmd() *cobra.Command {
|
||||
var cfg string
|
||||
app.APPVERSION = VERSION
|
||||
c := &cobra.Command{
|
||||
Use: "anticheat",
|
||||
Short: "anticheat server",
|
||||
Use: "multi",
|
||||
Short: "multi server",
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
return app.Run(context.Background(), cfg)
|
||||
},
|
||||
@@ -1,23 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"hk4e/pathfinding/app"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
func PathfindingCmd() *cobra.Command {
|
||||
var cfg string
|
||||
app.APPVERSION = VERSION
|
||||
c := &cobra.Command{
|
||||
Use: "pathfinding",
|
||||
Short: "pathfinding server",
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
return app.Run(context.Background(), cfg)
|
||||
},
|
||||
}
|
||||
c.Flags().StringVar(&cfg, "config", "application.toml", "config file")
|
||||
return c
|
||||
}
|
||||
File renamed without changes.
@@ -7,7 +7,7 @@ import (
|
||||
_ "net/http/pprof"
|
||||
"os"
|
||||
|
||||
"hk4e/anticheat/app"
|
||||
"hk4e/multi/app"
|
||||
"hk4e/pkg/statsviz_serve"
|
||||
)
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
[logger]
|
||||
level = "DEBUG"
|
||||
mode = "CONSOLE"
|
||||
track = true
|
||||
max_size = 10485760
|
||||
|
||||
[mq]
|
||||
nats_url = "nats://nats:4222"
|
||||
@@ -1,31 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
"fmt"
|
||||
_ "net/http/pprof"
|
||||
"os"
|
||||
|
||||
"hk4e/pathfinding/app"
|
||||
"hk4e/pkg/statsviz_serve"
|
||||
)
|
||||
|
||||
var (
|
||||
config = flag.String("config", "application.toml", "config file")
|
||||
)
|
||||
|
||||
var VERSION = "UNKNOWN"
|
||||
|
||||
func main() {
|
||||
flag.Parse()
|
||||
go func() {
|
||||
_ = statsviz_serve.Serve("0.0.0.0:6789")
|
||||
}()
|
||||
app.APPVERSION = VERSION
|
||||
err := app.Run(context.TODO(), *config)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
+7
-10
@@ -67,7 +67,7 @@ func NewMessageQueue(serverType string, appId string, discoveryClient *rpc.Disco
|
||||
r.discoveryClient = discoveryClient
|
||||
if serverType == api.GATE {
|
||||
go r.runGateTcpMqServer()
|
||||
} else if serverType == api.GS || serverType == api.ANTICHEAT || serverType == api.PATHFINDING || serverType == api.ROBOT {
|
||||
} else if serverType == api.GS || serverType == api.MULTI || serverType == api.ROBOT {
|
||||
go r.runGateTcpMqClient()
|
||||
}
|
||||
go r.natsMsgRecvHandler()
|
||||
@@ -170,11 +170,10 @@ func (m *MessageQueue) parseNetMsg(rawData []byte) *NetMsg {
|
||||
func (m *MessageQueue) sendHandler() {
|
||||
// 网关tcp连接消息收发快速通道 key1:服务器类型 key2:服务器appid value:连接实例
|
||||
gateTcpMqInstMap := map[string]map[string]*GateTcpMqInst{
|
||||
api.GATE: make(map[string]*GateTcpMqInst),
|
||||
api.GS: make(map[string]*GateTcpMqInst),
|
||||
api.ANTICHEAT: make(map[string]*GateTcpMqInst),
|
||||
api.PATHFINDING: make(map[string]*GateTcpMqInst),
|
||||
api.ROBOT: make(map[string]*GateTcpMqInst),
|
||||
api.GATE: make(map[string]*GateTcpMqInst),
|
||||
api.GS: make(map[string]*GateTcpMqInst),
|
||||
api.MULTI: make(map[string]*GateTcpMqInst),
|
||||
api.ROBOT: make(map[string]*GateTcpMqInst),
|
||||
}
|
||||
for {
|
||||
select {
|
||||
@@ -320,10 +319,8 @@ func (m *MessageQueue) gateTcpMqHandshake(conn *net.TCPConn) {
|
||||
inst.serverType = api.GATE
|
||||
case api.GS:
|
||||
inst.serverType = api.GS
|
||||
case api.ANTICHEAT:
|
||||
inst.serverType = api.ANTICHEAT
|
||||
case api.PATHFINDING:
|
||||
inst.serverType = api.PATHFINDING
|
||||
case api.MULTI:
|
||||
inst.serverType = api.MULTI
|
||||
case api.ROBOT:
|
||||
inst.serverType = api.ROBOT
|
||||
default:
|
||||
|
||||
+10
-10
@@ -63,16 +63,16 @@ const (
|
||||
)
|
||||
|
||||
type ServerMsg struct {
|
||||
AnticheatServerAppId string
|
||||
UserId uint32
|
||||
IsOnline bool
|
||||
GameServerAppId string
|
||||
JoinHostUserId uint32
|
||||
PlayerMpInfo *PlayerMpInfo
|
||||
ChatMsgInfo *ChatMsgInfo
|
||||
AddFriendInfo *AddFriendInfo
|
||||
ForwardDispatchInfo *ForwardDispatchInfo
|
||||
AppVersion string
|
||||
MultiServerAppId string
|
||||
UserId uint32
|
||||
IsOnline bool
|
||||
GameServerAppId string
|
||||
JoinHostUserId uint32
|
||||
PlayerMpInfo *PlayerMpInfo
|
||||
ChatMsgInfo *ChatMsgInfo
|
||||
AddFriendInfo *AddFriendInfo
|
||||
ForwardDispatchInfo *ForwardDispatchInfo
|
||||
AppVersion string
|
||||
}
|
||||
|
||||
type OriginInfo struct {
|
||||
|
||||
+3
-13
@@ -35,19 +35,9 @@ func (m *MessageQueue) SendToGs(appId string, netMsg *NetMsg) {
|
||||
m.netMsgInput <- netMsg
|
||||
}
|
||||
|
||||
func (m *MessageQueue) SendToAnticheat(appId string, netMsg *NetMsg) {
|
||||
netMsg.Topic = m.getTopic(api.ANTICHEAT, appId)
|
||||
netMsg.ServerType = api.ANTICHEAT
|
||||
netMsg.AppId = appId
|
||||
originServerType, originServerAppId := m.getOriginServer()
|
||||
netMsg.OriginServerType = originServerType
|
||||
netMsg.OriginServerAppId = originServerAppId
|
||||
m.netMsgInput <- netMsg
|
||||
}
|
||||
|
||||
func (m *MessageQueue) SendToPathfinding(appId string, netMsg *NetMsg) {
|
||||
netMsg.Topic = m.getTopic(api.PATHFINDING, appId)
|
||||
netMsg.ServerType = api.PATHFINDING
|
||||
func (m *MessageQueue) SendToMulti(appId string, netMsg *NetMsg) {
|
||||
netMsg.Topic = m.getTopic(api.MULTI, appId)
|
||||
netMsg.ServerType = api.MULTI
|
||||
netMsg.AppId = appId
|
||||
originServerType, originServerAppId := m.getOriginServer()
|
||||
netMsg.OriginServerType = originServerType
|
||||
|
||||
+26
-47
@@ -68,49 +68,6 @@ services:
|
||||
limits:
|
||||
cpus: '8.00'
|
||||
memory: 8192M
|
||||
anticheat_services:
|
||||
restart: always
|
||||
image: flswld/anticheat:1.0.0
|
||||
container_name: anticheat
|
||||
ports:
|
||||
- "5678:5678/tcp"
|
||||
environment:
|
||||
TZ: Asia/Shanghai
|
||||
GOLANG_PROTOBUF_REGISTRATION_CONFLICT: ignore
|
||||
volumes:
|
||||
- /etc/localtime:/etc/localtime
|
||||
- /etc/timezone:/etc/timezone
|
||||
- /usr/share/zoneinfo:/usr/share/zoneinfo
|
||||
- ./anticheat/bin/application.toml:/anticheat/application.toml
|
||||
- ../gdconf/game_data_config:/anticheat/game_data_config
|
||||
depends_on:
|
||||
- gate_320_services
|
||||
deploy:
|
||||
resources:
|
||||
limits:
|
||||
cpus: '1.00'
|
||||
memory: 512M
|
||||
pathfinding_services:
|
||||
restart: always
|
||||
image: flswld/pathfinding:1.0.0
|
||||
container_name: pathfinding
|
||||
ports:
|
||||
- "6789:6789/tcp"
|
||||
environment:
|
||||
TZ: Asia/Shanghai
|
||||
GOLANG_PROTOBUF_REGISTRATION_CONFLICT: ignore
|
||||
volumes:
|
||||
- /etc/localtime:/etc/localtime
|
||||
- /etc/timezone:/etc/timezone
|
||||
- /usr/share/zoneinfo:/usr/share/zoneinfo
|
||||
- ./pathfinding/bin/application.toml:/pathfinding/application.toml
|
||||
depends_on:
|
||||
- anticheat_services
|
||||
deploy:
|
||||
resources:
|
||||
limits:
|
||||
cpus: '1.00'
|
||||
memory: 512M
|
||||
gs_1_services:
|
||||
restart: always
|
||||
image: flswld/gs:1.0.0
|
||||
@@ -127,7 +84,7 @@ services:
|
||||
- ./gs/bin/application.toml:/gs/application.toml
|
||||
- ../gdconf/game_data_config:/gs/game_data_config
|
||||
depends_on:
|
||||
- pathfinding_services
|
||||
- gate_320_services
|
||||
deploy:
|
||||
resources:
|
||||
limits:
|
||||
@@ -149,7 +106,7 @@ services:
|
||||
- ./gs/bin/application.toml:/gs/application.toml
|
||||
- ../gdconf/game_data_config:/gs/game_data_config
|
||||
depends_on:
|
||||
- gs_1_services
|
||||
- gate_320_services
|
||||
deploy:
|
||||
resources:
|
||||
limits:
|
||||
@@ -171,12 +128,34 @@ services:
|
||||
- ./gs/bin/application.toml:/gs/application.toml
|
||||
- ../gdconf/game_data_config:/gs/game_data_config
|
||||
depends_on:
|
||||
- gs_2_services
|
||||
- gate_320_services
|
||||
deploy:
|
||||
resources:
|
||||
limits:
|
||||
cpus: '8.00'
|
||||
memory: 8192M
|
||||
multi_services:
|
||||
restart: always
|
||||
image: flswld/multi:1.0.0
|
||||
container_name: multi
|
||||
ports:
|
||||
- "5678:5678/tcp"
|
||||
environment:
|
||||
TZ: Asia/Shanghai
|
||||
GOLANG_PROTOBUF_REGISTRATION_CONFLICT: ignore
|
||||
volumes:
|
||||
- /etc/localtime:/etc/localtime
|
||||
- /etc/timezone:/etc/timezone
|
||||
- /usr/share/zoneinfo:/usr/share/zoneinfo
|
||||
- ./multi/bin/application.toml:/multi/application.toml
|
||||
- ../gdconf/game_data_config:/multi/game_data_config
|
||||
depends_on:
|
||||
- gate_320_services
|
||||
deploy:
|
||||
resources:
|
||||
limits:
|
||||
cpus: '4.00'
|
||||
memory: 4096M
|
||||
gm_services:
|
||||
restart: always
|
||||
image: flswld/gm:1.0.0
|
||||
@@ -193,7 +172,7 @@ services:
|
||||
- /usr/share/zoneinfo:/usr/share/zoneinfo
|
||||
- ./gm/bin/application.toml:/gm/application.toml
|
||||
depends_on:
|
||||
- gs_3_services
|
||||
- multi_services
|
||||
deploy:
|
||||
resources:
|
||||
limits:
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
FROM ubuntu:18.04
|
||||
|
||||
WORKDIR /anticheat
|
||||
COPY ./bin/anticheat ./anticheat
|
||||
RUN chmod +x ./anticheat
|
||||
|
||||
ENTRYPOINT ["./anticheat"]
|
||||
@@ -0,0 +1,7 @@
|
||||
FROM ubuntu:18.04
|
||||
|
||||
WORKDIR /multi
|
||||
COPY ./bin/multi ./multi
|
||||
RUN chmod +x ./multi
|
||||
|
||||
ENTRYPOINT ["./multi"]
|
||||
@@ -1,7 +0,0 @@
|
||||
FROM ubuntu:18.04
|
||||
|
||||
WORKDIR /pathfinding
|
||||
COPY ./bin/pathfinding ./pathfinding
|
||||
RUN chmod +x ./pathfinding
|
||||
|
||||
ENTRYPOINT ["./pathfinding"]
|
||||
@@ -51,17 +51,16 @@ type KcpEvent struct {
|
||||
}
|
||||
|
||||
type KcpConnManager struct {
|
||||
kcpListener *kcp.Listener
|
||||
db *dao.Dao
|
||||
discoveryClient *rpc.DiscoveryClient // 节点服务器rpc客户端
|
||||
messageQueue *mq.MessageQueue // 消息队列
|
||||
globalGsOnlineMap map[uint32]string // 全服玩家在线表
|
||||
globalGsOnlineMapLock sync.RWMutex
|
||||
minLoadGsServerAppId string
|
||||
minLoadAnticheatServerAppId string
|
||||
minLoadPathfindingServerAppId string
|
||||
stopServerInfo *api.StopServerInfo
|
||||
whiteList *api.GetWhiteListRsp
|
||||
kcpListener *kcp.Listener
|
||||
db *dao.Dao
|
||||
discoveryClient *rpc.DiscoveryClient // 节点服务器rpc客户端
|
||||
messageQueue *mq.MessageQueue // 消息队列
|
||||
globalGsOnlineMap map[uint32]string // 全服玩家在线表
|
||||
globalGsOnlineMapLock sync.RWMutex
|
||||
minLoadGsServerAppId string
|
||||
minLoadMultiServerAppId string
|
||||
stopServerInfo *api.StopServerInfo
|
||||
whiteList *api.GetWhiteListRsp
|
||||
// 会话
|
||||
sessionIdCounter uint32
|
||||
sessionMap map[uint32]*Session
|
||||
@@ -89,8 +88,7 @@ func NewKcpConnManager(db *dao.Dao, messageQueue *mq.MessageQueue, discovery *rp
|
||||
r.messageQueue = messageQueue
|
||||
r.globalGsOnlineMap = make(map[uint32]string)
|
||||
r.minLoadGsServerAppId = ""
|
||||
r.minLoadAnticheatServerAppId = ""
|
||||
r.minLoadPathfindingServerAppId = ""
|
||||
r.minLoadMultiServerAppId = ""
|
||||
r.stopServerInfo = nil
|
||||
r.whiteList = nil
|
||||
r.sessionIdCounter = 0
|
||||
@@ -260,23 +258,22 @@ func (k *KcpConnManager) acceptHandle(tcpMode bool, kcpListener *kcp.Listener, t
|
||||
logger.Info("[ACCEPT] client connect, tcpMode: %v, sessionId: %v, conv: %v, addr: %v",
|
||||
tcpMode, sessionId, conn.GetConv(), conn.RemoteAddr())
|
||||
session := &Session{
|
||||
sessionId: sessionId,
|
||||
conn: conn,
|
||||
connState: ConnEst,
|
||||
userId: 0,
|
||||
sendChan: make(chan *ProtoMsg, SessionSendChanLen),
|
||||
seed: 0,
|
||||
xorKey: k.dispatchKey,
|
||||
changeXorKeyFin: false,
|
||||
gsServerAppId: "",
|
||||
anticheatServerAppId: "",
|
||||
pathfindingServerAppId: "",
|
||||
robotServerAppId: "",
|
||||
useMagicSeed: false,
|
||||
keyId: 0,
|
||||
clientRandKey: "",
|
||||
tcpRtt: 0,
|
||||
tcpRttLastSendTime: 0,
|
||||
sessionId: sessionId,
|
||||
conn: conn,
|
||||
connState: ConnEst,
|
||||
userId: 0,
|
||||
sendChan: make(chan *ProtoMsg, SessionSendChanLen),
|
||||
seed: 0,
|
||||
xorKey: k.dispatchKey,
|
||||
changeXorKeyFin: false,
|
||||
gsServerAppId: "",
|
||||
multiServerAppId: "",
|
||||
robotServerAppId: "",
|
||||
useMagicSeed: false,
|
||||
keyId: 0,
|
||||
clientRandKey: "",
|
||||
tcpRtt: 0,
|
||||
tcpRttLastSendTime: 0,
|
||||
}
|
||||
if config.GetConfig().Hk4e.ForwardModeEnable {
|
||||
robotServerAppId, err := k.discoveryClient.GetServerAppId(context.TODO(), &api.GetServerAppIdReq{
|
||||
@@ -353,23 +350,22 @@ func (k *KcpConnManager) kcpEnetHandle(listener *kcp.Listener) {
|
||||
|
||||
// Session 连接会话结构 只允许定义并发安全或者简单的基础数据结构
|
||||
type Session struct {
|
||||
sessionId uint32
|
||||
conn *Conn
|
||||
connState uint8
|
||||
userId uint32
|
||||
sendChan chan *ProtoMsg
|
||||
seed uint64
|
||||
xorKey []byte
|
||||
changeXorKeyFin bool
|
||||
gsServerAppId string
|
||||
anticheatServerAppId string
|
||||
pathfindingServerAppId string
|
||||
robotServerAppId string
|
||||
useMagicSeed bool
|
||||
keyId uint32
|
||||
clientRandKey string
|
||||
tcpRtt uint32
|
||||
tcpRttLastSendTime int64
|
||||
sessionId uint32
|
||||
conn *Conn
|
||||
connState uint8
|
||||
userId uint32
|
||||
sendChan chan *ProtoMsg
|
||||
seed uint64
|
||||
xorKey []byte
|
||||
changeXorKeyFin bool
|
||||
gsServerAppId string
|
||||
multiServerAppId string
|
||||
robotServerAppId string
|
||||
useMagicSeed bool
|
||||
keyId uint32
|
||||
clientRandKey string
|
||||
tcpRtt uint32
|
||||
tcpRttLastSendTime int64
|
||||
}
|
||||
|
||||
// 接收协程
|
||||
@@ -706,21 +702,14 @@ func (k *KcpConnManager) syncMinLoadServerAppid() {
|
||||
} else {
|
||||
k.minLoadGsServerAppId = gsServerAppId.AppId
|
||||
}
|
||||
anticheatServerAppId, err := k.discoveryClient.GetServerAppId(context.TODO(), &api.GetServerAppIdReq{
|
||||
ServerType: api.ANTICHEAT,
|
||||
|
||||
multiServerAppId, err := k.discoveryClient.GetServerAppId(context.TODO(), &api.GetServerAppIdReq{
|
||||
ServerType: api.MULTI,
|
||||
})
|
||||
if err != nil {
|
||||
k.minLoadAnticheatServerAppId = ""
|
||||
k.minLoadMultiServerAppId = ""
|
||||
} else {
|
||||
k.minLoadAnticheatServerAppId = anticheatServerAppId.AppId
|
||||
}
|
||||
pathfindingServerAppId, err := k.discoveryClient.GetServerAppId(context.TODO(), &api.GetServerAppIdReq{
|
||||
ServerType: api.PATHFINDING,
|
||||
})
|
||||
if err != nil {
|
||||
k.minLoadPathfindingServerAppId = ""
|
||||
} else {
|
||||
k.minLoadPathfindingServerAppId = pathfindingServerAppId.AppId
|
||||
k.minLoadMultiServerAppId = multiServerAppId.AppId
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+8
-22
@@ -121,23 +121,11 @@ func (k *KcpConnManager) forwardClientMsgToServerHandle(protoMsg *ProtoMsg, sess
|
||||
}
|
||||
k.serverCmdProtoMap.PutProtoObjCache(protoMsg.CmdId, protoMsg.PayloadMessage)
|
||||
gameMsg.PayloadMessageData = payloadMessageData
|
||||
// 转发到寻路服务器
|
||||
if session.pathfindingServerAppId != "" {
|
||||
// 转发到寻路服务
|
||||
if session.multiServerAppId != "" {
|
||||
if protoMsg.CmdId == cmd.QueryPathReq ||
|
||||
protoMsg.CmdId == cmd.ObstacleModifyNotify {
|
||||
k.messageQueue.SendToPathfinding(session.pathfindingServerAppId, &mq.NetMsg{
|
||||
MsgType: mq.MsgTypeGame,
|
||||
EventId: mq.NormalMsg,
|
||||
GameMsg: gameMsg,
|
||||
})
|
||||
return
|
||||
}
|
||||
}
|
||||
// 转发到反作弊服务器
|
||||
if session.anticheatServerAppId != "" {
|
||||
if protoMsg.CmdId == cmd.CombatInvocationsNotify ||
|
||||
protoMsg.CmdId == cmd.ToTheMoonEnterSceneReq {
|
||||
k.messageQueue.SendToAnticheat(session.anticheatServerAppId, &mq.NetMsg{
|
||||
k.messageQueue.SendToMulti(session.multiServerAppId, &mq.NetMsg{
|
||||
MsgType: mq.MsgTypeGame,
|
||||
EventId: mq.NormalMsg,
|
||||
GameMsg: gameMsg,
|
||||
@@ -244,8 +232,8 @@ func (k *KcpConnManager) gameMsgHandle(
|
||||
session.connState = ConnActive
|
||||
// 通知GS玩家各个服务器的appid
|
||||
serverMsg := &mq.ServerMsg{
|
||||
UserId: session.userId,
|
||||
AnticheatServerAppId: session.anticheatServerAppId,
|
||||
UserId: session.userId,
|
||||
MultiServerAppId: session.multiServerAppId,
|
||||
}
|
||||
k.messageQueue.SendToGs(session.gsServerAppId, &mq.NetMsg{
|
||||
MsgType: mq.MsgTypeServer,
|
||||
@@ -293,7 +281,7 @@ func (k *KcpConnManager) serverMsgHandle(
|
||||
return
|
||||
}
|
||||
session.gsServerAppId = serverMsg.GameServerAppId
|
||||
session.anticheatServerAppId = ""
|
||||
session.multiServerAppId = ""
|
||||
// 网关代发登录请求到新的GS
|
||||
gameMsg := &mq.GameMsg{
|
||||
UserId: serverMsg.UserId,
|
||||
@@ -603,11 +591,9 @@ func (k *KcpConnManager) doGateLogin(req *proto.GetPlayerTokenReq, session *Sess
|
||||
return k.loginFailRsp(0, proto.Retcode_RET_SVR_ERROR, false, 0)
|
||||
}
|
||||
session.gsServerAppId = k.minLoadGsServerAppId
|
||||
session.anticheatServerAppId = k.minLoadAnticheatServerAppId
|
||||
session.pathfindingServerAppId = k.minLoadPathfindingServerAppId
|
||||
session.multiServerAppId = k.minLoadMultiServerAppId
|
||||
logger.Debug("session gs appid: %v, uid: %v", session.gsServerAppId, uid)
|
||||
logger.Debug("session anticheat appid: %v, uid: %v", session.anticheatServerAppId, uid)
|
||||
logger.Debug("session pathfinding appid: %v, uid: %v", session.pathfindingServerAppId, uid)
|
||||
logger.Debug("session multi appid: %v, uid: %v", session.multiServerAppId, uid)
|
||||
// 构造响应
|
||||
rsp := k.buildGateLoginRsp(uid, req.AccountUid, req.AccountToken, clientIp)
|
||||
// 密钥交换
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
WorldGadgetId,GadgetId,X,Y,Z,Probability,Type,Param
|
||||
int32,int32,float32,float32,float32,int32,int32,[]int32
|
||||
ID,物件ID,X坐标,Y坐标,Z坐标,概率,类型,参数
|
||||
1,70690013,835.0,480.0,1425.0,100,0,0
|
||||
2,70690013,835.0,536.0,1425.0,100,0,0
|
||||
1,70690013,835.001,480.001,1425.001,100,0,0
|
||||
2,70690013,835.001,536.001,1425.001,100,0,0
|
||||
3,70520005,835.714,550.834,1429.667,100,1,500
|
||||
4,70520009,500.001,202.101,-500.001,80,1,50
|
||||
|
@@ -394,6 +394,10 @@ func (g *GMCmd) GMCreateMonster(userId uint32, monsterId uint32, posX, posY, pos
|
||||
logger.Error("scene is nil, sceneId: %v, uid: %v", player.SceneId, player.PlayerId)
|
||||
return
|
||||
}
|
||||
if count > 100 {
|
||||
logger.Error("monster count too large, uid: %v", userId)
|
||||
return
|
||||
}
|
||||
for i := 0; i < int(count); i++ {
|
||||
GAME.CreateMonster(player, &model.Vector{
|
||||
X: posX,
|
||||
@@ -410,6 +414,10 @@ func (g *GMCmd) GMCreateGadget(userId uint32, gadgetId uint32, count uint32) {
|
||||
logger.Error("player is nil, uid: %v", userId)
|
||||
return
|
||||
}
|
||||
if count > 100 {
|
||||
logger.Error("gadget count too large, uid: %v", userId)
|
||||
return
|
||||
}
|
||||
for i := 0; i < int(count); i++ {
|
||||
GAME.CreateGadget(player, nil, gadgetId, nil)
|
||||
}
|
||||
@@ -612,9 +620,13 @@ func (g *GMCmd) AiWorldAoiDebug(v bool) {
|
||||
}
|
||||
aiWorldAoi := aiWorld.GetAiWorldAoi()
|
||||
gridMap := aiWorldAoi.Debug()
|
||||
logger.Debug("total grid num: %v", len(gridMap))
|
||||
for _, grid := range gridMap {
|
||||
logger.Debug("================================================== GRID gid:%v ==================================================", grid.GetGid())
|
||||
objectMap := grid.GetObjectList()
|
||||
if len(objectMap) == 0 {
|
||||
continue
|
||||
}
|
||||
logger.Debug("================================================== GRID gid:%v ==================================================", grid.GetGid())
|
||||
for objectId, object := range objectMap {
|
||||
wa := object.(*WorldAvatar)
|
||||
logger.Debug("uid: %v, wa.uid: %v, wa.avatarId: %v, wa.entityId: %v", objectId, wa.uid, wa.avatarId, wa.avatarEntityId)
|
||||
|
||||
@@ -24,6 +24,7 @@ type RigidBody struct {
|
||||
avatarEntityId uint32 // 子弹发射者角色实体id
|
||||
hitAvatarEntityId uint32 // 子弹命中的角色实体id
|
||||
sceneId uint32 // 子弹所在场景id
|
||||
venti bool // 子弹是否为满蓄力箭
|
||||
position *alg.Vector3 // 坐标
|
||||
velocity *alg.Vector3 // 速度
|
||||
}
|
||||
@@ -203,7 +204,7 @@ func (p *PhysicsEngine) IsRigidBody(entityId uint32) bool {
|
||||
return exist
|
||||
}
|
||||
|
||||
func (p *PhysicsEngine) CreateRigidBody(entityId, avatarEntityId, sceneId uint32, x, y, z float32, pitchAngle, yawAngle float32) {
|
||||
func (p *PhysicsEngine) CreateRigidBody(entityId, avatarEntityId, sceneId uint32, venti bool, x, y, z float32, pitchAngle, yawAngle float32) {
|
||||
pitchAngle += p.pitchAngleOffset
|
||||
vy := math.Sin(float64(pitchAngle)/360.0*2*math.Pi) * float64(p.initSpeed)
|
||||
vxz := math.Cos(float64(pitchAngle)/360.0*2*math.Pi) * float64(p.initSpeed)
|
||||
@@ -213,6 +214,7 @@ func (p *PhysicsEngine) CreateRigidBody(entityId, avatarEntityId, sceneId uint32
|
||||
entityId: entityId,
|
||||
avatarEntityId: avatarEntityId,
|
||||
sceneId: sceneId,
|
||||
venti: venti,
|
||||
position: &alg.Vector3{X: x, Y: y, Z: z},
|
||||
velocity: &alg.Vector3{X: float32(vx), Y: float32(vy), Z: float32(vz)},
|
||||
}
|
||||
|
||||
@@ -130,17 +130,8 @@ type PluginEventInfo struct {
|
||||
type PluginGlobalTick uint8
|
||||
|
||||
const (
|
||||
PluginGlobalTick50MilliSecond = PluginGlobalTick(iota)
|
||||
PluginGlobalTick100MilliSecond
|
||||
PluginGlobalTick200MilliSecond
|
||||
PluginGlobalTickSecond
|
||||
PluginGlobalTick5Second
|
||||
PluginGlobalTick10Second
|
||||
PluginGlobalTickMinute
|
||||
PluginGlobalTickHour
|
||||
PluginGlobalTickHourChange
|
||||
PluginGlobalTickDayChange
|
||||
PluginGlobalTickMonthChange
|
||||
PluginGlobalTickSecond = PluginGlobalTick(iota)
|
||||
PluginGlobalTickMinuteChange
|
||||
)
|
||||
|
||||
// PluginUserTimerFunc 用户timer处理函数
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
"math"
|
||||
"time"
|
||||
|
||||
"hk4e/common/constant"
|
||||
"hk4e/gdconf"
|
||||
@@ -78,7 +79,7 @@ func (p *PluginPubg) OnEnable() {
|
||||
p.ListenEvent(PluginEventIdPostEnterScene, PluginEventPriorityNormal, p.EventPostEnterScene)
|
||||
// 添加全局定时器
|
||||
p.AddGlobalTick(PluginGlobalTickSecond, p.GlobalTickPubg)
|
||||
p.AddGlobalTick(PluginGlobalTickHourChange, p.GlobalTickHourChange)
|
||||
p.AddGlobalTick(PluginGlobalTickMinuteChange, p.GlobalTickMinuteChange)
|
||||
// 注册命令
|
||||
p.RegCommandController(p.NewPubgCommandController())
|
||||
}
|
||||
@@ -237,9 +238,13 @@ func (p *PluginPubg) GlobalTickPubg() {
|
||||
}
|
||||
}
|
||||
|
||||
// GlobalTickHourChange 每小时开启pubg游戏
|
||||
func (p *PluginPubg) GlobalTickHourChange() {
|
||||
p.StartPubg()
|
||||
// GlobalTickMinuteChange 定时开启pubg游戏
|
||||
func (p *PluginPubg) GlobalTickMinuteChange() {
|
||||
minute := time.Now().Minute()
|
||||
startMinute := GAME.GetGsId() % 6 * 10
|
||||
if uint32(minute) == startMinute {
|
||||
p.StartPubg()
|
||||
}
|
||||
}
|
||||
|
||||
/************************************************** 用户定时器 **************************************************/
|
||||
|
||||
@@ -199,7 +199,7 @@ func (r *RouteManager) RouteHandle(netMsg *mq.NetMsg) {
|
||||
logger.Debug("remote user online state change, uid: %v, online: %v", serverMsg.UserId, serverMsg.IsOnline)
|
||||
USER_MANAGER.SetRemoteUserOnlineState(serverMsg.UserId, serverMsg.IsOnline, netMsg.OriginServerAppId)
|
||||
case mq.ServerAppidBindNotify:
|
||||
GAME.ServerAppidBindNotify(serverMsg.UserId, serverMsg.AnticheatServerAppId)
|
||||
GAME.ServerAppidBindNotify(serverMsg.UserId, serverMsg.MultiServerAppId)
|
||||
case mq.ServerPlayerMpReq:
|
||||
GAME.ServerPlayerMpReq(serverMsg.PlayerMpInfo, netMsg.OriginServerAppId)
|
||||
case mq.ServerPlayerMpRsp:
|
||||
|
||||
@@ -161,15 +161,12 @@ func (t *TickManager) OnGameServerTick() {
|
||||
now := tm.UnixMilli()
|
||||
if t.globalTickCount%(50/ServerTickTime) == 0 {
|
||||
t.onTick50MilliSecond(now)
|
||||
PLUGIN_MANAGER.HandleGlobalTick(PluginGlobalTick50MilliSecond)
|
||||
}
|
||||
if t.globalTickCount%(100/ServerTickTime) == 0 {
|
||||
t.onTick100MilliSecond(now)
|
||||
PLUGIN_MANAGER.HandleGlobalTick(PluginGlobalTick100MilliSecond)
|
||||
}
|
||||
if t.globalTickCount%(200/ServerTickTime) == 0 {
|
||||
t.onTick200MilliSecond(now)
|
||||
PLUGIN_MANAGER.HandleGlobalTick(PluginGlobalTick200MilliSecond)
|
||||
}
|
||||
if t.globalTickCount%(1000/ServerTickTime) == 0 {
|
||||
t.onTickSecond(now)
|
||||
@@ -177,19 +174,15 @@ func (t *TickManager) OnGameServerTick() {
|
||||
}
|
||||
if t.globalTickCount%(5000/ServerTickTime) == 0 {
|
||||
t.onTick5Second(now)
|
||||
PLUGIN_MANAGER.HandleGlobalTick(PluginGlobalTick5Second)
|
||||
}
|
||||
if t.globalTickCount%(10000/ServerTickTime) == 0 {
|
||||
t.onTick10Second(now)
|
||||
PLUGIN_MANAGER.HandleGlobalTick(PluginGlobalTick10Second)
|
||||
}
|
||||
if t.globalTickCount%(60000/ServerTickTime) == 0 {
|
||||
t.onTickMinute(now)
|
||||
PLUGIN_MANAGER.HandleGlobalTick(PluginGlobalTickMinute)
|
||||
}
|
||||
if t.globalTickCount%(60000*60/ServerTickTime) == 0 {
|
||||
t.onTickHour(now)
|
||||
PLUGIN_MANAGER.HandleGlobalTick(PluginGlobalTickHour)
|
||||
}
|
||||
for userId, userTick := range t.userTickMap {
|
||||
if len(userTick.globalTick.C) == 0 {
|
||||
@@ -213,17 +206,18 @@ func (t *TickManager) OnGameServerTick() {
|
||||
t.userTimerHandle(userId, timer.action, timer.data)
|
||||
}
|
||||
}
|
||||
if tm.Minute() != t.tm.Minute() {
|
||||
t.onMinuteChange(now)
|
||||
PLUGIN_MANAGER.HandleGlobalTick(PluginGlobalTickMinuteChange)
|
||||
}
|
||||
if tm.Hour() != t.tm.Hour() {
|
||||
t.onHourChange(now)
|
||||
PLUGIN_MANAGER.HandleGlobalTick(PluginGlobalTickHourChange)
|
||||
}
|
||||
if tm.Day() != t.tm.Day() {
|
||||
t.onDayChange(now)
|
||||
PLUGIN_MANAGER.HandleGlobalTick(PluginGlobalTickDayChange)
|
||||
}
|
||||
if tm.Month() != t.tm.Month() {
|
||||
t.onMonthChange(now)
|
||||
PLUGIN_MANAGER.HandleGlobalTick(PluginGlobalTickMonthChange)
|
||||
}
|
||||
t.tm = tm
|
||||
}
|
||||
@@ -240,6 +234,9 @@ func (t *TickManager) onHourChange(now int64) {
|
||||
logger.Info("on hour change, time: %v", now)
|
||||
}
|
||||
|
||||
func (t *TickManager) onMinuteChange(now int64) {
|
||||
}
|
||||
|
||||
func (t *TickManager) onTickHour(now int64) {
|
||||
logger.Info("on tick hour, time: %v", now)
|
||||
}
|
||||
@@ -276,15 +273,16 @@ func (t *TickManager) onTick5Second(now int64) {
|
||||
return
|
||||
}
|
||||
pluginPubg := iPlugin.(*PluginPubg)
|
||||
agree := true
|
||||
if pluginPubg.IsStartPubg() {
|
||||
return
|
||||
agree = false
|
||||
}
|
||||
aiWorld := WORLD_MANAGER.GetAiWorld()
|
||||
if aiWorld.GetWorldPlayerNum() >= 100 {
|
||||
return
|
||||
agree = false
|
||||
}
|
||||
for applyUid := range aiWorld.GetOwner().CoopApplyMap {
|
||||
GAME.PlayerDealEnterWorld(aiWorld.GetOwner(), applyUid, true)
|
||||
GAME.PlayerDealEnterWorld(aiWorld.GetOwner(), applyUid, agree)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -348,11 +346,17 @@ func (t *TickManager) onTick100MilliSecond(now int64) {
|
||||
defPlayer := USER_MANAGER.GetOnlineUser(defAvatarEntity.GetAvatarEntity().GetUid())
|
||||
atkAvatarEntity := scene.GetEntity(rigidBody.avatarEntityId)
|
||||
atk := atkAvatarEntity.GetFightProp()[constant.FIGHT_PROP_CUR_ATTACK]
|
||||
dmg := float32(0.0)
|
||||
if rigidBody.venti {
|
||||
dmg = atk
|
||||
} else {
|
||||
dmg = atk / 3.0
|
||||
}
|
||||
GAME.handleEvtBeingHit(defPlayer, scene, &proto.EvtBeingHitInfo{
|
||||
AttackResult: &proto.AttackResult{
|
||||
AttackerId: atkAvatarEntity.GetId(),
|
||||
DefenseId: defAvatarEntity.GetId(),
|
||||
Damage: atk,
|
||||
Damage: dmg,
|
||||
},
|
||||
})
|
||||
if attackResultTemplate == nil {
|
||||
@@ -365,7 +369,7 @@ func (t *TickManager) onTick100MilliSecond(now int64) {
|
||||
}
|
||||
evtBeingHitInfo.AttackResult.AttackerId = atkAvatarEntity.GetId()
|
||||
evtBeingHitInfo.AttackResult.DefenseId = defAvatarEntity.GetId()
|
||||
evtBeingHitInfo.AttackResult.Damage = atk
|
||||
evtBeingHitInfo.AttackResult.Damage = dmg
|
||||
if evtBeingHitInfo.AttackResult.HitCollision == nil {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
package game
|
||||
|
||||
import (
|
||||
"hk4e/protocol/cmd"
|
||||
"time"
|
||||
|
||||
"hk4e/protocol/cmd"
|
||||
|
||||
"hk4e/common/constant"
|
||||
"hk4e/gdconf"
|
||||
"hk4e/gs/model"
|
||||
|
||||
@@ -263,12 +263,8 @@ func (g *Game) handleEntityMove(player *model.Player, world *World, scene *Scene
|
||||
// 玩家实体在移动
|
||||
avatarEntity := entity.GetAvatarEntity()
|
||||
if avatarEntity.GetUid() != player.PlayerId {
|
||||
logger.Error("can not move other player avatar entity, entityId: %v, uid: %v", entity.GetId(), player.PlayerId)
|
||||
return
|
||||
}
|
||||
aoiDebug := player.GetAoiDebug()
|
||||
aoiDebug.AddHistoryPos(pos)
|
||||
aoiDebug.CheckPlayerPosPtr(player)
|
||||
if !WORLD_MANAGER.IsAiWorld(world) {
|
||||
g.SceneBlockAoiPlayerMove(player, world, scene, player.Pos, pos, entity.GetId())
|
||||
} else {
|
||||
@@ -427,15 +423,6 @@ func (g *Game) AiWorldAoiPlayerMove(player *model.Player, world *World, scene *S
|
||||
// 玩家跨越了格子
|
||||
logger.Debug("player cross ai world aoi grid, oldGid: %v, oldPos: %+v, newGid: %v, newPos: %+v, uid: %v",
|
||||
oldGid, oldPos, newGid, newPos, player.PlayerId)
|
||||
aoiDebug := player.GetAoiDebug()
|
||||
if aoiDebug.LastGid == 0 {
|
||||
aoiDebug.LastGid = oldGid
|
||||
}
|
||||
if aoiDebug.LastGid != oldGid {
|
||||
logger.Error("aoi bug move skip grid, last gid: %v, old gid: %v, uid: %v", aoiDebug.LastGid, oldGid, player.PlayerId)
|
||||
aoiDebug.PrintHistoryPosList()
|
||||
}
|
||||
aoiDebug.LastGid = newGid
|
||||
// 找出本次移动所带来的消失和出现的格子
|
||||
oldGridList := aiWorldAoi.GetSurrGridListByGid(oldGid)
|
||||
newGridList := aiWorldAoi.GetSurrGridListByGid(newGid)
|
||||
@@ -849,11 +836,14 @@ func (g *Game) EvtCreateGadgetNotify(player *model.Player, payloadMsg pb.Message
|
||||
return
|
||||
}
|
||||
// 蓄力箭
|
||||
if gadgetDataConfig.PrefabPath != "ART/Others/Bullet/Bullet_ArrowAiming" &&
|
||||
gadgetDataConfig.PrefabPath != "ART/Others/Bullet/Bullet_Venti_ArrowAiming" {
|
||||
venti := false
|
||||
if gadgetDataConfig.PrefabPath == "ART/Others/Bullet/Bullet_ArrowAiming" {
|
||||
venti = false
|
||||
} else if gadgetDataConfig.PrefabPath == "ART/Others/Bullet/Bullet_Venti_ArrowAiming" {
|
||||
venti = true
|
||||
} else {
|
||||
return
|
||||
}
|
||||
logger.Debug("[FPS] EvtCreateGadgetNotify: %+v", ntf)
|
||||
pitchAngleRaw := ntf.InitEulerAngles.X
|
||||
pitchAngle := float32(0.0)
|
||||
if pitchAngleRaw < 90.0 {
|
||||
@@ -871,6 +861,7 @@ func (g *Game) EvtCreateGadgetNotify(player *model.Player, payloadMsg pb.Message
|
||||
ntf.EntityId,
|
||||
world.GetPlayerWorldAvatarEntityId(player, activeAvatarId),
|
||||
player.SceneId,
|
||||
venti,
|
||||
ntf.InitPos.X, ntf.InitPos.Y, ntf.InitPos.Z,
|
||||
pitchAngle, yawAngle,
|
||||
)
|
||||
|
||||
@@ -212,14 +212,14 @@ func (g *Game) CreatePlayer(userId uint32) *model.Player {
|
||||
return player
|
||||
}
|
||||
|
||||
func (g *Game) ServerAppidBindNotify(userId uint32, anticheatAppId string) {
|
||||
func (g *Game) ServerAppidBindNotify(userId uint32, multiServerAppId string) {
|
||||
player := USER_MANAGER.GetOnlineUser(userId)
|
||||
if player == nil {
|
||||
logger.Error("player is nil, uid: %v", userId)
|
||||
return
|
||||
}
|
||||
logger.Debug("server appid bind notify, uid: %v, anticheatAppId: %v", userId, anticheatAppId)
|
||||
player.AnticheatAppId = anticheatAppId
|
||||
logger.Debug("server appid bind notify, uid: %v, multiServerAppId: %v", userId, multiServerAppId)
|
||||
player.MultiServerAppId = multiServerAppId
|
||||
}
|
||||
|
||||
func (g *Game) OnOffline(userId uint32, changeGsInfo *ChangeGsInfo) {
|
||||
|
||||
@@ -245,6 +245,7 @@ func (g *Game) PlayerApplyEnterWorld(player *model.Player, targetUid uint32) {
|
||||
}
|
||||
targetWorld := WORLD_MANAGER.GetWorldById(targetPlayer.WorldId)
|
||||
if targetWorld == nil {
|
||||
// 目标玩家世界状态异常
|
||||
logger.Error("target world is nil, target worldId: %v, uid: %v", targetPlayer.WorldId, player.PlayerId)
|
||||
applyFailNotify(proto.PlayerApplyEnterMpResultNotify_PLAYER_CANNOT_ENTER_MP)
|
||||
return
|
||||
@@ -265,6 +266,7 @@ func (g *Game) PlayerApplyEnterWorld(player *model.Player, targetUid uint32) {
|
||||
}
|
||||
applyTime, exist := targetPlayer.CoopApplyMap[player.PlayerId]
|
||||
if exist && time.Now().UnixNano() < applyTime+int64(10*time.Second) {
|
||||
// 申请过期
|
||||
applyFailNotify(proto.PlayerApplyEnterMpResultNotify_PLAYER_CANNOT_ENTER_MP)
|
||||
return
|
||||
}
|
||||
@@ -314,7 +316,7 @@ func (g *Game) PlayerDealEnterWorld(hostPlayer *model.Player, otherUid uint32, a
|
||||
}
|
||||
|
||||
otherPlayerWorld := WORLD_MANAGER.GetWorldById(otherPlayer.WorldId)
|
||||
if otherPlayerWorld.GetMultiplayer() {
|
||||
if otherPlayerWorld == nil || otherPlayerWorld.GetMultiplayer() {
|
||||
playerApplyEnterMpResultNotify := &proto.PlayerApplyEnterMpResultNotify{
|
||||
TargetUid: hostPlayer.PlayerId,
|
||||
TargetNickname: hostPlayer.NickName,
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package game
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"time"
|
||||
@@ -380,7 +381,9 @@ func (g *Game) GetOnlinePlayerListReq(player *model.Player, payloadMsg pb.Messag
|
||||
aiUidList := USER_MANAGER.GetAllRemoteAiUidList()
|
||||
aiUidList = append(aiUidList, g.GetAi().PlayerId)
|
||||
for _, aiUid := range aiUidList {
|
||||
sign := AiSign + " GS:" + strconv.Itoa(int(aiUid-AiBaseUid))
|
||||
aiGsId := aiUid - AiBaseUid
|
||||
startMinute := aiGsId % 6 * 10
|
||||
sign := fmt.Sprintf("开启时间:每小时%v分。", strconv.Itoa(int(startMinute)))
|
||||
rsp.PlayerInfoList = append(rsp.PlayerInfoList, &proto.OnlinePlayerInfo{
|
||||
Uid: aiUid,
|
||||
Nickname: AiName,
|
||||
|
||||
@@ -677,7 +677,7 @@ func (g *Game) TeleportPlayer(
|
||||
return
|
||||
}
|
||||
|
||||
if WORLD_MANAGER.IsAiWorld(world) {
|
||||
if WORLD_MANAGER.IsAiWorld(world) && player.CmdPerm != uint8(CommandPermGM) {
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
+1
-51
@@ -1,9 +1,6 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"time"
|
||||
|
||||
"hk4e/pkg/logger"
|
||||
"hk4e/protocol/proto"
|
||||
|
||||
@@ -79,7 +76,7 @@ type Player struct {
|
||||
CombatInvokeHandler *InvokeHandler[proto.CombatInvokeEntry] `bson:"-" msgpack:"-"` // combat转发器
|
||||
AbilityInvokeHandler *InvokeHandler[proto.AbilityInvokeEntry] `bson:"-" msgpack:"-"` // ability转发器
|
||||
GateAppId string `bson:"-" msgpack:"-"` // 网关服务器的appid
|
||||
AnticheatAppId string `bson:"-" msgpack:"-"` // 反作弊服务器的appid
|
||||
MultiServerAppId string `bson:"-" msgpack:"-"` // 多功能服务器的appid
|
||||
GCGCurGameGuid uint32 `bson:"-" msgpack:"-"` // GCG玩家所在的游戏guid
|
||||
GCGInfo *GCGInfo `bson:"-" msgpack:"-"` // 七圣召唤信息
|
||||
XLuaDebug bool `bson:"-" msgpack:"-"` // 是否开启客户端XLUA调试
|
||||
@@ -88,7 +85,6 @@ type Player struct {
|
||||
CommandAssignUid uint32 `bson:"-" msgpack:"-"` // 命令指定uid
|
||||
WeatherInfo *WeatherInfo `bson:"-" msgpack:"-"` // 天气信息
|
||||
ClientVersion int `bson:"-" msgpack:"-"` // 玩家在线的客户端版本
|
||||
AoiDebug *AoiDebug `bson:"-" msgpack:"-"` // aoi debug
|
||||
// 特殊数据
|
||||
ChatMsgMap map[uint32][]*ChatMsg `bson:"-" msgpack:"-"` // 聊天信息 数据量偏大 只从db读写 不保存到redis
|
||||
}
|
||||
@@ -186,49 +182,3 @@ func (i *InvokeHandler[T]) Clear() {
|
||||
i.EntryListForwardHost = make([]*T, 0)
|
||||
i.EntryListForwardServer = make([]*T, 0)
|
||||
}
|
||||
|
||||
type HistoryPos struct {
|
||||
Time string
|
||||
Pos *Vector
|
||||
}
|
||||
|
||||
type AoiDebug struct {
|
||||
Uid uint32
|
||||
HistoryPosList []*HistoryPos
|
||||
LastGid uint32
|
||||
PlayerPosPtr *Vector
|
||||
}
|
||||
|
||||
func (p *Player) GetAoiDebug() *AoiDebug {
|
||||
if p.AoiDebug == nil {
|
||||
p.AoiDebug = &AoiDebug{
|
||||
Uid: p.PlayerId,
|
||||
HistoryPosList: make([]*HistoryPos, 0),
|
||||
LastGid: 0,
|
||||
PlayerPosPtr: p.Pos,
|
||||
}
|
||||
}
|
||||
return p.AoiDebug
|
||||
}
|
||||
|
||||
func (a *AoiDebug) AddHistoryPos(pos *Vector) {
|
||||
a.HistoryPosList = append(a.HistoryPosList, &HistoryPos{
|
||||
Time: time.Now().Format("2006-01-02 15:04:05.000"),
|
||||
Pos: &Vector{X: pos.X, Y: pos.Y, Z: pos.Z},
|
||||
})
|
||||
if len(a.HistoryPosList) > 100 {
|
||||
a.HistoryPosList = a.HistoryPosList[1:]
|
||||
}
|
||||
}
|
||||
|
||||
func (a *AoiDebug) PrintHistoryPosList() {
|
||||
data, _ := json.Marshal(a.HistoryPosList)
|
||||
logger.Debug("HistoryPosList: %v, uid: %v", string(data), a.Uid)
|
||||
}
|
||||
|
||||
func (a *AoiDebug) CheckPlayerPosPtr(player *Player) {
|
||||
if a.PlayerPosPtr != player.Pos {
|
||||
logger.Error("player pos ptr change, oldPtr: %p, nowPtr: %v, oldPos: %+v, nowPos: %+v, uid: %v",
|
||||
a.PlayerPosPtr, player.Pos, a.PlayerPosPtr, player.Pos, player.PlayerId)
|
||||
}
|
||||
}
|
||||
@@ -11,8 +11,9 @@ import (
|
||||
"hk4e/common/config"
|
||||
"hk4e/common/mq"
|
||||
"hk4e/common/rpc"
|
||||
"hk4e/gdconf"
|
||||
"hk4e/multi/handle"
|
||||
"hk4e/node/api"
|
||||
"hk4e/pathfinding/handle"
|
||||
"hk4e/pkg/logger"
|
||||
)
|
||||
|
||||
@@ -30,7 +31,7 @@ func Run(ctx context.Context, configFile string) error {
|
||||
|
||||
// 注册到节点服务器
|
||||
rsp, err := discoveryClient.RegisterServer(context.TODO(), &api.RegisterServerReq{
|
||||
ServerType: api.PATHFINDING,
|
||||
ServerType: api.MULTI,
|
||||
AppVersion: APPVERSION,
|
||||
})
|
||||
if err != nil {
|
||||
@@ -42,7 +43,7 @@ func Run(ctx context.Context, configFile string) error {
|
||||
for {
|
||||
<-ticker.C
|
||||
_, err := discoveryClient.KeepaliveServer(context.TODO(), &api.KeepaliveServerReq{
|
||||
ServerType: api.PATHFINDING,
|
||||
ServerType: api.MULTI,
|
||||
AppId: APPID,
|
||||
})
|
||||
if err != nil {
|
||||
@@ -52,18 +53,20 @@ func Run(ctx context.Context, configFile string) error {
|
||||
}()
|
||||
defer func() {
|
||||
_, _ = discoveryClient.CancelServer(context.TODO(), &api.CancelServerReq{
|
||||
ServerType: api.PATHFINDING,
|
||||
ServerType: api.MULTI,
|
||||
AppId: APPID,
|
||||
})
|
||||
}()
|
||||
|
||||
logger.InitLogger("pathfinding_" + APPID)
|
||||
logger.Warn("pathfinding start, appid: %v", APPID)
|
||||
logger.InitLogger("multi_" + APPID)
|
||||
logger.Warn("multi start, appid: %v", APPID)
|
||||
defer func() {
|
||||
logger.CloseLogger()
|
||||
}()
|
||||
|
||||
messageQueue := mq.NewMessageQueue(api.PATHFINDING, APPID, discoveryClient)
|
||||
gdconf.InitGameDataConfig()
|
||||
|
||||
messageQueue := mq.NewMessageQueue(api.MULTI, APPID, discoveryClient)
|
||||
defer messageQueue.Close()
|
||||
|
||||
_ = handle.NewHandle(messageQueue)
|
||||
@@ -78,7 +81,7 @@ func Run(ctx context.Context, configFile string) error {
|
||||
logger.Warn("get a signal %s", s.String())
|
||||
switch s {
|
||||
case syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT:
|
||||
logger.Warn("pathfinding exit, appid: %v", APPID)
|
||||
logger.Warn("multi exit, appid: %v", APPID)
|
||||
return nil
|
||||
case syscall.SIGHUP:
|
||||
default:
|
||||
@@ -5,12 +5,8 @@ import (
|
||||
"time"
|
||||
|
||||
"hk4e/common/constant"
|
||||
"hk4e/common/mq"
|
||||
"hk4e/gate/kcp"
|
||||
"hk4e/gdconf"
|
||||
"hk4e/node/api"
|
||||
"hk4e/pkg/logger"
|
||||
"hk4e/protocol/cmd"
|
||||
"hk4e/protocol/proto"
|
||||
|
||||
pb "google.golang.org/protobuf/proto"
|
||||
@@ -137,11 +133,6 @@ func NewAnticheatContext() *AnticheatContext {
|
||||
return r
|
||||
}
|
||||
|
||||
type Handle struct {
|
||||
messageQueue *mq.MessageQueue
|
||||
playerAcCtxMap map[uint32]*AnticheatContext
|
||||
}
|
||||
|
||||
func (h *Handle) AddPlayerAcCtx(userId uint32) {
|
||||
h.playerAcCtxMap[userId] = NewAnticheatContext()
|
||||
}
|
||||
@@ -154,48 +145,6 @@ func (h *Handle) GetPlayerAcCtx(userId uint32) *AnticheatContext {
|
||||
return h.playerAcCtxMap[userId]
|
||||
}
|
||||
|
||||
func NewHandle(messageQueue *mq.MessageQueue) (r *Handle) {
|
||||
r = new(Handle)
|
||||
r.messageQueue = messageQueue
|
||||
r.playerAcCtxMap = make(map[uint32]*AnticheatContext)
|
||||
go r.run()
|
||||
return r
|
||||
}
|
||||
|
||||
func (h *Handle) run() {
|
||||
logger.Info("start handle")
|
||||
for {
|
||||
netMsg := <-h.messageQueue.GetNetMsg()
|
||||
switch netMsg.MsgType {
|
||||
case mq.MsgTypeGame:
|
||||
if netMsg.OriginServerType != api.GATE {
|
||||
continue
|
||||
}
|
||||
if netMsg.EventId != mq.NormalMsg {
|
||||
continue
|
||||
}
|
||||
gameMsg := netMsg.GameMsg
|
||||
switch gameMsg.CmdId {
|
||||
case cmd.CombatInvocationsNotify:
|
||||
h.CombatInvocationsNotify(gameMsg.UserId, netMsg.OriginServerAppId, gameMsg.PayloadMessage)
|
||||
case cmd.ToTheMoonEnterSceneReq:
|
||||
h.ToTheMoonEnterSceneReq(gameMsg.UserId, netMsg.OriginServerAppId, gameMsg.PayloadMessage)
|
||||
}
|
||||
case mq.MsgTypeServer:
|
||||
serverMsg := netMsg.ServerMsg
|
||||
switch netMsg.EventId {
|
||||
case mq.ServerUserOnlineStateChangeNotify:
|
||||
logger.Info("player online state change, state: %v, uid: %v", serverMsg.IsOnline, serverMsg.UserId)
|
||||
if serverMsg.IsOnline {
|
||||
h.AddPlayerAcCtx(serverMsg.UserId)
|
||||
} else {
|
||||
h.DelPlayerAcCtx(serverMsg.UserId)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (h *Handle) CombatInvocationsNotify(userId uint32, gateAppId string, payloadMsg pb.Message) {
|
||||
req := payloadMsg.(*proto.CombatInvocationsNotify)
|
||||
ctx := h.GetPlayerAcCtx(userId)
|
||||
@@ -284,17 +233,3 @@ func GetDistance(v1 *proto.Vector, v2 *proto.Vector) float32 {
|
||||
float64((v1.Z-v2.Z)*(v1.Z-v2.Z)),
|
||||
))
|
||||
}
|
||||
|
||||
func (h *Handle) KickPlayer(userId uint32, gateAppId string) {
|
||||
if !KickCheatPlayer {
|
||||
return
|
||||
}
|
||||
h.messageQueue.SendToGate(gateAppId, &mq.NetMsg{
|
||||
MsgType: mq.MsgTypeConnCtrl,
|
||||
EventId: mq.KickPlayerNotify,
|
||||
ConnCtrlMsg: &mq.ConnCtrlMsg{
|
||||
KickUserId: userId,
|
||||
KickReason: kcp.EnetServerKillClient,
|
||||
},
|
||||
})
|
||||
}
|
||||
@@ -2,8 +2,8 @@ package handle
|
||||
|
||||
import (
|
||||
"hk4e/common/mq"
|
||||
"hk4e/gate/kcp"
|
||||
"hk4e/node/api"
|
||||
"hk4e/pathfinding/world"
|
||||
"hk4e/pkg/logger"
|
||||
"hk4e/protocol/cmd"
|
||||
|
||||
@@ -11,41 +11,71 @@ import (
|
||||
)
|
||||
|
||||
type Handle struct {
|
||||
worldStatic *world.WorldStatic
|
||||
messageQueue *mq.MessageQueue
|
||||
messageQueue *mq.MessageQueue
|
||||
playerAcCtxMap map[uint32]*AnticheatContext
|
||||
worldStatic *WorldStatic
|
||||
}
|
||||
|
||||
func NewHandle(messageQueue *mq.MessageQueue) (r *Handle) {
|
||||
r = new(Handle)
|
||||
r.worldStatic = world.NewWorldStatic()
|
||||
r.worldStatic.InitTerrain()
|
||||
r.messageQueue = messageQueue
|
||||
r.playerAcCtxMap = make(map[uint32]*AnticheatContext)
|
||||
r.worldStatic = NewWorldStatic()
|
||||
r.worldStatic.InitTerrain()
|
||||
go r.run()
|
||||
return r
|
||||
}
|
||||
|
||||
func (h *Handle) run() {
|
||||
go func() {
|
||||
for {
|
||||
netMsg := <-h.messageQueue.GetNetMsg()
|
||||
if netMsg.MsgType != mq.MsgTypeGame {
|
||||
logger.Info("start handle")
|
||||
for {
|
||||
netMsg := <-h.messageQueue.GetNetMsg()
|
||||
switch netMsg.MsgType {
|
||||
case mq.MsgTypeGame:
|
||||
if netMsg.OriginServerType != api.GATE {
|
||||
continue
|
||||
}
|
||||
if netMsg.EventId != mq.NormalMsg {
|
||||
continue
|
||||
}
|
||||
if netMsg.OriginServerType != api.GATE {
|
||||
continue
|
||||
}
|
||||
gameMsg := netMsg.GameMsg
|
||||
switch gameMsg.CmdId {
|
||||
case cmd.CombatInvocationsNotify:
|
||||
h.CombatInvocationsNotify(gameMsg.UserId, netMsg.OriginServerAppId, gameMsg.PayloadMessage)
|
||||
case cmd.ToTheMoonEnterSceneReq:
|
||||
h.ToTheMoonEnterSceneReq(gameMsg.UserId, netMsg.OriginServerAppId, gameMsg.PayloadMessage)
|
||||
case cmd.QueryPathReq:
|
||||
h.QueryPath(gameMsg.UserId, netMsg.OriginServerAppId, gameMsg.PayloadMessage)
|
||||
case cmd.ObstacleModifyNotify:
|
||||
h.ObstacleModifyNotify(gameMsg.UserId, netMsg.OriginServerAppId, gameMsg.PayloadMessage)
|
||||
}
|
||||
case mq.MsgTypeServer:
|
||||
serverMsg := netMsg.ServerMsg
|
||||
switch netMsg.EventId {
|
||||
case mq.ServerUserOnlineStateChangeNotify:
|
||||
logger.Info("player online state change, state: %v, uid: %v", serverMsg.IsOnline, serverMsg.UserId)
|
||||
if serverMsg.IsOnline {
|
||||
h.AddPlayerAcCtx(serverMsg.UserId)
|
||||
} else {
|
||||
h.DelPlayerAcCtx(serverMsg.UserId)
|
||||
}
|
||||
}
|
||||
}
|
||||
}()
|
||||
}
|
||||
}
|
||||
|
||||
func (h *Handle) KickPlayer(userId uint32, gateAppId string) {
|
||||
if !KickCheatPlayer {
|
||||
return
|
||||
}
|
||||
h.messageQueue.SendToGate(gateAppId, &mq.NetMsg{
|
||||
MsgType: mq.MsgTypeConnCtrl,
|
||||
EventId: mq.KickPlayerNotify,
|
||||
ConnCtrlMsg: &mq.ConnCtrlMsg{
|
||||
KickUserId: userId,
|
||||
KickReason: kcp.EnetServerKillClient,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
// SendMsg 发送消息给客户端
|
||||
@@ -1,6 +1,10 @@
|
||||
package handle
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/gob"
|
||||
"os"
|
||||
|
||||
"hk4e/pkg/alg"
|
||||
"hk4e/pkg/logger"
|
||||
"hk4e/protocol/cmd"
|
||||
@@ -73,3 +77,86 @@ func (h *Handle) ObstacleModifyNotify(userId uint32, gateAppId string, payloadMs
|
||||
req := payloadMsg.(*proto.ObstacleModifyNotify)
|
||||
logger.Debug("obstacle modify req: %v, uid: %v, gateAppId: %v", req, userId, gateAppId)
|
||||
}
|
||||
|
||||
type WorldStatic struct {
|
||||
// x y z -> if terrain exist
|
||||
terrain map[alg.MeshVector]bool
|
||||
}
|
||||
|
||||
func NewWorldStatic() (r *WorldStatic) {
|
||||
r = new(WorldStatic)
|
||||
r.terrain = make(map[alg.MeshVector]bool)
|
||||
return r
|
||||
}
|
||||
|
||||
func (w *WorldStatic) InitTerrain() bool {
|
||||
data, err := os.ReadFile("./world_terrain.bin")
|
||||
if err != nil {
|
||||
logger.Error("read world terrain file error: %v", err)
|
||||
return false
|
||||
}
|
||||
decoder := gob.NewDecoder(bytes.NewReader(data))
|
||||
err = decoder.Decode(&w.terrain)
|
||||
if err != nil {
|
||||
logger.Error("unmarshal world terrain data error: %v", err)
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func (w *WorldStatic) SaveTerrain() bool {
|
||||
var buffer bytes.Buffer
|
||||
encoder := gob.NewEncoder(&buffer)
|
||||
err := encoder.Encode(w.terrain)
|
||||
if err != nil {
|
||||
logger.Error("marshal world terrain data error: %v", err)
|
||||
return false
|
||||
}
|
||||
err = os.WriteFile("./world_terrain.bin", buffer.Bytes(), 0644)
|
||||
if err != nil {
|
||||
logger.Error("write world terrain file error: %v", err)
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func (w *WorldStatic) GetTerrain(x int16, y int16, z int16) (exist bool) {
|
||||
pos := alg.MeshVector{
|
||||
X: x,
|
||||
Y: y,
|
||||
Z: z,
|
||||
}
|
||||
exist = w.terrain[pos]
|
||||
return exist
|
||||
}
|
||||
|
||||
func (w *WorldStatic) SetTerrain(x int16, y int16, z int16) {
|
||||
pos := alg.MeshVector{
|
||||
X: x,
|
||||
Y: y,
|
||||
Z: z,
|
||||
}
|
||||
w.terrain[pos] = true
|
||||
}
|
||||
|
||||
func (w *WorldStatic) Pathfinding(startPos alg.MeshVector, endPos alg.MeshVector) (bool, []alg.MeshVector) {
|
||||
defer func() {
|
||||
if err := recover(); err != nil {
|
||||
logger.Error("pathfinding error, panic, startPos: %v, endPos: %v", startPos, endPos)
|
||||
}
|
||||
}()
|
||||
bfs := alg.NewBFS()
|
||||
bfs.InitMap(
|
||||
w.terrain,
|
||||
startPos,
|
||||
endPos,
|
||||
0,
|
||||
)
|
||||
pathVectorList := bfs.Pathfinding()
|
||||
if pathVectorList == nil {
|
||||
logger.Error("could not find path")
|
||||
return false, nil
|
||||
}
|
||||
logger.Debug("find path success, path: %v", pathVectorList)
|
||||
return true, pathVectorList
|
||||
}
|
||||
@@ -1,11 +1,12 @@
|
||||
package api
|
||||
|
||||
const (
|
||||
NODE = "NODE"
|
||||
DISPATCH = "DISPATCH"
|
||||
GATE = "GATE"
|
||||
GS = "GS"
|
||||
ANTICHEAT = "ANTICHEAT"
|
||||
PATHFINDING = "PATHFINDING"
|
||||
NODE = "NODE"
|
||||
MULTI = "MULTI"
|
||||
ROBOT = "ROBOT"
|
||||
DISPATCH = "DISPATCH"
|
||||
)
|
||||
@@ -88,8 +88,7 @@ func NewDiscoveryService(db *dao.Dao, messageQueue *mq.MessageQueue) (*Discovery
|
||||
r.serverInstanceMap = make(map[string]*sync.Map)
|
||||
r.serverInstanceMap[api.GATE] = new(sync.Map)
|
||||
r.serverInstanceMap[api.GS] = new(sync.Map)
|
||||
r.serverInstanceMap[api.ANTICHEAT] = new(sync.Map)
|
||||
r.serverInstanceMap[api.PATHFINDING] = new(sync.Map)
|
||||
r.serverInstanceMap[api.MULTI] = new(sync.Map)
|
||||
r.serverInstanceMap[api.ROBOT] = new(sync.Map)
|
||||
r.serverInstanceMap[api.DISPATCH] = new(sync.Map)
|
||||
r.serverAppIdMap = new(sync.Map)
|
||||
|
||||
@@ -1,93 +0,0 @@
|
||||
package world
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/gob"
|
||||
"os"
|
||||
|
||||
"hk4e/pkg/alg"
|
||||
"hk4e/pkg/logger"
|
||||
)
|
||||
|
||||
type WorldStatic struct {
|
||||
// x y z -> if terrain exist
|
||||
terrain map[alg.MeshVector]bool
|
||||
}
|
||||
|
||||
func NewWorldStatic() (r *WorldStatic) {
|
||||
r = new(WorldStatic)
|
||||
r.terrain = make(map[alg.MeshVector]bool)
|
||||
return r
|
||||
}
|
||||
|
||||
func (w *WorldStatic) InitTerrain() bool {
|
||||
data, err := os.ReadFile("./world_terrain.bin")
|
||||
if err != nil {
|
||||
logger.Error("read world terrain file error: %v", err)
|
||||
return false
|
||||
}
|
||||
decoder := gob.NewDecoder(bytes.NewReader(data))
|
||||
err = decoder.Decode(&w.terrain)
|
||||
if err != nil {
|
||||
logger.Error("unmarshal world terrain data error: %v", err)
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func (w *WorldStatic) SaveTerrain() bool {
|
||||
var buffer bytes.Buffer
|
||||
encoder := gob.NewEncoder(&buffer)
|
||||
err := encoder.Encode(w.terrain)
|
||||
if err != nil {
|
||||
logger.Error("marshal world terrain data error: %v", err)
|
||||
return false
|
||||
}
|
||||
err = os.WriteFile("./world_terrain.bin", buffer.Bytes(), 0644)
|
||||
if err != nil {
|
||||
logger.Error("write world terrain file error: %v", err)
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func (w *WorldStatic) GetTerrain(x int16, y int16, z int16) (exist bool) {
|
||||
pos := alg.MeshVector{
|
||||
X: x,
|
||||
Y: y,
|
||||
Z: z,
|
||||
}
|
||||
exist = w.terrain[pos]
|
||||
return exist
|
||||
}
|
||||
|
||||
func (w *WorldStatic) SetTerrain(x int16, y int16, z int16) {
|
||||
pos := alg.MeshVector{
|
||||
X: x,
|
||||
Y: y,
|
||||
Z: z,
|
||||
}
|
||||
w.terrain[pos] = true
|
||||
}
|
||||
|
||||
func (w *WorldStatic) Pathfinding(startPos alg.MeshVector, endPos alg.MeshVector) (bool, []alg.MeshVector) {
|
||||
defer func() {
|
||||
if err := recover(); err != nil {
|
||||
logger.Error("pathfinding error, panic, startPos: %v, endPos: %v", startPos, endPos)
|
||||
}
|
||||
}()
|
||||
bfs := alg.NewBFS()
|
||||
bfs.InitMap(
|
||||
w.terrain,
|
||||
startPos,
|
||||
endPos,
|
||||
0,
|
||||
)
|
||||
pathVectorList := bfs.Pathfinding()
|
||||
if pathVectorList == nil {
|
||||
logger.Error("could not find path")
|
||||
return false, nil
|
||||
}
|
||||
logger.Debug("find path success, path: %v", pathVectorList)
|
||||
return true, pathVectorList
|
||||
}
|
||||
@@ -156,7 +156,7 @@ func (l *Logger) writeLogFile(logStr string) {
|
||||
fmt.Printf(RED+"rename old log file error: %v\n"+RESET, err)
|
||||
return
|
||||
}
|
||||
file, err := os.OpenFile("./"+l.AppName+".log", os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0644)
|
||||
file, err := os.OpenFile("./log/"+l.AppName+".log", os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0644)
|
||||
if err != nil {
|
||||
fmt.Printf(RED+"open new log file error: %v\n"+RESET, err)
|
||||
return
|
||||
|
||||
Reference in new issue
Block a user