-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprotocol.go
57 lines (47 loc) · 1.17 KB
/
protocol.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
package protocol
import (
"fmt"
"github.com/Schumix/semver"
"io"
"strconv"
)
var w io.Writer
func UseConn(_w io.Writer) {
w = _w
}
func SendPing() {
msg := strconv.Itoa(CMSG_PING) + PACKET_SEPARATOR
fmt.Fprint(w, msg)
}
func SendPong() {
msg := strconv.Itoa(CMSG_PONG) + PACKET_SEPARATOR
fmt.Fprint(w, msg)
}
func SendCloseSignal() {
msg := strconv.Itoa(CMSG_CLOSE_CONNECTION) + PACKET_SEPARATOR +
"uh. stomachache. shutting down for now." + PACKET_SEPARATOR
fmt.Fprint(w, msg)
}
func RegConnection() {
msg := strconv.Itoa(CMSG_REQUEST_AUTH) + PACKET_SEPARATOR +
"schumix webadmin (reg GUID)" + PACKET_SEPARATOR +
md5_gen("schumix") + PACKET_SEPARATOR
fmt.Fprint(w, msg)
}
func RequestVersion() {
msg := strconv.Itoa(CMSG_SCHUMIX_VERSION) + PACKET_SEPARATOR
fmt.Fprint(w, msg)
}
func CheckVersion(ver string) bool {
v1, _ := semver.New(MIN_SCHUMIX_VERSION)
v2, _ := semver.New(ver)
if v2.Compare(v1) == 0 || v2.Compare(v1) == 1 {
fmt.Println("Version check OK.")
fmt.Println("[VERSION] Webadmin:", VERSION, "Min Schumix:",
MIN_SCHUMIX_VERSION, "Schumix connected:", v2)
return true
} else {
fmt.Println("Schumix version is too low...")
}
return false
}