From abd4dc788b5c7ecefa342b7b9c1d5871ff5f56df Mon Sep 17 00:00:00 2001 From: Egor Date: Wed, 11 May 2022 13:52:31 +0300 Subject: [PATCH] umode improvements --- common.h | 1 - irc.c | 34 ++++++++++++++++++++++++++-------- ircfmt.c | 4 ++-- 3 files changed, 28 insertions(+), 11 deletions(-) diff --git a/common.h b/common.h index 31d4ea1..0e4106b 100644 --- a/common.h +++ b/common.h @@ -13,7 +13,6 @@ struct tls; #define SETBIT(var, bit, val) ((void)((val) ? ((var)|=(bit)) : ((var)&=~(bit)))) #define UMODE_INVISIBLE 1 #define UMODE_OPER 2 -#define UMODE_LOPER 4 #define UMODE_REGISTERED 8 #define UMODE_WALLOPS 16 #define UMODE_SECURE 32 diff --git a/irc.c b/irc.c index 62668f7..e8ded31 100644 --- a/irc.c +++ b/irc.c @@ -80,6 +80,18 @@ void sendbuf_visible(struct client_data *client) { } while (trie_findnext(&f2) == 1); } while (trie_findnext(&f1) == 1); } +const char *format_umodes(struct client_data *cl) { + static char umodes[6] = ""; + char *p = umodes; + *p++ = '+'; + if (cl->umode & UMODE_INVISIBLE) *p++ = 'i'; + if (cl->umode & UMODE_OPER) *p++ = 'o'; + if (cl->umode & UMODE_REGISTERED) *p++ = 'r'; + if (cl->umode & UMODE_WALLOPS) *p++ = 'w'; + if (cl->umode & UMODE_SECURE) *p++ = 'Z'; + *p++ = '\0'; + return umodes; +} int parsePacket(struct client_data *client) { char *source = NULL; char *command = NULL; @@ -403,14 +415,12 @@ int processPacket(struct client_data *client, char *source, char *command, int a struct client_data *cl = findClient(nick); if (!cl) return err_nosuchnick(client, nick), sendbuf(client), 0; - copy_strf(&databuf, ":%s 221 %s +", hostname, client->nick); - if (cl->umode & UMODE_INVISIBLE) append_str(&databuf, "i"); - if (cl->umode & UMODE_OPER) append_str(&databuf, "o"); - if (cl->umode & UMODE_LOPER) append_str(&databuf, "O"); - if (cl->umode & UMODE_REGISTERED) append_str(&databuf, "r"); - if (cl->umode & UMODE_WALLOPS) append_str(&databuf, "w"); - if (cl->umode & UMODE_SECURE) append_str(&databuf, "Z"); - append_str(&databuf, "\r\n"); + if (client->FD != cl->FD) { + copy_strf(&databuf, ":%s 502 %s :Can't view mode for other users\n", hostname, client->nick); + sendbuf(client); + return 0; + } + copy_strf(&databuf, ":%s 221 %s %s\r\n", hostname, client->nick, format_umodes(client)); sendbuf(client); } else { struct channel *chan = findChannel(nick); @@ -459,6 +469,11 @@ int processPacket(struct client_data *client, char *source, char *command, int a copy_strf(&databuf, ":%s MODE %s %si\n", hostname, client->nick, is_plus?"+":"-"); sendbuf(client); break; + case 'w': + SETBIT(cl->umode, UMODE_WALLOPS, is_plus); + copy_strf(&databuf, ":%s MODE %s %sw\n", hostname, client->nick, is_plus?"+":"-"); + sendbuf(client); + break; case 'o': if (!is_plus) { SETBIT(cl->umode, UMODE_OPER, is_plus); @@ -795,6 +810,7 @@ void newUser(struct client_data *client) { if (!client->nick) return; client->regstate = REG_REGISTERED; + client->umode |= UMODE_INVISIBLE | UMODE_WALLOPS; rpl_welcome(client), sendbuf(client); rpl_yourhost(client), sendbuf(client); rpl_created(client), sendbuf(client); @@ -804,6 +820,8 @@ void newUser(struct client_data *client) { sendbuf(client); copy_strf(&databuf, ":%s 252 %s :Jannies don't exist\n", hostname, client->nick); sendbuf(client); + copy_strf(&databuf, ":%s 221 %s %s\r\n", hostname, client->nick, format_umodes(client)); + sendbuf(client); sendMOTD(client); } diff --git a/ircfmt.c b/ircfmt.c index 8aec38e..73bb403 100644 --- a/ircfmt.c +++ b/ircfmt.c @@ -98,11 +98,11 @@ void rpl_created(struct client_data *client) // 003 } void rpl_myinfo(struct client_data *client) // 004 { - copy_strf(&databuf, ":%s 004 %s PatchyIRCD 0.0.1 i nt\n", hostname, client->nick); + copy_strf(&databuf, ":%s 004 %s PatchyIRCD 0.0.1 iworZ beIklPimnst\n", hostname, client->nick); } void rpl_isupport(struct client_data *client) // 005 { - copy_strf(&databuf, ":%s 005 %s CASEMAPPING=rfc1459 NICKLEN=%u CHANMODES=beI,k,l,Pimnst CHANTYPES=#& PREFIX=(ov)@+ :are supported by this server\n", hostname, client->nick, MAX_NICKLEN-1); + copy_strf(&databuf, ":%s 005 %s CASEMAPPING=rfc1459 NICKLEN=%u EXCEPTS=e INVEX=I MAXTARGETS=1 CHANMODES=beI,k,l,Pimnst CHANTYPES=#& PREFIX=(ov)@+ STATUSMSG=@+ :are supported by this server\n", hostname, client->nick, MAX_NICKLEN-1); } // 010 RPL_BOUNC -- 2.56.0