1
0
Fork 0
mirror of https://github.com/FrankerFaceZ/FrankerFaceZ.git synced 2025-07-01 08:38:32 +00:00

Add TwitchUsername to ClientInfo

This commit is contained in:
Kane York 2015-10-24 21:42:16 -07:00
parent 6681c1d64b
commit 9a1d1b720d
2 changed files with 24 additions and 12 deletions

View file

@ -5,8 +5,13 @@ import (
"log"
)
var EmptyClientMessage ClientMessage = ClientMessage{}
func HandleHello(conn *websocket.Conn, client *ClientInfo, msg ClientMessage) (rmsg ClientMessage, err error) {
version, clientId, err := msg.ArgumentsAsTwoStrings()
if err != nil {
return EmptyClientMessage, nil
}
client.Version = version
client.ClientID = uuid.FromStringOrNil(clientId)
@ -20,6 +25,7 @@ func HandleHello(conn *websocket.Conn, client *ClientInfo, msg ClientMessage) (r
}
func HandleSetUser(conn *websocket.Conn, client *ClientInfo, msg ClientMessage) (rmsg ClientMessage, err error) {
username, err := msg.ArgumentsAsString()
return ClientMessage{}, nil
}

View file

@ -53,6 +53,12 @@ type ClientInfo struct {
// If it seems to be a performance problem, we can split this.
Mutex sync.Mutex
// The client's claimed username on Twitch.
TwitchUsername string
// Whether or not the server has validated the client's claimed username.
UsernameValidated bool
// The list of chats this client is currently in.
// Protected by Mutex
CurrentChannels []string
@ -180,13 +186,11 @@ func HandleSocketConnection(conn *websocket.Conn) {
for {
select {
case err := <-errorChan:
// note - socket might not be open at this point
// don't care
FFZCodec.Send(conn, ClientMessage{
MessageID: -1,
Command: "error",
Arguments: err.Error(),
})
}) // note - socket might be closed, but don't care
break RunLoop
case msg := <-clientChan:
if client.Version == "" && msg.Command != HelloCommand {
@ -206,6 +210,8 @@ func HandleSocketConnection(conn *websocket.Conn) {
continue
}
log.Println(conn.RemoteAddr(), msg.MessageID, msg.Command, msg.Arguments)
client.Mutex.Lock()
response, err := CallHandler(handler, conn, &client, msg)
client.Mutex.Unlock()