8000 Implement IRCv3 `extended-join` by hello-smile6 · Pull Request #300 · ngircd/ngircd · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Implement IRCv3 extended-join #300

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/ngircd/client-cap.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#define CLIENT_CAP_SUPPORTED 2 /* Client supports IRC capabilities */

#define CLIENT_CAP_MULTI_PREFIX 4 /* multi-prefix */
#define CLIENT_CAP_EXTENDED_JOIN 8 /* extended-join */

GLOBAL int Client_Cap PARAMS((CLIENT *Client));

Expand Down
8 changes: 6 additions & 2 deletions src/ngircd/irc-cap.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,16 @@ Parse_CAP(int Capabilities, char *Args)
ptr++;
if (strcmp(ptr, "multi-prefix") == 0)
Capabilities &= ~CLIENT_CAP_MULTI_PREFIX;
else if (strcmp(ptr, "extended-join") == 0)
Capabilities &= ~CLIENT_CAP_EXTENDED_JOIN;
else
return -1;
} else {
/* request capabilities */
if (strcmp(ptr, "multi-prefix") == 0)
Capabilities |= CLIENT_CAP_MULTI_PREFIX;
else if (strcmp(ptr, "extended-join") == 0)
Capabilities |= CLIENT_CAP_EXTENDED_JOIN;
else
return -1;
}
Expand All @@ -103,7 +107,7 @@ Get_CAP_String(int Capabilities)
txt[0] = '\0';

if (Capabilities & CLIENT_CAP_MULTI_PREFIX)
strlcat(txt, "multi-prefix ", sizeof(txt));
strlcat(txt, "multi-prefix extended-join ", sizeof(txt));

return txt;
}
Expand All @@ -123,7 +127,7 @@ Handle_CAP_LS(CLIENT *Client, UNUSED char *Arg)
Set_CAP_Negotiation(Client);

return IRC_WriteStrClient(Client,
"CAP %s LS :multi-prefix",
"CAP %s LS :multi-prefix extended-join",
Client_ID(Client));
}

Expand Down
56 changes: 49 additions & 7 deletions src/ngircd/irc-channel.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include "irc-macros.h"
#include "irc-write.h"
#include "conf.h"
#include "client-cap.h"

#include "irc-channel.h"

Expand Down Expand Up @@ -236,8 +237,39 @@ join_forward(CLIENT *Client, CLIENT *target, CHANNEL *chan,
}

/* tell users in this channel about the new client */
IRC_WriteStrChannelPrefix(Client, chan, target, false,
"JOIN :%s", channame);
CLIENT *c;
CHANNEL *Chan;
CONN_ID conn;
CL2CHAN *cl2chan;
Chan = chan;
cl2chan = Channel_FirstMember( Chan );
while(cl2chan) {
c = Channel_GetClient( cl2chan );
if (Client_Conn(c) <= NONE)
c = NULL;
else if(Client_Type(c) == CLIENT_SERVER)
c = NULL;
if(c)
c = Client_NextHop(c);
if(c && c != Client) {
/* Ok, another Client */
conn = Client_Conn(c);
if(Client_Cap(c) & CLIENT_CAP_EXTENDED_JOIN) {
char * account_name;
if(Client_AccountName(Client)) {
account_name = Client_AccountName(Client);
}
else {
account_name = "*";
}
IRC_WriteStrClientPrefix(c, Client, "JOIN %s %s :%s", channame, account_name, Client_Info(Client));
}
else {
IRC_WriteStrClientPrefix(c, Client, "JOIN %s", channame);
}
}
cl2chan = Channel_NextMember(Chan, cl2chan);
}

/* synchronize channel modes */
if (modes[1]) {
Expand All @@ -257,7 +289,21 @@ GLOBAL bool
IRC_Send_Channel_Info(CLIENT *Client, CHANNEL *Chan)
{
const char *topic;

if (Client_Type(Client) != CLIENT_USER)
return true;
/* acknowledge join */
CONN_ID conn;
conn = Client_Conn(Client);
if(Client_Cap(Client) & CLIENT_CAP_EXTENDED_JOIN) {
char * account_name;
if(Client_AccountName(Client))
account_name = Client_AccountName(Client);
else
account_name = "*";
Conn_WriteStr(conn, ":%s JOIN %s %s :%s", Client_MaskCloaked(Client), Channel_Name(Chan), account_name, Client_Info(Client));
}
else
Conn_WriteStr(conn, ":%s JOIN %s", Client_MaskCloaked(Client), Channel_Name(Chan));
/* Send the topic (if any) to the new client: */
topic = Channel_Topic(Chan);
assert(topic != NULL);
Expand Down Expand Up @@ -401,10 +447,6 @@ IRC_JOIN( CLIENT *Client, REQUEST *Req )
join_forward(Client, target, chan, channame);

if (Client_Type(Client) == CLIENT_USER) {
/* Acknowledge join ... */
if (!IRC_WriteStrClientPrefix(Client, target,
"JOIN :%s", channame))
break; /* write error */
/* ... and greet new user: */
if (!IRC_Send_Channel_Info(Client, chan))
break; /* write error */
Expand Down
0