DarkPlaces
Game engine based on the Quake 1 engine by id Software, developed by LadyHavoc
 
netconn.h File Reference
#include <stdarg.h>
#include "qtypes.h"
#include "crypto.h"
#include "lhnet.h"
#include "common.h"
+ Include dependency graph for netconn.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  challenge_t
 
struct  netconn_t::netconn_nq_s
 
struct  netconn_t::netconn_qw_s
 
struct  netconn_t
 
struct  netgraphitem_t
 

Macros

#define CCREP_ACCEPT   0x81
 
#define CCREP_PLAYER_INFO   0x84
 
#define CCREP_RCON   0x86
 
#define CCREP_REJECT   0x82
 
#define CCREP_RULE_INFO   0x85
 
#define CCREP_SERVER_INFO   0x83
 
#define CCREQ_CONNECT   0x01
 
#define CCREQ_PLAYER_INFO   0x03
 
#define CCREQ_RCON   0x05
 
#define CCREQ_RULE_INFO   0x04
 
#define CCREQ_SERVER_INFO   0x02
 
#define MAX_CHALLENGES   128
 
#define NET_EXTRESPONSE_MAX   16
 
#define NET_HEADERSIZE   (2 * sizeof(unsigned int))
 
#define NET_PROTOCOL_VERSION   3
 
#define NETFLAG_ACK   0x00020000
 
#define NETFLAG_CRYPTO0   0x10000000
 
#define NETFLAG_CRYPTO1   0x20000000
 
#define NETFLAG_CRYPTO2   0x40000000
 
#define NETFLAG_CTL   0x80000000
 
#define NETFLAG_DATA   0x00010000
 
#define NETFLAG_EOM   0x00080000
 
#define NETFLAG_LENGTH_MASK   0x0000ffff
 
#define NETFLAG_NAK   0x00040000
 
#define NETFLAG_UNRELIABLE   0x00100000
 
#define NETGRAPH_CHOKEDPACKET   -2
 
#define NETGRAPH_LOSTPACKET   -1
 
#define NETGRAPH_NOPACKET   0
 
#define NETGRAPH_PACKETS   256
 

Functions

void Net_Stats_f (struct cmd_state_s *cmd)
 
qbool NetConn_CanSend (netconn_t *conn)
 
lhnetsocket_tNetConn_ChooseClientSocketForAddress (lhnetaddress_t *address)
 
lhnetsocket_tNetConn_ChooseServerSocketForAddress (lhnetaddress_t *address)
 
void NetConn_ClientFrame (void)
 
void NetConn_Close (netconn_t *conn)
 
void NetConn_CloseClientPorts (void)
 
void NetConn_CloseServerPorts (void)
 
qbool NetConn_HaveClientPorts (void)
 
qbool NetConn_HaveServerPorts (void)
 
void NetConn_Heartbeat (int priority)
 
void NetConn_Init (void)
 
int NetConn_IsLocalGame (void)
 
void NetConn_Listen (qbool state)
 
netconn_tNetConn_Open (lhnetsocket_t *mysocket, lhnetaddress_t *peeraddress)
 
void NetConn_OpenClientPorts (void)
 
void NetConn_OpenServerPorts (int opennetports)
 
int NetConn_Read (lhnetsocket_t *mysocket, void *data, int maxlength, lhnetaddress_t *peeraddress)
 
int NetConn_SendUnreliableMessage (netconn_t *conn, sizebuf_t *data, protocolversion_t protocol, int rate, int burstsize, qbool quakesignon_suppressreliables)
 
void NetConn_ServerFrame (void)
 
void NetConn_Shutdown (void)
 
void NetConn_UpdateSockets (void)
 
int NetConn_Write (lhnetsocket_t *mysocket, const void *data, int length, const lhnetaddress_t *peeraddress)
 
int NetConn_WriteString (lhnetsocket_t *mysocket, const char *string, const lhnetaddress_t *peeraddress)
 

Variables

challenge_t challenges [MAX_CHALLENGES]
 
sizebuf_t cl_message
 
char cl_net_extresponse [NET_EXTRESPONSE_MAX][1400]
 
unsigned cl_net_extresponse_count
 
unsigned cl_net_extresponse_last
 
struct cvar_s cl_netport
 
char cl_readstring [MAX_INPUTLINE]
 
struct cvar_s developer_networking
 
struct cvar_s hostname
 
struct cvar_s net_address
 
struct cvar_s net_address_ipv6
 
struct cvar_s net_burstreserve
 
struct cvar_s net_fakelag
 
struct cvar_s net_usesizelimit
 
netconn_tnetconn_list
 
struct mempool_s * netconn_mempool
 
sizebuf_t sv_message
 
char sv_net_extresponse [NET_EXTRESPONSE_MAX][1400]
 
unsigned sv_net_extresponse_count
 
unsigned sv_net_extresponse_last
 
struct cvar_s sv_netport
 
struct cvar_s sv_public
 
char sv_readstring [MAX_INPUTLINE]
 

Macro Definition Documentation

◆ CCREP_ACCEPT

#define CCREP_ACCEPT   0x81

Definition at line 125 of file netconn.h.

Referenced by NetConn_ClientParsePacket(), and NetConn_ServerParsePacket().

◆ CCREP_PLAYER_INFO

#define CCREP_PLAYER_INFO   0x84

◆ CCREP_RCON

#define CCREP_RCON   0x86

Definition at line 130 of file netconn.h.

Referenced by Con_Rcon_Redirect_Init(), and NetConn_ClientParsePacket().

◆ CCREP_REJECT

#define CCREP_REJECT   0x82

Definition at line 126 of file netconn.h.

Referenced by NetConn_ClientParsePacket(), and NetConn_ServerParsePacket().

◆ CCREP_RULE_INFO

#define CCREP_RULE_INFO   0x85

◆ CCREP_SERVER_INFO

#define CCREP_SERVER_INFO   0x83

◆ CCREQ_CONNECT

#define CCREQ_CONNECT   0x01

Definition at line 119 of file netconn.h.

Referenced by NetConn_ClientFrame(), and NetConn_ServerParsePacket().

◆ CCREQ_PLAYER_INFO

#define CCREQ_PLAYER_INFO   0x03

Definition at line 121 of file netconn.h.

Referenced by NetConn_ServerParsePacket().

◆ CCREQ_RCON

#define CCREQ_RCON   0x05

Definition at line 123 of file netconn.h.

Referenced by CL_PQRcon_f(), and NetConn_ServerParsePacket().

◆ CCREQ_RULE_INFO

#define CCREQ_RULE_INFO   0x04

Definition at line 122 of file netconn.h.

Referenced by NetConn_ServerParsePacket().

◆ CCREQ_SERVER_INFO

#define CCREQ_SERVER_INFO   0x02

Definition at line 120 of file netconn.h.

Referenced by NetConn_ServerParsePacket().

◆ MAX_CHALLENGES

#define MAX_CHALLENGES   128

◆ NET_EXTRESPONSE_MAX

#define NET_EXTRESPONSE_MAX   16

◆ NET_HEADERSIZE

#define NET_HEADERSIZE   (2 * sizeof(unsigned int))

◆ NET_PROTOCOL_VERSION

#define NET_PROTOCOL_VERSION   3

◆ NETFLAG_ACK

#define NETFLAG_ACK   0x00020000

Definition at line 37 of file netconn.h.

Referenced by NetConn_ReceivedMessage().

◆ NETFLAG_CRYPTO0

#define NETFLAG_CRYPTO0   0x10000000

Definition at line 41 of file netconn.h.

Referenced by NetConn_AddCryptoFlag().

◆ NETFLAG_CRYPTO1

#define NETFLAG_CRYPTO1   0x20000000

Definition at line 42 of file netconn.h.

Referenced by NetConn_AddCryptoFlag().

◆ NETFLAG_CRYPTO2

#define NETFLAG_CRYPTO2   0x40000000

Definition at line 43 of file netconn.h.

Referenced by NetConn_AddCryptoFlag().

◆ NETFLAG_CTL

◆ NETFLAG_DATA

#define NETFLAG_DATA   0x00010000

Definition at line 36 of file netconn.h.

Referenced by NetConn_ReceivedMessage(), and NetConn_SendUnreliableMessage().

◆ NETFLAG_EOM

#define NETFLAG_EOM   0x00080000

Definition at line 39 of file netconn.h.

Referenced by NetConn_ReceivedMessage(), and NetConn_SendUnreliableMessage().

◆ NETFLAG_LENGTH_MASK

#define NETFLAG_LENGTH_MASK   0x0000ffff

◆ NETFLAG_NAK

#define NETFLAG_NAK   0x00040000

Definition at line 38 of file netconn.h.

◆ NETFLAG_UNRELIABLE

