-
Notifications
You must be signed in to change notification settings - Fork 1
/
Command.go
70 lines (62 loc) · 1.99 KB
/
Command.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package ipmsg
import (
"golang.org/x/text/encoding/simplifiedchinese"
"ipmsg/logger"
)
func NewCmdMap() (cmdMap map[CmdType]func(*IpMsg, *Package)) {
cmdMap = make(map[CmdType]func(*IpMsg, *Package))
cmdMap[IPMSG_BR_ENTRY] = OnIpMsgBrEntry
cmdMap[IPMSG_BR_EXIT] = OnIpMsgBrExit
cmdMap[IPMSG_ANSENTRY] = OnIpMsgAnsEntry
cmdMap[IPMSG_SENDMSG] = OnIpMsgSendMsg
cmdMap[IPMSG_RECVMSG] = OnIpMsgRecvMsg
cmdMap[IPMSG_NOOPERATION] = onIpMsgNoOperation
return cmdMap
}
func OnIpMsgBrEntry(im *IpMsg, pkg *Package) {
im.userManager.AddUser(pkg)
im.SendEntryAnswer(pkg.SenderAddr)
}
func OnIpMsgBrExit(im *IpMsg, pkg *Package) {
im.userManager.DelUser(pkg)
}
func OnIpMsgAnsEntry(im *IpMsg, pkg *Package) {
im.userManager.AddUser(pkg)
}
func OnIpMsgSendMsg(im *IpMsg, pkg *Package) {
var message string
if im.encoding == "gbk" {
message, _ = simplifiedchinese.GBK.NewDecoder().String(pkg.AdditionalSection)
} else {
message = pkg.AdditionalSection
}
logger.Info("new msg from [%s]# %s\n", pkg.SenderName, message)
if pkg.CheckFlag(IPMSG_SENDCHECKOPT) {
im.SendMessageReceived(pkg.SenderAddr, pkg.PacketNo)
}
if pkg.CheckFlag(IPMSG_SECRETEXOPT) {
im.SendMessageRead(pkg.SenderAddr, pkg.PacketNo)
}
if pkg.CheckFlag(IPMSG_FILEATTACHOPT) {
//char * p = ipMsg + strlen(ipMsg) + 1
////printf("filemsg=%s\n",p);
//char * fileopt = strtok(p, "\a") //fileopt指向第一个文件属性
//do{ //循环提取文件信息
// IPMSG_FILE, ftemp
// fmt.Sscanf(fileopt, "%d:%[^:]:%lx:%lx", &ftemp.PacketNo, ftemp.selfName, &ftemp.size, &ftemp.ltime)
// strcpy(ftemp.user, user.selfName)
// ftemp.pkgnum, = pkgnum
// add_file(ftemp, RECVFILE)
// fileopt = strtok(NULL, "\a") //fileopt指向下一个文件属性
//}
//while(fileopt != NULL)
//IPMSG_OUT_MSG_COLOR(
// printf("<<<Recv file from %s!>>>\n", user.selfName),
//)
}
}
func OnIpMsgRecvMsg(im *IpMsg, pkg *Package) {
logger.Info("[%s] have received your ipMsg!\n", pkg.SenderName)
}
func onIpMsgNoOperation(im *IpMsg, pkg *Package) {
}