A few gaming features added, e.g. rolling dice, flipping coin, eightball.
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
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,
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user