diff options
| author | Tomas Chvatal (scarabeus) <tomas.chvatal@gmail.com> | 2008-10-22 22:53:48 +0200 |
|---|---|---|
| committer | Tomas Chvatal (scarabeus) <tomas.chvatal@gmail.com> | 2008-10-22 22:53:48 +0200 |
| commit | 130d45bfc935da1702a7b5c246a099ea3b4a0bdf (patch) | |
| tree | 5cc4b029f24e7a3cfaf1fcbc671772059a9b8e73 /src/base | |
| parent | 44daf03024fbf7cbffa10349044786f6ab784821 (diff) | |
Ident all code correctly.
Diffstat (limited to 'src/base')
| -rw-r--r-- | src/base/archive.c | 81 | ||||
| -rw-r--r-- | src/base/arena.c | 607 | ||||
| -rw-r--r-- | src/base/arenaFile.c | 432 | ||||
| -rwxr-xr-x | src/base/buffer.c | 184 | ||||
| -rw-r--r-- | src/base/checkFront.c | 160 | ||||
| -rwxr-xr-x | src/base/director.c | 74 | ||||
| -rw-r--r-- | src/base/gun.c | 407 | ||||
| -rwxr-xr-x | src/base/homeDirector.c | 40 | ||||
| -rw-r--r-- | src/base/idManager.c | 247 | ||||
| -rw-r--r-- | src/base/index.c | 347 | ||||
| -rw-r--r-- | src/base/item.c | 780 | ||||
| -rwxr-xr-x | src/base/list.c | 245 | ||||
| -rw-r--r-- | src/base/main.c | 191 | ||||
| -rwxr-xr-x | src/base/modules.c | 388 | ||||
| -rw-r--r-- | src/base/myTimer.c | 191 | ||||
| -rw-r--r-- | src/base/net_multiplayer.c | 182 | ||||
| -rw-r--r-- | src/base/protect.c | 96 | ||||
| -rw-r--r-- | src/base/proto.c | 1247 | ||||
| -rw-r--r-- | src/base/server.c | 454 | ||||
| -rw-r--r-- | src/base/serverSelect.c | 102 | ||||
| -rw-r--r-- | src/base/serverSendMsg.c | 213 | ||||
| -rw-r--r-- | src/base/shareFunction.c | 64 | ||||
| -rw-r--r-- | src/base/shot.c | 514 | ||||
| -rw-r--r-- | src/base/space.c | 587 | ||||
| -rw-r--r-- | src/base/storage.c | 182 | ||||
| -rw-r--r-- | src/base/tcp_server.c | 372 | ||||
| -rwxr-xr-x | src/base/textFile.c | 215 | ||||
| -rw-r--r-- | src/base/tux.c | 963 | ||||
| -rw-r--r-- | src/base/udp_server.c | 326 |
29 files changed, 5057 insertions, 4834 deletions
diff --git a/src/base/archive.c b/src/base/archive.c index ac57721..7311930 100644 --- a/src/base/archive.c +++ b/src/base/archive.c @@ -10,64 +10,63 @@ #define ARCHIVE_BUFFER_SIZE 1024 #define STR_TMP_FILE_NAME 4096 -char *extractFileFromArchive(char *archive, char *filename) +char * +extractFileFromArchive(char *archive, char *filename) { - char buf[ARCHIVE_BUFFER_SIZE]; - char archive_name[STR_TMP_FILE_NAME]; - char name[STR_TMP_FILE_NAME]; + char buf[ARCHIVE_BUFFER_SIZE]; + char archive_name[STR_TMP_FILE_NAME]; + char name[STR_TMP_FILE_NAME]; - ZZIP_FILE *zip_file; - FILE *file; - zzip_ssize_t len; + ZZIP_FILE *zip_file; + FILE *file; + zzip_ssize_t len; - strcpy(archive_name, archive); - sprintf(strrchr(archive_name, '.'), "/%s", filename); + strcpy(archive_name, archive); + sprintf(strrchr(archive_name, '.'), "/%s", filename); - sprintf(name,"/tmp/tuxanci%d-%s", getpid(), filename); + sprintf(name, "/tmp/tuxanci%d-%s", getpid(), filename); - if( (zip_file = zzip_open(archive_name, O_RDONLY)) == NULL ) - { - fprintf(stderr, "No do not open %s archive\n", archive_name); - return NULL; - } + if ((zip_file = zzip_open(archive_name, O_RDONLY)) == NULL) { + fprintf(stderr, "No do not open %s archive\n", archive_name); + return NULL; + } - if( (file = fopen(name, "wb")) == NULL ) - { - fprintf(stderr, "No do not create temp file %s\n", name); - return NULL; - } + if ((file = fopen(name, "wb")) == NULL) { + fprintf(stderr, "No do not create temp file %s\n", name); + return NULL; + } - do{ - len = zzip_read(zip_file, buf, ARCHIVE_BUFFER_SIZE); - //printf("len = %d\n", len); + do { + len = zzip_read(zip_file, buf, ARCHIVE_BUFFER_SIZE); + //printf("len = %d\n", len); - if( len > 0 ) - { - fwrite(buf, len, 1, file); - } - }while( len > 0 ); + if (len > 0) { + fwrite(buf, len, 1, file); + } + } while (len > 0); - zzip_close(zip_file); - fclose(file); + zzip_close(zip_file); + fclose(file); - return strdup(name); + return strdup(name); } -void deleteExtractFile(char *s) +void +deleteExtractFile(char *s) { - unlink(s); - free(s); + unlink(s); + free(s); } #if ARCHIVE_TEST -int main() +int +main() { - char *name; + char *name; - name = extractFileFromArchive("hello/a/b/hello"); - printf("name = %s\n", name); - deleteExtractFile(name); - return 0; + name = extractFileFromArchive("hello/a/b/hello"); + printf("name = %s\n", name); + deleteExtractFile(name); + return 0; } #endif - diff --git a/src/base/arena.c b/src/base/arena.c index d8715e6..8237a72 100644 --- a/src/base/arena.c +++ b/src/base/arena.c @@ -22,417 +22,428 @@ static arena_t *currentArena; static int splitType; -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; - } - else - { - return 0; - } + if (arena->w > WINDOW_SIZE_X || arena->h > WINDOW_SIZE_Y) { + return 1; + } + else { + return 0; + } } -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 ) - { - return 1; - } + if (abs(tux1->x - tux2->x) < WINDOW_SIZE_X && + abs(tux1->y - tux2->y) < WINDOW_SIZE_Y) { + return 1; + } - return 0; + return 0; } -void setCurrentArena(arena_t *p) +void +setCurrentArena(arena_t * p) { - currentArena = p; + currentArena = p; } -arena_t* getCurrentArena() +arena_t * +getCurrentArena() { - return currentArena; + return currentArena; } -void hotkey_splitArena() +void +hotkey_splitArena() { - if( splitType == SCREEN_SPLIT_VERTICAL ) - { - splitType = SCREEN_SPLIT_HORIZONTAL; - } - else - { - splitType = SCREEN_SPLIT_VERTICAL; - } + if (splitType == SCREEN_SPLIT_VERTICAL) { + splitType = SCREEN_SPLIT_HORIZONTAL; + } + else { + splitType = SCREEN_SPLIT_VERTICAL; + } } #ifndef PUBLIC_SERVER -void initArena() +void +initArena() { - splitType = SCREEN_SPLIT_VERTICAL; + splitType = SCREEN_SPLIT_VERTICAL; - if( getParam("--split-vertical") ) - { - splitType = SCREEN_SPLIT_VERTICAL; - printf("SCREEN_SPLIT_VERTICAL\n"); - } + if (getParam("--split-vertical")) { + splitType = SCREEN_SPLIT_VERTICAL; + printf("SCREEN_SPLIT_VERTICAL\n"); + } - if( getParam("--split-horizontal") ) - { - splitType = SCREEN_SPLIT_HORIZONTAL; - printf("SCREEN_SPLIT_HORIZONTAL\n"); - } + if (getParam("--split-horizontal")) { + splitType = SCREEN_SPLIT_HORIZONTAL; + printf("SCREEN_SPLIT_HORIZONTAL\n"); + } - registerHotKey(SDLK_F3, hotkey_splitArena); + registerHotKey(SDLK_F3, hotkey_splitArena); } -void quitArena() +void +quitArena() { - unregisterHotKey(SDLK_F3); + unregisterHotKey(SDLK_F3); } #endif -arena_t* newArena(int w, int h) +arena_t * +newArena(int w, int h) { - arena_t *new; - int zone_w, zone_h; + arena_t *new; + int zone_w, zone_h; + + new = malloc(sizeof(arena_t)); - new = malloc( sizeof(arena_t) ); - #ifndef PUBLIC_SERVER - new->background = NULL; - strcpy(new->music, ""); + new->background = NULL; + strcpy(new->music, ""); #endif - new->w = w; - new->h = h; + new->w = w; + new->h = h; - new->listTimer = newList(); + new->listTimer = newList(); - if( w > 800 || h > 600 ) - { - zone_w = 320; - zone_h = 240; - } - else - { - zone_w = 80; - zone_h = 60; - } + if (w > 800 || h > 600) { + zone_w = 320; + zone_h = 240; + } + else { + zone_w = 80; + zone_h = 60; + } - new->spaceTux = newSpace(w, h, zone_w, zone_h, getStatusTux, setStatusTux); - new->spaceItem = newSpace(w, h, zone_w, zone_h, getStatusItem, setStatusItem); - new->spaceShot = newSpace(w, h, zone_w, zone_h, getStatusShot, setStatusShot); + new->spaceTux = + newSpace(w, h, zone_w, zone_h, getStatusTux, setStatusTux); + new->spaceItem = + newSpace(w, h, zone_w, zone_h, getStatusItem, setStatusItem); + new->spaceShot = + newSpace(w, h, zone_w, zone_h, getStatusShot, setStatusShot); - new->countRound = 0; - new->max_countRound = 0; + new->countRound = 0; + new->max_countRound = 0; - return new; + return new; } -int conflictSpace(int x1,int y1,int w1,int h1,int x2,int y2,int w2,int h2) +int +conflictSpace(int x1, int y1, int w1, int h1, int x2, int y2, int w2, int h2) { - return (x1<x2+w2 && x2<x1+w1 && y1<y2+h2 && y2<y1+h1); + return (x1 < x2 + w2 && x2 < x1 + w1 && y1 < y2 + h2 && y2 < y1 + h1); } -int isFreeSpace(arena_t *arena, int x, int y, int w, int h) +int +isFreeSpace(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( isConflictWithObjectFromSpace(arena->spaceTux, x, y, w, h) )return 0; - if( isConflictWithObjectFromSpace(arena->spaceShot, x, y, w, h) )return 0; - if( isConflictWithObjectFromSpace(arena->spaceItem, x, y, w, h) )return 0; - if( isConflictWithObjectFromSpace(arena->spaceShot, x, y, w, h) )return 0; - - if( isConflictModule(x, y, w, h) )return 0; - - return 1; + if (x < 0 || y < 0 || x + w > arena->w || y + h > arena->h) { + return 0; + } + + if (isConflictWithObjectFromSpace(arena->spaceTux, x, y, w, h)) + return 0; + if (isConflictWithObjectFromSpace(arena->spaceShot, x, y, w, h)) + return 0; + if (isConflictWithObjectFromSpace(arena->spaceItem, x, y, w, h)) + return 0; + if (isConflictWithObjectFromSpace(arena->spaceShot, x, y, w, h)) + return 0; + + if (isConflictModule(x, y, w, h)) + return 0; + + return 1; } -void findFreeSpace(arena_t *arena, int *x, int *y, int w, int h) +void +findFreeSpace(arena_t * arena, int *x, int *y, int w, int h) { - int z_x; - int z_y; + int z_x; + int z_y; - assert( x != NULL ); - assert( y != NULL ); + assert(x != NULL); + assert(y != NULL); - do{ - z_x = random() % (arena->w-w); - z_y = random() % (arena->h-h); - }while( isFreeSpace(arena, z_x, z_y ,w ,h) == 0 ); + do { + z_x = random() % (arena->w - w); + z_y = random() % (arena->h - h); + } while (isFreeSpace(arena, z_x, z_y, w, h) == 0); - *x = z_x; - *y = z_y; + *x = z_x; + *y = z_y; } -void getCenterScreen(int *screen_x, int *screen_y, int x, int y, int screen_size_x, int screen_size_y) +void +getCenterScreen(int *screen_x, int *screen_y, int x, int y, int screen_size_x, + int screen_size_y) { - arena_t *arena; + arena_t *arena; - arena = getCurrentArena(); + arena = getCurrentArena(); - *screen_x = x - screen_size_x/2; - *screen_y = y - screen_size_y/2; + *screen_x = x - screen_size_x / 2; + *screen_y = y - screen_size_y / 2; - if( *screen_x < 0 ) - { - *screen_x = 0; - } + if (*screen_x < 0) { + *screen_x = 0; + } - if( *screen_y < 0 ) - { - *screen_y = 0; - } + if (*screen_y < 0) { + *screen_y = 0; + } - if( *screen_x + screen_size_x >= arena->w ) - { - *screen_x = arena->w - screen_size_x; - } + if (*screen_x + screen_size_x >= arena->w) { + *screen_x = arena->w - screen_size_x; + } - if( *screen_y + screen_size_y >= arena->h ) - { - *screen_y = arena->h - screen_size_y; - } + if (*screen_y + screen_size_y >= arena->h) { + *screen_y = arena->h - screen_size_y; + } } #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++ ) - { - for( j = screen_x/arena->background->w ; - 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++; - } - } - } - else - { - addLayer(arena->background, - 0, 0, - 0, 0, - arena->background->w, arena->background->h, -100); - } + 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++) { + for (j = screen_x / arena->background->w; + 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++; + } + } + } + else { + addLayer(arena->background, + 0, 0, + 0, 0, arena->background->w, arena->background->h, -100); + } } -static void action_drawTux(space_t *space, tux_t *tux, void *p) +static void +action_drawTux(space_t * space, tux_t * tux, void *p) { - drawTux(tux); + drawTux(tux); } -static void action_drawItem(space_t *space, item_t *item, void *p) +static void +action_drawItem(space_t * space, item_t * item, void *p) { - drawItem(item); + drawItem(item); } -static void action_drawShot(space_t *space, shot_t *shot, void *p) +static void +action_drawShot(space_t * space, shot_t * shot, void *p) { - drawShot(shot); + drawShot(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) { - actionSpaceFromLocation(arena->spaceTux, action_drawTux, NULL, - screen_x, screen_y, WINDOW_SIZE_X, WINDOW_SIZE_Y); + actionSpaceFromLocation(arena->spaceTux, action_drawTux, NULL, + screen_x, screen_y, WINDOW_SIZE_X, WINDOW_SIZE_Y); - actionSpaceFromLocation(arena->spaceItem, action_drawItem, NULL, - screen_x, screen_y, WINDOW_SIZE_X, WINDOW_SIZE_Y); + actionSpaceFromLocation(arena->spaceItem, action_drawItem, NULL, + screen_x, screen_y, WINDOW_SIZE_X, WINDOW_SIZE_Y); - actionSpaceFromLocation(arena->spaceShot, action_drawShot, NULL, - screen_x, screen_y, WINDOW_SIZE_X, WINDOW_SIZE_Y); + actionSpaceFromLocation(arena->spaceShot, action_drawShot, NULL, + screen_x, screen_y, WINDOW_SIZE_X, WINDOW_SIZE_Y); - drawModule(screen_x, screen_y, WINDOW_SIZE_X, WINDOW_SIZE_Y); + drawModule(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; - - switch( splitType ) - { - case SCREEN_SPLIT_HORIZONTAL : - getCenterScreen(&screen_x, &screen_y, tux->x, tux->y, WINDOW_SIZE_X, WINDOW_SIZE_Y/2); - break; - case SCREEN_SPLIT_VERTICAL : - getCenterScreen(&screen_x, &screen_y, tux->x, tux->y, WINDOW_SIZE_X/2, WINDOW_SIZE_Y); - break; - default : - screen_x = -1; - screen_y = -1; - assert( ! "stupd error "); - break; - } - - drawBackground(arena, screen_x, screen_y); - drawObjects(arena, screen_x, screen_y); - - switch( splitType ) - { - case SCREEN_SPLIT_HORIZONTAL : - drawLayerSplit(location_x, location_y, screen_x, screen_y, WINDOW_SIZE_X, WINDOW_SIZE_Y/2); - break; - case SCREEN_SPLIT_VERTICAL : - drawLayerSplit(location_x, location_y, screen_x, screen_y, WINDOW_SIZE_X/2, WINDOW_SIZE_Y); - break; - default : - screen_x = -1; - screen_y = -1; - assert( ! "stupd error "); - break; - } + int screen_x, screen_y; + + switch (splitType) { + case SCREEN_SPLIT_HORIZONTAL: + getCenterScreen(&screen_x, &screen_y, tux->x, tux->y, WINDOW_SIZE_X, + WINDOW_SIZE_Y / 2); + break; + case SCREEN_SPLIT_VERTICAL: + getCenterScreen(&screen_x, &screen_y, tux->x, tux->y, + WINDOW_SIZE_X / 2, WINDOW_SIZE_Y); + break; + default: + screen_x = -1; + screen_y = -1; + assert(!"stupd error "); + break; + } + + drawBackground(arena, screen_x, screen_y); + drawObjects(arena, screen_x, screen_y); + + switch (splitType) { + case SCREEN_SPLIT_HORIZONTAL: + drawLayerSplit(location_x, location_y, screen_x, screen_y, + WINDOW_SIZE_X, WINDOW_SIZE_Y / 2); + break; + case SCREEN_SPLIT_VERTICAL: + drawLayerSplit(location_x, location_y, screen_x, screen_y, + WINDOW_SIZE_X / 2, WINDOW_SIZE_Y); + break; + default: + screen_x = -1; + screen_y = -1; + assert(!"stupd error "); + break; + } } -void drawSplitArena(arena_t *arena) +void +drawSplitArena(arena_t * arena) { - tux_t *tux = NULL; - - tux = getControlTux(TUX_CONTROL_KEYBOARD_RIGHT); - - if( tux != NULL ) - { - switch( splitType ) - { - case SCREEN_SPLIT_HORIZONTAL : - drawSplitArenaForTux(arena, tux, 0, WINDOW_SIZE_Y/2); - break; - case SCREEN_SPLIT_VERTICAL : - drawSplitArenaForTux(arena, tux, WINDOW_SIZE_X/2, 0); - break; - } - } - - tux = getControlTux(TUX_CONTROL_KEYBOARD_LEFT); - - if( tux != NULL ) - { - drawSplitArenaForTux(arena, tux, 0, 0); - } + tux_t *tux = NULL; + + tux = getControlTux(TUX_CONTROL_KEYBOARD_RIGHT); + + if (tux != NULL) { + switch (splitType) { + case SCREEN_SPLIT_HORIZONTAL: + drawSplitArenaForTux(arena, tux, 0, WINDOW_SIZE_Y / 2); + break; + case SCREEN_SPLIT_VERTICAL: + drawSplitArenaForTux(arena, tux, WINDOW_SIZE_X / 2, 0); + break; + } + } + + tux = getControlTux(TUX_CONTROL_KEYBOARD_LEFT); + + if (tux != NULL) { + drawSplitArenaForTux(arena, tux, 0, 0); + } } -void drawCenterArena(arena_t *arena, int x, int y) +void +drawCenterArena(arena_t * arena, int x, int y) { - int screen_x, screen_y; + int screen_x, screen_y; - getCenterScreen(&screen_x, &screen_y, x, y, WINDOW_SIZE_X, WINDOW_SIZE_Y); - drawBackground(arena, screen_x, screen_y); - drawObjects(arena, screen_x, screen_y); - drawLayerCenter(x, y); + getCenterScreen(&screen_x, &screen_y, x, y, WINDOW_SIZE_X, WINDOW_SIZE_Y); + drawBackground(arena, screen_x, screen_y); + drawObjects(arena, screen_x, screen_y); + drawLayerCenter(x, y); } -void drawSimpleArena(arena_t *arena) +void +drawSimpleArena(arena_t * arena) { - int screen_x, screen_y; - tux_t *tux = NULL; + int screen_x, screen_y; + tux_t *tux = NULL; - tux = getControlTux(TUX_CONTROL_KEYBOARD_RIGHT); + tux = getControlTux(TUX_CONTROL_KEYBOARD_RIGHT); - if( tux == NULL ) - { - return; - } + if (tux == NULL) { + return; + } - screen_x = 0; - screen_y = 0; + screen_x = 0; + screen_y = 0; - drawBackground(arena, screen_x, screen_y); - drawObjects(arena, screen_x, screen_y); - drawLayer(tux->x, tux->y); + drawBackground(arena, screen_x, screen_y); + drawObjects(arena, screen_x, screen_y); + drawLayer(tux->x, tux->y); } -void drawArena(arena_t *arena) +void +drawArena(arena_t * arena) { - if( isBigArena(arena) && - getNetTypeGame() == NET_GAME_TYPE_NONE && - ! isSettingAI() ) - { - tux_t *tux1; - tux_t *tux2; - - tux1 = getControlTux(TUX_CONTROL_KEYBOARD_RIGHT); - tux2 = getControlTux(TUX_CONTROL_KEYBOARD_LEFT); - - if( isTuxNear(tux1, tux2) ) - { - drawCenterArena(arena, (tux1->x + tux2->x)/2, (tux1->y + tux2->y)/2); - } - else - { - drawSplitArena(arena); - } - - return; - } - - if( isBigArena(arena) ) - { - tux_t *tux = NULL; - - tux = getControlTux(TUX_CONTROL_KEYBOARD_RIGHT); - - if( tux == NULL ) - { - return; - } - - drawCenterArena(arena, tux->x, tux->y); - return; - } - - drawSimpleArena(arena); + if (isBigArena(arena) && + getNetTypeGame() == NET_GAME_TYPE_NONE && !isSettingAI()) { + tux_t *tux1; + tux_t *tux2; + + tux1 = getControlTux(TUX_CONTROL_KEYBOARD_RIGHT); + tux2 = getControlTux(TUX_CONTROL_KEYBOARD_LEFT); + + if (isTuxNear(tux1, tux2)) { + drawCenterArena(arena, (tux1->x + tux2->x) / 2, + (tux1->y + tux2->y) / 2); + } + else { + drawSplitArena(arena); + } + + return; + } + + if (isBigArena(arena)) { + tux_t *tux = NULL; + + tux = getControlTux(TUX_CONTROL_KEYBOARD_RIGHT); + + if (tux == NULL) { + return; + } + + drawCenterArena(arena, tux->x, tux->y); + return; + } + + drawSimpleArena(arena); } #endif -static void action_tux(space_t *space, tux_t *tux, void *p) +static void +action_tux(space_t * space, tux_t * tux, void *p) { - eventTux(tux); + eventTux(tux); } -void eventArena(arena_t *arena) +void +eventArena(arena_t * arena) { - int i; + int i; + + for (i = 0; i < 8; i++) { + checkShotIsInTuxScreen(arena); - for( i = 0 ; i < 8 ; i++) - { - checkShotIsInTuxScreen(arena); + eventConflictShotWithItem(arena); + eventConflictTuxWithShot(arena); + eventModule(); - eventConflictShotWithItem(arena); - eventConflictTuxWithShot(arena); - eventModule(); + eventMoveListShot(arena); + } - eventMoveListShot(arena); - } + eventListItem(arena->spaceItem); - eventListItem(arena->spaceItem); - - actionSpace(arena->spaceTux, action_tux, NULL); + actionSpace(arena->spaceTux, action_tux, NULL); - eventTimer(arena->listTimer); + eventTimer(arena->listTimer); } -void destroyArena(arena_t *p) +void +destroyArena(arena_t * p) { - destroySpaceWithObject(p->spaceTux, destroyTux); - destroySpaceWithObject(p->spaceItem, destroyItem); - destroySpaceWithObject(p->spaceShot, destroyShot); - destroyTimer(p->listTimer); - free(p); + destroySpaceWithObject(p->spaceTux, destroyTux); + destroySpaceWithObject(p->spaceItem, destroyItem); + destroySpaceWithObject(p->spaceShot, destroyShot); + destroyTimer(p->listTimer); + free(p); } diff --git a/src/base/arenaFile.c b/src/base/arenaFile.c index 10b4449..3a1ff59 100644 --- a/src/base/arenaFile.c +++ b/src/base/arenaFile.c @@ -29,321 +29,343 @@ static list_t *listArenaFile; static bool_t isArenaFileInit = FALSE; -bool_t isAreaFileInicialized() +bool_t +isAreaFileInicialized() { - return isArenaFileInit; + return isArenaFileInit; } -int getArenaValue(char *line, char *env, char *val, int len) +int +getArenaValue(char *line, char *env, char *val, int len) { - char *offset_env; - char *offset_val_begin; - char *offset_val_end; - char clone_env[STR_SIZE]; - int val_len; - - strcpy(clone_env, " "); - strcat(clone_env, env); - offset_env = strstr(line, clone_env); - if (offset_env == NULL) - return -1; - offset_val_begin = strchr(offset_env, '"'); - if (offset_val_begin == NULL) - return -1; - offset_val_end = strchr(offset_val_begin+1, '"'); - if (offset_val_end == NULL) - return -1; - val_len = (int)(offset_val_end - (offset_val_begin + 1)); - if (val_len > len - 1) - val_len = len - 1; - memset(val, 0, len); - memcpy(val, offset_val_begin+1, val_len); - return 0; + char *offset_env; + char *offset_val_begin; + char *offset_val_end; + char clone_env[STR_SIZE]; + int val_len; + + strcpy(clone_env, " "); + strcat(clone_env, env); + offset_env = strstr(line, clone_env); + if (offset_env == NULL) + return -1; + offset_val_begin = strchr(offset_env, '"'); + if (offset_val_begin == NULL) + return -1; + offset_val_end = strchr(offset_val_begin + 1, '"'); + if (offset_val_end == NULL) + return -1; + val_len = (int) (offset_val_end - (offset_val_begin + 1)); + if (val_len > len - 1) + val_len = len - 1; + memset(val, 0, len); + memcpy(val, offset_val_begin + 1, val_len); + return 0; } #ifndef PUBLIC_SERVER -image_t* loadImageFromArena(arenaFile_t *arenaFile, char *filename, char *group, char *name, int alpha) +image_t * +loadImageFromArena(arenaFile_t * arenaFile, char *filename, char *group, + char *name, int alpha) { - char *extractFile; - image_t *image; + char *extractFile; + image_t *image; - extractFile = extractFileFromArchive(arenaFile->path, filename); - image = addImageData(extractFile, alpha, name, group); - deleteExtractFile(extractFile); + extractFile = extractFileFromArchive(arenaFile->path, filename); + image = addImageData(extractFile, alpha, name, group); + deleteExtractFile(extractFile); - return image; + return image; } #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; + char *extractFile; - extractFile = extractFileFromArchive(arenaFile->path, filename); - addMusic(extractFile, name, group); - deleteExtractFile(extractFile); + extractFile = extractFileFromArchive(arenaFile->path, filename); + addMusic(extractFile, name, group); + deleteExtractFile(extractFile); } #endif #endif -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 (getArenaValue(line, "background", str_image, STR_SIZE) != 0) - return; - if (getArenaValue(line, "w", str_w, STR_SIZE) != 0) - return; - if (getArenaValue(line, "h", str_h, STR_SIZE) != 0) - return; - (*arena) = newArena(atoi(str_w), atoi(str_h)); + char str_image[STR_SIZE]; + char str_w[STR_SIZE]; + char str_h[STR_SIZE]; + + if (getArenaValue(line, "background", str_image, STR_SIZE) != 0) + return; + if (getArenaValue(line, "w", str_w, STR_SIZE) != 0) + return; + if (getArenaValue(line, "h", str_h, STR_SIZE) != 0) + return; + (*arena) = newArena(atoi(str_w), atoi(str_h)); #ifndef PUBLIC_SERVER - (*arena)->background = getImage(IMAGE_GROUP_USER, str_image); + (*arena)->background = getImage(IMAGE_GROUP_USER, str_image); #endif - //(*arena)->w = atoi(str_w); - //(*arena)->h = atoi(str_h); - setCurrentArena(*arena); + //(*arena)->w = atoi(str_w); + //(*arena)->h = atoi(str_h); + setCurrentArena(*arena); #ifdef DEBUG - printf(_("Loaded new arena...\n")); + printf(_("Loaded new arena...\n")); #endif } -static void cmd_loadModule(char *line) +static void +cmd_loadModule(char *line) { - char str_file[STR_SIZE]; + char str_file[STR_SIZE]; - if (getArenaValue(line, "file", str_file, STR_SIZE) != 0) - return; - loadModule(str_file); + if (getArenaValue(line, "file", str_file, STR_SIZE) != 0) + return; + loadModule(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 (getArenaValue(line, "file", str_file, STR_SIZE) != 0) - return; - if (getArenaValue(line, "name", str_name, STR_SIZE) != 0) - return; - if (getArenaValue(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); - loadImageFromArena(arenaFile, str_file, IMAGE_GROUP_USER, str_name, isYesOrNO(str_alpha)); - - //addImageData(str_file, isYesOrNO(str_alpha), str_name, IMAGE_GROUP_USER); + char str_file[STR_SIZE]; + char str_name[STR_SIZE]; + char str_alpha[STR_SIZE]; + + if (getArenaValue(line, "file", str_file, STR_SIZE) != 0) + return; + if (getArenaValue(line, "name", str_name, STR_SIZE) != 0) + return; + if (getArenaValue(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); + loadImageFromArena(arenaFile, str_file, IMAGE_GROUP_USER, str_name, + isYesOrNO(str_alpha)); + + //addImageData(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]; + char str_file[STR_SIZE]; + char str_name[STR_SIZE]; - if (getArenaValue(line, "file", str_file, STR_SIZE) != 0) - return; - if (getArenaValue(line, "name", str_name, STR_SIZE) != 0) - return; + if (getArenaValue(line, "file", str_file, STR_SIZE) != 0) + return; + if (getArenaValue(line, "name", str_name, STR_SIZE) != 0) + return; #ifndef NO_SOUND - //addMusic(str_file, str_name, MUSIC_GROUP_USER); - loadMusicFromArena(arenaFile, str_file, MUSIC_GROUP_USER, str_name); + //addMusic(str_file, str_name, MUSIC_GROUP_USER); + loadMusicFromArena(arenaFile, str_file, MUSIC_GROUP_USER, str_name); #endif } -static void cmd_playMusic(arena_t *arena, char *line) +static void +cmd_playMusic(arena_t * arena, char *line) { - char str_music[STR_SIZE]; + char str_music[STR_SIZE]; - if (getArenaValue(line, "music", str_music, STR_SIZE) != 0) - return; - strcpy(arena->music, str_music); + if (getArenaValue(line, "music", str_music, STR_SIZE) != 0) + return; + strcpy(arena->music, str_music); } #endif -int getArenaCount() +int +getArenaCount() { - return listArenaFile->count; + return listArenaFile->count; } -static char *getArenaStatus(textFile_t *ts, char *s) +static char * +getArenaStatus(textFile_t * ts, char *s) { - int len; - int i; - - len = strlen(s); - for( i = 0; i < ts->text->count; i++ ) { - char *line; - line = (char *) (ts->text->list[i]); - if( strncmp(line, s, len) == 0 ) - return line+len+1; - } - return NULL; + int len; + int i; + + len = strlen(s); + for (i = 0; i < ts->text->count; i++) { + char *line; + line = (char *) (ts->text->list[i]); + if (strncmp(line, s, len) == 0) + return line + len + 1; + } + return NULL; } -char *getArenaName(arenaFile_t *arenaFile) +char * +getArenaName(arenaFile_t * arenaFile) { - char *ret; + char *ret; - ret = getArenaStatus(arenaFile->map, "name"); - return ( ret != NULL ? ret : "arena_no_name" ); + ret = getArenaStatus(arenaFile->map, "name"); + return (ret != NULL ? ret : "arena_no_name"); } -char *getArenaNetName(arenaFile_t *arenaFile) +char * +getArenaNetName(arenaFile_t * arenaFile) { - char *ret; + char *ret; - ret = getArenaStatus(arenaFile->map, "netName"); - return ( ret != NULL ? ret : "arena_no_net_name" ); + ret = getArenaStatus(arenaFile->map, "netName"); + return (ret != NULL ? ret : "arena_no_net_name"); } -arenaFile_t* getArenaFileFormNetName(char *s) +arenaFile_t * +getArenaFileFormNetName(char *s) { - int i; + int i; // - for (i = 0; i < listArenaFile->count; i++) - { - arenaFile_t *arenaFile; + for (i = 0; i < listArenaFile->count; i++) { + arenaFile_t *arenaFile; - arenaFile = (arenaFile_t *)listArenaFile->list[i]; - if (strcmp(getArenaNetName(arenaFile), s) == 0) - return arenaFile; - } + arenaFile = (arenaFile_t *) listArenaFile->list[i]; + if (strcmp(getArenaNetName(arenaFile), s) == 0) + return arenaFile; + } - return NULL; + return NULL; } -char *getArenaImage(arenaFile_t *arenaFile) +char * +getArenaImage(arenaFile_t * arenaFile) { - return getArenaStatus(arenaFile->map, "screen"); + return getArenaStatus(arenaFile->map, "screen"); } -arenaFile_t* getArenaFile(int n) +arenaFile_t * +getArenaFile(int n) { - return (arenaFile_t *)listArenaFile->list[n]; + return (arenaFile_t *) listArenaFile->list[n]; } -int getArenaFileID(arenaFile_t *arenaFile) +int +getArenaFileID(arenaFile_t * arenaFile) { - int i; + int i; - for (i = 0; i < listArenaFile->count; i++) - { - arenaFile_t *this; + for (i = 0; i < listArenaFile->count; i++) { + arenaFile_t *this; - this = (arenaFile_t *)listArenaFile->list[i]; - - if( this == arenaFile) - { - return i; - } - } + this = (arenaFile_t *) listArenaFile->list[i]; - return -1; + if (this == arenaFile) { + return i; + } + } + + return -1; } -arena_t* getArena(arenaFile_t *arenaFile) +arena_t * +getArena(arenaFile_t * arenaFile) { - textFile_t *ts; - arena_t *arena = NULL; // no warninng - int i; + textFile_t *ts; + arena_t *arena = NULL; // no warninng + int i; - ts = (textFile_t *) arenaFile->map; + ts = (textFile_t *) arenaFile->map; - for( i = 0 ; i < ts->text->count ; i++ ) { - char *line; + for (i = 0; i < ts->text->count; i++) { + char *line; - line = (char *) (ts->text->list[i]); - cmdModule(line); + line = (char *) (ts->text->list[i]); + cmdModule(line); #ifndef PUBLIC_SERVER - if (strncmp(line, "loadImage", 9) == 0) - cmd_loadImage(arenaFile, line); - if (strncmp(line, "loadMusic", 9) == 0) - cmd_loadMusic(arenaFile, line); - if (strncmp(line, "playMusic", 9) == 0) - cmd_playMusic(arena, line); + if (strncmp(line, "loadImage", 9) == 0) + cmd_loadImage(arenaFile, line); + if (strncmp(line, "loadMusic", 9) == 0) + cmd_loadMusic(arenaFile, line); + if (strncmp(line, "playMusic", 9) == 0) + cmd_playMusic(arena, line); #endif - if (strncmp(line, "arena", 5) == 0 ) - cmd_arena(&arena, line); - if (strncmp(line, "loadModule", 10) == 0 ) - cmd_loadModule(line); - //if( strncmp(line, "wall", 4) == 0 )cmd_wall(arena, line); - //if( strncmp(line, "teleport", 8) == 0 )cmd_teleport(arena, line); - //if( strncmp(line, "pipe", 4) == 0 )cmd_pipe(arena, line); - } - - return arena; + if (strncmp(line, "arena", 5) == 0) + cmd_arena(&arena, line); + if (strncmp(line, "loadModule", 10) == 0) + cmd_loadModule(line); + //if( strncmp(line, "wall", 4) == 0 )cmd_wall(arena, line); + //if( strncmp(line, "teleport", 8) == 0 )cmd_teleport(arena, line); + //if( strncmp(line, "pipe", 4) == 0 )cmd_pipe(arena, line); + } + + return arena; } -arenaFile_t* newArenaFile(char *path) +arenaFile_t * +newArenaFile(char *path) { - arenaFile_t *new; - char *extractFile; + arenaFile_t *new; + char *extractFile; - new = malloc( sizeof(arenaFile_t) ); - new->path = strdup(path); + new = malloc(sizeof(arenaFile_t)); + new->path = strdup(path); - extractFile = extractFileFromArchive(path, "arena.map"); - new->map = loadTextFile(extractFile); - deleteExtractFile(extractFile); + extractFile = extractFileFromArchive(path, "arena.map"); + new->map = loadTextFile(extractFile); + deleteExtractFile(extractFile); - return new; + return new; } -void destroyArenaFile(arenaFile_t *p) +void +destroyArenaFile(arenaFile_t * p) { - destroyTextFile(p->map); - free(p->path); - free(p); + destroyTextFile(p->map); + free(p->path); + free(p); } -void loadArenaFile(char *path) +void +loadArenaFile(char *path) { - addList(listArenaFile, newArenaFile(path) ); + addList(listArenaFile, newArenaFile(path)); } -void initArenaFile() +void +initArenaFile() { - director_t *p; - int i; + director_t *p; + int i; #ifndef PUBLIC_SERVER - assert( isImageInicialized() == TRUE ); + assert(isImageInicialized() == TRUE); #endif - isArenaFileInit = TRUE; - listArenaFile = newList(); + isArenaFileInit = TRUE; + listArenaFile = newList(); + + p = loadDirector(PATH_ARENA); + //p = loadDirector( getHomeDirector() ); - p = loadDirector(PATH_ARENA); - //p = loadDirector( getHomeDirector() ); + for (i = 0; i < p->list->count; i++) { + char *line; - 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) { - char path[STR_PATH_SIZE]; + if (strstr(line, ".zip") != NULL && strstr(line, "~") == NULL) { + char path[STR_PATH_SIZE]; - sprintf(path, PATH_ARENA "%s", line); + sprintf(path, PATH_ARENA "%s", line); #ifdef DEBUG - printf(_("Loading arena: %s\n"), line); + printf(_("Loading arena: %s\n"), line); #endif - accessExistFile(path); - loadArenaFile(path); - } - } - //printf("No. of Arens: %d\n", listArenaFile->count); - destroyDirector(p); + accessExistFile(path); + loadArenaFile(path); + } + } + //printf("No. of Arens: %d\n", listArenaFile->count); + destroyDirector(p); } -void quitArenaFile() +void +quitArenaFile() { - isArenaFileInit = FALSE; - destroyListItem(listArenaFile, destroyArenaFile); + isArenaFileInit = FALSE; + destroyListItem(listArenaFile, destroyArenaFile); } diff --git a/src/base/buffer.c b/src/base/buffer.c index 263037b..e09b7f2 100755 --- a/src/base/buffer.c +++ b/src/base/buffer.c @@ -6,132 +6,140 @@ #include "buffer.h" -buffer_t * newBuffer(int n) +buffer_t * +newBuffer(int n) { - buffer_t *new; + buffer_t *new; - new = malloc(sizeof(buffer_t)); - memset(new, 0, sizeof(buffer_t)); - new->alloc = n; - new->data = malloc(n); - memset(new->data , 0, n); + new = malloc(sizeof(buffer_t)); + memset(new, 0, sizeof(buffer_t)); + new->alloc = n; + new->data = malloc(n); + memset(new->data, 0, n); - return new; + return new; } -void* getBufferData(buffer_t *p) +void * +getBufferData(buffer_t * p) { - return p->data; + return p->data; } -int getBufferSize(buffer_t *p) +int +getBufferSize(buffer_t * p) { - return p->size; + return p->size; } -int addBuffer(buffer_t *p, char *data, int len) +int +addBuffer(buffer_t * p, char *data, int len) { - assert( p != NULL ); - assert( data != NULL ); - assert( len >= 0 ); - - if( p->size + len <= p->alloc ) - { - memcpy(p->data + p->size, data, len); - p->size += len; - return len; - } - - return -1; + assert(p != NULL); + assert(data != NULL); + assert(len >= 0); + + if (p->size + len <= p->alloc) { + memcpy(p->data + p->size, data, len); + p->size += len; + return len; + } + + return -1; } -int cutBuffer(buffer_t *p, int len) +int +cutBuffer(buffer_t * p, int len) { - assert( p != NULL ); - assert( len >= 0 ); + assert(p != NULL); + assert(len >= 0); - if( p->size - len >= 0 ) - { - memmove(p->data, p->data + len, p->size - len); - p->size -= len; - return 0; - } + if (p->size - len >= 0) { + memmove(p->data, p->data + len, p->size - len); + p->size -= len; + return 0; + } - return -1; + return -1; } -int getBufferCount(buffer_t *p) +int +getBufferCount(buffer_t * p) { - char *begin; - char *end; - int count; - int size; - - assert( p != NULL ); - - count = 0; - begin = p->data; - size = p->size; - - while( ( end = memchr(begin, '\n', size) ) != NULL ) - { - count++; - size -= ( (end+1) - begin); - begin = end+1; - } - - //printf("count = %d\n", count); - //printf("data = %s\n", p->data); - return count; + char *begin; + char *end; + int count; + int size; + + assert(p != NULL); + + count = 0; + begin = p->data; + size = p->size; + + while ((end = memchr(begin, '\n', size)) != NULL) { + count++; + size -= ((end + 1) - begin); + begin = end + 1; + } + + //printf("count = %d\n", count); + //printf("data = %s\n", p->data); + return count; } -int getBufferLine(buffer_t *p, char *line, int len) +int +getBufferLine(buffer_t * p, char *line, int len) { - char *end; - int ret_len; + char *end; + int ret_len; + + assert(p != NULL); + assert(line != NULL); + assert(len >= 0); - assert( p != NULL ); - assert( line != NULL ); - assert( len >= 0 ); + end = NULL; - end = NULL; + end = memchr(p->data, '\n', p->size); - end = memchr(p->data, '\n', p->size); + if (end == NULL) + return -1; - if( end == NULL ) return -1; + ret_len = (int) (end - p->data) + 1; + if (ret_len > len - 1) + ret_len = len - 1; - ret_len = (int) (end - p->data)+1; - if( ret_len > len-1 ) ret_len = len-1; - - memset(line, 0, len); - memcpy(line, p->data, ret_len); + memset(line, 0, len); + memcpy(line, p->data, ret_len); - cutBuffer(p, ret_len); + cutBuffer(p, ret_len); - return ret_len; + return ret_len; } -int getBufferDataLen(buffer_t *p, char *line, int len) +int +getBufferDataLen(buffer_t * p, char *line, int len) { - assert( p != NULL ); - assert( line != NULL ); - assert( len >= 0 ); + assert(p != NULL); + assert(line != NULL); + assert(len >= 0); - if( p->size < len ) - { - len = p->size; - } + if (p->size < len) { + len = p->size; + } - memcpy(line, p->data, len); - cutBuffer(p, len); + memcpy(line, p->data, len); + cutBuffer(p, len); - return len; + return len; } -void destroyBuffer(buffer_t *p) +void +destroyBuffer(buffer_t * p) { - assert( p != NULL ); + assert(p != NULL); - if( p->data != NULL )free(p->data); - free(p); + if (p->data != NULL) + free(p->data); + free(p); } diff --git a/src/base/checkFront.c b/src/base/checkFront.c index 536de1b..dfe11eb 100644 --- a/src/base/checkFront.c +++ b/src/base/checkFront.c @@ -13,101 +13,109 @@ typedef struct struct_checkfront_t { - char *msg; - my_time_t time; - int id; - int count; - int type; + char *msg; + my_time_t time; + int id; + int count; + int type; } checkfront_t; -static checkfront_t* newCheck(char *s, int type, int id) +static checkfront_t * +newCheck(char *s, int type, int id) { - checkfront_t *new; - - assert( s != NULL ); - new = malloc( sizeof(checkfront_t) ); - memset(new, 0, sizeof(checkfront_t)); - new->msg = strdup(s); - new->time = getMyTime(); - new->id = id; - new->type = type; - new->count = 0; - return new; + checkfront_t *new; + + assert(s != NULL); + new = malloc(sizeof(checkfront_t)); + memset(new, 0, sizeof(checkfront_t)); + new->msg = strdup(s); + new->time = getMyTime(); + new->id = id; + new->type = type; + new->count = 0; + return new; } -static void destroyCheck(checkfront_t *p) +static void +destroyCheck(checkfront_t * p) { - assert( p != NULL ); - free(p->msg); - free(p); + assert(p != NULL); + free(p->msg); + free(p); } -list_t* newCheckFront() +list_t * +newCheckFront() { - return newList(); + return newList(); } -void addMsgInCheckFront(list_t *list, char *msg, int type, int id) +void +addMsgInCheckFront(list_t * list, char *msg, int type, int id) { - if (type == CHECK_FRONT_TYPE_CHECK) - incID(id); - addList(list, newCheck(msg, type, id) ); + if (type == CHECK_FRONT_TYPE_CHECK) + incID(id); + addList(list, newCheck(msg, type, id)); } -void eventMsgInCheckFront(client_t *client) +void +eventMsgInCheckFront(client_t * client) { - my_time_t currentTime; - int i; - - currentTime = getMyTime(); - for (i = 0; i < client->listSendMsg->count; i++) { - checkfront_t *this; - - this = (checkfront_t *)client->listSendMsg->list[i]; - switch (this->type) { - case CHECK_FRONT_TYPE_SIMPLE : - sendClient(client, this->msg); - delListItem(client->listSendMsg, i, destroyCheck); - i--; - break; - case CHECK_FRONT_TYPE_CHECK : - if (this->count == 0 || currentTime - this->time > CHECK_FRONT_SEND_TIME_INTERVAL) { - sendClient(client, this->msg); - this->time = currentTime; - this->count++; - } - if (this->count > CHECK_FRONT_MAX_COUNT_SEND) { - delID(this->id); - delListItem(client->listSendMsg, i, destroyCheck); - i--; - } - break; - default : - assert(! _("Bad type of front!")); - break; - } - } + my_time_t currentTime; + int i; + + currentTime = getMyTime(); + for (i = 0; i < client->listSendMsg->count; i++) { + checkfront_t *this; + + this = (checkfront_t *) client->listSendMsg->list[i]; + switch (this->type) { + case CHECK_FRONT_TYPE_SIMPLE: + sendClient(client, this->msg); + delListItem(client->listSendMsg, i, destroyCheck); + i--; + break; + case CHECK_FRONT_TYPE_CHECK: + if (this->count == 0 + || currentTime - this->time > + CHECK_FRONT_SEND_TIME_INTERVAL) { + sendClient(client, this->msg); + this->time = currentTime; + this->count++; + } + if (this->count > CHECK_FRONT_MAX_COUNT_SEND) { + delID(this->id); + delListItem(client->listSendMsg, i, destroyCheck); + i--; + } + break; + default: + assert(!_("Bad type of front!")); + break; + } + } } -void delMsgInCheckFront(list_t *listCheckFront, int id) +void +delMsgInCheckFront(list_t * listCheckFront, int id) { - int i; - - for (i = 0 ; i < listCheckFront->count ; i++ ) { - checkfront_t *this; - - this = (checkfront_t *)listCheckFront->list[i]; - if (this->id == id) { - delID(this->id); - delListItem(listCheckFront, i, destroyCheck); - return; - } - } + int i; + + for (i = 0; i < listCheckFront->count; i++) { + checkfront_t *this; + + this = (checkfront_t *) listCheckFront->list[i]; + if (this->id == id) { + delID(this->id); + delListItem(listCheckFront, i, destroyCheck); + return; + } + } } -void destroyCheckFront(list_t *p) +void +destroyCheckFront(list_t * p) { - assert( p != NULL ); - destroyListItem(p, destroyCheck); + assert(p != NULL); + destroyListItem(p, destroyCheck); } - diff --git a/src/base/director.c b/src/base/director.c index a4c8496..eea7ea4 100755 --- a/src/base/director.c +++ b/src/base/director.c @@ -12,50 +12,52 @@ typedef struct director_struct { - char *path; - list_t *list; + char *path; + list_t *list; } director_t; -director_t* loadDirector(char *s) +director_t * +loadDirector(char *s) { - director_t *new; - DIR *dir; - struct dirent *item; - char path[STR_PATH_SIZE]; - assert( s != 0 ); - new = malloc( sizeof(director_t) ); - memset(new, 0, sizeof(director_t) ); - new->list = newList(); + director_t *new; + DIR *dir; + struct dirent *item; + char path[STR_PATH_SIZE]; + assert(s != 0); + new = malloc(sizeof(director_t)); + memset(new, 0, sizeof(director_t)); + new->list = newList(); #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 - getcwd(path, STR_PATH_SIZE); - strcat(path, "/"); - strcat(path, s); - } - new->path = strdup(path); - dir = opendir(new->path); - if( dir == NULL ) { - free(new->path); - free(new); - return NULL; - } + strcpy(path, s); + else { + // this is really correct aproach + getcwd(path, STR_PATH_SIZE); + strcat(path, "/"); + strcat(path, s); + } + new->path = strdup(path); + dir = opendir(new->path); + if (dir == NULL) { + free(new->path); + free(new); + return NULL; + } - while((item = readdir(dir)) != NULL) - addList(new->list, strdup(item->d_name) ); - closedir(dir); - return new; + while ((item = readdir(dir)) != NULL) + addList(new->list, strdup(item->d_name)); + closedir(dir); + return new; } -void destroyDirector(director_t *p) +void +destroyDirector(director_t * p) { - assert( p != NULL ); - destroyListItem(p->list, free); - free(p->path); - free(p); + assert(p != NULL); + destroyListItem(p->list, free); + free(p->path); + free(p); } diff --git a/src/base/gun.c b/src/base/gun.c index 7198a1e..bf6545e 100644 --- a/src/base/gun.c +++ b/src/base/gun.c @@ -25,258 +25,277 @@ #include "publicServer.h" #endif -static void modificiationCopuse(int courser, int right_x, int right_y, int *dest_x, int *dest_y) +static void +modificiationCopuse(int courser, int right_x, int right_y, int *dest_x, + int *dest_y) { - assert(dest_x != NULL); - assert(dest_y != NULL); - switch (courser) { - case TUX_UP : - *dest_x = right_y; - *dest_y = -right_x; - break; - case TUX_RIGHT : - *dest_x = right_x; - *dest_y = right_y; - break; - case TUX_LEFT : - *dest_x = -right_x; - *dest_y = right_y; - break; - case TUX_DOWN : - *dest_x = right_y; - *dest_y = right_x; - break; - default : - assert(! _("There is wrong value in course variable!")); - break; - } + assert(dest_x != NULL); + assert(dest_y != NULL); + switch (courser) { + case TUX_UP: + *dest_x = right_y; + *dest_y = -right_x; + break; + case TUX_RIGHT: + *dest_x = right_x; + *dest_y = right_y; + break; + case TUX_LEFT: + *dest_x = -right_x; + *dest_y = right_y; + break; + case TUX_DOWN: + *dest_x = right_y; + *dest_y = right_x; + break; + default: + assert(!_("There is wrong value in course variable!")); + 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; - shot_t *shot; + int dest_x = 0, dest_y = 0; + int dest_px = 0, dest_py = 0; + shot_t *shot; - modificiationCopuse(tux->position, px, py, &dest_px, &dest_py); - modificiationCopuse(tux->position, x, y, &dest_x, &dest_y); - if (gun == GUN_LASSER) - switch (tux->position) { - case TUX_UP : - dest_y -= GUN_LASSER_HORIZONTAL; - break; - case TUX_RIGHT : - break; - case TUX_LEFT : - dest_x -= GUN_LASSER_HORIZONTAL; - break; - case TUX_DOWN : - break; - } - shot = newShot(tux->x + dest_x, tux->y + dest_y, dest_px, dest_py, gun, tux->id); - addObjectToSpace(getCurrentArena()->spaceShot, shot); + modificiationCopuse(tux->position, px, py, &dest_px, &dest_py); + modificiationCopuse(tux->position, x, y, &dest_x, &dest_y); + if (gun == GUN_LASSER) + switch (tux->position) { + case TUX_UP: + dest_y -= GUN_LASSER_HORIZONTAL; + break; + case TUX_RIGHT: + break; + case TUX_LEFT: + dest_x -= GUN_LASSER_HORIZONTAL; + break; + case TUX_DOWN: + break; + } + shot = + newShot(tux->x + dest_x, tux->y + dest_y, dest_px, dest_py, gun, + tux->id); + addObjectToSpace(getCurrentArena()->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; + int gun; - if (getNetTypeGame() == NET_GAME_TYPE_CLIENT) - return; - if (tux->gun == GUN_BOMBBALL) - gun = GUN_BOMBBALL; - else if (tux->gun == GUN_LASSER) - gun = GUN_LASSER; - else - gun = GUN_SIMPLE; + if (getNetTypeGame() == NET_GAME_TYPE_CLIENT) + return; + if (tux->gun == GUN_BOMBBALL) + gun = GUN_BOMBBALL; + else if (tux->gun == GUN_LASSER) + gun = GUN_LASSER; + else + gun = GUN_SIMPLE; - if (tux->bonus == BONUS_4X) { - int zal; - int i; + if (tux->bonus == BONUS_4X) { + int zal; + int i; - zal = tux->position; - 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; - } - addShotTrivial(tux, x, y, px, py, gun); - } - tux->position = zal; - }else{ - addShotTrivial(tux, x, y, px, py, gun); - } + zal = tux->position; + 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; + } + addShotTrivial(tux, x, y, px, py, gun); + } + tux->position = zal; + } + else { + addShotTrivial(tux, x, y, px, py, gun); + } } -static void shotInGunSimpe(tux_t *tux) +static void +shotInGunSimpe(tux_t * tux) { - addShot(tux, 0, 0, +5, 0); + addShot(tux, 0, 0, +5, 0); } -static void shotInGunDualSimpe(tux_t *tux) +static void +shotInGunDualSimpe(tux_t * tux) { - addShot(tux, 0, -10, +6, 0); - addShot(tux, 0, +10, +6, 0); + addShot(tux, 0, -10, +6, 0); + addShot(tux, 0, +10, +6, 0); } -static void shotInGunScatter(tux_t *tux) +static void +shotInGunScatter(tux_t * tux) { - int i; + int i; - for (i = -2 ; i <= +2 ; i++) - addShot(tux, 0, 0, +8, i); + for (i = -2; i <= +2; i++) + addShot(tux, 0, 0, +8, i); } -static void timer_addShotTimer(void *p) +static void +timer_addShotTimer(void *p) { - tux_t *tux; - int id; - int gun; + tux_t *tux; + int id; + int gun; - id = * ((int *)p); - free(p); - tux = getObjectFromSpaceWithID(getCurrentArena()->spaceTux, id); - if (tux == NULL) - return; - if (tux->status != TUX_STATUS_ALIVE) - return; - gun = tux->gun; - tux->gun = GUN_SIMPLE; - addShot(tux, 0, 0, +6, 0); - tux->gun = gun; + id = *((int *) p); + free(p); + tux = getObjectFromSpaceWithID(getCurrentArena()->spaceTux, id); + if (tux == NULL) + return; + if (tux->status != TUX_STATUS_ALIVE) + return; + gun = tux->gun; + tux->gun = GUN_SIMPLE; + addShot(tux, 0, 0, +6, 0); + tux->gun = gun; } -static void shotInGunTommy(tux_t *tux) +static void +shotInGunTommy(tux_t * tux) { - int i; + int i; - for (i = 0; i < 10; i++) - addTaskToTimer(getCurrentArena()->listTimer, TIMER_ONE, timer_addShotTimer, newInt(tux->id), i * 100); + for (i = 0; i < 10; i++) + addTaskToTimer(getCurrentArena()->listTimer, TIMER_ONE, + timer_addShotTimer, newInt(tux->id), i * 100); } -static void timer_addLaserTimer(void *p) +static void +timer_addLaserTimer(void *p) { - tux_t *tux; - int id; - int gun; + tux_t *tux; + int id; + int gun; - id = * ((int *)p); - free(p); - tux = getObjectFromSpaceWithID(getCurrentArena()->spaceTux, id); - if (tux == NULL) - return; - 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); - tux->gun = gun; + id = *((int *) p); + free(p); + tux = getObjectFromSpaceWithID(getCurrentArena()->spaceTux, id); + if (tux == NULL) + return; + 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); + tux->gun = gun; } -static void shotInGunLasser(tux_t *tux) +static void +shotInGunLasser(tux_t * tux) { - int i; + int i; - for (i = 0; i < 50; i++) - addTaskToTimer(getCurrentArena()->listTimer, TIMER_ONE, timer_addLaserTimer, newInt(tux->id), i * 10 ); + for (i = 0; i < 50; i++) + addTaskToTimer(getCurrentArena()->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; + int x, y; + arena_t *arena; - x = tux->x; - y = tux->y; - switch (tux->position) { - case TUX_UP : - y += TUX_HEIGHT; - break; - case TUX_RIGHT : - x -= TUX_WIDTH; - break; - case TUX_LEFT : - x += TUX_WIDTH; - break; - case TUX_DOWN : - y -= TUX_HEIGHT; - break; - } - arena = getCurrentArena(); - if (isFreeSpace(getCurrentArena(), x, y, ITEM_MINE_WIDTH, ITEM_MINE_HEIGHT)) { - item_t *item; + x = tux->x; + y = tux->y; + switch (tux->position) { + case TUX_UP: + y += TUX_HEIGHT; + break; + case TUX_RIGHT: + x -= TUX_WIDTH; + break; + case TUX_LEFT: + x += TUX_WIDTH; + break; + case TUX_DOWN: + y -= TUX_HEIGHT; + break; + } + arena = getCurrentArena(); + if (isFreeSpace + (getCurrentArena(), x, y, ITEM_MINE_WIDTH, ITEM_MINE_HEIGHT)) { + item_t *item; #ifndef NO_SOUND - playSound("put_mine", SOUND_GROUP_BASE); + playSound("put_mine", SOUND_GROUP_BASE); #endif - tux->shot[tux->gun]--; - if (getNetTypeGame() != NET_GAME_TYPE_CLIENT) { - item = newItem(x, y, ITEM_MINE, tux->id); - if (getNetTypeGame() == NET_GAME_TYPE_SERVER) - proto_send_additem_server(PROTO_SEND_ALL, NULL, item); - addObjectToSpace(arena->spaceItem, item ); - } - } + tux->shot[tux->gun]--; + if (getNetTypeGame() != NET_GAME_TYPE_CLIENT) { + item = newItem(x, y, ITEM_MINE, tux->id); + if (getNetTypeGame() == NET_GAME_TYPE_SERVER) + proto_send_additem_server(PROTO_SEND_ALL, NULL, item); + addObjectToSpace(arena->spaceItem, item); + } + } } -static void shotInGunBombball(tux_t *tux) +static void +shotInGunBombball(tux_t * tux) { - addShot(tux, 0, 0, +10, 0); + addShot(tux, 0, 0, +10, 0); } -void shotInGun(tux_t *tux) +void +shotInGun(tux_t * tux) { - if (tux->bonus != BONUS_SHOT && tux->gun != GUN_MINE) - tux->shot[tux->gun]--; + if (tux->bonus != BONUS_SHOT && tux->gun != GUN_MINE) + tux->shot[tux->gun]--; - switch( tux->gun ) - { - case GUN_SIMPLE : + switch (tux->gun) { + case GUN_SIMPLE: #ifndef NO_SOUND - playSound("gun_revolver", SOUND_GROUP_BASE); + playSound("gun_revolver", SOUND_GROUP_BASE); #endif - shotInGunSimpe(tux); - break; - case GUN_DUAL_SIMPLE : + shotInGunSimpe(tux); + break; + case GUN_DUAL_SIMPLE: #ifndef NO_SOUND - playSound("gun_revolver", SOUND_GROUP_BASE); + playSound("gun_revolver", SOUND_GROUP_BASE); #endif - shotInGunDualSimpe(tux); - break; - case GUN_SCATTER : + shotInGunDualSimpe(tux); + break; + case GUN_SCATTER: #ifndef NO_SOUND - playSound("gun_scatter", SOUND_GROUP_BASE); + playSound("gun_scatter", SOUND_GROUP_BASE); #endif - shotInGunScatter(tux); - break; - case GUN_TOMMY : + shotInGunScatter(tux); + break; + case GUN_TOMMY: #ifndef NO_SOUND - playSound("gun_tommy", SOUND_GROUP_BASE); + playSound("gun_tommy", SOUND_GROUP_BASE); #endif - shotInGunTommy(tux); - break; - case GUN_LASSER : + shotInGunTommy(tux); + break; + case GUN_LASSER: #ifndef NO_SOUND - playSound("gun_lasser", SOUND_GROUP_BASE); + playSound("gun_lasser", SOUND_GROUP_BASE); #endif - shotInGunLasser(tux); - break; - case GUN_BOMBBALL : - shotInGunBombball(tux); - break; - case GUN_MINE : - putInGunMine(tux); - break; - } + shotInGunLasser(tux); + break; + case GUN_BOMBBALL: + shotInGunBombball(tux); + break; + case GUN_MINE: + putInGunMine(tux); + break; + } } diff --git a/src/base/homeDirector.c b/src/base/homeDirector.c index 1f10920..81d34c5 100755 --- a/src/base/homeDirector.c +++ b/src/base/homeDirector.c @@ -10,37 +10,39 @@ static char homeDirector[STR_PATH_SIZE]; -void createHomeDirector() +void +createHomeDirector() { - char *envHome; + char *envHome; #ifndef __WIN32__ - envHome = getenv("HOME"); + envHome = getenv("HOME"); #else - envHome = getenv("USERPROFILE"); + envHome = getenv("USERPROFILE"); #endif - if (envHome == NULL) { - fprintf(stderr, _("Environment variable HOME not found!\n")); - exit(0); - } + if (envHome == NULL) { + fprintf(stderr, _("Environment variable HOME not found!\n")); + exit(0); + } - sprintf(homeDirector, "%s/%s", envHome, HOMEDIRECTOR_NAME); + sprintf(homeDirector, "%s/%s", envHome, HOMEDIRECTOR_NAME); - if (access(homeDirector, F_OK) != 0) { + if (access(homeDirector, F_OK) != 0) { #ifdef DEBUG - printf(_("Creating home directory %s.\n"), homeDirector); + printf(_("Creating home directory %s.\n"), homeDirector); #endif #ifndef __WIN32__ - if (mkdir(homeDirector, 0755) != 0) { + if (mkdir(homeDirector, 0755) != 0) { #else - if (mkdir(homeDirector) != 0) { + if (mkdir(homeDirector) != 0) { #endif - fprintf(stderr, _("Unable to create home directory!\n")); - exit(0); - } - } + fprintf(stderr, _("Unable to create home directory!\n")); + exit(0); + } + } } -char *getHomeDirector() +char * +getHomeDirector() { - return homeDirector; + return homeDirector; } diff --git a/src/base/idManager.c b/src/base/idManager.c index fd4cac9..0e2fbfb 100644 --- a/src/base/idManager.c +++ b/src/base/idManager.c @@ -12,198 +12,201 @@ static int lastID; typedef struct id_item_struct { - int id; - int count; + int id; + int count; } id_item_t; -static id_item_t* newIdItem(int id, int count) +static id_item_t * +newIdItem(int id, int count) { - id_item_t *new; + id_item_t *new; - new = malloc( sizeof(id_item_t) ); - new->id = id; - new->count = count; + new = malloc(sizeof(id_item_t)); + new->id = id; + new->count = count; - return new; + return new; } -static void destroyIdItem(id_item_t *p) +static void +destroyIdItem(id_item_t * p) { - assert( p != NULL ); + assert(p != NULL); - free(p); + free(p); } -void initListID() +void +initListID() { - listID = newList(); - lastID = 0; + listID = newList(); + lastID = 0; #ifdef DEBUG - printf(_("Starting ID manger\n")); + printf(_("Starting ID manger\n")); #endif } -int isRegisterID(int id) +int +isRegisterID(int id) { - int i; + int i; - assert( listID != NULL ); + assert(listID != NULL); - for( i = 0 ; i < listID->count ; i++ ) - { - id_item_t *this; + for (i = 0; i < listID->count; i++) { + id_item_t *this; - this = listID->list[i]; + this = listID->list[i]; - if( this->id == id ) - { - return i; - } - } + if (this->id == id) { + return i; + } + } - return -1; + return -1; } -static int findNewID() +static int +findNewID() { - int ret; + int ret; - assert( listID != NULL ); + assert(listID != NULL); - if( listID->count >= MAX_ID-1 ) - { - assert( ! _("No free ID left!") ); - } + if (listID->count >= MAX_ID - 1) { + assert(!_("No free ID left!")); + } - do{ - //ret = ( random() % (listID->count + 8 ) ) + 1; - ret = random() % MAX_ID + 1; - }while( isRegisterID(ret) != -1 ); + do { + //ret = ( random() % (listID->count + 8 ) ) + 1; + ret = random() % MAX_ID + 1; + } while (isRegisterID(ret) != -1); - //printf("new ID %d\n", ret); + //printf("new ID %d\n", ret); - return ret; + return ret; } -int getNewIDcount(int count) +int +getNewIDcount(int count) { - int id; + int id; - id = findNewID(); + id = findNewID(); - addList(listID, newIdItem(id, count) ); + addList(listID, newIdItem(id, count)); - return id; + return id; } -int getNewID() +int +getNewID() { - return getNewIDcount(1); + return getNewIDcount(1); } -void incID(int id) +void +incID(int id) { - id_item_t *this; - int index; - - assert( listID != NULL ); + id_item_t *this; + int index; - index = isRegisterID(id); + assert(listID != NULL); - if( index == -1 ) - { - assert( ! _("This kind of ID was never registered!") ); - return; // ha ha ha - } + index = isRegisterID(id); - this = listID->list[index]; + if (index == -1) { + assert(!_("This kind of ID was never registered!")); + return; // ha ha ha + } - this->count++; + this = listID->list[index]; - //printf("inc ID %d %d\n", this->id, this->count); - return; + this->count++; + + //printf("inc ID %d %d\n", this->id, this->count); + return; } -void delID(int id) +void +delID(int id) { - id_item_t *this; - int index; - - assert( listID != NULL ); - - index = isRegisterID(id); - - if( index == -1 ) - { - assert( ! _("This kind of ID was never registered!") ); - return; // ha ha ha - } - - this = listID->list[index]; - - this->count--; - //printf("dec ID %d %d\n", this->id, this->count); - - if( this->count <= 0 ) - { - delListItem(listID, index, free); - //printf("listID->count = %d\n", listID->count); - } - - return; + id_item_t *this; + int index; + + assert(listID != NULL); + + index = isRegisterID(id); + + if (index == -1) { + assert(!_("This kind of ID was never registered!")); + return; // ha ha ha + } + + this = listID->list[index]; + + this->count--; + //printf("dec ID %d %d\n", this->id, this->count); + + if (this->count <= 0) { + delListItem(listID, index, free); + //printf("listID->count = %d\n", listID->count); + } + + return; } -void replaceID(int old_id, int new_id) +void +replaceID(int old_id, int new_id) { - int index_old_id; - int index_new_id; - id_item_t *this; + int index_old_id; + int index_new_id; + id_item_t *this; - if( old_id == new_id ) - { - return; - } + if (old_id == new_id) { + return; + } - index_old_id = isRegisterID(old_id); - assert( index_old_id != -1 ); + index_old_id = isRegisterID(old_id); + assert(index_old_id != -1); - index_new_id = isRegisterID(new_id); - assert( index_new_id == -1 ); + index_new_id = isRegisterID(new_id); + assert(index_new_id == -1); - this = listID->list[index_old_id]; - this->id = new_id; + this = listID->list[index_old_id]; + this->id = new_id; } -void infoID(int id) +void +infoID(int id) { - id_item_t *this; - int index; - - assert( listID != NULL ); + id_item_t *this; + int index; - index = isRegisterID(id); + assert(listID != NULL); - if( index == -1 ) - { + index = isRegisterID(id); + + if (index == -1) { #ifdef DEBUG - printf(_("ID %d does not exist\n"), id); + printf(_("ID %d does not exist\n"), id); #endif - return; - } + return; + } - this = listID->list[index]; + this = listID->list[index]; #ifdef DEBUG - printf(_("ID %d (count %d)\n"), this->id, this->count); + printf(_("ID %d (count %d)\n"), this->id, this->count); #endif - return; + return; } -void quitListID() +void +quitListID() { #ifdef DEBUG - printf(_("Quitting ID manger\n")); + printf(_("Quitting ID manger\n")); #endif - assert( listID != NULL ); - destroyListItem(listID, destroyIdItem); + assert(listID != NULL); + destroyListItem(listID, destroyIdItem); } - diff --git a/src/base/index.c b/src/base/index.c index 77b0eac..5247018 100644 --- a/src/base/index.c +++ b/src/base/index.c @@ -10,280 +10,273 @@ #define DEBUG_INDEX -static index_item_t* newIndexItem(int key, void *data) +static index_item_t * +newIndexItem(int key, void *data) { - index_item_t *new; + index_item_t *new; - new = malloc( sizeof(index_item_t) ); - new->key = key; - new->data = data; + new = malloc(sizeof(index_item_t)); + new->key = key; + new->data = data; - return new; + return new; } #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("key = %d data = %p\n", p->key, p->data); } -static void printListIndexItem(list_t *list) +static void +printListIndexItem(list_t * list) { - int i; + int i; - printf("list :\n"); - printf("------------------\n"); + printf("list :\n"); + printf("------------------\n"); - for( i = 0 ; i < list->count ; i++ ) - { - index_item_t *this; + for (i = 0; i < list->count; i++) { + index_item_t *this; - this = (index_item_t *)list->list[i]; - printIndexItem(this); - } + this = (index_item_t *) list->list[i]; + printIndexItem(this); + } } -static void checkList(list_t *list) +static void +checkList(list_t * list) { - int i; - int prev; - int this; + int i; + int prev; + int this; - //return; + //return; - if( list->count == 0 ) - { - printf("nothing\n"); - return; - } + if (list->count == 0) { + printf("nothing\n"); + return; + } - prev = ( (index_item_t *) list->list[0] )->key; + prev = ((index_item_t *) list->list[0])->key; - for( i = 1 ; i < list->count ; i++ ) - { - this = ( (index_item_t *) list->list[i] )->key; + for (i = 1; i < list->count; i++) { + this = ((index_item_t *) list->list[i])->key; - if( prev >= this ) - { - printListIndexItem(list); - assert( ! "error" ); - } + if (prev >= this) { + printListIndexItem(list); + assert(!"error"); + } - prev = this; - } + prev = this; + } } #endif -static void destroyIndexItem(index_item_t *p) +static void +destroyIndexItem(index_item_t * p) { - free(p); + free(p); } -list_t* newIndex() +list_t * +newIndex() { - return newList(); + return newList(); } -void addToIndex(list_t *list, int key, void *data) +void +addToIndex(list_t * list, int key, void *data) { #ifdef DEBUG_INDEX - int count = 0; + int count = 0; #endif - index_item_t *item; - index_item_t *this; - int min, max, point; - int len; + index_item_t *item; + index_item_t *this; + int min, max, point; + int len; - item = newIndexItem(key, data); - len = list->count; + item = newIndexItem(key, data); + len = list->count; - min = 0; - max = len-1; + min = 0; + max = len - 1; - for(;;) - { - point = min + ( max - min ) / 2; + for (;;) { + point = min + (max - min) / 2; #ifdef DEBUG_INDEX - if( ++count == len*5 ) - { - printf("CICLIC ERROR\n"); - printIndexItem(item); - printf("-------------------\n"); - printListIndexItem(list); - assert( 0 ); - } + if (++count == len * 5) { + printf("CICLIC ERROR\n"); + printIndexItem(item); + printf("-------------------\n"); + printListIndexItem(list); + assert(0); + } #endif - if( max < 0 ) - { - insList(list, 0, item); + if (max < 0) { + insList(list, 0, item); #ifdef DEBUG_INDEX - checkList(list); + checkList(list); #endif - return; - } + return; + } - if( min >= len ) - { - addList(list, item); + if (min >= len) { + addList(list, item); #ifdef DEBUG_INDEX - checkList(list); + checkList(list); #endif - return; - } - - this = (index_item_t *)list->list[point]; + return; + } + + 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( min > max ) - { - insList(list, point, item); + if (min > max) { + insList(list, point, item); #ifdef DEBUG_INDEX - checkList(list); + checkList(list); #endif - return; - } - - if( item->key > this->key ) - { - min = point + 1; - continue; - } - - if( item->key < this->key ) - { - max = point - 1; - continue; - } - } + return; + } + + if (item->key > this->key) { + min = point + 1; + continue; + } + + if (item->key < this->key) { + max = point - 1; + continue; + } + } } -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; + index_item_t *this; + int min, max, point, len; + + len = list->count; - len = list->count; + if (len == 0) { + return -1; + } - if( len == 0 ) - { - return -1; - } + min = 0; + max = len - 1; - min = 0; - max = len-1; + for (;;) { + point = min + (max - min) / 2; - for(;;) - { - point = min + ( max - min ) / 2; + if (max < 0 || point >= len || max < min) { + return -1; + } - if( max < 0 || point >= len || max < min ) - { - return -1; - } - - this = (index_item_t *)list->list[point]; + 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; - } - - if( key > this->key ) - { - min = point + 1; - continue; - } - - if( key < this->key ) - { - max = point - 1; - continue; - } - } + if (key == this->key) { + return point; + } + + if (key > this->key) { + min = point + 1; + continue; + } + + if (key < this->key) { + max = point - 1; + continue; + } + } } -void* getFromIndex(list_t *list, int key) +void * +getFromIndex(list_t * list, int key) { - int offset; + int offset; - offset = getOffsetFromIndex(list, key); + offset = getOffsetFromIndex(list, key); - if( offset != -1 ) - { - index_item_t *this; + if (offset != -1) { + index_item_t *this; - this = list->list[offset]; - return this->data; - } + this = list->list[offset]; + return this->data; + } - return NULL; + return NULL; } -void delFromIndex(list_t *list, int key) +void +delFromIndex(list_t * list, int key) { - int offset; + int offset; - offset = getOffsetFromIndex(list, key); + offset = getOffsetFromIndex(list, key); - if( offset != -1 ) - { - delListItem(list, offset, destroyIndexItem); - } + if (offset != -1) { + delListItem(list, offset, destroyIndexItem); + } } -void delFromIndexWithObject(list_t *list, int key, void *f) +void +delFromIndexWithObject(list_t * list, int key, void *f) { - int offset; + int offset; - offset = getOffsetFromIndex(list, key); + offset = getOffsetFromIndex(list, key); - if( offset != -1 ) - { - index_item_t *this; - void (*fce)(void *p); + if (offset != -1) { + index_item_t *this; + void (*fce) (void *p); - this = list->list[offset]; + this = list->list[offset]; - fce = f; - fce(this); + fce = f; + fce(this); - delListItem(list, offset, destroyIndexItem); - } + delListItem(list, offset, destroyIndexItem); + } } -void actionIndexWithObject(list_t *list, void *f) +void +actionIndexWithObject(list_t * list, void *f) { - int i; + int i; - for( i = 0 ; i < list->count ; i++) - { - index_item_t *this; - void (*fce)(void *p); + for (i = 0; i < list->count; i++) { + index_item_t *this; + void (*fce) (void *p); - this = list->list[i]; + this = list->list[i]; - fce = f; - fce(this); - } + fce = f; + fce(this); + } } -void destroyIndex(list_t *list) +void +destroyIndex(list_t * list) { - destroyListItem(list, destroyIndexItem); + destroyListItem(list, destroyIndexItem); } -void destroyIndexWithObject(list_t *list, void *f) +void +destroyIndexWithObject(list_t * list, void *f) { - actionIndexWithObject(list, f); - destroyListItem(list, destroyIndexItem); + actionIndexWithObject(list, f); + destroyListItem(list, destroyIndexItem); } diff --git a/src/base/item.c b/src/base/item.c index 07929ed..fb93c6a 100644 --- a/src/base/item.c +++ b/src/base/item.c @@ -32,485 +32,541 @@ #include "publicServer.h" #endif -#ifndef PUBLIC_SERVER +#ifndef PUBLIC_SERVER static image_t *g_item[ITEM_COUNT]; #endif static bool_t isItemInit = FALSE; -bool_t isItemInicialized() +bool_t +isItemInicialized() { - return isItemInit; + return isItemInit; } -void initItem() +void +initItem() { -#ifndef PUBLIC_SERVER - g_item[GUN_DUAL_SIMPLE] = addImageData("item.dual.png", IMAGE_ALPHA, "item_dual_simple", IMAGE_GROUP_BASE); - g_item[GUN_TOMMY] = addImageData("item.tommy.png", IMAGE_ALPHA, "item_tommy_simple", IMAGE_GROUP_BASE); - g_item[GUN_SCATTER] = addImageData("item.scatter.png", IMAGE_ALPHA, "item_scatter_simple", IMAGE_GROUP_BASE); - g_item[GUN_LASSER] = addImageData("item.lasser.png", IMAGE_ALPHA, "item_lasser_simple", IMAGE_GROUP_BASE); - g_item[GUN_MINE] = addImageData("item.mine.png", IMAGE_ALPHA, "item_mines_simple", IMAGE_GROUP_BASE); - g_item[GUN_BOMBBALL] = addImageData("item.bombball.png", IMAGE_ALPHA, "item_bombball_simple", IMAGE_GROUP_BASE); - - g_item[ITEM_MINE] = addImageData("mine.png", IMAGE_ALPHA, "item_mine_simple", IMAGE_GROUP_BASE); - g_item[ITEM_EXPLOSION] = addImageData("explosion.png", IMAGE_ALPHA, "item_explosion_simple", IMAGE_GROUP_BASE); - g_item[ITEM_BIG_EXPLOSION] = addImageData("big-explosion.png", IMAGE_ALPHA, "item_big-explosion_simple", IMAGE_GROUP_BASE); - - g_item[BONUS_SPEED] = addImageData("item.bonus.speed.png", IMAGE_ALPHA, "item_bonus_speed", IMAGE_GROUP_BASE); - g_item[BONUS_SHOT] = addImageData("item.bonus.shot.png", IMAGE_ALPHA, "item_shot_speed", IMAGE_GROUP_BASE); - g_item[BONUS_TELEPORT] = addImageData("item.bonus.teleport.png", IMAGE_ALPHA, "item_teleport_speed", IMAGE_GROUP_BASE); - g_item[BONUS_GHOST] = addImageData("item.bonus.ghost.png", IMAGE_ALPHA, "item_ghost_speed", IMAGE_GROUP_BASE); - g_item[BONUS_4X] = addImageData("item.bonus.4x.png", IMAGE_ALPHA, "item_4x_speed", IMAGE_GROUP_BASE); - g_item[BONUS_HIDDEN] = addImageData("item.bonus.hidden.png", IMAGE_ALPHA, "item_hidden_speed", IMAGE_GROUP_BASE); +#ifndef PUBLIC_SERVER + g_item[GUN_DUAL_SIMPLE] = + addImageData("item.dual.png", IMAGE_ALPHA, "item_dual_simple", + IMAGE_GROUP_BASE); + g_item[GUN_TOMMY] = + addImageData("item.tommy.png", IMAGE_ALPHA, "item_tommy_simple", + IMAGE_GROUP_BASE); + g_item[GUN_SCATTER] = + addImageData("item.scatter.png", IMAGE_ALPHA, "item_scatter_simple", + IMAGE_GROUP_BASE); + g_item[GUN_LASSER] = + addImageData("item.lasser.png", IMAGE_ALPHA, "item_lasser_simple", + IMAGE_GROUP_BASE); + g_item[GUN_MINE] = + addImageData("item.mine.png", IMAGE_ALPHA, "item_mines_simple", + IMAGE_GROUP_BASE); + g_item[GUN_BOMBBALL] = + addImageData("item.bombball.png", IMAGE_ALPHA, "item_bombball_simple", + IMAGE_GROUP_BASE); + + g_item[ITEM_MINE] = + addImageData("mine.png", IMAGE_ALPHA, "item_mine_simple", + IMAGE_GROUP_BASE); + g_item[ITEM_EXPLOSION] = + addImageData("explosion.png", IMAGE_ALPHA, "item_explosion_simple", + IMAGE_GROUP_BASE); + g_item[ITEM_BIG_EXPLOSION] = + addImageData("big-explosion.png", IMAGE_ALPHA, + "item_big-explosion_simple", IMAGE_GROUP_BASE); + + g_item[BONUS_SPEED] = + addImageData("item.bonus.speed.png", IMAGE_ALPHA, "item_bonus_speed", + IMAGE_GROUP_BASE); + g_item[BONUS_SHOT] = + addImageData("item.bonus.shot.png", IMAGE_ALPHA, "item_shot_speed", + IMAGE_GROUP_BASE); + g_item[BONUS_TELEPORT] = + addImageData("item.bonus.teleport.png", IMAGE_ALPHA, + "item_teleport_speed", IMAGE_GROUP_BASE); + g_item[BONUS_GHOST] = + addImageData("item.bonus.ghost.png", IMAGE_ALPHA, "item_ghost_speed", + IMAGE_GROUP_BASE); + g_item[BONUS_4X] = + addImageData("item.bonus.4x.png", IMAGE_ALPHA, "item_4x_speed", + IMAGE_GROUP_BASE); + g_item[BONUS_HIDDEN] = + addImageData("item.bonus.hidden.png", IMAGE_ALPHA, + "item_hidden_speed", IMAGE_GROUP_BASE); #endif - isItemInit = TRUE; + isItemInit = TRUE; } -item_t* newItem(int x, int y, int type, int author_id) +item_t * +newItem(int x, int y, int type, int author_id) { - item_t *new; - - new = malloc( sizeof(item_t) ); - assert( new != NULL ); - new->type = type; - new->id = getNewID(); - new->x = x; - new->y = y; - new->frame = 0; - new->count = 0; -#ifndef PUBLIC_SERVER - new->img = g_item[type]; -#endif - new->author_id = author_id; - switch (type) { - case GUN_DUAL_SIMPLE : - case GUN_SCATTER : - case GUN_TOMMY : - case GUN_LASSER : - case GUN_MINE : - case GUN_BOMBBALL : - new->w = ITEM_GUN_WIDTH; - new->h = ITEM_GUN_HEIGHT; - break; - case ITEM_MINE : - new->w = ITEM_MINE_WIDTH; - new->h = ITEM_MINE_HEIGHT; - break; - case ITEM_EXPLOSION : + item_t *new; + + new = malloc(sizeof(item_t)); + assert(new != NULL); + new->type = type; + new->id = getNewID(); + new->x = x; + new->y = y; + new->frame = 0; + new->count = 0; +#ifndef PUBLIC_SERVER + new->img = g_item[type]; +#endif + new->author_id = author_id; + switch (type) { + case GUN_DUAL_SIMPLE: + case GUN_SCATTER: + case GUN_TOMMY: + case GUN_LASSER: + case GUN_MINE: + case GUN_BOMBBALL: + new->w = ITEM_GUN_WIDTH; + new->h = ITEM_GUN_HEIGHT; + break; + case ITEM_MINE: + new->w = ITEM_MINE_WIDTH; + new->h = ITEM_MINE_HEIGHT; + break; + case ITEM_EXPLOSION: #ifndef NO_SOUND - playSound("explozion", SOUND_GROUP_BASE); -#endif - new->w = ITEM_EXPLOSION_WIDTH; - new->h = ITEM_EXPLOSION_HEIGHT; - break; - case ITEM_BIG_EXPLOSION : + playSound("explozion", SOUND_GROUP_BASE); +#endif + new->w = ITEM_EXPLOSION_WIDTH; + new->h = ITEM_EXPLOSION_HEIGHT; + break; + case ITEM_BIG_EXPLOSION: #ifndef NO_SOUND - playSound("explozion", SOUND_GROUP_BASE); -#endif - new->w = ITEM_BIG_EXPLOSION_WIDTH; - new->h = ITEM_BIG_EXPLOSION_HEIGHT; - break; - case BONUS_SPEED : - case BONUS_SHOT : - case BONUS_TELEPORT : - case BONUS_GHOST : - case BONUS_4X : - case BONUS_HIDDEN : - new->w = ITEM_BONUS_WIDTH; - new->h = ITEM_BONUS_HEIGHT; - break; - } - return new; + playSound("explozion", SOUND_GROUP_BASE); +#endif + new->w = ITEM_BIG_EXPLOSION_WIDTH; + new->h = ITEM_BIG_EXPLOSION_HEIGHT; + break; + case BONUS_SPEED: + case BONUS_SHOT: + case BONUS_TELEPORT: + case BONUS_GHOST: + case BONUS_4X: + case BONUS_HIDDEN: + new->w = ITEM_BONUS_WIDTH; + new->h = ITEM_BONUS_HEIGHT; + break; + } + return new; } -void getStatusItem(void *p, int *id, int *x, int *y ,int *w, int *h) +void +getStatusItem(void *p, int *id, int *x, int *y, int *w, int *h) { - item_t *item; - - item = p; - *id = item->id; - *x = item->x; - *y = item->y; - *w = item->w; - *h = item->h; + item_t *item; + + item = p; + *id = item->id; + *x = item->x; + *y = item->y; + *w = item->w; + *h = item->h; } -void setStatusItem(void *p, int x, int y, int w, int h) +void +setStatusItem(void *p, int x, int y, int w, int h) { - item_t *item; + item_t *item; - item = p; - item->x = x; - item->y = y; - item->w = w; - item->h = h; + item = p; + item->x = x; + item->y = y; + item->w = w; + item->h = h; } -void replaceItemID(item_t *item, int id) +void +replaceItemID(item_t * item, int id) { - replaceID(item->id, id); - item->id = id; + replaceID(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 ) ) - { - (*count)++; - } + if ((item->type >= GUN_DUAL_SIMPLE && item->type <= GUN_BOMBBALL) || + (item->type >= BONUS_SPEED && item->type <= BONUS_HIDDEN)) { + (*count)++; + } } -static int getCountWeaponOrBonusItem(space_t *spaceItem) +static int +getCountWeaponOrBonusItem(space_t * spaceItem) { - int count = 0; + int count = 0; - actionSpace(spaceItem, action_countitem, &count); + actionSpace(spaceItem, action_countitem, &count); - return count; + return count; } #endif -void addNewItem(space_t *spaceItem, int author_id) +void +addNewItem(space_t * spaceItem, int author_id) { - arena_t *arena; - item_t *item; - int new_x, new_y; - int type; - -#ifdef PUBLIC_SERVER - if( getCountWeaponOrBonusItem(spaceItem) >= atoi( getSetting("MAX_ITEM", "--max-item", "100") ) ) - { - return; - } + arena_t *arena; + item_t *item; + int new_x, new_y; + int type; + +#ifdef PUBLIC_SERVER + if (getCountWeaponOrBonusItem(spaceItem) >= + atoi(getSetting("MAX_ITEM", "--max-item", "100"))) { + return; + } #endif -#ifndef PUBLIC_SERVER - if( isSettingAnyItem() == FALSE || - getNetTypeGame() == NET_GAME_TYPE_CLIENT ) - { - return; - } +#ifndef PUBLIC_SERVER + if (isSettingAnyItem() == FALSE || + getNetTypeGame() == NET_GAME_TYPE_CLIENT) { + return; + } #endif - arena = getCurrentArena(); - findFreeSpace(getCurrentArena(), &new_x, &new_y, ITEM_GUN_WIDTH, ITEM_GUN_HEIGHT); + arena = getCurrentArena(); + findFreeSpace(getCurrentArena(), &new_x, &new_y, ITEM_GUN_WIDTH, + ITEM_GUN_HEIGHT); - type = GUN_DUAL_SIMPLE; + type = GUN_DUAL_SIMPLE; #ifndef PUBLIC_SERVER - do { + do { #endif - switch (random() % 12) { - case 0 : - type = GUN_DUAL_SIMPLE; - break; - case 1 : - type = GUN_SCATTER; - break; - case 2 : - type = GUN_TOMMY; - break; - case 3 : - type = GUN_MINE; - break; - case 4 : - type = GUN_LASSER; - break; - case 5 : - type = GUN_BOMBBALL; - break; - case 6 : - type = BONUS_SPEED; - break; - case 7 : - type = BONUS_SHOT; - break; - case 8 : - type = BONUS_TELEPORT; - break; - case 9 : - type = BONUS_GHOST; - break; - case 10 : - type = BONUS_4X; - break; - case 11 : - type = BONUS_HIDDEN; - break; - } + switch (random() % 12) { + case 0: + type = GUN_DUAL_SIMPLE; + break; + case 1: + type = GUN_SCATTER; + break; + case 2: + type = GUN_TOMMY; + break; + case 3: + type = GUN_MINE; + break; + case 4: + type = GUN_LASSER; + break; + case 5: + type = GUN_BOMBBALL; + break; + case 6: + type = BONUS_SPEED; + break; + case 7: + type = BONUS_SHOT; + break; + case 8: + type = BONUS_TELEPORT; + break; + case 9: + type = BONUS_GHOST; + break; + case 10: + type = BONUS_4X; + break; + case 11: + type = BONUS_HIDDEN; + break; + } #ifndef PUBLIC_SERVER - } while (isSettingItem(type) == FALSE || - (getNetTypeGame() == NET_GAME_TYPE_NONE - && type == BONUS_HIDDEN)); + } while (isSettingItem(type) == FALSE || + (getNetTypeGame() == NET_GAME_TYPE_NONE + && type == BONUS_HIDDEN)); #endif - item = newItem(new_x, new_y, type, author_id); - addObjectToSpace(spaceItem, item); - if (getNetTypeGame() == NET_GAME_TYPE_SERVER) - proto_send_additem_server(PROTO_SEND_ALL, NULL, item); + item = newItem(new_x, new_y, type, author_id); + addObjectToSpace(spaceItem, item); + if (getNetTypeGame() == NET_GAME_TYPE_SERVER) + proto_send_additem_server(PROTO_SEND_ALL, NULL, item); #ifndef PUBLIC_SERVER - if (getNetTypeGame() != NET_GAME_TYPE_CLIENT) - addToRadar(item->id, new_x, new_y, RADAR_TYPE_ITEM); + if (getNetTypeGame() != NET_GAME_TYPE_CLIENT) + addToRadar(item->id, new_x, new_y, RADAR_TYPE_ITEM); #endif } #ifndef PUBLIC_SERVER -void drawItem(item_t *p) +void +drawItem(item_t * p) { - assert(p != NULL); - addLayer(p->img, p->x, p->y, p->frame * p->w, 0, p->w, p->h, TUX_LAYER); + assert(p != NULL); + addLayer(p->img, p->x, p->y, p->frame * p->w, 0, p->w, p->h, TUX_LAYER); } -void drawListItem(list_t *listItem) +void +drawListItem(list_t * listItem) { - item_t *thisItem; - int i; - - assert(listItem != NULL); - for (i = 0; i < listItem->count; i++) { - thisItem = (item_t *)listItem->list[i]; - assert( thisItem != NULL ); - drawItem(thisItem); - } + item_t *thisItem; + int i; + + assert(listItem != NULL); + for (i = 0; i < listItem->count; i++) { + thisItem = (item_t *) listItem->list[i]; + assert(thisItem != NULL); + drawItem(thisItem); + } } #endif -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; - - currentTime = getMyTime(); - item->count++; - if (item->count == ITEM_MAX_COUNT) { - item->count = 0; - item->frame++; - } - switch (item->type) { - case GUN_TOMMY : - case GUN_DUAL_SIMPLE : - case GUN_SCATTER : - case GUN_LASSER : - case GUN_MINE : - case GUN_BOMBBALL : - if (item->frame == ITEM_GUN_MAX_FRAME) - item->frame = 0; - break; - case ITEM_MINE : - 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) - delObjectFromSpaceWithObject(space, item, destroyItem); - break; - case BONUS_SPEED : - case BONUS_SHOT : - case BONUS_TELEPORT : - case BONUS_GHOST : - case BONUS_4X : - case BONUS_HIDDEN : - if( item->frame == ITEM_GUN_MAX_FRAME ) - item->frame = 0; - break; - } + my_time_t currentTime; + + currentTime = getMyTime(); + item->count++; + if (item->count == ITEM_MAX_COUNT) { + item->count = 0; + item->frame++; + } + switch (item->type) { + case GUN_TOMMY: + case GUN_DUAL_SIMPLE: + case GUN_SCATTER: + case GUN_LASSER: + case GUN_MINE: + case GUN_BOMBBALL: + if (item->frame == ITEM_GUN_MAX_FRAME) + item->frame = 0; + break; + case ITEM_MINE: + 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) + delObjectFromSpaceWithObject(space, item, destroyItem); + break; + case BONUS_SPEED: + case BONUS_SHOT: + case BONUS_TELEPORT: + case BONUS_GHOST: + case BONUS_4X: + case BONUS_HIDDEN: + if (item->frame == ITEM_GUN_MAX_FRAME) + item->frame = 0; + break; + } } -void eventListItem(space_t *spaceItem) +void +eventListItem(space_t * spaceItem) { - actionSpace(spaceItem, action_itemevent, NULL); + actionSpace(spaceItem, action_itemevent, NULL); } -static void mineExplosion(space_t *spaceItem, item_t *item) +static void +mineExplosion(space_t * spaceItem, item_t * item) { - if (getNetTypeGame() != NET_GAME_TYPE_CLIENT) { - int x, y; - item_t *item_explosion; - - x = ( item->x + item->w/2 ) - ITEM_BIG_EXPLOSION_WIDTH/2; - y = ( item->y + item->h/2 ) - ITEM_BIG_EXPLOSION_HEIGHT/2; - item_explosion = newItem(x, y, ITEM_BIG_EXPLOSION, item->author_id); - if (getNetTypeGame() == NET_GAME_TYPE_SERVER) - proto_send_additem_server(PROTO_SEND_ALL, NULL, item_explosion); - addObjectToSpace(spaceItem, item_explosion ); - } - if (getNetTypeGame() == NET_GAME_TYPE_SERVER) - proto_send_del_server(PROTO_SEND_ALL, NULL, item->id); - if (getNetTypeGame() != NET_GAME_TYPE_CLIENT) - delObjectFromSpaceWithObject(spaceItem, item, destroyItem); + if (getNetTypeGame() != NET_GAME_TYPE_CLIENT) { + int x, y; + item_t *item_explosion; + + x = (item->x + item->w / 2) - ITEM_BIG_EXPLOSION_WIDTH / 2; + y = (item->y + item->h / 2) - ITEM_BIG_EXPLOSION_HEIGHT / 2; + item_explosion = newItem(x, y, ITEM_BIG_EXPLOSION, item->author_id); + if (getNetTypeGame() == NET_GAME_TYPE_SERVER) + proto_send_additem_server(PROTO_SEND_ALL, NULL, item_explosion); + addObjectToSpace(spaceItem, item_explosion); + } + if (getNetTypeGame() == NET_GAME_TYPE_SERVER) + proto_send_del_server(PROTO_SEND_ALL, NULL, item->id); + if (getNetTypeGame() != NET_GAME_TYPE_CLIENT) + delObjectFromSpaceWithObject(spaceItem, item, destroyItem); } -static void action_item(space_t *space, item_t *item, int *isDel) +static void +action_item(space_t * space, item_t * item, int *isDel) { - arena_t *arena; - - arena = getCurrentArena(); - switch(item->type) { - case ITEM_MINE : - if( getNetTypeGame() != NET_GAME_TYPE_CLIENT ) - mineExplosion(space, item); - break; - case ITEM_EXPLOSION : - case ITEM_BIG_EXPLOSION : - *isDel = 1; - break; - } + arena_t *arena; + + arena = getCurrentArena(); + switch (item->type) { + case ITEM_MINE: + if (getNetTypeGame() != NET_GAME_TYPE_CLIENT) + mineExplosion(space, item); + break; + case ITEM_EXPLOSION: + case ITEM_BIG_EXPLOSION: + *isDel = 1; + break; + } } -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; - - actionSpaceFromLocation(spaceItem, action_item, &isDel, shot->x, shot->y, shot->w, shot->h); - if (isDel) { - if (getNetTypeGame() == NET_GAME_TYPE_SERVER) - proto_send_del_server(PROTO_SEND_ALL, NULL, shot->id); - delObjectFromSpaceWithObject(space, shot, destroyShot); - } + int isDel = 0; + + actionSpaceFromLocation(spaceItem, action_item, &isDel, shot->x, shot->y, + shot->w, shot->h); + if (isDel) { + if (getNetTypeGame() == NET_GAME_TYPE_SERVER) + proto_send_del_server(PROTO_SEND_ALL, NULL, shot->id); + delObjectFromSpaceWithObject(space, shot, destroyShot); + } } -void eventConflictShotWithItem(arena_t *arena) +void +eventConflictShotWithItem(arena_t * arena) { - if (getNetTypeGame() == NET_GAME_TYPE_CLIENT) - return; - actionSpace(arena->spaceShot, action_shot, arena->spaceItem); + if (getNetTypeGame() == NET_GAME_TYPE_CLIENT) + return; + actionSpace(arena->spaceShot, action_shot, arena->spaceItem); } -static void eventTuxIsDeadWithItem(tux_t *tux, item_t *item) +static void +eventTuxIsDeadWithItem(tux_t * tux, item_t * item) { - if (tux->bonus == BONUS_GHOST) - return; - if (tux->bonus == BONUS_TELEPORT) { - tuxTeleport(tux); - return; - } - if (item->author_id == tux->id) { - tux->score--; - if (getNetTypeGame() == NET_GAME_TYPE_SERVER) - proto_send_newtux_server(PROTO_SEND_ALL, NULL, tux); - } - if (item->author_id != tux->id) { - tux_t *author; - - author = getObjectFromSpaceWithID(getCurrentArena()->spaceTux, item->author_id); - if (author != NULL) { - author->score++; - if (getNetTypeGame() == NET_GAME_TYPE_SERVER) - proto_send_newtux_server(PROTO_SEND_ALL, NULL, author); - } - } - countRoundInc(); - eventTuxIsDead(tux); + if (tux->bonus == BONUS_GHOST) + return; + if (tux->bonus == BONUS_TELEPORT) { + tuxTeleport(tux); + return; + } + if (item->author_id == tux->id) { + tux->score--; + if (getNetTypeGame() == NET_GAME_TYPE_SERVER) + proto_send_newtux_server(PROTO_SEND_ALL, NULL, tux); + } + if (item->author_id != tux->id) { + tux_t *author; + + author = + getObjectFromSpaceWithID(getCurrentArena()->spaceTux, + item->author_id); + if (author != NULL) { + author->score++; + if (getNetTypeGame() == NET_GAME_TYPE_SERVER) + proto_send_newtux_server(PROTO_SEND_ALL, NULL, author); + } + } + countRoundInc(); + eventTuxIsDead(tux); } -static void tuxGiveBonus(tux_t *tux, item_t *item) +static void +tuxGiveBonus(tux_t * tux, item_t * item) { #ifndef NO_SOUND - playSound("item_bonus", SOUND_GROUP_BASE); + playSound("item_bonus", SOUND_GROUP_BASE); #endif - tux->bonus = item->type; - tux->bonus_time = TUX_MAX_BONUS; + tux->bonus = item->type; + tux->bonus_time = TUX_MAX_BONUS; - if (getNetTypeGame() == NET_GAME_TYPE_SERVER) - proto_send_newtux_server(PROTO_SEND_ALL, NULL, tux); + if (getNetTypeGame() == NET_GAME_TYPE_SERVER) + proto_send_newtux_server(PROTO_SEND_ALL, NULL, tux); #ifndef PUBLIC_SERVER - if (getNetTypeGame() != NET_GAME_TYPE_CLIENT) - delFromRadar(item->id); + if (getNetTypeGame() != NET_GAME_TYPE_CLIENT) + delFromRadar(item->id); #endif } -static void tuxGiveGun(tux_t *tux, item_t *item) +static void +tuxGiveGun(tux_t * tux, item_t * item) { #ifndef NO_SOUND - playSound("item_gun", SOUND_GROUP_BASE); + playSound("item_gun", SOUND_GROUP_BASE); #endif - tux->pickup_time = 0; - tux->shot[ item->type ] += GUN_MAX_SHOT; - tux->gun = item->type; + tux->pickup_time = 0; + tux->shot[item->type] += GUN_MAX_SHOT; + tux->gun = item->type; - if (getNetTypeGame() == NET_GAME_TYPE_SERVER) - proto_send_newtux_server(PROTO_SEND_ALL, NULL, tux); + if (getNetTypeGame() == NET_GAME_TYPE_SERVER) + proto_send_newtux_server(PROTO_SEND_ALL, NULL, tux); #ifndef PUBLIC_SERVER - if (getNetTypeGame() != NET_GAME_TYPE_CLIENT) - delFromRadar(item->id); + if (getNetTypeGame() != NET_GAME_TYPE_CLIENT) + delFromRadar(item->id); #endif } -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 : - case GUN_DUAL_SIMPLE : - case GUN_SCATTER : - case GUN_LASSER : - case GUN_MINE : - case GUN_BOMBBALL : - tuxGiveGun(tux, item); - if (getNetTypeGame() == NET_GAME_TYPE_SERVER) - proto_send_del_server(PROTO_SEND_ALL, NULL, item->id); - delObjectFromSpaceWithObject(space, item, destroyItem); + switch (item->type) { + case GUN_TOMMY: + case GUN_DUAL_SIMPLE: + case GUN_SCATTER: + case GUN_LASSER: + case GUN_MINE: + case GUN_BOMBBALL: + tuxGiveGun(tux, item); + if (getNetTypeGame() == NET_GAME_TYPE_SERVER) + proto_send_del_server(PROTO_SEND_ALL, NULL, item->id); + delObjectFromSpaceWithObject(space, item, destroyItem); #ifdef PUBLIC_SERVER - addNewItem(space, ID_UNKNOWN); + addNewItem(space, ID_UNKNOWN); #endif - break; - - case ITEM_MINE : - if (tux->bonus != BONUS_GHOST) - mineExplosion(space, item); - break; - case ITEM_EXPLOSION : - case ITEM_BIG_EXPLOSION : - if (tux->bonus != BONUS_GHOST) - eventTuxIsDeadWithItem(tux, item); - break; - case BONUS_SPEED : - case BONUS_SHOT : - case BONUS_TELEPORT : - case BONUS_GHOST : - case BONUS_4X : - case BONUS_HIDDEN : - tuxGiveBonus(tux, item); - if (getNetTypeGame() == NET_GAME_TYPE_SERVER) - proto_send_del_server(PROTO_SEND_ALL, NULL, item->id); - delObjectFromSpaceWithObject(space, item, destroyItem); + break; + + case ITEM_MINE: + if (tux->bonus != BONUS_GHOST) + mineExplosion(space, item); + break; + case ITEM_EXPLOSION: + case ITEM_BIG_EXPLOSION: + if (tux->bonus != BONUS_GHOST) + eventTuxIsDeadWithItem(tux, item); + break; + case BONUS_SPEED: + case BONUS_SHOT: + case BONUS_TELEPORT: + case BONUS_GHOST: + case BONUS_4X: + case BONUS_HIDDEN: + tuxGiveBonus(tux, item); + if (getNetTypeGame() == NET_GAME_TYPE_SERVER) + proto_send_del_server(PROTO_SEND_ALL, NULL, item->id); + delObjectFromSpaceWithObject(space, item, destroyItem); #ifdef PUBLIC_SERVER - addNewItem(space, ID_UNKNOWN); + addNewItem(space, ID_UNKNOWN); #endif - break; - } + break; + } } -void eventGiveTuxListItem(tux_t *tux, space_t *spaceItem) +void +eventGiveTuxListItem(tux_t * tux, space_t * spaceItem) { - int x, y, w, h; + int x, y, w, h; - assert(spaceItem != NULL); - assert(tux != NULL); + assert(spaceItem != NULL); + assert(tux != NULL); - if (getNetTypeGame() == NET_GAME_TYPE_CLIENT) - return; + if (getNetTypeGame() == NET_GAME_TYPE_CLIENT) + return; - if (tux->status == TUX_STATUS_DEAD) - return; + if (tux->status == TUX_STATUS_DEAD) + return; - getTuxProportion(tux, &x, &y, &w, &h); - actionSpaceFromLocation(spaceItem, action_giveitem, tux, x, y, w, h); + getTuxProportion(tux, &x, &y, &w, &h); + actionSpaceFromLocation(spaceItem, action_giveitem, tux, x, y, w, h); } -void destroyItem(item_t *p) +void +destroyItem(item_t * p) { - assert(p != NULL); - delID(p->id); - free(p); + assert(p != NULL); + delID(p->id); + free(p); } -void quitItem() +void +quitItem() { - isItemInit = FALSE; + isItemInit = FALSE; } diff --git a/src/base/list.c b/src/base/list.c index 72ea95e..1a5a449 100755 --- a/src/base/list.c +++ b/src/base/list.c @@ -7,161 +7,176 @@ #include "main.h" #include "list.h" -list_t* newList() +list_t * +newList() { - list_t *new; + list_t *new; - new = malloc(sizeof(list_t)); - memset(new, 0, sizeof(list_t)); - return new; + new = malloc(sizeof(list_t)); + memset(new, 0, sizeof(list_t)); + return new; } -list_t* cloneList(list_t *p) +list_t * +cloneList(list_t * p) { - list_t *new; - - assert(p != NULL); - new = malloc( sizeof(list_t) ); - memcpy(new, p, sizeof(list_t) ); - if(p->list != NULL) { - new->list = malloc( p->alloc * sizeof(void *) ); - memcpy(new->list, p->list, p->alloc * sizeof(void *)); - } - return new; + list_t *new; + + assert(p != NULL); + new = malloc(sizeof(list_t)); + memcpy(new, p, sizeof(list_t)); + if (p->list != NULL) { + new->list = malloc(p->alloc * sizeof(void *)); + memcpy(new->list, p->list, p->alloc * sizeof(void *)); + } + return new; } -list_t* cloneListItem(list_t *p, void *f) +list_t * +cloneListItem(list_t * p, void *f) { - list_t *new; - void* (*fce)(void *); - int i; - - assert(p != NULL); - assert(f != NULL); - new = cloneList(p); - fce = f; - for (i = 0; i < p->count; i++) - new->list[i] = fce(p->list[i]); - return new; + list_t *new; + void *(*fce) (void *); + int i; + + assert(p != NULL); + assert(f != NULL); + new = cloneList(p); + fce = f; + for (i = 0; i < p->count; i++) + new->list[i] = fce(p->list[i]); + return new; } -void addList(list_t *p, void *item) +void +addList(list_t * p, void *item) { - assert( p != NULL ); - - if (p->alloc == 0) { - p->alloc = LIST_ALLOC_LIMIT; - p->count = 1; - p->list = malloc(p->alloc * sizeof(void *)); - p->list[0] = item; - return; - } - - if (p->count + 1 <= p->alloc) { - p->list[p->count] = item; - p->count += 1; - return; - } - - if (p->count + 1 > p->alloc) { - void **new; + assert(p != NULL); + + if (p->alloc == 0) { + p->alloc = LIST_ALLOC_LIMIT; + p->count = 1; + p->list = malloc(p->alloc * sizeof(void *)); + p->list[0] = item; + return; + } + + if (p->count + 1 <= p->alloc) { + p->list[p->count] = item; + p->count += 1; + return; + } + + 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("Realocating 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 *)); - memcpy(new, p->list, p->count * sizeof(void *)); - free(p->list); - p->list = new; - p->list[p->count] = item; - p->count++; - return; - } + p->alloc += LIST_ALLOC_LIMIT; + new = malloc(p->alloc * sizeof(void *)); + memcpy(new, p->list, p->count * sizeof(void *)); + free(p->list); + p->list = new; + p->list[p->count] = item; + p->count++; + return; + } } -void insList(list_t *p, int n, void *item) +void +insList(list_t * p, int n, void *item) { - assert( p != NULL ); - addList(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; + assert(p != NULL); + addList(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 *getList(list_t *p, int n) +void * +getList(list_t * p, int n) { - assert(p != NULL); - assert(n >= 0 || n < p->count); - return p->list[n]; + assert(p != NULL); + assert(n >= 0 || n < p->count); + return p->list[n]; } -int searchListItem(list_t *p, void *n) +int +searchListItem(list_t * p, void *n) { - int i; + int i; - assert( p != NULL ); - for (i = 0; i < p->count; i++) - if (p->list[i] == n) - return i; - return -1; + assert(p != NULL); + for (i = 0; i < p->count; i++) + if (p->list[i] == n) + return i; + return -1; } -void delList(list_t *p, int n) +void +delList(list_t * p, int n) { - assert(p != NULL); - assert(n >= 0 || n < p->count); - memmove(p->list+n, p->list+n+1, ( (p->count-1) - n ) * sizeof(void *)); - p->count--; - if(p->count + LIST_ALLOC_LIMIT < p->alloc) { - void **new; + assert(p != NULL); + assert(n >= 0 || n < p->count); + memmove(p->list + n, p->list + n + 1, + ((p->count - 1) - n) * sizeof(void *)); + p->count--; + if (p->count + LIST_ALLOC_LIMIT < 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("Realocating 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 *) ); - memcpy(new, p->list, p->count * sizeof(void *) ); - free(p->list); - p->list = new; - } + p->alloc -= LIST_ALLOC_LIMIT; + new = malloc(p->alloc * sizeof(void *)); + memcpy(new, p->list, p->count * sizeof(void *)); + free(p->list); + p->list = new; + } } -void delListItem(list_t *p, int n, void *f) +void +delListItem(list_t * p, int n, void *f) { - int (*fce)(void *); - - assert(p != NULL); - assert(n >= 0 || n < p->count); - fce = f; - if(fce != NULL) - fce(p->list[n]); - delList(p, n); + int (*fce) (void *); + + assert(p != NULL); + assert(n >= 0 || n < p->count); + fce = f; + if (fce != NULL) + fce(p->list[n]); + delList(p, n); } -void listDoEmpty(list_t *p) +void +listDoEmpty(list_t * p) { - p->count = 0; + p->count = 0; } -void destroyList(list_t *p) +void +destroyList(list_t * p) { - assert( p != NULL ); + assert(p != NULL); - if( p->list != NULL )free(p->list); - free(p); + if (p->list != NULL) + free(p->list); + free(p); } -void destroyListItem(list_t *p, void *f) +void +destroyListItem(list_t * p, void *f) { - void (*fce)(void *); - int i; - - assert( p != NULL ); - assert( f != NULL ); - fce = f; - for (i = 0; i < p->count; i++) - fce(p->list[i]); - destroyList(p); + void (*fce) (void *); + int i; + + assert(p != NULL); + assert(f != NULL); + fce = f; + for (i = 0; i < p->count; i++) + fce(p->list[i]); + destroyList(p); } diff --git a/src/base/main.c b/src/base/main.c index 18ff5f3..4163cac 100644 --- a/src/base/main.c +++ b/src/base/main.c @@ -27,134 +27,133 @@ static int my_argc; static char **my_argv; -char* getParam(char *s) +char * +getParam(char *s) { - int i; - int len; - - len = strlen(s); - - for( i = 1 ; i < my_argc ; i++ ) - { - //printf("%s %s\n", s, my_argv[i]); - - if( strlen(my_argv[i]) < len ) - { - continue; - } - - if( strncmp(s, my_argv[i], len) == 0 ) - { - return strchr(my_argv[i], '=')+1; - } - } - - return NULL; + int i; + int len; + + len = strlen(s); + + for (i = 1; i < my_argc; i++) { + //printf("%s %s\n", s, my_argv[i]); + + if (strlen(my_argv[i]) < len) { + continue; + } + + if (strncmp(s, my_argv[i], len) == 0) { + return strchr(my_argv[i], '=') + 1; + } + } + + return NULL; } -char* getParamElse(char *s1, char *s2) +char * +getParamElse(char *s1, char *s2) { - char *ret; - ret = getParam(s1); + char *ret; + ret = getParam(s1); - if( ret == NULL) - { - return s2; - } + if (ret == NULL) { + return s2; + } - return ret; + return ret; } -bool_t isParamFlag(char *s) +bool_t +isParamFlag(char *s) { - int i; + int i; - for( i = 0 ; i < my_argc ; i++ ) - { - if( strcmp(s, my_argv[i]) == 0 ) - { - return TRUE; - } - } + for (i = 0; i < my_argc; i++) { + if (strcmp(s, my_argv[i]) == 0) { + return TRUE; + } + } - return FALSE; + return FALSE; } -char *getString(int n) +char * +getString(int n) { - char str[STR_NUM_SIZE]; - sprintf(str, "%d", n); - return strdup(str); + char str[STR_NUM_SIZE]; + sprintf(str, "%d", n); + return strdup(str); } -int* newInt(int x) +int * +newInt(int x) { - int *new; - new = malloc( sizeof(int) ); - *new = x; - return new; + int *new; + new = malloc(sizeof(int)); + *new = x; + return new; } -void accessExistFile(const char *s) +void +accessExistFile(const char *s) { - if( access(s, F_OK) != 0 ) - { - fprintf(stderr, _("File %s not found !\nProgram shutdown !\n"), s); - exit(-1); - } + if (access(s, F_OK) != 0) { + fprintf(stderr, _("File %s not found !\nProgram shutdown !\n"), s); + exit(-1); + } } -int tryExistFile (const char *s) +int +tryExistFile(const char *s) { - if (access(s, F_OK) != 0) - return 1; - else - return 0; + if (access(s, F_OK) != 0) + return 1; + else + return 0; } -int isFillPath(const char *path) +int +isFillPath(const char *path) { - assert( path != NULL); + assert(path != NULL); #ifndef __WIN32__ - if( path[0] == '/' ) // for Unix-like systems ;) + if (path[0] == '/') // for Unix-like systems ;) #else - if( path[1] == ':' ) // for Windows-like systems ;) + if (path[1] == ':') // for Windows-like systems ;) #endif - { - return 1; - } - - return 0; + { + return 1; + } + + return 0; } #ifdef __WIN32__ -int WINAPI WinMain( - HINSTANCE hInstance, - HINSTANCE hPrevInstance, - LPSTR lpCmdLine, - int nCmdShow -) +int WINAPI +WinMain(HINSTANCE hInstance, + HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) #else -int main(int argc, char *argv[]) +int +main(int argc, char *argv[]) #endif { #ifndef __WIN32__ - signal(SIGPIPE, SIG_IGN); + signal(SIGPIPE, SIG_IGN); #endif - srand( (unsigned) time(NULL) ); + srand((unsigned) time(NULL)); #ifdef NLS - setlocale( LC_ALL, "" ); - bindtextdomain( PACKAGE, PATH_LOCALE); - bind_textdomain_codeset (PACKAGE, "UTF-8"); - textdomain( PACKAGE ); + setlocale(LC_ALL, ""); + bindtextdomain(PACKAGE, PATH_LOCALE); + bind_textdomain_codeset(PACKAGE, "UTF-8"); + textdomain(PACKAGE); #endif #ifndef __WIN32__ - my_argc = argc; - my_argv = argv; + my_argc = argc; + my_argv = argv; #endif /* test_space(); @@ -162,24 +161,24 @@ int main(int argc, char *argv[]) */ #ifdef __WIN32__ - WORD wVersionRequested = MAKEWORD(1,1); // WinSock version - WSADATA data; // WinSock information structure - - /* Let's initialize WinSock */ - if( WSAStartup(wVersionRequested, &data) != 0 ) - { - fprintf(stderr, _("WinSock initialization failed !\nProgram shutdown !\n")); - exit(-1); - } + WORD wVersionRequested = MAKEWORD(1, 1); // WinSock version + WSADATA data; // WinSock information structure + + /* Let's initialize WinSock */ + if (WSAStartup(wVersionRequested, &data) != 0) { + fprintf(stderr, + _("WinSock initialization failed !\nProgram shutdown !\n")); + exit(-1); + } #endif #ifndef PUBLIC_SERVER - startGame(); + startGame(); #endif #ifdef PUBLIC_SERVER - startPublicServer(); + startPublicServer(); #endif - return 0; + return 0; } diff --git a/src/base/modules.c b/src/base/modules.c index fd9087f..6248e8a 100755 --- a/src/base/modules.c +++ b/src/base/modules.c @@ -23,276 +23,292 @@ #include "configFile.h" #endif -static export_fce_t export_fce = - { +static export_fce_t export_fce = { #ifndef PUBLIC_SERVER - .fce_addLayer = addLayer, - .fce_getImage = getImage, + .fce_addLayer = addLayer, + .fce_getImage = getImage, #endif - .fce_loadDepModule = loadDepModule, - .fce_addToShareFce = addToShareFce, - .fce_getShareFce = getShareFce, + .fce_loadDepModule = loadDepModule, + .fce_addToShareFce = addToShareFce, + .fce_getShareFce = getShareFce, - .fce_getValue = getArenaValue, - .fce_getNetTypeGame = getNetTypeGame, - .fce_getTuxProportion = getTuxProportion, - .fce_setTuxProportion = setTuxProportion, - .fce_actionTux = actionTux, + .fce_getValue = getArenaValue, + .fce_getNetTypeGame = getNetTypeGame, + .fce_getTuxProportion = getTuxProportion, + .fce_setTuxProportion = setTuxProportion, + .fce_actionTux = actionTux, - .fce_getMyTime = getMyTime, + .fce_getMyTime = getMyTime, - .fce_getCurrentArena = getCurrentArena, - .fce_conflictSpace = conflictSpace, - .fce_isFreeSpace = isFreeSpace, - .fce_findFreeSpace = findFreeSpace, + .fce_getCurrentArena = getCurrentArena, + .fce_conflictSpace = conflictSpace, + .fce_isFreeSpace = isFreeSpace, + .fce_findFreeSpace = findFreeSpace, - .fce_proto_send_module_server = proto_send_module_server, + .fce_proto_send_module_server = proto_send_module_server, #ifndef PUBLIC_SERVER - .fce_proto_send_module_client = proto_send_module_client, + .fce_proto_send_module_client = proto_send_module_client, #endif - .fce_destroyShot = destroyShot, - .fce_boundBombBall = boundBombBall, - .fce_transformOnlyLasser = transformOnlyLasser - }; + .fce_destroyShot = destroyShot, + .fce_boundBombBall = boundBombBall, + .fce_transformOnlyLasser = transformOnlyLasser +}; static list_t *listModule; -static void* getFce(module_t *p, char *s) +static void * +getFce(module_t * p, char *s) { #ifndef __WIN32__ - void *ret; - char *error; - - assert(p != NULL); - assert(s != NULL); - ret = dlsym(p->image, s); - - if ((error = dlerror()) != NULL) { - fprintf (stderr, _("Error %s occured when using getFce function!\n"), error); - return NULL; - } + void *ret; + char *error; + + assert(p != NULL); + assert(s != NULL); + ret = dlsym(p->image, s); + + if ((error = dlerror()) != NULL) { + fprintf(stderr, _("Error %s occured when using getFce function!\n"), + error); + return NULL; + } #else - FARPROC ret = GetProcAddress((HMODULE)p->image,(LPCSTR)s); - if (!ret) - fprintf(stderr, _("Error %s occured when using getFce function!\n"), s); + FARPROC ret = GetProcAddress((HMODULE) p->image, (LPCSTR) s); + if (!ret) + fprintf(stderr, _("Error %s occured when using getFce function!\n"), + s); #endif - return (void *)ret; + return (void *) ret; } -static void* mapImage(char *name) +static void * +mapImage(char *name) { #ifndef __WIN32__ - void *image; - image = dlopen (name, RTLD_LAZY); - if( image == NULL ) { - fputs (dlerror(), stderr); - return NULL; - } + void *image; + image = dlopen(name, RTLD_LAZY); + if (image == NULL) { + fputs(dlerror(), stderr); + return NULL; + } #else - 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 - ); - fputs(msg, stderr); - free(msg); - FreeLibrary(image); - return NULL; - } - //FreeLibrary(image); //never ever untag this + 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); + fputs(msg, stderr); + free(msg); + FreeLibrary(image); + return NULL; + } + //FreeLibrary(image); //never ever untag this #endif - return image; + return image; } -static void unmapImage(void *image) +static void +unmapImage(void *image) { #ifndef __WIN32__ - dlclose(image); + dlclose(image); #else - FreeLibrary(image); + FreeLibrary(image); #endif } -static void setModulePath(char *name, char *path) +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); // linux #ifdef __WIN32__ - sprintf(path, PATH_MODULES "%s" MODULE_TYPE_WIN, name); // windows + sprintf(path, PATH_MODULES "%s" MODULE_TYPE_WIN, name); // windows #endif #ifdef APPLE - sprintf(path, PATH_MODULES "%s" MODULE_TYPE_APPLE, name); // apple + sprintf(path, PATH_MODULES "%s" MODULE_TYPE_APPLE, name); // apple #endif } -static module_t* newModule(char *name) +static module_t * +newModule(char *name) { - char path[STR_PATH_SIZE]; - void *image; - module_t *ret; - - assert(name != NULL); - setModulePath(name, path); - image = mapImage(path); - if (image == NULL) { - fprintf(stderr, _("Unable to map file %s!\n"), name); - return NULL; - } - ret = malloc(sizeof(module_t)); - ret->image = image; - ret->name = strdup(name); - ret->fce_init = getFce(ret, "init"); + char path[STR_PATH_SIZE]; + void *image; + module_t *ret; + + assert(name != NULL); + setModulePath(name, path); + image = mapImage(path); + if (image == NULL) { + fprintf(stderr, _("Unable to map file %s!\n"), name); + return NULL; + } + ret = malloc(sizeof(module_t)); + ret->image = image; + ret->name = strdup(name); + ret->fce_init = getFce(ret, "init"); #ifndef PUBLIC_SERVER - ret->fce_draw = getFce(ret, "draw"); + ret->fce_draw = getFce(ret, "draw"); #endif - 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"); + 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"); #ifdef DEBUG - printf(_("Loading module: \"%s\"\n"), name); + printf(_("Loading module: \"%s\"\n"), name); #endif - if (ret->fce_init(&export_fce) != 0) { - fprintf(stderr, _("Failed initialization of module \"%s\""), name); - unmapImage(image); - free(ret->name); - free(ret); - return NULL; - } - return ret; + if (ret->fce_init(&export_fce) != 0) { + fprintf(stderr, _("Failed initialization of module \"%s\""), name); + unmapImage(image); + free(ret->name); + free(ret); + return NULL; + } + return ret; } -static int destroyModule(module_t *p) +static int +destroyModule(module_t * p) { - assert( p != NULL ); - p->fce_destroy(); - unmapImage(p->image); - free(p->name); - free(p); + assert(p != NULL); + p->fce_destroy(); + unmapImage(p->image); + free(p->name); + free(p); #ifdef DEBUG - printf(_("Destroing module...\n")); + printf(_("Destroing module...\n")); #endif - return 0; + return 0; } -void initModule() +void +initModule() { - listModule = newList(); - initShareFunction(); + listModule = newList(); + initShareFunction(); } -int isModuleLoaded(char *name) +int +isModuleLoaded(char *name) { - int i; + int i; - for (i = 0; i < listModule->count; i++) { - module_t *this; + for (i = 0; i < listModule->count; i++) { + module_t *this; - this = (module_t *)listModule->list[i]; - if (strcmp(this->name, name) == 0) - return 1; - } - return 0; + this = (module_t *) listModule->list[i]; + if (strcmp(this->name, name) == 0) + return 1; + } + return 0; } -int loadModule(char *name) +int +loadModule(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); - return -1; - } - module = newModule(name); - if (module == NULL) { - fprintf(stderr, _("Loading module %s failed!\n"), name); - return -1; - } - addList(listModule, module); - return 0; + module_t *module; + + if (isModuleLoaded(name)) { + fprintf(stderr, + _ + ("I've done this once, dont want to mess memory with module %s again!\n"), + name); + return -1; + } + module = newModule(name); + if (module == NULL) { + fprintf(stderr, _("Loading module %s failed!\n"), name); + return -1; + } + addList(listModule, module); + return 0; } -int loadDepModule(char *name) +int +loadDepModule(char *name) { - if (isModuleLoaded(name)) - return 0; - return loadModule(name); + if (isModuleLoaded(name)) + return 0; + return loadModule(name); } -void cmdModule(char *s) +void +cmdModule(char *s) { - int i; + int i; - for (i = 0; i < listModule->count; i++) { - module_t *this; - this = (module_t *)listModule->list[i]; - this->fce_cmd(s); - } + for (i = 0; i < listModule->count; i++) { + module_t *this; + this = (module_t *) listModule->list[i]; + this->fce_cmd(s); + } } #ifndef PUBLIC_SERVER -void drawModule(int x, int y, int w, int h) +void +drawModule(int x, int y, int w, int h) { - int i; + int i; - for (i = 0; i < listModule->count; i++ ) { - module_t *this; - this = (module_t *)listModule->list[i]; - this->fce_draw(x, y, w, h); - } + for (i = 0; i < listModule->count; i++) { + module_t *this; + this = (module_t *) listModule->list[i]; + this->fce_draw(x, y, w, h); + } } #endif -void eventModule() +void +eventModule() { - int i; + int i; - for (i = 0; i < listModule->count; i++ ) { - module_t *this; - this = (module_t *)listModule->list[i]; - this->fce_event(); - } + for (i = 0; i < listModule->count; i++) { + module_t *this; + this = (module_t *) listModule->list[i]; + this->fce_event(); + } } -int isConflictModule(int x, int y, int w, int h) +int +isConflictModule(int x, int y, int w, int h) { - int i; + int i; - for (i = 0; i < listModule->count; i++) { - module_t *this; + for (i = 0; i < listModule->count; i++) { + module_t *this; - this = (module_t *)listModule->list[i]; - if (this->fce_isConflict(x, y, w, h) == 1) - return 1; - } - return 0; + this = (module_t *) listModule->list[i]; + if (this->fce_isConflict(x, y, w, h) == 1) + return 1; + } + return 0; } -int recvMsgModule(char *msg) +int +recvMsgModule(char *msg) { - int i; + int i; - for (i = 0; i < listModule->count; i++) { - module_t *this; + for (i = 0; i < listModule->count; i++) { + module_t *this; - this = (module_t *)listModule->list[i]; - this->fce_recvMsg(msg); - } - return 0; + this = (module_t *) listModule->list[i]; + this->fce_recvMsg(msg); + } + return 0; } -void quitModule() +void +quitModule() { - destroyListItem(listModule, destroyModule); - quitShareFunction(); + destroyListItem(listModule, destroyModule); + quitShareFunction(); } diff --git a/src/base/myTimer.c b/src/base/myTimer.c index 4de0fcc..0121a5f 100644 --- a/src/base/myTimer.c +++ b/src/base/myTimer.c @@ -16,124 +16,139 @@ #include "interface.h" #endif -static struct timeval start = { .tv_sec = 0, .tv_usec = 0 }; +static struct timeval start = {.tv_sec = 0,.tv_usec = 0 }; -list_t* newTimer() +list_t * +newTimer() { - return newList(); + return newList(); } -void restartTimer() +void +restartTimer() { - gettimeofday(&start, NULL); + gettimeofday(&start, NULL); } -my_time_t getMyTime() +my_time_t +getMyTime() { - struct timeval now; - my_time_t ticks; - - if (start.tv_sec == 0 && start.tv_usec == 0) - restartTimer(); - gettimeofday(&now, NULL); - ticks = (now.tv_sec-start.tv_sec)*1000+(now.tv_usec-start.tv_usec)/1000; - //printf("-> %d\n", ticks); - return ticks; + struct timeval now; + my_time_t ticks; + + if (start.tv_sec == 0 && start.tv_usec == 0) + restartTimer(); + gettimeofday(&now, NULL); + ticks = + (now.tv_sec - start.tv_sec) * 1000 + (now.tv_usec - + start.tv_usec) / 1000; + //printf("-> %d\n", ticks); + return ticks; } -my_time_t getMyTimeMicro() +my_time_t +getMyTimeMicro() { - static struct timeval start = { .tv_sec = 0, .tv_usec = 0 }; - struct timeval now; - my_time_t ticks; - if (start.tv_sec == 0 && start.tv_usec == 0) - gettimeofday(&start, NULL); - gettimeofday(&now, NULL); - ticks = (now.tv_sec-start.tv_sec)*1000*1000+(now.tv_usec-start.tv_usec); - //printf("-> %d\n", ticks); - return ticks; + static struct timeval start = {.tv_sec = 0,.tv_usec = 0 }; + struct timeval now; + my_time_t ticks; + if (start.tv_sec == 0 && start.tv_usec == 0) + gettimeofday(&start, NULL); + gettimeofday(&now, NULL); + ticks = + (now.tv_sec - start.tv_sec) * 1000 * 1000 + (now.tv_usec - + start.tv_usec); + //printf("-> %d\n", ticks); + return ticks; } -my_timer_t* newTimerItem(int type, void (*fce)(void *p), void *arg, my_time_t my_time) +my_timer_t * +newTimerItem(int type, void (*fce) (void *p), void *arg, my_time_t my_time) { - static int new_id = 0; - my_timer_t *new; - assert( fce != NULL ); - new = malloc( sizeof(my_timer_t) ); - memset(new, 0, sizeof(my_timer_t)); - new->id = new_id++; - new->type = type; - new->fce = fce; - new->arg = arg; - new->createTime = getMyTime(); - new->time = my_time; - return new; + static int new_id = 0; + my_timer_t *new; + assert(fce != NULL); + new = malloc(sizeof(my_timer_t)); + memset(new, 0, sizeof(my_timer_t)); + new->id = new_id++; + new->type = type; + new->fce = fce; + new->arg = arg; + new->createTime = getMyTime(); + new->time = my_time; + return new; } -static void destroyTimerItem(my_timer_t *p) +static void +destroyTimerItem(my_timer_t * p) { - assert( p != NULL ); - free(p); + assert(p != NULL); + free(p); } -int addTaskToTimer(list_t *listTimer, int type, void (*fce)(void *p), void *arg, my_time_t my_time) +int +addTaskToTimer(list_t * listTimer, int type, void (*fce) (void *p), void *arg, + my_time_t my_time) { - my_timer_t *new; + my_timer_t *new; - new = newTimerItem(type, fce, arg, my_time); - addList(listTimer, new); - return new->id; + new = newTimerItem(type, fce, arg, my_time); + addList(listTimer, new); + return new->id; } -void eventTimer(list_t *listTimer) +void +eventTimer(list_t * listTimer) { - int i; - my_timer_t *thisTimer; - my_time_t currentTime; - currentTime = getMyTime(); - for (i = 0; i < listTimer->count; i++) { - thisTimer = (my_timer_t *)listTimer->list[i]; - assert(thisTimer != NULL); - switch (thisTimer->type) { - case TIMER_ONE: - if (currentTime >= thisTimer->createTime + thisTimer->time) { - thisTimer->fce(thisTimer->arg); - delListItem(listTimer, i, free); - i--; - } - break; - case TIMER_PERIODIC: - if (currentTime >= thisTimer->createTime + thisTimer->time) { - thisTimer->fce(thisTimer->arg); - thisTimer->createTime = getMyTime(); - } - break; - default : - assert(! _("Timer is really wierdly set!")); - break; - } - } + int i; + my_timer_t *thisTimer; + my_time_t currentTime; + currentTime = getMyTime(); + for (i = 0; i < listTimer->count; i++) { + thisTimer = (my_timer_t *) listTimer->list[i]; + assert(thisTimer != NULL); + switch (thisTimer->type) { + case TIMER_ONE: + if (currentTime >= thisTimer->createTime + thisTimer->time) { + thisTimer->fce(thisTimer->arg); + delListItem(listTimer, i, free); + i--; + } + break; + case TIMER_PERIODIC: + if (currentTime >= thisTimer->createTime + thisTimer->time) { + thisTimer->fce(thisTimer->arg); + thisTimer->createTime = getMyTime(); + } + break; + default: + assert(!_("Timer is really wierdly set!")); + break; + } + } } -void delTimer(list_t *listTimer, int id) +void +delTimer(list_t * listTimer, int id) { - int i; - my_timer_t *thisTimer; - - for (i = 0; i < listTimer->count; i++) { - thisTimer = (my_timer_t *)listTimer->list[i]; - assert(thisTimer != NULL); - if (thisTimer->id == id ) { - delListItem(listTimer, i, free); - return; - } - } - assert(! _("There is no such ID!")); + int i; + my_timer_t *thisTimer; + + for (i = 0; i < listTimer->count; i++) { + thisTimer = (my_timer_t *) listTimer->list[i]; + assert(thisTimer != NULL); + if (thisTimer->id == id) { + delListItem(listTimer, i, free); + return; + } + } + assert(!_("There is no such ID!")); } -void destroyTimer(list_t *listTimer) +void +destroyTimer(list_t * listTimer) { - destroyListItem(listTimer, destroyTimerItem); + destroyListItem(listTimer, destroyTimerItem); } diff --git a/src/base/net_multiplayer.c b/src/base/net_multiplayer.c index f7d54eb..ef0deab 100644 --- a/src/base/net_multiplayer.c +++ b/src/base/net_multiplayer.c @@ -24,116 +24,116 @@ static int netGameType; -int getNetTypeGame() +int +getNetTypeGame() { - return netGameType; + return netGameType; } -int initNetMuliplayerForGameServer(char *ip4, int port4, char *ip6, int port6) +int +initNetMuliplayerForGameServer(char *ip4, int port4, char *ip6, int port6) { - int ret; + int ret; - ret = initServer(ip4, port4, ip6, port6); + ret = initServer(ip4, port4, ip6, port6); - if( ret > 0 ) - { - netGameType = NET_GAME_TYPE_SERVER; - } + if (ret > 0) { + netGameType = NET_GAME_TYPE_SERVER; + } - return ret; + return ret; } -int initNetMuliplayer(int type, char *ip, int port, int proto) +int +initNetMuliplayer(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( initServer(ip, port, NULL, 0) != 1 ) - { - fprintf(stderr, _("Unable to inicialize network game as server!\n")); - netGameType = NET_GAME_TYPE_NONE; - return -1; - } - break; - case PROTO_UDPv6 : - if( initServer(NULL, 0, ip, port) != 1 ) - { - fprintf(stderr, _("Unable to inicialize network game as server!\n")); - netGameType = NET_GAME_TYPE_NONE; - return -1; - } - break; - } - break; - -#ifndef PUBLIC_SERVER - case NET_GAME_TYPE_CLIENT : - if( initClient(ip, port, proto) != 0 ) - { - fprintf(stderr, _("Unable to inicialize network game as client!\n")); - netGameType = NET_GAME_TYPE_NONE; - return -1; - } - break; + netGameType = type; + + switch (netGameType) { + case NET_GAME_TYPE_NONE: + break; + + case NET_GAME_TYPE_SERVER: + switch (proto) { + case PROTO_UDPv4: + if (initServer(ip, port, NULL, 0) != 1) { + fprintf(stderr, + _("Unable to inicialize network game as server!\n")); + netGameType = NET_GAME_TYPE_NONE; + return -1; + } + break; + case PROTO_UDPv6: + if (initServer(NULL, 0, ip, port) != 1) { + fprintf(stderr, + _("Unable to inicialize network game as server!\n")); + netGameType = NET_GAME_TYPE_NONE; + return -1; + } + break; + } + break; + +#ifndef PUBLIC_SERVER + case NET_GAME_TYPE_CLIENT: + if (initClient(ip, port, proto) != 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 wierd value!") ); - break; - } + default: + assert(!_("Variable netGameType has a really wierd value!")); + break; + } - return 0; + return 0; } -void eventNetMultiplayer() +void +eventNetMultiplayer() { - switch( netGameType ) - { - case NET_GAME_TYPE_NONE : - break; - - case NET_GAME_TYPE_SERVER : - eventServer(); - break; - -#ifndef PUBLIC_SERVER - case NET_GAME_TYPE_CLIENT : - eventClient(); - break; + switch (netGameType) { + case NET_GAME_TYPE_NONE: + break; + + case NET_GAME_TYPE_SERVER: + eventServer(); + break; + +#ifndef PUBLIC_SERVER + case NET_GAME_TYPE_CLIENT: + eventClient(); + break; #endif - default : - assert( ! _("Variable netGameType has a really wierd value!") ); - break; - } + default: + assert(!_("Variable netGameType has a really wierd value!")); + break; + } } -void quitNetMultiplayer() +void +quitNetMultiplayer() { - switch( netGameType ) - { - case NET_GAME_TYPE_NONE : - break; - - case NET_GAME_TYPE_SERVER : - quitServer(); - break; - -#ifndef PUBLIC_SERVER - case NET_GAME_TYPE_CLIENT : - quitClient(); - break; + switch (netGameType) { + case NET_GAME_TYPE_NONE: + break; + + case NET_GAME_TYPE_SERVER: + quitServer(); + break; + +#ifndef PUBLIC_SERVER + case NET_GAME_TYPE_CLIENT: + quitClient(); + break; #endif - default : - assert( ! _("Variable netGameType has a really wierd value!") ); - break; - } + default: + assert(!_("Variable netGameType has a really wierd value!")); + break; + } - netGameType = NET_GAME_TYPE_NONE; + netGameType = NET_GAME_TYPE_NONE; } diff --git a/src/base/protect.c b/src/base/protect.c index e83c1ec..acfc1e3 100644 --- a/src/base/protect.c +++ b/src/base/protect.c @@ -8,68 +8,72 @@ #include "myTimer.h" #include "protect.h" -protect_t* newProtect() +protect_t * +newProtect() { - protect_t *new; - new = malloc( sizeof(protect_t) ); - new->lastMove = getMyTime(); - new->lastPing = getMyTime(); - new->avarage = 0; - new->count = 0; - new->isDown = FALSE; - return new; + protect_t *new; + new = malloc(sizeof(protect_t)); + new->lastMove = getMyTime(); + new->lastPing = getMyTime(); + new->avarage = 0; + new->count = 0; + new->isDown = FALSE; + return new; } -void refreshLastMove(protect_t *p) +void +refreshLastMove(protect_t * p) { - my_time_t currentTime; - my_time_t interval; + my_time_t currentTime; + my_time_t interval; - currentTime = getMyTime(); - interval = currentTime - p->lastMove; - p->lastMove = getMyTime(); - p->avarage += interval; - p->count++; - if (p->count == PROTECT_SPEED_AVARAGE) { - int index; + currentTime = getMyTime(); + interval = currentTime - p->lastMove; + p->lastMove = getMyTime(); + p->avarage += interval; + p->count++; + if (p->count == PROTECT_SPEED_AVARAGE) { + int index; - index = p->avarage/PROTECT_SPEED_AVARAGE; - p->avarage = 0; - p->count = 0; + index = p->avarage / PROTECT_SPEED_AVARAGE; + p->avarage = 0; + p->count = 0; #if 0 - if( index < PROTECT_SPEED_INTERVAL_TIMEOUT ) - { - p->isDown = TRUE; - } + if (index < PROTECT_SPEED_INTERVAL_TIMEOUT) { + p->isDown = TRUE; + } #endif - //printf("speed index = %d\n", index); - } + //printf("speed index = %d\n", index); + } } -void rereshLastPing(protect_t *p) +void +rereshLastPing(protect_t * p) { - //my_time_t currentTime; - //my_time_t interval; - //currentTime = getMyTime(); - //interval = currentTime - p->lastPing; - p->lastPing = getMyTime(); - //printf("interval = %d\n", interval); + //my_time_t currentTime; + //my_time_t interval; + //currentTime = getMyTime(); + //interval = currentTime - p->lastPing; + p->lastPing = getMyTime(); + //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; + my_time_t currentTime; + my_time_t interval; - currentTime = getMyTime(); - interval = currentTime - p->lastPing; - if (interval > PROTECT_PING_INTERVAL_TIMEOUT) - p->isDown = TRUE; - return p->isDown; + currentTime = getMyTime(); + interval = currentTime - p->lastPing; + 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); + assert(p != NULL); + free(p); } diff --git a/src/base/proto.c b/src/base/proto.c index 304eff8..c54c092 100644 --- a/src/base/proto.c +++ b/src/base/proto.c @@ -38,101 +38,106 @@ #include "serverConfigFile.h" #endif -void proto_send_error_server(int type, client_t *client, int errorcode) +void +proto_send_error_server(int type, client_t * client, int errorcode) { - char msg[STR_PROTO_SIZE]; - - snprintf(msg, STR_PROTO_SIZE, "error %d\n", errorcode); + char msg[STR_PROTO_SIZE]; - protoSendClient(type, client, msg, CHECK_FRONT_TYPE_SIMPLE, CHECK_FRONT_ID_NONE); + snprintf(msg, STR_PROTO_SIZE, "error %d\n", errorcode); + + protoSendClient(type, client, msg, CHECK_FRONT_TYPE_SIMPLE, + CHECK_FRONT_ID_NONE); } #ifndef PUBLIC_SERVER -void proto_recv_error_client(char *msg) +void +proto_recv_error_client(char *msg) { - char cmd[STR_PROTO_SIZE]; - int errorcode; - int recv_count; + char cmd[STR_PROTO_SIZE]; + int errorcode; + int recv_count; - assert( msg != NULL ); + assert(msg != NULL); - recv_count = sscanf(msg, "%s %d", - cmd, &errorcode); + recv_count = sscanf(msg, "%s %d", cmd, &errorcode); - if( recv_count != 2 ) - { - return; - } + if (recv_count != 2) { + return; + } #ifdef DEBUG - printf(_("Proto error code: \"%d\"\n"), errorcode); + printf(_("Proto error code: \"%d\"\n"), errorcode); #endif - switch(errorcode) - { - case PROTO_ERROR_CODE_BAD_VERSION : - setMsgToAnalyze(_("Version of your client isn't supported by the server.")); - setWorldEnd(); - break; - case PROTO_ERROR_CODE_TIMEOUT : - setMsgToAnalyze(_("The timeout of ping from server is out")); - setWorldEnd(); - break; - case PROTO_ERROR_LIMIT_MAX_CLIENT : - setMsgToAnalyze(_("The maximum amount of connected players has been exceeded!")); - setWorldEnd(); - break; - } + switch (errorcode) { + case PROTO_ERROR_CODE_BAD_VERSION: + setMsgToAnalyze(_ + ("Version of your client isn't supported by the server.")); + setWorldEnd(); + break; + case PROTO_ERROR_CODE_TIMEOUT: + setMsgToAnalyze(_("The timeout of ping from server is out")); + setWorldEnd(); + break; + case PROTO_ERROR_LIMIT_MAX_CLIENT: + setMsgToAnalyze(_ + ("The maximum amount of connected players has been exceeded!")); + setWorldEnd(); + break; + } } #endif #ifndef PUBLIC_SERVER -void proto_send_hello_client(char *name) +void +proto_send_hello_client(char *name) { - char msg[STR_PROTO_SIZE]; - - snprintf(msg, STR_PROTO_SIZE, "hello %s %s\n", getParamElse("--version", TUXANCI_VERSION), name); - sendServer(msg); + char msg[STR_PROTO_SIZE]; + + snprintf(msg, STR_PROTO_SIZE, "hello %s %s\n", + getParamElse("--version", TUXANCI_VERSION), name); + sendServer(msg); } #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) { - proto_send_additem_server(PROTO_SEND_ONE, client, item); + 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; - tux_t *thisTux; - int i; + list_t *listClient; + client_t *thisClient; + tux_t *thisTux; + int i; - assert( client != NULL ); + assert(client != NULL); - listClient = getListServerClient(); + listClient = getListServerClient(); - proto_send_init_server(PROTO_SEND_ONE, client, client); + proto_send_init_server(PROTO_SEND_ONE, client, client); #ifndef PUBLIC_SERVER - proto_send_newtux_server(PROTO_SEND_ONE, client, getControlTux(TUX_CONTROL_KEYBOARD_RIGHT) ); + proto_send_newtux_server(PROTO_SEND_ONE, client, + getControlTux(TUX_CONTROL_KEYBOARD_RIGHT)); #endif - for( i = 0 ; i < listClient->count; i++) - { - thisClient = (client_t *) listClient->list[i]; - thisTux = thisClient->tux; - - if( thisTux != NULL && thisTux != client->tux ) - { - proto_send_newtux_server(PROTO_SEND_ONE, thisClient, client->tux); - proto_send_newtux_server(PROTO_SEND_ONE, client, thisTux); - } - } + for (i = 0; i < listClient->count; i++) { + thisClient = (client_t *) listClient->list[i]; + thisTux = thisClient->tux; - actionSpace(getCurrentArena()->spaceItem, action_sendItem, client); + if (thisTux != NULL && thisTux != client->tux) { + proto_send_newtux_server(PROTO_SEND_ONE, thisClient, client->tux); + proto_send_newtux_server(PROTO_SEND_ONE, client, thisTux); + } + } + + actionSpace(getCurrentArena()->spaceItem, action_sendItem, client); /* for( i = 0 ; i < getCurrentArena()->spaceItem->listIndex->count; i++) { @@ -142,866 +147,896 @@ static void sendInfoCreateClient(client_t *client) */ } -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]; - char version[STR_NAME_SIZE]; - char name[STR_NAME_SIZE]; - int recv_count; - - assert( client != NULL ); - - if( getSpaceCount(getCurrentArena()->spaceTux)+1 > getServerMaxClients() ) - { - proto_send_error_server(PROTO_SEND_ONE, client, PROTO_ERROR_LIMIT_MAX_CLIENT); - eventMsgInCheckFront(client); - client->status = NET_STATUS_ZOMBIE; - return; - } + static char *supportVersion = NULL; + char cmd[STR_PROTO_SIZE]; + char version[STR_NAME_SIZE]; + char name[STR_NAME_SIZE]; + int recv_count; + + assert(client != NULL); + + if (getSpaceCount(getCurrentArena()->spaceTux) + 1 > + getServerMaxClients()) { + proto_send_error_server(PROTO_SEND_ONE, client, + PROTO_ERROR_LIMIT_MAX_CLIENT); + eventMsgInCheckFront(client); + client->status = NET_STATUS_ZOMBIE; + return; + } + + strcpy(version, ""); + strcpy(name, ""); - strcpy(version, ""); - strcpy(name, ""); - #ifdef PUBLIC_SERVER - if( supportVersion == NULL ) - { - supportVersion = getSetting("SUPPORT_CLIENTS", "--support-clients", TUXANCI_VERSION); - } + if (supportVersion == NULL) { + supportVersion = + getSetting("SUPPORT_CLIENTS", "--support-clients", + TUXANCI_VERSION); + } #endif #ifndef PUBLIC_SERVER - if( supportVersion == NULL ) - { - supportVersion = TUXANCI_VERSION; - } + if (supportVersion == NULL) { + supportVersion = TUXANCI_VERSION; + } #endif - recv_count = sscanf(msg, "%s %s %s", cmd, version, name); + recv_count = sscanf(msg, "%s %s %s", cmd, version, name); - if( recv_count != 3 ) - { - return; - } + if (recv_count != 3) { + return; + } - if( strstr(supportVersion, version ) == NULL ) - { - proto_send_error_server(PROTO_SEND_ONE, client, PROTO_ERROR_CODE_BAD_VERSION); - eventMsgInCheckFront(client); - client->status = NET_STATUS_ZOMBIE; - return; - } + if (strstr(supportVersion, version) == NULL) { + proto_send_error_server(PROTO_SEND_ONE, client, + PROTO_ERROR_CODE_BAD_VERSION); + eventMsgInCheckFront(client); + client->status = NET_STATUS_ZOMBIE; + return; + } - client->tux = newTux(); - client->tux->control = TUX_CONTROL_NET; - client->tux->client = client; + client->tux = newTux(); + client->tux->control = TUX_CONTROL_NET; + client->tux->client = client; - addObjectToSpace(getCurrentArena()->spaceTux, client->tux); + addObjectToSpace(getCurrentArena()->spaceTux, client->tux); - if( strlen(name) > STR_NAME_SIZE-1 ) - { - name[STR_NAME_SIZE-1] = '\0'; - } + if (strlen(name) > STR_NAME_SIZE - 1) { + name[STR_NAME_SIZE - 1] = '\0'; + } - tuxSetName(client->tux, name); - sendInfoCreateClient(client); + tuxSetName(client->tux, name); + 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; - char *version; - int clients; - int maxclients; - unsigned int uptime; - char *arena; + char msg[STR_PROTO_SIZE]; + char *name; + char *version; + int clients; + int maxclients; + unsigned int uptime; + char *arena; #ifndef PUBLIC_SERVER - name = "noname"; + name = "noname"; #endif #ifdef PUBLIC_SERVER - name = getSetting("NAME", "--name", "noname"); + name = getSetting("NAME", "--name", "noname"); #endif - version = TUXANCI_VERSION; - clients = getCurrentArena()->spaceTux->listIndex->count; - maxclients = getServerMaxClients(); - uptime = (unsigned int)getUpdateServer(); - arena = getArenaNetName( getChoiceArena() ); - - 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); - - protoSendClient(type, client, msg, CHECK_FRONT_TYPE_SIMPLE, CHECK_FRONT_ID_NONE); - //proto_send(type, client, msg); + version = TUXANCI_VERSION; + clients = getCurrentArena()->spaceTux->listIndex->count; + maxclients = getServerMaxClients(); + uptime = (unsigned int) getUpdateServer(); + arena = getArenaNetName(getChoiceArena()); + + 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); + + protoSendClient(type, client, msg, CHECK_FRONT_TYPE_SIMPLE, + CHECK_FRONT_ID_NONE); + //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) { - proto_send_status_server(PROTO_SEND_ONE, client); + proto_send_status_server(PROTO_SEND_ONE, client); } #ifdef PUBLIC_SERVER -void proto_send_listscore_server(int type, client_t *client, int max) +void +proto_send_listscore_server(int type, client_t * client, int max) { - char *str; - char *msg; - int i; + char *str; + char *msg; + int i; - msg = malloc( (max * 48) * sizeof(char) ); - strcpy(msg, ""); + msg = malloc((max * 48) * sizeof(char)); + strcpy(msg, ""); - for( i = 0 ; i < max ; i++ ) - { - str = getTableItem(i); + for (i = 0; i < max; i++) { + str = getTableItem(i); - if( str == NULL ) - { - break; - } + if (str == NULL) { + break; + } - strcat(msg, str); - strcat(msg, "\n"); - } + strcat(msg, str); + strcat(msg, "\n"); + } - //proto_send(type, client, msg); - protoSendClient(type, client, msg, CHECK_FRONT_TYPE_SIMPLE, CHECK_FRONT_ID_NONE); - free(msg); + //proto_send(type, client, msg); + protoSendClient(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; - int max; + char cmd[STR_PROTO_SIZE]; + int recv_count; + int max; - assert( msg != NULL ); + assert(msg != NULL); - recv_count = sscanf(msg, "%s %d", - cmd, &max); + recv_count = sscanf(msg, "%s %d", cmd, &max); - if( recv_count != 2 ) - { - max = HEIGHTSCORE_MAX_PLAYERS; - } + if (recv_count != 2) { + max = HEIGHTSCORE_MAX_PLAYERS; + } - proto_send_listscore_server(PROTO_SEND_ONE, client, max); + proto_send_listscore_server(PROTO_SEND_ONE, client, max); } #endif #ifndef PUBLIC_SERVER -void proto_send_check_client(int id) +void +proto_send_check_client(int id) { - char msg[STR_PROTO_SIZE]; - - snprintf(msg, STR_PROTO_SIZE, "check %d\n", id); - sendServer(msg); + char msg[STR_PROTO_SIZE]; + + snprintf(msg, STR_PROTO_SIZE, "check %d\n", id); + sendServer(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; - int id; + char cmd[STR_PROTO_SIZE]; + int recv_count; + int id; - assert( msg != NULL ); + assert(msg != NULL); - recv_count = sscanf(msg, "%s %d", - cmd, &id); + recv_count = sscanf(msg, "%s %d", cmd, &id); - if( recv_count != 2 ) - { - return; - } + if (recv_count != 2) { + return; + } - delMsgInCheckFront(client->listSendMsg, id); + delMsgInCheckFront(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; - int check_id; + char msg[STR_PROTO_SIZE]; + int count; + int check_id; - assert( client2 != NULL ); + assert(client2 != NULL); - count = WORLD_COUNT_ROUND_UNLIMITED; + count = WORLD_COUNT_ROUND_UNLIMITED; #ifndef PUBLIC_SERVER - getSettingCountRound(&count); + getSettingCountRound(&count); #endif - check_id = getNewIDcount(0); - - snprintf(msg, STR_PROTO_SIZE, "init %d %d %d %d %s %d\n", - client2->tux->id, client2->tux->x, client2->tux->y, - count, getArenaNetName( getChoiceArena() ), check_id); - - //proto_send(type, client, msg); - protoSendClient(type, client, msg, CHECK_FRONT_TYPE_CHECK, check_id); + check_id = getNewIDcount(0); + + snprintf(msg, STR_PROTO_SIZE, "init %d %d %d %d %s %d\n", + client2->tux->id, client2->tux->x, client2->tux->y, + count, getArenaNetName(getChoiceArena()), check_id); + + //proto_send(type, client, msg); + protoSendClient(type, client, msg, CHECK_FRONT_TYPE_CHECK, check_id); } #ifndef PUBLIC_SERVER -void proto_recv_init_client(char *msg) +void +proto_recv_init_client(char *msg) { - char cmd[STR_PROTO_SIZE]; - char arena_name[STR_PROTO_SIZE]; - tux_t *tux; - int id; - int x, y, n; - int check_id; - int recv_count; - arena_t *arena; + char cmd[STR_PROTO_SIZE]; + char arena_name[STR_PROTO_SIZE]; + tux_t *tux; + int id; + int x, y, n; + int check_id; + int recv_count; + arena_t *arena; - assert( msg != NULL ); + assert(msg != NULL); - recv_count = sscanf(msg, "%s %d %d %d %d %s %d", - cmd, &id, &x, &y, &n, arena_name, &check_id); + recv_count = sscanf(msg, "%s %d %d %d %d %s %d", + cmd, &id, &x, &y, &n, arena_name, &check_id); - if( recv_count != 7 ) - { - return; - } + if (recv_count != 7) { + return; + } - proto_send_check_client(check_id); + proto_send_check_client(check_id); - if( getCurrentArena() != NULL ) - { - return; - } + if (getCurrentArena() != NULL) { + return; + } - setWorldArena( getArenaFileFormNetName(arena_name) ); + setWorldArena(getArenaFileFormNetName(arena_name)); - arena = getCurrentArena(); - arena->max_countRound = n; + arena = getCurrentArena(); + arena->max_countRound = n; - tux = newTux(); - replaceTuxID(tux, id); - tux->x = x; - tux->y = y; - tux->control = TUX_CONTROL_KEYBOARD_RIGHT; - setControlTux(tux, TUX_CONTROL_KEYBOARD_RIGHT); + tux = newTux(); + replaceTuxID(tux, id); + tux->x = x; + tux->y = y; + tux->control = TUX_CONTROL_KEYBOARD_RIGHT; + setControlTux(tux, TUX_CONTROL_KEYBOARD_RIGHT); - getSettingNameRight(tux->name); + getSettingNameRight(tux->name); - addObjectToSpace(arena->spaceTux, tux); + addObjectToSpace(arena->spaceTux, tux); } #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); - protoSendClient(type, client, msg, CHECK_FRONT_TYPE_SIMPLE, CHECK_FRONT_ID_NONE); + char msg[STR_PROTO_SIZE]; + + snprintf(msg, STR_PROTO_SIZE, "event %d %d\n", tux->id, action); + + //proto_send(type, client, msg); + protoSendClient(type, client, msg, CHECK_FRONT_TYPE_SIMPLE, + CHECK_FRONT_ID_NONE); } #ifndef PUBLIC_SERVER -void proto_recv_event_client(char *msg) +void +proto_recv_event_client(char *msg) { - char cmd[STR_PROTO_SIZE]; - int id, action; - tux_t *tux; - int recv_count; + char cmd[STR_PROTO_SIZE]; + int id, action; + tux_t *tux; + int recv_count; - assert( msg != NULL ); + assert(msg != NULL); - recv_count = sscanf(msg, "%s %d %d", cmd, &id, &action); + recv_count = sscanf(msg, "%s %d %d", cmd, &id, &action); - if( recv_count != 3 ) - { - return; - } + if (recv_count != 3) { + return; + } - tux = getObjectFromSpaceWithID(getCurrentArena()->spaceTux, id); + tux = getObjectFromSpaceWithID(getCurrentArena()->spaceTux, id); - if( tux != NULL ) - { - actionTux(tux, action); - addToRadar(tux->id, tux->x, tux->y, RADAR_TYPE_TUX); - } + if (tux != NULL) { + actionTux(tux, action); + addToRadar(tux->id, tux->x, tux->y, RADAR_TYPE_TUX); + } } #endif #ifndef PUBLIC_SERVER -void proto_send_event_client(int action) +void +proto_send_event_client(int action) { - char msg[STR_PROTO_SIZE]; - - snprintf(msg, STR_PROTO_SIZE, "event %d\n", action); - - sendServer(msg); + char msg[STR_PROTO_SIZE]; + + snprintf(msg, STR_PROTO_SIZE, "event %d\n", action); + + sendServer(msg); } #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; - int recv_count; + char cmd[STR_PROTO_SIZE]; + int action; + int recv_count; - assert( client != NULL ); - assert( msg != NULL ); + assert(client != NULL); + assert(msg != NULL); - //debug_interval(); + //debug_interval(); - recv_count = sscanf(msg, "%s %d", cmd, &action); + recv_count = sscanf(msg, "%s %d", cmd, &action); - if( recv_count != 2 ) - { - return; - } + if (recv_count != 2) { + return; + } - if( client->tux->bonus != BONUS_HIDDEN ) - { - proto_send_event_server(PROTO_SEND_ALL_SEES_TUX, client, client->tux, action); - } + if (client->tux->bonus != BONUS_HIDDEN) { + proto_send_event_server(PROTO_SEND_ALL_SEES_TUX, client, client->tux, + action); + } - refreshLastMove(client->protect); + refreshLastMove(client->protect); - actionTux(client->tux, action); + actionTux(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; - - assert( tux != NULL ); - - if( tux->bonus == BONUS_HIDDEN ) - { - x = TUX_LOCATE_UNKNOWN; - y = TUX_LOCATE_UNKNOWN; - } - else - { - getTuxProportion(tux, &x, &y, NULL, NULL); - } - - 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); - protoSendClient(type, client, msg, CHECK_FRONT_TYPE_SIMPLE, CHECK_FRONT_ID_NONE); + char msg[STR_PROTO_SIZE]; + int x, y; + + assert(tux != NULL); + + if (tux->bonus == BONUS_HIDDEN) { + x = TUX_LOCATE_UNKNOWN; + y = TUX_LOCATE_UNKNOWN; + } + else { + getTuxProportion(tux, &x, &y, NULL, NULL); + } + + 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); + protoSendClient(type, client, msg, CHECK_FRONT_TYPE_SIMPLE, + CHECK_FRONT_ID_NONE); } #ifndef PUBLIC_SERVER -void proto_recv_newtux_client(char *msg) +void +proto_recv_newtux_client(char *msg) { - char cmd[STR_PROTO_SIZE]; - char name[STR_NAME_SIZE]; - int id, x, y, status, position, frame, score; - int myGun, myBonus; - int gun1, gun2, gun3, gun4, gun5, gun6, gun7; - int time1, time2; - tux_t *tux; - int recv_count; - - assert( msg != NULL ); - - if( getCurrentArena() == NULL ) - { - 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); - - if( recv_count != 20 ) - { - return; - } - - tux = getObjectFromSpaceWithID(getCurrentArena()->spaceTux, id); - - if( tux != NULL ) - { - assert( tux->id == id ); - } - - if( tux == NULL ) - { - tux = newTux(); - replaceTuxID(tux, id); - tux->control = TUX_CONTROL_NET; - addObjectToSpace(getCurrentArena()->spaceTux, tux); - } - - if( tux->control == TUX_CONTROL_KEYBOARD_RIGHT && - x == TUX_LOCATE_UNKNOWN && y == TUX_LOCATE_UNKNOWN ) - { - getTuxProportion(tux, &x, &y, NULL, NULL); - } - - addToRadar(id, x, y, RADAR_TYPE_TUX); - - if( tux->bonus == BONUS_HIDDEN ) - { - delFromRadar(id); - } - - moveObjectInSpace(getCurrentArena()->spaceTux, tux, x, y); - tux->status = status; - tux->position = position; - tux->frame = frame; - tux->score = score; - strcpy(tux->name, name); - tux->gun = myGun; - tux->bonus = myBonus; - tux->shot[GUN_SIMPLE] = gun1; - tux->shot[GUN_DUAL_SIMPLE] = gun2; - tux->shot[GUN_SCATTER] = gun3; - tux->shot[GUN_TOMMY] = gun4; - tux->shot[GUN_LASSER] = gun5; - tux->shot[GUN_MINE] = gun6; - tux->shot[GUN_BOMBBALL] = gun7; - tux->bonus_time = time1; - tux->pickup_time = time2; + char cmd[STR_PROTO_SIZE]; + char name[STR_NAME_SIZE]; + int id, x, y, status, position, frame, score; + int myGun, myBonus; + int gun1, gun2, gun3, gun4, gun5, gun6, gun7; + int time1, time2; + tux_t *tux; + int recv_count; + + assert(msg != NULL); + + if (getCurrentArena() == NULL) { + 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); + + if (recv_count != 20) { + return; + } + + tux = getObjectFromSpaceWithID(getCurrentArena()->spaceTux, id); + + if (tux != NULL) { + assert(tux->id == id); + } + + if (tux == NULL) { + tux = newTux(); + replaceTuxID(tux, id); + tux->control = TUX_CONTROL_NET; + addObjectToSpace(getCurrentArena()->spaceTux, tux); + } + + if (tux->control == TUX_CONTROL_KEYBOARD_RIGHT && + x == TUX_LOCATE_UNKNOWN && y == TUX_LOCATE_UNKNOWN) { + getTuxProportion(tux, &x, &y, NULL, NULL); + } + + addToRadar(id, x, y, RADAR_TYPE_TUX); + + if (tux->bonus == BONUS_HIDDEN) { + delFromRadar(id); + } + + moveObjectInSpace(getCurrentArena()->spaceTux, tux, x, y); + tux->status = status; + tux->position = position; + tux->frame = frame; + tux->score = score; + strcpy(tux->name, name); + tux->gun = myGun; + tux->bonus = myBonus; + tux->shot[GUN_SIMPLE] = gun1; + tux->shot[GUN_DUAL_SIMPLE] = gun2; + tux->shot[GUN_SCATTER] = gun3; + tux->shot[GUN_TOMMY] = gun4; + tux->shot[GUN_LASSER] = gun5; + tux->shot[GUN_MINE] = gun6; + tux->shot[GUN_BOMBBALL] = gun7; + tux->bonus_time = time1; + tux->pickup_time = time2; } #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]; - - assert( tux != NULL ); + char msg[STR_PROTO_SIZE]; + + assert(tux != NULL); - snprintf(msg, STR_PROTO_SIZE, "kill %d\n", tux->id); - - //proto_send(type, client, msg); - protoSendClient(type, client, msg, CHECK_FRONT_TYPE_SIMPLE, CHECK_FRONT_ID_NONE); + snprintf(msg, STR_PROTO_SIZE, "kill %d\n", tux->id); + + //proto_send(type, client, msg); + protoSendClient(type, client, msg, CHECK_FRONT_TYPE_SIMPLE, + CHECK_FRONT_ID_NONE); } #ifndef PUBLIC_SERVER -void proto_recv_kill_client(char *msg) +void +proto_recv_kill_client(char *msg) { - char cmd[STR_PROTO_SIZE]; - int id; - tux_t *tux; - int recv_count; + char cmd[STR_PROTO_SIZE]; + int id; + tux_t *tux; + int recv_count; - assert( msg != NULL ); + assert(msg != NULL); - recv_count = sscanf(msg, "%s %d", cmd, &id); + recv_count = sscanf(msg, "%s %d", cmd, &id); - if( recv_count != 2 ) - { - return; - } + if (recv_count != 2) { + return; + } - tux = getObjectFromSpaceWithID(getCurrentArena()->spaceTux, id); + tux = getObjectFromSpaceWithID(getCurrentArena()->spaceTux, id); - if( tux != NULL ) - { - eventTuxIsDead(tux); - } + if (tux != NULL) { + eventTuxIsDead(tux); + } } #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; + char msg[STR_PROTO_SIZE]; + int check_id; - check_id = getNewIDcount(0); + check_id = getNewIDcount(0); - snprintf(msg, STR_PROTO_SIZE, "del %d %d\n", - id, check_id); + snprintf(msg, STR_PROTO_SIZE, "del %d %d\n", id, check_id); - protoSendClient(type, client, msg, CHECK_FRONT_TYPE_CHECK, check_id); - //proto_check(type, client, msg, check_id); + protoSendClient(type, client, msg, CHECK_FRONT_TYPE_CHECK, check_id); + //proto_check(type, client, msg, check_id); } #ifndef PUBLIC_SERVER -void proto_recv_del_client(char *msg) +void +proto_recv_del_client(char *msg) { - char cmd[STR_PROTO_SIZE]; - int id, check_id; - tux_t *tux; - shot_t *shot; - item_t *item; - int recv_count; - - assert( msg != NULL ); - - recv_count = sscanf(msg, "%s %d %d", - cmd, &id, &check_id); - - if( recv_count != 3 ) - { - return; - } - - proto_send_check_client(check_id); - - tux = getObjectFromSpaceWithID(getCurrentArena()->spaceTux, id); - - if( tux != NULL ) - { - delFromRadar(id); - delObjectFromSpaceWithObject(getCurrentArena()->spaceTux, tux, destroyTux); - return; - } - - shot = getObjectFromSpaceWithID(getCurrentArena()->spaceShot, id); - - if( shot != NULL ) - { - //printf("delete shot..\n"); - delFromRadar(id); - delObjectFromSpaceWithObject(getCurrentArena()->spaceShot, shot, destroyShot); - return; - } - - item = getObjectFromSpaceWithID(getCurrentArena()->spaceItem, id); - - if( item != NULL ) - { - //printf("delete item..\n"); - delFromRadar(id); - delObjectFromSpaceWithObject(getCurrentArena()->spaceItem, item, destroyItem); - return; - } + char cmd[STR_PROTO_SIZE]; + int id, check_id; + tux_t *tux; + shot_t *shot; + item_t *item; + int recv_count; + + assert(msg != NULL); + + recv_count = sscanf(msg, "%s %d %d", cmd, &id, &check_id); + + if (recv_count != 3) { + return; + } + + proto_send_check_client(check_id); + + tux = getObjectFromSpaceWithID(getCurrentArena()->spaceTux, id); + + if (tux != NULL) { + delFromRadar(id); + delObjectFromSpaceWithObject(getCurrentArena()->spaceTux, tux, + destroyTux); + return; + } + + shot = getObjectFromSpaceWithID(getCurrentArena()->spaceShot, id); + + if (shot != NULL) { + //printf("delete shot..\n"); + delFromRadar(id); + delObjectFromSpaceWithObject(getCurrentArena()->spaceShot, shot, + destroyShot); + return; + } + + item = getObjectFromSpaceWithID(getCurrentArena()->spaceItem, id); + + if (item != NULL) { + //printf("delete item..\n"); + delFromRadar(id); + delObjectFromSpaceWithObject(getCurrentArena()->spaceItem, item, + destroyItem); + return; + } } #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; + char msg[STR_PROTO_SIZE]; + int check_id; - assert( p != NULL ); + assert(p != NULL); - check_id = getNewIDcount(0); + check_id = getNewIDcount(0); - 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); + 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); - protoSendClient(type, client, msg, CHECK_FRONT_TYPE_CHECK, check_id); + //proto_send(type, client, msg); + //proto_check(type, client, msg, check_id); + protoSendClient(type, client, msg, CHECK_FRONT_TYPE_CHECK, check_id); } #ifndef PUBLIC_SERVER -void proto_recv_additem_client(char *msg) +void +proto_recv_additem_client(char *msg) { - char cmd[STR_PROTO_SIZE]; - int id, type, x, y, count, frame, author_id, check_id; - item_t *item; - int recv_count; + char cmd[STR_PROTO_SIZE]; + int id, type, x, y, count, frame, author_id, check_id; + item_t *item; + int recv_count; - assert( msg != NULL ); + assert(msg != NULL); - if( getCurrentArena() == NULL ) - { - return; - } + if (getCurrentArena() == NULL) { + return; + } - recv_count = sscanf(msg, "%s %d %d %d %d %d %d %d %d", - cmd, &id, &type, &x, &y, &count, &frame, &author_id, &check_id); + recv_count = sscanf(msg, "%s %d %d %d %d %d %d %d %d", + cmd, &id, &type, &x, &y, &count, &frame, &author_id, + &check_id); - if( recv_count != 9 ) - { - return; - } + if (recv_count != 9) { + return; + } - proto_send_check_client(check_id); + proto_send_check_client(check_id); - if( ( item = getObjectFromSpaceWithID(getCurrentArena()->spaceItem, id) ) != NULL ) - { - return; - } + if ((item = + getObjectFromSpaceWithID(getCurrentArena()->spaceItem, + id)) != NULL) { + return; + } - if( type != ITEM_MINE && type != ITEM_EXPLOSION && type != ITEM_BIG_EXPLOSION ) - { - addToRadar(id, x, y, RADAR_TYPE_ITEM); - } + if (type != ITEM_MINE && type != ITEM_EXPLOSION + && type != ITEM_BIG_EXPLOSION) { + addToRadar(id, x, y, RADAR_TYPE_ITEM); + } - item = newItem(x, y, type, author_id); + item = newItem(x, y, type, author_id); - replaceItemID(item, id); - item->count = count; - item->frame = frame; + replaceItemID(item, id); + item->count = count; + item->frame = frame; - addObjectToSpace(getCurrentArena()->spaceItem, item); + addObjectToSpace(getCurrentArena()->spaceItem, item); } #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]; + char msg[STR_PROTO_SIZE]; - assert( p != NULL ); + assert(p != NULL); - snprintf(msg, STR_PROTO_SIZE, "shot %d %d %d %d %d %d %d %d %d\n", - p->id, p->x, p->y, p->px, p->py, p->position, p->gun, p->author_id, p->isCanKillAuthor); + snprintf(msg, STR_PROTO_SIZE, "shot %d %d %d %d %d %d %d %d %d\n", + p->id, p->x, p->y, 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); - protoSendClient(type, client, msg, CHECK_FRONT_TYPE_SIMPLE, CHECK_FRONT_ID_NONE); + //proto_send(type, client, msg); + //proto_check(type, client, msg, check_id); + protoSendClient(type, client, msg, CHECK_FRONT_TYPE_SIMPLE, + CHECK_FRONT_ID_NONE); } #ifndef PUBLIC_SERVER -void proto_recv_shot_client(char *msg) +void +proto_recv_shot_client(char *msg) { - char cmd[STR_PROTO_SIZE]; - int x, y, px, py, position, gun, shot_id, author_id, isCanKillAuthor; - shot_t *shot; - int recv_count; + char cmd[STR_PROTO_SIZE]; + int x, y, px, py, position, gun, shot_id, author_id, isCanKillAuthor; + shot_t *shot; + int recv_count; - assert( msg != NULL ); + assert(msg != NULL); - recv_count = sscanf(msg, "%s %d %d %d %d %d %d %d %d %d", - cmd, &shot_id, &x, &y, &px, &py, &position, &gun, &author_id, &isCanKillAuthor); + recv_count = sscanf(msg, "%s %d %d %d %d %d %d %d %d %d", + cmd, &shot_id, &x, &y, &px, &py, &position, &gun, + &author_id, &isCanKillAuthor); - if( recv_count != 10 ) - { - return; - } + if (recv_count != 10) { + return; + } - if( ( shot = getObjectFromSpaceWithID(getCurrentArena()->spaceShot, shot_id) ) != NULL ) - { - delObjectFromSpaceWithObject(getCurrentArena()->spaceShot, shot, destroyShot); + if ((shot = + getObjectFromSpaceWithID(getCurrentArena()->spaceShot, + shot_id)) != NULL) { + delObjectFromSpaceWithObject(getCurrentArena()->spaceShot, shot, + destroyShot); - //return; - } + //return; + } - shot = newShot(x, y, px, py, gun, author_id); + shot = newShot(x, y, px, py, gun, author_id); - replaceShotID(shot, shot_id); - shot->isCanKillAuthor = isCanKillAuthor; - shot->position = position; + replaceShotID(shot, shot_id); + shot->isCanKillAuthor = isCanKillAuthor; + shot->position = position; - if( shot->gun == GUN_LASSER ) - { - transformOnlyLasser(shot); - } + if (shot->gun == GUN_LASSER) { + transformOnlyLasser(shot); + } - addObjectToSpace(getCurrentArena()->spaceShot, shot); + addObjectToSpace(getCurrentArena()->spaceShot, shot); } #endif #ifndef PUBLIC_SERVER -void proto_send_chat_client(char *s) +void +proto_send_chat_client(char *s) { - char msg[STR_PROTO_SIZE]; - snprintf(msg, STR_PROTO_SIZE, "chat %s\n", s); - sendServer(msg); + char msg[STR_PROTO_SIZE]; + snprintf(msg, STR_PROTO_SIZE, "chat %s\n", s); + sendServer(msg); } #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; - - if( client->tux == NULL ) - { - return; - } + char out[STR_PROTO_SIZE]; + int len; + + if (client->tux == NULL) { + return; + } - len = strlen(msg); - msg[len-1] = '\0'; + len = strlen(msg); + msg[len - 1] = '\0'; - snprintf(out, STR_PROTO_SIZE, "chat %s:%s\n", client->tux->name, msg+5); + snprintf(out, STR_PROTO_SIZE, "chat %s:%s\n", client->tux->name, msg + 5); - proto_send_chat_server(PROTO_SEND_ALL, NULL, out); + 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) { - protoSendClient(type, client, msg, CHECK_FRONT_TYPE_SIMPLE, CHECK_FRONT_ID_NONE); + protoSendClient(type, client, msg, CHECK_FRONT_TYPE_SIMPLE, + CHECK_FRONT_ID_NONE); #ifndef PUBLIC_SERVER - proto_recv_chat_client(msg); + proto_recv_chat_client(msg); #endif } #ifndef PUBLIC_SERVER -void proto_recv_chat_client(char *msg) +void +proto_recv_chat_client(char *msg) { - int len; + int len; - assert( msg != NULL ); + assert(msg != NULL); - len = strlen(msg); - msg[len-1] = '\0'; + len = strlen(msg); + msg[len - 1] = '\0'; - addToChat(msg+5); + addToChat(msg + 5); } #endif #ifndef PUBLIC_SERVER -void proto_send_module_client(char *msg) +void +proto_send_module_client(char *msg) { - char out[STR_PROTO_SIZE]; + char out[STR_PROTO_SIZE]; - snprintf(out, STR_PROTO_SIZE, "module %s\n", msg); + snprintf(out, STR_PROTO_SIZE, "module %s\n", msg); /* strcpy(out, "modules "); strcat(out, msg); strcat(out, "\n"); */ - sendServer(out); + sendServer(out); } #endif -void proto_recv_module_server(client_t *client, char *msg) +void +proto_recv_module_server(client_t * client, char *msg) { - recvMsgModule(msg+7); + recvMsgModule(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]; + char out[STR_PROTO_SIZE]; - snprintf(out, STR_PROTO_SIZE, "module %s\n", msg); + snprintf(out, STR_PROTO_SIZE, "module %s\n", msg); /* strcpy(out, "modules "); strcat(out, msg); strcat(out, "\n"); */ - protoSendClient(type, client, out, CHECK_FRONT_TYPE_SIMPLE, CHECK_FRONT_ID_NONE); + protoSendClient(type, client, out, CHECK_FRONT_TYPE_SIMPLE, + CHECK_FRONT_ID_NONE); } #ifndef PUBLIC_SERVER -void proto_recv_module_client(char *msg) +void +proto_recv_module_client(char *msg) { - recvMsgModule(msg+7); + recvMsgModule(msg + 7); } #endif #ifndef PUBLIC_SERVER -void proto_send_ping_client() +void +proto_send_ping_client() { - char msg[STR_PROTO_SIZE]; - snprintf(msg, STR_PROTO_SIZE, "ping\n"); - sendServer(msg); + char msg[STR_PROTO_SIZE]; + snprintf(msg, STR_PROTO_SIZE, "ping\n"); + sendServer(msg); } #endif -void proto_recv_ping_server(client_t *client, char *msg) +void +proto_recv_ping_server(client_t * client, char *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); - protoSendClient(type, client, msg, CHECK_FRONT_TYPE_SIMPLE, CHECK_FRONT_ID_NONE); + char msg[STR_PROTO_SIZE]; + snprintf(msg, STR_PROTO_SIZE, "ping\n"); + //proto_send(type, client, msg); + protoSendClient(type, client, msg, CHECK_FRONT_TYPE_SIMPLE, + CHECK_FRONT_ID_NONE); } #ifndef PUBLIC_SERVER -void proto_recv_ping_client(char *msg) +void +proto_recv_ping_client(char *msg) { } #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]; + char msg[STR_PROTO_SIZE]; - snprintf(msg, STR_PROTO_SIZE, "echo%s", s); - //proto_send(type, client, msg); - protoSendClient(type, client, msg, CHECK_FRONT_TYPE_SIMPLE, CHECK_FRONT_ID_NONE); + snprintf(msg, STR_PROTO_SIZE, "echo%s", s); + //proto_send(type, client, msg); + protoSendClient(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]; + char msg[STR_PROTO_SIZE]; - snprintf(msg, STR_PROTO_SIZE, "end\n"); - //proto_send(type, client, msg); - protoSendClient(type, client, msg, CHECK_FRONT_TYPE_SIMPLE, CHECK_FRONT_ID_NONE); + snprintf(msg, STR_PROTO_SIZE, "end\n"); + //proto_send(type, client, msg); + protoSendClient(type, client, msg, CHECK_FRONT_TYPE_SIMPLE, + CHECK_FRONT_ID_NONE); } #ifndef PUBLIC_SERVER -void proto_recv_end_client(char *msg) +void +proto_recv_end_client(char *msg) { - assert( msg != NULL ); + assert(msg != NULL); - setWorldEnd(); + setWorldEnd(); } #endif #ifndef PUBLIC_SERVER -void proto_send_end_client() +void +proto_send_end_client() { - char msg[STR_PROTO_SIZE]; + char msg[STR_PROTO_SIZE]; - snprintf(msg, STR_PROTO_SIZE, "end\n"); - sendServer(msg); + snprintf(msg, STR_PROTO_SIZE, "end\n"); + sendServer(msg); } #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 ); + assert(msg != NULL); + assert(client != NULL); - client->status = NET_STATUS_ZOMBIE; + client->status = NET_STATUS_ZOMBIE; } - diff --git a/src/base/server.c b/src/base/server.c index 836b9d2..ac7bfc0 100644 --- a/src/base/server.c +++ b/src/base/server.c @@ -51,348 +51,356 @@ static int maxClients; typedef struct proto_cmd_server_struct { - char *name; - int len; - int tux; - void (*fce_proto)(client_t *,char *msg); + char *name; + int len; + int tux; + void (*fce_proto) (client_t *, char *msg); } proto_cmd_server_t; -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 }, +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 }, + {.name = "list",.len = 4,.tux = 0,.fce_proto = + proto_recv_listscore_server}, #endif - { .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 }, - { .name = "chat", .len = 4, .tux = 1, .fce_proto = proto_recv_chat_server }, - { .name = "ping", .len = 4, .tux = 1, .fce_proto = proto_recv_ping_server }, - { .name = "echo", .len = 4, .tux = 0, .fce_proto = proto_recv_echo_server }, - { .name = "end", .len = 3, .tux = 1, .fce_proto = proto_recv_end_server }, - { .name = "", .len = 0, .tux = 0, .fce_proto = NULL }, + {.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}, + {.name = "chat",.len = 4,.tux = 1,.fce_proto = proto_recv_chat_server}, + {.name = "ping",.len = 4,.tux = 1,.fce_proto = proto_recv_ping_server}, + {.name = "echo",.len = 4,.tux = 0,.fce_proto = proto_recv_echo_server}, + {.name = "end",.len = 3,.tux = 1,.fce_proto = proto_recv_end_server}, + {.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; + int len; + int i; + + len = strlen(msg); - len = strlen(msg); + for (i = 0; proto_cmd_list[i].len != 0; i++) { + proto_cmd_server_t *thisCmd; - for( i = 0 ; proto_cmd_list[i].len != 0 ; i++ ) - { - proto_cmd_server_t *thisCmd; - - thisCmd = &proto_cmd_list[i]; + thisCmd = &proto_cmd_list[i]; - if( len >= thisCmd->len && strncmp(msg, thisCmd->name, thisCmd->len) == 0 ) - { - if( thisCmd->tux && client->tux == NULL ) - { - return NULL; - } + if (len >= thisCmd->len + && strncmp(msg, thisCmd->name, thisCmd->len) == 0) { + if (thisCmd->tux && client->tux == NULL) { + return NULL; + } - return thisCmd; - } - } + return thisCmd; + } + } - return NULL; + return NULL; } -static void startUpdateServer() +static void +startUpdateServer() { - timeUpdate = time(NULL); + timeUpdate = time(NULL); } -time_t getUpdateServer() +time_t +getUpdateServer() { - return time(NULL) - timeUpdate; + return time(NULL) - timeUpdate; } -client_t* newAnyClient() +client_t * +newAnyClient() { - client_t *new; + client_t *new; - new = malloc( sizeof(client_t) ); - memset(new, 0, sizeof(client_t)); + new = malloc(sizeof(client_t)); + memset(new, 0, sizeof(client_t)); - new->status = NET_STATUS_OK; - new->listRecvMsg = newList(); - new->listSendMsg = newCheckFront(); - new->listSeesShot = newList(); - new->protect = newProtect(); + new->status = NET_STATUS_OK; + new->listRecvMsg = newList(); + new->listSendMsg = newCheckFront(); + new->listSeesShot = newList(); + new->protect = newProtect(); - return new; + return new; } -void destroyAnyClient(client_t *p) +void +destroyAnyClient(client_t * p) { - assert( p != NULL ); + assert(p != NULL); - //eventMsgInCheckFront(p); - destroyListItem(p->listRecvMsg, free); - destroyListItem(p->listSeesShot, free); - destroyCheckFront(p->listSendMsg); + //eventMsgInCheckFront(p); + destroyListItem(p->listRecvMsg, free); + destroyListItem(p->listSeesShot, free); + destroyCheckFront(p->listSendMsg); - destroyProtect(p->protect); + destroyProtect(p->protect); - if( p->tux != NULL ) - { + if (p->tux != NULL) { #ifdef PUBLIC_SERVER - addPlayerInHighScore(p->tux->name, p->tux->score); + addPlayerInHighScore(p->tux->name, p->tux->score); #endif - delObjectFromSpaceWithObject(getCurrentArena()->spaceTux, p->tux, destroyTux); - } + delObjectFromSpaceWithObject(getCurrentArena()->spaceTux, p->tux, + destroyTux); + } - free(p); + free(p); } -static void eventDelClientFromListClient(client_t *client) +static void +eventDelClientFromListClient(client_t * client) { - int offset; + int offset; - offset = searchListItem(listClient, client); + offset = searchListItem(listClient, client); - assert( offset != -1 ); + assert(offset != -1); - delListItem(listClient, offset, destroyUdpClient); + delListItem(listClient, offset, destroyUdpClient); } -static void delZombieCLient(void *p_nothink) +static void +delZombieCLient(void *p_nothink) { - client_t *thisClient; - my_time_t currentTime; - int i; - - currentTime = getMyTime(); - - for( i = 0 ; i < listClient->count; i++) - { - thisClient = (client_t *) listClient->list[i]; - - if( isDown(thisClient->protect) == TRUE ) - { - proto_send_end_server(PROTO_SEND_ONE, thisClient); - eventMsgInCheckFront(thisClient); - thisClient->status = NET_STATUS_ZOMBIE; - } - - if( thisClient->status == NET_STATUS_ZOMBIE ) - { - if( thisClient->tux != NULL ) - { - proto_send_del_server(PROTO_SEND_ALL, NULL, thisClient->tux->id); - } - - eventDelClientFromListClient(thisClient); - i--; - } - } + client_t *thisClient; + my_time_t currentTime; + int i; + + currentTime = getMyTime(); + + for (i = 0; i < listClient->count; i++) { + thisClient = (client_t *) listClient->list[i]; + + if (isDown(thisClient->protect) == TRUE) { + proto_send_end_server(PROTO_SEND_ONE, thisClient); + eventMsgInCheckFront(thisClient); + thisClient->status = NET_STATUS_ZOMBIE; + } + + if (thisClient->status == NET_STATUS_ZOMBIE) { + if (thisClient->tux != NULL) { + proto_send_del_server(PROTO_SEND_ALL, NULL, + thisClient->tux->id); + } + + eventDelClientFromListClient(thisClient); + i--; + } + } } -static void eventPeriodicSyncClient(void *p_nothink) +static void +eventPeriodicSyncClient(void *p_nothink) { - client_t *thisClientSend; - tux_t *thisTux; - int i; + client_t *thisClientSend; + tux_t *thisTux; + int i; #ifndef PUBLIC_SERVER - proto_send_newtux_server(PROTO_SEND_ALL_SEES_TUX, NULL, getControlTux(TUX_CONTROL_KEYBOARD_RIGHT)); + proto_send_newtux_server(PROTO_SEND_ALL_SEES_TUX, NULL, + getControlTux(TUX_CONTROL_KEYBOARD_RIGHT)); #endif - for( i = 0 ; i < listClient->count; i++ ) - { - thisClientSend = (client_t *) listClient->list[i]; - thisTux = thisClientSend->tux; + for (i = 0; i < listClient->count; i++) { + thisClientSend = (client_t *) listClient->list[i]; + thisTux = thisClientSend->tux; - if( thisTux == NULL ) - { - continue; - } + if (thisTux == NULL) { + continue; + } - //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_ALL_SEES_TUX, thisClientSend, thisTux); + proto_send_newtux_server(PROTO_SEND_BUT, thisClientSend, thisTux); + } } -static void eventSendPingClients(void *p_nothink) +static void +eventSendPingClients(void *p_nothink) { - proto_send_ping_server(PROTO_SEND_ALL, NULL); + proto_send_ping_server(PROTO_SEND_ALL, NULL); } -void setServerTimer() +void +setServerTimer() { - if( listServerTimer != NULL ) - { - destroyTimer(listServerTimer); - } - - restartTimer(); - listServerTimer = newTimer(); - - addTaskToTimer(listServerTimer, TIMER_PERIODIC, delZombieCLient, NULL, SERVER_TIMEOUT); - addTaskToTimer(listServerTimer, TIMER_PERIODIC, eventPeriodicSyncClient, NULL, SERVER_TIME_SYNC); - addTaskToTimer(listServerTimer, TIMER_PERIODIC, eventSendPingClients, NULL, SERVER_TIME_PING); + if (listServerTimer != NULL) { + destroyTimer(listServerTimer); + } + + restartTimer(); + listServerTimer = newTimer(); + + addTaskToTimer(listServerTimer, TIMER_PERIODIC, delZombieCLient, NULL, + SERVER_TIMEOUT); + addTaskToTimer(listServerTimer, TIMER_PERIODIC, eventPeriodicSyncClient, + NULL, SERVER_TIME_SYNC); + addTaskToTimer(listServerTimer, TIMER_PERIODIC, eventSendPingClients, + NULL, SERVER_TIME_PING); } -int initServer(char *ip4, int port4, char *ip6, int port6) +int +initServer(char *ip4, int port4, char *ip6, int port6) { - int ret; + int ret; - startUpdateServer(); - listServerTimer = NULL; + startUpdateServer(); + listServerTimer = NULL; - listClient = newList(); + listClient = newList(); - setServerMaxClients(SERVER_MAX_CLIENTS); - setServerTimer(); + setServerMaxClients(SERVER_MAX_CLIENTS); + setServerTimer(); - ret = initUdpServer(ip4, port4, ip6, port6); + ret = initUdpServer(ip4, port4, ip6, port6); - if( ret == 0 ) - { - return -1; - } + if (ret == 0) { + return -1; + } - return ret; + return ret; } -list_t* getListServerClient() +list_t * +getListServerClient() { - return listClient; + return listClient; } -int getServerMaxClients() +int +getServerMaxClients() { - return maxClients; + return maxClients; } -void setServerMaxClients(int n) +void +setServerMaxClients(int n) { - maxClients = n; + maxClients = n; } -void sendClient(client_t *p, char *msg) +void +sendClient(client_t * p, char *msg) { - assert( p != NULL ); - assert( msg != NULL ); + assert(p != NULL); + assert(msg != NULL); - if( p->status != NET_STATUS_ZOMBIE ) - { - int ret = -1; // no Warnnings + if (p->status != NET_STATUS_ZOMBIE) { + int ret = -1; // no Warnnings #ifndef PUBLIC_SERVER - if( isParamFlag("--send") ) - { - printf(_("Sending: \"%s\""), msg); - } + if (isParamFlag("--send")) { + printf(_("Sending: \"%s\""), msg); + } #endif - ret = writeUdpSocket(p->socket_udp, p->socket_udp, msg, strlen(msg)); + ret = writeUdpSocket(p->socket_udp, p->socket_udp, msg, strlen(msg)); - if( ret <= 0 ) - { - p->status = NET_STATUS_ZOMBIE; - } - } + if (ret <= 0) { + p->status = NET_STATUS_ZOMBIE; + } + } } -static void eventClientWorkRecvList(client_t *client) +static void +eventClientWorkRecvList(client_t * client) { - proto_cmd_server_t* protoCmd; - char *line; - int i; + proto_cmd_server_t *protoCmd; + char *line; + int i; + + assert(client != NULL); - assert( client != NULL ); + /* obsluha udalosti od clientov */ - /* obsluha udalosti od clientov */ - - for( i = 0 ; i < client->listRecvMsg->count ; i++ ) - { - line = (char *)client->listRecvMsg->list[i]; - protoCmd = findCmdProto(client, line); + 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); - } + if (isParamFlag("--recv")) { + printf(_("Recieved: \"%s\""), line); + } #endif - if( protoCmd != NULL ) - { - protoCmd->fce_proto(client, line); - rereshLastPing(client->protect); - } - else - { - proto_send_error_server(PROTO_SEND_ONE, client, PROTO_ERROR_CODE_BAD_COMMAND); - } - } - - destroyListItem(client->listRecvMsg, free); - client->listRecvMsg = newList(); + if (protoCmd != NULL) { + protoCmd->fce_proto(client, line); + rereshLastPing(client->protect); + } + else { + proto_send_error_server(PROTO_SEND_ONE, client, + PROTO_ERROR_CODE_BAD_COMMAND); + } + } + + destroyListItem(client->listRecvMsg, free); + client->listRecvMsg = newList(); } -static void porcesListClients() +static void +porcesListClients() { - int i; - client_t *thisClient; + int i; + client_t *thisClient; - for( i = 0 ; i < listClient->count; i++) - { - thisClient = (client_t *) listClient->list[i]; + for (i = 0; i < listClient->count; i++) { + thisClient = (client_t *) listClient->list[i]; - eventClientWorkRecvList(thisClient); - eventMsgInCheckFront(thisClient); - } + eventClientWorkRecvList(thisClient); + eventMsgInCheckFront(thisClient); + } } -void eventServer() +void +eventServer() { #ifndef PUBLIC_SERVER - int count; + int count; - do{ - restartSelect(); - setServerUdpSelect(); - actionSelect(); - count = selectServerUdpSocket(); - }while( count > 0 ); + do { + restartSelect(); + setServerUdpSelect(); + actionSelect(); + count = selectServerUdpSocket(); + } while (count > 0); #endif #ifdef PUBLIC_SERVER - int ret; + int ret; - restartSelect(); + restartSelect(); - setServerUdpSelect(); + setServerUdpSelect(); - ret = actionSelect(); + ret = actionSelect(); - if( ret > 0 ) - { - selectServerUdpSocket(); - } + if (ret > 0) { + selectServerUdpSocket(); + } #endif - porcesListClients(); - eventTimer(listServerTimer); + porcesListClients(); + eventTimer(listServerTimer); } -void quitServer() +void +quitServer() { - proto_send_end_server(PROTO_SEND_ALL, NULL); + proto_send_end_server(PROTO_SEND_ALL, NULL); - assert( listClient != NULL ); + assert(listClient != NULL); - destroyListItem(listClient, destroyUdpClient); + destroyListItem(listClient, destroyUdpClient); - destroyTimer(listServerTimer); + destroyTimer(listServerTimer); - quitUdpServer(); + quitUdpServer(); } diff --git a/src/base/serverSelect.c b/src/base/serverSelect.c index 2b25a4f..710142f 100644 --- a/src/base/serverSelect.c +++ b/src/base/serverSelect.c @@ -25,91 +25,93 @@ static fd_set readfds; static fd_set writefds; static int max_fd; -void restartSelect() +void +restartSelect() { #ifndef PUBLIC_SERVER - tv.tv_sec = 0; - tv.tv_usec = 0; -#endif + tv.tv_sec = 0; + tv.tv_usec = 0; +#endif #ifdef PUBLIC_SERVER - tv.tv_sec = 0; - tv.tv_usec = 1000; -#endif + tv.tv_sec = 0; + tv.tv_usec = 1000; +#endif - FD_ZERO(&readfds); - FD_ZERO(&writefds); - max_fd = 0; + FD_ZERO(&readfds); + FD_ZERO(&writefds); + max_fd = 0; } -void addSockToSelectRead(int sock) +void +addSockToSelectRead(int sock) { - //printf("addSockToSelectRead %d\n", sock); + //printf("addSockToSelectRead %d\n", sock); - FD_SET(sock, &readfds); + FD_SET(sock, &readfds); - if( sock > max_fd ) - { - max_fd = sock; - } + if (sock > max_fd) { + max_fd = sock; + } } -void addSockToSelectWrite(int sock) +void +addSockToSelectWrite(int sock) { - //printf("addSockToSelectWrite %d\n", sock); + //printf("addSockToSelectWrite %d\n", sock); - FD_SET(sock, &writefds); + FD_SET(sock, &writefds); - if(sock > max_fd ) - { - max_fd = sock; - } + if (sock > max_fd) { + max_fd = sock; + } } -int actionSelect() +int +actionSelect() { - int ret; + int ret; #ifdef PUBLIC_SERVER - list_t *listClient; - listClient = getListServerClient(); - - if( listClient->count == 0 ) - { - ret = select(max_fd+1, &readfds, &writefds, (fd_set *)NULL, NULL); - setServerTimer(); - } - else - { - ret = select(max_fd+1, &readfds, &writefds, (fd_set *)NULL, &tv); - } + list_t *listClient; + listClient = getListServerClient(); + + if (listClient->count == 0) { + ret = select(max_fd + 1, &readfds, &writefds, (fd_set *) NULL, NULL); + setServerTimer(); + } + 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); + ret = select(max_fd + 1, &readfds, &writefds, (fd_set *) NULL, &tv); #endif - return ret; + return ret; } -int isChangeSockInSelectRead(int sock) +int +isChangeSockInSelectRead(int sock) { - int ret; + int ret; - ret = FD_ISSET(sock, &readfds); + ret = FD_ISSET(sock, &readfds); - //printf("isChangeSockInSelect %d -> %d\n", sock, ret); + //printf("isChangeSockInSelect %d -> %d\n", sock, ret); - return ret; + return ret; } -int isChangeSockInSelectWrite(int sock) +int +isChangeSockInSelectWrite(int sock) { - int ret; + int ret; - ret = FD_ISSET(sock, &writefds); + ret = FD_ISSET(sock, &writefds); - //printf("isChangeSockInSelect %d -> %d\n", sock, ret); + //printf("isChangeSockInSelect %d -> %d\n", sock, ret); - return ret; + return ret; } diff --git a/src/base/serverSendMsg.c b/src/base/serverSendMsg.c index a347b37..013d41c 100644 --- a/src/base/serverSendMsg.c +++ b/src/base/serverSendMsg.c @@ -14,133 +14,134 @@ #include "screen_world.h" #endif -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 ); + assert(p != NULL); + assert(msg != NULL); - if( p->status != NET_STATUS_ZOMBIE ) - { - addMsgInCheckFront(p->listSendMsg, msg, type, id); - } + if (p->status != NET_STATUS_ZOMBIE) { + addMsgInCheckFront(p->listSendMsg, msg, type, 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; - int i; + list_t *listClient; + client_t *thisClient; + int i; - assert( msg != NULL ); + assert(msg != NULL); - listClient = getListServerClient(); + listClient = getListServerClient(); - for( i = 0 ; i < listClient->count; i++) - { - thisClient = (client_t *) listClient->list[i]; + for (i = 0; i < listClient->count; i++) { + thisClient = (client_t *) listClient->list[i]; - if( thisClient->tux != NULL && thisClient != p ) - { - addMsgClient(thisClient, msg, type, id); - } - } + if (thisClient->tux != NULL && thisClient != p) { + addMsgClient(thisClient, msg, type, id); + } + } } -static void addMsgAllClient(char *msg, int type, int id) +static void +addMsgAllClient(char *msg, int type, int id) { - assert( msg != NULL ); + assert(msg != NULL); - addMsgAllClientBut(msg, NULL, type, 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; - space_t *space; - int x, y, w, h; - int i; - - assert( msg != NULL ); - - arena = getCurrentArena(); - space = arena->spaceTux; - - x = tux->x - WINDOW_SIZE_X; - y = tux->y - WINDOW_SIZE_Y; - - w = 2 * WINDOW_SIZE_X; - h = 2 * WINDOW_SIZE_Y; - - if( x < 0 )x = 0; - if( y < 0 )y = 0; - if( w+x >= arena->w )w = arena->w - (x+1); - if( h+y >= arena->h )h = arena->h - (y+1); - - listHelp = newList(); - - getObjectFromSpace(space, x, y, w, h, listHelp); - //printf("%d %d %d %d %d\n", x, y, w, h, listHelp->count); - - for( i = 0 ; i < listHelp->count ; i++ ) - { - tux_t *thisTux; - client_t *thisClient; - - thisTux = (tux_t *)listHelp->list[i]; - - if( thisTux == tux ) - { - continue; - } - - thisClient = thisTux->client; - - if( thisClient != NULL ) - { - addMsgClient(thisClient, msg, type, id); - } - } - - destroyList(listHelp); + list_t *listHelp; + arena_t *arena; + space_t *space; + int x, y, w, h; + int i; + + assert(msg != NULL); + + arena = getCurrentArena(); + space = arena->spaceTux; + + x = tux->x - WINDOW_SIZE_X; + y = tux->y - WINDOW_SIZE_Y; + + w = 2 * WINDOW_SIZE_X; + h = 2 * WINDOW_SIZE_Y; + + if (x < 0) + x = 0; + if (y < 0) + y = 0; + if (w + x >= arena->w) + w = arena->w - (x + 1); + if (h + y >= arena->h) + h = arena->h - (y + 1); + + listHelp = newList(); + + getObjectFromSpace(space, x, y, w, h, listHelp); + //printf("%d %d %d %d %d\n", x, y, w, h, listHelp->count); + + for (i = 0; i < listHelp->count; i++) { + tux_t *thisTux; + client_t *thisClient; + + thisTux = (tux_t *) listHelp->list[i]; + + if (thisTux == tux) { + continue; + } + + thisClient = thisTux->client; + + if (thisClient != NULL) { + addMsgClient(thisClient, msg, type, id); + } + } + + destroyList(listHelp); } -void protoSendClient(int type, client_t *client, char *msg, int type2, int id) +void +protoSendClient(int type, client_t * client, char *msg, int type2, int id) { - assert( msg != NULL ); - - switch( type ) - { - case PROTO_SEND_ONE : - assert( client != NULL ); - addMsgClient(client, msg, type2, id); - break; - case PROTO_SEND_ALL : - assert( client == NULL ); - addMsgAllClient(msg, type2, id); - break; - case PROTO_SEND_BUT : - assert( client != NULL ); - addMsgAllClientBut(msg, client, type2, id); - break; - case PROTO_SEND_ALL_SEES_TUX : + assert(msg != NULL); + + switch (type) { + case PROTO_SEND_ONE: + assert(client != NULL); + addMsgClient(client, msg, type2, id); + break; + case PROTO_SEND_ALL: + assert(client == NULL); + addMsgAllClient(msg, type2, id); + break; + case PROTO_SEND_BUT: + assert(client != NULL); + addMsgAllClientBut(msg, client, type2, id); + break; + case PROTO_SEND_ALL_SEES_TUX: #ifndef PUBLIC_SERVER - if( client != NULL ) - { - addMsgAllClientSeesTux(msg, client->tux, type2, id); - } - else - { - addMsgAllClientSeesTux(msg, getControlTux(TUX_CONTROL_KEYBOARD_RIGHT), type2, id); - } + if (client != NULL) { + addMsgAllClientSeesTux(msg, client->tux, type2, id); + } + else { + addMsgAllClientSeesTux(msg, + getControlTux(TUX_CONTROL_KEYBOARD_RIGHT), + type2, id); + } #endif #ifdef PUBLIC_SERVER - addMsgAllClientSeesTux(msg, client->tux, type2, id); + addMsgAllClientSeesTux(msg, client->tux, type2, id); #endif - break; - default : - assert( ! _("Type variable has a really wierd value!") ); - break; - } + break; + default: + assert(!_("Type variable has a really wierd value!")); + break; + } } - diff --git a/src/base/shareFunction.c b/src/base/shareFunction.c index b7bddc2..fa7d56b 100644 --- a/src/base/shareFunction.c +++ b/src/base/shareFunction.c @@ -10,56 +10,62 @@ typedef struct share_fce_item_struct { - char *name; - void *function; -} share_fce_item_t; + char *name; + void *function; +} share_fce_item_t; static list_t *listShareFce; -static share_fce_item_t* newShareFceItem(char *name, void *function) +static share_fce_item_t * +newShareFceItem(char *name, void *function) { - share_fce_item_t *new; + share_fce_item_t *new; - new = malloc( sizeof(share_fce_item_t) ); - new->name = strdup(name); - new->function = function; - return new; + new = malloc(sizeof(share_fce_item_t)); + new->name = strdup(name); + new->function = function; + return new; } -static void destroyShareFce(share_fce_item_t *p) +static void +destroyShareFce(share_fce_item_t * p) { - free(p->name); - free(p); + free(p->name); + free(p); } -void initShareFunction() +void +initShareFunction() { - listShareFce = newList(); + listShareFce = newList(); } -void addToShareFce(char *name, void *function) + +void +addToShareFce(char *name, void *function) { #ifdef DEBUG - printf(_("Adding \"%s\" to share function.\n"), name); + printf(_("Adding \"%s\" to share function.\n"), name); #endif - addList(listShareFce, newShareFceItem(name, function) ); + addList(listShareFce, newShareFceItem(name, function)); } -void* getShareFce(char *name) +void * +getShareFce(char *name) { - int i; + int i; - for (i = 0; i < listShareFce->count; i++) { - share_fce_item_t *this; + for (i = 0; i < listShareFce->count; i++) { + share_fce_item_t *this; - this = (share_fce_item_t *)listShareFce->list[i]; - if( strcmp(this->name, name) == 0 ) - return this->function; - } - return NULL; + this = (share_fce_item_t *) listShareFce->list[i]; + if (strcmp(this->name, name) == 0) + return this->function; + } + return NULL; } -void quitShareFunction() +void +quitShareFunction() { - destroyListItem(listShareFce, destroyShareFce); + destroyListItem(listShareFce, destroyShareFce); } - diff --git a/src/base/shot.c b/src/base/shot.c index 36f876e..2fe1490 100644 --- a/src/base/shot.c +++ b/src/base/shot.c @@ -32,342 +32,350 @@ static image_t *g_shot_bombball; static bool_t isShotInit = FALSE; -bool_t isShotInicialized() +bool_t +isShotInicialized() { - return isShotInit; + return isShotInit; } -void initShot() +void +initShot() { #ifndef PUBLIC_SERVER - assert( isImageInicialized() == TRUE ); + assert(isImageInicialized() == TRUE); #endif #ifndef PUBLIC_SERVER - g_shot_simple = addImageData("shot.png", IMAGE_ALPHA, "shot", IMAGE_GROUP_BASE); - g_shot_lasserX = addImageData("lasserX.png", IMAGE_NO_ALPHA, "lasserX", IMAGE_GROUP_BASE); - g_shot_lasserY = addImageData("lasserY.png", IMAGE_NO_ALPHA, "lasserY", IMAGE_GROUP_BASE); - g_shot_bombball = addImageData("bombball.png", IMAGE_ALPHA, "bombball", IMAGE_GROUP_BASE); + g_shot_simple = + addImageData("shot.png", IMAGE_ALPHA, "shot", IMAGE_GROUP_BASE); + g_shot_lasserX = + addImageData("lasserX.png", IMAGE_NO_ALPHA, "lasserX", + IMAGE_GROUP_BASE); + g_shot_lasserY = + addImageData("lasserY.png", IMAGE_NO_ALPHA, "lasserY", + IMAGE_GROUP_BASE); + g_shot_bombball = + addImageData("bombball.png", IMAGE_ALPHA, "bombball", + IMAGE_GROUP_BASE); #endif - isShotInit = TRUE; + isShotInit = TRUE; } -shot_t* newShot(int x,int y, int px, int py, int gun, int author_id) +shot_t * +newShot(int x, int y, int px, int py, int gun, int author_id) { - shot_t *new; - tux_t *author; - - new = malloc( sizeof(shot_t) ); - memset(new, 0, sizeof(shot_t) ); - - new->id = getNewID(); - new->x = x; - new->y = y; - new->px = px; - new->py = py; - new->gun = gun; - new->author_id = author_id; - - new->position = POSITION_UNKNOWN; - - author = getObjectFromSpaceWithID(getCurrentArena()->spaceTux, author_id); - - if( author != NULL ) - { - new->position = author->position; - } - - new->isCanKillAuthor = FALSE; - new->del = FALSE; - - switch( gun ) - { - case GUN_SIMPLE : - new->w = GUN_SHOT_WIDTH; - new->h = GUN_SHOT_HEIGHT; -#ifndef PUBLIC_SERVER - new->img = g_shot_simple; + shot_t *new; + tux_t *author; + + new = malloc(sizeof(shot_t)); + memset(new, 0, sizeof(shot_t)); + + new->id = getNewID(); + new->x = x; + new->y = y; + new->px = px; + new->py = py; + new->gun = gun; + new->author_id = author_id; + + new->position = POSITION_UNKNOWN; + + author = getObjectFromSpaceWithID(getCurrentArena()->spaceTux, author_id); + + if (author != NULL) { + new->position = author->position; + } + + new->isCanKillAuthor = FALSE; + new->del = FALSE; + + switch (gun) { + case GUN_SIMPLE: + new->w = GUN_SHOT_WIDTH; + new->h = GUN_SHOT_HEIGHT; +#ifndef PUBLIC_SERVER + new->img = g_shot_simple; #endif - 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; + 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; + 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; - } - break; + break; + } + break; - case GUN_BOMBBALL : - new->w = GUN_BOMBBALL_WIDTH; - new->h = GUN_BOMBBALL_HEIGHT; + case GUN_BOMBBALL: + new->w = GUN_BOMBBALL_WIDTH; + new->h = GUN_BOMBBALL_HEIGHT; -#ifndef PUBLIC_SERVER - new->img = g_shot_bombball; +#ifndef PUBLIC_SERVER + new->img = g_shot_bombball; #endif - break; + break; - default : - assert( ! _("Type variable has a really wierd value!") ); - break; - } + default: + assert(!_("Type variable has a really wierd value!")); + break; + } - return new; + return new; } -void replaceShotID(shot_t *shot, int id) +void +replaceShotID(shot_t * shot, int id) { - replaceID(shot->id, id); - shot->id = id; + replaceID(shot->id, id); + shot->id = id; } -void getStatusShot(void *p, int *id, int *x,int *y, int *w, int *h) +void +getStatusShot(void *p, int *id, int *x, int *y, int *w, int *h) { - shot_t *shot; - - shot = p; - *id = shot->id; - *x = shot->x; - *y = shot->y; - *w = shot->w; - *h = shot->h; + shot_t *shot; + + shot = p; + *id = shot->id; + *x = shot->x; + *y = shot->y; + *w = shot->w; + *h = shot->h; } -void setStatusShot(void *p, int x, int y, int w, int h) +void +setStatusShot(void *p, int x, int y, int w, int h) { - shot_t *shot; + shot_t *shot; - shot = p; - shot->x = x; - shot->y = y; - shot->w = w; - shot->h = h; + shot = p; + shot->x = x; + shot->y = y; + shot->w = w; + shot->h = h; } -#ifndef PUBLIC_SERVER +#ifndef PUBLIC_SERVER -void drawShot(shot_t *p) +void +drawShot(shot_t * p) { - assert( p != NULL ); - addLayer(p->img, p->x, p->y, 0, 0, p->img->w, p->img->h, TUX_LAYER); + assert(p != NULL); + addLayer(p->img, p->x, p->y, 0, 0, p->img->w, p->img->h, TUX_LAYER); } -void drawListShot(list_t *listShot) +void +drawListShot(list_t * listShot) { - shot_t *thisShot; - int i; + shot_t *thisShot; + int i; - assert( listShot != NULL ); + assert(listShot != NULL); - for( i = 0 ; i < listShot->count ; i++ ) - { - thisShot = (shot_t *)listShot->list[i]; - assert( thisShot != NULL ); - drawShot(thisShot); - } + for (i = 0; i < listShot->count; i++) { + thisShot = (shot_t *) listShot->list[i]; + assert(thisShot != NULL); + drawShot(thisShot); + } } #endif -static int getRandomCourse(int x, int y) +static int +getRandomCourse(int x, int y) { - int ret = -1; // no warnning - - do{ - switch( random() % 3 ) - { - case 0 : - ret = y; - break; - case 1 : - ret = -y; - break; - case 2 : - ret = 0; - break; - } - }while( ret == x ); - - return ret; + int ret = -1; // no warnning + + do { + switch (random() % 3) { + case 0: + ret = y; + break; + case 1: + ret = -y; + break; + case 2: + ret = 0; + break; + } + } while (ret == x); + + return ret; } -void boundBombBall(shot_t *shot) +void +boundBombBall(shot_t * shot) { - if( shot->gun != GUN_BOMBBALL ) - { - return; - } - - shot->px = getRandomCourse(shot->px, +10); - shot->py = getRandomCourse(shot->py, +10); - shot->isCanKillAuthor = 1; - - if( getNetTypeGame() == NET_GAME_TYPE_SERVER ) - { - proto_send_shot_server(PROTO_SEND_ALL, NULL, shot); - } + if (shot->gun != GUN_BOMBBALL) { + return; + } + + shot->px = getRandomCourse(shot->px, +10); + shot->py = getRandomCourse(shot->py, +10); + shot->isCanKillAuthor = 1; + + if (getNetTypeGame() == NET_GAME_TYPE_SERVER) { + proto_send_shot_server(PROTO_SEND_ALL, NULL, shot); + } } -void transformOnlyLasser(shot_t *shot) +void +transformOnlyLasser(shot_t * shot) { - space_t *space; - int mustRefesh = 0; - - space = getCurrentArena()->spaceShot; - - if( getObjectFromSpaceWithID(space, shot->id) != NULL ) - { - mustRefesh = 1; - } - - if( mustRefesh ) - { - delObjectFromSpace(space, shot); - } - - switch( shot->position ) - { - case TUX_RIGHT : - case TUX_LEFT : - shot->w = GUN_LASSER_HORIZONTAL; - shot->h = GUN_SHOT_VERTICAL; -#ifndef PUBLIC_SERVER - shot->img = g_shot_lasserX; + space_t *space; + int mustRefesh = 0; + + space = getCurrentArena()->spaceShot; + + if (getObjectFromSpaceWithID(space, shot->id) != NULL) { + mustRefesh = 1; + } + + if (mustRefesh) { + delObjectFromSpace(space, shot); + } + + switch (shot->position) { + case TUX_RIGHT: + case TUX_LEFT: + shot->w = GUN_LASSER_HORIZONTAL; + shot->h = GUN_SHOT_VERTICAL; +#ifndef PUBLIC_SERVER + shot->img = g_shot_lasserX; #endif - break; - case TUX_UP : - case TUX_DOWN : - shot->w = GUN_SHOT_VERTICAL; - shot->h = GUN_LASSER_HORIZONTAL; -#ifndef PUBLIC_SERVER - shot->img = g_shot_lasserY; + break; + case TUX_UP: + case TUX_DOWN: + shot->w = GUN_SHOT_VERTICAL; + shot->h = GUN_LASSER_HORIZONTAL; +#ifndef PUBLIC_SERVER + shot->img = g_shot_lasserY; #endif - break; - } + break; + } - if( mustRefesh) - { - addObjectToSpace(space, shot); - } + if (mustRefesh) { + addObjectToSpace(space, 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; + int new_x, new_y; + arena_t *arena; - arena = getCurrentArena(); + arena = getCurrentArena(); - new_x = shot->x + shot->px; - new_y = shot->y + shot->py; + new_x = shot->x + shot->px; + new_y = shot->y + shot->py; - moveObjectInSpace(space, shot, new_x, new_y); + moveObjectInSpace(space, shot, new_x, new_y); - if( shot->x+shot->w < 0 || shot->x > arena->w || - shot->y+shot->h < 0 || shot->y > arena->h ) - { - delObjectFromSpaceWithObject(space, shot, destroyShot); - } + if (shot->x + shot->w < 0 || shot->x > arena->w || + shot->y + shot->h < 0 || shot->y > arena->h) { + delObjectFromSpaceWithObject(space, shot, destroyShot); + } } -void eventMoveListShot(arena_t *arena) +void +eventMoveListShot(arena_t * arena) { - actionSpace(arena->spaceShot, action_moveShot, NULL); + actionSpace(arena->spaceShot, action_moveShot, NULL); } -static int isValueInList(list_t *list, int x) +static int +isValueInList(list_t * list, int x) { - int i; + int i; - for( i = 0 ; i < list->count ; i++ ) - { - if( x == ( *(int *)list->list[i] ) ) - { - return 1; - } - } + for (i = 0; i < list->count; i++) { + if (x == (*(int *) list->list[i])) { + return 1; + } + } - return 0; + 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) { - if( isValueInList(client->listSeesShot, shot->id) == 0 ) - { - addList(client->listSeesShot, newInt(shot->id) ); - proto_send_shot_server(PROTO_SEND_ONE, client, shot); - } + if (isValueInList(client->listSeesShot, shot->id) == 0) { + addList(client->listSeesShot, newInt(shot->id)); + proto_send_shot_server(PROTO_SEND_ONE, client, shot); + } } -void checkShotIsInTuxScreen(arena_t *arena) +void +checkShotIsInTuxScreen(arena_t * arena) { - int screen_x, screen_y; - tux_t *thisTux; - client_t *thisClient; - list_t *listClient; - int i; - - if( getNetTypeGame() != NET_GAME_TYPE_SERVER ) - { - return; - } - - listClient = getListServerClient(); - - for( i = 0 ; i < listClient->count ; i++ ) - { - thisClient = (client_t *)listClient->list[i]; - thisTux = (tux_t *)thisClient->tux; - int del = 0; - - if( thisTux == NULL || thisTux->control != TUX_CONTROL_NET ) - { - continue; - } - - getCenterScreen(&screen_x, &screen_y, thisTux->x, thisTux->y, WINDOW_SIZE_X, WINDOW_SIZE_Y); - - actionSpaceFromLocation(arena->spaceShot, action_check, - thisClient, screen_x, screen_y, WINDOW_SIZE_X, WINDOW_SIZE_Y); - - while( thisClient->listSeesShot->count > 100 ) - { - delListItem(thisClient->listSeesShot, 0, free); - del++; - } - - //if( del > 0 )printf("del = %d\n", del); - } + int screen_x, screen_y; + tux_t *thisTux; + client_t *thisClient; + list_t *listClient; + int i; + + if (getNetTypeGame() != NET_GAME_TYPE_SERVER) { + return; + } + + listClient = getListServerClient(); + + for (i = 0; i < listClient->count; i++) { + thisClient = (client_t *) listClient->list[i]; + thisTux = (tux_t *) thisClient->tux; + int del = 0; + + if (thisTux == NULL || thisTux->control != TUX_CONTROL_NET) { + continue; + } + + getCenterScreen(&screen_x, &screen_y, thisTux->x, thisTux->y, + WINDOW_SIZE_X, WINDOW_SIZE_Y); + + actionSpaceFromLocation(arena->spaceShot, action_check, + thisClient, screen_x, screen_y, WINDOW_SIZE_X, + WINDOW_SIZE_Y); + + while (thisClient->listSeesShot->count > 100) { + delListItem(thisClient->listSeesShot, 0, free); + del++; + } + + //if( del > 0 )printf("del = %d\n", del); + } } -void destroyShot(shot_t *p) +void +destroyShot(shot_t * p) { - assert( p != NULL ); - - delID(p->id); + assert(p != NULL); + + delID(p->id); - free(p); + free(p); } -void quitShot() +void +quitShot() { - isShotInit = FALSE; + isShotInit = FALSE; } diff --git a/src/base/space.c b/src/base/space.c index 382c4a4..dff34c5 100644 --- a/src/base/space.c +++ b/src/base/space.c @@ -9,387 +9,378 @@ #include "space.h" #include "index.h" -zone_t* newZone() +zone_t * +newZone() { - zone_t *new; + zone_t *new; - new = malloc( sizeof(zone_t) ); - new->list = newList(); + new = malloc(sizeof(zone_t)); + new->list = newList(); - return new; + return new; } -void destroyZone(zone_t *p) +void +destroyZone(zone_t * p) { - assert( p != NULL ); + assert(p != NULL); - destroyList(p->list); - free(p); + destroyList(p->list); + free(p); } -static int my_conflictSpace(int x1,int y1,int w1,int h1,int x2,int y2,int w2,int h2) +static int +my_conflictSpace(int x1, int y1, int w1, int h1, int x2, int y2, int w2, + int h2) { - return (x1<x2+w2 && x2<x1+w1 && y1<y2+h2 && y2<y1+h1); + return (x1 < x2 + w2 && x2 < x1 + w1 && y1 < y2 + h2 && y2 < y1 + h1); } -space_t *newSpace(int w, int h, int segW, int segH, - void (*getStatus)(void *p, int *id, int *x, int *y, int *w, int *h), - void (*setStatus)(void *p, int x, int y, int w, int h)) +space_t * +newSpace(int w, int h, int segW, int segH, + void (*getStatus) (void *p, int *id, int *x, int *y, int *w, int *h), + void (*setStatus) (void *p, int x, int y, int w, int h)) { - space_t *new; - int i, j; - - new = malloc( sizeof(space_t) ); - memset(new, 0, sizeof(space_t)); - - new->w = w / segW + 1; - new->h = h / segH + 1; - new->segW = segW; - new->segH = segH; - new->getStatus = getStatus; - new->setStatus = setStatus; - new->listIndex = newIndex(); - - new->zone = malloc( new->w * sizeof(list_t **) ); - - for( i = 0 ; i < new->w ; i++ ) - { - new->zone[i] = malloc( new->h * sizeof(list_t *) ); - } - - for( i = 0 ; i < new->h ; i++ ) - { - for( j = 0 ; j < new->w ; j++ ) - { - new->zone[j][i] = newZone(); - } - } - - return new; + space_t *new; + int i, j; + + new = malloc(sizeof(space_t)); + memset(new, 0, sizeof(space_t)); + + new->w = w / segW + 1; + new->h = h / segH + 1; + new->segW = segW; + new->segH = segH; + new->getStatus = getStatus; + new->setStatus = setStatus; + new->listIndex = newIndex(); + + new->zone = malloc(new->w * sizeof(list_t **)); + + for (i = 0; i < new->w; i++) { + new->zone[i] = malloc(new->h * sizeof(list_t *)); + } + + for (i = 0; i < new->h; i++) { + for (j = 0; j < new->w; j++) { + new->zone[j][i] = newZone(); + } + } + + 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; - *segW = ( (x+w) / p->segW + 1 ) - *segX; - *segH = ( (y+h) / p->segH + 1 ) - *segY; + *segX = x / p->segW; + *segY = y / p->segH; + *segW = ((x + w) / p->segW + 1) - *segX; + *segH = ((y + h) / p->segH + 1) - *segY; } -int getSpaceCount(space_t *p) +int +getSpaceCount(space_t * p) { - return p->listIndex->count; + return p->listIndex->count; } -void* getItemFromSpace(space_t *p, int offset) +void * +getItemFromSpace(space_t * p, int offset) { - index_item_t *this; + index_item_t *this; - this = (index_item_t *)p->listIndex->list[offset]; - return this->data; + this = (index_item_t *) p->listIndex->list[offset]; + return this->data; } -void addObjectToSpace(space_t *p, void *item) +void +addObjectToSpace(space_t * p, void *item) { - int segX, segY, segW, segH; - int id, x, y, w, h; - int i, j; - - p->getStatus(item, &id, &x, &y, &w, &h); - getSegment(p, x, y, w, h, &segX, &segY, &segW, &segH); - - for( i = segY ; i < segY + segH ; i++ ) - { - for( j = segX ; j < segX + segW ; j++ ) - { - if( j < 0 || j >= p->w || i < 0 || i >= p->h ) - { - continue; - } - - addList(p->zone[j][i]->list, item); - } - } - - addToIndex(p->listIndex, id, item); + int segX, segY, segW, segH; + int id, x, y, w, h; + int i, j; + + p->getStatus(item, &id, &x, &y, &w, &h); + getSegment(p, x, y, w, h, &segX, &segY, &segW, &segH); + + for (i = segY; i < segY + segH; i++) { + for (j = segX; j < segX + segW; j++) { + if (j < 0 || j >= p->w || i < 0 || i >= p->h) { + continue; + } + + addList(p->zone[j][i]->list, item); + } + } + + addToIndex(p->listIndex, id, item); } -void getObjectFromSpace(space_t *p, int x, int y, int w, int h, list_t *list) +void +getObjectFromSpace(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; - int i, j, k; - - getSegment(p, x, y, w, h, &segX, &segY, &segW, &segH); - - for( i = segY ; i < segY + segH ; i++ ) - { - for( j = segX ; j < segX + segW ; j++ ) - { - void *this; - - if( j < 0 || j >= p->w || i < 0 || i >= p->h ) - { - continue; - } - - for( k = 0 ; k < p->zone[j][i]->list->count ; k++ ) - { - this = p->zone[j][i]->list->list[k]; - p->getStatus(this, &id, &this_x, &this_y, &this_w, &this_h); - - if( my_conflictSpace(x, y, w, h, this_x, this_y, this_w, this_h) && - searchListItem(list, this) == -1 ) - { - addList(list, this); - } - } - } - } + int segX, segY, segW, segH; + int id, this_x, this_y, this_w, this_h; + int i, j, k; + + getSegment(p, x, y, w, h, &segX, &segY, &segW, &segH); + + for (i = segY; i < segY + segH; i++) { + for (j = segX; j < segX + segW; j++) { + void *this; + + if (j < 0 || j >= p->w || i < 0 || i >= p->h) { + continue; + } + + for (k = 0; k < p->zone[j][i]->list->count; k++) { + this = p->zone[j][i]->list->list[k]; + p->getStatus(this, &id, &this_x, &this_y, &this_w, &this_h); + + if (my_conflictSpace + (x, y, w, h, this_x, this_y, this_w, this_h) + && searchListItem(list, this) == -1) { + addList(list, this); + } + } + } + } } -void* getObjectFromSpaceWithID(space_t *space, int id) +void * +getObjectFromSpaceWithID(space_t * space, int id) { - return getFromIndex(space->listIndex, id); + return getFromIndex(space->listIndex, id); } -int isConflictWithObjectFromSpace(space_t *p, int x, int y, int w, int h) +int +isConflictWithObjectFromSpace(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; - int i, j, k; - - getSegment(p, x, y, w, h, &segX, &segY, &segW, &segH); - - for( i = segY ; i < segY + segH ; i++ ) - { - for( j = segX ; j < segX + segW ; j++ ) - { - void *this; - - if( j < 0 || j >= p->w || i < 0 || i >= p->h ) - { - continue; - } - - for( k = 0 ; k < p->zone[j][i]->list->count ; k++ ) - { - this = p->zone[j][i]->list->list[k]; - p->getStatus(this, &id, &this_x, &this_y, &this_w, &this_h); - - if( my_conflictSpace(x, y, w, h, this_x, this_y, this_w, this_h) ) - { - return 1; - } - } - } - } - - return 0; + int segX, segY, segW, segH; + int id, this_x, this_y, this_w, this_h; + int i, j, k; + + getSegment(p, x, y, w, h, &segX, &segY, &segW, &segH); + + for (i = segY; i < segY + segH; i++) { + for (j = segX; j < segX + segW; j++) { + void *this; + + if (j < 0 || j >= p->w || i < 0 || i >= p->h) { + continue; + } + + for (k = 0; k < p->zone[j][i]->list->count; k++) { + this = p->zone[j][i]->list->list[k]; + p->getStatus(this, &id, &this_x, &this_y, &this_w, &this_h); + + if (my_conflictSpace + (x, y, w, h, this_x, this_y, this_w, this_h)) { + return 1; + } + } + } + } + + return 0; } -int isConflictWithObjectFromSpaceBut(space_t *p, int x, int y, int w, int h, void *but) +int +isConflictWithObjectFromSpaceBut(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; - int i, j, k; - - getSegment(p, x, y, w, h, &segX, &segY, &segW, &segH); - - for( i = segY ; i < segY + segH ; i++ ) - { - for( j = segX ; j < segX + segW ; j++ ) - { - void *this; - - if( j < 0 || j >= p->w || i < 0 || i >= p->h ) - { - continue; - } - - for( k = 0 ; k < p->zone[j][i]->list->count ; k++ ) - { - this = p->zone[j][i]->list->list[k]; - - if( this == but ) - { - continue; - } - - p->getStatus(this, &id, &this_x, &this_y, &this_w, &this_h); - - if( my_conflictSpace(x, y, w, h, this_x, this_y, this_w, this_h) ) - { - return 1; - } - } - } - } - - return 0; + int segX, segY, segW, segH; + int id, this_x, this_y, this_w, this_h; + int i, j, k; + + getSegment(p, x, y, w, h, &segX, &segY, &segW, &segH); + + for (i = segY; i < segY + segH; i++) { + for (j = segX; j < segX + segW; j++) { + void *this; + + if (j < 0 || j >= p->w || i < 0 || i >= p->h) { + continue; + } + + for (k = 0; k < p->zone[j][i]->list->count; k++) { + this = p->zone[j][i]->list->list[k]; + + if (this == but) { + continue; + } + + p->getStatus(this, &id, &this_x, &this_y, &this_w, &this_h); + + if (my_conflictSpace + (x, y, w, h, this_x, this_y, this_w, this_h)) { + return 1; + } + } + } + } + + return 0; } -void delObjectFromSpace(space_t *p, void *item) +void +delObjectFromSpace(space_t * p, void *item) { - int segX, segY, segW, segH; - int id, x, y, w, h; - int index; - int i, j; - - p->getStatus(item, &id, &x, &y, &w, &h); - getSegment(p, x, y, w, h, &segX, &segY, &segW, &segH); - - for( i = segY ; i < segY + segH ; i++ ) - { - for( j = segX ; j < segX + segW ; j++ ) - { - if( j < 0 || j >= p->w || i < 0 || i >= p->h ) - { - continue; - } - - index = searchListItem(p->zone[j][i]->list, item); - assert( index != -1 ); - delList(p->zone[j][i]->list, index); - } - } - - delFromIndex(p->listIndex, id); + int segX, segY, segW, segH; + int id, x, y, w, h; + int index; + int i, j; + + p->getStatus(item, &id, &x, &y, &w, &h); + getSegment(p, x, y, w, h, &segX, &segY, &segW, &segH); + + for (i = segY; i < segY + segH; i++) { + for (j = segX; j < segX + segW; j++) { + if (j < 0 || j >= p->w || i < 0 || i >= p->h) { + continue; + } + + index = searchListItem(p->zone[j][i]->list, item); + assert(index != -1); + delList(p->zone[j][i]->list, index); + } + } + + delFromIndex(p->listIndex, id); } -void delObjectFromSpaceWithObject(space_t *p, void *item, void *f) +void +delObjectFromSpaceWithObject(space_t * p, void *item, void *f) { - void (*fce)(void *param); + void (*fce) (void *param); - fce = f; + fce = f; - delObjectFromSpace(p, item); - fce(item); + delObjectFromSpace(p, item); + fce(item); } -void moveObjectInSpace(space_t *p, void *item, int move_x, int move_y) +void +moveObjectInSpace(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; - int id, x, y, w, h; - - 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); + int old_segX, old_segY, old_segW, old_segH; + int new_segX, new_segY, new_segW, new_segH; + int id, x, y, w, h; + + 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 ) - { - delObjectFromSpace(p, item); - p->setStatus(item, move_x, move_y, w, h); - addObjectToSpace(p, item); - return; - } - - p->setStatus(item, move_x, move_y, w, h); + if (old_segX != new_segX || old_segY != new_segY || + old_segW != new_segW || old_segH != new_segH) { + delObjectFromSpace(p, item); + p->setStatus(item, move_x, move_y, w, h); + addObjectToSpace(p, item); + return; + } + + p->setStatus(item, move_x, move_y, w, h); } -void printSpace(space_t *p) +void +printSpace(space_t * p) { - int i, j; + int i, j; - printf("print space : \n"); + printf("print space : \n"); - for( i = 0 ; i < p->h ; i++ ) - { - for( j = 0 ; j < p->w ; j++ ) - { - printf("%3d ", p->zone[j][i]->list->count); - } + for (i = 0; i < p->h; i++) { + for (j = 0; j < p->w; j++) { + printf("%3d ", p->zone[j][i]->list->count); + } - putchar('\n'); - } + putchar('\n'); + } } -void actionSpace(space_t *space, void *f, void *p) +void +actionSpace(space_t * space, void *f, void *p) { - void (*fce)(space_t *space, void *f, void *p); - int len; - int i; - - fce = f; - len = space->listIndex->count; - - for( i = 0 ; i < len ; i++ ) - { - fce(space, getItemFromSpace(space, i), p); - - if( space->listIndex->count == len-1 ) - { - len--; - i--; - } - } + void (*fce) (space_t * space, void *f, void *p); + int len; + int i; + + fce = f; + len = space->listIndex->count; + + for (i = 0; i < len; i++) { + fce(space, getItemFromSpace(space, i), p); + + if (space->listIndex->count == len - 1) { + len--; + i--; + } + } } -void actionSpaceFromLocation(space_t *space, void *f, void *p, int x, int y, int w, int h) +void +actionSpaceFromLocation(space_t * space, void *f, void *p, int x, int y, + int w, int h) { - void (*fce)(space_t *space, void *f, void *p); - list_t *list; - int len; - int i; + void (*fce) (space_t * space, void *f, void *p); + list_t *list; + int len; + int i; - fce = f; + fce = f; - list = newList(); + list = newList(); - getObjectFromSpace(space, x, y, w, h, list); + getObjectFromSpace(space, x, y, w, h, list); - len = list->count; + len = list->count; - for( i = 0 ; i < len ; i++ ) - { - fce(space, list->list[i], p); - } + for (i = 0; i < len; i++) { + fce(space, list->list[i], p); + } - destroyList(list); + destroyList(list); } -void destroySpace(space_t *p) +void +destroySpace(space_t * p) { - int j, i; + int j, i; - destroyIndex(p->listIndex); + destroyIndex(p->listIndex); - for( i = 0 ; i < p->h ; i++ ) - { - for( j = 0 ; j < p->w ; j++ ) - { - destroyZone(p->zone[j][i]); - } - } + for (i = 0; i < p->h; i++) { + for (j = 0; j < p->w; j++) { + destroyZone(p->zone[j][i]); + } + } - for( i = 0 ; i < p->w ; i++ ) - { - free(p->zone[i]); - } + for (i = 0; i < p->w; i++) { + free(p->zone[i]); + } - free(p->zone); - free(p); + free(p->zone); + free(p); } -void destroySpaceWithObject(space_t *p, void *f) +void +destroySpaceWithObject(space_t * p, void *f) { - void (*fce)(void *param); - int i; + void (*fce) (void *param); + int i; - fce = f; + fce = f; - for( i = 0 ; i < p->listIndex->count ; i++ ) - { - fce( getItemFromSpace(p, i) ); - } + for (i = 0; i < p->listIndex->count; i++) { + fce(getItemFromSpace(p, i)); + } - destroySpace(p); + destroySpace(p); } - diff --git a/src/base/storage.c b/src/base/storage.c index 7a7ee91..ca55bc4 100644 --- a/src/base/storage.c +++ b/src/base/storage.c @@ -9,117 +9,125 @@ typedef struct struct_storage_item { - char *name; - char *group; - void *data; + char *name; + char *group; + void *data; } storage_item_t; -list_t* newStorage() +list_t * +newStorage() { - return newList(); + return newList(); } -static storage_item_t* newStorageItem(char *group, char *name, void *data) +static storage_item_t * +newStorageItem(char *group, char *name, void *data) { - storage_item_t *new; - - assert(name != NULL); - assert(group != NULL); - assert(data != NULL); - new = malloc(sizeof(storage_item_t)); - new->name = strdup(name); - new->group = strdup(group); - new->data = data; - return new; + storage_item_t *new; + + assert(name != NULL); + assert(group != NULL); + assert(data != NULL); + new = malloc(sizeof(storage_item_t)); + new->name = strdup(name); + new->group = strdup(group); + new->data = data; + return new; } -static void destroyStorageItem(storage_item_t *p, void *f) +static void +destroyStorageItem(storage_item_t * p, void *f) { - void(*fce)(void *); - - assert(p != NULL); - assert(f != NULL); - fce = f; - fce(p->data); - free(p->name); - free(p->group); - free(p); + void (*fce) (void *); + + assert(p != NULL); + assert(f != NULL); + fce = f; + fce(p->data); + free(p->name); + free(p->group); + free(p); } -void addItemToStorage(list_t *list, char *group, char *name, void *data) +void +addItemToStorage(list_t * list, char *group, char *name, void *data) { - assert(list != NULL); - assert(group != NULL); - assert(name != NULL); - addList(list, newStorageItem(group, name, data) ); + assert(list != NULL); + assert(group != NULL); + assert(name != NULL); + addList(list, newStorageItem(group, name, data)); } -void* getItemFromStorage(list_t *list, char *group, char *name) +void * +getItemFromStorage(list_t * list, char *group, char *name) { - storage_item_t *this; - int i; - - assert(list != NULL); - assert(group != NULL); - assert(name != NULL); - 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) - return this->data; - } + storage_item_t *this; + int i; + + assert(list != NULL); + assert(group != NULL); + assert(name != NULL); + 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) + return this->data; + } #ifdef DEBUG - printf(_("%s %s was not found in storage!\n"), group, name); + printf(_("%s %s was not found in storage!\n"), group, name); #endif - return NULL; + return NULL; } -void delItemFromStorage(list_t *list, char *group, char *name, void *f) +void +delItemFromStorage(list_t * list, char *group, char *name, void *f) { - storage_item_t *this; - int i; - - assert(list != NULL); - assert(group != NULL); - assert(name != NULL); - 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) { - destroyStorageItem(this, f); - delList(list, i); - return; - } - } - return; + storage_item_t *this; + int i; + + assert(list != NULL); + assert(group != NULL); + assert(name != NULL); + 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) { + destroyStorageItem(this, f); + delList(list, i); + return; + } + } + return; } -void delAllItemFromStorage(list_t *list, char *group, void *f) +void +delAllItemFromStorage(list_t * list, char *group, void *f) { - storage_item_t *this; - int i; - - assert(list != NULL); - assert(group != NULL); - - for (i = 0; i < list->count; i++) { - this = (storage_item_t *) list->list[i]; - if (strcmp(group, this->group) == 0) { - destroyStorageItem(this, f); - delList(list, i); - i--; - } - } + storage_item_t *this; + int i; + + assert(list != NULL); + assert(group != NULL); + + for (i = 0; i < list->count; i++) { + this = (storage_item_t *) list->list[i]; + if (strcmp(group, this->group) == 0) { + destroyStorageItem(this, f); + delList(list, i); + i--; + } + } } -void destroyStorage(list_t *p, void *f) +void +destroyStorage(list_t * p, void *f) { - storage_item_t *this; - int i; - - assert(p != NULL); - assert(f != NULL); - for (i = 0; i < p->count; i++) { - this = (storage_item_t *)p->list[i]; - destroyStorageItem(this, f); - } - destroyList(p); + storage_item_t *this; + int i; + + assert(p != NULL); + assert(f != NULL); + for (i = 0; i < p->count; i++) { + this = (storage_item_t *) p->list[i]; + destroyStorageItem(this, f); + } + destroyList(p); } diff --git a/src/base/tcp_server.c b/src/base/tcp_server.c index 14e7e22..14d1794 100644 --- a/src/base/tcp_server.c +++ b/src/base/tcp_server.c @@ -46,248 +46,242 @@ static sock_tcp_t *sock_server_tcp; static sock_tcp_t *sock_server_tcp_second; -client_t* newTcpClient(sock_tcp_t *sock_tcp) +client_t * +newTcpClient(sock_tcp_t * sock_tcp) { - client_t *new; + client_t *new; - assert( sock_tcp != NULL ); + assert(sock_tcp != NULL); - new = newAnyClient(); - new->type = CLIENT_TYPE_TCP; - new->socket_tcp = sock_tcp; - new->recvBuffer = newBuffer(SERVER_TCP_BUFFER_LIMIT); - new->sendBuffer = newBuffer(SERVER_TCP_BUFFER_LIMIT); + new = newAnyClient(); + new->type = CLIENT_TYPE_TCP; + new->socket_tcp = sock_tcp; + new->recvBuffer = newBuffer(SERVER_TCP_BUFFER_LIMIT); + new->sendBuffer = newBuffer(SERVER_TCP_BUFFER_LIMIT); #ifdef PUBLIC_SERVER - char str_log[STR_LOG_SIZE]; - char str_ip[STR_IP_SIZE]; + char str_log[STR_LOG_SIZE]; + char str_ip[STR_IP_SIZE]; - getSockTcpIp(sock_tcp, str_ip, STR_IP_SIZE); - sprintf(str_log, _("New client \"%s\" on port \"%d\" connected"), str_ip, getSockTcpPort(sock_tcp)); - addToLog(LOG_INF, str_log); + getSockTcpIp(sock_tcp, str_ip, STR_IP_SIZE); + sprintf(str_log, _("New client \"%s\" on port \"%d\" connected"), str_ip, + getSockTcpPort(sock_tcp)); + addToLog(LOG_INF, str_log); #endif - return new; + return new; } -void sendTcpClientBuffer(client_t *client) +void +sendTcpClientBuffer(client_t * client) { - void *data; - int len; - int res; + void *data; + int len; + int res; - len = getBufferSize(client->sendBuffer); + len = getBufferSize(client->sendBuffer); - if( len == 0 ) - { - return; - } + if (len == 0) { + return; + } - data = getBufferData(client->sendBuffer); + data = getBufferData(client->sendBuffer); - res = writeTcpSocket(client->socket_tcp, data, len); - //printf("writeTcpSocket = %d\n", res); + res = writeTcpSocket(client->socket_tcp, data, len); + //printf("writeTcpSocket = %d\n", res); - if( res < 0 ) - { - client->status = NET_STATUS_ZOMBIE; - return; - } + if (res < 0) { + client->status = NET_STATUS_ZOMBIE; + return; + } - cutBuffer(client->sendBuffer, res); + cutBuffer(client->sendBuffer, res); } -void destroyTcpClient(client_t *client) +void +destroyTcpClient(client_t * client) { - eventMsgInCheckFront(client); - sendTcpClientBuffer(client); + eventMsgInCheckFront(client); + sendTcpClientBuffer(client); #ifdef PUBLIC_SERVER - char str_log[STR_LOG_SIZE]; - char str_ip[STR_IP_SIZE]; + char str_log[STR_LOG_SIZE]; + char str_ip[STR_IP_SIZE]; - getSockTcpIp(client->socket_tcp, str_ip, STR_IP_SIZE); - sprintf(str_log, _("Client \"%s\" on port \"%d\" disconnected"), str_ip, getSockTcpPort(client->socket_tcp)); - addToLog(LOG_INF, str_log); + getSockTcpIp(client->socket_tcp, str_ip, STR_IP_SIZE); + sprintf(str_log, _("Client \"%s\" on port \"%d\" disconnected"), str_ip, + getSockTcpPort(client->socket_tcp)); + addToLog(LOG_INF, str_log); #endif - closeTcpSocket(client->socket_tcp); - destroyBuffer(client->recvBuffer); - destroyBuffer(client->sendBuffer); + closeTcpSocket(client->socket_tcp); + destroyBuffer(client->recvBuffer); + destroyBuffer(client->sendBuffer); - destroyAnyClient(client); + destroyAnyClient(client); } -int initTcpServer(char *ip4, int port4, char *ip6, int port6) +int +initTcpServer(char *ip4, int port4, char *ip6, int port6) { - int ret; + int ret; - ret = 0; + ret = 0; - if( ip4 != NULL ) - { - sock_server_tcp = bindTcpSocket(ip4, port4, PROTO_UDPv4); + if (ip4 != NULL) { + sock_server_tcp = bindTcpSocket(ip4, port4, PROTO_UDPv4); - if( sock_server_tcp != NULL ) - { - ret++; - disableNagle(sock_server_tcp); + if (sock_server_tcp != NULL) { + ret++; + disableNagle(sock_server_tcp); #ifdef DEBUG - printf(_("Starting server: \"%s\" on port: \"%d\"\n"), ip4, port4); + printf(_("Starting server: \"%s\" on port: \"%d\"\n"), ip4, + port4); #endif - } - else - { + } + else { #ifdef DEBUG - printf(_("Starting server: \"%s\" on port: \"%d\" FAILED!\n"), ip4, port4); + printf(_("Starting server: \"%s\" on port: \"%d\" FAILED!\n"), + ip4, port4); #endif - } - } + } + } - if( ip6 != NULL ) - { - sock_server_tcp_second = bindTcpSocket(ip6, port6, PROTO_UDPv6); + if (ip6 != NULL) { + sock_server_tcp_second = bindTcpSocket(ip6, port6, PROTO_UDPv6); - if( sock_server_tcp_second != NULL ) - { - ret++; - disableNagle(sock_server_tcp_second); + if (sock_server_tcp_second != NULL) { + ret++; + disableNagle(sock_server_tcp_second); #ifdef DEBUG - printf(_("Starting server: \"%s\" on port: \"%d\"\n"), ip6, port6); + printf(_("Starting server: \"%s\" on port: \"%d\"\n"), ip6, + port6); #endif - } - else - { + } + else { #ifdef DEBUG - printf(_("Starting server: \"%s\" on port: \"%d\" FAILED!\n"), ip6, port6); + printf(_("Starting server: \"%s\" on port: \"%d\" FAILED!\n"), + ip6, port6); #endif - } - } + } + } - return ret; + return ret; } -static void eventNewClient(sock_tcp_t *server_sock) +static void +eventNewClient(sock_tcp_t * server_sock) { - list_t *listClient; - sock_tcp_t *sock; - client_t *client; - - listClient = getListServerClient(); + list_t *listClient; + sock_tcp_t *sock; + client_t *client; - sock = getTcpNewClient(server_sock); - disableNagle(sock); - setTcpSockNonBlock(sock); + listClient = getListServerClient(); - client = newTcpClient(sock); - addList(listClient, client); -} + sock = getTcpNewClient(server_sock); + disableNagle(sock); + setTcpSockNonBlock(sock); -static void eventTcpClient(client_t *client) -{ - char buffer[STR_PROTO_SIZE]; - int ret; - - memset(buffer, 0, STR_PROTO_SIZE); - - ret = readTcpSocket(client->socket_tcp, buffer, STR_PROTO_SIZE-1); - //printf("readTcpSocket = %d\n", ret); - - if( ret <= 0 ) - { - client->status = NET_STATUS_ZOMBIE; - return; - } - - if( addBuffer(client->recvBuffer, buffer, ret) < 0 ) - { - client->status = NET_STATUS_ZOMBIE; - return; - } - - while( getBufferLine(client->recvBuffer, buffer, STR_PROTO_SIZE) >= 0 ) - { - addList(client->listRecvMsg, strdup(buffer) ); - } + client = newTcpClient(sock); + addList(listClient, client); } -void setServerTcpSelect() +static void +eventTcpClient(client_t * client) { - list_t *listClient; - int i; + char buffer[STR_PROTO_SIZE]; + int ret; - listClient = getListServerClient(); + memset(buffer, 0, STR_PROTO_SIZE); - if( sock_server_tcp != NULL ) - { - addSockToSelectRead(sock_server_tcp->sock); - } + ret = readTcpSocket(client->socket_tcp, buffer, STR_PROTO_SIZE - 1); + //printf("readTcpSocket = %d\n", ret); - if( sock_server_tcp_second != NULL ) - { - addSockToSelectRead(sock_server_tcp_second->sock); - } + if (ret <= 0) { + client->status = NET_STATUS_ZOMBIE; + return; + } - for( i = 0 ; i < listClient->count ; i++ ) - { - client_t *client; - - client = (client_t *)listClient->list[i]; - - if( client->status != NET_STATUS_OK || client->type != CLIENT_TYPE_TCP ) - { - continue; - } + if (addBuffer(client->recvBuffer, buffer, ret) < 0) { + client->status = NET_STATUS_ZOMBIE; + return; + } - addSockToSelectRead(client->socket_tcp->sock); - } + while (getBufferLine(client->recvBuffer, buffer, STR_PROTO_SIZE) >= 0) { + addList(client->listRecvMsg, strdup(buffer)); + } } -int selectServerTcpSocket() +void +setServerTcpSelect() { - list_t *listClient; - int count; - int i; + list_t *listClient; + int i; - count = 0; + listClient = getListServerClient(); - if( sock_server_tcp != NULL ) - { - if( isChangeSockInSelectRead(sock_server_tcp->sock) ) - { - eventNewClient(sock_server_tcp); - count++; - } - } + if (sock_server_tcp != NULL) { + addSockToSelectRead(sock_server_tcp->sock); + } - if( sock_server_tcp_second != NULL ) - { - if( isChangeSockInSelectRead(sock_server_tcp_second->sock) ) - { - eventNewClient(sock_server_tcp_second); - count++; - } - } + if (sock_server_tcp_second != NULL) { + addSockToSelectRead(sock_server_tcp_second->sock); + } - listClient = getListServerClient(); + for (i = 0; i < listClient->count; i++) { + client_t *client; - for( i = 0 ; i < listClient->count ; i++ ) - { - client_t *client; + client = (client_t *) listClient->list[i]; - client = (client_t *)listClient->list[i]; + if (client->status != NET_STATUS_OK + || client->type != CLIENT_TYPE_TCP) { + continue; + } - if( client->status != NET_STATUS_OK || client->type != CLIENT_TYPE_TCP ) - { - continue; - } + addSockToSelectRead(client->socket_tcp->sock); + } +} - if( isChangeSockInSelectRead(client->socket_tcp->sock) ) - { - //printf("sChangeSockInSelectRead\n"); - eventTcpClient(client); - count++; - } +int +selectServerTcpSocket() +{ + list_t *listClient; + int count; + int i; + + count = 0; + + if (sock_server_tcp != NULL) { + if (isChangeSockInSelectRead(sock_server_tcp->sock)) { + eventNewClient(sock_server_tcp); + count++; + } + } + + if (sock_server_tcp_second != NULL) { + if (isChangeSockInSelectRead(sock_server_tcp_second->sock)) { + eventNewClient(sock_server_tcp_second); + count++; + } + } + + listClient = getListServerClient(); + + for (i = 0; i < listClient->count; i++) { + client_t *client; + + client = (client_t *) listClient->list[i]; + + if (client->status != NET_STATUS_OK + || client->type != CLIENT_TYPE_TCP) { + continue; + } + + if (isChangeSockInSelectRead(client->socket_tcp->sock)) { + //printf("sChangeSockInSelectRead\n"); + eventTcpClient(client); + count++; + } /* if( isChangeSockInSelectWrite(client->socket_tcp->sock) ) { @@ -295,30 +289,30 @@ int selectServerTcpSocket() sendTcpClientBuffer(client); count++; } -*/ - } +*/ + } - return count; + return count; } -void quitTcpServer() +void +quitTcpServer() { - if( sock_server_tcp != NULL ) - { + if (sock_server_tcp != NULL) { #ifdef DEBUG - printf(_("Closing port: \"%d\"\n"), getSockTcpPort(sock_server_tcp)); + printf(_("Closing port: \"%d\"\n"), getSockTcpPort(sock_server_tcp)); #endif - closeTcpSocket(sock_server_tcp); - } + closeTcpSocket(sock_server_tcp); + } - if( sock_server_tcp_second != NULL ) - { + if (sock_server_tcp_second != NULL) { #ifdef DEBUG - printf(_("Closing port: \"%d\"\n"), getSockTcpPort(sock_server_tcp_second)); + printf(_("Closing port: \"%d\"\n"), + getSockTcpPort(sock_server_tcp_second)); #endif - closeTcpSocket(sock_server_tcp_second); - } + closeTcpSocket(sock_server_tcp_second); + } #ifdef DEBUG - printf("Quitting TCP\n"); + printf("Quitting TCP\n"); #endif } diff --git a/src/base/textFile.c b/src/base/textFile.c index 48e5044..4b93d5c 100755 --- a/src/base/textFile.c +++ b/src/base/textFile.c @@ -9,152 +9,149 @@ #include "main.h" #include "textFile.h" -textFile_t* newTextFile(char *s) +textFile_t * +newTextFile(char *s) { - textFile_t *new; - char path[STR_PATH_SIZE]; - assert( s != NULL ); - - if( isFillPath(s) ) - { - strcpy(path, s); - } - else - { - getcwd(path, STR_PATH_SIZE); - strcat(path, "/"); - strcat(path, s); - } - - new = malloc(sizeof(textFile_t)); - new->file = strdup(path); - new->text = newList(); - - return new; + textFile_t *new; + char path[STR_PATH_SIZE]; + assert(s != NULL); + + if (isFillPath(s)) { + strcpy(path, s); + } + else { + getcwd(path, STR_PATH_SIZE); + strcat(path, "/"); + strcat(path, s); + } + + new = malloc(sizeof(textFile_t)); + new->file = strdup(path); + new->text = newList(); + + 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; - char *end_line; - int length_line = 0; + char *line; + char *begin_line; + char *end_line; + int length_line = 0; - assert( list != NULL ); - assert( p != NULL ); - assert( len >= 0 ); + assert(list != NULL); + assert(p != NULL); + assert(len >= 0); - begin_line = p; - - do{ - end_line = memchr( begin_line, '\n', len); - if( end_line == NULL )break; + begin_line = p; - length_line = (int ) (end_line - ( begin_line ) ); + do { + end_line = memchr(begin_line, '\n', len); + if (end_line == NULL) + break; - line = malloc( (length_line+1) * sizeof(char) ); - memset(line, 0, (length_line+1) * sizeof(char) ); - strncpy(line, begin_line, length_line); + length_line = (int) (end_line - (begin_line)); - addList(list, line); - len -= (length_line+1); + line = malloc((length_line + 1) * sizeof(char)); + memset(line, 0, (length_line + 1) * sizeof(char)); + strncpy(line, begin_line, length_line); - begin_line = end_line+1; + addList(list, line); + len -= (length_line + 1); - }while( begin_line != NULL ); + begin_line = end_line + 1; + + } while (begin_line != NULL); } /* * Nacita subor *s a vrati ho f * formatovany v type textFile_t* */ -textFile_t* loadTextFile(char *s) +textFile_t * +loadTextFile(char *s) { - FILE *file; - textFile_t *ret; - char *p; - int file_length = 0; - struct stat buf; - - assert( s != NULL ); - - if( lstat(s, &buf) < 0 ) - { - fprintf(stderr, _("ERROR: unable to get file status for %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); - 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); - fclose(file); - return NULL; - } - - fclose(file); - - ret = newTextFile(s); - createLine(ret->text, p, file_length); - - free(p); - - return ret; + FILE *file; + textFile_t *ret; + char *p; + int file_length = 0; + struct stat buf; + + assert(s != NULL); + + if (lstat(s, &buf) < 0) { + fprintf(stderr, _("ERROR: unable to get file status for %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); + 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); + fclose(file); + return NULL; + } + + fclose(file); + + ret = newTextFile(s); + createLine(ret->text, p, file_length); + + free(p); + + return ret; } /* * Zobrazi text ulozeny v *p * do stdout */ -void printTextFile(textFile_t *p) +void +printTextFile(textFile_t * p) { - int i; + int i; - assert( p != NULL ); + assert(p != NULL); - printf(_("Printing file: \"%s\"\n\n"), p->file); + printf(_("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]); - } + for (i = 0; i < p->text->count; i++) { + printf("%3d >> %s\n", i, (char *) p->text->list[i]); + } } -void saveTextFile(textFile_t *p) +void +saveTextFile(textFile_t * p) { - int i; - FILE *file; - assert( p != NULL ); - - file = fopen(p->file, "wb"); - for(i = 0; i < p->text->count; i++) - { - fprintf(file, "%s\n", (char *)p->text->list[i]); - } - - fclose(file); + int i; + FILE *file; + assert(p != NULL); + + file = fopen(p->file, "wb"); + for (i = 0; i < p->text->count; i++) { + fprintf(file, "%s\n", (char *) p->text->list[i]); + } + + fclose(file); } /* * Uvolni text ulozeny v type textFile_t* * z pamate. */ -void destroyTextFile(textFile_t *p) +void +destroyTextFile(textFile_t * p) { - assert( p != NULL ); + assert(p != NULL); - free(p->file); - destroyListItem(p->text, free); - free(p); + free(p->file); + destroyListItem(p->text, free); + free(p); } - - - diff --git a/src/base/tux.c b/src/base/tux.c index a8e40b5..13467bb 100644 --- a/src/base/tux.c +++ b/src/base/tux.c @@ -47,168 +47,173 @@ static image_t *g_cross; static bool_t isTuxInit = FALSE; -bool_t isTuxInicialized() +bool_t +isTuxInicialized() { - return isTuxInit; + return isTuxInit; } -void initTux() +void +initTux() { #ifndef PUBLIC_SERVER - assert( isImageInicialized() == TRUE ); + assert(isImageInicialized() == TRUE); #endif #ifndef PUBLIC_SERVER - g_tux_up = addImageData("tux8.png", IMAGE_ALPHA, "tux8", IMAGE_GROUP_BASE); - g_tux_right = addImageData("tux6.png", IMAGE_ALPHA, "tux6", IMAGE_GROUP_BASE); - g_tux_left = addImageData("tux4.png", IMAGE_ALPHA, "tux4", IMAGE_GROUP_BASE); - g_tux_down = addImageData("tux2.png", IMAGE_ALPHA, "tux2", IMAGE_GROUP_BASE); - g_cross = addImageData("cross.png", IMAGE_ALPHA, "cross", IMAGE_GROUP_BASE); + g_tux_up = + addImageData("tux8.png", IMAGE_ALPHA, "tux8", IMAGE_GROUP_BASE); + g_tux_right = + addImageData("tux6.png", IMAGE_ALPHA, "tux6", IMAGE_GROUP_BASE); + g_tux_left = + addImageData("tux4.png", IMAGE_ALPHA, "tux4", IMAGE_GROUP_BASE); + g_tux_down = + addImageData("tux2.png", IMAGE_ALPHA, "tux2", IMAGE_GROUP_BASE); + g_cross = + addImageData("cross.png", IMAGE_ALPHA, "cross", IMAGE_GROUP_BASE); #endif - isTuxInit = TRUE; + isTuxInit = TRUE; } -tux_t* newTux() +tux_t * +newTux() { - int x, y; - tux_t *new; + int x, y; + tux_t *new; - new = malloc( sizeof(tux_t) ); - assert( new != NULL ); + new = malloc(sizeof(tux_t)); + assert(new != NULL); - memset(new, 0, sizeof(tux_t) ); - - new->id = getNewID(); - new->status = TUX_STATUS_ALIVE; - new->control = TUX_CONTROL_NONE; + memset(new, 0, sizeof(tux_t)); - findFreeSpace(getCurrentArena(), &x, &y, TUX_WIDTH, TUX_HEIGHT); - setTuxProportion(new, x, y); + new->id = getNewID(); + new->status = TUX_STATUS_ALIVE; + new->control = TUX_CONTROL_NONE; - new->position = TUX_DOWN; - new->gun = GUN_SIMPLE; - new->shot[ new->gun ] = GUN_MAX_SHOT; + findFreeSpace(getCurrentArena(), &x, &y, TUX_WIDTH, TUX_HEIGHT); + setTuxProportion(new, x, y); - sprintf(new->name, "no_name_id_%d", new->id); - new->score = 0; - new->frame = 0; + new->position = TUX_DOWN; + new->gun = GUN_SIMPLE; + new->shot[new->gun] = GUN_MAX_SHOT; - new->bonus = BONUS_NONE; - new->bonus_time = 0; + sprintf(new->name, "no_name_id_%d", new->id); + new->score = 0; + new->frame = 0; - new->isCanShot = TRUE; - new->isCanSwitchGun = TRUE; + new->bonus = BONUS_NONE; + new->bonus_time = 0; - new->client = NULL; + new->isCanShot = TRUE; + new->isCanSwitchGun = TRUE; - return new; + new->client = NULL; + + return new; } -void tuxSetName(tux_t *tux, char *name) +void +tuxSetName(tux_t * tux, char *name) { - strcpy(tux->name, name); - //tux->g_name = getFontImage(name, COLOR_WHITE); + strcpy(tux->name, name); + //tux->g_name = getFontImage(name, COLOR_WHITE); } -bool_t isTuxAnyGun(tux_t *tux) +bool_t +isTuxAnyGun(tux_t * tux) { - int i; - - for( i = 0 ; i < GUN_COUNT ; i++ ) - { - if( tux->shot[i] > 0 ) - { - return TRUE; - } - } + int i; + + for (i = 0; i < GUN_COUNT; i++) { + if (tux->shot[i] > 0) { + return TRUE; + } + } - return FALSE; + return FALSE; } -void getCourse(int n, int *x, int *y) +void +getCourse(int n, int *x, int *y) { - assert( x != NULL ); - assert( y != NULL ); + assert(x != NULL); + assert(y != NULL); - switch( n ) - { - case TUX_UP : - *x = 0; - *y = -1; - break; + switch (n) { + case TUX_UP: + *x = 0; + *y = -1; + break; - case TUX_LEFT : - *x = -1; - *y = 0; - break; + case TUX_LEFT: + *x = -1; + *y = 0; + break; - case TUX_RIGHT : - *x = +1; - *y = 0; - break; + case TUX_RIGHT: + *x = +1; + *y = 0; + break; - case TUX_DOWN : - *x = 0; - *y = +1; - break; + case TUX_DOWN: + *x = 0; + *y = +1; + break; - default : - assert( ! _("Type variable has a really wierd value!") ); - break; - } + default: + assert(!_("Type variable has a really wierd value!")); + break; + } } #ifndef PUBLIC_SERVER -void drawTux(tux_t *tux) +void +drawTux(tux_t * tux) { - image_t *g_image = NULL; + image_t *g_image = NULL; - assert( tux != NULL ); + assert(tux != NULL); - if( tux->bonus == BONUS_HIDDEN && - getNetTypeGame() != NET_GAME_TYPE_NONE && - tux->control == TUX_CONTROL_NET ) - { - return; - } + if (tux->bonus == BONUS_HIDDEN && + getNetTypeGame() != NET_GAME_TYPE_NONE && + tux->control == TUX_CONTROL_NET) { + return; + } - switch( tux->position ) - { - case TUX_UP : - g_image = g_tux_up; - break; + switch (tux->position) { + case TUX_UP: + g_image = g_tux_up; + break; - case TUX_LEFT : - g_image = g_tux_left; - break; + case TUX_LEFT: + g_image = g_tux_left; + break; - case TUX_RIGHT : - g_image = g_tux_right; - break; + case TUX_RIGHT: + g_image = g_tux_right; + break; - case TUX_DOWN : - g_image = g_tux_down; - break; + case TUX_DOWN: + g_image = g_tux_down; + break; - default : - assert( ! _("p->control has a really wierd value!") ); - break; - } + default: + assert(!_("p->control has a really wierd value!")); + break; + } - if( tux->status == TUX_STATUS_DEAD ) - { - g_image = g_cross; + if (tux->status == TUX_STATUS_DEAD) { + g_image = g_cross; - addLayer(g_cross, - tux->x - g_cross->w / 2, - ( tux->y + g_cross->h / 2 ) - g_cross->h, - 0, 0, - g_cross->w, g_cross->h, TUX_LAYER); + addLayer(g_cross, + tux->x - g_cross->w / 2, + (tux->y + g_cross->h / 2) - g_cross->h, + 0, 0, g_cross->w, g_cross->h, TUX_LAYER); - return; - } + return; + } /* if( tux->g_name != NULL ) { @@ -219,12 +224,13 @@ void drawTux(tux_t *tux) 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, - TUX_IMG_WIDTH, TUX_IMG_HEIGHT, 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, + TUX_IMG_WIDTH, TUX_IMG_HEIGHT, TUX_LAYER); } + /* void drawListTux(list_t *listTux) { @@ -243,461 +249,450 @@ void drawListTux(list_t *listTux) */ #endif -void replaceTuxID(tux_t *tux, int id) +void +replaceTuxID(tux_t * tux, int id) { - replaceID(tux->id, id); - tux->id = id; + replaceID(tux->id, id); + tux->id = id; } -static void timer_spawnTux(void *p) +static void +timer_spawnTux(void *p) { - tux_t *tux; - arena_t *arena; - int x, y; - int id; + tux_t *tux; + arena_t *arena; + int x, y; + int id; - id = * ((int *)p); - free(p); + id = *((int *) p); + free(p); - arena = getCurrentArena(); - tux = getObjectFromSpaceWithID(arena->spaceTux, id); + arena = getCurrentArena(); + tux = getObjectFromSpaceWithID(arena->spaceTux, id); - if( tux == NULL )return; + if (tux == NULL) + return; - tux->status = TUX_STATUS_ALIVE; - findFreeSpace(getCurrentArena(), &x, &y, TUX_WIDTH, TUX_HEIGHT); - moveObjectInSpace(getCurrentArena()->spaceTux, tux, x, y); - tux->gun = GUN_SIMPLE; - - addNewItem(arena->spaceItem, ID_UNKNOWN); + tux->status = TUX_STATUS_ALIVE; + findFreeSpace(getCurrentArena(), &x, &y, TUX_WIDTH, TUX_HEIGHT); + moveObjectInSpace(getCurrentArena()->spaceTux, tux, x, y); + tux->gun = GUN_SIMPLE; - if( getNetTypeGame() == NET_GAME_TYPE_SERVER ) - { - proto_send_newtux_server(PROTO_SEND_ALL, NULL, tux); - } + addNewItem(arena->spaceItem, ID_UNKNOWN); + + if (getNetTypeGame() == NET_GAME_TYPE_SERVER) { + proto_send_newtux_server(PROTO_SEND_ALL, NULL, tux); + } } -static void timer_tuxCanShot(void *p) +static void +timer_tuxCanShot(void *p) { - tux_t *tux; - int id; + tux_t *tux; + int id; - id = * ((int *)p); - free(p); + id = *((int *) p); + free(p); - tux = getObjectFromSpaceWithID(getCurrentArena()->spaceTux, id); + tux = getObjectFromSpaceWithID(getCurrentArena()->spaceTux, id); - if( tux == NULL )return; + if (tux == NULL) + return; - tux->isCanShot = TRUE; + tux->isCanShot = TRUE; } -static void timer_tuxCanSwitchGun(void *p) +static void +timer_tuxCanSwitchGun(void *p) { - tux_t *tux; - int id; + tux_t *tux; + int id; - id = * ((int *)p); - free(p); + id = *((int *) p); + free(p); - tux = getObjectFromSpaceWithID(getCurrentArena()->spaceTux, id); + tux = getObjectFromSpaceWithID(getCurrentArena()->spaceTux, id); - if( tux == NULL )return; + if (tux == NULL) + return; - tux->isCanSwitchGun = TRUE; + tux->isCanSwitchGun = TRUE; } -void eventTuxIsDead(tux_t *tux) +void +eventTuxIsDead(tux_t * tux) { - if( tux->status == TUX_STATUS_DEAD ) - { - return; - } + if (tux->status == TUX_STATUS_DEAD) { + return; + } #ifndef NO_SOUND - playSound("dead", SOUND_GROUP_BASE); + playSound("dead", SOUND_GROUP_BASE); #endif - tux->status = TUX_STATUS_DEAD; - memset(tux->shot, 0, sizeof(int) * GUN_COUNT); - tux->gun = GUN_SIMPLE; - tux->shot[ tux->gun ] = GUN_MAX_SHOT; + tux->status = TUX_STATUS_DEAD; + memset(tux->shot, 0, sizeof(int) * GUN_COUNT); + tux->gun = GUN_SIMPLE; + tux->shot[tux->gun] = GUN_MAX_SHOT; - tux->bonus = BONUS_NONE; - tux->bonus_time = 0; - tux->pickup_time = 0; + tux->bonus = BONUS_NONE; + tux->bonus_time = 0; + tux->pickup_time = 0; - tux->isCanShot = TRUE; - tux->isCanSwitchGun = TRUE; + tux->isCanShot = TRUE; + tux->isCanSwitchGun = TRUE; - if( getNetTypeGame() != NET_GAME_TYPE_CLIENT ) - { - addTaskToTimer(getCurrentArena()->listTimer, TIMER_ONE, timer_spawnTux, newInt(tux->id), TUX_TIME_SPAWN ); - } + if (getNetTypeGame() != NET_GAME_TYPE_CLIENT) { + addTaskToTimer(getCurrentArena()->listTimer, TIMER_ONE, + timer_spawnTux, newInt(tux->id), TUX_TIME_SPAWN); + } - if( getNetTypeGame() == NET_GAME_TYPE_SERVER ) - { - proto_send_kill_server(PROTO_SEND_ALL, NULL, tux); - } + if (getNetTypeGame() == NET_GAME_TYPE_SERVER) { + proto_send_kill_server(PROTO_SEND_ALL, NULL, tux); + } } -static void eventTuxIsDeadWIthShot(tux_t *tux, shot_t *shot) +static void +eventTuxIsDeadWIthShot(tux_t * tux, shot_t * shot) { - if( shot->author_id == tux->id ) - { - tux->score--; + if (shot->author_id == tux->id) { + tux->score--; - if( getNetTypeGame() == NET_GAME_TYPE_SERVER ) - { - proto_send_newtux_server(PROTO_SEND_ALL, NULL, tux); - } - } + if (getNetTypeGame() == NET_GAME_TYPE_SERVER) { + proto_send_newtux_server(PROTO_SEND_ALL, NULL, tux); + } + } - if( shot->author_id != tux->id ) - { - tux_t *author; + if (shot->author_id != tux->id) { + tux_t *author; - author = getObjectFromSpaceWithID(getCurrentArena()->spaceTux, shot->author_id); - - if( author != NULL ) - { - author->score++; + author = + getObjectFromSpaceWithID(getCurrentArena()->spaceTux, + shot->author_id); - if( getNetTypeGame() == NET_GAME_TYPE_SERVER ) - { - proto_send_newtux_server(PROTO_SEND_ALL, NULL, author); - } - } + if (author != NULL) { + author->score++; - } + if (getNetTypeGame() == NET_GAME_TYPE_SERVER) { + proto_send_newtux_server(PROTO_SEND_ALL, NULL, author); + } + } + + } - countRoundInc(); - eventTuxIsDead(tux); + countRoundInc(); + eventTuxIsDead(tux); } -void tuxTeleport(tux_t *tux) +void +tuxTeleport(tux_t * tux) { - int x, y; + int x, y; #ifndef NO_SOUND - playSound("teleport", SOUND_GROUP_BASE); + playSound("teleport", SOUND_GROUP_BASE); #endif - if( getNetTypeGame() != NET_GAME_TYPE_CLIENT ) - { - findFreeSpace(getCurrentArena(), &x, &y, TUX_WIDTH, TUX_HEIGHT); - moveObjectInSpace(getCurrentArena()->spaceTux, tux, x, y); - //setTuxProportion(tux, x, y); - } + if (getNetTypeGame() != NET_GAME_TYPE_CLIENT) { + findFreeSpace(getCurrentArena(), &x, &y, TUX_WIDTH, TUX_HEIGHT); + moveObjectInSpace(getCurrentArena()->spaceTux, tux, x, y); + //setTuxProportion(tux, x, y); + } - if( getNetTypeGame() == NET_GAME_TYPE_SERVER ) - { - proto_send_newtux_server(PROTO_SEND_ALL, NULL, tux); - } + if (getNetTypeGame() == NET_GAME_TYPE_SERVER) { + proto_send_newtux_server(PROTO_SEND_ALL, NULL, tux); + } } -static void bombBallExplosion(shot_t *shot) +static void +bombBallExplosion(shot_t * shot) { - item_t *item; - int x, y; - - x = ( shot->x + shot->w/2 ) - ITEM_BIG_EXPLOSION_WIDTH/2; - y = ( shot->y + shot->h/2 ) - ITEM_BIG_EXPLOSION_HEIGHT/2; - - item = newItem(x, y, ITEM_BIG_EXPLOSION, shot->author_id ); + item_t *item; + int x, y; - addObjectToSpace(getCurrentArena()->spaceItem, item ); + x = (shot->x + shot->w / 2) - ITEM_BIG_EXPLOSION_WIDTH / 2; + y = (shot->y + shot->h / 2) - ITEM_BIG_EXPLOSION_HEIGHT / 2; - if( getNetTypeGame() == NET_GAME_TYPE_SERVER ) - { - proto_send_del_server(PROTO_SEND_ALL, NULL, shot->id); - proto_send_additem_server(PROTO_SEND_ALL, NULL, item); - } + item = newItem(x, y, ITEM_BIG_EXPLOSION, shot->author_id); + + addObjectToSpace(getCurrentArena()->spaceItem, item); + + if (getNetTypeGame() == NET_GAME_TYPE_SERVER) { + proto_send_del_server(PROTO_SEND_ALL, NULL, shot->id); + proto_send_additem_server(PROTO_SEND_ALL, NULL, item); + } - delObjectFromSpaceWithObject(getCurrentArena()->spaceShot, shot, destroyShot); + delObjectFromSpaceWithObject(getCurrentArena()->spaceShot, shot, + destroyShot); } -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) { - arena_t *arena; + arena_t *arena; - arena = getCurrentArena(); + arena = getCurrentArena(); - if( tux->status == TUX_STATUS_ALIVE ) - { - if( shot->author_id == tux->id && - shot->isCanKillAuthor == FALSE ) - { - return; - } - - if( tux->bonus == BONUS_TELEPORT ) - { - tuxTeleport(tux); - return; - } - - if( shot->gun == GUN_BOMBBALL ) - { - if( getNetTypeGame() != NET_GAME_TYPE_CLIENT ) - { - bombBallExplosion(shot); - } - - return; - } - - if( getNetTypeGame() != NET_GAME_TYPE_CLIENT ) - { - eventTuxIsDeadWIthShot(tux, shot); - } - } + if (tux->status == TUX_STATUS_ALIVE) { + if (shot->author_id == tux->id && shot->isCanKillAuthor == FALSE) { + return; + } - delObjectFromSpaceWithObject(arena->spaceShot, shot, destroyShot); + if (tux->bonus == BONUS_TELEPORT) { + tuxTeleport(tux); + return; + } + + if (shot->gun == GUN_BOMBBALL) { + if (getNetTypeGame() != NET_GAME_TYPE_CLIENT) { + bombBallExplosion(shot); + } + + return; + } + + if (getNetTypeGame() != NET_GAME_TYPE_CLIENT) { + eventTuxIsDeadWIthShot(tux, shot); + } + } + + delObjectFromSpaceWithObject(arena->spaceShot, shot, destroyShot); } -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) { - actionSpaceFromLocation(spaceTux, action_tux, shot, shot->x, shot->y, shot->w, shot->h); + actionSpaceFromLocation(spaceTux, action_tux, shot, shot->x, shot->y, + shot->w, shot->h); } -void eventConflictTuxWithShot(arena_t *arena) +void +eventConflictTuxWithShot(arena_t * arena) { - actionSpace(arena->spaceShot, action_shot, arena->spaceTux); + actionSpace(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 zal_x, zal_y; - int new_x, new_y; - int w, h; - arena_t *arena; + int px = 0, py = 0; // no warninng + int zal_x, zal_y; + int new_x, new_y; + int w, h; + arena_t *arena; - assert( tux != NULL ); + assert(tux != NULL); - arena = getCurrentArena(); - //interval(); + arena = getCurrentArena(); + //interval(); - if( tux->position != n ) - { - tux->position = n; - return; - } + if (tux->position != n) { + tux->position = n; + return; + } - if( ( n == TUX_LEFT && tux->x-TUX_STEP <= 0 ) || - ( n == TUX_RIGHT && tux->x+TUX_STEP >= arena->w ) || - ( n == TUX_UP && tux->y-TUX_STEP <= 0 ) || - ( n == TUX_DOWN && tux->y+TUX_STEP >= arena->h ) ) - { - return; - } + if ((n == TUX_LEFT && tux->x - TUX_STEP <= 0) || + (n == TUX_RIGHT && tux->x + TUX_STEP >= arena->w) || + (n == TUX_UP && tux->y - TUX_STEP <= 0) || + (n == TUX_DOWN && tux->y + TUX_STEP >= arena->h)) { + return; + } - getTuxProportion(tux, &zal_x, &zal_y, &w, &h); + getTuxProportion(tux, &zal_x, &zal_y, &w, &h); - getCourse(tux->position, &px, &py); - - new_x = zal_x; - new_y = zal_y; + getCourse(tux->position, &px, &py); - new_x += px * TUX_STEP; - new_y += py * TUX_STEP; + new_x = zal_x; + new_y = zal_y; - if( tux->bonus == BONUS_SPEED ) - { - new_x += px * TUX_STEP; - new_y += py * TUX_STEP; - } + new_x += px * TUX_STEP; + new_y += py * TUX_STEP; - if( tux->bonus != BONUS_GHOST && ( - isConflictWithObjectFromSpaceBut(arena->spaceTux, new_x, new_y, w, h, tux) || - isConflictModule(new_x, new_y, w, h) ) ) - { - setTuxProportion(tux, zal_x, zal_y); - return; - } + if (tux->bonus == BONUS_SPEED) { + new_x += px * TUX_STEP; + new_y += py * TUX_STEP; + } + + if (tux->bonus != BONUS_GHOST + && + (isConflictWithObjectFromSpaceBut + (arena->spaceTux, new_x, new_y, w, h, tux) + || isConflictModule(new_x, new_y, w, h))) { + setTuxProportion(tux, zal_x, zal_y); + return; + } - setTuxProportion(tux, zal_x, zal_y); - moveObjectInSpace(arena->spaceTux, tux, new_x, new_y); - eventGiveTuxListItem(tux, getCurrentArena()->spaceItem); - tux->frame++; - if( tux->frame == TUX_KEY * TUX_MAX_ANIMATION_FRAME ) tux->frame = 0; + setTuxProportion(tux, zal_x, zal_y); + moveObjectInSpace(arena->spaceTux, tux, new_x, new_y); + eventGiveTuxListItem(tux, getCurrentArena()->spaceItem); + tux->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; + int i; - if( tux->control != TUX_CONTROL_NET && - tux->isCanSwitchGun == FALSE ) - { - return; - } + if (tux->control != TUX_CONTROL_NET && tux->isCanSwitchGun == FALSE) { + return; + } - for( i = tux->gun+1 ; i < GUN_COUNT ; i++ ) - { - if( tux->shot[i] > 0 ) - { - tux->gun = i; - tux->isCanSwitchGun = FALSE; - addTaskToTimer(getCurrentArena()->listTimer, TIMER_ONE, timer_tuxCanSwitchGun, - newInt(tux->id), TUX_TIME_CAN_SWITCH_GUN ); + for (i = tux->gun + 1; i < GUN_COUNT; i++) { + if (tux->shot[i] > 0) { + tux->gun = i; + tux->isCanSwitchGun = FALSE; + addTaskToTimer(getCurrentArena()->listTimer, TIMER_ONE, + timer_tuxCanSwitchGun, newInt(tux->id), + TUX_TIME_CAN_SWITCH_GUN); #ifndef NO_SOUND - playSound("switch_gun", SOUND_GROUP_BASE); + playSound("switch_gun", SOUND_GROUP_BASE); #endif - return; - } - } - - for( i = 0 ; i < GUN_COUNT ; i++ ) - { - if( tux->shot[i] > 0 ) - { - tux->gun = i; - tux->isCanSwitchGun = FALSE; - addTaskToTimer(getCurrentArena()->listTimer, TIMER_ONE, timer_tuxCanSwitchGun, - newInt(tux->id), TUX_TIME_CAN_SWITCH_GUN ); + return; + } + } + + for (i = 0; i < GUN_COUNT; i++) { + if (tux->shot[i] > 0) { + tux->gun = i; + tux->isCanSwitchGun = FALSE; + addTaskToTimer(getCurrentArena()->listTimer, TIMER_ONE, + timer_tuxCanSwitchGun, newInt(tux->id), + TUX_TIME_CAN_SWITCH_GUN); #ifndef NO_SOUND - playSound("switch_gun", SOUND_GROUP_BASE); + playSound("switch_gun", SOUND_GROUP_BASE); #endif - return; - } - } + return; + } + } } -void shotTux(tux_t *tux) +void +shotTux(tux_t * tux) { - assert( tux != NULL ); + assert(tux != NULL); - if( tux->isCanShot == FALSE || - tux->shot[tux->gun] == 0 ) - { - return; - } + if (tux->isCanShot == FALSE || tux->shot[tux->gun] == 0) { + return; + } #ifndef NO_SOUND - playSound("switch_gun", SOUND_GROUP_BASE); + playSound("switch_gun", SOUND_GROUP_BASE); #endif - shotInGun(tux); + shotInGun(tux); - tux->isCanShot = FALSE; + tux->isCanShot = FALSE; - addTaskToTimer(getCurrentArena()->listTimer, TIMER_ONE, timer_tuxCanShot, - newInt(tux->id), TUX_TIME_CAN_SHOT ); + addTaskToTimer(getCurrentArena()->listTimer, TIMER_ONE, timer_tuxCanShot, + newInt(tux->id), TUX_TIME_CAN_SHOT); - if( tux->shot[tux->gun] == 0 ) - { - switchTuxGun(tux); - } + if (tux->shot[tux->gun] == 0) { + switchTuxGun(tux); + } } -void actionTux(tux_t *tux, int action) +void +actionTux(tux_t * tux, int action) { - if( tux->status == TUX_STATUS_DEAD ) - { - return; - } - - switch( action ) - { - case TUX_UP : - case TUX_LEFT : - case TUX_RIGHT : - case TUX_DOWN : - moveTux(tux, action); - break; - - case TUX_SHOT : - shotTux(tux); - break; - - case TUX_SWITCH_GUN : - switchTuxGun(tux); - break; - } + if (tux->status == TUX_STATUS_DEAD) { + return; + } + + switch (action) { + case TUX_UP: + case TUX_LEFT: + case TUX_RIGHT: + case TUX_DOWN: + moveTux(tux, action); + break; + + case TUX_SHOT: + shotTux(tux); + break; + + case TUX_SWITCH_GUN: + switchTuxGun(tux); + break; + } } -static void pickUpGun(tux_t *tux) +static void +pickUpGun(tux_t * tux) { - if( isTuxAnyGun(tux) == FALSE ) - { - tux->gun = GUN_SIMPLE; - - if( tux->pickup_time < TUX_MAX_PICKUP ) - { - tux->pickup_time++; - } - - if( tux->pickup_time == TUX_MAX_PICKUP && getNetTypeGame() != NET_GAME_TYPE_CLIENT ) - { + if (isTuxAnyGun(tux) == FALSE) { + tux->gun = GUN_SIMPLE; + + if (tux->pickup_time < TUX_MAX_PICKUP) { + tux->pickup_time++; + } + + if (tux->pickup_time == TUX_MAX_PICKUP + && getNetTypeGame() != NET_GAME_TYPE_CLIENT) { #ifndef NO_SOUND - playSound("switch_gun", SOUND_GROUP_BASE); + playSound("switch_gun", SOUND_GROUP_BASE); #endif - tux->gun = GUN_SIMPLE; - tux->shot[ tux->gun ] = GUN_MAX_SHOT; - tux->pickup_time = 0; + tux->gun = GUN_SIMPLE; + tux->shot[tux->gun] = GUN_MAX_SHOT; + tux->pickup_time = 0; - if( getNetTypeGame() == NET_GAME_TYPE_SERVER ) - { - proto_send_newtux_server(PROTO_SEND_ALL, NULL, tux); - } - } - } + if (getNetTypeGame() == NET_GAME_TYPE_SERVER) { + proto_send_newtux_server(PROTO_SEND_ALL, NULL, tux); + } + } + } } -static void eventBonus(tux_t *tux) +static void +eventBonus(tux_t * tux) { - if( tux->bonus != BONUS_NONE ) - { - if( tux->bonus_time > 0 ) - { - tux->bonus_time--; - } - - if( tux->bonus_time == 0 && getNetTypeGame() != NET_GAME_TYPE_CLIENT ) - { - if( tux->bonus == BONUS_GHOST ) - { - int x, y, w, h; - getTuxProportion(tux, &x, &y, &w, &h); - - tux->bonus = BONUS_NONE; - - if( /*isConflictTuxWithListTux(tux, getCurrentArena()->listTux) || */ - isConflictModule(x, y, w, h) ) - { - tux->bonus = BONUS_GHOST; - return; - } - } - - tux->bonus = BONUS_NONE; - - if( getNetTypeGame() == NET_GAME_TYPE_SERVER ) - { - proto_send_newtux_server(PROTO_SEND_ALL, NULL, tux); - } - } - } + if (tux->bonus != BONUS_NONE) { + if (tux->bonus_time > 0) { + tux->bonus_time--; + } + + if (tux->bonus_time == 0 && getNetTypeGame() != NET_GAME_TYPE_CLIENT) { + if (tux->bonus == BONUS_GHOST) { + int x, y, w, h; + getTuxProportion(tux, &x, &y, &w, &h); + + tux->bonus = BONUS_NONE; + + if ( /*isConflictTuxWithListTux(tux, getCurrentArena()->listTux) || */ + isConflictModule(x, y, w, h)) { + tux->bonus = BONUS_GHOST; + return; + } + } + + tux->bonus = BONUS_NONE; + + if (getNetTypeGame() == NET_GAME_TYPE_SERVER) { + proto_send_newtux_server(PROTO_SEND_ALL, NULL, tux); + } + } + } } -void eventTux(tux_t *tux) +void +eventTux(tux_t * tux) { - arena_t *arena; + arena_t *arena; - arena = getCurrentArena(); + arena = getCurrentArena(); #ifndef PUBLIC_SERVER - tuxControl(tux); + tuxControl(tux); #endif - pickUpGun(tux); - eventBonus(tux); - eventGiveTuxListItem(tux, arena->spaceItem); + pickUpGun(tux); + eventBonus(tux); + eventGiveTuxListItem(tux, arena->spaceItem); } + /* void eventListTux(list_t *listTux) { @@ -714,65 +709,75 @@ void eventListTux(list_t *listTux) } } */ -void getTuxProportion(tux_t *tux, int *x,int *y, int *w, int *h) +void +getTuxProportion(tux_t * tux, int *x, int *y, int *w, int *h) { - assert( tux != NULL ); + assert(tux != NULL); - if( x != NULL ) *x = tux->x - TUX_WIDTH / 2; - if( y != NULL ) *y = tux->y - TUX_HEIGHT / 2; - if( w != NULL ) *w = TUX_WIDTH; - if( h != NULL ) *h = TUX_HEIGHT; + if (x != NULL) + *x = tux->x - TUX_WIDTH / 2; + if (y != NULL) + *y = tux->y - TUX_HEIGHT / 2; + if (w != NULL) + *w = TUX_WIDTH; + if (h != NULL) + *h = TUX_HEIGHT; } -void setTuxProportion(tux_t *tux, int x, int y) +void +setTuxProportion(tux_t * tux, int x, int y) { - assert( tux != NULL ); + assert(tux != NULL); - tux->x = x + TUX_WIDTH / 2; - tux->y = y + TUX_WIDTH / 2; + tux->x = x + TUX_WIDTH / 2; + tux->y = y + TUX_WIDTH / 2; } -void getStatusTux(void *p, int *id, int *x,int *y, int *w, int *h) +void +getStatusTux(void *p, int *id, int *x, int *y, int *w, int *h) { - tux_t *tux; + tux_t *tux; - tux = p; - *id = tux->id; - getTuxProportion(tux, x, y, w, h); + tux = p; + *id = tux->id; + getTuxProportion(tux, x, y, w, h); } -void setStatusTux(void *p, int x, int y, int w, int h) +void +setStatusTux(void *p, int x, int y, int w, int h) { - tux_t *tux; + tux_t *tux; - tux = p; - setTuxProportion(tux, x, y); + tux = p; + setTuxProportion(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) { - if( item->type == ITEM_MINE && item->author_id == tux->id ) - { - item->author_id = ID_UNKNOWN; - } + if (item->type == ITEM_MINE && item->author_id == tux->id) { + item->author_id = ID_UNKNOWN; + } } -void destroyTux(tux_t *tux) +void +destroyTux(tux_t * tux) { - arena_t *arena; + arena_t *arena; + + arena = getCurrentArena(); - arena = getCurrentArena(); + assert(tux != NULL); - assert( tux != NULL ); + delID(tux->id); - delID(tux->id); + actionSpace(arena->spaceItem, action_checkMine, tux); - actionSpace(arena->spaceItem, action_checkMine, tux); - - free(tux); + free(tux); } -void quitTux() +void +quitTux() { - isTuxInit = FALSE; + isTuxInit = FALSE; } diff --git a/src/base/udp_server.c b/src/base/udp_server.c index afe0cba..16fe722 100644 --- a/src/base/udp_server.c +++ b/src/base/udp_server.c @@ -46,236 +46,232 @@ static sock_udp_t *sock_server_udp; static sock_udp_t *sock_server_udp_second; -client_t* newUdpClient(sock_udp_t *sock_udp) +client_t * +newUdpClient(sock_udp_t * sock_udp) { - client_t *new; + client_t *new; - assert( sock_udp != NULL ); + assert(sock_udp != NULL); - new = newAnyClient(); - new->type = CLIENT_TYPE_UDP; - new->socket_udp = sock_udp; + new = newAnyClient(); + new->type = CLIENT_TYPE_UDP; + new->socket_udp = sock_udp; #ifdef PUBLIC_SERVER - char str_log[STR_LOG_SIZE]; - char str_ip[STR_IP_SIZE]; + char str_log[STR_LOG_SIZE]; + char str_ip[STR_IP_SIZE]; - getSockUdpIp(sock_udp, str_ip, STR_IP_SIZE); - sprintf(str_log, _("New client \"%s\" on port \"%d\" connected"), str_ip, getSockUdpPort(sock_udp)); - addToLog(LOG_INF, str_log); + getSockUdpIp(sock_udp, str_ip, STR_IP_SIZE); + sprintf(str_log, _("New client \"%s\" on port \"%d\" connected"), str_ip, + getSockUdpPort(sock_udp)); + addToLog(LOG_INF, str_log); #endif - return new; + return new; } -void destroyUdpClient(client_t *p) +void +destroyUdpClient(client_t * p) { - eventMsgInCheckFront(p); + eventMsgInCheckFront(p); #ifdef PUBLIC_SERVER - char str_log[STR_LOG_SIZE]; - char str_ip[STR_IP_SIZE]; + char str_log[STR_LOG_SIZE]; + char str_ip[STR_IP_SIZE]; - getSockUdpIp(p->socket_udp, str_ip, STR_IP_SIZE); - sprintf(str_log, _("Client \"%s\" on port \"%d\" disconnected"), str_ip, getSockUdpPort(p->socket_udp)); - addToLog(LOG_INF, str_log); + getSockUdpIp(p->socket_udp, str_ip, STR_IP_SIZE); + sprintf(str_log, _("Client \"%s\" on port \"%d\" disconnected"), str_ip, + getSockUdpPort(p->socket_udp)); + addToLog(LOG_INF, str_log); #endif - destroySockUdp(p->socket_udp); + destroySockUdp(p->socket_udp); - destroyAnyClient(p); + destroyAnyClient(p); } -int initUdpServer(char *ip4, int port4, char *ip6, int port6) +int +initUdpServer(char *ip4, int port4, char *ip6, int port6) { - int ret; + int ret; - ret = 0; + ret = 0; - if( ip4 != NULL ) - { - sock_server_udp = bindUdpSocket(ip4, port4, PROTO_UDPv4); + if (ip4 != NULL) { + sock_server_udp = bindUdpSocket(ip4, port4, PROTO_UDPv4); - if( sock_server_udp != NULL ) - { - ret++; + if (sock_server_udp != NULL) { + ret++; #ifdef DEBUG - printf(_("Starting server: \"%s\" on port: \"%d\"\n"), ip4, port4); + printf(_("Starting server: \"%s\" on port: \"%d\"\n"), ip4, + port4); #endif - } - else - { + } + else { #ifdef DEBUG - printf(_("Starting server: \"%s\" on port: \"%d\" FAILED!\n"), ip4, port4); + printf(_("Starting server: \"%s\" on port: \"%d\" FAILED!\n"), + ip4, port4); #endif - } - } + } + } - if( ip6 != NULL ) - { - sock_server_udp_second = bindUdpSocket(ip6, port6, PROTO_UDPv6); + if (ip6 != NULL) { + sock_server_udp_second = bindUdpSocket(ip6, port6, PROTO_UDPv6); - if( sock_server_udp_second != NULL ) - { - ret++; + if (sock_server_udp_second != NULL) { + ret++; #ifdef DEBUG - printf(_("Starting server: \"%s\" on port: \"%d\"\n"), ip6, port6); + printf(_("Starting server: \"%s\" on port: \"%d\"\n"), ip6, + port6); #endif - } - else - { + } + else { #ifdef DEBUG - printf(_("Starting server: \"%s\" on port: \"%d\" FAILED!\n"), ip6, port6); + printf(_("Starting server: \"%s\" on port: \"%d\" FAILED!\n"), + ip6, port6); #endif - } - } + } + } - return ret; + return ret; } -static void eventCreateNewUdpClient(sock_udp_t *socket_udp) +static void +eventCreateNewUdpClient(sock_udp_t * socket_udp) { - list_t *listClient; - client_t *client; + list_t *listClient; + client_t *client; - assert( socket_udp != NULL ); + assert(socket_udp != NULL); - listClient = getListServerClient(); + listClient = getListServerClient(); - client = newUdpClient(socket_udp); - addList(listClient, client); + client = newUdpClient(socket_udp); + addList(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; - int i; + list_t *listClient; + int port; + int i; - port = getSockUdpPort(sock_udp); - listClient = getListServerClient(); + port = getSockUdpPort(sock_udp); + listClient = getListServerClient(); - for( i = 0 ; i < listClient->count ; i++ ) - { - client_t *client; + for (i = 0; i < listClient->count; i++) { + client_t *client; - client = (client_t *)listClient->list[i]; + client = (client_t *) listClient->list[i]; - if( client->type == CLIENT_TYPE_UDP && - getSockUdpPort(client->socket_udp) == port ) - { - return client; - } - } + if (client->type == CLIENT_TYPE_UDP && + getSockUdpPort(client->socket_udp) == port) { + return client; + } + } - return NULL; + return NULL; } -static void eventClientUdpSelect(sock_udp_t *sock_server) +static void +eventClientUdpSelect(sock_udp_t * sock_server) { - sock_udp_t *sock_client; - client_t *client; - char listRecvMsg[STR_SIZE]; - bool_t isCreateNewClient; - int ret; - - assert( sock_server != NULL ); - - sock_client = newSockUdp(sock_server->proto); - isCreateNewClient = FALSE; - - memset(listRecvMsg, 0, STR_SIZE); - - ret = readUdpSocket(sock_server, sock_client, listRecvMsg, STR_SIZE-1); - - client = findUdpClient(sock_client); - - if( client == NULL ) - { - eventCreateNewUdpClient(sock_client); - client = findUdpClient(sock_client); - isCreateNewClient = TRUE; - } - - if( client == NULL ) - { - fprintf(stderr, _("Client was not FOUND!\n")); - return; - } - - if( isCreateNewClient == FALSE ) - { - destroySockUdp(sock_client); - } - - if( ret <= 0 ) - { - client->status = NET_STATUS_ZOMBIE; - return; - } - - //printf("add packet >>%s<<\n", listRecvMsg); - addList(client->listRecvMsg, strdup(listRecvMsg) ); + sock_udp_t *sock_client; + client_t *client; + char listRecvMsg[STR_SIZE]; + bool_t isCreateNewClient; + int ret; + + assert(sock_server != NULL); + + sock_client = newSockUdp(sock_server->proto); + isCreateNewClient = FALSE; + + memset(listRecvMsg, 0, STR_SIZE); + + ret = readUdpSocket(sock_server, sock_client, listRecvMsg, STR_SIZE - 1); + + client = findUdpClient(sock_client); + + if (client == NULL) { + eventCreateNewUdpClient(sock_client); + client = findUdpClient(sock_client); + isCreateNewClient = TRUE; + } + + if (client == NULL) { + fprintf(stderr, _("Client was not FOUND!\n")); + return; + } + + if (isCreateNewClient == FALSE) { + destroySockUdp(sock_client); + } + + if (ret <= 0) { + client->status = NET_STATUS_ZOMBIE; + return; + } + + //printf("add packet >>%s<<\n", listRecvMsg); + addList(client->listRecvMsg, strdup(listRecvMsg)); } -void setServerUdpSelect() +void +setServerUdpSelect() { - if( sock_server_udp != NULL ) - { - addSockToSelectRead(sock_server_udp->sock); - } - - if( sock_server_udp_second != NULL ) - { - addSockToSelectRead(sock_server_udp_second->sock); - } + if (sock_server_udp != NULL) { + addSockToSelectRead(sock_server_udp->sock); + } + + if (sock_server_udp_second != NULL) { + addSockToSelectRead(sock_server_udp_second->sock); + } } -int selectServerUdpSocket() +int +selectServerUdpSocket() { - int count; - - count = 0; - - if( sock_server_udp != NULL ) - { - if( isChangeSockInSelectRead(sock_server_udp->sock) ) - { - eventClientUdpSelect(sock_server_udp); - count++; - } - } - - if( sock_server_udp_second != NULL ) - { - if( isChangeSockInSelectRead(sock_server_udp_second->sock) ) - { - eventClientUdpSelect(sock_server_udp_second); - count++; - } - } - - return count; + int count; + + count = 0; + + if (sock_server_udp != NULL) { + if (isChangeSockInSelectRead(sock_server_udp->sock)) { + eventClientUdpSelect(sock_server_udp); + count++; + } + } + + if (sock_server_udp_second != NULL) { + if (isChangeSockInSelectRead(sock_server_udp_second->sock)) { + eventClientUdpSelect(sock_server_udp_second); + count++; + } + } + + return count; } -void quitUdpServer() +void +quitUdpServer() { - if( sock_server_udp != NULL ) - { + if (sock_server_udp != NULL) { #ifdef DEBUG - printf(_("Closing port: \"%d\"\n"), getSockUdpPort(sock_server_udp)); + printf(_("Closing port: \"%d\"\n"), getSockUdpPort(sock_server_udp)); #endif - closeUdpSocket(sock_server_udp); - } + closeUdpSocket(sock_server_udp); + } - if( sock_server_udp_second != NULL ) - { + if (sock_server_udp_second != NULL) { #ifdef DEBUG - printf(_("Closing port: \"%d\"\n"), getSockUdpPort(sock_server_udp_second)); + printf(_("Closing port: \"%d\"\n"), + getSockUdpPort(sock_server_udp_second)); #endif - closeUdpSocket(sock_server_udp_second); - } + closeUdpSocket(sock_server_udp_second); + } #ifdef DEBUG - printf(_("Quitting UDP\n")); + printf(_("Quitting UDP\n")); #endif } |