forked from bihua-university/alisten
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchat.go
More file actions
38 lines (34 loc) · 748 Bytes
/
chat.go
File metadata and controls
38 lines (34 loc) · 748 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package main
import (
"time"
"github.com/gin-gonic/gin"
)
func chat(c *Context) {
// 转发所有消息
msg := gin.H{
"type": "chat",
"nickName": c.conn.GetUser(),
"sendTime": c.data.Get("sendTime").Int(),
"content": c.data.Get("content").String(),
}
c.house.Broadcast(msg)
}
func (c *Context) Chat(msg string) {
h := gin.H{
"type": "chat",
"nickName": c.conn.GetUser(),
"sendTime": time.Now().UnixMilli(),
"content": msg,
}
c.house.Broadcast(h)
}
func setName(c *Context) {
c.conn.mu.Lock()
defer c.conn.mu.Unlock()
delay := c.Get("sendTime").Int() - time.Now().UnixMilli()
c.conn.user = c.data.Get("name").String() + "(" + c.conn.ip + ")"
c.conn.Send(gin.H{
"type": "delay",
"delay": delay,
})
}