#define NETFLAG_UNRELIABLE   0x00100000

Definition at line 40 of file netconn.h.

Referenced by NetConn_ReceivedMessage(), and NetConn_SendUnreliableMessage().

◆ NETGRAPH_CHOKEDPACKET

#define NETGRAPH_CHOKEDPACKET   -2

◆ NETGRAPH_LOSTPACKET

#define NETGRAPH_LOSTPACKET   -1

◆ NETGRAPH_NOPACKET

#define NETGRAPH_NOPACKET   0

◆ NETGRAPH_PACKETS

Function Documentation

◆ Net_Stats_f()

void Net_Stats_f ( struct cmd_state_s * cmd)

◆ NetConn_CanSend()

qbool NetConn_CanSend ( netconn_t * conn)

Definition at line 789 of file netconn.c.

790{
797 if (host.realtime > conn->cleartime)
798 return true;
799 else
800 {
802 return false;
803 }
804}
host_static_t host
Definition host.c:41
#define NETGRAPH_NOPACKET
Definition netconn.h:223
#define NETGRAPH_PACKETS
Definition netconn.h:222
#define NETGRAPH_CHOKEDPACKET
Definition netconn.h:225
double realtime
the accumulated mainloop time since application started (with filtering), without any slowmo or clamp...
Definition host.h:46
int outgoing_packetcounter
Definition netconn.h:228
double cleartime
Definition netconn.h:217
netgraphitem_t outgoing_netgraph[NETGRAPH_PACKETS]
Definition netconn.h:229
double time
Definition netconn.h:134
double cleartime
Definition netconn.h:138
int unreliablebytes
Definition netconn.h:136
int reliablebytes
Definition netconn.h:135

References netgraphitem_t::ackbytes, netconn_t::cleartime, netgraphitem_t::cleartime, host, NETGRAPH_CHOKEDPACKET, NETGRAPH_NOPACKET, NETGRAPH_PACKETS, netconn_t::outgoing_netgraph, netconn_t::outgoing_packetcounter, host_static_t::realtime, netgraphitem_t::reliablebytes, netgraphitem_t::time, and netgraphitem_t::unreliablebytes.

Referenced by CL_SendMove(), and SV_SendClientDatagram().

◆ NetConn_ChooseClientSocketForAddress()

lhnetsocket_t * NetConn_ChooseClientSocketForAddress ( lhnetaddress_t * address)

Definition at line 1198 of file netconn.c.

1199{
1200 unsigned i;
1202
1203 for (i = 0;i < cl_numsockets;i++)
1205 return cl_sockets[i];
1206 return NULL;
1207}
lhnetaddress_t * LHNET_AddressFromSocket(lhnetsocket_t *sock)
Definition lhnet.c:1026
lhnetaddresstype_t
Definition lhnet.h:11
static lhnetaddresstype_t LHNETADDRESS_GetAddressType(const lhnetaddress_t *address)
Definition lhnet.h:31
static lhnetsocket_t * cl_sockets[16]
Definition netconn.c:147
static unsigned cl_numsockets
Definition netconn.c:146
int i
#define NULL
Definition qtypes.h:12
ret a

References a, cl_numsockets, cl_sockets, i, LHNET_AddressFromSocket(), LHNETADDRESS_GetAddressType(), and NULL.

Referenced by CL_EstablishConnection(), CL_Packet_f(), CL_PQRcon_f(), CL_Rcon_f(), and Log_DestBuffer_Flush_NoLock().

◆ NetConn_ChooseServerSocketForAddress()

lhnetsocket_t * NetConn_ChooseServerSocketForAddress ( lhnetaddress_t * address)

Definition at line 1209 of file netconn.c.

1210{
1211 unsigned i;
1213
1214 for (i = 0;i < sv_numsockets;i++)
1216 return sv_sockets[i];
1217 return NULL;
1218}
static unsigned sv_numsockets
Definition netconn.c:148
static lhnetsocket_t * sv_sockets[16]
Definition netconn.c:149

References a, i, LHNET_AddressFromSocket(), LHNETADDRESS_GetAddressType(), NULL, sv_numsockets, and sv_sockets.

Referenced by CL_Packet_f(), Log_DestBuffer_Flush_NoLock(), and NetConn_Heartbeat().

◆ NetConn_ClientFrame()

void NetConn_ClientFrame ( void )

Definition at line 2674 of file netconn.c.

2675{
2676 unsigned i;
2677 int length;
2678 lhnetaddress_t peeraddress;
2679 unsigned char readbuffer[NET_HEADERSIZE+NET_MAXMESSAGE];
2680
2682
2684 {
2686 {
2688 dpsnprintf(cl_connect_status, sizeof(cl_connect_status), "Connect: sending initial request, %i %s left...", cls.connect_remainingtries, cls.connect_remainingtries == 1 ? "retry" : "retries");
2689 }
2690 else
2691 {
2692 char address[128];
2693
2694 cls.connect_trying = false;
2695 LHNETADDRESS_ToString(&cls.connect_address, address, sizeof(address), true);
2696 dp_strlcpy(cl_connect_status, "Connect: failed, no reply", sizeof(cl_connect_status));
2697 Con_Printf(CON_ERROR "%s from %s\n", cl_connect_status, address);
2698 return;
2699 }
2701
2702 // try challenge first (newer DP server or QW)
2703 NetConn_WriteString(cls.connect_mysocket, "\377\377\377\377getchallenge", &cls.connect_address);
2704 // then try netquake as a fallback (old server, or netquake)
2706 // save space for the header, filled in later
2709 MSG_WriteString(&cl_message, "QUAKE");
2711 // extended proquake stuff
2712 MSG_WriteByte(&cl_message, 1); // mod = MOD_PROQUAKE
2713 // this version matches ProQuake 3.40, the first version to support
2714 // the NAT fix, and it only supports the NAT fix for ProQuake 3.40 or
2715 // higher clients, so we pretend we are that version...
2716 MSG_WriteByte(&cl_message, 34); // version * 10
2717 MSG_WriteByte(&cl_message, 0); // flags
2718 MSG_WriteLong(&cl_message, 0); // password
2719 // write the packetsize now...
2723 }
2724
2725 for (i = 0;i < cl_numsockets;i++)
2726 {
2727 while (cl_sockets[i] && (length = NetConn_Read(cl_sockets[i], readbuffer, sizeof(readbuffer), &peeraddress)) > 0)
2728 {
2729// R_TimeReport("clientreadnetwork");
2730 NetConn_ClientParsePacket(cl_sockets[i], readbuffer, length, &peeraddress);
2731// R_TimeReport("clientparsepacket");
2732 }
2733 }
2734#ifdef CONFIG_MENU
2735 NetConn_QueryQueueFrame();
2736#endif
2738 CL_DisconnectEx(true, "Connection timed out");
2739}
void CL_DisconnectEx(qbool kicked, const char *fmt,...)
Definition cl_main.c:370
client_static_t cls
Definition cl_main.c:116
char cl_connect_status[MAX_QPATH]
User-friendly connection status for the menu and/or loading screen, colours and not supported.
Definition cl_screen.c:1573
void MSG_WriteString(sizebuf_t *sb, const char *s)
Definition com_msg.c:173
void MSG_WriteLong(sizebuf_t *sb, int c)
Definition com_msg.c:147
void MSG_WriteByte(sizebuf_t *sb, int c)
Definition com_msg.c:130
void StoreBigLong(unsigned char *buffer, unsigned int i)
Encode a big endian 32bit int to the given buffer.
Definition com_msg.c:81
void SZ_Clear(sizebuf_t *buf)
Definition common.c:44
int dpsnprintf(char *buffer, size_t buffersize, const char *format,...)
Returns the number of printed characters, excluding the final '\0' or returns -1 if the buffer isn't ...
Definition common.c:997
#define dp_strlcpy(dst, src, dsize)
Definition common.h:303
void Con_Printf(const char *fmt,...)
Prints to all appropriate console targets.
Definition console.c:1514
#define CON_ERROR
Definition console.h:102
GLenum GLuint GLenum GLsizei length
Definition glquake.h:657
int LHNETADDRESS_ToString(const lhnetaddress_t *vaddress, char *string, int stringbuffersize, int includeport)
Returns the number of bytes written to *string excluding the \0 terminator.
Definition lhnet.c:540
int NetConn_Write(lhnetsocket_t *mysocket, const void *data, int length, const lhnetaddress_t *peeraddress)
Definition netconn.c:758
int NetConn_WriteString(lhnetsocket_t *mysocket, const char *string, const lhnetaddress_t *peeraddress)
Definition netconn.c:783
int NetConn_Read(lhnetsocket_t *mysocket, void *data, int maxlength, lhnetaddress_t *peeraddress)
Definition netconn.c:726
sizebuf_t cl_message
Definition netconn.c:71
void NetConn_UpdateSockets(void)
Definition netconn.c:1306
static int NetConn_ClientParsePacket(lhnetsocket_t *mysocket, unsigned char *data, int length, lhnetaddress_t *peeraddress)
Definition netconn.c:2019
#define NETFLAG_CTL
Definition netconn.h:44
#define NET_HEADERSIZE
Definition netconn.h:32
#define NET_PROTOCOL_VERSION
Definition netconn.h:47
#define NETFLAG_LENGTH_MASK
Definition netconn.h:35
#define CCREQ_CONNECT
Definition netconn.h:119
#define NET_MAXMESSAGE
max reliable packet size (sent as multiple fragments of MAX_PACKETFRAGMENT)
Definition qdefs.h:103
server_t sv
local server
Definition sv_main.c:223
qbool connect_trying
Definition client.h:609
int connect_remainingtries
Definition client.h:610
netconn_t * netcon
Definition client.h:630
double connect_nextsendtime
Definition client.h:611
lhnetaddress_t connect_address
Definition client.h:613
lhnetsocket_t * connect_mysocket
Definition client.h:612
double timeout
Definition netconn.h:153
qbool active
false if only a net client
Definition server.h:66
unsigned char * data
Definition common.h:52
int cursize
Definition common.h:54

