33 lines
741 B
Go
33 lines
741 B
Go
package rtpconn
|
|
|
|
import (
|
|
"crypto/rand"
|
|
"encoding/base64"
|
|
"time"
|
|
|
|
"git.stormux.org/storm/skald/hall"
|
|
)
|
|
|
|
func isServerGeneratedChatKind(kind string) bool {
|
|
return kind == "dice" || kind == "eightball" || kind == "coin"
|
|
}
|
|
|
|
func broadcastServerChat(g *hall.Hall, name, kind, message string) error {
|
|
idBytes := make([]byte, 8)
|
|
if _, err := rand.Read(idBytes); err != nil {
|
|
return err
|
|
}
|
|
id := base64.RawURLEncoding.EncodeToString(idBytes)
|
|
now := time.Now()
|
|
g.AddToChatHistory(id, "", &name, now, kind, message)
|
|
return broadcast(g.GetClients(nil), clientMessage{
|
|
Type: "chat",
|
|
Id: id,
|
|
Username: &name,
|
|
Privileged: true,
|
|
Time: now.Format(time.RFC3339),
|
|
Kind: kind,
|
|
Value: message,
|
|
})
|
|
}
|