diff options
| author | cashmere <cashmere@autistici.org> | 2026-07-01 14:26:08 +0200 |
|---|---|---|
| committer | cashmere <cashmere@autistici.org> | 2026-07-01 14:26:08 +0200 |
| commit | abb7f7fbfa1cafbb7bb98f4fa8c4101746d93cbf (patch) | |
| tree | 332c984cf03d7cb50d110daabcd2d729eaf86381 | |
| parent | b3639402e86834b9e69ebb371256d4b9e67ed9f7 (diff) | |
| download | telnet-master.tar.gz | |
| -rw-r--r-- | src/telnet.h | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/src/telnet.h b/src/telnet.h index ec22139..f36f944 100644 --- a/src/telnet.h +++ b/src/telnet.h @@ -9,6 +9,12 @@ struct client { char nickname[32]; int has_nickname; }; +int prompt_nickname(int fd) { + char *message = "Enter your nickname:\n"; + write(fd, message, strlen(message)); + return 0; +} +int set_nickname(struct client *c, const char *input, ssize_t n); // returns a socket file descriptor. // if connection could not be established, -1 gets returned @@ -42,9 +48,7 @@ int handle_new_connection(int sfd, struct pollfd *fds, nfds_t *nfds, fds[*nfds].fd = conn; fds[*nfds].events = POLLIN; clients[*nfds].has_nickname = 0; - char *message = "Enter your nickname:\n"; - write(fds[*nfds].fd, message, strlen(message)); - + prompt_nickname(fds[*nfds].fd); (*nfds)++; return 0; } @@ -74,9 +78,6 @@ int process_message(struct pollfd *fds, nfds_t *nfds, struct client *clients) { i--; return -1; } else { - if (clients[i].has_nickname == 0) { - - } /* send every message bytes to the other clients */ for (nfds_t j = 1; j < *nfds; j++) { if (j != i) { |
