diff --git a/Makefile b/Makefile index af08114..6b35c0d 100644 --- a/Makefile +++ b/Makefile @@ -17,6 +17,9 @@ build: go build -o bin/account cmd/http.go go build -o bin/game cmd/game.go go build -o bin/test test/client.go +regame:plugin + lsof -i:8849 | grep "game" | grep -v grep | awk '{print $$2}' | xargs -I {} kill -USR1 {} + plugin: #go build -ldflags -pluginpath="plugin/hot-1" --buildmode=plugin -o bin/plugin.so src/plugin/*.go go build --buildmode=plugin -o bin/$(pname) src/plugin/*.go diff --git a/plugin/plugin.go b/plugin/plugin.go deleted file mode 100644 index 638d61f..0000000 --- a/plugin/plugin.go +++ /dev/null @@ -1,11 +0,0 @@ -package main - -import ( - "fmt" - "pro2d/src/components/net" -) - -func IamPluginA(pkg net.MsgPkg) { - fmt.Println("Hello, I am PluginB!") - fmt.Println(pkg.Head.Length) -} diff --git a/plugin/plumain.go b/plugin/plumain.go deleted file mode 100644 index 31a0cac..0000000 --- a/plugin/plumain.go +++ /dev/null @@ -1,32 +0,0 @@ -package main - -import ( - "fmt" - "os" - "plugin" - "pro2d/src/components/net" -) - -func main() { - p, err := plugin.Open("./bin/plugin.so") - if err != nil { - fmt.Println("error open plugin: ", err) - os.Exit(-1) - } - s, err := p.Lookup("IamPluginA") - if err != nil { - fmt.Println("error lookup IamPluginA: ", err) - os.Exit(-1) - } - pkg1 := net.MsgPkg{ - Head: &net.Head{ - Length: 16, - Cmd: 0, - ErrCode: 0, - }, - } - if x, ok := s.(func(net.MsgPkg)); ok { - x(pkg1) - } - -} diff --git a/src/actions/HttpAction.go b/src/actions/HttpAction.go index 828b95b..32fc9d7 100644 --- a/src/actions/HttpAction.go +++ b/src/actions/HttpAction.go @@ -106,7 +106,11 @@ func (h *HttpAction) Start() error { models.InitAccountServerModels() //Etcd 初始化 - h.EtcdClient = etcd.NewEtcdClient(conf.GlobalConf.Etcd) + var err error + h.EtcdClient, err = etcd.NewEtcdClient(conf.GlobalConf.Etcd) + if err != nil { + return err + } h.EtcdClient.PutWithLeasePrefix(conf.GlobalConf.AccountConf.Name, conf.GlobalConf.AccountConf.ID, fmt.Sprintf("%s:%d", conf.GlobalConf.AccountConf.IP, conf.GlobalConf.AccountConf.Port), 5) //gin初始化 diff --git a/src/components/etcd/etcd.go b/src/components/etcd/etcd.go index 3fff95e..3c38570 100644 --- a/src/components/etcd/etcd.go +++ b/src/components/etcd/etcd.go @@ -13,18 +13,18 @@ type EtcdClient struct { etcd *clientv3.Client } -func NewEtcdClient(conf *conf.Etcd) *EtcdClient { +func NewEtcdClient(conf *conf.Etcd) (*EtcdClient, error) { cli, err := clientv3.New(clientv3.Config{ Endpoints: conf.Endpoints, DialTimeout: time.Duration(conf.DialTimeout) * time.Second, }) if err != nil { logger.Error("etcd init err: %v", err) - return nil + return nil, err } return &EtcdClient{ etcd: cli, - } + }, nil } func (e *EtcdClient)PutWithPrefix(prefix, key, val string) { diff --git a/src/components/etcd/etcd_test.go b/src/components/etcd/etcd_test.go index adbb3b5..a3c94cc 100644 --- a/src/components/etcd/etcd_test.go +++ b/src/components/etcd/etcd_test.go @@ -11,7 +11,11 @@ import ( ) func TestEtcdClient_GetByPrefix(t *testing.T) { - etcd := NewEtcdClient(conf.GlobalConf.Etcd) + etcd, err := NewEtcdClient(conf.GlobalConf.Etcd) + if err != nil { + logger.Error(err) + return + } gameInfo := etcd.GetByPrefix(conf.GlobalConf.AccountConf.Name) for k, v := range gameInfo { logger.Debug("game info key: %v val: %v", k, v) diff --git a/src/components/net/server.go b/src/components/net/server.go index 70466d6..5f0166d 100644 --- a/src/components/net/server.go +++ b/src/components/net/server.go @@ -85,7 +85,7 @@ func (s *Server) LoadPlugin() { //重新加载 _, err:=plugin.Open(conf.GlobalConf.GameConf.PluginPath) if err != nil { - logger.Error("load plugin err: %v", err) + logger.Error("load plugin err: %v, %s", err, conf.GlobalConf.GameConf.PluginPath) return } logger.Debug("load plugin success") @@ -97,11 +97,15 @@ func (s *Server)Start() error { models.InitGameServerModels() //Etcd 初始化 - s.EtcdClient = etcd.NewEtcdClient(conf.GlobalConf.Etcd) + var err error + s.EtcdClient, err = etcd.NewEtcdClient(conf.GlobalConf.Etcd) + if err != nil { + return err + } s.EtcdClient.PutWithLeasePrefix(conf.GlobalConf.GameConf.Name, conf.GlobalConf.GameConf.ID, fmt.Sprintf("%s:%d", conf.GlobalConf.GameConf.IP, conf.GlobalConf.GameConf.Port), 5) //初始化plugin - _, err := plugin.Open(conf.GlobalConf.GameConf.PluginPath) + _, err = plugin.Open(conf.GlobalConf.GameConf.PluginPath) if err != nil { return err } diff --git a/src/plugin/RolePlugin.go b/src/plugin/RolePlugin.go index face1ce..235d45f 100644 --- a/src/plugin/RolePlugin.go +++ b/src/plugin/RolePlugin.go @@ -34,7 +34,7 @@ func CreateRpc(msg *net.MsgPkg) (int32, proto.Message) { } func LoginRpc(msg *net.MsgPkg) (int32, proto.Message) { - logger.Debug("cmd: %v, msg: %s", msg.Head.Cmd, msg.Body) + //logger.Debug("cmd: %v, msg: %s", msg.Head.Cmd, msg.Body) req := pb.LoginReq{} if err := proto.Unmarshal(msg.Body, &req); err != nil { logger.Error("loginRpc err: %v", err) -- libgit2 0.21.2