simplify
--HG-- branch : nmdc-ircfrontend
This commit is contained in:
parent
3d582d2004
commit
62487dd437
40
server.go
40
server.go
@ -138,8 +138,7 @@ func (s *Server) upstreamWorker() {
|
|||||||
s.sendClientGlobalMessage("Upstream: " + hubEvent.StateChange.Format())
|
s.sendClientGlobalMessage("Upstream: " + hubEvent.StateChange.Format())
|
||||||
|
|
||||||
case libnmdc.EVENT_HUBNAME_CHANGED:
|
case libnmdc.EVENT_HUBNAME_CHANGED:
|
||||||
s.reply(rplTopic, BLESSED_CHANNEL, hubEvent.Nick)
|
s.sendChannelTopic(hubEvent.Nick)
|
||||||
// c.reply(rplNoTopic, BLESSED_CHANNEL)
|
|
||||||
|
|
||||||
case libnmdc.EVENT_PRIVATE:
|
case libnmdc.EVENT_PRIVATE:
|
||||||
s.reply(rplMsg, s.clientNick, hubEvent.Nick, hubEvent.Message)
|
s.reply(rplMsg, s.clientNick, hubEvent.Nick, hubEvent.Message)
|
||||||
@ -228,7 +227,6 @@ func (s *Server) handleRegisteredCommand(command string, args []string) {
|
|||||||
|
|
||||||
switch command {
|
switch command {
|
||||||
case "JOIN":
|
case "JOIN":
|
||||||
|
|
||||||
if len(args) < 1 {
|
if len(args) < 1 {
|
||||||
s.reply(errMoreArgs)
|
s.reply(errMoreArgs)
|
||||||
return
|
return
|
||||||
@ -236,21 +234,18 @@ func (s *Server) handleRegisteredCommand(command string, args []string) {
|
|||||||
|
|
||||||
switch args[0] {
|
switch args[0] {
|
||||||
case BLESSED_CHANNEL:
|
case BLESSED_CHANNEL:
|
||||||
// That's fine, but they're already there
|
// Ignore, but they're already there
|
||||||
case "0":
|
case "0":
|
||||||
// Intend to quit all channels, but we don't allow that
|
// Ignore, Intend to quit all channels but we don't allow that
|
||||||
default:
|
default:
|
||||||
s.reply(rplKill, "There is only '"+BLESSED_CHANNEL+"'.", "")
|
s.reply(rplKill, "There is only '"+BLESSED_CHANNEL+"'.", "")
|
||||||
s.DisconnectClient()
|
s.DisconnectClient()
|
||||||
}
|
}
|
||||||
|
|
||||||
case "PART":
|
case "PART":
|
||||||
|
// 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
|
|
||||||
// we'll need to transmit s.reply(rplPart, s.clientNick, channel.name, reason) messages on behalf of other nmdc users, though
|
|
||||||
|
|
||||||
case "PRIVMSG":
|
case "PRIVMSG":
|
||||||
|
|
||||||
if len(args) < 2 {
|
if len(args) < 2 {
|
||||||
s.reply(errMoreArgs)
|
s.reply(errMoreArgs)
|
||||||
return
|
return
|
||||||
@ -273,40 +268,31 @@ func (s *Server) handleRegisteredCommand(command string, args []string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
case "QUIT":
|
case "QUIT":
|
||||||
|
|
||||||
s.DisconnectClient()
|
s.DisconnectClient()
|
||||||
|
|
||||||
case "TOPIC":
|
case "TOPIC":
|
||||||
|
|
||||||
if len(args) < 1 {
|
if len(args) < 1 {
|
||||||
s.reply(errMoreArgs)
|
s.reply(errMoreArgs)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
exists := strings.ToLower(args[0]) == BLESSED_CHANNEL
|
if strings.ToLower(args[0]) != BLESSED_CHANNEL {
|
||||||
if exists == false {
|
|
||||||
s.reply(errNoSuchNick, args[0])
|
s.reply(errNoSuchNick, args[0])
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Valid topic get
|
|
||||||
if len(args) == 1 {
|
if len(args) == 1 {
|
||||||
s.reply(rplTopic, BLESSED_CHANNEL, s.upstream.HubName)
|
s.sendChannelTopic(s.upstream.HubName) // Valid topic get
|
||||||
return
|
} else {
|
||||||
|
s.reply(errNoPriv) // Disallow topic set
|
||||||
}
|
}
|
||||||
|
|
||||||
// Disallow topic set
|
|
||||||
s.reply(errNoPriv)
|
|
||||||
return
|
|
||||||
|
|
||||||
case "LIST":
|
case "LIST":
|
||||||
|
|
||||||
listItem := fmt.Sprintf("%s %d :%s", BLESSED_CHANNEL, len(s.upstream.Users), s.upstream.HubName)
|
listItem := fmt.Sprintf("%s %d :%s", BLESSED_CHANNEL, len(s.upstream.Users), s.upstream.HubName)
|
||||||
s.reply(rplList, listItem)
|
s.reply(rplList, listItem)
|
||||||
s.reply(rplListEnd)
|
s.reply(rplListEnd)
|
||||||
|
|
||||||
case "OPER":
|
case "OPER":
|
||||||
|
|
||||||
if len(args) < 2 {
|
if len(args) < 2 {
|
||||||
s.reply(errMoreArgs)
|
s.reply(errMoreArgs)
|
||||||
return
|
return
|
||||||
@ -316,7 +302,6 @@ func (s *Server) handleRegisteredCommand(command string, args []string) {
|
|||||||
s.reply(errPassword)
|
s.reply(errPassword)
|
||||||
|
|
||||||
case "KILL":
|
case "KILL":
|
||||||
|
|
||||||
s.reply(errNoPriv)
|
s.reply(errNoPriv)
|
||||||
return
|
return
|
||||||
|
|
||||||
@ -330,7 +315,6 @@ func (s *Server) handleRegisteredCommand(command string, args []string) {
|
|||||||
return
|
return
|
||||||
|
|
||||||
case "MODE":
|
case "MODE":
|
||||||
|
|
||||||
if len(args) < 1 {
|
if len(args) < 1 {
|
||||||
s.reply(errMoreArgs)
|
s.reply(errMoreArgs)
|
||||||
return
|
return
|
||||||
@ -363,6 +347,14 @@ func (s *Server) DisconnectClient() {
|
|||||||
// Readloop will stop, which kills the upstream connection too
|
// Readloop will stop, which kills the upstream connection too
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *Server) sendChannelTopic(topic string) {
|
||||||
|
if len(topic) > 0 {
|
||||||
|
s.reply(rplTopic, BLESSED_CHANNEL, s.upstream.HubName)
|
||||||
|
} else {
|
||||||
|
s.reply(rplNoTopic, BLESSED_CHANNEL)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (s *Server) sendClientGlobalMessage(motd string) {
|
func (s *Server) sendClientGlobalMessage(motd string) {
|
||||||
s.reply(rplMOTDStart)
|
s.reply(rplMOTDStart)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user