do {
channels++;
} while (trie_findnext(&f) == 1);
- for (int i = 0; i < CLIENTS; i++)
- if (clients[i])
- total++;
+ for (struct client_data *cl = clients; cl; cl = cl->next)
+ total++;
rpl_luserclient(client, registered, invisible, 1), sendbuf(client);
rpl_luserop(client, ops), sendbuf(client);
rpl_luserunknown(client, total-registered), sendbuf(client);
rpl_luserchannels(client, channels), sendbuf(client);
rpl_luserme(client, registered, 0), sendbuf(client);
- rpl_localusers(client, registered, CLIENTS), sendbuf(client);
- rpl_globalusers(client, registered, CLIENTS), sendbuf(client);
+ rpl_localusers(client, registered, 666), sendbuf(client);
+ rpl_globalusers(client, registered, 666), sendbuf(client);
}
void sendMOTD(struct client_data *client) {
#endif
// Client linked list
-struct client_data *clients[CLIENTS];
+struct client_data *clients = NULL;
// FDSET List
fd_set readfds;
#endif
}
// Add to list of sockets
- for(int i=0;i<CLIENTS;i++) {
- if(clients[i] == 0){
- clients[i] = allocClient();
- clients[i]->FD = newSocket;
- clients[i]->cctx = cctx;
- clients[i]->type = addr.ss_family == AF_INET6 ? 6 : 4;
- clients[i]->peername = mystrdup(client_addr);
- if (!clients[i]->peername) abort();
- clients[i]->peerport = port;
- if (cctx)
- clients[i]->umode |= UMODE_SECURE;
- extern const char *hostname;
- copy_strf(&databuf, ":%s NOTICE * :Hello welcome to PatchyIRCD!\r\n", hostname);
- sendbuf(clients[i]);
- break;
- }
- }
+ struct client_data *cl = allocClient();
+ cl->FD = newSocket;
+ cl->cctx = cctx;
+ cl->type = addr.ss_family == AF_INET6 ? 6 : 4;
+ cl->peername = mystrdup(client_addr);
+ if (!cl->peername) abort();
+ cl->peerport = port;
+ if (cctx)
+ cl->umode |= UMODE_SECURE;
+ extern const char *hostname;
+ copy_strf(&databuf, ":%s NOTICE * :Hello welcome to PatchyIRCD!\r\n", hostname);
+ sendbuf(cl);
+ cl->next = clients;
+ clients = cl;
}
}
databuf.buf = malloc(sizeof(char) * 512);
databuf.cap = 512;
- // Zero stuff out
- memset(clients, 0, sizeof(clients));
-
struct tls *tls_ctx = NULL;
#ifdef HAS_TLS
struct tls_config *tls_cfg;
if (self_sock != INVALID_SOCKET)
FD_SET(self_sock, &readfds);
#endif
- for (int i = 0; i < CLIENTS; i++)
- if (clients[i])
- FD_SET(clients[i]->FD, &readfds);
+ for (struct client_data *cl = clients; cl; cl = cl->next)
+ FD_SET(cl->FD, &readfds);
// Set highestFD
#ifdef _WIN32
for (int i = 0; i < listener_count; i++)
if (highestFD < listeners[i].sock)
highestFD = listeners[i].sock;
- for (int i = 0; i < CLIENTS; i++)
- if (clients[i] && highestFD < clients[i]->FD)
- highestFD = clients[i]->FD;
+ for (struct client_data *cl = clients; cl; cl = cl->next)
+ if (highestFD < cl->FD)
+ highestFD = cl->FD;
#endif
// Wait until activity on sockets
if(select(highestFD+1,&readfds,NULL,NULL,NULL) == -1) {
if (FD_ISSET(listeners[i].sock, &readfds))
accept_from_sock(&listeners[i]);
// Respond to already connected clients
- for (int i = 0; i < CLIENTS; i++)
- if (clients[i] && FD_ISSET(clients[i]->FD, &readfds))
- recvProc(clients[i]);
+ for (struct client_data *cl = clients; cl;) {
+ struct client_data *next = cl->next;
+ if (FD_ISSET(cl->FD, &readfds))
+ recvProc(cl);
+ cl = next;
+ }
}
fprintf(stderr, "[PatchyIRCD]: Cleaning up...\n");
- for (int i = 0; i < CLIENTS; i++)
- if (clients[i])
- killConnection(clients[i], false);
+ for (struct client_data *cl = clients; cl;) {
+ struct client_data *next = cl->next;
+ killConnection(cl, false);
+ cl = next;
+ }
net_cleanup();
for (int i = 0; i < listener_count; i++)
closesocket(listeners[i].sock);