-
Notifications
You must be signed in to change notification settings - Fork 1
/
event.go
53 lines (47 loc) · 1.35 KB
/
event.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
package whatsauth
import (
"database/sql"
"fmt"
"log"
"strings"
"github.com/whatsauth/watoken"
)
func EventReadSocket(roomId string, PublicKey string, usertables []LoginInfo, db *sql.DB) {
if roomId[0:1] == "v" {
phonenumber := watoken.DecodeGetId(PublicKey, roomId)
if phonenumber != "" {
infologin := GetLoginInfofromPhoneNumber(phonenumber, usertables, db)
infologin.Uuid = roomId
log.Println("Info Login EventReadSocket ", infologin)
SendStructTo(roomId, infologin)
} else {
fmt.Println("EventReadSocket: phonenumber is empty")
}
} else if roomId[0:1] == "g" {
token := strings.SplitN(roomId, ".", 3)
if len(token) < 3 {
return
}
phonenumber := watoken.DecodeGetId(PublicKey, token[2])
if phonenumber != "" {
infologin := GetRolesByPhonenumber(phonenumber, token[1], usertables, db)
infologin.Uuid = roomId
log.Println("Info Login EventReadSocket ", infologin)
SendStructTo(roomId, infologin)
} else {
fmt.Println("EventReadSocket: phonenumber is empty")
}
} else {
log.Println("EventReadSocket: roomId[0:1] != v ", roomId, PublicKey)
}
}
func KeyGenerator(roomId string, PublicKey string) {
if roomId[0:1] != "v" {
return
}
phonenumber := watoken.DecodeGetId(PublicKey, roomId)
if phonenumber != "" {
infologin := LoginInfo{Phone: phonenumber, Uuid: roomId}
SendStructTo(roomId, infologin)
}
}