|
|
@ -294,14 +294,18 @@ int networktraffic(void) { |
|
|
|
if (myaction == ACT_QUIT) { |
|
|
|
for (i = 1; i < MAXNETNODES; ++i) { |
|
|
|
if (netnodes[i].used) |
|
|
|
actions[i]=ACT_QUIT; |
|
|
|
actions[i] = ACT_QUIT; |
|
|
|
} |
|
|
|
} else { |
|
|
|
now=gtime(); |
|
|
|
for(;;) { |
|
|
|
if(gtime()-now>15) break; |
|
|
|
length=getmsg(5); |
|
|
|
if(length>0 && *mesg!=PKT_MYDATA) fprintf(stderr, "Strange packet %d\n", (int) *mesg); |
|
|
|
for (i = 1; i < MAXNETNODES; ++i) { |
|
|
|
if (netnodes[i].used) |
|
|
|
actions[i] &= ACT_MASK; /* only keep direction */ |
|
|
|
} |
|
|
|
now = gtime(); |
|
|
|
for (;;) { |
|
|
|
if (gtime() - now > 15) break; |
|
|
|
length = getmsg(5); |
|
|
|
if (length > 0 && *mesg != PKT_MYDATA) fprintf(stderr, "Strange packet %d\n", (int) *mesg); |
|
|
|
/* check for unexpected old packets... |
|
|
|
* for example JOIN on frame 0, respond with BEGIN if player already in game |
|
|
|
* respond with uninvite INVITE on JOIN from others |
|
|
@ -312,7 +316,7 @@ int networktraffic(void) { |
|
|
|
count = readuint32(mesg+5); |
|
|
|
if (count > latestcounts[whosent]) { |
|
|
|
latestcounts[whosent] = count; |
|
|
|
actions[whosent] = mesg[9]; |
|
|
|
actions[whosent] = (actions[whosent] & ~ACT_MASK) | mesg[9]; /* don't drop "action" keys */ |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -322,8 +326,8 @@ int networktraffic(void) { |
|
|
|
for (i = 1; i < MAXNETNODES; ++i) { |
|
|
|
if(netnodes[i].used) { |
|
|
|
sendactions(i); /* send actions to every active node */ |
|
|
|
if (actions[i]==ACT_QUIT) |
|
|
|
netnodes[i].used=0; /* remove disconnected clients */ |
|
|
|
if (actions[i] == ACT_QUIT) |
|
|
|
netnodes[i].used = 0; /* remove disconnected clients */ |
|
|
|
} |
|
|
|
} |
|
|
|
return actioncount; |
|
|
@ -334,7 +338,7 @@ int networktraffic(void) { |
|
|
|
++mydatacount; |
|
|
|
sendmine(mydatacount); |
|
|
|
|
|
|
|
for(;;) { |
|
|
|
for (;;) { |
|
|
|
/* if we got already one packet we only wait 3msec, otherwise 30msec */ |
|
|
|
long cur = gtime(); |
|
|
|
if (count >= 0 && cur - now > 3) break; |
|
|
@ -342,13 +346,13 @@ int networktraffic(void) { |
|
|
|
|
|
|
|
length = getmsg(count >= 0 ? 3 : 20); |
|
|
|
|
|
|
|
if (MAXNETNODES*ACTIONHIST+9 != length) continue; |
|
|
|
if (MAXNETNODES * ACTIONHIST + 9 != length) continue; |
|
|
|
if (!isvalidmsg_from_master()) continue; |
|
|
|
|
|
|
|
i = readuint32(mesg+5); |
|
|
|
i = readuint32(mesg + 5); |
|
|
|
if (i < actioncount) continue; |
|
|
|
count = actioncount = i; |
|
|
|
memcpy(actionblock,mesg+9,MAXNETNODES*ACTIONHIST); |
|
|
|
memcpy(actionblock, mesg + 9, MAXNETNODES * ACTIONHIST); |
|
|
|
} |
|
|
|
return actioncount; |
|
|
|
} |
|
|
|