forked from aler9/dctk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
chat.go
41 lines (35 loc) · 1.13 KB
/
chat.go
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
39
40
41
package dctoolkit
// MessagePublic publishes a message in the hub public chat.
func (c *Client) MessagePublic(content string) {
if c.protoIsAdc == true {
c.connHub.conn.Write(&msgAdcBMessage{
msgAdcTypeB{c.sessionId},
msgAdcKeyMessage{Content: content},
})
} else {
c.connHub.conn.Write(&msgNmdcPublicChat{c.conf.Nick, content})
}
}
// MessagePrivate sends a private message to a specific peer connected to the hub.
func (c *Client) MessagePrivate(dest *Peer, content string) {
if c.protoIsAdc == true {
c.connHub.conn.Write(&msgAdcDMessage{
msgAdcTypeD{c.sessionId, dest.adcSessionId},
msgAdcKeyMessage{Content: content},
})
} else {
c.connHub.conn.Write(&msgNmdcPrivateChat{c.conf.Nick, dest.Nick, content})
}
}
func (c *Client) handlePublicMessage(author *Peer, content string) {
dolog(LevelInfo, "[PUB] <%s> %s", author.Nick, content)
if c.OnMessagePublic != nil {
c.OnMessagePublic(author, content)
}
}
func (c *Client) handlePrivateMessage(author *Peer, content string) {
dolog(LevelInfo, "[PRIV] <%s> %s", author.Nick, content)
if c.OnMessagePrivate != nil {
c.OnMessagePrivate(author, content)
}
}