References server_t::active, CCREQ_CONNECT, cl_connect_status, CL_DisconnectEx(), cl_message, cl_numsockets, cl_sockets, cls, CON_ERROR, Con_Printf(), client_static_t::connect_address, client_static_t::connect_mysocket, client_static_t::connect_nextsendtime, client_static_t::connect_remainingtries, client_static_t::connect_trying, sizebuf_t::cursize, sizebuf_t::data, dp_strlcpy, dpsnprintf(), host, i, length, LHNETADDRESS_ToString(), MSG_WriteByte(), MSG_WriteLong(), MSG_WriteString(), NET_HEADERSIZE, NET_MAXMESSAGE, NET_PROTOCOL_VERSION, client_static_t::netcon, NetConn_ClientParsePacket(), NetConn_Read(), NetConn_UpdateSockets(), NetConn_Write(), NetConn_WriteString(), NETFLAG_CTL, NETFLAG_LENGTH_MASK, host_static_t::realtime, StoreBigLong(), sv, SZ_Clear(), and netconn_t::timeout.

Referenced by CL_Frame(), and CL_KeepaliveMessage().

◆ NetConn_Close()

void NetConn_Close ( netconn_t * conn)

Definition at line 1240 of file netconn.c.

1241{
1242 netconn_t *c;
1243 // remove connection from list
1244
1245 // allow the client to reconnect immediately
1247
1248 if (conn == netconn_list)
1249 netconn_list = conn->next;
1250 else
1251 {
1252 for (c = netconn_list;c;c = c->next)
1253 {
1254 if (c->next == conn)
1255 {
1256 c->next = conn->next;
1257 break;
1258 }
1259 }
1260 // not found in list, we'll avoid crashing here...
1261 if (!c)
1262 return;
1263 }
1264 // free connection
1265 Mem_Free(conn);
1266}
void NetConn_ClearFlood(lhnetaddress_t *peeraddress, server_floodaddress_t *floodlist, size_t floodlength)
Definition netconn.c:2966
netconn_t * netconn_list
Definition netconn.c:151
lhnetaddress_t peeraddress
Definition netconn.h:147
struct netconn_s * next
Definition netconn.h:144
server_floodaddress_t connectfloodaddresses[MAX_CONNECTFLOODADDRESSES]
connection flood blocking note this is in server_t rather than server_static_t so that it is reset on...
Definition server.h:140
#define Mem_Free(mem)
Definition zone.h:96

References server_t::connectfloodaddresses, Mem_Free, NetConn_ClearFlood(), netconn_list, netconn_t::next, netconn_t::peeraddress, and sv.

Referenced by CL_DisconnectEx(), and SV_DropClient().

◆ NetConn_CloseClientPorts()

void NetConn_CloseClientPorts ( void )

Definition at line 1062 of file netconn.c.

1063{
1064 for (;cl_numsockets > 0;cl_numsockets--)
1065 if (cl_sockets[cl_numsockets - 1])
1067}
void LHNET_CloseSocket(lhnetsocket_t *lhnetsocket)
Definition lhnet.c:1012

References cl_numsockets, cl_sockets, and LHNET_CloseSocket().

Referenced by NetConn_CL_UpdateSockets_Callback(), NetConn_OpenClientPorts(), and NetConn_Shutdown().

◆ NetConn_CloseServerPorts()

void NetConn_CloseServerPorts ( void )

◆ NetConn_HaveClientPorts()

qbool NetConn_HaveClientPorts ( void )

Definition at line 1052 of file netconn.c.

1053{
1054 return !!cl_numsockets;
1055}

References cl_numsockets.

Referenced by Log_DestBuffer_Flush_NoLock().

◆ NetConn_HaveServerPorts()

qbool NetConn_HaveServerPorts ( void )

Definition at line 1057 of file netconn.c.

1058{
1059 return !!sv_numsockets;
1060}

References sv_numsockets.

Referenced by Log_DestBuffer_Flush_NoLock().

◆ NetConn_Heartbeat()

void NetConn_Heartbeat ( int priority)

Definition at line 3984 of file netconn.c.

3985{
3986 lhnetaddress_t masteraddress;
3987 uint8_t masternum;
3988 lhnetsocket_t *mysocket;
3989
3990 // if it's a state change (client connected), limit next heartbeat to no
3991 // more than 30 sec in the future
3992 if (priority == 1 && nextheartbeattime > host.realtime + 30.0)
3994
3995 // limit heartbeatperiod to 30 to 270 second range,
3996 // lower limit is to avoid abusing master servers with excess traffic,
3997 // upper limit is to avoid timing out on the master server (which uses
3998 // 300 sec timeout)
3999 if (sv_heartbeatperiod.value < 30)
4001 if (sv_heartbeatperiod.value > 270)
4003
4004 // make advertising optional and don't advertise singleplayer games, and
4005 // only send a heartbeat as often as the admin wants
4006 if (sv.active && sv_public.integer > 0 && svs.maxclients >= 2 && (priority > 1 || host.realtime > nextheartbeattime))
4007 {
4009 for (masternum = 0; masternum < DPMASTER_COUNT; ++masternum)
4010 if (sv_masters[masternum].string[0]
4011 && LHNETADDRESS_FromString(&masteraddress, sv_masters[masternum].string, DPMASTER_PORT)
4012 && (mysocket = NetConn_ChooseServerSocketForAddress(&masteraddress)))
4013 NetConn_WriteString(mysocket, "\377\377\377\377heartbeat DarkPlaces\x0A", &masteraddress);
4014 }
4015}
void Cvar_SetValueQuick(cvar_t *var, float value)
Definition cvar.c:473
int LHNETADDRESS_FromString(lhnetaddress_t *vaddress, const char *string, int defaultport)
Definition lhnet.c:204
#define DPMASTER_PORT
Definition netconn.c:33
cvar_t sv_public
Definition netconn.c:36
static cvar_t sv_masters[]
Definition netconn.c:41
static double nextheartbeattime
Definition netconn.c:69
static cvar_t sv_heartbeatperiod
Definition netconn.c:38
#define DPMASTER_COUNT
Definition netconn.c:125
lhnetsocket_t * NetConn_ChooseServerSocketForAddress(lhnetaddress_t *address)
Definition netconn.c:1209
server_static_t svs
persistant server info
Definition sv_main.c:224
float value
Definition cvar.h:74
int integer
Definition cvar.h:73
int maxclients
number of svs.clients slots (updated by maxplayers command)
Definition server.h:28

References server_t::active, Cvar_SetValueQuick(), DPMASTER_COUNT, DPMASTER_PORT, host, cvar_t::integer, LHNETADDRESS_FromString(), server_static_t::maxclients, NetConn_ChooseServerSocketForAddress(), NetConn_WriteString(), nextheartbeattime, host_static_t::realtime, sv, sv_heartbeatperiod, sv_masters, sv_public, svs, and cvar_t::value.

Referenced by Net_Heartbeat_f(), NetConn_ServerParsePacket(), SV_DropClient(), SV_Frame(), SV_Shutdown(), SV_SpawnServer(), and SV_ThreadFunc().

◆ NetConn_Init()

void NetConn_Init ( void )

Definition at line 4094 of file netconn.c.

