fee11bff
zhangqijia
客户端无法使用grpc热更,不用g...
|
1
2
3
4
|
package net
import (
"fmt"
|
9644352a
zhangqijia
登录服改为http,游戏服改为长连...
|
5
|
"github.com/golang/protobuf/proto"
|
fee11bff
zhangqijia
客户端无法使用grpc热更,不用g...
|
6
|
"net"
|
9644352a
zhangqijia
登录服改为http,游戏服改为长连...
|
7
8
|
"pro2d/common"
"pro2d/components/db"
|
fee11bff
zhangqijia
客户端无法使用grpc热更,不用g...
|
9
|
"pro2d/conf"
|
9644352a
zhangqijia
登录服改为http,游戏服改为长连...
|
10
11
|
"pro2d/models"
"pro2d/protos/pb"
|
fee11bff
zhangqijia
客户端无法使用grpc热更,不用g...
|
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
"pro2d/utils"
"sync"
)
type Server struct {
SConf *conf.SConf
Clients *sync.Map
}
func NewServer(sConf *conf.SConf) *Server {
return &Server{
SConf: sConf,
Clients: new(sync.Map),
}
}
func (s *Server) OnRecv(msg *MsgPkg) {
utils.Sugar.Debugf("cmd: %d, data: %s", msg.Head.Cmd, msg.Body)
|
9644352a
zhangqijia
登录服改为http,游戏服改为长连...
|
31
32
33
34
35
36
37
38
39
40
41
|
if md, ok := common.ActionMap[pb.ProtoCode(msg.Head.Cmd)]; ok {
errCode, protomsg := md(msg)
rsp, err := proto.Marshal(protomsg)
if err != nil {
msg.Conn.SendMsgByCode(-100, msg.Head.Cmd, nil)
return
}
msg.Conn.SendMsgByCode(errCode, msg.Head.Cmd, rsp)
return
}
utils.Sugar.Errorf("protocode not handler: %d", msg.Head.Cmd)
|
fee11bff
zhangqijia
客户端无法使用grpc热更,不用g...
|
42
43
44
45
46
47
48
|
}
func (s *Server) OnClose(conn *Connection) {
s.Clients.Delete(conn.Id)
}
func (s *Server)Start() error {
|
9644352a
zhangqijia
登录服改为http,游戏服改为长连...
|
49
50
51
52
53
54
55
|
//mongo 初始化
db.MongoDatabase = db.MongoClient.Database(conf.GlobalConf.AccountConf.DBName)
models.InitGameServerModels()
//Etcd 初始化
conf.EtcdClient.PutWithLeasePrefix(conf.GlobalConf.GameConf.Name, conf.GlobalConf.GameConf.ID, fmt.Sprintf("%s:%d", conf.GlobalConf.GameConf.IP, conf.GlobalConf.GameConf.Port), 5)
|
fee11bff
zhangqijia
客户端无法使用grpc热更,不用g...
|
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
port := fmt.Sprintf(":%d", s.SConf.Port)
l, err := net.Listen("tcp", port)
if err != nil {
return err
}
utils.Sugar.Debugf("listen on %s\n", port)
id := 0
for {
conn, err := l.Accept()
if err != nil {
return err
}
id++
client := NewConn(id, conn, s)
s.Clients.Store(id, client)
go client.Start()
}
}
func (s *Server)Stop() {
}
|