summaryrefslogtreecommitdiff
path: root/src/base
diff options
context:
space:
mode:
Diffstat (limited to 'src/base')
-rw-r--r--src/base/arena.c4
-rw-r--r--src/base/gun.c4
-rw-r--r--src/base/server.c143
-rw-r--r--src/base/tux.c2
-rw-r--r--src/base/tux.h1
5 files changed, 115 insertions, 39 deletions
diff --git a/src/base/arena.c b/src/base/arena.c
index 448ee5b..bd471a2 100644
--- a/src/base/arena.c
+++ b/src/base/arena.c
@@ -150,10 +150,10 @@ void drawArena(arena_t *arena)
getCenterScreen(&screen_x, &screen_y, tux->x, tux->y);
for( i = screen_y/arena->background->h ;
- i <= screen_y/arena->background->h + WINDOW_SIZE_Y/arena->background->h ; i++ )
+ 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 ; j++ )
+ j <= screen_x/arena->background->w + WINDOW_SIZE_X/arena->background->w+1 ; j++ )
{
addLayer(arena->background,
j * arena->background->w,
diff --git a/src/base/gun.c b/src/base/gun.c
index 3cd6122..0a7e1a1 100644
--- a/src/base/gun.c
+++ b/src/base/gun.c
@@ -13,9 +13,11 @@
#include "base/proto.h"
#include "base/net_multiplayer.h"
-#ifndef PUBLIC_SERVER
+#ifndef NO_SOUND
#include "audio/sound.h"
+#endif
+#ifndef PUBLIC_SERVER
#include "client/interface.h"
#include "client/term.h"
diff --git a/src/base/server.c b/src/base/server.c
index e91e85c..fba543c 100644
--- a/src/base/server.c
+++ b/src/base/server.c
@@ -22,6 +22,7 @@
#include "base/net_multiplayer.h"
#include "base/checkFront.h"
#include "base/protect.h"
+#include "base/index.h"
#ifndef PUBLIC_SERVER
#include "screen/screen_world.h"
@@ -38,6 +39,8 @@ static sock_udp_t *sock_server_udp;
static sock_udp_t *sock_server_udp_second;
static list_t *listClient;
+static list_t *listClientIndex;
+
static list_t *listServerTimer;
static time_t timeUpdate;
static int maxClients;
@@ -52,6 +55,18 @@ time_t getUpdateServer()
return time(NULL) - timeUpdate;
}
+static void eventDelClient(client_t *client)
+{
+ int offset;
+
+ offset = getFormIndex(listClientIndex, getSockUdpPort(client->socket_udp));
+
+ assert( offset != -1 );
+
+ delFromIndex(listClientIndex, getSockUdpPort(client->socket_udp));
+ delListItem(listClient, offset, destroyClient);
+}
+
static void delZombieCLient(void *p_nothink)
{
client_t *thisClient;
@@ -78,7 +93,8 @@ static void delZombieCLient(void *p_nothink)
proto_send_del_server(PROTO_SEND_ALL, NULL, thisClient->tux->id);
}
- delListItem(listClient, i, destroyClient);
+ eventDelClient(thisClient);
+ i--;
}
}
@@ -86,39 +102,25 @@ static void delZombieCLient(void *p_nothink)
static void eventPeriodicSyncClient(void *p_nothink)
{
- client_t *thisClientInfo;
client_t *thisClientSend;
tux_t *thisTux;
- int i, j;
+ int i;
- for( i = 0 ; i < listClient->count; i++)
+#ifndef PUBLIC_SERVER
+ proto_send_newtux_server(PROTO_SEND_ALL_SEES_TUX, NULL, getControlTux(TUX_CONTROL_KEYBOARD_RIGHT));
+#endif
+
+ for( i = 0 ; i < listClient->count; i++ )
{
thisClientSend = (client_t *) listClient->list[i];
+ thisTux = thisClientSend->tux;
- if( thisClientSend->tux == NULL )
+ if( thisTux == NULL )
{
continue;
}
-#ifndef PUBLIC_SERVER
- thisTux = getControlTux(TUX_CONTROL_KEYBOARD_RIGHT);
- if( isTuxSeesTux(thisClientSend->tux, thisTux) )
- proto_send_newtux_server(PROTO_SEND_ONE, thisClientSend, thisTux);
-#endif
-
- for( j = 0 ; j < listClient->count; j++)
- {
- thisClientInfo = (client_t *) listClient->list[j];
- thisTux = thisClientInfo->tux;
-
- if( thisTux != NULL &&
- thisClientSend != thisClientInfo &&
- isTuxSeesTux(thisClientSend->tux, thisTux) )
- {
- proto_send_newtux_server(PROTO_SEND_ONE,
- thisClientSend, thisTux);
- }
- }
+ proto_send_newtux_server(PROTO_SEND_ALL_SEES_TUX, thisClientSend, thisTux);
}
}
@@ -147,7 +149,10 @@ static void initServer()
{
startUpdateServer();
listServerTimer = NULL;
+
listClient = newList();
+ listClientIndex = newIndex();
+
setServerMaxClients(SERVER_MAX_CLIENTS);
setServerTimer();
}
@@ -350,10 +355,68 @@ static void addMsgAllClient(char *msg, int type, int id)
static void addMsgAllClientSeesTux(char *msg, tux_t *tux, int type, int id)
{
+ arena_t *arena;
+ space_t *space;
+ int x, y, w, h;
int i;
assert( msg != NULL );
+ listDoEmpty(listHelp);
+
+ arena = getCurrentArena();
+ space = arena->spaceTux;
+
+ x = tux->x-(WINDOW_SIZE_X/2)*1.25;
+ y = tux->y-(WINDOW_SIZE_Y/2)*1.25;
+
+ w = WINDOW_SIZE_X*1.5;
+ h = WINDOW_SIZE_Y*1.5;
+
+ 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);
+ }
+
+ getObjectFromSpace(space, x, y, w, h, listHelp);
+ //printf("%d %d %d %d %d\n", x, y, w, h, listHelp->count);
+
+ for( i = 0 ; i < listHelp->count ; i++ )
+ {
+ tux_t *thisTux;
+ client_t *thisClient;
+
+ thisTux = (tux_t *)listHelp->list[i];
+
+ if( thisTux == tux )
+ {
+ continue;
+ }
+
+ thisClient = thisTux->client;
+
+ if( thisClient != NULL )
+ {
+ addMsgClient(thisClient, msg, type, id);
+ }
+ }
+
+#if 0
for( i = 0 ; i < listClient->count ; i++ )
{
client_t *thisClient;
@@ -373,6 +436,7 @@ static void addMsgAllClientSeesTux(char *msg, tux_t *tux, int type, int id)
addMsgClient(thisClient, msg, type, id);
}
}
+#endif
}
void protoSendClient(int type, client_t *client, char *msg, int type2, int id)
@@ -474,11 +538,20 @@ void sendInfoCreateClient(client_t *client)
static void eventCreateNewUdpClient(sock_udp_t *socket_udp)
{
client_t *client;
+ int offset;
assert( socket_udp != NULL );
client = newUdpClient( socket_udp );
- addList(listClient, client);
+
+ offset = addToIndex(listClientIndex, getSockUdpPort(client->socket_udp) );
+
+ if( offset == -1 )
+ {
+ return;
+ }
+
+ insList(listClient, offset, client);
}
static void eventClientBuffer(client_t *client)
@@ -575,20 +648,17 @@ void eventClientListBuffer()
static client_t* findUdpClient(sock_udp_t *sock_udp)
{
- int i;
- client_t *thisClient;
+ int offset;
- for( i = 0 ; i < listClient->count; i++)
- {
- thisClient = (client_t *) listClient->list[i];
+ offset = getFormIndex(listClientIndex, getSockUdpPort(sock_udp));
- if( getSockUdpPort(thisClient->socket_udp) == getSockUdpPort(sock_udp) )
- {
- return thisClient;
- }
+ if( offset == -1 )
+ {
+ return NULL;
}
- return NULL;
+ return (client_t *) listClient->list[offset];
+
}
static void eventClientUdpSelect(sock_udp_t *sock_server)
@@ -773,7 +843,10 @@ void quitUdpServer()
proto_send_end_server(PROTO_SEND_ALL, NULL);
assert( listClient != NULL );
+
destroyListItem(listClient, destroyClient);
+ destroyIndex(listClientIndex);
+
destroyTimer(listServerTimer);
if( sock_server_udp != NULL )
diff --git a/src/base/tux.c b/src/base/tux.c
index cd7cd4a..9d34cc9 100644
--- a/src/base/tux.c
+++ b/src/base/tux.c
@@ -230,6 +230,7 @@ void replaceTuxID(tux_t *tux, int id)
tux->id = id;
}
+#if 0
int isTuxSeesTux(tux_t *tux, tux_t *thisTux)
{
int tux_x, tux_y, tux_w, tux_h;
@@ -244,6 +245,7 @@ int isTuxSeesTux(tux_t *tux, tux_t *thisTux)
return conflictSpace(screen_x-WINDOW_SIZE_X/4, screen_y-WINDOW_SIZE_Y/4,
WINDOW_SIZE_X*1.25, WINDOW_SIZE_Y*1.25, thisTux_x, thisTux_y, thisTux_w, thisTux_h);
}
+#endif
static void timer_spawnTux(void *p)
{
diff --git a/src/base/tux.h b/src/base/tux.h
index 8a39cf9..c8f6e51 100644
--- a/src/base/tux.h
+++ b/src/base/tux.h
@@ -127,7 +127,6 @@ extern void eventListTux(list_t *listTux);
extern tux_t* getTuxID(list_t *listTux, int id);
extern void getTuxProportion(tux_t *tux, int *x,int *y, int *w, int *h);
extern void replaceTuxID(tux_t *tux, int id);
-extern int isTuxSeesTux(tux_t *tux, tux_t *thisTux);
extern void setTuxProportion(tux_t *tux, int x, int y);
extern void getStatusTux(void *p, int *id, int *x,int *y, int *w, int *h);
extern void setStatusTux(void *p, int x, int y, int w, int h);