+ pthread_mutex_unlock (&server->mutex);
+
+ if (!usernamefound)
+ return TTT_ERROR_NO_USER;
+
+ return TTT_ERROR_NONE;
+}
+
+/* Exported: See ttt-server.h for documentation. */
+const char*
+ttt_server_get_host (ttt_server_t *server)
+{
+ return server->host;
+}
+
+/* Exported: See ttt-server.h for documentation. */
+const char*
+ttt_server_get_port (ttt_server_t *server)
+{
+ return server->port;
+}
+
+static const char *WELCOME_MESSAGE =
+"Welcome to ttt-server. The server is currently listening on:\r\n"
+"\r\n"
+" %s:%s\r\n"
+"\r\n"
+"To test this, simply connect one or more clients to that host and port.\r\n"
+"For example:\r\n"
+"\r\n"
+" telnet %s %s\r\n"
+"\r\n"
+"The TTTP (tic-tac-toe protocol) has been partially implemented.\r\n"
+"The following commands should work: HELO, HELP, MESSAGE, VERSION, QUIT, WHO.\r\n"
+"\r\n";
+
+static void
+_ttt_server_accept (void *closure, int client_socket)
+{
+ ttt_server_t *server = closure;
+
+ ttt_client_new (server, client_socket);
+}
+
+int
+main (int argc, char **argv)
+{
+ ttt_args_t args;
+ ttt_server_t server;
+ int socket;
+
+ ttt_args_parse (&args, argc, argv);
+
+ if (args.log_file)
+ xfreopen (args.log_file, "a", stderr);
+
+ socket = ttt_socket_create_server (args.host, args.port);
+
+ printf (WELCOME_MESSAGE, args.host, args.port, args.host, args.port);
+
+ ttt_server_init (&server, args.host, args.port);
+
+ while (1)
+ ttt_socket_accept (socket, _ttt_server_accept, &server);
+
+ /* We only reach here if something bad happened. */
+ return 1;