Fixed ZDE build - missing header file
[ZeXOS.git] / apps / openchess / src / client.c
bloba60b2436e72dd26bb83100da4f86a0cdb65e03e4
1 /*
2 * ZeX/OS
3 * Copyright (C) 2008 Tomas 'ZeXx86' Jedrzejek (zexx86@zexos.org)
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #include <stdio.h>
21 #include <string.h>
22 #include <stdlib.h>
23 #include <unistd.h>
24 #include "client.h"
25 #include "net.h"
27 client_t client_list;
29 int client_pmmsg (client_t *client, char *buf, unsigned len)
31 return net_send (client->sock, buf, len);
34 int client_msgtoall (char *buf, unsigned len)
36 client_t *c;
37 for (c = client_list.next; c != &client_list; c = c->next)
38 net_send (c->sock, buf, len);
40 return 1;
43 int client_msgtoall2 (client_t *client, char *buf, unsigned len)
45 client_t *c;
46 for (c = client_list.next; c != &client_list; c = c->next)
47 if (c != client)
48 net_send (c->sock, buf, len);
50 return 1;
53 /** Create new client's structure */
54 client_t *client_new (int sock)
56 /* alloc and init context */
57 client_t *client = (client_t *) malloc (sizeof (client_t));
59 if (!client)
60 return 0;
62 client->sock = sock;
63 client->nick = 0;
65 /* add into list */
66 client->next = &client_list;
67 client->prev = client_list.prev;
68 client->prev->next = client;
69 client->next->prev = client;
71 return client;
74 /** Delete client's structure */
75 int client_quit (client_t *client)
77 client->next->prev = client->prev;
78 client->prev->next = client->next;
80 if (client->nick)
81 free (client->nick);
83 free (client);
85 return 1;
88 /** Client Init function */
89 int init_client ()
91 client_list.next = &client_list;
92 client_list.prev = &client_list;
94 return 1;