add clang-format config and format everything
This commit is contained in:
parent
187ec1a68e
commit
56458af5fc
29
.clang-format
Normal file
29
.clang-format
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
---
|
||||||
|
BasedOnStyle: LLVM
|
||||||
|
IndentWidth: 4
|
||||||
|
TabWidth: 4
|
||||||
|
---
|
||||||
|
Language: Cpp
|
||||||
|
AccessModifierOffset: -4
|
||||||
|
AlignAfterOpenBracket: AlwaysBreak
|
||||||
|
AlignOperands: false
|
||||||
|
AlignTrailingComments: false
|
||||||
|
AllowAllParametersOfDeclarationOnNextLine: false
|
||||||
|
AllowShortBlocksOnASingleLine: true
|
||||||
|
AllowShortFunctionsOnASingleLine: Empty
|
||||||
|
AllowShortIfStatementsOnASingleLine: true
|
||||||
|
AllowShortLoopsOnASingleLine: true
|
||||||
|
AlwaysBreakTemplateDeclarations: true
|
||||||
|
BinPackArguments: false
|
||||||
|
BinPackParameters: false
|
||||||
|
BreakConstructorInitializersBeforeComma: true
|
||||||
|
ColumnLimit: 160
|
||||||
|
ConstructorInitializerAllOnOneLineOrOnePerLine: true
|
||||||
|
ConstructorInitializerIndentWidth: 0
|
||||||
|
MaxEmptyLinesToKeep: 2
|
||||||
|
NamespaceIndentation: All
|
||||||
|
PointerAlignment: Left
|
||||||
|
SpaceAfterCStyleCast: true
|
||||||
|
Standard: Cpp11
|
||||||
|
UseTab: Always
|
||||||
|
...
|
@ -2,12 +2,12 @@
|
|||||||
#include "announce.h"
|
#include "announce.h"
|
||||||
#include "network.h"
|
#include "network.h"
|
||||||
|
|
||||||
#include <time.h>
|
#include <assert.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <assert.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <time.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
#include <avahi-client/client.h>
|
#include <avahi-client/client.h>
|
||||||
#include <avahi-client/lookup.h>
|
#include <avahi-client/lookup.h>
|
||||||
@ -50,8 +50,7 @@ static void entry_group_callback(AvahiEntryGroup *g, AvahiEntryGroupState state,
|
|||||||
case AVAHI_ENTRY_GROUP_ESTABLISHED:
|
case AVAHI_ENTRY_GROUP_ESTABLISHED:
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case AVAHI_ENTRY_GROUP_COLLISION :
|
case AVAHI_ENTRY_GROUP_COLLISION: {
|
||||||
{
|
|
||||||
char* n = avahi_alternative_service_name(name);
|
char* n = avahi_alternative_service_name(name);
|
||||||
avahi_free(name);
|
avahi_free(name);
|
||||||
name = n;
|
name = n;
|
||||||
@ -90,8 +89,7 @@ again:
|
|||||||
snprintf(buf_version, sizeof(buf_version), "version=%X", (unsigned int) version);
|
snprintf(buf_version, sizeof(buf_version), "version=%X", (unsigned int) version);
|
||||||
if ((ret = avahi_entry_group_add_service(group, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, 0, name, SERVICE_TYPE, NULL, NULL, port, buf_version, NULL)) < 0) {
|
if ((ret = avahi_entry_group_add_service(group, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, 0, name, SERVICE_TYPE, NULL, NULL, port, buf_version, NULL)) < 0) {
|
||||||
|
|
||||||
if (ret == AVAHI_ERR_COLLISION)
|
if (ret == AVAHI_ERR_COLLISION) goto collision;
|
||||||
goto collision;
|
|
||||||
|
|
||||||
fprintf(stderr, "Failed to add " SERVICE_TYPE ": %s\n", avahi_strerror(ret));
|
fprintf(stderr, "Failed to add " SERVICE_TYPE ": %s\n", avahi_strerror(ret));
|
||||||
goto fail;
|
goto fail;
|
||||||
@ -105,8 +103,7 @@ again:
|
|||||||
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
collision:
|
collision : {
|
||||||
{
|
|
||||||
char* n = avahi_alternative_service_name(name);
|
char* n = avahi_alternative_service_name(name);
|
||||||
avahi_free(name);
|
avahi_free(name);
|
||||||
name = n;
|
name = n;
|
||||||
@ -132,9 +129,7 @@ static void client_callback(AvahiClient *c, AvahiClientState state, void * userd
|
|||||||
break;
|
break;
|
||||||
case AVAHI_CLIENT_S_COLLISION:
|
case AVAHI_CLIENT_S_COLLISION:
|
||||||
case AVAHI_CLIENT_S_REGISTERING:
|
case AVAHI_CLIENT_S_REGISTERING:
|
||||||
if (group) {
|
if (group) { avahi_entry_group_reset(group); }
|
||||||
avahi_entry_group_reset(group);
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case AVAHI_CLIENT_CONNECTING:
|
case AVAHI_CLIENT_CONNECTING:
|
||||||
break;
|
break;
|
||||||
@ -180,9 +175,20 @@ static void remove_game_with_name(const char *name) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void resolve_callback(AvahiServiceResolver *r, AvahiIfIndex interface, AvahiProtocol protocol, AvahiResolverEvent event,
|
static void resolve_callback(
|
||||||
const char *name, const char *type, const char *domain, const char *host_name, const AvahiAddress *address,
|
AvahiServiceResolver* r,
|
||||||
uint16_t port, AvahiStringList *txt, AvahiLookupResultFlags flags, void* userdata) {
|
AvahiIfIndex interface,
|
||||||
|
AvahiProtocol protocol,
|
||||||
|
AvahiResolverEvent event,
|
||||||
|
const char* name,
|
||||||
|
const char* type,
|
||||||
|
const char* domain,
|
||||||
|
const char* host_name,
|
||||||
|
const AvahiAddress* address,
|
||||||
|
uint16_t port,
|
||||||
|
AvahiStringList* txt,
|
||||||
|
AvahiLookupResultFlags flags,
|
||||||
|
void* userdata) {
|
||||||
int i;
|
int i;
|
||||||
uint32_t want_version;
|
uint32_t want_version;
|
||||||
(void) interface;
|
(void) interface;
|
||||||
@ -201,7 +207,13 @@ static void resolve_callback(AvahiServiceResolver *r, AvahiIfIndex interface, Av
|
|||||||
|
|
||||||
switch (event) {
|
switch (event) {
|
||||||
case AVAHI_RESOLVER_FAILURE:
|
case AVAHI_RESOLVER_FAILURE:
|
||||||
fprintf(stderr, "(Resolver) Failed to resolve service '%s' of type '%s' in domain '%s': %s\n", name, type, domain, avahi_strerror(avahi_client_errno(avahi_service_resolver_get_client(r))));
|
fprintf(
|
||||||
|
stderr,
|
||||||
|
"(Resolver) Failed to resolve service '%s' of type '%s' in domain '%s': %s\n",
|
||||||
|
name,
|
||||||
|
type,
|
||||||
|
domain,
|
||||||
|
avahi_strerror(avahi_client_errno(avahi_service_resolver_get_client(r))));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case AVAHI_RESOLVER_FOUND: {
|
case AVAHI_RESOLVER_FOUND: {
|
||||||
@ -233,8 +245,16 @@ done:
|
|||||||
avahi_service_resolver_free(r);
|
avahi_service_resolver_free(r);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void browse_callback(AvahiServiceBrowser *b, AvahiIfIndex interface, AvahiProtocol protocol, AvahiBrowserEvent event,
|
static void browse_callback(
|
||||||
const char *name, const char *type, const char *domain, AvahiLookupResultFlags flags, void* userdata) {
|
AvahiServiceBrowser* b,
|
||||||
|
AvahiIfIndex interface,
|
||||||
|
AvahiProtocol protocol,
|
||||||
|
AvahiBrowserEvent event,
|
||||||
|
const char* name,
|
||||||
|
const char* type,
|
||||||
|
const char* domain,
|
||||||
|
AvahiLookupResultFlags flags,
|
||||||
|
void* userdata) {
|
||||||
(void) flags;
|
(void) flags;
|
||||||
|
|
||||||
assert(b);
|
assert(b);
|
||||||
|
26
src/bomber.c
26
src/bomber.c
@ -1,24 +1,24 @@
|
|||||||
|
#include <fcntl.h>
|
||||||
|
#include <netdb.h>
|
||||||
|
#include <signal.h>
|
||||||
|
#include <stdarg.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <unistd.h>
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <sys/types.h>
|
|
||||||
#include <netdb.h>
|
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#include <signal.h>
|
#include <sys/types.h>
|
||||||
#include <fcntl.h>
|
#include <unistd.h>
|
||||||
#include <stdarg.h>
|
|
||||||
|
|
||||||
#include "bomber.h"
|
|
||||||
#include "gfx.h"
|
|
||||||
#include "announce.h"
|
#include "announce.h"
|
||||||
#include "sound.h"
|
#include "bomber.h"
|
||||||
#include "menu.h"
|
|
||||||
#include "utils.h"
|
|
||||||
#include "network.h"
|
|
||||||
#include "game.h"
|
|
||||||
#include "draw.h"
|
#include "draw.h"
|
||||||
|
#include "game.h"
|
||||||
|
#include "gfx.h"
|
||||||
|
#include "menu.h"
|
||||||
|
#include "network.h"
|
||||||
|
#include "sound.h"
|
||||||
|
#include "utils.h"
|
||||||
|
|
||||||
int main(void) {
|
int main(void) {
|
||||||
char* p;
|
char* p;
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
#ifndef BOMBER_H
|
#ifndef BOMBER_H
|
||||||
#define BOMBER_H
|
#define BOMBER_H
|
||||||
|
|
||||||
#include "SDL.h"
|
#include "list.h"
|
||||||
|
#include <SDL.h>
|
||||||
|
|
||||||
typedef unsigned char uchar;
|
typedef unsigned char uchar;
|
||||||
extern int xcolors[256];
|
extern int xcolors[256];
|
||||||
@ -54,11 +55,6 @@ typedef struct solid {
|
|||||||
uchar* graphics;
|
uchar* graphics;
|
||||||
} solid;
|
} solid;
|
||||||
|
|
||||||
typedef struct listhead listhead;
|
|
||||||
struct listhead {
|
|
||||||
listhead *prev, *next;
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef struct player {
|
typedef struct player {
|
||||||
listhead list, list_all_players;
|
listhead list, list_all_players;
|
||||||
int xpos, ypos;
|
int xpos, ypos;
|
||||||
@ -200,7 +196,6 @@ enum tile_types {
|
|||||||
#define CODE_ALLDEAD 2
|
#define CODE_ALLDEAD 2
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#define MAXTHINGS 500
|
#define MAXTHINGS 500
|
||||||
#define MAXSETS 8
|
#define MAXSETS 8
|
||||||
#define MAXSPRITES 256
|
#define MAXSPRITES 256
|
||||||
|
70
src/draw.c
70
src/draw.c
@ -1,15 +1,15 @@
|
|||||||
|
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <netdb.h>
|
||||||
|
#include <signal.h>
|
||||||
|
#include <stdarg.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <unistd.h>
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <sys/types.h>
|
|
||||||
#include <netdb.h>
|
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#include <signal.h>
|
#include <sys/types.h>
|
||||||
#include <fcntl.h>
|
#include <unistd.h>
|
||||||
#include <stdarg.h>
|
|
||||||
|
|
||||||
#include "bomber.h"
|
#include "bomber.h"
|
||||||
#include "draw.h"
|
#include "draw.h"
|
||||||
@ -103,13 +103,24 @@ static int dopcxreal(char *name,gfxset *gs) {
|
|||||||
char tname2[260];
|
char tname2[260];
|
||||||
snprintf(tname2, sizeof(tname2), "%s.pcx", tname);
|
snprintf(tname2, sizeof(tname2), "%s.pcx", tname);
|
||||||
ihand = open(tname2, O_RDONLY);
|
ihand = open(tname2, O_RDONLY);
|
||||||
if(ihand<0)
|
if (ihand < 0) return 1;
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
if(myci()!=10) {close(ihand);return 2;} // 10=zsoft .pcx
|
if (myci() != 10) {
|
||||||
if(myci()!=5) {close(ihand);return 3;} // version 3.0
|
close(ihand);
|
||||||
if(myci()!=1) {close(ihand);return 4;} //encoding method
|
return 2;
|
||||||
if(myci()!=8) {close(ihand);return 5;} //bpp
|
} // 10=zsoft .pcx
|
||||||
|
if (myci() != 5) {
|
||||||
|
close(ihand);
|
||||||
|
return 3;
|
||||||
|
} // version 3.0
|
||||||
|
if (myci() != 1) {
|
||||||
|
close(ihand);
|
||||||
|
return 4;
|
||||||
|
} // encoding method
|
||||||
|
if (myci() != 8) {
|
||||||
|
close(ihand);
|
||||||
|
return 5;
|
||||||
|
} // bpp
|
||||||
xs = myci();
|
xs = myci();
|
||||||
xs |= myci() << 8;
|
xs |= myci() << 8;
|
||||||
ys = myci();
|
ys = myci();
|
||||||
@ -122,7 +133,10 @@ static int dopcxreal(char *name,gfxset *gs) {
|
|||||||
height = height + 1 - ys;
|
height = height + 1 - ys;
|
||||||
for (i = 0; i < 48 + 4; ++i) myci();
|
for (i = 0; i < 48 + 4; ++i) myci();
|
||||||
myci();
|
myci();
|
||||||
if(myci()!=1) {close(ihand);return 6;} // # of planes
|
if (myci() != 1) {
|
||||||
|
close(ihand);
|
||||||
|
return 6;
|
||||||
|
} // # of planes
|
||||||
byteswide = myci();
|
byteswide = myci();
|
||||||
byteswide |= myci() << 8;
|
byteswide |= myci() << 8;
|
||||||
i = myci();
|
i = myci();
|
||||||
@ -131,7 +145,10 @@ static int dopcxreal(char *name,gfxset *gs) {
|
|||||||
for (i = 0; i < 58; ++i) myci();
|
for (i = 0; i < 58; ++i) myci();
|
||||||
totalsize = height * byteswide;
|
totalsize = height * byteswide;
|
||||||
bm = malloc(totalsize + 1);
|
bm = malloc(totalsize + 1);
|
||||||
if(!bm) {close(ihand);return 8;} // no memory
|
if (!bm) {
|
||||||
|
close(ihand);
|
||||||
|
return 8;
|
||||||
|
} // no memory
|
||||||
gs->gs_pic = bm;
|
gs->gs_pic = bm;
|
||||||
gs->gs_xsize = width;
|
gs->gs_xsize = width;
|
||||||
gs->gs_ysize = height;
|
gs->gs_ysize = height;
|
||||||
@ -164,8 +181,7 @@ static int dopcx(char *name,gfxset *gs) {
|
|||||||
int err;
|
int err;
|
||||||
|
|
||||||
err = dopcxreal(name, gs);
|
err = dopcxreal(name, gs);
|
||||||
if(err)
|
if (err) printf("Error loading \"%s\":code %d\n", name, err);
|
||||||
printf("Error loading \"%s\":code %d\n",name,err);
|
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -179,8 +195,7 @@ static void getgroup(char *name,gfxset *colorgs,figure *fig,int count) {
|
|||||||
createinout(&gs);
|
createinout(&gs);
|
||||||
for (i = 0; i < MAXSETS; ++i, fig += count, ++colorgs) {
|
for (i = 0; i < MAXSETS; ++i, fig += count, ++colorgs) {
|
||||||
if (!colorgs->gs_pic) continue;
|
if (!colorgs->gs_pic) continue;
|
||||||
memmove(gs.gs_colormap,colorgs->gs_colormap,
|
memmove(gs.gs_colormap, colorgs->gs_colormap, sizeof(gs.gs_colormap));
|
||||||
sizeof(gs.gs_colormap));
|
|
||||||
createinout(&gs);
|
createinout(&gs);
|
||||||
gfxfetch(&gs, fig, count);
|
gfxfetch(&gs, fig, count);
|
||||||
}
|
}
|
||||||
@ -309,9 +324,7 @@ void erasesprites(void) {
|
|||||||
for (i = 0; i < spritesused; ++i) {
|
for (i = 0; i < spritesused; ++i) {
|
||||||
fig = sp->fig;
|
fig = sp->fig;
|
||||||
|
|
||||||
solidcopy(&background,
|
solidcopy(&background, sp->xpos + fig->xdelta, sp->ypos + fig->ydelta, fig->xsize, fig->ysize);
|
||||||
sp->xpos+fig->xdelta,sp->ypos+fig->ydelta,
|
|
||||||
fig->xsize,fig->ysize);
|
|
||||||
++sp;
|
++sp;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -325,8 +338,7 @@ void clearsprites(void) {
|
|||||||
for (i = 0; i < spritesused; ++i) {
|
for (i = 0; i < spritesused; ++i) {
|
||||||
fig = sp->fig;
|
fig = sp->fig;
|
||||||
|
|
||||||
clearrect(sp->xpos+fig->xdelta,sp->ypos+fig->ydelta,
|
clearrect(sp->xpos + fig->xdelta, sp->ypos + fig->ydelta, fig->xsize, fig->ysize);
|
||||||
fig->xsize,fig->ysize);
|
|
||||||
++sp;
|
++sp;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -373,12 +385,12 @@ static void loadfonts(void) {
|
|||||||
bigfontysize = 24;
|
bigfontysize = 24;
|
||||||
bigfontyspace = 32;
|
bigfontyspace = 32;
|
||||||
p = remapstring;
|
p = remapstring;
|
||||||
j=0;while(*p && *p!=' ') ++p,++j;
|
j = 0;
|
||||||
|
while (*p && *p != ' ') ++p, ++j;
|
||||||
memset(asciiremap, j, sizeof(asciiremap));
|
memset(asciiremap, j, sizeof(asciiremap));
|
||||||
p = remapstring;
|
p = remapstring;
|
||||||
i = 0;
|
i = 0;
|
||||||
while(*p && i<NUMCHARACTERS)
|
while (*p && i < NUMCHARACTERS) asciiremap[(int) *p++] = i++;
|
||||||
asciiremap[(int)*p++]=i++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void loadgfx() {
|
void loadgfx() {
|
||||||
@ -402,8 +414,7 @@ void loadgfx() {
|
|||||||
strcpy(bigfontname, "bigfont");
|
strcpy(bigfontname, "bigfont");
|
||||||
|
|
||||||
gs = malloc((MAXSETS + 1) * sizeof(gfxset));
|
gs = malloc((MAXSETS + 1) * sizeof(gfxset));
|
||||||
if(!gs)
|
if (!gs) nomem("loadgfx");
|
||||||
nomem("loadgfx");
|
|
||||||
colorgs = gs + 1;
|
colorgs = gs + 1;
|
||||||
|
|
||||||
for (i = 0; i < MAXSETS; ++i) {
|
for (i = 0; i < MAXSETS; ++i) {
|
||||||
@ -441,8 +452,7 @@ void loadgfx() {
|
|||||||
bigscrprintf("Loading death sequence\n");
|
bigscrprintf("Loading death sequence\n");
|
||||||
getsingle(deathname, death, NUMDEATHFRAMES);
|
getsingle(deathname, death, NUMDEATHFRAMES);
|
||||||
|
|
||||||
for(i=0;i<MAXSETS;++i)
|
for (i = 0; i < MAXSETS; ++i) freegfxset(colorgs + i);
|
||||||
freegfxset(colorgs+i);
|
|
||||||
free(gs);
|
free(gs);
|
||||||
bigscrprintf("Done loading graphics\n");
|
bigscrprintf("Done loading graphics\n");
|
||||||
}
|
}
|
||||||
|
@ -37,6 +37,7 @@ extern int arraynumx, arraynumy, arraystartx, arraystarty, arrayspacex, arrayspa
|
|||||||
#define NUMDEATHFRAMES 41
|
#define NUMDEATHFRAMES 41
|
||||||
|
|
||||||
|
|
||||||
extern figure blocks[3], blocksx[9], bombs1[MAXSETS][NUMBOMBFRAMES], bombs2[MAXSETS][NUMBOMBFRAMES], flamefigs[MAXSETS][NUMFLAMEFRAMES], tiles[15], death[NUMDEATHFRAMES];
|
extern figure blocks[3], blocksx[9], bombs1[MAXSETS][NUMBOMBFRAMES], bombs2[MAXSETS][NUMBOMBFRAMES], flamefigs[MAXSETS][NUMFLAMEFRAMES], tiles[15],
|
||||||
|
death[NUMDEATHFRAMES];
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
129
src/game.c
129
src/game.c
@ -1,13 +1,13 @@
|
|||||||
|
|
||||||
#include "bomber.h"
|
|
||||||
#include "game.h"
|
#include "game.h"
|
||||||
#include "gfx.h"
|
#include "bomber.h"
|
||||||
#include "network.h"
|
|
||||||
#include "draw.h"
|
#include "draw.h"
|
||||||
#include "utils.h"
|
#include "gfx.h"
|
||||||
#include "sound.h"
|
|
||||||
#include "menu.h"
|
|
||||||
#include "list.h"
|
#include "list.h"
|
||||||
|
#include "menu.h"
|
||||||
|
#include "network.h"
|
||||||
|
#include "sound.h"
|
||||||
|
#include "utils.h"
|
||||||
|
|
||||||
static int gameframe;
|
static int gameframe;
|
||||||
|
|
||||||
@ -35,27 +35,13 @@ char playername[16];
|
|||||||
static int mycount;
|
static int mycount;
|
||||||
|
|
||||||
static int bonustotal;
|
static int bonustotal;
|
||||||
static const int bonuschances[]= {
|
static const int bonuschances[] = {TILE_BOMB, 20, TILE_FLAME, 20, TILE_TRIGGER, 2, TILE_GOLDFLAME, 2, TILE_SKATES, 20, TILE_TURTLE, 5, TILE_NONE, 160};
|
||||||
TILE_BOMB,20,
|
|
||||||
TILE_FLAME,20,
|
|
||||||
TILE_TRIGGER,2,
|
|
||||||
TILE_GOLDFLAME,2,
|
|
||||||
TILE_SKATES,20,
|
|
||||||
TILE_TURTLE,5,
|
|
||||||
TILE_NONE,160
|
|
||||||
};
|
|
||||||
|
|
||||||
static GameOptions gameoptions;
|
static GameOptions gameoptions;
|
||||||
|
|
||||||
static const unsigned char playerpositions[MAXNETNODES*3] = { /* color, x, y */
|
static const unsigned char playerpositions[MAXNETNODES * 3] = {
|
||||||
2,0,0,
|
/* color, x, y */
|
||||||
3,14,10,
|
2, 0, 0, 3, 14, 10, 4, 14, 0, 5, 0, 10, 1, 6, 0, 6, 8, 10, 7, 0, 6, 8, 14, 4,
|
||||||
4,14,0,
|
|
||||||
5,0,10,
|
|
||||||
1,6,0,
|
|
||||||
6,8,10,
|
|
||||||
7,0,6,
|
|
||||||
8,14,4,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static void resetplayer(player* pl, int color, int x, int y) {
|
static void resetplayer(player* pl, int color, int x, int y) {
|
||||||
@ -82,8 +68,7 @@ static void initplayer(int color,int x,int y,int controller) {
|
|||||||
player* pl;
|
player* pl;
|
||||||
|
|
||||||
pl = allocentry(player);
|
pl = allocentry(player);
|
||||||
if(!pl)
|
if (!pl) nomem("Couldn't get player structure (allocentry())");
|
||||||
nomem("Couldn't get player structure (allocentry())");
|
|
||||||
|
|
||||||
list_add_tail(&allplayers, &pl->list_all_players);
|
list_add_tail(&allplayers, &pl->list_all_players);
|
||||||
|
|
||||||
@ -153,8 +138,7 @@ static void initgame() {
|
|||||||
const int* p;
|
const int* p;
|
||||||
int comp;
|
int comp;
|
||||||
|
|
||||||
if (network != NETWORK_SLAVE)
|
if (network != NETWORK_SLAVE) set_game_options(&configopts);
|
||||||
set_game_options(&configopts);
|
|
||||||
gameframe = 0;
|
gameframe = 0;
|
||||||
|
|
||||||
things_list_clear(&activebombs);
|
things_list_clear(&activebombs);
|
||||||
@ -180,8 +164,7 @@ static void initgame() {
|
|||||||
/* if((i&j)&1) {
|
/* if((i&j)&1) {
|
||||||
field[j][i]=FIELD_BORDER;
|
field[j][i]=FIELD_BORDER;
|
||||||
} else*/
|
} else*/
|
||||||
field[j][i]=
|
field[j][i] = (myrand() & 3) >= comp ? FIELD_BRICK : FIELD_EMPTY;
|
||||||
(myrand()&3)>=comp ? FIELD_BRICK : FIELD_EMPTY;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
solidcopyany(&backgroundoriginal, &background, 0, 0, IXSIZE, IYSIZE);
|
solidcopyany(&backgroundoriginal, &background, 0, 0, IXSIZE, IYSIZE);
|
||||||
@ -193,9 +176,12 @@ static void initgame() {
|
|||||||
for (i = 0; i < arraynumx; ++i) {
|
for (i = 0; i < arraynumx; ++i) {
|
||||||
x = arraystartx + i * arrayspacex;
|
x = arraystartx + i * arrayspacex;
|
||||||
bl = field[j][i];
|
bl = field[j][i];
|
||||||
if(bl==FIELD_BORDER) bl=2;
|
if (bl == FIELD_BORDER)
|
||||||
else if(bl==FIELD_BRICK) bl=1;
|
bl = 2;
|
||||||
else continue;
|
else if (bl == FIELD_BRICK)
|
||||||
|
bl = 1;
|
||||||
|
else
|
||||||
|
continue;
|
||||||
drawfigureany(x, y, blocks + bl, &background);
|
drawfigureany(x, y, blocks + bl, &background);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -273,8 +259,7 @@ static void adddecay(int px,int py) {
|
|||||||
addtail(&activedecays, bd);
|
addtail(&activedecays, bd);
|
||||||
xpos = tovideox(bd->xpos);
|
xpos = tovideox(bd->xpos);
|
||||||
ypos = tovideoy(bd->ypos);
|
ypos = tovideoy(bd->ypos);
|
||||||
solidcopyany(&backgroundoriginal,&background,xpos,ypos,
|
solidcopyany(&backgroundoriginal, &background, xpos, ypos, arrayspacex, arrayspacey);
|
||||||
arrayspacex,arrayspacey);
|
|
||||||
solidcopy(&background, xpos, ypos, arrayspacex, arrayspacey);
|
solidcopy(&background, xpos, ypos, arrayspacex, arrayspacey);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -338,8 +323,7 @@ static void processbombs() {
|
|||||||
++bmb->timer;
|
++bmb->timer;
|
||||||
switch (bmb->type) {
|
switch (bmb->type) {
|
||||||
case BOMB_NORMAL:
|
case BOMB_NORMAL:
|
||||||
if (bmb->timer == BOMBLIFE)
|
if (bmb->timer == BOMBLIFE) adddetonate(bmb);
|
||||||
adddetonate(bmb);
|
|
||||||
break;
|
break;
|
||||||
case BOMB_CONTROLLED:
|
case BOMB_CONTROLLED:
|
||||||
if (bmb->timer == BOMB_CONTROLLED_LIFE) {
|
if (bmb->timer == BOMB_CONTROLLED_LIFE) {
|
||||||
@ -487,8 +471,7 @@ static void drawdecays() {
|
|||||||
brickdecay* bd;
|
brickdecay* bd;
|
||||||
|
|
||||||
list_for_each_entry(bd, &activedecays, list) {
|
list_for_each_entry(bd, &activedecays, list) {
|
||||||
addsprite(tovideox(bd->xpos),tovideoy(bd->ypos),
|
addsprite(tovideox(bd->xpos), tovideoy(bd->ypos), blocksx + (bd->timer * 9) / DECAYLIFE);
|
||||||
blocksx+(bd->timer*9)/DECAYLIFE);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -496,8 +479,7 @@ static void drawbonus() {
|
|||||||
bonustile* bonus;
|
bonustile* bonus;
|
||||||
|
|
||||||
list_for_each_entry(bonus, &activebonus, list) {
|
list_for_each_entry(bonus, &activebonus, list) {
|
||||||
addsprite(tovideox(bonus->xpos),tovideoy(bonus->ypos),
|
addsprite(tovideox(bonus->xpos), tovideoy(bonus->ypos), tiles + bonus->type);
|
||||||
tiles+bonus->type);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -507,8 +489,7 @@ static void drawplayers() {
|
|||||||
|
|
||||||
list_for_each_entry(pl, &activeplayers, list) {
|
list_for_each_entry(pl, &activeplayers, list) {
|
||||||
if (!(pl->flags & FLG_DEAD)) {
|
if (!(pl->flags & FLG_DEAD)) {
|
||||||
if(!pl->figure)
|
if (!pl->figure) pl->figure = walking[pl->color] + 30;
|
||||||
pl->figure=walking[pl->color]+30;
|
|
||||||
xpos = tovideox(pl->xpos) + pl->fixx;
|
xpos = tovideox(pl->xpos) + pl->fixx;
|
||||||
ypos = tovideoy(pl->ypos) + pl->fixy;
|
ypos = tovideoy(pl->ypos) + pl->fixy;
|
||||||
addsprite(xpos, ypos, pl->figure);
|
addsprite(xpos, ypos, pl->figure);
|
||||||
@ -520,8 +501,7 @@ static void detonatecontrolled(player *pl) {
|
|||||||
bomb *bmb, *next;
|
bomb *bmb, *next;
|
||||||
|
|
||||||
list_for_each_entry_safe(bmb, next, &activebombs, list) {
|
list_for_each_entry_safe(bmb, next, &activebombs, list) {
|
||||||
if(bmb->owner==pl && bmb->type==BOMB_CONTROLLED)
|
if (bmb->owner == pl && bmb->type == BOMB_CONTROLLED) adddetonate(bmb);
|
||||||
adddetonate(bmb);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -642,14 +622,12 @@ static int centerychange(player *pl) {
|
|||||||
val = pl->ypos + (max << 2);
|
val = pl->ypos + (max << 2);
|
||||||
val %= max;
|
val %= max;
|
||||||
line = max >> 1;
|
line = max >> 1;
|
||||||
if(val<line)
|
if (val < line) {
|
||||||
{
|
|
||||||
if (val - speed < 0)
|
if (val - speed < 0)
|
||||||
return -val;
|
return -val;
|
||||||
else
|
else
|
||||||
return -speed;
|
return -speed;
|
||||||
} else if(val>=line)
|
} else if (val >= line) {
|
||||||
{
|
|
||||||
if (val + speed > max)
|
if (val + speed > max)
|
||||||
return max - val;
|
return max - val;
|
||||||
else
|
else
|
||||||
@ -686,18 +664,14 @@ static void trymove(player *pl,int dx,int dy) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
there = field[wy][wx];
|
there = field[wy][wx];
|
||||||
if((px!=wx || py!=wy) &&
|
if ((px != wx || py != wy) && (there == FIELD_BRICK || there == FIELD_BOMB || there == FIELD_BORDER)) {
|
||||||
(there==FIELD_BRICK||there==FIELD_BOMB||there==FIELD_BORDER))
|
|
||||||
{
|
|
||||||
if (dx && !dy) {
|
if (dx && !dy) {
|
||||||
ty = centerychange(pl);
|
ty = centerychange(pl);
|
||||||
if(ty && depth==1)
|
if (ty && depth == 1) trymove(pl, 0, -SGN(ty));
|
||||||
trymove(pl,0,-SGN(ty));
|
|
||||||
|
|
||||||
} else if (dy && !dx) {
|
} else if (dy && !dx) {
|
||||||
tx = centerxchange(pl);
|
tx = centerxchange(pl);
|
||||||
if(tx && depth==1)
|
if (tx && depth == 1) trymove(pl, -SGN(tx), 0);
|
||||||
trymove(pl,-SGN(tx),0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
@ -719,12 +693,10 @@ static void applybonus(player *pl,bonustile *bonus) {
|
|||||||
deletebonus(bonus);
|
deletebonus(bonus);
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case TILE_BOMB:
|
case TILE_BOMB:
|
||||||
if (pl->bombsavailable < 9)
|
if (pl->bombsavailable < 9) ++(pl->bombsavailable);
|
||||||
++(pl->bombsavailable);
|
|
||||||
break;
|
break;
|
||||||
case TILE_FLAME:
|
case TILE_FLAME:
|
||||||
if(pl->flamelength<maxflame)
|
if (pl->flamelength < maxflame) ++(pl->flamelength);
|
||||||
++(pl->flamelength);
|
|
||||||
break;
|
break;
|
||||||
case TILE_GOLDFLAME:
|
case TILE_GOLDFLAME:
|
||||||
pl->flamelength = maxflame;
|
pl->flamelength = maxflame;
|
||||||
@ -793,12 +765,9 @@ static void doplayer(player *pl) {
|
|||||||
|
|
||||||
// if(what&ACT_TURBO) speed<<=2;
|
// if(what&ACT_TURBO) speed<<=2;
|
||||||
if (what & ACT_PRIMARY) {
|
if (what & ACT_PRIMARY) {
|
||||||
if(there==FIELD_EMPTY && pl->bombsavailable)
|
if (there == FIELD_EMPTY && pl->bombsavailable) dropbomb(pl, px, py, (flags & FLG_CONTROL) ? BOMB_CONTROLLED : BOMB_NORMAL);
|
||||||
dropbomb(pl,px,py,
|
|
||||||
(flags&FLG_CONTROL) ? BOMB_CONTROLLED :BOMB_NORMAL);
|
|
||||||
}
|
}
|
||||||
if(what&ACT_SECONDARY && (flags&FLG_CONTROL))
|
if (what & ACT_SECONDARY && (flags & FLG_CONTROL)) detonatecontrolled(pl);
|
||||||
detonatecontrolled(pl);
|
|
||||||
|
|
||||||
switch (what & ACT_MASK) {
|
switch (what & ACT_MASK) {
|
||||||
case ACT_UP:
|
case ACT_UP:
|
||||||
@ -846,8 +815,7 @@ static void processquits(void) {
|
|||||||
|
|
||||||
if (network != NETWORK_SLAVE) return;
|
if (network != NETWORK_SLAVE) return;
|
||||||
for (i = 0; i < MAXNETNODES; ++i) {
|
for (i = 0; i < MAXNETNODES; ++i) {
|
||||||
if (netnodes[i].used && actions[i]==ACT_QUIT)
|
if (netnodes[i].used && actions[i] == ACT_QUIT) netnodes[i].used = 0;
|
||||||
netnodes[i].used=0;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -855,17 +823,21 @@ static int getaction(void) {
|
|||||||
int what;
|
int what;
|
||||||
|
|
||||||
what = ACT_NONE;
|
what = ACT_NONE;
|
||||||
if(checkpressed(MYLEFT)) what=ACT_LEFT;
|
if (checkpressed(MYLEFT))
|
||||||
else if(checkpressed(MYRIGHT)) what=ACT_RIGHT;
|
what = ACT_LEFT;
|
||||||
else if(checkpressed(MYDOWN)) what=ACT_DOWN;
|
else if (checkpressed(MYRIGHT))
|
||||||
else if(checkpressed(MYUP)) what=ACT_UP;
|
what = ACT_RIGHT;
|
||||||
else if(checkdown(13)) what=ACT_ENTER;
|
else if (checkpressed(MYDOWN))
|
||||||
else if(checkdown(0x1b)) what=ACT_QUIT;
|
what = ACT_DOWN;
|
||||||
|
else if (checkpressed(MYUP))
|
||||||
|
what = ACT_UP;
|
||||||
|
else if (checkdown(13))
|
||||||
|
what = ACT_ENTER;
|
||||||
|
else if (checkdown(0x1b))
|
||||||
|
what = ACT_QUIT;
|
||||||
|
|
||||||
if(checkdown(' '))
|
if (checkdown(' ')) what |= ACT_PRIMARY;
|
||||||
what|=ACT_PRIMARY;
|
if (checkdown('b')) what |= ACT_SECONDARY;
|
||||||
if(checkdown('b'))
|
|
||||||
what|=ACT_SECONDARY;
|
|
||||||
|
|
||||||
return what;
|
return what;
|
||||||
}
|
}
|
||||||
@ -939,8 +911,7 @@ static int iterate(void) {
|
|||||||
}
|
}
|
||||||
if (deadplayers > 0 && (!i || (NETWORK_NONE != network && i == 1))) {
|
if (deadplayers > 0 && (!i || (NETWORK_NONE != network && i == 1))) {
|
||||||
++deathcount;
|
++deathcount;
|
||||||
if(deathcount==25)
|
if (deathcount == 25) return CODE_ALLDEAD;
|
||||||
return CODE_ALLDEAD;
|
|
||||||
} else
|
} else
|
||||||
deathcount = 0;
|
deathcount = 0;
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
#ifndef GAME_H
|
#ifndef GAME_H
|
||||||
#define GAME_H
|
#define GAME_H
|
||||||
|
|
||||||
|
#include "bomber.h"
|
||||||
|
|
||||||
#define FRACTION 9
|
#define FRACTION 9
|
||||||
#define SPEEDDELTA (1 << (FRACTION - 1))
|
#define SPEEDDELTA (1 << (FRACTION - 1))
|
||||||
#define SPEEDMAX (10 << FRACTION)
|
#define SPEEDMAX (10 << FRACTION)
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
|
|
||||||
#include "bomber.h"
|
|
||||||
#include "list.h"
|
#include "list.h"
|
||||||
|
#include "bomber.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
|
||||||
typedef union genericlistitem genericlistitem;
|
typedef union genericlistitem genericlistitem;
|
||||||
@ -31,9 +31,7 @@ void alloc_things(void) {
|
|||||||
}
|
}
|
||||||
if (!things) nomem("Trying to allocate thing memory");
|
if (!things) nomem("Trying to allocate thing memory");
|
||||||
|
|
||||||
for (i=0; i < MAXTHINGS - 1; ++i) {
|
for (i = 0; i < MAXTHINGS - 1; ++i) { things[i].next = &things[i + 1]; }
|
||||||
things[i].next = &things[i + 1];
|
|
||||||
}
|
|
||||||
things[i].next = 0;
|
things[i].next = 0;
|
||||||
free_things = things;
|
free_things = things;
|
||||||
count_used = 0;
|
count_used = 0;
|
||||||
|
17
src/list.h
17
src/list.h
@ -1,10 +1,16 @@
|
|||||||
#ifndef LIST_H
|
#ifndef LIST_H
|
||||||
#define LIST_H
|
#define LIST_H
|
||||||
|
|
||||||
|
#include <stddef.h>
|
||||||
|
|
||||||
/* from linux kernel (with some changes for "iso" c) */
|
/* from linux kernel (with some changes for "iso" c) */
|
||||||
|
|
||||||
#define container_of(ptr, type, member) \
|
typedef struct listhead listhead;
|
||||||
((type *)( (char *)(__typeof__( ((type *)0)->member ) *)(ptr) - offsetof(type,member)))
|
struct listhead {
|
||||||
|
listhead *prev, *next;
|
||||||
|
};
|
||||||
|
|
||||||
|
#define container_of(ptr, type, member) ((type*) ((char*) (__typeof__(((type*) 0)->member)*) (ptr) -offsetof(type, member)))
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* list_entry - get the struct for this entry
|
* list_entry - get the struct for this entry
|
||||||
@ -37,8 +43,7 @@ void things_list_clear(listhead *head); /* listhead member must be the first mem
|
|||||||
* @member: the name of the list_struct within the struct.
|
* @member: the name of the list_struct within the struct.
|
||||||
*/
|
*/
|
||||||
#define list_for_each_entry(pos, head, member) \
|
#define list_for_each_entry(pos, head, member) \
|
||||||
for (pos = list_entry((head)->next, __typeof__(*pos), member); \
|
for (pos = list_entry((head)->next, __typeof__(*pos), member); /* prefetch(pos->member.next), */ \
|
||||||
/* prefetch(pos->member.next), */ \
|
|
||||||
&pos->member != (head); \
|
&pos->member != (head); \
|
||||||
pos = list_entry(pos->member.next, __typeof__(*pos), member))
|
pos = list_entry(pos->member.next, __typeof__(*pos), member))
|
||||||
|
|
||||||
@ -50,9 +55,7 @@ void things_list_clear(listhead *head); /* listhead member must be the first mem
|
|||||||
* @member:>the name of the list_struct within the struct.
|
* @member:>the name of the list_struct within the struct.
|
||||||
*/
|
*/
|
||||||
#define list_for_each_entry_safe(pos, n, head, member) \
|
#define list_for_each_entry_safe(pos, n, head, member) \
|
||||||
for (pos = list_entry((head)->next, __typeof__(*pos), member), \
|
for (pos = list_entry((head)->next, __typeof__(*pos), member), n = list_entry(pos->member.next, __typeof__(*pos), member); &pos->member != (head); \
|
||||||
n = list_entry(pos->member.next, __typeof__(*pos), member); \
|
|
||||||
&pos->member != (head); \
|
|
||||||
pos = n, n = list_entry(n->member.next, __typeof__(*n), member))
|
pos = n, n = list_entry(n->member.next, __typeof__(*n), member))
|
||||||
|
|
||||||
#define list_empty(head) ((head) == (head)->next)
|
#define list_empty(head) ((head) == (head)->next)
|
||||||
|
185
src/matcher.c
185
src/matcher.c
@ -1,17 +1,17 @@
|
|||||||
|
#include <arpa/inet.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <netdb.h>
|
||||||
|
#include <netinet/in.h>
|
||||||
|
#include <signal.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <sys/uio.h>
|
|
||||||
#include <sys/types.h>
|
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#include <netinet/in.h>
|
|
||||||
#include <arpa/inet.h>
|
|
||||||
#include <netdb.h>
|
|
||||||
#include <sys/timeb.h>
|
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
|
#include <sys/timeb.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/uio.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <signal.h>
|
|
||||||
#include <fcntl.h>
|
|
||||||
|
|
||||||
|
|
||||||
#define MAXMSG 256
|
#define MAXMSG 256
|
||||||
@ -35,8 +35,7 @@ char masterhostname[256];
|
|||||||
#define MAXMATCHES 16
|
#define MAXMATCHES 16
|
||||||
|
|
||||||
|
|
||||||
struct registration
|
struct registration {
|
||||||
{
|
|
||||||
uchar id;
|
uchar id;
|
||||||
uchar unique[4];
|
uchar unique[4];
|
||||||
uchar password[4];
|
uchar password[4];
|
||||||
@ -44,15 +43,13 @@ struct registration
|
|||||||
uchar name[16];
|
uchar name[16];
|
||||||
uchar status;
|
uchar status;
|
||||||
};
|
};
|
||||||
struct query
|
struct query {
|
||||||
{
|
|
||||||
uchar id;
|
uchar id;
|
||||||
uchar password[4];
|
uchar password[4];
|
||||||
uchar version[4];
|
uchar version[4];
|
||||||
};
|
};
|
||||||
|
|
||||||
struct gamehost
|
struct gamehost {
|
||||||
{
|
|
||||||
struct gamehost *next, *prev;
|
struct gamehost *next, *prev;
|
||||||
uchar machine[4];
|
uchar machine[4];
|
||||||
uchar port[2];
|
uchar port[2];
|
||||||
@ -64,21 +61,18 @@ struct gamehost
|
|||||||
struct gamehost *freehosts = 0, *activehosts = 0;
|
struct gamehost *freehosts = 0, *activehosts = 0;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int udpsocket, myport;
|
int udpsocket, myport;
|
||||||
struct sockaddr_in myname = {0}, mastername = {0};
|
struct sockaddr_in myname = {0}, mastername = {0};
|
||||||
socklen_t senderlength;
|
socklen_t senderlength;
|
||||||
struct sockaddr_in sender = {0};
|
struct sockaddr_in sender = {0};
|
||||||
|
|
||||||
long longtime(void)
|
long longtime(void) {
|
||||||
{
|
|
||||||
struct timeb tb;
|
struct timeb tb;
|
||||||
ftime(&tb);
|
ftime(&tb);
|
||||||
return tb.time;
|
return tb.time;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *timestr()
|
char* timestr() {
|
||||||
{
|
|
||||||
static char timestring[80];
|
static char timestring[80];
|
||||||
|
|
||||||
time_t t;
|
time_t t;
|
||||||
@ -91,16 +85,13 @@ int l;
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int putmsg(struct sockaddr_in *toname,unsigned char *msg,int len)
|
int putmsg(struct sockaddr_in* toname, unsigned char* msg, int len) {
|
||||||
{
|
|
||||||
int status;
|
int status;
|
||||||
|
|
||||||
status=sendto(udpsocket,msg,len,0,
|
status = sendto(udpsocket, msg, len, 0, (struct sockaddr*) toname, sizeof(struct sockaddr_in));
|
||||||
(struct sockaddr *)toname,sizeof(struct sockaddr_in));
|
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
void ack()
|
void ack() {
|
||||||
{
|
|
||||||
uchar copy[256];
|
uchar copy[256];
|
||||||
|
|
||||||
*copy = PKT_ACK;
|
*copy = PKT_ACK;
|
||||||
@ -108,15 +99,13 @@ uchar copy[256];
|
|||||||
putmsg(&sender, copy, lastsize + 1);
|
putmsg(&sender, copy, lastsize + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
int getmsg(int seconds)
|
int getmsg(int seconds) {
|
||||||
{
|
|
||||||
int size;
|
int size;
|
||||||
|
|
||||||
lastsize = -1;
|
lastsize = -1;
|
||||||
memset(&sender, 0, sizeof(sender));
|
memset(&sender, 0, sizeof(sender));
|
||||||
senderlength = sizeof(sender);
|
senderlength = sizeof(sender);
|
||||||
if(seconds)
|
if (seconds) {
|
||||||
{
|
|
||||||
struct timeval timeout;
|
struct timeval timeout;
|
||||||
fd_set readfds;
|
fd_set readfds;
|
||||||
int res;
|
int res;
|
||||||
@ -128,29 +117,24 @@ int size;
|
|||||||
res = select(udpsocket + 1, &readfds, 0, 0, &timeout);
|
res = select(udpsocket + 1, &readfds, 0, 0, &timeout);
|
||||||
if (res <= 0) return -1;
|
if (res <= 0) return -1;
|
||||||
}
|
}
|
||||||
lastsize=size=recvfrom(udpsocket,mesg,MAXMSG,0,
|
lastsize = size = recvfrom(udpsocket, mesg, MAXMSG, 0, (struct sockaddr*) &sender, &senderlength);
|
||||||
(struct sockaddr *)&sender,&senderlength);
|
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
long longind(unsigned char *p)
|
long longind(unsigned char* p) {
|
||||||
{
|
|
||||||
return (p[0] << 24L) | (p[1] << 16L) | (p[2] << 8) | p[3];
|
return (p[0] << 24L) | (p[1] << 16L) | (p[2] << 8) | p[3];
|
||||||
}
|
}
|
||||||
short shortind(unsigned char *p)
|
short shortind(unsigned char* p) {
|
||||||
{
|
|
||||||
return (p[0] << 8L) | p[1];
|
return (p[0] << 8L) | p[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void openport(int portwant)
|
void openport(int portwant) {
|
||||||
{
|
|
||||||
int status;
|
int status;
|
||||||
|
|
||||||
myport = portwant;
|
myport = portwant;
|
||||||
udpsocket = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP);
|
udpsocket = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP);
|
||||||
if(udpsocket==-1)
|
if (udpsocket == -1) {
|
||||||
{
|
|
||||||
perror("socket()");
|
perror("socket()");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
@ -160,8 +144,7 @@ int status;
|
|||||||
myname.sin_port = htons(myport);
|
myname.sin_port = htons(myport);
|
||||||
|
|
||||||
status = bind(udpsocket, (struct sockaddr*) &myname, sizeof(myname));
|
status = bind(udpsocket, (struct sockaddr*) &myname, sizeof(myname));
|
||||||
if(status==-1)
|
if (status == -1) {
|
||||||
{
|
|
||||||
perror("bind()");
|
perror("bind()");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
@ -169,19 +152,16 @@ int status;
|
|||||||
|
|
||||||
#define PERBLOCK 512
|
#define PERBLOCK 512
|
||||||
|
|
||||||
struct gamehost *newhost()
|
struct gamehost* newhost() {
|
||||||
{
|
|
||||||
struct gamehost *h, *block;
|
struct gamehost *h, *block;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
if(!freehosts)
|
if (!freehosts) {
|
||||||
{
|
|
||||||
block = malloc(sizeof(struct gamehost) * PERBLOCK);
|
block = malloc(sizeof(struct gamehost) * PERBLOCK);
|
||||||
if (!block) return 0;
|
if (!block) return 0;
|
||||||
freehosts = block;
|
freehosts = block;
|
||||||
i = PERBLOCK - 1;
|
i = PERBLOCK - 1;
|
||||||
while(i--)
|
while (i--) {
|
||||||
{
|
|
||||||
block->next = block + 1;
|
block->next = block + 1;
|
||||||
++block;
|
++block;
|
||||||
}
|
}
|
||||||
@ -193,72 +173,73 @@ int i;
|
|||||||
return h;
|
return h;
|
||||||
}
|
}
|
||||||
|
|
||||||
void freehost(struct gamehost *h)
|
void freehost(struct gamehost* h) {
|
||||||
{
|
|
||||||
h->next = freehosts;
|
h->next = freehosts;
|
||||||
freehosts = h;
|
freehosts = h;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct gamehost *findmatch(struct registration *key)
|
struct gamehost* findmatch(struct registration* key) {
|
||||||
{
|
|
||||||
struct gamehost* h;
|
struct gamehost* h;
|
||||||
h = activehosts;
|
h = activehosts;
|
||||||
while(h)
|
while (h) {
|
||||||
{
|
if (!memcmp(&h->reg, key, sizeof(struct registration) - 1)) return h;
|
||||||
if(!memcmp(&h->reg,key,sizeof(struct registration)-1))
|
|
||||||
return h;
|
|
||||||
h = h->next;
|
h = h->next;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void insert(struct gamehost* h) {
|
||||||
void insert(struct gamehost *h)
|
if (activehosts) {
|
||||||
{
|
|
||||||
if(activehosts)
|
|
||||||
{
|
|
||||||
h->next = activehosts;
|
h->next = activehosts;
|
||||||
h->prev = activehosts->prev;
|
h->prev = activehosts->prev;
|
||||||
activehosts->prev = h;
|
activehosts->prev = h;
|
||||||
activehosts = h;
|
activehosts = h;
|
||||||
} else
|
} else {
|
||||||
{
|
|
||||||
h->next = h->prev = 0;
|
h->next = h->prev = 0;
|
||||||
activehosts = h;
|
activehosts = h;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void delete(struct gamehost *h)
|
void delete (struct gamehost* h) {
|
||||||
{
|
|
||||||
if (h->prev)
|
if (h->prev)
|
||||||
h->prev->next = h->next;
|
h->prev->next = h->next;
|
||||||
else
|
else
|
||||||
activehosts = h->next;
|
activehosts = h->next;
|
||||||
if(h->next)
|
if (h->next) h->next->prev = h->prev;
|
||||||
h->next->prev=h->prev;
|
|
||||||
freehost(h);
|
freehost(h);
|
||||||
}
|
}
|
||||||
void doreg()
|
void doreg() {
|
||||||
{
|
|
||||||
struct registration* new;
|
struct registration* new;
|
||||||
struct gamehost* match;
|
struct gamehost* match;
|
||||||
long now;
|
long now;
|
||||||
|
|
||||||
new = (struct registration*) mesg;
|
new = (struct registration*) mesg;
|
||||||
match = findmatch(new);
|
match = findmatch(new);
|
||||||
if(logging)
|
if (logging) {
|
||||||
{
|
|
||||||
unsigned addr = ntohl(sender.sin_addr.s_addr);
|
unsigned addr = ntohl(sender.sin_addr.s_addr);
|
||||||
unsigned short port = ntohs(sender.sin_port);
|
unsigned short port = ntohs(sender.sin_port);
|
||||||
printf("reg :%s:%d.%d.%d.%d:%d %c%lx '%s'\n",timestr(),
|
printf(
|
||||||
(addr>>24)&255,(addr>>16)&255,(addr>>8)&255,addr&255,port,
|
"reg :%s:%d.%d.%d.%d:%d %c%lx '%s'\n",
|
||||||
new->status ? '+' : '-',(long)match,new->name);
|
timestr(),
|
||||||
|
(addr >> 24) & 255,
|
||||||
|
(addr >> 16) & 255,
|
||||||
|
(addr >> 8) & 255,
|
||||||
|
addr & 255,
|
||||||
|
port,
|
||||||
|
new->status ? '+' : '-',
|
||||||
|
(long) match,
|
||||||
|
new->name);
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
}
|
}
|
||||||
if(!match && !new->status) {ack();return;}
|
if (!match && !new->status) {
|
||||||
if(match && new->status) {ack();return;}
|
ack();
|
||||||
if(!match && new->status)
|
return;
|
||||||
{
|
}
|
||||||
|
if (match && new->status) {
|
||||||
|
ack();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!match && new->status) {
|
||||||
match = newhost();
|
match = newhost();
|
||||||
if (!match) return; // No memory, what can we do?
|
if (!match) return; // No memory, what can we do?
|
||||||
memmove(match->machine, &sender.sin_addr.s_addr, 4);
|
memmove(match->machine, &sender.sin_addr.s_addr, 4);
|
||||||
@ -277,20 +258,17 @@ long now;
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void doquery()
|
void doquery() {
|
||||||
{
|
|
||||||
uchar* password;
|
uchar* password;
|
||||||
uchar* version;
|
uchar* version;
|
||||||
struct gamehost* h;
|
struct gamehost* h;
|
||||||
uchar response[2048], *rput, *countersave;
|
uchar response[2048], *rput, *countersave;
|
||||||
int counter;
|
int counter;
|
||||||
|
|
||||||
if(logging)
|
if (logging) {
|
||||||
{
|
|
||||||
unsigned addr = ntohl(sender.sin_addr.s_addr);
|
unsigned addr = ntohl(sender.sin_addr.s_addr);
|
||||||
unsigned short port = ntohs(sender.sin_port);
|
unsigned short port = ntohs(sender.sin_port);
|
||||||
printf("query:%s:%d.%d.%d.%d:%d\n",timestr(),
|
printf("query:%s:%d.%d.%d.%d:%d\n", timestr(), (addr >> 24) & 255, (addr >> 16) & 255, (addr >> 8) & 255, addr & 255, port);
|
||||||
(addr>>24)&255,(addr>>16)&255,(addr>>8)&255,addr&255,port);
|
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
}
|
}
|
||||||
password = mesg + 1;
|
password = mesg + 1;
|
||||||
@ -307,11 +285,8 @@ int counter;
|
|||||||
*rput++ = 0;
|
*rput++ = 0;
|
||||||
counter = 0;
|
counter = 0;
|
||||||
|
|
||||||
while(h)
|
while (h) {
|
||||||
{
|
if (!memcmp(password, h->reg.password, 4) && !memcmp(version, h->reg.version, 4) && counter < MAXMATCHES) {
|
||||||
if(!memcmp(password,h->reg.password,4) &&
|
|
||||||
!memcmp(version,h->reg.version,4) && counter<MAXMATCHES)
|
|
||||||
{
|
|
||||||
++counter;
|
++counter;
|
||||||
memmove(rput, h->reg.unique, 4);
|
memmove(rput, h->reg.unique, 4);
|
||||||
rput += 4;
|
rput += 4;
|
||||||
@ -327,27 +302,20 @@ int counter;
|
|||||||
*countersave++ = counter >> 8;
|
*countersave++ = counter >> 8;
|
||||||
*countersave++ = counter;
|
*countersave++ = counter;
|
||||||
putmsg(&sender, response, rput - response);
|
putmsg(&sender, response, rput - response);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void purge(long cutoff)
|
void purge(long cutoff) {
|
||||||
{
|
|
||||||
struct gamehost *h, *h2;
|
struct gamehost *h, *h2;
|
||||||
h = activehosts;
|
h = activehosts;
|
||||||
while(h)
|
while (h) {
|
||||||
{
|
|
||||||
h2 = h;
|
h2 = h;
|
||||||
h = h->next;
|
h = h->next;
|
||||||
if(cutoff-h2->timeout>0)
|
if (cutoff - h2->timeout > 0) { delete (h2); }
|
||||||
{
|
|
||||||
delete(h2);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int main(int argc,char **argv)
|
int main(int argc, char** argv) {
|
||||||
{
|
|
||||||
int i;
|
int i;
|
||||||
int want;
|
int want;
|
||||||
int size;
|
int size;
|
||||||
@ -355,24 +323,21 @@ long purgetime;
|
|||||||
long now;
|
long now;
|
||||||
|
|
||||||
want = PORT;
|
want = PORT;
|
||||||
if(argc>1)
|
if (argc > 1) {
|
||||||
{
|
|
||||||
for (i = 1; i < argc; ++i)
|
for (i = 1; i < argc; ++i)
|
||||||
if(!strncmp(argv[i],"-p",2))
|
if (!strncmp(argv[i], "-p", 2)) {
|
||||||
{
|
if (strlen(argv[i]) > 2)
|
||||||
if(strlen(argv[i])>2) want=atoi(argv[i]+2);
|
want = atoi(argv[i] + 2);
|
||||||
else if(i+1<argc) want=atoi(argv[i+1]);
|
else if (i + 1 < argc)
|
||||||
|
want = atoi(argv[i + 1]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
freehosts = 0;
|
freehosts = 0;
|
||||||
openport(want);
|
openport(want);
|
||||||
purgetime = longtime() + TIMETOLIVE;
|
purgetime = longtime() + TIMETOLIVE;
|
||||||
for(;;)
|
for (;;) {
|
||||||
{
|
|
||||||
size = getmsg(10);
|
size = getmsg(10);
|
||||||
if(size>=1)
|
if (size >= 1) switch (*mesg) {
|
||||||
switch(*mesg)
|
|
||||||
{
|
|
||||||
case PKT_REGISTER:
|
case PKT_REGISTER:
|
||||||
if (size < sizeof(struct registration)) continue;
|
if (size < sizeof(struct registration)) continue;
|
||||||
doreg();
|
doreg();
|
||||||
|
63
src/menu.c
63
src/menu.c
@ -1,24 +1,19 @@
|
|||||||
|
|
||||||
#include "bomber.h"
|
|
||||||
#include "menu.h"
|
#include "menu.h"
|
||||||
#include "draw.h"
|
|
||||||
#include "gfx.h"
|
|
||||||
#include "utils.h"
|
|
||||||
#include "sound.h"
|
|
||||||
#include "network.h"
|
|
||||||
#include "announce.h"
|
#include "announce.h"
|
||||||
|
#include "bomber.h"
|
||||||
|
#include "draw.h"
|
||||||
#include "game.h"
|
#include "game.h"
|
||||||
|
#include "gfx.h"
|
||||||
|
#include "network.h"
|
||||||
|
#include "sound.h"
|
||||||
|
#include "utils.h"
|
||||||
|
|
||||||
GameOptions configopts = {2, 1, 0, 2};
|
GameOptions configopts = {2, 1, 0, 2};
|
||||||
|
|
||||||
/* Generic menu */
|
/* Generic menu */
|
||||||
|
|
||||||
typedef enum {
|
typedef enum { MENU_ANY = -1, MENU_MAIN = 0, MENU_CONFIG = 2, MENU_JOIN = 3 } menuname;
|
||||||
MENU_ANY = -1,
|
|
||||||
MENU_MAIN = 0,
|
|
||||||
MENU_CONFIG = 2,
|
|
||||||
MENU_JOIN = 3
|
|
||||||
} menuname;
|
|
||||||
|
|
||||||
#define MENU_SELECT(x) ((menuname)(-x - 1))
|
#define MENU_SELECT(x) ((menuname)(-x - 1))
|
||||||
|
|
||||||
@ -36,12 +31,10 @@ static void drawmenu(int selected) {
|
|||||||
j = strlen(menutitle) * bigfontxsize;
|
j = strlen(menutitle) * bigfontxsize;
|
||||||
drawbigstring((IXSIZE - j) >> 1, 20, menutitle);
|
drawbigstring((IXSIZE - j) >> 1, 20, menutitle);
|
||||||
ty = ((IYSIZE - (bigfontysize * menunum)) >> 1) - (IYSIZE >> 3);
|
ty = ((IYSIZE - (bigfontysize * menunum)) >> 1) - (IYSIZE >> 3);
|
||||||
for(i=0;i<menunum;++i)
|
for (i = 0; i < menunum; ++i) {
|
||||||
{
|
|
||||||
j = strlen(menuitems[i]) * bigfontxsize;
|
j = strlen(menuitems[i]) * bigfontxsize;
|
||||||
tx = (IXSIZE - j) >> 1;
|
tx = (IXSIZE - j) >> 1;
|
||||||
if(i==selected)
|
if (i == selected) {
|
||||||
{
|
|
||||||
greyrect(0, ty - 1, tx - 5, bigfontysize);
|
greyrect(0, ty - 1, tx - 5, bigfontysize);
|
||||||
greyrect(tx + j + 3, ty - 1, IXSIZE - (tx + j + 3), bigfontysize);
|
greyrect(tx + j + 3, ty - 1, IXSIZE - (tx + j + 3), bigfontysize);
|
||||||
}
|
}
|
||||||
@ -93,18 +86,18 @@ static int domenu(menuname whichmenu, int (*pause)(void)) {
|
|||||||
return selected;
|
return selected;
|
||||||
case 'k':
|
case 'k':
|
||||||
case MYUP:
|
case MYUP:
|
||||||
if (selected) --selected;
|
if (selected)
|
||||||
else selected=menunum-1;
|
--selected;
|
||||||
if (whichmenu>=0)
|
else
|
||||||
menuhistory[whichmenu]=selected;
|
selected = menunum - 1;
|
||||||
|
if (whichmenu >= 0) menuhistory[whichmenu] = selected;
|
||||||
redraw = 1;
|
redraw = 1;
|
||||||
break;
|
break;
|
||||||
case 'j':
|
case 'j':
|
||||||
case MYDOWN:
|
case MYDOWN:
|
||||||
++selected;
|
++selected;
|
||||||
if (selected == menunum) selected = 0;
|
if (selected == menunum) selected = 0;
|
||||||
if (whichmenu>=0)
|
if (whichmenu >= 0) menuhistory[whichmenu] = selected;
|
||||||
menuhistory[whichmenu]=selected;
|
|
||||||
redraw = 1;
|
redraw = 1;
|
||||||
break;
|
break;
|
||||||
case 0x1b:
|
case 0x1b:
|
||||||
@ -296,9 +289,7 @@ static void drawjoinscreen(void) {
|
|||||||
static int tryjoin(int which) {
|
static int tryjoin(int which) {
|
||||||
int res;
|
int res;
|
||||||
|
|
||||||
if (0 == (res = send_join(&gamelistentries[which].netname, playername))) {
|
if (0 == (res = send_join(&gamelistentries[which].netname, playername))) { return 0; }
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
while (!exitflag) {
|
while (!exitflag) {
|
||||||
switch (res) {
|
switch (res) {
|
||||||
@ -309,8 +300,10 @@ static int tryjoin(int which) {
|
|||||||
drawjoinscreen();
|
drawjoinscreen();
|
||||||
copyup();
|
copyup();
|
||||||
break;
|
break;
|
||||||
case 3: return 1;
|
case 3:
|
||||||
default: break;
|
return 1;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
scaninput();
|
scaninput();
|
||||||
while (anydown()) {
|
while (anydown()) {
|
||||||
@ -335,9 +328,7 @@ static void join_game(void) {
|
|||||||
int i;
|
int i;
|
||||||
int sel = -1;
|
int sel = -1;
|
||||||
|
|
||||||
if (!searchgames()) {
|
if (!searchgames()) { return; }
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
menuhistory[MENU_JOIN] = 0;
|
menuhistory[MENU_JOIN] = 0;
|
||||||
|
|
||||||
@ -348,9 +339,7 @@ static void join_game(void) {
|
|||||||
addexit("EXIT");
|
addexit("EXIT");
|
||||||
} else {
|
} else {
|
||||||
additem("JOIN NETWORK GAME");
|
additem("JOIN NETWORK GAME");
|
||||||
for (i = 0; i < gamelistsize; i++) {
|
for (i = 0; i < gamelistsize; i++) { additem(gamelistentries[i].name); }
|
||||||
additem(gamelistentries[i].name);
|
|
||||||
}
|
|
||||||
addexit("EXIT");
|
addexit("EXIT");
|
||||||
}
|
}
|
||||||
sel = domenu(MENU_JOIN, join_game_pause);
|
sel = domenu(MENU_JOIN, join_game_pause);
|
||||||
@ -358,12 +347,8 @@ static void join_game(void) {
|
|||||||
}
|
}
|
||||||
stop_search();
|
stop_search();
|
||||||
|
|
||||||
if(menuexit == sel || !gamelistsize) {
|
if (menuexit == sel || !gamelistsize) { return; }
|
||||||
return;
|
if (!tryjoin(sel)) { return; }
|
||||||
}
|
|
||||||
if(!tryjoin(sel)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
run_network_game();
|
run_network_game();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
|
|
||||||
#include "bomber.h"
|
#include "network.h"
|
||||||
#include "announce.h"
|
#include "announce.h"
|
||||||
|
#include "bomber.h"
|
||||||
|
#include "draw.h"
|
||||||
#include "game.h"
|
#include "game.h"
|
||||||
#include "menu.h"
|
#include "menu.h"
|
||||||
#include "network.h"
|
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
#include "draw.h"
|
|
||||||
|
|
||||||
#define MAXMSG 4096
|
#define MAXMSG 4096
|
||||||
|
|
||||||
@ -65,10 +65,7 @@ enum reject_reason {
|
|||||||
|
|
||||||
#define _REJECT_LAST REJECT_VERSION
|
#define _REJECT_LAST REJECT_VERSION
|
||||||
|
|
||||||
const char *reject_reason_str[] = {
|
const char* reject_reason_str[] = {"Server full", "Version mismatch"};
|
||||||
"Server full",
|
|
||||||
"Version mismatch"
|
|
||||||
};
|
|
||||||
|
|
||||||
/* all bytes stored MSB first */
|
/* all bytes stored MSB first */
|
||||||
|
|
||||||
@ -143,8 +140,7 @@ outmsgs() {
|
|||||||
if (message[i].time) {
|
if (message[i].time) {
|
||||||
--message[i].time;
|
--message[i].time;
|
||||||
if (message[i].time) continue;
|
if (message[i].time) continue;
|
||||||
sendto(udpsocket,message[i].msg,message[i].len,0,
|
sendto(udpsocket, message[i].msg, message[i].len, 0, message[i].to, sizeof(struct sockaddr_in));
|
||||||
message[i].to,sizeof(struct sockaddr_in));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -167,11 +163,9 @@ static int putmsg(struct sockaddr_in *toname,unsigned char *msg,int len) {
|
|||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
#else
|
#else
|
||||||
status=sendto(udpsocket,msg,len,0,
|
status = sendto(udpsocket, msg, len, 0, (struct sockaddr*) toname, sizeof(struct sockaddr_in));
|
||||||
(struct sockaddr *)toname,sizeof(struct sockaddr_in));
|
|
||||||
return status;
|
return status;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int getmsg(int msec) {
|
static int getmsg(int msec) {
|
||||||
@ -192,8 +186,7 @@ static int getmsg(int msec) {
|
|||||||
res = select(udpsocket + 1, &readfds, 0, 0, &timeout);
|
res = select(udpsocket + 1, &readfds, 0, 0, &timeout);
|
||||||
if (res <= 0) return -1;
|
if (res <= 0) return -1;
|
||||||
}
|
}
|
||||||
size=recvfrom(udpsocket,mesg,MAXMSG,0,
|
size = recvfrom(udpsocket, mesg, MAXMSG, 0, (struct sockaddr*) &sender, &senderlength);
|
||||||
(struct sockaddr *)&sender,&senderlength);
|
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -236,17 +229,12 @@ static int isvalidmsg_from_slave() {
|
|||||||
host = &sender.sin_addr.s_addr;
|
host = &sender.sin_addr.s_addr;
|
||||||
port = &sender.sin_port;
|
port = &sender.sin_port;
|
||||||
for (i = 1; i < MAXNETNODES; ++i)
|
for (i = 1; i < MAXNETNODES; ++i)
|
||||||
if(netnodes[i].used &&
|
if (netnodes[i].used && !memcmp(&netnodes[i].netname.sin_addr.s_addr, host, 4) && !memcmp(&netnodes[i].netname.sin_port, port, 2)) return i;
|
||||||
!memcmp(&netnodes[i].netname.sin_addr.s_addr,host,4) &&
|
|
||||||
!memcmp(&netnodes[i].netname.sin_port,port,2))
|
|
||||||
return i;
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int isvalidmsg_from_master() {
|
static int isvalidmsg_from_master() {
|
||||||
if (sender.sin_family != mastername.sin_family
|
if (sender.sin_family != mastername.sin_family || sender.sin_addr.s_addr != mastername.sin_addr.s_addr || sender.sin_port != mastername.sin_port) return 0;
|
||||||
|| sender.sin_addr.s_addr != mastername.sin_addr.s_addr
|
|
||||||
|| sender.sin_port != mastername.sin_port) return 0;
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -293,13 +281,11 @@ int networktraffic(void) {
|
|||||||
actions[0] = myaction;
|
actions[0] = myaction;
|
||||||
if (myaction == ACT_QUIT) {
|
if (myaction == ACT_QUIT) {
|
||||||
for (i = 1; i < MAXNETNODES; ++i) {
|
for (i = 1; i < MAXNETNODES; ++i) {
|
||||||
if (netnodes[i].used)
|
if (netnodes[i].used) actions[i] = ACT_QUIT;
|
||||||
actions[i] = ACT_QUIT;
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for (i = 1; i < MAXNETNODES; ++i) {
|
for (i = 1; i < MAXNETNODES; ++i) {
|
||||||
if (netnodes[i].used)
|
if (netnodes[i].used) actions[i] &= ACT_MASK; /* only keep direction */
|
||||||
actions[i] &= ACT_MASK; /* only keep direction */
|
|
||||||
}
|
}
|
||||||
now = gtime();
|
now = gtime();
|
||||||
for (;;) {
|
for (;;) {
|
||||||
@ -326,8 +312,7 @@ int networktraffic(void) {
|
|||||||
for (i = 1; i < MAXNETNODES; ++i) {
|
for (i = 1; i < MAXNETNODES; ++i) {
|
||||||
if (netnodes[i].used) {
|
if (netnodes[i].used) {
|
||||||
sendactions(i); /* send actions to every active node */
|
sendactions(i); /* send actions to every active node */
|
||||||
if (actions[i] == ACT_QUIT)
|
if (actions[i] == ACT_QUIT) netnodes[i].used = 0; /* remove disconnected clients */
|
||||||
netnodes[i].used = 0; /* remove disconnected clients */
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return actioncount;
|
return actioncount;
|
||||||
@ -464,8 +449,7 @@ void send_config() {
|
|||||||
int i;
|
int i;
|
||||||
build_config();
|
build_config();
|
||||||
for (i = 1; i < MAXNETNODES; ++i)
|
for (i = 1; i < MAXNETNODES; ++i)
|
||||||
if (netnodes[i].used)
|
if (netnodes[i].used) send_config1(i);
|
||||||
send_config1(i);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void send_reject(struct sockaddr_in* toname, Uint32 network_join_unique, unsigned char reason) {
|
static void send_reject(struct sockaddr_in* toname, Uint32 network_join_unique, unsigned char reason) {
|
||||||
@ -516,9 +500,7 @@ void cancel_network_game() {
|
|||||||
mesg[5] = 0xff;
|
mesg[5] = 0xff;
|
||||||
|
|
||||||
for (i = 1; i < MAXNETNODES; ++i) {
|
for (i = 1; i < MAXNETNODES; ++i) {
|
||||||
if(netnodes[i].used) {
|
if (netnodes[i].used) { putmsg(&netnodes[i].netname, mesg, 6); }
|
||||||
putmsg(&netnodes[i].netname,mesg,6);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -556,10 +538,8 @@ int handle_joins() {
|
|||||||
if (-1 == j) j = i;
|
if (-1 == j) j = i;
|
||||||
continue; /* don't compare with unused host */
|
continue; /* don't compare with unused host */
|
||||||
}
|
}
|
||||||
if(memcmp(&netnodes[i].netname.sin_addr.s_addr,
|
if (memcmp(&netnodes[i].netname.sin_addr.s_addr, &sender.sin_addr.s_addr, 4)) continue;
|
||||||
&sender.sin_addr.s_addr,4)) continue;
|
if (memcmp(&netnodes[i].netname.sin_port, &sender.sin_port, 2)) continue;
|
||||||
if(memcmp(&netnodes[i].netname.sin_port,
|
|
||||||
&sender.sin_port,2)) continue;
|
|
||||||
/* found host */
|
/* found host */
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -580,10 +560,8 @@ int handle_joins() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (i == MAXNETNODES) i = j;
|
if (i == MAXNETNODES) i = j;
|
||||||
memmove(&netnodes[i].netname.sin_addr.s_addr,
|
memmove(&netnodes[i].netname.sin_addr.s_addr, &sender.sin_addr.s_addr, 4);
|
||||||
&sender.sin_addr.s_addr,4);
|
memmove(&netnodes[i].netname.sin_port, &sender.sin_port, 2);
|
||||||
memmove(&netnodes[i].netname.sin_port,
|
|
||||||
&sender.sin_port,2);
|
|
||||||
netnodes[i].netname.sin_family = AF_INET;
|
netnodes[i].netname.sin_family = AF_INET;
|
||||||
netnodes[i].used = 1;
|
netnodes[i].used = 1;
|
||||||
memcpy(netnodes[i].name, mesg + 9, 16);
|
memcpy(netnodes[i].name, mesg + 9, 16);
|
||||||
@ -603,12 +581,14 @@ static int read_inform(unsigned char** pbuf, int *psize) {
|
|||||||
int i;
|
int i;
|
||||||
|
|
||||||
if (size < 1) return 0;
|
if (size < 1) return 0;
|
||||||
myslot = *buf++; size--;
|
myslot = *buf++;
|
||||||
|
size--;
|
||||||
if (0xff == myslot) return 1;
|
if (0xff == myslot) return 1;
|
||||||
|
|
||||||
if (size < 1) return 0;
|
if (size < 1) return 0;
|
||||||
while (0xff != *buf) {
|
while (0xff != *buf) {
|
||||||
i = *buf++; size--;
|
i = *buf++;
|
||||||
|
size--;
|
||||||
if (size < 17 || i >= MAXNETNODES) return 0;
|
if (size < 17 || i >= MAXNETNODES) return 0;
|
||||||
netnodes[i].used = 1;
|
netnodes[i].used = 1;
|
||||||
memcpy(netnodes[i].name, buf, 16);
|
memcpy(netnodes[i].name, buf, 16);
|
||||||
@ -723,7 +703,6 @@ void send_quit() {
|
|||||||
size = getmsg(1000);
|
size = getmsg(1000);
|
||||||
if (size < 6) continue;
|
if (size < 6) continue;
|
||||||
if (mesg[0] != PKT_ACK || mesg[1] != PKT_QUIT) continue;
|
if (mesg[0] != PKT_ACK || mesg[1] != PKT_QUIT) continue;
|
||||||
if (isvalidunique(mesg+2))
|
if (isvalidunique(mesg + 2)) break;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,13 +1,11 @@
|
|||||||
#ifndef NETWORK_H
|
#ifndef NETWORK_H
|
||||||
#define NETWORK_H
|
#define NETWORK_H
|
||||||
|
|
||||||
#include <sys/socket.h>
|
|
||||||
#include <netinet/in.h>
|
|
||||||
#include <arpa/inet.h>
|
#include <arpa/inet.h>
|
||||||
|
#include <netinet/in.h>
|
||||||
|
#include <sys/socket.h>
|
||||||
|
|
||||||
enum {
|
enum { MAXNETNODES = 8 };
|
||||||
MAXNETNODES = 8
|
|
||||||
};
|
|
||||||
|
|
||||||
struct netnode {
|
struct netnode {
|
||||||
struct sockaddr_in netname;
|
struct sockaddr_in netname;
|
||||||
|
62
src/sound.c
62
src/sound.c
@ -1,9 +1,9 @@
|
|||||||
#include <unistd.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <fcntl.h>
|
|
||||||
#include <SDL_audio.h>
|
#include <SDL_audio.h>
|
||||||
#include <SDL_error.h>
|
#include <SDL_error.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
#include "sound.h"
|
#include "sound.h"
|
||||||
|
|
||||||
@ -31,8 +31,7 @@ static const char *soundnames[] = {
|
|||||||
"power2.raw",
|
"power2.raw",
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct sample
|
typedef struct sample {
|
||||||
{
|
|
||||||
char* data;
|
char* data;
|
||||||
int len;
|
int len;
|
||||||
} sample;
|
} sample;
|
||||||
@ -53,23 +52,22 @@ static char soundcommands[MAXSOUNDCOMMANDS];
|
|||||||
static int soundtake, soundput;
|
static int soundtake, soundput;
|
||||||
|
|
||||||
static int sndplaying[MIXMAX], sndposition[MIXMAX];
|
static int sndplaying[MIXMAX], sndposition[MIXMAX];
|
||||||
static void fillaudio(void *udata,Uint8 *buffer,int len)
|
static void fillaudio(void* udata, Uint8* buffer, int len) {
|
||||||
{
|
|
||||||
char com, *p;
|
char com, *p;
|
||||||
int i, j, *ip;
|
int i, j, *ip;
|
||||||
int which;
|
int which;
|
||||||
(void) udata;
|
(void) udata;
|
||||||
|
|
||||||
while(soundtake!=soundput)
|
while (soundtake != soundput) {
|
||||||
{
|
|
||||||
com = soundcommands[soundtake];
|
com = soundcommands[soundtake];
|
||||||
soundtake = (soundtake + 1) & (MAXSOUNDCOMMANDS - 1);
|
soundtake = (soundtake + 1) & (MAXSOUNDCOMMANDS - 1);
|
||||||
if(com==SOUND_QUIET) {memset(sndposition,0,sizeof(sndposition));continue;}
|
if (com == SOUND_QUIET) {
|
||||||
if(com<NUMSOUNDS)
|
memset(sndposition, 0, sizeof(sndposition));
|
||||||
{
|
continue;
|
||||||
|
}
|
||||||
|
if (com < NUMSOUNDS) {
|
||||||
for (i = 0; i < MIXMAX; ++i)
|
for (i = 0; i < MIXMAX; ++i)
|
||||||
if(!sndposition[i])
|
if (!sndposition[i]) {
|
||||||
{
|
|
||||||
sndposition[i] = 1;
|
sndposition[i] = 1;
|
||||||
sndplaying[i] = com;
|
sndplaying[i] = com;
|
||||||
break;
|
break;
|
||||||
@ -77,12 +75,10 @@ int which;
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
memset(soundbuffer, 0, soundbufferlen);
|
memset(soundbuffer, 0, soundbufferlen);
|
||||||
for(i=0;i<MIXMAX;++i)
|
for (i = 0; i < MIXMAX; ++i) {
|
||||||
{
|
|
||||||
if (!sndposition[i]) continue;
|
if (!sndposition[i]) continue;
|
||||||
which = sndplaying[i];
|
which = sndplaying[i];
|
||||||
if(sndposition[i]==samples[which].len)
|
if (sndposition[i] == samples[which].len) {
|
||||||
{
|
|
||||||
sndposition[i] = 0;
|
sndposition[i] = 0;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -94,9 +90,9 @@ int which;
|
|||||||
while (j--) *ip++ += *p++;
|
while (j--) *ip++ += *p++;
|
||||||
}
|
}
|
||||||
j = len;
|
j = len;
|
||||||
ip=soundbuffer;;
|
ip = soundbuffer;
|
||||||
|
;
|
||||||
while (j--) *buffer++ = sndclip[4096 + *ip++];
|
while (j--) *buffer++ = sndclip[4096 + *ip++];
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -120,28 +116,24 @@ int i,j;
|
|||||||
wanted.callback = fillaudio;
|
wanted.callback = fillaudio;
|
||||||
wanted.userdata = 0;
|
wanted.userdata = 0;
|
||||||
|
|
||||||
if(SDL_OpenAudio(&wanted,0)<0)
|
if (SDL_OpenAudio(&wanted, 0) < 0) {
|
||||||
{
|
|
||||||
fprintf(stderr, "Couldn't open audio: %s\n", SDL_GetError());
|
fprintf(stderr, "Couldn't open audio: %s\n", SDL_GetError());
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
soundworking = 1;
|
soundworking = 1;
|
||||||
|
|
||||||
for(i=0;i<8192;i++)
|
for (i = 0; i < 8192; i++) {
|
||||||
{
|
|
||||||
j = i - 4096;
|
j = i - 4096;
|
||||||
sndclip[i] = j > 127 ? 255 : (j < -128 ? 0 : j + 128);
|
sndclip[i] = j > 127 ? 255 : (j < -128 ? 0 : j + 128);
|
||||||
}
|
}
|
||||||
|
|
||||||
for(i=0;i<NUMSOUNDS;++i)
|
for (i = 0; i < NUMSOUNDS; ++i) readsound(i);
|
||||||
readsound(i);
|
|
||||||
|
|
||||||
SDL_PauseAudio(0);
|
SDL_PauseAudio(0);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
void soundclose(void) {
|
void soundclose(void) {
|
||||||
if(soundworking)
|
if (soundworking) {
|
||||||
{
|
|
||||||
SDL_CloseAudio();
|
SDL_CloseAudio();
|
||||||
soundworking = 0;
|
soundworking = 0;
|
||||||
}
|
}
|
||||||
@ -152,17 +144,14 @@ int readsound(int num) {
|
|||||||
char name[256], *p1, *p2, ch;
|
char name[256], *p1, *p2, ch;
|
||||||
int file, size, len;
|
int file, size, len;
|
||||||
p1 = dirlist;
|
p1 = dirlist;
|
||||||
for(;;)
|
for (;;) {
|
||||||
{
|
|
||||||
p2 = name;
|
p2 = name;
|
||||||
while(*p1 && (ch=*p1++)!=',')
|
while (*p1 && (ch = *p1++) != ',') *p2++ = ch;
|
||||||
*p2++=ch;
|
|
||||||
if (p2 > name && p2[-1] != '/') *p2++ = '/';
|
if (p2 > name && p2[-1] != '/') *p2++ = '/';
|
||||||
strcpy(p2, soundnames[num]);
|
strcpy(p2, soundnames[num]);
|
||||||
file = open(name, O_RDONLY);
|
file = open(name, O_RDONLY);
|
||||||
if (file >= 0) break;
|
if (file >= 0) break;
|
||||||
if(!*p1)
|
if (!*p1) {
|
||||||
{
|
|
||||||
samples[num].len = -1;
|
samples[num].len = -1;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -172,8 +161,7 @@ int file,size,len;
|
|||||||
len = samples[num].len = (size + fragment - 1) / fragment;
|
len = samples[num].len = (size + fragment - 1) / fragment;
|
||||||
len *= fragment;
|
len *= fragment;
|
||||||
p1 = samples[num].data = malloc(len);
|
p1 = samples[num].data = malloc(len);
|
||||||
if(p1)
|
if (p1) {
|
||||||
{
|
|
||||||
read(file, p1, size);
|
read(file, p1, size);
|
||||||
if (len - size) memset(p1 + size, 0, len - size);
|
if (len - size) memset(p1 + size, 0, len - size);
|
||||||
while (size--) *p1++ ^= 0x80;
|
while (size--) *p1++ ^= 0x80;
|
||||||
|
39
src/utils.c
39
src/utils.c
@ -1,13 +1,13 @@
|
|||||||
|
|
||||||
#include "bomber.h"
|
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
#include "bomber.h"
|
||||||
#include "gfx.h"
|
#include "gfx.h"
|
||||||
|
|
||||||
#include <arpa/inet.h>
|
#include <arpa/inet.h>
|
||||||
|
|
||||||
#include <sys/types.h>
|
|
||||||
#include <sys/stat.h>
|
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <sys/types.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
int volatile hc = 0;
|
int volatile hc = 0;
|
||||||
@ -35,9 +35,18 @@ static void surf(Uint32 out[8], const Uint32 in[12], const Uint32 seed[32]) {
|
|||||||
for (loop = 0; loop < 2; ++loop) {
|
for (loop = 0; loop < 2; ++loop) {
|
||||||
for (r = 0; r < 16; ++r) {
|
for (r = 0; r < 16; ++r) {
|
||||||
sum += 0x9e3779b9;
|
sum += 0x9e3779b9;
|
||||||
MUSH(0, 5); MUSH(1, 7); MUSH(2, 9); MUSH(3, 13);
|
MUSH(0, 5);
|
||||||
MUSH(4, 5); MUSH(5, 7); MUSH(6, 9); MUSH(7, 13);
|
MUSH(1, 7);
|
||||||
MUSH(8, 5); MUSH(9, 7); MUSH(10, 9); MUSH(11, 13);
|
MUSH(2, 9);
|
||||||
|
MUSH(3, 13);
|
||||||
|
MUSH(4, 5);
|
||||||
|
MUSH(5, 7);
|
||||||
|
MUSH(6, 9);
|
||||||
|
MUSH(7, 13);
|
||||||
|
MUSH(8, 5);
|
||||||
|
MUSH(9, 7);
|
||||||
|
MUSH(10, 9);
|
||||||
|
MUSH(11, 13);
|
||||||
}
|
}
|
||||||
for (i = 0; i < 8; ++i) out[i] ^= t[i + 4];
|
for (i = 0; i < 8; ++i) out[i] ^= t[i + 4];
|
||||||
}
|
}
|
||||||
@ -62,10 +71,14 @@ static Uint32 surf_init(void) {
|
|||||||
if (-1 == fd) {
|
if (-1 == fd) {
|
||||||
Uint32 genseed[4][8];
|
Uint32 genseed[4][8];
|
||||||
surf_seed[0] = surf_seed[1] = gtime();
|
surf_seed[0] = surf_seed[1] = gtime();
|
||||||
surf_in[0]++; surf(genseed[0], surf_in, surf_seed);
|
surf_in[0]++;
|
||||||
surf_in[0]++; surf(genseed[1], surf_in, surf_seed);
|
surf(genseed[0], surf_in, surf_seed);
|
||||||
surf_in[0]++; surf(genseed[2], surf_in, surf_seed);
|
surf_in[0]++;
|
||||||
surf_in[0]++; surf(genseed[3], surf_in, surf_seed);
|
surf(genseed[1], surf_in, surf_seed);
|
||||||
|
surf_in[0]++;
|
||||||
|
surf(genseed[2], surf_in, surf_seed);
|
||||||
|
surf_in[0]++;
|
||||||
|
surf(genseed[3], surf_in, surf_seed);
|
||||||
memcpy(surf_seed, genseed[0], 32);
|
memcpy(surf_seed, genseed[0], 32);
|
||||||
memcpy(surf_seed, genseed[1], 32);
|
memcpy(surf_seed, genseed[1], 32);
|
||||||
memcpy(surf_seed, genseed[2], 32);
|
memcpy(surf_seed, genseed[2], 32);
|
||||||
@ -86,7 +99,8 @@ static Uint32 surf_init(void) {
|
|||||||
static Uint32 surf_random(void) {
|
static Uint32 surf_random(void) {
|
||||||
if (surf_left == 0) {
|
if (surf_left == 0) {
|
||||||
int i;
|
int i;
|
||||||
for (i = 0; (i < 12) && !(++surf_in[i]); i++) ;
|
for (i = 0; (i < 12) && !(++surf_in[i]); i++)
|
||||||
|
;
|
||||||
surf_left = 8;
|
surf_left = 8;
|
||||||
surf(surf_out, surf_in, surf_seed);
|
surf(surf_out, surf_in, surf_seed);
|
||||||
}
|
}
|
||||||
@ -235,6 +249,5 @@ void hexdump(unsigned char *p, int len) {
|
|||||||
else
|
else
|
||||||
fprintf(stderr, "0x%X ", p[i]);
|
fprintf(stderr, "0x%X ", p[i]);
|
||||||
}
|
}
|
||||||
if (i % 16)
|
if (i % 16) fprintf(stderr, "\n");
|
||||||
fprintf(stderr, "\n");
|
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
#ifndef UTILS_H
|
#ifndef UTILS_H
|
||||||
#define UTILS_H
|
#define UTILS_H
|
||||||
|
|
||||||
|
#include <SDL.h>
|
||||||
|
|
||||||
Uint32 gtime(void);
|
Uint32 gtime(void);
|
||||||
Uint32 longtime(void);
|
Uint32 longtime(void);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user