diff options
| author | xHire <xhire@tuxportal.cz> | 2009-05-26 00:44:42 +0200 |
|---|---|---|
| committer | xHire <xhire@tuxportal.cz> | 2009-05-26 01:12:04 +0200 |
| commit | 409083e69d4bb9d8b1eb492b3474c86e093f2de8 (patch) | |
| tree | 741e3214c07578cde88e700895f203706284017c | |
| parent | b992c007c186fddf31f67a7ed0bd5789cfb9b85e (diff) | |
Rewritten messages/comments in code of base
Rectified the coding style in code of base
| -rw-r--r-- | src/base/archive.c | 28 | ||||
| -rw-r--r-- | src/base/arena.c | 93 | ||||
| -rw-r--r-- | src/base/arenaFile.c | 155 | ||||
| -rw-r--r-- | src/base/buffer.c | 33 | ||||
| -rw-r--r-- | src/base/checkFront.c | 16 | ||||
| -rw-r--r-- | src/base/director.c | 15 | ||||
| -rw-r--r-- | src/base/downServer.c | 104 | ||||
| -rw-r--r-- | src/base/gun.c | 117 | ||||
| -rw-r--r-- | src/base/homeDirector.c | 16 | ||||
| -rw-r--r-- | src/base/idManager.c | 35 | ||||
| -rw-r--r-- | src/base/index.c | 55 | ||||
| -rw-r--r-- | src/base/item.c | 189 | ||||
| -rw-r--r-- | src/base/list.c | 52 | ||||
| -rw-r--r-- | src/base/main.c | 70 | ||||
| -rw-r--r-- | src/base/modules.c | 96 | ||||
| -rw-r--r-- | src/base/myTimer.c | 42 | ||||
| -rw-r--r-- | src/base/net_multiplayer.c | 119 | ||||
| -rw-r--r-- | src/base/protect.c | 34 | ||||
| -rw-r--r-- | src/base/proto.c | 321 | ||||
| -rw-r--r-- | src/base/server.c | 85 | ||||
| -rw-r--r-- | src/base/serverSelect.c | 39 | ||||
| -rw-r--r-- | src/base/serverSendMsg.c | 37 | ||||
| -rw-r--r-- | src/base/shareFunction.c | 8 | ||||
| -rw-r--r-- | src/base/shot.c | 115 | ||||
| -rw-r--r-- | src/base/space.c | 48 | ||||
| -rw-r--r-- | src/base/storage.c | 18 | ||||
| -rw-r--r-- | src/base/textFile.c | 29 | ||||
| -rw-r--r-- | src/base/tux.c | 188 | ||||
| -rw-r--r-- | src/base/udp_server.c | 66 |
29 files changed, 1100 insertions, 1123 deletions
diff --git a/src/base/archive.c b/src/base/archive.c index 6aa6254..30956a0 100644 --- a/src/base/archive.c +++ b/src/base/archive.c @@ -1,10 +1,10 @@ - #include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> #include <zip.h> +#include "main.h" #include "archive.h" #define ARCHIVE_BUFFER_SIZE 4096 @@ -22,30 +22,27 @@ char *archive_extract_file(char *archive, char *filename) int len; int err; - sprintf(name, "/tmp/tuxanci%d-%s", getpid(), filename); + sprintf(name, "/tmp/tuxanci.%d-%s", getpid(), filename); - //printf("ARCHIVE %s %s %s\n", archive, filename, name); + /*printf("ARCHIVE %s %s %s\n", archive, filename, name);*/ zipArchive = zip_open(archive, 0, &err); - if( zipArchive == NULL ) - { - fprintf(stderr, "Archive not open !\n"); + if (zipArchive == NULL) { + fprintf(stderr, _("[Error] Unable to open archive [%s]\n"), archive); return NULL; } zipFile = zip_fopen(zipArchive, filename, ZIP_FL_UNCHANGED); - if( zipFile == NULL ) - { - fprintf(stderr, "File from archive not open !\n"); + if (zipFile == NULL) { + fprintf(stderr, _("[Error] Unable to extract the file [%s] from archive [%s]\n"), filename, archive); zip_close(zipArchive); return NULL; } - if( (file = fopen(name, "wb") ) == NULL) - { - fprintf(stderr, "No do not create temp file %s\n", name); + if ((file = fopen(name, "wb")) == NULL) { + fprintf(stderr, _("[Error] Unable to create temporary file [%s]\n"), name); zip_fclose(zipFile); zip_close(zipArchive); return NULL; @@ -53,13 +50,12 @@ char *archive_extract_file(char *archive, char *filename) do { len = zip_fread(zipFile, buf, ARCHIVE_BUFFER_SIZE); - //printf("len = %d\n", len); + /*printf("len = %d\n", len);*/ - if( len > 0 ) - { + if (len > 0) { fwrite(buf, len, 1, file); } - } while( len > 0 ); + } while (len > 0); fclose(file); zip_fclose(zipFile); diff --git a/src/base/arena.c b/src/base/arena.c index a692830..e26eb6c 100644 --- a/src/base/arena.c +++ b/src/base/arena.c @@ -1,4 +1,3 @@ - #include <stdlib.h> #include <assert.h> #include <string.h> @@ -13,17 +12,17 @@ #include "modules.h" #ifndef PUBLIC_SERVER -# include "hotKey.h" -# include "world.h" -# include "setting.h" -# include "layer.h" -#endif +#include "hotKey.h" +#include "world.h" +#include "setting.h" +#include "layer.h" +#endif /* PUBLIC_SERVER */ static arena_t *currentArena; static int splitType; #ifndef PUBLIC_SERVER -static int isBigArena(arena_t * arena) +static int isBigArena(arena_t *arena) { if (arena->w > WINDOW_SIZE_X || arena->h > WINDOW_SIZE_Y) { return 1; @@ -32,7 +31,7 @@ static int isBigArena(arena_t * arena) } } -static int isTuxNear(tux_t * tux1, tux_t * tux2) +static int isTuxNear(tux_t *tux1, tux_t *tux2) { if (abs(tux1->x - tux2->x) < WINDOW_SIZE_X && abs(tux1->y - tux2->y) < WINDOW_SIZE_Y) { @@ -41,9 +40,9 @@ static int isTuxNear(tux_t * tux1, tux_t * tux2) return 0; } -#endif +#endif /* PUBLIC_SERVER */ -void arena_set_current(arena_t * p) +void arena_set_current(arena_t *p) { currentArena = p; } @@ -69,12 +68,12 @@ void arena_init() if (getParam("--split-vertical")) { splitType = SCREEN_SPLIT_VERTICAL; - printf("SCREEN_SPLIT_VERTICAL\n"); + printf(_("[Debug] Set vertical screen splitting\n")); } if (getParam("--split-horizontal")) { splitType = SCREEN_SPLIT_HORIZONTAL; - printf("SCREEN_SPLIT_HORIZONTAL\n"); + printf(_("[Debug] Set horizontal screen splitting\n")); } hot_key_register(SDLK_F3, hotkey_splitArena); @@ -84,7 +83,7 @@ void arena_quit() { hot_key_unregister(SDLK_F3); } -#endif +#endif /* PUBLIC_SERVER */ arena_t *arena_new(int w, int h) { @@ -96,7 +95,7 @@ arena_t *arena_new(int w, int h) #ifndef PUBLIC_SERVER new->background = NULL; strcpy(new->music, ""); -#endif +#endif /* PUBLIC_SERVER */ new->w = w; new->h = h; @@ -121,37 +120,41 @@ arena_t *arena_new(int w, int h) return new; } -int -arena_conflict_space(int x1, int y1, int w1, int h1, int x2, int y2, int w2, int h2) +int arena_conflict_space(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 arena_is_free_space(arena_t * arena, int x, int y, int w, int h) +int arena_is_free_space(arena_t *arena, int x, int y, int w, int h) { if (x < 0 || y < 0 || x + w > arena->w || y + h > arena->h) { return 0; } - if (space_is_conflict_with_object(arena->spaceTux, x, y, w, h)) + if (space_is_conflict_with_object(arena->spaceTux, x, y, w, h)) { return 0; + } - if (space_is_conflict_with_object(arena->spaceShot, x, y, w, h)) + if (space_is_conflict_with_object(arena->spaceShot, x, y, w, h)) { return 0; + } - if (space_is_conflict_with_object(arena->spaceItem, x, y, w, h)) + if (space_is_conflict_with_object(arena->spaceItem, x, y, w, h)) { return 0; + } - if (space_is_conflict_with_object(arena->spaceShot, x, y, w, h)) + if (space_is_conflict_with_object(arena->spaceShot, x, y, w, h)) { return 0; + } - if (module_is_conflict(x, y, w, h)) + if (module_is_conflict(x, y, w, h)) { return 0; + } return 1; } -void arena_find_free_space(arena_t * arena, int *x, int *y, int w, int h) +void arena_find_free_space(arena_t *arena, int *x, int *y, int w, int h) { int z_x; int z_y; @@ -195,24 +198,22 @@ void arena_get_center_screen(int *screen_x, int *screen_y, int x, int y, int scr } #ifndef PUBLIC_SERVER - -static void drawBackground(arena_t * arena, int screen_x, int screen_y) +static void drawBackground(arena_t *arena, int screen_x, int screen_y) { - if (isBigArena(arena)) { int i, j; for (i = screen_y / arena->background->h; - i <= screen_y / arena->background->h + WINDOW_SIZE_Y / arena->background->h + 1; 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 + 1; j++) { - + j <= screen_x / arena->background->w + WINDOW_SIZE_X / arena->background->w + 1; + j++) { addLayer(arena->background, j * arena->background->w, i * arena->background->h, 0, 0, arena->background->w, arena->background->h, -100); - //count++; + /*count++;*/ } } } else { @@ -220,7 +221,7 @@ static void drawBackground(arena_t * arena, int screen_x, int screen_y) } } -static void action_tux_draw(space_t * space, tux_t * tux, void *p) +static void action_tux_draw(space_t *space, tux_t *tux, void *p) { UNUSED(space); UNUSED(p); @@ -228,7 +229,7 @@ static void action_tux_draw(space_t * space, tux_t * tux, void *p) tux_draw(tux); } -static void action_item_draw(space_t * space, item_t * item, void *p) +static void action_item_draw(space_t *space, item_t *item, void *p) { UNUSED(space); UNUSED(p); @@ -236,7 +237,7 @@ static void action_item_draw(space_t * space, item_t * item, void *p) item_draw(item); } -static void action_shot_draw(space_t * space, shot_t * shot, void *p) +static void action_shot_draw(space_t *space, shot_t *shot, void *p) { UNUSED(space); UNUSED(p); @@ -244,7 +245,7 @@ static void action_shot_draw(space_t * space, shot_t * shot, void *p) shot_draw(shot); } -static void drawObjects(arena_t * arena, int screen_x, int screen_y) +static void drawObjects(arena_t *arena, int screen_x, int screen_y) { space_action_from_location(arena->spaceTux, action_tux_draw, NULL, screen_x, screen_y, WINDOW_SIZE_X, WINDOW_SIZE_Y); space_action_from_location(arena->spaceItem, action_item_draw, NULL, screen_x, screen_y, WINDOW_SIZE_X, WINDOW_SIZE_Y); @@ -253,7 +254,7 @@ static void drawObjects(arena_t * arena, int screen_x, int screen_y) module_draw(screen_x, screen_y, WINDOW_SIZE_X, WINDOW_SIZE_Y); } -static void drawSplitArenaForTux(arena_t * arena, tux_t * tux, int location_x, int location_y) +static void drawSplitArenaForTux(arena_t *arena, tux_t *tux, int location_x, int location_y) { int screen_x, screen_y; @@ -267,7 +268,7 @@ static void drawSplitArenaForTux(arena_t * arena, tux_t * tux, int location_x, i default: screen_x = -1; screen_y = -1; - assert(!"stupd error "); + assert(!_("[Error] Unknown method of splitting the screen")); break; } @@ -284,12 +285,12 @@ static void drawSplitArenaForTux(arena_t * arena, tux_t * tux, int location_x, i default: screen_x = -1; screen_y = -1; - assert(!"stupd error "); + assert(!_("[Error] Unknown method of splitting the screen")); break; } } -void drawSplitArena(arena_t * arena) +void drawSplitArena(arena_t *arena) { tux_t *tux = NULL; @@ -313,7 +314,7 @@ void drawSplitArena(arena_t * arena) } } -void drawCenterArena(arena_t * arena, int x, int y) +void drawCenterArena(arena_t *arena, int x, int y) { int screen_x, screen_y; @@ -323,7 +324,7 @@ void drawCenterArena(arena_t * arena, int x, int y) layer_draw_center(x, y); } -void drawSimpleArena(arena_t * arena) +void drawSimpleArena(arena_t *arena) { int screen_x, screen_y; tux_t *tux = NULL; @@ -342,7 +343,7 @@ void drawSimpleArena(arena_t * arena) layer_draw_all(tux->x, tux->y); } -void arena_draw(arena_t * arena) +void arena_draw(arena_t *arena) { if (isBigArena(arena) && net_multiplayer_get_game_type() == NET_GAME_TYPE_NONE && !setting_is_ai()) { @@ -377,9 +378,9 @@ void arena_draw(arena_t * arena) drawSimpleArena(arena); } -#endif +#endif /* PUBLIC_SERVER */ -static void action_tux(space_t * space, tux_t * tux, void *p) +static void action_tux(space_t *space, tux_t *tux, void *p) { UNUSED(space); UNUSED(p); @@ -387,7 +388,7 @@ static void action_tux(space_t * space, tux_t * tux, void *p) tux_event(tux); } -void arena_event(arena_t * arena) +void arena_event(arena_t *arena) { int i; @@ -408,7 +409,7 @@ void arena_event(arena_t * arena) timer_event(arena->listTimer); } -void arena_destroy(arena_t * p) +void arena_destroy(arena_t *p) { space_destroy_with_item(p->spaceTux, tux_destroy); space_destroy_with_item(p->spaceItem, item_destroy); diff --git a/src/base/arenaFile.c b/src/base/arenaFile.c index 45ba4ac..da2d09f 100644 --- a/src/base/arenaFile.c +++ b/src/base/arenaFile.c @@ -1,4 +1,3 @@ - #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -18,13 +17,13 @@ #include "homeDirector.h" #ifndef PUBLIC_SERVER -# include "configFile.h" -# include "image.h" -#endif +#include "configFile.h" +#include "image.h" +#endif /* PUBLIC_SERVER */ #ifndef NO_SOUND -# include "music.h" -#endif +#include "music.h" +#endif /* NO_SOUND */ static list_t *listArenaFile; static bool_t isArenaFileInit = FALSE; @@ -47,23 +46,27 @@ int arena_file_get_value(char *line, char *env, char *val, int len) offset_env = strstr(line, clone_env); - if (offset_env == NULL) + if (offset_env == NULL) { return -1; + } offset_val_begin = strchr(offset_env, '"'); - if (offset_val_begin == NULL) + if (offset_val_begin == NULL) { return -1; + } offset_val_end = strchr(offset_val_begin + 1, '"'); - if (offset_val_end == NULL) + if (offset_val_end == NULL) { return -1; + } val_len = (int) (offset_val_end - (offset_val_begin + 1)); - if (val_len > len - 1) + if (val_len > len - 1) { val_len = len - 1; + } memset(val, 0, len); memcpy(val, offset_val_begin + 1, val_len); @@ -73,7 +76,7 @@ int arena_file_get_value(char *line, char *env, char *val, int len) #ifndef PUBLIC_SERVER -image_t *arena_file_load_image(arenaFile_t * arenaFile, char *filename, char *group, char *name, int alpha) +image_t *arena_file_load_image(arenaFile_t *arenaFile, char *filename, char *group, char *name, int alpha) { char *extractFile; image_t *image; @@ -86,7 +89,7 @@ image_t *arena_file_load_image(arenaFile_t * arenaFile, char *filename, char *gr } #ifndef NO_SOUND -void loadMusicFromArena(arenaFile_t * arenaFile, char *filename, char *group, char *name) +void loadMusicFromArena(arenaFile_t *arenaFile, char *filename, char *group, char *name) { char *extractFile; @@ -94,102 +97,113 @@ void loadMusicFromArena(arenaFile_t * arenaFile, char *filename, char *group, ch music_add(extractFile, name, group); archive_delete_file(extractFile); } -#endif -#endif +#endif /* NO_SOUND */ +#endif /* PUBLIC_SERVER */ -static void cmd_arena(arena_t ** arena, char *line) +static void cmd_arena(arena_t **arena, char *line) { char str_image[STR_SIZE]; char str_w[STR_SIZE]; char str_h[STR_SIZE]; - if (arena_file_get_value(line, "background", str_image, STR_SIZE) != 0) + if (arena_file_get_value(line, "background", str_image, STR_SIZE) != 0) { return; + } - if (arena_file_get_value(line, "w", str_w, STR_SIZE) != 0) + if (arena_file_get_value(line, "w", str_w, STR_SIZE) != 0) { return; + } - if (arena_file_get_value(line, "h", str_h, STR_SIZE) != 0) + if (arena_file_get_value(line, "h", str_h, STR_SIZE) != 0) { return; + } (*arena) = arena_new(atoi(str_w), atoi(str_h)); #ifndef PUBLIC_SERVER (*arena)->background = image_get(IMAGE_GROUP_USER, str_image); -#endif - //(*arena)->w = atoi(str_w); - //(*arena)->h = atoi(str_h); +#endif /* PUBLIC_SERVER */ + /* + (*arena)->w = atoi(str_w); + (*arena)->h = atoi(str_h); + */ arena_set_current(*arena); - DEBUG_MSG(_("Loaded new arena...\n")); + DEBUG_MSG(_("[Debug] Arena loaded\n")); } static void cmd_module_load(char *line) { char str_file[STR_SIZE]; - if (arena_file_get_value(line, "file", str_file, STR_SIZE) != 0) + if (arena_file_get_value(line, "file", str_file, STR_SIZE) != 0) { return; + } module_load(str_file); } #ifndef PUBLIC_SERVER - -static void cmd_loadImage(arenaFile_t * arenaFile, char *line) +static void cmd_loadImage(arenaFile_t *arenaFile, char *line) { char str_file[STR_SIZE]; char str_name[STR_SIZE]; char str_alpha[STR_SIZE]; - if (arena_file_get_value(line, "file", str_file, STR_SIZE) != 0) + if (arena_file_get_value(line, "file", str_file, STR_SIZE) != 0) { return; + } - if (arena_file_get_value(line, "name", str_name, STR_SIZE) != 0) + if (arena_file_get_value(line, "name", str_name, STR_SIZE) != 0) { return; + } - if (arena_file_get_value(line, "alpha", str_alpha, STR_SIZE) != 0) + if (arena_file_get_value(line, "alpha", str_alpha, STR_SIZE) != 0) { return; + } - //printf("str_file=%s str_name=%s str_alpha=%s\n", str_file, str_name, str_alpha); + /*printf("str_file=%s str_name=%s str_alpha=%s\n", str_file, str_name, str_alpha);*/ arena_file_load_image(arenaFile, str_file, IMAGE_GROUP_USER, str_name, isYesOrNO(str_alpha)); - //image_add(str_file, isYesOrNO(str_alpha), str_name, IMAGE_GROUP_USER); + /*image_add(str_file, isYesOrNO(str_alpha), str_name, IMAGE_GROUP_USER);*/ } -static void cmd_loadMusic(arenaFile_t * arenaFile, char *line) +static void cmd_loadMusic(arenaFile_t *arenaFile, char *line) { char str_file[STR_SIZE]; char str_name[STR_SIZE]; - if (arena_file_get_value(line, "file", str_file, STR_SIZE) != 0) + if (arena_file_get_value(line, "file", str_file, STR_SIZE) != 0) { return; + } - if (arena_file_get_value(line, "name", str_name, STR_SIZE) != 0) + if (arena_file_get_value(line, "name", str_name, STR_SIZE) != 0) { return; + } #ifndef NO_SOUND - //music_add(str_file, str_name, MUSIC_GROUP_USER); + /*music_add(str_file, str_name, MUSIC_GROUP_USER);*/ loadMusicFromArena(arenaFile, str_file, MUSIC_GROUP_USER, str_name); -#endif +#endif /* NO_SOUND */ } -static void cmd_music_play(arena_t * arena, char *line) +static void cmd_music_play(arena_t *arena, char *line) { char str_music[STR_SIZE]; - if (arena_file_get_value(line, "music", str_music, STR_SIZE) != 0) + if (arena_file_get_value(line, "music", str_music, STR_SIZE) != 0) { return; + } strcpy(arena->music, str_music); } -#endif +#endif /* PUBLIC_SERVER */ int arena_file_get_count() { return listArenaFile->count; } -static char *arena_file_get_status(textFile_t * ts, char *s) +static char *arena_file_get_status(textFile_t *ts, char *s) { int len; int i; @@ -201,14 +215,15 @@ static char *arena_file_get_status(textFile_t * ts, char *s) line = (char *) (ts->text->list[i]); - if (strncmp(line, s, len) == 0) + if (strncmp(line, s, len) == 0) { return line + len + 1; + } } return NULL; } -char *arena_file_get_name(arenaFile_t * arenaFile) +char *arena_file_get_name(arenaFile_t *arenaFile) { char *ret; @@ -216,7 +231,7 @@ char *arena_file_get_name(arenaFile_t * arenaFile) return (ret != NULL ? ret : "arena_no_name"); } -char *arena_file_get_net_name(arenaFile_t * arenaFile) +char *arena_file_get_net_name(arenaFile_t *arenaFile) { char *ret; @@ -233,14 +248,15 @@ arenaFile_t *arena_file_get_file_format_net_name(char *s) arenaFile = (arenaFile_t *) listArenaFile->list[i]; - if (strcmp(arena_file_get_net_name(arenaFile), s) == 0) + if (strcmp(arena_file_get_net_name(arenaFile), s) == 0) { return arenaFile; + } } return NULL; } -char *arena_file_get_image(arenaFile_t * arenaFile) +char *arena_file_get_image(arenaFile_t *arenaFile) { return arena_file_get_status(arenaFile->map, "screen"); } @@ -250,7 +266,7 @@ arenaFile_t *arena_file_get(int n) return (arenaFile_t *) listArenaFile->list[n]; } -int arena_file_get_id(arenaFile_t * arenaFile) +int arena_file_get_id(arenaFile_t *arenaFile) { int i; @@ -267,10 +283,10 @@ int arena_file_get_id(arenaFile_t * arenaFile) return -1; } -arena_t *arena_file_get_arena(arenaFile_t * arenaFile) +arena_t *arena_file_get_arena(arenaFile_t *arenaFile) { textFile_t *ts; - arena_t *arena = NULL; // no warninng + arena_t *arena = NULL; /* no warnings */ int i; ts = (textFile_t *) arenaFile->map; @@ -278,24 +294,29 @@ arena_t *arena_file_get_arena(arenaFile_t * arenaFile) for (i = 0; i < ts->text->count; i++) { char *line; - line = (char *) (ts->text->list[i]); + line = (char *) ts->text->list[i]; module_cmd(line); #ifndef PUBLIC_SERVER - if (strncmp(line, "loadImage", 9) == 0) + if (strncmp(line, "loadImage", 9) == 0) { cmd_loadImage(arenaFile, line); + } - if (strncmp(line, "loadMusic", 9) == 0) + if (strncmp(line, "loadMusic", 9) == 0) { cmd_loadMusic(arenaFile, line); + } - if (strncmp(line, "playMusic", 9) == 0) + if (strncmp(line, "playMusic", 9) == 0) { cmd_music_play(arena, line); + } +#endif /* PUBLIC_SERVER */ -#endif - if (strncmp(line, "arena", 5) == 0) + if (strncmp(line, "arena", 5) == 0) { cmd_arena(&arena, line); + } - if (strncmp(line, "loadModule", 10) == 0) + if (strncmp(line, "loadModule", 10) == 0) { cmd_module_load(line); + } } return arena; @@ -316,7 +337,7 @@ arenaFile_t *arena_file_new(char *path) return new; } -void arena_destroyFile(arenaFile_t * p) +void arena_destroyFile(arenaFile_t *p) { text_file_destroy(p->map); free(p->path); @@ -333,38 +354,36 @@ static void load_arenaFromDirector(char *director) director_t *p; int i; - DEBUG_MSG(_("Loading arena files from %s\n"), director); + DEBUG_MSG(_("[Debug] Loading arena files [%s]\n"), director); p = director_load(director); - if (p==NULL) - { - fprintf(stderr, _("Directory %s not found !\n"), director); + if (p == NULL) { + fprintf(stderr, _("[Error] Directory not found [%s]\n"), director); exit(-1); } for (i = 0; i < p->list->count; i++) { char *line; - line = (char *) (p->list->list[i]); + line = (char *) p->list->list[i]; - if (strstr(line, ".zip") != NULL && strstr(line, "~")==NULL) { + if (strstr(line, ".zip") != NULL && strstr(line, "~") == NULL) { char path[STR_PATH_SIZE]; - if (director[strlen(director)-1]=='/') { + if (director[strlen(director)-1] == '/') { sprintf(path, "%s%s", director, line); - } - else { + } else { sprintf(path, "%s/%s", director, line); } - DEBUG_MSG(_("Loading arena: %s\n"), line); + DEBUG_MSG(_("[Debug] Loading arena [%s]\n"), line); accessExistFile(path); arena_file_load(path); } } - //printf("No. of Arens: %d\n", listArenaFile->count); + /*printf("No. of Arens: %d\n", listArenaFile->count);*/ director_destroy(p); } @@ -373,7 +392,7 @@ void arena_file_init() { #ifndef PUBLIC_SERVER assert(image_is_inicialized() == TRUE); -#endif +#endif /* PUBLIC_SERVER */ isArenaFileInit = TRUE; listArenaFile = list_new(); @@ -381,7 +400,7 @@ void arena_file_init() #ifndef PUBLIC_SERVER load_arenaFromDirector(home_director_get()); -#endif +#endif /* PUBLIC_SERVER */ } void arena_file_quit() diff --git a/src/base/buffer.c b/src/base/buffer.c index 04e77a5..2ecc148 100644 --- a/src/base/buffer.c +++ b/src/base/buffer.c @@ -1,4 +1,3 @@ - #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -19,17 +18,17 @@ buffer_t *buffer_new(int n) return new; } -void *buffer_get_data(buffer_t * p) +void *buffer_get_data(buffer_t *p) { return p->data; } -int buffer_get_size(buffer_t * p) +int buffer_get_size(buffer_t *p) { return p->size; } -int buffer_append(buffer_t * p, char *data, int len) +int buffer_append(buffer_t *p, char *data, int len) { assert(p != NULL); assert(data != NULL); @@ -44,7 +43,7 @@ int buffer_append(buffer_t * p, char *data, int len) return -1; } -int buffer_cut(buffer_t * p, int len) +int buffer_cut(buffer_t *p, int len) { assert(p != NULL); assert(len >= 0); @@ -58,7 +57,7 @@ int buffer_cut(buffer_t * p, int len) return -1; } -int buffer_count_line(buffer_t * p) +int buffer_count_line(buffer_t *p) { char *begin; char *end; @@ -77,12 +76,15 @@ int buffer_count_line(buffer_t * p) begin = end + 1; } - //printf("count = %d\n", count); - //printf("data = %s\n", p->data); + /* + printf("count = %d\n", count); + printf("data = %s\n", p->data); + */ + return count; } -int buffer_get_line(buffer_t * p, char *line, int len) +int buffer_get_line(buffer_t *p, char *line, int len) { char *end; int ret_len; @@ -95,12 +97,14 @@ int buffer_get_line(buffer_t * p, char *line, int len) end = memchr(p->data, '\n', p->size); - if (end == NULL) + if (end == NULL) { return -1; + } ret_len = (int) (end - p->data) + 1; - if (ret_len > len - 1) + if (ret_len > len - 1) { ret_len = len - 1; + } memset(line, 0, len); memcpy(line, p->data, ret_len); @@ -110,7 +114,7 @@ int buffer_get_line(buffer_t * p, char *line, int len) return ret_len; } -int buffer_get_data_len(buffer_t * p, char *line, int len) +int buffer_get_data_len(buffer_t *p, char *line, int len) { assert(p != NULL); assert(line != NULL); @@ -126,12 +130,13 @@ int buffer_get_data_len(buffer_t * p, char *line, int len) return len; } -void buffer_destroy(buffer_t * p) +void buffer_destroy(buffer_t *p) { assert(p != NULL); - if (p->data != NULL) + if (p->data != NULL) { free(p->data); + } free(p); } diff --git a/src/base/checkFront.c b/src/base/checkFront.c index 6c44580..a8218de 100644 --- a/src/base/checkFront.c +++ b/src/base/checkFront.c @@ -1,4 +1,3 @@ - #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -36,7 +35,7 @@ static checkfront_t *newCheck(char *s, int type, int id) return new; } -static void destroyCheck(checkfront_t * p) +static void destroyCheck(checkfront_t *p) { assert(p != NULL); free(p->msg); @@ -48,15 +47,16 @@ list_t *check_front_new() return list_new(); } -void check_front_msg_add(list_t * list, char *msg, int type, int id) +void check_front_msg_add(list_t *list, char *msg, int type, int id) { - if (type == CHECK_FRONT_TYPE_CHECK) + if (type == CHECK_FRONT_TYPE_CHECK) { id_inc(id); + } list_add(list, newCheck(msg, type, id)); } -void check_front_event(client_t * client) +void check_front_event(client_t *client) { my_time_t currentTime; int i; @@ -87,13 +87,13 @@ void check_front_event(client_t * client) } break; default: - assert(!_("Bad type of front!")); + assert(!_("[Error] Wrong type of the event front")); break; } } } -void check_front_del_msg(list_t * listCheckFront, int id) +void check_front_del_msg(list_t *listCheckFront, int id) { int i; @@ -110,7 +110,7 @@ void check_front_del_msg(list_t * listCheckFront, int id) } } -void check_front_destroy(list_t * p) +void check_front_destroy(list_t *p) { assert(p != NULL); list_destroy_item(p, destroyCheck); diff --git a/src/base/director.c b/src/base/director.c index 2e6a24a..66cef0c 100644 --- a/src/base/director.c +++ b/src/base/director.c @@ -1,4 +1,3 @@ - #include <dirent.h> #include <sys/types.h> #include <stdlib.h> @@ -30,14 +29,13 @@ director_t *director_load(char *s) new->list = list_new(); #ifndef __WIN32__ - if (s[0] == '/') + if (s[0] == '/') { #else - if (s[1] == ':') + if (s[1] == ':') { #endif strcpy(path, s); - - else { - // this is really correct aproach + } else { + /* this is really correct aproach */ getcwd(path, STR_PATH_SIZE); strcat(path, "/"); strcat(path, s); @@ -52,15 +50,16 @@ director_t *director_load(char *s) return NULL; } - while ((item = readdir(dir)) != NULL) + while ((item = readdir(dir)) != NULL) { list_add(new->list, strdup(item->d_name)); + } closedir(dir); return new; } -void director_destroy(director_t * p) +void director_destroy(director_t *p) { assert(p != NULL); diff --git a/src/base/downServer.c b/src/base/downServer.c index 13bd0ab..3015214 100644 --- a/src/base/downServer.c +++ b/src/base/downServer.c @@ -1,4 +1,3 @@ - #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -26,14 +25,13 @@ #define DOWN_SERVER_LIMIT_BUFFER 10240 #define DOWN_SERVER_SEND_FILE_BUFFER 4096 -#define NET_STATUS_OK 0 -#define NET_STATUS_ZOMBIE 1 +#define NET_STATUS_OK 0 +#define NET_STATUS_ZOMBIE 1 static sock_tcp_t *sock_server_tcp; static list_t *listClient; -typedef struct client_down_server_struct -{ +typedef struct client_down_server_struct { int status_connect; sock_tcp_t *sock; buffer_t *recvBuffer; @@ -48,8 +46,7 @@ static int getFileSize(char *s) { struct stat buf; - if( lstat(s, &buf) < 0 ) - { + if (lstat(s, &buf) < 0) { return -1; } @@ -62,45 +59,42 @@ static void proto_getarena(client_ds_t *client, char *msg) char msg_out[STR_PROTO_SIZE]; char *arenaName; - arenaName = msg+9; + arenaName = msg + 9; - //printf("arena = >>%s<<\n", arenaName); + /*printf("arena = >>%s<<\n", arenaName);*/ arenaFile = arena_file_get_file_format_net_name(arenaName); - if( arenaFile == NULL ) - { - char *error_msg = _("ERR Arena not found !\n"); + if (arenaFile == NULL) { + char *error_msg = _("[Error] Arena not found\n"); buffer_append(client->sendBuffer, error_msg, strlen(error_msg)); return; } client->file = fopen(arenaFile->path, "rb"); - if( client->file == NULL ) - { - char *error_msg = _("ERR Server has a problem !\n"); + if (client->file == NULL) { + char *error_msg = _("[Error] Server has some problem\n"); buffer_append(client->sendBuffer, error_msg, strlen(error_msg)); return; } client->size = getFileSize(arenaFile->path); - sprintf(msg_out, "OK %d\n", client->size); + sprintf(msg_out, _("OK %d\n"), client->size); buffer_append(client->sendBuffer, msg_out, strlen(msg_out)); } static void do_proto(client_ds_t *client, char *msg) { - if( strncmp(msg, "GETARENA ", 9) == 0 && client->file == NULL ) - { + if (strncmp(msg, "GETARENA ", 9) == 0 && client->file == NULL) { proto_getarena(client, msg); } } -static client_ds_t* newClient(sock_tcp_t *sock) +static client_ds_t *newClient(sock_tcp_t *sock) { client_ds_t *new; - new = malloc( sizeof(client_ds_t) ); + new = malloc(sizeof(client_ds_t)); memset(new, 0, sizeof(client_ds_t)); new->status_connect = NET_STATUS_OK; @@ -117,8 +111,7 @@ static void destroyClient(client_ds_t *client) buffer_destroy(client->recvBuffer); buffer_destroy(client->sendBuffer); - if( client->file != NULL ) - { + if (client->file != NULL) { fclose(client->file); } @@ -129,9 +122,8 @@ int down_server_init(char *ip4, int port4) { sock_server_tcp = sock_tcp_bind(ip4, port4); - if( sock_server_tcp == NULL ) - { - fprintf(stderr, _("Unable to initialize download server!\n")); + if (sock_server_tcp == NULL) { + fprintf(stderr, _("[Error] Unable to initialize download server\n")); return -1; } @@ -148,16 +140,14 @@ int down_server_set_select() select_add_sock_for_read(sock_server_tcp->sock); - for( i = 0 ; i < listClient->count ; i++ ) - { + for (i = 0; i < listClient->count; i++) { client_ds_t *this; - this = (client_ds_t *)listClient->list[i]; + this = (client_ds_t *) listClient->list[i]; select_add_sock_for_read(this->sock->sock); - if( buffer_get_size(this->sendBuffer) > 0 ) - { + if (buffer_get_size(this->sendBuffer) > 0) { select_add_sock_for_write(this->sock->sock); } } @@ -177,7 +167,7 @@ static void eventNewClient(sock_tcp_t *sock_server) list_add(listClient, client); } -static void eventReadClient(client_ds_t * client) +static void eventReadClient(client_ds_t *client) { char buffer[STR_PROTO_SIZE]; int ret; @@ -185,33 +175,29 @@ static void eventReadClient(client_ds_t * client) memset(buffer, 0, STR_PROTO_SIZE); ret = sock_tcp_read(client->sock, buffer, STR_PROTO_SIZE - 1); - //printf("sock_tcp_read = %d\n", ret); + /*printf("sock_tcp_read = %d\n", ret);*/ - if( ret <= 0 ) - { + if (ret <= 0) { client->status_connect = NET_STATUS_ZOMBIE; return; } - if( buffer_append(client->recvBuffer, buffer, ret) < 0 ) - { + if (buffer_append(client->recvBuffer, buffer, ret) < 0) { client->status_connect = NET_STATUS_ZOMBIE; return; } - while( buffer_get_line(client->recvBuffer, buffer, STR_PROTO_SIZE) >= 0 ) - { + while (buffer_get_line(client->recvBuffer, buffer, STR_PROTO_SIZE) >= 0) { int len; len = strlen(buffer); - if( buffer[len-1] == '\n' ) - { - buffer[len-1] = '\0'; + if (buffer[len - 1] == '\n') { + buffer[len - 1] = '\0'; } do_proto(client, buffer); - //buffer_append(client->sendBuffer, buffer, strlen(buffer)); + /*buffer_append(client->sendBuffer, buffer, strlen(buffer));*/ } } @@ -223,18 +209,16 @@ static void eventWriteClient(client_ds_t *client) len = buffer_get_size(client->sendBuffer); - if( len == 0 ) - { + if (len == 0) { return; } data = buffer_get_data(client->sendBuffer); res = sock_tcp_write(client->sock, data, len); - //printf("sock_tcp_write = %d\n", res); + /*printf("sock_tcp_write = %d\n", res);*/ - if( res < 0 ) - { + if (res < 0) { client->status_connect = NET_STATUS_ZOMBIE; return; } @@ -249,13 +233,11 @@ static void sendFile(client_ds_t *client) count = client->size - client->send; - if( count > DOWN_SERVER_SEND_FILE_BUFFER ) - { + if (count > DOWN_SERVER_SEND_FILE_BUFFER) { count = DOWN_SERVER_SEND_FILE_BUFFER; } - if( fread(buffer, count, 1, client->file) != 1 ) - { + if (fread(buffer, count, 1, client->file) != 1) { client->status_connect = NET_STATUS_ZOMBIE; return; } @@ -268,34 +250,28 @@ int down_server_select_socket() { int i; - if( select_is_change_sock_for_read(sock_server_tcp->sock) ) - { + if (select_is_change_sock_for_read(sock_server_tcp->sock)) { eventNewClient(sock_server_tcp); } - for( i = 0 ; i < listClient->count ; i++ ) - { + for (i = 0; i < listClient->count; i++) { client_ds_t *this; - this = (client_ds_t *)listClient->list[i]; + this = (client_ds_t *) listClient->list[i]; - if( select_is_change_sock_for_read(this->sock->sock) ) - { + if (select_is_change_sock_for_read(this->sock->sock)) { eventReadClient(this); } - if( select_is_change_sock_for_write(this->sock->sock) ) - { + if (select_is_change_sock_for_write(this->sock->sock)) { eventWriteClient(this); } - if( this->file != NULL && buffer_get_size(this->sendBuffer) == 0 ) - { + if (this->file != NULL && buffer_get_size(this->sendBuffer) == 0) { sendFile(this); } - if( this->status_connect == NET_STATUS_ZOMBIE ) - { + if (this->status_connect == NET_STATUS_ZOMBIE) { list_del_item(listClient, i, destroyClient); } } diff --git a/src/base/gun.c b/src/base/gun.c index 6a4ed36..d0bfe86 100644 --- a/src/base/gun.c +++ b/src/base/gun.c @@ -1,4 +1,3 @@ - #include <stdio.h> #include <stdlib.h> #include <assert.h> @@ -15,15 +14,15 @@ #include "serverSendMsg.h" #ifndef NO_SOUND -# include "sound.h" -#endif +#include "sound.h" +#endif /* NO_SOUND */ + #ifndef PUBLIC_SERVER -# include "interface.h" -# include "world.h" -#endif -#ifdef PUBLIC_SERVER -# include "publicServer.h" -#endif +#include "interface.h" +#include "world.h" +#else /* PUBLIC_SERVER */ +#include "publicServer.h" +#endif /* PUBLIC_SERVER */ static void modificiationCopuse(int courser, int right_x, int right_y, int *dest_x, int *dest_y) { @@ -48,12 +47,12 @@ static void modificiationCopuse(int courser, int right_x, int right_y, int *dest *dest_y = right_x; break; default: - assert(!_("There is wrong value in course variable!")); + assert(!_("[Debug] Wrong Tux course change")); break; } } -static void addShotTrivial(tux_t * tux, int x, int y, int px, int py, int gun) +static void addShotTrivial(tux_t *tux, int x, int y, int px, int py, int gun) { int dest_x = 0, dest_y = 0; int dest_px = 0, dest_py = 0; @@ -62,7 +61,7 @@ static void addShotTrivial(tux_t * tux, int x, int y, int px, int py, int gun) modificiationCopuse(tux->position, px, py, &dest_px, &dest_py); modificiationCopuse(tux->position, x, y, &dest_x, &dest_y); - if (gun == GUN_LASSER) + if (gun == GUN_LASSER) { switch (tux->position) { case TUX_UP: dest_y -= GUN_LASSER_HORIZONTAL; @@ -75,24 +74,27 @@ static void addShotTrivial(tux_t * tux, int x, int y, int px, int py, int gun) case TUX_DOWN: break; } + } shot = shot_new(tux->x + dest_x, tux->y + dest_y, dest_px, dest_py, gun, tux->id); space_add(arena_get_current()->spaceShot, shot); } -static void addShot(tux_t * tux, int x, int y, int px, int py) +static void addShot(tux_t *tux, int x, int y, int px, int py) { int gun; - if (net_multiplayer_get_game_type() == NET_GAME_TYPE_CLIENT) + if (net_multiplayer_get_game_type() == NET_GAME_TYPE_CLIENT) { return; + } - if (tux->gun == GUN_BOMBBALL) + if (tux->gun == GUN_BOMBBALL) { gun = GUN_BOMBBALL; - else if (tux->gun == GUN_LASSER) + } else if (tux->gun == GUN_LASSER) { gun = GUN_LASSER; - else + } else { gun = GUN_SIMPLE; + } if (tux->bonus == BONUS_4X) { int zal; @@ -102,18 +104,18 @@ static void addShot(tux_t * tux, int x, int y, int px, int py) for (i = 0; i < 4; i++) { switch (i) { - case 0: - tux->position = TUX_UP; - break; - case 1: - tux->position = TUX_RIGHT; - break; - case 2: - tux->position = TUX_LEFT; - break; - case 3: - tux->position = TUX_DOWN; - break; + case 0: + tux->position = TUX_UP; + break; + case 1: + tux->position = TUX_RIGHT; + break; + case 2: + tux->position = TUX_LEFT; + break; + case 3: + tux->position = TUX_DOWN; + break; } addShotTrivial(tux, x, y, px, py, gun); @@ -125,23 +127,24 @@ static void addShot(tux_t * tux, int x, int y, int px, int py) } } -static void gun_shotSimpe(tux_t * tux) +static void gun_shotSimpe(tux_t *tux) { addShot(tux, 0, 0, +5, 0); } -static void gun_shotDualSimpe(tux_t * tux) +static void gun_shotDualSimpe(tux_t *tux) { addShot(tux, 0, -10, +6, 0); addShot(tux, 0, +10, +6, 0); } -static void gun_shotScatter(tux_t * tux) +static void gun_shotScatter(tux_t *tux) { int i; - for (i = -2; i <= +2; i++) + for (i = -2; i <= +2; i++) { addShot(tux, 0, 0, +8, i); + } } static void timer_addShotTimer(void *p) @@ -155,11 +158,13 @@ static void timer_addShotTimer(void *p) tux = space_get_object_id(arena_get_current()->spaceTux, id); - if (tux == NULL) + if (tux == NULL) { return; + } - if (tux->status != TUX_STATUS_ALIVE) + if (tux->status != TUX_STATUS_ALIVE) { return; + } gun = tux->gun; tux->gun = GUN_SIMPLE; @@ -167,13 +172,14 @@ static void timer_addShotTimer(void *p) tux->gun = gun; } -static void gun_shotTommy(tux_t * tux) +static void gun_shotTommy(tux_t *tux) { int i; - for (i = 0; i < 10; i++) + for (i = 0; i < 10; i++) { timer_add_task(arena_get_current()->listTimer, TIMER_ONE, timer_addShotTimer, newInt(tux->id), i * 100); + } } static void timer_addLaserTimer(void *p) @@ -187,31 +193,34 @@ static void timer_addLaserTimer(void *p) tux = space_get_object_id(arena_get_current()->spaceTux, id); - if (tux == NULL) + if (tux == NULL) { return; + } - if (tux->status != TUX_STATUS_ALIVE) + if (tux->status != TUX_STATUS_ALIVE) { return; + } gun = tux->gun; tux->gun = GUN_LASSER; addShot(tux, 0, 0, +10, 0); addShot(tux, +40, 0, +10, 0); - //addShot(tux, +40, 0, +10, 0); + /*addShot(tux, +40, 0, +10, 0);*/ tux->gun = gun; } -static void gun_shotLasser(tux_t * tux) +static void gun_shotLasser(tux_t *tux) { int i; - for (i = 0; i < 50; i++) + for (i = 0; i < 50; i++) { timer_add_task(arena_get_current()->listTimer, TIMER_ONE, timer_addLaserTimer, newInt(tux->id), i * 10); + } } -static void putInGunMine(tux_t * tux) +static void putInGunMine(tux_t *tux) { int x, y; arena_t *arena; @@ -240,59 +249,61 @@ static void putInGunMine(tux_t * tux) item_t *item; #ifndef NO_SOUND sound_play("put_mine", SOUND_GROUP_BASE); -#endif +#endif /* NO_SOUND */ tux->shot[tux->gun]--; if (net_multiplayer_get_game_type() != NET_GAME_TYPE_CLIENT) { item = item_new(x, y, ITEM_MINE, tux->id); - if (net_multiplayer_get_game_type() == NET_GAME_TYPE_SERVER) + if (net_multiplayer_get_game_type() == NET_GAME_TYPE_SERVER) { proto_send_additem_server(PROTO_SEND_ALL, NULL, item); + } space_add(arena->spaceItem, item); } } } -static void gun_shotBombball(tux_t * tux) +static void gun_shotBombball(tux_t *tux) { addShot(tux, 0, 0, +10, 0); } -void gun_shot(tux_t * tux) +void gun_shot(tux_t *tux) { - if (tux->bonus != BONUS_SHOT && tux->gun != GUN_MINE) + if (tux->bonus != BONUS_SHOT && tux->gun != GUN_MINE) { tux->shot[tux->gun]--; + } switch (tux->gun) { case GUN_SIMPLE: #ifndef NO_SOUND sound_play("gun_revolver", SOUND_GROUP_BASE); - #endif + #endif /* NO_SOUND */ gun_shotSimpe(tux); break; case GUN_DUAL_SIMPLE: #ifndef NO_SOUND sound_play("gun_revolver", SOUND_GROUP_BASE); - #endif + #endif /* NO_SOUND */ gun_shotDualSimpe(tux); break; case GUN_SCATTER: #ifndef NO_SOUND sound_play("gun_scatter", SOUND_GROUP_BASE); - #endif + #endif /* NO_SOUND */ gun_shotScatter(tux); break; case GUN_TOMMY: #ifndef NO_SOUND sound_play("gun_tommy", SOUND_GROUP_BASE); - #endif + #endif /* NO_SOUND */ gun_shotTommy(tux); break; case GUN_LASSER: #ifndef NO_SOUND sound_play("gun_lasser", SOUND_GROUP_BASE); - #endif + #endif /* NO_SOUND */ gun_shotLasser(tux); break; case GUN_BOMBBALL: diff --git a/src/base/homeDirector.c b/src/base/homeDirector.c index 2a7cbfc..f0083ba 100644 --- a/src/base/homeDirector.c +++ b/src/base/homeDirector.c @@ -1,4 +1,3 @@ - #include <stdlib.h> #include <stdio.h> #include <unistd.h> @@ -15,26 +14,25 @@ void home_director_create() char *envHome; #ifndef __WIN32__ envHome = getenv("HOME"); -#else +#else /* __WIN32__ */ envHome = getenv("USERPROFILE"); -#endif +#endif /* __WIN32__ */ if (envHome == NULL) { - fprintf(stderr, _("Environment variable HOME not found!\n")); + fprintf(stderr, _("[Error] Environment variable HOME not found\n")); exit(0); } sprintf(homeDirector, "%s/%s", envHome, HOMEDIRECTOR_NAME); if (access(homeDirector, F_OK) != 0) { - - DEBUG_MSG(_("Creating home directory %s.\n"), homeDirector); + DEBUG_MSG(_("[Debug] Creating home directory [%s]\n"), homeDirector); #ifndef __WIN32__ if (mkdir(homeDirector, 0755) != 0) { -#else +#else /* __WIN32__ */ if (mkdir(homeDirector) != 0) { -#endif - fprintf(stderr, _("Unable to create home directory!\n")); +#endif /* __WIN32__ */ + fprintf(stderr, _("[Error] Unable to create home directory [%s]\n"), homeDirector); exit(0); } } diff --git a/src/base/idManager.c b/src/base/idManager.c index e30cd5a..dea2e95 100644 --- a/src/base/idManager.c +++ b/src/base/idManager.c @@ -1,4 +1,3 @@ - #include <stdlib.h> #include <stdio.h> #include <assert.h> @@ -26,7 +25,7 @@ static id_item_t *newIdItem(int id, int count) return new; } -static void destroyIdItem(id_item_t * p) +static void destroyIdItem(id_item_t *p) { assert(p != NULL); @@ -35,11 +34,11 @@ static void destroyIdItem(id_item_t * p) void id_init_list() { + DEBUG_MSG(_("[Debug] Initializing ID manager\n")); + listID = list_new(); lastID = 0; - DEBUG_MSG(_("Starting ID manger\n")); - } int id_is_register(int id) @@ -68,15 +67,15 @@ static int findNewID() assert(listID != NULL); if (listID->count >= MAX_ID - 1) { - assert(!_("No free ID left!")); + assert(!_("[Error] There is no free ID left")); } do { - //ret = ( random() % (listID->count + 8 ) ) + 1; + /*ret = (random() % (listID->count + 8 )) + 1;*/ ret = random() % MAX_ID + 1; } while (id_is_register(ret) != -1); - //printf("new ID %d\n", ret); + /*printf("new ID %d\n", ret);*/ return ret; } @@ -107,15 +106,16 @@ void id_inc(int id) index = id_is_register(id); if (index == -1) { - assert(!_("This kind of ID was never registered!")); - return; // ha ha ha + fprintf(stderr, _("[Error] Trying to increment counter of never registered ID [%d]"), id); + assert(0); + return; /* ha ha ha */ } this = listID->list[index]; this->count++; - //printf("inc ID %d %d\n", this->id, this->count); + /*printf("inc ID %d %d\n", this->id, this->count);*/ return; } @@ -129,18 +129,19 @@ void id_del(int id) index = id_is_register(id); if (index == -1) { - assert(!_("This kind of ID was never registered!")); - return; // ha ha ha + fprintf(stderr, _("[Error] Trying to delete never registered ID [%d]"), id); + assert(0); + return; /* ha ha ha */ } this = listID->list[index]; this->count--; - //printf("dec ID %d %d\n", this->id, this->count); + /*printf("dec ID %d %d\n", this->id, this->count);*/ if (this->count <= 0) { list_del_item(listID, index, free); - //printf("listID->count = %d\n", listID->count); + /*printf("listID->count = %d\n", listID->count);*/ } return; @@ -176,21 +177,21 @@ void infoID(int id) index = id_is_register(id); if (index == -1) { - DEBUG_MSG(_("ID %d does not exist\n"), id); + DEBUG_MSG(_("[Debug] Getting information of nonexistent ID [%d]\n"), id); return; } this = listID->list[index]; - DEBUG_MSG(_("ID %d (count %d)\n"), this->id, this->count); + DEBUG_MSG(_("[Debug] ID information [%d]: used %d times\n"), this->id, this->count); return; } void id_quit_list() { - DEBUG_MSG(_("Quitting ID manger\n")); + DEBUG_MSG(_("[Debug] Shutting down ID manager\n")); assert(listID != NULL); list_destroy_item(listID, destroyIdItem); diff --git a/src/base/index.c b/src/base/index.c index fc07766..6683ec8 100644 --- a/src/base/index.c +++ b/src/base/index.c @@ -1,4 +1,3 @@ - #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -22,17 +21,16 @@ static index_item_t *index_item_new(int key, void *data) } #ifdef DEBUG_INDEX -static void printIndexItem(index_item_t * p) +static void printIndexItem(index_item_t *p) { - printf("key = %d data = %p\n", p->key, p->data); + printf(_("[Debug] Index [%d] contains: %p\n"), p->key, p->data); } -static void printListIndexItem(list_t * list) +static void printListIndexItem(list_t *list) { int i; - printf("list :\n"); - printf("------------------\n"); + printf(_("List:\n")); for (i = 0; i < list->count; i++) { index_item_t *this; @@ -42,16 +40,16 @@ static void printListIndexItem(list_t * list) } } -static void checkList(list_t * list) +static void checkList(list_t *list) { int i; int prev; int this; - //return; + /*return;*/ if (list->count == 0) { - printf("nothing\n"); + printf(_("Nothing\n")); return; } @@ -62,15 +60,15 @@ static void checkList(list_t * list) if (prev >= this) { printListIndexItem(list); - assert(!"error"); + assert(!_("Error")); } prev = this; } } -#endif +#endif /* DEBUG_INDEX */ -static void index_item_destroy(index_item_t * p) +static void index_item_destroy(index_item_t *p) { free(p); } @@ -80,11 +78,11 @@ list_t *index_new() return list_new(); } -void index_add(list_t * list, int key, void *data) +void index_add(list_t *list, int key, void *data) { #ifdef DEBUG_INDEX int count = 0; -#endif +#endif /* DEBUG_INDEX */ index_item_t *item; index_item_t *this; @@ -102,19 +100,18 @@ void index_add(list_t * list, int key, void *data) #ifdef DEBUG_INDEX if (++count == len * 5) { - printf("CICLIC ERROR\n"); + printf(_("[Error] Cyclic error\n")); printIndexItem(item); - printf("-------------------\n"); printListIndexItem(list); assert(0); } -#endif +#endif /* DEBUG_INDEX */ if (max < 0) { list_ins(list, 0, item); #ifdef DEBUG_INDEX checkList(list); -#endif +#endif /* DEBUG_INDEX */ return; } @@ -122,7 +119,7 @@ void index_add(list_t * list, int key, void *data) list_add(list, item); #ifdef DEBUG_INDEX checkList(list); -#endif +#endif /* DEBUG_INDEX */ return; } @@ -131,13 +128,13 @@ void index_add(list_t * list, int key, void *data) /* printf("min = %d max = %d point = %d len = %d offset = %d\n", min, max, point, len, offset); - */ + if (min > max) { list_ins(list, point, item); #ifdef DEBUG_INDEX checkList(list); -#endif +#endif /* DEBUG_INDEX */ return; } @@ -153,7 +150,7 @@ void index_add(list_t * list, int key, void *data) } } -static int getOffsetFromIndex(list_t * list, int key) +static int getOffsetFromIndex(list_t *list, int key) { index_item_t *this; int min, max, point, len; @@ -175,10 +172,12 @@ static int getOffsetFromIndex(list_t * list, int key) } this = (index_item_t *) list->list[point]; + /* printf("min = %d max = %d point = %d len = %d offset = %d\n", min, max, point, len, offset); */ + if (key == this->key) { return point; } @@ -195,7 +194,7 @@ static int getOffsetFromIndex(list_t * list, int key) } } -void *index_get(list_t * list, int key) +void *index_get(list_t *list, int key) { int offset; @@ -211,7 +210,7 @@ void *index_get(list_t * list, int key) return NULL; } -void index_del(list_t * list, int key) +void index_del(list_t *list, int key) { int offset; @@ -222,7 +221,7 @@ void index_del(list_t * list, int key) } } -void index_del_with_object(list_t * list, int key, void *f) +void index_del_with_object(list_t *list, int key, void *f) { int offset; @@ -241,7 +240,7 @@ void index_del_with_object(list_t * list, int key, void *f) } } -void index_action(list_t * list, void *f) +void index_action(list_t *list, void *f) { int i; @@ -256,12 +255,12 @@ void index_action(list_t * list, void *f) } } -void index_destroy(list_t * list) +void index_destroy(list_t *list) { list_destroy_item(list, index_item_destroy); } -void index_destroyWithObject(list_t * list, void *f) +void index_destroyWithObject(list_t *list, void *f) { index_action(list, f); list_destroy_item(list, index_item_destroy); diff --git a/src/base/item.c b/src/base/item.c index 02533b3..6bf1a67 100644 --- a/src/base/item.c +++ b/src/base/item.c @@ -1,4 +1,3 @@ - #include <stdlib.h> #include <assert.h> @@ -13,28 +12,25 @@ #include "serverSendMsg.h" #ifndef PUBLIC_SERVER +#include "interface.h" +#include "image.h" +#include "radar.h" +#include "layer.h" -# include "interface.h" -# include "image.h" -# include "radar.h" -# include "layer.h" - -# include "world.h" -# include "setting.h" +#include "world.h" +#include "setting.h" -# ifndef NO_SOUND -# include "sound.h" -# endif +#ifndef NO_SOUND +#include "sound.h" +#endif /* NO_SOUND */ -#endif - -#ifdef PUBLIC_SERVER -# include "publicServer.h" -#endif +#else /* PUBLIC_SERVER */ +#include "publicServer.h" +#endif /* PUBLIC_SERVER */ #ifndef PUBLIC_SERVER static image_t *g_item[ITEM_COUNT]; -#endif +#endif /* PUBLIC_SERVER */ static bool_t isItemInit = FALSE; @@ -61,7 +57,7 @@ void item_init() g_item[BONUS_GHOST] = image_add("item.bonus.ghost.png", IMAGE_ALPHA, "item_ghost_speed", IMAGE_GROUP_BASE); g_item[BONUS_4X] = image_add("item.bonus.4x.png", IMAGE_ALPHA, "item_4x_speed", IMAGE_GROUP_BASE); g_item[BONUS_HIDDEN] = image_add("item.bonus.hidden.png", IMAGE_ALPHA, "item_hidden_speed", IMAGE_GROUP_BASE); -#endif +#endif /* PUBLIC_SERVER */ isItemInit = TRUE; } @@ -79,7 +75,7 @@ item_t *item_new(int x, int y, int type, int author_id) new->count = 0; #ifndef PUBLIC_SERVER new->img = g_item[type]; -#endif +#endif /* PUBLIC_SERVER */ new->author_id = author_id; switch (type) { @@ -97,16 +93,16 @@ item_t *item_new(int x, int y, int type, int author_id) new->h = ITEM_MINE_HEIGHT; break; case ITEM_EXPLOSION: - #ifndef NO_SOUND +#ifndef NO_SOUND sound_play("explozion", SOUND_GROUP_BASE); - #endif +#endif /* NO_SOUND */ new->w = ITEM_EXPLOSION_WIDTH; new->h = ITEM_EXPLOSION_HEIGHT; break; case ITEM_BIG_EXPLOSION: - #ifndef NO_SOUND +#ifndef NO_SOUND sound_play("explozion", SOUND_GROUP_BASE); - #endif +#endif /* NO_SOUND */ new->w = ITEM_BIG_EXPLOSION_WIDTH; new->h = ITEM_BIG_EXPLOSION_HEIGHT; break; @@ -147,22 +143,22 @@ void item_set_status(void *p, int x, int y, int w, int h) item->h = h; } -void item_replace_id(item_t * item, int id) +void item_replace_id(item_t *item, int id) { id_replace(item->id, id); item->id = id; } #ifdef PUBLIC_SERVER -static void action_countitem(space_t * space, item_t * item, int *count) +static void action_countitem(space_t *space, item_t *item, int *count) { if ((item->type >= GUN_DUAL_SIMPLE && item->type <= GUN_BOMBBALL) || - (item->type >= BONUS_SPEED && item->type <= BONUS_HIDDEN) ) { + (item->type >= BONUS_SPEED && item->type <= BONUS_HIDDEN)) { (*count)++; } } -static int getCountWeaponOrBonusItem(space_t * spaceItem) +static int getCountWeaponOrBonusItem(space_t *spaceItem) { int count = 0; @@ -170,9 +166,9 @@ static int getCountWeaponOrBonusItem(space_t * spaceItem) return count; } -#endif +#endif /* PUBLIC_SERVER */ -void item_add_new_item(space_t * spaceItem, int author_id) +void item_add_new_item(space_t *spaceItem, int author_id) { arena_t *arena; item_t *item; @@ -183,13 +179,13 @@ void item_add_new_item(space_t * spaceItem, int author_id) if (getCountWeaponOrBonusItem(spaceItem) >= atoi(public_server_get_setting("MAX_ITEM", "--max-item", "100"))) { return; } -#endif +#endif /* PUBLIC_SERVER */ #ifndef PUBLIC_SERVER if (setting_is_any_item() == FALSE || net_multiplayer_get_game_type() == NET_GAME_TYPE_CLIENT) { return; } -#endif +#endif /* PUBLIC_SERVER */ arena = arena_get_current(); arena_find_free_space(arena_get_current(), &new_x, &new_y, ITEM_GUN_WIDTH, ITEM_GUN_HEIGHT); @@ -198,7 +194,7 @@ void item_add_new_item(space_t * spaceItem, int author_id) #ifndef PUBLIC_SERVER do { -#endif +#endif /* PUBLIC_SERVER */ switch (random() % 12) { case 0: type = GUN_DUAL_SIMPLE; @@ -239,28 +235,30 @@ void item_add_new_item(space_t * spaceItem, int author_id) } #ifndef PUBLIC_SERVER } while (setting_is_item(type) == FALSE || - (net_multiplayer_get_game_type() == NET_GAME_TYPE_NONE && type == BONUS_HIDDEN)); -#endif + (net_multiplayer_get_game_type() == NET_GAME_TYPE_NONE && type == BONUS_HIDDEN)); +#endif /* PUBLIC_SERVER */ item = item_new(new_x, new_y, type, author_id); space_add(spaceItem, item); - if (net_multiplayer_get_game_type() == NET_GAME_TYPE_SERVER) + if (net_multiplayer_get_game_type() == NET_GAME_TYPE_SERVER) { proto_send_additem_server(PROTO_SEND_ALL, NULL, item); + } #ifndef PUBLIC_SERVER - if (net_multiplayer_get_game_type() != NET_GAME_TYPE_CLIENT) + if (net_multiplayer_get_game_type() != NET_GAME_TYPE_CLIENT) { radar_add(item->id, new_x, new_y, RADAR_TYPE_ITEM); -#endif + } +#endif /* PUBLIC_SERVER */ } #ifndef PUBLIC_SERVER -void item_draw(item_t * p) +void item_draw(item_t *p) { assert(p != NULL); addLayer(p->img, p->x, p->y, p->frame * p->w, 0, p->w, p->h, TUX_LAYER); } -void item_draw_list(list_t * listItem) +void item_draw_list(list_t *listItem) { item_t *thisItem; int i; @@ -274,9 +272,9 @@ void item_draw_list(list_t * listItem) } } -#endif +#endif /* PUBLIC_SERVER */ -static void action_itemevent(space_t * space, item_t * item, void *p) +static void action_itemevent(space_t *space, item_t *item, void *p) { my_time_t currentTime; @@ -297,17 +295,20 @@ static void action_itemevent(space_t * space, item_t * item, void *p) case GUN_LASSER: case GUN_MINE: case GUN_BOMBBALL: - if (item->frame == ITEM_GUN_MAX_FRAME) + if (item->frame == ITEM_GUN_MAX_FRAME) { item->frame = 0; + } break; case ITEM_MINE: - if (item->frame == ITEM_MINE_MAX_FRAME) + if (item->frame == ITEM_MINE_MAX_FRAME) { item->frame = 0; + } break; case ITEM_EXPLOSION: case ITEM_BIG_EXPLOSION: - if (item->frame == ITEM_EXPLOSION_MAX_FRAME) + if (item->frame == ITEM_EXPLOSION_MAX_FRAME) { space_del_with_item(space, item, item_destroy); + } break; case BONUS_SPEED: case BONUS_SHOT: @@ -315,18 +316,19 @@ static void action_itemevent(space_t * space, item_t * item, void *p) case BONUS_GHOST: case BONUS_4X: case BONUS_HIDDEN: - if (item->frame == ITEM_GUN_MAX_FRAME) + if (item->frame == ITEM_GUN_MAX_FRAME) { item->frame = 0; + } break; } } -void item_event(space_t * spaceItem) +void item_event(space_t *spaceItem) { space_action(spaceItem, action_itemevent, NULL); } -static void mineExplosion(space_t * spaceItem, item_t * item) +static void mineExplosion(space_t *spaceItem, item_t *item) { if (net_multiplayer_get_game_type() != NET_GAME_TYPE_CLIENT) { int x, y; @@ -336,25 +338,29 @@ static void mineExplosion(space_t * spaceItem, item_t * item) y = (item->y + item->h / 2) - ITEM_BIG_EXPLOSION_HEIGHT / 2; item_explosion = item_new(x, y, ITEM_BIG_EXPLOSION, item->author_id); - if (net_multiplayer_get_game_type() == NET_GAME_TYPE_SERVER) + if (net_multiplayer_get_game_type() == NET_GAME_TYPE_SERVER) { proto_send_additem_server(PROTO_SEND_ALL, NULL, item_explosion); + } space_add(spaceItem, item_explosion); } - if (net_multiplayer_get_game_type() == NET_GAME_TYPE_SERVER) + if (net_multiplayer_get_game_type() == NET_GAME_TYPE_SERVER) { proto_send_del_server(PROTO_SEND_ALL, NULL, item->id); + } - if (net_multiplayer_get_game_type() != NET_GAME_TYPE_CLIENT) + if (net_multiplayer_get_game_type() != NET_GAME_TYPE_CLIENT) { space_del_with_item(spaceItem, item, item_destroy); + } } -static void action_item(space_t * space, item_t * item, int *isDel) +static void action_item(space_t *space, item_t *item, int *isDel) { switch (item->type) { case ITEM_MINE: - if (net_multiplayer_get_game_type() != NET_GAME_TYPE_CLIENT) + if (net_multiplayer_get_game_type() != NET_GAME_TYPE_CLIENT) { mineExplosion(space, item); + } break; case ITEM_EXPLOSION: case ITEM_BIG_EXPLOSION: @@ -363,33 +369,36 @@ static void action_item(space_t * space, item_t * item, int *isDel) } } -static void action_shot(space_t * space, shot_t * shot, space_t * spaceItem) +static void action_shot(space_t *space, shot_t *shot, space_t *spaceItem) { int isDel = 0; space_action_from_location(spaceItem, action_item, &isDel, - shot->x, shot->y, shot->w, shot->h); + shot->x, shot->y, shot->w, shot->h); if (isDel) { - if (net_multiplayer_get_game_type() == NET_GAME_TYPE_SERVER) + if (net_multiplayer_get_game_type() == NET_GAME_TYPE_SERVER) { proto_send_del_server(PROTO_SEND_ALL, NULL, shot->id); + } space_del_with_item(space, shot, shot_destroy); } } -void item_event_conglicts_shot_with_item(arena_t * arena) +void item_event_conglicts_shot_with_item(arena_t *arena) { - if (net_multiplayer_get_game_type() == NET_GAME_TYPE_CLIENT) + if (net_multiplayer_get_game_type() == NET_GAME_TYPE_CLIENT) { return; + } space_action(arena->spaceShot, action_shot, arena->spaceItem); } -static void tux_event_tux_is_deadWithItem(tux_t * tux, item_t * item) +static void tux_event_tux_is_deadWithItem(tux_t *tux, item_t *item) { - if (tux->bonus == BONUS_GHOST) + if (tux->bonus == BONUS_GHOST) { return; + } if (tux->bonus == BONUS_TELEPORT) { tux_teleport(tux); @@ -399,8 +408,9 @@ static void tux_event_tux_is_deadWithItem(tux_t * tux, item_t * item) if (item->author_id == tux->id) { tux->score--; - if (net_multiplayer_get_game_type() == NET_GAME_TYPE_SERVER) + if (net_multiplayer_get_game_type() == NET_GAME_TYPE_SERVER) { proto_send_newtux_server(PROTO_SEND_ALL, NULL, tux); + } } if (item->author_id != tux->id) { @@ -411,8 +421,9 @@ static void tux_event_tux_is_deadWithItem(tux_t * tux, item_t * item) if (author != NULL) { author->score++; - if (net_multiplayer_get_game_type() == NET_GAME_TYPE_SERVER) + if (net_multiplayer_get_game_type() == NET_GAME_TYPE_SERVER) { proto_send_newtux_server(PROTO_SEND_ALL, NULL, author); + } } } @@ -420,42 +431,46 @@ static void tux_event_tux_is_deadWithItem(tux_t * tux, item_t * item) tux_event_tux_is_dead(tux); } -static void tuxGiveBonus(tux_t * tux, item_t * item) +static void tuxGiveBonus(tux_t *tux, item_t *item) { #ifndef NO_SOUND sound_play("item_bonus", SOUND_GROUP_BASE); -#endif +#endif /* NO_SOUND */ tux->bonus = item->type; tux->bonus_time = TUX_MAX_BONUS; - if (net_multiplayer_get_game_type() == NET_GAME_TYPE_SERVER) + if (net_multiplayer_get_game_type() == NET_GAME_TYPE_SERVER) { proto_send_newtux_server(PROTO_SEND_ALL, NULL, tux); + } #ifndef PUBLIC_SERVER - if (net_multiplayer_get_game_type() != NET_GAME_TYPE_CLIENT) + if (net_multiplayer_get_game_type() != NET_GAME_TYPE_CLIENT) { radar_del(item->id); -#endif + } +#endif /* PUBLIC_SERVER */ } -static void tuxGiveGun(tux_t * tux, item_t * item) +static void tuxGiveGun(tux_t *tux, item_t *item) { #ifndef NO_SOUND sound_play("item_gun", SOUND_GROUP_BASE); -#endif +#endif /* NO_SOUND */ tux->pickup_time = 0; tux->shot[item->type] += GUN_MAX_SHOT; tux->gun = item->type; - if (net_multiplayer_get_game_type() == NET_GAME_TYPE_SERVER) + if (net_multiplayer_get_game_type() == NET_GAME_TYPE_SERVER) { proto_send_newtux_server(PROTO_SEND_ALL, NULL, tux); + } #ifndef PUBLIC_SERVER - if (net_multiplayer_get_game_type() != NET_GAME_TYPE_CLIENT) + if (net_multiplayer_get_game_type() != NET_GAME_TYPE_CLIENT) { radar_del(item->id); -#endif + } +#endif /* PUBLIC_SERVER */ } -static void action_giveitem(space_t * space, item_t * item, tux_t * tux) +static void action_giveitem(space_t *space, item_t *item, tux_t *tux) { switch (item->type) { case GUN_TOMMY: @@ -466,23 +481,26 @@ static void action_giveitem(space_t * space, item_t * item, tux_t * tux) case GUN_BOMBBALL: tuxGiveGun(tux, item); - if (net_multiplayer_get_game_type() == NET_GAME_TYPE_SERVER) + if (net_multiplayer_get_game_type() == NET_GAME_TYPE_SERVER) { proto_send_del_server(PROTO_SEND_ALL, NULL, item->id); + } space_del_with_item(space, item, item_destroy); - #ifdef PUBLIC_SERVER +#ifdef PUBLIC_SERVER item_add_new_item(space, ID_UNKNOWN); - #endif +#endif /* PUBLIC_SERVER */ break; case ITEM_MINE: - if (tux->bonus != BONUS_GHOST) + if (tux->bonus != BONUS_GHOST) { mineExplosion(space, item); + } break; case ITEM_EXPLOSION: case ITEM_BIG_EXPLOSION: - if (tux->bonus != BONUS_GHOST) + if (tux->bonus != BONUS_GHOST) { tux_event_tux_is_deadWithItem(tux, item); + } break; case BONUS_SPEED: case BONUS_SHOT: @@ -492,35 +510,38 @@ static void action_giveitem(space_t * space, item_t * item, tux_t * tux) case BONUS_HIDDEN: tuxGiveBonus(tux, item); - if (net_multiplayer_get_game_type() == NET_GAME_TYPE_SERVER) + if (net_multiplayer_get_game_type() == NET_GAME_TYPE_SERVER) { proto_send_del_server(PROTO_SEND_ALL, NULL, item->id); + } space_del_with_item(space, item, item_destroy); - #ifdef PUBLIC_SERVER +#ifdef PUBLIC_SERVER item_add_new_item(space, ID_UNKNOWN); - #endif +#endif /* PUBLIC_SERVER */ break; } } -void item_tux_give_list_item(tux_t * tux, space_t * spaceItem) +void item_tux_give_list_item(tux_t *tux, space_t *spaceItem) { int x, y, w, h; assert(spaceItem != NULL); assert(tux != NULL); - if (net_multiplayer_get_game_type() == NET_GAME_TYPE_CLIENT) + if (net_multiplayer_get_game_type() == NET_GAME_TYPE_CLIENT) { return; + } - if (tux->status == TUX_STATUS_DEAD) + if (tux->status == TUX_STATUS_DEAD) { return; + } tux_get_proportion(tux, &x, &y, &w, &h); space_action_from_location(spaceItem, action_giveitem, tux, x, y, w, h); } -void item_destroy(item_t * p) +void item_destroy(item_t *p) { assert(p != NULL); id_del(p->id); diff --git a/src/base/list.c b/src/base/list.c index d211bec..40e7749 100644 --- a/src/base/list.c +++ b/src/base/list.c @@ -1,4 +1,3 @@ - #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -17,7 +16,7 @@ list_t *list_new() return new; } -list_t *list_clone(list_t * p) +list_t *list_clone(list_t *p) { list_t *new; @@ -29,10 +28,11 @@ list_t *list_clone(list_t * p) new->list = malloc(p->alloc * sizeof(void *)); memcpy(new->list, p->list, p->alloc * sizeof(void *)); } + return new; } -list_t *list_clone_item(list_t * p, void *f) +list_t *list_clone_item(list_t *p, void *f) { list_t *new; void *(*fce) (void *); @@ -43,13 +43,14 @@ list_t *list_clone_item(list_t * p, void *f) new = list_clone(p); fce = f; - for (i = 0; i < p->count; i++) + for (i = 0; i < p->count; i++) { new->list[i] = fce(p->list[i]); + } return new; } -void list_add(list_t * p, void *item) +void list_add(list_t *p, void *item) { assert(p != NULL); @@ -70,8 +71,8 @@ void list_add(list_t * p, void *item) if (p->count + 1 > p->alloc) { void **new; #ifdef DEBUG_LIST - printf("Realocating from %d to %d (count=%d)\n", - p->alloc, p->alloc + LIST_ALLOC_LIMIT, p->count); + printf("[Debug] Reallocating list from %d to %d (count: %d)\n", + p->alloc, p->alloc + LIST_ALLOC_LIMIT, p->count); #endif p->alloc += LIST_ALLOC_LIMIT; new = malloc(p->alloc * sizeof(void *)); @@ -84,36 +85,38 @@ void list_add(list_t * p, void *item) } } -void list_ins(list_t * p, int n, void *item) +void list_ins(list_t *p, int n, void *item) { assert(p != NULL); - list_add(p, NULL); // :) + list_add(p, NULL); /* :) */ assert(n >= 0 || n < p->count); memmove(p->list + n + 1, p->list + n, ((p->count - 1) - n) * sizeof(void *)); p->list[n] = item; } -void *list_get(list_t * p, int n) +void *list_get(list_t *p, int n) { assert(p != NULL); assert(n >= 0 || n < p->count); return p->list[n]; } -int list_search(list_t * p, void *n) +int list_search(list_t *p, void *n) { int i; assert(p != NULL); - for (i = 0; i < p->count; i++) - if (p->list[i] == n) + for (i = 0; i < p->count; i++) { + if (p->list[i] == n) { return i; + } + } return -1; } -void list_del(list_t * p, int n) +void list_del(list_t *p, int n) { assert(p != NULL); assert(n >= 0 || n < p->count); @@ -125,8 +128,8 @@ void list_del(list_t * p, int n) void **new; #ifdef DEBUG_LIST - printf("Realocating from %d to %d (count=%d)\n", - p->alloc, p->alloc - LIST_ALLOC_LIMIT, p->count); + printf("Reallocating list from %d to %d (count: %d)\n", + p->alloc, p->alloc - LIST_ALLOC_LIMIT, p->count); #endif p->alloc -= LIST_ALLOC_LIMIT; new = malloc(p->alloc * sizeof(void *)); @@ -136,7 +139,7 @@ void list_del(list_t * p, int n) } } -void list_del_item(list_t * p, int n, void *f) +void list_del_item(list_t *p, int n, void *f) { int (*fce) (void *); @@ -144,28 +147,30 @@ void list_del_item(list_t * p, int n, void *f) assert(n >= 0 || n < p->count); fce = f; - if (fce != NULL) + if (fce != NULL) { fce(p->list[n]); + } list_del(p, n); } -void list_do_empty(list_t * p) +void list_do_empty(list_t *p) { p->count = 0; } -void list_destroy(list_t * p) +void list_destroy(list_t *p) { assert(p != NULL); - if (p->list != NULL) + if (p->list != NULL) { free(p->list); + } free(p); } -void list_destroy_item(list_t * p, void *f) +void list_destroy_item(list_t *p, void *f) { void (*fce) (void *); int i; @@ -175,8 +180,9 @@ void list_destroy_item(list_t * p, void *f) fce = f; - for (i = 0; i < p->count; i++) + for (i = 0; i < p->count; i++) { fce(p->list[i]); + } list_destroy(p); } diff --git a/src/base/main.c b/src/base/main.c index 9d8600a..8766b55 100644 --- a/src/base/main.c +++ b/src/base/main.c @@ -1,4 +1,3 @@ - #include <time.h> #include <stdio.h> #include <stdlib.h> @@ -9,20 +8,18 @@ #include <sys/stat.h> #ifdef __WIN32__ -# include <windows.h> -# include <wininet.h> -#endif +#include <windows.h> +#include <wininet.h> +#endif /* __WIN32__ */ #include "main.h" #include "tux.h" #ifndef PUBLIC_SERVER -# include "game.h" -#endif - -#ifdef PUBLIC_SERVER -# include "publicServer.h" -#endif +#include "game.h" +#else /* PUBLIC_SERVER */ +#include "publicServer.h" +#endif /* PUBLIC_SERVER */ static int my_argc; static char **my_argv; @@ -35,7 +32,7 @@ char *getParam(char *s) len = strlen(s); for (i = 1; i < my_argc; i++) { - //printf("%s %s\n", s, my_argv[i]); + /*printf("%s %s\n", s, my_argv[i]);*/ if (strlen(my_argv[i]) < len) { continue; @@ -94,17 +91,19 @@ int *newInt(int x) void accessExistFile(const char *s) { if (access(s, F_OK) != 0) { - fprintf(stderr, _("File %s not found !\nProgram shutdown !\n"), s); + fprintf(stderr, _("[Error] File not found [%s]\n"), s); + fprintf(stderr, _("[Error] Shutting down the game\n")); exit(-1); } } int tryExistFile(const char *s) { - if (access(s, F_OK) != 0) + if (access(s, F_OK) != 0) { return 1; - else + } else { return 0; + } } int isFillPath(const char *path) @@ -112,11 +111,10 @@ int isFillPath(const char *path) assert(path != NULL); #ifndef __WIN32__ - if (path[0] == '/') // for Unix-like systems ;) -#else - if (path[1] == ':') // for Windows-like systems ;) -#endif - { + if (path[0] == '/') { /* for Unix-like systems ;) */ +#else /* __WIN32__ */ + if (path[1] == ':') { /* for Windows-like systems ;) */ +#endif /* __WIN32__ */ return 1; } @@ -125,53 +123,51 @@ int isFillPath(const char *path) #ifdef __WIN32__ int WINAPI -WinMain(HINSTANCE hInstance, - HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) -#else +WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) +#else /* __WIN32__ */ int main(int argc, char *argv[]) -#endif +#endif /* __WIN32__ */ { #ifndef __WIN32__ signal(SIGPIPE, SIG_IGN); -#endif +#endif /* __WIN32__ */ srand((unsigned) time(NULL)); - #ifdef NLS setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, PATH_LOCALE); bind_textdomain_codeset(PACKAGE, "UTF-8"); textdomain(PACKAGE); -#endif +#endif /* NLS */ + #ifndef __WIN32__ my_argc = argc; my_argv = argv; -#endif +#endif /* __WIN32__ */ + /* test_space(); exit(0); */ #ifdef __WIN32__ - WORD wVersionRequested = MAKEWORD(1, 1); // WinSock version - WSADATA data; // WinSock information structure + WORD wVersionRequested = MAKEWORD(1, 1); /* WinSock version */ + WSADATA data; /* WinSock information structure */ - /* Let's initialize WinSock */ + /* let's initialize WinSock */ if (WSAStartup(wVersionRequested, &data) != 0) { - fprintf(stderr, - _("WinSock initialization failed !\nProgram shutdown !\n")); + fprintf(stderr, _("[Error] Initialization of WinSock failed\n")); + fprintf(stderr, _("[Error] Shutting down the game\n")); exit(-1); } -#endif +#endif /* __WIN32__ */ #ifndef PUBLIC_SERVER game_start(); -#endif - -#ifdef PUBLIC_SERVER +#else /* PUBLIC_SERVER */ public_server_start(); -#endif +#endif /* PUBLIC_SERVER */ return 0; } diff --git a/src/base/modules.c b/src/base/modules.c index 7b0b7c2..5e4e32e 100644 --- a/src/base/modules.c +++ b/src/base/modules.c @@ -1,10 +1,9 @@ - #include <stdio.h> #include <stdlib.h> #include <string.h> #ifndef __WIN32__ -# include <dlfcn.h> -#endif +#include <dlfcn.h> +#endif /* __WIN32__ */ #include <assert.h> #include "main.h" @@ -18,17 +17,17 @@ #include "shareFunction.h" #ifndef PUBLIC_SERVER -# include "interface.h" -# include "image.h" -# include "layer.h" -# include "configFile.h" -#endif +#include "interface.h" +#include "image.h" +#include "layer.h" +#include "configFile.h" +#endif /* PUBLIC_SERVER */ static export_fce_t export_fce = { #ifndef PUBLIC_SERVER .fce_addLayer = addLayer, .fce_image_get = image_get, -#endif +#endif /* PUBLIC_SERVER */ .fce_module_load_dep = module_load_dep, .fce_share_function_add = share_function_add, .fce_share_function_get = share_function_get, @@ -49,14 +48,14 @@ static export_fce_t export_fce = { .fce_proto_send_module_server = proto_send_module_server, #ifndef PUBLIC_SERVER .fce_proto_send_module_client = proto_send_module_client, -#endif +#endif /* PUBLIC_SERVER */ .fce_shot_destroy = shot_destroy, .fce_shot_bound_bombBall = shot_bound_bombBall, .fce_shot_transform_lasser = shot_transform_lasser }; static list_t *listModule; -static void *getFce(module_t * p, char *s) +static void *getFce(module_t *p, char *s) { #ifndef __WIN32__ void *ret; @@ -67,15 +66,16 @@ static void *getFce(module_t * p, char *s) ret = dlsym(p->image, s); if ((error = dlerror()) != NULL) { - fprintf(stderr, _("Error %s occured when using getFce function!\n"), error); + fprintf(stderr, _("[Error] Use of getFce function failed: %s\n"), error); return NULL; } -#else +#else /* __WIN32__ */ FARPROC ret = GetProcAddress((HMODULE) p->image, (LPCSTR) s); if (!ret) { - fprintf(stderr, _("Error %s occured when using getFce function!\n"), s); + fprintf(stderr, _("[Error] Use of getFce function failed: %s\n"), s); } -#endif +#endif /* __WIN32__ */ + return (void *) ret; } @@ -89,26 +89,26 @@ static void *mapImage(char *name) fputs(dlerror(), stderr); return NULL; } -#else +#else /* __WIN32__ */ HINSTANCE image; image = LoadLibrary((LPCSTR) name); if (!image) { LPVOID msg; FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | - FORMAT_MESSAGE_FROM_SYSTEM | - FORMAT_MESSAGE_IGNORE_INSERTS, - NULL, - GetLastError(), - MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), - (LPTSTR) & msg, 0, NULL); + FORMAT_MESSAGE_FROM_SYSTEM | + FORMAT_MESSAGE_IGNORE_INSERTS, + NULL, + GetLastError(), + MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), + (LPTSTR) & msg, 0, NULL); fputs(msg, stderr); free(msg); FreeLibrary(image); return NULL; } - //FreeLibrary(image); //never ever untag this -#endif + /*FreeLibrary(image);*/ /* never ever uncomment this */ +#endif /* __WIN32__ */ return image; } @@ -116,20 +116,20 @@ static void unmapImage(void *image) { #ifndef __WIN32__ dlclose(image); -#else +#else /* __WIN32__ */ FreeLibrary(image); -#endif +#endif /* __WIN32__ */ } static void setModulePath(char *name, char *path) { - sprintf(path, PATH_MODULES "%s" MODULE_TYPE_UNIX, name); // linux + sprintf(path, PATH_MODULES "%s" MODULE_TYPE_UNIX, name); /* GNU/Linux */ #ifdef __WIN32__ - sprintf(path, PATH_MODULES "%s" MODULE_TYPE_WIN, name); // windows -#endif + sprintf(path, PATH_MODULES "%s" MODULE_TYPE_WIN, name); /* MS Windows */ +#endif /* __WIN32__ */ #ifdef APPLE - sprintf(path, PATH_MODULES "%s" MODULE_TYPE_APPLE, name); // apple -#endif + sprintf(path, PATH_MODULES "%s" MODULE_TYPE_APPLE, name); /* Apple */ +#endif /* APPLE */ } static module_t *newModule(char *name) @@ -143,7 +143,7 @@ static module_t *newModule(char *name) image = mapImage(path); if (image == NULL) { - fprintf(stderr, _("Unable to map file %s!\n"), name); + fprintf(stderr, _("[Error] Unable to map image of new module [%s]\n"), name); return NULL; } @@ -153,17 +153,17 @@ static module_t *newModule(char *name) ret->fce_init = getFce(ret, "init"); #ifndef PUBLIC_SERVER ret->fce_draw = getFce(ret, "draw"); -#endif +#endif /* PUBLIC_SERVER */ ret->fce_event = getFce(ret, "event"); ret->fce_destroy = getFce(ret, "destroy"); ret->fce_isConflict = getFce(ret, "isConflict"); ret->fce_cmd = getFce(ret, "cmdArena"); ret->fce_recvMsg = getFce(ret, "recvMsg"); - DEBUG_MSG(_("Loading module: \"%s\"\n"), name); + DEBUG_MSG(_("[Debug] Loading module [%s]\n"), name); if (ret->fce_init(&export_fce) != 0) { - fprintf(stderr, _("Failed initialization of module \"%s\""), name); + fprintf(stderr, _("[Error] Unable to load module [%s]\n"), name); unmapImage(image); free(ret->name); free(ret); @@ -173,16 +173,17 @@ static module_t *newModule(char *name) return ret; } -static int destroyModule(module_t * p) +static int destroyModule(module_t *p) { assert(p != NULL); + + DEBUG_MSG(_("[Debug] Unloading module [%s]\n"), p->name); + p->fce_destroy(); unmapImage(p->image); free(p->name); free(p); - DEBUG_MSG(_("Destroing module...\n")); - return 0; } @@ -201,9 +202,11 @@ int isModuleLoaded(char *name) this = (module_t *) listModule->list[i]; - if (strcmp(this->name, name) == 0) + if (strcmp(this->name, name) == 0) { return 1; + } } + return 0; } @@ -212,25 +215,27 @@ int module_load(char *name) module_t *module; if (isModuleLoaded(name)) { - fprintf(stderr, ("I've done this once, dont want to mess memory with module %s again!\n"), name); + fprintf(stderr, ("[Error] Unable to load already loaded module [%s]\n"), name); return -1; } module = newModule(name); if (module == NULL) { - fprintf(stderr, _("Loading module %s failed!\n"), name); + fprintf(stderr, _("[Error] Unable to load module [%s]\n"), name); return -1; } list_add(listModule, module); + return 0; } int module_load_dep(char *name) { - if (isModuleLoaded(name)) + if (isModuleLoaded(name)) { return 0; + } return module_load(name); } @@ -259,7 +264,7 @@ void module_draw(int x, int y, int w, int h) this->fce_draw(x, y, w, h); } } -#endif +#endif /* PUBLIC_SERVER */ void module_event() { @@ -282,9 +287,11 @@ int module_is_conflict(int x, int y, int w, int h) this = (module_t *) listModule->list[i]; - if (this->fce_isConflict(x, y, w, h) == 1) + if (this->fce_isConflict(x, y, w, h) == 1) { return 1; + } } + return 0; } @@ -298,6 +305,7 @@ int module_recv_msg(char *msg) this = (module_t *) listModule->list[i]; this->fce_recvMsg(msg); } + return 0; } diff --git a/src/base/myTimer.c b/src/base/myTimer.c index 0f72d3e..0c1ff5b 100644 --- a/src/base/myTimer.c +++ b/src/base/myTimer.c @@ -1,4 +1,3 @@ - #include <time.h> #include <assert.h> #include <stdlib.h> @@ -6,17 +5,17 @@ #include <sys/time.h> #include <signal.h> #ifdef __WIN32__ -# include <time.h> -#endif +#include <time.h> +#endif /* __WIN32__ */ #include "main.h" #include "list.h" #include "myTimer.h" #ifndef PUBLIC_SERVER -# include "interface.h" -#endif +#include "interface.h" +#endif /* PUBLIC_SERVER */ -static struct timeval my_start = {.tv_sec = 0,.tv_usec = 0 }; +static struct timeval my_start = {.tv_sec = 0, .tv_usec = 0}; list_t *timer_new() { @@ -34,12 +33,13 @@ my_time_t timer_get_current_time() struct timeval now; my_time_t ticks; - if (my_start.tv_sec == 0 && my_start.tv_usec == 0) + if (my_start.tv_sec == 0 && my_start.tv_usec == 0) { timer_restart(); + } gettimeofday(&now, NULL); ticks = (now.tv_sec - my_start.tv_sec) * 1000 + (now.tv_usec - my_start.tv_usec) / 1000; - //printf("-> %d\n", ticks); + /*printf("-> %d\n", ticks);*/ return ticks; } @@ -50,18 +50,18 @@ my_time_t timer_get_current_timeMicro() struct timeval now; my_time_t ticks; - if (my_micro_start.tv_sec == 0 && my_micro_start.tv_usec == 0) + if (my_micro_start.tv_sec == 0 && my_micro_start.tv_usec == 0) { gettimeofday(&my_micro_start, NULL); + } gettimeofday(&now, NULL); ticks = (now.tv_sec - my_micro_start.tv_sec) * 1000 * 1000 + (now.tv_usec - my_micro_start.tv_usec); - //printf("-> %d\n", ticks); + /*printf("-> %d\n", ticks);*/ return ticks; } -my_timer_t *timer_newItem(int type, void (*fce) (void *p), void *arg, - my_time_t my_time) +my_timer_t *timer_newItem(int type, void (*fce) (void *p), void *arg, my_time_t my_time) { static int new_id = 0; my_timer_t *new; @@ -80,13 +80,13 @@ my_timer_t *timer_newItem(int type, void (*fce) (void *p), void *arg, return new; } -static void timer_destroyItem(my_timer_t * p) +static void timer_destroyItem(my_timer_t *p) { assert(p != NULL); free(p); } -int timer_add_task(list_t * listTimer, int type, void (*fce) (void *p), void *arg, my_time_t my_time) +int timer_add_task(list_t *listTimer, int type, void (*fce) (void *p), void *arg, my_time_t my_time) { my_timer_t *new; @@ -96,7 +96,7 @@ int timer_add_task(list_t * listTimer, int type, void (*fce) (void *p), void *ar return new->id; } -void timer_event(list_t * listTimer) +void timer_event(list_t *listTimer) { int i; my_timer_t *thisTimer; @@ -123,13 +123,13 @@ void timer_event(list_t * listTimer) } break; default: - assert(!_("Timer is really weirdly set!")); + assert(!_("[Error] Bad setting of the timer")); break; } } } -void timer_del(list_t * listTimer, int id) +void timer_del(list_t *listTimer, int id) { my_timer_t *thisTimer; int i; @@ -139,16 +139,18 @@ void timer_del(list_t * listTimer, int id) assert(thisTimer != NULL); - if (thisTimer->id == (unsigned)id) { + if (thisTimer->id == (unsigned) id) { list_del_item(listTimer, i, free); return; } } - assert(!_("There is no such ID!")); + + fprintf(stderr, _("[Error] Unable to delete event from the timer as it is not present in it [%d]\n"), id); + assert(0); } -void timer_destroy(list_t * listTimer) +void timer_destroy(list_t *listTimer) { list_destroy_item(listTimer, timer_destroyItem); } diff --git a/src/base/net_multiplayer.c b/src/base/net_multiplayer.c index 68b19d7..43abf7c 100644 --- a/src/base/net_multiplayer.c +++ b/src/base/net_multiplayer.c @@ -15,12 +15,12 @@ #include "udp.h" #ifndef PUBLIC_SERVER -# include "setting.h" -# include "choiceArena.h" +#include "setting.h" +#include "choiceArena.h" -# include "screen.h" -# include "client.h" -#endif +#include "screen.h" +#include "client.h" +#endif /* PUBLIC_SERVER */ static int netGameType; @@ -47,40 +47,43 @@ int net_multiplayer_init(int type, char *ip, int port, int proto) netGameType = type; switch (netGameType) { - case NET_GAME_TYPE_NONE: - break; - - case NET_GAME_TYPE_SERVER: - switch (proto) { - case PROTO_UDPv4: - if (server_init(ip, port, NULL, 0) != 1) { - fprintf(stderr, _("Unable to inicialize network game as server!\n")); - netGameType = NET_GAME_TYPE_NONE; - return -1; + case NET_GAME_TYPE_NONE: + break; + + case NET_GAME_TYPE_SERVER: + switch (proto) { + case PROTO_UDPv4: + if (server_init(ip, port, NULL, 0) != 1) { + fprintf(stderr, _("[Error] Unable to initialize multiplayer game\n")); + netGameType = NET_GAME_TYPE_NONE; + return -1; + } + break; + + case PROTO_UDPv6: + if (server_init(NULL, 0, ip, port) != 1) { + fprintf(stderr, _("[Error] Unable to initialize multiplayer game\n")); + netGameType = NET_GAME_TYPE_NONE; + return -1; + } + break; } break; - case PROTO_UDPv6: - if (server_init(NULL, 0, ip, port) != 1) { - fprintf(stderr, _("Unable to inicialize network game as server!\n")); + +#ifndef PUBLIC_SERVER + case NET_GAME_TYPE_CLIENT: + if (client_init(ip, port) != 0) { + fprintf(stderr, _("[Error] Unable to join multiplayer game\n")); netGameType = NET_GAME_TYPE_NONE; return -1; } break; - } - break; +#endif /* PUBLIC_SERVER */ -#ifndef PUBLIC_SERVER - case NET_GAME_TYPE_CLIENT: - if (client_init(ip, port) != 0) { - fprintf(stderr, _("Unable to inicialize network game as client!\n")); - netGameType = NET_GAME_TYPE_NONE; - return -1; - } - break; -#endif - default: - assert(!_("Variable netGameType has a really weird value!")); - break; + default: + fprintf(stderr, _("[Error] Unknown type of the network game [%d]\n"), netGameType); + assert(0); + break; } return 0; @@ -89,42 +92,46 @@ int net_multiplayer_init(int type, char *ip, int port, int proto) void net_multiplayer_event() { switch (netGameType) { - case NET_GAME_TYPE_NONE: - break; + case NET_GAME_TYPE_NONE: + break; - case NET_GAME_TYPE_SERVER: - server_event(); - break; + case NET_GAME_TYPE_SERVER: + server_event(); + break; #ifndef PUBLIC_SERVER - case NET_GAME_TYPE_CLIENT: - client_event(); - break; -#endif - default: - assert(!_("Variable netGameType has a really weird value!")); - break; + case NET_GAME_TYPE_CLIENT: + client_event(); + break; +#endif /* PUBLIC_SERVER */ + + default: + fprintf(stderr, _("[Error] Unknown type of the network game [%d]\n"), netGameType); + assert(0); + break; } } void net_multiplayer_quit() { switch (netGameType) { - case NET_GAME_TYPE_NONE: - break; + case NET_GAME_TYPE_NONE: + break; - case NET_GAME_TYPE_SERVER: - server_quit(); - break; + case NET_GAME_TYPE_SERVER: + server_quit(); + break; #ifndef PUBLIC_SERVER - case NET_GAME_TYPE_CLIENT: - client_quit(); - break; -#endif - default: - assert(!_("Variable netGameType has a really weird value!")); - break; + case NET_GAME_TYPE_CLIENT: + client_quit(); + break; +#endif /* PUBLIC_SERVER */ + + default: + fprintf(stderr, _("[Error] Unknown type of the network game [%d]\n"), netGameType); + assert(0); + break; } netGameType = NET_GAME_TYPE_NONE; diff --git a/src/base/protect.c b/src/base/protect.c index a384734..754fa26 100644 --- a/src/base/protect.c +++ b/src/base/protect.c @@ -1,4 +1,3 @@ - #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -22,7 +21,7 @@ protect_t *newProtect() return new; } -void refreshLastMove(protect_t * p) +void refreshLastMove(protect_t *p) { my_time_t currentTime; my_time_t interval; @@ -40,26 +39,32 @@ void refreshLastMove(protect_t * p) my_index = p->avarage / PROTECT_SPEED_AVARAGE; p->avarage = 0; p->count = 0; -#if 0 + +/* if (my_index < PROTECT_SPEED_INTERVAL_TIMEOUT) { p->isDown = TRUE; } -#endif - //printf("speed index = %d\n", my_index); +*/ + + /*printf("speed index = %d\n", my_index);*/ } } -void rereshLastPing(protect_t * p) +void rereshLastPing(protect_t *p) { - //my_time_t currentTime; - //my_time_t interval; - //currentTime = timer_get_current_time(); - //interval = currentTime - p->lastPing; + /* + my_time_t currentTime; + my_time_t interval; + currentTime = timer_get_current_time(); + interval = currentTime - p->lastPing; + */ + p->lastPing = timer_get_current_time(); - //printf("interval = %d\n", interval); + + /*printf("interval = %d\n", interval);*/ } -bool_t isDown(protect_t * p) +bool_t isDown(protect_t *p) { my_time_t currentTime; my_time_t interval; @@ -67,13 +72,14 @@ bool_t isDown(protect_t * p) currentTime = timer_get_current_time(); interval = currentTime - p->lastPing; - if (interval > PROTECT_PING_INTERVAL_TIMEOUT) + if (interval > PROTECT_PING_INTERVAL_TIMEOUT) { p->isDown = TRUE; + } return p->isDown; } -void destroyProtect(protect_t * p) +void destroyProtect(protect_t *p) { assert(p != NULL); free(p); diff --git a/src/base/proto.c b/src/base/proto.c index f4a1972..1c56653 100644 --- a/src/base/proto.c +++ b/src/base/proto.c @@ -1,4 +1,3 @@ - #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -21,24 +20,22 @@ #include "serverSendMsg.h" #ifndef PUBLIC_SERVER -# include "world.h" -# include "setting.h" -# include "choiceArena.h" -# include "analyze.h" -# include "downArena.h" -# include "client.h" -# include "term.h" -# include "radar.h" -# include "chat.h" -#endif - -#ifdef PUBLIC_SERVER -# include "highScore.h" -# include "publicServer.h" -# include "serverConfigFile.h" -#endif - -void proto_send_error_server(int type, client_t * client, int errorcode) +#include "world.h" +#include "setting.h" +#include "choiceArena.h" +#include "analyze.h" +#include "downArena.h" +#include "client.h" +#include "term.h" +#include "radar.h" +#include "chat.h" +#else /* PUBLIC_SERVER*/ +#include "highScore.h" +#include "publicServer.h" +#include "serverConfigFile.h" +#endif /* PUBLIC_SERVER*/ + +void proto_send_error_server(int type, client_t *client, int errorcode) { char msg[STR_PROTO_SIZE]; @@ -48,7 +45,6 @@ void proto_send_error_server(int type, client_t * client, int errorcode) } #ifndef PUBLIC_SERVER - void proto_recv_error_client(char *msg) { char cmd[STR_PROTO_SIZE]; @@ -63,28 +59,24 @@ void proto_recv_error_client(char *msg) return; } - DEBUG_MSG(_("Proto error code: \"%d\"\n"), errorcode); + DEBUG_MSG(_("[Debug] Communication error [%d]\n"), errorcode); switch (errorcode) { case PROTO_ERROR_CODE_BAD_VERSION: - analyze_set_msg(_("Version of your client isn't supported by the server.")); + analyze_set_msg(_("Cannot connect to the server. You have incompatible version of the game.")); world_do_end(); break; case PROTO_ERROR_CODE_TIMEOUT: - analyze_set_msg(_("The timeout of ping from server is out")); + analyze_set_msg(_("Connection timeout")); world_do_end(); break; case PROTO_ERROR_LIMIT_MAX_CLIENT: - analyze_set_msg(_("The maximum amount of connected players has been exceeded!")); + analyze_set_msg(_("Server is full")); world_do_end(); break; } } -#endif - -#ifndef PUBLIC_SERVER - void proto_send_hello_client(char *name) { char msg[STR_PROTO_SIZE]; @@ -92,20 +84,19 @@ void proto_send_hello_client(char *name) snprintf(msg, STR_PROTO_SIZE, "hello %s %s\n", getParamElse("--version", TUXANCI_VERSION), name); - printf("-> %s", msg); + printf(_("[Debug] Sending: %s\n"), msg); client_send(msg); } +#endif /* PUBLIC_SERVER */ -#endif - -static void action_sendItem(space_t * space, item_t * item, client_t * client) +static void action_sendItem(space_t *space, item_t *item, client_t *client) { UNUSED(space); proto_send_additem_server(PROTO_SEND_ONE, client, item); } -static void sendInfoCreateClient(client_t * client) +static void sendInfoCreateClient(client_t *client) { list_t *listClient; client_t *thisClient; @@ -120,34 +111,35 @@ static void sendInfoCreateClient(client_t * client) #ifndef PUBLIC_SERVER proto_send_newtux_server(PROTO_SEND_ONE, client, world_get_control_tux(TUX_CONTROL_KEYBOARD_RIGHT)); -#endif +#endif /* PUBLIC_SERVER */ for (i = 0; i < listClient->count; i++) { thisClient = (client_t *) listClient->list[i]; thisTux = thisClient->tux; - // odosli kazdemu stremu hracovy informacie o novom hracovy + /* odosli kazdemu stremu hracovy informacie o novom hracovy */ + /* send to all players information about new player */ if (thisTux != NULL && thisTux != client->tux) { proto_send_newtux_server(PROTO_SEND_ONE, thisClient, client->tux); } - // odosli novemu hracovy informacie o kazdom starom hracovy aj o sebe + /* send to new players information about all players, including himself */ if (thisTux != NULL) { proto_send_newtux_server(PROTO_SEND_ONE, client, thisTux); } } space_action(arena_get_current()->spaceItem, action_sendItem, client); + /* - for( i = 0 ; i < arena_get_current()->spaceItem->listIndex->count; i++) - { + for (i = 0; i < arena_get_current()->spaceItem->listIndex->count; i++) { thisItem = (item_t *) arena_get_current()->spaceItem->list->list[i]; proto_send_additem_server(PROTO_SEND_ONE, client, thisItem); } */ } -void proto_recv_hello_server(client_t * client, char *msg) +void proto_recv_hello_server(client_t *client, char *msg) { static char *supportVersion = NULL; char cmd[STR_PROTO_SIZE]; @@ -167,17 +159,13 @@ void proto_recv_hello_server(client_t * client, char *msg) strcpy(version, ""); strcpy(name, ""); -#ifdef PUBLIC_SERVER if (supportVersion == NULL) { - supportVersion = public_server_get_setting("SUPPORT_CLIENTS", "--support-clients", TUXANCI_VERSION); - } -#endif - #ifndef PUBLIC_SERVER - if (supportVersion == NULL) { supportVersion = TUXANCI_VERSION; +#else /* PUBLIC_SERVER */ + supportVersion = public_server_get_setting("SUPPORT_CLIENTS", "--support-clients", TUXANCI_VERSION); +#endif /* PUBLIC_SERVER */ } -#endif recv_count = sscanf(msg, "%s %s %s", cmd, version, name); @@ -206,7 +194,7 @@ void proto_recv_hello_server(client_t * client, char *msg) sendInfoCreateClient(client); } -void proto_send_status_server(int type, client_t * client) +void proto_send_status_server(int type, client_t *client) { char msg[STR_PROTO_SIZE]; char *name; @@ -217,12 +205,12 @@ void proto_send_status_server(int type, client_t * client) char *arena; #ifndef PUBLIC_SERVER - name = "noname"; -#endif + name = "NewServer"; +#endif /* PUBLIC_SERVER */ #ifdef PUBLIC_SERVER name = public_server_get_setting("NAME", "--name", "noname"); -#endif +#endif /* PUBLIC_SERVER */ version = TUXANCI_VERSION; clients = arena_get_current()->spaceTux->listIndex->count; @@ -231,27 +219,35 @@ void proto_send_status_server(int type, client_t * client) arena = arena_file_get_net_name(choice_arena_get()); snprintf(msg, STR_PROTO_SIZE, - "name: %s\n" - "version: %s\n" - "clients: %d\n" - "maxclients: %d\n" - "uptime: %d\n" - "arena: %s\n", name, version, clients, maxclients, uptime, arena); + "name: %s\n" + "version: %s\n" + "clients: %d\n" + "maxclients: %d\n" + "uptime: %d\n" + "arena: %s\n", + name, version, clients, maxclients, uptime, arena); send_msg_to_client(type, client, msg, CHECK_FRONT_TYPE_SIMPLE, CHECK_FRONT_ID_NONE); - //proto_send(type, client, msg); + /*proto_send(type, client, msg);*/ } -void proto_recv_status_server(client_t * client, char *msg) +void proto_recv_status_server(client_t *client, char *msg) { UNUSED(msg); proto_send_status_server(PROTO_SEND_ONE, client); } -#ifdef PUBLIC_SERVER +#ifndef PUBLIC_SERVER +void proto_send_check_client(int id) +{ + char msg[STR_PROTO_SIZE]; -void proto_send_listscore_server(int type, client_t * client, int max) + snprintf(msg, STR_PROTO_SIZE, "check %d\n", id); + client_send(msg); +} +#else /* PUBLIC_SERVER */ +void proto_send_listscore_server(int type, client_t *client, int max) { char *str; char *msg; @@ -271,12 +267,12 @@ void proto_send_listscore_server(int type, client_t * client, int max) strcat(msg, "\n"); } - //proto_send(type, client, msg); + /*proto_send(type, client, msg);*/ send_msg_to_client(type, client, msg, CHECK_FRONT_TYPE_SIMPLE, CHECK_FRONT_ID_NONE); free(msg); } -void proto_recv_listscore_server(client_t * client, char *msg) +void proto_recv_listscore_server(client_t *client, char *msg) { char cmd[STR_PROTO_SIZE]; int recv_count; @@ -292,22 +288,9 @@ void proto_recv_listscore_server(client_t * client, char *msg) proto_send_listscore_server(PROTO_SEND_ONE, client, max); } +#endif /* PUBLIC_SERVER */ -#endif - -#ifndef PUBLIC_SERVER - -void proto_send_check_client(int id) -{ - char msg[STR_PROTO_SIZE]; - - snprintf(msg, STR_PROTO_SIZE, "check %d\n", id); - client_send(msg); -} - -#endif - -void proto_recv_check_server(client_t * client, char *msg) +void proto_recv_check_server(client_t *client, char *msg) { char cmd[STR_PROTO_SIZE]; int recv_count; @@ -324,7 +307,7 @@ void proto_recv_check_server(client_t * client, char *msg) check_front_del_msg(client->listSendMsg, id); } -void proto_send_init_server(int type, client_t * client, client_t * client2) +void proto_send_init_server(int type, client_t *client, client_t *client2) { char msg[STR_PROTO_SIZE]; int count; @@ -336,7 +319,7 @@ void proto_send_init_server(int type, client_t * client, client_t * client2) #ifndef PUBLIC_SERVER public_server_get_settingCountRound(&count); -#endif +#endif /* PUBLIC_SERVER */ check_id = id_get_newcount(0); @@ -344,12 +327,11 @@ void proto_send_init_server(int type, client_t * client, client_t * client2) client2->tux->id, client2->tux->x, client2->tux->y, count, arena_file_get_net_name(choice_arena_get()), check_id); - //proto_send(type, client, msg); + /*proto_send(type, client, msg);*/ send_msg_to_client(type, client, msg, CHECK_FRONT_TYPE_CHECK, check_id); } #ifndef PUBLIC_SERVER - void proto_recv_init_client(char *msg) { char cmd[STR_PROTO_SIZE]; @@ -392,22 +374,19 @@ void proto_recv_init_client(char *msg) space_add(arena->spaceTux, tux); } +#endif /* PUBLIC_SERVER */ -#endif - -void -proto_send_event_server(int type, client_t * client, tux_t * tux, int action) +void proto_send_event_server(int type, client_t *client, tux_t *tux, int action) { char msg[STR_PROTO_SIZE]; snprintf(msg, STR_PROTO_SIZE, "event %d %d\n", tux->id, action); - //proto_send(type, client, msg); + /*proto_send(type, client, msg);*/ send_msg_to_client(type, client, msg, CHECK_FRONT_TYPE_SIMPLE, CHECK_FRONT_ID_NONE); } #ifndef PUBLIC_SERVER - void proto_recv_event_client(char *msg) { char cmd[STR_PROTO_SIZE]; @@ -431,10 +410,6 @@ void proto_recv_event_client(char *msg) } } -#endif - -#ifndef PUBLIC_SERVER - void proto_send_event_client(int action) { char msg[STR_PROTO_SIZE]; @@ -443,10 +418,9 @@ void proto_send_event_client(int action) client_send(msg); } +#endif /* PUBLIC_SERVER */ -#endif - -void proto_recv_event_server(client_t * client, char *msg) +void proto_recv_event_server(client_t *client, char *msg) { char cmd[STR_PROTO_SIZE]; int action; @@ -455,7 +429,7 @@ void proto_recv_event_server(client_t * client, char *msg) assert(client != NULL); assert(msg != NULL); - //debug_interval(); + /*debug_interval();*/ recv_count = sscanf(msg, "%s %d", cmd, &action); @@ -472,7 +446,7 @@ void proto_recv_event_server(client_t * client, char *msg) tux_action(client->tux, action); } -void proto_send_newtux_server(int type, client_t * client, tux_t * tux) +void proto_send_newtux_server(int type, client_t *client, tux_t *tux) { char msg[STR_PROTO_SIZE]; int x, y; @@ -487,20 +461,19 @@ void proto_send_newtux_server(int type, client_t * client, tux_t * tux) } snprintf(msg, STR_PROTO_SIZE, "newtux %d %d %d %d %d %d %d %s %d %d %d %d %d %d %d %d %d %d %d\n", - tux->id, x, y, tux->status, tux->position, tux->frame, - tux->score, tux->name, tux->gun, tux->bonus, - tux->shot[GUN_SIMPLE], tux->shot[GUN_DUAL_SIMPLE], - tux->shot[GUN_SCATTER], tux->shot[GUN_TOMMY], - tux->shot[GUN_LASSER], tux->shot[GUN_MINE], - tux->shot[GUN_BOMBBALL], tux->bonus_time, tux->pickup_time); - - //proto_send(type, client, msg); + tux->id, x, y, tux->status, tux->position, tux->frame, + tux->score, tux->name, tux->gun, tux->bonus, + tux->shot[GUN_SIMPLE], tux->shot[GUN_DUAL_SIMPLE], + tux->shot[GUN_SCATTER], tux->shot[GUN_TOMMY], + tux->shot[GUN_LASSER], tux->shot[GUN_MINE], + tux->shot[GUN_BOMBBALL], tux->bonus_time, tux->pickup_time); + + /*proto_send(type, client, msg);*/ send_msg_to_client(type, client, msg, CHECK_FRONT_TYPE_SIMPLE, - CHECK_FRONT_ID_NONE); + CHECK_FRONT_ID_NONE); } #ifndef PUBLIC_SERVER - void proto_recv_newtux_client(char *msg) { char cmd[STR_PROTO_SIZE]; @@ -518,11 +491,10 @@ void proto_recv_newtux_client(char *msg) return; } - recv_count = - sscanf(msg, "%s %d %d %d %d %d %d %d %s %d %d %d %d %d %d %d %d %d %d %d", - cmd, &id, &x, &y, &status, &position, &frame, &score, name, - &myGun, &myBonus, &gun1, &gun2, &gun3, &gun4, &gun5, &gun6, - &gun7, &time1, &time2); + recv_count = sscanf(msg, "%s %d %d %d %d %d %d %d %s %d %d %d %d %d %d %d %d %d %d %d", + cmd, &id, &x, &y, &status, &position, &frame, &score, name, + &myGun, &myBonus, &gun1, &gun2, &gun3, &gun4, &gun5, &gun6, + &gun7, &time1, &time2); if (recv_count != 20) { return; @@ -570,10 +542,9 @@ void proto_recv_newtux_client(char *msg) tux->bonus_time = time1; tux->pickup_time = time2; } +#endif /* PUBLIC_SERVER */ -#endif - -void proto_send_kill_server(int type, client_t * client, tux_t * tux) +void proto_send_kill_server(int type, client_t *client, tux_t *tux) { char msg[STR_PROTO_SIZE]; @@ -581,12 +552,11 @@ void proto_send_kill_server(int type, client_t * client, tux_t * tux) snprintf(msg, STR_PROTO_SIZE, "kill %d\n", tux->id); - //proto_send(type, client, msg); + /*proto_send(type, client, msg);*/ send_msg_to_client(type, client, msg, CHECK_FRONT_TYPE_SIMPLE, CHECK_FRONT_ID_NONE); } #ifndef PUBLIC_SERVER - void proto_recv_kill_client(char *msg) { char cmd[STR_PROTO_SIZE]; @@ -608,10 +578,9 @@ void proto_recv_kill_client(char *msg) tux_event_tux_is_dead(tux); } } +#endif /* PUBLIC_SERVER */ -#endif - -void proto_send_del_server(int type, client_t * client, int id) +void proto_send_del_server(int type, client_t *client, int id) { char msg[STR_PROTO_SIZE]; int check_id; @@ -621,7 +590,7 @@ void proto_send_del_server(int type, client_t * client, int id) snprintf(msg, STR_PROTO_SIZE, "del %d %d\n", id, check_id); send_msg_to_client(type, client, msg, CHECK_FRONT_TYPE_CHECK, check_id); - //proto_check(type, client, msg, check_id); + /*proto_check(type, client, msg, check_id);*/ } #ifndef PUBLIC_SERVER @@ -632,12 +601,11 @@ void timer_delShot(void *p) int *id; assert( p != NULL ); - id = (int *)(p); + id = (int *) p; shot = space_get_object_id(arena_get_current()->spaceShot, *id); - if( shot != NULL ) - { + if (shot != NULL) { radar_del(shot->id); space_del_with_item(arena_get_current()->spaceShot, shot, shot_destroy); } @@ -675,9 +643,11 @@ void proto_recv_del_client(char *msg) shot = space_get_object_id(arena_get_current()->spaceShot, id); if (shot != NULL) { - //printf("delete shot..\n"); - //radar_del(id); - //space_del_with_item(arena_get_current()->spaceShot, shot, shot_destroy); + /* + printf("delete shot..\n"); + radar_del(id); + space_del_with_item(arena_get_current()->spaceShot, shot, shot_destroy); + */ timer_add_task(arena_get_current()->listTimer, TIMER_ONE, timer_delShot, newInt(id), 50); return; } @@ -685,16 +655,15 @@ void proto_recv_del_client(char *msg) item = space_get_object_id(arena_get_current()->spaceItem, id); if (item != NULL) { - //printf("delete item..\n"); + /*printf("delete item..\n");*/ radar_del(id); space_del_with_item(arena_get_current()->spaceItem, item, item_destroy); return; } } +#endif /* PUBLIC_SERVER */ -#endif - -void proto_send_additem_server(int type, client_t * client, item_t * p) +void proto_send_additem_server(int type, client_t *client, item_t *p) { char msg[STR_PROTO_SIZE]; int check_id; @@ -706,13 +675,14 @@ void proto_send_additem_server(int type, client_t * client, item_t * p) snprintf(msg, STR_PROTO_SIZE, "additem %d %d %d %d %d %d %d %d\n", p->id, p->type, p->x, p->y, p->count, p->frame, p->author_id, check_id); - //proto_send(type, client, msg); - //proto_check(type, client, msg, check_id); + /* + proto_send(type, client, msg); + proto_check(type, client, msg, check_id); + */ send_msg_to_client(type, client, msg, CHECK_FRONT_TYPE_CHECK, check_id); } #ifndef PUBLIC_SERVER - void proto_recv_additem_client(char *msg) { char cmd[STR_PROTO_SIZE]; @@ -735,8 +705,7 @@ void proto_recv_additem_client(char *msg) proto_send_check_client(check_id); - if ((item = - space_get_object_id(arena_get_current()->spaceItem, id)) != NULL) { + if ((item = space_get_object_id(arena_get_current()->spaceItem, id)) != NULL) { return; } @@ -753,10 +722,9 @@ void proto_recv_additem_client(char *msg) space_add(arena_get_current()->spaceItem, item); } +#endif /* PUBLIC_SERVER */ -#endif - -void proto_send_shot_server(int type, client_t * client, shot_t * p) +void proto_send_shot_server(int type, client_t *client, shot_t *p) { char msg[STR_PROTO_SIZE]; @@ -766,13 +734,14 @@ void proto_send_shot_server(int type, client_t * client, shot_t * p) p->id, p->x-p->px*8, p->y-p->py*8, p->px, p->py, p->position, p->gun, p->author_id, p->isCanKillAuthor); - //proto_send(type, client, msg); - //proto_check(type, client, msg, check_id); + /* + proto_send(type, client, msg); + proto_check(type, client, msg, check_id); + */ send_msg_to_client(type, client, msg, CHECK_FRONT_TYPE_SIMPLE, CHECK_FRONT_ID_NONE); } #ifndef PUBLIC_SERVER - void proto_recv_shot_client(char *msg) { char cmd[STR_PROTO_SIZE]; @@ -792,7 +761,7 @@ void proto_recv_shot_client(char *msg) if ((shot = space_get_object_id(arena_get_current()->spaceShot, shot_id)) != NULL) { space_del_with_item(arena_get_current()->spaceShot, shot, shot_destroy); - //return; + /*return;*/ } shot = shot_new(x, y, px, py, gun, author_id); @@ -808,20 +777,15 @@ void proto_recv_shot_client(char *msg) space_add(arena_get_current()->spaceShot, shot); } -#endif - -#ifndef PUBLIC_SERVER - void proto_send_chat_client(char *s) { char msg[STR_PROTO_SIZE]; snprintf(msg, STR_PROTO_SIZE, "chat %s\n", s); client_send(msg); } +#endif /* PUBLIC_SERVER */ -#endif - -void proto_recv_chat_server(client_t * client, char *msg) +void proto_recv_chat_server(client_t *client, char *msg) { char out[STR_PROTO_SIZE]; int len; @@ -838,17 +802,16 @@ void proto_recv_chat_server(client_t * client, char *msg) proto_send_chat_server(PROTO_SEND_ALL, NULL, out); } -void proto_send_chat_server(int type, client_t * client, char *msg) +void proto_send_chat_server(int type, client_t *client, char *msg) { send_msg_to_client(type, client, msg, CHECK_FRONT_TYPE_SIMPLE, CHECK_FRONT_ID_NONE); #ifndef PUBLIC_SERVER proto_recv_chat_client(msg); -#endif +#endif /* PUBLIC_SERVER */ } #ifndef PUBLIC_SERVER - void proto_recv_chat_client(char *msg) { int len; @@ -861,37 +824,35 @@ void proto_recv_chat_client(char *msg) chat_add(msg + 5); } -#endif - -#ifndef PUBLIC_SERVER - void proto_send_module_client(char *msg) { char out[STR_PROTO_SIZE]; snprintf(out, STR_PROTO_SIZE, "module %s\n", msg); + /* strcpy(out, "modules "); strcat(out, msg); strcat(out, "\n"); */ + client_send(out); } +#endif /* PUBLIC_SERVER */ -#endif - -void proto_recv_module_server(client_t * client, char *msg) +void proto_recv_module_server(client_t *client, char *msg) { UNUSED(client); module_recv_msg(msg + 7); } -void proto_send_module_server(int type, client_t * client, char *msg) +void proto_send_module_server(int type, client_t *client, char *msg) { char out[STR_PROTO_SIZE]; snprintf(out, STR_PROTO_SIZE, "module %s\n", msg); + /* strcpy(out, "modules "); strcat(out, msg); @@ -902,73 +863,64 @@ void proto_send_module_server(int type, client_t * client, char *msg) } #ifndef PUBLIC_SERVER - void proto_recv_module_client(char *msg) { module_recv_msg(msg + 7); } -#endif - -#ifndef PUBLIC_SERVER - void proto_send_ping_client() { char msg[STR_PROTO_SIZE]; snprintf(msg, STR_PROTO_SIZE, "ping\n"); client_send(msg); } +#endif /* PUBLIC_SERVER */ -#endif - -void proto_recv_ping_server(client_t * client, char *msg) +void proto_recv_ping_server(client_t *client, char *msg) { UNUSED(client); UNUSED(msg); } -void proto_send_ping_server(int type, client_t * client) +void proto_send_ping_server(int type, client_t *client) { char msg[STR_PROTO_SIZE]; snprintf(msg, STR_PROTO_SIZE, "ping\n"); - //proto_send(type, client, msg); + /*proto_send(type, client, msg);*/ send_msg_to_client(type, client, msg, CHECK_FRONT_TYPE_SIMPLE, CHECK_FRONT_ID_NONE); } #ifndef PUBLIC_SERVER - void proto_recv_ping_client(char *msg) { UNUSED(msg); } +#endif /* PUBLIC_SERVER */ -#endif - -void proto_recv_echo_server(client_t * client, char *msg) +void proto_recv_echo_server(client_t *client, char *msg) { - proto_send_echo_server(PROTO_SEND_ONE, client, msg + 4); // msg + strlen("echo"); + proto_send_echo_server(PROTO_SEND_ONE, client, msg + 4); /* msg + strlen("echo"); */ } -void proto_send_echo_server(int type, client_t * client, char *s) +void proto_send_echo_server(int type, client_t *client, char *s) { char msg[STR_PROTO_SIZE]; snprintf(msg, STR_PROTO_SIZE, "echo%s", s); - //proto_send(type, client, msg); + /*proto_send(type, client, msg);*/ send_msg_to_client(type, client, msg, CHECK_FRONT_TYPE_SIMPLE, CHECK_FRONT_ID_NONE); } -void proto_send_end_server(int type, client_t * client) +void proto_send_end_server(int type, client_t *client) { char msg[STR_PROTO_SIZE]; snprintf(msg, STR_PROTO_SIZE, "end\n"); - //proto_send(type, client, msg); + /*proto_send(type, client, msg);*/ send_msg_to_client(type, client, msg, CHECK_FRONT_TYPE_SIMPLE, CHECK_FRONT_ID_NONE); } #ifndef PUBLIC_SERVER - void proto_recv_end_client(char *msg) { assert(msg != NULL); @@ -976,10 +928,6 @@ void proto_recv_end_client(char *msg) world_do_end(); } -#endif - -#ifndef PUBLIC_SERVER - void proto_send_end_client() { char msg[STR_PROTO_SIZE]; @@ -987,10 +935,9 @@ void proto_send_end_client() snprintf(msg, STR_PROTO_SIZE, "end\n"); client_send(msg); } +#endif /* PUBLIC_SERVER */ -#endif - -void proto_recv_end_server(client_t * client, char *msg) +void proto_recv_end_server(client_t *client, char *msg) { assert(msg != NULL); assert(client != NULL); diff --git a/src/base/server.c b/src/base/server.c index cdd1487..2b968d1 100644 --- a/src/base/server.c +++ b/src/base/server.c @@ -1,14 +1,13 @@ - #ifndef __WIN32__ -# include <sys/socket.h> -# include <sys/types.h> -# include <netinet/in.h> -# include <arpa/inet.h> -# include <netdb.h> -#else -# include <windows.h> -# include <wininet.h> -#endif +#include <sys/socket.h> +#include <sys/types.h> +#include <netinet/in.h> +#include <arpa/inet.h> +#include <netdb.h> +#else /* __WIN32__ */ +#include <windows.h> +#include <wininet.h> +#endif /* __WIN32__ */ #include <unistd.h> #include <stdlib.h> @@ -33,14 +32,11 @@ #include "downServer.h" #ifndef PUBLIC_SERVER -# include "world.h" -#endif - -#ifdef PUBLIC_SERVER -# include "publicServer.h" -# include "highScore.h" -#endif - +#include "world.h" +#else /* PUBLIC_SERVER */ +#include "publicServer.h" +#include "highScore.h" +#endif /* PUBLIC_SERVER */ #include "udp_server.h" @@ -61,9 +57,8 @@ static proto_cmd_server_t proto_cmd_list[] = { {.name = "hello",.len = 5,.tux = 0,.fce_proto = proto_recv_hello_server}, {.name = "status",.len = 6,.tux = 0,.fce_proto = proto_recv_status_server}, #ifdef PUBLIC_SERVER - {.name = "list",.len = 4,.tux = 0,.fce_proto = - proto_recv_listscore_server}, -#endif + {.name = "list",.len = 4,.tux = 0,.fce_proto = proto_recv_listscore_server}, +#endif /* PUBLIC_SERVER */ {.name = "event",.len = 5,.tux = 1,.fce_proto = proto_recv_event_server}, {.name = "check",.len = 5,.tux = 1,.fce_proto = proto_recv_check_server}, {.name = "module",.len = 6,.tux = 1,.fce_proto = proto_recv_module_server}, @@ -74,7 +69,7 @@ static proto_cmd_server_t proto_cmd_list[] = { {.name = "",.len = 0,.tux = 0,.fce_proto = NULL}, }; -static proto_cmd_server_t *findCmdProto(client_t * client, char *msg) +static proto_cmd_server_t *findCmdProto(client_t *client, char *msg) { int len; int i; @@ -88,8 +83,9 @@ static proto_cmd_server_t *findCmdProto(client_t * client, char *msg) if (len >= thisCmd->len && strncmp(msg, thisCmd->name, thisCmd->len) == 0) { if ((thisCmd->tux == 1 && client->tux == NULL) || - (thisCmd->tux == 0 && client->tux != NULL)) + (thisCmd->tux == 0 && client->tux != NULL)) { return NULL; + } return thisCmd; } @@ -124,11 +120,11 @@ client_t *server_new_any_client() return new; } -void server_destroy_any_client(client_t * p) +void server_destroy_any_client(client_t *p) { assert(p != NULL); - //check_front_event(p); + /*check_front_event(p);*/ list_destroy_item(p->listRecvMsg, free); list_destroy_item(p->listSeesShot, free); check_front_destroy(p->listSendMsg); @@ -138,14 +134,14 @@ void server_destroy_any_client(client_t * p) if (p->tux != NULL) { #ifdef PUBLIC_SERVER table_add(p->tux->name, p->tux->score); -#endif +#endif /* PUBLIC_SERVER */ space_del_with_item(arena_get_current()->spaceTux, p->tux, tux_destroy); } free(p); } -static void eventDelClientFromListClient(client_t * client) +static void eventDelClientFromListClient(client_t *client) { int offset; @@ -207,7 +203,7 @@ static void eventPeriodicSyncClient(void *p_nothink) } proto_send_newtux_server(PROTO_SEND_ALL_SEES_TUX, thisClientSend, thisTux); - //proto_send_newtux_server(PROTO_SEND_BUT, thisClientSend, thisTux); + /*proto_send_newtux_server(PROTO_SEND_BUT, thisClientSend, thisTux);*/ } } @@ -244,19 +240,16 @@ int server_init(char *ip4, int port4, char *ip6, int port6) server_set_max_clients(SERVER_MAX_CLIENTS); server_set_time(); - //printf("%s %d %s %d\n", ip4, port4, ip6, port6); + /*printf("%s %d %s %d\n", ip4, port4, ip6, port6);*/ ret = server_udp_init(ip4, port4, ip6, port6); if (ret == 0) { return -1; } - if( ip4 != NULL ) - { + if (ip4 != NULL) { down_server_init(ip4, port4); - } - else if( ip6 != NULL ) - { + } else if (ip6 != NULL) { down_server_init(ip6, port6); } @@ -278,19 +271,20 @@ void server_set_max_clients(int n) maxClients = n; } -void server_send_client(client_t * p, char *msg) +void server_send_client(client_t *p, char *msg) { assert(p != NULL); assert(msg != NULL); if (p->status != NET_STATUS_ZOMBIE) { - int ret = -1; // no Warnnings + int ret = -1; /* no warnings */ #ifndef PUBLIC_SERVER if (isParamFlag("--send")) { - printf(_("Sending: \"%s\""), msg); + printf(_("[Debug] Sending: %s"), msg); } -#endif +#endif /* PUBLIC_SERVER */ + ret = sock_udp_write(p->socket_udp, p->socket_udp, msg, strlen(msg)); if (ret <= 0) { @@ -299,7 +293,7 @@ void server_send_client(client_t * p, char *msg) } } -static void client_eventWorkRecvList(client_t * client) +static void client_eventWorkRecvList(client_t *client) { proto_cmd_server_t *protoCmd; char *line; @@ -307,17 +301,16 @@ static void client_eventWorkRecvList(client_t * client) assert(client != NULL); - /* obsluha udalosti od clientov */ - + /* processing of events from clients */ for (i = 0; i < client->listRecvMsg->count; i++) { line = (char *) client->listRecvMsg->list[i]; protoCmd = findCmdProto(client, line); #ifndef PUBLIC_SERVER if (isParamFlag("--recv")) { - printf(_("Recieved: \"%s\""), line); + printf(_("[Debug] Received: %s"), line); } -#endif +#endif /* PUBLIC_SERVER */ if (protoCmd != NULL) { protoCmd->fce_proto(client, line); @@ -360,9 +353,7 @@ void server_event() count = server_udp_select_sock(); down_server_select_socket(); } while (count > 0); -#endif - -#ifdef PUBLIC_SERVER +#else /* PUBLIC_SERVER */ int ret; select_restart(); @@ -376,7 +367,7 @@ void server_event() server_udp_select_sock(); down_server_select_socket(); } -#endif +#endif /* PUBLIC_SERVER */ porcesListClients(); timer_event(listServerTimer); diff --git a/src/base/serverSelect.c b/src/base/serverSelect.c index 2cf2586..6f8d64e 100644 --- a/src/base/serverSelect.c +++ b/src/base/serverSelect.c @@ -1,4 +1,3 @@ - #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -10,13 +9,13 @@ #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 <sys/ioctl.h> +#include <sys/socket.h> +#include <sys/select.h> +#else /* __WIN32__ */ +#include <io.h> +#include <winsock2.h> +#endif /* __WIN32__ */ #include "server.h" @@ -30,12 +29,10 @@ void select_restart() #ifndef PUBLIC_SERVER tv.tv_sec = 0; tv.tv_usec = 0; -#endif - -#ifdef PUBLIC_SERVER +#else /* PUBLIC_SERVER */ tv.tv_sec = 0; tv.tv_usec = 1000; -#endif +#endif /* PUBLIC_SERVER */ FD_ZERO(&readfds); FD_ZERO(&writefds); @@ -44,7 +41,7 @@ void select_restart() void select_add_sock_for_read(int sock) { - //printf("select_add_sock_for_read %d\n", sock); + /*printf("select_add_sock_for_read %d\n", sock);*/ FD_SET(sock, &readfds); @@ -55,7 +52,7 @@ void select_add_sock_for_read(int sock) void select_add_sock_for_write(int sock) { - //printf("select_add_sock_for_write %d\n", sock); + /*printf("select_add_sock_for_write %d\n", sock);*/ FD_SET(sock, &writefds); @@ -68,7 +65,9 @@ int select_action() { int ret; -#ifdef PUBLIC_SERVER +#ifndef PUBLIC_SERVER + ret = select(max_fd + 1, &readfds, &writefds, (fd_set *) NULL, &tv); +#else /* PUBLIC_SERVER */ list_t *listClient; listClient = server_get_list_clients(); @@ -78,11 +77,7 @@ int select_action() } else { ret = select(max_fd + 1, &readfds, &writefds, (fd_set *) NULL, &tv); } -#endif - -#ifndef PUBLIC_SERVER - ret = select(max_fd + 1, &readfds, &writefds, (fd_set *) NULL, &tv); -#endif +#endif /* PUBLIC_SERVER */ return ret; } @@ -93,7 +88,7 @@ int select_is_change_sock_for_read(int sock) ret = FD_ISSET(sock, &readfds); - //printf("select_is_change_sock %d -> %d\n", sock, ret); + /*printf("select_is_change_sock %d -> %d\n", sock, ret);*/ return ret; } @@ -104,7 +99,7 @@ int select_is_change_sock_for_write(int sock) ret = FD_ISSET(sock, &writefds); - //printf("select_is_change_sock %d -> %d\n", sock, ret); + /*printf("select_is_change_sock %d -> %d\n", sock, ret);*/ return ret; } diff --git a/src/base/serverSendMsg.c b/src/base/serverSendMsg.c index c6c9a0a..ed30020 100644 --- a/src/base/serverSendMsg.c +++ b/src/base/serverSendMsg.c @@ -1,4 +1,3 @@ - #include <unistd.h> #include <stdlib.h> #include <stdio.h> @@ -11,10 +10,10 @@ #include "serverSendMsg.h" #ifndef PUBLIC_SERVER -# include "world.h" -#endif +#include "world.h" +#endif /* PUBLIC_SERVER */ -static void addMsgClient(client_t * p, char *msg, int type, int id) +static void addMsgClient(client_t *p, char *msg, int type, int id) { assert(p != NULL); assert(msg != NULL); @@ -24,7 +23,7 @@ static void addMsgClient(client_t * p, char *msg, int type, int id) } } -static void addMsgAllClientBut(char *msg, client_t * p, int type, int id) +static void addMsgAllClientBut(char *msg, client_t *p, int type, int id) { list_t *listClient; client_t *thisClient; @@ -50,7 +49,7 @@ static void addMsgAllClient(char *msg, int type, int id) addMsgAllClientBut(msg, NULL, type, id); } -static void addMsgAllClientSeesTux(char *msg, tux_t * tux, int type, int id) +static void addMsgAllClientSeesTux(char *msg, tux_t *tux, int type, int id) { list_t *listHelp; arena_t *arena; @@ -69,22 +68,26 @@ static void addMsgAllClientSeesTux(char *msg, tux_t * tux, int type, int id) w = 2 * WINDOW_SIZE_X; h = 2 * WINDOW_SIZE_Y; - if (x < 0) + if (x < 0) { x = 0; + } - if (y < 0) + if (y < 0) { y = 0; + } - if (w + x >= arena->w) + if (w + x >= arena->w) { w = arena->w - (x + 1); + } - if (h + y >= arena->h) + if (h + y >= arena->h) { h = arena->h - (y + 1); + } listHelp = list_new(); space_get_object(space, x, y, w, h, listHelp); - //printf("%d %d %d %d %d\n", x, y, w, h, listHelp->count); + /*printf("%d %d %d %d %d\n", x, y, w, h, listHelp->count);*/ for (i = 0; i < listHelp->count; i++) { tux_t *thisTux; @@ -106,7 +109,7 @@ static void addMsgAllClientSeesTux(char *msg, tux_t * tux, int type, int id) list_destroy(listHelp); } -void send_msg_to_client(int type, client_t * client, char *msg, int type2, int id) +void send_msg_to_client(int type, client_t *client, char *msg, int type2, int id) { assert(msg != NULL); @@ -124,19 +127,19 @@ void send_msg_to_client(int type, client_t * client, char *msg, int type2, int i addMsgAllClientBut(msg, client, type2, id); break; case PROTO_SEND_ALL_SEES_TUX: - #ifndef PUBLIC_SERVER +#ifndef PUBLIC_SERVER if (client != NULL) { addMsgAllClientSeesTux(msg, client->tux, type2, id); } else { addMsgAllClientSeesTux(msg, world_get_control_tux(TUX_CONTROL_KEYBOARD_RIGHT), type2, id); } - #endif - #ifdef PUBLIC_SERVER +#else /*Â PUBLIC_SERVER*/ addMsgAllClientSeesTux(msg, client->tux, type2, id); - #endif +#endif /* PUBLIC_SERVER */ break; default: - assert(!_("Type variable has a really wierd value!")); + fprintf(stderr, _("[Error] Unknown type of target group of players [%d]\n"), type); + assert(0); break; } } diff --git a/src/base/shareFunction.c b/src/base/shareFunction.c index 52fc48a..7121cfd 100644 --- a/src/base/shareFunction.c +++ b/src/base/shareFunction.c @@ -1,4 +1,3 @@ - #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -25,7 +24,7 @@ static share_fce_item_t *newShareFceItem(char *name, void *function) return new; } -static void destroyShareFce(share_fce_item_t * p) +static void destroyShareFce(share_fce_item_t *p) { free(p->name); free(p); @@ -38,7 +37,7 @@ void share_function_init() void share_function_add(char *name, void *function) { - DEBUG_MSG(_("Adding \"%s\" to share function.\n"), name); + DEBUG_MSG(_("[Debug] Adding new shared function [%s]\n"), name); list_add(listShareFce, newShareFceItem(name, function)); } @@ -52,8 +51,9 @@ void *share_function_get(char *name) this = (share_fce_item_t *) listShareFce->list[i]; - if (strcmp(this->name, name) == 0) + if (strcmp(this->name, name) == 0) { return this->function; + } } return NULL; diff --git a/src/base/shot.c b/src/base/shot.c index 564f458..f11760a 100644 --- a/src/base/shot.c +++ b/src/base/shot.c @@ -1,4 +1,3 @@ - #include <stdlib.h> #include <string.h> #include <assert.h> @@ -12,23 +11,19 @@ #include "serverSendMsg.h" #ifndef PUBLIC_SERVER -# include "image.h" -# include "layer.h" -# include "world.h" -#endif - -#ifdef PUBLIC_SERVER -# include "publicServer.h" -#endif +#include "image.h" +#include "layer.h" +#include "world.h" +#else /* PUBLIC_SERVER */ +#include "publicServer.h" +#endif /* PUBLIC_SERVER */ #ifndef PUBLIC_SERVER - static image_t *g_shot_simple; static image_t *g_shot_lasserX; static image_t *g_shot_lasserY; static image_t *g_shot_bombball; - -#endif +#endif /* PUBLIC_SERVER */ static bool_t isShotInit = FALSE; @@ -41,15 +36,12 @@ void shot_init() { #ifndef PUBLIC_SERVER assert(image_is_inicialized() == TRUE); -#endif -#ifndef PUBLIC_SERVER g_shot_simple = image_add("shot.png", IMAGE_ALPHA, "shot", IMAGE_GROUP_BASE); g_shot_lasserX = image_add("lasserX.png", IMAGE_NO_ALPHA, "lasserX", IMAGE_GROUP_BASE); g_shot_lasserY = image_add("lasserY.png", IMAGE_NO_ALPHA, "lasserY",IMAGE_GROUP_BASE); g_shot_bombball = image_add("bombball.png", IMAGE_ALPHA, "bombball", IMAGE_GROUP_BASE); - -#endif +#endif /* PUBLIC_SERVER */ isShotInit = TRUE; } @@ -85,29 +77,29 @@ shot_t *shot_new(int x, int y, int px, int py, int gun, int author_id) case GUN_SIMPLE: new->w = GUN_SHOT_WIDTH; new->h = GUN_SHOT_HEIGHT; - #ifndef PUBLIC_SERVER +#ifndef PUBLIC_SERVER new->img = g_shot_simple; - #endif +#endif /* PUBLIC_SERVER */ break; case GUN_LASSER: switch (author->position) { - case TUX_RIGHT: - case TUX_LEFT: - new->w = GUN_LASSER_HORIZONTAL; - new->h = GUN_SHOT_VERTICAL; - #ifndef PUBLIC_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 PUBLIC_SERVER - new->img = g_shot_lasserY; - #endif - break; + case TUX_RIGHT: + case TUX_LEFT: + new->w = GUN_LASSER_HORIZONTAL; + new->h = GUN_SHOT_VERTICAL; +#ifndef PUBLIC_SERVER + new->img = g_shot_lasserX; +#endif /* PUBLIC_SERVER */ + break; + case TUX_UP: + case TUX_DOWN: + new->w = GUN_SHOT_VERTICAL; + new->h = GUN_LASSER_HORIZONTAL; +#ifndef PUBLIC_SERVER + new->img = g_shot_lasserY; +#endif /* PUBLIC_SERVER */ + break; } break; @@ -115,20 +107,21 @@ shot_t *shot_new(int x, int y, int px, int py, int gun, int author_id) new->w = GUN_BOMBBALL_WIDTH; new->h = GUN_BOMBBALL_HEIGHT; - #ifndef PUBLIC_SERVER +#ifndef PUBLIC_SERVER new->img = g_shot_bombball; - #endif +#endif /* PUBLIC_SERVER */ break; default: - assert(!_("Type variable has a really wierd value!")); + fprintf(stderr, _("[Error] Unknown type of gun [%d]\n"), gun); + assert(0); break; } return new; } -void shot_replace_id(shot_t * shot, int id) +void shot_replace_id(shot_t *shot, int id) { id_replace(shot->id, id); shot->id = id; @@ -159,14 +152,13 @@ void shot_set_status(void *p, int x, int y, int w, int h) } #ifndef PUBLIC_SERVER - -void shot_draw(shot_t * p) +void shot_draw(shot_t *p) { assert(p != NULL); addLayer(p->img, p->x, p->y, 0, 0, p->img->w, p->img->h, TUX_LAYER); } -void shot_draw_list(list_t * listShot) +void shot_draw_list(list_t *listShot) { shot_t *thisShot; int i; @@ -179,12 +171,11 @@ void shot_draw_list(list_t * listShot) shot_draw(thisShot); } } - -#endif +#endif /* PUBLIC_SERVER */ static int getRandomCourse(int x, int y) { - int ret = -1; // no warnning + int ret = -1; /* no warnings */ do { switch (random() % 3) { @@ -203,7 +194,7 @@ static int getRandomCourse(int x, int y) return ret; } -void shot_bound_bombBall(shot_t * shot) +void shot_bound_bombBall(shot_t *shot) { if (shot->gun != GUN_BOMBBALL) { return; @@ -218,7 +209,7 @@ void shot_bound_bombBall(shot_t * shot) } } -void shot_transform_lasser(shot_t * shot) +void shot_transform_lasser(shot_t *shot) { space_t *space; int mustRefesh = 0; @@ -238,17 +229,17 @@ void shot_transform_lasser(shot_t * shot) case TUX_LEFT: shot->w = GUN_LASSER_HORIZONTAL; shot->h = GUN_SHOT_VERTICAL; - #ifndef PUBLIC_SERVER +#ifndef PUBLIC_SERVER shot->img = g_shot_lasserX; - #endif +#endif /* PUBLIC_SERVER */ break; case TUX_UP: case TUX_DOWN: shot->w = GUN_SHOT_VERTICAL; shot->h = GUN_LASSER_HORIZONTAL; - #ifndef PUBLIC_SERVER +#ifndef PUBLIC_SERVER shot->img = g_shot_lasserY; - #endif +#endif /* PUBLIC_SERVER */ break; } @@ -257,7 +248,7 @@ void shot_transform_lasser(shot_t * shot) } } -static void action_moveShot(space_t * space, shot_t * shot, void *p) +static void action_moveShot(space_t *space, shot_t *shot, void *p) { int new_x, new_y; arena_t *arena; @@ -277,12 +268,12 @@ static void action_moveShot(space_t * space, shot_t * shot, void *p) } } -void shot_event_move_list(arena_t * arena) +void shot_event_move_list(arena_t *arena) { space_action(arena->spaceShot, action_moveShot, NULL); } -static int isValueInList(list_t * list, int x) +static int isValueInList(list_t *list, int x) { int i; @@ -295,17 +286,17 @@ static int isValueInList(list_t * list, int x) return 0; } -static void action_check(space_t * space, shot_t * shot, client_t * client) +static void action_check(space_t *space, shot_t *shot, client_t *client) { UNUSED(space); if (isValueInList(client->listSeesShot, shot->id) == 0) { - list_add(client->listSeesShot, newInt(shot->id)); - proto_send_shot_server(PROTO_SEND_ONE, client, shot); + list_add(client->listSeesShot, newInt(shot->id)); + proto_send_shot_server(PROTO_SEND_ONE, client, shot); } } -void shot_check_is_tux_screen(arena_t * arena) +void shot_check_is_tux_screen(arena_t *arena) { int screen_x, screen_y; tux_t *thisTux; @@ -329,22 +320,22 @@ void shot_check_is_tux_screen(arena_t * arena) } arena_get_center_screen(&screen_x, &screen_y, thisTux->x, thisTux->y, - WINDOW_SIZE_X, WINDOW_SIZE_Y); + WINDOW_SIZE_X, WINDOW_SIZE_Y); space_action_from_location(arena->spaceShot, action_check, - thisClient, screen_x, screen_y, - WINDOW_SIZE_X, WINDOW_SIZE_Y); + thisClient, screen_x, screen_y, + WINDOW_SIZE_X, WINDOW_SIZE_Y); while (thisClient->listSeesShot->count > 100) { list_del_item(thisClient->listSeesShot, 0, free); del++; } - //if( del > 0 )printf("del = %d\n", del); + /*if( del > 0 )printf("del = %d\n", del);*/ } } -void shot_destroy(shot_t * p) +void shot_destroy(shot_t *p) { assert(p != NULL); diff --git a/src/base/space.c b/src/base/space.c index 2621ecf..4f3adbe 100644 --- a/src/base/space.c +++ b/src/base/space.c @@ -1,4 +1,3 @@ - #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -19,7 +18,7 @@ zone_t *newZone() return new; } -void destroyZone(zone_t * p) +void destroyZone(zone_t *p) { assert(p != NULL); @@ -27,8 +26,7 @@ void destroyZone(zone_t * p) free(p); } -static int my_arena_conflict_space(int x1, int y1, int w1, int h1, int x2, int y2, int w2, - int h2) +static int my_arena_conflict_space(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); } @@ -66,8 +64,8 @@ space_t *space_new(int w, int h, int segW, int segH, return new; } -static void getSegment(space_t * p, int x, int y, int w, int h, - int *segX, int *segY, int *segW, int *segH) +static void getSegment(space_t *p, int x, int y, int w, int h, + int *segX, int *segY, int *segW, int *segH) { *segX = x / p->segW; *segY = y / p->segH; @@ -75,12 +73,12 @@ static void getSegment(space_t * p, int x, int y, int w, int h, *segH = ((y + h) / p->segH + 1) - *segY; } -int space_get_count(space_t * p) +int space_get_count(space_t *p) { return p->listIndex->count; } -void *space_get_item(space_t * p, int offset) +void *space_get_item(space_t *p, int offset) { index_item_t *this; @@ -88,7 +86,7 @@ void *space_get_item(space_t * p, int offset) return this->data; } -void space_add(space_t * p, void *item) +void space_add(space_t *p, void *item) { int segX, segY, segW, segH; int id, x, y, w, h; @@ -110,7 +108,7 @@ void space_add(space_t * p, void *item) index_add(p->listIndex, id, item); } -void space_get_object(space_t * p, int x, int y, int w, int h, list_t * list) +void space_get_object(space_t *p, int x, int y, int w, int h, list_t *list) { int segX, segY, segW, segH; int id, this_x, this_y, this_w, this_h; @@ -139,12 +137,12 @@ void space_get_object(space_t * p, int x, int y, int w, int h, list_t * list) } } -void *space_get_object_id(space_t * space, int id) +void *space_get_object_id(space_t *space, int id) { return index_get(space->listIndex, id); } -int space_is_conflict_with_object(space_t * p, int x, int y, int w, int h) +int space_is_conflict_with_object(space_t *p, int x, int y, int w, int h) { int segX, segY, segW, segH; int id, this_x, this_y, this_w, this_h; @@ -174,7 +172,7 @@ int space_is_conflict_with_object(space_t * p, int x, int y, int w, int h) return 0; } -int space_is_conflict_with_object_but(space_t * p, int x, int y, int w, int h, void *but) +int space_is_conflict_with_object_but(space_t *p, int x, int y, int w, int h, void *but) { int segX, segY, segW, segH; int id, this_x, this_y, this_w, this_h; @@ -209,7 +207,7 @@ int space_is_conflict_with_object_but(space_t * p, int x, int y, int w, int h, v return 0; } -void space_del(space_t * p, void *item) +void space_del(space_t *p, void *item) { int segX, segY, segW, segH; int id, x, y, w, h; @@ -234,7 +232,7 @@ void space_del(space_t * p, void *item) index_del(p->listIndex, id); } -void space_del_with_item(space_t * p, void *item, void *f) +void space_del_with_item(space_t *p, void *item, void *f) { void (*fce) (void *param); @@ -244,7 +242,7 @@ void space_del_with_item(space_t * p, void *item, void *f) fce(item); } -void space_move_object(space_t * p, void *item, int move_x, int move_y) +void space_move_object(space_t *p, void *item, int move_x, int move_y) { int old_segX, old_segY, old_segW, old_segH; int new_segX, new_segY, new_segW, new_segH; @@ -253,11 +251,13 @@ void space_move_object(space_t * p, void *item, int move_x, int move_y) p->getStatus(item, &id, &x, &y, &w, &h); getSegment(p, x, y, w, h, &old_segX, &old_segY, &old_segW, &old_segH); getSegment(p, move_x, move_y, w, h, &new_segX, &new_segY, &new_segW, &new_segH); + /* printf("%d %d %d %d -> %d %d %d %d \n", old_segX, old_segY, old_segW, old_segH, new_segX, new_segY, new_segW, new_segH); */ + if (old_segX != new_segX || old_segY != new_segY || old_segW != new_segW || old_segH != new_segH) { space_del(p, item); @@ -269,11 +269,11 @@ void space_move_object(space_t * p, void *item, int move_x, int move_y) p->setStatus(item, move_x, move_y, w, h); } -void space_print(space_t * p) +void space_print(space_t *p) { int i, j; - printf("print space : \n"); + printf(_("[Debug] Debugging space:\n")); for (i = 0; i < p->h; i++) { for (j = 0; j < p->w; j++) { @@ -284,9 +284,9 @@ void space_print(space_t * p) } } -void space_action(space_t * space, void *f, void *p) +void space_action(space_t *space, void *f, void *p) { - void (*fce) (space_t * space, void *f, void *p); + void (*fce) (space_t *space, void *f, void *p); int len; int i; @@ -303,9 +303,9 @@ void space_action(space_t * space, void *f, void *p) } } -void space_action_from_location(space_t * space, void *f, void *p, int x, int y, int w, int h) +void space_action_from_location(space_t *space, void *f, void *p, int x, int y, int w, int h) { - void (*fce) (space_t * space, void *f, void *p); + void (*fce) (space_t *space, void *f, void *p); list_t *list; int len; int i; @@ -325,7 +325,7 @@ void space_action_from_location(space_t * space, void *f, void *p, int x, int y, list_destroy(list); } -void space_destroy(space_t * p) +void space_destroy(space_t *p) { int j, i; @@ -345,7 +345,7 @@ void space_destroy(space_t * p) free(p); } -void space_destroy_with_item(space_t * p, void *f) +void space_destroy_with_item(space_t *p, void *f) { void (*fce) (void *param); int i; diff --git a/src/base/storage.c b/src/base/storage.c index 99082be..971e576 100644 --- a/src/base/storage.c +++ b/src/base/storage.c @@ -1,4 +1,3 @@ - #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -33,7 +32,7 @@ static storage_item_t *storage_new_item(char *group, char *name, void *data) return new; } -static void storage_destroy_item(storage_item_t * p, void *f) +static void storage_destroy_item(storage_item_t *p, void *f) { void (*fce) (void *); @@ -47,7 +46,7 @@ static void storage_destroy_item(storage_item_t * p, void *f) free(p); } -void storage_add(list_t * list, char *group, char *name, void *data) +void storage_add(list_t *list, char *group, char *name, void *data) { assert(list != NULL); assert(group != NULL); @@ -56,7 +55,7 @@ void storage_add(list_t * list, char *group, char *name, void *data) list_add(list, storage_new_item(group, name, data)); } -void *storage_get(list_t * list, char *group, char *name) +void *storage_get(list_t *list, char *group, char *name) { storage_item_t *this; int i; @@ -68,16 +67,17 @@ void *storage_get(list_t * list, char *group, char *name) for (i = 0; i < list->count; i++) { this = (storage_item_t *) list->list[i]; - if (strcmp(group, this->group) == 0 && strcmp(name, this->name) == 0) + if (strcmp(group, this->group) == 0 && strcmp(name, this->name) == 0) { return this->data; + } } - DEBUG_MSG(_("%s %s was not found in storage!\n"), group, name); + DEBUG_MSG(_("[Error] Storage item not found [%s %s]\n"), group, name); return NULL; } -void storage_del(list_t * list, char *group, char *name, void *f) +void storage_del(list_t *list, char *group, char *name, void *f) { storage_item_t *this; int i; @@ -99,7 +99,7 @@ void storage_del(list_t * list, char *group, char *name, void *f) return; } -void storage_del_all(list_t * list, char *group, void *f) +void storage_del_all(list_t *list, char *group, void *f) { storage_item_t *this; int i; @@ -118,7 +118,7 @@ void storage_del_all(list_t * list, char *group, void *f) } } -void storage_destroy(list_t * p, void *f) +void storage_destroy(list_t *p, void *f) { storage_item_t *this; int i; diff --git a/src/base/textFile.c b/src/base/textFile.c index c09c879..8db6713 100644 --- a/src/base/textFile.c +++ b/src/base/textFile.c @@ -1,4 +1,3 @@ - #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -31,7 +30,7 @@ textFile_t *text_file_new(char *s) return new; } -static void createLine(list_t * list, char *p, int len) +static void createLine(list_t *list, char *p, int len) { char *line; char *begin_line; @@ -47,8 +46,9 @@ static void createLine(list_t * list, char *p, int len) do { end_line = memchr(begin_line, '\n', len); - if (end_line == NULL) + if (end_line == NULL) { break; + } length_line = (int) (end_line - (begin_line)); @@ -65,8 +65,7 @@ static void createLine(list_t * list, char *p, int len) } /* - * Nacita subor *s a vrati ho f - * formatovany v type textFile_t* + * Loads file *s and returns him formatted to textFile_t* */ textFile_t *text_file_load(char *s) { @@ -79,20 +78,20 @@ textFile_t *text_file_load(char *s) assert(s != NULL); if (lstat(s, &buf) < 0) { - fprintf(stderr, _("ERROR: unable to get file status for %s!\n"), s); + fprintf(stderr, _("[Error] Unable to get file status [%s]\n"), s); return NULL; } file_length = buf.st_size; if ((file = fopen(s, "rb")) == NULL) { - fprintf(stderr, _("ERROR: unable to open file %s for reading\n"), s); + fprintf(stderr, _("[Error] Unable to open file for reading [%s]\n"), s); return NULL; } p = malloc(file_length * sizeof(char)); if (fread(p, file_length * sizeof(char), 1, file) != 1) { - fprintf(stderr, _("ERROR: unable to read data from file %s\n"), s); + fprintf(stderr, _("[Error] Unable to read data from file [%s]\n"), s); fclose(file); return NULL; } @@ -108,23 +107,22 @@ textFile_t *text_file_load(char *s) } /* - * Zobrazi text ulozeny v *p - * do stdout + * Prints the text saved in *p into stdout */ -void text_file_print(textFile_t * p) +void text_file_print(textFile_t *p) { int i; assert(p != NULL); - printf(_("Printing file: \"%s\"\n\n"), p->file); + printf(_("[Debug] Printing file [%s]\n\n"), p->file); for (i = 0; i < p->text->count; i++) { printf("%3d >> %s\n", i, (char *) p->text->list[i]); } } -void text_file_save(textFile_t * p) +void text_file_save(textFile_t *p) { int i; FILE *file; @@ -141,10 +139,9 @@ void text_file_save(textFile_t * p) } /* - * Uvolni text ulozeny v type textFile_t* - * z pamate. + * Removes text saved in *p from the memory */ -void text_file_destroy(textFile_t * p) +void text_file_destroy(textFile_t *p) { assert(p != NULL); diff --git a/src/base/tux.c b/src/base/tux.c index 287ffea..b41d63e 100644 --- a/src/base/tux.c +++ b/src/base/tux.c @@ -1,4 +1,3 @@ - #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -19,31 +18,27 @@ #include "serverSendMsg.h" #ifndef PUBLIC_SERVER -# include "font.h" -# include "image.h" -# include "layer.h" -# include "radar.h" - -# ifndef NO_SOUND -# include "sound.h" -# endif +#include "font.h" +#include "image.h" +#include "layer.h" +#include "radar.h" -# include "world.h" -#endif +#ifndef NO_SOUND +#include "sound.h" +#endif /* NO_SOUND */ -#ifdef PUBLIC_SERVER -# include "publicServer.h" -#endif +#include "world.h" +#else /* PUBLIC_SERVER */ +#include "publicServer.h" +#endif /* PUBLIC_SERVER */ #ifndef PUBLIC_SERVER - static image_t *g_tux_up; static image_t *g_tux_right; static image_t *g_tux_left; static image_t *g_tux_down; static image_t *g_cross; - -#endif +#endif /* PUBLIC_SERVER */ static bool_t isTuxInit = FALSE; @@ -56,15 +51,13 @@ void tux_init() { #ifndef PUBLIC_SERVER assert(image_is_inicialized() == TRUE); -#endif -#ifndef PUBLIC_SERVER g_tux_up = image_add("tux8.png", IMAGE_ALPHA, "tux8", IMAGE_GROUP_BASE); g_tux_right = image_add("tux6.png", IMAGE_ALPHA, "tux6", IMAGE_GROUP_BASE); g_tux_left = image_add("tux4.png", IMAGE_ALPHA, "tux4", IMAGE_GROUP_BASE); g_tux_down = image_add("tux2.png", IMAGE_ALPHA, "tux2", IMAGE_GROUP_BASE); g_cross = image_add("cross.png", IMAGE_ALPHA, "cross", IMAGE_GROUP_BASE); -#endif +#endif /* PUBLIC_SERVER */ isTuxInit = TRUE; } @@ -109,13 +102,13 @@ tux_t *tux_new() return new; } -void tux_set_name(tux_t * tux, char *name) +void tux_set_name(tux_t *tux, char *name) { strcpy(tux->name, name); - //tux->g_name = getFontImage(name, COLOR_WHITE); + /*tux->g_name = getFontImage(name, COLOR_WHITE);*/ } -bool_t tux_is_any_gun(tux_t * tux) +bool_t tux_is_any_gun(tux_t *tux) { int i; @@ -155,14 +148,14 @@ void tux_get_course(int n, int *x, int *y) break; default: - assert(!_("Type variable has a really wierd value!")); + fprintf(stderr, _("[Error] Unknown direction of the tux [%d]\n"), n); + assert(0); break; } } #ifndef PUBLIC_SERVER - -void tux_draw(tux_t * tux) +void tux_draw(tux_t *tux) { image_t *g_image = NULL; @@ -192,7 +185,8 @@ void tux_draw(tux_t * tux) break; default: - assert(!_("p->control has a really wierd value!")); + fprintf(stderr, _("[Error] Unknown direction of the tux [%d]\n"), tux->position); + assert(0); break; } @@ -205,16 +199,17 @@ void tux_draw(tux_t * tux) return; } + /* - if( tux->g_name != NULL ) - { + if (tux->g_name != NULL) { addLayer(tux->g_name, - tux->x - TUX_IMG_WIDTH / 2, - ( tux->y + TUX_HEIGHT / 2 ) - TUX_IMG_HEIGHT, - 0, 0, - tux->g_name->w, tux->g_name->h, TUX_LAYER); + tux->x - TUX_IMG_WIDTH / 2, + (tux->y + TUX_HEIGHT / 2) - TUX_IMG_HEIGHT, + 0, 0, + tux->g_name->w, tux->g_name->h, TUX_LAYER); } */ + addLayer(g_image, tux->x - TUX_IMG_WIDTH / 2, (tux->y + TUX_HEIGHT / 2) - TUX_IMG_HEIGHT, (tux->frame / TUX_KEY) * TUX_IMG_WIDTH, 0, @@ -227,19 +222,18 @@ void drawListTux(list_t *listTux) tux_t *thisTux; int i; - assert( listTux != NULL ); + assert(listTux != NULL); - for( i = 0 ; i < listTux->count ; i++ ) - { - thisTux = (tux_t *)listTux->list[i]; - assert( thisTux != NULL ); + for(i = 0; i < listTux->count; i++) { + thisTux = (tux_t *) listTux->list[i]; + assert(thisTux != NULL); tux_draw(thisTux); } } */ -#endif +#endif /* PUBLIC_SERVER */ -void tux_replace_id(tux_t * tux, int id) +void tux_replace_id(tux_t *tux, int id) { id_replace(tux->id, id); tux->id = id; @@ -258,8 +252,9 @@ static void timer_spawnTux(void *p) arena = arena_get_current(); tux = space_get_object_id(arena->spaceTux, id); - if (tux == NULL) + if (tux == NULL) { return; + } tux->status = TUX_STATUS_ALIVE; arena_find_free_space(arena_get_current(), &x, &y, TUX_WIDTH, TUX_HEIGHT); @@ -283,8 +278,9 @@ static void timer_tuxCanShot(void *p) tux = space_get_object_id(arena_get_current()->spaceTux, id); - if (tux == NULL) + if (tux == NULL) { return; + } tux->isCanShot = TRUE; } @@ -299,13 +295,14 @@ static void timer_tuxCanSwitchGun(void *p) tux = space_get_object_id(arena_get_current()->spaceTux, id); - if (tux == NULL) + if (tux == NULL) { return; + } tux->isCanSwitchGun = TRUE; } -void tux_event_tux_is_dead(tux_t * tux) +void tux_event_tux_is_dead(tux_t *tux) { if (tux->status == TUX_STATUS_DEAD) { return; @@ -313,7 +310,7 @@ void tux_event_tux_is_dead(tux_t * tux) #ifndef NO_SOUND sound_play("dead", SOUND_GROUP_BASE); -#endif +#endif /* NO_SOUND */ tux->status = TUX_STATUS_DEAD; memset(tux->shot, 0, sizeof(int) * GUN_COUNT); @@ -337,7 +334,7 @@ void tux_event_tux_is_dead(tux_t * tux) } } -static void tux_event_tux_is_deadWIthShot(tux_t * tux, shot_t * shot) +static void tux_event_tux_is_deadWIthShot(tux_t *tux, shot_t *shot) { if (shot->author_id == tux->id) { tux->score--; @@ -366,18 +363,18 @@ static void tux_event_tux_is_deadWIthShot(tux_t * tux, shot_t * shot) tux_event_tux_is_dead(tux); } -void tux_teleport(tux_t * tux) +void tux_teleport(tux_t *tux) { int x, y; #ifndef NO_SOUND sound_play("teleport", SOUND_GROUP_BASE); -#endif +#endif /* NO_SOUND */ if (net_multiplayer_get_game_type() != NET_GAME_TYPE_CLIENT) { arena_find_free_space(arena_get_current(), &x, &y, TUX_WIDTH, TUX_HEIGHT); space_move_object(arena_get_current()->spaceTux, tux, x, y); - //tux_set_proportion(tux, x, y); + /*tux_set_proportion(tux, x, y);*/ } if (net_multiplayer_get_game_type() == NET_GAME_TYPE_SERVER) { @@ -385,7 +382,7 @@ void tux_teleport(tux_t * tux) } } -static void bombBallExplosion(shot_t * shot) +static void bombBallExplosion(shot_t *shot) { item_t *item; int x, y; @@ -398,15 +395,14 @@ static void bombBallExplosion(shot_t * shot) space_add(arena_get_current()->spaceItem, item); if (net_multiplayer_get_game_type() == NET_GAME_TYPE_SERVER) { - //proto_send_del_server(PROTO_SEND_ALL, NULL, shot->id); + /*proto_send_del_server(PROTO_SEND_ALL, NULL, shot->id);*/ proto_send_additem_server(PROTO_SEND_ALL, NULL, item); } - //space_del_with_item(arena_get_current()->spaceShot, shot, shot_destroy); - + /*space_del_with_item(arena_get_current()->spaceShot, shot, shot_destroy);*/ } -static void action_tux(space_t * space, tux_t * tux, shot_t * shot) +static void action_tux(space_t *space, tux_t *tux, shot_t *shot) { UNUSED(space); @@ -435,6 +431,7 @@ static void action_tux(space_t * space, tux_t * tux, shot_t * shot) } shot->del = TRUE; + /* if (net_multiplayer_get_game_type() == NET_GAME_TYPE_SERVER) { proto_send_del_server(PROTO_SEND_ALL, NULL, shot->id); @@ -444,30 +441,32 @@ static void action_tux(space_t * space, tux_t * tux, shot_t * shot) */ } -static void action_shot(space_t * space, shot_t * shot, space_t * spaceTux) +static void action_shot(space_t *space, shot_t *shot, space_t *spaceTux) { space_action_from_location(spaceTux, action_tux, shot, shot->x, shot->y, shot->w, shot->h); if (shot->del == TRUE) { - if (net_multiplayer_get_game_type() == NET_GAME_TYPE_SERVER) + if (net_multiplayer_get_game_type() == NET_GAME_TYPE_SERVER) { proto_send_del_server(PROTO_SEND_ALL, NULL, shot->id); + } space_del_with_item(space, shot, shot_destroy); } } -void tux_conflict_woth_shot(arena_t * arena) +void tux_conflict_woth_shot(arena_t *arena) { - if (net_multiplayer_get_game_type() == NET_GAME_TYPE_CLIENT) { // na skusku + /* just for a test */ + if (net_multiplayer_get_game_type() == NET_GAME_TYPE_CLIENT) { return; } space_action(arena->spaceShot, action_shot, arena->spaceTux); } -void moveTux(tux_t * tux, int n) +void moveTux(tux_t *tux, int n) { - int px = 0, py = 0; // no warninng + int px = 0, py = 0; /* no warnings */ int zal_x, zal_y; int new_x, new_y; int w, h; @@ -476,7 +475,7 @@ void moveTux(tux_t * tux, int n) assert(tux != NULL); arena = arena_get_current(); - //interval(); + /*interval();*/ if (tux->position != n) { tux->position = n; @@ -506,8 +505,8 @@ void moveTux(tux_t * tux, int n) } if (tux->bonus != BONUS_GHOST && - ( space_is_conflict_with_object_but(arena->spaceTux, new_x, new_y, w, h, tux) || - module_is_conflict(new_x, new_y, w, h))) { + (space_is_conflict_with_object_but(arena->spaceTux, new_x, new_y, w, h, tux) || + module_is_conflict(new_x, new_y, w, h))) { tux_set_proportion(tux, zal_x, zal_y); return; } @@ -517,11 +516,12 @@ void moveTux(tux_t * tux, int n) item_tux_give_list_item(tux, arena_get_current()->spaceItem); tux->frame++; - if (tux->frame == TUX_KEY * TUX_MAX_ANIMATION_FRAME) + if (tux->frame == TUX_KEY * TUX_MAX_ANIMATION_FRAME) { tux->frame = 0; + } } -void switchTuxGun(tux_t * tux) +void switchTuxGun(tux_t *tux) { int i; @@ -534,11 +534,11 @@ void switchTuxGun(tux_t * tux) tux->gun = i; tux->isCanSwitchGun = FALSE; timer_add_task(arena_get_current()->listTimer, TIMER_ONE, - timer_tuxCanSwitchGun, newInt(tux->id), - TUX_TIME_CAN_SWITCH_GUN); + timer_tuxCanSwitchGun, newInt(tux->id), + TUX_TIME_CAN_SWITCH_GUN); #ifndef NO_SOUND sound_play("switch_gun", SOUND_GROUP_BASE); -#endif +#endif /* NO_SOUND */ return; } } @@ -554,13 +554,13 @@ void switchTuxGun(tux_t * tux) #ifndef NO_SOUND sound_play("switch_gun", SOUND_GROUP_BASE); -#endif +#endif /* NO_SOUND */ return; } } } -void shotTux(tux_t * tux) +void shotTux(tux_t *tux) { assert(tux != NULL); @@ -570,7 +570,7 @@ void shotTux(tux_t * tux) #ifndef NO_SOUND sound_play("switch_gun", SOUND_GROUP_BASE); -#endif +#endif /* NO_SOUND */ gun_shot(tux); @@ -584,7 +584,7 @@ void shotTux(tux_t * tux) } } -void tux_action(tux_t * tux, int action) +void tux_action(tux_t *tux, int action) { if (tux->status == TUX_STATUS_DEAD) { return; @@ -608,7 +608,7 @@ void tux_action(tux_t * tux, int action) } } -static void pickUpGun(tux_t * tux) +static void pickUpGun(tux_t *tux) { if (tux_is_any_gun(tux) == FALSE) { tux->gun = GUN_SIMPLE; @@ -620,7 +620,7 @@ static void pickUpGun(tux_t * tux) if (tux->pickup_time == TUX_MAX_PICKUP && net_multiplayer_get_game_type() != NET_GAME_TYPE_CLIENT) { #ifndef NO_SOUND sound_play("switch_gun", SOUND_GROUP_BASE); -#endif +#endif /* NO_SOUND */ tux->gun = GUN_SIMPLE; tux->shot[tux->gun] = GUN_MAX_SHOT; @@ -633,7 +633,7 @@ static void pickUpGun(tux_t * tux) } } -static void eventBonus(tux_t * tux) +static void eventBonus(tux_t *tux) { if (tux->bonus != BONUS_NONE) { if (tux->bonus_time > 0) { @@ -647,8 +647,8 @@ static void eventBonus(tux_t * tux) tux->bonus = BONUS_NONE; - if ( /*isConflictTuxWithListTux(tux, arena_get_current()->listTux) || */ - module_is_conflict(x, y, w, h)) { + if (/*isConflictTuxWithListTux(tux, arena_get_current()->listTux) ||*/ + module_is_conflict(x, y, w, h)) { tux->bonus = BONUS_GHOST; return; } @@ -663,7 +663,7 @@ static void eventBonus(tux_t * tux) } } -void tux_event(tux_t * tux) +void tux_event(tux_t *tux) { arena_t *arena; @@ -671,7 +671,7 @@ void tux_event(tux_t * tux) #ifndef PUBLIC_SERVER world_tux_control(tux); -#endif +#endif /* PUBLIC_SERVER */ pickUpGun(tux); eventBonus(tux); item_tux_give_list_item(tux, arena->spaceItem); @@ -683,34 +683,38 @@ void eventListTux(list_t *listTux) tux_t *thisTux; int i; - assert( listTux != NULL ); + assert(listTux != NULL); - for( i = 0 ; i < listTux->count ; i++ ) - { - thisTux = (tux_t *)listTux->list[i]; - assert( thisTux != NULL ); + for (i = 0; i < listTux->count; i++) { + thisTux = (tux_t *) listTux->list[i]; + assert(thisTux != NULL); tux_event(thisTux); } } */ -void tux_get_proportion(tux_t * tux, int *x, int *y, int *w, int *h) + +void tux_get_proportion(tux_t *tux, int *x, int *y, int *w, int *h) { assert(tux != NULL); - if (x != NULL) + if (x != NULL) { *x = tux->x - TUX_WIDTH / 2; + } - if (y != NULL) + if (y != NULL) { *y = tux->y - TUX_HEIGHT / 2; + } - if (w != NULL) + if (w != NULL) { *w = TUX_WIDTH; + } - if (h != NULL) + if (h != NULL) { *h = TUX_HEIGHT; + } } -void tux_set_proportion(tux_t * tux, int x, int y) +void tux_set_proportion(tux_t *tux, int x, int y) { assert(tux != NULL); @@ -738,7 +742,7 @@ void tux_set_status(void *p, int x, int y, int w, int h) tux_set_proportion(tux, x, y); } -static void action_checkMine(space_t * space, item_t * item, tux_t * tux) +static void action_checkMine(space_t *space, item_t *item, tux_t *tux) { UNUSED(space); @@ -747,7 +751,7 @@ static void action_checkMine(space_t * space, item_t * item, tux_t * tux) } } -void tux_destroy(tux_t * tux) +void tux_destroy(tux_t *tux) { arena_t *arena; diff --git a/src/base/udp_server.c b/src/base/udp_server.c index 5033162..01aa081 100644 --- a/src/base/udp_server.c +++ b/src/base/udp_server.c @@ -9,13 +9,13 @@ #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 <sys/ioctl.h> +#include <sys/socket.h> +#include <sys/select.h> +#else /* __WIN32__ */ +#include <io.h> +#include <winsock2.h> +#endif /* __WIN32__ */ #include "main.h" #include "list.h" @@ -30,14 +30,12 @@ #include "index.h" #ifndef PUBLIC_SERVER -# include "world.h" -#endif - -#ifdef PUBLIC_SERVER -# include "publicServer.h" -# include "highScore.h" -# include "log.h" -#endif +#include "world.h" +#else /* PUBLIC_SERVER */ +#include "publicServer.h" +#include "highScore.h" +#include "log.h" +#endif /* PUBLIC_SERVER */ #include "udp.h" #include "udp_server.h" @@ -46,7 +44,7 @@ static sock_udp_t *sock_server_udp; static sock_udp_t *sock_server_udp_second; -client_t *server_udp_new_client(sock_udp_t * sock_udp) +client_t *server_udp_new_client(sock_udp_t *sock_udp) { client_t *new; @@ -61,14 +59,14 @@ client_t *server_udp_new_client(sock_udp_t * sock_udp) char str_ip[STR_IP_SIZE]; sock_udp_get_ip(sock_udp, str_ip, STR_IP_SIZE); - sprintf(str_log, _("New client \"%s\" on port \"%d\" connected"), str_ip, sock_udp_get_port(sock_udp)); + sprintf(str_log, _("New player [%s]:%d connected"), str_ip, sock_udp_get_port(sock_udp)); log_add(LOG_INF, str_log); -#endif +#endif /* PUBLIC_SERVER */ return new; } -void server_udp_destroy_client(client_t * p) +void server_udp_destroy_client(client_t *p) { check_front_event(p); @@ -77,9 +75,9 @@ void server_udp_destroy_client(client_t * p) char str_ip[STR_IP_SIZE]; sock_udp_get_ip(p->socket_udp, str_ip, STR_IP_SIZE); - sprintf(str_log, _("Client \"%s\" on port \"%d\" disconnected"), str_ip, sock_udp_get_port(p->socket_udp)); + sprintf(str_log, _("Player [%s]:%d disconnected"), str_ip, sock_udp_get_port(p->socket_udp)); log_add(LOG_INF, str_log); -#endif +#endif /* PUBLIC_SERVER */ sock_udp_destroy(p->socket_udp); @@ -97,9 +95,9 @@ int server_udp_init(char *ip4, int port4, char *ip6, int port6) if (sock_server_udp != NULL) { ret++; - DEBUG_MSG(_("Starting server: \"%s\" on port: \"%d\"\n"), ip4, port4); + DEBUG_MSG(_("[Debug] Starting server on [%s]:%d\n"), ip4, port4); } else { - DEBUG_MSG(_("Starting server: \"%s\" on port: \"%d\" FAILED!\n"), ip4, port4); + DEBUG_MSG(_("[Error] Unable to start server on [%s]:%d\n"), ip4, port4); } } @@ -108,16 +106,16 @@ int server_udp_init(char *ip4, int port4, char *ip6, int port6) if (sock_server_udp_second != NULL) { ret++; - DEBUG_MSG(_("Starting server: \"%s\" on port: \"%d\"\n"), ip6, port6); + DEBUG_MSG(_("[Debug] Starting server on [%s]:%d\n"), ip6, port6); } else { - DEBUG_MSG(_("Starting server: \"%s\" on port: \"%d\" FAILED!\n"), ip6, port6); + DEBUG_MSG(_("[Error] Unable to start server on [%s]:%d\n"), ip6, port6); } } return ret; } -static void eventCreateNewUdpClient(sock_udp_t * socket_udp) +static void eventCreateNewUdpClient(sock_udp_t *socket_udp) { list_t *listClient; client_t *client; @@ -130,7 +128,7 @@ static void eventCreateNewUdpClient(sock_udp_t * socket_udp) list_add(listClient, client); } -static client_t *findUdpClient(sock_udp_t * sock_udp) +static client_t *findUdpClient(sock_udp_t *sock_udp) { list_t *listClient; int port; @@ -153,7 +151,7 @@ static client_t *findUdpClient(sock_udp_t * sock_udp) return NULL; } -static void client_eventUdpSelect(sock_udp_t * sock_server) +static void client_eventUdpSelect(sock_udp_t *sock_server) { sock_udp_t *sock_client; client_t *client; @@ -179,7 +177,7 @@ static void client_eventUdpSelect(sock_udp_t * sock_server) } if (client == NULL) { - fprintf(stderr, _("Client was not FOUND!\n")); + fprintf(stderr, _("[Error] UDP client not found\n")); return; } @@ -192,7 +190,7 @@ static void client_eventUdpSelect(sock_udp_t * sock_server) return; } - //printf("add packet >>%s<<\n", listRecvMsg); + /*printf("add packet >>%s<<\n", listRecvMsg);*/ list_add(client->listRecvMsg, strdup(listRecvMsg)); } @@ -232,15 +230,15 @@ int server_udp_select_sock() void server_udp_quit() { + DEBUG_MSG(_("[Debug] Shutting down UDP\n")); + if (sock_server_udp != NULL) { - DEBUG_MSG(_("Closing port: \"%d\"\n"), sock_udp_get_port(sock_server_udp)); + DEBUG_MSG(_("[Debug] Closing IPv4 [port %d]\n"), sock_udp_get_port(sock_server_udp)); sock_udp_close(sock_server_udp); } if (sock_server_udp_second != NULL) { - DEBUG_MSG(_("Closing port: \"%d\"\n"), sock_udp_get_port(sock_server_udp_second)); + DEBUG_MSG(_("[Debug] Closing IPv6 [port %d]\n"), sock_udp_get_port(sock_server_udp)); sock_udp_close(sock_server_udp_second); } - - DEBUG_MSG(_("Quitting UDP\n")); } |