4095{
4096 int i;
4097 unsigned j;
4098 lhnetaddress_t tempaddress;
4099
4100 netconn_mempool = Mem_AllocPool("network connections", 0, NULL);
4101 Cmd_AddCommand(CF_SHARED, "net_stats", Net_Stats_f, "print network statistics");
4102#ifdef CONFIG_MENU
4103 Cmd_AddCommand(CF_CLIENT, "net_slist", Net_Slist_f, "query dp master servers and print all server information");
4104 Cmd_AddCommand(CF_CLIENT, "net_slistqw", Net_SlistQW_f, "query qw master servers and print all server information");
4105 Cmd_AddCommand(CF_CLIENT, "net_refresh", Net_Refresh_f, "query dp master servers and refresh all server information");
4106#endif
4107 Cmd_AddCommand(CF_SERVER, "heartbeat", Net_Heartbeat_f, "send a heartbeat to the master server (updates your server information)");
4114
4115#ifdef CONFIG_MENU
4116 Cvar_RegisterVariable(&net_slist_debug);
4117 Cvar_RegisterVariable(&net_slist_favorites);
4118 Cvar_RegisterCallback(&net_slist_favorites, NetConn_UpdateFavorites_c);
4119 Cvar_RegisterVariable(&net_slist_interval);
4120 Cvar_RegisterVariable(&net_slist_maxping);
4121 Cvar_RegisterVariable(&net_slist_maxtries);
4122 Cvar_RegisterVariable(&net_slist_pause);
4123 Cvar_RegisterCallback(&net_slist_pause, ServerList_RebuildViewList);
4124 Cvar_RegisterVariable(&net_slist_queriespersecond);
4125 Cvar_RegisterVariable(&net_slist_queriesperframe);
4126 Cvar_RegisterVariable(&net_slist_timeout);
4127#endif
4128
4129#ifdef IP_TOS // register cvar only if supported
4131#endif
4142 Cvar_RegisterVirtual(&net_fakelag, "cl_netlocalping");
4143 Cvar_RegisterVirtual(&net_fakeloss_send, "cl_netpacketloss_send");
4144 Cvar_RegisterVirtual(&net_fakeloss_receive, "cl_netpacketloss_receive");
4156 for (j = 0; j < DPMASTER_COUNT; ++j)
4158#ifdef CONFIG_MENU
4159 for (j = 0; j < QWMASTER_COUNT; ++j)
4160 Cvar_RegisterVariable(&sv_qwmasters[j]);
4161#endif
4165// COMMANDLINEOPTION: Server: -ip <ipaddress> 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.
4166 if ((i = Sys_CheckParm("-ip")) && i + 1 < sys.argc)
4167 {
4168 if (LHNETADDRESS_FromString(&tempaddress, sys.argv[i + 1], 0) == 1)
4169 {
4170 Con_Printf("-ip option used, setting net_address to \"%s\"\n", sys.argv[i + 1]);
4172 }
4173 else
4174 Con_Printf(CON_ERROR "-ip option used, but unable to parse the address \"%s\"\n", sys.argv[i + 1]);
4175 }
4176// COMMANDLINEOPTION: Server: -port <portnumber> 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
4177 if (((i = Sys_CheckParm("-port")) || (i = Sys_CheckParm("-ipport")) || (i = Sys_CheckParm("-udpport"))) && i + 1 < sys.argc)
4178 {
4179 i = atoi(sys.argv[i + 1]);
4180 if (i >= 0 && i < 65536)
4181 {
4182 Con_Printf("-port option used, setting port cvar to %i\n", i);
4184 }
4185 else
4186 Con_Printf(CON_ERROR "-port option used, but %i is not a valid port number\n", i);
4187 }
4188 cl_numsockets = 0;
4189 sv_numsockets = 0;
4192 cl_message.cursize = 0;
4195 sv_message.cursize = 0;
4196 LHNET_Init();
4197 if (Thread_HasThreads())
4199}
void Cmd_AddCommand(unsigned flags, const char *cmd_name, xcommand_t function, const char *description)
called by the init functions of other parts of the program to register commands and functions to call...
Definition cmd.c:1661
#define CF_SHARED
Definition cmd.h:67
#define CF_SERVER
cvar/command that only the server can change/execute
Definition cmd.h:49
#define CF_CLIENT
cvar/command that only the client can change/execute
Definition cmd.h:48
void Cvar_SetQuick(cvar_t *var, const char *value)
Definition cvar.c:436
void Cvar_RegisterVariable(cvar_t *variable)
registers a cvar that already has the name, string, and optionally the archive elements set.
Definition cvar.c:599
void Cvar_RegisterVirtual(cvar_t *variable, const char *name)
Definition cvar.c:513
void Cvar_RegisterCallback(cvar_t *variable, void(*callback)(cvar_t *))
Definition cvar.c:495
void LHNET_Init(void)
Definition lhnet.c:725
void * netconn_mutex
Definition netconn.c:153
cvar_t net_burstreserve
Definition netconn.c:80
mempool_t * netconn_mempool
Definition netconn.c:152
cvar_t net_address_ipv6
Definition netconn.c:158
cvar_t net_messagetimeout
Definition netconn.c:81
cvar_t net_fakelag
Definition netconn.c:91
void Net_Stats_f(cmd_state_t *cmd)
Definition netconn.c:4042
static void NetConn_CL_UpdateSockets_Callback(cvar_t *var)
Definition netconn.c:1272
cvar_t net_connecttimeout
Definition netconn.c:82
static cvar_t rcon_restricted_commands
Definition netconn.c:112
static cvar_t gameversion_min
Definition netconn.c:109
cvar_t sv_public_rejectreason
Definition netconn.c:37
static cvar_t net_tos_dscp
Definition netconn.c:107
cvar_t developer_networking
Definition netconn.c:89
cvar_t net_usesizelimit
Definition netconn.c:79
static cvar_t net_fakeloss_receive
Definition netconn.c:93
static unsigned char cl_message_buf[NET_MAXMESSAGE]
Definition netconn.c:73
static void Net_Heartbeat_f(cmd_state_t *cmd)
Definition netconn.c:4017
#define QWMASTER_COUNT
Definition netconn.c:126
static cvar_t rcon_restricted_password
Definition netconn.c:111
cvar_t net_challengefloodblockingtimeout
Definition netconn.c:85
cvar_t net_test
Definition netconn.c:78
cvar_t net_getstatusfloodblockingtimeout
Definition netconn.c:86
static cvar_t gameversion
Definition netconn.c:108
static unsigned char sv_message_buf[NET_MAXMESSAGE]
Definition netconn.c:74
sizebuf_t sv_message
Definition netconn.c:72
cvar_t cl_netport
Definition netconn.c:155
static void NetConn_sv_netport_Callback(cvar_t *var)
Definition netconn.c:1296
cvar_t net_address
Definition netconn.c:157
cvar_t hostname
Definition netconn.c:88
cvar_t net_connect_entnum_ofs
Definition netconn.c:83
cvar_t net_sourceaddresscheck
Definition netconn.c:87
static cvar_t gameversion_max
Definition netconn.c:110
static cvar_t rcon_secure_maxdiff
Definition netconn.c:113
static cvar_t net_fakeloss_send
Definition netconn.c:92
cvar_t net_connectfloodblockingtimeout
Definition netconn.c:84
cvar_t sv_netport
Definition netconn.c:156
int maxsize
Definition common.h:53
int argc
Definition sys.h:146
const char ** argv
Definition sys.h:147
sys_t sys
Definition sys_shared.c:42
int Sys_CheckParm(const char *parm)
Definition sys_shared.c:327
qbool Thread_HasThreads(void)
Definition thread_null.c:13
#define Thread_CreateMutex()
Definition thread.h:15
#define Mem_AllocPool(name, flags, parent)
Definition zone.h:104

References sys_t::argc, sys_t::argv, CF_CLIENT, CF_SERVER, CF_SHARED, cl_message, cl_message_buf, cl_netport, cl_numsockets, Cmd_AddCommand(), CON_ERROR, Con_Printf(), sizebuf_t::cursize, Cvar_RegisterCallback(), Cvar_RegisterVariable(), Cvar_RegisterVirtual(), Cvar_SetQuick(), Cvar_SetValueQuick(), sizebuf_t::data, developer_networking, DPMASTER_COUNT, gameversion, gameversion_max, gameversion_min, hostname, i, LHNET_Init(), LHNETADDRESS_FromString(), sizebuf_t::maxsize, Mem_AllocPool, net_address, net_address_ipv6, net_burstreserve, net_challengefloodblockingtimeout, net_connect_entnum_ofs, net_connectfloodblockingtimeout, net_connecttimeout, net_fakelag, net_fakeloss_receive, net_fakeloss_send, net_getstatusfloodblockingtimeout, Net_Heartbeat_f(), net_messagetimeout, net_sourceaddresscheck, Net_Stats_f(), net_test, net_tos_dscp, net_usesizelimit, NetConn_CL_UpdateSockets_Callback(), netconn_mempool, netconn_mutex, NetConn_sv_netport_Callback(), NULL, QWMASTER_COUNT, rcon_restricted_commands, rcon_restricted_password, rcon_secure_maxdiff, sv_heartbeatperiod, sv_masters, sv_message, sv_message_buf, sv_netport, sv_numsockets, sv_public, sv_public_rejectreason, sys, Sys_CheckParm(), Thread_CreateMutex, and Thread_HasThreads().

