1
0
Fork 0
mirror of https://github.com/FrankerFaceZ/FrankerFaceZ.git synced 2025-07-03 17:48:30 +00:00

add hello error debugging, lock mutex during hello

This commit is contained in:
Kane York 2017-09-15 13:19:20 -07:00
parent f31a93f790
commit d254435173

View file

@ -110,44 +110,63 @@ func callHandler(handler CommandHandler, conn *websocket.Conn, client *ClientInf
return handler(conn, client, cmsg) return handler(conn, client, cmsg)
} }
var DebugHello = ""
// C2SHello implements the `hello` C2S Command. // C2SHello implements the `hello` C2S Command.
// It calls SubscribeGlobal() and SubscribeDefaults() with the client, and fills out ClientInfo.Version and ClientInfo.ClientID. // It calls SubscribeGlobal() and SubscribeDefaults() with the client, and fills out ClientInfo.Version and ClientInfo.ClientID.
func C2SHello(conn *websocket.Conn, client *ClientInfo, msg ClientMessage) (rmsg ClientMessage, err error) { func C2SHello(conn *websocket.Conn, client *ClientInfo, msg ClientMessage) (rmsg ClientMessage, err error) {
ary, ok := msg.Arguments.([]interface{}) ary, ok := msg.Arguments.([]interface{})
if !ok { if !ok {
if DebugHello != "" {
fmt.Println("Hello error: was not an array:", ary)
}
err = ErrExpectedTwoStrings err = ErrExpectedTwoStrings
return return
} }
if len(ary) != 2 { if len(ary) != 2 {
if DebugHello != "" {
fmt.Println("Hello error: array wrong length:", ary)
}
err = ErrExpectedTwoStrings err = ErrExpectedTwoStrings
return return
} }
version, ok := ary[0].(string) version, ok := ary[0].(string)
if !ok { if !ok {
if DebugHello != "" {
fmt.Println("Hello error: version not a string:", ary)
}
err = ErrExpectedTwoStrings err = ErrExpectedTwoStrings
return return
} }
var clientID uuid.UUID
if clientIDStr, ok := ary[1].(string); ok { if clientIDStr, ok := ary[1].(string); ok {
client.ClientID = uuid.FromStringOrNil(clientIDStr) clientID = uuid.FromStringOrNil(clientIDStr)
if client.ClientID == uuid.Nil { if clientID == uuid.Nil {
client.ClientID = uuid.NewV4() clientID = uuid.NewV4()
} }
} else if _, ok := ary[1].(bool); ok { } else if _, ok := ary[1].(bool); ok {
// opt out // opt out
client.ClientID = AnonymousClientID clientID = AnonymousClientID
} else if ary[1] == nil { } else if ary[1] == nil {
client.ClientID = uuid.NewV4() clientID = uuid.NewV4()
} else { } else {
if DebugHello != "" {
fmt.Println("Hello error: client id not acceptable:", ary)
}
err = ErrExpectedTwoStrings err = ErrExpectedTwoStrings
return return
} }
client.Mutex.Lock()
client.ClientID = clientID
client.VersionString = copyString(version) client.VersionString = copyString(version)
client.Version = VersionFromString(version) client.Version = VersionFromString(version)
uniqueUserChannel <- client.ClientID uniqueUserChannel <- client.ClientID
SubscribeGlobal(client)
client.HelloOK = true client.HelloOK = true
client.Mutex.Unlock()
SubscribeGlobal(client)
jsTime := float64(time.Now().UnixNano()/1000) / 1000 jsTime := float64(time.Now().UnixNano()/1000) / 1000
return ClientMessage{ return ClientMessage{