summaryrefslogtreecommitdiff
path: root/src/base
diff options
context:
space:
mode:
authorConnor Thomson <blumatrikz@gmail.com>2026-09-08 18:27:39 -0700
committerConnor Thomson <blumatrikz@gmail.com>2026-09-08 18:27:39 -0700
commitf1ddc12b68b4e4c8087962de25260470e6df2bea (patch)
tree7d0440a6402a9b0ef75ded23fa64b68534255bba /src/base
parent6025860a61386bf767b29c3ec5fd0d31285f1056 (diff)
Add tuxanci2 files
Diffstat (limited to 'src/base')
-rw-r--r--src/base/CMakeLists.txt7
-rw-r--r--src/base/archive.c143
-rw-r--r--src/base/archive.h7
-rw-r--r--src/base/arena.c392
-rw-r--r--src/base/arena.h55
-rw-r--r--src/base/arenaFile.c413
-rw-r--r--src/base/arenaFile.h34
-rw-r--r--src/base/bool.h10
-rw-r--r--src/base/buffer.c142
-rw-r--r--src/base/buffer.h22
-rw-r--r--src/base/checkFront.c117
-rw-r--r--src/base/checkFront.h20
-rw-r--r--src/base/director.c69
-rw-r--r--src/base/director.h15
-rw-r--r--src/base/downServer.c288
-rw-r--r--src/base/downServer.h13
-rw-r--r--src/base/gun.c316
-rw-r--r--src/base/gun.h16
-rw-r--r--src/base/homeDirector.c44
-rw-r--r--src/base/homeDirector.h11
-rw-r--r--src/base/idManager.c198
-rw-r--r--src/base/idManager.h22
-rw-r--r--src/base/index.c267
-rw-r--r--src/base/index.h21
-rw-r--r--src/base/item.c551
-rw-r--r--src/base/item.h75
-rw-r--r--src/base/list.c184
-rw-r--r--src/base/list.h27
-rw-r--r--src/base/main.c186
-rw-r--r--src/base/main.h41
-rw-r--r--src/base/modules.c317
-rw-r--r--src/base/modules.h110
-rw-r--r--src/base/msg.h18
-rw-r--r--src/base/myTimer.c157
-rw-r--r--src/base/myTimer.h29
-rw-r--r--src/base/net_multiplayer.c138
-rw-r--r--src/base/net_multiplayer.h37
-rw-r--r--src/base/path.h.in26
-rw-r--r--src/base/protect.c86
-rw-r--r--src/base/protect.h25
-rw-r--r--src/base/proto.c937
-rw-r--r--src/base/proto.h98
-rw-r--r--src/base/server.c383
-rw-r--r--src/base/server.h60
-rw-r--r--src/base/serverSelect.c105
-rw-r--r--src/base/serverSelect.h12
-rw-r--r--src/base/serverSendMsg.c145
-rw-r--r--src/base/serverSendMsg.h13
-rw-r--r--src/base/shareFunction.c65
-rw-r--r--src/base/shareFunction.h9
-rw-r--r--src/base/shot.c347
-rw-r--r--src/base/shot.h53
-rw-r--r--src/base/space.c375
-rw-r--r--src/base/space.h47
-rw-r--r--src/base/storage.c136
-rw-r--r--src/base/storage.h14
-rw-r--r--src/base/string_length.h15
-rw-r--r--src/base/textFile.c151
-rw-r--r--src/base/textFile.h21
-rw-r--r--src/base/tux.c766
-rw-r--r--src/base/tux.h135
-rw-r--r--src/base/udp_server.c244
-rw-r--r--src/base/udp_server.h14
63 files changed, 0 insertions, 8794 deletions
diff --git a/src/base/CMakeLists.txt b/src/base/CMakeLists.txt
deleted file mode 100644
index 2e93cef..0000000
--- a/src/base/CMakeLists.txt
+++ /dev/null
@@ -1,7 +0,0 @@
-###############################################################################
-# tuxanci/src/*/CMakeLists.txt
-###############################################################################
-# Generate source_code files from .c files we find in directory
-###############################################################################
-MacroAddSources()
-###############################################################################
diff --git a/src/base/archive.c b/src/base/archive.c
deleted file mode 100644
index 2c188c3..0000000
--- a/src/base/archive.c
+++ /dev/null
@@ -1,143 +0,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-
-#ifdef SUPPORT_LIBPHYSFS
-#include <physfs.h>
-#endif /* SUPPORT_LIBPHYSFS */
-
-#ifdef SUPPORT_LIBZIP
-#include <zip.h>
-#endif /* SUPPORT_LIBZIP */
-
-#include "main.h"
-#include "archive.h"
-
-#define ARCHIVE_BUFFER_SIZE 4096
-#define STR_TMP_FILE_NAME 4096
-
-#ifdef SUPPORT_LIBZIP
-char *archive_extract_file(char *archive, char *filename)
-{
- char name[STR_TMP_FILE_NAME];
- char buf[ARCHIVE_BUFFER_SIZE];
-
- struct zip *zipArchive;
- struct zip_file *zipFile;
-
- FILE *file;
- int len;
- int err;
- char *tmp;
-
-#ifndef __WIN32__
- tmp = getenv("TMPDIR") == NULL ? "/tmp" : getenv("TMPDIR");
-#else /* __WIN32__ */
- tmp = getenv("TEMP");
-#endif /* __WIN32__ */
- sprintf(name, "%s%stuxanci.%d-%s", tmp, PATH_SEPARATOR, getpid(), filename);
-
- /*printf("ARCHIVE %s %s %s\n", archive, filename, name);*/
-
- zipArchive = zip_open(archive, 0, &err);
-
- if (zipArchive == NULL) {
- error("Unable to open archive [%s]", archive);
- return NULL;
- }
-
- zipFile = zip_fopen(zipArchive, filename, ZIP_FL_UNCHANGED);
-
- if (zipFile == NULL) {
- error("Unable to extract the file [%s] from archive [%s]", filename, archive);
- zip_close(zipArchive);
- return NULL;
- }
-
- if ((file = fopen(name, "wb")) == NULL) {
- error("Unable to create temporary file [%s]", name);
- zip_fclose(zipFile);
- zip_close(zipArchive);
- return NULL;
- }
-
- do {
- len = zip_fread(zipFile, buf, ARCHIVE_BUFFER_SIZE);
-
- if (len > 0) {
- fwrite(buf, len, 1, file);
- }
- } while (len > 0);
-
- fclose(file);
- zip_fclose(zipFile);
- zip_close(zipArchive);
-
- return strdup(name);
-}
-#endif /* SUPPORT_LIBZIP */
-
-#ifdef SUPPORT_LIBPHYSFS
-char *archive_extract_file(char *archive, char *filename)
-{
- char name[STR_TMP_FILE_NAME];
- char buffer[ARCHIVE_BUFFER_SIZE];
-
- PHYSFS_file *file_archive;
- FILE *file;
- int count;
-
- char *tmp;
-
-#ifndef __WIN32__
- tmp = getenv("TMPDIR") == NULL ? "/tmp" : getenv("TMPDIR");
-#else /* __WIN32__ */
- tmp = getenv("TEMP");
-#endif /* __WIN32__ */
- sprintf(name, "%s%stuxanci.%d-%s", tmp, PATH_SEPARATOR, getpid(), filename);
-
- if (!(PHYSFS_init(get_program_name()))) {
- error("Unable to init physfs");
- return NULL;
- }
-
- if (!(PHYSFS_addToSearchPath(archive, 1))) {
- error("Unable to open archive [%s]", archive);
- PHYSFS_deinit();
- return NULL;
- }
-
- file_archive = PHYSFS_openRead(filename);
-
- if (file_archive == NULL) {
- error("Unable to extract the file [%s] from archive [%s]", filename, archive);
- PHYSFS_deinit();
- return NULL;
- }
-
- if ((file = fopen(name, "wb")) == NULL) {
- error("Unable to create temporary file [%s]", name);
- PHYSFS_close(file_archive);
- PHYSFS_deinit();
- return NULL;
- }
-
- while ((count = PHYSFS_read(file_archive, buffer, 1, ARCHIVE_BUFFER_SIZE)) > 0) {
- fwrite(buffer, count, 1, file);
- }
-
- PHYSFS_close(file_archive);
- fclose(file);
-
- PHYSFS_deinit();
-
- return strdup(name);
-}
-#endif /* SUPPORT_LIBPHYSFS */
-
-void archive_delete_file(char *s)
-{
- unlink(s);
- free(s);
-}
diff --git a/src/base/archive.h b/src/base/archive.h
deleted file mode 100644
index e2ad361..0000000
--- a/src/base/archive.h
+++ /dev/null
@@ -1,7 +0,0 @@
-#ifndef ARCHIVE_H
-#define ARCHIVE_H
-
-extern char *archive_extract_file(char *archive, char *file);
-extern void archive_delete_file(char *s);
-
-#endif /* ARCHIVE_H */
diff --git a/src/base/arena.c b/src/base/arena.c
deleted file mode 100644
index 6d883b3..0000000
--- a/src/base/arena.c
+++ /dev/null
@@ -1,392 +0,0 @@
-#include <stdlib.h>
-#include <assert.h>
-#include <string.h>
-
-#include "main.h"
-#include "arena.h"
-#include "list.h"
-#include "tux.h"
-#include "shot.h"
-#include "item.h"
-#include "myTimer.h"
-#include "modules.h"
-
-#ifndef PUBLIC_SERVER
-#include "hotKey.h"
-#include "world.h"
-#include "setting.h"
-#include "layer.h"
-#endif /* PUBLIC_SERVER */
-
-static arena_t *currentArena;
-static int splitType;
-
-#ifndef PUBLIC_SERVER
-static int isBigArena(arena_t *arena)
-{
- 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)
-{
- if (abs(tux1->x - tux2->x) < WINDOW_SIZE_X &&
- abs(tux1->y - tux2->y) < WINDOW_SIZE_Y) {
- return 1;
- }
-
- return 0;
-}
-#endif /* PUBLIC_SERVER */
-
-void arena_set_current(arena_t *p)
-{
- currentArena = p;
-}
-
-arena_t *arena_get_current()
-{
- return currentArena;
-}
-
-void hotkey_splitArena()
-{
- if (splitType == SCREEN_SPLIT_VERTICAL) {
- splitType = SCREEN_SPLIT_HORIZONTAL;
- } else {
- splitType = SCREEN_SPLIT_VERTICAL;
- }
-}
-
-#ifndef PUBLIC_SERVER
-void arena_init()
-{
- splitType = SCREEN_SPLIT_VERTICAL;
-
- if (getParam("--split-vertical")) {
- splitType = SCREEN_SPLIT_VERTICAL;
- debug("Set vertical screen splitting");
- }
-
- if (getParam("--split-horizontal")) {
- splitType = SCREEN_SPLIT_HORIZONTAL;
- debug("Set horizontal screen splitting");
- }
-
- hot_key_register(SDLK_F3, hotkey_splitArena);
-}
-
-void arena_quit()
-{
- hot_key_unregister(SDLK_F3);
-}
-#endif /* PUBLIC_SERVER */
-
-arena_t *arena_new(int w, int h)
-{
- arena_t *new;
- int zone_w, zone_h;
-
- new = malloc(sizeof(arena_t));
-
-#ifndef PUBLIC_SERVER
- new->background = NULL;
- strcpy(new->music, "");
-#endif /* PUBLIC_SERVER */
-
- new->w = w;
- new->h = h;
-
- new->listTimer = list_new();
-
- if (w > 800 || h > 600) {
- zone_w = 320;
- zone_h = 240;
- } else {
- zone_w = 80;
- zone_h = 60;
- }
-
- new->spaceTux = space_new(w, h, zone_w, zone_h, tux_get_status, tux_set_status);
- new->spaceItem = space_new(w, h, zone_w, zone_h, item_get_status, item_set_status);
- new->spaceShot = space_new(w, h, zone_w, zone_h, shot_get_status, shot_set_status);
-
- new->countRound = 0;
- new->max_countRound = 0;
-
- return new;
-}
-
-int arena_conflict_space(int x1, int y1, int w1, int h1, int x2, int y2, int w2, int h2)
-{
- return (x1 < x2 + w2 && x2 < x1 + w1 && y1 < y2 + h2 && y2 < y1 + h1);
-}
-
-int arena_is_free_space(arena_t *arena, int x, int y, int w, int h)
-{
- if ((x < 0 || y < 0 || x + w > arena->w || y + h > arena->h) ||
- space_is_conflict_with_object(arena->spaceTux, x, y, w, h) ||
- space_is_conflict_with_object(arena->spaceShot, x, y, w, h) ||
- space_is_conflict_with_object(arena->spaceItem, x, y, w, h) ||
- space_is_conflict_with_object(arena->spaceShot, x, y, w, h) ||
- module_is_conflict(x, y, w, h)) {
- return 0;
- }
-
- return 1;
-}
-
-void arena_find_free_space(arena_t *arena, int *x, int *y, int w, int h)
-{
- int z_x;
- int z_y;
-
- assert(x != NULL);
- assert(y != NULL);
-
- do {
- z_x = random() % (arena->w - w);
- z_y = random() % (arena->h - h);
- } while (arena_is_free_space(arena, z_x, z_y, w, h) == 0);
-
- *x = z_x;
- *y = z_y;
-}
-
-void arena_get_center_screen(int *screen_x, int *screen_y, int x, int y, int screen_size_x, int screen_size_y)
-{
- arena_t *arena;
-
- arena = arena_get_current();
-
- *screen_x = x - screen_size_x / 2;
- *screen_y = y - screen_size_y / 2;
-
- if (*screen_x < 0) {
- *screen_x = 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_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)
-{
- 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_tux_draw(space_t *space, tux_t *tux, void *p)
-{
- tux_draw(tux);
-}
-
-static void action_item_draw(space_t *space, item_t *item, void *p)
-{
- item_draw(item);
-}
-
-static void action_shot_draw(space_t *space, shot_t *shot, void *p)
-{
- shot_draw(shot);
-}
-
-static void drawObjects(arena_t *arena, int screen_x, int screen_y)
-{
- space_action_from_location(arena->spaceTux, action_tux_draw, NULL, screen_x, screen_y, WINDOW_SIZE_X, WINDOW_SIZE_Y);
- space_action_from_location(arena->spaceItem, action_item_draw, NULL, screen_x, screen_y, WINDOW_SIZE_X, WINDOW_SIZE_Y);
- space_action_from_location(arena->spaceShot, action_shot_draw, NULL, screen_x, screen_y, WINDOW_SIZE_X, WINDOW_SIZE_Y);
-
- module_draw(screen_x, screen_y, WINDOW_SIZE_X, WINDOW_SIZE_Y);
-}
-
-static void drawSplitArenaForTux(arena_t *arena, tux_t *tux, int location_x, int location_y)
-{
- int screen_x, screen_y;
-
- switch (splitType) {
- case SCREEN_SPLIT_HORIZONTAL:
- arena_get_center_screen(&screen_x, &screen_y, tux->x, tux->y, WINDOW_SIZE_X, WINDOW_SIZE_Y / 2);
- break;
- case SCREEN_SPLIT_VERTICAL:
- arena_get_center_screen(&screen_x, &screen_y, tux->x, tux->y, WINDOW_SIZE_X / 2, WINDOW_SIZE_Y);
- break;
- default:
- screen_x = -1;
- screen_y = -1;
- fatal("Unknown method of splitting the screen");
- break;
- }
-
- drawBackground(arena, screen_x, screen_y);
- drawObjects(arena, screen_x, screen_y);
-
- switch (splitType) {
- case SCREEN_SPLIT_HORIZONTAL:
- layer_draw_slpit(location_x, location_y, screen_x, screen_y, WINDOW_SIZE_X, WINDOW_SIZE_Y / 2);
- break;
- case SCREEN_SPLIT_VERTICAL:
- layer_draw_slpit(location_x, location_y, screen_x, screen_y, WINDOW_SIZE_X / 2, WINDOW_SIZE_Y);
- break;
- default:
- screen_x = -1;
- screen_y = -1;
- fatal("Unknown method of splitting the screen");
- break;
- }
-}
-
-void drawSplitArena(arena_t *arena)
-{
- tux_t *tux = NULL;
-
- tux = world_get_control_tux(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 = world_get_control_tux(TUX_CONTROL_KEYBOARD_LEFT);
-
- if (tux != NULL) {
- drawSplitArenaForTux(arena, tux, 0, 0);
- }
-}
-
-void drawCenterArena(arena_t *arena, int x, int y)
-{
- int screen_x, screen_y;
-
- arena_get_center_screen(&screen_x, &screen_y, x, y, WINDOW_SIZE_X, WINDOW_SIZE_Y);
- drawBackground(arena, screen_x, screen_y);
- drawObjects(arena, screen_x, screen_y);
- layer_draw_center(x, y);
-}
-
-void drawSimpleArena(arena_t *arena)
-{
- int screen_x, screen_y;
- tux_t *tux = NULL;
-
- tux = world_get_control_tux(TUX_CONTROL_KEYBOARD_RIGHT);
-
- if (tux == NULL) {
- return;
- }
-
- screen_x = 0;
- screen_y = 0;
-
- drawBackground(arena, screen_x, screen_y);
- drawObjects(arena, screen_x, screen_y);
- layer_draw_all(tux->x, tux->y);
-}
-
-void arena_draw(arena_t *arena)
-{
- if (isBigArena(arena) &&
- net_multiplayer_get_game_type() == NET_GAME_TYPE_NONE && !setting_is_ai()) {
- tux_t *tux1;
- tux_t *tux2;
-
- tux1 = world_get_control_tux(TUX_CONTROL_KEYBOARD_RIGHT);
- tux2 = world_get_control_tux(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 = world_get_control_tux(TUX_CONTROL_KEYBOARD_RIGHT);
-
- if (tux == NULL) {
- return;
- }
-
- drawCenterArena(arena, tux->x, tux->y);
- return;
- }
-
- drawSimpleArena(arena);
-}
-
-#endif /* PUBLIC_SERVER */
-
-static void action_tux(space_t *space, tux_t *tux, void *p)
-{
- tux_event(tux);
-}
-
-void arena_event(arena_t *arena)
-{
- int i;
-
- for (i = 0; i < 8; i++) {
- shot_check_is_tux_screen(arena);
-
- item_event_conglicts_shot_with_item(arena);
- tux_conflict_woth_shot(arena);
- module_event();
-
- shot_event_move_list(arena);
- }
-
- item_event(arena->spaceItem);
-
- space_action(arena->spaceTux, action_tux, NULL);
-
- timer_event(arena->listTimer);
-}
-
-void arena_destroy(arena_t *p)
-{
- space_destroy_with_item(p->spaceTux, tux_destroy);
- space_destroy_with_item(p->spaceItem, item_destroy);
- space_destroy_with_item(p->spaceShot, shot_destroy);
- timer_destroy(p->listTimer);
- free(p);
-}
diff --git a/src/base/arena.h b/src/base/arena.h
deleted file mode 100644
index a01484a..0000000
--- a/src/base/arena.h
+++ /dev/null
@@ -1,55 +0,0 @@
-#ifndef ARENA_H
-#define ARENA_H
-
-#include "main.h"
-
-#ifndef PUBLIC_SERVER
-#include "image.h"
-#endif /* PUBLIC_SERVER */
-
-#include "list.h"
-#include "space.h"
-
-#ifdef __WIN32__
-#define random rand
-#endif /* __WIN32__ */
-
-#define SCREEN_SPLIT_HORIZONTAL 1
-#define SCREEN_SPLIT_VERTICAL 2
-
-typedef struct arena_struct {
-#ifndef PUBLIC_SERVER
- char music[STR_SIZE];
-
- image_t *background;
-#endif /* PUBLIC_SERVER */
- int w, h;
-
- list_t *listTimer;
-
- space_t *spaceShot;
- space_t *spaceTux;
- space_t *spaceItem;
-
- int countRound;
- int max_countRound;
-} arena_t;
-
-extern void arena_set_current(arena_t *p);
-extern arena_t *arena_get_current();
-extern void arena_init();
-extern void arena_quit();
-extern arena_t *arena_new(int w, int h);
-extern int arena_conflict_space(int x1, int y1, int w1, int h1,
- int x2, int y2, int w2, int h2);
-extern int arena_is_free_space(arena_t *arena, int x, int y, int w, int h);
-extern void arena_find_free_space(arena_t *arena, int *x, int *y, int w, int h);
-extern void arena_get_center_screen(int *screen_x, int *screen_y, int x, int y,
- int screen_size_x, int screen_size_y);
-#ifndef PUBLIC_SERVER
-extern void arena_draw(arena_t *arena);
-#endif /* PUBLIC_SERVER */
-extern void arena_event(arena_t *arena);
-extern void arena_destroy(arena_t *p);
-
-#endif /* ARENA_H */
diff --git a/src/base/arenaFile.c b/src/base/arenaFile.c
deleted file mode 100644
index b5ef6a2..0000000
--- a/src/base/arenaFile.c
+++ /dev/null
@@ -1,413 +0,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <assert.h>
-
-#include "main.h"
-#include "list.h"
-#include "textFile.h"
-#include "arenaFile.h"
-#include "arena.h"
-#include "tux.h"
-#include "shot.h"
-#include "item.h"
-#include "director.h"
-#include "modules.h"
-#include "archive.h"
-#include "homeDirector.h"
-
-#ifndef PUBLIC_SERVER
-#include "configFile.h"
-#include "image.h"
-#endif /* PUBLIC_SERVER */
-
-#ifndef NO_SOUND
-#include "music.h"
-#endif /* NO_SOUND */
-
-static list_t *listArenaFile;
-static bool_t isArenaFileInit = FALSE;
-
-bool_t arena_file_is_inicialized()
-{
- return isArenaFileInit;
-}
-
-int arena_file_get_value(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;
-}
-
-
-#ifndef PUBLIC_SERVER
-image_t *arena_file_load_image(arenaFile_t *arenaFile, char *filename, char *group, char *name, int alpha)
-{
- char *extractFile;
- image_t *image;
-
- extractFile = archive_extract_file(arenaFile->path, filename);
- image = image_add(extractFile, alpha, name, group);
- archive_delete_file(extractFile);
-
- return image;
-}
-
-#ifndef NO_SOUND
-void loadMusicFromArena(arenaFile_t *arenaFile, char *filename, char *group, char *name)
-{
- char *extractFile;
-
- extractFile = archive_extract_file(arenaFile->path, filename);
- music_add(extractFile, name, group);
- archive_delete_file(extractFile);
-}
-#endif /* NO_SOUND */
-#endif /* PUBLIC_SERVER */
-
-static void cmd_arena(arena_t **arena, char *line)
-{
- char str_image[STR_SIZE];
- char str_w[STR_SIZE];
- char str_h[STR_SIZE];
-
- if (arena_file_get_value(line, "background", str_image, STR_SIZE) != 0) {
- return;
- }
-
- if (arena_file_get_value(line, "w", str_w, STR_SIZE) != 0) {
- return;
- }
-
- if (arena_file_get_value(line, "h", str_h, STR_SIZE) != 0) {
- return;
- }
-
- (*arena) = arena_new(atoi(str_w), atoi(str_h));
-#ifndef PUBLIC_SERVER
- (*arena)->background = image_get(IMAGE_GROUP_USER, str_image);
-#endif /* PUBLIC_SERVER */
- /*
- (*arena)->w = atoi(str_w);
- (*arena)->h = atoi(str_h);
- */
- arena_set_current(*arena);
-
- debug("Arena loaded");
-}
-
-static void cmd_module_load(char *line)
-{
- char str_file[STR_SIZE];
-
- if (arena_file_get_value(line, "file", str_file, STR_SIZE) != 0) {
- return;
- }
-
- module_load(str_file);
-}
-
-#ifndef PUBLIC_SERVER
-static void cmd_loadImage(arenaFile_t *arenaFile, char *line)
-{
- char str_file[STR_SIZE];
- char str_name[STR_SIZE];
- char str_alpha[STR_SIZE];
-
- if (arena_file_get_value(line, "file", str_file, STR_SIZE) != 0) {
- return;
- }
-
- if (arena_file_get_value(line, "name", str_name, STR_SIZE) != 0) {
- return;
- }
-
- if (arena_file_get_value(line, "alpha", str_alpha, STR_SIZE) != 0) {
- return;
- }
-
- /*printf("str_file=%s str_name=%s str_alpha=%s\n", str_file, str_name, str_alpha);*/
- arena_file_load_image(arenaFile, str_file, IMAGE_GROUP_USER, str_name, isYesOrNO(str_alpha));
-
- /*image_add(str_file, isYesOrNO(str_alpha), str_name, IMAGE_GROUP_USER);*/
-}
-
-static void cmd_loadMusic(arenaFile_t *arenaFile, char *line)
-{
- char str_file[STR_SIZE];
- char str_name[STR_SIZE];
-
- if (arena_file_get_value(line, "file", str_file, STR_SIZE) != 0) {
- return;
- }
-
- if (arena_file_get_value(line, "name", str_name, STR_SIZE) != 0) {
- return;
- }
-
-#ifndef NO_SOUND
- /*music_add(str_file, str_name, MUSIC_GROUP_USER);*/
- loadMusicFromArena(arenaFile, str_file, MUSIC_GROUP_USER, str_name);
-#endif /* NO_SOUND */
-}
-
-static void cmd_music_play(arena_t *arena, char *line)
-{
- char str_music[STR_SIZE];
-
- if (arena_file_get_value(line, "music", str_music, STR_SIZE) != 0) {
- return;
- }
-
- strcpy(arena->music, str_music);
-}
-#endif /* PUBLIC_SERVER */
-
-int arena_file_get_count()
-{
- return listArenaFile->count;
-}
-
-static char *arena_file_get_status(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;
-}
-
-char *arena_file_get_name(arenaFile_t *arenaFile)
-{
- char *ret;
-
- ret = arena_file_get_status(arenaFile->map, "name");
- return (ret != NULL ? ret : "arena_no_name");
-}
-
-char *arena_file_get_net_name(arenaFile_t *arenaFile)
-{
- char *ret;
-
- ret = arena_file_get_status(arenaFile->map, "netName");
- return (ret != NULL ? ret : "arena_no_net_name");
-}
-
-arenaFile_t *arena_file_get_file_format_net_name(char *s)
-{
- int i;
-
- for (i = 0; i < listArenaFile->count; i++) {
- arenaFile_t *arenaFile;
-
- arenaFile = (arenaFile_t *) listArenaFile->list[i];
-
- if (strcmp(arena_file_get_net_name(arenaFile), s) == 0) {
- return arenaFile;
- }
- }
-
- return NULL;
-}
-
-char *arena_file_get_image(arenaFile_t *arenaFile)
-{
- return arena_file_get_status(arenaFile->map, "screen");
-}
-
-arenaFile_t *arena_file_get(int n)
-{
- return (arenaFile_t *) listArenaFile->list[n];
-}
-
-int arena_file_get_id(arenaFile_t *arenaFile)
-{
- int i;
-
- for (i = 0; i < listArenaFile->count; i++) {
- arenaFile_t *this;
-
- this = (arenaFile_t *) listArenaFile->list[i];
-
- if (this == arenaFile) {
- return i;
- }
- }
-
- return -1;
-}
-
-arena_t *arena_file_get_arena(arenaFile_t *arenaFile)
-{
- textFile_t *ts;
- arena_t *arena = NULL; /* no warnings */
- int i;
-
- ts = (textFile_t *) arenaFile->map;
-
- for (i = 0; i < ts->text->count; i++) {
- char *line;
-
- line = (char *) ts->text->list[i];
- module_cmd(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_music_play(arena, line);
- }
-#endif /* PUBLIC_SERVER */
-
- if (strncmp(line, "arena", 5) == 0) {
- cmd_arena(&arena, line);
- }
-
- if (strncmp(line, "loadModule", 10) == 0) {
- cmd_module_load(line);
- }
- }
-
- return arena;
-}
-
-arenaFile_t *arena_file_new(char *path)
-{
- arenaFile_t *new;
- char *extractFile;
-
- new = malloc(sizeof(arenaFile_t));
- new->path = strdup(path);
-
- extractFile = archive_extract_file(path, "arena.map");
- new->map = text_file_load(extractFile);
- archive_delete_file(extractFile);
-
- return new;
-}
-
-void arena_destroyFile(arenaFile_t *p)
-{
- text_file_destroy(p->map);
- free(p->path);
- free(p);
-}
-
-void arena_file_load(char *path)
-{
- list_add(listArenaFile, arena_file_new(path));
-}
-
-static void load_arenaFromDirector(char *director)
-{
- director_t *p;
- int i;
-
- debug("Loading arena files [%s]", director);
- p = director_load(director);
-
- if (p == NULL) {
- error("Directory not found [%s]", director);
- exit(-1);
- }
-
- unsigned l = strlen(director) - 1;
-
- for (i = 0; i < p->list->count; i++) {
- char *line;
-
- line = (char *) p->list->list[i];
-
- if (strstr(line, ".zip") != NULL && strstr(line, "~") == NULL) {
- char path[STR_PATH_SIZE];
-
-
- if (director[l] == (char) PATH_SEPARATOR[0]) {
- sprintf(path, "%s%s", director, line);
- } else {
- sprintf(path, "%s%s%s", director, PATH_SEPARATOR, line);
- }
-
- debug("Loading arena [%s]", line);
-
- accessExistFile(path);
- arena_file_load(path);
- }
- }
-
- /*printf("No. of Arens: %d\n", listArenaFile->count);*/
- director_destroy(p);
-
-}
-
-void arena_file_init()
-{
-#ifndef PUBLIC_SERVER
- assert(image_is_inicialized() == TRUE);
-#endif /* PUBLIC_SERVER */
- isArenaFileInit = TRUE;
- listArenaFile = list_new();
-
- load_arenaFromDirector(PATH_ARENA);
-
-#ifndef PUBLIC_SERVER
- load_arenaFromDirector(home_director_get());
-#endif /* PUBLIC_SERVER */
-}
-
-void arena_file_quit()
-{
- isArenaFileInit = FALSE;
- list_destroy_item(listArenaFile, arena_destroyFile);
-}
diff --git a/src/base/arenaFile.h b/src/base/arenaFile.h
deleted file mode 100644
index 40a9f5f..0000000
--- a/src/base/arenaFile.h
+++ /dev/null
@@ -1,34 +0,0 @@
-#ifndef ARENA_FILE_H
-#define ARENA_FILE_H
-
-#define PUBLIC_SERVER_PATH_ARENA "./arena/"
-
-#include "main.h"
-#include "arena.h"
-#include "textFile.h"
-
-typedef struct {
- char *path;
- textFile_t *map;
-} arenaFile_t;
-
-extern bool_t arena_file_is_inicialized();
-extern int arena_file_get_value(char *line, char *env, char *val, int len);
-extern int arena_file_get_count();
-extern char *arena_file_get_name(arenaFile_t *arenaFile);
-extern char *arena_file_get_net_name(arenaFile_t *arenaFile);
-extern arenaFile_t *arena_file_get_file_format_net_name(char *s);
-extern char *arena_file_get_image(arenaFile_t *arenaFile);
-#ifndef PUBLIC_SERVER
-extern image_t *arena_file_load_image(arenaFile_t *arenaFile, char *filename,
- char *group, char *name, int alpha);
-#endif /* PUBLIC_SERVER */
-extern arenaFile_t *arena_file_get(int n);
-extern int arena_file_get_id(arenaFile_t *arenaFile);
-extern arena_t *arena_file_get_arena(arenaFile_t *arenaFile);
-extern arenaFile_t *arena_file_new(char *path);
-extern void arena_file_load(char *path);
-extern void arena_file_init();
-extern void arena_file_quit();
-
-#endif /* ARENA_FILE_H */
diff --git a/src/base/bool.h b/src/base/bool.h
deleted file mode 100644
index 76a3756..0000000
--- a/src/base/bool.h
+++ /dev/null
@@ -1,10 +0,0 @@
-#ifndef BOOL_H
-#define BOOL_H
-
-#include "main.h"
-
-#define bool_t int
-#define TRUE 1
-#define FALSE 0
-
-#endif /* BOOL_H */
diff --git a/src/base/buffer.c b/src/base/buffer.c
deleted file mode 100644
index 2ecc148..0000000
--- a/src/base/buffer.c
+++ /dev/null
@@ -1,142 +0,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <assert.h>
-
-#include "buffer.h"
-
-buffer_t *buffer_new(int n)
-{
- 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);
-
- return new;
-}
-
-void *buffer_get_data(buffer_t *p)
-{
- return p->data;
-}
-
-int buffer_get_size(buffer_t *p)
-{
- return p->size;
-}
-
-int buffer_append(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;
-}
-
-int buffer_cut(buffer_t *p, int len)
-{
- 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;
- }
-
- return -1;
-}
-
-int buffer_count_line(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;
-}
-
-int buffer_get_line(buffer_t *p, char *line, int len)
-{
- char *end;
- int ret_len;
-
- assert(p != NULL);
- assert(line != NULL);
- assert(len >= 0);
-
- end = NULL;
-
- end = memchr(p->data, '\n', p->size);
-
- if (end == NULL) {
- return -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);
-
- buffer_cut(p, ret_len);
-
- return ret_len;
-}
-
-int buffer_get_data_len(buffer_t *p, char *line, int len)
-{
- assert(p != NULL);
- assert(line != NULL);
- assert(len >= 0);
-
- if ((unsigned)p->size < (unsigned)len) {
- len = p->size;
- }
-
- memcpy(line, p->data, len);
- buffer_cut(p, len);
-
- return len;
-}
-
-void buffer_destroy(buffer_t *p)
-{
- assert(p != NULL);
-
- if (p->data != NULL) {
- free(p->data);
- }
-
- free(p);
-}
diff --git a/src/base/buffer.h b/src/base/buffer.h
deleted file mode 100644
index 9ddc5e6..0000000
--- a/src/base/buffer.h
+++ /dev/null
@@ -1,22 +0,0 @@
-#ifndef BUFFER_H
-#define BUFFER_H
-
-#define BUFFER_LIMIT_ALLOC 1024
-
-typedef struct str_buffer {
- char *data;
- unsigned int size;
- unsigned int alloc;
-} buffer_t;
-
-extern buffer_t *buffer_new(int n);
-extern void *buffer_get_data(buffer_t *p);
-extern int buffer_get_size(buffer_t *p);
-extern int buffer_append(buffer_t *p, char *data, int len);
-extern int buffer_cut(buffer_t *p, int len);
-extern int buffer_count_line(buffer_t *p);
-extern int buffer_get_line(buffer_t *p, char *line, int len);
-extern int buffer_get_data_len(buffer_t *p, char *line, int len);
-extern void buffer_destroy(buffer_t *p);
-
-#endif /* BUFFER_H */
diff --git a/src/base/checkFront.c b/src/base/checkFront.c
deleted file mode 100644
index 999eb58..0000000
--- a/src/base/checkFront.c
+++ /dev/null
@@ -1,117 +0,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <assert.h>
-
-#include "main.h"
-#include "list.h"
-#include "myTimer.h"
-#include "checkFront.h"
-#include "idManager.h"
-#include "server.h"
-
-typedef struct struct_checkfront_t {
- char *msg;
- my_time_t time;
- int id;
- int count;
- int type;
-} checkfront_t;
-
-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 = timer_get_current_time();
- new->id = id;
- new->type = type;
- new->count = 0;
-
- return new;
-}
-
-static void destroyCheck(checkfront_t *p)
-{
- assert(p != NULL);
- free(p->msg);
- free(p);
-}
-
-list_t *check_front_new()
-{
- return list_new();
-}
-
-void check_front_msg_add(list_t *list, char *msg, int type, int id)
-{
- if (type == CHECK_FRONT_TYPE_CHECK) {
- id_inc(id);
- }
-
- list_add(list, newCheck(msg, type, id));
-}
-
-void check_front_event(client_t *client)
-{
- my_time_t currentTime;
- int i;
-
- currentTime = timer_get_current_time();
-
- 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:
- server_send_client(client, this->msg);
- list_del_item(client->listSendMsg, i, destroyCheck);
- i--;
- break;
- case CHECK_FRONT_TYPE_CHECK:
- if (this->count == 0 || currentTime - this->time > CHECK_FRONT_SEND_TIME_INTERVAL) {
- server_send_client(client, this->msg);
- this->time = currentTime;
- this->count++;
- }
- if (this->count > CHECK_FRONT_MAX_COUNT_SEND) {
- id_del(this->id);
- list_del_item(client->listSendMsg, i, destroyCheck);
- i--;
- }
- break;
- default:
- fatal("Wrong type of the event front");
- break;
- }
- }
-}
-
-void check_front_del_msg(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) {
- id_del(this->id);
- list_del_item(listCheckFront, i, destroyCheck);
- return;
- }
- }
-}
-
-void check_front_destroy(list_t *p)
-{
- assert(p != NULL);
- list_destroy_item(p, destroyCheck);
-}
diff --git a/src/base/checkFront.h b/src/base/checkFront.h
deleted file mode 100644
index a65d532..0000000
--- a/src/base/checkFront.h
+++ /dev/null
@@ -1,20 +0,0 @@
-#ifndef CHECK_FRONT_H
-#define CHECK_FRONT_H
-
-#include "list.h"
-#include "server.h"
-
-#define CHECK_FRONT_SEND_TIME_INTERVAL 100
-#define CHECK_FRONT_MAX_COUNT_SEND 30
-
-#define CHECK_FRONT_ID_NONE -1
-#define CHECK_FRONT_TYPE_SIMPLE 1
-#define CHECK_FRONT_TYPE_CHECK 2
-
-extern list_t *check_front_new();
-extern void check_front_msg_add(list_t *list, char *msg, int type, int id);
-extern void check_front_event(client_t *client);
-extern void check_front_del_msg(list_t *listCheckFront, int id);
-extern void check_front_destroy(list_t *p);
-
-#endif /* CHECK_FRONT_H */
diff --git a/src/base/director.c b/src/base/director.c
deleted file mode 100644
index 5c005cb..0000000
--- a/src/base/director.c
+++ /dev/null
@@ -1,69 +0,0 @@
-#include <dirent.h>
-#include <sys/types.h>
-#include <stdlib.h>
-#include <string.h>
-#include <stdio.h>
-#include <unistd.h>
-#include <assert.h>
-
-#include "main.h"
-#include "list.h"
-
-typedef struct director_struct {
- char *path;
- list_t *list;
-} director_t;
-
-director_t *director_load(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 = list_new();
-
-#ifndef __WIN32__
- if (s[0] == '/') {
-#else
- if (s[1] == ':') {
-#endif
- strcpy(path, s);
- } else {
- /* this is really correct aproach */
- getcwd(path, STR_PATH_SIZE);
- strcat(path, PATH_SEPARATOR);
- 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) {
- list_add(new->list, strdup(item->d_name));
- }
-
- closedir(dir);
-
- return new;
-}
-
-void director_destroy(director_t *p)
-{
- assert(p != NULL);
-
- list_destroy_item(p->list, free);
- free(p->path);
- free(p);
-}
diff --git a/src/base/director.h b/src/base/director.h
deleted file mode 100644
index 18c15e9..0000000
--- a/src/base/director.h
+++ /dev/null
@@ -1,15 +0,0 @@
-#ifndef DIRECTOR_H
-#define DIRECTOR_H
-
-#include "main.h"
-#include "list.h"
-
-typedef struct director_struct {
- char *path;
- list_t *list;
-} director_t;
-
-extern director_t *director_load(char *s);
-extern void director_destroy(director_t * p);
-
-#endif /* DIRECTOR_H */
diff --git a/src/base/downServer.c b/src/base/downServer.c
deleted file mode 100644
index a5ab58a..0000000
--- a/src/base/downServer.c
+++ /dev/null
@@ -1,288 +0,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include <sys/types.h>
-
-#include <unistd.h>
-#include <fcntl.h>
-#include <signal.h>
-#include <sys/time.h>
-#include <sys/stat.h>
-
-#include "main.h"
-#include "list.h"
-#include "server.h"
-#include "myTimer.h"
-#include "arena.h"
-#include "serverSelect.h"
-#include "downServer.h"
-#include "arenaFile.h"
-
-#include "tcp.h"
-#include "buffer.h"
-
-#define DOWN_SERVER_LIMIT_BUFFER 10240
-#define DOWN_SERVER_SEND_FILE_BUFFER 4096
-
-#define NET_STATUS_OK 0
-#define NET_STATUS_ZOMBIE 1
-
-static sock_tcp_t *sock_server_tcp;
-static list_t *listClient;
-
-typedef struct client_down_server_struct {
- int status_connect;
- sock_tcp_t *sock;
- buffer_t *recvBuffer;
- buffer_t *sendBuffer;
-
- FILE *file;
- int size;
- int send;
-} client_ds_t;
-
-static int getFileSize(char *s)
-{
- struct stat buf;
-
- if (lstat(s, &buf) < 0) {
- return -1;
- }
-
- return buf.st_size;
-}
-
-static void proto_getarena(client_ds_t *client, char *msg)
-{
- arenaFile_t *arenaFile;
- char msg_out[STR_PROTO_SIZE];
- char *arenaName;
-
- arenaName = msg + 9;
-
- /*printf("arena = >>%s<<\n", arenaName);*/
- arenaFile = arena_file_get_file_format_net_name(arenaName);
-
- if (arenaFile == NULL) {
- char *error_msg = _("[Error] Arena not found\n");
- buffer_append(client->sendBuffer, error_msg, strlen(error_msg));
- return;
- }
-
- client->file = fopen(arenaFile->path, "rb");
-
- if (client->file == NULL) {
- char *error_msg = _("[Error] Server has some problem\n");
- buffer_append(client->sendBuffer, error_msg, strlen(error_msg));
- return;
- }
-
- client->size = getFileSize(arenaFile->path);
- sprintf(msg_out, _("OK %d\n"), client->size);
- buffer_append(client->sendBuffer, msg_out, strlen(msg_out));
-}
-
-static void do_proto(client_ds_t *client, char *msg)
-{
- if (strncmp(msg, "GETARENA ", 9) == 0 && client->file == NULL) {
- proto_getarena(client, msg);
- }
-}
-
-static client_ds_t *newClient(sock_tcp_t *sock)
-{
- client_ds_t *new;
-
- new = malloc(sizeof(client_ds_t));
- memset(new, 0, sizeof(client_ds_t));
-
- new->status_connect = NET_STATUS_OK;
- new->sock = sock;
- new->recvBuffer = buffer_new(DOWN_SERVER_LIMIT_BUFFER);
- new->sendBuffer = buffer_new(DOWN_SERVER_LIMIT_BUFFER);
-
- return new;
-}
-
-static void destroyClient(client_ds_t *client)
-{
- sock_tcp_close(client->sock);
- buffer_destroy(client->recvBuffer);
- buffer_destroy(client->sendBuffer);
-
- if (client->file != NULL) {
- fclose(client->file);
- }
-
- free(client);
-}
-
-int down_server_init(char *ip, int port)
-{
- sock_server_tcp = sock_tcp_bind(ip, port);
-
- if (sock_server_tcp == NULL) {
- error("Unable to initialize download server");
- return -1;
- }
-
- sock_tcp_set_non_block(sock_server_tcp);
-
- listClient = list_new();
-
- return 0;
-}
-
-int down_server_set_select()
-{
- int i;
-
- select_add_sock_for_read(sock_server_tcp->sock);
-
- for (i = 0; i < listClient->count; i++) {
- client_ds_t *this;
-
- this = (client_ds_t *) listClient->list[i];
-
- select_add_sock_for_read(this->sock->sock);
-
- if (buffer_get_size(this->sendBuffer) > 0) {
- select_add_sock_for_write(this->sock->sock);
- }
- }
-
- return 0;
-}
-
-static void eventNewClient(sock_tcp_t *sock_server)
-{
- sock_tcp_t *sock_client;
- client_ds_t *client;
-
- sock_client = sock_tcp_accept(sock_server);
- sock_tcp_set_non_block(sock_client);
- client = newClient(sock_client);
-
- list_add(listClient, client);
-}
-
-static void eventReadClient(client_ds_t *client)
-{
- char buffer[STR_PROTO_SIZE];
- int ret;
-
- memset(buffer, 0, STR_PROTO_SIZE);
-
- ret = sock_tcp_read(client->sock, buffer, STR_PROTO_SIZE - 1);
- /*printf("sock_tcp_read = %d\n", ret);*/
-
- if (ret <= 0) {
- client->status_connect = NET_STATUS_ZOMBIE;
- return;
- }
-
- if (buffer_append(client->recvBuffer, buffer, ret) < 0) {
- client->status_connect = NET_STATUS_ZOMBIE;
- return;
- }
-
- while (buffer_get_line(client->recvBuffer, buffer, STR_PROTO_SIZE) >= 0) {
- int len;
-
- len = strlen(buffer);
-
- if (buffer[len - 1] == '\n') {
- buffer[len - 1] = '\0';
- }
-
- do_proto(client, buffer);
- /*buffer_append(client->sendBuffer, buffer, strlen(buffer));*/
- }
-}
-
-static void eventWriteClient(client_ds_t *client)
-{
- void *data;
- int len;
- int res;
-
- len = buffer_get_size(client->sendBuffer);
-
- if (len == 0) {
- return;
- }
-
- data = buffer_get_data(client->sendBuffer);
-
- res = sock_tcp_write(client->sock, data, len);
- /*printf("sock_tcp_write = %d\n", res);*/
-
- if (res < 0) {
- client->status_connect = NET_STATUS_ZOMBIE;
- return;
- }
-
- buffer_cut(client->sendBuffer, res);
-}
-
-static void sendFile(client_ds_t *client)
-{
- char buffer[DOWN_SERVER_SEND_FILE_BUFFER];
- int count;
-
- count = client->size - client->send;
-
- if (count > DOWN_SERVER_SEND_FILE_BUFFER) {
- count = DOWN_SERVER_SEND_FILE_BUFFER;
- }
-
- if (fread(buffer, count, 1, client->file) != 1) {
- client->status_connect = NET_STATUS_ZOMBIE;
- return;
- }
-
- buffer_append(client->sendBuffer, buffer, count);
- client->send += count;
-}
-
-int down_server_select_socket()
-{
- int i;
-
- if (select_is_change_sock_for_read(sock_server_tcp->sock)) {
- eventNewClient(sock_server_tcp);
- }
-
- for (i = 0; i < listClient->count; i++) {
- client_ds_t *this;
-
- this = (client_ds_t *) listClient->list[i];
-
- if (select_is_change_sock_for_read(this->sock->sock)) {
- eventReadClient(this);
- }
-
- if (select_is_change_sock_for_write(this->sock->sock)) {
- eventWriteClient(this);
- }
-
- if (this->file != NULL && buffer_get_size(this->sendBuffer) == 0) {
- sendFile(this);
- }
-
- if (this->status_connect == NET_STATUS_ZOMBIE) {
- list_del_item(listClient, i, destroyClient);
- }
- }
-
- return 0;
-}
-
-int down_server_quit()
-{
- sock_tcp_close(sock_server_tcp);
- list_destroy_item(listClient, destroyClient);
-
- return 0;
-}
diff --git a/src/base/downServer.h b/src/base/downServer.h
deleted file mode 100644
index cab59e3..0000000
--- a/src/base/downServer.h
+++ /dev/null
@@ -1,13 +0,0 @@
-#ifndef DOWN_SERVER_H
-#define DOWN_SERVER_H
-
-#include "list.h"
-#include "tcp.h"
-#include "buffer.h"
-
-extern int down_server_init(char *ip, int port);
-extern int down_server_set_select();
-extern int down_server_select_socket();
-extern int down_server_quit();
-
-#endif /* DOWN_SERVER_H */
diff --git a/src/base/gun.c b/src/base/gun.c
deleted file mode 100644
index 9c59662..0000000
--- a/src/base/gun.c
+++ /dev/null
@@ -1,316 +0,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <assert.h>
-
-#include "main.h"
-#include "arena.h"
-#include "tux.h"
-#include "shot.h"
-#include "myTimer.h"
-#include "item.h"
-#include "gun.h"
-#include "proto.h"
-#include "net_multiplayer.h"
-#include "serverSendMsg.h"
-
-#ifndef NO_SOUND
-#include "sound.h"
-#endif /* NO_SOUND */
-
-#ifndef PUBLIC_SERVER
-#include "interface.h"
-#include "world.h"
-#else /* PUBLIC_SERVER */
-#include "publicServer.h"
-#endif /* PUBLIC_SERVER */
-
-static void modificiationCopuse(int courser, int right_x, int right_y, int *dest_x, int *dest_y)
-{
- 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:
- fatal("Wrong Tux course change");
- break;
- }
-}
-
-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;
-
- 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 = shot_new(tux->x + dest_x, tux->y + dest_y, dest_px, dest_py, gun, tux->id);
- space_add(arena_get_current()->spaceShot, shot);
-}
-
-static void addShot(tux_t *tux, int x, int y, int px, int py)
-{
- int gun;
-
- if (net_multiplayer_get_game_type() == 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;
-
- 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 gun_shotSimpe(tux_t *tux)
-{
- addShot(tux, 0, 0, +5, 0);
-}
-
-static void gun_shotDualSimpe(tux_t *tux)
-{
- addShot(tux, 0, -10, +6, 0);
- addShot(tux, 0, +10, +6, 0);
-}
-
-static void gun_shotScatter(tux_t *tux)
-{
- int i;
-
- for (i = -2; i <= +2; i++) {
- addShot(tux, 0, 0, +8, i);
- }
-}
-
-static void timer_addShotTimer(void *p)
-{
- tux_t *tux;
- int id;
- int gun;
-
- id = *((int *) p);
- free(p);
-
- tux = space_get_object_id(arena_get_current()->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 gun_shotTommy(tux_t *tux)
-{
- int i;
-
- for (i = 0; i < 10; i++) {
- timer_add_task(arena_get_current()->listTimer, TIMER_ONE,
- timer_addShotTimer, newInt(tux->id), i * 100);
- }
-}
-
-static void timer_addLaserTimer(void *p)
-{
- tux_t *tux;
- int id;
- int gun;
-
- id = *((int *) p);
- free(p);
-
- tux = space_get_object_id(arena_get_current()->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 gun_shotLasser(tux_t *tux)
-{
- int i;
-
- for (i = 0; i < 50; i++) {
- timer_add_task(arena_get_current()->listTimer, TIMER_ONE,
- timer_addLaserTimer, newInt(tux->id), i * 10);
- }
-}
-
-static void putInGunMine(tux_t *tux)
-{
- 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 = arena_get_current();
-
- if (arena_is_free_space(arena_get_current(), x, y, ITEM_MINE_WIDTH, ITEM_MINE_HEIGHT)) {
- item_t *item;
-#ifndef NO_SOUND
- sound_play("put_mine", SOUND_GROUP_BASE);
-#endif /* NO_SOUND */
- tux->shot[tux->gun]--;
-
- if (net_multiplayer_get_game_type() != NET_GAME_TYPE_CLIENT) {
- item = item_new(x, y, ITEM_MINE, tux->id);
-
- if (net_multiplayer_get_game_type() == NET_GAME_TYPE_SERVER) {
- proto_send_additem_server(PROTO_SEND_ALL, NULL, item);
- }
-
- space_add(arena->spaceItem, item);
- }
- }
-}
-
-static void gun_shotBombball(tux_t *tux)
-{
- addShot(tux, 0, 0, +10, 0);
-}
-
-void gun_shot(tux_t *tux)
-{
- if (tux->bonus != BONUS_SHOT && tux->gun != GUN_MINE) {
- tux->shot[tux->gun]--;
- }
-
- switch (tux->gun) {
- case GUN_SIMPLE:
- #ifndef NO_SOUND
- sound_play("gun_revolver", SOUND_GROUP_BASE);
- #endif /* NO_SOUND */
- gun_shotSimpe(tux);
- break;
- case GUN_DUAL_SIMPLE:
- #ifndef NO_SOUND
- sound_play("gun_revolver", SOUND_GROUP_BASE);
- #endif /* NO_SOUND */
- gun_shotDualSimpe(tux);
- break;
- case GUN_SCATTER:
- #ifndef NO_SOUND
- sound_play("gun_scatter", SOUND_GROUP_BASE);
- #endif /* NO_SOUND */
- gun_shotScatter(tux);
- break;
- case GUN_TOMMY:
- #ifndef NO_SOUND
- sound_play("gun_tommy", SOUND_GROUP_BASE);
- #endif /* NO_SOUND */
- gun_shotTommy(tux);
- break;
- case GUN_LASSER:
- #ifndef NO_SOUND
- sound_play("gun_lasser", SOUND_GROUP_BASE);
- #endif /* NO_SOUND */
- gun_shotLasser(tux);
- break;
- case GUN_BOMBBALL:
- gun_shotBombball(tux);
- break;
- case GUN_MINE:
- putInGunMine(tux);
- break;
- }
-}
diff --git a/src/base/gun.h b/src/base/gun.h
deleted file mode 100644
index 94d2cc9..0000000
--- a/src/base/gun.h
+++ /dev/null
@@ -1,16 +0,0 @@
-#ifndef GUN_H
-#define GUN_H
-
-#define GUN_SHOT_WIDTH 5
-#define GUN_SHOT_HEIGHT 5
-#define GUN_LASSER_HORIZONTAL 40
-#define GUN_SHOT_VERTICAL 5
-#define GUN_BOMBBALL_WIDTH 20
-#define GUN_BOMBBALL_HEIGHT 20
-
-#include "main.h"
-#include "tux.h"
-
-extern void gun_shot(tux_t *p);
-
-#endif /* GUN_H */
diff --git a/src/base/homeDirector.c b/src/base/homeDirector.c
deleted file mode 100644
index 5ff14b7..0000000
--- a/src/base/homeDirector.c
+++ /dev/null
@@ -1,44 +0,0 @@
-#include <stdlib.h>
-#include <stdio.h>
-#include <unistd.h>
-#include <assert.h>
-#include <sys/stat.h>
-
-#include "main.h"
-#include "homeDirector.h"
-
-static char homeDirector[STR_PATH_SIZE];
-
-void home_director_create()
-{
- char *envHome;
-#ifndef __WIN32__
- envHome = getenv("HOME");
-#else /* __WIN32__ */
- envHome = getenv("USERPROFILE");
-#endif /* __WIN32__ */
- if (envHome == NULL) {
- error("Environment variable HOME not found");
- exit(0);
- }
-
- sprintf(homeDirector, "%s%s%s", envHome, PATH_SEPARATOR, HOMEDIRECTOR_NAME);
-
- if (access(homeDirector, F_OK) != 0) {
- debug("Creating home directory [%s]", homeDirector);
-
-#ifndef __WIN32__
- if (mkdir(homeDirector, 0755) != 0) {
-#else /* __WIN32__ */
- if (mkdir(homeDirector) != 0) {
-#endif /* __WIN32__ */
- error("Unable to create home directory [%s]", homeDirector);
- exit(0);
- }
- }
-}
-
-char *home_director_get()
-{
- return homeDirector;
-}
diff --git a/src/base/homeDirector.h b/src/base/homeDirector.h
deleted file mode 100644
index e89f0af..0000000
--- a/src/base/homeDirector.h
+++ /dev/null
@@ -1,11 +0,0 @@
-#ifndef HOMEDIRECTOR_H
-#define HOMEDIRECTOR_H
-
-#include "main.h"
-
-#define HOMEDIRECTOR_NAME ".tuxanci"
-
-extern void home_director_create();
-extern char *home_director_get();
-
-#endif /* HOMEDIRECTOR_H */
diff --git a/src/base/idManager.c b/src/base/idManager.c
deleted file mode 100644
index 87042bb..0000000
--- a/src/base/idManager.c
+++ /dev/null
@@ -1,198 +0,0 @@
-#include <stdlib.h>
-#include <stdio.h>
-#include <assert.h>
-
-#include "main.h"
-#include "list.h"
-#include "idManager.h"
-
-static list_t *listID;
-static int lastID;
-
-typedef struct id_item_struct {
- int id;
- int count;
-} id_item_t;
-
-static id_item_t *newIdItem(int id, int count)
-{
- id_item_t *new;
-
- new = malloc(sizeof(id_item_t));
- new->id = id;
- new->count = count;
-
- return new;
-}
-
-static void destroyIdItem(id_item_t *p)
-{
- assert(p != NULL);
-
- free(p);
-}
-
-void id_init_list()
-{
- debug("Initializing ID manager");
-
- listID = list_new();
- lastID = 0;
-
-}
-
-int id_is_register(int id)
-{
- int i;
-
- assert(listID != NULL);
-
- for (i = 0; i < listID->count; i++) {
- id_item_t *this;
-
- this = listID->list[i];
-
- if (this->id == id) {
- return i;
- }
- }
-
- return -1;
-}
-
-static int findNewID()
-{
- int ret;
-
- assert(listID != NULL);
-
- if (listID->count >= MAX_ID - 1) {
- fatal("There is no free ID left");
- }
-
- do {
- /*ret = (random() % (listID->count + 8 )) + 1;*/
- ret = random() % MAX_ID + 1;
- } while (id_is_register(ret) != -1);
-
- /*printf("new ID %d\n", ret);*/
-
- return ret;
-}
-
-int id_get_newcount(int count)
-{
- int id;
-
- id = findNewID();
-
- list_add(listID, newIdItem(id, count));
-
- return id;
-}
-
-int id_get_new()
-{
- return id_get_newcount(1);
-}
-
-void id_inc(int id)
-{
- id_item_t *this;
- int index;
-
- assert(listID != NULL);
-
- index = id_is_register(id);
-
- if (index == -1) {
- error("Trying to increment counter of never registered ID [%d]", id);
- assert(0);
- return; /* ha ha ha */
- }
-
- this = listID->list[index];
-
- this->count++;
-
- /*printf("inc ID %d %d\n", this->id, this->count);*/
- return;
-}
-
-void id_del(int id)
-{
- id_item_t *this;
- int index;
-
- assert(listID != NULL);
-
- index = id_is_register(id);
-
- if (index == -1) {
- error("Trying to delete never registered ID [%d]", id);
- assert(0);
- return; /* ha ha ha */
- }
-
- this = listID->list[index];
-
- this->count--;
- /*printf("dec ID %d %d\n", this->id, this->count);*/
-
- if (this->count <= 0) {
- list_del_item(listID, index, free);
- /*printf("listID->count = %d\n", listID->count);*/
- }
-
- return;
-}
-
-void id_replace(int old_id, int new_id)
-{
- int index_old_id;
- int index_new_id;
- id_item_t *this;
-
- if (old_id == new_id) {
- return;
- }
-
- index_old_id = id_is_register(old_id);
- assert(index_old_id != -1);
-
- index_new_id = id_is_register(new_id);
- assert(index_new_id == -1);
-
- this = listID->list[index_old_id];
- this->id = new_id;
-}
-
-void infoID(int id)
-{
- id_item_t *this;
- int index;
-
- assert(listID != NULL);
-
- index = id_is_register(id);
-
- if (index == -1) {
- debug("Getting information of nonexistent ID [%d]", id);
-
- return;
- }
-
- this = listID->list[index];
-
- debug("ID information [%d]: used %d times", this->id, this->count);
-
- return;
-}
-
-void id_quit_list()
-{
- debug("Shutting down ID manager");
-
- assert(listID != NULL);
- list_destroy_item(listID, destroyIdItem);
-}
diff --git a/src/base/idManager.h b/src/base/idManager.h
deleted file mode 100644
index 4ad2abc..0000000
--- a/src/base/idManager.h
+++ /dev/null
@@ -1,22 +0,0 @@
-#ifndef ID_MANAGER_H
-#define ID_MANAGER_H
-
-#include "list.h"
-
-#define MAX_ID 1000000
-#define ID_UNKNOWN -1
-
-#ifdef __WIN32__
-#define random rand
-#endif /* __WIN32__ */
-
-extern void id_init_list();
-extern int id_is_register(int id);
-extern int id_get_newcount(int count);
-extern int id_get_new();
-extern void id_inc(int id);
-extern void id_del(int id);
-extern void id_replace(int old_id, int new_id);
-extern void id_quit_list();
-
-#endif /* ID_MANAGER_H */
diff --git a/src/base/index.c b/src/base/index.c
deleted file mode 100644
index a320443..0000000
--- a/src/base/index.c
+++ /dev/null
@@ -1,267 +0,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <assert.h>
-
-#include "main.h"
-#include "list.h"
-#include "index.h"
-
-#define DEBUG_INDEX
-
-static index_item_t *index_item_new(int key, void *data)
-{
- index_item_t *new;
-
- new = malloc(sizeof(index_item_t));
- new->key = key;
- new->data = data;
-
- return new;
-}
-
-#ifdef DEBUG_INDEX
-static void printIndexItem(index_item_t *p)
-{
- debug("Index [%d] contains: %p", p->key, p->data);
-}
-
-static void printListIndexItem(list_t *list)
-{
- int i;
-
- debug("List:");
-
- for (i = 0; i < list->count; i++) {
- index_item_t *this;
-
- this = (index_item_t *) list->list[i];
- printIndexItem(this);
- }
-}
-
-static void checkList(list_t *list)
-{
- int i;
- int prev;
- int this;
-
- /*return;*/
-
- if (list->count == 0) {
- printf(_("Nothing\n"));
- return;
- }
-
- prev = ((index_item_t *) list->list[0])->key;
-
- for (i = 1; i < list->count; i++) {
- this = ((index_item_t *) list->list[i])->key;
-
- if (prev >= this) {
- printListIndexItem(list);
- fatal("Error in list");
- }
-
- prev = this;
- }
-}
-#endif /* DEBUG_INDEX */
-
-static void index_item_destroy(index_item_t *p)
-{
- free(p);
-}
-
-list_t *index_new()
-{
- return list_new();
-}
-
-void index_add(list_t *list, int key, void *data)
-{
-#ifdef DEBUG_INDEX
- int count = 0;
-#endif /* DEBUG_INDEX */
-
- index_item_t *item;
- index_item_t *this;
- int min, max, point;
- int len;
-
- item = index_item_new(key, data);
- len = list->count;
-
- min = 0;
- max = len - 1;
-
- for (;;) {
- point = min + (max - min) / 2;
-
-#ifdef DEBUG_INDEX
- if (++count == len * 5) {
- error("Cyclic error");
- printIndexItem(item);
- printListIndexItem(list);
- abort();
- }
-#endif /* DEBUG_INDEX */
-
- if (max < 0) {
- list_ins(list, 0, item);
-#ifdef DEBUG_INDEX
- checkList(list);
-#endif /* DEBUG_INDEX */
- return;
- }
-
- if (min >= len) {
- list_add(list, item);
-#ifdef DEBUG_INDEX
- checkList(list);
-#endif /* DEBUG_INDEX */
- 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) {
- list_ins(list, point, item);
-#ifdef DEBUG_INDEX
- checkList(list);
-#endif /* DEBUG_INDEX */
- 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)
-{
- index_item_t *this;
- int min, max, point, len;
-
- len = list->count;
-
- if (len == 0) {
- return -1;
- }
-
- min = 0;
- max = len - 1;
-
- for (;;) {
- point = min + (max - min) / 2;
-
- if (max < 0 || point >= len || max < min) {
- return -1;
- }
-
- 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;
- }
- }
-}
-
-void *index_get(list_t *list, int key)
-{
- int offset;
-
- offset = getOffsetFromIndex(list, key);
-
- if (offset != -1) {
- index_item_t *this;
-
- this = list->list[offset];
- return this->data;
- }
-
- return NULL;
-}
-
-void index_del(list_t *list, int key)
-{
- int offset;
-
- offset = getOffsetFromIndex(list, key);
-
- if (offset != -1) {
- list_del_item(list, offset, index_item_destroy);
- }
-}
-
-void index_del_with_object(list_t *list, int key, void *f)
-{
- int offset;
-
- offset = getOffsetFromIndex(list, key);
-
- if (offset != -1) {
- index_item_t *this;
- void (*fce) (void *p);
-
- this = list->list[offset];
-
- fce = f;
- fce(this);
-
- list_del_item(list, offset, index_item_destroy);
- }
-}
-
-void index_action(list_t *list, void *f)
-{
- int i;
-
- for (i = 0; i < list->count; i++) {
- index_item_t *this;
- void (*fce) (void *p);
-
- this = list->list[i];
-
- fce = f;
- fce(this);
- }
-}
-
-void index_destroy(list_t *list)
-{
- list_destroy_item(list, index_item_destroy);
-}
-
-void index_destroyWithObject(list_t *list, void *f)
-{
- index_action(list, f);
- list_destroy_item(list, index_item_destroy);
-}
diff --git a/src/base/index.h b/src/base/index.h
deleted file mode 100644
index 4bb1c1b..0000000
--- a/src/base/index.h
+++ /dev/null
@@ -1,21 +0,0 @@
-#ifndef INDEX_H
-#define INDEX_H
-
-#include "main.h"
-#include "list.h"
-
-typedef struct index_item_struct {
- int key;
- void *data;
-} index_item_t;
-
-extern list_t *index_new();
-extern void index_add(list_t *list, int key, void *data);
-extern void *index_get(list_t *list, int key);
-extern void index_del(list_t *list, int key);
-extern void index_del_with_object(list_t *list, int key, void *f);
-extern void index_action(list_t *list, void *f);
-extern void index_destroy(list_t *list);
-extern void index_destroyWithObject(list_t *list, void *f);
-
-#endif /* INDEX_H */
diff --git a/src/base/item.c b/src/base/item.c
deleted file mode 100644
index 66d69e2..0000000
--- a/src/base/item.c
+++ /dev/null
@@ -1,551 +0,0 @@
-#include <stdlib.h>
-#include <assert.h>
-
-#include "main.h"
-#include "arena.h"
-#include "tux.h"
-#include "item.h"
-#include "shot.h"
-#include "proto.h"
-#include "idManager.h"
-#include "net_multiplayer.h"
-#include "serverSendMsg.h"
-
-#ifndef PUBLIC_SERVER
-#include "interface.h"
-#include "image.h"
-#include "radar.h"
-#include "layer.h"
-
-#include "world.h"
-#include "setting.h"
-
-#ifndef NO_SOUND
-#include "sound.h"
-#endif /* NO_SOUND */
-
-#else /* PUBLIC_SERVER */
-#include "publicServer.h"
-#endif /* PUBLIC_SERVER */
-
-#ifndef PUBLIC_SERVER
-static image_t *g_item[ITEM_COUNT];
-#endif /* PUBLIC_SERVER */
-
-static bool_t isItemInit = FALSE;
-
-bool_t item_is_inicialized()
-{
- return isItemInit;
-}
-
-void item_init()
-{
-#ifndef PUBLIC_SERVER
- g_item[GUN_DUAL_SIMPLE] = image_add("item.dual.png", IMAGE_ALPHA, "item_dual_simple", IMAGE_GROUP_BASE);
- g_item[GUN_TOMMY] = image_add("item.tommy.png", IMAGE_ALPHA, "item_tommy_simple", IMAGE_GROUP_BASE);
- g_item[GUN_SCATTER] = image_add("item.scatter.png", IMAGE_ALPHA, "item_scatter_simple", IMAGE_GROUP_BASE);
- g_item[GUN_LASSER] = image_add("item.lasser.png", IMAGE_ALPHA, "item_lasser_simple", IMAGE_GROUP_BASE);
- g_item[GUN_MINE] = image_add("item.mine.png", IMAGE_ALPHA, "item_mines_simple", IMAGE_GROUP_BASE);
- g_item[GUN_BOMBBALL] = image_add("item.bombball.png", IMAGE_ALPHA, "item_bombball_simple", IMAGE_GROUP_BASE);
- g_item[ITEM_MINE] = image_add("mine.png", IMAGE_ALPHA, "item_mine_simple", IMAGE_GROUP_BASE);
- g_item[ITEM_EXPLOSION] = image_add("explosion.png", IMAGE_ALPHA, "item_explosion_simple", IMAGE_GROUP_BASE);
- g_item[ITEM_BIG_EXPLOSION] = image_add("big-explosion.png", IMAGE_ALPHA, "item_big-explosion_simple", IMAGE_GROUP_BASE);
- g_item[BONUS_SPEED] = image_add("item.bonus.speed.png", IMAGE_ALPHA, "item_bonus_speed", IMAGE_GROUP_BASE);
- g_item[BONUS_SHOT] = image_add("item.bonus.shot.png", IMAGE_ALPHA, "item_shot_speed", IMAGE_GROUP_BASE);
- g_item[BONUS_TELEPORT] = image_add("item.bonus.teleport.png", IMAGE_ALPHA, "item_teleport_speed", IMAGE_GROUP_BASE);
- g_item[BONUS_GHOST] = image_add("item.bonus.ghost.png", IMAGE_ALPHA, "item_ghost_speed", IMAGE_GROUP_BASE);
- g_item[BONUS_4X] = image_add("item.bonus.4x.png", IMAGE_ALPHA, "item_4x_speed", IMAGE_GROUP_BASE);
- g_item[BONUS_HIDDEN] = image_add("item.bonus.hidden.png", IMAGE_ALPHA, "item_hidden_speed", IMAGE_GROUP_BASE);
-#endif /* PUBLIC_SERVER */
- isItemInit = TRUE;
-}
-
-item_t *item_new(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 = id_get_new();
- new->x = x;
- new->y = y;
- new->frame = 0;
- new->count = 0;
-#ifndef PUBLIC_SERVER
- new->img = g_item[type];
-#endif /* PUBLIC_SERVER */
- 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
- sound_play("explozion", SOUND_GROUP_BASE);
-#endif /* NO_SOUND */
- new->w = ITEM_EXPLOSION_WIDTH;
- new->h = ITEM_EXPLOSION_HEIGHT;
- break;
- case ITEM_BIG_EXPLOSION:
-#ifndef NO_SOUND
- sound_play("explozion", SOUND_GROUP_BASE);
-#endif /* NO_SOUND */
- 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 item_get_status(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;
-}
-
-void item_set_status(void *p, int x, int y, int w, int h)
-{
- item_t *item;
-
- item = p;
- item->x = x;
- item->y = y;
- item->w = w;
- item->h = h;
-}
-
-void item_replace_id(item_t *item, int id)
-{
- id_replace(item->id, id);
- item->id = id;
-}
-
-#ifdef PUBLIC_SERVER
-static void action_countitem(space_t *space, item_t *item, int *count)
-{
- 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)
-{
- int count = 0;
-
- space_action(spaceItem, action_countitem, &count);
-
- return count;
-}
-#endif /* PUBLIC_SERVER */
-
-void item_add_new_item(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(public_server_get_setting("MAX_ITEM", "--max-item", "100"))) {
- return;
- }
-#endif /* PUBLIC_SERVER */
-
-#ifndef PUBLIC_SERVER
- if (setting_is_any_item() == FALSE || net_multiplayer_get_game_type() == NET_GAME_TYPE_CLIENT) {
- return;
- }
-#endif /* PUBLIC_SERVER */
-
- arena = arena_get_current();
- arena_find_free_space(arena_get_current(), &new_x, &new_y, ITEM_GUN_WIDTH, ITEM_GUN_HEIGHT);
-
- type = GUN_DUAL_SIMPLE;
-
-#ifndef PUBLIC_SERVER
- do {
-#endif /* PUBLIC_SERVER */
- 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 (setting_is_item(type) == FALSE ||
- (net_multiplayer_get_game_type() == NET_GAME_TYPE_NONE && type == BONUS_HIDDEN));
-#endif /* PUBLIC_SERVER */
- item = item_new(new_x, new_y, type, author_id);
- space_add(spaceItem, item);
-
- if (net_multiplayer_get_game_type() == NET_GAME_TYPE_SERVER) {
- proto_send_additem_server(PROTO_SEND_ALL, NULL, item);
- }
-
-#ifndef PUBLIC_SERVER
- if (net_multiplayer_get_game_type() != NET_GAME_TYPE_CLIENT) {
- radar_add(item->id, new_x, new_y, RADAR_TYPE_ITEM);
- }
-#endif /* PUBLIC_SERVER */
-}
-
-#ifndef PUBLIC_SERVER
-void item_draw(item_t *p)
-{
- assert(p != NULL);
- addLayer(p->img, p->x, p->y, p->frame * p->w, 0, p->w, p->h, TUX_LAYER);
-}
-
-void item_draw_list(list_t *listItem)
-{
- item_t *thisItem;
- int i;
-
- assert(listItem != NULL);
-
- for (i = 0; i < listItem->count; i++) {
- thisItem = (item_t *) listItem->list[i];
- assert(thisItem != NULL);
- item_draw(thisItem);
- }
-}
-
-#endif /* PUBLIC_SERVER */
-
-static void action_itemevent(space_t *space, item_t *item, void *p)
-{
- my_time_t currentTime;
-
- currentTime = timer_get_current_time();
- 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) {
- space_del_with_item(space, item, item_destroy);
- }
- 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 item_event(space_t *spaceItem)
-{
- space_action(spaceItem, action_itemevent, NULL);
-}
-
-static void mineExplosion(space_t *spaceItem, item_t *item)
-{
- if (net_multiplayer_get_game_type() != 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 = item_new(x, y, ITEM_BIG_EXPLOSION, item->author_id);
-
- if (net_multiplayer_get_game_type() == NET_GAME_TYPE_SERVER) {
- proto_send_additem_server(PROTO_SEND_ALL, NULL, item_explosion);
- }
-
- space_add(spaceItem, item_explosion);
- }
-
- if (net_multiplayer_get_game_type() == NET_GAME_TYPE_SERVER) {
- proto_send_del_server(PROTO_SEND_ALL, NULL, item->id);
- }
-
- if (net_multiplayer_get_game_type() != NET_GAME_TYPE_CLIENT) {
- space_del_with_item(spaceItem, item, item_destroy);
- }
-}
-
-static void action_item(space_t *space, item_t *item, int *isDel)
-{
- switch (item->type) {
- case ITEM_MINE:
- if (net_multiplayer_get_game_type() != 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)
-{
- int isDel = 0;
-
- space_action_from_location(spaceItem, action_item, &isDel,
- shot->x, shot->y, shot->w, shot->h);
-
- if (isDel) {
- if (net_multiplayer_get_game_type() == NET_GAME_TYPE_SERVER) {
- proto_send_del_server(PROTO_SEND_ALL, NULL, shot->id);
- }
-
- space_del_with_item(space, shot, shot_destroy);
- }
-}
-
-void item_event_conglicts_shot_with_item(arena_t *arena)
-{
- if (net_multiplayer_get_game_type() == NET_GAME_TYPE_CLIENT) {
- return;
- }
-
- space_action(arena->spaceShot, action_shot, arena->spaceItem);
-}
-
-static void tux_event_tux_is_deadWithItem(tux_t *tux, item_t *item)
-{
- if (tux->bonus == BONUS_GHOST) {
- return;
- }
-
- if (tux->bonus == BONUS_TELEPORT) {
- tux_teleport(tux);
- return;
- }
-
- if (item->author_id == tux->id) {
- tux->score--;
-
- if (net_multiplayer_get_game_type() == NET_GAME_TYPE_SERVER) {
- proto_send_newtux_server(PROTO_SEND_ALL, NULL, tux);
- }
- }
-
- if (item->author_id != tux->id) {
- tux_t *author;
-
- author = space_get_object_id(arena_get_current()->spaceTux, item->author_id);
-
- if (author != NULL) {
- author->score++;
-
- if (net_multiplayer_get_game_type() == NET_GAME_TYPE_SERVER) {
- proto_send_newtux_server(PROTO_SEND_ALL, NULL, author);
- }
- }
- }
-
- tux_event_tux_is_dead(tux);
-}
-
-static void tuxGiveBonus(tux_t *tux, item_t *item)
-{
-#ifndef NO_SOUND
- sound_play("item_bonus", SOUND_GROUP_BASE);
-#endif /* NO_SOUND */
- tux->bonus = item->type;
- tux->bonus_time = TUX_MAX_BONUS;
-
- if (net_multiplayer_get_game_type() == NET_GAME_TYPE_SERVER) {
- proto_send_newtux_server(PROTO_SEND_ALL, NULL, tux);
- }
-
-#ifndef PUBLIC_SERVER
- if (net_multiplayer_get_game_type() != NET_GAME_TYPE_CLIENT) {
- radar_del(item->id);
- }
-#endif /* PUBLIC_SERVER */
-}
-
-static void tuxGiveGun(tux_t *tux, item_t *item)
-{
-#ifndef NO_SOUND
- sound_play("item_gun", SOUND_GROUP_BASE);
-#endif /* NO_SOUND */
- tux->pickup_time = 0;
- tux->shot[item->type] += GUN_MAX_SHOT;
- tux->gun = item->type;
-
- if (net_multiplayer_get_game_type() == NET_GAME_TYPE_SERVER) {
- proto_send_newtux_server(PROTO_SEND_ALL, NULL, tux);
- }
-
-#ifndef PUBLIC_SERVER
- if (net_multiplayer_get_game_type() != NET_GAME_TYPE_CLIENT) {
- radar_del(item->id);
- }
-#endif /* PUBLIC_SERVER */
-}
-
-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 (net_multiplayer_get_game_type() == NET_GAME_TYPE_SERVER) {
- proto_send_del_server(PROTO_SEND_ALL, NULL, item->id);
- }
-
- space_del_with_item(space, item, item_destroy);
-#ifdef PUBLIC_SERVER
- item_add_new_item(space, ID_UNKNOWN);
-#endif /* PUBLIC_SERVER */
- 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) {
- tux_event_tux_is_deadWithItem(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 (net_multiplayer_get_game_type() == NET_GAME_TYPE_SERVER) {
- proto_send_del_server(PROTO_SEND_ALL, NULL, item->id);
- }
-
- space_del_with_item(space, item, item_destroy);
-#ifdef PUBLIC_SERVER
- item_add_new_item(space, ID_UNKNOWN);
-#endif /* PUBLIC_SERVER */
- break;
- }
-}
-
-void item_tux_give_list_item(tux_t *tux, space_t *spaceItem)
-{
- int x, y, w, h;
-
- assert(spaceItem != NULL);
- assert(tux != NULL);
-
- if (net_multiplayer_get_game_type() == NET_GAME_TYPE_CLIENT) {
- return;
- }
-
- if (tux->status == TUX_STATUS_DEAD) {
- return;
- }
-
- tux_get_proportion(tux, &x, &y, &w, &h);
- space_action_from_location(spaceItem, action_giveitem, tux, x, y, w, h);
-}
-
-void item_destroy(item_t *p)
-{
- assert(p != NULL);
- id_del(p->id);
- free(p);
-}
-
-void item_quiy()
-{
- isItemInit = FALSE;
-}
diff --git a/src/base/item.h b/src/base/item.h
deleted file mode 100644
index 48f2930..0000000
--- a/src/base/item.h
+++ /dev/null
@@ -1,75 +0,0 @@
-#ifndef ITEM_H
-#define ITEM_H
-
-#include "main.h"
-
-#ifndef PUBLIC_SERVER
-#include "image.h"
-#endif /* PUBLIC_SERVER */
-
-#include "list.h"
-#include "tux.h"
-#include "myTimer.h"
-
-#define ITEM_SYNC_TIMEOUT 5000
-
-#ifdef __WIN32__
-#define random rand
-#endif /* __WIN32__ */
-
-#define ITEM_MAX_COUNT 1
-#define ITEM_GUN_MAX_FRAME 8
-#define ITEM_MINE_MAX_FRAME 1
-#define ITEM_EXPLOSION_MAX_FRAME 10
-#define ITEM_BONUS_MAX_FRAME 8
-#define ITEM_GUN_WIDTH 50
-#define ITEM_GUN_HEIGHT 20
-#define ITEM_MINE_WIDTH 15
-#define ITEM_MINE_HEIGHT 11
-#define ITEM_EXPLOSION_WIDTH 40
-#define ITEM_EXPLOSION_HEIGHT 40
-#define ITEM_BIG_EXPLOSION_WIDTH 100
-#define ITEM_BIG_EXPLOSION_HEIGHT 100
-#define ITEM_BONUS_WIDTH 20
-#define ITEM_BONUS_HEIGHT 20
-
-typedef struct item_struct {
- int id;
- int type; /* type of the item */
-
- /* position */
- int x;
- int y;
-
- /* size */
- int w;
- int h;
-
- int frame; /* number of animation frames */
- int count;
-
- int author_id;
-#ifndef PUBLIC_SERVER
- image_t *img; /* picture of the item*/
-#endif
-} item_t;
-
-extern bool_t item_is_inicialized();
-extern void item_init();
-extern item_t *item_new(int x, int y, int type, int author_id);
-extern void item_get_status(void *p, int *id, int *x, int *y, int *w, int *h);
-extern void item_set_status(void *p, int x, int y, int w, int h);
-extern void item_replace_id(item_t *item, int id);
-extern void item_add_new_item(space_t *spaceItem, int author_id);
-#ifndef PUBLIC_SERVER
-extern void item_draw(item_t *p);
-extern void item_draw_list(list_t *listItem);
-#endif /* PUBLIC_SERVER */
-extern void item_event(space_t *listSpace);
-extern void item_event_conglicts_shot_with_item(arena_t *arena);
-extern void item_event_tux_give_item(tux_t *tux, item_t *item, space_t *spaceItem);
-extern void item_tux_give_list_item(tux_t *tux, space_t *spaceItem);
-extern void item_destroy(item_t *p);
-extern void item_quiy();
-
-#endif /* ITEM_H */
diff --git a/src/base/list.c b/src/base/list.c
deleted file mode 100644
index 482b50e..0000000
--- a/src/base/list.c
+++ /dev/null
@@ -1,184 +0,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <assert.h>
-
-#include "main.h"
-#include "list.h"
-
-list_t *list_new()
-{
- list_t *new;
-
- new = malloc(sizeof(list_t));
- memset(new, 0, sizeof(list_t));
-
- return new;
-}
-
-list_t *list_clone(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 *list_clone_item(list_t *p, void *f)
-{
- list_t *new;
- void *(*fce) (void *);
- int i;
-
- assert(p != NULL);
- assert(f != NULL);
- new = list_clone(p);
- fce = f;
-
- for (i = 0; i < p->count; i++) {
- new->list[i] = fce(p->list[i]);
- }
-
- return new;
-}
-
-void list_add(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) {
-#ifdef DEBUG_LIST
- printf("[Debug] Reallocating list from %d to %d (count: %d)\n",
- p->alloc, p->alloc + LIST_ALLOC_LIMIT, p->count);
-#endif
- p->alloc += LIST_ALLOC_LIMIT;
- p->list = realloc(p->list, p->alloc * sizeof(void *));
- p->list[p->count] = item;
- p->count++;
- return;
- }
-}
-
-void list_ins(list_t *p, int n, void *item)
-{
- assert(p != NULL);
- list_add(p, NULL); /* :) */
- assert(n >= 0 || n < p->count);
- memmove(p->list + n + 1, p->list + n, ((p->count - 1) - n) * sizeof(void *));
- p->list[n] = item;
-}
-
-void *list_get(list_t *p, int n)
-{
- assert(p != NULL);
- assert(n >= 0 || n < p->count);
- return p->list[n];
-}
-
-int list_search(list_t *p, void *n)
-{
- int i;
-
- assert(p != NULL);
-
- for (i = 0; i < p->count; i++) {
- if (p->list[i] == n) {
- return i;
- }
- }
-
- return -1;
-}
-
-void list_del(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;
-
-#ifdef DEBUG_LIST
- printf("Reallocating list from %d to %d (count: %d)\n",
- p->alloc, p->alloc - LIST_ALLOC_LIMIT, p->count);
-#endif
- p->alloc -= LIST_ALLOC_LIMIT;
- new = malloc(p->alloc * sizeof(void *));
- memcpy(new, p->list, p->count * sizeof(void *));
- free(p->list);
- p->list = new;
- }
-}
-
-void list_del_item(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]);
- }
-
- list_del(p, n);
-}
-
-void list_do_empty(list_t *p)
-{
- p->count = 0;
-}
-
-void list_destroy(list_t *p)
-{
- assert(p != NULL);
-
- if (p->list != NULL) {
- free(p->list);
- }
-
- free(p);
-}
-
-void list_destroy_item(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]);
- }
-
- list_destroy(p);
-}
diff --git a/src/base/list.h b/src/base/list.h
deleted file mode 100644
index 7c9c610..0000000
--- a/src/base/list.h
+++ /dev/null
@@ -1,27 +0,0 @@
-#ifndef LIST_H
-#define LIST_H
-
-#include "main.h"
-
-#define LIST_ALLOC_LIMIT 16
-
-typedef struct list_str {
- void **list;
- int count;
- int alloc;
-} list_t;
-
-extern list_t *list_new();
-extern list_t *list_clone(list_t *p);
-extern list_t *list_clone_item(list_t *p, void *f);
-extern void list_add(list_t *p, void *item);
-extern void list_ins(list_t *p, int n, void *item);
-extern void *list_get(list_t *p, int n);
-extern int list_search(list_t *p, void *n);
-extern void list_del(list_t *p, int n);
-extern void list_del_item(list_t *p, int n, void *f);
-extern void list_do_empty(list_t *p);
-extern void list_destroy(list_t *p);
-extern void list_destroy_item(list_t *p, void *f);
-
-#endif /* LIST_H */
diff --git a/src/base/main.c b/src/base/main.c
deleted file mode 100644
index b2ab1f6..0000000
--- a/src/base/main.c
+++ /dev/null
@@ -1,186 +0,0 @@
-#include <time.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <signal.h>
-#include <unistd.h>
-#include <assert.h>
-#include <sys/stat.h>
-
-#ifdef __WIN32__
-#include <windows.h>
-#include <wininet.h>
-#endif /* __WIN32__ */
-
-#include "main.h"
-#include "tux.h"
-
-#ifndef PUBLIC_SERVER
-#include "game.h"
-#else /* PUBLIC_SERVER */
-#include "publicServer.h"
-#endif /* PUBLIC_SERVER */
-
-static int my_argc;
-static char **my_argv;
-
-char *getParam(char *s)
-{
- unsigned int len;
- int i;
-
- 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 && strchr(my_argv[i], '=') != NULL ) {
- return strchr(my_argv[i], '=') + 1;
- }
- }
-
- return NULL;
-}
-
-char *getParamElse(char *s1, char *s2)
-{
- char *ret;
- ret = getParam(s1);
-
- if (ret == NULL) {
- return s2;
- }
-
- return ret;
-}
-
-bool_t isParamFlag(char *s)
-{
- int i;
-
- for (i = 0; i < my_argc; i++) {
- if (strcmp(s, my_argv[i]) == 0) {
- return TRUE;
- }
- }
-
- return FALSE;
-}
-
-char *get_program_name()
-{
- return my_argv[0];
-}
-
-char *getString(int n)
-{
- char str[STR_NUM_SIZE];
- sprintf(str, "%d", n);
- return strdup(str);
-}
-
-char *get_string_static(int n)
-{
- static char str[STR_SIZE];
- sprintf(str, "%d", n);
-
- return str; /* !!! */
-}
-
-int *newInt(int x)
-{
- int *new;
-
- new = malloc(sizeof(int));
- *new = x;
-
- return new;
-}
-
-void accessExistFile(const char *s)
-{
- if (access(s, F_OK) != 0) {
- error("File not found [%s]", s);
- error("Shutting down the game");
- exit(-1);
- }
-}
-
-int tryExistFile(const char *s)
-{
- if (access(s, F_OK) != 0) {
- return 1;
- } else {
- return 0;
- }
-}
-
-int isFillPath(const char *path)
-{
- assert(path != NULL);
-
-#ifndef __WIN32__
- if (path[0] == '/') { /* for Unix-like systems ;) */
-#else /* __WIN32__ */
- if (path[1] == ':') { /* for Windows-like systems ;) */
-#endif /* __WIN32__ */
- return 1;
- }
-
- return 0;
-}
-
-#ifdef __WIN32__
-int WINAPI
-WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
-#else /* __WIN32__ */
-int main(int argc, char *argv[])
-#endif /* __WIN32__ */
-{
-#ifndef __WIN32__
- signal(SIGPIPE, SIG_IGN);
-#endif /* __WIN32__ */
-
- srand((unsigned) time(NULL));
-
-#ifdef NLS
- setlocale(LC_ALL, "");
- bindtextdomain(PACKAGE, PATH_LOCALE);
- bind_textdomain_codeset(PACKAGE, "UTF-8");
- textdomain(PACKAGE);
-#endif /* NLS */
-
-#ifndef __WIN32__
- my_argc = argc;
- my_argv = argv;
-#endif /* __WIN32__ */
-
-/*
- test_space();
- exit(0);
-*/
-
-#ifdef __WIN32__
- WORD wVersionRequested = MAKEWORD(1, 1); /* WinSock version */
- WSADATA data; /* WinSock information structure */
-
- /* let's initialize WinSock */
- if (WSAStartup(wVersionRequested, &data) != 0) {
- error("Initialization of WinSock failed");
- error("Shutting down the game");
- exit(-1);
- }
-#endif /* __WIN32__ */
-
-#ifndef PUBLIC_SERVER
- game_start();
-#else /* PUBLIC_SERVER */
- public_server_start();
-#endif /* PUBLIC_SERVER */
-
- return 0;
-}
diff --git a/src/base/main.h b/src/base/main.h
deleted file mode 100644
index cf380cd..0000000
--- a/src/base/main.h
+++ /dev/null
@@ -1,41 +0,0 @@
-#ifndef MAIN_H
-#define MAIN_H
-
-#ifdef NLS
-#include <libintl.h>
-#include <locale.h>
-#endif /* NLS */
-
-#include "bool.h"
-#include "string_length.h"
-#include "path.h"
-
-#define WINDOW_SIZE_X 800
-#define WINDOW_SIZE_Y 600
-
-#ifdef NLS
-#define _(text) gettext(text)
-#else /* NLS */
-#define _(text) (text)
-#endif /* NLS */
-
-#include "msg.h"
-
-#ifndef __WIN32__
-#define PATH_SEPARATOR "/"
-#else /* __WIN32__ */
-#define PATH_SEPARATOR "\\"
-#endif /* __WIN32__ */
-
-extern char *getParam(char *s);
-extern char *getParamElse(char *s1, char *s2);
-extern bool_t isParamFlag(char *s);
-extern char *get_program_name();
-extern char *getString(int n);
-extern char *get_string_static(int n);
-extern int *newInt(int x);
-extern int isFillPath(const char *path);
-extern void accessExistFile(const char *s);
-extern int tryExistFile(const char *s);
-
-#endif /* MAIN_H */
diff --git a/src/base/modules.c b/src/base/modules.c
deleted file mode 100644
index eab4506..0000000
--- a/src/base/modules.c
+++ /dev/null
@@ -1,317 +0,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <assert.h>
-
-#include "main.h"
-#include "list.h"
-#include "tux.h"
-#include "shot.h"
-#include "modules.h"
-#include "arena.h"
-#include "arenaFile.h"
-#include "proto.h"
-#include "shareFunction.h"
-
-#ifndef PUBLIC_SERVER
-#include "interface.h"
-#include "image.h"
-#include "layer.h"
-#include "configFile.h"
-#endif /* PUBLIC_SERVER */
-
-static export_fce_t export_fce = {
-#ifndef PUBLIC_SERVER
- .fce_addLayer = addLayer,
- .fce_image_get = image_get,
-#endif /* PUBLIC_SERVER */
- .fce_module_load_dep = module_load_dep,
- .fce_share_function_add = share_function_add,
- .fce_share_function_get = share_function_get,
-
- .fce_getValue = arena_file_get_value,
- .fce_net_multiplayer_get_game_type = net_multiplayer_get_game_type,
- .fce_tux_get_proportion = tux_get_proportion,
- .fce_tux_set_proportion = tux_set_proportion,
- .fce_tux_action = tux_action,
-
- .fce_timer_get_current_time = timer_get_current_time,
-
- .fce_arena_get_current = arena_get_current,
- .fce_arena_conflict_space = arena_conflict_space,
- .fce_arena_is_free_space = arena_is_free_space,
- .fce_arena_find_free_space = arena_find_free_space,
-
- .fce_proto_send_module_server = proto_send_module_server,
- .fce_proto_send_del_server = proto_send_del_server,
-#ifndef PUBLIC_SERVER
- .fce_proto_send_module_client = proto_send_module_client,
-#endif /* PUBLIC_SERVER */
- .fce_shot_destroy = shot_destroy,
- .fce_shot_bound_bombBall = shot_bound_bombBall,
- .fce_shot_transform_lasser = shot_transform_lasser
-};
-
-static list_t *listModule;
-static mod_reg_t mod_reglist;
-
-/* register module as valid */
-static mod_reg_t *mod_register(char *name, mod_sym_t *sym)
-{
- /* alloc and init context */
- mod_reg_t *mod = (mod_reg_t *) malloc(sizeof(mod_reg_t));
-
- if (!mod) {
- return 0;
- }
-
- mod->name = strdup(name);
- mod->sym = sym;
-
- /* add entry into list */
- mod->next = &mod_reglist;
- mod->prev = mod_reglist.prev;
- mod->prev->next = mod;
- mod->next->prev = mod;
-
- return mod;
-}
-
-/* free all unnecessary memory blocks from module's reglist */
-static void mod_destroy()
-{
- unsigned i;
- for (;;) {
- i = 0;
-
- mod_reg_t *mod;
- for (mod = mod_reglist.next; mod != &mod_reglist; mod = mod->next) {
- /* delete entry from context */
- mod->next->prev = mod->prev;
- mod->prev->next = mod->next;
-
- free(mod->name);
- free(mod);
-
- i++;
-
- break;
- }
-
- if (!i) {
- break;
- }
- }
-}
-
-static mod_reg_t *mod_find(char *name)
-{
- mod_reg_t *mod;
- for (mod = mod_reglist.next; mod != &mod_reglist; mod = mod->next) {
- if (!strcmp(mod->name, name)) {
- return mod;
- }
- }
-
- return 0;
-}
-
-static module_t *newModule(char *name)
-{
- assert(name != NULL);
-
- mod_reg_t *mod = mod_find(name);
-
- if (!mod) {
- error("Module [%s] is unavailable", name);
- return 0;
- }
-
- module_t *ret = malloc(sizeof(module_t));
-
- if (!ret) {
- return 0;
- }
-
- ret->name = strdup(name);
-
- if (!ret->name) {
- free(ret);
- return 0;
- }
-
- ret->fce_init = mod->sym->init;
-#ifndef PUBLIC_SERVER
- ret->fce_draw = mod->sym->draw;
-#endif /* PUBLIC_SERVER */
- ret->fce_event = mod->sym->event;
- ret->fce_destroy = mod->sym->destroy;
- ret->fce_isConflict = mod->sym->isConflict;
- ret->fce_cmd = mod->sym->cmdArena;
- ret->fce_recvMsg = mod->sym->recvMsg;
-
- debug("Loading module [%s]", name);
-
- if (ret->fce_init(&export_fce) != 0) {
- error("Unable to load module [%s]", name);
- free(ret->name);
- free(ret);
- return NULL;
- }
-
- return ret;
-}
-
-static int destroyModule(module_t *p)
-{
- assert(p != NULL);
-
- debug("Unloading module [%s]", p->name);
-
- p->fce_destroy();
-
- free(p->name);
- free(p);
-
- return 0;
-}
-
-void module_init()
-{
- listModule = list_new();
- share_function_init();
-
- mod_reglist.next = &mod_reglist;
- mod_reglist.prev = &mod_reglist;
-
- mod_register("libmodAI", &modai_sym);
- mod_register("libmodWall", &modwall_sym);
- mod_register("libmodPipe", &modpipe_sym);
- mod_register("libmodMove", &modmove_sym);
- mod_register("libmodBasic", &modbasic_sym);
- mod_register("libmodTeleport", &modteleport_sym);
-}
-
-int isModuleLoaded(char *name)
-{
- int i;
-
- 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;
-}
-
-int module_load(char *name)
-{
- module_t *module;
-
- if (isModuleLoaded(name)) {
- error("Unable to load already loaded module [%s]", name);
- return -1;
- }
-
- module = newModule(name);
-
- if (module == NULL) {
- error("Unable to load module [%s]", name);
- return -1;
- }
-
- list_add(listModule, module);
-
- return 0;
-}
-
-int module_load_dep(char *name)
-{
- if (isModuleLoaded(name)) {
- return 0;
- }
-
- return module_load(name);
-}
-
-void module_cmd(char *s)
-{
- int i;
-
- for (i = 0; i < listModule->count; i++) {
- module_t *this;
-
- this = (module_t *) listModule->list[i];
- this->fce_cmd(s);
- }
-}
-
-#ifndef PUBLIC_SERVER
-void module_draw(int x, int y, int w, int h)
-{
- 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);
- }
-}
-#endif /* PUBLIC_SERVER */
-
-void module_event()
-{
- int i;
-
- for (i = 0; i < listModule->count; i++) {
- module_t *this;
-
- this = (module_t *) listModule->list[i];
- this->fce_event();
- }
-}
-
-int module_is_conflict(int x, int y, int w, int h)
-{
- int i;
-
- 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;
-}
-
-int module_recv_msg(char *msg)
-{
- int i;
-
- for (i = 0; i < listModule->count; i++) {
- module_t *this;
-
- this = (module_t *) listModule->list[i];
- this->fce_recvMsg(msg);
- }
-
- return 0;
-}
-
-void module_quit()
-{
- list_destroy_item(listModule, destroyModule);
- share_function_quit();
-
- mod_destroy();
-}
diff --git a/src/base/modules.h b/src/base/modules.h
deleted file mode 100644
index 7cece8a..0000000
--- a/src/base/modules.h
+++ /dev/null
@@ -1,110 +0,0 @@
-#ifndef MODULE_H
-#define MODULE_H
-
-#include "tux.h"
-#include "shot.h"
-#include "arena.h"
-#include "proto.h"
-#include "myTimer.h"
-
-#ifndef PUBLIC_SERVER
-#include "image.h"
-#endif /* PUBLIC_SERVER */
-
-typedef struct export_fce_s {
- int (*fce_getValue) (char *line, char *env, char *val, int len);
-
-#ifndef PUBLIC_SERVER
- image_t *(*fce_image_get) (char *group, char *name);
-
- void (*fce_addLayer) (image_t *img, int x, int y, int px, int py,
- int w, int h, int player);
-#endif
-
- int (*fce_net_multiplayer_get_game_type) ();
- int (*fce_module_load_dep) (char *name);
- void (*fce_share_function_add) (char *name, void *function);
- void *(*fce_share_function_get) (char *name);
-
- void (*fce_tux_get_proportion) (tux_t *tux, int *x, int *y, int *w, int *h);
- void (*fce_tux_set_proportion) (tux_t *tux, int x, int y);
- tux_t *(*fce_getTuxID) (list_t *listTux, int id);
- void (*fce_tux_action) (tux_t *tux, int action);
-
- arena_t *(*fce_arena_get_current) ();
- int (*fce_arena_conflict_space) (int x1, int y1, int w1, int h1,
- int x2, int y2, int w2, int h2);
- int (*fce_arena_is_free_space) (arena_t *arena, int x, int y, int w, int h);
- void (*fce_arena_find_free_space) (arena_t *arena, int *x, int *y, int w, int h);
-
- void (*fce_proto_send_del_server)(int type, client_t *client, int id);
- void (*fce_proto_send_module_server) (int type, client_t *client, char *msg);
- void (*fce_proto_send_module_client) (char *msg);
-
- my_time_t(*fce_timer_get_current_time) ();
-
- void (*fce_shot_destroy) (shot_t *p);
- void (*fce_shot_bound_bombBall) (shot_t *shot);
- void (*fce_shot_transform_lasser) (shot_t *shot);
-} export_fce_t;
-
-typedef struct module_s {
- char *name;
-#ifndef __WIN32__
- void *image;
-#else /* __WIN32__ */
- HINSTANCE *image;
-#endif /* __WIN32__ */
-
- int (*fce_init) (export_fce_t *p);
-#ifndef PUBLIC_SERVER
- int (*fce_draw) (int x, int y, int w, int h);
-#endif /* PUBLIC_SERVER */
- int (*fce_event) ();
- int (*fce_isConflict) (int x, int y, int w, int h);
- void (*fce_cmd) (char *line);
- void (*fce_recvMsg) (char *msg);
- int (*fce_destroy) ();
-
-} module_t;
-
-/* module's call list */
-typedef struct {
- void *init;
- void *draw;
- void *event;
- void *isConflict;
- void *cmdArena;
- void *recvMsg;
- void *destroy;
-} mod_sym_t;
-
-/* structure of the registered modules */
-typedef struct mod_context {
- struct mod_context *next, *prev;
-
- char *name;
- mod_sym_t *sym;
-} mod_reg_t;
-
-/* available modules */
-extern mod_sym_t modai_sym;
-extern mod_sym_t modwall_sym;
-extern mod_sym_t modpipe_sym;
-extern mod_sym_t modmove_sym;
-extern mod_sym_t modbasic_sym;
-extern mod_sym_t modteleport_sym;
-
-extern void module_init();
-extern int module_load(char *name);
-extern int module_load_dep(char *name);
-#ifndef PUBLIC_SERVER
-extern void module_draw(int x, int y, int w, int h);
-#endif /* PUBLIC_SERVER */
-extern void module_event();
-extern void module_cmd(char *s);
-extern int module_is_conflict(int x, int y, int w, int h);
-extern int module_recv_msg(char *msg);
-extern void module_quit();
-
-#endif /* MODULES_H */
diff --git a/src/base/msg.h b/src/base/msg.h
deleted file mode 100644
index 403100c..0000000
--- a/src/base/msg.h
+++ /dev/null
@@ -1,18 +0,0 @@
-#ifndef MSG_H
-#define MSG_H
-
-#ifdef DEBUG
-#define debug(msg,arg...) fprintf(stdout, "%s ", _("[Debug]")); fprintf(stdout, _(msg), ##arg); fprintf(stdout, "\n")
-#else /* DEBUG */
-#define debug(msg,arg...)
-#endif /* DEBUG */
-
-#define warning(msg,arg...) fprintf(stderr, "%s ", _("[Warning]")); fprintf(stderr, _(msg), ##arg); fprintf(stderr, "\n")
-#define error(msg,arg...) fprintf(stderr, "%s ", _("[Error]")); fprintf(stderr, _(msg), ##arg); fprintf(stderr, "\n")
-#define fatal(msg,arg...) \
-{ \
- fprintf(stderr, "%s ", _("[Fatal]")); fprintf(stderr, _(msg), ##arg); fprintf(stderr, "\n"); \
- abort(); \
-}
-
-#endif /* MSG_H */
diff --git a/src/base/myTimer.c b/src/base/myTimer.c
deleted file mode 100644
index 5015cc6..0000000
--- a/src/base/myTimer.c
+++ /dev/null
@@ -1,157 +0,0 @@
-#include <time.h>
-#include <assert.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <sys/time.h>
-#include <signal.h>
-#ifdef __WIN32__
-#include <time.h>
-#endif /* __WIN32__ */
-
-#include "main.h"
-#include "list.h"
-#include "myTimer.h"
-#ifndef PUBLIC_SERVER
-#include "interface.h"
-#endif /* PUBLIC_SERVER */
-
-static struct timeval my_start = {.tv_sec = 0, .tv_usec = 0};
-
-list_t *timer_new()
-{
- return list_new();
-}
-
-void timer_restart()
-{
- gettimeofday(&my_start, NULL);
-}
-
-
-my_time_t timer_get_current_time()
-{
- struct timeval now;
- my_time_t ticks;
-
- if (my_start.tv_sec == 0 && my_start.tv_usec == 0) {
- timer_restart();
- }
-
- gettimeofday(&now, NULL);
- ticks = (now.tv_sec - my_start.tv_sec) * 1000 + (now.tv_usec - my_start.tv_usec) / 1000;
- /*printf("-> %d\n", ticks);*/
-
- return ticks;
-}
-
-my_time_t timer_get_current_timeMicro()
-{
- static struct timeval my_micro_start = {.tv_sec = 0,.tv_usec = 0 };
- struct timeval now;
- my_time_t ticks;
-
- if (my_micro_start.tv_sec == 0 && my_micro_start.tv_usec == 0) {
- gettimeofday(&my_micro_start, NULL);
- }
-
- gettimeofday(&now, NULL);
- ticks = (now.tv_sec - my_micro_start.tv_sec) * 1000 * 1000 + (now.tv_usec - my_micro_start.tv_usec);
- /*printf("-> %d\n", ticks);*/
-
- return ticks;
-}
-
-my_timer_t *timer_newItem(int type, void (*fce) (void *p), void *arg, my_time_t my_time)
-{
- static int new_id = 0;
- my_timer_t *new;
-
- 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 = timer_get_current_time();
- new->time = my_time;
-
- return new;
-}
-
-static void timer_destroyItem(my_timer_t *p)
-{
- assert(p != NULL);
- free(p);
-}
-
-int timer_add_task(list_t *listTimer, int type, void (*fce) (void *p), void *arg, my_time_t my_time)
-{
- my_timer_t *new;
-
- new = timer_newItem(type, fce, arg, my_time);
- list_add(listTimer, new);
-
- return new->id;
-}
-
-void timer_event(list_t *listTimer)
-{
- int i;
- my_timer_t *thisTimer;
- my_time_t currentTime;
-
- currentTime = timer_get_current_time();
-
- 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);
- list_del_item(listTimer, i, free);
- i--;
- }
- break;
- case TIMER_PERIODIC:
- if (currentTime >= thisTimer->createTime + thisTimer->time) {
- thisTimer->fce(thisTimer->arg);
- thisTimer->createTime = timer_get_current_time();
- }
- break;
- default:
- fatal("Bad setting of the timer");
- break;
- }
- }
-}
-
-void timer_del(list_t *listTimer, int id)
-{
- my_timer_t *thisTimer;
- int i;
-
- for (i = 0; i < listTimer->count; i++) {
- thisTimer = (my_timer_t *) listTimer->list[i];
-
- assert(thisTimer != NULL);
-
- if (thisTimer->id == (unsigned) id) {
- list_del_item(listTimer, i, free);
- return;
- }
- }
-
- error("Unable to delete event from the timer as it is not present in it [%d]", id);
- assert(0);
-}
-
-
-void timer_destroy(list_t *listTimer)
-{
- list_destroy_item(listTimer, timer_destroyItem);
-}
diff --git a/src/base/myTimer.h b/src/base/myTimer.h
deleted file mode 100644
index db05365..0000000
--- a/src/base/myTimer.h
+++ /dev/null
@@ -1,29 +0,0 @@
-#ifndef MY_TIME_H
-#define MY_TIME_H
-
-#include "main.h"
-#include "list.h"
-
-#define my_time_t unsigned int
-#define TIMER_ONE 0
-#define TIMER_PERIODIC 1
-
-typedef struct my_timer_struct {
- unsigned int id;
- void (*fce) (void *p);
- void *arg;
- int type;
- my_time_t createTime;
- my_time_t time;
-} my_timer_t;
-
-extern list_t *timer_new();
-extern void timer_restart();
-extern my_time_t timer_get_current_time();
-extern int timer_add_task(list_t *listTimer, int type, void (*fce) (void *p),
- void *arg, my_time_t my_time);
-extern void timer_event(list_t *listTimer);
-extern void timer_del(list_t *listTimer, int id);
-extern void timer_destroy(list_t *listTimer);
-
-#endif /* MY_TIME_H */
diff --git a/src/base/net_multiplayer.c b/src/base/net_multiplayer.c
deleted file mode 100644
index 9888f03..0000000
--- a/src/base/net_multiplayer.c
+++ /dev/null
@@ -1,138 +0,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <assert.h>
-#include <unistd.h>
-
-#include "main.h"
-#include "list.h"
-#include "tux.h"
-#include "item.h"
-#include "arenaFile.h"
-#include "net_multiplayer.h"
-#include "server.h"
-
-#include "udp.h"
-
-#ifndef PUBLIC_SERVER
-#include "setting.h"
-#include "choiceArena.h"
-
-#include "screen.h"
-#include "client.h"
-#endif /* PUBLIC_SERVER */
-
-static int netGameType;
-
-int net_multiplayer_get_game_type()
-{
- return netGameType;
-}
-
-int net_multiplayer_init_for_game_server(char *ip4, char *ip6, int port)
-{
- int ret;
-
- ret = server_init(ip4, ip6, port);
-
- if (ret > 0) {
- netGameType = NET_GAME_TYPE_SERVER;
- }
-
- return ret;
-}
-
-int net_multiplayer_init(int type, char *ip, int port, int proto)
-{
- netGameType = type;
-
- switch (netGameType) {
- case NET_GAME_TYPE_NONE:
- break;
-
- case NET_GAME_TYPE_SERVER:
- switch (proto) {
- case PROTO_UDPv4:
- if (server_init(ip, NULL, port) != 1) {
- error("Unable to initialize multiplayer game");
- netGameType = NET_GAME_TYPE_NONE;
- return -1;
- }
- break;
-
- case PROTO_UDPv6:
- if (server_init(NULL, ip, port) != 1) {
- error("Unable to initialize multiplayer game");
- netGameType = NET_GAME_TYPE_NONE;
- return -1;
- }
- break;
- }
- break;
-
-#ifndef PUBLIC_SERVER
- case NET_GAME_TYPE_CLIENT:
- if (client_init(ip, port) != 0) {
- error("Unable to join multiplayer game");
- netGameType = NET_GAME_TYPE_NONE;
- return -1;
- }
- break;
-#endif /* PUBLIC_SERVER */
-
- default:
- error("Unknown type of the network game [%d]", netGameType);
- assert(0);
- break;
- }
-
- return 0;
-}
-
-void net_multiplayer_event()
-{
- switch (netGameType) {
- case NET_GAME_TYPE_NONE:
- break;
-
- case NET_GAME_TYPE_SERVER:
- server_event();
- break;
-
-#ifndef PUBLIC_SERVER
- case NET_GAME_TYPE_CLIENT:
- client_event();
- break;
-#endif /* PUBLIC_SERVER */
-
- default:
- error("Unknown type of the network game [%d]", netGameType);
- assert(0);
- break;
- }
-}
-
-void net_multiplayer_quit()
-{
- switch (netGameType) {
- case NET_GAME_TYPE_NONE:
- break;
-
- case NET_GAME_TYPE_SERVER:
- server_quit();
- break;
-
-#ifndef PUBLIC_SERVER
- case NET_GAME_TYPE_CLIENT:
- client_quit();
- break;
-#endif /* PUBLIC_SERVER */
-
- default:
- error("Unknown type of the network game [%d]", netGameType);
- assert(0);
- break;
- }
-
- netGameType = NET_GAME_TYPE_NONE;
-}
diff --git a/src/base/net_multiplayer.h b/src/base/net_multiplayer.h
deleted file mode 100644
index c52b1ee..0000000
--- a/src/base/net_multiplayer.h
+++ /dev/null
@@ -1,37 +0,0 @@
-#ifndef NET_MULTIPLAYER_H
-#define NET_MULTIPLAYER_H
-
-#include "main.h"
-#include "tux.h"
-#include "item.h"
-#include "arena.h"
-
-#define PROTO_UDPv4 0
-#define PROTO_UDPv6 1
-
-#define NET_GAME_TYPE_NONE 0
-#define NET_GAME_TYPE_SERVER 1
-#define NET_GAME_TYPE_CLIENT 2
-
-#define NET_STATUS_OK 0
-#define NET_STATUS_ZOMBIE 1
-
-#define NET_PROTOCOL_TYPE_TCP 0
-#define NET_PROTOCOL_TYPE_UDP 1
-
-#define LIMIT_BUFFER 10240
-
-#define NET_MASTER_SERVER_DOMAIN "ms.tuxanci.org"
-#define NET_MASTER_SERVER "83.167.234.16"
-#define NET_MASTER_PORT 6800
-
-#ifdef PUBLIC_SERVER
-extern int net_multiplayer_init_for_game_server(char *ip4, char *ip6, int port);
-#endif /* PUBLIC_SERVER */
-
-extern int net_multiplayer_init(int type, char *ip, int port, int proto);
-extern int net_multiplayer_get_game_type();
-extern void net_multiplayer_event();
-extern void net_multiplayer_quit();
-
-#endif /* NET_MULTIPLAYER_H */
diff --git a/src/base/path.h.in b/src/base/path.h.in
deleted file mode 100644
index 8dfded9..0000000
--- a/src/base/path.h.in
+++ /dev/null
@@ -1,26 +0,0 @@
-#ifndef PATH_H
-#define PATH_H
-
-#include "main.h"
-
-#cmakedefine USE_MAGICK
-#define APPNAME "@APPNAME@"
-#ifdef __WIN32__
- #define PATH_DIR "data" PATH_SEPARATOR
-#else
- #define PATH_DIR "@CMAKE_DATA_PATH@" PATH_SEPARATOR APPNAME PATH_SEPARATOR
-#endif
-#define TUXANCI_VERSION "@TUXANCI_VERSION@"
-#define PREFIX "@CMAKE_INSTALL_PREFIX@" PATH_SEPARATOR
-#ifdef PUBLIC_SERVER
- #define SERVER_CONFIG "@CMAKE_CONF_PATH@" PATH_SEPARATOR APPNAME PATH_SEPARATOR "server.conf"
-#endif /* PUBLIC_SERVER */
-#define PATH_IMAGE PATH_DIR "images" PATH_SEPARATOR
-#define PATH_ARENA PATH_DIR "arena" PATH_SEPARATOR
-#define PATH_SOUND PATH_DIR "sound" PATH_SEPARATOR
-#define PATH_MUSIC PATH_DIR "music" PATH_SEPARATOR
-#define PATH_LOCALE "@CMAKE_LOCALE_PATH@" PATH_SEPARATOR
-#define PATH_DOC "@CMAKE_DOC_PATH@" PATH_SEPARATOR
-#define PACKAGE APPNAME
-
-#endif /* PATH_H */
diff --git a/src/base/protect.c b/src/base/protect.c
deleted file mode 100644
index 754fa26..0000000
--- a/src/base/protect.c
+++ /dev/null
@@ -1,86 +0,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <assert.h>
-
-#include "main.h"
-#include "myTimer.h"
-#include "protect.h"
-
-protect_t *newProtect()
-{
- protect_t *new;
-
- new = malloc(sizeof(protect_t));
- new->lastMove = timer_get_current_time();
- new->lastPing = timer_get_current_time();
- new->avarage = 0;
- new->count = 0;
- new->isDown = FALSE;
-
- return new;
-}
-
-void refreshLastMove(protect_t *p)
-{
- my_time_t currentTime;
- my_time_t interval;
-
- currentTime = timer_get_current_time();
- interval = currentTime - p->lastMove;
-
- p->lastMove = timer_get_current_time();
- p->avarage += interval;
- p->count++;
-
- if (p->count == PROTECT_SPEED_AVARAGE) {
- int my_index;
-
- my_index = p->avarage / PROTECT_SPEED_AVARAGE;
- p->avarage = 0;
- p->count = 0;
-
-/*
- if (my_index < PROTECT_SPEED_INTERVAL_TIMEOUT) {
- p->isDown = TRUE;
- }
-*/
-
- /*printf("speed index = %d\n", my_index);*/
- }
-}
-
-void rereshLastPing(protect_t *p)
-{
- /*
- my_time_t currentTime;
- my_time_t interval;
- currentTime = timer_get_current_time();
- interval = currentTime - p->lastPing;
- */
-
- p->lastPing = timer_get_current_time();
-
- /*printf("interval = %d\n", interval);*/
-}
-
-bool_t isDown(protect_t *p)
-{
- my_time_t currentTime;
- my_time_t interval;
-
- currentTime = timer_get_current_time();
- interval = currentTime - p->lastPing;
-
- if (interval > PROTECT_PING_INTERVAL_TIMEOUT) {
- p->isDown = TRUE;
- }
-
- return p->isDown;
-}
-
-void destroyProtect(protect_t *p)
-{
- assert(p != NULL);
- free(p);
-}
diff --git a/src/base/protect.h b/src/base/protect.h
deleted file mode 100644
index 1a55ef7..0000000
--- a/src/base/protect.h
+++ /dev/null
@@ -1,25 +0,0 @@
-#ifndef PROTECT_H
-#define PROTECT_H
-
-#include "main.h"
-#include "myTimer.h"
-
-#define PROTECT_PING_INTERVAL_TIMEOUT 5000
-#define PROTECT_SPEED_INTERVAL_TIMEOUT 40
-#define PROTECT_SPEED_AVARAGE 10
-
-typedef struct protect_struct {
- my_time_t lastPing;
- my_time_t lastMove;
- my_time_t avarage;
- int count;
- bool_t isDown;
-} protect_t;
-
-extern protect_t *newProtect();
-extern void refreshLastMove(protect_t *p);
-extern void rereshLastPing(protect_t *p);
-extern bool_t isDown(protect_t *p);
-extern void destroyProtect(protect_t *p);
-
-#endif /* PROTECT_H */
diff --git a/src/base/proto.c b/src/base/proto.c
deleted file mode 100644
index 422a304..0000000
--- a/src/base/proto.c
+++ /dev/null
@@ -1,937 +0,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <assert.h>
-
-#include "main.h"
-#include "list.h"
-#include "tux.h"
-#include "item.h"
-#include "shot.h"
-#include "arenaFile.h"
-#include "myTimer.h"
-#include "server.h"
-#include "proto.h"
-#include "net_multiplayer.h"
-#include "checkFront.h"
-#include "idManager.h"
-#include "modules.h"
-#include "protect.h"
-#include "serverSendMsg.h"
-
-#ifndef PUBLIC_SERVER
-#include "world.h"
-#include "setting.h"
-#include "choiceArena.h"
-#include "analyze.h"
-#include "downArena.h"
-#include "client.h"
-#include "term.h"
-#include "radar.h"
-#include "chat.h"
-#else /* PUBLIC_SERVER*/
-#include "highScore.h"
-#include "publicServer.h"
-#include "serverConfigFile.h"
-#endif /* PUBLIC_SERVER*/
-
-void proto_send_error_server(int type, client_t *client, int errorcode)
-{
- char msg[STR_PROTO_SIZE];
-
- snprintf(msg, STR_PROTO_SIZE, "error %d\n", errorcode);
-
- send_msg_to_client(type, client, msg, CHECK_FRONT_TYPE_SIMPLE, CHECK_FRONT_ID_NONE);
-}
-
-#ifndef PUBLIC_SERVER
-void proto_recv_error_client(char *msg)
-{
- char cmd[STR_PROTO_SIZE];
- int errorcode;
- int recv_count;
-
- assert(msg != NULL);
-
- recv_count = sscanf(msg, "%s %d", cmd, &errorcode);
-
- if (recv_count != 2) {
- return;
- }
-
- debug("Communication error [%d]", errorcode);
-
- switch (errorcode) {
- case PROTO_ERROR_CODE_BAD_VERSION:
- analyze_set_msg(_("Cannot connect to the server. You have incompatible version of the game."));
- world_do_end();
- break;
- case PROTO_ERROR_CODE_TIMEOUT:
- analyze_set_msg(_("Connection timeout"));
- world_do_end();
- break;
- case PROTO_ERROR_LIMIT_MAX_CLIENT:
- analyze_set_msg(_("Server is full"));
- world_do_end();
- break;
- }
-}
-
-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);
-
- debug("Sending: %s", msg);
- client_send(msg);
-}
-#endif /* PUBLIC_SERVER */
-
-static void action_sendItem(space_t *space, item_t *item, client_t *client)
-{
- proto_send_additem_server(PROTO_SEND_ONE, client, item);
-}
-
-static void sendInfoCreateClient(client_t *client)
-{
- list_t *listClient;
- client_t *thisClient;
- tux_t *thisTux;
- int i;
-
- assert(client != NULL);
-
- listClient = server_get_list_clients();
-
- proto_send_init_server(PROTO_SEND_ONE, client, client);
-
-#ifndef PUBLIC_SERVER
- proto_send_newtux_server(PROTO_SEND_ONE, client, world_get_control_tux(TUX_CONTROL_KEYBOARD_RIGHT));
-#endif /* PUBLIC_SERVER */
-
- for (i = 0; i < listClient->count; i++) {
- thisClient = (client_t *) listClient->list[i];
- thisTux = thisClient->tux;
-
- /* odosli kazdemu stremu hracovy informacie o novom hracovy */
- /* send to all players information about new player */
- if (thisTux != NULL && thisTux != client->tux) {
- proto_send_newtux_server(PROTO_SEND_ONE, thisClient, client->tux);
- }
-
- /* send to new players information about all players, including himself */
- if (thisTux != NULL) {
- proto_send_newtux_server(PROTO_SEND_ONE, client, thisTux);
- }
- }
-
- space_action(arena_get_current()->spaceItem, action_sendItem, client);
-
-/*
- for (i = 0; i < arena_get_current()->spaceItem->listIndex->count; i++) {
- thisItem = (item_t *) arena_get_current()->spaceItem->list->list[i];
- proto_send_additem_server(PROTO_SEND_ONE, client, thisItem);
- }
-*/
-}
-
-void proto_recv_hello_server(client_t *client, char *msg)
-{
- 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 (space_get_count(arena_get_current()->spaceTux) + 1 > server_get_max_clients()) {
- proto_send_error_server(PROTO_SEND_ONE, client, PROTO_ERROR_LIMIT_MAX_CLIENT);
- check_front_event(client);
- client->status = NET_STATUS_ZOMBIE;
- return;
- }
-
- strcpy(version, "");
- strcpy(name, "");
-
- if (supportVersion == NULL) {
-#ifndef PUBLIC_SERVER
- supportVersion = TUXANCI_VERSION;
-#else /* PUBLIC_SERVER */
- supportVersion = public_server_get_setting("SUPPORT_CLIENTS", "--support-clients", TUXANCI_VERSION);
-#endif /* PUBLIC_SERVER */
- }
-
- recv_count = sscanf(msg, "%s %s %s", cmd, version, name);
-
- if (recv_count != 3) {
- return;
- }
-
- if (strstr(supportVersion, version) == NULL) {
- proto_send_error_server(PROTO_SEND_ONE, client, PROTO_ERROR_CODE_BAD_VERSION);
- check_front_event(client);
- client->status = NET_STATUS_ZOMBIE;
- return;
- }
-
- client->tux = tux_new();
- client->tux->control = TUX_CONTROL_NET;
- client->tux->client = client;
-
- space_add(arena_get_current()->spaceTux, client->tux);
-
- if (strlen(name) > STR_NAME_SIZE - 1) {
- name[STR_NAME_SIZE - 1] = '\0';
- }
-
- tux_set_name(client->tux, name);
- sendInfoCreateClient(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;
-
-#ifndef PUBLIC_SERVER
- name = "NewServer";
-#endif /* PUBLIC_SERVER */
-
-#ifdef PUBLIC_SERVER
- name = public_server_get_setting("NAME", "--name", "noname");
-#endif /* PUBLIC_SERVER */
-
- version = TUXANCI_VERSION;
- clients = arena_get_current()->spaceTux->listIndex->count;
- maxclients = server_get_max_clients();
- uptime = (unsigned int) server_get_update();
- arena = arena_file_get_net_name(choice_arena_get());
-
- snprintf(msg, STR_PROTO_SIZE,
- "name: %s\n"
- "version: %s\n"
- "clients: %d\n"
- "maxclients: %d\n"
- "uptime: %d\n"
- "arena: %s\n",
- name, version, clients, maxclients, uptime, arena);
-
- send_msg_to_client(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)
-{
- proto_send_status_server(PROTO_SEND_ONE, client);
-}
-
-#ifndef PUBLIC_SERVER
-void proto_send_check_client(int id)
-{
- char msg[STR_PROTO_SIZE];
-
- snprintf(msg, STR_PROTO_SIZE, "check %d\n", id);
- client_send(msg);
-}
-#else /* PUBLIC_SERVER */
-void proto_send_listscore_server(int type, client_t *client, int max)
-{
- char *str;
- char *msg;
- int i;
-
- msg = malloc((max * 48) * sizeof(char));
- strcpy(msg, "");
-
- for (i = 0; i < max; i++) {
- str = high_score_get_table(i);
-
- if (str == NULL) {
- break;
- }
-
- strcat(msg, str);
- strcat(msg, "\n");
- }
-
- /*proto_send(type, client, msg);*/
- send_msg_to_client(type, client, msg, CHECK_FRONT_TYPE_SIMPLE, CHECK_FRONT_ID_NONE);
- free(msg);
-}
-
-void proto_recv_listscore_server(client_t *client, char *msg)
-{
- char cmd[STR_PROTO_SIZE];
- int recv_count;
- int max;
-
- assert(msg != NULL);
-
- recv_count = sscanf(msg, "%s %d", cmd, &max);
-
- if (recv_count != 2) {
- max = HIGHSCORE_MAX_PLAYERS;
- }
-
- proto_send_listscore_server(PROTO_SEND_ONE, client, max);
-}
-#endif /* PUBLIC_SERVER */
-
-void proto_recv_check_server(client_t *client, char *msg)
-{
- char cmd[STR_PROTO_SIZE];
- int recv_count;
- int id;
-
- assert(msg != NULL);
-
- recv_count = sscanf(msg, "%s %d", cmd, &id);
-
- if (recv_count != 2) {
- return;
- }
-
- check_front_del_msg(client->listSendMsg, id);
-}
-
-void proto_send_init_server(int type, client_t *client, client_t *client2)
-{
- char msg[STR_PROTO_SIZE];
- int count;
- int check_id;
-
- assert(client2 != NULL);
-
- count = WORLD_COUNT_ROUND_UNLIMITED;
-
-#ifndef PUBLIC_SERVER
- public_server_get_settingCountRound(&count);
-#endif /* PUBLIC_SERVER */
-
- check_id = id_get_newcount(0);
-
- snprintf(msg, STR_PROTO_SIZE, "init %d %d %d %d %s %d\n",
- client2->tux->id, client2->tux->x, client2->tux->y,
- count, arena_file_get_net_name(choice_arena_get()), check_id);
-
- /*proto_send(type, client, msg);*/
- send_msg_to_client(type, client, msg, CHECK_FRONT_TYPE_CHECK, check_id);
-}
-
-#ifndef PUBLIC_SERVER
-void proto_recv_init_client(char *msg)
-{
- char cmd[STR_PROTO_SIZE];
- 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);
-
- 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;
- }
-
- proto_send_check_client(check_id);
-
- if (arena_get_current() != NULL) {
- return;
- }
-
- world_set_arena(arena_file_get_file_format_net_name(arena_name));
-
- arena = arena_get_current();
- arena->max_countRound = n;
-
- tux = tux_new();
- tux_replace_id(tux, id);
- tux->x = x;
- tux->y = y;
- tux->control = TUX_CONTROL_KEYBOARD_RIGHT;
- world_set_control_tux(tux, TUX_CONTROL_KEYBOARD_RIGHT);
-
- public_server_get_setting_name_right(tux->name);
-
- space_add(arena->spaceTux, tux);
-}
-#endif /* PUBLIC_SERVER */
-
-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);*/
- send_msg_to_client(type, client, msg, CHECK_FRONT_TYPE_SIMPLE, CHECK_FRONT_ID_NONE);
-}
-
-#ifndef PUBLIC_SERVER
-void proto_recv_event_client(char *msg)
-{
- char cmd[STR_PROTO_SIZE];
- int id, action;
- tux_t *tux;
- int recv_count;
-
- assert(msg != NULL);
-
- recv_count = sscanf(msg, "%s %d %d", cmd, &id, &action);
-
- if (recv_count != 3) {
- return;
- }
-
- tux = space_get_object_id(arena_get_current()->spaceTux, id);
-
- if (tux != NULL) {
- tux_action(tux, action);
- radar_add(tux->id, tux->x, tux->y, RADAR_TYPE_TUX);
- }
-}
-
-void proto_send_event_client(int action)
-{
- char msg[STR_PROTO_SIZE];
-
- snprintf(msg, STR_PROTO_SIZE, "event %d\n", action);
-
- client_send(msg);
-}
-#endif /* PUBLIC_SERVER */
-
-void proto_recv_event_server(client_t *client, char *msg)
-{
- char cmd[STR_PROTO_SIZE];
- int action;
- int recv_count;
-
- assert(client != NULL);
- assert(msg != NULL);
-
- /*debug_interval();*/
-
- recv_count = sscanf(msg, "%s %d", cmd, &action);
-
- if (recv_count != 2) {
- return;
- }
-
- if (client->tux->bonus != BONUS_HIDDEN) {
- proto_send_event_server(PROTO_SEND_ALL_SEES_TUX, client, client->tux, action);
- }
-
- refreshLastMove(client->protect);
-
- tux_action(client->tux, action);
-}
-
-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 {
- tux_get_proportion(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);*/
- send_msg_to_client(type, client, msg, CHECK_FRONT_TYPE_SIMPLE,
- CHECK_FRONT_ID_NONE);
-}
-
-#ifndef PUBLIC_SERVER
-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 (arena_get_current() == 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 = space_get_object_id(arena_get_current()->spaceTux, id);
-
- if (tux != NULL) {
- assert(tux->id == id);
- }
-
- if (tux == NULL) {
- tux = tux_new();
- tux_replace_id(tux, id);
- tux->control = TUX_CONTROL_NET;
- space_add(arena_get_current()->spaceTux, tux);
- }
-
- if (tux->control == TUX_CONTROL_KEYBOARD_RIGHT &&
- x == TUX_LOCATE_UNKNOWN && y == TUX_LOCATE_UNKNOWN) {
- tux_get_proportion(tux, &x, &y, NULL, NULL);
- }
-
- radar_add(id, x, y, RADAR_TYPE_TUX);
-
- if (tux->bonus == BONUS_HIDDEN) {
- radar_del(id);
- }
-
- space_move_object(arena_get_current()->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 /* PUBLIC_SERVER */
-
-void proto_send_kill_server(int type, client_t *client, tux_t *tux)
-{
- char msg[STR_PROTO_SIZE];
-
- assert(tux != NULL);
-
- snprintf(msg, STR_PROTO_SIZE, "kill %d\n", tux->id);
-
- /*proto_send(type, client, msg);*/
- send_msg_to_client(type, client, msg, CHECK_FRONT_TYPE_SIMPLE, CHECK_FRONT_ID_NONE);
-}
-
-#ifndef PUBLIC_SERVER
-void proto_recv_kill_client(char *msg)
-{
- char cmd[STR_PROTO_SIZE];
- int id;
- tux_t *tux;
- int recv_count;
-
- assert(msg != NULL);
-
- recv_count = sscanf(msg, "%s %d", cmd, &id);
-
- if (recv_count != 2) {
- return;
- }
-
- tux = space_get_object_id(arena_get_current()->spaceTux, id);
-
- if (tux != NULL) {
- tux_event_tux_is_dead(tux);
- }
-}
-#endif /* PUBLIC_SERVER */
-
-void proto_send_del_server(int type, client_t *client, int id)
-{
- char msg[STR_PROTO_SIZE];
- int check_id;
-
- check_id = id_get_newcount(0);
-
- snprintf(msg, STR_PROTO_SIZE, "del %d %d\n", id, check_id);
-
- send_msg_to_client(type, client, msg, CHECK_FRONT_TYPE_CHECK, check_id);
- /*proto_check(type, client, msg, check_id);*/
-}
-
-#ifndef PUBLIC_SERVER
-
-void timer_delShot(void *p)
-{
- shot_t *shot;
- int *id;
-
- assert( p != NULL );
- id = (int *) p;
-
- shot = space_get_object_id(arena_get_current()->spaceShot, *id);
-
- if (shot != NULL) {
- radar_del(shot->id);
- space_del_with_item(arena_get_current()->spaceShot, shot, shot_destroy);
- }
-
- free(p);
-}
-
-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 = space_get_object_id(arena_get_current()->spaceTux, id);
-
- if (tux != NULL) {
- radar_del(id);
- space_del_with_item(arena_get_current()->spaceTux, tux, tux_destroy);
- return;
- }
-
- shot = space_get_object_id(arena_get_current()->spaceShot, id);
-
- if (shot != NULL) {
- /*
- printf("delete shot..\n");
- radar_del(id);
- space_del_with_item(arena_get_current()->spaceShot, shot, shot_destroy);
- */
- timer_add_task(arena_get_current()->listTimer, TIMER_ONE, timer_delShot, newInt(id), 50);
- return;
- }
-
- item = space_get_object_id(arena_get_current()->spaceItem, id);
-
- if (item != NULL) {
- /*printf("delete item..\n");*/
- radar_del(id);
- space_del_with_item(arena_get_current()->spaceItem, item, item_destroy);
- return;
- }
-}
-#endif /* PUBLIC_SERVER */
-
-void proto_send_additem_server(int type, client_t *client, item_t *p)
-{
- char msg[STR_PROTO_SIZE];
- int check_id;
-
- assert(p != NULL);
-
- check_id = id_get_newcount(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);
-
- /*
- proto_send(type, client, msg);
- proto_check(type, client, msg, check_id);
- */
- send_msg_to_client(type, client, msg, CHECK_FRONT_TYPE_CHECK, check_id);
-}
-
-#ifndef PUBLIC_SERVER
-void proto_recv_additem_client(char *msg)
-{
- char cmd[STR_PROTO_SIZE];
- int id, type, x, y, count, frame, author_id, check_id;
- item_t *item;
- int recv_count;
-
- assert(msg != NULL);
-
- if (arena_get_current() == 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);
-
- if (recv_count != 9) {
- return;
- }
-
- proto_send_check_client(check_id);
-
- if ((item = space_get_object_id(arena_get_current()->spaceItem, id)) != NULL) {
- return;
- }
-
- if (type != ITEM_MINE && type != ITEM_EXPLOSION &&
- type != ITEM_BIG_EXPLOSION) {
- radar_add(id, x, y, RADAR_TYPE_ITEM);
- }
-
- item = item_new(x, y, type, author_id);
-
- item_replace_id(item, id);
- item->count = count;
- item->frame = frame;
-
- space_add(arena_get_current()->spaceItem, item);
-}
-#endif /* PUBLIC_SERVER */
-
-void proto_send_shot_server(int type, client_t *client, shot_t *p)
-{
- char msg[STR_PROTO_SIZE];
-
- 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);
-
- /*
- proto_send(type, client, msg);
- proto_check(type, client, msg, check_id);
- */
- send_msg_to_client(type, client, msg, CHECK_FRONT_TYPE_SIMPLE, CHECK_FRONT_ID_NONE);
-}
-
-#ifndef PUBLIC_SERVER
-void proto_recv_shot_client(char *msg)
-{
- char cmd[STR_PROTO_SIZE];
- int x, y, px, py, position, gun, shot_id, author_id, isCanKillAuthor;
- shot_t *shot;
- int recv_count;
-
- 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);
-
- if (recv_count != 10) {
- return;
- }
-
- if ((shot = space_get_object_id(arena_get_current()->spaceShot, shot_id)) != NULL) {
- space_del_with_item(arena_get_current()->spaceShot, shot, shot_destroy);
- /*return;*/
- }
-
- shot = shot_new(x, y, px, py, gun, author_id);
-
- shot_replace_id(shot, shot_id);
- shot->isCanKillAuthor = isCanKillAuthor;
- shot->position = position;
-
- if (shot->gun == GUN_LASSER) {
- shot_transform_lasser(shot);
- }
-
- space_add(arena_get_current()->spaceShot, shot);
-}
-
-void proto_send_chat_client(char *s)
-{
- char msg[STR_PROTO_SIZE];
- snprintf(msg, STR_PROTO_SIZE, "chat %s\n", s);
- client_send(msg);
-}
-#endif /* PUBLIC_SERVER */
-
-void proto_recv_chat_server(client_t *client, char *msg)
-{
- char out[STR_PROTO_SIZE];
- int len;
-
- if (client->tux == NULL) {
- return;
- }
-
- len = strlen(msg);
- msg[len - 1] = '\0';
-
- snprintf(out, STR_PROTO_SIZE, "chat %s:%s\n", client->tux->name, msg + 5);
-
- proto_send_chat_server(PROTO_SEND_ALL, NULL, out);
-}
-
-void proto_send_chat_server(int type, client_t *client, char *msg)
-{
- send_msg_to_client(type, client, msg, CHECK_FRONT_TYPE_SIMPLE, CHECK_FRONT_ID_NONE);
-
-#ifndef PUBLIC_SERVER
- proto_recv_chat_client(msg);
-#endif /* PUBLIC_SERVER */
-}
-
-#ifndef PUBLIC_SERVER
-void proto_recv_chat_client(char *msg)
-{
- int len;
-
- assert(msg != NULL);
-
- len = strlen(msg);
- msg[len - 1] = '\0';
-
- chat_add(msg + 5);
-}
-
-void proto_send_module_client(char *msg)
-{
- char out[STR_PROTO_SIZE];
-
- snprintf(out, STR_PROTO_SIZE, "module %s\n", msg);
-
-/*
- strcpy(out, "modules ");
- strcat(out, msg);
- strcat(out, "\n");
-*/
-
- client_send(out);
-}
-#endif /* PUBLIC_SERVER */
-
-void proto_recv_module_server(client_t *client, char *msg)
-{
- module_recv_msg(msg + 7);
-}
-
-void proto_send_module_server(int type, client_t *client, char *msg)
-{
- char out[STR_PROTO_SIZE];
-
- snprintf(out, STR_PROTO_SIZE, "module %s\n", msg);
-
-/*
- strcpy(out, "modules ");
- strcat(out, msg);
- strcat(out, "\n");
-*/
-
- send_msg_to_client(type, client, out, CHECK_FRONT_TYPE_SIMPLE, CHECK_FRONT_ID_NONE);
-}
-
-#ifndef PUBLIC_SERVER
-void proto_recv_module_client(char *msg)
-{
- module_recv_msg(msg + 7);
-}
-
-void proto_send_ping_client()
-{
- char msg[STR_PROTO_SIZE];
- snprintf(msg, STR_PROTO_SIZE, "ping\n");
- client_send(msg);
-}
-#endif /* PUBLIC_SERVER */
-
-void proto_recv_ping_server(client_t *client, char *msg)
-{
-}
-
-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);*/
- send_msg_to_client(type, client, msg, CHECK_FRONT_TYPE_SIMPLE, CHECK_FRONT_ID_NONE);
-}
-
-#ifndef PUBLIC_SERVER
-void proto_recv_ping_client(char *msg)
-{
-}
-#endif /* PUBLIC_SERVER */
-
-void proto_recv_echo_server(client_t *client, char *msg)
-{
- 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)
-{
- char msg[STR_PROTO_SIZE];
-
- snprintf(msg, STR_PROTO_SIZE, "echo%s", s);
- /*proto_send(type, client, msg);*/
- send_msg_to_client(type, client, msg, CHECK_FRONT_TYPE_SIMPLE, CHECK_FRONT_ID_NONE);
-}
-
-void proto_send_end_server(int type, client_t *client)
-{
- char msg[STR_PROTO_SIZE];
-
- snprintf(msg, STR_PROTO_SIZE, "end\n");
- /*proto_send(type, client, msg);*/
- send_msg_to_client(type, client, msg, CHECK_FRONT_TYPE_SIMPLE, CHECK_FRONT_ID_NONE);
-}
-
-#ifndef PUBLIC_SERVER
-void proto_recv_end_client(char *msg)
-{
- assert(msg != NULL);
-
- world_do_end();
-}
-
-void proto_send_end_client()
-{
- char msg[STR_PROTO_SIZE];
-
- snprintf(msg, STR_PROTO_SIZE, "end\n");
- client_send(msg);
-}
-#endif /* PUBLIC_SERVER */
-
-void proto_recv_end_server(client_t *client, char *msg)
-{
- assert(msg != NULL);
- assert(client != NULL);
-
- client->status = NET_STATUS_ZOMBIE;
-}
diff --git a/src/base/proto.h b/src/base/proto.h
deleted file mode 100644
index a743b8c..0000000
--- a/src/base/proto.h
+++ /dev/null
@@ -1,98 +0,0 @@
-#ifndef MY_PROTO_H
-#define MY_PROTO_H
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <assert.h>
-
-#include "main.h"
-#include "list.h"
-#include "item.h"
-#include "shot.h"
-#include "arenaFile.h"
-#include "myTimer.h"
-#include "server.h"
-#include "net_multiplayer.h"
-
-#ifndef PUBLIC_SERVER
-#include "world.h"
-#include "setting.h"
-#include "choiceArena.h"
-#include "client.h"
-#else /* PUBLIC_SERVER */
-#include "publicServer.h"
-#endif /* PUBLIC_SERVER */
-
-#define PROTO_ERROR_CODE_UNKNOWN 0
-#define PROTO_ERROR_CODE_BAD_VERSION 1
-#define PROTO_ERROR_CODE_BAD_NAME 2
-#define PROTO_ERROR_CODE_BAD_COMMAND 3
-#define PROTO_ERROR_CODE_TIMEOUT 4
-#define PROTO_ERROR_LIMIT_MAX_CLIENT 5
-
-extern void proto_send_error_server(int type, client_t *client, int errorcode);
-extern void proto_recv_error_client(char *msg);
-
-extern void proto_send_hello_client(char *name);
-extern void proto_recv_hello_server(client_t *client, char *msg);
-
-extern void proto_send_status_server(int type, client_t *client);
-extern void proto_recv_status_server(client_t *client, char *msg);
-
-extern void proto_send_listscore_server(int type, client_t *client, int max);
-extern void proto_recv_listscore_server(client_t *client, char *msg);
-
-extern void proto_send_check_client(int id);
-extern void proto_recv_check_server(client_t *client, char *msg);
-
-extern void proto_send_init_server(int type, client_t *client, client_t *client2);
-extern void proto_recv_init_client(char *msg);
-
-extern void proto_send_event_server(int type, client_t *client, tux_t *tux, int action);
-extern void proto_recv_event_client(char *msg);
-extern void proto_send_event_client(int action);
-extern void proto_recv_event_server(client_t *client, char *msg);
-
-extern void proto_send_newtux_server(int type, client_t *client, tux_t *tux);
-extern void proto_recv_newtux_client(char *msg);
-
-extern void proto_send_kill_server(int type, client_t *client, tux_t *tux);
-extern void proto_recv_kill_client(char *msg);
-
-extern void proto_send_score_server(int type, client_t *client, tux_t *tux);
-extern void proto_recv_score_client(char *msg);
-
-extern void proto_send_del_server(int type, client_t *client, int id);
-extern void proto_recv_del_client(char *msg);
-
-extern void proto_send_additem_server(int type, client_t *client, item_t *p);
-extern void proto_recv_additem_client(char *msg);
-
-extern void proto_send_shot_server(int type, client_t *client, shot_t *p);
-extern void proto_recv_shot_client(char *msg);
-
-extern void proto_send_chat_client(char *s);
-extern void proto_recv_chat_server(client_t *client, char *msg);
-extern void proto_send_chat_server(int type, client_t *client, char *msg);
-extern void proto_recv_chat_client(char *msg);
-
-extern void proto_send_module_client(char *s);
-extern void proto_recv_module_server(client_t *client, char *msg);
-extern void proto_send_module_server(int type, client_t *client, char *msg);
-extern void proto_recv_module_client(char *msg);
-
-extern void proto_send_ping_client();
-extern void proto_recv_ping_server(client_t *client, char *msg);
-extern void proto_send_ping_server(int type, client_t *client);
-extern void proto_recv_ping_client(char *msg);
-
-extern void proto_recv_echo_server(client_t *client, char *msg);
-extern void proto_send_echo_server(int type, client_t *client, char *s);
-
-extern void proto_send_end_server(int type, client_t *client);
-extern void proto_recv_end_client(char *msg);
-extern void proto_send_end_client();
-extern void proto_recv_end_server(client_t *client, char *msg);
-
-#endif /* MY_PROTO_H */
diff --git a/src/base/server.c b/src/base/server.c
deleted file mode 100644
index 6f26859..0000000
--- a/src/base/server.c
+++ /dev/null
@@ -1,383 +0,0 @@
-#ifndef __WIN32__
-#include <sys/socket.h>
-#include <sys/types.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <netdb.h>
-#else /* __WIN32__ */
-#include <windows.h>
-#include <wininet.h>
-#endif /* __WIN32__ */
-
-#include <unistd.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <assert.h>
-#include <fcntl.h>
-
-#include "main.h"
-#include "list.h"
-#include "tux.h"
-#include "proto.h"
-#include "server.h"
-#include "myTimer.h"
-#include "arena.h"
-#include "net_multiplayer.h"
-#include "checkFront.h"
-#include "protect.h"
-#include "index.h"
-#include "serverSelect.h"
-#include "serverSendMsg.h"
-#include "downServer.h"
-
-#ifndef PUBLIC_SERVER
-#include "world.h"
-#else /* PUBLIC_SERVER */
-#include "publicServer.h"
-#include "highScore.h"
-#endif /* PUBLIC_SERVER */
-
-#include "udp_server.h"
-
-static list_t *listClient;
-
-static list_t *listServerTimer;
-static time_t timeUpdate;
-static int maxClients;
-
-typedef struct proto_cmd_server_struct {
- 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},
-#ifdef PUBLIC_SERVER
- {.name = "list",.len = 4,.tux = 0,.fce_proto = proto_recv_listscore_server},
-#endif /* PUBLIC_SERVER */
- {.name = "event",.len = 5,.tux = 1,.fce_proto = proto_recv_event_server},
- {.name = "check",.len = 5,.tux = 1,.fce_proto = proto_recv_check_server},
- {.name = "module",.len = 6,.tux = 1,.fce_proto = proto_recv_module_server},
- {.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)
-{
- int len;
- int i;
-
- len = strlen(msg);
-
- for (i = 0; proto_cmd_list[i].len != 0; i++) {
- proto_cmd_server_t *thisCmd;
-
- thisCmd = &proto_cmd_list[i];
-
- if (len >= thisCmd->len && strncmp(msg, thisCmd->name, thisCmd->len) == 0) {
- if ((thisCmd->tux == 1 && client->tux == NULL) ||
- (thisCmd->tux == 0 && client->tux != NULL)) {
- return NULL;
- }
-
- return thisCmd;
- }
- }
-
- return NULL;
-}
-
-static void startUpdateServer()
-{
- timeUpdate = time(NULL);
-}
-
-time_t server_get_update()
-{
- return time(NULL) - timeUpdate;
-}
-
-client_t *server_new_any_client()
-{
- client_t *new;
-
- new = malloc(sizeof(client_t));
- memset(new, 0, sizeof(client_t));
-
- new->status = NET_STATUS_OK;
- new->listRecvMsg = list_new();
- new->listSendMsg = check_front_new();
- new->listSeesShot = list_new();
- new->protect = newProtect();
-
- return new;
-}
-
-void server_destroy_any_client(client_t *p)
-{
- assert(p != NULL);
-
- /*check_front_event(p);*/
- list_destroy_item(p->listRecvMsg, free);
- list_destroy_item(p->listSeesShot, free);
- check_front_destroy(p->listSendMsg);
-
- destroyProtect(p->protect);
-
- if (p->tux != NULL) {
-#ifdef PUBLIC_SERVER
- table_add(p->tux->name, p->tux->score);
-#endif /* PUBLIC_SERVER */
- space_del_with_item(arena_get_current()->spaceTux, p->tux, tux_destroy);
- }
-
- free(p);
-}
-
-static void eventDelClientFromListClient(client_t *client)
-{
- int offset;
-
- offset = list_search(listClient, client);
-
- assert(offset != -1);
-
- list_del_item(listClient, offset, server_udp_destroy_client);
-}
-
-static void delZombieCLient(void *p_nothing)
-{
- client_t *thisClient;
- my_time_t currentTime;
- int i;
-
- currentTime = timer_get_current_time();
-
- 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);
- check_front_event(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_nothing)
-{
- client_t *thisClientSend;
- tux_t *thisTux;
- int i;
-
-#ifndef PUBLIC_SERVER
- proto_send_newtux_server(PROTO_SEND_ALL_SEES_TUX, NULL, world_get_control_tux(TUX_CONTROL_KEYBOARD_RIGHT));
-#endif /* PUBLIC_SERVER */
-
- for (i = 0; i < listClient->count; i++) {
- thisClientSend = (client_t *) listClient->list[i];
- thisTux = thisClientSend->tux;
-
- if (thisTux == NULL) {
- continue;
- }
-
- 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_nothing)
-{
- proto_send_ping_server(PROTO_SEND_ALL, NULL);
-}
-
-void server_set_time()
-{
- if (listServerTimer != NULL) {
- timer_destroy(listServerTimer);
- }
-
- timer_restart();
- listServerTimer = timer_new();
-
- timer_add_task(listServerTimer, TIMER_PERIODIC, delZombieCLient, NULL, SERVER_TIMEOUT);
- timer_add_task(listServerTimer, TIMER_PERIODIC, eventPeriodicSyncClient, NULL, SERVER_TIME_SYNC);
- timer_add_task(listServerTimer, TIMER_PERIODIC, eventSendPingClients, NULL, SERVER_TIME_PING);
-}
-
-int server_init(char *ip4, char *ip6, int port)
-{
- int ret;
-
- startUpdateServer();
- listServerTimer = NULL;
-
- listClient = list_new();
-
- server_set_max_clients(SERVER_MAX_CLIENTS);
- server_set_time();
-
- ret = server_udp_init(ip4, ip6, port);
-
- if (ret == 0) {
- return -1;
- }
-
- /* initialize the arena download server */
- if (ip4 != NULL) {
- down_server_init(ip4, port);
- } else if (ip6 != NULL) {
- down_server_init(ip6, port);
- }
-
- return ret;
-}
-
-list_t *server_get_list_clients()
-{
- return listClient;
-}
-
-int server_get_max_clients()
-{
- return maxClients;
-}
-
-void server_set_max_clients(int n)
-{
- maxClients = n;
-}
-
-void server_send_client(client_t *p, char *msg)
-{
- assert(p != NULL);
- assert(msg != NULL);
-
- if (p->status != NET_STATUS_ZOMBIE) {
- int ret = -1;
-
-#ifndef PUBLIC_SERVER
- if (isParamFlag("--send")) {
- debug("Sending: %s", msg);
- }
-#endif /* PUBLIC_SERVER */
-
- ret = sock_udp_write(p->socket_udp, p->socket_udp, msg, strlen(msg));
-
- if (ret <= 0) {
- p->status = NET_STATUS_ZOMBIE;
- }
- }
-}
-
-static void client_eventWorkRecvList(client_t *client)
-{
- proto_cmd_server_t *protoCmd;
- char *line;
- int i;
-
- assert(client != NULL);
-
- /* processing of events from clients */
- for (i = 0; i < client->listRecvMsg->count; i++) {
- line = (char *) client->listRecvMsg->list[i];
- protoCmd = findCmdProto(client, line);
-
-#ifndef PUBLIC_SERVER
- if (isParamFlag("--recv")) {
- debug("Received: %s", line);
- }
-#endif /* PUBLIC_SERVER */
-
- 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);
- }
- }
-
- list_destroy_item(client->listRecvMsg, free);
- client->listRecvMsg = list_new();
-}
-
-static void porcesListClients()
-{
- int i;
- client_t *thisClient;
-
- for (i = 0; i < listClient->count; i++) {
- thisClient = (client_t *) listClient->list[i];
-
- client_eventWorkRecvList(thisClient);
- check_front_event(thisClient);
- }
-}
-
-void server_event()
-{
-#ifndef PUBLIC_SERVER
- int count;
-
- do {
- select_restart();
-
- server_udp_set_select();
- down_server_set_select();
-
- select_action();
-
- count = server_udp_select_sock();
- down_server_select_socket();
- } while (count > 0);
-#else /* PUBLIC_SERVER */
- int ret;
-
- select_restart();
-
- server_udp_set_select();
- down_server_set_select();
-
- ret = select_action();
-
- if (ret > 0) {
- server_udp_select_sock();
- down_server_select_socket();
- }
-#endif /* PUBLIC_SERVER */
-
- porcesListClients();
- timer_event(listServerTimer);
-}
-
-void server_quit()
-{
- proto_send_end_server(PROTO_SEND_ALL, NULL);
-
- assert(listClient != NULL);
-
- list_destroy_item(listClient, server_udp_destroy_client);
-
- timer_destroy(listServerTimer);
-
- server_udp_quit();
-
- down_server_quit();
-}
diff --git a/src/base/server.h b/src/base/server.h
deleted file mode 100644
index 72d7585..0000000
--- a/src/base/server.h
+++ /dev/null
@@ -1,60 +0,0 @@
-#ifndef MY_SERVER_H
-#define MY_SERVER_H
-
-#include <time.h>
-
-#include "list.h"
-#include "tux.h"
-#include "myTimer.h"
-#include "protect.h"
-#include "buffer.h"
-
-#ifndef PUBLIC_SERVER
-#include "interface.h"
-#endif /* PUBLIC_SERVER */
-
-#include "udp.h"
-
-#define SERVER_TIMEOUT 1000
-#define SERVER_TIME_SYNC 1000
-#define SERVER_TIME_PING 1000
-#define SERVER_MAX_CLIENTS 100
-
-#define SERVER_INDEX_ROOT_TUX 0
-
-#define CLIENT_TYPE_UDP 1
-#define CLIENT_TYPE_TCP 2
-
-typedef struct client_struct {
- int type;
-
- sock_udp_t *socket_udp;
-
- buffer_t *recvBuffer;
- buffer_t *sendBuffer;
-
- int status;
-
- tux_t *tux;
-
- protect_t *protect;
-
- list_t *listSendMsg;
- list_t *listRecvMsg;
-
- list_t *listSeesShot;
-} client_t;
-
-extern int server_init(char *ip4, char *ip6, int port);
-extern time_t server_get_update();
-extern client_t *server_new_any_client();
-extern void server_destroy_any_client(client_t *p);
-extern list_t *server_get_list_clients();
-extern int server_get_max_clients();
-extern void server_set_time();
-extern void server_set_max_clients(int n);
-extern void server_send_client(client_t *p, char *msg);
-extern void server_event();
-extern void server_quit();
-
-#endif /* MY_SERVER_H */
diff --git a/src/base/serverSelect.c b/src/base/serverSelect.c
deleted file mode 100644
index 6f8d64e..0000000
--- a/src/base/serverSelect.c
+++ /dev/null
@@ -1,105 +0,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include <sys/types.h>
-
-#include <unistd.h>
-#include <fcntl.h>
-#include <sys/time.h>
-
-#ifndef __WIN32__
-#include <sys/ioctl.h>
-#include <sys/socket.h>
-#include <sys/select.h>
-#else /* __WIN32__ */
-#include <io.h>
-#include <winsock2.h>
-#endif /* __WIN32__ */
-
-#include "server.h"
-
-static struct timeval tv;
-static fd_set readfds;
-static fd_set writefds;
-static int max_fd;
-
-void select_restart()
-{
-#ifndef PUBLIC_SERVER
- tv.tv_sec = 0;
- tv.tv_usec = 0;
-#else /* PUBLIC_SERVER */
- tv.tv_sec = 0;
- tv.tv_usec = 1000;
-#endif /* PUBLIC_SERVER */
-
- FD_ZERO(&readfds);
- FD_ZERO(&writefds);
- max_fd = 0;
-}
-
-void select_add_sock_for_read(int sock)
-{
- /*printf("select_add_sock_for_read %d\n", sock);*/
-
- FD_SET(sock, &readfds);
-
- if (sock > max_fd) {
- max_fd = sock;
- }
-}
-
-void select_add_sock_for_write(int sock)
-{
- /*printf("select_add_sock_for_write %d\n", sock);*/
-
- FD_SET(sock, &writefds);
-
- if (sock > max_fd) {
- max_fd = sock;
- }
-}
-
-int select_action()
-{
- int ret;
-
-#ifndef PUBLIC_SERVER
- ret = select(max_fd + 1, &readfds, &writefds, (fd_set *) NULL, &tv);
-#else /* PUBLIC_SERVER */
- list_t *listClient;
- listClient = server_get_list_clients();
-
- if (listClient->count == 0) {
- ret = select(max_fd + 1, &readfds, &writefds, (fd_set *) NULL, NULL);
- server_set_time();
- } else {
- ret = select(max_fd + 1, &readfds, &writefds, (fd_set *) NULL, &tv);
- }
-#endif /* PUBLIC_SERVER */
-
- return ret;
-}
-
-int select_is_change_sock_for_read(int sock)
-{
- int ret;
-
- ret = FD_ISSET(sock, &readfds);
-
- /*printf("select_is_change_sock %d -> %d\n", sock, ret);*/
-
- return ret;
-}
-
-int select_is_change_sock_for_write(int sock)
-{
- int ret;
-
- ret = FD_ISSET(sock, &writefds);
-
- /*printf("select_is_change_sock %d -> %d\n", sock, ret);*/
-
- return ret;
-}
diff --git a/src/base/serverSelect.h b/src/base/serverSelect.h
deleted file mode 100644
index e1880cb..0000000
--- a/src/base/serverSelect.h
+++ /dev/null
@@ -1,12 +0,0 @@
-#ifndef SERVER_SELECT_H
-#define SERVER_SELECT_H
-
-extern void select_restart();
-extern void select_add_sock_for_read(int sock);
-extern void select_add_sock_for_write(int sock);
-extern int select_action();
-extern int select_is_change_sock(int sock);
-extern int select_is_change_sock_for_read(int sock);
-extern int select_is_change_sock_for_write(int sock);
-
-#endif /* SERVER_SELECT_H */
diff --git a/src/base/serverSendMsg.c b/src/base/serverSendMsg.c
deleted file mode 100644
index d74103e..0000000
--- a/src/base/serverSendMsg.c
+++ /dev/null
@@ -1,145 +0,0 @@
-#include <unistd.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <assert.h>
-
-#include "server.h"
-#include "net_multiplayer.h"
-#include "checkFront.h"
-#include "serverSendMsg.h"
-
-#ifndef PUBLIC_SERVER
-#include "world.h"
-#endif /* PUBLIC_SERVER */
-
-static void addMsgClient(client_t *p, char *msg, int type, int id)
-{
- assert(p != NULL);
- assert(msg != NULL);
-
- if (p->status != NET_STATUS_ZOMBIE) {
- check_front_msg_add(p->listSendMsg, msg, type, id);
- }
-}
-
-static void addMsgAllClientBut(char *msg, client_t *p, int type, int id)
-{
- list_t *listClient;
- client_t *thisClient;
- int i;
-
- assert(msg != NULL);
-
- listClient = server_get_list_clients();
-
- for (i = 0; i < listClient->count; i++) {
- thisClient = (client_t *) listClient->list[i];
-
- if (thisClient->tux != NULL && thisClient != p) {
- addMsgClient(thisClient, msg, type, id);
- }
- }
-}
-
-static void addMsgAllClient(char *msg, int type, int id)
-{
- assert(msg != NULL);
-
- addMsgAllClientBut(msg, NULL, type, 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 = arena_get_current();
- 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 = list_new();
-
- space_get_object(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);
- }
- }
-
- list_destroy(listHelp);
-}
-
-void send_msg_to_client(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:
-#ifndef PUBLIC_SERVER
- if (client != NULL) {
- addMsgAllClientSeesTux(msg, client->tux, type2, id);
- } else {
- addMsgAllClientSeesTux(msg, world_get_control_tux(TUX_CONTROL_KEYBOARD_RIGHT), type2, id);
- }
-#else /* PUBLIC_SERVER*/
- addMsgAllClientSeesTux(msg, client->tux, type2, id);
-#endif /* PUBLIC_SERVER */
- break;
- default:
- error("Unknown type of target group of players [%d]", type);
- assert(0);
- break;
- }
-}
diff --git a/src/base/serverSendMsg.h b/src/base/serverSendMsg.h
deleted file mode 100644
index 68bd65c..0000000
--- a/src/base/serverSendMsg.h
+++ /dev/null
@@ -1,13 +0,0 @@
-#ifndef SERVER_SEND_MSG_H
-#define SERVER_SEND_MSG_H
-
-#include "server.h"
-
-#define PROTO_SEND_ONE 0
-#define PROTO_SEND_ALL 1
-#define PROTO_SEND_BUT 3
-#define PROTO_SEND_ALL_SEES_TUX 4
-
-extern void send_msg_to_client(int type, client_t *client, char *msg, int type2, int id);
-
-#endif /* SERVER_SEND_MSG_H */
diff --git a/src/base/shareFunction.c b/src/base/shareFunction.c
deleted file mode 100644
index a9cd69d..0000000
--- a/src/base/shareFunction.c
+++ /dev/null
@@ -1,65 +0,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <assert.h>
-
-#include "main.h"
-#include "list.h"
-#include "shareFunction.h"
-
-typedef struct share_fce_item_struct {
- char *name;
- void *function;
-} share_fce_item_t;
-
-static list_t *listShareFce;
-
-static share_fce_item_t *newShareFceItem(char *name, void *function)
-{
- share_fce_item_t *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)
-{
- free(p->name);
- free(p);
-}
-
-void share_function_init()
-{
- listShareFce = list_new();
-}
-
-void share_function_add(char *name, void *function)
-{
- debug("Adding new shared function [%s]", name);
-
- list_add(listShareFce, newShareFceItem(name, function));
-}
-
-void *share_function_get(char *name)
-{
- int i;
-
- 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;
-}
-
-void share_function_quit()
-{
- list_destroy_item(listShareFce, destroyShareFce);
-}
diff --git a/src/base/shareFunction.h b/src/base/shareFunction.h
deleted file mode 100644
index a444842..0000000
--- a/src/base/shareFunction.h
+++ /dev/null
@@ -1,9 +0,0 @@
-#ifndef SHARE_FUNCTION_H
-#define SHARE_FUNCTION_H
-
-extern void share_function_init();
-extern void share_function_add(char *name, void *function);
-extern void *share_function_get(char *name);
-extern void share_function_quit();
-
-#endif /* SHARE_FUNCTION_H */
diff --git a/src/base/shot.c b/src/base/shot.c
deleted file mode 100644
index 0d30750..0000000
--- a/src/base/shot.c
+++ /dev/null
@@ -1,347 +0,0 @@
-#include <stdlib.h>
-#include <string.h>
-#include <assert.h>
-
-#include "main.h"
-#include "shot.h"
-#include "gun.h"
-#include "net_multiplayer.h"
-#include "proto.h"
-#include "idManager.h"
-#include "serverSendMsg.h"
-
-#ifndef PUBLIC_SERVER
-#include "image.h"
-#include "layer.h"
-#include "world.h"
-#else /* PUBLIC_SERVER */
-#include "publicServer.h"
-#endif /* PUBLIC_SERVER */
-
-#ifndef PUBLIC_SERVER
-static image_t *g_shot_simple;
-static image_t *g_shot_lasserX;
-static image_t *g_shot_lasserY;
-static image_t *g_shot_bombball;
-#endif /* PUBLIC_SERVER */
-
-static bool_t isShotInit = FALSE;
-
-bool_t shot_is_inicialized()
-{
- return isShotInit;
-}
-
-void shot_init()
-{
-#ifndef PUBLIC_SERVER
- assert(image_is_inicialized() == TRUE);
-
- g_shot_simple = image_add("shot.png", IMAGE_ALPHA, "shot", IMAGE_GROUP_BASE);
- g_shot_lasserX = image_add("lasserX.png", IMAGE_NO_ALPHA, "lasserX", IMAGE_GROUP_BASE);
- g_shot_lasserY = image_add("lasserY.png", IMAGE_NO_ALPHA, "lasserY",IMAGE_GROUP_BASE);
- g_shot_bombball = image_add("bombball.png", IMAGE_ALPHA, "bombball", IMAGE_GROUP_BASE);
-#endif /* PUBLIC_SERVER */
-
- isShotInit = TRUE;
-}
-
-shot_t *shot_new(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 = id_get_new();
- 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 = space_get_object_id(arena_get_current()->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 /* PUBLIC_SERVER */
- break;
-
- case GUN_LASSER:
- switch (author->position) {
- case TUX_RIGHT:
- case TUX_LEFT:
- new->w = GUN_LASSER_HORIZONTAL;
- new->h = GUN_SHOT_VERTICAL;
-#ifndef PUBLIC_SERVER
- new->img = g_shot_lasserX;
-#endif /* PUBLIC_SERVER */
- break;
- case TUX_UP:
- case TUX_DOWN:
- new->w = GUN_SHOT_VERTICAL;
- new->h = GUN_LASSER_HORIZONTAL;
-#ifndef PUBLIC_SERVER
- new->img = g_shot_lasserY;
-#endif /* PUBLIC_SERVER */
- break;
- }
- break;
-
- case GUN_BOMBBALL:
- new->w = GUN_BOMBBALL_WIDTH;
- new->h = GUN_BOMBBALL_HEIGHT;
-
-#ifndef PUBLIC_SERVER
- new->img = g_shot_bombball;
-#endif /* PUBLIC_SERVER */
- break;
-
- default:
- error("Unknown type of gun [%d]", gun);
- assert(0);
- break;
- }
-
- return new;
-}
-
-void shot_replace_id(shot_t *shot, int id)
-{
- id_replace(shot->id, id);
- shot->id = id;
-}
-
-
-void shot_get_status(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;
-}
-
-void shot_set_status(void *p, int x, int y, int w, int h)
-{
- shot_t *shot;
-
- shot = p;
- shot->x = x;
- shot->y = y;
- shot->w = w;
- shot->h = h;
-}
-
-#ifndef PUBLIC_SERVER
-void shot_draw(shot_t *p)
-{
- assert(p != NULL);
- addLayer(p->img, p->x, p->y, 0, 0, p->img->w, p->img->h, TUX_LAYER);
-}
-
-void shot_draw_list(list_t *listShot)
-{
- shot_t *thisShot;
- int i;
-
- assert(listShot != NULL);
-
- for (i = 0; i < listShot->count; i++) {
- thisShot = (shot_t *) listShot->list[i];
- assert(thisShot != NULL);
- shot_draw(thisShot);
- }
-}
-#endif /* PUBLIC_SERVER */
-
-static int getRandomCourse(int x, int y)
-{
- int ret = -1;
-
- 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 shot_bound_bombBall(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 (net_multiplayer_get_game_type() == NET_GAME_TYPE_SERVER) {
- proto_send_shot_server(PROTO_SEND_ALL, NULL, shot);
- }
-}
-
-void shot_transform_lasser(shot_t *shot)
-{
- space_t *space;
- int mustRefesh = 0;
-
- space = arena_get_current()->spaceShot;
-
- if (space_get_object_id(space, shot->id) != NULL) {
- mustRefesh = 1;
- }
-
- if (mustRefesh) {
- space_del(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 /* PUBLIC_SERVER */
- 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 /* PUBLIC_SERVER */
- break;
- }
-
- if (mustRefesh) {
- space_add(space, shot);
- }
-}
-
-static void action_moveShot(space_t *space, shot_t *shot, void *p)
-{
- int new_x, new_y;
- arena_t *arena;
-
- arena = arena_get_current();
-
- new_x = shot->x + shot->px;
- new_y = shot->y + shot->py;
-
- space_move_object(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) {
- space_del_with_item(space, shot, shot_destroy);
- }
-}
-
-void shot_event_move_list(arena_t *arena)
-{
- space_action(arena->spaceShot, action_moveShot, NULL);
-}
-
-static int isValueInList(list_t *list, int x)
-{
- int i;
-
- for (i = 0; i < list->count; i++) {
- if (x == (*(int *) list->list[i])) {
- return 1;
- }
- }
-
- return 0;
-}
-
-static void action_check(space_t *space, shot_t *shot, client_t *client)
-{
- if (isValueInList(client->listSeesShot, shot->id) == 0) {
- list_add(client->listSeesShot, newInt(shot->id));
- proto_send_shot_server(PROTO_SEND_ONE, client, shot);
- }
-}
-
-void shot_check_is_tux_screen(arena_t *arena)
-{
- int screen_x, screen_y;
- tux_t *thisTux;
- client_t *thisClient;
- list_t *listClient;
- int i;
-
- if (net_multiplayer_get_game_type() != NET_GAME_TYPE_SERVER) {
- return;
- }
-
- listClient = server_get_list_clients();
-
- 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;
- }
-
- arena_get_center_screen(&screen_x, &screen_y, thisTux->x, thisTux->y,
- WINDOW_SIZE_X, WINDOW_SIZE_Y);
-
- space_action_from_location(arena->spaceShot, action_check,
- thisClient, screen_x, screen_y,
- WINDOW_SIZE_X, WINDOW_SIZE_Y);
-
- while (thisClient->listSeesShot->count > 100) {
- list_del_item(thisClient->listSeesShot, 0, free);
- del++;
- }
-
- /*if( del > 0 )printf("del = %d\n", del);*/
- }
-}
-
-void shot_destroy(shot_t *p)
-{
- assert(p != NULL);
-
- id_del(p->id);
-
- free(p);
-}
-
-void shot_quit()
-{
- isShotInit = FALSE;
-}
diff --git a/src/base/shot.h b/src/base/shot.h
deleted file mode 100644
index 97b7a91..0000000
--- a/src/base/shot.h
+++ /dev/null
@@ -1,53 +0,0 @@
-#ifndef SHOT_H
-#define SHOT_H
-
-#include "main.h"
-#include "list.h"
-#include "tux.h"
-#include "arena.h"
-#ifndef PUBLIC_SERVER
-#include "image.h"
-#endif /* PUBLIC_SERVER */
-
-#ifdef __WIN32__
-#define random rand
-#endif /* __WIN32__ */
-
-typedef struct shot_struct {
- int id;
- int x;
- int y;
- int w;
- int h;
- int px;
- int py;
- int position;
- int gun;
- int author_id;
- bool_t isCanKillAuthor;
- bool_t del;
-#ifndef PUBLIC_SERVER
- image_t *img;
-#endif /* PUBLIC_SERVER */
-} shot_t;
-
-extern bool_t shot_is_inicialized();
-extern void shot_init();
-extern shot_t *shot_new(int x, int y, int px, int py, int gun, int author_id);
-extern shot_t *shot_get_id(list_t *listShot, int id);
-extern void shot_replace_id(shot_t *shot, int id);
-extern void shot_get_status(void *p, int *id, int *x, int *y, int *w, int *h);
-extern void shot_set_status(void *p, int x, int y, int w, int h);
-#ifndef PUBLIC_SERVER
-extern void shot_draw(shot_t *p);
-extern void shot_draw_list(list_t *listShot);
-#endif /* PUBLIC_SERVER */
-extern int shot_is_conflict_with_list_shot(list_t *listShot, int x, int y, int w, int h);
-extern void shot_event_move_list(arena_t *arena);
-extern void shot_check_is_tux_screen(arena_t *arena);
-extern void shot_bound_bombBall(shot_t *shot);
-extern void shot_transform_lasser(shot_t *shot);
-extern void shot_destroy(shot_t *p);
-extern void shot_quit();
-
-#endif /* SHOT_H */
diff --git a/src/base/space.c b/src/base/space.c
deleted file mode 100644
index 6ef2892..0000000
--- a/src/base/space.c
+++ /dev/null
@@ -1,375 +0,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <assert.h>
-
-#include "main.h"
-#include "list.h"
-#include "space.h"
-#include "index.h"
-
-zone_t *newZone()
-{
- zone_t *new;
-
- new = malloc(sizeof(zone_t));
- new->list = list_new();
-
- return new;
-}
-
-void destroyZone(zone_t *p)
-{
- assert(p != NULL);
-
- list_destroy(p->list);
- free(p);
-}
-
-static int my_arena_conflict_space(int x1, int y1, int w1, int h1, int x2, int y2, int w2, int h2)
-{
- return (x1 < x2 + w2 && x2 < x1 + w1 && y1 < y2 + h2 && y2 < y1 + h1);
-}
-
-space_t *space_new(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;
-
- assert(w > 0 && h > 0 && segW > 0 && segH > 0);
-
- new = malloc(sizeof(space_t));
-
- if (!new) {
- return 0;
- }
-
- 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 = index_new();
-
- 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)
-{
- *segX = x / p->segW;
- *segY = y / p->segH;
- *segW = ((x + w) / p->segW + 1) - *segX;
- *segH = ((y + h) / p->segH + 1) - *segY;
-}
-
-int space_get_count(space_t *p)
-{
- return p->listIndex->count;
-}
-
-void *space_get_item(space_t *p, int offset)
-{
- index_item_t *this;
-
- this = (index_item_t *) p->listIndex->list[offset];
- return this->data;
-}
-
-void space_add(space_t *p, void *item)
-{
- int segX, segY, segW, segH;
- int id, x, y, w, h;
- int i, j;
-
- if (!p || !item) {
- return;
- }
-
- if (!p->zone) {
- return;
- }
-
- 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;
- }
-
- list_add(p->zone[j][i]->list, item);
- }
- }
-
- index_add(p->listIndex, id, item);
-}
-
-void space_get_object(space_t *p, int x, int y, int w, int h, list_t *list)
-{
- 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_arena_conflict_space(x, y, w, h, this_x, this_y, this_w, this_h) &&
- list_search(list, this) == -1) {
- list_add(list, this);
- }
- }
- }
- }
-}
-
-void *space_get_object_id(space_t *space, int id)
-{
- return index_get(space->listIndex, id);
-}
-
-int space_is_conflict_with_object(space_t *p, int x, int y, int w, int h)
-{
- int 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_arena_conflict_space(x, y, w, h, this_x, this_y, this_w, this_h)) {
- return 1;
- }
- }
- }
- }
-
- return 0;
-}
-
-int space_is_conflict_with_object_but(space_t *p, int x, int y, int w, int h, void *but)
-{
- int segX, segY, segW, segH;
- int id, this_x, this_y, this_w, this_h;
- 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_arena_conflict_space(x, y, w, h, this_x, this_y, this_w, this_h)) {
- return 1;
- }
- }
- }
- }
-
- return 0;
-}
-
-void space_del(space_t *p, void *item)
-{
- int segX, segY, segW, segH;
- int id, x, y, w, h;
- int myIndex;
- 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;
- }
-
- myIndex = list_search(p->zone[j][i]->list, item);
- assert(myIndex != -1);
- list_del(p->zone[j][i]->list, myIndex);
- }
- }
-
- index_del(p->listIndex, id);
-}
-
-void space_del_with_item(space_t *p, void *item, void *f)
-{
- void (*fce) (void *param);
-
- fce = f;
-
- space_del(p, item);
- fce(item);
-}
-
-void space_move_object(space_t *p, void *item, int move_x, int move_y)
-{
- int old_segX, old_segY, old_segW, old_segH;
- int new_segX, new_segY, new_segW, new_segH;
- 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) {
- space_del(p, item);
- p->setStatus(item, move_x, move_y, w, h);
- space_add(p, item);
- return;
- }
-
- p->setStatus(item, move_x, move_y, w, h);
-}
-
-void space_print(space_t *p)
-{
- int i, j;
-
- debug("Debugging space:");
-
- for (i = 0; i < p->h; i++) {
- for (j = 0; j < p->w; j++) {
- printf("%3d ", p->zone[j][i]->list->count);
- }
-
- putchar('\n');
- }
-}
-
-void space_action(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, space_get_item(space, i), p);
-
- if (space->listIndex->count == len - 1) {
- len--;
- i--;
- }
- }
-}
-
-void space_action_from_location(space_t *space, void *f, void *p, int x, int y, int w, int h)
-{
- void (*fce) (space_t *space, void *f, void *p);
- list_t *list;
- int len;
- int i;
-
- fce = f;
-
- list = list_new();
-
- space_get_object(space, x, y, w, h, list);
-
- len = list->count;
-
- for (i = 0; i < len; i++) {
- fce(space, list->list[i], p);
- }
-
- list_destroy(list);
-}
-
-void space_destroy(space_t *p)
-{
- int j, i;
-
- index_destroy(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->w; i++) {
- free(p->zone[i]);
- }
-
- free(p->zone);
- free(p);
-}
-
-void space_destroy_with_item(space_t *p, void *f)
-{
- void (*fce) (void *param);
- int i;
-
- fce = f;
-
- for (i = 0; i < p->listIndex->count; i++) {
- fce(space_get_item(p, i));
- }
-
- space_destroy(p);
-}
diff --git a/src/base/space.h b/src/base/space.h
deleted file mode 100644
index 8b888a7..0000000
--- a/src/base/space.h
+++ /dev/null
@@ -1,47 +0,0 @@
-#ifndef SPACE_H
-#define SPACE_H
-
-#include "main.h"
-#include "list.h"
-
-typedef struct zone_struct {
- list_t *list;
-} zone_t;
-
-typedef struct space_struct {
- int w;
- int h;
-
- int segW;
- int segH;
-
- zone_t ***zone;
-
- list_t *listIndex;
-
- 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;
-
-extern space_t *space_new(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));
-
-extern int space_get_count(space_t *p);
-extern void *space_get_item(space_t *p, int offset);
-extern void space_add(space_t *p, void *item);
-extern void space_get_object(space_t *p, int x, int y, int w, int h, list_t *list);
-extern void *space_get_object_id(space_t *p, int id);
-extern int space_is_conflict_with_object(space_t *p, int x, int y, int w, int h);
-extern int space_is_conflict_with_object_but(space_t *p, int x, int y, int w, int h, void *but);
-extern void space_del(space_t *p, void *item);
-extern void space_del_with_item(space_t *p, void *item, void *f);
-extern void space_move_object(space_t *p, void *item, int move_x, int move_y);
-extern void space_print(space_t *p);
-extern void space_action(space_t *space, void *f, void *p);
-extern void space_action_from_location(space_t *space, void *f, void *p,
- int x, int y, int w, int h);
-extern void space_destroy(space_t *p);
-extern void space_destroy_with_item(space_t *p, void *f);
-
-#endif /* SPACE_H */
diff --git a/src/base/storage.c b/src/base/storage.c
deleted file mode 100644
index 842c560..0000000
--- a/src/base/storage.c
+++ /dev/null
@@ -1,136 +0,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <assert.h>
-
-#include "main.h"
-#include "list.h"
-
-typedef struct struct_storage_item {
- char *name;
- char *group;
- void *data;
-} storage_item_t;
-
-list_t *storage_new()
-{
- return list_new();
-}
-
-static storage_item_t *storage_new_item(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;
-}
-
-static void storage_destroy_item(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 storage_add(list_t *list, char *group, char *name, void *data)
-{
- assert(list != NULL);
- assert(group != NULL);
- assert(name != NULL);
-
- list_add(list, storage_new_item(group, name, data));
-}
-
-void *storage_get(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;
- }
- }
-
- debug("Storage item not found [%s %s]", group, name);
-
- return NULL;
-}
-
-void storage_del(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) {
- storage_destroy_item(this, f);
- list_del(list, i);
- return;
- }
- }
-
- return;
-}
-
-void storage_del_all(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) {
- storage_destroy_item(this, f);
- list_del(list, i);
- i--;
- }
- }
-}
-
-void storage_destroy(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];
-
- storage_destroy_item(this, f);
- }
-
- list_destroy(p);
-}
diff --git a/src/base/storage.h b/src/base/storage.h
deleted file mode 100644
index 1ef9b78..0000000
--- a/src/base/storage.h
+++ /dev/null
@@ -1,14 +0,0 @@
-#ifndef STORAGE_H
-#define STORAGE_H
-
-#include "main.h"
-#include "list.h"
-
-extern list_t *storage_new();
-extern void storage_add(list_t *list, char *group, char *name, void *data);
-extern void *storage_get(list_t *list, char *group, char *name);
-extern void storage_del(list_t *list, char *group, char *name, void *f);
-extern void storage_del_all(list_t *list, char *group, void *f);
-extern void storage_destroy(list_t *p, void *f);
-
-#endif /* STORAGE_H */
diff --git a/src/base/string_length.h b/src/base/string_length.h
deleted file mode 100644
index 43a6883..0000000
--- a/src/base/string_length.h
+++ /dev/null
@@ -1,15 +0,0 @@
-#ifndef STR_LENGTH_H
-#define STR_LENGTH_H
-
-#include "main.h"
-
-#define STR_SIZE 128
-#define STR_PROTO_SIZE 128
-#define STR_LOG_SIZE 256
-#define STR_NUM_SIZE 8
-#define STR_NAME_SIZE 32
-#define STR_PATH_SIZE 4096
-#define STR_FILE_NAME_SIZE 256
-#define STR_IP_SIZE 64
-
-#endif /* STR_LENGTH_H */
diff --git a/src/base/textFile.c b/src/base/textFile.c
deleted file mode 100644
index b1c2ad9..0000000
--- a/src/base/textFile.c
+++ /dev/null
@@ -1,151 +0,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <sys/stat.h>
-#include <assert.h>
-#include <unistd.h>
-
-#include "main.h"
-#include "textFile.h"
-
-textFile_t *text_file_new(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, PATH_SEPARATOR);
- strcat(path, s);
- }
-
- new = malloc(sizeof(textFile_t));
- new->file = strdup(path);
- new->text = list_new();
-
- return new;
-}
-
-static void createLine(list_t *list, char *p, int len)
-{
- char *line;
- char *begin_line;
- char *end_line;
- int length_line = 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;
- }
-
- length_line = (int) (end_line - begin_line);
-
- line = malloc((length_line + 1) * sizeof(char));
- memset(line, 0, (length_line + 1) * sizeof(char));
- strncpy(line, begin_line, length_line);
-
- list_add(list, line);
- len -= (length_line + 1);
-
- begin_line = end_line + 1;
-
- } while (begin_line != NULL);
-}
-
-/**
- * Loads file *s and returns him formatted to textFile_t*
- */
-textFile_t *text_file_load(char *s)
-{
- FILE *file;
- textFile_t *ret;
- char *p;
- int file_length = 0;
- struct stat buf;
-
- assert(s != NULL);
-
- if (lstat(s, &buf) < 0) {
- error("Unable to get file status [%s]", s);
- return NULL;
- }
-
- file_length = buf.st_size;
- if ((file = fopen(s, "rb")) == NULL) {
- error("Unable to open file for reading [%s]", s);
- return NULL;
- }
-
- p = malloc(file_length * sizeof(char));
-
- if (fread(p, file_length * sizeof(char), 1, file) != 1) {
- error("Unable to read data from file [%s]", s);
- fclose(file);
- return NULL;
- }
-
- fclose(file);
-
- ret = text_file_new(s);
- createLine(ret->text, p, file_length);
-
- free(p);
-
- return ret;
-}
-
-/**
- * Prints the text saved in *p into stdout
- */
-void text_file_print(textFile_t *p)
-{
- int i;
-
- assert(p != NULL);
-
- debug("Printing file [%s]", p->file);
-
- for (i = 0; i < p->text->count; i++) {
- printf("%3d >> %s\n", i, (char *) p->text->list[i]);
- }
-}
-
-void text_file_save(textFile_t *p)
-{
- 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);
-}
-
-/**
- * Removes text saved in *p from the memory
- */
-void text_file_destroy(textFile_t *p)
-{
- assert(p != NULL);
-
- free(p->file);
- list_destroy_item(p->text, free);
- free(p);
-}
diff --git a/src/base/textFile.h b/src/base/textFile.h
deleted file mode 100644
index d2153fc..0000000
--- a/src/base/textFile.h
+++ /dev/null
@@ -1,21 +0,0 @@
-#ifndef TEXTFILE_H
-#define TEXTFILE_H
-
-#include "list.h"
-
-#ifdef __WIN32__
-#define lstat stat
-#endif /* __WIN32__ */
-
-typedef struct str_textFile_t {
- char *file;
- list_t *text;
-} textFile_t;
-
-extern textFile_t *text_file_new(char *s);
-extern textFile_t *text_file_load(char *s);
-extern void text_file_print(textFile_t *p);
-extern void text_file_save(textFile_t *p);
-extern void text_file_destroy(textFile_t *p);
-
-#endif /* TEXTFILE_H */
diff --git a/src/base/tux.c b/src/base/tux.c
deleted file mode 100644
index f88d6a4..0000000
--- a/src/base/tux.c
+++ /dev/null
@@ -1,766 +0,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <assert.h>
-
-#include "main.h"
-#include "tux.h"
-#include "arena.h"
-#include "shot.h"
-#include "gun.h"
-#include "item.h"
-#include "arena.h"
-#include "myTimer.h"
-#include "net_multiplayer.h"
-#include "proto.h"
-#include "modules.h"
-#include "idManager.h"
-#include "serverSendMsg.h"
-
-#ifndef PUBLIC_SERVER
-#include "font.h"
-#include "image.h"
-#include "layer.h"
-#include "radar.h"
-
-#ifndef NO_SOUND
-#include "sound.h"
-#endif /* NO_SOUND */
-
-#include "world.h"
-#else /* PUBLIC_SERVER */
-#include "publicServer.h"
-#endif /* PUBLIC_SERVER */
-
-#ifndef PUBLIC_SERVER
-static image_t *g_tux_up;
-static image_t *g_tux_right;
-static image_t *g_tux_left;
-static image_t *g_tux_down;
-static image_t *g_cross;
-#endif /* PUBLIC_SERVER */
-
-static bool_t isTuxInit = FALSE;
-
-bool_t tux_is_inicialized()
-{
- return isTuxInit;
-}
-
-void tux_init()
-{
-#ifndef PUBLIC_SERVER
- assert(image_is_inicialized() == TRUE);
-
- g_tux_up = image_add("tux8.png", IMAGE_ALPHA, "tux8", IMAGE_GROUP_BASE);
- g_tux_right = image_add("tux6.png", IMAGE_ALPHA, "tux6", IMAGE_GROUP_BASE);
- g_tux_left = image_add("tux4.png", IMAGE_ALPHA, "tux4", IMAGE_GROUP_BASE);
- g_tux_down = image_add("tux2.png", IMAGE_ALPHA, "tux2", IMAGE_GROUP_BASE);
- g_cross = image_add("cross.png", IMAGE_ALPHA, "cross", IMAGE_GROUP_BASE);
-#endif /* PUBLIC_SERVER */
- isTuxInit = TRUE;
-}
-
-int getRandomGun()
-{
- return random() % (GUN_BOMBBALL+1);
-}
-
-tux_t *tux_new()
-{
- int x, y;
- tux_t *new;
-
- new = malloc(sizeof(tux_t));
- assert(new != NULL);
-
- memset(new, 0, sizeof(tux_t));
-
- new->id = id_get_new();
- new->status = TUX_STATUS_ALIVE;
- new->control = TUX_CONTROL_NONE;
-
- arena_find_free_space(arena_get_current(), &x, &y, TUX_WIDTH, TUX_HEIGHT);
- tux_set_proportion(new, x, y);
-
- new->position = TUX_DOWN;
- new->gun = getRandomGun();
- new->shot[new->gun] = GUN_MAX_SHOT;
-
- sprintf(new->name, "no_name_id_%d", new->id);
- new->score = 0;
- new->frame = 0;
-
- new->bonus = BONUS_NONE;
- new->bonus_time = 0;
-
- new->isCanShot = TRUE;
- new->isCanSwitchGun = TRUE;
-
- new->client = NULL;
-
- return new;
-}
-
-void tux_set_name(tux_t *tux, char *name)
-{
- strcpy(tux->name, name);
- /*tux->g_name = getFontImage(name, COLOR_WHITE);*/
-}
-
-bool_t tux_is_any_gun(tux_t *tux)
-{
- int i;
-
- for (i = 0; i < GUN_COUNT; i++) {
- if (tux->shot[i] > 0) {
- return TRUE;
- }
- }
-
- return FALSE;
-}
-
-void tux_get_course(int n, int *x, int *y)
-{
- assert(x != NULL);
- assert(y != NULL);
-
- switch (n) {
- case TUX_UP:
- *x = 0;
- *y = -1;
- break;
-
- case TUX_LEFT:
- *x = -1;
- *y = 0;
- break;
-
- case TUX_RIGHT:
- *x = +1;
- *y = 0;
- break;
-
- case TUX_DOWN:
- *x = 0;
- *y = +1;
- break;
-
- default:
- error("Unknown direction of the tux [%d]", n);
- assert(0);
- break;
- }
-}
-
-#ifndef PUBLIC_SERVER
-void tux_draw(tux_t *tux)
-{
- image_t *g_image = NULL;
-
- assert(tux != NULL);
-
- if (tux->bonus == BONUS_HIDDEN &&
- net_multiplayer_get_game_type() != NET_GAME_TYPE_NONE &&
- tux->control == TUX_CONTROL_NET) {
- return;
- }
-
- switch (tux->position) {
- case TUX_UP:
- g_image = g_tux_up;
- break;
-
- case TUX_LEFT:
- g_image = g_tux_left;
- break;
-
- case TUX_RIGHT:
- g_image = g_tux_right;
- break;
-
- case TUX_DOWN:
- g_image = g_tux_down;
- break;
-
- default:
- error("Unknown direction of the tux [%d]", tux->position);
- assert(0);
- break;
- }
-
- 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);
-
- return;
- }
-
-/*
- if (tux->g_name != NULL) {
- addLayer(tux->g_name,
- tux->x - TUX_IMG_WIDTH / 2,
- (tux->y + TUX_HEIGHT / 2) - TUX_IMG_HEIGHT,
- 0, 0,
- tux->g_name->w, tux->g_name->h, TUX_LAYER);
- }
-*/
-
- 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)
-{
- tux_t *thisTux;
- int i;
-
- assert(listTux != NULL);
-
- for(i = 0; i < listTux->count; i++) {
- thisTux = (tux_t *) listTux->list[i];
- assert(thisTux != NULL);
- tux_draw(thisTux);
- }
-}
-*/
-#endif /* PUBLIC_SERVER */
-
-void tux_replace_id(tux_t *tux, int id)
-{
- id_replace(tux->id, id);
- tux->id = id;
-}
-
-static void timer_spawnTux(void *p)
-{
- tux_t *tux;
- arena_t *arena;
- int x, y;
- int id;
-
- id = *((int *) p);
- free(p);
-
- arena = arena_get_current();
- tux = space_get_object_id(arena->spaceTux, id);
-
- if (tux == NULL) {
- return;
- }
-
- tux->status = TUX_STATUS_ALIVE;
- arena_find_free_space(arena_get_current(), &x, &y, TUX_WIDTH, TUX_HEIGHT);
- space_move_object(arena_get_current()->spaceTux, tux, x, y);
- tux->gun = GUN_SIMPLE;
-
- item_add_new_item(arena->spaceItem, ID_UNKNOWN);
-
- if (net_multiplayer_get_game_type() == NET_GAME_TYPE_SERVER) {
- proto_send_newtux_server(PROTO_SEND_ALL, NULL, tux);
- }
-}
-
-static void timer_tuxCanShot(void *p)
-{
- tux_t *tux;
- int id;
-
- id = *((int *) p);
- free(p);
-
- tux = space_get_object_id(arena_get_current()->spaceTux, id);
-
- if (tux == NULL) {
- return;
- }
-
- tux->isCanShot = TRUE;
-}
-
-static void timer_tuxCanSwitchGun(void *p)
-{
- tux_t *tux;
- int id;
-
- id = *((int *) p);
- free(p);
-
- tux = space_get_object_id(arena_get_current()->spaceTux, id);
-
- if (tux == NULL) {
- return;
- }
-
- tux->isCanSwitchGun = TRUE;
-}
-
-void tux_event_tux_is_dead(tux_t *tux)
-{
- if (tux->status == TUX_STATUS_DEAD) {
- return;
- }
-
- world_inc_round();
-
-#ifndef NO_SOUND
- sound_play("dead", SOUND_GROUP_BASE);
-#endif /* NO_SOUND */
-
- 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->isCanShot = TRUE;
- tux->isCanSwitchGun = TRUE;
-
- if (net_multiplayer_get_game_type() != NET_GAME_TYPE_CLIENT) {
- timer_add_task(arena_get_current()->listTimer, TIMER_ONE,
- timer_spawnTux, newInt(tux->id), TUX_TIME_SPAWN);
- }
-
- if (net_multiplayer_get_game_type() == NET_GAME_TYPE_SERVER) {
- proto_send_kill_server(PROTO_SEND_ALL, NULL, tux);
- }
-}
-
-static void tux_event_tux_is_deadWIthShot(tux_t *tux, shot_t *shot)
-{
- if (shot->author_id == tux->id) {
- tux->score--;
-
- if (net_multiplayer_get_game_type() == NET_GAME_TYPE_SERVER) {
- proto_send_newtux_server(PROTO_SEND_ALL, NULL, tux);
- }
- }
-
- if (shot->author_id != tux->id) {
- tux_t *author;
-
- author = space_get_object_id(arena_get_current()->spaceTux, shot->author_id);
-
- if (author != NULL) {
- author->score++;
-
- if (net_multiplayer_get_game_type() == NET_GAME_TYPE_SERVER) {
- proto_send_newtux_server(PROTO_SEND_ALL, NULL, author);
- }
- }
-
- }
-
- tux_event_tux_is_dead(tux);
-}
-
-void tux_teleport(tux_t *tux)
-{
- int x, y;
-
-#ifndef NO_SOUND
- sound_play("teleport", SOUND_GROUP_BASE);
-#endif /* NO_SOUND */
-
- if (net_multiplayer_get_game_type() != NET_GAME_TYPE_CLIENT) {
- arena_find_free_space(arena_get_current(), &x, &y, TUX_WIDTH, TUX_HEIGHT);
- space_move_object(arena_get_current()->spaceTux, tux, x, y);
- /*tux_set_proportion(tux, x, y);*/
- }
-
- if (net_multiplayer_get_game_type() == NET_GAME_TYPE_SERVER) {
- proto_send_newtux_server(PROTO_SEND_ALL, NULL, tux);
- }
-}
-
-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 = item_new(x, y, ITEM_BIG_EXPLOSION, shot->author_id);
-
- space_add(arena_get_current()->spaceItem, item);
-
- if (net_multiplayer_get_game_type() == NET_GAME_TYPE_SERVER) {
- /*proto_send_del_server(PROTO_SEND_ALL, NULL, shot->id);*/
- proto_send_additem_server(PROTO_SEND_ALL, NULL, item);
- }
-
- /*space_del_with_item(arena_get_current()->spaceShot, shot, shot_destroy);*/
-}
-
-static void action_tux(space_t *space, tux_t *tux, shot_t *shot)
-{
- if (tux->status == TUX_STATUS_ALIVE) {
- if (shot->author_id == tux->id && shot->isCanKillAuthor == FALSE) {
- return;
- }
-
- if (tux->bonus == BONUS_TELEPORT) {
- tux_teleport(tux);
- return;
- }
-
- if (shot->gun == GUN_BOMBBALL) {
- if (net_multiplayer_get_game_type() != NET_GAME_TYPE_CLIENT) {
- bombBallExplosion(shot);
- shot->del = TRUE;
- }
-
- return;
- }
-
- if (net_multiplayer_get_game_type() != NET_GAME_TYPE_CLIENT) {
- tux_event_tux_is_deadWIthShot(tux, shot);
- }
- }
-
- shot->del = TRUE;
-
-/*
- if (net_multiplayer_get_game_type() == NET_GAME_TYPE_SERVER) {
- proto_send_del_server(PROTO_SEND_ALL, NULL, shot->id);
- }
-
- space_del_with_item(arena->spaceShot, shot, shot_destroy);
-*/
-}
-
-static void action_shot(space_t *space, shot_t *shot, space_t *spaceTux)
-{
- space_action_from_location(spaceTux, action_tux, shot, shot->x, shot->y, shot->w, shot->h);
-
- if (shot->del == TRUE) {
- if (net_multiplayer_get_game_type() == NET_GAME_TYPE_SERVER) {
- proto_send_del_server(PROTO_SEND_ALL, NULL, shot->id);
- }
-
- space_del_with_item(space, shot, shot_destroy);
- }
-}
-
-void tux_conflict_woth_shot(arena_t *arena)
-{
- /* just for a test */
- if (net_multiplayer_get_game_type() == NET_GAME_TYPE_CLIENT) {
- return;
- }
-
- space_action(arena->spaceShot, action_shot, arena->spaceTux);
-}
-
-void moveTux(tux_t *tux, int n)
-{
- int px = 0, py = 0; /* no warnings */
- int zal_x, zal_y;
- int new_x, new_y;
- int w, h;
- arena_t *arena;
-
- assert(tux != NULL);
-
- arena = arena_get_current();
- /*interval();*/
-
- 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;
- }
-
- tux_get_proportion(tux, &zal_x, &zal_y, &w, &h);
-
- tux_get_course(tux->position, &px, &py);
-
- new_x = zal_x;
- new_y = zal_y;
-
- new_x += px * TUX_STEP;
- new_y += py * TUX_STEP;
-
- if (tux->bonus == BONUS_SPEED) {
- new_x += px * TUX_STEP;
- new_y += py * TUX_STEP;
- }
-
- if (tux->bonus != BONUS_GHOST &&
- (space_is_conflict_with_object_but(arena->spaceTux, new_x, new_y, w, h, tux) ||
- module_is_conflict(new_x, new_y, w, h))) {
- tux_set_proportion(tux, zal_x, zal_y);
- return;
- }
-
- tux_set_proportion(tux, zal_x, zal_y);
- space_move_object(arena->spaceTux, tux, new_x, new_y);
- item_tux_give_list_item(tux, arena_get_current()->spaceItem);
- tux->frame++;
-
- if (tux->frame == TUX_KEY * TUX_MAX_ANIMATION_FRAME) {
- tux->frame = 0;
- }
-}
-
-void switchTuxGun(tux_t *tux)
-{
- int i;
-
- 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;
- timer_add_task(arena_get_current()->listTimer, TIMER_ONE,
- timer_tuxCanSwitchGun, newInt(tux->id),
- TUX_TIME_CAN_SWITCH_GUN);
-#ifndef NO_SOUND
- sound_play("switch_gun", SOUND_GROUP_BASE);
-#endif /* NO_SOUND */
- return;
- }
- }
-
- for (i = 0; i < GUN_COUNT; i++) {
- if (tux->shot[i] > 0) {
- tux->gun = i;
- tux->isCanSwitchGun = FALSE;
-
- timer_add_task(arena_get_current()->listTimer, TIMER_ONE,
- timer_tuxCanSwitchGun, newInt(tux->id),
- TUX_TIME_CAN_SWITCH_GUN);
-
-#ifndef NO_SOUND
- sound_play("switch_gun", SOUND_GROUP_BASE);
-#endif /* NO_SOUND */
- return;
- }
- }
-}
-
-void shotTux(tux_t *tux)
-{
- assert(tux != NULL);
-
- if (tux->isCanShot == FALSE || tux->shot[tux->gun] == 0) {
- return;
- }
-
-#ifndef NO_SOUND
- sound_play("switch_gun", SOUND_GROUP_BASE);
-#endif /* NO_SOUND */
-
- gun_shot(tux);
-
- tux->isCanShot = FALSE;
-
- timer_add_task(arena_get_current()->listTimer, TIMER_ONE, timer_tuxCanShot,
- newInt(tux->id), TUX_TIME_CAN_SHOT);
-
- if (tux->shot[tux->gun] == 0) {
- switchTuxGun(tux);
- }
-}
-
-void tux_action(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;
- }
-}
-
-static void pickUpGun(tux_t *tux)
-{
- if (tux_is_any_gun(tux) == FALSE) {
- tux->gun = GUN_SIMPLE;
-
- if (tux->pickup_time < TUX_MAX_PICKUP) {
- tux->pickup_time++;
- }
-
- if (tux->pickup_time == TUX_MAX_PICKUP && net_multiplayer_get_game_type() != NET_GAME_TYPE_CLIENT) {
-#ifndef NO_SOUND
- sound_play("switch_gun", SOUND_GROUP_BASE);
-#endif /* NO_SOUND */
-
- tux->gun = GUN_SIMPLE;
- tux->shot[tux->gun] = GUN_MAX_SHOT;
- tux->pickup_time = 0;
-
- if (net_multiplayer_get_game_type() == NET_GAME_TYPE_SERVER) {
- proto_send_newtux_server(PROTO_SEND_ALL, NULL, 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 && net_multiplayer_get_game_type() != NET_GAME_TYPE_CLIENT) {
- if (tux->bonus == BONUS_GHOST) {
- int x, y, w, h;
- tux_get_proportion(tux, &x, &y, &w, &h);
-
- tux->bonus = BONUS_NONE;
-
- if (/*isConflictTuxWithListTux(tux, arena_get_current()->listTux) ||*/
- module_is_conflict(x, y, w, h)) {
- tux->bonus = BONUS_GHOST;
- return;
- }
- }
-
- tux->bonus = BONUS_NONE;
-
- if (net_multiplayer_get_game_type() == NET_GAME_TYPE_SERVER) {
- proto_send_newtux_server(PROTO_SEND_ALL, NULL, tux);
- }
- }
- }
-}
-
-void tux_event(tux_t *tux)
-{
- arena_t *arena;
-
- arena = arena_get_current();
-
-#ifndef PUBLIC_SERVER
- world_tux_control(tux);
-#endif /* PUBLIC_SERVER */
- pickUpGun(tux);
- eventBonus(tux);
- item_tux_give_list_item(tux, arena->spaceItem);
-}
-
-/*
-void eventListTux(list_t *listTux)
-{
- tux_t *thisTux;
- int i;
-
- assert(listTux != NULL);
-
- for (i = 0; i < listTux->count; i++) {
- thisTux = (tux_t *) listTux->list[i];
- assert(thisTux != NULL);
- tux_event(thisTux);
- }
-}
-*/
-
-void tux_get_proportion(tux_t *tux, int *x, int *y, int *w, int *h)
-{
- 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;
- }
-}
-
-void tux_set_proportion(tux_t *tux, int x, int y)
-{
- assert(tux != NULL);
-
- tux->x = x + TUX_WIDTH / 2;
- tux->y = y + TUX_WIDTH / 2;
-}
-
-void tux_get_status(void *p, int *id, int *x, int *y, int *w, int *h)
-{
- tux_t *tux;
-
- tux = p;
- *id = tux->id;
- tux_get_proportion(tux, x, y, w, h);
-}
-
-void tux_set_status(void *p, int x, int y, int w, int h)
-{
- tux_t *tux;
-
- tux = p;
- tux_set_proportion(tux, x, y);
-}
-
-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;
- }
-}
-
-void tux_destroy(tux_t *tux)
-{
- arena_t *arena;
-
- arena = arena_get_current();
-
- assert(tux != NULL);
-
- id_del(tux->id);
-
- space_action(arena->spaceItem, action_checkMine, tux);
-
- free(tux);
-}
-
-void tux_quit()
-{
- isTuxInit = FALSE;
-}
diff --git a/src/base/tux.h b/src/base/tux.h
deleted file mode 100644
index 9258a78..0000000
--- a/src/base/tux.h
+++ /dev/null
@@ -1,135 +0,0 @@
-#ifndef TUX_H
-#define TUX_H
-
-#include "main.h"
-#include "list.h"
-#include "arena.h"
-
-#define TUX_STEP 7
-#define TUX_LAYER 0
-
-#define TUX_MAX_ANIMATION_FRAME 10
-#define TUX_KEY 1
-
-#define TUX_LOCATE_UNKNOWN -100
-
-#define TUX_MAX_PICKUP 50
-#define TUX_MAX_BONUS 500
-
-#define TUX_TIME_SPAWN 2000
-#define TUX_TIME_CAN_SHOT 500
-#define TUX_TIME_CAN_SWITCH_GUN 100
-
-#define TUX_STATUS_ALIVE 0
-#define TUX_STATUS_DEAD 1
-#define TUX_STATUS_PAUZED 2
-
-#define TUX_CONTROL_NONE 0
-#define TUX_CONTROL_KEYBOARD_LEFT 1
-#define TUX_CONTROL_KEYBOARD_RIGHT 2
-#define TUX_CONTROL_NET 3
-#define TUX_CONTROL_AI 4
-
-#define TUX_WIDTH 30
-#define TUX_HEIGHT 30
-
-#define TUX_IMG_WIDTH 40
-#define TUX_IMG_HEIGHT 54
-
-#define TUX_UP 8
-#define TUX_LEFT 4
-#define TUX_RIGHT 6
-#define TUX_DOWN 2
-#define POSITION_UNKNOWN -1
-
-#define TUX_SHOT 5
-#define TUX_SWITCH_GUN 0
-
-
-#define GUN_NONE -1
-
-#define GUN_COUNT 7
-#define GUN_MAX_SHOT 5
-
-#define BONUS_COUNT 6
-#define ITEM_COUNT 16
-
-
-#define SHOT_CHECK_AREA 25
-
-#define GUN_SIMPLE 0
-#define GUN_DUAL_SIMPLE 1
-#define GUN_SCATTER 2
-#define GUN_TOMMY 3
-#define GUN_LASSER 4
-#define GUN_MINE 5
-#define GUN_BOMBBALL 6
-
-#define ITEM_MINE 7
-#define ITEM_EXPLOSION 8
-#define ITEM_BIG_EXPLOSION 9
-
-#define BONUS_NONE -1
-#define BONUS_SPEED 10
-#define BONUS_SHOT 11
-#define BONUS_TELEPORT 12
-#define BONUS_GHOST 13
-#define BONUS_4X 14
-#define BONUS_HIDDEN 15
-
-typedef struct tux_struct {
- int id;
-
- int x;
- int y;
-
- char name[STR_NAME_SIZE];
-
- int status;
- int control;
- int position;
- int score;
-
- int gun;
- int shot[GUN_COUNT];
- int round;
- int bonus;
-
- int bonus_time;
- int pickup_time;
-
- bool_t isCanShot;
- bool_t isCanSwitchGun;
-
- int frame;
-
- void *client;
-} tux_t;
-
-extern bool_t tux_is_inicialized();
-extern void tux_init();
-extern tux_t *tux_new();
-extern void tux_set_name(tux_t *tux, char *name);
-extern bool_t tux_is_any_gun(tux_t *tux);
-extern void tux_get_course(int n, int *x, int *y);
-extern void tux_draw(tux_t *tux);
-/*extern void drawListTux(list_t *listTux);*/
-extern void tux_event_tux_is_dead(tux_t *tux);
-/*extern tux_t *isConflictWithListTux(list_t *listTux, int x, int y, int w, int h);*/
-/*extern int isConflictTuxWithListTux(tux_t *tux, list_t *listTux);*/
-extern void tux_conflict_woth_shot(arena_t *arena);
-/*extern void eventConflictTuxWithTeleport(list_t *listTux, list_t *listTeleport);*/
-extern void tux_teleport(tux_t *tux);
-extern void tux_action(tux_t *tux, int action);
-extern void tux_event(tux_t *tux);
-/*extern void eventListTux(list_t *listTux);*/
-/*extern tux_t *getTuxID(list_t *listTux, int id);*/
-extern void tux_get_proportion(tux_t *tux, int *x, int *y, int *w, int *h);
-extern void tux_replace_id(tux_t *tux, int id);
-extern void tux_set_proportion(tux_t *tux, int x, int y);
-extern void tux_get_status(void *p, int *id, int *x, int *y, int *w, int *h);
-extern void tux_set_status(void *p, int x, int y, int w, int h);
-extern void tux_destroy(tux_t *tux);
-extern void tux_quit();
-
-#endif /* TUX_H */
diff --git a/src/base/udp_server.c b/src/base/udp_server.c
deleted file mode 100644
index aa24c46..0000000
--- a/src/base/udp_server.c
+++ /dev/null
@@ -1,244 +0,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include <sys/types.h>
-
-#include <unistd.h>
-#include <fcntl.h>
-#include <sys/time.h>
-
-#ifndef __WIN32__
-#include <sys/ioctl.h>
-#include <sys/socket.h>
-#include <sys/select.h>
-#else /* __WIN32__ */
-#include <io.h>
-#include <winsock2.h>
-#endif /* __WIN32__ */
-
-#include "main.h"
-#include "list.h"
-#include "tux.h"
-#include "proto.h"
-#include "server.h"
-#include "myTimer.h"
-#include "arena.h"
-#include "net_multiplayer.h"
-#include "checkFront.h"
-#include "protect.h"
-#include "index.h"
-
-#ifndef PUBLIC_SERVER
-#include "world.h"
-#else /* PUBLIC_SERVER */
-#include "publicServer.h"
-#include "highScore.h"
-#include "log.h"
-#endif /* PUBLIC_SERVER */
-
-#include "udp.h"
-#include "udp_server.h"
-#include "serverSelect.h"
-
-static sock_udp_t *sock_server_udp;
-static sock_udp_t *sock_server_udp_second;
-
-client_t *server_udp_new_client(sock_udp_t *sock_udp)
-{
- client_t *new;
-
- assert(sock_udp != NULL);
-
- new = server_new_any_client();
- 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];
-
- sock_udp_get_ip(sock_udp, str_ip, STR_IP_SIZE);
- sprintf(str_log, _("New player [%s]:%d connected"), str_ip, sock_udp_get_port(sock_udp));
- log_add(LOG_INF, str_log);
-#endif /* PUBLIC_SERVER */
-
- return new;
-}
-
-void server_udp_destroy_client(client_t *p)
-{
- check_front_event(p);
-
-#ifdef PUBLIC_SERVER
- char str_log[STR_LOG_SIZE];
- char str_ip[STR_IP_SIZE];
-
- sock_udp_get_ip(p->socket_udp, str_ip, STR_IP_SIZE);
- sprintf(str_log, _("Player [%s]:%d disconnected"), str_ip, sock_udp_get_port(p->socket_udp));
- log_add(LOG_INF, str_log);
-#endif /* PUBLIC_SERVER */
-
- sock_udp_destroy(p->socket_udp);
-
- server_destroy_any_client(p);
-}
-
-int server_udp_init(char *ip4, char *ip6, int port)
-{
- int ret;
-
- ret = 0;
-
- if (ip4 != NULL) {
- sock_server_udp = sock_udp_bind(ip4, port);
-
- if (sock_server_udp != NULL) {
- ret++;
- debug("Starting server on [%s]:%d", ip4, port);
- } else {
- debug("Unable to start server on [%s]:%d", ip4, port);
- }
- }
-
- if (ip6 != NULL) {
- sock_server_udp_second = sock_udp_bind(ip6, port);
-
- if (sock_server_udp_second != NULL) {
- ret++;
- debug("Starting server on [%s]:%d", ip6, port);
- } else {
- debug("Unable to start server on [%s]:%d", ip6, port);
- }
- }
-
- return ret;
-}
-
-static void eventCreateNewUdpClient(sock_udp_t *socket_udp)
-{
- list_t *listClient;
- client_t *client;
-
- assert(socket_udp != NULL);
-
- listClient = server_get_list_clients();
-
- client = server_udp_new_client(socket_udp);
- list_add(listClient, client);
-}
-
-static client_t *findUdpClient(sock_udp_t *sock_udp)
-{
- list_t *listClient;
- int port;
- int i;
-
- port = sock_udp_get_port(sock_udp);
- listClient = server_get_list_clients();
-
- for (i = 0; i < listClient->count; i++) {
- client_t *client;
-
- client = (client_t *) listClient->list[i];
-
- if (client->type == CLIENT_TYPE_UDP &&
- sock_udp_get_port(client->socket_udp) == port) {
- return client;
- }
- }
-
- return NULL;
-}
-
-static void client_eventUdpSelect(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 = sock_udp_new();
- isCreateNewClient = FALSE;
-
- memset(listRecvMsg, 0, STR_SIZE);
-
- ret = sock_udp_read(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) {
- error("UDP client not found");
- return;
- }
-
- if (isCreateNewClient == FALSE) {
- sock_udp_destroy(sock_client);
- }
-
- if (ret <= 0) {
- client->status = NET_STATUS_ZOMBIE;
- return;
- }
-
- /*printf("add packet >>%s<<\n", listRecvMsg);*/
- list_add(client->listRecvMsg, strdup(listRecvMsg));
-}
-
-void server_udp_set_select()
-{
- if (sock_server_udp != NULL) {
- select_add_sock_for_read(sock_server_udp->sock);
- }
-
- if (sock_server_udp_second != NULL) {
- select_add_sock_for_read(sock_server_udp_second->sock);
- }
-}
-
-int server_udp_select_sock()
-{
- int count;
-
- count = 0;
-
- if (sock_server_udp != NULL) {
- if (select_is_change_sock_for_read(sock_server_udp->sock)) {
- client_eventUdpSelect(sock_server_udp);
- count++;
- }
- }
-
- if (sock_server_udp_second != NULL) {
- if (select_is_change_sock_for_read(sock_server_udp_second->sock)) {
- client_eventUdpSelect(sock_server_udp_second);
- count++;
- }
- }
-
- return count;
-}
-
-void server_udp_quit()
-{
- debug("Shutting down UDP");
-
- if (sock_server_udp != NULL) {
- debug("Closing IPv4 [port %d]", sock_udp_get_port(sock_server_udp));
- sock_udp_close(sock_server_udp);
- }
-
- if (sock_server_udp_second != NULL) {
- debug("Closing IPv6 [port %d]", sock_udp_get_port(sock_server_udp_second));
- sock_udp_close(sock_server_udp_second);
- }
-}
diff --git a/src/base/udp_server.h b/src/base/udp_server.h
deleted file mode 100644
index 0d4c1d9..0000000
--- a/src/base/udp_server.h
+++ /dev/null
@@ -1,14 +0,0 @@
-#ifndef SERVER_UDP_H
-#define SERVER_UDP_H
-
-#include "server.h"
-#include "udp.h"
-
-extern client_t *server_udp_new_client(sock_udp_t *sock_udp);
-extern void server_udp_destroy_client(client_t *p);
-extern int server_udp_init(char *ip4, char *ip6, int port);
-extern void server_udp_set_select();
-extern int server_udp_select_sock();
-extern void server_udp_quit();
-
-#endif /* SERVER_UDP_H */