Commit 028948855b57eb9a0e8e5c13ec375cf2adfbc6aa

Authored by zhangqijia
1 parent 81289393

fix: del etcd. add serverlist.yml

cmd/gameserver/service/game.go
1 1 package service
2 2  
3 3 import (
4   - "fmt"
5 4 "math/rand"
6 5 _ "net/http/pprof"
7 6 "pro2d/cmd/gameserver/action"
... ... @@ -12,8 +11,6 @@ import (
12 11 "pro2d/common/logger"
13 12 "pro2d/models"
14 13 "time"
15   -
16   - "pro2d/common/etcd"
17 14 )
18 15  
19 16 type GameServer struct {
... ... @@ -57,11 +54,11 @@ func NewGameServer() (*GameServer, error) {
57 54 }
58 55  
59 56 //Etcd 初始化
60   - err = etcd.NewEtcdClient(common.GlobalConf.Etcd)
61   - if err != nil {
62   - return nil, err
63   - }
64   - etcd.PutWithLeasePrefix(sconf.Name, fmt.Sprintf("%d", sconf.ID), fmt.Sprintf("%s:%d", sconf.IP, sconf.Port), 5)
  57 + //err = etcd.NewEtcdClient(common.GlobalConf.Etcd)
  58 + //if err != nil {
  59 + // return nil, err
  60 + //}
  61 + //etcd.PutWithLeasePrefix(sconf.Name, fmt.Sprintf("%d", sconf.ID), fmt.Sprintf("%s:%d", sconf.IP, sconf.Port), 5)
65 62  
66 63 //设置服务器ID & game
67 64 models.NewDBSeed(sconf.ID).InitServerDatabase(models.GameModels())
... ... @@ -92,7 +89,7 @@ func (s *GameServer) Stop() {
92 89  
93 90 mongoproxy.CloseMongo()
94 91 redisproxy.CloseRedis()
95   - etcd.CloseEtcd()
  92 + //etcd.CloseEtcd()
96 93 }
97 94  
98 95 func (s *GameServer) OnConnection(conn components.IConnection) {
... ...
cmd/httpserver/action/AccountAction.go
... ... @@ -8,7 +8,6 @@ import (
8 8 "pro2d/cmd/httpserver/service"
9 9 "pro2d/common"
10 10 "pro2d/common/db/redisproxy"
11   - "pro2d/common/etcd"
12 11 "pro2d/common/logger"
13 12 "pro2d/common/sms"
14 13 "pro2d/models"
... ... @@ -84,17 +83,9 @@ func (h *AccountAction) Login(c *gin.Context) (int, interface{}) {
84 83 return 3, "password error"
85 84 }
86 85  
87   - var gs []*pb.ServiceInfo
88   - for k, v := range etcd.GEtcdClient().GetByPrefix(common.GlobalConf.GameConf.Name) {
89   - gs = append(gs, &pb.ServiceInfo{
90   - Id: k,
91   - Name: common.GlobalConf.GameConf.Name,
92   - Address: v,
93   - })
94   - }
95 86 rsp := &pb.LoginRsp{
96 87 Token: account.Uid,
97   - GameService: gs,
  88 + GameService: common.GlobalConf.GameService.ServiceInfo,
98 89 }
99 90 return 0, rsp
100 91 }
... ...
cmd/httpserver/service/http.go
1 1 package service
2 2  
3 3 import (
4   - "fmt"
5 4 "math/rand"
6 5 "pro2d/common"
7 6 "pro2d/common/components"
8 7 "pro2d/common/db/mongoproxy"
9 8 "pro2d/common/db/redisproxy"
10   - "pro2d/common/etcd"
11 9 "pro2d/models"
12 10 "time"
13 11 )
... ... @@ -33,11 +31,11 @@ func (s *AccountServer) Init(sconf *common.SConf) error {
33 31 }
34 32  
35 33 //Etcd 初始化
36   - err = etcd.NewEtcdClient(common.GlobalConf.Etcd)
37   - if err != nil {
38   - return err
39   - }
40   - etcd.PutWithLeasePrefix(sconf.Name, fmt.Sprintf("%d", sconf.ID), fmt.Sprintf("%s:%d", sconf.IP, sconf.Port), 5)
  34 + //err = etcd.NewEtcdClient(common.GlobalConf.Etcd)
  35 + //if err != nil {
  36 + // return err
  37 + //}
  38 + //etcd.PutWithLeasePrefix(sconf.Name, fmt.Sprintf("%d", sconf.ID), fmt.Sprintf("%s:%d", sconf.IP, sconf.Port), 5)
41 39  
42 40 models.NewDBSeed(sconf.ID).InitServerDatabase(models.AccountModels())
43 41 models.DBSeedS().InitAutoIncreUidTable(models.AccountModels())
... ... @@ -64,5 +62,5 @@ func (s *AccountServer) Start() error {
64 62  
65 63 func (s *AccountServer) Stop() {
66 64 s.IHttp.Stop()
67   - etcd.CloseEtcd()
  65 + //etcd.CloseEtcd()
68 66 }
... ...
common/conf.go
... ... @@ -6,7 +6,7 @@ import (
6 6 "gopkg.in/yaml.v3"
7 7 "io/ioutil"
8 8 "pro2d/common/logger"
9   - "pro2d/common/snow"
  9 + "pro2d/pb"
10 10 "strings"
11 11 )
12 12  
... ... @@ -81,6 +81,10 @@ type TestClient struct {
81 81 Count int `yaml:"count"`
82 82 }
83 83  
  84 +type GameService struct {
  85 + ServiceInfo []*pb.ServiceInfo `yaml:"server_list"`
  86 +}
  87 +
84 88 type ServerConf struct {
85 89 ID string `yaml:"id"`
86 90 Name string `yaml:"name"`
... ... @@ -90,24 +94,38 @@ type ServerConf struct {
90 94 GameConf *SConf `yaml:"server_game"`
91 95 LogConf *LogConf `yaml:"logconf" json:"logconf"`
92 96 TestClient *TestClient `yaml:"test_client"`
93   - Etcd *Etcd `yaml:"etcd"`
  97 + //Etcd *Etcd `yaml:"etcd"`
  98 + GameService *GameService `yaml:"server_list"`
94 99 }
95 100  
96 101 var (
97 102 GlobalConf ServerConf
98 103 GlobalSconf *SConf
99   - SnowFlack *snow.Snowflake
  104 + //SnowFlack *snow.Snowflake
100 105 )
101 106  
102 107 func init() {
103   - configFile, err := ioutil.ReadFile("conf/conf.yaml")
  108 + configFile, err := ioutil.ReadFile("conf/conf.yml")
  109 + if err != nil {
  110 + fmt.Printf("conf read faild: %v", err)
  111 + return
  112 + }
  113 +
  114 + servList, err := ioutil.ReadFile("conf/serverlist.yml")
104 115 if err != nil {
105   - fmt.Printf("conf faild: %v", err)
  116 + fmt.Printf("serverlist read faild: %v\n", err)
106 117 return
107 118 }
  119 +
108 120 //初始化配置
109 121 if err = yaml.Unmarshal(configFile, &GlobalConf); err != nil {
110   - fmt.Printf("yaml unmarshal faild: %v", err)
  122 + fmt.Printf("config.yml unmarshal faild: %v\n", err)
  123 + return
  124 + }
  125 +
  126 + //游戏服务列表
  127 + if err = yaml.Unmarshal(servList, &GlobalConf.GameService); err != nil {
  128 + fmt.Printf("serverlist.yml unmarshal faild: %v\n", err)
111 129 return
112 130 }
113 131  
... ... @@ -124,5 +142,5 @@ func init() {
124 142 }
125 143  
126 144 //初始化雪花算法
127   - SnowFlack = snow.NewSnowflake(GlobalConf.WorkerID, GlobalConf.DatacenterID)
  145 + //SnowFlack = snow.NewSnowflake(GlobalConf.WorkerID, GlobalConf.DatacenterID)
128 146 }
... ...
conf/conf.yaml renamed to conf/conf.yml
... ... @@ -15,10 +15,10 @@ redis: &default-redis
15 15 address: "192.168.0.100:6100"
16 16 auth: ""
17 17  
18   -etcd:
19   - dialtimeout: 5
20   - endpoints:
21   - - "192.168.0.100:2379"
  18 +#etcd:
  19 +# dialtimeout: 5
  20 +# endpoints:
  21 +# - "192.168.0.100:2379"
22 22  
23 23 server_account:
24 24 id: 1
... ... @@ -28,7 +28,7 @@ server_account:
28 28 pool_size: 1
29 29 debugport: 6062
30 30 mongo:
31   - <<: *default-mongo
  31 + <<: *default-mongo
32 32 dbname: "account"
33 33 redis:
34 34 <<: *default-redis
... ... @@ -51,27 +51,6 @@ server_game:
51 51 <<: *default-redis
52 52 db: 0
53 53  
54   -server_game1:
55   - id: 2
56   - name: "game"
57   - ip: "192.168.0.206"
58   - encipher: false
59   - port: 8850
60   - debugport: 6061
61   - gm: 8881
62   - pool_size: 1
63   - plugin_path: "./bin/plugin.so"
64   - mongo:
65   - <<: *default-mongo
66   - dbname: "game"
67   - redis:
68   - <<: *default-redis
69   - db: 0
70   -test_client:
71   - ip: "192.168.0.100"
72   - port: 8849
73   - count: 1
74   -
75 54 logconf:
76 55 TimeFormat: "2006-01-02 15:04:05"
77 56 Console:
... ...
conf/serverlist.yml 0 → 100644
... ... @@ -0,0 +1,11 @@
  1 +server_list:
  2 + - id: "1"
  3 + name: "似海浮沉"
  4 + address: "47.118.38.251"
  5 + game_port: 8849
  6 + gm_port: 8880
  7 + - id: "2"
  8 + name: "西风一年"
  9 + address: "192.168.0.100"
  10 + game_port: 8849
  11 + gm_port: 8880
0 12 \ No newline at end of file
... ...
docker/Dockerfile
... ... @@ -19,7 +19,8 @@ WORKDIR /data
19 19 COPY --from=0 /usr/local/bin/http .
20 20 COPY --from=0 /usr/local/bin/game .
21 21 COPY csvdata/data ./csvdata/data
22   -COPY ./docker/conf.yaml ./conf/
  22 +COPY ./docker/conf.yml ./conf/
  23 +COPY ./docker/serverlist.yml ./conf/
23 24  
24 25  
25 26 RUN mkdir -p /data/logs && \
... ...
docker/conf.yaml renamed to docker/conf.yml
... ... @@ -23,7 +23,7 @@ etcd:
23 23 server_account:
24 24 id: 1
25 25 name: "account"
26   - ip: "192.168.0.100"
  26 + ip: "47.118.38.251"
27 27 port: 8080
28 28 pool_size: 1
29 29 debugport: 6060
... ... @@ -37,7 +37,7 @@ server_account:
37 37 server_game:
38 38 id: 1
39 39 name: "game"
40   - ip: "192.168.0.100"
  40 + ip: "47.118.38.251"
41 41 encipher: false
42 42 port: 8849
43 43 debugport: 6060
... ...
docker/docker-compose.yml
... ... @@ -14,12 +14,12 @@ services:
14 14 - ./.docker/mongo.conf:/data/mongo.conf
15 15 # command: --config /data/mongo.conf # 配置文件
16 16 command: [--auth] # 配置文件
17   - etcd:
18   - image: xieyanze/etcd3
19   - container_name: etcd3-pro2d
20   - restart: always
21   - ports:
22   - - '2379:2379'
  17 +# etcd:
  18 +# image: xieyanze/etcd3
  19 +# container_name: etcd3-pro2d
  20 +# restart: always
  21 +# ports:
  22 +# - '2379:2379'
23 23 redis:
24 24 image: redis:latest
25 25 container_name: redis-pro2d
... ... @@ -38,7 +38,7 @@ services:
38 38 - '6061:6060' #debug
39 39 volumes:
40 40 - ./.docker/account_logs:/data/logs
41   - - ./conf.yaml:/data/conf/conf.yaml
  41 + - ./conf.yml:/data/conf/conf.yml
42 42 working_dir: /data
43 43 command: [./http]
44 44 game:
... ... @@ -51,6 +51,6 @@ services:
51 51 - '8880:8880' #gm
52 52 volumes:
53 53 - ./.docker/game_logs:/data/logs
54   - - ./conf.yaml:/data/conf/conf.yaml
  54 + - ./conf.yml:/data/conf/conf.yml
55 55 working_dir: /data
56 56 command: [./game]
... ...
docker/serverlist.yml 0 → 100644
... ... @@ -0,0 +1,11 @@
  1 +server_list:
  2 + - id: "1"
  3 + name: "似海浮沉"
  4 + address: "47.118.38.251"
  5 + game_port: 8849
  6 + gm_port: 8880
  7 + - id: "2"
  8 + name: "西风一年"
  9 + address: "192.168.0.100"
  10 + game_port: 8849
  11 + gm_port: 8880
0 12 \ No newline at end of file
... ...
pb/account.pb.go
... ... @@ -25,9 +25,11 @@ type ServiceInfo struct {
25 25 sizeCache protoimpl.SizeCache
26 26 unknownFields protoimpl.UnknownFields
27 27  
28   - Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"`
29   - Name string `protobuf:"bytes,2,opt,name=name,proto3" json:"name,omitempty"`
30   - Address string `protobuf:"bytes,3,opt,name=address,proto3" json:"address,omitempty"`
  28 + Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"`
  29 + Name string `protobuf:"bytes,2,opt,name=name,proto3" json:"name,omitempty"`
  30 + Address string `protobuf:"bytes,3,opt,name=address,proto3" json:"address,omitempty"`
  31 + GamePort int32 `protobuf:"varint,4,opt,name=game_port,json=gamePort,proto3" json:"game_port,omitempty"`
  32 + GmPort int32 `protobuf:"varint,5,opt,name=gm_port,json=gmPort,proto3" json:"gm_port,omitempty"`
31 33 }
32 34  
33 35 func (x *ServiceInfo) Reset() {
... ... @@ -83,6 +85,20 @@ func (x *ServiceInfo) GetAddress() string {
83 85 return ""
84 86 }
85 87  
  88 +func (x *ServiceInfo) GetGamePort() int32 {
  89 + if x != nil {
  90 + return x.GamePort
  91 + }
  92 + return 0
  93 +}
  94 +
  95 +func (x *ServiceInfo) GetGmPort() int32 {
  96 + if x != nil {
  97 + return x.GmPort
  98 + }
  99 + return 0
  100 +}
  101 +
86 102 type LoginRsp struct {
87 103 state protoimpl.MessageState
88 104 sizeCache protoimpl.SizeCache
... ... @@ -205,24 +221,27 @@ var File_account_proto protoreflect.FileDescriptor
205 221  
206 222 var file_account_proto_rawDesc = []byte{
207 223 0x0a, 0x0d, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12,
208   - 0x07, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x22, 0x4b, 0x0a, 0x0b, 0x53, 0x65, 0x72, 0x76,
209   - 0x69, 0x63, 0x65, 0x49, 0x6e, 0x66, 0x6f, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20,
210   - 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18,
211   - 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x61,
212   - 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x61, 0x64,
213   - 0x64, 0x72, 0x65, 0x73, 0x73, 0x22, 0x59, 0x0a, 0x08, 0x4c, 0x6f, 0x67, 0x69, 0x6e, 0x52, 0x73,
214   - 0x70, 0x12, 0x14, 0x0a, 0x05, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09,
215   - 0x52, 0x05, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x12, 0x37, 0x0a, 0x0c, 0x67, 0x61, 0x6d, 0x65, 0x5f,
216   - 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x18, 0x02, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x14, 0x2e,
217   - 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x2e, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x49,
218   - 0x6e, 0x66, 0x6f, 0x52, 0x0b, 0x67, 0x61, 0x6d, 0x65, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65,
219   - 0x22, 0x50, 0x0a, 0x08, 0x52, 0x65, 0x67, 0x69, 0x73, 0x74, 0x65, 0x72, 0x12, 0x14, 0x0a, 0x05,
220   - 0x70, 0x68, 0x6f, 0x6e, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x70, 0x68, 0x6f,
221   - 0x6e, 0x65, 0x12, 0x1a, 0x0a, 0x08, 0x70, 0x61, 0x73, 0x73, 0x77, 0x6f, 0x72, 0x64, 0x18, 0x02,
222   - 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x70, 0x61, 0x73, 0x73, 0x77, 0x6f, 0x72, 0x64, 0x12, 0x12,
223   - 0x0a, 0x04, 0x63, 0x6f, 0x64, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x63, 0x6f,
224   - 0x64, 0x65, 0x42, 0x0a, 0x5a, 0x08, 0x2e, 0x2e, 0x2f, 0x70, 0x62, 0x3b, 0x70, 0x62, 0x62, 0x06,
225   - 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
  224 + 0x07, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x22, 0x81, 0x01, 0x0a, 0x0b, 0x53, 0x65, 0x72,
  225 + 0x76, 0x69, 0x63, 0x65, 0x49, 0x6e, 0x66, 0x6f, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01,
  226 + 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65,
  227 + 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x18, 0x0a, 0x07,
  228 + 0x61, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x61,
  229 + 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x12, 0x1b, 0x0a, 0x09, 0x67, 0x61, 0x6d, 0x65, 0x5f, 0x70,
  230 + 0x6f, 0x72, 0x74, 0x18, 0x04, 0x20, 0x01, 0x28, 0x05, 0x52, 0x08, 0x67, 0x61, 0x6d, 0x65, 0x50,
  231 + 0x6f, 0x72, 0x74, 0x12, 0x17, 0x0a, 0x07, 0x67, 0x6d, 0x5f, 0x70, 0x6f, 0x72, 0x74, 0x18, 0x05,
  232 + 0x20, 0x01, 0x28, 0x05, 0x52, 0x06, 0x67, 0x6d, 0x50, 0x6f, 0x72, 0x74, 0x22, 0x59, 0x0a, 0x08,
  233 + 0x4c, 0x6f, 0x67, 0x69, 0x6e, 0x52, 0x73, 0x70, 0x12, 0x14, 0x0a, 0x05, 0x74, 0x6f, 0x6b, 0x65,
  234 + 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x12, 0x37,
  235 + 0x0a, 0x0c, 0x67, 0x61, 0x6d, 0x65, 0x5f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x18, 0x02,
  236 + 0x20, 0x03, 0x28, 0x0b, 0x32, 0x14, 0x2e, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x2e, 0x53,
  237 + 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x0b, 0x67, 0x61, 0x6d, 0x65,
  238 + 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x22, 0x50, 0x0a, 0x08, 0x52, 0x65, 0x67, 0x69, 0x73,
  239 + 0x74, 0x65, 0x72, 0x12, 0x14, 0x0a, 0x05, 0x70, 0x68, 0x6f, 0x6e, 0x65, 0x18, 0x01, 0x20, 0x01,
  240 + 0x28, 0x09, 0x52, 0x05, 0x70, 0x68, 0x6f, 0x6e, 0x65, 0x12, 0x1a, 0x0a, 0x08, 0x70, 0x61, 0x73,
  241 + 0x73, 0x77, 0x6f, 0x72, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x70, 0x61, 0x73,
  242 + 0x73, 0x77, 0x6f, 0x72, 0x64, 0x12, 0x12, 0x0a, 0x04, 0x63, 0x6f, 0x64, 0x65, 0x18, 0x03, 0x20,
  243 + 0x01, 0x28, 0x09, 0x52, 0x04, 0x63, 0x6f, 0x64, 0x65, 0x42, 0x0a, 0x5a, 0x08, 0x2e, 0x2e, 0x2f,
  244 + 0x70, 0x62, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
226 245 }
227 246  
228 247 var (
... ...
pb/models.pb.go
... ... @@ -94,7 +94,7 @@ type Hero struct {
94 94 Level int32 `protobuf:"varint,4,opt,name=level,proto3" json:"level,omitempty"`
95 95 ReinCount int32 `protobuf:"varint,5,opt,name=rein_count,json=reinCount,proto3" json:"rein_count,omitempty"`
96 96 ReinPoint int32 `protobuf:"varint,6,opt,name=rein_point,json=reinPoint,proto3" json:"rein_point,omitempty"`
97   - Equipments string `protobuf:"bytes,7,opt,name=equipments,proto3" json:"equipments,omitempty"` //"id=type id1=type1"
  97 + Equipments string `protobuf:"bytes,7,opt,name=equipments,proto3" json:"equipments,omitempty"` //"id=tb_id id1=tb_id1"
98 98 Exp int32 `protobuf:"varint,8,opt,name=exp,proto3" json:"exp,omitempty"`
99 99 }
100 100  
... ...
1   -Subproject commit a1d159bdae5ffc9b49220ec8f20ff3f6649cc349
  1 +Subproject commit b89856524155c49f2aa3c598e2d39b7b38e94c5d
... ...