44 "fmt"
55 "strings"
66 "time"
7+
8+ "nxircd/config"
79)
810
911type ClientCmd struct {
@@ -86,10 +88,39 @@ var clientCmdMap = map[string]ClientCmd{
8688 minParams : 1 ,
8789 handler : whoisUCmdHandler ,
8890 },
91+ "NAMES" : {
92+ minParams : 1 ,
93+ handler : namesUCmdHandler ,
94+ },
95+ "OPER" : {
96+ minParams : 2 ,
97+ handler : operUCmdHandler ,
98+ },
99+ "KILL" : {
100+ minParams : 1 ,
101+ handler : killUCmdHandler ,
102+ },
103+ }
104+
105+ func namesUCmdHandler (srv * Server , cli * Client , m * Message ) error {
106+ target := m .Args [0 ]
107+
108+ if ValidChannel (target ) {
109+ ch := srv .FindChannel (target )
110+ if ch == nil {
111+ cli .SendNumeric (ERR_NOSUCHCHANNEL , target , "no such channel" )
112+ return fmt .Errorf ("no such channel" )
113+ }
114+ ch .Names (cli )
115+ return nil
116+ }
117+
118+ cli .SendNumeric (ERR_NOSUCHCHANNEL , target , "invalid channel name" )
119+ return fmt .Errorf ("invalid channel" )
89120}
90121
91122func pingUCmdHandler (src * Server , cli * Client , m * Message ) error {
92- cli .SendFromServer ("PING " , fmt .Sprintf ("%d" , time .Now ().Unix ()))
123+ cli .SendFromServer ("PONG " , fmt .Sprintf ("%d" , time .Now ().Unix ()))
93124 return nil
94125}
95126
@@ -98,13 +129,13 @@ func nickUCmdHandler(srv *Server, cli *Client, m *Message) error {
98129
99130 if srv .NickInUse (nick ) {
100131 // TODO Send no such nick
101- cli .SendNumeric (ERR_NICKNAMEINUSE , nick , "*" , " nick in use" )
132+ cli .SendNumeric (ERR_NICKNAMEINUSE , nick , "nick in use" )
102133 return fmt .Errorf ("nick in use" )
103134 }
104135
105136 if ! ValidNick (nick ) {
106137 // This is what unreal sends? cray
107- cli .SendNumeric (ERR_NICKNAMEINUSE , nick , "*" , " Nickname is unavailable: Illegal characters" )
138+ cli .SendNumeric (ERR_NICKNAMEINUSE , nick , "Nickname is unavailable: Illegal characters" )
108139 return fmt .Errorf ("invalid nick" )
109140 }
110141
@@ -124,9 +155,12 @@ func userUCmdHandler(srv *Server, cli *Client, m *Message) error {
124155
125156 cli .Ident = m .Args [0 ]
126157 cli .Name = m .Args [3 ]
158+ cli .registered = true
127159
128160 srv .Greet (cli )
129161
162+ srv .SNotice (fmt .Sprintf ("Client connecting: %s (%s@%s) [%s] on %s" , cli .Nick , cli .Ident , cli .RealHost , cli .IP , cli .Server .Name ))
163+
130164 srv .Log .InfoF ("Client Connected: %s" , cli .HostMask ())
131165
132166 return nil
@@ -187,13 +221,8 @@ func whoUCmdHandler(srv *Server, cli *Client, m *Message) error {
187221}
188222
189223func quitUCmdHandler (srv * Server , cli * Client , m * Message ) error {
190- msg := m .Args [0 ]
191-
192- for _ , ch := range cli .Channels .list {
193- ch .Quit (cli , msg )
194- }
195-
196224 srv .Clients .Delete (cli )
225+ cli .Quit (m .Args [0 ])
197226 return nil
198227}
199228
@@ -229,7 +258,7 @@ func msgUCmdHandler(srv *Server, cli *Client, m *Message) error {
229258 if ValidChannel (target ) {
230259 ch := srv .FindChannel (target )
231260 if ch == nil {
232- cli .SendNumeric (ERR_NOSUCHCHANNEL , target , "*" , " no such channel" )
261+ cli .SendNumeric (ERR_NOSUCHCHANNEL , target , "no such channel" )
233262 return fmt .Errorf ("no such channel" )
234263 }
235264 ch .PrivMsg (cli , m .Args [1 ])
@@ -238,7 +267,7 @@ func msgUCmdHandler(srv *Server, cli *Client, m *Message) error {
238267
239268 ct := srv .FindClient (target )
240269 if ct == nil {
241- cli .SendNumeric (ERR_NOSUCHNICK , target , "*" , " no such nick" )
270+ cli .SendNumeric (ERR_NOSUCHNICK , target , "no such nick" )
242271 return fmt .Errorf ("no such nick" )
243272 }
244273
@@ -252,7 +281,7 @@ func noticeUCmdHandler(srv *Server, cli *Client, m *Message) error {
252281 if ValidChannel (target ) {
253282 ch := srv .FindChannel (target )
254283 if ch == nil {
255- cli .SendNumeric (ERR_NOSUCHCHANNEL , target , "*" , " no such channel" )
284+ cli .SendNumeric (ERR_NOSUCHCHANNEL , target , "no such channel" )
256285 return fmt .Errorf ("no such channel" )
257286 }
258287 ch .Notice (cli , m .Args [1 ])
@@ -289,12 +318,12 @@ func modeUCmdHandler(srv *Server, cli *Client, m *Message) error {
289318 if ValidNick (target ) {
290319 client := srv .FindClient (target )
291320 if client == nil {
292- cli .SendNumeric (ERR_NOSUCHNICK , target , "*" , " no such nickname" )
321+ cli .SendNumeric (ERR_NOSUCHNICK , target , "no such nickname" )
293322 return nil
294323 }
295324
296325 changes := ParseUMode (m .Args [1 :]... )
297- client .ApplyModeChanges (changes )
326+ client .ApplyModeChanges (cli . Nick , changes )
298327 }
299328
300329 return nil
@@ -304,13 +333,13 @@ func topicUCmdHandler(srv *Server, cli *Client, m *Message) error {
304333 target := m .Args [0 ]
305334
306335 if ! ValidChannel (target ) {
307- cli .SendNumeric (ERR_NOSUCHCHANNEL , target , "*" , " no such channel: invalid channel name" )
336+ cli .SendNumeric (ERR_NOSUCHCHANNEL , target , "no such channel: invalid channel name" )
308337 return fmt .Errorf ("invalid channel" )
309338 }
310339
311340 ch := srv .FindChannel (target )
312341 if ch == nil {
313- cli .SendNumeric (ERR_NOSUCHCHANNEL , target , "*" , " no such channel" )
342+ cli .SendNumeric (ERR_NOSUCHCHANNEL , target , "no such channel" )
314343 return fmt .Errorf ("no such channel" )
315344 }
316345
@@ -320,7 +349,7 @@ func topicUCmdHandler(srv *Server, cli *Client, m *Message) error {
320349 }
321350
322351 if ! ch .IsOperator (cli ) {
323- cli .SendNumeric (ERR_NOPRIVS , target , "topic" , "invalid permissions " )
352+ cli .SendNumeric (ERR_NOPRIVILEGES , target , target , "topic: no permission. " )
324353 return fmt .Errorf ("no privs" )
325354 }
326355 ch .SetTopic (cli , m .Args [1 ])
@@ -330,18 +359,18 @@ func topicUCmdHandler(srv *Server, cli *Client, m *Message) error {
330359func kickUCmdHandler (srv * Server , cli * Client , m * Message ) error {
331360 target := m .Args [0 ]
332361 if ! ValidChannel (target ) {
333- cli .SendNumeric (ERR_NOSUCHCHANNEL , target , "*" , " no such channel: invalid channel name" )
362+ cli .SendNumeric (ERR_NOSUCHCHANNEL , target , "no such channel: invalid channel name" )
334363 return fmt .Errorf ("invalid channel" )
335364 }
336365
337366 ch := srv .FindChannel (target )
338367 if ch == nil {
339- cli .SendNumeric (ERR_NOSUCHCHANNEL , target , "*" , " no such channel" )
368+ cli .SendNumeric (ERR_NOSUCHCHANNEL , target , "no such channel" )
340369 return fmt .Errorf ("no such channel" )
341370 }
342371
343372 if ! ch .IsHalfOp (cli ) && ! ch .IsOperator (cli ) {
344- cli .SendNumeric (ERR_NOPRIVILEGES , "kick" , target , "no permissions." )
373+ cli .SendNumeric (ERR_NOPRIVILEGES , target , "kick: no permissions." )
345374 return fmt .Errorf ("no permissions" )
346375 }
347376
@@ -367,7 +396,7 @@ func listUCmdHandler(srv *Server, cli *Client, m *Message) error {
367396 for _ , channel := range srv .Channels .list {
368397 cli .SendNumeric (RPL_LIST , channel .Name , fmt .Sprintf ("%d" , channel .Clients .Count ()), fmt .Sprintf ("[+%s] %s" , channel .Modes .FlagString (), channel .Topic ))
369398 }
370- cli .SendNumeric (RPL_LISTEND , "*" , "end of /LIST" )
399+ cli .SendNumeric (RPL_LISTEND , "End of /LIST" )
371400
372401 return nil
373402}
@@ -382,3 +411,53 @@ func whoisUCmdHandler(srv *Server, cli *Client, m *Message) error {
382411 cli .Whois (target )
383412 return nil
384413}
414+
415+ func operUCmdHandler (srv * Server , cli * Client , m * Message ) error {
416+ var oc * config.IRCOp
417+
418+ for _ , oconf := range srv .Config .IrcOps {
419+ if oconf .User == m .Args [0 ] {
420+ oc = & oconf
421+ break
422+ }
423+ }
424+
425+ if oc == nil {
426+ srv .SNotice (fmt .Sprintf ("Failed oper attempt by %s (%s) [unknown acct]" , cli .Nick , cli .IdentHost ()))
427+ return fmt .Errorf ("invalid oper attempt (user)" )
428+ }
429+
430+ if oc .Pass != m .Args [1 ] {
431+ srv .SNotice (fmt .Sprintf ("Failed oper attempt by %s (%s) [%s] invalid password" , cli .Nick , cli .IdentHost (), oc .User ))
432+ return fmt .Errorf ("invalid oper attempt (pass)" )
433+ }
434+
435+ cli .Oper (* oc )
436+ return nil
437+ }
438+
439+ func killUCmdHandler (srv * Server , cli * Client , m * Message ) error {
440+ target := m .Args [0 ]
441+
442+ ct := srv .FindClient (target )
443+ if ct == nil {
444+ cli .SendNumeric (ERR_NOSUCHNICK , target , "no such nick" )
445+ return fmt .Errorf ("no such nick" )
446+ }
447+
448+ msg := "no reason"
449+ if len (m .Args ) > 1 {
450+ msg = m .Args [1 ]
451+ }
452+
453+ quitmsg := fmt .Sprintf ("Killed by %s (%s)" , cli .Nick , msg )
454+
455+ ct .Send ("" , "ERROR" , fmt .Sprintf ("Closing link: %s [%s] %s (%s)" , ct .Nick , ct .RealHost , cli .Nick , quitmsg ))
456+
457+ ct .sock .Close ()
458+
459+ // Received KILL message for [email protected] from _Twitch Path: manager.centralchat.net!_Twitch (.) 460+ srv .SNotice (fmt .Sprintf ("Received KILL message for %s from %s Path: %s!%s (%s)" , ct .HostMask (), cli .Nick , cli .Host , cli .Ident , quitmsg ))
461+
462+ return nil
463+ }
0 commit comments