diff options
| author | Tomas Chvatal <scarabeus@gentoo.org> | 2009-05-16 14:04:24 +0200 |
|---|---|---|
| committer | Tomas Chvatal <scarabeus@gentoo.org> | 2009-05-16 14:04:24 +0200 |
| commit | 52671935e3337cf0b76259964aa539a72869f486 (patch) | |
| tree | 4fab0c161fe63952b73689c5733931e8552de92e /src/base | |
| parent | 556544095bb548f07f771e4e0bbfe97333e8ee82 (diff) | |
Update build system to include source files automaticaly.
Diffstat (limited to 'src/base')
| -rw-r--r-- | src/base/CMakeLists.txt | 12 | ||||
| -rw-r--r-- | src/base/path.h.in | 1 | ||||
| -rw-r--r-- | src/base/tcp_server.c | 291 | ||||
| -rw-r--r-- | src/base/tcp_server.h | 19 |
4 files changed, 12 insertions, 311 deletions
diff --git a/src/base/CMakeLists.txt b/src/base/CMakeLists.txt new file mode 100644 index 0000000..6c8c7a1 --- /dev/null +++ b/src/base/CMakeLists.txt @@ -0,0 +1,12 @@ +############################################################################### +# tuxanci/src/*/CMakeLists.txt +############################################################################### +# Generate source_code files from .c files we find in directory +############################################################################### +FILE ( GLOB src ${fn}/*.c ) +FOREACH ( fle ${src} ) + GET_FILENAME_COMPONENT ( fnp ${fle} NAME_WE ) + GET_FILENAME_COMPONENT ( pth ${fle} PATH ) + SET ( SRC_${fn} ${SRC_${fn}} ${pth}/${fnp} ) +ENDFOREACH ( fle ) +############################################################################### diff --git a/src/base/path.h.in b/src/base/path.h.in index 79bce33..7e3a7a6 100644 --- a/src/base/path.h.in +++ b/src/base/path.h.in @@ -1,4 +1,3 @@ - #ifndef PATH_H #cmakedefine USE_MAGICK #define TUXANCI_VERSION "@TUXANCI_VERSION@" diff --git a/src/base/tcp_server.c b/src/base/tcp_server.c deleted file mode 100644 index 1635c1a..0000000 --- a/src/base/tcp_server.c +++ /dev/null @@ -1,291 +0,0 @@ -#include <stdio.h> -#include <stdlib.h> -#include <string.h> - -#include <sys/types.h> - -#include <unistd.h> -#include <fcntl.h> -#include <sys/time.h> - -#ifndef __WIN32__ -# include <sys/ioctl.h> -# include <sys/socket.h> -# include <sys/select.h> -#else -# include <io.h> -# include <winsock2.h> -#endif - -#include "main.h" -#include "list.h" -#include "tux.h" -#include "proto.h" -#include "server.h" -#include "myTimer.h" -#include "arena.h" -#include "net_multiplayer.h" -#include "checkFront.h" -#include "protect.h" -#include "index.h" - -#ifndef PUBLIC_SERVER -# include "screen_world.h" -#endif - -#ifdef PUBLIC_SERVER -# include "publicServer.h" -# include "highScore.h" -# include "log.h" -#endif - -#include "tcp.h" -#include "tcp_server.h" -#include "serverSelect.h" - -static sock_tcp_t *sock_server_tcp; -static sock_tcp_t *sock_server_tcp_second; - -client_t *server_tcp_new_client(sock_tcp_t * sock_tcp) -{ - client_t *new; - - assert(sock_tcp != NULL); - - new = server_new_any_client(); - new->type = CLIENT_TYPE_TCP; - new->socket_tcp = sock_tcp; - new->recvBuffer = buffer_new(SERVER_TCP_BUFFER_LIMIT); - new->sendBuffer = buffer_new(SERVER_TCP_BUFFER_LIMIT); - -#ifdef PUBLIC_SERVER - char str_log[STR_LOG_SIZE]; - char str_ip[STR_IP_SIZE]; - - sock_tcp_get_ip(sock_tcp, str_ip, STR_IP_SIZE); - sprintf(str_log, _("New client \"%s\" on port \"%d\" connected"), str_ip, - sock_tcp_get_port(sock_tcp)); - log_add(LOG_INF, str_log); -#endif - - return new; -} - -void server_tcp_send_client_buffer(client_t * client) -{ - void *data; - int len; - int res; - - len = buffer_get_size(client->sendBuffer); - - if (len == 0) { - return; - } - - data = buffer_get_data(client->sendBuffer); - - res = sock_tcp_write(client->socket_tcp, data, len); - //printf("sock_tcp_write = %d\n", res); - - if (res < 0) { - client->status = NET_STATUS_ZOMBIE; - return; - } - - buffer_cut(client->sendBuffer, res); -} - -void server_tcp_destroy_client(client_t * client) -{ - check_front_event(client); - server_tcp_send_client_buffer(client); - -#ifdef PUBLIC_SERVER - char str_log[STR_LOG_SIZE]; - char str_ip[STR_IP_SIZE]; - - sock_tcp_get_ip(client->socket_tcp, str_ip, STR_IP_SIZE); - sprintf(str_log, _("Client \"%s\" on port \"%d\" disconnected"), str_ip, - sock_tcp_get_port(client->socket_tcp)); - log_add(LOG_INF, str_log); -#endif - - sock_tcp_close(client->socket_tcp); - buffer_destroy(client->recvBuffer); - buffer_destroy(client->sendBuffer); - - server_destroy_any_client(client); -} - -int server_tcp_init(char *ip4, int port4, char *ip6, int port6) -{ - int ret; - - ret = 0; - - if (ip4 != NULL) { - sock_server_tcp = sock_tcp_bind(ip4, port4, PROTO_UDPv4); - - if (sock_server_tcp != NULL) { - ret++; - sock_tcp_diable_nagle(sock_server_tcp); - - DEBUG_MSG(_("Starting server: \"%s\" on port: \"%d\"\n"), ip4, port4); - } else { - DEBUG_MSG(_("Starting server: \"%s\" on port: \"%d\" FAILED!\n"), ip4, port4); - - } - } - - if (ip6 != NULL) { - sock_server_tcp_second = sock_tcp_bind(ip6, port6, PROTO_UDPv6); - - if (sock_server_tcp_second != NULL) { - ret++; - sock_tcp_diable_nagle(sock_server_tcp_second); - - DEBUG_MSG(_("Starting server: \"%s\" on port: \"%d\"\n"), ip6, port6); - } else { - - DEBUG_MSG(_("Starting server: \"%s\" on port: \"%d\" FAILED!\n"), ip6, port6); - } - } - - return ret; -} - -static void eventNewClient(sock_tcp_t * server_sock) -{ - list_t *listClient; - sock_tcp_t *sock; - client_t *client; - - listClient = server_get_list_clients(); - - sock = sock_tcp_accept(server_sock); - sock_tcp_diable_nagle(sock); - sock_tcp_set_non_block(sock); - - client = server_tcp_new_client(sock); - list_add(listClient, client); -} - -static void eventTcpClient(client_t * client) -{ - char buffer[STR_PROTO_SIZE]; - int ret; - - memset(buffer, 0, STR_PROTO_SIZE); - - ret = sock_tcp_read(client->socket_tcp, buffer, STR_PROTO_SIZE - 1); - //printf("sock_tcp_read = %d\n", ret); - - if (ret <= 0) { - client->status = NET_STATUS_ZOMBIE; - return; - } - - if (buffer_append(client->recvBuffer, buffer, ret) < 0) { - client->status = NET_STATUS_ZOMBIE; - return; - } - - while (buffer_get_line(client->recvBuffer, buffer, STR_PROTO_SIZE) >= 0) { - list_add(client->listRecvMsg, strdup(buffer)); - } -} - -void server_tcp_set_select() -{ - list_t *listClient; - int i; - - listClient = server_get_list_clients(); - - if (sock_server_tcp != NULL) { - select_add_sock_for_read(sock_server_tcp->sock); - } - - if (sock_server_tcp_second != NULL) { - select_add_sock_for_read(sock_server_tcp_second->sock); - } - - for (i = 0; i < listClient->count; i++) { - client_t *client; - - client = (client_t *) listClient->list[i]; - - if (client->status != NET_STATUS_OK || client->type != CLIENT_TYPE_TCP) { - continue; - } - - select_add_sock_for_read(client->socket_tcp->sock); - } -} - -int server_tcp_select_sock() -{ - list_t *listClient; - int count; - int i; - - count = 0; - - if (sock_server_tcp != NULL) { - if (select_is_change_sock_for_read(sock_server_tcp->sock)) { - eventNewClient(sock_server_tcp); - count++; - } - } - - if (sock_server_tcp_second != NULL) { - if (select_is_change_sock_for_read(sock_server_tcp_second->sock)) { - eventNewClient(sock_server_tcp_second); - count++; - } - } - - listClient = server_get_list_clients(); - - for (i = 0; i < listClient->count; i++) { - client_t *client; - - client = (client_t *) listClient->list[i]; - - if (client->status != NET_STATUS_OK || client->type != CLIENT_TYPE_TCP) { - continue; - } - - if (select_is_change_sock_for_read(client->socket_tcp->sock)) { - //printf("sChangeSockInSelectRead\n"); - eventTcpClient(client); - count++; - } -/* - if( select_is_change_sock_for_write(client->socket_tcp->sock) ) - { - //printf("select_is_change_sock_for_write\n"); - server_tcp_send_client_buffer(client); - count++; - } -*/ - } - - return count; -} - -void server_tcp_quit() -{ - if (sock_server_tcp != NULL) { - DEBUG_MSG(_("Closing port: \"%d\"\n"), sock_tcp_get_port(sock_server_tcp)); - sock_tcp_close(sock_server_tcp); - } - - if (sock_server_tcp_second != NULL) { - DEBUG_MSG(_("Closing port: \"%d\"\n"), sock_tcp_get_port(sock_server_tcp_second)); - sock_tcp_close(sock_server_tcp_second); - } - - DEBUG_MSG("Quitting TCP\n"); -} diff --git a/src/base/tcp_server.h b/src/base/tcp_server.h deleted file mode 100644 index e206402..0000000 --- a/src/base/tcp_server.h +++ /dev/null @@ -1,19 +0,0 @@ - -#ifndef SERVER_TCP_H - -# define SERVER_TCP_H - -# include "server.h" -# include "tcp.h" - -# define SERVER_TCP_BUFFER_LIMIT 4096 - -extern client_t *server_tcp_new_client(sock_tcp_t * sock_tcp); -extern void server_tcp_destroy_client(client_t * p); -extern int server_tcp_init(char *ip4, int port4, char *ip6, int port6); -extern void server_tcp_set_select(); -extern int server_tcp_select_sock(); -extern void server_tcp_send_client_buffer(client_t * p); -extern void server_tcp_quit(); - -#endif |