```
refactor(common/cool/coolconfig): 修改RPC配置字段类型 将RPC字段从uint16类型更改为string类型的Address字段, 以支持更灵活的地址配置。同时更新了配置初始化逻辑, 从server.rpc改为server.address作为配置键。 ```
This commit is contained in:
@@ -14,7 +14,7 @@ type sConfig struct {
|
||||
GameOnlineID uint16 `json:"port_bl"` //这个是命令行输入的参数
|
||||
ServerInfo ServerList
|
||||
|
||||
RPC uint16 //rpc端口
|
||||
Address string //rpc端口
|
||||
|
||||
}
|
||||
type ServerList struct {
|
||||
@@ -69,9 +69,10 @@ func newConfig() *sConfig {
|
||||
config := &sConfig{
|
||||
AutoMigrate: GetCfgWithDefault(ctx, "blazing.autoMigrate", g.NewVar(false)).Bool(),
|
||||
Name: GetCfgWithDefault(ctx, "server.name", g.NewVar("")).String(),
|
||||
Eps: GetCfgWithDefault(ctx, "blazing.eps", g.NewVar(false)).Bool(),
|
||||
LoginPort: string(GetCfgWithDefault(ctx, "server.port", g.NewVar("8080")).String()),
|
||||
RPC: GetCfgWithDefault(ctx, "server.rpc", g.NewVar("8080")).Uint16(),
|
||||
|
||||
Eps: GetCfgWithDefault(ctx, "blazing.eps", g.NewVar(false)).Bool(),
|
||||
LoginPort: string(GetCfgWithDefault(ctx, "server.port", g.NewVar("8080")).String()),
|
||||
Address: GetCfgWithDefault(ctx, "server.address", g.NewVar("8080")).String(),
|
||||
//GamePort: GetCfgWithDefault(ctx, "server.game", g.NewVar("8080")).Uint64s(),
|
||||
|
||||
File: &file{
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -7,7 +7,6 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
|
||||
config "blazing/modules/config/service"
|
||||
|
||||
@@ -15,13 +14,11 @@ import (
|
||||
"github.com/gogf/gf/v2/util/gconv"
|
||||
)
|
||||
|
||||
var rpcport = gconv.String(cool.Config.RPC)
|
||||
|
||||
// Define the server handler
|
||||
type ServerHandler struct{}
|
||||
|
||||
// 实现踢人
|
||||
func (h *ServerHandler) Kick(ctx context.Context, userid uint32) error {
|
||||
func (*ServerHandler) Kick(_ context.Context, userid uint32) error {
|
||||
|
||||
cool.Logger.Info(context.TODO(), "服务器收到踢人")
|
||||
useid1, err := share.ShareManager.GetUserOnline(userid)
|
||||
@@ -41,7 +38,7 @@ func (h *ServerHandler) Kick(ctx context.Context, userid uint32) error {
|
||||
}
|
||||
|
||||
// 注册logic服务器
|
||||
func (h *ServerHandler) RegisterLogic(ctx context.Context, id, port uint16) error {
|
||||
func (*ServerHandler) RegisterLogic(ctx context.Context, id, port uint16) error {
|
||||
cool.Logger.Debug(context.Background(), "注册logic服务器", id, port)
|
||||
|
||||
//TODO 待修复滚动更新可能导致的玩家可以同时在旧服务器和新服务器同时在线的bug
|
||||
@@ -62,18 +59,28 @@ func (h *ServerHandler) RegisterLogic(ctx context.Context, id, port uint16) erro
|
||||
|
||||
}
|
||||
|
||||
func StartServer() {
|
||||
// func StartServer() {
|
||||
// // create a new server instance
|
||||
// rpcServer := jsonrpc.NewServer(jsonrpc.WithReverseClient[cool.ClientHandler](""))
|
||||
|
||||
// rpcServer.Register("", &ServerHandler{})
|
||||
// cool.Logger.Debug(context.Background(), "jsonrpc server start", rpcport)
|
||||
// // go time.AfterFunc(3000, func() {
|
||||
// // testjsonrpc()
|
||||
// // })
|
||||
|
||||
// err := http.ListenAndServe("0.0.0.0:"+rpcport, rpcServer)
|
||||
// cool.Logger.Debug(context.Background(), "jsonrpc server fail", err)
|
||||
// }
|
||||
func CServer() *jsonrpc.RPCServer {
|
||||
// create a new server instance
|
||||
rpcServer := jsonrpc.NewServer(jsonrpc.WithReverseClient[cool.ClientHandler](""))
|
||||
|
||||
rpcServer.Register("", &ServerHandler{})
|
||||
cool.Logger.Debug(context.Background(), "jsonrpc server start", rpcport)
|
||||
// go time.AfterFunc(3000, func() {
|
||||
// testjsonrpc()
|
||||
// })
|
||||
|
||||
err := http.ListenAndServe("0.0.0.0:"+rpcport, rpcServer)
|
||||
cool.Logger.Debug(context.Background(), "jsonrpc server fail", err)
|
||||
return rpcServer
|
||||
// err := http.ListenAndServe("0.0.0.0:"+rpcport, rpcServer)
|
||||
// // cool.Logger.Debug(context.Background(), "jsonrpc server fail", err)
|
||||
}
|
||||
|
||||
var closer jsonrpc.ClientCloser
|
||||
@@ -84,10 +91,10 @@ func StartClient(id, port uint16, callback any) *struct {
|
||||
RegisterLogic func(uint16, uint16) error
|
||||
} {
|
||||
|
||||
var rpcaddr = cool.Config.File.Domain
|
||||
var rpcaddr = "ws://" + cool.Config.File.Domain + gconv.String(cool.Config.Address) + "/rpc"
|
||||
//rpcaddr = "127.0.0.1"
|
||||
closer1, err := jsonrpc.NewMergeClient(context.Background(),
|
||||
"ws://"+rpcaddr+":"+rpcport, "", []interface{}{
|
||||
rpcaddr, "", []interface{}{
|
||||
&RPCClient,
|
||||
}, nil, jsonrpc.WithClientHandler("", callback),
|
||||
jsonrpc.WithReconnFun(func() { RPCClient.RegisterLogic(id, port) }),
|
||||
@@ -97,19 +104,13 @@ func StartClient(id, port uint16, callback any) *struct {
|
||||
}
|
||||
|
||||
//if port != 0 { //注册logic
|
||||
RPCClient.RegisterLogic(id, port)
|
||||
defer RPCClient.RegisterLogic(id, port)
|
||||
|
||||
//}
|
||||
|
||||
closer = closer1
|
||||
return &RPCClient
|
||||
}
|
||||
|
||||
// 关闭客户端
|
||||
func CloseClient() {
|
||||
if closer != nil {
|
||||
closer()
|
||||
}
|
||||
return &RPCClient
|
||||
}
|
||||
|
||||
// Setup RPCClient with reverse call handler
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"blazing/logic/service/player"
|
||||
"context"
|
||||
"fmt"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Broadcast struct {
|
||||
@@ -41,9 +42,17 @@ func (s *Server) QuitSelf(a int) error {
|
||||
s.quit = true
|
||||
if a != 0 {
|
||||
player.Mainplayer.Range(func(key uint32, value *player.Player) bool {
|
||||
value.Kick()
|
||||
value.Kick(1)
|
||||
return true
|
||||
})
|
||||
} else {
|
||||
go func() {
|
||||
<-time.After(10 * time.Minute)
|
||||
player.Mainplayer.Range(func(key uint32, value *player.Player) bool {
|
||||
value.Kick(1)
|
||||
return true
|
||||
})
|
||||
}()
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user