-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
73 lines (57 loc) · 1.73 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package main
import (
"flag"
"net"
"github.com/sean0x42/mineshark/api"
"github.com/sean0x42/mineshark/api/websocket"
"github.com/sean0x42/mineshark/proxy"
log "github.com/sirupsen/logrus"
)
var connid = uint64(0)
var (
listenAddr *string = flag.String("l", "localhost:25566", "listen address")
serverAddr *string = flag.String("r", "localhost:25565", "server address")
disableWeb *bool = flag.Bool("no-web", false, "do not start the web interface")
)
func main() {
flag.Parse()
log.WithFields(log.Fields{
"listenAddr": *listenAddr,
"serverAddr": *serverAddr,
"webInterfaceEnabled": !*disableWeb,
}).Info("Welcome to Mineshark!")
var socketController *websocket.Controller
if !*disableWeb {
log.Info("Enabling web interface...")
socketController = websocket.NewController()
go api.StartHttpApi(socketController)
}
proxyAddr, err := net.ResolveTCPAddr("tcp", *listenAddr)
if err != nil {
log.Fatalf("Failed to resolve listen address: %s\n", err)
}
serverAddr, err := net.ResolveTCPAddr("tcp", *serverAddr)
if err != nil {
log.Fatalf("Failed to resolve server address: %s\n", err)
}
log.Info("Listening for TCP connections...")
listener, err := net.ListenTCP("tcp", proxyAddr)
if err != nil {
log.Fatalf("Failed to listen on port: %s\n", err)
}
proxyController := proxy.NewController(socketController)
for {
conn, err := listener.AcceptTCP()
if err != nil {
log.Printf("Failed to accept connection: %s\n", err)
continue
}
connid++
log.WithFields(log.Fields{
"id": connid,
"connectionAddr": conn.RemoteAddr().String(),
}).Info("Established a new proxy connection!")
prox := proxy.New(connid, proxyController, conn, proxyAddr, serverAddr)
go prox.Start()
}
}