convenience wrapper
--HG-- branch : nmdc-ircfrontend
This commit is contained in:
parent
64a8d32d5e
commit
efca16f188
80
server.go
80
server.go
@ -161,7 +161,7 @@ func (s *Server) postGeneralMessageInRoom(msg string) {
|
|||||||
if s.upstream.UserExists(firstWord) {
|
if s.upstream.UserExists(firstWord) {
|
||||||
// it's a /me in disguise - convert back to a CTCP ACTION
|
// it's a /me in disguise - convert back to a CTCP ACTION
|
||||||
// If it's **our own** action, skip it
|
// If it's **our own** action, skip it
|
||||||
if firstWord != s.upstreamLauncher.Self.Nick {
|
if firstWord != s.clientNick() {
|
||||||
s.reply(
|
s.reply(
|
||||||
rplMsg, firstWord+"!"+firstWord+"@"+firstWord, BLESSED_CHANNEL,
|
rplMsg, firstWord+"!"+firstWord+"@"+firstWord, BLESSED_CHANNEL,
|
||||||
"\x01ACTION "+remainder+"\x01",
|
"\x01ACTION "+remainder+"\x01",
|
||||||
@ -238,10 +238,10 @@ func (s *Server) upstreamWorker() {
|
|||||||
s.sendChannelTopic(hubEvent.Nick)
|
s.sendChannelTopic(hubEvent.Nick)
|
||||||
|
|
||||||
case libnmdc.EVENT_PRIVATE:
|
case libnmdc.EVENT_PRIVATE:
|
||||||
s.reply(rplMsg, hubEvent.Nick+"!"+hubEvent.Nick+"@"+hubEvent.Nick, s.upstreamLauncher.Self.Nick, reformatIncomingMessageBody(hubEvent.Message))
|
s.reply(rplMsg, hubEvent.Nick+"!"+hubEvent.Nick+"@"+hubEvent.Nick, s.clientNick(), reformatIncomingMessageBody(hubEvent.Message))
|
||||||
|
|
||||||
case libnmdc.EVENT_PUBLIC:
|
case libnmdc.EVENT_PUBLIC:
|
||||||
if hubEvent.Nick == s.upstreamLauncher.Self.Nick {
|
if hubEvent.Nick == s.clientNick() {
|
||||||
// irc doesn't echo our own pubchat
|
// irc doesn't echo our own pubchat
|
||||||
} 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
|
||||||
@ -311,11 +311,11 @@ func (s *Server) handleCommand(command string, args []string) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if s.upstreamLauncher.Self.Nick == "" {
|
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 = args[0]
|
||||||
|
|
||||||
} else if args[0] == s.upstreamLauncher.Self.Nick {
|
} else if args[0] == 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
|
||||||
|
|
||||||
@ -334,7 +334,7 @@ func (s *Server) handleCommand(command string, args []string) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if s.upstreamLauncher.Self.Nick == "" {
|
if s.clientNick() == "" {
|
||||||
// Whatever, treat it as a NICK call (non-strict client handshake) and take the username field to be the intended nick
|
// Whatever, treat it as a NICK call (non-strict client handshake) and take the username field to be the intended nick
|
||||||
// This will allow Lite IRC's bad handshake to log in (as long as the username and the nickname are the same)
|
// This will allow Lite IRC's bad handshake to log in (as long as the username and the nickname are the same)
|
||||||
s.upstreamLauncher.Self.Nick = args[0]
|
s.upstreamLauncher.Self.Nick = args[0]
|
||||||
@ -388,7 +388,7 @@ func (s *Server) handleRegisteredCommand(command string, args []string) {
|
|||||||
s.clientState = CSJoined
|
s.clientState = CSJoined
|
||||||
|
|
||||||
// Acknowledge
|
// Acknowledge
|
||||||
s.reply(rplJoin, s.upstreamLauncher.Self.Nick, BLESSED_CHANNEL)
|
s.reply(rplJoin, s.clientNick(), BLESSED_CHANNEL)
|
||||||
|
|
||||||
// Send (initially just us) nicklist for the chat channel
|
// Send (initially just us) nicklist for the chat channel
|
||||||
//s.sendNames()
|
//s.sendNames()
|
||||||
@ -456,7 +456,7 @@ func (s *Server) handleJoinedCommand(command string, args []string) {
|
|||||||
|
|
||||||
if args[0] == BLESSED_CHANNEL {
|
if args[0] == BLESSED_CHANNEL {
|
||||||
// You can check out any time you like, but you can never leave
|
// You can check out any time you like, but you can never leave
|
||||||
s.reply(rplJoin, s.upstreamLauncher.Self.Nick, BLESSED_CHANNEL)
|
s.reply(rplJoin, s.clientNick(), BLESSED_CHANNEL)
|
||||||
s.sendNames()
|
s.sendNames()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -614,11 +614,11 @@ func (s *Server) sendChannelMode() {
|
|||||||
func (s *Server) sendWho(arg string) {
|
func (s *Server) sendWho(arg string) {
|
||||||
if arg == BLESSED_CHANNEL {
|
if arg == BLESSED_CHANNEL {
|
||||||
// always include ourselves
|
// always include ourselves
|
||||||
s.reply(rplWho, s.upstreamLauncher.Self.Nick, arg)
|
s.reply(rplWho, s.clientNick(), arg)
|
||||||
|
|
||||||
s.upstream.Users(func(u *map[string]libnmdc.UserInfo) error {
|
s.upstream.Users(func(u *map[string]libnmdc.UserInfo) error {
|
||||||
for nick, _ := range *u {
|
for nick, _ := range *u {
|
||||||
if nick != s.upstreamLauncher.Self.Nick { // but don't repeat ourselves
|
if nick != s.clientNick() { // but don't repeat ourselves
|
||||||
s.reply(rplWho, nick, arg)
|
s.reply(rplWho, nick, arg)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -660,37 +660,41 @@ func (s *Server) sendMOTD(motd string) {
|
|||||||
s.reply(rplEndOfMOTD)
|
s.reply(rplEndOfMOTD)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *Server) clientNick() string {
|
||||||
|
return s.upstreamLauncher.Self.Nick
|
||||||
|
}
|
||||||
|
|
||||||
// Send a reply to a user with the code specified
|
// Send a reply to a user with the code specified
|
||||||
func (s *Server) reply(code replyCode, args ...string) {
|
func (s *Server) reply(code replyCode, args ...string) {
|
||||||
|
|
||||||
switch code {
|
switch code {
|
||||||
case rplWelcome:
|
case rplWelcome:
|
||||||
s.writeClient(fmt.Sprintf(":%s 001 %s :Welcome to %s", s.name, s.upstreamLauncher.Self.Nick, s.name))
|
s.writeClient(fmt.Sprintf(":%s 001 %s :Welcome to %s", s.name, s.clientNick(), s.name))
|
||||||
s.writeClient(fmt.Sprintf(":%s 005 %s NAMESX CHANTYPES=# :are supported by this server", s.name, s.upstreamLauncher.Self.Nick))
|
s.writeClient(fmt.Sprintf(":%s 005 %s NAMESX CHANTYPES=# :are supported by this server", s.name, s.clientNick()))
|
||||||
|
|
||||||
case rplJoin:
|
case rplJoin:
|
||||||
s.writeClient(fmt.Sprintf(":%s JOIN %s", args[0], args[1]))
|
s.writeClient(fmt.Sprintf(":%s JOIN %s", args[0], args[1]))
|
||||||
case rplPart:
|
case rplPart:
|
||||||
s.writeClient(fmt.Sprintf(":%s PART %s %s", args[0], args[1], args[2]))
|
s.writeClient(fmt.Sprintf(":%s PART %s %s", args[0], args[1], args[2]))
|
||||||
case rplTopic:
|
case rplTopic:
|
||||||
s.writeClient(fmt.Sprintf(":%s 332 %s %s :%s", s.name, s.upstreamLauncher.Self.Nick, args[0], args[1]))
|
s.writeClient(fmt.Sprintf(":%s 332 %s %s :%s", s.name, s.clientNick(), args[0], args[1]))
|
||||||
case rplNoTopic:
|
case rplNoTopic:
|
||||||
s.writeClient(fmt.Sprintf(":%s 331 %s %s :No topic is set", s.name, s.upstreamLauncher.Self.Nick, args[0]))
|
s.writeClient(fmt.Sprintf(":%s 331 %s %s :No topic is set", s.name, s.clientNick(), args[0]))
|
||||||
|
|
||||||
case rplNames:
|
case rplNames:
|
||||||
s.writeClient(fmt.Sprintf(":%s 353 %s = %s :%s", s.name, s.upstreamLauncher.Self.Nick, args[0], args[1]))
|
s.writeClient(fmt.Sprintf(":%s 353 %s = %s :%s", s.name, s.clientNick(), args[0], args[1]))
|
||||||
case rplEndOfNames:
|
case rplEndOfNames:
|
||||||
s.writeClient(fmt.Sprintf(":%s 366 %s %s :End of NAMES list", s.name, s.upstreamLauncher.Self.Nick, args[0]))
|
s.writeClient(fmt.Sprintf(":%s 366 %s %s :End of NAMES list", s.name, s.clientNick(), args[0]))
|
||||||
|
|
||||||
case rplWho:
|
case rplWho:
|
||||||
s.writeClient(fmt.Sprintf(":%s 352 %s %s %s %s %s %s H :0 %s", s.name, s.upstreamLauncher.Self.Nick, args[1], args[0], args[0], s.name, args[0], args[0]))
|
s.writeClient(fmt.Sprintf(":%s 352 %s %s %s %s %s %s H :0 %s", s.name, s.clientNick(), args[1], args[0], args[0], s.name, args[0], args[0]))
|
||||||
case rplEndOfWho:
|
case rplEndOfWho:
|
||||||
s.writeClient(fmt.Sprintf(":%s 315 %s %s :End of WHO list", s.name, s.upstreamLauncher.Self.Nick, args[0]))
|
s.writeClient(fmt.Sprintf(":%s 315 %s %s :End of WHO list", s.name, s.clientNick(), args[0]))
|
||||||
|
|
||||||
case rplNickChange:
|
case rplNickChange:
|
||||||
s.writeClient(fmt.Sprintf(":%s NICK %s", args[0], args[1]))
|
s.writeClient(fmt.Sprintf(":%s NICK %s", args[0], args[1]))
|
||||||
case rplKill:
|
case rplKill:
|
||||||
s.writeClient(fmt.Sprintf(":%s KILL %s A %s", args[0], s.upstreamLauncher.Self.Nick, args[1]))
|
s.writeClient(fmt.Sprintf(":%s KILL %s A %s", args[0], s.clientNick(), args[1]))
|
||||||
|
|
||||||
case rplMsg:
|
case rplMsg:
|
||||||
for _, itm := range strings.Split(args[2], "\n") {
|
for _, itm := range strings.Split(args[2], "\n") {
|
||||||
@ -698,53 +702,53 @@ func (s *Server) reply(code replyCode, args ...string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
case rplList:
|
case rplList:
|
||||||
s.writeClient(fmt.Sprintf(":%s 322 %s %s", s.name, s.upstreamLauncher.Self.Nick, args[0]))
|
s.writeClient(fmt.Sprintf(":%s 322 %s %s", s.name, s.clientNick(), args[0]))
|
||||||
case rplListEnd:
|
case rplListEnd:
|
||||||
s.writeClient(fmt.Sprintf(":%s 323 %s", s.name, s.upstreamLauncher.Self.Nick))
|
s.writeClient(fmt.Sprintf(":%s 323 %s", s.name, s.clientNick()))
|
||||||
|
|
||||||
case rplOper:
|
case rplOper:
|
||||||
s.writeClient(fmt.Sprintf(":%s 381 %s :You are now an operator", s.name, s.upstreamLauncher.Self.Nick))
|
s.writeClient(fmt.Sprintf(":%s 381 %s :You are now an operator", s.name, s.clientNick()))
|
||||||
case rplChannelModeIs:
|
case rplChannelModeIs:
|
||||||
s.writeClient(fmt.Sprintf(":%s 324 %s %s %s %s", s.name, s.upstreamLauncher.Self.Nick, args[0], args[1], args[2]))
|
s.writeClient(fmt.Sprintf(":%s 324 %s %s %s %s", s.name, s.clientNick(), args[0], args[1], args[2]))
|
||||||
case rplKick:
|
case rplKick:
|
||||||
s.writeClient(fmt.Sprintf(":%s KICK %s %s %s", args[0], args[1], args[2], args[3]))
|
s.writeClient(fmt.Sprintf(":%s KICK %s %s %s", args[0], args[1], args[2], args[3]))
|
||||||
case rplInfo:
|
case rplInfo:
|
||||||
s.writeClient(fmt.Sprintf(":%s 371 %s :%s", s.name, s.upstreamLauncher.Self.Nick, args[0]))
|
s.writeClient(fmt.Sprintf(":%s 371 %s :%s", s.name, s.clientNick(), args[0]))
|
||||||
case rplVersion:
|
case rplVersion:
|
||||||
s.writeClient(fmt.Sprintf(":%s 351 %s %s", s.name, s.upstreamLauncher.Self.Nick, args[0]))
|
s.writeClient(fmt.Sprintf(":%s 351 %s %s", s.name, s.clientNick(), args[0]))
|
||||||
|
|
||||||
case rplMOTDStart:
|
case rplMOTDStart:
|
||||||
s.writeClient(fmt.Sprintf(":%s 375 %s :- Message of the day - ", s.name, s.upstreamLauncher.Self.Nick))
|
s.writeClient(fmt.Sprintf(":%s 375 %s :- Message of the day - ", s.name, s.clientNick()))
|
||||||
case rplMOTD:
|
case rplMOTD:
|
||||||
s.writeClient(fmt.Sprintf(":%s 372 %s :- %s", s.name, s.upstreamLauncher.Self.Nick, args[0]))
|
s.writeClient(fmt.Sprintf(":%s 372 %s :- %s", s.name, s.clientNick(), args[0]))
|
||||||
case rplEndOfMOTD:
|
case rplEndOfMOTD:
|
||||||
s.writeClient(fmt.Sprintf(":%s 376 %s :- End of MOTD", s.name, s.upstreamLauncher.Self.Nick))
|
s.writeClient(fmt.Sprintf(":%s 376 %s :- End of MOTD", s.name, s.clientNick()))
|
||||||
|
|
||||||
case rplPong:
|
case rplPong:
|
||||||
s.writeClient(fmt.Sprintf(":%s PONG %s %s", s.name, s.upstreamLauncher.Self.Nick, args[0]))
|
s.writeClient(fmt.Sprintf(":%s PONG %s %s", s.name, s.clientNick(), args[0]))
|
||||||
|
|
||||||
case errMoreArgs:
|
case errMoreArgs:
|
||||||
s.writeClient(fmt.Sprintf(":%s 461 %s :Not enough params", s.name, s.upstreamLauncher.Self.Nick))
|
s.writeClient(fmt.Sprintf(":%s 461 %s :Not enough params", s.name, s.clientNick()))
|
||||||
case errNoNick:
|
case errNoNick:
|
||||||
s.writeClient(fmt.Sprintf(":%s 431 %s :No nickname given", s.name, s.upstreamLauncher.Self.Nick))
|
s.writeClient(fmt.Sprintf(":%s 431 %s :No nickname given", s.name, s.clientNick()))
|
||||||
case errInvalidNick:
|
case errInvalidNick:
|
||||||
s.writeClient(fmt.Sprintf(":%s 432 %s %s :Erronenous nickname", s.name, s.upstreamLauncher.Self.Nick, args[0]))
|
s.writeClient(fmt.Sprintf(":%s 432 %s %s :Erronenous nickname", s.name, s.clientNick(), args[0]))
|
||||||
case errNickInUse:
|
case errNickInUse:
|
||||||
s.writeClient(fmt.Sprintf(":%s 433 %s %s :Nick already in use", s.name, s.upstreamLauncher.Self.Nick, args[0]))
|
s.writeClient(fmt.Sprintf(":%s 433 %s %s :Nick already in use", s.name, s.clientNick(), args[0]))
|
||||||
case errAlreadyReg:
|
case errAlreadyReg:
|
||||||
s.writeClient(fmt.Sprintf(":%s 462 :You need a valid nick first", s.name))
|
s.writeClient(fmt.Sprintf(":%s 462 :You need a valid nick first", s.name))
|
||||||
case errNoSuchNick:
|
case errNoSuchNick:
|
||||||
s.writeClient(fmt.Sprintf(":%s 401 %s %s :No such nick/channel", s.name, s.upstreamLauncher.Self.Nick, args[0]))
|
s.writeClient(fmt.Sprintf(":%s 401 %s %s :No such nick/channel", s.name, s.clientNick(), args[0]))
|
||||||
case errUnknownCommand:
|
case errUnknownCommand:
|
||||||
s.writeClient(fmt.Sprintf(":%s 421 %s %s :Unknown command", s.name, s.upstreamLauncher.Self.Nick, args[0]))
|
s.writeClient(fmt.Sprintf(":%s 421 %s %s :Unknown command", s.name, s.clientNick(), args[0]))
|
||||||
case errNotReg:
|
case errNotReg:
|
||||||
s.writeClient(fmt.Sprintf(":%s 451 :- You have not registered", s.name))
|
s.writeClient(fmt.Sprintf(":%s 451 :- You have not registered", s.name))
|
||||||
case errPassword:
|
case errPassword:
|
||||||
s.writeClient(fmt.Sprintf(":%s 464 %s :Error, password incorrect", s.name, s.upstreamLauncher.Self.Nick))
|
s.writeClient(fmt.Sprintf(":%s 464 %s :Error, password incorrect", s.name, s.clientNick()))
|
||||||
case errNoPriv:
|
case errNoPriv:
|
||||||
s.writeClient(fmt.Sprintf(":%s 481 %s :Permission denied", s.name, s.upstreamLauncher.Self.Nick))
|
s.writeClient(fmt.Sprintf(":%s 481 %s :Permission denied", s.name, s.clientNick()))
|
||||||
case errCannotSend:
|
case errCannotSend:
|
||||||
s.writeClient(fmt.Sprintf(":%s 404 %s %s :Cannot send to channel", s.name, s.upstreamLauncher.Self.Nick, args[0]))
|
s.writeClient(fmt.Sprintf(":%s 404 %s %s :Cannot send to channel", s.name, s.clientNick(), args[0]))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user