diff options
| author | oroborus <oroborus@0ee4d065-81f0-4d1e-b06c-ff20ad07cc3e> | 2008-03-15 18:35:48 +0000 |
|---|---|---|
| committer | oroborus <oroborus@0ee4d065-81f0-4d1e-b06c-ff20ad07cc3e> | 2008-03-15 18:35:48 +0000 |
| commit | b84b59153c587248ca8a6a94a6d93977e851233f (patch) | |
| tree | e13b33f09ee6ac130bb6045626618b1c5fc4d787 /src | |
| parent | 6038f9434f1eb40caf7992ece9a3972e95a9fc11 (diff) | |
- moznost skompilovat public server bez GUI ( pomocou Makefile-publicServer )
port sa nastavuje ako ./publicserver --port <port>
- jeto iba prvotna verzia treba to este odladit a zostabilnit
git-svn-id: http://opensvn.csie.org/tuxanci_ng@18 0ee4d065-81f0-4d1e-b06c-ff20ad07cc3e
Diffstat (limited to 'src')
| -rwxr-xr-x | src/Makefile-publicServer | 90 | ||||
| -rw-r--r-- | src/arena.c | 2 | ||||
| -rw-r--r-- | src/arenaFile.c | 37 | ||||
| -rw-r--r-- | src/client.c | 10 | ||||
| -rw-r--r-- | src/gun.c | 23 | ||||
| -rw-r--r-- | src/item.c | 43 | ||||
| -rw-r--r-- | src/main.c | 37 | ||||
| -rw-r--r-- | src/myTimer.c | 39 | ||||
| -rw-r--r-- | src/net_multiplayer.c | 21 | ||||
| -rw-r--r-- | src/pipe.c | 26 | ||||
| -rw-r--r-- | src/proto.c | 78 | ||||
| -rw-r--r-- | src/publicServer.c | 109 | ||||
| -rw-r--r-- | src/screen_table.c | 1 | ||||
| -rw-r--r-- | src/screen_world.c | 3 | ||||
| -rw-r--r-- | src/server.c | 40 | ||||
| -rw-r--r-- | src/shot.c | 35 | ||||
| -rw-r--r-- | src/teleport.c | 28 | ||||
| -rw-r--r-- | src/tux.c | 43 | ||||
| -rw-r--r-- | src/wall.c | 26 |
19 files changed, 622 insertions, 69 deletions
diff --git a/src/Makefile-publicServer b/src/Makefile-publicServer new file mode 100755 index 0000000..bb4b12b --- /dev/null +++ b/src/Makefile-publicServer @@ -0,0 +1,90 @@ + +#CC = /usr/local/gcc/bin/gcc +CC = gcc + +DISTDIR:=/usr/ + +CFLAGS = -g -O0 -DBUBLIC_SERVER -DDISTDIR=\"$(DISTDIR)\" `sdl-config --cflags` -I../include -Wall +#CFLAGS = -O2 -DDISTDIR=\"$(DISTDIR)\" `sdl-config --cflags` -I../include -Wall + +LIBS = + +FILES = list.o director.o configFile.o tux.o main.o wall.o shot.o myTimer.o \ + buffer.o dynamicInt.o arena.o arenaFile.o textFile.o gun.o item.o teleport.o pipe.o tcp.o\ + udp.o proto.o server.o publicServer.o net_multiplayer.o + +publicserver: $(FILES) + $(CC) $(CFLAGS) $(LIBS) -o publicserver $(FILES) + +main.o: main.c + $(CC) $(CFLAGS) -o main.o -c main.c + +publicServer.o: publicServer.c + $(CC) $(CFLAGS) -o publicServer.o -c publicServer.c + +list.o: list.c ../include/list.h + $(CC) $(CFLAGS) -o list.o -c list.c + +director.o: director.c ../include/director.h + $(CC) $(CFLAGS) -o director.o -c director.c + +configFile.o: configFile.c ../include/configFile.h + $(CC) $(CFLAGS) -o configFile.o -c configFile.c + +tux.o: tux.c ../include/tux.h + $(CC) $(CFLAGS) -o tux.o -c tux.c + +wall.o: wall.c ../include/wall.h + $(CC) $(CFLAGS) -o wall.o -c wall.c + +shot.o: shot.c ../include/shot.h + $(CC) $(CFLAGS) -o shot.o -c shot.c + +myTimer.o: myTimer.c ../include/myTimer.h + $(CC) $(CFLAGS) -o myTimer.o -c myTimer.c + +buffer.o: buffer.c ../include/buffer.h + $(CC) $(CFLAGS) -o buffer.o -c buffer.c + +tcp.o: tcp.c ../include/tcp.h + $(CC) $(CFLAGS) -o tcp.o -c tcp.c + +udp.o: udp.c ../include/udp.h + $(CC) $(CFLAGS) -o udp.o -c udp.c + +proto.o: proto.c ../include/proto.h + $(CC) $(CFLAGS) -o proto.o -c proto.c + +server.o: server.c ../include/server.h + $(CC) $(CFLAGS) -o server.o -c server.c + +net_multiplayer.o: net_multiplayer.c ../include/net_multiplayer.h + $(CC) $(CFLAGS) -o net_multiplayer.o -c net_multiplayer.c + +dynamicInt.o: dynamicInt.c ../include/dynamicInt.h + $(CC) $(CFLAGS) -o dynamicInt.o -c dynamicInt.c + +arena.o: arena.c ../include/arena.h + $(CC) $(CFLAGS) -o arena.o -c arena.c + +textFile.o: textFile.c ../include/textFile.h + $(CC) $(CFLAGS) -o textFile.o -c textFile.c + +arenaFile.o: arenaFile.c ../include/arenaFile.h + $(CC) $(CFLAGS) -o arenaFile.o -c arenaFile.c + +gun.o: gun.c ../include/gun.h + $(CC) $(CFLAGS) -o gun.o -c gun.c + +item.o: item.c ../include/item.h + $(CC) $(CFLAGS) -o item.o -c item.c + +teleport.o: teleport.c ../include/teleport.h + $(CC) $(CFLAGS) -o teleport.o -c teleport.c + +pipe.o: pipe.c ../include/pipe.h + $(CC) $(CFLAGS) -o pipe.o -c pipe.c + +clean: + rm -rf *.o *.c~ *.h~ publicserver + diff --git a/src/arena.c b/src/arena.c index 6ce2712..52044d1 100644 --- a/src/arena.c +++ b/src/arena.c @@ -15,8 +15,10 @@ arena_t* newArena() arena_t *new; new = malloc( sizeof(arena_t) ); +#ifndef BUBLIC_SERVER new->background = NULL; strcpy(new->music, ""); +#endif new->listTux = newList(); new->listShot = newList(); diff --git a/src/arenaFile.c b/src/arenaFile.c index 76780c6..f13750a 100644 --- a/src/arenaFile.c +++ b/src/arenaFile.c @@ -19,8 +19,11 @@ #include "director.h" #include "path.h" #include "string_length.h" + +#ifndef BUBLIC_SERVER #include "image.h" #include "music.h" +#endif static list_t *listArenaFile; @@ -31,6 +34,8 @@ bool_t isAreaFileInicialized() return isArenaFileInit; } +#ifndef BUBLIC_SERVER + static void cmd_loadImage(char *line) { char str_file[STR_SIZE]; @@ -73,6 +78,8 @@ static void cmd_playMusic(arena_t *arena, char *line) strcpy(arena->music, str_music); } +#endif + static void cmd_wall(arena_t *arena, char *line) { char str_x[STR_NUM_SIZE]; @@ -94,10 +101,19 @@ static void cmd_wall(arena_t *arena, char *line) if( getValue(line, "layer", str_layer, STR_NUM_SIZE) != 0 )return; if( getValue(line, "image", str_image, STR_SIZE) != 0 )return; +#ifndef BUBLIC_SERVER new = newWall(atoi(str_x), atoi(str_y), atoi(str_w), atoi(str_h), atoi(str_img_x), atoi(str_img_y), atoi(str_layer), getImage(IMAGE_GROUP_USER, str_image) ); +#endif + +#ifdef BUBLIC_SERVER + new = newWall(atoi(str_x), atoi(str_y), + atoi(str_w), atoi(str_h), + atoi(str_img_x), atoi(str_img_y), + atoi(str_layer) ); +#endif addList(arena->listWall, new); } @@ -119,9 +135,17 @@ static void cmd_teleport(arena_t *arena, char *line) if( getValue(line, "layer", str_layer, STR_NUM_SIZE) != 0 )return; if( getValue(line, "image", str_image, STR_SIZE) != 0 )return; +#ifndef BUBLIC_SERVER new = newTeleport(atoi(str_x), atoi(str_y), atoi(str_w), atoi(str_h), atoi(str_layer), getImage(IMAGE_GROUP_USER, str_image) ); +#endif + +#ifdef BUBLIC_SERVER + new = newTeleport(atoi(str_x), atoi(str_y), + atoi(str_w), atoi(str_h), + atoi(str_layer) ); +#endif addList(arena->listTeleport, new); } @@ -149,10 +173,18 @@ static void cmd_pipe(arena_t *arena, char *line) if( getValue(line, "layer", str_layer, STR_NUM_SIZE) != 0 )return; if( getValue(line, "image", str_image, STR_SIZE) != 0 )return; +#ifndef BUBLIC_SERVER new = newPipe(atoi(str_x), atoi(str_y), atoi(str_w), atoi(str_h), atoi(str_layer), atoi(str_id), atoi(str_id_out), atoi(str_position), getImage(IMAGE_GROUP_USER, str_image) ); +#endif + +#ifdef BUBLIC_SERVER + new = newPipe(atoi(str_x), atoi(str_y), + atoi(str_w), atoi(str_h), + atoi(str_layer), atoi(str_id), atoi(str_id_out), atoi(str_position) ); +#endif addList(arena->listPipe, new); } @@ -237,10 +269,13 @@ arena_t* getArena(int id) char *line; line = (char *) (ts->text->list[i]); +#ifndef BUBLIC_SERVER if( strncmp(line, "loadImage", 9) == 0 )cmd_loadImage(line); if( strncmp(line, "loadMusic", 9) == 0 )cmd_loadMusic(line); if( strncmp(line, "background", 10) == 0 )cmd_background(arena, line); if( strncmp(line, "playMusic", 9) == 0 )cmd_playMusic(arena, line); +#endif + if( strncmp(line, "wall", 4) == 0 )cmd_wall(arena, line); if( strncmp(line, "teleport", 8) == 0 )cmd_teleport(arena, line); if( strncmp(line, "pipe", 4) == 0 )cmd_pipe(arena, line); @@ -254,7 +289,9 @@ void initArenaFile() director_t *p; int i; +#ifndef BUBLIC_SERVER assert( isImageInicialized() == TRUE ); +#endif isArenaFileInit = TRUE; listArenaFile = newList(); diff --git a/src/client.c b/src/client.c index 5a96b00..4992b40 100644 --- a/src/client.c +++ b/src/client.c @@ -18,12 +18,12 @@ static int protocolType; static sock_tcp_t *sock_server_tcp; static sock_udp_t *sock_server_udp; static buffer_t *clientBuffer; -static Uint32 lastPing; +static my_time_t lastPing; static void initClient() { clientBuffer = newBuffer( LIMIT_BUFFER ); - lastPing = SDL_GetTicks(); + lastPing = getMyTime(); proto_send_hello_client(); } @@ -176,14 +176,14 @@ void selectClientTcpSocket() void eventPingServer() { - Uint32 currentTime; + my_time_t currentTime; - currentTime = SDL_GetTicks(); + currentTime = getMyTime(); if( currentTime - lastPing > CLIENT_TIMEOUT ) { proto_send_ping_client(); - lastPing = SDL_GetTicks(); + lastPing = getMyTime(); } } @@ -10,10 +10,17 @@ #include "myTimer.h" #include "main.h" #include "item.h" +#include "gun.h" + +#ifndef BUBLIC_SERVER #include "sound.h" #include "screen_world.h" #include "interface.h" -#include "gun.h" +#endif + +#ifdef BUBLIC_SERVER +#include "publicServer.h" +#endif static void modificiationCopuse(int courser, int right_x, int right_y, int *dest_x, int *dest_y) { @@ -238,27 +245,39 @@ void shotInGun(tux_t *tux) switch( tux->gun ) { case GUN_SIMPLE : +#ifndef BUBLIC_SERVER playSound("gun_revolver", SOUND_GROUP_BASE); +#endif shotInGunSimpe(tux); break; case GUN_DUAL_SIMPLE : +#ifndef BUBLIC_SERVER playSound("gun_revolver", SOUND_GROUP_BASE); +#endif shotInGunDualSimpe(tux); break; case GUN_SCATTER : - playSound("gun_scatter", SOUND_GROUP_BASE); +#ifndef BUBLIC_SERVER + playSound("gun_scatter", SOUND_GROUP_BASE); +#endif shotInGunScatter(tux); break; case GUN_TOMMY : +#ifndef BUBLIC_SERVER playSound("gun_tommy", SOUND_GROUP_BASE); +#endif shotInGunTommy(tux); break; case GUN_LASSER : +#ifndef BUBLIC_SERVER playSound("gun_lasser", SOUND_GROUP_BASE); +#endif shotInGunLasser(tux); break; case GUN_MINE : +#ifndef BUBLIC_SERVER playSound("put_mine", SOUND_GROUP_BASE); +#endif putInGunMine(tux); break; } @@ -3,19 +3,29 @@ #include <assert.h> #include "main.h" +#include "arena.h" +#include "tux.h" +#include "item.h" +#include "shot.h" +#include "proto.h" +#include "net_multiplayer.h" + +#ifndef BUBLIC_SERVER #include "interface.h" #include "image.h" #include "sound.h" #include "layer.h" #include "screen_world.h" #include "screen_setting.h" -#include "net_multiplayer.h" -#include "tux.h" -#include "item.h" -#include "shot.h" -#include "proto.h" +#endif + +#ifdef BUBLIC_SERVER +#include "publicServer.h" +#endif +#ifndef BUBLIC_SERVER static SDL_Surface *g_item[ITEM_COUNT]; +#endif static bool_t isItemInit = FALSE; @@ -26,6 +36,7 @@ bool_t isItemInicialized() void initItem() { +#ifndef BUBLIC_SERVER g_item[GUN_DUAL_SIMPLE] = addImageData("item.dual.png", IMAGE_ALPHA, "item_dual_simple", IMAGE_GROUP_BASE); g_item[GUN_TOMMY] = addImageData("item.tommy.png", IMAGE_ALPHA, "item_tommy_simple", IMAGE_GROUP_BASE); g_item[GUN_SCATTER] = addImageData("item.scatter.png", IMAGE_ALPHA, "item_scatter_simple", IMAGE_GROUP_BASE); @@ -41,7 +52,7 @@ void initItem() g_item[BONUS_GHOST] = addImageData("item.bonus.ghost.png", IMAGE_ALPHA, "item_ghost_speed", IMAGE_GROUP_BASE); g_item[BONUS_4X] = addImageData("item.bonus.4x.png", IMAGE_ALPHA, "item_4x_speed", IMAGE_GROUP_BASE); g_item[BONUS_HIDDEN] = addImageData("item.bonus.hidden.png", IMAGE_ALPHA, "item_hidden_speed", IMAGE_GROUP_BASE); - +#endif isItemInit = TRUE; } @@ -58,7 +69,9 @@ item_t* newItem(int x, int y, int type, tux_t *author) new->y = y; new->frame = 0; new->count = 0; +#ifndef BUBLIC_SERVER new->img = g_item[type]; +#endif new->author = author; switch( type ) @@ -78,13 +91,17 @@ item_t* newItem(int x, int y, int type, tux_t *author) break; case ITEM_EXPLOSION : +#ifndef BUBLIC_SERVER playSound("explozion", SOUND_GROUP_BASE); +#endif new->w = ITEM_EXPLOSION_WIDTH; new->h = ITEM_EXPLOSION_HEIGHT; break; case ITEM_BIG_EXPLOSION : +#ifndef BUBLIC_SERVER playSound("explozion", SOUND_GROUP_BASE); +#endif new->w = ITEM_BIG_EXPLOSION_WIDTH; new->h = ITEM_BIG_EXPLOSION_HEIGHT; break; @@ -110,18 +127,22 @@ void addNewItem(list_t *listItem, tux_t *author) int new_x, new_y; int type; +#ifndef BUBLIC_SERVER if( isSettingAnyItem() == FALSE || getNetTypeGame() == NET_GAME_TYPE_CLIENT ) { return; } +#endif arena = getWorldArena(); findFreeSpace(&new_x, &new_y, ITEM_GUN_WIDTH, ITEM_GUN_HEIGHT); type = GUN_DUAL_SIMPLE; +#ifndef BUBLIC_SERVER do{ +#endif switch( random() % 11 ) { case 0 : type = GUN_DUAL_SIMPLE; @@ -147,7 +168,9 @@ void addNewItem(list_t *listItem, tux_t *author) case 10 : type = BONUS_HIDDEN; break; } +#ifndef BUBLIC_SERVER }while( isSettingItem(type) == FALSE ); +#endif item = newItem(new_x, new_y, type, author); addList(listItem, item); @@ -158,6 +181,8 @@ void addNewItem(list_t *listItem, tux_t *author) } } +#ifndef BUBLIC_SERVER + void drawItem(item_t *p) { assert( p != NULL ); @@ -180,6 +205,8 @@ void drawListItem(list_t *listItem) } } +#endif + void eventListItem(list_t *listItem) { item_t *thisItem; @@ -351,7 +378,9 @@ void eventGiveTuxItem(tux_t *tux, list_t *listItem) case GUN_LASSER : case GUN_MINE : tux->pickup_time = 0; +#ifndef BUBLIC_SERVER playSound("item_gun", SOUND_GROUP_BASE); +#endif tux->shot[ thisItem->type ] += GUN_MAX_SHOT; tux->gun = thisItem->type; delListItem(listItem, i, destroyItem); @@ -390,7 +419,9 @@ void eventGiveTuxItem(tux_t *tux, list_t *listItem) case BONUS_GHOST : case BONUS_4X : case BONUS_HIDDEN : +#ifndef BUBLIC_SERVER playSound("item_bonus", SOUND_GROUP_BASE); +#endif tux->bonus = thisItem->type; tux->bonus_time = TUX_MAX_BONUS; delListItem(listItem, i, destroyItem); @@ -1,12 +1,15 @@ #include <time.h> -#include "interface.h" #include "main.h" +#include "tux.h" + +#ifndef BUBLIC_SERVER + #include "font.h" #include "image.h" #include "layer.h" -#include "tux.h" +#include "interface.h" #include "screen.h" #include "screen_world.h" #include "screen_mainMenu.h" @@ -17,19 +20,25 @@ #include "screen_table.h" #include "screen_credits.h" #include "homeDirector.h" -#include "wall.h" -#include "shot.h" #include "panel.h" -#include "myTimer.h" -#include "arenaFile.h" #include "audio.h" #include "sound.h" #include "music.h" + +#endif + +#include "wall.h" +#include "shot.h" +#include "myTimer.h" +#include "arenaFile.h" #include "item.h" +#include "publicServer.h" static int my_argc; static char **my_argv; +#ifndef BUBLIC_SERVER + static void init() { createHomeDirector(); @@ -86,6 +95,8 @@ void quit() exit(0); } +#endif + char* getParam(char *s) { int i; @@ -145,12 +156,26 @@ int main(int argc, char *argv[]) my_argc = argc; my_argv = argv; +#ifndef BUBLIC_SERVER + init(); setScreen("mainMenu"); eventSDL(); quit(); +#endif + +#ifdef BUBLIC_SERVER + + initPublicServer(); + + while(1) + { + eventPublicServer(); + } + +#endif return 0; } diff --git a/src/myTimer.c b/src/myTimer.c index 1a73384..04abef0 100644 --- a/src/myTimer.c +++ b/src/myTimer.c @@ -2,12 +2,17 @@ #include <time.h> #include <assert.h> #include <stdlib.h> +#include <sys/time.h> +#include <signal.h> #include "main.h" -#include "interface.h" #include "list.h" #include "myTimer.h" +#ifndef BUBLIC_SERVER +#include "interface.h" +#endif + static list_t *listTime; static bool_t isTimerInit = FALSE; @@ -19,19 +24,37 @@ bool_t isMyTimerInicialized() void initTimer() { - assert( isInterfaceInicialized() == TRUE ); - listTime = newList(); isTimerInit = TRUE; } -int addTimer(void (*fce)(void *p), void *arg, int my_time) +my_time_t getMyTime() +{ + static struct timeval start; + struct timeval now; + static char first = '0'; + my_time_t ticks; + + if( first == '0' ) + { + gettimeofday(&start, NULL); + first = 'x'; + } + + gettimeofday(&now, NULL); + + ticks = (now.tv_sec-start.tv_sec)*1000+(now.tv_usec-start.tv_usec)/1000; + + return ticks; +} + +int addTimer(void (*fce)(void *p), void *arg, my_time_t my_time) { static int new_id = 0; my_timer_t *new; - Uint32 currentTime; + my_time_t currentTime; - currentTime = SDL_GetTicks(); + currentTime = getMyTime(); new = malloc( sizeof(my_timer_t) ); assert( new != NULL ); @@ -50,9 +73,9 @@ void eventTimer() { int i; my_timer_t *thisTimer; - Uint32 currentTime; + my_time_t currentTime; - currentTime = SDL_GetTicks(); + currentTime = getMyTime(); for( i = 0 ; i < listTime->count ; i++ ) { diff --git a/src/net_multiplayer.c b/src/net_multiplayer.c index e3f5d93..410ee99 100644 --- a/src/net_multiplayer.c +++ b/src/net_multiplayer.c @@ -8,20 +8,21 @@ #include "list.h" #include "tux.h" #include "item.h" -#include "network.h" #include "buffer.h" #include "string_length.h" -#include "screen.h" -#include "screen_world.h" -#include "screen_setting.h" -#include "screen_choiceArena.h" #include "arenaFile.h" #include "net_multiplayer.h" #include "server.h" -#include "client.h" #include "tcp.h" #include "udp.h" +#ifndef BUBLIC_SERVER +#include "screen.h" +#include "screen_setting.h" +#include "screen_choiceArena.h" +#include "client.h" +#endif + static int netGameType; static int netProtoType = NET_PROTOCOL_TYPE_UDP; @@ -62,6 +63,7 @@ int initNetMuliplayer(int type, char *ip, int port) break; +#ifndef BUBLIC_SERVER case NET_GAME_TYPE_CLIENT : switch( netProtoType ) { @@ -83,7 +85,7 @@ int initNetMuliplayer(int type, char *ip, int port) break; } break; - +#endif default : assert( ! "Premenna netGameType ma zlu hodnotu !" ); break; @@ -115,6 +117,7 @@ void eventNetMultiplayer() } break; +#ifndef BUBLIC_SERVER case NET_GAME_TYPE_CLIENT : switch( netProtoType ) { @@ -129,7 +132,7 @@ void eventNetMultiplayer() break; } break; - +#endif default : assert( ! "Premenna netGameType ma zlu hodnotu !" ); break; @@ -155,6 +158,7 @@ void quitNetMultiplayer() } break; +#ifndef BUBLIC_SERVER case NET_GAME_TYPE_CLIENT : switch( netProtoType ) { @@ -166,6 +170,7 @@ void quitNetMultiplayer() break; } break; +#endif default : assert( ! "Premenna netGameType ma zlu hodnotu !" ); @@ -2,16 +2,33 @@ #include <stdlib.h> #include <assert.h> +#include "main.h" #include "pipe.h" #include "layer.h" -#include "screen_world.h" #include "shot.h" +#ifndef BUBLIC_SERVER +#include "screen_world.h" +#endif + +#ifdef BUBLIC_SERVER +#include "publicServer.h" +#endif + +#ifndef BUBLIC_SERVER pipe_t* newPipe(int x, int y, int w, int h, int layer, int id, int id_out, int position, SDL_Surface *img) +#endif + +#ifdef BUBLIC_SERVER +pipe_t* newPipe(int x, int y, int w, int h, int layer, int id, int id_out, int position) +#endif + { pipe_t *new; +#ifndef BUBLIC_SERVER assert( img != NULL ); +#endif new = malloc( sizeof(pipe_t) ); assert( new != NULL ); @@ -24,11 +41,14 @@ pipe_t* newPipe(int x, int y, int w, int h, int layer, int id, int id_out, int p new->id = id; new->id_out = id_out; new->position = position; +#ifndef BUBLIC_SERVER new->img = img; - +#endif return new; } +#ifndef BUBLIC_SERVER + void drawPipe(pipe_t *p) { assert( p != NULL ); @@ -51,6 +71,8 @@ void drawListPipe(list_t *listPipe) } } +#endif + pipe_t* isConflictWithListPipe(list_t *listPipe, int x, int y, int w, int h) { pipe_t *thisPipe; diff --git a/src/proto.c b/src/proto.c index ddfc51c..01a4ad2 100644 --- a/src/proto.c +++ b/src/proto.c @@ -2,19 +2,29 @@ #include <stdio.h> #include <assert.h> +#include "main.h" #include "list.h" #include "tux.h" #include "item.h" +#include "arenaFile.h" +#include "myTimer.h" +#include "server.h" +#include "proto.h" +#include "net_multiplayer.h" + +#ifndef BUBLIC_SERVER #include "network.h" -#include "string_length.h" #include "screen_world.h" #include "screen_setting.h" #include "screen_choiceArena.h" -#include "arenaFile.h" -#include "net_multiplayer.h" #include "client.h" -#include "server.h" -#include "proto.h" +#endif + +#ifdef BUBLIC_SERVER +#include "publicServer.h" +#endif + +#ifndef BUBLIC_SERVER void proto_send_hello_client() { @@ -24,18 +34,24 @@ void proto_send_hello_client() sendServer(msg); } +#endif + void proto_recv_hello_server(client_t *client, char *msg) { } + void proto_send_init_server(client_t *client) { char msg[STR_SIZE]; - int n; + int n = 9999; assert( client != NULL ); +#ifndef BUBLIC_SERVER getSettingCountRound(&n); +#endif + sprintf(msg, "init %d %d %d %d %s\n", client->tux->id, client->tux->x, client->tux->y, @@ -44,6 +60,8 @@ void proto_send_init_server(client_t *client) sendClient(client, msg); } +#ifndef BUBLIC_SERVER + void proto_recv_init_client(char *msg) { char cmd[STR_SIZE]; @@ -71,6 +89,8 @@ void proto_recv_init_client(char *msg) addList(getWorldArena()->listTux, tux); } +#endif + void proto_send_event_server(tux_t *tux, int action, client_t *client) { char msg[STR_SIZE]; @@ -82,6 +102,8 @@ void proto_send_event_server(tux_t *tux, int action, client_t *client) sendAllClientBut(msg, client); } +#ifndef BUBLIC_SERVER + void proto_recv_event_client(char *msg) { char cmd[STR_SIZE]; @@ -100,6 +122,10 @@ void proto_recv_event_client(char *msg) } } +#endif + +#ifndef BUBLIC_SERVER + void proto_send_event_client(int action) { char msg[STR_SIZE]; @@ -109,6 +135,8 @@ void proto_send_event_client(int action) sendServer(msg); } +#endif + void proto_recv_event_server(client_t *client, char *msg) { char cmd[STR_SIZE]; @@ -147,6 +175,8 @@ void proto_send_newtux_server(client_t *client, tux_t *tux) } } +#ifndef BUBLIC_SERVER + void proto_recv_newtux_client(char *msg) { char cmd[STR_SIZE]; @@ -193,6 +223,8 @@ void proto_recv_newtux_client(char *msg) tux->status = TUX_STATUS_ALIVE; } +#endif + void proto_send_kill_server(tux_t *tux) { char msg[STR_SIZE]; @@ -204,6 +236,8 @@ void proto_send_kill_server(tux_t *tux) sendAllClient(msg); } +#ifndef BUBLIC_SERVER + void proto_recv_kill_client(char *msg) { char cmd[STR_SIZE]; @@ -222,6 +256,8 @@ void proto_recv_kill_client(char *msg) } } +#endif + void proto_send_score_server(tux_t *tux) { char msg[STR_SIZE]; @@ -233,6 +269,8 @@ void proto_send_score_server(tux_t *tux) sendAllClient(msg); } +#ifndef BUBLIC_SERVER + void proto_recv_score_client(char *msg) { char cmd[STR_SIZE]; @@ -253,6 +291,8 @@ void proto_recv_score_client(char *msg) countRoundInc(); } +#endif + void proto_send_deltux_server(client_t *client) { char msg[STR_SIZE]; @@ -264,6 +304,8 @@ void proto_send_deltux_server(client_t *client) sendAllClientBut(msg, client); } +#ifndef BUBLIC_SERVER + void proto_recv_deltux_client(char *msg) { char cmd[STR_SIZE]; @@ -285,6 +327,8 @@ void proto_recv_deltux_client(char *msg) } } +#endif + void proto_send_additem_server(item_t *p) { char msg[STR_SIZE]; @@ -303,6 +347,8 @@ void proto_send_additem_server(item_t *p) sendAllClient(msg); } +#ifndef BUBLIC_SERVER + void proto_recv_additem_client(char *msg) { char cmd[STR_SIZE]; @@ -327,6 +373,10 @@ void proto_recv_additem_client(char *msg) addList(getWorldArena()->listItem, item); } +#endif + +#ifndef BUBLIC_SERVER + void proto_send_context_client(tux_t *tux) { char msg[STR_SIZE]; @@ -338,6 +388,8 @@ void proto_send_context_client(tux_t *tux) sendServer(msg); } +#endif + void proto_recv_context_server(client_t *client, char *msg) { char cmd[STR_SIZE]; @@ -353,6 +405,8 @@ void proto_recv_context_server(client_t *client, char *msg) proto_send_newtux_server(NULL, client->tux); } +#ifndef BUBLIC_SERVER + void proto_send_ping_client() { char msg[STR_SIZE]; @@ -360,14 +414,18 @@ void proto_send_ping_client() sendServer(msg); } +#endif + void proto_recv_ping_server(client_t *client, char *msg) { assert( msg != NULL ); assert( client != NULL ); - client->lastPing = SDL_GetTicks(); + client->lastPing = getMyTime(); } +#ifndef BUBLIC_SERVER + void proto_send_end_client() { char msg[STR_SIZE]; @@ -375,6 +433,8 @@ void proto_send_end_client() sendServer(msg); } +#endif + void proto_recv_end_server(client_t *client, char *msg) { assert( msg != NULL ); @@ -390,6 +450,9 @@ void proto_send_end_server() sendAllClient(msg); } + +#ifndef BUBLIC_SERVER + void proto_recv_end_client(char *msg) { assert( msg != NULL ); @@ -397,3 +460,4 @@ void proto_recv_end_client(char *msg) setWorldEnd(); } +#endif diff --git a/src/publicServer.c b/src/publicServer.c new file mode 100644 index 0000000..f76da76 --- /dev/null +++ b/src/publicServer.c @@ -0,0 +1,109 @@ + +#include <stdio.h> +#include <assert.h> + +#include "main.h" +#include "list.h" +#include "tux.h" +#include "wall.h" +#include "teleport.h" +#include "pipe.h" +#include "item.h" +#include "shot.h" +#include "myTimer.h" +#include "arena.h" +#include "arenaFile.h" +#include "proto.h" +#include "publicServer.h" +#include "net_multiplayer.h" + +static int arenaId = 0; +static arena_t *arena; + +arena_t* getWorldArena() +{ + return arena; +} + +void countRoundInc() +{ +} + +void initPublicServer() +{ + initArenaFile(); + initTux(); + initItem(); + initShot(); + initTimer(); + + arena = getArena(arenaId); + addNewItem(arena->listItem, NULL); + + initNetMuliplayer(NET_GAME_TYPE_SERVER, NULL, atoi( getParamElse("--port", "2200") ) ); +} + +int getChoiceArenaId() +{ + return arenaId; +} + +int conflictSpace(int x1,int y1,int w1,int h1,int x2,int y2,int w2,int h2) +{ + return (x1<x2+w2 && x2<x1+w1 && y1<y2+h2 && y2<y1+h1); +} + +int isFreeSpace(int x, int y, int w, int h) +{ + if ( isConflictWithListTux(arena->listTux, x, y, w, h) )return 0; + if ( isConflictWithListWall(arena->listWall, x, y, w, h) )return 0; + if ( isConflictWithListShot(arena->listShot, x, y, w, h) )return 0; + if ( isConflictWithListItem(arena->listItem, x, y, w, h) )return 0; + if ( isConflictWithListTeleport(arena->listTeleport, x, y, w, h) )return 0; + if ( isConflictWithListPipe(arena->listPipe, x, y, w, h) )return 0; + + return 1; +} + +void findFreeSpace(int *x, int *y, int w, int h) +{ + int z_x; + int z_y; + + assert( x != NULL ); + assert( y != NULL ); + + do{ + z_x = random() % WINDOW_SIZE_X; + z_y = random() % (WINDOW_SIZE_Y-200); + }while( isFreeSpace(z_x, z_y ,w ,h) == 0 ); + + *x = z_x; + *y = z_y; +} + +void eventPublicServer() +{ + eventConflictTuxWithTeleport(arena->listTux, arena->listTeleport); + eventConflictTuxWithShot(arena->listTux, arena->listShot); + + eventConflictShotWithWall(arena->listWall, arena->listShot); + eventConflictShotWithTeleport(arena->listTeleport, arena->listShot); + eventConflictShotWithPipe(arena->listPipe, arena->listShot); + eventConflictShotWithItem(arena->listItem, arena->listShot); + + eventMoveListShot(arena->listShot); + eventListItem(arena->listItem); + eventListTux(arena->listTux); + eventNetMultiplayer(); + + eventTimer(); +} + +void quitPublicServer() +{ + printf("quit public server\n"); + quitNetMultiplayer(); + destroyArena(arena); + quitTimer(); +} diff --git a/src/screen_table.c b/src/screen_table.c index c071572..2733859 100644 --- a/src/screen_table.c +++ b/src/screen_table.c @@ -1,5 +1,6 @@ #include <stdio.h> +#include <stdlib.h> #include <assert.h> #include "main.h" diff --git a/src/screen_world.c b/src/screen_world.c index fb9a559..7e63cd0 100644 --- a/src/screen_world.c +++ b/src/screen_world.c @@ -75,6 +75,7 @@ arena_t* getWorldArena() void setWorldArena(int id) { arena = getArena(id); + playMusic(arena->music, MUSIC_GROUP_USER); } void setMaxCountRound(int n) @@ -141,7 +142,6 @@ void prepareArena() case NET_GAME_TYPE_NONE : setWorldArena( getChoiceArenaId() ); addNewItem(arena->listItem, NULL); - playMusic(arena->music, MUSIC_GROUP_USER); getSettingCountRound(&max_count); tux = newTux(); @@ -158,7 +158,6 @@ void prepareArena() case NET_GAME_TYPE_SERVER : setWorldArena( getChoiceArenaId() ); addNewItem(arena->listItem, NULL); - playMusic(arena->music, MUSIC_GROUP_USER); getSettingCountRound(&max_count); tux = newTux(); diff --git a/src/server.c b/src/server.c index 92d5eae..6e3ec99 100644 --- a/src/server.c +++ b/src/server.c @@ -3,24 +3,32 @@ #include "tux.h" #include "network.h" #include "buffer.h" -#include "net_multiplayer.h" -#include "screen_world.h" #include "tcp.h" #include "udp.h" #include "proto.h" #include "server.h" #include "assert.h" +#include "myTimer.h" +#include "net_multiplayer.h" + +#ifndef BUBLIC_SERVER +#include "screen_world.h" +#endif + +#ifdef BUBLIC_SERVER +#include "publicServer.h" +#endif static int protocolType; static sock_tcp_t *sock_server_tcp; static sock_udp_t *sock_server_udp; static list_t *listClient; -static Uint32 lastSyncClient; +static my_time_t lastSyncClient; void static initServer() { listClient = newList(); - lastSyncClient = SDL_GetTicks(); + lastSyncClient = getMyTime(); } int initTcpServer(int port) @@ -70,7 +78,7 @@ static client_t* newAnyClient() new->buffer = newBuffer(LIMIT_BUFFER); new->tux = newTux(); new->tux->control = TUX_CONTROL_NET; - new->lastPing = SDL_GetTicks(); + new->lastPing = getMyTime(); addList(getWorldArena()->listTux, new->tux); return new; @@ -199,8 +207,10 @@ static void eventCreateClient(client_t *client) proto_send_init_server(client); +#ifndef BUBLIC_SERVER proto_send_newtux_server(client, (tux_t *)(getWorldArena()->listTux->list[SERVER_INDEX_ROOT_TUX]) ); +#endif for( i = 0 ; i < listClient->count; i++) { @@ -372,10 +382,10 @@ static client_t* findUdpClient(sock_udp_t *sock_udp) static void delZombieCLient() { client_t *thisClient; - Uint32 currentTime; + my_time_t currentTime; int i; - currentTime = SDL_GetTicks(); + currentTime = getMyTime(); for( i = 0 ; i < listClient->count; i++) { @@ -450,8 +460,15 @@ void selectServerUdpSocket() struct timeval tv; int max_fd; +#ifndef BUBLIC_SERVER tv.tv_sec = 0; tv.tv_usec = 0; +#endif + +#ifdef BUBLIC_SERVER + tv.tv_sec = 0; + tv.tv_usec = 50 * 1000; +#endif FD_ZERO(&readfds); FD_SET(sock_server_udp->sock, &readfds); @@ -469,25 +486,26 @@ void selectServerUdpSocket() void eventPeriodicSyncClient() { - Uint32 currentTime; + my_time_t currentTime; - currentTime = SDL_GetTicks(); + currentTime = getMyTime(); if( currentTime - lastSyncClient > SERVER_TIME_SYNC ) { client_t *thisClient; int i; +#ifndef BUBLIC_SERVER proto_send_newtux_server(NULL, (tux_t *)(getWorldArena()->listTux->list[SERVER_INDEX_ROOT_TUX])); - +#endif for( i = 0 ; i < listClient->count; i++) { thisClient = (client_t *) listClient->list[i]; proto_send_newtux_server(NULL, thisClient->tux); } - lastSyncClient = SDL_GetTicks(); + lastSyncClient = getMyTime(); } } @@ -4,15 +4,26 @@ #include "main.h" #include "shot.h" -#include "layer.h" -#include "image.h" #include "gun.h" + +#ifndef BUBLIC_SERVER +#include "image.h" #include "screen_world.h" +#include "layer.h" +#endif + +#ifdef BUBLIC_SERVER +#include "publicServer.h" +#endif + +#ifndef BUBLIC_SERVER static SDL_Surface *g_shot_simple; static SDL_Surface *g_shot_lasserX; static SDL_Surface *g_shot_lasserY; +#endif + static bool_t isShotInit = FALSE; bool_t isShotInicialized() @@ -22,12 +33,18 @@ bool_t isShotInicialized() void initShot() { +#ifndef BUBLIC_SERVER assert( isImageInicialized() == TRUE ); +#endif + +#ifndef BUBLIC_SERVER g_shot_simple = addImageData("shot.png", IMAGE_ALPHA, "shot", IMAGE_GROUP_BASE); g_shot_lasserX = addImageData("lasserX.png", IMAGE_NO_ALPHA, "lasserX", IMAGE_GROUP_BASE); g_shot_lasserY = addImageData("lasserY.png", IMAGE_NO_ALPHA, "lasserY", IMAGE_GROUP_BASE); +#endif + isShotInit = TRUE; } @@ -56,7 +73,9 @@ shot_t* newShot(int x,int y, int px, int py, int gun, tux_t *author) case GUN_SIMPLE : new->w = GUN_SHOT_WIDTH; new->h = GUN_SHOT_HEIGHT; +#ifndef BUBLIC_SERVER new->img = g_shot_simple; +#endif break; case GUN_LASSER : @@ -66,13 +85,17 @@ shot_t* newShot(int x,int y, int px, int py, int gun, tux_t *author) case TUX_LEFT : new->w = GUN_LASSER_HORIZONTAL; new->h = GUN_SHOT_VERTICAL; +#ifndef BUBLIC_SERVER new->img = g_shot_lasserX; +#endif break; case TUX_UP : case TUX_DOWN : new->w = GUN_SHOT_VERTICAL; new->h = GUN_LASSER_HORIZONTAL; +#ifndef BUBLIC_SERVER new->img = g_shot_lasserY; +#endif break; } break; @@ -85,6 +108,8 @@ shot_t* newShot(int x,int y, int px, int py, int gun, tux_t *author) return new; } +#ifndef BUBLIC_SERVER + void drawShot(shot_t *p) { assert( p != NULL ); @@ -106,6 +131,8 @@ void drawListShot(list_t *listShot) } } +#endif + int isConflictWithListShot(list_t *listShot, int x, int y, int w, int h) { shot_t *thisShot; @@ -171,13 +198,17 @@ static void eventOnlyLasser(shot_t *shot) case TUX_LEFT : shot->w = GUN_LASSER_HORIZONTAL; shot->h = GUN_SHOT_VERTICAL; +#ifndef BUBLIC_SERVER shot->img = g_shot_lasserX; +#endif break; case TUX_UP : case TUX_DOWN : shot->w = GUN_SHOT_VERTICAL; shot->h = GUN_LASSER_HORIZONTAL; +#ifndef BUBLIC_SERVER shot->img = g_shot_lasserY; +#endif break; } } diff --git a/src/teleport.c b/src/teleport.c index f0d9c57..776d7c7 100644 --- a/src/teleport.c +++ b/src/teleport.c @@ -2,18 +2,35 @@ #include <stdlib.h> #include <assert.h> +#include "main.h" #include "tux.h" #include "teleport.h" +#include "shot.h" +#include "sound.h" + +#ifndef BUBLIC_SERVER #include "layer.h" #include "screen_world.h" -#include "shot.h" #include "sound.h" +#endif + +#ifdef BUBLIC_SERVER +#include "publicServer.h" +#endif +#ifndef BUBLIC_SERVER teleport_t* newTeleport(int x, int y, int w, int h, int layer, SDL_Surface *img) +#endif + +#ifdef BUBLIC_SERVER +teleport_t* newTeleport(int x, int y, int w, int h, int layer) +#endif { teleport_t *new; +#ifndef BUBLIC_SERVER assert( img != NULL ); +#endif new = malloc( sizeof(teleport_t) ); assert( new != NULL ); @@ -23,11 +40,14 @@ teleport_t* newTeleport(int x, int y, int w, int h, int layer, SDL_Surface *img) new->w = w; new->h = h; new->layer = layer; +#ifndef BUBLIC_SERVER new->img = img; - +#endif return new; } +#ifndef BUBLIC_SERVER + void drawTeleport(teleport_t *p) { assert( p != NULL ); @@ -50,6 +70,8 @@ void drawListTeleport(list_t *listTeleport) } } +#endif + teleport_t* isConflictWithListTeleport(list_t *listTeleport, int x, int y, int w, int h) { teleport_t *thisTeleport; @@ -185,7 +207,9 @@ void eventTeleportTux(list_t *listTeleport, teleport_t *teleport, tux_t *tux) if( isFreeSpace(dist_x, dist_y, TUX_WIDTH, TUX_HEIGHT) ) { setTuxProportion(tux, dist_x, dist_y); +#ifndef BUBLIC_SERVER playSound("teleport", SOUND_GROUP_BASE); +#endif } } @@ -6,10 +6,6 @@ #include "main.h" #include "tux.h" -#include "image.h" -#include "sound.h" -#include "layer.h" -#include "screen_world.h" #include "shot.h" #include "gun.h" #include "wall.h" @@ -22,12 +18,27 @@ #include "dynamicInt.h" #include "proto.h" +#ifndef BUBLIC_SERVER +#include "image.h" +#include "sound.h" +#include "layer.h" +#include "screen_world.h" +#endif + +#ifdef BUBLIC_SERVER +#include "publicServer.h" +#endif + +#ifndef BUBLIC_SERVER + static SDL_Surface *g_tux_up; static SDL_Surface *g_tux_right; static SDL_Surface *g_tux_left; static SDL_Surface *g_tux_down; static SDL_Surface *g_cross; +#endif + static bool_t isTuxInit = FALSE; bool_t isTuxInicialized() @@ -37,13 +48,17 @@ bool_t isTuxInicialized() void initTux() { +#ifndef BUBLIC_SERVER assert( isImageInicialized() == TRUE ); +#endif +#ifndef BUBLIC_SERVER g_tux_up = addImageData("tux8.png", IMAGE_ALPHA, "tux8", IMAGE_GROUP_BASE); g_tux_right = addImageData("tux6.png", IMAGE_ALPHA, "tux6", IMAGE_GROUP_BASE); g_tux_left = addImageData("tux4.png", IMAGE_ALPHA, "tux4", IMAGE_GROUP_BASE); g_tux_down = addImageData("tux2.png", IMAGE_ALPHA, "tux2", IMAGE_GROUP_BASE); g_cross = addImageData("cross.png", IMAGE_ALPHA, "cross", IMAGE_GROUP_BASE); +#endif isTuxInit = TRUE; } @@ -131,6 +146,8 @@ void getCourse(int n, int *x, int *y) } } +#ifndef BUBLIC_SERVER + void drawTux(tux_t *tux) { SDL_Surface *g_image = NULL; @@ -202,6 +219,8 @@ void drawListTux(list_t *listTux) } } +#endif + tux_t* getTuxID(list_t *listTux, int id) { tux_t *thisTux; @@ -346,7 +365,9 @@ void eventTuxIsDead(tux_t *tux) return; } - playSound("dead", SOUND_GROUP_BASE); +#ifndef BUBLIC_SERVER + playSound("dead", SOUND_GROUP_BASE); +#endif printf("tux id %d is dead\n", tux->id); tux->status = TUX_STATUS_DEAD; @@ -389,7 +410,9 @@ void tuxTeleport(tux_t *tux) { int x, y; +#ifndef BUBLIC_SERVER playSound("teleport", SOUND_GROUP_BASE); +#endif printf("tux id %d teleporting\n", tux->id); if( getNetTypeGame() != NET_GAME_TYPE_CLIENT ) @@ -551,8 +574,9 @@ void switchTuxGun(tux_t *tux) return; } +#ifndef BUBLIC_SERVER playSound("switch_gun", SOUND_GROUP_BASE); - +#endif for( i = tux->gun+1 ; i < GUN_COUNT ; i++ ) { if( tux->shot[i] > 0 ) @@ -599,6 +623,11 @@ void shotTux(tux_t *tux) void actionTux(tux_t *tux, int action) { + if( tux->status != TUX_STATUS_ALIVE ) + { + return; + } + switch( action ) { case TUX_UP : @@ -678,7 +707,9 @@ void eventListTux(list_t *listTux) thisTux = (tux_t *)listTux->list[i]; assert( thisTux != NULL ); +#ifndef BUBLIC_SERVER tuxControl(thisTux); +#endif pickUpGun(thisTux); eventBonus(thisTux); eventGiveTuxItem(thisTux, getWorldArena()->listItem); @@ -2,18 +2,34 @@ #include <stdlib.h> #include <assert.h> +#include "main.h" #include "wall.h" +#include "shot.h" + +#ifndef BUBLIC_SERVER #include "layer.h" #include "screen_world.h" -#include "shot.h" +#endif +#ifdef BUBLIC_SERVER +#include "publicServer.h" +#endif + +#ifndef BUBLIC_SERVER wall_t* newWall(int x, int y, int w, int h, int img_x, int img_y, int layer, SDL_Surface *img) +#endif + +#ifdef BUBLIC_SERVER +wall_t* newWall(int x, int y, int w, int h, + int img_x, int img_y, int layer) +#endif { wall_t *new; +#ifndef BUBLIC_SERVER assert( img != NULL ); - +#endif new = malloc( sizeof(wall_t) ); assert( new != NULL ); @@ -24,11 +40,15 @@ wall_t* newWall(int x, int y, int w, int h, new->img_x = img_x; new->img_y = img_y; new->layer = layer; +#ifndef BUBLIC_SERVER new->img = img; +#endif return new; } +#ifndef BUBLIC_SERVER + void drawWall(wall_t *p) { assert( p != NULL ); @@ -51,6 +71,8 @@ void drawListWall(list_t *listWall) } } +#endif + int isConflictWithListWall(list_t *listWall, int x, int y, int w, int h) { wall_t *thisWall; |