-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
77 lines (62 loc) · 1.48 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
74
75
76
77
package main
import (
"encoding/base64"
"flag"
"log"
"strings"
irc "github.com/thoj/go-ircevent"
"github.com/songgao/water"
)
func main() {
channel := flag.String("channel", "#ipircdata", "")
nick := flag.String("nick", "owo", "")
addr := flag.String("connect", "", "")
flag.Parse()
// setup the tun interface
ifce, err := water.New(water.Config{
DeviceType: water.TUN,
})
if err != nil {
log.Fatal(err)
return
}
// just log the interface name
log.Printf("if: %s\n", ifce.Name())
// setup the irc connection
ircConn := irc.IRC(*nick, "this is cursed https://cynthia.re")
// callback for irc connection being established
ircConn.AddCallback("001", func(e *irc.Event) {
ircConn.Join(*channel)
})
// callback for messages on irc
ircConn.AddCallback("PRIVMSG", func(e *irc.Event) {
msg := e.Message()
// do magic with packet messages
if strings.HasPrefix(msg, "PACKET ") {
packet, err := base64.StdEncoding.DecodeString(msg[7:])
if err != nil {
log.Println(err)
}
log.Printf("Packet recv: % x\n", packet)
_, err = ifce.Write(packet)
if err != nil {
log.Println("failed to write to if")
}
}
})
// connect to irc
err = ircConn.Connect(*addr)
if err != nil {
log.Fatal(err)
}
go ircConn.Loop()
// listen for packets to send to irc
packet := make([]byte, 2000)
for {
n, err := ifce.Read(packet)
if err != nil {
log.Fatal(err)
}
ircConn.Privmsgf(*channel, "PACKET %s", base64.StdEncoding.EncodeToString(packet[:n]))
}
}