Free a client, associated resources, and unbind it from the global * state in Chat. */
| 93 | /* Free a client, associated resources, and unbind it from the global |
| 94 | * state in Chat. */ |
| 95 | void freeClient(struct client *c) { |
| 96 | free(c->nick); |
| 97 | close(c->fd); |
| 98 | Chat->clients[c->fd] = NULL; |
| 99 | Chat->numclients--; |
| 100 | if (Chat->maxclient == c->fd) { |
| 101 | /* Ooops, this was the max client set. Let's find what is |
| 102 | * the new highest slot used. */ |
| 103 | int j; |
| 104 | for (j = Chat->maxclient-1; j >= 0; j--) { |
| 105 | if (Chat->clients[j] != NULL) { |
| 106 | Chat->maxclient = j; |
| 107 | break; |
| 108 | } |
| 109 | } |
| 110 | if (j == -1) Chat->maxclient = -1; // We no longer have clients. |
| 111 | } |
| 112 | free(c); |
| 113 | } |
| 114 | |
| 115 | /* Allocate and init the global stuff. */ |
| 116 | void initChat(void) { |