2015-10-26 10:06:45 -07:00
|
|
|
package server
|
2015-10-26 10:07:15 -07:00
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"fmt"
|
|
|
|
"net/http"
|
|
|
|
)
|
|
|
|
|
2015-10-26 10:23:53 -07:00
|
|
|
type PushCommandCacheInfo struct {
|
|
|
|
Caching BacklogCacheType
|
|
|
|
Target MessageTargetType
|
|
|
|
}
|
|
|
|
|
2015-10-26 10:07:15 -07:00
|
|
|
// this value is just docs right now
|
2015-10-26 10:23:53 -07:00
|
|
|
var ServerInitiatedCommands = map[string]PushCommandCacheInfo{
|
2015-10-26 10:07:15 -07:00
|
|
|
/// Global updates & notices
|
2015-10-26 10:23:53 -07:00
|
|
|
"update_news": {CacheTypeTimestamps, MsgTargetTypeGlobal}, // timecache:global
|
|
|
|
"message": {CacheTypeTimestamps, MsgTargetTypeGlobal}, // timecache:global
|
|
|
|
"reload_ff": {CacheTypeTimestamps, MsgTargetTypeGlobal}, // timecache:global
|
2015-10-26 10:07:15 -07:00
|
|
|
|
|
|
|
/// Emote updates
|
2015-10-26 10:23:53 -07:00
|
|
|
"reload_badges": {CacheTypeTimestamps, MsgTargetTypeGlobal}, // timecache:global
|
|
|
|
"set_badge": {CacheTypeTimestamps, MsgTargetTypeMultichat}, // timecache:multichat
|
|
|
|
"reload_set": {CacheTypeTimestamps, MsgTargetTypeMultichat}, // timecache:multichat
|
|
|
|
"load_set": {}, // TODO what are the semantics of this?
|
2015-10-26 10:07:15 -07:00
|
|
|
|
|
|
|
/// User auth
|
2015-10-26 10:23:53 -07:00
|
|
|
"do_authorize": {CacheTypeNever, MsgTargetTypeSingle}, // nocache:single
|
2015-10-26 10:07:15 -07:00
|
|
|
|
|
|
|
/// Channel data
|
2015-10-26 10:23:53 -07:00
|
|
|
// follow_sets: extra emote sets included in the chat
|
|
|
|
// follow_buttons: extra follow buttons below the stream
|
|
|
|
"follow_sets": {CacheTypePersistent, MsgTargetTypeChat}, // mustcache:chat
|
|
|
|
"follow_buttons": {CacheTypePersistent, MsgTargetTypeWatching}, // mustcache:watching
|
|
|
|
"srl_race": {CacheTypeLastOnly, MsgTargetTypeWatching}, // cachelast:watching
|
2015-10-26 10:07:15 -07:00
|
|
|
|
|
|
|
/// Chatter/viewer counts
|
2015-10-26 10:23:53 -07:00
|
|
|
"chatters": {CacheTypeLastOnly, MsgTargetTypeWatching}, // cachelast:watching
|
|
|
|
"viewers": {CacheTypeLastOnly, MsgTargetTypeWatching}, // cachelast:watching
|
2015-10-26 10:07:15 -07:00
|
|
|
}
|
|
|
|
var _ = ServerInitiatedCommands
|
|
|
|
|
|
|
|
type BacklogCacheType int
|
|
|
|
|
|
|
|
const (
|
|
|
|
// This is not a cache type.
|
|
|
|
CacheTypeInvalid BacklogCacheType = iota
|
|
|
|
// This message cannot be cached.
|
|
|
|
CacheTypeNever
|
|
|
|
// Save the last 24 hours of this message.
|
|
|
|
// If a client indicates that it has reconnected, replay the messages sent after the disconnect.
|
|
|
|
CacheTypeTimestamps
|
|
|
|
// Save only the last copy of this message, and always send it when the backlog is requested.
|
|
|
|
CacheTypeLastOnly
|
|
|
|
// Save this backlog data to disk with its timestamp.
|
|
|
|
// Send it when the backlog is requested, or after a reconnect if it was updated.
|
|
|
|
CacheTypePersistent
|
|
|
|
)
|
|
|
|
|
|
|
|
type MessageTargetType int
|
|
|
|
|
|
|
|
const (
|
|
|
|
// This is not a message target.
|
|
|
|
MsgTargetTypeInvalid MessageTargetType = iota
|
|
|
|
// This message is targeted to a single TODO(user or connection)
|
|
|
|
MsgTargetTypeSingle
|
|
|
|
// This message is targeted to all users in a chat
|
|
|
|
MsgTargetTypeChat
|
|
|
|
// This message is targeted to all users in multiple chats
|
|
|
|
MsgTargetTypeMultichat
|
|
|
|
// This message is targeted to all users watching a stream
|
|
|
|
MsgTargetTypeWatching
|
|
|
|
// This message is sent to all FFZ users.
|
|
|
|
MsgTargetTypeGlobal
|
|
|
|
)
|
|
|
|
|
2015-10-26 10:23:53 -07:00
|
|
|
// note: see types.go for methods on these
|
|
|
|
|
2015-10-26 10:07:15 -07:00
|
|
|
// Returned by BacklogCacheType.UnmarshalJSON()
|
|
|
|
var ErrorUnrecognizedCacheType = errors.New("Invalid value for cachetype")
|
|
|
|
|
|
|
|
// Returned by MessageTargetType.UnmarshalJSON()
|
|
|
|
var ErrorUnrecognizedTargetType = errors.New("Invalid value for message target")
|
|
|
|
|
2015-10-26 10:23:53 -07:00
|
|
|
func HBackendUpdateAndPublish(w http.ResponseWriter, r *http.Request) {
|
2015-10-26 10:07:15 -07:00
|
|
|
formData, err := UnsealRequest(r.Form)
|
|
|
|
if err != nil {
|
|
|
|
w.WriteHeader(403)
|
|
|
|
fmt.Fprintf(w, "Error: %v", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2015-10-26 10:23:53 -07:00
|
|
|
cmd := formData.Get("command")
|
|
|
|
cacheinfo, ok := ServerInitiatedCommands[cmd]
|
|
|
|
if !ok {
|
|
|
|
w.WriteHeader(422)
|
|
|
|
}
|
2015-10-26 10:07:15 -07:00
|
|
|
}
|