I think this will get the nq networking going

This commit is contained in:
Bill Currie 2001-11-24 08:19:34 +00:00
parent 405e8fffc9
commit e97a4b7ce7
7 changed files with 73 additions and 28 deletions

View file

@ -26,6 +26,11 @@
$Id$
*/
#ifndef __net_loop_h
#define __net_loop_h
#include "QF/qtypes.h"
#include "net.h"
int Loop_Init (void);
void Loop_Listen (qboolean state);
@ -39,3 +44,5 @@ qboolean Loop_CanSendMessage (qsocket_t *sock);
qboolean Loop_CanSendUnreliableMessage (qsocket_t *sock);
void Loop_Close (qsocket_t *sock);
void Loop_Shutdown (void);
#endif//__net_loop_h

View file

@ -26,6 +26,17 @@
$Id$
*/
#ifndef __net_wins_h
#define __net_wind_h
#include "winquake.h"
#include "QF/qtypes.h"
extern int winsock_initialized;
extern WSADATA winsockdata;
struct qsockaddr;
int WINS_Init (void);
void WINS_Shutdown (void);
@ -40,8 +51,10 @@ int WINS_Broadcast (int socket, byte *buf, int len);
const char *WINS_AddrToString (struct qsockaddr *addr);
int WINS_StringToAddr (const char *string, struct qsockaddr *addr);
int WINS_GetSocketAddr (int socket, struct qsockaddr *addr);
int WINS_GetNameFromAddr (struct qsockaddr *addr, const char *name);
int WINS_GetNameFromAddr (struct qsockaddr *addr, char *name);
int WINS_GetAddrFromName (const char *name, struct qsockaddr *addr);
int WINS_AddrCompare (struct qsockaddr *addr1, struct qsockaddr *addr2);
int WINS_GetSocketPort (struct qsockaddr *addr);
int WINS_SetSocketPort (struct qsockaddr *addr, int port);
#endif//__net_wins_h

View file

@ -26,6 +26,10 @@
$Id$
*/
#ifndef __net_wipx_h
#define __net_wipx_h
#include "net.h"
int WIPX_Init (void);
void WIPX_Shutdown (void);
@ -40,8 +44,10 @@ int WIPX_Broadcast (int socket, byte *buf, int len);
const char *WIPX_AddrToString (struct qsockaddr *addr);
int WIPX_StringToAddr (const char *string, struct qsockaddr *addr);
int WIPX_GetSocketAddr (int socket, struct qsockaddr *addr);
int WIPX_GetNameFromAddr (struct qsockaddr *addr, const char *name);
int WIPX_GetNameFromAddr (struct qsockaddr *addr, char *name);
int WIPX_GetAddrFromName (const char *name, struct qsockaddr *addr);
int WIPX_AddrCompare (struct qsockaddr *addr1, struct qsockaddr *addr2);
int WIPX_GetSocketPort (struct qsockaddr *addr);
int WIPX_SetSocketPort (struct qsockaddr *addr, int port);
#endif//__net_wipx_h

View file

@ -53,12 +53,16 @@ common_sources= game.c world.c com.c
common_ldflags= -export-dynamic
# ... Networking
libqfnet_la_SOURCES= net_bsd.c net_dgrm.c net_loop.c net_main.c net_udp.c \
net_vcr.c
if SYSTYPE_WIN32
net_sources= net_win.c net_wins.c
else
net_sources= net_bsd.c net_udp.c
endif
libqfnet_la_SOURCES= net_dgrm.c net_loop.c net_main.c net_vcr.c $(net_sources)
EXTRA_libqfnet_la_SOURCES= \
net_dos.c net_bw.c net_ipx.c net_mp.c net_win.c net_wins.c \
net_wipx.c
net_dos.c net_bw.c net_bsd.c net_ipx.c net_mp.c net_win.c net_wins.c \
net_wipx.c net_udp.c
client_LIBFILES= \
$(top_builddir)/libs/video/targets/libQFjs.la \

View file

@ -98,6 +98,7 @@ net_landriver_t net_landrivers[MAX_NET_DRIVERS] = {
WINS_AddrCompare,
WINS_GetSocketPort,
WINS_SetSocketPort},
#if 0
{
"Winsock IPX",
false,
@ -120,7 +121,7 @@ net_landriver_t net_landrivers[MAX_NET_DRIVERS] = {
WIPX_AddrCompare,
WIPX_GetSocketPort,
WIPX_SetSocketPort}
#endif
};
int net_numlandrivers = 2;

View file

@ -34,6 +34,14 @@ static const char rcsid[] =
#include "winquake.h"
#include "QF/console.h"
#include "QF/cvar.h"
#include "QF/qargs.h"
#include "QF/sys.h"
#include "compat.h"
#include "net.h"
#define MAXHOSTNAMELEN 256
static int net_acceptsocket = -1; // socket for fielding new
@ -149,7 +157,7 @@ WINS_Init (void)
hInst = LoadLibrary ("wsock32.dll");
if (hInst == NULL) {
Con_SafePrintf ("Failed to load winsock.dll\n");
Con_Printf ("Failed to load winsock.dll\n");
winsock_lib_initialized = false;
return -1;
}
@ -174,7 +182,7 @@ WINS_Init (void)
!psocket || !pioctlsocket || !psetsockopt ||
!precvfrom || !psendto || !pclosesocket ||
!pgethostname || !pgethostbyname || !pgethostbyaddr || !pgetsockname) {
Con_SafePrintf ("Couldn't GetProcAddress from winsock.dll\n");
Con_Printf ("Couldn't GetProcAddress from winsock.dll\n");
return -1;
}
@ -187,7 +195,7 @@ WINS_Init (void)
r = pWSAStartup (MAKEWORD (1, 1), &winsockdata);
if (r) {
Con_SafePrintf ("Winsock initialization failed.\n");
Con_Printf ("Winsock initialization failed.\n");
return -1;
}
}
@ -201,7 +209,7 @@ WINS_Init (void)
return -1;
}
// if the quake hostname isn't set, set it to the machine name
if (Q_strcmp (hostname->string, "UNNAMED") == 0) {
if (strcmp (hostname->string, "UNNAMED") == 0) {
// see if it's a text IP address (well, close enough)
for (p = buff; *p; p++)
if ((*p < '0' || *p > '9') && *p != '.')
@ -330,7 +338,7 @@ the local network components to fill in the rest
============
*/
static int
PartialIPAddress (char *in, struct qsockaddr *hostaddr)
PartialIPAddress (const char *in, struct qsockaddr *hostaddr)
{
char buff[256];
char *b;
@ -366,7 +374,7 @@ PartialIPAddress (char *in, struct qsockaddr *hostaddr)
}
if (*b++ == ':')
port = Q_atoi (b);
port = atoi (b);
else
port = net_hostport;
@ -413,9 +421,9 @@ WINS_Read (int socket, byte * buf, int len, struct qsockaddr *addr)
ret = precvfrom (socket, buf, len, 0, (struct sockaddr *) addr, &addrlen);
if (ret == -1) {
int errno = pWSAGetLastError ();
int err = pWSAGetLastError ();
if (errno == WSAEWOULDBLOCK || errno == WSAECONNREFUSED)
if (err == WSAEWOULDBLOCK || err == WSAECONNREFUSED)
return 0;
}
@ -479,7 +487,7 @@ WINS_Write (int socket, byte * buf, int len, struct qsockaddr *addr)
//=============================================================================
char *
const char *
WINS_AddrToString (struct qsockaddr *addr)
{
static char buffer[22];
@ -495,7 +503,7 @@ WINS_AddrToString (struct qsockaddr *addr)
//=============================================================================
int
WINS_StringToAddr (char *string, struct qsockaddr *addr)
WINS_StringToAddr (const char *string, struct qsockaddr *addr)
{
int ha1, ha2, ha3, ha4, hp;
int ipaddr;
@ -517,7 +525,7 @@ WINS_GetSocketAddr (int socket, struct qsockaddr *addr)
int addrlen = sizeof (struct qsockaddr);
unsigned int a;
Q_memset (addr, 0, sizeof (struct qsockaddr));
memset (addr, 0, sizeof (struct qsockaddr));
pgetsockname (socket, (struct sockaddr *) addr, &addrlen);
a = ((struct sockaddr_in *) addr)->sin_addr.s_addr;
@ -539,18 +547,18 @@ WINS_GetNameFromAddr (struct qsockaddr *addr, char *name)
sizeof (struct in_addr), AF_INET);
if (hostentry) {
Q_strncpy (name, (char *) hostentry->h_name, NET_NAMELEN - 1);
strncpy (name, (char *) hostentry->h_name, NET_NAMELEN - 1);
return 0;
}
Q_strcpy (name, WINS_AddrToString (addr));
strcpy (name, WINS_AddrToString (addr));
return 0;
}
//=============================================================================
int
WINS_GetAddrFromName (char *name, struct qsockaddr *addr)
WINS_GetAddrFromName (const char *name, struct qsockaddr *addr)
{
struct hostent *hostentry;

View file

@ -33,6 +33,12 @@ static const char rcsid[] =
#include "winquake.h"
#include <wsipx.h>
#include "QF/console.h"
#include "QF/cvar.h"
#include "QF/qargs.h"
#include "net_wins.h"
#include "net_wipx.h"
#define MAXHOSTNAMELEN 256
@ -85,7 +91,7 @@ WIPX_Init (void)
// determine my name & address
if (pgethostname (buff, MAXHOSTNAMELEN) == 0) {
// if the quake hostname isn't set, set it to the machine name
if (Q_strcmp (hostname->string, "UNNAMED") == 0) {
if (strcmp (hostname->string, "UNNAMED") == 0) {
// see if it's a text IP address (well, close enough)
for (p = buff; *p; p++)
if ((*p < '0' || *p > '9') && *p != '.')
@ -118,8 +124,8 @@ WIPX_Init (void)
htons ((unsigned short) net_hostport);
WIPX_GetSocketAddr (net_controlsocket, &addr);
Q_strcpy (my_ipx_address, WIPX_AddrToString (&addr));
p = Q_strrchr (my_ipx_address, ':');
strcpy (my_ipx_address, WIPX_AddrToString (&addr));
p = strrchr (my_ipx_address, ':');
if (p)
*p = 0;
@ -338,7 +344,7 @@ WIPX_StringToAddr (char *string, struct qsockaddr *addr)
char buf[3];
buf[2] = 0;
Q_memset (addr, 0, sizeof (struct qsockaddr));
memset (addr, 0, sizeof (struct qsockaddr));
addr->sa_family = AF_IPX;
@ -376,7 +382,7 @@ WIPX_GetSocketAddr (int handle, struct qsockaddr *addr)
int addrlen = sizeof (struct qsockaddr);
unsigned int a;
Q_memset (addr, 0, sizeof (struct qsockaddr));
memset (addr, 0, sizeof (struct qsockaddr));
if (pgetsockname (socket, (struct sockaddr *) addr, &addrlen) != 0) {
int errno = pWSAGetLastError ();
@ -390,7 +396,7 @@ WIPX_GetSocketAddr (int handle, struct qsockaddr *addr)
int
WIPX_GetNameFromAddr (struct qsockaddr *addr, char *name)
{
Q_strcpy (name, WIPX_AddrToString (addr));
strcpy (name, WIPX_AddrToString (addr));
return 0;
}
@ -402,7 +408,7 @@ WIPX_GetAddrFromName (char *name, struct qsockaddr *addr)
int n;
char buf[32];
n = Q_strlen (name);
n = strlen (name);
if (n == 12) {
snprintf (buf, sizeof (buf), "00000000:%s:%u", name, net_hostport);