#ifdef CONFIG_MENU
static cvar_t net_slist_debug = {CF_CLIENT, "net_slist_debug", "0", "enables verbose messages for master server queries"};
static cvar_t net_slist_favorites = {CF_CLIENT | CF_ARCHIVE, "net_slist_favorites", "", "contains a list of IP addresses and ports to always query explicitly"};
-static cvar_t net_slist_interval = {CF_CLIENT, "net_slist_interval", "1.125", "minimum number of seconds to wait between getstatus queries to the same DP server, must be >= server's net_getstatusfloodblockingtimeout"};
+static cvar_t net_slist_interval = {CF_CLIENT, "net_slist_interval", "1", "minimum number of seconds to wait between getstatus queries to the same DP server, must be >= server's net_getstatusfloodblockingtimeout"};
static cvar_t net_slist_maxping = {CF_CLIENT | CF_ARCHIVE, "net_slist_maxping", "420", "server query responses are ignored if their ping in milliseconds is higher than this"};
static cvar_t net_slist_maxtries = {CF_CLIENT, "net_slist_maxtries", "3", "how many times to ask the same server for information (more times gives better ping reports but takes longer)"};
static cvar_t net_slist_pause = {CF_CLIENT, "net_slist_pause", "0", "when set to 1, the server list sorting in the menu won't update until it is set back to 0"};
{
serverlist_entry_t *entry = &serverlist_cache[i];
entry->responded = false;
- entry->querycounter = 0;
}
}
serverlist_consoleoutput = consoleoutput;
static void NetConn_ConnectionEstablished(lhnetsocket_t *mysocket, lhnetaddress_t *peeraddress, protocolversion_t initialprotocol)
{
crypto_t *crypto;
+
cls.connect_trying = false;
-#ifdef CONFIG_MENU
- M_Update_Return_Reason("");
-#endif
// Disconnect from the current server or stop demo playback
if(cls.state == ca_connected || cls.demoplayback)
CL_Disconnect();
// allocate a net connection to keep track of things
cls.netcon = NetConn_Open(mysocket, peeraddress);
+ strlcpy(cl_connect_status, "Connection established", sizeof(cl_connect_status));
crypto = &cls.netcon->crypto;
if(cls.crypto.authenticated)
{
crypto_keyfp_recommended_length, crypto->client_keyfp[0] ? crypto->client_keyfp : "-"
);
}
- Con_Printf("Connection accepted to %s\n", cls.netcon->address);
+ else
+ Con_Printf("%s to %s\n", cl_connect_status, cls.netcon->address);
+
key_dest = key_game;
#ifdef CONFIG_MENU
m_state = m_none;
memset(entry, 0, sizeof(*entry));
strlcpy(entry->info.cname, addressstring, sizeof(entry->info.cname));
- // consider the broadcast to be the first query
- // NetConn_QueryQueueFrame() will perform more until net_slist_maxtries is reached
- entry->querycounter = 1;
+ // use the broadcast as the first query, NetConn_QueryQueueFrame() will send more
entry->querytime = masterquerytime;
// protocol is one of these at all
// NetConn_ClientParsePacket_ServerList_PrepareQuery() callsites
}
sendlength = sizeof(senddata) - 4;
- switch(Crypto_ClientParsePacket(string, length, senddata+4, &sendlength, peeraddress))
+ switch(Crypto_ClientParsePacket(string, length, senddata+4, &sendlength, peeraddress, addressstring2))
{
case CRYPTO_NOMATCH:
// nothing to do
{
// darkplaces or quake3
char protocolnames[1400];
- Con_DPrintf("\"%s\" received, sending connect request back to %s\n", string, addressstring2);
+
if (net_sourceaddresscheck.integer && LHNETADDRESS_Compare(peeraddress, &cls.connect_address)) {
- Con_DPrintf("challenge message from wrong server %s\n", addressstring2);
+ Con_Printf(CON_WARN "ignoring challenge message from wrong server %s\n", addressstring2);
return true;
}
+ Con_DPrintf("\"%s\" received, sending connect request back to %s\n", string, addressstring2);
+ strlcpy(cl_connect_status, "Connect: replying to challenge...", sizeof(cl_connect_status));
+
Protocol_Names(protocolnames, sizeof(protocolnames));
-#ifdef CONFIG_MENU
- M_Update_Return_Reason("Got challenge response");
-#endif
// update the server IP in the userinfo (QW servers expect this, and it is used by the reconnect command)
InfoString_SetValue(cls.userinfo, sizeof(cls.userinfo), "*ip", addressstring2);
// TODO: add userinfo stuff here instead of using NQ commands?
{
// darkplaces or quake3
if (net_sourceaddresscheck.integer && LHNETADDRESS_Compare(peeraddress, &cls.connect_address)) {
- Con_DPrintf("accept message from wrong server %s\n", addressstring2);
+ Con_Printf(CON_WARN "ignoring accept message from wrong server %s\n", addressstring2);
return true;
}
-#ifdef CONFIG_MENU
- M_Update_Return_Reason("Accepted");
-#endif
NetConn_ConnectionEstablished(mysocket, peeraddress, PROTOCOL_DARKPLACES3);
return true;
}
if (length > 7 && !memcmp(string, "reject ", 7) && cls.connect_trying)
{
- char rejectreason[128];
if (net_sourceaddresscheck.integer && LHNETADDRESS_Compare(peeraddress, &cls.connect_address)) {
- Con_DPrintf("reject message from wrong server %s\n", addressstring2);
+ Con_Printf(CON_WARN "ignoring reject message from wrong server %s\n", addressstring2);
return true;
}
cls.connect_trying = false;
string += 7;
- length = min(length - 7, (int)sizeof(rejectreason) - 1);
- memcpy(rejectreason, string, length);
- rejectreason[length] = 0;
-#ifdef CONFIG_MENU
- M_Update_Return_Reason(rejectreason);
-#endif
+ length = min(length - 7, (int)sizeof(cl_connect_status) - 1);
+ dpsnprintf(cl_connect_status, sizeof(cl_connect_status), "Connect: rejected, %.*s", length, string);
+ Con_Printf(CON_ERROR "Connect: rejected by %s\n" CON_ERROR "%.*s\n", addressstring2, length, string);
return true;
}
#ifdef CONFIG_MENU
{
// challenge message
if (net_sourceaddresscheck.integer && LHNETADDRESS_Compare(peeraddress, &cls.connect_address)) {
- Con_DPrintf("c message from wrong server %s\n", addressstring2);
+ Con_Printf(CON_WARN "ignoring c message from wrong server %s\n", addressstring2);
return true;
}
- Con_Printf("challenge %s received, sending QuakeWorld connect request back to %s\n", string + 1, addressstring2);
-#ifdef CONFIG_MENU
- M_Update_Return_Reason("Got QuakeWorld challenge response");
-#endif
+ Con_DPrintf("challenge %s received, sending QuakeWorld connect request back to %s\n", string + 1, addressstring2);
+ strlcpy(cl_connect_status, "Connect: replying to challenge...", sizeof(cl_connect_status));
+
cls.qw_qport = qport.integer;
// update the server IP in the userinfo (QW servers expect this, and it is used by the reconnect command)
InfoString_SetValue(cls.userinfo, sizeof(cls.userinfo), "*ip", addressstring2);
{
// accept message
if (net_sourceaddresscheck.integer && LHNETADDRESS_Compare(peeraddress, &cls.connect_address)) {
- Con_DPrintf("j message from wrong server %s\n", addressstring2);
+ Con_Printf(CON_WARN "ignoring j message from wrong server %s\n", addressstring2);
return true;
}
-#ifdef CONFIG_MENU
- M_Update_Return_Reason("QuakeWorld Accepted");
-#endif
NetConn_ConnectionEstablished(mysocket, peeraddress, PROTOCOL_QUAKEWORLD);
return true;
}
{
// qw print command, used by rcon replies too
if (net_sourceaddresscheck.integer && LHNETADDRESS_Compare(peeraddress, &cls.connect_address) && LHNETADDRESS_Compare(peeraddress, &cls.rcon_address)) {
- Con_DPrintf("n message from wrong server %s\n", addressstring2);
+ Con_Printf(CON_WARN "ignoring n message from wrong server %s\n", addressstring2);
return true;
}
Con_Printf("QW print command from server at %s:\n%s\n", addressstring2, string + 1);
{
lhnetaddress_t clientportaddress;
if (net_sourceaddresscheck.integer && LHNETADDRESS_Compare(peeraddress, &cls.connect_address)) {
- Con_DPrintf("CCREP_ACCEPT message from wrong server %s\n", addressstring2);
+ Con_Printf(CON_WARN "ignoring CCREP_ACCEPT message from wrong server %s\n", addressstring2);
break;
}
clientportaddress = *peeraddress;
Con_Printf("Connected to ProQuake %.1f server, enabling precise aim\n", cls.proquake_serverversion / 10.0f);
// update the server IP in the userinfo (QW servers expect this, and it is used by the reconnect command)
InfoString_SetValue(cls.userinfo, sizeof(cls.userinfo), "*ip", addressstring2);
-#ifdef CONFIG_MENU
- M_Update_Return_Reason("Accepted");
-#endif
NetConn_ConnectionEstablished(mysocket, &clientportaddress, PROTOCOL_QUAKE);
}
break;
case CCREP_REJECT:
- if (developer_extra.integer) {
- Con_DPrintf("CCREP_REJECT message from wrong server %s\n", addressstring2);
- break;
- }
if (net_sourceaddresscheck.integer && LHNETADDRESS_Compare(peeraddress, &cls.connect_address))
+ {
+ Con_Printf(CON_WARN "ignoring CCREP_REJECT message from wrong server %s\n", addressstring2);
break;
+ }
cls.connect_trying = false;
-#ifdef CONFIG_MENU
- M_Update_Return_Reason((char *)MSG_ReadString(&cl_message, cl_readstring, sizeof(cl_readstring)));
-#endif
+ dpsnprintf(cl_connect_status, sizeof(cl_connect_status), "Connect: rejected, %s", MSG_ReadString(&cl_message, cl_readstring, sizeof(cl_readstring)));
+ Con_Printf(CON_ERROR "Connect: rejected by %s\n%s\n", addressstring2, MSG_ReadString(&cl_message, cl_readstring, sizeof(cl_readstring)));
break;
case CCREP_SERVER_INFO:
if (developer_extra.integer)
break;
case CCREP_RCON: // RocketGuy: ProQuake rcon support
if (net_sourceaddresscheck.integer && LHNETADDRESS_Compare(peeraddress, &cls.rcon_address)) {
- Con_DPrintf("CCREP_RCON message from wrong server %s\n", addressstring2);
+ Con_Printf(CON_WARN "ignoring CCREP_RCON message from wrong server %s\n", addressstring2);
break;
}
if (developer_extra.integer)
void NetConn_QueryQueueFrame(void)
{
unsigned index;
- unsigned queries, maxqueries;
+ unsigned maxqueries;
char dpquery[53]; // theoretical max: 14+22+16+1
double currentrealtime;
static double querycounter = 0;
- qbool pending = false;
+ static unsigned pass = 0, server = 0;
+ unsigned queriesperserver = bound(1, net_slist_maxtries.integer, 8);
if (!serverlist_querystage)
return;
if (maxqueries == 0)
return;
- // QW depends on waiting "long enough" between queries that responses "definitely" refer to the most recent querytime
- // DP servers can echo back a timestamp for reliable (and more frequent, see net_slist_interval) pings
- ServerList_BuildDPServerQuery(dpquery, sizeof(dpquery), currentrealtime);
-
- for (index = 0, queries = 0; index < serverlist_cachecount && queries < maxqueries; ++index)
+ if (pass < queriesperserver)
{
- serverlist_entry_t *entry = &serverlist_cache[index];
+ // QW depends on waiting "long enough" between queries that responses "definitely" refer to the most recent querytime
+ // DP servers can echo back a timestamp for reliable (and more frequent, see net_slist_interval) pings
+ ServerList_BuildDPServerQuery(dpquery, sizeof(dpquery), currentrealtime);
- if (entry->querycounter < min(8, (unsigned)net_slist_maxtries.integer))
+ for (unsigned queries = 0; server < serverlist_cachecount; ++server)
{
lhnetaddress_t address;
unsigned socket;
+ serverlist_entry_t *entry = &serverlist_cache[server];
- // only check this when there are tries remaining so we finish querying sooner
- if (currentrealtime < entry->querytime + (entry->protocol == PROTOCOL_QUAKEWORLD ? net_slist_timeout : net_slist_interval).value)
- {
- pending = true;
- continue;
- }
+ if (queries >= maxqueries
+ || currentrealtime <= entry->querytime + (entry->protocol == PROTOCOL_QUAKEWORLD ? net_slist_timeout : net_slist_interval).value)
+ return; // continue this pass at the current server on a later frame
LHNETADDRESS_FromString(&address, entry->info.cname, 0);
if (entry->protocol == PROTOCOL_QUAKEWORLD)
}
entry->querytime = currentrealtime;
- entry->querycounter++;
queries++;
if (serverlist_consoleoutput)
- Con_Printf("querying %25s (%i. try)\n", entry->info.cname, entry->querycounter);
+ Con_Printf("querying %25s (%i. try)\n", entry->info.cname, pass + 1);
}
- else // reached net_slist_maxtries
- if (!entry->responded // no acceptable response during this refresh cycle
- && (entry->info.ping)) // visible in the list (has old ping from previous refresh cycle)
+ }
+ else
+ {
+ // check timeouts
+ for (; server < serverlist_cachecount; ++server)
{
- if (currentrealtime >= entry->querytime + net_slist_maxping.integer/1000)
+ serverlist_entry_t *entry = &serverlist_cache[server];
+
+ if (!entry->responded // no acceptable response during this refresh cycle
+ && entry->info.ping) // visible in the list (has old ping from previous refresh cycle)
{
- // you have no chance to survive make your timeout
- serverreplycount--;
- if(!net_slist_pause.integer)
- ServerList_ViewList_Remove(entry);
- entry->info.ping = 0; // removed later if net_slist_pause
+ if (currentrealtime > entry->querytime + net_slist_maxping.integer/1000)
+ {
+ // you have no chance to survive make your timeout
+ serverreplycount--;
+ if(!net_slist_pause.integer)
+ ServerList_ViewList_Remove(entry);
+ entry->info.ping = 0; // removed later if net_slist_pause
+ }
+ else // still has time
+ return; // continue this pass at the current server on a later frame
}
- else // still has time
- pending = true;
}
}
- // If we got to the end of the list (didn't hit maxqueries)
- // and no servers remain to be queried or checked for timeout,
- // there's nothing else to do here until the next refresh cycle.
- if (index >= serverlist_cachecount && !pending)
+ // We finished the pass, ie didn't stop at maxqueries
+ // or a server that can't be (re)queried or timed out yet.
+ ++pass;
+ server = 0;
+
+ if (pass == queriesperserver)
{
+ // timeout pass begins next frame
if (net_slist_debug.integer)
Con_Printf("^2Finished querying masters and servers in %f\n", currentrealtime - masterquerytime);
+ }
+ else if (pass > queriesperserver)
+ {
+ // Nothing else to do until the next refresh cycle.
+ if (net_slist_debug.integer)
+ Con_Printf("^4Finished checking server timeouts in %f\n", currentrealtime - serverlist_cache[serverlist_cachecount - 1].querytime);
serverlist_querystage = 0;
+ pass = 0;
}
}
#endif
unsigned char readbuffer[NET_HEADERSIZE+NET_MAXMESSAGE];
NetConn_UpdateSockets();
+
if (cls.connect_trying && cls.connect_nextsendtime < host.realtime)
{
-#ifdef CONFIG_MENU
- if (cls.connect_remainingtries == 0)
- M_Update_Return_Reason("Connect: Waiting 10 seconds for reply");
-#endif
- cls.connect_nextsendtime = host.realtime + 1;
- cls.connect_remainingtries--;
- if (cls.connect_remainingtries <= -10)
+ if (cls.connect_remainingtries > 0)
{
+ cls.connect_remainingtries--;
+ dpsnprintf(cl_connect_status, sizeof(cl_connect_status), "Connect: sending initial request, %i %s left...", cls.connect_remainingtries, cls.connect_remainingtries == 1 ? "retry" : "retries");
+ }
+ else
+ {
+ char address[128];
+
cls.connect_trying = false;
-#ifdef CONFIG_MENU
- M_Update_Return_Reason("Connect: Failed");
-#endif
+ LHNETADDRESS_ToString(&cls.connect_address, address, sizeof(address), true);
+ strlcpy(cl_connect_status, "Connect: failed, no reply", sizeof(cl_connect_status));
+ Con_Printf(CON_ERROR "%s from %s\n", cl_connect_status, address);
return;
}
+ cls.connect_nextsendtime = host.realtime + 1;
+
// try challenge first (newer DP server or QW)
NetConn_WriteString(cls.connect_mysocket, "\377\377\377\377getchallenge", &cls.connect_address);
// then try netquake as a fallback (old server, or netquake)
NetConn_Write(cls.connect_mysocket, cl_message.data, cl_message.cursize, &cls.connect_address);
SZ_Clear(&cl_message);
}
+
for (i = 0;i < cl_numsockets;i++)
{
while (cl_sockets[i] && (length = NetConn_Read(cl_sockets[i], readbuffer, sizeof(readbuffer), &peeraddress)) > 0)
if(l)
{
client_t *host_client_save = host_client;
- Cmd_ExecuteString(cmd_local, s, src_local, true);
+ //Cmd_ExecuteString(cmd_local, s, src_local, true); // no variable expansion
+ // bones_was_here: prepending allows a loop such as `alias foo "bar; wait; foo"; foo`
+ // to be broken with an alias or unalias command
+ Cbuf_InsertText(cmd_local, s);
host_client = host_client_save;
// in case it is a command that changes host_client (like restart)
}
NetConn_ServerParsePacket(sv_sockets[i], readbuffer, length, &peeraddress);
}
-void NetConn_SleepMicroseconds(int microseconds)
-{
- LHNET_SleepUntilPacket_Microseconds(microseconds);
-}
-
#ifdef CONFIG_MENU
void NetConn_QueryMasters(qbool querydp, qbool queryqw)
{
if (!masterquerycount)
{
Con_Print(CON_ERROR "Unable to query master servers, no suitable network sockets active.\n");
- M_Update_Return_Reason("No network");
+ strlcpy(cl_connect_status, "No network", sizeof(cl_connect_status));
}
}
#endif