mirror of
https://github.com/FrankerFaceZ/FrankerFaceZ.git
synced 2025-06-28 15:27:43 +00:00
Add ping command
This commit is contained in:
parent
30bc90b152
commit
7a6b9e66ab
1 changed files with 29 additions and 22 deletions
|
@ -22,6 +22,7 @@ type CommandHandler func(*websocket.Conn, *ClientInfo, ClientMessage) (ClientMes
|
||||||
|
|
||||||
var commandHandlers = map[Command]CommandHandler{
|
var commandHandlers = map[Command]CommandHandler{
|
||||||
HelloCommand: C2SHello,
|
HelloCommand: C2SHello,
|
||||||
|
"ping": C2SPing,
|
||||||
"setuser": C2SSetUser,
|
"setuser": C2SSetUser,
|
||||||
"ready": C2SReady,
|
"ready": C2SReady,
|
||||||
|
|
||||||
|
@ -120,6 +121,34 @@ func C2SHello(conn *websocket.Conn, client *ClientInfo, msg ClientMessage) (rmsg
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func C2SPing(conn *websocket.Conn, client *ClientInfo, msg ClientMessage) (rmsg ClientMessage, err error) {
|
||||||
|
return ClientMessage{
|
||||||
|
Arguments: float64(time.Now().UnixNano() / 1000) / 1000,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func C2SSetUser(conn *websocket.Conn, client *ClientInfo, msg ClientMessage) (rmsg ClientMessage, err error) {
|
||||||
|
username, err := msg.ArgumentsAsString()
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
client.Mutex.Lock()
|
||||||
|
client.TwitchUsername = username
|
||||||
|
client.UsernameValidated = false
|
||||||
|
client.Mutex.Unlock()
|
||||||
|
|
||||||
|
if Configuration.SendAuthToNewClients {
|
||||||
|
client.MsgChannelKeepalive.Add(1)
|
||||||
|
go client.StartAuthorization(func(_ *ClientInfo, _ bool) {
|
||||||
|
client.MsgChannelKeepalive.Done()
|
||||||
|
})
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return ResponseSuccess, nil
|
||||||
|
}
|
||||||
|
|
||||||
func C2SReady(conn *websocket.Conn, client *ClientInfo, msg ClientMessage) (rmsg ClientMessage, err error) {
|
func C2SReady(conn *websocket.Conn, client *ClientInfo, msg ClientMessage) (rmsg ClientMessage, err error) {
|
||||||
// disconnectAt, err := msg.ArgumentsAsInt()
|
// disconnectAt, err := msg.ArgumentsAsInt()
|
||||||
// if err != nil {
|
// if err != nil {
|
||||||
|
@ -150,28 +179,6 @@ func C2SReady(conn *websocket.Conn, client *ClientInfo, msg ClientMessage) (rmsg
|
||||||
return ClientMessage{Command: AsyncResponseCommand}, nil
|
return ClientMessage{Command: AsyncResponseCommand}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func C2SSetUser(conn *websocket.Conn, client *ClientInfo, msg ClientMessage) (rmsg ClientMessage, err error) {
|
|
||||||
username, err := msg.ArgumentsAsString()
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
client.Mutex.Lock()
|
|
||||||
client.TwitchUsername = username
|
|
||||||
client.UsernameValidated = false
|
|
||||||
client.Mutex.Unlock()
|
|
||||||
|
|
||||||
if Configuration.SendAuthToNewClients {
|
|
||||||
client.MsgChannelKeepalive.Add(1)
|
|
||||||
go client.StartAuthorization(func(_ *ClientInfo, _ bool) {
|
|
||||||
client.MsgChannelKeepalive.Done()
|
|
||||||
})
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
return ResponseSuccess, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func C2SSubscribe(conn *websocket.Conn, client *ClientInfo, msg ClientMessage) (rmsg ClientMessage, err error) {
|
func C2SSubscribe(conn *websocket.Conn, client *ClientInfo, msg ClientMessage) (rmsg ClientMessage, err error) {
|
||||||
channel, err := msg.ArgumentsAsString()
|
channel, err := msg.ArgumentsAsString()
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue