|
@ -4,8 +4,8 @@ import ( |
|
|
"encoding/json" |
|
|
"encoding/json" |
|
|
"errors" |
|
|
"errors" |
|
|
"fmt" |
|
|
"fmt" |
|
|
|
|
|
"github.com/rs/zerolog/log" |
|
|
"gopkg.in/olahol/melody.v1" |
|
|
"gopkg.in/olahol/melody.v1" |
|
|
"hudongzhuanjia/logger" |
|
|
|
|
|
"strings" |
|
|
"strings" |
|
|
"sync" |
|
|
"sync" |
|
|
) |
|
|
) |
|
@ -48,7 +48,7 @@ func NewNode() *Node { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func (t *Node) handleMelodyConnect(client *Client) { |
|
|
func (t *Node) handleMelodyConnect(client *Client) { |
|
|
logger.Sugar.Infof("[websocket] [connect] [room:%s] [client:%s] %s", client.RoomId, client.Id, client.Request.URL) |
|
|
|
|
|
|
|
|
log.Printf("[websocket] [connect] [room:%s] [client:%s] %s\n", client.RoomId, client.Id, client.Request.URL) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// 处理msg
|
|
|
// 处理msg
|
|
@ -61,7 +61,7 @@ func (t *Node) handleMelodyMessage(client *Client, msg *Message) { |
|
|
if fn, ok := t.handles[msg.Type]; ok { |
|
|
if fn, ok := t.handles[msg.Type]; ok { |
|
|
fn(client, msg) |
|
|
fn(client, msg) |
|
|
} |
|
|
} |
|
|
logger.Sugar.Infof("[websocket] [message] [room:%s] [client:%s] %v", client.RoomId, client.Id, msg) |
|
|
|
|
|
|
|
|
log.Printf("[websocket] [message] [room:%s] [client:%s] %v\n", client.RoomId, client.Id, msg) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// 删掉注册的
|
|
|
// 删掉注册的
|
|
@ -102,7 +102,7 @@ func (t *Node) handleMelodyDisconnect(client *Client) { |
|
|
t.DeleteRoom(room.Id) |
|
|
t.DeleteRoom(room.Id) |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
logger.Sugar.Infof("[websocket] [disconnect] [room:%s] [client:%s] online=>%v", client.RoomId, client.Id, client.Online) |
|
|
|
|
|
|
|
|
log.Printf("[websocket] [disconnect] [room:%s] [client:%s] online=>%v\n", client.RoomId, client.Id, client.Online) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func (t *Node) RegisterLogic(name string, fn logic) { |
|
|
func (t *Node) RegisterLogic(name string, fn logic) { |
|
@ -143,7 +143,7 @@ func (t *Node) Send(msg *Message) { |
|
|
} else if msg.Dest != 0 && msg.Tag != "" { |
|
|
} else if msg.Dest != 0 && msg.Tag != "" { |
|
|
t.BroadcastDest(msg) |
|
|
t.BroadcastDest(msg) |
|
|
} else { |
|
|
} else { |
|
|
logger.Sugar.Infof("[websocket] [send] msg=>%v", msg) |
|
|
|
|
|
|
|
|
log.Printf("[websocket] [send] msg=>%v", msg) |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|