diff options
| author | oroborus <oroborus@0ee4d065-81f0-4d1e-b06c-ff20ad07cc3e> | 2008-07-03 15:19:08 +0000 |
|---|---|---|
| committer | oroborus <oroborus@0ee4d065-81f0-4d1e-b06c-ff20ad07cc3e> | 2008-07-03 15:19:08 +0000 |
| commit | 157e2a29828f2ddbdf32e1c9e565b13e5e732e34 (patch) | |
| tree | 5c895536cd4771a12380dc37e76f3891d3ddd385 /src | |
| parent | 47d56153f243424c0074874c8db1b6cec2365344 (diff) | |
- predene zvuky zbrani revolver a samopal
- server config sa vie spravne vysporiadat s mederami v subore server.conf
- upraveny kod pre bigAreny
- nova funkcia pre odstranovanie vsektch poloziek vo widget_select
- screen_browser duplicitne nenacitava obrazok zo suboru
- server si indexuje clientov na zaklade ich zdrojoveho portu ( ja viem, ze je to pstrosi alogritmus, ale aj tak
predtym server identifikoval clientov podla ich zdrojoveho portu len ich podla toho neindexoval )
git-svn-id: http://opensvn.csie.org/tuxanci_ng@89 0ee4d065-81f0-4d1e-b06c-ff20ad07cc3e
Diffstat (limited to 'src')
| -rw-r--r-- | src/base/arena.c | 4 | ||||
| -rw-r--r-- | src/base/gun.c | 4 | ||||
| -rw-r--r-- | src/base/server.c | 143 | ||||
| -rw-r--r-- | src/base/tux.c | 2 | ||||
| -rw-r--r-- | src/base/tux.h | 1 | ||||
| -rw-r--r-- | src/net_unix/udp.c | 3 | ||||
| -rw-r--r-- | src/net_unix/udp.h | 1 | ||||
| -rw-r--r-- | src/screen/screen_browser.c | 25 | ||||
| -rw-r--r-- | src/server/serverConfigFile.c | 20 | ||||
| -rw-r--r-- | src/widget/widget_select.c | 8 | ||||
| -rw-r--r-- | src/widget/widget_select.h | 1 | ||||
| -rw-r--r-- | src/widget/widget_textfield.c | 1 |
12 files changed, 159 insertions, 54 deletions
diff --git a/src/base/arena.c b/src/base/arena.c index 448ee5b..bd471a2 100644 --- a/src/base/arena.c +++ b/src/base/arena.c @@ -150,10 +150,10 @@ void drawArena(arena_t *arena) getCenterScreen(&screen_x, &screen_y, tux->x, tux->y); for( i = screen_y/arena->background->h ; - i <= screen_y/arena->background->h + WINDOW_SIZE_Y/arena->background->h ; i++ ) + i <= screen_y/arena->background->h + WINDOW_SIZE_Y/arena->background->h+1 ; i++ ) { for( j = screen_x/arena->background->w ; - j <= screen_x/arena->background->w + WINDOW_SIZE_X/arena->background->w ; j++ ) + j <= screen_x/arena->background->w + WINDOW_SIZE_X/arena->background->w+1 ; j++ ) { addLayer(arena->background, j * arena->background->w, diff --git a/src/base/gun.c b/src/base/gun.c index 3cd6122..0a7e1a1 100644 --- a/src/base/gun.c +++ b/src/base/gun.c @@ -13,9 +13,11 @@ #include "base/proto.h" #include "base/net_multiplayer.h" -#ifndef PUBLIC_SERVER +#ifndef NO_SOUND #include "audio/sound.h" +#endif +#ifndef PUBLIC_SERVER #include "client/interface.h" #include "client/term.h" diff --git a/src/base/server.c b/src/base/server.c index e91e85c..fba543c 100644 --- a/src/base/server.c +++ b/src/base/server.c @@ -22,6 +22,7 @@ #include "base/net_multiplayer.h" #include "base/checkFront.h" #include "base/protect.h" +#include "base/index.h" #ifndef PUBLIC_SERVER #include "screen/screen_world.h" @@ -38,6 +39,8 @@ static sock_udp_t *sock_server_udp; static sock_udp_t *sock_server_udp_second; static list_t *listClient; +static list_t *listClientIndex; + static list_t *listServerTimer; static time_t timeUpdate; static int maxClients; @@ -52,6 +55,18 @@ time_t getUpdateServer() return time(NULL) - timeUpdate; } +static void eventDelClient(client_t *client) +{ + int offset; + + offset = getFormIndex(listClientIndex, getSockUdpPort(client->socket_udp)); + + assert( offset != -1 ); + + delFromIndex(listClientIndex, getSockUdpPort(client->socket_udp)); + delListItem(listClient, offset, destroyClient); +} + static void delZombieCLient(void *p_nothink) { client_t *thisClient; @@ -78,7 +93,8 @@ static void delZombieCLient(void *p_nothink) proto_send_del_server(PROTO_SEND_ALL, NULL, thisClient->tux->id); } - delListItem(listClient, i, destroyClient); + eventDelClient(thisClient); + i--; } } @@ -86,39 +102,25 @@ static void delZombieCLient(void *p_nothink) static void eventPeriodicSyncClient(void *p_nothink) { - client_t *thisClientInfo; client_t *thisClientSend; tux_t *thisTux; - int i, j; + int i; - for( i = 0 ; i < listClient->count; i++) +#ifndef PUBLIC_SERVER + proto_send_newtux_server(PROTO_SEND_ALL_SEES_TUX, NULL, getControlTux(TUX_CONTROL_KEYBOARD_RIGHT)); +#endif + + for( i = 0 ; i < listClient->count; i++ ) { thisClientSend = (client_t *) listClient->list[i]; + thisTux = thisClientSend->tux; - if( thisClientSend->tux == NULL ) + if( thisTux == NULL ) { continue; } -#ifndef PUBLIC_SERVER - thisTux = getControlTux(TUX_CONTROL_KEYBOARD_RIGHT); - if( isTuxSeesTux(thisClientSend->tux, thisTux) ) - proto_send_newtux_server(PROTO_SEND_ONE, thisClientSend, thisTux); -#endif - - for( j = 0 ; j < listClient->count; j++) - { - thisClientInfo = (client_t *) listClient->list[j]; - thisTux = thisClientInfo->tux; - - if( thisTux != NULL && - thisClientSend != thisClientInfo && - isTuxSeesTux(thisClientSend->tux, thisTux) ) - { - proto_send_newtux_server(PROTO_SEND_ONE, - thisClientSend, thisTux); - } - } + proto_send_newtux_server(PROTO_SEND_ALL_SEES_TUX, thisClientSend, thisTux); } } @@ -147,7 +149,10 @@ static void initServer() { startUpdateServer(); listServerTimer = NULL; + listClient = newList(); + listClientIndex = newIndex(); + setServerMaxClients(SERVER_MAX_CLIENTS); setServerTimer(); } @@ -350,10 +355,68 @@ static void addMsgAllClient(char *msg, int type, int id) static void addMsgAllClientSeesTux(char *msg, tux_t *tux, int type, int id) { + arena_t *arena; + space_t *space; + int x, y, w, h; int i; assert( msg != NULL ); + listDoEmpty(listHelp); + + arena = getCurrentArena(); + space = arena->spaceTux; + + x = tux->x-(WINDOW_SIZE_X/2)*1.25; + y = tux->y-(WINDOW_SIZE_Y/2)*1.25; + + w = WINDOW_SIZE_X*1.5; + h = WINDOW_SIZE_Y*1.5; + + if( x < 0 ) + { + x = 0; + } + + if( y < 0 ) + { + y = 0; + } + + if( w+x >= arena->w ) + { + w = arena->w - (x+1); + } + + if( h+y >= arena->h ) + { + h = arena->h - (y+1); + } + + getObjectFromSpace(space, x, y, w, h, listHelp); + //printf("%d %d %d %d %d\n", x, y, w, h, listHelp->count); + + for( i = 0 ; i < listHelp->count ; i++ ) + { + tux_t *thisTux; + client_t *thisClient; + + thisTux = (tux_t *)listHelp->list[i]; + + if( thisTux == tux ) + { + continue; + } + + thisClient = thisTux->client; + + if( thisClient != NULL ) + { + addMsgClient(thisClient, msg, type, id); + } + } + +#if 0 for( i = 0 ; i < listClient->count ; i++ ) { client_t *thisClient; @@ -373,6 +436,7 @@ static void addMsgAllClientSeesTux(char *msg, tux_t *tux, int type, int id) addMsgClient(thisClient, msg, type, id); } } +#endif } void protoSendClient(int type, client_t *client, char *msg, int type2, int id) @@ -474,11 +538,20 @@ void sendInfoCreateClient(client_t *client) static void eventCreateNewUdpClient(sock_udp_t *socket_udp) { client_t *client; + int offset; assert( socket_udp != NULL ); client = newUdpClient( socket_udp ); - addList(listClient, client); + + offset = addToIndex(listClientIndex, getSockUdpPort(client->socket_udp) ); + + if( offset == -1 ) + { + return; + } + + insList(listClient, offset, client); } static void eventClientBuffer(client_t *client) @@ -575,20 +648,17 @@ void eventClientListBuffer() static client_t* findUdpClient(sock_udp_t *sock_udp) { - int i; - client_t *thisClient; + int offset; - for( i = 0 ; i < listClient->count; i++) - { - thisClient = (client_t *) listClient->list[i]; + offset = getFormIndex(listClientIndex, getSockUdpPort(sock_udp)); - if( getSockUdpPort(thisClient->socket_udp) == getSockUdpPort(sock_udp) ) - { - return thisClient; - } + if( offset == -1 ) + { + return NULL; } - return NULL; + return (client_t *) listClient->list[offset]; + } static void eventClientUdpSelect(sock_udp_t *sock_server) @@ -773,7 +843,10 @@ void quitUdpServer() proto_send_end_server(PROTO_SEND_ALL, NULL); assert( listClient != NULL ); + destroyListItem(listClient, destroyClient); + destroyIndex(listClientIndex); + destroyTimer(listServerTimer); if( sock_server_udp != NULL ) diff --git a/src/base/tux.c b/src/base/tux.c index cd7cd4a..9d34cc9 100644 --- a/src/base/tux.c +++ b/src/base/tux.c @@ -230,6 +230,7 @@ void replaceTuxID(tux_t *tux, int id) tux->id = id; } +#if 0 int isTuxSeesTux(tux_t *tux, tux_t *thisTux) { int tux_x, tux_y, tux_w, tux_h; @@ -244,6 +245,7 @@ int isTuxSeesTux(tux_t *tux, tux_t *thisTux) return conflictSpace(screen_x-WINDOW_SIZE_X/4, screen_y-WINDOW_SIZE_Y/4, WINDOW_SIZE_X*1.25, WINDOW_SIZE_Y*1.25, thisTux_x, thisTux_y, thisTux_w, thisTux_h); } +#endif static void timer_spawnTux(void *p) { diff --git a/src/base/tux.h b/src/base/tux.h index 8a39cf9..c8f6e51 100644 --- a/src/base/tux.h +++ b/src/base/tux.h @@ -127,7 +127,6 @@ extern void eventListTux(list_t *listTux); extern tux_t* getTuxID(list_t *listTux, int id); extern void getTuxProportion(tux_t *tux, int *x,int *y, int *w, int *h); extern void replaceTuxID(tux_t *tux, int id); -extern int isTuxSeesTux(tux_t *tux, tux_t *thisTux); extern void setTuxProportion(tux_t *tux, int x, int y); extern void getStatusTux(void *p, int *id, int *x,int *y, int *w, int *h); extern void setStatusTux(void *p, int x, int y, int w, int h); diff --git a/src/net_unix/udp.c b/src/net_unix/udp.c index 79df4b0..13cb916 100644 --- a/src/net_unix/udp.c +++ b/src/net_unix/udp.c @@ -249,10 +249,11 @@ void getSockUdpIp(sock_udp_t *p, char *str_ip, int len) assert( p != NULL ); assert( str_ip != NULL ); - //strcpy(str_ip, inet_ntoa(p->sockAddr.sin_addr)); if( p->proto == PROTO_UDPv4 ) { + //strcpy(str_ip, inet_ntoa(p->sockAddr.sin_addr)); + //printf("strcpy(str_ip, inet_ntoa(p->sockAddr.sin_addr));\n"); inet_ntop(AF_INET, &(p->sockAddr.sin_addr), str_ip, len); } diff --git a/src/net_unix/udp.h b/src/net_unix/udp.h index a8d935f..a9a38f6 100644 --- a/src/net_unix/udp.h +++ b/src/net_unix/udp.h @@ -28,5 +28,4 @@ extern int writeUdpSocket(sock_udp_t *src, sock_udp_t *dst, void *address, int l extern void getSockUdpIp(sock_udp_t *p, char *str_ip, int len); extern int getSockUdpPort(sock_udp_t *p); extern void closeUdpSocket(sock_udp_t *p); - #endif diff --git a/src/screen/screen_browser.c b/src/screen/screen_browser.c index 0eb82af..44b0411 100644 --- a/src/screen/screen_browser.c +++ b/src/screen/screen_browser.c @@ -98,8 +98,9 @@ void stopScreenBrowser() unsigned i = 0; server_t *server; - destroyListItem(select_server->list, free); - select_server->list = newList(); + //destroyListItem(select_server->list, free); + //select_server->list = newList(); + removeAllFromWidgetSelect(select_server); while (1) { i = 0; @@ -397,16 +398,16 @@ static int LoadServers () } struct timeval tv; - // Mno¾ina + // Mno�ina fd_set myset; - // Mno¾ina obsahuje náhodná data. Odstraním je. + // Mno�ina obsahuje n�hodn� data. Odstran�m je. FD_ZERO(&myset); - // Zaplnìní mno¾iny sokety + // Zapln�n� mno�iny sokety FD_SET(s, &myset); - // Vyplním èasový údaj (napøíklad na 3 minuty) - tv.tv_sec = 3;// Poèet sekund - tv.tv_usec = 0;// Poèet mikrosekund - // Zavolám select (V Linuxu musím mít nastavenou promìnnou max.) + // Vypln�m �asov� �daj (nap��klad na 3 minuty) + tv.tv_sec = 3;// Po�et sekund + tv.tv_usec = 0;// Po�et mikrosekund + // Zavol�m select (V Linuxu mus�m m�t nastavenou prom�nnou max.) int ret = select (s+1, NULL, &myset, NULL, &tv); if (ret == -1) @@ -418,9 +419,9 @@ static int LoadServers () /* send request for server list */ send (s, "l", 1, 0); - // Mno¾ina obsahuje náhodná data. Odstraním je. + // Mno�ina obsahuje n�hodn� data. Odstran�m je. FD_ZERO(&myset); - // Zaplnìní mno¾iny sokety + // Zapln�n� mno�iny sokety FD_SET(s, &myset); ret = select (s+1, &myset, NULL, NULL, &tv); @@ -546,7 +547,7 @@ void initScreenBrowser() { SDL_Surface *image; - image = addImageData("screen_main.png", IMAGE_NO_ALPHA, "screen_browser", IMAGE_GROUP_BASE); + image = getImage(IMAGE_GROUP_BASE, "screen_main"); image_backgorund = newWidgetImage(0, 0, image); button_back = newWidgetButton(getMyText("BACK"), 100, WINDOW_SIZE_Y-100, eventWidget); diff --git a/src/server/serverConfigFile.c b/src/server/serverConfigFile.c index c6456ee..48d57eb 100644 --- a/src/server/serverConfigFile.c +++ b/src/server/serverConfigFile.c @@ -49,6 +49,24 @@ void initServerConfigFile() } +static char *findValue(char *s) +{ + int len; + int i; + + len = strlen(s); + + for( i = 0 ; i < len-1 ; i++) + { + if( s[i] == ' ' && s[i+1] != ' ' ) + { + return s+i+1; + } + } + + return NULL; +} + char* getServerConfigFileValue(char *env, char *s) { int i; @@ -69,7 +87,7 @@ char* getServerConfigFileValue(char *env, char *s) if( strncmp(line, env, len) == 0 ) { - return strrchr(line,' ')+1; + return findValue(line); } } diff --git a/src/widget/widget_select.c b/src/widget/widget_select.c index f51239c..4d10bc4 100644 --- a/src/widget/widget_select.c +++ b/src/widget/widget_select.c @@ -34,6 +34,14 @@ void addToWidgetSelect(widget_select_t *p, char *s) addList(p->list, strdup(s) ); } +void removeAllFromWidgetSelect(widget_select_t *p) +{ + while( p->list->count > 0 ) + { + delListItem(p->list, 0, free); + } +} + void drawWidgetSelect(widget_select_t *p) { int x, y, w, h; diff --git a/src/widget/widget_select.h b/src/widget/widget_select.h index 2765f11..7bbe5c0 100644 --- a/src/widget/widget_select.h +++ b/src/widget/widget_select.h @@ -18,6 +18,7 @@ typedef struct widget_select extern widget_select_t* newWidgetSelect(int x, int y, void (*fce_event)(void *)); extern void addToWidgetSelect(widget_select_t *p, char *s); +extern void removeAllFromWidgetSelect(widget_select_t *p); extern void drawWidgetSelect(widget_select_t *p); extern void eventWidgetSelect(widget_select_t *p); extern void destroyWidgetSelect(widget_select_t *p); diff --git a/src/widget/widget_textfield.c b/src/widget/widget_textfield.c index 2e4a9ec..f93f298 100644 --- a/src/widget/widget_textfield.c +++ b/src/widget/widget_textfield.c @@ -16,6 +16,7 @@ widget_textfield_t* newWidgetTextfield(char *text, int x, int y) new->y = y; new->time = 0; new->timeBlick = 0; + new->atime = 0; new->active = FALSE; getTextSize(text, &new->w, &new->h); |