Separate network info from self

master
C. McEnroe 2020-02-15 04:54:53 -05:00
parent 91fa136672
commit 42d106260b
4 changed files with 19 additions and 15 deletions

7
chat.c
View File

@ -65,6 +65,7 @@ enum Color idColors[IDCap] = {
size_t idNext = Network + 1; size_t idNext = Network + 1;
struct Network network;
struct Self self = { .color = Default }; struct Self self = { .color = Default };
static const char *save; static const char *save;
@ -187,10 +188,10 @@ int main(int argc, char *argv[]) {
if (!user) user = nick; if (!user) user = nick;
if (!real) real = nick; if (!real) real = nick;
set(&network.name, host);
set(&network.chanTypes, "#&");
set(&network.prefixes, "@+");
set(&self.nick, "*"); set(&self.nick, "*");
set(&self.network, host);
set(&self.chanTypes, "#&");
set(&self.prefixes, "@+");
commandComplete(); commandComplete();
FILE *certFile = NULL; FILE *certFile = NULL;

9
chat.h
View File

@ -82,15 +82,18 @@ enum Cap {
#undef X #undef X
}; };
extern struct Network {
char *name;
char *chanTypes;
char *prefixes;
} network;
extern struct Self { extern struct Self {
bool debug; bool debug;
bool restricted; bool restricted;
char *plain; char *plain;
const char *join; const char *join;
enum Cap caps; enum Cap caps;
char *network;
char *chanTypes;
char *prefixes;
char *nick; char *nick;
char *user; char *user;
enum Color color; enum Color color;

View File

@ -212,17 +212,17 @@ static void handleReplyISupport(struct Message *msg) {
char *key = strsep(&msg->params[i], "="); char *key = strsep(&msg->params[i], "=");
if (!msg->params[i]) continue; if (!msg->params[i]) continue;
if (!strcmp(key, "NETWORK")) { if (!strcmp(key, "NETWORK")) {
set(&self.network, msg->params[i]); set(&network.name, msg->params[i]);
uiFormat( uiFormat(
Network, Cold, tagTime(msg), Network, Cold, tagTime(msg),
"You arrive in %s", msg->params[i] "You arrive in %s", msg->params[i]
); );
} else if (!strcmp(key, "CHANTYPES")) { } else if (!strcmp(key, "CHANTYPES")) {
set(&self.chanTypes, msg->params[i]); set(&network.chanTypes, msg->params[i]);
} else if (!strcmp(key, "PREFIX")) { } else if (!strcmp(key, "PREFIX")) {
strsep(&msg->params[i], ")"); strsep(&msg->params[i], ")");
if (!msg->params[i]) continue; if (!msg->params[i]) continue;
set(&self.prefixes, msg->params[i]); set(&network.prefixes, msg->params[i]);
} }
} }
} }
@ -348,7 +348,7 @@ static void handleReplyNames(struct Message *msg) {
size_t len = 0; size_t len = 0;
while (msg->params[3]) { while (msg->params[3]) {
char *name = strsep(&msg->params[3], " "); char *name = strsep(&msg->params[3], " ");
name += strspn(name, self.prefixes); name += strspn(name, network.prefixes);
char *nick = strsep(&name, "!"); char *nick = strsep(&name, "!");
char *user = strsep(&name, "@"); char *user = strsep(&name, "@");
enum Color color = (user ? hash(user) : Default); enum Color color = (user ? hash(user) : Default);
@ -510,7 +510,7 @@ static void handleReplyWhoisChannels(struct Message *msg) {
size_t len = 0; size_t len = 0;
while (msg->params[2]) { while (msg->params[2]) {
char *channel = strsep(&msg->params[2], " "); char *channel = strsep(&msg->params[2], " ");
channel += strspn(channel, self.prefixes); channel += strspn(channel, network.prefixes);
int n = snprintf( int n = snprintf(
&buf[len], sizeof(buf) - len, &buf[len], sizeof(buf) - len,
"%s\3%02d%s\3", (len ? ", " : ""), hash(channel), channel "%s\3%02d%s\3", (len ? ", " : ""), hash(channel), channel
@ -642,11 +642,11 @@ static const char *colorMentions(size_t id, struct Message *msg) {
static void handlePrivmsg(struct Message *msg) { static void handlePrivmsg(struct Message *msg) {
require(msg, true, 2); require(msg, true, 2);
bool query = !strchr(self.chanTypes, msg->params[0][0]); bool query = !strchr(network.chanTypes, msg->params[0][0]);
bool network = strchr(msg->nick, '.'); bool server = strchr(msg->nick, '.');
bool mine = !strcmp(msg->nick, self.nick); bool mine = !strcmp(msg->nick, self.nick);
size_t id; size_t id;
if (query && network) { if (query && server) {
id = Network; id = Network;
} else if (query && !mine) { } else if (query && !mine) {
id = idFor(msg->nick); id = idFor(msg->nick);

2
ui.c
View File

@ -426,7 +426,7 @@ static void statusUpdate(void) {
wclrtoeol(status); wclrtoeol(status);
const struct Window *window = windows.ptrs[windows.show]; const struct Window *window = windows.ptrs[windows.show];
snprintf(title, sizeof(title), "%s %s", self.network, idNames[window->id]); snprintf(title, sizeof(title), "%s %s", network.name, idNames[window->id]);
if (window->mark && window->unreadWarm) { if (window->mark && window->unreadWarm) {
snprintf( snprintf(
&title[strlen(title)], sizeof(title) - strlen(title), &title[strlen(title)], sizeof(title) - strlen(title),