More fixes for network code (slaves don't block anymore)
This commit is contained in:
parent
36a55544f9
commit
9b60fa91f0
7
game.c
7
game.c
@ -858,7 +858,7 @@ static int iterate(void) {
|
|||||||
if (NETWORK_NONE != network) {
|
if (NETWORK_NONE != network) {
|
||||||
i = gountil - mycount;
|
i = gountil - mycount;
|
||||||
if(i >= ACTIONHIST) // too far behind
|
if(i >= ACTIONHIST) // too far behind
|
||||||
return CODE_QUIT;
|
goto leave_game;
|
||||||
memcpy(actions, actionblock+i*MAXNETNODES, MAXNETNODES);
|
memcpy(actions, actionblock+i*MAXNETNODES, MAXNETNODES);
|
||||||
if (actions[myslot] == ACT_QUIT) return CODE_QUIT;
|
if (actions[myslot] == ACT_QUIT) return CODE_QUIT;
|
||||||
}
|
}
|
||||||
@ -907,6 +907,11 @@ static int iterate(void) {
|
|||||||
deathcount=0;
|
deathcount=0;
|
||||||
}
|
}
|
||||||
return CODE_CONT;
|
return CODE_CONT;
|
||||||
|
|
||||||
|
leave_game: /* client disconnect/timeout: send ACT_QUIT to master */
|
||||||
|
myaction = ACT_QUIT;
|
||||||
|
networktraffic();
|
||||||
|
return CODE_QUIT;
|
||||||
}
|
}
|
||||||
|
|
||||||
void set_game_options(GameOptions *options) {
|
void set_game_options(GameOptions *options) {
|
||||||
|
72
network.c
72
network.c
@ -291,14 +291,21 @@ int networktraffic(void) {
|
|||||||
case NETWORK_MASTER:
|
case NETWORK_MASTER:
|
||||||
memcpy(actions,latestactions,MAXNETNODES);
|
memcpy(actions,latestactions,MAXNETNODES);
|
||||||
actions[0]=myaction;
|
actions[0]=myaction;
|
||||||
|
if (myaction == ACT_QUIT) {
|
||||||
|
for (i = 1; i < MAXNETNODES; ++i) {
|
||||||
|
if (netnodes[i].used)
|
||||||
|
actions[i]=ACT_QUIT;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
now=gtime();
|
now=gtime();
|
||||||
for(;;) {
|
for(;;) {
|
||||||
if(gtime()-now>15) break;
|
if(gtime()-now>15) break;
|
||||||
length=getmsg(5);
|
length=getmsg(5);
|
||||||
if(length>0 && *mesg!=PKT_MYDATA) fprintf(stderr, "Strange packet %d\n", (int) *mesg);
|
if(length>0 && *mesg!=PKT_MYDATA) fprintf(stderr, "Strange packet %d\n", (int) *mesg);
|
||||||
// check for unexpected old packets...
|
/* check for unexpected old packets...
|
||||||
// for example JOIN on frame 0, respond with BEGIN if player already in game
|
* for example JOIN on frame 0, respond with BEGIN if player already in game
|
||||||
// respond with uninvite INVITE on JOIN from others
|
* respond with uninvite INVITE on JOIN from others
|
||||||
|
*/
|
||||||
if (length < 10) continue;
|
if (length < 10) continue;
|
||||||
whosent = isvalidmsg_from_slave();
|
whosent = isvalidmsg_from_slave();
|
||||||
if (whosent <= 0) continue;
|
if (whosent <= 0) continue;
|
||||||
@ -308,49 +315,42 @@ int networktraffic(void) {
|
|||||||
actions[whosent] = mesg[9];
|
actions[whosent] = mesg[9];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(myaction==ACT_QUIT) {
|
|
||||||
for(i=1;i<MAXNETNODES;++i)
|
|
||||||
if(netnodes[i].used)
|
|
||||||
actions[i]=ACT_QUIT;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
addactions();
|
addactions(); /* update action history block */
|
||||||
for(i=1;i<MAXNETNODES;++i)
|
|
||||||
if(netnodes[i].used)
|
for (i = 1; i < MAXNETNODES; ++i) {
|
||||||
sendactions(i);
|
if(netnodes[i].used) {
|
||||||
for(i=1;i<MAXNETNODES;++i)
|
sendactions(i); /* send actions to every active node */
|
||||||
if(netnodes[i].used && actions[i]==ACT_QUIT)
|
if (actions[i]==ACT_QUIT)
|
||||||
netnodes[i].used=0;
|
netnodes[i].used=0; /* remove disconnected clients */
|
||||||
|
}
|
||||||
|
}
|
||||||
return actioncount;
|
return actioncount;
|
||||||
case NETWORK_SLAVE:
|
case NETWORK_SLAVE:
|
||||||
{
|
count = -1; /* set to actioncount if we got at least one packet */
|
||||||
long latest=-1;
|
now = gtime();
|
||||||
long lastsent;
|
|
||||||
|
|
||||||
lastsent=now=gtime();
|
|
||||||
++mydatacount;
|
++mydatacount;
|
||||||
sendmine(mydatacount);
|
sendmine(mydatacount);
|
||||||
|
|
||||||
for(;;) {
|
for(;;) {
|
||||||
/*
|
/* if we got already one packet we only wait 3msec, otherwise 30msec */
|
||||||
if(gtime()-lastsent>=1)
|
long cur = gtime();
|
||||||
{
|
if (count >= 0 && cur - now > 3) break;
|
||||||
lastsent=gtime();
|
if (exitflag || cur - now > 30) break;
|
||||||
sendmine(mydatacount);
|
|
||||||
}
|
length = getmsg(count >= 0 ? 3 : 20);
|
||||||
*/
|
|
||||||
if(latest>=0 && gtime()-now>3) break;
|
if (MAXNETNODES*ACTIONHIST+9 != length) continue;
|
||||||
length=getmsg(3);
|
if (!isvalidmsg_from_master()) continue;
|
||||||
if(length==MAXNETNODES*ACTIONHIST+9 &&
|
|
||||||
sender.sin_addr.s_addr==mastername.sin_addr.s_addr &&
|
|
||||||
sender.sin_port==mastername.sin_port) {
|
|
||||||
i = readuint32(mesg+5);
|
i = readuint32(mesg+5);
|
||||||
if(i<latest) continue;
|
if (i < actioncount) continue;
|
||||||
latest=i;
|
count = actioncount = i;
|
||||||
memmove(actionblock,mesg+9,MAXNETNODES*ACTIONHIST);
|
memcpy(actionblock,mesg+9,MAXNETNODES*ACTIONHIST);
|
||||||
}
|
|
||||||
}
|
|
||||||
return latest;
|
|
||||||
}
|
}
|
||||||
|
return actioncount;
|
||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user