Skip to content

Commit

Permalink
don't run the post-connect routine twice
Browse files Browse the repository at this point in the history
  • Loading branch information
cfindlayisme committed Dec 6, 2024
1 parent bc37a61 commit a37d8f4
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions ircclient/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ import (

var IrcConnection net.Conn

var doPostConnectRoutine = false
var donePostConnectRoutine = false

func Connect(server string) error {
conn, err := net.Dial("tcp", server)
if err != nil {
Expand Down Expand Up @@ -63,8 +66,6 @@ func Loop() {
readMessages(IrcConnection, messageChannel, errorChannel)
}()

isPostConnect := false

for {
select {
case message, ok := <-messageChannel:
Expand All @@ -79,17 +80,17 @@ func Loop() {
} else if len(words) >= 2 && words[1] == "PRIVMSG" {
processPrivmsg(words)
} else if len(words) >= 2 && words[1] == "001" {
isPostConnect = true
doPostConnectRoutine = true
} else if len(words) >= 2 && (words[1] == "376" || words[1] == "422") {
isPostConnect = true
doPostConnectRoutine = true
} else {
log.Println("Raw unprocessed message:", message)
}

if isPostConnect {
if doPostConnectRoutine && !donePostConnectRoutine {
log.Println("Connected to IRC server - doing post-connect routine")
initializePostConnect()
isPostConnect = false
donePostConnectRoutine = true
}

case err := <-errorChannel:
Expand Down

0 comments on commit a37d8f4

Please sign in to comment.