Referenced by Host_Init().

◆ NetConn_IsLocalGame()

int NetConn_IsLocalGame ( void )

Definition at line 1696 of file netconn.c.

1697{
1698 if (cls.state == ca_connected && sv.active && cl.maxclients == 1)
1699 return true;
1700 return false;
1701}
client_state_t cl
Definition cl_main.c:117
@ ca_connected
Definition client.h:532
cactive_t state
Definition client.h:568

References server_t::active, ca_connected, cl, cls, client_state_t::maxclients, client_static_t::state, and sv.

Referenced by CL_ParseServerInfo().

◆ NetConn_Listen()

void NetConn_Listen ( qbool state)

◆ NetConn_Open()

netconn_t * NetConn_Open ( lhnetsocket_t * mysocket,
lhnetaddress_t * peeraddress )

Definition at line 1220 of file netconn.c.

1221{
1222 netconn_t *conn;
1223 conn = (netconn_t *)Mem_Alloc(netconn_mempool, sizeof(*conn));
1224 conn->mysocket = mysocket;
1225 conn->peeraddress = *peeraddress;
1227 conn->message.data = conn->messagedata;
1228 conn->message.maxsize = sizeof(conn->messagedata);
1229 conn->message.cursize = 0;
1230 // LadyHavoc: (inspired by ProQuake) use a short connect timeout to
1231 // reduce effectiveness of connection request floods
1233 LHNETADDRESS_ToString(&conn->peeraddress, conn->address, sizeof(conn->address), true);
1234 conn->next = netconn_list;
1235 netconn_list = conn;
1236 return conn;
1237}
double lastMessageTime
Definition netconn.h:154
unsigned char messagedata[NET_MAXMESSAGE]
Definition netconn.h:162
lhnetsocket_t * mysocket
Definition netconn.h:146
sizebuf_t message
writing buffer to send to peer as the next reliable message can be added to at any time,...
Definition netconn.h:161
char address[128]
Definition netconn.h:231
#define Mem_Alloc(pool, size)
Definition zone.h:92

References netconn_t::address, sizebuf_t::cursize, sizebuf_t::data, host, netconn_t::lastMessageTime, LHNETADDRESS_ToString(), sizebuf_t::maxsize, Mem_Alloc, netconn_t::message, netconn_t::messagedata, netconn_t::mysocket, net_connecttimeout, netconn_list, netconn_mempool, netconn_t::next, netconn_t::peeraddress, host_static_t::realtime, netconn_t::timeout, and cvar_t::value.

Referenced by NetConn_ConnectionEstablished(), and NetConn_ServerParsePacket().

◆ NetConn_OpenClientPorts()

void NetConn_OpenClientPorts ( void )

Definition at line 1098 of file netconn.c.

1099{
1100 int port;
1102
1103 SV_LockThreadMutex(); // FIXME recursive?
1104 Crypto_LoadKeys(); // client sockets
1106
1107 port = bound(0, cl_netport.integer, 65535);
1108 if (cl_netport.integer != port)
1110 if(port == 0)
1111 Con_Printf("Client using an automatically assigned port\n");
1112 else
1113 Con_Printf("Client using port %i\n", port);
1116#ifndef NOSUPPORTIPV6
1118#endif
1119}
void Crypto_LoadKeys(void)
Definition crypto.c:855
@ LHNETADDRESSTYPE_INET6
Definition lhnet.h:15
@ LHNETADDRESSTYPE_INET4
Definition lhnet.h:14
@ LHNETADDRESSTYPE_LOOP
Definition lhnet.h:13
#define bound(min, num, max)
Definition mathlib.h:34
static void NetConn_OpenClientPort(const char *addressstring, lhnetaddresstype_t addresstype, int defaultport)
Definition netconn.c:1069
void NetConn_CloseClientPorts(void)
Definition netconn.c:1062
#define SV_LockThreadMutex()
Definition server.h:606
#define SV_UnlockThreadMutex()
Definition server.h:607
const char * string
Definition cvar.h:71

References bound, cl_netport, Con_Printf(), Crypto_LoadKeys(), Cvar_SetValueQuick(), cvar_t::integer, LHNETADDRESSTYPE_INET4, LHNETADDRESSTYPE_INET6, LHNETADDRESSTYPE_LOOP, net_address, net_address_ipv6, NetConn_CloseClientPorts(), NetConn_OpenClientPort(), NULL, cvar_t::string, SV_LockThreadMutex, and SV_UnlockThreadMutex.

Referenced by NetConn_CL_UpdateSockets_Callback().

◆ NetConn_OpenServerPorts()

void NetConn_OpenServerPorts ( int opennetports)

Definition at line 1168 of file netconn.c.

1169{
1170 int port;
1172
1173 SV_LockThreadMutex(); // FIXME recursive?
1174 Crypto_LoadKeys(); // server sockets
1176
1178 port = bound(0, sv_netport.integer, 65535);
1179 if (port == 0)
1180 port = 26000;
1181 if (sv_netport.integer != port)
1183 if (cls.state != ca_dedicated)
1185 if (opennetports)
1186 {
1187#ifndef NOSUPPORTIPV6
1190#else
1192#endif
1193 }
1194 if (sv_numsockets == 0)
1195 Host_Error("NetConn_OpenServerPorts: unable to open any ports!");
1196}
@ ca_dedicated
Definition client.h:530
void Host_Error(const char *error,...)
Definition host.c:85
void NetConn_CloseServerPorts(void)
Definition netconn.c:1121
static qbool NetConn_OpenServerPort(const char *addressstring, lhnetaddresstype_t addresstype, int defaultport, int range)
Definition netconn.c:1128
bool qbool
Definition qtypes.h:9

References bound, ca_dedicated, cls, Crypto_LoadKeys(), Cvar_SetValueQuick(), Host_Error(), cvar_t::integer, LHNETADDRESSTYPE_INET4, LHNETADDRESSTYPE_INET6, LHNETADDRESSTYPE_LOOP, net_address, net_address_ipv6, NetConn_CloseServerPorts(), NetConn_OpenServerPort(), NetConn_UpdateSockets(), NULL, client_static_t::state, cvar_t::string, SV_LockThreadMutex, sv_netport, sv_numsockets, and SV_UnlockThreadMutex.

Referenced by Log_DestBuffer_Flush_NoLock(), and SV_SpawnServer().

◆ NetConn_Read()

int NetConn_Read ( lhnetsocket_t * mysocket,
void * data,
int maxlength,
lhnetaddress_t * peeraddress )

Definition at line 726 of file netconn.c.

727{
728 int length;
729 unsigned i;
730
733 length = LHNET_Read(mysocket, data, maxlength, peeraddress);
736 if (length == 0)
737 return 0;
739 for (i = 0;i < cl_numsockets;i++)
740 if (cl_sockets[i] == mysocket && (rand() % 100) < net_fakeloss_receive.integer)
741 return 0;
743 {
744 char addressstring[128], addressstring2[128];
745 LHNETADDRESS_ToString(LHNET_AddressFromSocket(mysocket), addressstring, sizeof(addressstring), true);
746 if (length > 0)
747 {
748 LHNETADDRESS_ToString(peeraddress, addressstring2, sizeof(addressstring2), true);
749 Con_Printf("LHNET_Read(%p (%s), %p, %i, %p) = %i from %s:\n", (void *)mysocket, addressstring, (void *)data, maxlength, (void *)peeraddress, length, addressstring2);
750 Com_HexDumpToConsole((unsigned char *)data, length);
751 }
752 else
753 Con_Printf("LHNET_Read(%p (%s), %p, %i, %p) = %i\n", (void *)mysocket, addressstring, (void *)data, maxlength, (void *)peeraddress, length);
754 }
755 return length;
756}
void Com_HexDumpToConsole(const unsigned char *data, int size)
Definition common.c:82
GLsizeiptr const GLvoid * data
Definition glquake.h:639
int LHNET_Read(lhnetsocket_t *lhnetsocket, void *content, int maxcontentlength, lhnetaddress_t *vaddress)
Definition lhnet.c:1034
lhnetaddresstype_t addresstype
Definition lhnet.h:21
lhnetaddress_t address
Definition lhnet.h:45
#define Thread_LockMutex(m)
Definition thread.h:17
#define Thread_UnlockMutex(m)
Definition thread.h:18

