feat 稳定300人
This commit is contained in:
@@ -24,13 +24,13 @@ type Client struct {
|
||||
cancel context.CancelFunc // 取消上下文
|
||||
heartBeat time.Time // 最后一次心跳
|
||||
|
||||
UID int
|
||||
UID int32 // 用户ID
|
||||
SceneSID int64 // 场景服ID
|
||||
InstanceID int
|
||||
UniqueNo int64
|
||||
InstanceID int32 // 副本ID,副本类型
|
||||
UniqueNo int64 // 副本唯一编号
|
||||
}
|
||||
|
||||
func NewClient(uid int, conn socket.ISocketConn) *Client {
|
||||
func NewClient(uid int32, conn socket.ISocketConn) *Client {
|
||||
client := &Client{
|
||||
UID: uid,
|
||||
conn: conn,
|
||||
@@ -64,7 +64,7 @@ func (c *Client) Loop() {
|
||||
}
|
||||
case <-t.C:
|
||||
_ = c.conn.Ping()
|
||||
if time.Now().Sub(c.heartBeat) > 120*time.Second {
|
||||
if time.Now().Sub(c.heartBeat) > 60*time.Second {
|
||||
return
|
||||
}
|
||||
}
|
||||
@@ -86,6 +86,9 @@ func (c *Client) OnEvent(event Event) {
|
||||
|
||||
// WriteMessage 向客户端发送消息
|
||||
func (c *Client) WriteMessage(id sc_pb.MessageID, data proto.Message) {
|
||||
if c.conn.IsClose() {
|
||||
return
|
||||
}
|
||||
d, err := proto.Marshal(data)
|
||||
if err != nil {
|
||||
c.logger.Errorf("WriteMessage proto.Marshal err: %v", err)
|
||||
@@ -106,6 +109,9 @@ func (c *Client) WriteMessage(id sc_pb.MessageID, data proto.Message) {
|
||||
|
||||
// WriteBytes 向客户端发送字节数据
|
||||
func (c *Client) WriteBytes(id sc_pb.MessageID, data []byte) {
|
||||
if c.conn.IsClose() {
|
||||
return
|
||||
}
|
||||
m, err := proto.Marshal(&sc_pb.Message{
|
||||
ID: id,
|
||||
Payload: data,
|
||||
@@ -137,5 +143,6 @@ func (c *Client) onClose() {
|
||||
c.mailChan = nil
|
||||
}
|
||||
UserMgr.Delete(c.UID)
|
||||
c.onLeave()
|
||||
c.Done()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user