1 /* ttt-server.c - tic-tac-toe game server
3 * Copyright © 2005 Carl Worth
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 2, or (at your option)
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, write to the Free Software Foundation,
17 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 * Author: Carl Worth <cworth@cworth.org>
23 #include "ttt-error.h"
25 #ifndef _TTT_SERVER_H_
26 #define _TTT_SERVER_H_
28 /* Register a new client with the server.
30 * Returns: TTT_ERROR_NONE on success, else TTT_ERROR_INVALIDNAME if client's
33 * Locking: The server mutex will be acquired and held throughout the
34 * execution of this function.
36 * Errors: If an error (such as out-of-memory) occurs, this function
40 ttt_server_register_client (ttt_server_t *server, ttt_client_t *client);
42 /* Un-register a client from the server.
44 * Locking: The server mutex will be acquired and held throughout the
45 * execution of this function.
48 ttt_server_unregister_client (ttt_server_t *server, ttt_client_t *client);
50 /* Send a message to all connected clients.
52 * Locking: The server mutex will be acquired and held throughout the
53 * execution of this function. Each client mutex may also be acquired
54 * and held by functions called during the execution of this function.
56 * Errors: If an error such as an IO error occurs, this function will
60 ttt_server_broadcast (ttt_server_t *server, const char *message);
63 /* Returns the WHO response. The return string is allocated in this
64 * function and will need to be free'd by the caller.
66 * Locking: The server mutex will be acquired and held throughout the
67 * execution of this function. Each client mutex may also be acquired
68 * and held by functions called during the execution of this function.
70 * Errors: If an error such as an IO error occurs, this function will
74 ttt_server_who (ttt_server_t *server);
76 /* Checks to see whether a username exists.
78 * Returns: ttt_server_get_client_from_username(server, username)
80 * Locking: See ttt_server_get_client_from_username
82 * Errors: See ttt_server_get_client_from_username
85 ttt_server_verify_username (ttt_server_t *server,
86 const char *username);
88 /* Points *client to the client with the supplied username, else
89 * leaves *client unhanged.
91 * Returns: TTT_ERROR_NONE, else TTT_ERROR_NO_USER if username not
94 * Locking: The server mutex will be acquired and held throughout the
95 * execution of this function. Each client mutex may also be acquired
96 * and held by functions called during the execution of this function.
98 * Errors: If an error such as an IO error occurs, this function will
102 ttt_server_get_client_from_username (ttt_server_t *server,
103 const char *username,
104 ttt_client_t **client);
106 /* Adds an invitation
108 * Locking: The server mutex will be acquired and held throughout the
109 * execution of this function. Each client mutex may also be acquired
110 * and held by functions called during the execution of this function.
112 * Errors: If an error such as an IO error occurs, this function will
116 ttt_server_add_invite (ttt_server_t *server,
118 ttt_client_t *invitee);
120 /* Removes an invitation
122 * Returns: TTT_ERROR_NONE, else TTT_ERROR_NO_INVITE if no invite
125 * Locking: The server mutex will be acquired and held throughout the
126 * execution of this function. Each client mutex may also be acquired
127 * and held by functions called during the execution of this function.
129 * Errors: If an error such as an IO error occurs, this function will
133 ttt_server_remove_invite (ttt_server_t *server,
135 ttt_client_t *invitee);
137 /* Gets the server hostname.
141 ttt_server_get_host (ttt_server_t *server);
143 /* Gets the server port
147 ttt_server_get_port (ttt_server_t *server);
149 #endif /* _TTT_SERVER_H_ */