Commit the first part of patch #901. This ports the ping functions over to the new netcode.
git-svn-id: svn+ssh://svn.gna.org/svn/warzone/trunk@3218 4a71c877-e1ca-e34f-864e-861f7616d084master
parent
6334f1d6d1
commit
919cac4c78
|
@ -726,7 +726,7 @@ BOOL recvMessage(void)
|
||||||
recvDestroyFeature(&msg);
|
recvDestroyFeature(&msg);
|
||||||
break;
|
break;
|
||||||
case NET_PING: // diagnostic ping msg.
|
case NET_PING: // diagnostic ping msg.
|
||||||
recvPing(&msg);
|
recvPing();
|
||||||
break;
|
break;
|
||||||
case NET_DEMOLISH: // structure demolished.
|
case NET_DEMOLISH: // structure demolished.
|
||||||
recvDemolishFinished();
|
recvDemolishFinished();
|
||||||
|
|
|
@ -40,7 +40,7 @@ extern BOOL recvBuildFinished ();
|
||||||
extern BOOL recvTemplate (NETMSG *pMsg);
|
extern BOOL recvTemplate (NETMSG *pMsg);
|
||||||
extern BOOL recvDestroyFeature (NETMSG *pMsg);
|
extern BOOL recvDestroyFeature (NETMSG *pMsg);
|
||||||
extern BOOL recvDemolishFinished ();
|
extern BOOL recvDemolishFinished ();
|
||||||
extern BOOL recvPing (NETMSG *pMsg);
|
extern BOOL recvPing ();
|
||||||
extern BOOL recvRequestDroid (NETMSG *pMsg);
|
extern BOOL recvRequestDroid (NETMSG *pMsg);
|
||||||
extern BOOL recvTextMessage (NETMSG *pMsg);
|
extern BOOL recvTextMessage (NETMSG *pMsg);
|
||||||
extern BOOL recvDroidSecondary (NETMSG *pMsg);
|
extern BOOL recvDroidSecondary (NETMSG *pMsg);
|
||||||
|
|
110
src/multisync.c
110
src/multisync.c
|
@ -1070,77 +1070,109 @@ UDWORD averagePing(void)
|
||||||
|
|
||||||
BOOL sendPing(void)
|
BOOL sendPing(void)
|
||||||
{
|
{
|
||||||
NETMSG ping;
|
BOOL new = TRUE;
|
||||||
UDWORD i;
|
uint8_t player = selectedPlayer;
|
||||||
static UDWORD lastPing=0; // last time we sent a ping.
|
int i;
|
||||||
static UDWORD lastav=0; // last time we updated average.
|
static UDWORD lastPing = 0; // Last time we sent a ping
|
||||||
|
static UDWORD lastav = 0; // Last time we updated average
|
||||||
|
|
||||||
// only ping every so often.
|
// Only ping every so often
|
||||||
if(lastPing > gameTime)lastPing= 0;
|
if (lastPing > gameTime)
|
||||||
if((gameTime-lastPing) < PING_FREQUENCY)
|
{
|
||||||
|
lastPing = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (gameTime - lastPing < PING_FREQUENCY)
|
||||||
{
|
{
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
lastPing = gameTime;
|
lastPing = gameTime;
|
||||||
|
|
||||||
|
|
||||||
/// if host, also update the average ping stat for joiners.
|
// If host, also update the average ping stat for joiners
|
||||||
if(NetPlay.bHost)
|
if (NetPlay.bHost)
|
||||||
{
|
{
|
||||||
if(lastav > gameTime)lastav= 0;
|
if (lastav > gameTime)
|
||||||
if((gameTime-lastav) > AV_PING_FREQUENCY)
|
|
||||||
{
|
{
|
||||||
NETsetGameFlags(2,averagePing());
|
lastav = 0;
|
||||||
lastav=gameTime;
|
}
|
||||||
|
|
||||||
|
if (gameTime - lastav > AV_PING_FREQUENCY)
|
||||||
|
{
|
||||||
|
NETsetGameFlags(2, averagePing());
|
||||||
|
lastav = gameTime;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// before we send the ping, if any player failed to respond to the last one
|
/*
|
||||||
// we should re-enumerate the players.
|
* Before we send the ping, if any player failed to respond to the last one
|
||||||
|
* we should re-enumerate the players.
|
||||||
|
*/
|
||||||
|
|
||||||
for (i=0; i<MAX_PLAYERS;i++)
|
for (i = 0; i < MAX_PLAYERS; i++)
|
||||||
{
|
{
|
||||||
if( isHumanPlayer(i) && PingSend[i] && ingame.PingTimes[i] && (i!= selectedPlayer) )
|
if (isHumanPlayer(i)
|
||||||
|
&& PingSend[i]
|
||||||
|
&& ingame.PingTimes[i]
|
||||||
|
&& i != selectedPlayer)
|
||||||
{
|
{
|
||||||
// CONPRINTF(ConsoleString,(ConsoleString,_("%s is Not Respoding"),getPlayerName(i) ));
|
|
||||||
ingame.PingTimes[i] = PING_LIMIT;
|
ingame.PingTimes[i] = PING_LIMIT;
|
||||||
}
|
}
|
||||||
else if( !isHumanPlayer(i) && PingSend[i] && ingame.PingTimes[i] && (i!= selectedPlayer) )
|
else if (!isHumanPlayer(i)
|
||||||
|
&& PingSend[i]
|
||||||
|
&& ingame.PingTimes[i]
|
||||||
|
&& i != selectedPlayer)
|
||||||
{
|
{
|
||||||
ingame.PingTimes[i] = 0;
|
ingame.PingTimes[i] = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ping.body[0] = (char)selectedPlayer;
|
NETbeginEncode(NET_PING, NET_ALL_PLAYERS);
|
||||||
ping.body[1] = 1;
|
NETuint8_t(&player);
|
||||||
ping.size = 2;
|
NETbool(&new);
|
||||||
ping.type = NET_PING;
|
NETend();
|
||||||
|
|
||||||
for(i=0;i<MAX_PLAYERS;i++)
|
// Note when we sent the ping
|
||||||
|
for (i = 0; i < MAX_PLAYERS; i++)
|
||||||
{
|
{
|
||||||
PingSend[i] = gameTime2;//clock();
|
PingSend[i] = gameTime2;
|
||||||
}
|
}
|
||||||
return(NETbcast(&ping,FALSE));
|
|
||||||
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
// accept and process incoming ping messages.
|
// accept and process incoming ping messages.
|
||||||
BOOL recvPing(NETMSG *ping)
|
BOOL recvPing()
|
||||||
{
|
{
|
||||||
NETMSG reply;
|
BOOL new;
|
||||||
|
uint8_t sender, us = selectedPlayer;
|
||||||
|
|
||||||
if (ping->body[1] ==1) // if this is a new ping
|
NETbeginDecode();
|
||||||
{
|
NETuint8_t(&sender);
|
||||||
reply.body[0] = (char) selectedPlayer;
|
NETbool(&new);
|
||||||
reply.body[1] = 0;
|
NETend();
|
||||||
reply.size = 2;
|
|
||||||
reply.type = NET_PING;
|
|
||||||
|
|
||||||
NETsend(&reply, player2dpid[(int) ping->body[0]], FALSE); // reply to it
|
// If this is a new ping, respond to it
|
||||||
}
|
if (new)
|
||||||
else // else it's returned, so store it.
|
|
||||||
{
|
{
|
||||||
ingame.PingTimes[(int) ping->body[0]] = (gameTime2 - PingSend[(int) ping->body[0]] ) /2 ;
|
NETbeginEncode(NET_PING, player2dpid[sender]);
|
||||||
PingSend[(int) ping->body[0]] = 0; // note we've recvd it!
|
// We are responding to a new ping
|
||||||
|
new = FALSE;
|
||||||
|
|
||||||
|
NETuint8_t(&us);
|
||||||
|
NETbool(&new);
|
||||||
|
NETend();
|
||||||
}
|
}
|
||||||
|
// They are responding to one of our pings
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Work out how long it took them to respond
|
||||||
|
ingame.PingTimes[sender] = (gameTime2 = PingSend[sender]) / 2;
|
||||||
|
|
||||||
|
// Note that we have received it
|
||||||
|
PingSend[sender] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue