From bca0b6f9ebe36234f503bec580fb46d861811ae5 Mon Sep 17 00:00:00 2001 From: zqj <582132116@qq.com> Date: Wed, 2 Mar 2022 09:39:36 +0800 Subject: [PATCH] 重新加载plugin server.LoadPlugin --- src/components/net/server.go | 12 ++---------- src/plugin/protocode.go | 7 ++----- tools/protostostruct.go | 2 +- 3 files changed, 5 insertions(+), 16 deletions(-) diff --git a/src/components/net/server.go b/src/components/net/server.go index 44dcd71..70466d6 100644 --- a/src/components/net/server.go +++ b/src/components/net/server.go @@ -83,20 +83,12 @@ func (s *Server) OnClose(conn *Connection) { func (s *Server) LoadPlugin() { //重新加载 - p, err:=plugin.Open(conf.GlobalConf.GameConf.PluginPath) + _, err:=plugin.Open(conf.GlobalConf.GameConf.PluginPath) if err != nil { logger.Error("load plugin err: %v", err) return } - symboll, err := p.Lookup("LoadRpc") - if err != nil { - logger.Error("plugin symbol err: %v", err) - return - } - if x, ok := symboll.(func()); ok { - x() - logger.Debug("load plugin success") - } + logger.Debug("load plugin success") } func (s *Server)Start() error { diff --git a/src/plugin/protocode.go b/src/plugin/protocode.go index e778830..6286e2c 100644 --- a/src/plugin/protocode.go +++ b/src/plugin/protocode.go @@ -6,15 +6,12 @@ import ( "pro2d/src/components/net" ) -func LoadRpc() { +func init() { logger.Debug("init protocode...") net.ActionMap = make(map[pb.ProtoCode]net.ActionHandler) + net.ActionMap[pb.ProtoCode_HeartRpc] = HeartRpc net.ActionMap[pb.ProtoCode_LoginRpc] = LoginRpc net.ActionMap[pb.ProtoCode_CreateRpc] = CreateRpc } - -func init() { - LoadRpc() -} \ No newline at end of file diff --git a/tools/protostostruct.go b/tools/protostostruct.go index 724b9e6..3db1f23 100644 --- a/tools/protostostruct.go +++ b/tools/protostostruct.go @@ -14,7 +14,7 @@ var ( ProtoCode = "syntax = \"proto3\";\noption go_package = \"./pb;pb\";\n\npackage protocode;\n\nenum ProtoCode\n{\n UNKNOWN = 0x000;\n %s\n}" ProtoCodeLine = "\t%sRpc = %02x;\n" - GoProtoCodeStr = "package main\n\nimport (\n\t\"pro2d/protos/pb\"\n\t\"pro2d/src/components/logger\"\n\t\"pro2d/src/components/net\"\n)\n\nfunc LoadRpc() {\n\tlogger.Debug(\"init protocode...\")\n\tnet.ActionMap = make(map[pb.ProtoCode]net.ActionHandler)\n%s\n}\n\nfunc init() {\n\tLoadRpc()\n}" + GoProtoCodeStr = "package main\n\nimport (\n\t\"pro2d/protos/pb\"\n\t\"pro2d/src/components/logger\"\n\t\"pro2d/src/components/net\"\n)\n\nfunc init() {\n\tlogger.Debug(\"init protocode...\")\n\tnet.ActionMap = make(map[pb.ProtoCode]net.ActionHandler)\n\n%s\n}\n" GoProtoCodeLine = "\tnet.ActionMap[pb.ProtoCode_%sRpc] = %sRpc\n" ) -- libgit2 0.21.2