diff options
| author | Nakidai <nakidai@disroot.org> | 2026-02-10 17:31:35 +0300 |
|---|---|---|
| committer | Nakidai <nakidai@disroot.org> | 2026-02-10 17:31:35 +0300 |
| commit | 7d51a93567e7f1e70a0e7f006bdf8a248f94d1ee (patch) | |
| tree | abcbb7d0805b203967645845f82a51c517411141 | |
| parent | 1a6500b5cb4eaf74b5d47f683a8a9bdc2985ddda (diff) | |
| download | libreircd-7d51a93567e7f1e70a0e7f006bdf8a248f94d1ee.tar.gz libreircd-7d51a93567e7f1e70a0e7f006bdf8a248f94d1ee.zip | |
Factor writechanf() calls out to a macro
As they will anyway repeat a lot of times, it's better to make a macro for that. Also now this look better and printing doesn't take too much attention within a block of logic
| -rw-r--r-- | handle.c | 32 |
1 files changed, 10 insertions, 22 deletions
diff --git a/handle.c b/handle.c index 0b8e557..377a95e 100644 --- a/handle.c +++ b/handle.c @@ -98,6 +98,13 @@ mode_channel(struct Message *msg, struct Peer *peer) ensure(modes & CHANNEL_OPER || peer->modes & OPER, reply(peer, 482, channel->name), 0); +/* to not repeat this each time... */ +#define announce_change(issingle) writechanf( \ + 0, channel, \ + issingle ? ":%s!%s@%s MODE %s %c%c" : ":%s!%s@%s MODE %s %c%c %s", \ + getnick(peer), peer->user, peer->host, channel->name, \ + parsed->set ? '+' : '-', parsed->mode, parsed->param \ +) parsed = channel_modes_parse(msg); for (; parsed->param || parsed->mode; ++parsed) switch (parsed->mode) { @@ -109,34 +116,14 @@ mode_channel(struct Message *msg, struct Peer *peer) break; ensure(i != channel->peers_c, reply(peer, 441, parsed->param, channel->name), 0); - writechanf( - 0, - channel, - ":%s!%s@%s MODE %s %co %s", - getnick(peer), - peer->user, - peer->host, - channel->name, - parsed->set ? '+' : '-', - parsed->param - ); - + announce_change(0); if (parsed->set) channel->peers[i].modes |= CHANNEL_OPER; else channel->peers[i].modes &= ~CHANNEL_OPER; break; case 's': /* TODO: implement +s. For now it's just a some mode with no param */ - writechanf( - 0, - channel, - ":%s!%s@%s MODE %s %cs", - getnick(peer), - peer->user, - peer->host, - channel->name, - parsed->set ? '+' : '-' - ); + announce_change(1); if (parsed->set) channel->modes |= CHANNEL_SECRET; else @@ -147,6 +134,7 @@ mode_channel(struct Message *msg, struct Peer *peer) reply(peer, 472, modebuf, channel->name); return 0; } +#undef announce_change return 0; } |