Browse Source

fix:bug

dev
Tooooommy 4 years ago
parent
commit
3ab4290678
  1. BIN
      hdws/main_2
  2. 7
      hdws/ws/login.go
  3. 11
      hdws/ws/ping.go
  4. 8
      hdws/ws/ws.go

BIN
hdws/main_2

7
hdws/ws/login.go

@ -4,6 +4,7 @@ import (
"fmt"
"hudongzhuanjia/models"
"hudongzhuanjia/utils"
"strconv"
)
func init() {
@ -15,8 +16,12 @@ func LoginMid(c *Client, msg *Message) {
var token string
var ok bool
if token, ok = msg.Data["token"].(string); !ok || token == "" {
c.Online = true
if signerId, ok := msg.Data["signer_id"]; ok {
c.AccountId, _ = strconv.Atoi(signerId.(string))
} else {
c.AccountId = utils.RandomInt(6)
}
c.Online = true
c.AccountType = "guest"
c.Id = fmt.Sprintf("%s:%d", c.AccountType, c.AccountId)
} else {

11
hdws/ws/ping.go

@ -0,0 +1,11 @@
package ws
func init() {
N.SetMiddleware("ping", pingFunc)
}
func pingFunc(c *Client, msg *Message) {
if _, ok := msg.Data["id"].(string); ok {
c.WriteJson(msg)
}
}

8
hdws/ws/ws.go

@ -27,8 +27,12 @@ func (ws *WsCtl) HandleConnect(s *melody.Session) {
}
client := NewClient(s, ws.node, roomId)
token := query.Get("token")
LoginMid(client, &Message{Data: map[string]interface{}{"token": token}}) // 登录设置
var res = map[string]interface{}{}
for k, v := range query {
res[k] = v[0]
}
LoginMid(client, &Message{Data: res}) // 登录设置
ws.node.conns[s] = client
ws.node.handleMelodyConnect(client)
}

Loading…
Cancel
Save