summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/CMakeLists.txt4
-rw-r--r--src/base/arenaFile.c12
-rw-r--r--src/base/arenaFile.h1
-rw-r--r--src/base/proto.c3
-rw-r--r--src/client/game.c3
-rwxr-xr-xsrc/downserver/Makefile14
-rw-r--r--src/downserver/arena.conf5
-rw-r--r--src/downserver/downServer.c376
-rw-r--r--src/screen/screen_choiceArena.c7
-rw-r--r--src/screen/screen_downArena.c406
-rw-r--r--src/screen/screen_downArena.h22
-rw-r--r--src/screen/screen_gameType.c3
12 files changed, 848 insertions, 8 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 4504227..2560114 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -31,7 +31,7 @@ ENDIF ( Win )
#IF ( Win )
SET ( SRC_base
${SRC_base}
- ${WORKDIR}/net/udp
+ ${WORKDIR}/net/udp ${WORKDIR}/net/tcp
${WORKDIR}/base/udp_server )
#ELSE ( Win )
# SET ( SRC_base
@@ -74,7 +74,7 @@ SET ( SRC_client
${WORKDIR}/screen/screen_setting ${WORKDIR}/screen/screen_credits
${WORKDIR}/screen/screen_world ${WORKDIR}/screen/screen_analyze
${WORKDIR}/screen/screen_mainMenu ${WORKDIR}/screen/screen_browser
- ${WORKDIR}/screen/screen_gameType
+ ${WORKDIR}/screen/screen_gameType ${WORKDIR}/screen/screen_downArena
${WORKDIR}/widget/widget_check ${WORKDIR}/widget/widget_button
${WORKDIR}/widget/widget_textfield ${WORKDIR}/widget/widget_label
diff --git a/src/base/arenaFile.c b/src/base/arenaFile.c
index 6c50d34..10b4449 100644
--- a/src/base/arenaFile.c
+++ b/src/base/arenaFile.c
@@ -15,6 +15,7 @@
#include "director.h"
#include "modules.h"
#include "archive.h"
+#include "homeDirector.h"
#ifndef PUBLIC_SERVER
#include "configFile.h"
@@ -301,6 +302,11 @@ void destroyArenaFile(arenaFile_t *p)
free(p);
}
+void loadArenaFile(char *path)
+{
+ addList(listArenaFile, newArenaFile(path) );
+}
+
void initArenaFile()
{
director_t *p;
@@ -311,7 +317,10 @@ void initArenaFile()
#endif
isArenaFileInit = TRUE;
listArenaFile = newList();
+
p = loadDirector(PATH_ARENA);
+ //p = loadDirector( getHomeDirector() );
+
for (i = 0; i < p->list->count; i++) {
char *line;
@@ -326,8 +335,7 @@ void initArenaFile()
printf(_("Loading arena: %s\n"), line);
#endif
accessExistFile(path);
-
- addList(listArenaFile, newArenaFile(path));
+ loadArenaFile(path);
}
}
//printf("No. of Arens: %d\n", listArenaFile->count);
diff --git a/src/base/arenaFile.h b/src/base/arenaFile.h
index 4f1cdc5..652cdf0 100644
--- a/src/base/arenaFile.h
+++ b/src/base/arenaFile.h
@@ -28,6 +28,7 @@ extern arenaFile_t* getArenaFile(int n);
extern int getArenaFileID(arenaFile_t *arenaFile);
extern arena_t* getArena(arenaFile_t *arenaFile);
extern arenaFile_t* newArenaFile(char *path);
+extern void loadArenaFile(char *path);
extern void initArenaFile();
extern void quitArenaFile();
diff --git a/src/base/proto.c b/src/base/proto.c
index 5097146..304eff8 100644
--- a/src/base/proto.c
+++ b/src/base/proto.c
@@ -25,6 +25,7 @@
#include "screen_setting.h"
#include "screen_choiceArena.h"
#include "screen_analyze.h"
+#include "screen_downArena.h"
#include "client.h"
#include "term.h"
#include "radar.h"
@@ -379,7 +380,7 @@ void proto_recv_init_client(char *msg)
}
proto_send_check_client(check_id);
-
+
if( getCurrentArena() != NULL )
{
return;
diff --git a/src/client/game.c b/src/client/game.c
index b0d2322..68b88d7 100644
--- a/src/client/game.c
+++ b/src/client/game.c
@@ -36,6 +36,7 @@
#include "screen_setting.h"
#include "screen_settingKeys.h"
#include "screen_gameType.h"
+#include "screen_downArena.h"
#include "screen_choiceArena.h"
#include "screen_table.h"
#include "screen_credits.h"
@@ -68,6 +69,7 @@ static void initGame()
initScreenSetting();
initScreenSettingKeys();
initScreenGameType();
+ initScreenDownArena();
initScreenCredits();
initScreenTable();
initScreenBrowser();
@@ -82,6 +84,7 @@ void quitGame()
quitScreenSetting();
quitScreenSettingKeys();
quitScreenGameType();
+ quitScreenDownArena();
quitScreenChoiceArena();
quitScreenCredits();
quitScreenTable();
diff --git a/src/downserver/Makefile b/src/downserver/Makefile
new file mode 100755
index 0000000..df15b12
--- /dev/null
+++ b/src/downserver/Makefile
@@ -0,0 +1,14 @@
+
+#CC = /usr/local/gcc/bin/gcc
+CC = gcc
+
+CFLAGS = -g -O0 -std=c99 -D_GNU_SOURCE=1 -I../base -I../net
+LIBS =
+
+FILES = ../base/list.o ../base/textFile.o ../base/buffer.o ../net/tcp.o
+
+downServer: downServer.c $(FILES)
+ $(CC) $(CFLAGS) $(LIBS) -o downServer downServer.c $(FILES)
+
+clean:
+ rm -rf *.o *.c~ *.h~ Makefile~
diff --git a/src/downserver/arena.conf b/src/downserver/arena.conf
new file mode 100644
index 0000000..c936e19
--- /dev/null
+++ b/src/downserver/arena.conf
@@ -0,0 +1,5 @@
+/home/dusan/projectTuxanci/tuxanci_ng/data/arena/for_a_good_night.zip FAGN
+/home/dusan/projectTuxanci/tuxanci_ng/data/arena/night_workshift.zip NW
+/home/dusan/projectTuxanci/tuxanci_ng/data/arena/in_a_captivity_of_8-bit.zip IACO8B
+/home/dusan/projectTuxanci/tuxanci_ng/data/arena/construction_site.zip CS
+
diff --git a/src/downserver/downServer.c b/src/downserver/downServer.c
new file mode 100644
index 0000000..ae1c314
--- /dev/null
+++ b/src/downserver/downServer.c
@@ -0,0 +1,376 @@
+
+#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 "list.h"
+#include "tcp.h"
+#include "buffer.h"
+#include "textFile.h"
+
+#define CLIENT_LIMIT_BUFFER (4096+256)
+
+#define STR_PATH_SIZE 4096
+#define STR_ARENA_NET_NAME_SIZE 256
+#define BUFFER_SEND_FILE_SIZE 4096
+
+#define NET_STATUS_OK 0
+#define NET_STATUS_ZOMBIE 1
+
+#define BUFFER_SIZE 256
+#define PROTO_SIZE 256
+
+static sock_tcp_t *sock_server_tcp;
+static list_t *listClient;
+static textFile_t *configFile;
+
+typedef struct
+{
+ int status;
+
+ FILE *file;
+ int fileSize;
+ int fileOffset;
+
+ sock_tcp_t *socket;
+ buffer_t *recvBuffer;
+ buffer_t *sendBuffer;
+} client_t;
+
+static client_t* newClient(sock_tcp_t *sock)
+{
+ client_t *new;
+
+ new = malloc( sizeof(client_t) );
+ new->socket = sock;
+ new->status = NET_STATUS_OK;
+ new->file = NULL;
+ new->recvBuffer = newBuffer(CLIENT_LIMIT_BUFFER);
+ new->sendBuffer = newBuffer(CLIENT_LIMIT_BUFFER);
+
+ return new;
+}
+
+static void destroyClient(client_t *client)
+{
+ if( client->file != NULL )fclose(client->file);
+ closeTcpSocket(client->socket);
+ destroyBuffer(client->recvBuffer);
+ destroyBuffer(client->sendBuffer);
+ free(client);
+}
+
+int getFileSize(char *s)
+{
+ struct stat buf;
+
+ if( lstat(s, &buf) < 0 )
+ {
+ return -1;
+ }
+
+ return buf.st_size;
+}
+
+static char* getFileFromArenaNetName(char *s)
+{
+ int i;
+
+ for( i = 0 ; i < configFile->text->count ; i++ )
+ {
+ char path[STR_PATH_SIZE];
+ char arena[STR_ARENA_NET_NAME_SIZE];
+ char *line;
+ int len;
+
+ line = configFile->text->list[i];
+
+ sscanf(line, "%s %s", path, arena);
+ len = strlen(arena);
+
+ if( strncmp(arena, s, len) == 0 )
+ {
+ return strdup(path);
+ }
+ }
+
+ return NULL;
+}
+
+static void proto_getarena(client_t *client, char *msg)
+{
+ char msg_out[PROTO_SIZE];
+ char *path;
+
+ path = getFileFromArenaNetName(msg);
+
+ if( path != NULL )
+ {
+ client->file = fopen(path, "rb");
+ client->fileSize = getFileSize(path);
+ client->fileOffset = 0;
+ free(path);
+
+ if( client->file == NULL || client->fileSize < 0 )
+ {
+ client->file = NULL;
+ client->fileSize = 0;
+ sprintf(msg_out, "ERR server has a problem !\n");
+ }
+ else
+ {
+ sprintf(msg_out, "OK %d\n", client->fileSize);
+ }
+ }
+ else
+ {
+ sprintf(msg_out, "ERR arena not found\n");
+ }
+
+ addBuffer(client->sendBuffer, msg_out, strlen(msg_out));
+}
+
+static void doProto(client_t *client, char *msg)
+{
+ printf("hmm msg = %s\n", msg);
+
+ if( strncmp(msg, "GETARENA", 8) == 0 && client->file == NULL )
+ {
+ proto_getarena(client, msg+9);
+ }
+}
+
+static int initDownServer(char *ip, int port)
+{
+ sock_server_tcp = bindTcpSocket(ip, port, PROTO_TCPv4);
+
+ listClient = newList();
+
+ configFile = loadTextFile("arena.conf");
+
+ return 0;
+}
+
+static void eventNewClient(sock_tcp_t *server_sock)
+{
+ sock_tcp_t *sock;
+ client_t *client;
+
+ sock = getTcpNewClient(server_sock);
+ setTcpSockNonBlock(sock);
+
+ client = newClient(sock);
+ addList(listClient, client);
+}
+
+static void eventRecvClient(client_t *client)
+{
+ char buffer[BUFFER_SIZE];
+ char line[PROTO_SIZE];
+ int ret;
+
+ memset(buffer, 0, BUFFER_SIZE);
+
+ ret = readTcpSocket(client->socket, buffer, BUFFER_SIZE-1);
+ //printf("readTcpSocket = %d\n", ret);
+
+ if( ret <= 0 )
+ {
+ client->status = NET_STATUS_ZOMBIE;
+ return;
+ }
+
+ if( addBuffer(client->recvBuffer, buffer, ret) < 0 )
+ {
+ client->status = NET_STATUS_ZOMBIE;
+ return;
+ }
+
+ while( getBufferLine(client->recvBuffer, line, PROTO_SIZE) >= 0 )
+ {
+ doProto(client, line);
+ }
+}
+
+static void eventSendClient(client_t *client)
+{
+ void *data;
+ int len;
+ int res;
+
+ len = getBufferSize(client->sendBuffer);
+
+ if( len == 0 )
+ {
+ return;
+ }
+
+ data = getBufferData(client->sendBuffer);
+
+ res = writeTcpSocket(client->socket, data, len);
+ //printf("send = %d\n", res);
+ //printf("writeTcpSocket = %d\n", res);
+
+ if( res < 0 )
+ {
+ client->status = NET_STATUS_ZOMBIE;
+ return;
+ }
+
+ cutBuffer(client->sendBuffer, res);
+}
+
+static void eventClient(client_t *client)
+{
+ if( client->file != NULL && getBufferSize(client->sendBuffer) == 0 )
+ {
+ char buffer[BUFFER_SEND_FILE_SIZE];
+ int count;
+ int ret;
+
+ count = client->fileSize - client->fileOffset;
+
+ if( count > BUFFER_SEND_FILE_SIZE )
+ {
+ count = BUFFER_SEND_FILE_SIZE;
+ }
+
+ ret = fread(buffer, count, 1, client->file);
+ //printf("read = %d\n", count);
+
+ if( ret == 1 )
+ {
+ if( addBuffer(client->sendBuffer, buffer, count) < 0 )
+ {
+ client->status = NET_STATUS_ZOMBIE;
+ return;
+ }
+
+ client->fileOffset += count;
+ }
+ else
+ {
+ client->status = NET_STATUS_ZOMBIE;
+ }
+ }
+}
+
+void startDownServer()
+{
+ struct timeval tv;
+ fd_set readfds;
+ fd_set writefds;
+ int max_fd;
+ int ret;
+ int i;
+
+ tv.tv_sec = 1;
+ tv.tv_usec = 0;
+ FD_ZERO(&readfds);
+ FD_ZERO(&writefds);
+
+ max_fd = sock_server_tcp->sock;
+
+ FD_SET(sock_server_tcp->sock, &readfds);
+
+ for( i = 0 ; i < listClient->count ; i++ )
+ {
+ client_t *client;
+ int sock;
+
+ client = (client_t *)listClient->list[i];
+
+ if( client->status != NET_STATUS_ZOMBIE )
+ {
+ sock = client->socket->sock;
+
+ if( sock > max_fd )
+ {
+ max_fd = sock;
+ }
+
+ FD_SET(sock, &readfds);
+
+ if( getBufferSize(client->sendBuffer) > 0 )
+ {
+ FD_SET(sock, &writefds);
+ }
+ }
+ }
+
+ ret = select(max_fd+1, &readfds, &writefds, (fd_set *)NULL, &tv);
+
+ if( ret > 0 )
+ {
+ if( FD_ISSET(sock_server_tcp->sock, &readfds) )
+ {
+ eventNewClient(sock_server_tcp);
+ }
+
+ for( i = 0 ; i < listClient->count ; i++ )
+ {
+ client_t *client;
+ int sock;
+
+ client = (client_t *)listClient->list[i];
+ sock = client->socket->sock;
+
+ if( FD_ISSET(sock, &readfds) )
+ {
+ eventRecvClient(client);
+ }
+
+ if( FD_ISSET(sock, &writefds) )
+ {
+ eventSendClient(client);
+ }
+ }
+ }
+
+ for( i = 0 ; i < listClient->count ; i++ )
+ {
+ client_t *client;
+
+ client = (client_t *)listClient->list[i];
+
+ if( client->status == NET_STATUS_ZOMBIE )
+ {
+ delListItem(listClient, i, destroyClient);
+ i--;
+ continue;
+ }
+
+ eventClient(client);
+ }
+}
+
+void quitDownServer()
+{
+ closeTcpSocket(sock_server_tcp);
+ destroyListItem(listClient, destroyClient);
+}
+
+int isFillPath(const char *path)
+{
+ return 0;
+}
+
+int main(int argc, char **argv)
+{
+ signal(SIGPIPE, SIG_IGN);
+
+ initDownServer("127.0.0.1", 2200);
+
+ while(1)
+ {
+ startDownServer();
+ }
+}
diff --git a/src/screen/screen_choiceArena.c b/src/screen/screen_choiceArena.c
index b12b8ec..b6c66b5 100644
--- a/src/screen/screen_choiceArena.c
+++ b/src/screen/screen_choiceArena.c
@@ -112,8 +112,11 @@ void setChoiceArena(arenaFile_t *arenaFile)
id = getArenaFileID(arenaFile);
currentArena = arenaFile;
- widget_buttonimage = (widget_t *)listWidgetButtonimage->list[id];
- setWidgetButtonimageActive(widget_buttonimage, TRUE);
+ if( id >= 0 )
+ {
+ widget_buttonimage = (widget_t *)listWidgetButtonimage->list[id];
+ setWidgetButtonimageActive(widget_buttonimage, TRUE);
+ }
}
static void eventWidget(void *p)
diff --git a/src/screen/screen_downArena.c b/src/screen/screen_downArena.c
new file mode 100644
index 0000000..00ab83a
--- /dev/null
+++ b/src/screen/screen_downArena.c
@@ -0,0 +1,406 @@
+
+#include <stdio.h>
+#include <unistd.h>
+#include <assert.h>
+
+#include "main.h"
+#include "list.h"
+#include "buffer.h"
+#include "textFile.h"
+#include "arenaFile.h"
+#include "homeDirector.h"
+
+#include "interface.h"
+#include "screen.h"
+#include "image.h"
+
+#include "net_multiplayer.h"
+#include "udp.h"
+#include "tcp.h"
+
+#include "widget.h"
+#include "widget_image.h"
+#include "widget_label.h"
+#include "widget_button.h"
+
+#include "screen_setting.h"
+#include "screen_downArena.h"
+#include "screen_gameType.h"
+
+static sock_udp_t *sock_server_udp;
+static sock_tcp_t *sock_server_tcp;
+
+static widget_t *image_backgorund;
+static widget_t *button_back;
+static widget_t *label_status;
+
+static char str_status[STR_PROTO_SIZE];
+static char arenaNetName[STR_SIZE];
+
+static int status_tcp_socket;
+static buffer_t *recvBuffer;
+static buffer_t *sendBuffer;
+
+static char path[STR_PATH_SIZE];
+static FILE *file;
+static int fileSize;
+static int fileOffset;
+
+static my_time_t timeSendMsg;
+static int countSendMsg;
+
+static void setStatusString(char *s)
+{
+ //printf("status -> %s\n", s);
+ destroyWidgetLabel(label_status);
+ label_status = newWidgetLabel(s, WINDOW_SIZE_X/2, 250, WIDGET_LABEL_CENTER);
+}
+
+static void connectToDownServer()
+{
+ char status[STR_SIZE];
+ char msg[STR_PROTO_SIZE];
+
+ sock_server_tcp = connectTcpSocket(getSettingIP(), getSettingPort(), PROTO_TCPv4);
+
+ if( sock_server_tcp == NULL )
+ {
+ sprintf(status, "I do not connect to %s %d TCP down server", getSettingIP(), getSettingPort());
+ setStatusString(status);
+ return;
+ }
+
+ setTcpSockNonBlock(sock_server_tcp);
+
+ recvBuffer = newBuffer(DOWN_ARENA_BUFFER_SIZE);
+ sendBuffer = newBuffer(DOWN_ARENA_BUFFER_SIZE);
+ status_tcp_socket = DOWN_SERVER_STATUS_OK;
+
+ file = NULL;
+ countSendMsg = 0;
+ timeSendMsg = getMyTime();
+
+ sprintf(msg, "GETARENA %s\n", arenaNetName);
+
+ addBuffer(sendBuffer, msg, strlen(msg));
+
+ sprintf(status, "Connect to %s %d TCP down server", getSettingIP(), getSettingPort());
+ setStatusString(status);
+}
+
+static void closeConnectFromDownServer()
+{
+ closeTcpSocket(sock_server_tcp);
+ destroyBuffer(recvBuffer);
+ destroyBuffer(sendBuffer);
+ sock_server_tcp = NULL;
+ recvBuffer = NULL;
+ sendBuffer = NULL;
+}
+
+static void sendStatusToGameServer()
+{
+ char *msg = "status\n";
+
+ if( countSendMsg > DOWN_ARENA_MAX_SEND_MSG_STATUS )
+ {
+ char status[STR_SIZE];
+ sprintf(status, "Game server %s %d is down", getSettingIP(), getSettingPort());
+ setStatusString(status);
+ return;
+ }
+
+ timeSendMsg = getMyTime();
+ countSendMsg++;
+ printf("countSendMsg = %d\n", countSendMsg++);
+
+ if( writeUdpSocket(sock_server_udp, sock_server_udp, msg, strlen(msg)) < 0 )
+ {
+ char status[STR_SIZE];
+ sprintf(status, "I do not send message to %s %d UDP game server", getSettingIP(), getSettingPort());
+ setStatusString(status);
+ }
+}
+
+void startScreenDownArena()
+{
+ char status[STR_SIZE];
+
+ strcpy(str_status, "none");
+ memset(arenaNetName, 0, STR_SIZE);
+
+ sock_server_udp = connectUdpSocket(getSettingIP(), getSettingPort(), PROTO_UDPv4);
+
+ if( sock_server_udp == NULL )
+ {
+ sprintf(status, "I do not connect to %s %d UDP game server", getSettingIP(), getSettingPort());
+ setStatusString(status);
+ return;
+ }
+
+ setUdpSockNonBlock(sock_server_udp);
+
+ sprintf(status, "Connect to %s %d UDP game server", getSettingIP(), getSettingPort());
+ setStatusString(status);
+
+ sendStatusToGameServer();
+}
+
+void drawScreenDownArena()
+{
+ drawWidgetImage(image_backgorund);
+ drawWidgetLabel(label_status);
+ drawWidgetButton(button_back);
+}
+
+static void proto_ok(char *line)
+{
+ //printf("line = %s\n", line);
+ fileSize = atoi(line+3);
+ fileOffset = 0;
+
+ sprintf(path, "%s/%s.zip", getHomeDirector(), arenaNetName);
+ //printf("path = %s\n", path);
+ file = fopen(path, "wb");
+}
+
+static void proto_err(char *line)
+{
+ //printf("line = %s\n", line);
+ setStatusString(line+4);
+ closeConnectFromDownServer();
+}
+
+static void eventProto(char *line)
+{
+ if( strncmp(line, "OK", 2) == 0 )
+ {
+ proto_ok(line);
+ }
+
+ if( strncmp(line, "ERR", 3) == 0 )
+ {
+ proto_err(line);
+ }
+}
+
+static int downArenaFile()
+{
+ char status[STR_SIZE];
+ void *data;
+ int len;
+
+ len = getBufferSize(recvBuffer);
+ data = getBufferData(recvBuffer);
+ cutBuffer(recvBuffer, len);
+
+ fwrite(data, len, 1, file);
+ fileOffset += len;
+
+ sprintf(status, "I down %d / %d", fileOffset, fileSize);
+ setStatusString(status);
+
+ return len;
+}
+
+static int eventRecvBuffer()
+{
+ char buffer[STR_PROTO_SIZE];
+ char line[STR_PROTO_SIZE];
+ int ret;
+
+ memset(buffer, 0, STR_PROTO_SIZE);
+
+ ret = readTcpSocket(sock_server_tcp, buffer, STR_PROTO_SIZE-1);
+ //printf("readTcpSocket = %d\n", ret);
+
+ if( ret < 0 )
+ {
+ return -1;
+ }
+
+ if( addBuffer(recvBuffer, buffer, ret) < 0 )
+ {
+ char status[STR_SIZE];
+ sprintf(status, "Error -- recv buffer is full");
+ setStatusString(status);
+ closeConnectFromDownServer();
+ return -1;
+ }
+
+ if( file == NULL && getBufferLine(recvBuffer, line, STR_PROTO_SIZE) >= 0 )
+ {
+ eventProto(line);
+ return ret;
+ }
+
+ if( file != NULL )
+ {
+ return downArenaFile();
+ }
+
+ return -1;
+}
+
+static int eventSendBuffer()
+{
+ void *data;
+ int len;
+ int res;
+
+ len = getBufferSize(sendBuffer);
+
+ if( len == 0 )
+ {
+ return -1;
+ }
+
+ data = getBufferData(sendBuffer);
+
+ res = writeTcpSocket(sock_server_tcp, data, len);
+
+ if( res < 0 )
+ {
+ return -1;
+ }
+
+ cutBuffer(sendBuffer, res);
+ return res;
+}
+
+static void readArenaFromStatus()
+{
+ const char *str_arena = "arena: ";
+
+ char *offset_begin;
+ char *offset_end;
+
+ offset_begin = strstr(str_status, str_arena);
+
+ if( offset_begin != NULL )
+ {
+ offset_begin += strlen(str_arena);
+ offset_end = strstr(offset_begin, "\n");
+
+ if( offset_end != NULL )
+ {
+ closeUdpSocket(sock_server_udp);
+ sock_server_udp = NULL;
+ strncpy(arenaNetName, offset_begin, offset_end-offset_begin);
+
+ if( getArenaFileFormNetName(arenaNetName) != NULL )
+ {
+ setScreen("world");
+ return;
+ }
+
+ connectToDownServer();
+
+ //printf("arenaNetName = >>%s<<\n", arenaNetName);
+ }
+ }
+}
+
+static void eventStatus()
+{
+ if( getMyTime() - timeSendMsg > DOWN_ARENA_MAX_TIEMOUT_LIMIT )
+ {
+ sendStatusToGameServer();
+ }
+
+ if( readUdpSocket(sock_server_udp, sock_server_udp, str_status, STR_PROTO_SIZE-1) > 0 )
+ {
+ //printf("str_status = %s\n", str_status);
+ readArenaFromStatus();
+ }
+}
+
+void eventScreenDownArena()
+{
+ int i;
+
+ if( strcmp(str_status, "none") == 0 )
+ {
+ eventStatus();
+ }
+
+ if( recvBuffer != NULL )
+ {
+ for( i = 0 ; i < DOWN_ARENA_COUNT_READ_SOCKET ; i++ )
+ {
+ if( eventRecvBuffer() <= 0 )
+ {
+ break;
+ }
+ }
+ }
+
+ if( sendBuffer != NULL )
+ {
+ eventSendBuffer();
+ }
+
+ if( file != NULL && fileSize == fileOffset && fileSize > 0 )
+ {
+ fclose(file);
+ file = NULL;
+ closeConnectFromDownServer();
+ loadArenaFile(path);
+ setScreen("world");
+ }
+
+ eventWidgetButton(button_back);
+}
+
+void stopScreenDownArena()
+{
+ if( file != NULL )
+ {
+ unlink(path);
+ }
+
+ if( sock_server_tcp != NULL )
+ {
+ closeConnectFromDownServer();
+ }
+
+ if( sock_server_udp != NULL )
+ {
+ closeUdpSocket(sock_server_udp);
+ }
+
+}
+
+static void eventWidget(void *p)
+{
+ widget_t *button;
+
+ button = (widget_t *)(p);
+
+ if( button == button_back )
+ {
+ setScreen("mainMenu");
+ }
+}
+
+void initScreenDownArena()
+{
+ image_t *image;
+
+ image = getImage(IMAGE_GROUP_BASE, "screen_main");
+ image_backgorund = newWidgetImage(0, 0, image);
+
+ button_back = newWidgetButton(_("back"), WINDOW_SIZE_X/2 -WIDGET_BUTTON_WIDTH/2, WINDOW_SIZE_Y-80, eventWidget);
+
+ label_status = newWidgetLabel("none", WINDOW_SIZE_X/2, 250, WIDGET_LABEL_CENTER);
+
+ registerScreen( newScreen("downArena", startScreenDownArena, eventScreenDownArena,
+ drawScreenDownArena, stopScreenDownArena) );
+}
+
+void quitScreenDownArena()
+{
+ destroyWidgetImage(image_backgorund);
+ destroyWidgetButton(button_back);
+ destroyWidgetLabel(label_status);
+}
diff --git a/src/screen/screen_downArena.h b/src/screen/screen_downArena.h
new file mode 100644
index 0000000..0e71887
--- /dev/null
+++ b/src/screen/screen_downArena.h
@@ -0,0 +1,22 @@
+
+#ifndef SCREEN_DOWN_ARENA_H
+
+#define SCREEN_DOWN_ARENA_H
+
+#define DOWN_SERVER_STATUS_OK 0
+#define DOWN_SERVER_STATUS_ZOMBIE 1
+
+#define DOWN_ARENA_BUFFER_SIZE 4096
+
+#define DOWN_ARENA_MAX_SEND_MSG_STATUS 10
+#define DOWN_ARENA_MAX_TIEMOUT_LIMIT 500
+#define DOWN_ARENA_COUNT_READ_SOCKET 100
+
+extern void startScreenDownArena();
+extern void drawScreenDownArena();
+extern void eventScreenDownArena();
+extern void stopScreenDownArena();
+extern void initScreenDownArena();
+extern void quitScreenDownArena();
+
+#endif
diff --git a/src/screen/screen_gameType.c b/src/screen/screen_gameType.c
index ae2e350..d755072 100644
--- a/src/screen/screen_gameType.c
+++ b/src/screen/screen_gameType.c
@@ -207,7 +207,8 @@ static void eventWidget(void *p)
if( getSettingGameType() == NET_GAME_TYPE_CLIENT )
{
- setScreen("world");
+ setScreen("downArena");
+ //setScreen("world");
}
else
{