mirror of
https://github.com/FrankerFaceZ/FrankerFaceZ.git
synced 2025-07-01 16:48:32 +00:00
Add TwitchUsername to ClientInfo
This commit is contained in:
parent
6681c1d64b
commit
9a1d1b720d
2 changed files with 24 additions and 12 deletions
|
@ -5,8 +5,13 @@ import (
|
||||||
"log"
|
"log"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var EmptyClientMessage ClientMessage = ClientMessage{}
|
||||||
|
|
||||||
func HandleHello(conn *websocket.Conn, client *ClientInfo, msg ClientMessage) (rmsg ClientMessage, err error) {
|
func HandleHello(conn *websocket.Conn, client *ClientInfo, msg ClientMessage) (rmsg ClientMessage, err error) {
|
||||||
version, clientId, err := msg.ArgumentsAsTwoStrings()
|
version, clientId, err := msg.ArgumentsAsTwoStrings()
|
||||||
|
if err != nil {
|
||||||
|
return EmptyClientMessage, nil
|
||||||
|
}
|
||||||
|
|
||||||
client.Version = version
|
client.Version = version
|
||||||
client.ClientID = uuid.FromStringOrNil(clientId)
|
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) {
|
func HandleSetUser(conn *websocket.Conn, client *ClientInfo, msg ClientMessage) (rmsg ClientMessage, err error) {
|
||||||
|
username, err := msg.ArgumentsAsString()
|
||||||
|
|
||||||
return ClientMessage{}, nil
|
return ClientMessage{}, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,6 +53,12 @@ type ClientInfo struct {
|
||||||
// If it seems to be a performance problem, we can split this.
|
// If it seems to be a performance problem, we can split this.
|
||||||
Mutex sync.Mutex
|
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.
|
// The list of chats this client is currently in.
|
||||||
// Protected by Mutex
|
// Protected by Mutex
|
||||||
CurrentChannels []string
|
CurrentChannels []string
|
||||||
|
@ -180,13 +186,11 @@ func HandleSocketConnection(conn *websocket.Conn) {
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case err := <-errorChan:
|
case err := <-errorChan:
|
||||||
// note - socket might not be open at this point
|
|
||||||
// don't care
|
|
||||||
FFZCodec.Send(conn, ClientMessage{
|
FFZCodec.Send(conn, ClientMessage{
|
||||||
MessageID: -1,
|
MessageID: -1,
|
||||||
Command: "error",
|
Command: "error",
|
||||||
Arguments: err.Error(),
|
Arguments: err.Error(),
|
||||||
})
|
}) // note - socket might be closed, but don't care
|
||||||
break RunLoop
|
break RunLoop
|
||||||
case msg := <-clientChan:
|
case msg := <-clientChan:
|
||||||
if client.Version == "" && msg.Command != HelloCommand {
|
if client.Version == "" && msg.Command != HelloCommand {
|
||||||
|
@ -206,6 +210,8 @@ func HandleSocketConnection(conn *websocket.Conn) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log.Println(conn.RemoteAddr(), msg.MessageID, msg.Command, msg.Arguments)
|
||||||
|
|
||||||
client.Mutex.Lock()
|
client.Mutex.Lock()
|
||||||
response, err := CallHandler(handler, conn, &client, msg)
|
response, err := CallHandler(handler, conn, &client, msg)
|
||||||
client.Mutex.Unlock()
|
client.Mutex.Unlock()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue