*/
#include "quakedef.h"
+#include "thread.h"
#include "lhnet.h"
// for secure rcon authentication
netconn_t *netconn_list = NULL;
mempool_t *netconn_mempool = NULL;
+void *netconn_mutex = NULL;
cvar_t cl_netport = {0, "cl_port", "0", "forces client to use chosen port number if not 0"};
cvar_t sv_netport = {0, "port", "26000", "server port for players to connect to"};
int NetConn_Read(lhnetsocket_t *mysocket, void *data, int maxlength, lhnetaddress_t *peeraddress)
{
- int length = LHNET_Read(mysocket, data, maxlength, peeraddress);
+ int length;
int i;
+ if (mysocket->address.addresstype == LHNETADDRESSTYPE_LOOP && netconn_mutex)
+ Thread_LockMutex(netconn_mutex);
+ length = LHNET_Read(mysocket, data, maxlength, peeraddress);
+ if (mysocket->address.addresstype == LHNETADDRESSTYPE_LOOP && netconn_mutex)
+ Thread_UnlockMutex(netconn_mutex);
if (length == 0)
return 0;
if (cl_netpacketloss_receive.integer)
for (i = 0;i < cl_numsockets;i++)
if (cl_sockets[i] == mysocket && (rand() % 100) < cl_netpacketloss_send.integer)
return length;
+ if (mysocket->address.addresstype == LHNETADDRESSTYPE_LOOP && netconn_mutex)
+ Thread_LockMutex(netconn_mutex);
ret = LHNET_Write(mysocket, data, length, peeraddress);
+ if (mysocket->address.addresstype == LHNETADDRESSTYPE_LOOP && netconn_mutex)
+ Thread_UnlockMutex(netconn_mutex);
if (developer_networking.integer)
{
char addressstring[128], addressstring2[128];
if(l)
{
client_t *host_client_save = host_client;
- Cmd_ExecuteString(s, src_command);
+ Cmd_ExecuteString(s, src_command, true);
host_client = host_client_save;
// in case it is a command that changes host_client (like restart)
}
net_message.maxsize = sizeof(net_message_buf);
net_message.cursize = 0;
LHNET_Init();
+ if (Thread_HasThreads())
+ netconn_mutex = Thread_CreateMutex();
}
void NetConn_Shutdown(void)
NetConn_CloseClientPorts();
NetConn_CloseServerPorts();
LHNET_Shutdown();
+ if (netconn_mutex)
+ Thread_DestroyMutex(netconn_mutex);
+ netconn_mutex = NULL;
}