117 lines
3.6 KiB
Go
117 lines
3.6 KiB
Go
package main
|
|
|
|
import (
|
|
"ecs/servers/admin/handler"
|
|
"github.com/oylshe1314/framework/client/rpc"
|
|
"github.com/oylshe1314/framework/client/sd"
|
|
"github.com/oylshe1314/framework/client/sd/zk"
|
|
"github.com/oylshe1314/framework/errors"
|
|
"github.com/oylshe1314/framework/server"
|
|
"github.com/oylshe1314/framework/util"
|
|
"time"
|
|
)
|
|
|
|
type ServerConfig struct {
|
|
Subscriptions []string `json:"Subscriptions"`
|
|
}
|
|
|
|
type adminServer struct {
|
|
server.NamedServer
|
|
|
|
serverConfig *ServerConfig
|
|
|
|
ExterServer server.HttpServer
|
|
|
|
sdConfig *sd.Config
|
|
HttpRpcClient rpc.HttpRpcClient
|
|
SubscribeClient sd.SubscribeClient
|
|
|
|
innerHandler *handler.InnerHandler
|
|
}
|
|
|
|
func NewAdminServer() server.Server {
|
|
return &adminServer{}
|
|
}
|
|
|
|
func (this *adminServer) WithServerConfig(serverConfig *ServerConfig) {
|
|
this.serverConfig = serverConfig
|
|
}
|
|
|
|
func (this *adminServer) WithSdConfig(config *sd.Config) {
|
|
this.sdConfig = config
|
|
}
|
|
|
|
func (this *adminServer) Init() (err error) {
|
|
err = this.NamedServer.Init()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
this.ExterServer.SetServer(this)
|
|
err = this.ExterServer.Init()
|
|
if err != nil {
|
|
return errors.Errorf("the 'ExterServer' init failed, %v", err)
|
|
}
|
|
|
|
this.HttpRpcClient = rpc.NewHttpRpcClient(this.Logger())
|
|
err = this.HttpRpcClient.Init()
|
|
if err != nil {
|
|
return errors.Errorf("the 'HttpRpcClient' init failed, %v", err)
|
|
}
|
|
|
|
var subscriptions = map[string]sd.SubscribeCallback{}
|
|
for _, svrName := range this.serverConfig.Subscriptions {
|
|
subscriptions[svrName] = this.HttpRpcClient.SubscribeCallback
|
|
}
|
|
this.SubscribeClient = zk.NewSubscribeClient(this, this.sdConfig, subscriptions)
|
|
err = this.SubscribeClient.Init()
|
|
if err != nil {
|
|
return errors.Errorf("the 'SubscribeClient' init failed, %v", err)
|
|
}
|
|
|
|
this.innerHandler = handler.NewInnerHandler(this, this.HttpRpcClient)
|
|
|
|
//this.ExterServer.PostHandler("/server/detect", this.innerHandler.ServerDetect)
|
|
//
|
|
//this.ExterServer.GetHandler("/gate/setting/get", this.innerHandler.GateSettingGet)
|
|
//this.ExterServer.PostHandler("/gate/setting/save", this.innerHandler.GateSettingSave)
|
|
//
|
|
//this.ExterServer.GetHandler("/gate/cdkey/get", this.innerHandler.GateCdkeyGet)
|
|
//this.ExterServer.GetHandler("/gate/cdkey/list", this.innerHandler.GateCdkeyList)
|
|
//this.ExterServer.PostHandler("/gate/cdkey/add", this.innerHandler.GateCdkeyAdd)
|
|
//this.ExterServer.PostHandler("/gate/cdkey/generate", this.innerHandler.GateCdkeyGenerate)
|
|
//this.ExterServer.PostHandler("/gate/cdkey/delete", this.innerHandler.GateCdkeyDelete)
|
|
//
|
|
//this.ExterServer.GetHandler("/gate/user/query", this.innerHandler.GateUserQuery)
|
|
//this.ExterServer.PostHandler("/gate/user/operate", this.innerHandler.GateUserOperate)
|
|
//
|
|
//this.ExterServer.PostHandler("/game_1/data/reload", this.innerHandler.GameDataReload)
|
|
//
|
|
//this.ExterServer.GetHandler("/game_1/mail/list", this.innerHandler.GameMailList)
|
|
//this.ExterServer.PostHandler("/game_1/mail/send", this.innerHandler.GameMailSend)
|
|
//this.ExterServer.PostHandler("/game_1/mail/delete", this.innerHandler.GameMailDelete)
|
|
//
|
|
//this.ExterServer.GetHandler("/game_1/player/query", this.innerHandler.GamePlayerQuery)
|
|
//this.ExterServer.PostHandler("/game_1/player/operate", this.innerHandler.GamePlayerOperate)
|
|
return nil
|
|
}
|
|
|
|
func (this *adminServer) Serve() error {
|
|
return util.WaitAny(this.ExterServer.Serve, this.SubscribeClient.Work)
|
|
}
|
|
|
|
func (this *adminServer) Close() error {
|
|
|
|
this.Logger().Info("The 'SubscribeClient' is closing")
|
|
_ = this.SubscribeClient.Close()
|
|
|
|
this.Logger().Info("The 'ExterServer' is closing")
|
|
_ = this.ExterServer.Close()
|
|
|
|
this.Logger().Info("Server closed")
|
|
|
|
time.Sleep(time.Second)
|
|
_ = this.NamedServer.Close()
|
|
return nil
|
|
}
|