From 2c160370499826609371fa9621b8c31aa8a8566a Mon Sep 17 00:00:00 2001 From: oroborus Date: Sun, 16 Mar 2008 13:45:40 +0000 Subject: - siete boli prepisane do SDL_net git-svn-id: http://opensvn.csie.org/tuxanci_ng@19 0ee4d065-81f0-4d1e-b06c-ff20ad07cc3e --- include/client.h | 25 ++++++++++++++++++++---- include/sdl_udp.h | 28 +++++++++++++++++++++++++++ include/server.h | 57 +++++++++++++++++++++++++++++++++++++++++++++++-------- 3 files changed, 98 insertions(+), 12 deletions(-) create mode 100644 include/sdl_udp.h (limited to 'include') diff --git a/include/client.h b/include/client.h index 979b5e8..6aa4d58 100644 --- a/include/client.h +++ b/include/client.h @@ -3,16 +3,33 @@ #define MY_CLIENT +#if defined SUPPORT_NET_UNIX_UDP || defined SUPPORT_NET_SDL_UDP + #define CLIENT_TIMEOUT 2500 +#endif + +#ifdef SUPPORT_NET_UNIX_TCP extern int initTcpClient(char *ip, int port); -extern int initUdpClient(char *ip, int port); -extern void sendServer(char *msg); -extern void eventServerBuffer(); extern void selectClientTcpSocket(); +extern void quitTcpClient(); +#endif + +#ifdef SUPPORT_NET_UNIX_UDP +extern int initUdpClient(char *ip, int port); extern void eventPingServer(); extern void selectClientUdpSocket(); -extern void quitTcpClient(); extern void quitUdpClient(); +#endif + +#ifdef SUPPORT_NET_SDL_UDP +extern int initSdlUdpClient(char *ip, int port); +extern void eventPingServer(); +extern void selectClientSdlUdpSocket(); +extern void quitSdlUdpClient(); +#endif + +extern void sendServer(char *msg); +extern void eventServerBuffer(); #endif diff --git a/include/sdl_udp.h b/include/sdl_udp.h new file mode 100644 index 0000000..91a3c71 --- /dev/null +++ b/include/sdl_udp.h @@ -0,0 +1,28 @@ + +#ifndef MY_SDL_UDP + +#include + +#define MY_SDL_UDP + +#define SDL_UDP_SERVER 0 +#define SDL_UDP_CLIENT 1 + +typedef struct struct_sock_sdl_udp_t +{ + int type; + UDPsocket sock; + IPaddress srvadd; + UDPpacket *packet; +} sock_sdl_udp_t; + +sock_sdl_udp_t* newSdlSockUdp(); +void destroySockSdlUdp(sock_sdl_udp_t *p); +sock_sdl_udp_t* bindSdlUdpSocket(int port); +sock_sdl_udp_t* connectSdlUdpSocket(char *address, int port); +int readSdlUdpSocket(sock_sdl_udp_t *src, sock_sdl_udp_t *dst, void *address, int len); +int writeSdlUdpSocket(sock_sdl_udp_t *src, sock_sdl_udp_t *dst, void *address, int len); +int getSockSdlUdpPort(sock_sdl_udp_t *p); +void closeSdlUdpSocket(sock_sdl_udp_t *p); + +#endif diff --git a/include/server.h b/include/server.h index 531afd0..f35f155 100644 --- a/include/server.h +++ b/include/server.h @@ -7,42 +7,83 @@ #include "tux.h" #include "buffer.h" #include "myTimer.h" -#include "tcp.h" -#include "udp.h" #ifndef BUBLIC_SERVER #include "interface.h" #endif +#ifdef SUPPORT_NET_UNIX_TCP +#include "tcp.h" +#endif + +#ifdef SUPPORT_NET_UNIX_UDP + +#include "udp.h" + #define SERVER_TIMEOUT 5000 #define SERVER_TIME_SYNC 5000 +#endif + +#ifdef SUPPORT_NET_SDL_UDP + +#include "sdl_udp.h" + +#define SERVER_TIMEOUT 5000 +#define SERVER_TIME_SYNC 5000 + +#endif + + #define SERVER_INDEX_ROOT_TUX 0 typedef struct client_struct { +#ifdef SUPPORT_NET_UNIX_TCP sock_tcp_t *socket_tcp; +#endif + +#ifdef SUPPORT_NET_UNIX_UDP sock_udp_t *socket_udp; - int status; my_time_t lastPing; +#endif + +#ifdef SUPPORT_NET_SDL_UDP + sock_sdl_udp_t *socket_sdl_udp; + my_time_t lastPing; +#endif + int status; tux_t *tux; buffer_t *buffer; } client_t; +#ifdef SUPPORT_NET_UNIX_TCP extern int initTcpServer(int port); -extern int initUdpServer(int port); extern client_t* newTcpClient(sock_tcp_t *sock_tcp); +extern void selectServerTcpSocket(); +extern void quitTcpServer(); +#endif + +#ifdef SUPPORT_NET_UNIX_UDP +extern int initUdpServer(int port); extern client_t* newUdpClient(sock_udp_t *sock_udp); +extern void selectServerUdpSocket(); +extern void quitUdpServer(); +#endif + +#ifdef SUPPORT_NET_SDL_UDP +extern int initSdlUdpServer(int port); +extern client_t* newSdlUdpClient(sock_sdl_udp_t *sock_udp); +extern void selectServerSdlUdpSocket(); +extern void quitSdlUdpServer(); +#endif + extern void destroyClient(client_t *p); extern void sendClient(client_t *p, char *msg); extern void sendAllClientBut(char *msg, client_t *p); extern void sendAllClient(char *msg); extern void eventClientListBuffer(); -extern void selectServerTcpSocket(); -extern void selectServerUdpSocket(); extern void eventPeriodicSyncClient(); -extern void quitTcpServer(); -extern void quitUdpServer(); #endif -- cgit v1.2.3