-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
58 lines (52 loc) · 1.03 KB
/
main.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
package main
import (
"encoding/json"
"errors"
"fmt"
"github.com/KrxkGit/CrackMM/handlers"
"log"
"net"
"os"
)
type Setting struct {
Addr string `json:"Addr"`
Port string `json:"Port"`
}
func main() {
fmt.Println("Welcome to Use CrackMM.\nKrxk Copyright.")
setting := new(Setting)
readSettings(setting)
fmt.Printf("Listen at %s:%s\n", setting.Addr, setting.Port)
l, err := net.Listen("tcp", fmt.Sprintf("%s:%s", setting.Addr, setting.Port))
defer l.Close()
if err != nil {
log.Println(err.Error())
}
for {
conn, err := l.Accept()
if err != nil {
log.Println(err.Error())
}
go handlers.HandleRegister(conn)
}
}
func readSettings(setting *Setting) {
filePath := "setting.json"
if fi, err := os.Stat(filePath); err == nil {
file, err := os.Open(filePath)
if err != nil {
panic(err)
}
buf := make([]byte, fi.Size())
_, err = file.Read(buf)
if err != nil {
panic(err)
}
err = json.Unmarshal(buf, setting)
if err != nil {
panic(err)
}
return
}
panic(errors.New("cannot find setting file"))
}