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 will also be acquired
54 * for a portion of 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.
69 * Errors: If an error such as an IO error occurs, this function will
73 ttt_server_who (ttt_server_t *server);
75 /* Checks to see whether a username exists.
77 * Returns: ttt_server_get_client_from_username(server, username)
79 * Locking: See ttt_server_get_client_from_username
81 * Errors: See ttt_server_get_client_from_username
84 ttt_server_verify_username (ttt_server_t *server,
85 const char *username);
87 /* Points *client to the client with the supplied username, else
88 * leaves *client unhanged.
90 * Returns: TTT_ERROR_NONE, else TTT_ERROR_NO_USER if username not
93 * Locking: The server mutex will be acquired and held throughout the
94 * execution of this function.
96 * Errors: If an error such as an IO error occurs, this function will
100 ttt_server_get_client_from_username (ttt_server_t *server,
101 const char *username,
102 ttt_client_t **client);
104 /* Adds an invitation
106 * Locking: The server mutex will be acquired and held throughout the
107 * execution of this function.
109 * Errors: If an error such as an IO error occurs, this function will
113 ttt_server_add_invite (ttt_server_t *server,
115 ttt_client_t *invitee);
117 /* Removes an invitation
119 * Returns: TTT_ERROR_NONE, else TTT_ERROR_NO_INVITE if no invite
122 * Locking: The server mutex will be acquired and held throughout the
123 * execution of this function.
125 * Errors: If an error such as an IO error occurs, this function will
129 ttt_server_remove_invite (ttt_server_t *server,
131 ttt_client_t *invitee);
133 /* Gets the server hostname.
137 ttt_server_get_host (ttt_server_t *server);
139 /* Gets the server port
143 ttt_server_get_port (ttt_server_t *server);
145 #endif /* _TTT_SERVER_H_ */