Compare commits
36 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 53b72e0cb0 | |||
| 839dea016a | |||
| e235ee014e | |||
|
|
c54a271f17 | ||
|
|
264ee8c61c | ||
|
|
85e44756e3 | ||
|
|
e628bdcf91 | ||
|
|
f929379569 | ||
|
|
d5f331ec7c | ||
|
|
a609996484 | ||
|
|
0ec1c20d7e | ||
|
|
3cffacaa45 | ||
|
|
e0e5c742e3 | ||
|
|
7494823b07 | ||
|
|
7b2ab6642b | ||
|
|
f1051fbfc2 | ||
|
|
73a4134b18 | ||
|
|
962cc8dea0 | ||
|
|
9bde052d9d | ||
|
|
eabae2ce9b | ||
|
|
10f4db39cc | ||
|
|
6a7847f71b | ||
|
|
7592bf6002 | ||
|
|
fb34cefc46 | ||
|
|
0df6237005 | ||
|
|
c35062a3df | ||
|
|
74e4f6cfa3 | ||
|
|
7bf832322d | ||
|
|
169debea93 | ||
|
|
9c2cad7986 | ||
|
|
32296eeffa | ||
|
|
3a00df8ef4 | ||
|
|
a948b457bd | ||
|
|
11dbafe387 | ||
|
|
a72f7be558 | ||
|
|
637bfd6c78 |
4
.hgtags
Normal file
4
.hgtags
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
da295cede46d95848348292e04e54fa5a5713ae3 release-1.0.0
|
||||||
|
34892054c34384edeafa2b04a483697d7d8a73a3 release-1.1.0
|
||||||
|
3586b48a5abfdbdeef310f2e154b06f4d16d38bb release-1.2.0
|
||||||
|
49dcc63e80e98f8c2ce3bb029fe0c41a6426678f release-1.2.1
|
||||||
16
TODO.txt
16
TODO.txt
@@ -1,4 +1,13 @@
|
|||||||
|
|
||||||
|
BUGS
|
||||||
|
====
|
||||||
|
|
||||||
|
- /wrong/ password message shows up, but not if no password was given for a passworded nick
|
||||||
|
|
||||||
|
- tags not showing up in ncdc
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
WISHLIST
|
WISHLIST
|
||||||
========
|
========
|
||||||
|
|
||||||
@@ -6,19 +15,12 @@ WISHLIST
|
|||||||
|
|
||||||
- automatic markdown bold/italic formatting
|
- automatic markdown bold/italic formatting
|
||||||
|
|
||||||
- support changing nick (via reconnecting)
|
|
||||||
|
|
||||||
- support WHOIS
|
|
||||||
|
|
||||||
- respond to CTCP VERSION with the clienttag on behalf of other users
|
|
||||||
|
|
||||||
- support USERIP/KILL/KICK for ops
|
- support USERIP/KILL/KICK for ops
|
||||||
|
|
||||||
- use CTCP chat to support irc-special characters in chat messages (colon, newline)
|
- use CTCP chat to support irc-special characters in chat messages (colon, newline)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
WONTFIX
|
WONTFIX
|
||||||
=======
|
=======
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,9 @@ TLS (SSL) support is not integrated. To host the IRC frontend over TLS, please u
|
|||||||
|
|
||||||
This program uses some code from the AGPLv3 project https://github.com/eXeC64/Rosella , from which it inherits the Affero GPLv3 license. Anyone hosting a modified version of this software is required to release their changes under the terms of the AGPLv3.
|
This program uses some code from the AGPLv3 project https://github.com/eXeC64/Rosella , from which it inherits the Affero GPLv3 license. Anyone hosting a modified version of this software is required to release their changes under the terms of the AGPLv3.
|
||||||
|
|
||||||
Tags: NMDC AGPLv3
|
Written in golang
|
||||||
|
|
||||||
|
Tags: nmdc, AGPLv3
|
||||||
|
|
||||||
=FEATURES=
|
=FEATURES=
|
||||||
|
|
||||||
@@ -18,6 +20,7 @@ Tags: NMDC AGPLv3
|
|||||||
- NMDC server's title exposed as IRC channel topic
|
- NMDC server's title exposed as IRC channel topic
|
||||||
- Login with passworded nick (classic `PASS`, not `SASL`)
|
- Login with passworded nick (classic `PASS`, not `SASL`)
|
||||||
- Full nick list integration including op status
|
- Full nick list integration including op status
|
||||||
|
- Support IRC client changing nick via NMDC upstream reconnection
|
||||||
- Automatic join to single-enforced chatroom
|
- Automatic join to single-enforced chatroom
|
||||||
- Multithreaded
|
- Multithreaded
|
||||||
- Single binary deployment
|
- Single binary deployment
|
||||||
@@ -29,6 +32,8 @@ Tags: NMDC AGPLv3
|
|||||||
Automatically join clients to the channel (default true)
|
Automatically join clients to the channel (default true)
|
||||||
-bind string
|
-bind string
|
||||||
The address:port to bind to and listen for clients on (default ":6667")
|
The address:port to bind to and listen for clients on (default ":6667")
|
||||||
|
-hubsecurity string
|
||||||
|
Nick used for administrative events (default "Hub-Security")
|
||||||
-servername string
|
-servername string
|
||||||
Server name displayed to clients (default "nmdc-ircfrontend")
|
Server name displayed to clients (default "nmdc-ircfrontend")
|
||||||
-upstream string
|
-upstream string
|
||||||
@@ -40,24 +45,48 @@ Tags: NMDC AGPLv3
|
|||||||
|
|
||||||
NMDC's smaller community has standardised around comparatively few protocol implementations by means of necessity. In comparison, there are a lot of IRC client implementations with slightly differing interpretations of the protocol.
|
NMDC's smaller community has standardised around comparatively few protocol implementations by means of necessity. In comparison, there are a lot of IRC client implementations with slightly differing interpretations of the protocol.
|
||||||
|
|
||||||
[b]Everything works:[/b]
|
Everything works:
|
||||||
- Hexchat
|
- Hexchat
|
||||||
- Mango IRC
|
- Mango IRC
|
||||||
- AndroIRC
|
- AndroIRC
|
||||||
- Lite IRC
|
|
||||||
- Mutter
|
- Mutter
|
||||||
- Weechat
|
- Weechat
|
||||||
|
- mIRC 7
|
||||||
|
- HoloIRC (after version 4.1.0)
|
||||||
|
|
||||||
[b]Usable, with bugs:[/b]
|
Usable, with bugs:
|
||||||
- HoloIRC - Can't parse client tag, upstream bug https://github.com/tilal6991/HoloIRC/issues/140
|
- Lite IRC - The username and nickname fields must be identical
|
||||||
|
- HoloIRC (4.1.0 and earlier) - Can't parse client tag, upstream bug https://github.com/tilal6991/HoloIRC/issues/140
|
||||||
- AndChat - Duplicate usernames appear, upstream bug https://github.com/znc/znc/issues/424
|
- AndChat - Duplicate usernames appear, upstream bug https://github.com/znc/znc/issues/424
|
||||||
- Irssi - Ignorable warning "critical nicklist_set_host: assertion 'host != NULL' failed"
|
- Irssi - Ignorable warning "critical nicklist_set_host: assertion 'host != NULL' failed"
|
||||||
|
|
||||||
[b]Unusable:[/b]
|
Unusable:
|
||||||
- Yaaic - doesn't properly understand/parse the room join
|
- Yaaic and Atomic - doesn't properly understand/parse the room join
|
||||||
- Atomic - doesn't properly understand/parse the room join, crashes on `PRIVMSG` with blank sender
|
|
||||||
|
|
||||||
=CHANGELOG=
|
=CHANGELOG=
|
||||||
|
|
||||||
|
2017-05-27 1.2.2
|
||||||
|
- Update libnmdc to 0.14
|
||||||
|
- Fix a crash that could occur if the server is scanned by a non-irc client
|
||||||
|
|
||||||
|
2016-11-29 1.2.1
|
||||||
|
- Update libnmdc to 0.11
|
||||||
|
- Fix an issue with -devel version tag in 1.2.0 release binaries
|
||||||
|
|
||||||
|
2016-08-27 1.2.0
|
||||||
|
- Feature: Support WHOIS (display NMDC user's description + client software)
|
||||||
|
- Feature: `-version` command-line option
|
||||||
|
- Compatibility: Demote 'Lite IRC' to 'Usable with bugs' section
|
||||||
|
- Update libnmdc to r9 (fix protocol issues)
|
||||||
|
- Update golang to 1.7 (smaller binary size)
|
||||||
|
|
||||||
|
2016-05-10 1.1.0
|
||||||
|
- Feature: Support renaming own client during connection (`/nick`)
|
||||||
|
- Enhancement: Option to set Hub-Security nick (needed for initial CTCP, upgraded after upstream connection)
|
||||||
|
- Compatibility: Apply user-agent-specific hacks for mIRC and Atomic clients not nicely handling PRIVMSG with blank sender
|
||||||
|
- Compatibility: Better heuristic detection for client tag extraction
|
||||||
|
- Fix an issue causing the default client tag (nmdc-ircfrontend) to briefly appear in the NMDC user list, by (briefly) delaying the upstream join unless CTCP VERSION response comes in
|
||||||
|
- Fix an issue generating malformed version numbers in NMDC client tag
|
||||||
|
|
||||||
2016-05-08 1.0.0
|
2016-05-08 1.0.0
|
||||||
- Initial public release
|
- Initial public release
|
||||||
2
godist.sh
Normal file → Executable file
2
godist.sh
Normal file → Executable file
@@ -97,7 +97,7 @@ single_build() {
|
|||||||
|
|
||||||
# Build.
|
# Build.
|
||||||
# GOARCH/GOOS supplied in function env
|
# GOARCH/GOOS supplied in function env
|
||||||
go build -a -ldflags '-s -w' -o "$(pathfix "${tmpdir}/${local_bin_name}")"
|
go build -a -ldflags "-s -w -X main.APP_VERSION=${version}" -o "$(pathfix "${tmpdir}/${local_bin_name}")"
|
||||||
|
|
||||||
# Sanitise.
|
# Sanitise.
|
||||||
sanitise "${tmpdir}/${local_bin_name}"
|
sanitise "${tmpdir}/${local_bin_name}"
|
||||||
|
|||||||
14
main.go
14
main.go
@@ -20,20 +20,29 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"flag"
|
"flag"
|
||||||
"libnmdc"
|
|
||||||
"log"
|
"log"
|
||||||
"net"
|
"net"
|
||||||
|
|
||||||
|
"code.ivysaur.me/libnmdc"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
||||||
ircAddress := flag.String("bind", ":6667", "The address:port to bind to and listen for clients on")
|
ircAddress := flag.String("bind", ":6667", "The address:port to bind to and listen for clients on")
|
||||||
dcAddress := flag.String("upstream", "127.0.0.1:411", "Upstream NMDC server")
|
dcAddress := flag.String("upstream", "127.0.0.1:411", "Upstream NMDC server")
|
||||||
serverName := flag.String("servername", "nmdc-ircfrontend", "Server name displayed to clients")
|
serverName := flag.String("servername", APP_NAME, "Server name displayed to clients")
|
||||||
|
hubsec := flag.String("hubsecurity", "Hub-Security", "Nick used for administrative events")
|
||||||
verbose := flag.Bool("verbose", false, "Display debugging information")
|
verbose := flag.Bool("verbose", false, "Display debugging information")
|
||||||
autojoin := flag.Bool("autojoin", true, "Automatically join clients to the channel")
|
autojoin := flag.Bool("autojoin", true, "Automatically join clients to the channel")
|
||||||
|
version := flag.Bool("version", false, "Display version and exit")
|
||||||
|
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
|
if *version {
|
||||||
|
log.Printf("%s version %s\n", APP_NAME, APP_VERSION)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
log.Printf("Listening on '%s'...", *ircAddress)
|
log.Printf("Listening on '%s'...", *ircAddress)
|
||||||
if *autojoin {
|
if *autojoin {
|
||||||
log.Printf("Clients will be automatically joined to the channel.")
|
log.Printf("Clients will be automatically joined to the channel.")
|
||||||
@@ -56,6 +65,7 @@ func main() {
|
|||||||
server := NewServer(*serverName, libnmdc.HubAddress(*dcAddress), conn)
|
server := NewServer(*serverName, libnmdc.HubAddress(*dcAddress), conn)
|
||||||
server.verbose = *verbose
|
server.verbose = *verbose
|
||||||
server.autojoin = *autojoin
|
server.autojoin = *autojoin
|
||||||
|
server.hubSecNick = *hubsec
|
||||||
go server.RunWorker()
|
go server.RunWorker()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
331
server.go
331
server.go
@@ -22,12 +22,14 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"libnmdc"
|
|
||||||
"log"
|
"log"
|
||||||
"net"
|
"net"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"code.ivysaur.me/libnmdc"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ClientState int
|
type ClientState int
|
||||||
@@ -41,9 +43,11 @@ const (
|
|||||||
type Server struct {
|
type Server struct {
|
||||||
name string
|
name string
|
||||||
motd string
|
motd string
|
||||||
|
hubSecNick string
|
||||||
|
|
||||||
clientConn net.Conn
|
clientConn net.Conn
|
||||||
clientState ClientState
|
clientState ClientState
|
||||||
|
ClientStateLock sync.Mutex
|
||||||
|
|
||||||
upstreamLauncher libnmdc.HubConnectionOptions
|
upstreamLauncher libnmdc.HubConnectionOptions
|
||||||
upstreamCloser chan struct{}
|
upstreamCloser chan struct{}
|
||||||
@@ -52,12 +56,15 @@ type Server struct {
|
|||||||
verbose bool
|
verbose bool
|
||||||
autojoin bool
|
autojoin bool
|
||||||
|
|
||||||
sentCtcpVersion bool
|
recievedFirstServerMessage bool
|
||||||
|
recievedCtcpVersion bool
|
||||||
|
nickChangeAttempt int
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewServer(name string, upstream libnmdc.HubAddress, conn net.Conn) *Server {
|
func NewServer(name string, upstream libnmdc.HubAddress, conn net.Conn) *Server {
|
||||||
self := libnmdc.NewUserInfo("")
|
self := libnmdc.NewUserInfo("")
|
||||||
self.ClientTag = APP_DESCRIPTION
|
self.ClientTag = APP_NAME
|
||||||
|
self.ClientVersion = APP_VERSION
|
||||||
|
|
||||||
return &Server{
|
return &Server{
|
||||||
name: name,
|
name: name,
|
||||||
@@ -107,7 +114,7 @@ func (s *Server) RunWorker() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// If this was a /timeout/, send a KA and continue.
|
// If this was a /timeout/, send a KA and continue.
|
||||||
if libnmdc.CheckIsNetTimeout(err) {
|
if netErr, ok := err.(net.Error); ok && netErr.Timeout() {
|
||||||
s.writeClient("PING :" + s.name)
|
s.writeClient("PING :" + s.name)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@@ -126,7 +133,7 @@ func (s *Server) RunWorker() {
|
|||||||
|
|
||||||
// Client sent a command
|
// Client sent a command
|
||||||
fields := strings.Fields(string(line))
|
fields := strings.Fields(string(line))
|
||||||
if len(fields) < 1 {
|
if len(fields) < 2 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -152,10 +159,14 @@ func (s *Server) RunWorker() {
|
|||||||
|
|
||||||
func (s *Server) postGeneralMessageInRoom(msg string) {
|
func (s *Server) postGeneralMessageInRoom(msg string) {
|
||||||
|
|
||||||
// FIXME blank names work well in hexchat, but not in yaaic
|
var sendAs = ""
|
||||||
var BLANK_NICK = "" // "!@" + s.name // "PtokaX" // "\xC2\xA0"
|
|
||||||
|
|
||||||
// CTCP action conversion
|
// Some clients can't handle blank nicks very well
|
||||||
|
if s.upstreamLauncher.Self.ClientTag == "mIRC" || s.upstreamLauncher.Self.ClientTag == "Atomic" {
|
||||||
|
sendAs = s.hubSecNick + "!" + s.hubSecNick + "@" + s.hubSecNick
|
||||||
|
}
|
||||||
|
|
||||||
|
// Detect pseudo-system message for potential CTCP ACTION conversion
|
||||||
words := strings.Split(msg, " ")
|
words := strings.Split(msg, " ")
|
||||||
firstWord := words[0]
|
firstWord := words[0]
|
||||||
remainder := strings.Join(words[1:], " ")
|
remainder := strings.Join(words[1:], " ")
|
||||||
@@ -176,7 +187,7 @@ func (s *Server) postGeneralMessageInRoom(msg string) {
|
|||||||
|
|
||||||
} else {
|
} else {
|
||||||
// genuine system message
|
// genuine system message
|
||||||
s.reply(rplMsg, BLANK_NICK, BLESSED_CHANNEL, msg)
|
s.reply(rplMsg, sendAs, BLESSED_CHANNEL, msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -230,14 +241,24 @@ func (s *Server) upstreamWorker() {
|
|||||||
// description change - no relevance for IRC users
|
// description change - no relevance for IRC users
|
||||||
|
|
||||||
case libnmdc.EVENT_CONNECTION_STATE_CHANGED:
|
case libnmdc.EVENT_CONNECTION_STATE_CHANGED:
|
||||||
s.postGeneralMessageInRoom("* Upstream: " + hubEvent.StateChange.Format())
|
s.postGeneralMessageInRoom("* Upstream: " + hubEvent.StateChange.String())
|
||||||
|
|
||||||
if hubEvent.StateChange == libnmdc.CONNECTIONSTATE_CONNECTED {
|
if hubEvent.StateChange == libnmdc.CONNECTIONSTATE_CONNECTED {
|
||||||
s.sendNames() // delay doing this until now
|
s.sendNames() // delay doing this until now
|
||||||
}
|
}
|
||||||
if hubEvent.StateChange == libnmdc.CONNECTIONSTATE_DISCONNECTED {
|
if hubEvent.StateChange == libnmdc.CONNECTIONSTATE_DISCONNECTED {
|
||||||
|
if s.nickChangeAttempt > 0 {
|
||||||
|
// If this was a nick change, reconnect /immediately/
|
||||||
|
s.upstream = nil
|
||||||
|
s.clientState = CSRegistered
|
||||||
|
s.maybeStartUpstream() // launches new goroutine
|
||||||
|
|
||||||
|
} else {
|
||||||
// Abandon thread. Don't try to autoreconnect at our level, the remote client can be responsible for that
|
// Abandon thread. Don't try to autoreconnect at our level, the remote client can be responsible for that
|
||||||
s.DisconnectClient()
|
s.DisconnectClient()
|
||||||
|
|
||||||
|
}
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
case libnmdc.EVENT_HUBNAME_CHANGED:
|
case libnmdc.EVENT_HUBNAME_CHANGED:
|
||||||
@@ -252,12 +273,10 @@ func (s *Server) upstreamWorker() {
|
|||||||
} else {
|
} else {
|
||||||
// nick!username@userhost, but for us all three of those are always identical
|
// nick!username@userhost, but for us all three of those are always identical
|
||||||
s.reply(rplMsg, hubEvent.Nick+"!"+hubEvent.Nick+"@"+hubEvent.Nick, BLESSED_CHANNEL, reformatIncomingMessageBody(hubEvent.Message))
|
s.reply(rplMsg, hubEvent.Nick+"!"+hubEvent.Nick+"@"+hubEvent.Nick, BLESSED_CHANNEL, reformatIncomingMessageBody(hubEvent.Message))
|
||||||
|
|
||||||
if !s.sentCtcpVersion {
|
|
||||||
// Abuse this first username in order to also send a CTCP version request
|
|
||||||
s.reply(rplMsg, hubEvent.Nick+"!"+hubEvent.Nick+"@"+hubEvent.Nick, BLESSED_CHANNEL, "\x01VERSION\x01")
|
|
||||||
s.sentCtcpVersion = true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !s.recievedFirstServerMessage {
|
||||||
|
s.hubSecNick = hubEvent.Nick // Replace with the hub's real Hub-Security nick, although we shouldn't need it again
|
||||||
}
|
}
|
||||||
|
|
||||||
case libnmdc.EVENT_SYSTEM_MESSAGE_FROM_CONN, libnmdc.EVENT_SYSTEM_MESSAGE_FROM_HUB:
|
case libnmdc.EVENT_SYSTEM_MESSAGE_FROM_CONN, libnmdc.EVENT_SYSTEM_MESSAGE_FROM_HUB:
|
||||||
@@ -280,10 +299,10 @@ func (s *Server) handleCommand(command string, args []string) {
|
|||||||
// do nothing
|
// do nothing
|
||||||
|
|
||||||
case "INFO":
|
case "INFO":
|
||||||
s.reply(rplInfo, APP_DESCRIPTION)
|
s.reply(rplInfo, APP_NAME+" v"+APP_VERSION)
|
||||||
|
|
||||||
case "VERSION":
|
case "VERSION":
|
||||||
s.reply(rplVersion, VERSION)
|
s.reply(rplVersion, APP_VERSION)
|
||||||
|
|
||||||
case "MOTD":
|
case "MOTD":
|
||||||
s.sendMOTD(s.motd)
|
s.sendMOTD(s.motd)
|
||||||
@@ -317,17 +336,38 @@ func (s *Server) handleCommand(command string, args []string) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// mIRC puts a colon in first place when changing nick, hexchat doesn't
|
||||||
|
suppliedNick := args[0]
|
||||||
|
if len(suppliedNick) >= 2 && suppliedNick[0] == ':' {
|
||||||
|
suppliedNick = suppliedNick[1:]
|
||||||
|
}
|
||||||
|
|
||||||
if s.clientNick() == "" {
|
if s.clientNick() == "" {
|
||||||
// allow set, as part of the login phase
|
// allow set, as part of the login phase
|
||||||
s.upstreamLauncher.Self.Nick = args[0]
|
s.upstreamLauncher.Self.Nick = suppliedNick
|
||||||
|
|
||||||
} else if args[0] == s.clientNick() {
|
} else if suppliedNick == s.clientNick() {
|
||||||
// Ignore
|
// Ignore
|
||||||
// Required for compatibility with Lite IRC, which sends USER/NICK in the wrong order
|
// Required for compatibility with Lite IRC, which sends USER/NICK in the wrong order
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
s.reply(rplKill, "Can't change nicks on this server.")
|
|
||||||
s.DisconnectClient()
|
s.ClientStateLock.Lock()
|
||||||
|
defer s.ClientStateLock.Unlock()
|
||||||
|
if s.upstream == nil {
|
||||||
|
// Not yet connected, should be safe to change nick
|
||||||
|
s.upstreamLauncher.Self.Nick = suppliedNick
|
||||||
|
} else {
|
||||||
|
// Need to disconnect/reconnect the upstream
|
||||||
|
s.writeClient(fmt.Sprintf(":%s!%s@%s NICK %s", s.clientNick(), s.clientNick(), s.clientNick(), suppliedNick)) // notify client about what they've done
|
||||||
|
s.upstreamLauncher.Self.Nick = suppliedNick
|
||||||
|
|
||||||
|
s.nickChangeAttempt++
|
||||||
|
s.upstream.Disconnect()
|
||||||
|
}
|
||||||
|
|
||||||
|
//s.reply(rplKill, "Can't change nicks on this server.")
|
||||||
|
//s.DisconnectClient()
|
||||||
}
|
}
|
||||||
|
|
||||||
case "USER":
|
case "USER":
|
||||||
@@ -355,7 +395,9 @@ func (s *Server) handleCommand(command string, args []string) {
|
|||||||
s.reply(rplWelcome)
|
s.reply(rplWelcome)
|
||||||
s.clientState = CSRegistered
|
s.clientState = CSRegistered
|
||||||
|
|
||||||
// TODO tell the client that they /must/ join #chat
|
// Send CTCP VERSION request immediately
|
||||||
|
s.reply(rplMsg, s.hubSecNick+"!"+s.hubSecNick+"@"+s.hubSecNick, BLESSED_CHANNEL, "\x01VERSION\x01")
|
||||||
|
|
||||||
if s.autojoin {
|
if s.autojoin {
|
||||||
s.handleCommand("JOIN", []string{BLESSED_CHANNEL})
|
s.handleCommand("JOIN", []string{BLESSED_CHANNEL})
|
||||||
}
|
}
|
||||||
@@ -381,91 +423,6 @@ func (s *Server) handleRegisteredCommand(command string, args []string) {
|
|||||||
}
|
}
|
||||||
s.reply(rplListEnd)
|
s.reply(rplListEnd)
|
||||||
|
|
||||||
case "JOIN":
|
|
||||||
if len(args) < 1 {
|
|
||||||
s.reply(errMoreArgs)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
switch args[0] {
|
|
||||||
case BLESSED_CHANNEL:
|
|
||||||
if s.clientState != CSJoined {
|
|
||||||
// Join for the first time
|
|
||||||
s.clientState = CSJoined
|
|
||||||
|
|
||||||
// Acknowledge
|
|
||||||
s.reply(rplJoin, s.clientNick(), BLESSED_CHANNEL)
|
|
||||||
|
|
||||||
// Send (initially just us) nicklist for the chat channel
|
|
||||||
//s.sendNames()
|
|
||||||
|
|
||||||
// Spawn upstream connection
|
|
||||||
s.upstream = s.upstreamLauncher.Connect()
|
|
||||||
go s.upstreamWorker()
|
|
||||||
|
|
||||||
} else {
|
|
||||||
// They're already here, ignore
|
|
||||||
// Can happen if autojoin is enabled but the client already requested a login
|
|
||||||
}
|
|
||||||
|
|
||||||
case "0":
|
|
||||||
// Quitting all channels? Drop client
|
|
||||||
s.reply(rplKill, "Bye.")
|
|
||||||
s.DisconnectClient()
|
|
||||||
|
|
||||||
default:
|
|
||||||
s.reply(rplKill, "There is only '"+BLESSED_CHANNEL+"'.")
|
|
||||||
s.DisconnectClient()
|
|
||||||
}
|
|
||||||
|
|
||||||
default:
|
|
||||||
s.handleJoinedCommand(command, args)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *Server) SetClientSoftwareVersion(ver string) {
|
|
||||||
// "HexChat 2.12.1 [x64] / Microsoft Windows 10 Pro (x64) [Intel(R) Core(TM) i5-2500 CPU @ 3.30GHz (3.60GHz)]"
|
|
||||||
// "AndroIRC - Android IRC Client (5.2 - Build 6830152) - http://www.androirc.com"
|
|
||||||
// "AndChat 1.4.3.2 http://www.andchat.net"
|
|
||||||
// "liteIRC for Android 1.1.8"
|
|
||||||
// ":Relay:1.0:Android"
|
|
||||||
|
|
||||||
// A bit long and unwieldy. Heuristic: stop after the first word containing digits
|
|
||||||
|
|
||||||
parts := regexp.MustCompilePOSIX("^([^0-9]*[0-9]+[^ ]*) ").FindStringSubmatch(ver)
|
|
||||||
|
|
||||||
if len(parts) > 0 {
|
|
||||||
ver = strings.TrimRight(parts[0], " ")
|
|
||||||
}
|
|
||||||
|
|
||||||
s.verbosef("Replacing client tag with '%s'...", ver)
|
|
||||||
|
|
||||||
s.upstreamLauncher.Self.ClientTag = ver
|
|
||||||
s.upstream.Hco.Self.ClientTag = ver
|
|
||||||
|
|
||||||
s.upstream.SayInfo()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *Server) handleJoinedCommand(command string, args []string) {
|
|
||||||
|
|
||||||
if s.clientState != CSJoined {
|
|
||||||
s.reply(errNotReg)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
switch command {
|
|
||||||
case "PART":
|
|
||||||
if len(args) < 1 {
|
|
||||||
s.reply(errMoreArgs)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if args[0] == BLESSED_CHANNEL {
|
|
||||||
// You can check out any time you like, but you can never leave
|
|
||||||
s.reply(rplJoin, s.clientNick(), BLESSED_CHANNEL)
|
|
||||||
s.sendNames()
|
|
||||||
}
|
|
||||||
|
|
||||||
case "PRIVMSG", "NOTICE":
|
case "PRIVMSG", "NOTICE":
|
||||||
if len(args) < 2 {
|
if len(args) < 2 {
|
||||||
s.reply(errMoreArgs)
|
s.reply(errMoreArgs)
|
||||||
@@ -509,6 +466,130 @@ func (s *Server) handleJoinedCommand(command string, args []string) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case "JOIN":
|
||||||
|
if len(args) < 1 {
|
||||||
|
s.reply(errMoreArgs)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
switch args[0] {
|
||||||
|
case BLESSED_CHANNEL:
|
||||||
|
// Give it a few seconds - it's better to hear the CTCP VERSION
|
||||||
|
// response first. Once we get that, it'll connect instantly
|
||||||
|
go func() {
|
||||||
|
<-time.After(WAIT_FOR_VERSION * time.Second)
|
||||||
|
|
||||||
|
s.ClientStateLock.Lock()
|
||||||
|
defer s.ClientStateLock.Unlock()
|
||||||
|
|
||||||
|
s.maybeStartUpstream()
|
||||||
|
}()
|
||||||
|
|
||||||
|
case "0":
|
||||||
|
// Quitting all channels? Drop client
|
||||||
|
s.reply(rplKill, "Bye.")
|
||||||
|
s.DisconnectClient()
|
||||||
|
|
||||||
|
default:
|
||||||
|
s.reply(rplKill, "There is only '"+BLESSED_CHANNEL+"'.")
|
||||||
|
s.DisconnectClient()
|
||||||
|
}
|
||||||
|
|
||||||
|
default:
|
||||||
|
s.handleJoinedCommand(command, args)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *Server) maybeStartUpstream() {
|
||||||
|
if s.clientState != CSJoined {
|
||||||
|
// Join for the first time
|
||||||
|
s.clientState = CSJoined
|
||||||
|
|
||||||
|
// Acknowledge
|
||||||
|
s.reply(rplJoin, s.clientNick(), BLESSED_CHANNEL)
|
||||||
|
|
||||||
|
// Spawn upstream connection
|
||||||
|
s.upstream = s.upstreamLauncher.Connect()
|
||||||
|
go s.upstreamWorker()
|
||||||
|
|
||||||
|
} else {
|
||||||
|
// They're already here, ignore
|
||||||
|
// Can happen if autojoin is enabled but the client already requested a login
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *Server) SetClientSoftwareVersion(ver string) {
|
||||||
|
// "HexChat 2.12.1 [x64] / Microsoft Windows 10 Pro (x64) [Intel(R) Core(TM) i5-2500 CPU @ 3.30GHz (3.60GHz)]"
|
||||||
|
// "AndroIRC - Android IRC Client (5.2 - Build 6830152) - http://www.androirc.com"
|
||||||
|
// "AndChat 1.4.3.2 http://www.andchat.net"
|
||||||
|
// "liteIRC for Android 1.1.8"
|
||||||
|
// ":Relay:1.0:Android"
|
||||||
|
// "mIRC v7.45"
|
||||||
|
|
||||||
|
// A bit long and unwieldy.
|
||||||
|
// Heuristic: keep the first word, and the the first word containing digits
|
||||||
|
|
||||||
|
tag := APP_NAME
|
||||||
|
version := APP_VERSION
|
||||||
|
|
||||||
|
words := strings.Split(ver, " ")
|
||||||
|
|
||||||
|
for _, word := range words[1:] {
|
||||||
|
if strings.ContainsAny(word, "0123456789") {
|
||||||
|
tag = words[0]
|
||||||
|
version = strings.Replace(word, "(", "", -1) // AndroIRC
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Strip leading v from mIRC
|
||||||
|
if len(version) >= 2 && (version[0] == 'v' || version[0] == 'V') && strings.ContainsAny(string(version[1]), "0123456789") {
|
||||||
|
version = version[1:]
|
||||||
|
}
|
||||||
|
|
||||||
|
s.verbosef("Replacing client tag with '%s' version '%s'", tag, version)
|
||||||
|
|
||||||
|
s.upstreamLauncher.Self.ClientTag = tag
|
||||||
|
s.upstreamLauncher.Self.ClientVersion = version
|
||||||
|
s.recievedCtcpVersion = true
|
||||||
|
|
||||||
|
s.ClientStateLock.Lock()
|
||||||
|
defer s.ClientStateLock.Unlock()
|
||||||
|
|
||||||
|
if s.upstream != nil {
|
||||||
|
s.upstream.Hco.Self.ClientTag = tag
|
||||||
|
s.upstream.Hco.Self.ClientVersion = version
|
||||||
|
s.upstream.SayInfo()
|
||||||
|
|
||||||
|
} else {
|
||||||
|
// Connected for the first time (order was CTCP VERSION --> JOIN)
|
||||||
|
|
||||||
|
s.maybeStartUpstream()
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *Server) handleJoinedCommand(command string, args []string) {
|
||||||
|
|
||||||
|
if s.clientState != CSJoined {
|
||||||
|
s.reply(errNotReg)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
switch command {
|
||||||
|
case "PART":
|
||||||
|
if len(args) < 1 {
|
||||||
|
s.reply(errMoreArgs)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if args[0] == BLESSED_CHANNEL {
|
||||||
|
// You can check out any time you like, but you can never leave
|
||||||
|
s.reply(rplJoin, s.clientNick(), BLESSED_CHANNEL)
|
||||||
|
s.sendNames()
|
||||||
|
}
|
||||||
|
|
||||||
case "QUIT":
|
case "QUIT":
|
||||||
s.DisconnectClient()
|
s.DisconnectClient()
|
||||||
|
|
||||||
@@ -577,6 +658,35 @@ func (s *Server) handleJoinedCommand(command string, args []string) {
|
|||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
|
case "WHOIS":
|
||||||
|
if len(args) < 1 {
|
||||||
|
s.reply(errMoreArgs)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// WHOIS [target] nick[,nick2[,nick...]]
|
||||||
|
nicklist := args[0] // Assume WHOIS ${nick} only,
|
||||||
|
if len(args) >= 2 {
|
||||||
|
nicklist = args[1] // It was WHOIS ${target} ${nick} instead
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, targetnick := range strings.Split(nicklist, ",") {
|
||||||
|
// tell the client something about it
|
||||||
|
// The protocol does ostensibly support wildcard WHOIS, but we don't (yet)
|
||||||
|
s.upstream.Users(func(u *map[string]libnmdc.UserInfo) error {
|
||||||
|
for nick, nickinfo := range *u {
|
||||||
|
if nick == targetnick {
|
||||||
|
s.reply(rplWhoisUser, nick, nickinfo.Description+" <"+nickinfo.ClientTag+" V:"+nickinfo.ClientVersion+">")
|
||||||
|
if nickinfo.IsOperator {
|
||||||
|
s.reply(rplWhoisOperator, nick)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
s.reply(rplEndOfWhois)
|
||||||
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
s.reply(errUnknownCommand, command)
|
s.reply(errUnknownCommand, command)
|
||||||
}
|
}
|
||||||
@@ -735,6 +845,13 @@ func (s *Server) reply(code replyCode, args ...string) {
|
|||||||
case rplPong:
|
case rplPong:
|
||||||
s.writeClient(fmt.Sprintf(":%s PONG %s %s", s.name, s.clientNick(), args[0]))
|
s.writeClient(fmt.Sprintf(":%s PONG %s %s", s.name, s.clientNick(), args[0]))
|
||||||
|
|
||||||
|
case rplWhoisUser:
|
||||||
|
s.writeClient(fmt.Sprintf(":%s 311 %s %s %s %s * :%s", s.name, args[0], args[0], args[0], s.name, args[1])) // caller should supply nick,description
|
||||||
|
case rplWhoisOperator:
|
||||||
|
s.writeClient(fmt.Sprintf(":%s 313 %s :is an IRC operator", s.name, args[0]))
|
||||||
|
case rplEndOfWhois:
|
||||||
|
s.writeClient(fmt.Sprintf(":%s 318 :End of WHOIS list", s.name))
|
||||||
|
|
||||||
case errMoreArgs:
|
case errMoreArgs:
|
||||||
s.writeClient(fmt.Sprintf(":%s 461 %s :Not enough params", s.name, s.clientNick()))
|
s.writeClient(fmt.Sprintf(":%s 461 %s :Not enough params", s.name, s.clientNick()))
|
||||||
case errNoNick:
|
case errNoNick:
|
||||||
|
|||||||
11
typedefs.go
11
typedefs.go
@@ -18,15 +18,19 @@ You should have received a copy of the GNU Affero General Public License
|
|||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
var (
|
||||||
|
APP_VERSION = "1.x.x-dev" // overridden with build ldflags
|
||||||
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
VERSION = "1.0.0"
|
APP_NAME = "nmdc-ircfrontend"
|
||||||
APP_DESCRIPTION = "nmdc-ircfrontend v" + VERSION
|
|
||||||
BLESSED_CHANNEL = "#chat" // must be lowercase
|
BLESSED_CHANNEL = "#chat" // must be lowercase
|
||||||
BLESSED_CHANNEL_MODE = "n" // means that you have to be in the channel to chat, but that's it
|
BLESSED_CHANNEL_MODE = "n" // means that you have to be in the channel to chat, but that's it
|
||||||
|
|
||||||
NICKS_PER_PROTOMSG = 128 // Max number of nicks to send per message
|
NICKS_PER_PROTOMSG = 128 // Max number of nicks to send per message
|
||||||
CLIENT_READ_BUFFSIZE = 512
|
CLIENT_READ_BUFFSIZE = 512
|
||||||
CLIENT_KEEPALIVE_EVERY = 60 // should be longer than the client's one, hexchat is 30s
|
CLIENT_KEEPALIVE_EVERY = 60 // should be longer than the client's one, hexchat is 30s
|
||||||
|
WAIT_FOR_VERSION = 3 // Seconds to wait for the CTCP VERSION response before connecting with default MyINFO
|
||||||
)
|
)
|
||||||
|
|
||||||
type replyCode int
|
type replyCode int
|
||||||
@@ -55,6 +59,9 @@ const (
|
|||||||
rplMOTD
|
rplMOTD
|
||||||
rplEndOfMOTD
|
rplEndOfMOTD
|
||||||
rplPong
|
rplPong
|
||||||
|
rplWhoisUser
|
||||||
|
rplWhoisOperator
|
||||||
|
rplEndOfWhois
|
||||||
errMoreArgs
|
errMoreArgs
|
||||||
errNoNick
|
errNoNick
|
||||||
errInvalidNick
|
errInvalidNick
|
||||||
|
|||||||
Reference in New Issue
Block a user