diff options
| author | oroborus <oroborus@0ee4d065-81f0-4d1e-b06c-ff20ad07cc3e> | 2008-07-05 15:56:13 +0000 |
|---|---|---|
| committer | oroborus <oroborus@0ee4d065-81f0-4d1e-b06c-ff20ad07cc3e> | 2008-07-05 15:56:13 +0000 |
| commit | 6ed79c5de77b3f6be5c297cb5432d123ff1ff177 (patch) | |
| tree | a21336754348eb80263aa72768a474c500c8a607 /src | |
| parent | 17b80069913989598a27fc31b952407f895f5b51 (diff) | |
- miny sa nezobrazuju na radare
- tux moze chodit strielat a zmenit zbran sucastne
- master server sa pouziga ten na "ms.tuxanci.org"
- AI sa nastavuje v GUI ako v TFG
git-svn-id: http://opensvn.csie.org/tuxanci_ng@93 0ee4d065-81f0-4d1e-b06c-ff20ad07cc3e
Diffstat (limited to 'src')
| -rw-r--r-- | src/base/net_multiplayer.h | 5 | ||||
| -rw-r--r-- | src/base/proto.c | 5 | ||||
| -rw-r--r-- | src/base/tux.c | 2 | ||||
| -rw-r--r-- | src/net_unix/Makefile | 5 | ||||
| -rw-r--r-- | src/net_unix/dns.c | 19 | ||||
| -rw-r--r-- | src/net_unix/dns.h | 8 | ||||
| -rw-r--r-- | src/screen/screen_browser.c | 15 | ||||
| -rw-r--r-- | src/screen/screen_setting.c | 48 | ||||
| -rw-r--r-- | src/screen/screen_setting.h | 2 | ||||
| -rw-r--r-- | src/screen/screen_world.c | 45 | ||||
| -rw-r--r-- | src/server/publicServer.c | 18 |
11 files changed, 108 insertions, 64 deletions
diff --git a/src/base/net_multiplayer.h b/src/base/net_multiplayer.h index aacd55f..a37df6f 100644 --- a/src/base/net_multiplayer.h +++ b/src/base/net_multiplayer.h @@ -23,8 +23,9 @@ #define LIMIT_BUFFER 10240 -#define NET_MASTER_SERVER "193.85.244.165" -#define NET_MASTER_PORT 2200 +#define NET_MASTER_SERVER_DOMAIN "ms.tuxanci.org" +#define NET_MASTER_SERVER "193.85.244.165" +#define NET_MASTER_PORT 2200 #ifdef PUBLIC_SERVER extern int initNetMulitplayerPublicServer(char *ip4, int port4, char *ip6, int port6); diff --git a/src/base/proto.c b/src/base/proto.c index 9a5cc4b..cc33149 100644 --- a/src/base/proto.c +++ b/src/base/proto.c @@ -618,7 +618,10 @@ void proto_recv_additem_client(char *msg) return; } - addToRadar(id, x, y, RADAR_TYPE_ITEM); + if( type != ITEM_MINE && type != ITEM_EXPLOSION && type != ITEM_BIG_EXPLOSION ) + { + addToRadar(id, x, y, RADAR_TYPE_ITEM); + } item = newItem(x, y, type, author_id); diff --git a/src/base/tux.c b/src/base/tux.c index f60bd1b..7992bd9 100644 --- a/src/base/tux.c +++ b/src/base/tux.c @@ -754,7 +754,7 @@ void eventListTux(list_t *listTux) #endif pickUpGun(thisTux); eventBonus(thisTux); - eventGiveTuxListItem(thisTux, arena->spaceItem); + //eventGiveTuxListItem(thisTux, arena->spaceItem); } } diff --git a/src/net_unix/Makefile b/src/net_unix/Makefile index 648ca88..d13af8e 100644 --- a/src/net_unix/Makefile +++ b/src/net_unix/Makefile @@ -1,6 +1,9 @@ -all: udp.o +all: udp.o dns.o + +dns.o: dns.c dns.h + $(CC) $(CFLAGS) -o dns.o -c dns.c udp.o: udp.c udp.h $(CC) $(CFLAGS) -o udp.o -c udp.c diff --git a/src/net_unix/dns.c b/src/net_unix/dns.c new file mode 100644 index 0000000..f4036a2 --- /dev/null +++ b/src/net_unix/dns.c @@ -0,0 +1,19 @@ + +#include <netdb.h> +#include <string.h> + +#include "base/main.h" + +char* getIPFormDNS(char *domain) +{ + struct hostent *host; + + host = gethostbyname(domain); + + if( host == NULL || host->h_addr_list[0] == NULL ) + { + return NULL; + } + + return strdup( inet_ntoa( * ( (struct in_addr *) host->h_addr_list[0] ) ) ); +} diff --git a/src/net_unix/dns.h b/src/net_unix/dns.h new file mode 100644 index 0000000..ae92c35 --- /dev/null +++ b/src/net_unix/dns.h @@ -0,0 +1,8 @@ + +#ifndef DNS_H + +#define DNS_H + +extern char* getIPFormDNS(char *domain); + +#endif diff --git a/src/screen/screen_browser.c b/src/screen/screen_browser.c index 44b0411..5d99cf7 100644 --- a/src/screen/screen_browser.c +++ b/src/screen/screen_browser.c @@ -26,6 +26,7 @@ #include <errno.h> #include "net_unix/udp.h" +#include "net_unix/dns.h" extern int errno; #endif @@ -377,11 +378,23 @@ static int LoadServers () /* TODO: dodelat TCP makro */ #ifdef SUPPORT_NET_UNIX_UDP struct sockaddr_in server; + char *master_server_ip; + + master_server_ip = getIPFormDNS(NET_MASTER_SERVER_DOMAIN); + + //printf("master_server_ip = %s\n", master_server_ip); + + if( master_server_ip == NULL ) // master server is down + { + return -1; + } server.sin_family = AF_INET; server.sin_port = htons (NET_MASTER_PORT); - server.sin_addr.s_addr = inet_addr (NET_MASTER_SERVER); + server.sin_addr.s_addr = inet_addr (master_server_ip); + free(master_server_ip); + if ((s = socket (AF_INET, SOCK_STREAM, 0)) < 0) { close (s); return 0; diff --git a/src/screen/screen_setting.c b/src/screen/screen_setting.c index fd1388d..5a7fb29 100644 --- a/src/screen/screen_setting.c +++ b/src/screen/screen_setting.c @@ -69,7 +69,7 @@ static widget_textfield_t *textfield_count_cound; static widget_textfield_t *textfield_name_player1; static widget_textfield_t *textfield_name_player2; -static widget_select_t *select_ai; +static widget_check_t *check_ai; static textFile_t *configFile; @@ -129,7 +129,7 @@ void drawScreenSetting() drawWidgetCheck(check[i]); } - drawWidgetSelect(select_ai); + drawWidgetCheck(check_ai); drawWidgetButton(button_back); } @@ -166,7 +166,7 @@ void eventScreenSetting() eventWidgetCheck(check[i]); } - eventWidgetSelect(select_ai); + eventWidgetCheck(check_ai); eventWidgetButton(button_back); } @@ -257,6 +257,9 @@ static void initSettingFile() loadValueFromConfigFile(configFile, "BONUS_HIDDEN", val, STR_SIZE, "YES"); check[BONUS_HIDDEN]->status = isYesOrNO(val); + loadValueFromConfigFile(configFile, "AI", val, STR_SIZE, "NO"); + check_ai->status = isYesOrNO(val); + #ifndef NO_SOUND loadValueFromConfigFile(configFile, "MUSIC", val, STR_SIZE, "YES"); check_music->status = isYesOrNO(val); @@ -295,6 +298,8 @@ static void saveAndDestroyConfigFile() setValueInConfigFile(configFile, "BONUS_4X", getYesOrNo(check[BONUS_4X]->status) ); setValueInConfigFile(configFile, "BONUS_HIDDEN", getYesOrNo(check[BONUS_HIDDEN]->status) ); + setValueInConfigFile(configFile, "AI", getYesOrNo(check_ai->status) ); + #ifndef NO_SOUND setValueInConfigFile(configFile, "MUSIC", getYesOrNo(check_music->status) ); setValueInConfigFile(configFile, "SOUND", getYesOrNo(check_sound->status) ); @@ -304,29 +309,6 @@ static void saveAndDestroyConfigFile() destroyTextFile(configFile); } -static void findModulesAI() -{ - director_t *listModules; - int i; - - listModules = loadDirector(PATH_MODULES); - - for( i = 0 ; i < listModules->list->count ; i++) - { - char *line; - - line = (char *)listModules->list->list[i]; - - if( strstr(line,"AI") != NULL && - strstr(line,".so") != NULL ) - { - addToWidgetSelect(select_ai, line); - } - } - - destroyDirector(listModules); -} - void initScreenSetting() { SDL_Surface *image; @@ -357,6 +339,8 @@ void initScreenSetting() WINDOW_SIZE_Y-80, isSoundActive() , eventWidget); #endif + check_ai = newWidgetCheck(460, 405, FALSE, eventWidget); + for( i = GUN_DUAL_SIMPLE ; i <= GUN_BOMBBALL ; i++ ) { int x = 0; @@ -416,10 +400,6 @@ void initScreenSetting() initSettingFile(); - select_ai = newWidgetSelect(label_ai->x, label_ai->y+40, eventWidget); - addToWidgetSelect(select_ai, "none"); - findModulesAI(); - #ifndef NO_SOUND eventWidget(check_music); eventWidget(check_sound); @@ -441,9 +421,9 @@ void getSettingCountRound(int *n) *n = atoi( textfield_count_cound->text ); } -char* getSettingAI() +bool_t isSettingAI() { - return (char *) select_ai->list->list[ select_ai->select ]; + return check_ai->status; } bool_t isSettingAnyItem() @@ -515,6 +495,8 @@ void quitScreenSetting() destroyWidgetCheck(check_sound); #endif + destroyWidgetCheck(check_ai); + for( i = GUN_DUAL_SIMPLE ; i <= GUN_BOMBBALL ; i++ ) { destroyWidgetCheck(check[i]); @@ -525,8 +507,6 @@ void quitScreenSetting() destroyWidgetCheck(check[i]); } - destroyWidgetSelect(select_ai); - destroyWidgetButton(button_back); } diff --git a/src/screen/screen_setting.h b/src/screen/screen_setting.h index 5b0bae3..b9631f8 100644 --- a/src/screen/screen_setting.h +++ b/src/screen/screen_setting.h @@ -11,7 +11,7 @@ extern void eventScreenSetting(); extern void getSettingNameRight(char *s); extern void getSettingNameLeft(char *s); extern void getSettingCountRound(int *n); -extern char* getSettingAI(); +extern bool_t isSettingAI(); extern bool_t isSettingAnyItem(); extern bool_t isSettingItem(int item); extern void quitScreenSetting(); diff --git a/src/screen/screen_world.c b/src/screen/screen_world.c index 380fd43..91820ff 100644 --- a/src/screen/screen_world.c +++ b/src/screen/screen_world.c @@ -148,10 +148,12 @@ void prepareArena() getSettingNameLeft(tux->name); addObjectToSpace(arena->spaceTux, tux); - if( strcmp(getSettingAI(), "none") != 0 ) + if( isSettingAI() ) { - loadModule( getSettingAI() ); - tux->control = TUX_CONTROL_AI; + if( loadModule("modAI.so") == 0 ) + { + tux->control = TUX_CONTROL_AI; + } } break; @@ -237,6 +239,16 @@ static void control_keyboard_right(tux_t *tux) if( mapa[(SDLKey)getKey(KEY_TUX_RIGHT_MOVE_LEFT)] == SDL_PRESSED )countKey++; if( mapa[(SDLKey)getKey(KEY_TUX_RIGHT_MOVE_DOWN)] == SDL_PRESSED )countKey++; + if( mapa[(SDLKey)getKey(KEY_TUX_RIGHT_SWITCH_WEAPON)] == SDL_PRESSED ) + { + if( tux->isCanSwitchGun == TRUE ) + { + netAction(tux, TUX_SWITCH_GUN); + actionTux(tux, TUX_SWITCH_GUN); + return; + } + } + if( mapa[(SDLKey)getKey(KEY_TUX_RIGHT_SHOOT)] == SDL_PRESSED && tux->isCanShot == TRUE ) { netAction(tux, TUX_SHOT); @@ -292,16 +304,6 @@ static void control_keyboard_right(tux_t *tux) tuDown:; } - - if( mapa[(SDLKey)getKey(KEY_TUX_RIGHT_SWITCH_WEAPON)] == SDL_PRESSED ) - { - if( tux->isCanSwitchGun == TRUE ) - { - netAction(tux, TUX_SWITCH_GUN); - actionTux(tux, TUX_SWITCH_GUN); - return; - } - } } static void control_keyboard_left(tux_t *tux) @@ -321,6 +323,15 @@ static void control_keyboard_left(tux_t *tux) if( mapa[(SDLKey)getKey(KEY_TUX_LEFT_MOVE_LEFT)] == SDL_PRESSED )countKey++; if( mapa[(SDLKey)getKey(KEY_TUX_LEFT_MOVE_DOWN)] == SDL_PRESSED )countKey++; + if( mapa[(SDLKey)getKey(KEY_TUX_LEFT_SWITCH_WEAPON)] == SDL_PRESSED ) + { + if( tux->isCanSwitchGun == TRUE ) + { + actionTux(tux, TUX_SWITCH_GUN); + return; + } + } + if( mapa[(SDLKey)getKey(KEY_TUX_LEFT_SHOOT)] == SDL_PRESSED && tux->isCanShot == TRUE ) { actionTux(tux, TUX_SHOT); @@ -372,14 +383,6 @@ static void control_keyboard_left(tux_t *tux) tuDown:; } - if( mapa[(SDLKey)getKey(KEY_TUX_LEFT_SWITCH_WEAPON)] == SDL_PRESSED ) - { - if( tux->isCanSwitchGun == TRUE ) - { - actionTux(tux, TUX_SWITCH_GUN); - return; - } - } /* if( mapa[(SDLKey)getKey(KEY_TUX_LEFT_MOVE_UP)] == SDL_PRESSED )actionTux(tux, TUX_UP); if( mapa[(SDLKey)getKey(KEY_TUX_LEFT_MOVE_RIGHT)] == SDL_PRESSED )actionTux(tux, TUX_RIGHT); diff --git a/src/server/publicServer.c b/src/server/publicServer.c index 1d2ccf0..d7246a0 100644 --- a/src/server/publicServer.c +++ b/src/server/publicServer.c @@ -32,6 +32,8 @@ #include "server/serverConfigFile.h" #include "server/heightScore.h" +#include "net_unix/dns.h" + static int arenaId; static arena_t *arena; static bool_t isSignalEnd; @@ -58,11 +60,23 @@ static int registerPublicServer() /* TODO: dodelat TCP makro */ #ifdef SUPPORT_NET_UNIX_UDP struct sockaddr_in server; - + char *master_server_ip; + + master_server_ip = getIPFormDNS(NET_MASTER_SERVER_DOMAIN); + + //printf("master_server_ip = %s\n", master_server_ip); + + if( master_server_ip == NULL ) // master server is down + { + return -1; + } + server.sin_family = AF_INET; server.sin_port = htons (NET_MASTER_PORT); - server.sin_addr.s_addr = inet_addr (NET_MASTER_SERVER); + server.sin_addr.s_addr = inet_addr (master_server_ip); + free(master_server_ip); + if ((s = socket (AF_INET, SOCK_STREAM, 0)) < 0) { close (s); return 0; |