References lhnetsocket_t::address, lhnetaddress_t::addresstype, cl_numsockets, cl_sockets, Com_HexDumpToConsole(), Con_Printf(), data, developer_networking, i, cvar_t::integer, length, LHNET_AddressFromSocket(), LHNET_Read(), LHNETADDRESS_ToString(), LHNETADDRESSTYPE_LOOP, net_fakeloss_receive, netconn_mutex, Thread_LockMutex, and Thread_UnlockMutex.

Referenced by NetConn_ClientFrame(), and NetConn_ServerFrame().

◆ NetConn_SendUnreliableMessage()

int NetConn_SendUnreliableMessage ( netconn_t * conn,
sizebuf_t * data,
protocolversion_t protocol,
int rate,
int burstsize,
qbool quakesignon_suppressreliables )

Definition at line 844 of file netconn.c.

845{
846 int totallen = 0;
847 unsigned char sendbuffer[NET_HEADERSIZE+NET_MAXMESSAGE];
848 unsigned char cryptosendbuffer[NET_HEADERSIZE+NET_MAXMESSAGE+CRYPTO_HEADERSIZE];
849
850 // if this packet was supposedly choked, but we find ourselves sending one
851 // anyway, make sure the size counting starts at zero
852 // (this mostly happens on level changes and disconnects and such)
855
857
858 if (protocol == PROTOCOL_QUAKEWORLD)
859 {
860 int packetLen;
861 qbool sendreliable;
862
863 // note that it is ok to send empty messages to the qw server,
864 // otherwise it won't respond to us at all
865
866 sendreliable = false;
867 // if the remote side dropped the last reliable message, resend it
869 sendreliable = true;
870 // if the reliable transmit buffer is empty, copy the current message out
871 if (!conn->sendMessageLength && conn->message.cursize)
872 {
873 memcpy (conn->sendMessage, conn->message.data, conn->message.cursize);
874 conn->sendMessageLength = conn->message.cursize;
875 SZ_Clear(&conn->message); // clear the message buffer
876 conn->qw.reliable_sequence ^= 1;
877 sendreliable = true;
878 }
879 // outgoing unreliable packet number, and outgoing reliable packet number (0 or 1)
880 StoreLittleLong(sendbuffer, conn->outgoing_unreliable_sequence | (((unsigned int)sendreliable)<<31));
881 // last received unreliable packet number, and last received reliable packet number (0 or 1)
882 StoreLittleLong(sendbuffer + 4, conn->qw.incoming_sequence | (((unsigned int)conn->qw.incoming_reliable_sequence)<<31));
883 packetLen = 8;
885 // client sends qport in every packet
886 if (conn == cls.netcon)
887 {
888 *((short *)(sendbuffer + 8)) = LittleShort(cls.qw_qport);
889 packetLen += 2;
890 // also update cls.qw_outgoing_sequence
892 }
893 if (packetLen + (sendreliable ? conn->sendMessageLength : 0) > 1400)
894 {
895 Con_Printf ("NetConn_SendUnreliableMessage: reliable message too big %u\n", data->cursize);
896 return -1;
897 }
898
899 conn->outgoing_netgraph[conn->outgoing_packetcounter].unreliablebytes += packetLen + 28;
900
901 // add the reliable message if there is one
902 if (sendreliable)
903 {
905 memcpy(sendbuffer + packetLen, conn->sendMessage, conn->sendMessageLength);
906 packetLen += conn->sendMessageLength;
908 }
909
910 // add the unreliable message if possible
911 if (packetLen + data->cursize <= 1400)
912 {
913 conn->outgoing_netgraph[conn->outgoing_packetcounter].unreliablebytes += data->cursize + 28;
914 memcpy(sendbuffer + packetLen, data->data, data->cursize);
915 packetLen += data->cursize;
916 }
917
918 NetConn_Write(conn->mysocket, (void *)&sendbuffer, packetLen, &conn->peeraddress);
919
920 conn->packetsSent++;
922
923 totallen += packetLen + 28;
924 }
925 else
926 {
927 unsigned int packetLen;
928 unsigned int dataLen;
929 unsigned int eom;
930 const void *sendme;
931 size_t sendmelen;
932
933 // if a reliable message fragment has been lost, send it again
934 if (conn->sendMessageLength && (host.realtime - conn->lastSendTime) > 1.0)
935 {
937 {
938 dataLen = conn->sendMessageLength;
939 eom = NETFLAG_EOM;
940 }
941 else
942 {
943 dataLen = MAX_PACKETFRAGMENT;
944 eom = 0;
945 }
946
947 packetLen = NET_HEADERSIZE + dataLen;
948
949 StoreBigLong(sendbuffer, packetLen | (NETFLAG_DATA | eom | NetConn_AddCryptoFlag(&conn->crypto)));
950 StoreBigLong(sendbuffer + 4, conn->nq.sendSequence - 1);
951 memcpy(sendbuffer + NET_HEADERSIZE, conn->sendMessage, dataLen);
952
953 conn->outgoing_netgraph[conn->outgoing_packetcounter].reliablebytes += packetLen + 28;
954
955 sendme = Crypto_EncryptPacket(&conn->crypto, &sendbuffer, packetLen, &cryptosendbuffer, &sendmelen, sizeof(cryptosendbuffer));
956 if (sendme && NetConn_Write(conn->mysocket, sendme, (int)sendmelen, &conn->peeraddress) == (int)sendmelen)
957 {
958 conn->lastSendTime = host.realtime;
959 conn->packetsReSent++;
960 }
961
962 totallen += (int)sendmelen + 28;
963 }
964
965 // if we have a new reliable message to send, do so
966 if (!conn->sendMessageLength && conn->message.cursize && !quakesignon_suppressreliables)
967 {
968 if (conn->message.cursize > (int)sizeof(conn->sendMessage))
969 {
970 Con_Printf("NetConn_SendUnreliableMessage: reliable message too big (%u > %u)\n", conn->message.cursize, (int)sizeof(conn->sendMessage));
971 conn->message.overflowed = true;
972 return -1;
973 }
974
975 if (developer_networking.integer && conn == cls.netcon)
976 {
977 Con_Print("client sending reliable message to server:\n");
979 }
980
981 memcpy(conn->sendMessage, conn->message.data, conn->message.cursize);
982 conn->sendMessageLength = conn->message.cursize;
983 SZ_Clear(&conn->message);
984
986 {
987 dataLen = conn->sendMessageLength;
988 eom = NETFLAG_EOM;
989 }
990 else
991 {
992 dataLen = MAX_PACKETFRAGMENT;
993 eom = 0;
994 }
995
996 packetLen = NET_HEADERSIZE + dataLen;
997
998 StoreBigLong(sendbuffer, packetLen | (NETFLAG_DATA | eom | NetConn_AddCryptoFlag(&conn->crypto)));
999 StoreBigLong(sendbuffer + 4, conn->nq.sendSequence);
1000 memcpy(sendbuffer + NET_HEADERSIZE, conn->sendMessage, dataLen);
1001
1002 conn->nq.sendSequence++;
1003
1004 conn->outgoing_netgraph[conn->outgoing_packetcounter].reliablebytes += packetLen + 28;
1005
1006 sendme = Crypto_EncryptPacket(&conn->crypto, &sendbuffer, packetLen, &cryptosendbuffer, &sendmelen, sizeof(cryptosendbuffer));
1007 if(sendme)
1008 NetConn_Write(conn->mysocket, sendme, (int)sendmelen, &conn->peeraddress);
1009
1010 conn->lastSendTime = host.realtime;
1011 conn->packetsSent++;
1012 conn->reliableMessagesSent++;
1013
1014 totallen += (int)sendmelen + 28;
1015 }
1016
1017 // if we have an unreliable message to send, do so
1018 if (data->cursize)
1019 {
1020 packetLen = NET_HEADERSIZE + data->cursize;
1021
1022 if (packetLen > (int)sizeof(sendbuffer))
1023 {
1024 Con_Printf("NetConn_SendUnreliableMessage: message too big %u\n", data->cursize);
1025 return -1;
1026 }
1027
1028 StoreBigLong(sendbuffer, packetLen | NETFLAG_UNRELIABLE | NetConn_AddCryptoFlag(&conn->crypto));
1029 StoreBigLong(sendbuffer + 4, conn->outgoing_unreliable_sequence);
1030 memcpy(sendbuffer + NET_HEADERSIZE, data->data, data->cursize);
1031
1033
1034 conn->outgoing_netgraph[conn->outgoing_packetcounter].unreliablebytes += packetLen + 28;
1035
1036 sendme = Crypto_EncryptPacket(&conn->crypto, &sendbuffer, packetLen, &cryptosendbuffer, &sendmelen, sizeof(cryptosendbuffer));
1037 if(sendme)
1038 NetConn_Write(conn->mysocket, sendme, (int)sendmelen, &conn->peeraddress);
1039
1040 conn->packetsSent++;
1041 conn->unreliableMessagesSent++;
1042
1043 totallen += (int)sendmelen + 28;
1044 }
1045 }
1046
1047 NetConn_UpdateCleartime(&conn->cleartime, rate, burstsize, totallen);
1048
1049 return 0;
1050}
void StoreLittleLong(unsigned char *buffer, unsigned int i)
Encode a little endian 32bit int to the given buffer.
Definition com_msg.c:95
void SZ_HexDumpToConsole(const sizebuf_t *buf)
Definition common.c:148
@ PROTOCOL_QUAKEWORLD
quakeworld protocol
Definition common.h:145
#define LittleShort(l)
Definition common.h:90
void Con_Print(const char *msg)
Prints to all appropriate console targets, and adds timestamps.
Definition console.c:1504
const void * Crypto_EncryptPacket(crypto_t *crypto, const void *data_src, size_t len_src, void *data_dst, size_t *len_dst, size_t len)
Definition crypto.c:1527
#define CRYPTO_HEADERSIZE
Definition crypto.h:34
static int(ZEXPORT *qz_inflate)(z_stream *strm
static void NetConn_UpdateCleartime(double *cleartime, int rate, int burstsize, int len)
Definition netconn.c:806
static int NetConn_AddCryptoFlag(crypto_t *crypto)
Definition netconn.c:823
#define NETFLAG_EOM
Definition netconn.h:39
#define NETFLAG_UNRELIABLE
Definition netconn.h:40
#define NETFLAG_DATA
Definition netconn.h:36
#define MAX_PACKETFRAGMENT
max length of packet fragment
Definition qdefs.h:104
unsigned int qw_outgoing_sequence
Definition client.h:645
unsigned int sendSequence
Definition netconn.h:181
unsigned int last_reliable_sequence
sequence number of last send
Definition netconn.h:212
qbool incoming_reliable_sequence
single bit, maintained local
Definition netconn.h:209
unsigned int incoming_acknowledged
Definition netconn.h:206
qbool incoming_reliable_acknowledged
single bit
Definition netconn.h:207
unsigned int incoming_sequence
Definition netconn.h:205
qbool reliable_sequence
single bit
Definition netconn.h:211
double lastSendTime
Definition netconn.h:155
int packetsSent
Definition netconn.h:235
int reliableMessagesSent
Definition netconn.h:242
unsigned int outgoing_unreliable_sequence
used by both NQ and QW protocols
Definition netconn.h:176
int unreliableMessagesSent
Definition netconn.h:240
int sendMessageLength
reliable message that is currently sending (for building fragments)
Definition netconn.h:167
unsigned char sendMessage[NET_MAXMESSAGE]
Definition netconn.h:168
int packetsReSent
Definition netconn.h:236
struct netconn_t::netconn_qw_s qw
struct netconn_t::netconn_nq_s nq
crypto_t crypto
Definition netconn.h:232
qbool overflowed
set to true if the buffer size failed
Definition common.h:51

References netconn_t::cleartime, netgraphitem_t::cleartime, cls, Con_Print(), Con_Printf(), netconn_t::crypto, Crypto_EncryptPacket(), CRYPTO_HEADERSIZE, sizebuf_t::cursize, data, sizebuf_t::data, developer_networking, host, netconn_t::netconn_qw_s::incoming_acknowledged, netconn_t::netconn_qw_s::incoming_reliable_acknowledged, netconn_t::netconn_qw_s::incoming_reliable_sequence, netconn_t::netconn_qw_s::incoming_sequence, int(), cvar_t::integer, netconn_t::netconn_qw_s::last_reliable_sequence, netconn_t::lastSendTime, LittleShort, MAX_PACKETFRAGMENT, netconn_t::message, netconn_t::mysocket, NET_HEADERSIZE, NET_MAXMESSAGE, client_static_t::netcon, NetConn_AddCryptoFlag(), NetConn_UpdateCleartime(), NetConn_Write(), NETFLAG_DATA, NETFLAG_EOM, NETFLAG_UNRELIABLE, NETGRAPH_CHOKEDPACKET, NETGRAPH_NOPACKET, netconn_t::nq, netconn_t::outgoing_netgraph, netconn_t::outgoing_packetcounter, netconn_t::outgoing_unreliable_sequence, sizebuf_t::overflowed, netconn_t::packetsReSent, netconn_t::packetsSent, netconn_t::peeraddress, PROTOCOL_QUAKEWORLD, netconn_t::qw, client_static_t::qw_outgoing_sequence, client_static_t::qw_qport, host_static_t::realtime, netconn_t::netconn_qw_s::reliable_sequence, netgraphitem_t::reliablebytes, netconn_t::reliableMessagesSent, netconn_t::sendMessage, netconn_t::sendMessageLength, netconn_t::netconn_nq_s::sendSequence, StoreBigLong(), StoreLittleLong(), SZ_Clear(), SZ_HexDumpToConsole(), netgraphitem_t::unreliablebytes, and netconn_t::unreliableMessagesSent.

Referenced by CL_DisconnectEx(), CL_KeepaliveMessage(), CL_SendMove(), NetConn_ConnectionEstablished(), SV_DropClient(), and SV_SendClientDatagram().

◆ NetConn_ServerFrame()

void NetConn_ServerFrame ( void )

Definition at line 3861 of file netconn.c.

3862{
3863 unsigned i;
3864 int length;
3865 lhnetaddress_t peeraddress;
3866 unsigned char readbuffer[NET_HEADERSIZE+NET_MAXMESSAGE];
3867
3868 for (i = 0;i < sv_numsockets;i++)
3869 while (sv_sockets[i] && (length = NetConn_Read(sv_sockets[i], readbuffer, sizeof(readbuffer), &peeraddress)) > 0)
3870 NetConn_ServerParsePacket(sv_sockets[i], readbuffer, length, &peeraddress);
3871}
static int NetConn_ServerParsePacket(lhnetsocket_t *mysocket, unsigned char *data, int length, lhnetaddress_t *peeraddress)
Definition netconn.c:3193

References i, length, NET_HEADERSIZE, NET_MAXMESSAGE, NetConn_Read(), NetConn_ServerParsePacket(), sv_numsockets, and sv_sockets.

Referenced by SV_Frame(), and SV_ThreadFunc().

◆ NetConn_Shutdown()

void NetConn_Shutdown ( void )

Definition at line 4201 of file netconn.c.

4202{
4206 if (netconn_mutex)
4209}
void LHNET_Shutdown(void)
Definition lhnet.c:751
#define Thread_DestroyMutex(m)
Definition thread.h:16

References LHNET_Shutdown(), NetConn_CloseClientPorts(), NetConn_CloseServerPorts(), netconn_mutex, NULL, and Thread_DestroyMutex.

Referenced by Host_Shutdown().

◆ NetConn_UpdateSockets()

void NetConn_UpdateSockets ( void )

Definition at line 1306 of file netconn.c.

1307{
1308 int i, j;
1309
1310 // TODO add logic to automatically close sockets if needed
1312
1313 for (j = 0;j < MAX_RCONS;j++)
1314 {
1315 i = (cls.rcon_ringpos + j + 1) % MAX_RCONS;
1316 if(cls.rcon_commands[i][0])
1317 {
1319 {
1320 char s[128];
1321 LHNETADDRESS_ToString(&cls.rcon_addresses[i], s, sizeof(s), true);
1322 Con_Printf("rcon to %s (for command %s) failed: challenge request timed out\n", s, cls.rcon_commands[i]);
1323 cls.rcon_commands[i][0] = 0;
1324 --cls.rcon_trying;
1325 break;
1326 }
1327 }
1328 }
1329}
#define MAX_RCONS
Definition client.h:619
int LHNET_DefaultDSCP(int dscp)
Definition lhnet.c:739
lhnetaddress_t rcon_addresses[MAX_RCONS]
Definition client.h:621
double rcon_timeout[MAX_RCONS]
Definition client.h:623
char rcon_commands[MAX_RCONS][MAX_INPUTLINE]
Definition client.h:622

References cls, Con_Printf(), host, i, cvar_t::integer, LHNET_DefaultDSCP(), LHNETADDRESS_ToString(), MAX_RCONS, net_tos_dscp, client_static_t::rcon_addresses, client_static_t::rcon_commands, client_static_t::rcon_ringpos, client_static_t::rcon_timeout, client_static_t::rcon_trying, and host_static_t::realtime.

Referenced by CL_EstablishConnection(), CL_PlayDemo(), CL_StartVideo(), Host_Frame(), NetConn_ClientFrame(), and NetConn_OpenServerPorts().

◆ NetConn_Write()

int NetConn_Write ( lhnetsocket_t * mysocket,
const void * data,
int length,
const lhnetaddress_t * peeraddress )

Definition at line 758 of file netconn.c.

759{
760 int ret;
761 unsigned i;
762
764 for (i = 0;i < cl_numsockets;i++)
765 if (cl_sockets[i] == mysocket && (rand() % 100) < net_fakeloss_send.integer)
766 return length;
769 ret = LHNET_Write(mysocket, data, length, peeraddress);
773 {
774 char addressstring[128], addressstring2[128];
775 LHNETADDRESS_ToString(LHNET_AddressFromSocket(mysocket), addressstring, sizeof(addressstring), true);
776 LHNETADDRESS_ToString(peeraddress, addressstring2, sizeof(addressstring2), true);
777 Con_Printf("LHNET_Write(%p (%s), %p, %i, %p (%s)) = %i%s\n", (void *)mysocket, addressstring, (void *)data, length, (void *)peeraddress, addressstring2, length, ret == length ? "" : " (ERROR)");
778 Com_HexDumpToConsole((unsigned char *)data, length);
779 }
780 return ret;
781}
int LHNET_Write(lhnetsocket_t *lhnetsocket, const void *content, int contentlength, const lhnetaddress_t *vaddress)
Definition lhnet.c:1135
return ret

References lhnetsocket_t::address, lhnetaddress_t::addresstype, cl_numsockets, cl_sockets, Com_HexDumpToConsole(), Con_Printf(), data, developer_networking, i, cvar_t::integer, length, LHNET_AddressFromSocket(), LHNET_Write(), LHNETADDRESS_ToString(), LHNETADDRESSTYPE_LOOP, net_fakeloss_send, netconn_mutex, ret, Thread_LockMutex, and Thread_UnlockMutex.

Referenced by CL_Packet_f(), CL_PQRcon_f(), CL_Rcon_f(), Con_Rcon_Redirect_Flush(), NetConn_ClientFrame(), NetConn_ClientParsePacket(), NetConn_ReceivedMessage(), NetConn_SendUnreliableMessage(), NetConn_ServerParsePacket(), and NetConn_WriteString().

◆ NetConn_WriteString()

int NetConn_WriteString ( lhnetsocket_t * mysocket,
const char * string,
const lhnetaddress_t * peeraddress )

Definition at line 783 of file netconn.c.

784{
785 // note this does not include the trailing NULL because we add that in the parser
786 return NetConn_Write(mysocket, string, (int)strlen(string), peeraddress);
787}
float strlen(string s)

References NetConn_Write(), and strlen().

Referenced by CL_Rcon_f(), Log_DestBuffer_Flush_NoLock(), NetConn_ClientFrame(), NetConn_ClientParsePacket(), NetConn_Heartbeat(), and NetConn_ServerParsePacket().

Variable Documentation

◆ challenges

◆ cl_message

◆ cl_net_extresponse

char cl_net_extresponse[NET_EXTRESPONSE_MAX][1400]
extern

Definition at line 160 of file netconn.c.

Referenced by NetConn_ClientParsePacket(), and VM_CL_getextresponse().

◆ cl_net_extresponse_count

unsigned cl_net_extresponse_count
extern

Definition at line 161 of file netconn.c.

Referenced by NetConn_ClientParsePacket(), and VM_CL_getextresponse().

◆ cl_net_extresponse_last

unsigned cl_net_extresponse_last
extern

Definition at line 162 of file netconn.c.

Referenced by NetConn_ClientParsePacket(), and VM_CL_getextresponse().

◆ cl_netport

struct cvar_s cl_netport
extern

Definition at line 155 of file netconn.c.

155{CF_CLIENT, "cl_port", "0", "forces client to use chosen port number if not 0"};

Referenced by CL_DisconnectEx(), CL_Init(), NetConn_Init(), and NetConn_OpenClientPorts().

◆ cl_readstring

◆ developer_networking

struct cvar_s developer_networking
extern

Definition at line 89 of file netconn.c.

89{CF_CLIENT | CF_SERVER, "developer_networking", "0", "prints all received and sent packets (recommended only for debugging)"};

Referenced by Crypto_DecryptPacket(), Crypto_EncryptPacket(), NetConn_ClientParsePacket(), NetConn_Init(), NetConn_Read(), NetConn_SendUnreliableMessage(), NetConn_Write(), and SV_ReadClientMessage().

◆ hostname

struct cvar_s hostname
extern

Definition at line 88 of file netconn.c.

88{CF_SERVER | CF_ARCHIVE, "hostname", "UNNAMED", "server message to show in server browser"};
#define CF_ARCHIVE
cvar should have its set value saved to config.cfg and persist across sessions
Definition cmd.h:53

Referenced by M_GameOptions_Draw(), M_GameOptions_Key(), NetConn_BuildStatusResponse(), NetConn_Init(), NetConn_ServerParsePacket(), SV_Pause_f(), SV_Say(), SV_SpawnServer(), and SV_Tell_f().

◆ net_address

struct cvar_s net_address
extern

Definition at line 157 of file netconn.c.

157{CF_CLIENT | CF_SERVER, "net_address", "", "network address to open ipv4 ports on (if empty, use default interfaces)"};

Referenced by NetConn_Init(), NetConn_OpenClientPorts(), and NetConn_OpenServerPorts().

◆ net_address_ipv6

struct cvar_s net_address_ipv6
extern

Definition at line 158 of file netconn.c.

158{CF_CLIENT | CF_SERVER, "net_address_ipv6", "", "network address to open ipv6 ports on (if empty, use default interfaces)"};

Referenced by NetConn_Init(), NetConn_OpenClientPorts(), and NetConn_OpenServerPorts().

◆ net_burstreserve

struct cvar_s net_burstreserve
extern

Definition at line 80 of file netconn.c.

80{CF_SERVER, "net_burstreserve", "0.3", "how much of the burst time to reserve for packet size spikes"};

Referenced by NetConn_Init(), and SV_SendClientDatagram().

◆ net_fakelag

struct cvar_s net_fakelag
extern

Definition at line 91 of file netconn.c.

91{CF_CLIENT, "net_fakelag","0", "lags local loopback connection by this much ping time (useful to play more fairly on your own server with people with higher pings)"};

Referenced by LHNET_Read(), and NetConn_Init().

◆ net_usesizelimit

struct cvar_s net_usesizelimit
extern

Definition at line 79 of file netconn.c.

79{CF_SERVER, "net_usesizelimit", "2", "use packet size limiting (0: never, 1: in non-CSQC mode, 2: always)"};

Referenced by NetConn_Init(), and SV_SendClientDatagram().

◆ netconn_list

netconn_t* netconn_list
extern

Definition at line 151 of file netconn.c.

Referenced by Net_Stats_f(), NetConn_Close(), and NetConn_Open().

◆ netconn_mempool

struct mempool_s* netconn_mempool
extern

Definition at line 152 of file netconn.c.

Referenced by NetConn_Init(), and NetConn_Open().

◆ sv_message

◆ sv_net_extresponse

char sv_net_extresponse[NET_EXTRESPONSE_MAX][1400]
extern

Definition at line 164 of file netconn.c.

Referenced by NetConn_ServerParsePacket(), and VM_SV_getextresponse().

◆ sv_net_extresponse_count

unsigned sv_net_extresponse_count
extern

Definition at line 165 of file netconn.c.

Referenced by NetConn_ServerParsePacket(), and VM_SV_getextresponse().

◆ sv_net_extresponse_last

unsigned sv_net_extresponse_last
extern

Definition at line 166 of file netconn.c.

Referenced by NetConn_ServerParsePacket(), and VM_SV_getextresponse().

◆ sv_netport

struct cvar_s sv_netport
extern

Definition at line 156 of file netconn.c.

156{CF_SERVER, "port", "26000", "server port for players to connect to"};

Referenced by CL_Packet_f(), CL_PQRcon_f(), CL_Rcon_f(), M_LanConfig_Key(), NetConn_Init(), NetConn_OpenServerPorts(), and SV_Init().

◆ sv_public

struct cvar_s sv_public
extern

Definition at line 36 of file netconn.c.

36{CF_SERVER, "sv_public", "0", "1: advertises this server on the master server (so that players can find it in the server browser); 0: allow direct queries only; -1: do not respond to direct queries; -2: do not allow anyone to connect; -3: already block at getchallenge level"};

Referenced by Crypto_ServerParsePacket_Internal(), M_GameOptions_Draw(), M_NetStart_Change(), NetConn_Heartbeat(), NetConn_Init(), NetConn_ServerParsePacket(), and SV_ServerOptions().

◆ sv_readstring

char sv_readstring[MAX_INPUTLINE]
extern

Definition at line 76 of file netconn.c.

Referenced by NetConn_ServerParsePacket(), and SV_ReadClientMessage().