]> git.cworth.org Git - ttt/blob - src/ttt-server.h
Ignore ttt-lex.h
[ttt] / src / ttt-server.h
1 /* ttt-server.c - tic-tac-toe game server
2  *
3  * Copyright © 2005 Carl Worth
4  *
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)
8  * any later version.
9  *
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.
14  *
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.
18  *
19  * Author: Carl Worth <cworth@cworth.org>
20  */
21
22 #include "ttt.h"
23 #include "ttt-error.h"
24
25 #ifndef _TTT_SERVER_H_
26 #define _TTT_SERVER_H_
27
28 /* Register a new client with the server.
29  * 
30  * Returns: TTT_ERROR_NONE on success, else TTT_ERROR_INVALIDNAME if client's
31  * name is not unique.
32  *
33  * Locking: The server mutex will be acquired and held throughout the
34  * execution of this function.
35  *
36  * Errors: If an error (such as out-of-memory) occurs, this function
37  * will not return.
38  */
39 ttt_error_t
40 ttt_server_register_client (ttt_server_t *server, ttt_client_t *client);
41
42 /* Un-register a client from the server.
43  *
44  * Locking: The server mutex will be acquired and held throughout the
45  * execution of this function.
46  */
47 void
48 ttt_server_unregister_client (ttt_server_t *server, ttt_client_t *client);
49
50 /* Send a message to all connected clients.
51  *
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.
55  *
56  * Errors: If an error such as an IO error occurs, this function will
57  * not return.
58  */
59 void
60 ttt_server_broadcast (ttt_server_t *server, const char *message);
61
62
63 /* Returns the WHO response. The return string is allocated in this
64  * function and will need to be free'd by the caller.
65  *
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.
69  *
70  * Errors: If an error such as an IO error occurs, this function will
71  * not return.
72  */
73 const char*
74 ttt_server_who (ttt_server_t *server);
75
76 /* Generates the statistics for the user. If the function does not
77  * return an error, the response will be allocated in this function
78  * and will need to be free'd by the caller.
79  *
80  * Locking: The server mutex will be acquired and held throughout the
81  * execution of this function. Each client mutex may also be acquired
82  * and held by functions called during the execution of this function.
83  *
84  * Errors: If an error such as an IO error occurs, this function will
85  * not return.
86  */
87 ttt_error_t
88 ttt_server_statistics (ttt_server_t *server,
89                        const char *username,
90                        char **response);
91
92 /* Checks to see if the username is registered. If the username exists
93  * will return TTT_ERROR_NONE, else TTT_ERROR_NO_USER.
94  *
95  * Locking: The server mutex will be acquired and held throughout the
96  * execution of this function. Each client mutex may also be acquired
97  * and held by functions called during the execution of this function.
98  *
99  * Errors: If an error such as an IO error occurs, this function will
100  * not return.
101  */
102 ttt_error_t
103 ttt_server_verify_username (ttt_server_t *server,
104                             const char *username);
105
106 /* Gets the server hostname.
107  *
108  */
109 const char*
110 ttt_server_get_host (ttt_server_t *server);
111
112 /* Gets the server port
113  *
114  */
115 const char*
116 ttt_server_get_port (ttt_server_t *server);
117
118 #endif /* _TTT_SERVER_H_ */