summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/CMakeLists.txt2
-rw-r--r--src/base/arenaFile.c37
-rw-r--r--src/base/downServer.c312
-rw-r--r--src/base/downServer.h15
-rw-r--r--src/base/proto.c2
-rw-r--r--src/base/server.c14
-rw-r--r--src/downserver/downServer.c320
-rw-r--r--src/screen/screen_downArena.c53
-rw-r--r--src/screen/screen_setting.c7
9 files changed, 401 insertions, 361 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 7f809df..5200707 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -36,7 +36,7 @@ SET ( SRC_base
${WORKDIR}/base/director ${WORKDIR}/base/idManager
${WORKDIR}/base/homeDirector ${WORKDIR}/base/proto
${WORKDIR}/base/shareFunction ${WORKDIR}/base/buffer
- ${WORKDIR}/base/archive
+ ${WORKDIR}/base/archive ${WORKDIR}/base/downServer
${WORKDIR}/net/dns
)
diff --git a/src/base/arenaFile.c b/src/base/arenaFile.c
index f6f3935..1a16cbf 100644
--- a/src/base/arenaFile.c
+++ b/src/base/arenaFile.c
@@ -308,22 +308,17 @@ void loadArenaFile(char *path)
addList(listArenaFile, newArenaFile(path));
}
-void initArenaFile()
+static void loadArenaFromDirector(char *director)
{
director_t *p;
int i;
-#ifndef PUBLIC_SERVER
- assert(isImageInicialized() == TRUE);
-#endif
- isArenaFileInit = TRUE;
- listArenaFile = newList();
-
- p = loadDirector(PATH_ARENA);
+ printf(_("Load arena file from %s\n"), director);
+ p = loadDirector(director);
if (p==NULL)
{
- fprintf(stderr, _("Director " PATH_ARENA " not found !\n"));
+ fprintf(stderr, _("Director %s not found !\n"), director);
exit(-1);
}
@@ -335,7 +330,14 @@ void initArenaFile()
if (strstr(line, ".zip") != NULL && strstr(line, "~") == NULL) {
char path[STR_PATH_SIZE];
- sprintf(path, PATH_ARENA "%s", line);
+ if( director[strlen(director)-1] == '/' )
+ {
+ sprintf(path, "%s%s", director, line);
+ }
+ else
+ {
+ sprintf(path, "%s/%s", director, line);
+ }
#ifdef DEBUG
printf(_("Loading arena: %s\n"), line);
#endif
@@ -343,8 +345,23 @@ void initArenaFile()
loadArenaFile(path);
}
}
+
//printf("No. of Arens: %d\n", listArenaFile->count);
destroyDirector(p);
+
+}
+
+void initArenaFile()
+{
+#ifndef PUBLIC_SERVER
+ assert(isImageInicialized() == TRUE);
+#endif
+ isArenaFileInit = TRUE;
+ listArenaFile = newList();
+
+ loadArenaFromDirector(PATH_ARENA);
+ loadArenaFromDirector(getHomeDirector());
+
}
void quitArenaFile()
diff --git a/src/base/downServer.c b/src/base/downServer.c
new file mode 100644
index 0000000..f0625a9
--- /dev/null
+++ b/src/base/downServer.c
@@ -0,0 +1,312 @@
+
+#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 = getArenaFileFormNetName(arenaName);
+
+ if( arenaFile == NULL )
+ {
+ char *error_msg = _("ERR Arena not found !\n");
+ addBuffer(client->sendBuffer, error_msg, strlen(error_msg));
+ return;
+ }
+
+ client->file = fopen(arenaFile->path, "rb");
+
+ if( client->file == NULL )
+ {
+ char *error_msg = _("ERR Server has a problem !\n");
+ addBuffer(client->sendBuffer, error_msg, strlen(error_msg));
+ return;
+ }
+
+ client->size = getFileSize(arenaFile->path);
+ sprintf(msg_out, "OK %d\n", client->size);
+ addBuffer(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 = newBuffer(DOWN_SERVER_LIMIT_BUFFER);
+ new->sendBuffer = newBuffer(DOWN_SERVER_LIMIT_BUFFER);
+
+ return new;
+}
+
+static void destroyClient(client_ds_t *client)
+{
+ closeTcpSocket(client->sock);
+ destroyBuffer(client->recvBuffer);
+ destroyBuffer(client->sendBuffer);
+
+ if( client->file != NULL )
+ {
+ fclose(client->file);
+ }
+
+ free(client);
+}
+
+int initDownServer(char *ip4, int port4)
+{
+ sock_server_tcp = bindTcpSocket(ip4, port4, PROTO_TCPv4);
+
+ if( sock_server_tcp == NULL )
+ {
+ fprintf(stderr, _("down server do not inicialized !\n"));
+ return -1;
+ }
+
+ setTcpSockNonBlock(sock_server_tcp);
+
+ listClient = newList();
+
+ return 0;
+}
+
+int setDownServerSelect()
+{
+ int i;
+
+ addSockToSelectRead(sock_server_tcp->sock);
+
+ for( i = 0 ; i < listClient->count ; i++ )
+ {
+ client_ds_t *this;
+
+ this = (client_ds_t *)listClient->list[i];
+
+ addSockToSelectRead(this->sock->sock);
+
+ if( getBufferSize(this->sendBuffer) > 0 )
+ {
+ addSockToSelectWrite(this->sock->sock);
+ }
+ }
+
+ return 0;
+}
+
+static void eventNewClient(sock_tcp_t *sock_server)
+{
+ sock_tcp_t *sock_client;
+ client_ds_t *client;
+
+ sock_client = getTcpNewClient(sock_server);
+ setTcpSockNonBlock(sock_client);
+ client = newClient(sock_client);
+
+ addList(listClient, client);
+}
+
+static void eventReadClient(client_ds_t * client)
+{
+ char buffer[STR_PROTO_SIZE];
+ int ret;
+
+ memset(buffer, 0, STR_PROTO_SIZE);
+
+ ret = readTcpSocket(client->sock, buffer, STR_PROTO_SIZE - 1);
+ //printf("readTcpSocket = %d\n", ret);
+
+ if (ret <= 0)
+ {
+ client->status_connect = NET_STATUS_ZOMBIE;
+ return;
+ }
+
+ if( addBuffer(client->recvBuffer, buffer, ret) < 0 )
+ {
+ client->status_connect = NET_STATUS_ZOMBIE;
+ return;
+ }
+
+ while( getBufferLine(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);
+ //addBuffer(client->sendBuffer, buffer, strlen(buffer));
+ }
+}
+
+static void eventWriteClient(client_ds_t *client)
+{
+ void *data;
+ int len;
+ int res;
+
+ len = getBufferSize(client->sendBuffer);
+
+ if( len == 0 )
+ {
+ return;
+ }
+
+ data = getBufferData(client->sendBuffer);
+
+ res = writeTcpSocket(client->sock, data, len);
+ //printf("writeTcpSocket = %d\n", res);
+
+ if( res < 0 )
+ {
+ client->status_connect = NET_STATUS_ZOMBIE;
+ return;
+ }
+
+ cutBuffer(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;
+ }
+
+ addBuffer(client->sendBuffer, buffer, count);
+ client->send += count;
+}
+
+int selectDownServerSocket()
+{
+ int i;
+
+ if( isChangeSockInSelectRead(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( isChangeSockInSelectRead(this->sock->sock) )
+ {
+ eventReadClient(this);
+ }
+
+ if( isChangeSockInSelectWrite(this->sock->sock) )
+ {
+ eventWriteClient(this);
+ }
+
+ if( this->file != NULL && getBufferSize(this->sendBuffer) == 0 )
+ {
+ sendFile(this);
+ }
+
+ if( this->status_connect == NET_STATUS_ZOMBIE )
+ {
+ delListItem(listClient, i, destroyClient);
+ }
+ }
+
+ return 0;
+}
+
+int quitDownServer()
+{
+ closeTcpSocket(sock_server_tcp);
+ destroyListItem(listClient, destroyClient);
+
+ return 0;
+}
diff --git a/src/base/downServer.h b/src/base/downServer.h
new file mode 100644
index 0000000..6ca8d93
--- /dev/null
+++ b/src/base/downServer.h
@@ -0,0 +1,15 @@
+
+#ifndef DOWN_SERVER_H
+
+#define DOWN_SERVER_H
+
+#include "list.h"
+#include "tcp.h"
+#include "buffer.h"
+
+extern int initDownServer(char *ip4, int port4);
+extern int setDownServerSelect();
+extern int selectDownServerSocket();
+extern int quitDownServer();
+
+#endif
diff --git a/src/base/proto.c b/src/base/proto.c
index 51fedaa..f14a29a 100644
--- a/src/base/proto.c
+++ b/src/base/proto.c
@@ -94,6 +94,8 @@ void proto_send_hello_client(char *name)
snprintf(msg, STR_PROTO_SIZE, "hello %s %s\n",
getParamElse("--version", TUXANCI_VERSION), name);
+
+ printf("-> %s", msg);
sendServer(msg);
}
diff --git a/src/base/server.c b/src/base/server.c
index f98ae2f..282d135 100644
--- a/src/base/server.c
+++ b/src/base/server.c
@@ -30,6 +30,7 @@
#include "index.h"
#include "serverSelect.h"
#include "serverSendMsg.h"
+#include "downServer.h"
#ifndef PUBLIC_SERVER
# include "screen_world.h"
@@ -249,6 +250,8 @@ int initServer(char *ip4, int port4, char *ip6, int port6)
return -1;
}
+ initDownServer(ip4, port4);
+
return ret;
}
@@ -340,13 +343,16 @@ void eventServer()
#ifndef PUBLIC_SERVER
int count;
-
-
do {
restartSelect();
+
setServerUdpSelect();
+ setDownServerSelect();
+
actionSelect();
+
count = selectServerUdpSocket();
+ selectDownServerSocket();
} while (count > 0);
#endif
@@ -356,11 +362,13 @@ void eventServer()
restartSelect();
setServerUdpSelect();
+ setDownServerSelect();
ret = actionSelect();
if (ret > 0) {
selectServerUdpSocket();
+ selectDownServerSocket();
}
#endif
@@ -379,4 +387,6 @@ void quitServer()
destroyTimer(listServerTimer);
quitUdpServer();
+
+ quitDownServer();
}
diff --git a/src/downserver/downServer.c b/src/downserver/downServer.c
index 52e757d..7711f52 100644
--- a/src/downserver/downServer.c
+++ b/src/downserver/downServer.c
@@ -16,328 +16,12 @@
#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)
+int main()
{
- signal(SIGPIPE, SIG_IGN);
-
- initDownServer("0.0.0.0", 6800);
-
- while (1) {
- startDownServer();
- }
+ return 0;
}
diff --git a/src/screen/screen_downArena.c b/src/screen/screen_downArena.c
index 0ff0c7b..737543d 100644
--- a/src/screen/screen_downArena.c
+++ b/src/screen/screen_downArena.c
@@ -54,8 +54,7 @@ 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);
+ label_status = newWidgetLabel(s, WINDOW_SIZE_X / 2, 250, WIDGET_LABEL_CENTER);
}
static void connectToDownServer()
@@ -63,12 +62,11 @@ static void connectToDownServer()
char status[STR_SIZE];
char msg[STR_PROTO_SIZE];
- sock_server_tcp =
- connectTcpSocket(getSettingIP(), getSettingPort(), PROTO_TCPv4);
+ 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());
+ if( sock_server_tcp == NULL )
+ {
+ sprintf(status, "I do not connect to %s %d TCP down server", getSettingIP(), getSettingPort());
setStatusString(status);
return;
}
@@ -87,8 +85,7 @@ static void connectToDownServer()
addBuffer(sendBuffer, msg, strlen(msg));
- sprintf(status, "Connect to %s %d TCP down server", getSettingIP(),
- getSettingPort());
+ sprintf(status, "Connect to %s %d TCP down server", getSettingIP(), getSettingPort());
setStatusString(status);
}
@@ -106,10 +103,10 @@ static void sendStatusToGameServer()
{
char *msg = "status\n";
- if (countSendMsg > DOWN_ARENA_MAX_SEND_MSG_STATUS) {
+ if( countSendMsg > DOWN_ARENA_MAX_SEND_MSG_STATUS )
+ {
char status[STR_SIZE];
- sprintf(status, "Game server %s %d is down", getSettingIP(),
- getSettingPort());
+ sprintf(status, "Game server %s %d is down", getSettingIP(), getSettingPort());
setStatusString(status);
return;
}
@@ -118,10 +115,10 @@ static void sendStatusToGameServer()
countSendMsg++;
printf("countSendMsg = %d\n", countSendMsg++);
- if (writeUdpSocket(sock_server_udp, sock_server_udp, msg, strlen(msg)) < 0) {
+ 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());
+ sprintf(status, "I do not send message to %s %d UDP game server", getSettingIP(), getSettingPort());
setStatusString(status);
}
}
@@ -133,20 +130,18 @@ void startScreenDownArena()
strcpy(str_status, "none");
memset(arenaNetName, 0, STR_SIZE);
- sock_server_udp =
- connectUdpSocket(getSettingIP(), getSettingPort(), PROTO_UDPv4);
+ 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());
+ 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());
+ sprintf(status, "Connect to %s %d UDP game server", getSettingIP(), getSettingPort());
setStatusString(status);
sendStatusToGameServer();
@@ -179,11 +174,13 @@ static void proto_err(char *line)
static void eventProto(char *line)
{
- if (strncmp(line, "OK", 2) == 0) {
+ if( strncmp(line, "OK", 2) == 0 )
+ {
proto_ok(line);
}
- if (strncmp(line, "ERR", 3) == 0) {
+ if( strncmp(line, "ERR", 3) == 0 )
+ {
proto_err(line);
}
}
@@ -298,13 +295,13 @@ static void readArenaFromStatus()
static void eventStatus()
{
- if (getMyTime() - timeSendMsg > DOWN_ARENA_MAX_TIEMOUT_LIMIT) {
+ if( getMyTime() - timeSendMsg > DOWN_ARENA_MAX_TIEMOUT_LIMIT )
+ {
sendStatusToGameServer();
}
- if (readUdpSocket
- (sock_server_udp, sock_server_udp, str_status,
- STR_PROTO_SIZE - 1) > 0) {
+ if( readUdpSocket(sock_server_udp, sock_server_udp, str_status, STR_PROTO_SIZE - 1) > 0 )
+ {
//printf("str_status = %s\n", str_status);
readArenaFromStatus();
}
diff --git a/src/screen/screen_setting.c b/src/screen/screen_setting.c
index 790f42b..06adda3 100644
--- a/src/screen/screen_setting.c
+++ b/src/screen/screen_setting.c
@@ -333,8 +333,11 @@ static void saveAndDestroyConfigFile()
getYesOrNo(getWidgetCheckStatus(check_sound)));
#endif
- setValueInConfigFile(configFile, "ARENA",
- getArenaNetName(getChoiceArena()));
+ if( getChoiceArena() != NULL )
+ {
+ setValueInConfigFile(configFile, "ARENA",
+ getArenaNetName(getChoiceArena()));
+ }
//TODO
saveTextFile(configFile);