summary refs log tree commit diff
path: root/client.c
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2019-10-23 18:51:57 -0400
committerJune McEnroe <june@causal.agency>2019-10-23 18:51:57 -0400
commite2be3c85131896e203f7ba16d883bc61bfa09064 (patch)
treefbea6de725284cba7a7c06f5a4b28ff247eba599 /client.c
parentSend to server if client has no needs (diff)
downloadpounce-e2be3c85131896e203f7ba16d883bc61bfa09064.tar.gz
pounce-e2be3c85131896e203f7ba16d883bc61bfa09064.zip
Synchronize state after client registration
Diffstat (limited to 'client.c')
-rw-r--r--client.c19
1 files changed, 16 insertions, 3 deletions
diff --git a/client.c b/client.c
index 74d1e5c..442ed2d 100644
--- a/client.c
+++ b/client.c
@@ -63,7 +63,7 @@ bool clientClose(const struct Client *client) {
 	return client->close;
 }
 
-static void clientSend(struct Client *client, const char *ptr, size_t len) {
+void clientSend(struct Client *client, const char *ptr, size_t len) {
 	if (verbose) fprintf(stderr, "\x1B[34m%.*s\x1B[m", (int)len, ptr);
 	while (len) {
 		ssize_t ret = tls_write(client->tls, ptr, len);
@@ -89,25 +89,38 @@ static void format(struct Client *client, const char *format, ...) {
 	clientSend(client, buf, len);
 }
 
+static void passRequired(struct Client *client) {
+	format(
+		client,
+		":invalid 464 * :Password incorrect\r\n"
+		"ERROR :Password incorrect\r\n"
+	);
+	client->close = true;
+}
+
 typedef void Handler(struct Client *client, struct Command cmd);
 
 static void handleNick(struct Client *client, struct Command cmd) {
 	(void)cmd;
 	client->need &= ~NeedNick;
+	if (!client->need) stateSync(client);
+	if (client->need == NeedPass) passRequired(client);
 }
 
 static void handleUser(struct Client *client, struct Command cmd) {
 	(void)cmd;
 	// TODO: Identify client by username.
 	client->need &= ~NeedUser;
+	if (!client->need) stateSync(client);
+	if (client->need == NeedPass) passRequired(client);
 }
 
 static void handlePass(struct Client *client, struct Command cmd) {
 	if (!cmd.params[0] || strcmp(clientPass, cmd.params[0])) {
-		format(client, ":invalid 464 * :Password incorrect\r\n");
-		client->close = true;
+		passRequired(client);
 	} else {
 		client->need &= ~NeedPass;
+		if (!client->need) stateSync(client);
 	}
 }