Commit bca0b6f9ebe36234f503bec580fb46d861811ae5
1 parent
5d9cf01c
重新加载plugin server.LoadPlugin
Showing
3 changed files
with
5 additions
and
16 deletions
 
Show diff stats
src/components/net/server.go
| ... | ... | @@ -83,20 +83,12 @@ func (s *Server) OnClose(conn *Connection) { | 
| 83 | 83 | |
| 84 | 84 | func (s *Server) LoadPlugin() { | 
| 85 | 85 | //重新加载 | 
| 86 | - p, err:=plugin.Open(conf.GlobalConf.GameConf.PluginPath) | |
| 86 | + _, err:=plugin.Open(conf.GlobalConf.GameConf.PluginPath) | |
| 87 | 87 | if err != nil { | 
| 88 | 88 | logger.Error("load plugin err: %v", err) | 
| 89 | 89 | return | 
| 90 | 90 | } | 
| 91 | - symboll, err := p.Lookup("LoadRpc") | |
| 92 | - if err != nil { | |
| 93 | - logger.Error("plugin symbol err: %v", err) | |
| 94 | - return | |
| 95 | - } | |
| 96 | - if x, ok := symboll.(func()); ok { | |
| 97 | - x() | |
| 98 | - logger.Debug("load plugin success") | |
| 99 | - } | |
| 91 | + logger.Debug("load plugin success") | |
| 100 | 92 | } | 
| 101 | 93 | |
| 102 | 94 | func (s *Server)Start() error { | ... | ... | 
src/plugin/protocode.go
| ... | ... | @@ -6,15 +6,12 @@ import ( | 
| 6 | 6 | "pro2d/src/components/net" | 
| 7 | 7 | ) | 
| 8 | 8 | |
| 9 | -func LoadRpc() { | |
| 9 | +func init() { | |
| 10 | 10 | logger.Debug("init protocode...") | 
| 11 | 11 | net.ActionMap = make(map[pb.ProtoCode]net.ActionHandler) | 
| 12 | + | |
| 12 | 13 | net.ActionMap[pb.ProtoCode_HeartRpc] = HeartRpc | 
| 13 | 14 | net.ActionMap[pb.ProtoCode_LoginRpc] = LoginRpc | 
| 14 | 15 | net.ActionMap[pb.ProtoCode_CreateRpc] = CreateRpc | 
| 15 | 16 | |
| 16 | 17 | } | 
| 17 | - | |
| 18 | -func init() { | |
| 19 | - LoadRpc() | |
| 20 | -} | |
| 21 | 18 | \ No newline at end of file | ... | ... | 
tools/protostostruct.go
| ... | ... | @@ -14,7 +14,7 @@ var ( | 
| 14 | 14 | ProtoCode = "syntax = \"proto3\";\noption go_package = \"./pb;pb\";\n\npackage protocode;\n\nenum ProtoCode\n{\n UNKNOWN = 0x000;\n %s\n}" | 
| 15 | 15 | ProtoCodeLine = "\t%sRpc = %02x;\n" | 
| 16 | 16 | |
| 17 | - 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}" | |
| 17 | + 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" | |
| 18 | 18 | GoProtoCodeLine = "\tnet.ActionMap[pb.ProtoCode_%sRpc] = %sRpc\n" | 
| 19 | 19 | ) | 
| 20 | 20 | ... | ... |