-
Notifications
You must be signed in to change notification settings - Fork 106
Dcc chat support/Binding Ip support #144
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
kofany
wants to merge
17
commits into
thoj:master
Choose a base branch
from
kofany:dcc-chat-support
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 16 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
aca1ec7
Update irc.go
kofany df9a396
Update go.mod
kofany 1ae3976
Update irc.go
kofany 80ded75
Update irc.go
kofany 370fd7a
Update irc.go
kofany a96c3cc
Update irc.go
kofany 26bf44f
Update irc_struct.go
kofany 6de4913
Added host bind option for irc connection
kofany 232084d
Added fully_connected flag with 001 event for better nick change erro…
kofany b282546
Nick error callbacks update, go fro 1.13 to 1.23.2 update
kofany 3736169
Update irc_struct.go
kofany 80afa9a
Update irc_struct.go
kofany 360449a
Code fixes
kofany adce523
Backward compatiblity fix
kofany 0e23694
Initial DCC support
kofany e67df24
Initial DCC support
kofany 961742d
Ping
kofany File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| .DS_Store |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,27 +1,28 @@ | ||
| package main | ||
|
|
||
| import ( | ||
| "github.com/thoj/go-ircevent" | ||
| "crypto/tls" | ||
| "fmt" | ||
|
|
||
| irc "github.com/kofany/go-ircevent" | ||
| ) | ||
|
|
||
| const channel = "#go-eventirc-test"; | ||
| const channel = "#go-eventirc-test" | ||
| const serverssl = "irc.freenode.net:7000" | ||
|
|
||
| func main() { | ||
| ircnick1 := "blatiblat" | ||
| irccon := irc.IRC(ircnick1, "IRCTestSSL") | ||
| irccon.VerboseCallbackHandler = true | ||
| irccon.Debug = true | ||
| irccon.UseTLS = true | ||
| irccon.TLSConfig = &tls.Config{InsecureSkipVerify: true} | ||
| irccon.AddCallback("001", func(e *irc.Event) { irccon.Join(channel) }) | ||
| irccon.AddCallback("366", func(e *irc.Event) { }) | ||
| err := irccon.Connect(serverssl) | ||
| ircnick1 := "blatiblat" | ||
| irccon := irc.IRC(ircnick1, "IRCTestSSL") | ||
| irccon.VerboseCallbackHandler = true | ||
| irccon.Debug = true | ||
| irccon.UseTLS = true | ||
| irccon.TLSConfig = &tls.Config{InsecureSkipVerify: true} | ||
| irccon.AddCallback("001", func(e *irc.Event) { irccon.Join(channel) }) | ||
| irccon.AddCallback("366", func(e *irc.Event) {}) | ||
| err := irccon.Connect(serverssl) | ||
| if err != nil { | ||
| fmt.Printf("Err %s", err ) | ||
| fmt.Printf("Err %s", err) | ||
| return | ||
| } | ||
| irccon.Loop() | ||
| irccon.Loop() | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,5 @@ | ||
| golang.org/x/net v0.0.0-20210614182718-04defd469f4e h1:XpT3nA5TvE525Ne3hInMh6+GETgn27Zfm9dxsThnX2Q= | ||
| golang.org/x/net v0.0.0-20210614182718-04defd469f4e/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= | ||
| golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= | ||
| golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= | ||
| golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= | ||
| golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs= | ||
| golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= | ||
| golang.org/x/text v0.3.6 h1:aRYxNxv6iGQlyVaZmk6ZgYEDa+Jg18DxebPSrd6bg1M= | ||
| golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= | ||
| golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,13 @@ | ||
| // irc.go - corrected version | ||
| // Copyright 2009 Thomas Jager <[email protected]> All rights reserved. | ||
| // Use of this source code is governed by a BSD-style | ||
| // license that can be found in the LICENSE file. | ||
|
|
||
| /* | ||
| This package provides an event based IRC client library. It allows to | ||
| This package provides an event-based IRC client library. It allows you to | ||
| register callbacks for the events you need to handle. Its features | ||
| include handling standard CTCP, reconnecting on errors and detecting | ||
| stones servers. | ||
| include handling standard CTCP, reconnecting on errors, and detecting | ||
| stone servers. | ||
| Details of the IRC protocol can be found in the following RFCs: | ||
| https://tools.ietf.org/html/rfc1459 | ||
| https://tools.ietf.org/html/rfc2810 | ||
|
|
@@ -36,7 +37,7 @@ import ( | |
| ) | ||
|
|
||
| const ( | ||
| VERSION = "go-ircevent v2.1" | ||
| VERSION = "go-ircevent v2.1+myip" | ||
| ) | ||
|
|
||
| const CAP_TIMEOUT = time.Second * 15 | ||
|
|
@@ -65,7 +66,7 @@ func (irc *Connection) readLoop() { | |
|
|
||
| msg, err := br.ReadString('\n') | ||
|
|
||
| // We got past our blocking read, so bin timeout | ||
| // We got past our blocking read, so clear timeout | ||
| if irc.socket != nil { | ||
| var zero time.Time | ||
| irc.socket.SetReadDeadline(zero) | ||
|
|
@@ -103,13 +104,13 @@ func unescapeTagValue(value string) string { | |
| return value | ||
| } | ||
|
|
||
| //Parse raw irc messages | ||
| // Parse raw IRC messages | ||
| func parseToEvent(msg string) (*Event, error) { | ||
| msg = strings.TrimSuffix(msg, "\n") //Remove \r\n | ||
| msg = strings.TrimSuffix(msg, "\n") // Remove \r\n | ||
| msg = strings.TrimSuffix(msg, "\r") | ||
| event := &Event{Raw: msg} | ||
| if len(msg) < 5 { | ||
| return nil, errors.New("Malformed msg from server") | ||
| return nil, errors.New("malformed msg from server") | ||
| } | ||
|
|
||
| if msg[0] == '@' { | ||
|
|
@@ -125,25 +126,24 @@ func parseToEvent(msg string) (*Event, error) { | |
| event.Tags[parts[0]] = unescapeTagValue(parts[1]) | ||
| } | ||
| } | ||
| msg = msg[i+1 : len(msg)] | ||
| msg = msg[i+1:] | ||
| } else { | ||
| return nil, errors.New("Malformed msg from server") | ||
| return nil, errors.New("malformed msg from server") | ||
| } | ||
| } | ||
|
|
||
| if msg[0] == ':' { | ||
| if i := strings.Index(msg, " "); i > -1 { | ||
| event.Source = msg[1:i] | ||
| msg = msg[i+1 : len(msg)] | ||
|
|
||
| msg = msg[i+1:] | ||
| } else { | ||
| return nil, errors.New("Malformed msg from server") | ||
| return nil, errors.New("malformed msg from server") | ||
| } | ||
|
|
||
| if i, j := strings.Index(event.Source, "!"), strings.Index(event.Source, "@"); i > -1 && j > -1 && i < j { | ||
| event.Nick = event.Source[0:i] | ||
| event.User = event.Source[i+1 : j] | ||
| event.Host = event.Source[j+1 : len(event.Source)] | ||
| event.Host = event.Source[j+1:] | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -176,12 +176,12 @@ func (irc *Connection) writeLoop() { | |
| irc.Log.Printf("--> %s\n", strings.TrimSpace(b)) | ||
| } | ||
|
|
||
| // Set a write deadline based on the time out | ||
| // Set a write deadline based on the timeout | ||
| irc.socket.SetWriteDeadline(time.Now().Add(irc.Timeout)) | ||
|
|
||
| _, err := w.Write([]byte(b)) | ||
|
|
||
| // Past blocking write, bin timeout | ||
| // Clear the write deadline | ||
| var zero time.Time | ||
| irc.socket.SetWriteDeadline(zero) | ||
|
|
||
|
|
@@ -202,16 +202,16 @@ func (irc *Connection) pingLoop() { | |
| for { | ||
| select { | ||
| case <-ticker.C: | ||
| //Ping if we haven't received anything from the server within the keep alive period | ||
| // Ping if we haven't received anything from the server within the keep-alive period | ||
| irc.lastMessageMutex.Lock() | ||
| if time.Since(irc.lastMessage) >= irc.KeepAlive { | ||
| irc.SendRawf("PING %d", time.Now().UnixNano()) | ||
| } | ||
| irc.lastMessageMutex.Unlock() | ||
| case <-ticker2.C: | ||
| //Ping at the ping frequency | ||
| // Ping at the ping frequency | ||
| irc.SendRawf("PING %d", time.Now().UnixNano()) | ||
| //Try to recapture nickname if it's not as configured. | ||
| // Try to recapture nickname if it's not as configured. | ||
| irc.Lock() | ||
| if irc.nick != irc.nickcurrent { | ||
| irc.nickcurrent = irc.nick | ||
|
|
@@ -288,7 +288,7 @@ func (irc *Connection) Notice(target, message string) { | |
| irc.pwrite <- fmt.Sprintf("NOTICE %s :%s\r\n", target, message) | ||
| } | ||
|
|
||
| // Send a formated notification to a nickname. | ||
| // Send a formatted notification to a nickname. | ||
| // RFC 1459 details: https://tools.ietf.org/html/rfc1459#section-4.4.2 | ||
| func (irc *Connection) Noticef(target, format string, a ...interface{}) { | ||
| irc.Notice(target, fmt.Sprintf(format, a...)) | ||
|
|
@@ -311,7 +311,7 @@ func (irc *Connection) Privmsg(target, message string) { | |
| irc.pwrite <- fmt.Sprintf("PRIVMSG %s :%s\r\n", target, message) | ||
| } | ||
|
|
||
| // Send formated string to specified target (channel or nickname). | ||
| // Send formatted string to specified target (channel or nickname). | ||
| func (irc *Connection) Privmsgf(target, format string, a ...interface{}) { | ||
| irc.Privmsg(target, fmt.Sprintf(format, a...)) | ||
| } | ||
|
|
@@ -344,7 +344,7 @@ func (irc *Connection) SendRaw(message string) { | |
| irc.pwrite <- message + "\r\n" | ||
| } | ||
|
|
||
| // Send raw formated string. | ||
| // Send raw formatted string. | ||
| func (irc *Connection) SendRawf(format string, a ...interface{}) { | ||
| irc.SendRaw(fmt.Sprintf(format, a...)) | ||
| } | ||
|
|
@@ -397,6 +397,7 @@ func (irc *Connection) Connected() bool { | |
| // stops all goroutines and then closes the socket. | ||
| func (irc *Connection) Disconnect() { | ||
| irc.Lock() | ||
| irc.fullyConnected = false | ||
| defer irc.Unlock() | ||
|
|
||
| if irc.end != nil { | ||
|
|
@@ -419,6 +420,9 @@ func (irc *Connection) Disconnect() { | |
|
|
||
| // Reconnect to a server using the current connection. | ||
| func (irc *Connection) Reconnect() error { | ||
| irc.Lock() | ||
| irc.fullyConnected = false | ||
| irc.Unlock() | ||
| irc.end = make(chan struct{}) | ||
| return irc.Connect(irc.Server) | ||
| } | ||
|
|
@@ -428,10 +432,10 @@ func (irc *Connection) Reconnect() error { | |
| // RFC 1459 details: https://tools.ietf.org/html/rfc1459#section-4.1 | ||
| func (irc *Connection) Connect(server string) error { | ||
| irc.Server = server | ||
| // mark Server as stopped since there can be an error during connect | ||
| // Mark Server as stopped since there can be an error during connect | ||
| irc.stopped = true | ||
|
|
||
| // make sure everything is ready for connection | ||
| // Make sure everything is ready for connection | ||
| if len(irc.Server) == 0 { | ||
| return errors.New("empty 'server'") | ||
| } | ||
|
|
@@ -462,7 +466,19 @@ func (irc *Connection) Connect(server string) error { | |
| return errors.New("empty 'user'") | ||
| } | ||
|
|
||
| dialer := proxy.FromEnvironmentUsing(&net.Dialer{Timeout: irc.Timeout}) | ||
| var localAddr net.Addr | ||
| if irc.localIP != "" { | ||
| localAddr = &net.TCPAddr{ | ||
| IP: net.ParseIP(irc.localIP), | ||
| Port: 0, | ||
| } | ||
| } | ||
|
|
||
| dialer := proxy.FromEnvironmentUsing(&net.Dialer{ | ||
| LocalAddr: localAddr, | ||
| Timeout: irc.Timeout, | ||
| }) | ||
|
|
||
| irc.socket, err = dialer.Dial("tcp", irc.Server) | ||
| if err != nil { | ||
| return err | ||
|
|
@@ -596,7 +612,7 @@ func (irc *Connection) negotiateCaps() error { | |
| remaining_caps-- | ||
| } | ||
|
|
||
| irc.pwrite <- fmt.Sprintf("CAP END\r\n") | ||
| irc.pwrite <- "CAP END\r\n" | ||
|
|
||
| return nil | ||
| } | ||
|
|
@@ -605,7 +621,7 @@ func (irc *Connection) negotiateCaps() error { | |
| // The nickname is later used to address the user. Returns nil if nick | ||
| // or user are empty. | ||
| func IRC(nick, user string) *Connection { | ||
| // catch invalid values | ||
| // Catch invalid values | ||
| if len(nick) == 0 { | ||
| return nil | ||
| } | ||
|
|
@@ -614,18 +630,28 @@ func IRC(nick, user string) *Connection { | |
| } | ||
|
|
||
| irc := &Connection{ | ||
| nick: nick, | ||
| nickcurrent: nick, | ||
| user: user, | ||
| Log: log.New(os.Stdout, "", log.LstdFlags), | ||
| end: make(chan struct{}), | ||
| Version: VERSION, | ||
| KeepAlive: 4 * time.Minute, | ||
| Timeout: 1 * time.Minute, | ||
| PingFreq: 15 * time.Minute, | ||
| SASLMech: "PLAIN", | ||
| QuitMessage: "", | ||
| nick: nick, | ||
| nickcurrent: nick, | ||
| user: user, | ||
| Log: log.New(os.Stdout, "", log.LstdFlags), | ||
| end: make(chan struct{}), | ||
| Version: VERSION, | ||
| KeepAlive: 4 * time.Minute, | ||
| Timeout: 1 * time.Minute, | ||
| PingFreq: 15 * time.Minute, | ||
| SASLMech: "PLAIN", | ||
| QuitMessage: "", | ||
| fullyConnected: false, // Initialize to false | ||
| DCCManager: NewDCCManager(), // DCC chat support | ||
| } | ||
| irc.setupCallbacks() | ||
| return irc | ||
| } | ||
|
|
||
| // SetLocalIP sets the local IP address to bind when connecting. | ||
| // This allows the client to specify which local interface/IP to use. | ||
| func (irc *Connection) SetLocalIP(ip string) { | ||
| irc.localIP = ip | ||
| } | ||
|
|
||
| // DCC | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Despite being in the gitignore it ended up here.