-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathctcp.go
73 lines (59 loc) · 1.46 KB
/
ctcp.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 (
//"code.google.com/p/go.net/html"
"errors"
"io"
"io/ioutil"
"net"
"path"
"strconv"
"strings"
"time"
)
func (i *instance) DCCSend(nick string, file string) error {
//if _, ok := i.DCCHandshakes[nick]; !ok {
//inch := make(chan string, 5)
ip := net.ParseIP(conf.ExternalIP)
var ipn uint32
for _, b := range ip {
ipn <<= 8
ipn += uint32(b)
}
listen, err := net.ListenTCP("tcp", &net.TCPAddr{IP: net.IPv4(0, 0, 0, 0), Port: 0})
if err != nil {
return errors.New("Couldnt listen to socket")
}
_, port, _ := net.SplitHostPort(listen.Addr().String())
f, err := conf.FileSystemPrefixes[conf.DCCFilesystem].Dir.Open(file)
if err != nil {
return errors.New("File does not exist")
}
finfo, _ := f.Stat()
//i.DCCHandshakes[nick] = inch
i.Irc.Privmsg(nick, "\x01DCC SEND "+path.Base(strings.Trim(file, " "))+" "+strconv.Itoa(int(ipn))+" "+port+" "+strconv.FormatInt(finfo.Size(), 10))
go func() {
/*
select {
case msg := <-inch:
spl := strings.Split(msg, " ")
if spl[0] == "DCC" && spl[1] == "ACCEPT" {
if
}
case <-time.After(8 * time.Minute):
delete(i.DCCHandshakes, nick)
return
}
*/
defer listen.Close()
deadline := time.Now().Add(8 * time.Minute)
listen.SetDeadline(deadline)
con, err := listen.Accept()
if err != nil {
return
}
go io.Copy(ioutil.Discard, con)
io.Copy(con, f)
}()
//}
return nil
}