X-Git-Url: http://git.xonotic.org/?a=blobdiff_plain;f=netconn.c;h=09a8ab3da60a176a60c72e3db8e7eb1ede9b8b0a;hb=0a05c446ba26bd5897645a37ceec8646c5bc93eb;hp=a2b259b69a417c317013847a4f55691b6cd447a4;hpb=a51a70c2254b27a68e5fe74cc5985b02dc36e1e9;p=xonotic%2Fdarkplaces.git diff --git a/netconn.c b/netconn.c index a2b259b6..09a8ab3d 100755 --- a/netconn.c +++ b/netconn.c @@ -93,7 +93,7 @@ static cvar_t net_slist_queriesperframe = {CVAR_CLIENT, "net_slist_queriesperfra static cvar_t net_slist_timeout = {CVAR_CLIENT, "net_slist_timeout", "4", "how long to listen for a server information response before giving up"}; static cvar_t net_slist_pause = {CVAR_CLIENT, "net_slist_pause", "0", "when set to 1, the server list won't update until it is set back to 0"}; static cvar_t net_slist_maxtries = {CVAR_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_favorites = {CVAR_CLIENT | CVAR_SAVE | CVAR_NQUSERINFOHACK, "net_slist_favorites", "", "contains a list of IP addresses and ports to always query explicitly"}; +static cvar_t net_slist_favorites = {CVAR_CLIENT | CVAR_SAVE, "net_slist_favorites", "", "contains a list of IP addresses and ports to always query explicitly"}; static cvar_t net_tos_dscp = {CVAR_CLIENT | CVAR_SAVE, "net_tos_dscp", "32", "DiffServ Codepoint for network sockets (may need game restart to apply)"}; static cvar_t gameversion = {CVAR_SERVER, "gameversion", "0", "version of game data (mod-specific) to be sent to querying clients"}; static cvar_t gameversion_min = {CVAR_CLIENT | CVAR_SERVER, "gameversion_min", "-1", "minimum version of game data (mod-specific), when client and server gameversion mismatch in the server browser the server is shown as incompatible; if -1, gameversion is used alone"}; @@ -114,8 +114,8 @@ challenge_t challenges[MAX_CHALLENGES]; #ifdef CONFIG_MENU /// this is only false if there are still servers left to query -static qboolean serverlist_querysleep = true; -static qboolean serverlist_paused = false; +static qbool serverlist_querysleep = true; +static qbool serverlist_paused = false; /// this is pushed a second or two ahead of realtime whenever a master server /// reply is received, to avoid issuing queries while master replies are still /// flooding in (which would make a mess of the ping times) @@ -159,19 +159,19 @@ int serverlist_maxcachecount = 0; int serverlist_cachecount = 0; serverlist_entry_t *serverlist_cache = NULL; -qboolean serverlist_consoleoutput; +qbool serverlist_consoleoutput; static int nFavorites = 0; static lhnetaddress_t favorites[MAX_FAVORITESERVERS]; static int nFavorites_idfp = 0; static char favorites_idfp[MAX_FAVORITESERVERS][FP64_SIZE+1]; -void NetConn_UpdateFavorites(void) +void NetConn_UpdateFavorites_c(cvar_t *var) { const char *p; nFavorites = 0; nFavorites_idfp = 0; - p = net_slist_favorites.string; + p = var->string; while((size_t) nFavorites < sizeof(favorites) / sizeof(*favorites) && COM_ParseToken_Console(&p)) { if(com_token[0] != '[' && strlen(com_token) == FP64_SIZE && !strchr(com_token, '.')) @@ -215,7 +215,7 @@ static void _ServerList_ViewList_Helper_Remove( int index ) } /// \returns true if A should be inserted before B -static qboolean _ServerList_Entry_Compare( serverlist_entry_t *A, serverlist_entry_t *B ) +static qbool _ServerList_Entry_Compare( serverlist_entry_t *A, serverlist_entry_t *B ) { int result = 0; // > 0 if for numbers A > B and for text if A < B @@ -297,7 +297,7 @@ static qboolean _ServerList_Entry_Compare( serverlist_entry_t *A, serverlist_ent return A < B; } -static qboolean _ServerList_CompareInt( int A, serverlist_maskop_t op, int B ) +static qbool _ServerList_CompareInt( int A, serverlist_maskop_t op, int B ) { // This should actually be done with some intermediate and end-of-function return switch( op ) { @@ -323,7 +323,7 @@ static qboolean _ServerList_CompareInt( int A, serverlist_maskop_t op, int B ) } } -static qboolean _ServerList_CompareStr( const char *A, serverlist_maskop_t op, const char *B ) +static qbool _ServerList_CompareStr( const char *A, serverlist_maskop_t op, const char *B ) { int i; char bufferA[ 1400 ], bufferB[ 1400 ]; // should be more than enough @@ -365,7 +365,7 @@ static qboolean _ServerList_CompareStr( const char *A, serverlist_maskop_t op, c } } -static qboolean _ServerList_Entry_Mask( serverlist_mask_t *mask, serverlist_info_t *info ) +static qbool _ServerList_Entry_Mask( serverlist_mask_t *mask, serverlist_info_t *info ) { if( !_ServerList_CompareInt( info->ping, mask->tests[SLIF_PING], mask->info.ping ) ) return false; @@ -576,7 +576,7 @@ static void _ServerList_Test(void) } #endif -void ServerList_QueryList(qboolean resetcache, qboolean querydp, qboolean queryqw, qboolean consoleoutput) +void ServerList_QueryList(qbool resetcache, qbool querydp, qbool queryqw, qbool consoleoutput) { masterquerytime = host.realtime; masterquerycount = 0; @@ -668,7 +668,7 @@ int NetConn_WriteString(lhnetsocket_t *mysocket, const char *string, const lhnet return NetConn_Write(mysocket, string, (int)strlen(string), peeraddress); } -qboolean NetConn_CanSend(netconn_t *conn) +qbool NetConn_CanSend(netconn_t *conn) { conn->outgoing_packetcounter = (conn->outgoing_packetcounter + 1) % NETGRAPH_PACKETS; conn->outgoing_netgraph[conn->outgoing_packetcounter].time = host.realtime; @@ -723,7 +723,7 @@ static int NetConn_AddCryptoFlag(crypto_t *crypto) return flag; } -int NetConn_SendUnreliableMessage(netconn_t *conn, sizebuf_t *data, protocolversion_t protocol, int rate, int burstsize, qboolean quakesignon_suppressreliables) +int NetConn_SendUnreliableMessage(netconn_t *conn, sizebuf_t *data, protocolversion_t protocol, int rate, int burstsize, qbool quakesignon_suppressreliables) { int totallen = 0; unsigned char sendbuffer[NET_HEADERSIZE+NET_MAXMESSAGE]; @@ -740,7 +740,7 @@ int NetConn_SendUnreliableMessage(netconn_t *conn, sizebuf_t *data, protocolvers if (protocol == PROTOCOL_QUAKEWORLD) { int packetLen; - qboolean sendreliable; + qbool sendreliable; // note that it is ok to send empty messages to the qw server, // otherwise it won't respond to us at all @@ -931,12 +931,12 @@ int NetConn_SendUnreliableMessage(netconn_t *conn, sizebuf_t *data, protocolvers return 0; } -qboolean NetConn_HaveClientPorts(void) +qbool NetConn_HaveClientPorts(void) { return !!cl_numsockets; } -qboolean NetConn_HaveServerPorts(void) +qbool NetConn_HaveServerPorts(void) { return !!sv_numsockets; } @@ -970,11 +970,11 @@ static void NetConn_OpenClientPort(const char *addressstring, lhnetaddresstype_t else { LHNETADDRESS_ToString(&address, addressstring2, sizeof(addressstring2), true); - Con_Errorf("Client failed to open a socket on address %s\n", addressstring2); + Con_Printf(CON_ERROR "Client failed to open a socket on address %s\n", addressstring2); } } else - Con_Errorf("Client unable to parse address %s\n", addressstring); + Con_Printf(CON_ERROR "Client unable to parse address %s\n", addressstring); } void NetConn_OpenClientPorts(void) @@ -1007,7 +1007,7 @@ void NetConn_CloseServerPorts(void) LHNET_CloseSocket(sv_sockets[sv_numsockets - 1]); } -static qboolean NetConn_OpenServerPort(const char *addressstring, lhnetaddresstype_t addresstype, int defaultport, int range) +static qbool NetConn_OpenServerPort(const char *addressstring, lhnetaddresstype_t addresstype, int defaultport, int range) { lhnetaddress_t address; lhnetsocket_t *s; @@ -1034,12 +1034,12 @@ static qboolean NetConn_OpenServerPort(const char *addressstring, lhnetaddressty else { LHNETADDRESS_ToString(&address, addressstring2, sizeof(addressstring2), true); - Con_Errorf("Server failed to open socket on address %s\n", addressstring2); + Con_Printf(CON_ERROR "Server failed to open socket on address %s\n", addressstring2); } } else { - Con_Errorf("Server unable to parse address %s\n", addressstring); + Con_Printf(CON_ERROR "Server unable to parse address %s\n", addressstring); // if it cant parse one address, it wont be able to parse another for sure return false; } @@ -1060,7 +1060,6 @@ void NetConn_OpenServerPorts(int opennetports) port = bound(0, sv_netport.integer, 65535); if (port == 0) port = 26000; - Con_Printf("Server using port %i\n", port); if (sv_netport.integer != port) Cvar_SetValueQuick(&sv_netport, port); if (cls.state != ca_dedicated) @@ -1068,7 +1067,7 @@ void NetConn_OpenServerPorts(int opennetports) if (opennetports) { #ifndef NOSUPPORTIPV6 - qboolean ip4success = NetConn_OpenServerPort(net_address.string, LHNETADDRESSTYPE_INET4, port, 100); + qbool ip4success = NetConn_OpenServerPort(net_address.string, LHNETADDRESSTYPE_INET4, port, 100); NetConn_OpenServerPort(net_address_ipv6.string, LHNETADDRESSTYPE_INET6, port, ip4success ? 1 : 100); #else NetConn_OpenServerPort(net_address.string, LHNETADDRESSTYPE_INET4, port, 100); @@ -1208,7 +1207,7 @@ static int NetConn_ReceivedMessage(netconn_t *conn, const unsigned char *data, s if (protocol == PROTOCOL_QUAKEWORLD) { unsigned int sequence, sequence_ack; - qboolean reliable_ack, reliable_message; + qbool reliable_ack, reliable_message; int count; //int qport; @@ -1517,7 +1516,7 @@ static void NetConn_ConnectionEstablished(lhnetsocket_t *mysocket, lhnetaddress_ if (LHNETADDRESS_GetAddressType(peeraddress) != LHNETADDRESSTYPE_LOOP && sv.active) { SV_LockThreadMutex(); - Host_ShutdownServer (); + SV_Shutdown (); SV_UnlockThreadMutex(); } // allocate a net connection to keep track of things @@ -1549,7 +1548,7 @@ static void NetConn_ConnectionEstablished(lhnetsocket_t *mysocket, lhnetaddress_ // reset move sequence numbering on this new connection cls.servermovesequence = 0; if (cls.protocol == PROTOCOL_QUAKEWORLD) - Cmd_ForwardStringToServer("new"); + CL_ForwardToServer("new"); if (cls.protocol == PROTOCOL_QUAKE) { // write a keepalive (clc_nop) as it seems to greatly improve the @@ -1662,7 +1661,7 @@ static void NetConn_ClientParsePacket_ServerList_UpdateCache(int n) } // returns true, if it's sensible to continue the processing -static qboolean NetConn_ClientParsePacket_ServerList_PrepareQuery( int protocol, const char *ipstring, qboolean isfavorite ) { +static qbool NetConn_ClientParsePacket_ServerList_PrepareQuery( int protocol, const char *ipstring, qbool isfavorite ) { int n; serverlist_entry_t *entry; @@ -1705,7 +1704,7 @@ static qboolean NetConn_ClientParsePacket_ServerList_PrepareQuery( int protocol, return true; } -static void NetConn_ClientParsePacket_ServerList_ParseDPList(lhnetaddress_t *senderaddress, const unsigned char *data, int length, qboolean isextended) +static void NetConn_ClientParsePacket_ServerList_ParseDPList(lhnetaddress_t *senderaddress, const unsigned char *data, int length, qbool isextended) { masterreplycount++; if (serverlist_consoleoutput) @@ -1784,7 +1783,7 @@ static void NetConn_ClientParsePacket_ServerList_ParseDPList(lhnetaddress_t *sen static int NetConn_ClientParsePacket(lhnetsocket_t *mysocket, unsigned char *data, int length, lhnetaddress_t *peeraddress) { - qboolean fromserver; + qbool fromserver; int ret, c; char *string, addressstring2[128]; char stringbuf[16384]; @@ -2482,7 +2481,7 @@ void NetConn_ClientFrame(void) Con_Print("Connection timed out\n"); CL_Disconnect(); SV_LockThreadMutex(); - Host_ShutdownServer (); + SV_Shutdown (); SV_UnlockThreadMutex(); } } @@ -2503,7 +2502,7 @@ static void NetConn_BuildChallengeString(char *buffer, int bufferlength) } /// (div0) build the full response only if possible; better a getinfo response than no response at all if getstatus won't fit -static qboolean NetConn_BuildStatusResponse(const char* challenge, char* out_msg, size_t out_size, qboolean fullstatus) +static qbool NetConn_BuildStatusResponse(const char* challenge, char* out_msg, size_t out_size, qbool fullstatus) { prvm_prog_t *prog = SVVM_prog; char qcstatus[256]; @@ -2669,7 +2668,7 @@ bad: return false; } -static qboolean NetConn_PreventFlood(lhnetaddress_t *peeraddress, server_floodaddress_t *floodlist, size_t floodlength, double floodtime, qboolean renew) +static qbool NetConn_PreventFlood(lhnetaddress_t *peeraddress, server_floodaddress_t *floodlist, size_t floodlength, double floodtime, qbool renew) { size_t floodslotnum, bestfloodslotnum; double bestfloodtime; @@ -2732,15 +2731,15 @@ void NetConn_ClearFlood(lhnetaddress_t *peeraddress, server_floodaddress_t *floo } } -typedef qboolean (*rcon_matchfunc_t) (lhnetaddress_t *peeraddress, const char *password, const char *hash, const char *s, int slen); +typedef qbool (*rcon_matchfunc_t) (lhnetaddress_t *peeraddress, const char *password, const char *hash, const char *s, int slen); -static qboolean hmac_mdfour_time_matching(lhnetaddress_t *peeraddress, const char *password, const char *hash, const char *s, int slen) +static qbool hmac_mdfour_time_matching(lhnetaddress_t *peeraddress, const char *password, const char *hash, const char *s, int slen) { char mdfourbuf[16]; long t1, t2; if (!password[0]) { - Con_Error("LOGIC ERROR: RCon_Authenticate should never call the comparator with an empty password. Please report.\n"); + Con_Print(CON_ERROR "LOGIC ERROR: RCon_Authenticate should never call the comparator with an empty password. Please report.\n"); return false; } @@ -2755,13 +2754,13 @@ static qboolean hmac_mdfour_time_matching(lhnetaddress_t *peeraddress, const cha return !memcmp(mdfourbuf, hash, 16); } -static qboolean hmac_mdfour_challenge_matching(lhnetaddress_t *peeraddress, const char *password, const char *hash, const char *s, int slen) +static qbool hmac_mdfour_challenge_matching(lhnetaddress_t *peeraddress, const char *password, const char *hash, const char *s, int slen) { char mdfourbuf[16]; int i; if (!password[0]) { - Con_Error("LOGIC ERROR: RCon_Authenticate should never call the comparator with an empty password. Please report.\n"); + Con_Print(CON_ERROR "LOGIC ERROR: RCon_Authenticate should never call the comparator with an empty password. Please report.\n"); return false; } @@ -2789,10 +2788,10 @@ static qboolean hmac_mdfour_challenge_matching(lhnetaddress_t *peeraddress, cons return true; } -static qboolean plaintext_matching(lhnetaddress_t *peeraddress, const char *password, const char *hash, const char *s, int slen) +static qbool plaintext_matching(lhnetaddress_t *peeraddress, const char *password, const char *hash, const char *s, int slen) { if (!password[0]) { - Con_Error("LOGIC ERROR: RCon_Authenticate should never call the comparator with an empty password. Please report.\n"); + Con_Print(CON_ERROR "LOGIC ERROR: RCon_Authenticate should never call the comparator with an empty password. Please report.\n"); return false; } @@ -2804,9 +2803,9 @@ static const char *RCon_Authenticate(lhnetaddress_t *peeraddress, const char *pa { const char *text, *userpass_start, *userpass_end, *userpass_startpass; static char buf[MAX_INPUTLINE]; - qboolean hasquotes; - qboolean restricted = false; - qboolean have_usernames = false; + qbool hasquotes; + qbool restricted = false; + qbool have_usernames = false; static char vabuf[1024]; userpass_start = rcon_password.string; @@ -2898,7 +2897,7 @@ allow: return va(vabuf, sizeof(vabuf), "%srcon", restricted ? "restricted " : ""); } -static void RCon_Execute(lhnetsocket_t *mysocket, lhnetaddress_t *peeraddress, const char *addressstring2, const char *userlevel, const char *s, const char *endpos, qboolean proquakeprotocol) +static void RCon_Execute(lhnetsocket_t *mysocket, lhnetaddress_t *peeraddress, const char *addressstring2, const char *userlevel, const char *s, const char *endpos, qbool proquakeprotocol) { if(userlevel) { @@ -2922,7 +2921,7 @@ static void RCon_Execute(lhnetsocket_t *mysocket, lhnetaddress_t *peeraddress, c if(l) { client_t *host_client_save = host_client; - Cmd_ExecuteString(&cmd_server, s, src_command, true); + Cmd_ExecuteString(&cmd_server, s, src_local, true); host_client = host_client_save; // in case it is a command that changes host_client (like restart) } @@ -2942,7 +2941,7 @@ static int NetConn_ServerParsePacket(lhnetsocket_t *mysocket, unsigned char *dat double besttime; char *string, response[2800], addressstring2[128]; static char stringbuf[16384]; // server only - qboolean islocal = (LHNETADDRESS_GetAddressType(peeraddress) == LHNETADDRESSTYPE_LOOP); + qbool islocal = (LHNETADDRESS_GetAddressType(peeraddress) == LHNETADDRESSTYPE_LOOP); char senddata[NET_HEADERSIZE+NET_MAXMESSAGE+CRYPTO_HEADERSIZE]; size_t sendlength, response_len; char infostringvalue[MAX_INPUTLINE]; @@ -3626,7 +3625,7 @@ void NetConn_SleepMicroseconds(int microseconds) } #ifdef CONFIG_MENU -void NetConn_QueryMasters(qboolean querydp, qboolean queryqw) +void NetConn_QueryMasters(qbool querydp, qbool queryqw) { int i, j; int masternum; @@ -3757,7 +3756,7 @@ void NetConn_QueryMasters(qboolean querydp, qboolean queryqw) } if (!masterquerycount) { - Con_Error("Unable to query master servers, no suitable network sockets active.\n"); + Con_Print(CON_ERROR "Unable to query master servers, no suitable network sockets active.\n"); M_Update_Return_Reason("No network"); } } @@ -3889,6 +3888,9 @@ void NetConn_Init(void) Cvar_RegisterVariable(&net_slist_timeout); Cvar_RegisterVariable(&net_slist_maxtries); Cvar_RegisterVariable(&net_slist_favorites); +#ifdef CONFIG_MENU + Cvar_RegisterCallback(&net_slist_favorites, NetConn_UpdateFavorites_c); +#endif Cvar_RegisterVariable(&net_slist_pause); if(LHNET_DefaultDSCP(-1) >= 0) // register cvar only if supported Cvar_RegisterVariable(&net_tos_dscp); @@ -3919,7 +3921,7 @@ void NetConn_Init(void) Cvar_RegisterVariable(&gameversion_min); Cvar_RegisterVariable(&gameversion_max); // COMMANDLINEOPTION: Server: -ip sets the ip address of this machine for purposes of networking (default 0.0.0.0 also known as INADDR_ANY), use only if you have multiple network adapters and need to choose one specifically. - if ((i = COM_CheckParm("-ip")) && i + 1 < sys.argc) + if ((i = Sys_CheckParm("-ip")) && i + 1 < sys.argc) { if (LHNETADDRESS_FromString(&tempaddress, sys.argv[i + 1], 0) == 1) { @@ -3927,10 +3929,10 @@ void NetConn_Init(void) Cvar_SetQuick(&net_address, sys.argv[i + 1]); } else - Con_Errorf("-ip option used, but unable to parse the address \"%s\"\n", sys.argv[i + 1]); + Con_Printf(CON_ERROR "-ip option used, but unable to parse the address \"%s\"\n", sys.argv[i + 1]); } // COMMANDLINEOPTION: Server: -port sets the port to use for a server (default 26000, the same port as QUAKE itself), useful if you host multiple servers on your machine - if (((i = COM_CheckParm("-port")) || (i = COM_CheckParm("-ipport")) || (i = COM_CheckParm("-udpport"))) && i + 1 < sys.argc) + if (((i = Sys_CheckParm("-port")) || (i = Sys_CheckParm("-ipport")) || (i = Sys_CheckParm("-udpport"))) && i + 1 < sys.argc) { i = atoi(sys.argv[i + 1]); if (i >= 0 && i < 65536) @@ -3939,7 +3941,7 @@ void NetConn_Init(void) Cvar_SetValueQuick(&sv_netport, i); } else - Con_Errorf("-port option used, but %i is not a valid port number\n", i); + Con_Printf(CON_ERROR "-port option used, but %i is not a valid port number\n", i); } cl_numsockets = 0; sv_numsockets = 0;