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())
|
||||
|
||||
case libnmdc.EVENT_HUBNAME_CHANGED:
|
||||
s.reply(rplTopic, BLESSED_CHANNEL, hubEvent.Nick)
|
||||
// c.reply(rplNoTopic, BLESSED_CHANNEL)
|
||||
s.sendChannelTopic(hubEvent.Nick)
|
||||
|
||||
case libnmdc.EVENT_PRIVATE:
|
||||
s.reply(rplMsg, s.clientNick, hubEvent.Nick, hubEvent.Message)
|
||||
@ -228,7 +227,6 @@ func (s *Server) handleRegisteredCommand(command string, args []string) {
|
||||
|
||||
switch command {
|
||||
case "JOIN":
|
||||
|
||||
if len(args) < 1 {
|
||||
s.reply(errMoreArgs)
|
||||
return
|
||||
@ -236,21 +234,18 @@ func (s *Server) handleRegisteredCommand(command string, args []string) {
|
||||
|
||||
switch args[0] {
|
||||
case BLESSED_CHANNEL:
|
||||
// That's fine, but they're already there
|
||||
// Ignore, but they're already there
|
||||
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:
|
||||
s.reply(rplKill, "There is only '"+BLESSED_CHANNEL+"'.", "")
|
||||
s.DisconnectClient()
|
||||
}
|
||||
|
||||
case "PART":
|
||||
|
||||
// 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
|
||||
// You can check out any time you like, but you can never leave
|
||||
|
||||
case "PRIVMSG":
|
||||
|
||||
if len(args) < 2 {
|
||||
s.reply(errMoreArgs)
|
||||
return
|
||||
@ -273,40 +268,31 @@ func (s *Server) handleRegisteredCommand(command string, args []string) {
|
||||
}
|
||||
|
||||
case "QUIT":
|
||||
|
||||
s.DisconnectClient()
|
||||
|
||||
case "TOPIC":
|
||||
|
||||
if len(args) < 1 {
|
||||
s.reply(errMoreArgs)
|
||||
return
|
||||
}
|
||||
|
||||
exists := strings.ToLower(args[0]) == BLESSED_CHANNEL
|
||||
if exists == false {
|
||||
if strings.ToLower(args[0]) != BLESSED_CHANNEL {
|
||||
s.reply(errNoSuchNick, args[0])
|
||||
return
|
||||
}
|
||||
|
||||
// Valid topic get
|
||||
if len(args) == 1 {
|
||||
s.reply(rplTopic, BLESSED_CHANNEL, s.upstream.HubName)
|
||||
return
|
||||
s.sendChannelTopic(s.upstream.HubName) // Valid topic get
|
||||
} else {
|
||||
s.reply(errNoPriv) // Disallow topic set
|
||||
}
|
||||
|
||||
// Disallow topic set
|
||||
s.reply(errNoPriv)
|
||||
return
|
||||
|
||||
case "LIST":
|
||||
|
||||
listItem := fmt.Sprintf("%s %d :%s", BLESSED_CHANNEL, len(s.upstream.Users), s.upstream.HubName)
|
||||
s.reply(rplList, listItem)
|
||||
s.reply(rplListEnd)
|
||||
|
||||
case "OPER":
|
||||
|
||||
if len(args) < 2 {
|
||||
s.reply(errMoreArgs)
|
||||
return
|
||||
@ -316,7 +302,6 @@ func (s *Server) handleRegisteredCommand(command string, args []string) {
|
||||
s.reply(errPassword)
|
||||
|
||||
case "KILL":
|
||||
|
||||
s.reply(errNoPriv)
|
||||
return
|
||||
|
||||
@ -330,7 +315,6 @@ func (s *Server) handleRegisteredCommand(command string, args []string) {
|
||||
return
|
||||
|
||||
case "MODE":
|
||||
|
||||
if len(args) < 1 {
|
||||
s.reply(errMoreArgs)
|
||||
return
|
||||
@ -363,6 +347,14 @@ func (s *Server) DisconnectClient() {
|
||||
// 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) {
|
||||
s.reply(rplMOTDStart)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user