Browse Source

Only change AWAY status for registered clients

Turns out I did eventually fix this, because I may want to implement
"passive clients" for logging or notification stuff, which wouldn't
affect AWAY status either.
master
Causal Agent 1 week ago
parent
commit
da2643bc80
Signed by: C. McEnroe <june@causal.agency> GPG Key ID: CEA2F97ADCFCD77C
3 changed files with 13 additions and 7 deletions
  1. 3
    6
      bounce.c
  2. 1
    0
      bounce.h
  3. 9
    1
      client.c

+ 3
- 6
bounce.c View File

@@ -228,7 +228,6 @@ int main(int argc, char *argv[]) {
const char *real = NULL;

const char *join = NULL;
const char *away = "pounced :3";
const char *quit = "connection reset by purr";

const char *Opts = "!A:C:H:K:NP:Q:U:W:a:c:ef:g:h:j:k:n:p:r:s:u:vw:x";
@@ -264,7 +263,7 @@ int main(int argc, char *argv[]) {
while (0 < (opt = getopt_config(argc, argv, Opts, LongOpts, NULL))) {
switch (opt) {
break; case '!': insecure = true;
break; case 'A': away = optarg;
break; case 'A': clientAway = optarg;
break; case 'C': strlcpy(certPath, optarg, sizeof(certPath));
break; case 'H': bindHost = optarg;
break; case 'K': strlcpy(privPath, optarg, sizeof(privPath));
@@ -322,6 +321,7 @@ int main(int argc, char *argv[]) {
}
if (!user) user = nick;
if (!real) real = nick;
if (!clientAway) clientAway = "pounced :3";

ringAlloc(ringSize);
if (savePath) saveLoad(savePath);
@@ -367,7 +367,7 @@ int main(int argc, char *argv[]) {
if (plain) explicit_bzero(plain, strlen(plain));

while (!stateReady()) serverRecv();
serverFormat("AWAY :%s\r\n", away);
serverFormat("AWAY :%s\r\n", clientAway);
if (join) serverFormat("JOIN :%s\r\n", join);

signal(SIGINT, signalHandler);
@@ -383,7 +383,6 @@ int main(int argc, char *argv[]) {
}
eventAdd(server, NULL);

size_t clients = 0;
for (;;) {
int nfds = poll(event.fds, event.len, -1);
if (nfds < 0 && errno != EINTR) err(EX_IOERR, "poll");
@@ -423,7 +422,6 @@ int main(int argc, char *argv[]) {
close(fd);
} else {
eventAdd(fd, clientAlloc(tls));
if (!clients++) serverFormat("AWAY\r\n");
}
continue;
}
@@ -434,7 +432,6 @@ int main(int argc, char *argv[]) {
if (clientError(client) || revents & (POLLHUP | POLLERR)) {
clientFree(client);
eventRemove(i);
if (!--clients) serverFormat("AWAY :%s\r\n", away);
}
}


+ 1
- 0
bounce.h View File

@@ -80,6 +80,7 @@ void serverFormat(const char *format, ...)
__attribute__((format(printf, 1, 2)));

char *clientPass;
char *clientAway;
struct Client *clientAlloc(struct tls *tls);
void clientFree(struct Client *client);
bool clientError(const struct Client *client);

+ 9
- 1
client.c View File

@@ -28,6 +28,8 @@

#include "bounce.h"

static size_t count;

enum Need {
NeedNick = 1 << 0,
NeedUser = 1 << 1,
@@ -54,6 +56,9 @@ struct Client *clientAlloc(struct tls *tls) {
}

void clientFree(struct Client *client) {
if (!client->need) {
if (!--count) serverFormat("AWAY :%s\r\n", clientAway);
}
tls_close(client->tls);
tls_free(client->tls);
free(client);
@@ -100,7 +105,10 @@ static void passRequired(struct Client *client) {

static void maybeSync(struct Client *client) {
if (client->need == NeedPass) passRequired(client);
if (!client->need) stateSync(client);
if (!client->need) {
stateSync(client);
if (!count++) serverFormat("AWAY\r\n");
}
}

typedef void Handler(struct Client *client, struct Message *msg);

Loading…
Cancel
Save