Commit 3f0a1991fca052be37d14fa325a0e2297270d13b
1 parent
bca0b6f9
del test plugin
Showing
8 changed files
with
24 additions
and
52 deletions
Show diff stats
Makefile
@@ -17,6 +17,9 @@ build: | @@ -17,6 +17,9 @@ build: | ||
17 | go build -o bin/account cmd/http.go | 17 | go build -o bin/account cmd/http.go |
18 | go build -o bin/game cmd/game.go | 18 | go build -o bin/game cmd/game.go |
19 | go build -o bin/test test/client.go | 19 | go build -o bin/test test/client.go |
20 | +regame:plugin | ||
21 | + lsof -i:8849 | grep "game" | grep -v grep | awk '{print $$2}' | xargs -I {} kill -USR1 {} | ||
22 | + | ||
20 | plugin: | 23 | plugin: |
21 | #go build -ldflags -pluginpath="plugin/hot-1" --buildmode=plugin -o bin/plugin.so src/plugin/*.go | 24 | #go build -ldflags -pluginpath="plugin/hot-1" --buildmode=plugin -o bin/plugin.so src/plugin/*.go |
22 | go build --buildmode=plugin -o bin/$(pname) src/plugin/*.go | 25 | go build --buildmode=plugin -o bin/$(pname) src/plugin/*.go |
plugin/plugin.go deleted
plugin/plumain.go deleted
@@ -1,32 +0,0 @@ | @@ -1,32 +0,0 @@ | ||
1 | -package main | ||
2 | - | ||
3 | -import ( | ||
4 | - "fmt" | ||
5 | - "os" | ||
6 | - "plugin" | ||
7 | - "pro2d/src/components/net" | ||
8 | -) | ||
9 | - | ||
10 | -func main() { | ||
11 | - p, err := plugin.Open("./bin/plugin.so") | ||
12 | - if err != nil { | ||
13 | - fmt.Println("error open plugin: ", err) | ||
14 | - os.Exit(-1) | ||
15 | - } | ||
16 | - s, err := p.Lookup("IamPluginA") | ||
17 | - if err != nil { | ||
18 | - fmt.Println("error lookup IamPluginA: ", err) | ||
19 | - os.Exit(-1) | ||
20 | - } | ||
21 | - pkg1 := net.MsgPkg{ | ||
22 | - Head: &net.Head{ | ||
23 | - Length: 16, | ||
24 | - Cmd: 0, | ||
25 | - ErrCode: 0, | ||
26 | - }, | ||
27 | - } | ||
28 | - if x, ok := s.(func(net.MsgPkg)); ok { | ||
29 | - x(pkg1) | ||
30 | - } | ||
31 | - | ||
32 | -} |
src/actions/HttpAction.go
@@ -106,7 +106,11 @@ func (h *HttpAction) Start() error { | @@ -106,7 +106,11 @@ func (h *HttpAction) Start() error { | ||
106 | models.InitAccountServerModels() | 106 | models.InitAccountServerModels() |
107 | 107 | ||
108 | //Etcd 初始化 | 108 | //Etcd 初始化 |
109 | - h.EtcdClient = etcd.NewEtcdClient(conf.GlobalConf.Etcd) | 109 | + var err error |
110 | + h.EtcdClient, err = etcd.NewEtcdClient(conf.GlobalConf.Etcd) | ||
111 | + if err != nil { | ||
112 | + return err | ||
113 | + } | ||
110 | h.EtcdClient.PutWithLeasePrefix(conf.GlobalConf.AccountConf.Name, conf.GlobalConf.AccountConf.ID, fmt.Sprintf("%s:%d", conf.GlobalConf.AccountConf.IP, conf.GlobalConf.AccountConf.Port), 5) | 114 | h.EtcdClient.PutWithLeasePrefix(conf.GlobalConf.AccountConf.Name, conf.GlobalConf.AccountConf.ID, fmt.Sprintf("%s:%d", conf.GlobalConf.AccountConf.IP, conf.GlobalConf.AccountConf.Port), 5) |
111 | 115 | ||
112 | //gin初始化 | 116 | //gin初始化 |
src/components/etcd/etcd.go
@@ -13,18 +13,18 @@ type EtcdClient struct { | @@ -13,18 +13,18 @@ type EtcdClient struct { | ||
13 | etcd *clientv3.Client | 13 | etcd *clientv3.Client |
14 | } | 14 | } |
15 | 15 | ||
16 | -func NewEtcdClient(conf *conf.Etcd) *EtcdClient { | 16 | +func NewEtcdClient(conf *conf.Etcd) (*EtcdClient, error) { |
17 | cli, err := clientv3.New(clientv3.Config{ | 17 | cli, err := clientv3.New(clientv3.Config{ |
18 | Endpoints: conf.Endpoints, | 18 | Endpoints: conf.Endpoints, |
19 | DialTimeout: time.Duration(conf.DialTimeout) * time.Second, | 19 | DialTimeout: time.Duration(conf.DialTimeout) * time.Second, |
20 | }) | 20 | }) |
21 | if err != nil { | 21 | if err != nil { |
22 | logger.Error("etcd init err: %v", err) | 22 | logger.Error("etcd init err: %v", err) |
23 | - return nil | 23 | + return nil, err |
24 | } | 24 | } |
25 | return &EtcdClient{ | 25 | return &EtcdClient{ |
26 | etcd: cli, | 26 | etcd: cli, |
27 | - } | 27 | + }, nil |
28 | } | 28 | } |
29 | 29 | ||
30 | func (e *EtcdClient)PutWithPrefix(prefix, key, val string) { | 30 | func (e *EtcdClient)PutWithPrefix(prefix, key, val string) { |
src/components/etcd/etcd_test.go
@@ -11,7 +11,11 @@ import ( | @@ -11,7 +11,11 @@ import ( | ||
11 | ) | 11 | ) |
12 | 12 | ||
13 | func TestEtcdClient_GetByPrefix(t *testing.T) { | 13 | func TestEtcdClient_GetByPrefix(t *testing.T) { |
14 | - etcd := NewEtcdClient(conf.GlobalConf.Etcd) | 14 | + etcd, err := NewEtcdClient(conf.GlobalConf.Etcd) |
15 | + if err != nil { | ||
16 | + logger.Error(err) | ||
17 | + return | ||
18 | + } | ||
15 | gameInfo := etcd.GetByPrefix(conf.GlobalConf.AccountConf.Name) | 19 | gameInfo := etcd.GetByPrefix(conf.GlobalConf.AccountConf.Name) |
16 | for k, v := range gameInfo { | 20 | for k, v := range gameInfo { |
17 | logger.Debug("game info key: %v val: %v", k, v) | 21 | logger.Debug("game info key: %v val: %v", k, v) |
src/components/net/server.go
@@ -85,7 +85,7 @@ func (s *Server) LoadPlugin() { | @@ -85,7 +85,7 @@ func (s *Server) LoadPlugin() { | ||
85 | //重新加载 | 85 | //重新加载 |
86 | _, err:=plugin.Open(conf.GlobalConf.GameConf.PluginPath) | 86 | _, err:=plugin.Open(conf.GlobalConf.GameConf.PluginPath) |
87 | if err != nil { | 87 | if err != nil { |
88 | - logger.Error("load plugin err: %v", err) | 88 | + logger.Error("load plugin err: %v, %s", err, conf.GlobalConf.GameConf.PluginPath) |
89 | return | 89 | return |
90 | } | 90 | } |
91 | logger.Debug("load plugin success") | 91 | logger.Debug("load plugin success") |
@@ -97,11 +97,15 @@ func (s *Server)Start() error { | @@ -97,11 +97,15 @@ func (s *Server)Start() error { | ||
97 | models.InitGameServerModels() | 97 | models.InitGameServerModels() |
98 | 98 | ||
99 | //Etcd 初始化 | 99 | //Etcd 初始化 |
100 | - s.EtcdClient = etcd.NewEtcdClient(conf.GlobalConf.Etcd) | 100 | + var err error |
101 | + s.EtcdClient, err = etcd.NewEtcdClient(conf.GlobalConf.Etcd) | ||
102 | + if err != nil { | ||
103 | + return err | ||
104 | + } | ||
101 | s.EtcdClient.PutWithLeasePrefix(conf.GlobalConf.GameConf.Name, conf.GlobalConf.GameConf.ID, fmt.Sprintf("%s:%d", conf.GlobalConf.GameConf.IP, conf.GlobalConf.GameConf.Port), 5) | 105 | s.EtcdClient.PutWithLeasePrefix(conf.GlobalConf.GameConf.Name, conf.GlobalConf.GameConf.ID, fmt.Sprintf("%s:%d", conf.GlobalConf.GameConf.IP, conf.GlobalConf.GameConf.Port), 5) |
102 | 106 | ||
103 | //初始化plugin | 107 | //初始化plugin |
104 | - _, err := plugin.Open(conf.GlobalConf.GameConf.PluginPath) | 108 | + _, err = plugin.Open(conf.GlobalConf.GameConf.PluginPath) |
105 | if err != nil { | 109 | if err != nil { |
106 | return err | 110 | return err |
107 | } | 111 | } |
src/plugin/RolePlugin.go
@@ -34,7 +34,7 @@ func CreateRpc(msg *net.MsgPkg) (int32, proto.Message) { | @@ -34,7 +34,7 @@ func CreateRpc(msg *net.MsgPkg) (int32, proto.Message) { | ||
34 | } | 34 | } |
35 | 35 | ||
36 | func LoginRpc(msg *net.MsgPkg) (int32, proto.Message) { | 36 | func LoginRpc(msg *net.MsgPkg) (int32, proto.Message) { |
37 | - logger.Debug("cmd: %v, msg: %s", msg.Head.Cmd, msg.Body) | 37 | + //logger.Debug("cmd: %v, msg: %s", msg.Head.Cmd, msg.Body) |
38 | req := pb.LoginReq{} | 38 | req := pb.LoginReq{} |
39 | if err := proto.Unmarshal(msg.Body, &req); err != nil { | 39 | if err := proto.Unmarshal(msg.Body, &req); err != nil { |
40 | logger.Error("loginRpc err: %v", err) | 40 | logger.Error("loginRpc err: %v", err) |