summaryrefslogtreecommitdiff
path: root/src/net_sdl.c
diff options
context:
space:
mode:
authorSimon Howard2006-05-11 12:03:02 +0000
committerSimon Howard2006-05-11 12:03:02 +0000
commitff6493e0efe1c7ea628d8a6b596f915d9c9764e1 (patch)
tree6e4644187d3506c65c21104e0923a1b4a46bdfa3 /src/net_sdl.c
parent7d37b373ee43b8d509d9eae882a18bf6744db15c (diff)
downloadchocolate-doom-ff6493e0efe1c7ea628d8a6b596f915d9c9764e1.tar.gz
chocolate-doom-ff6493e0efe1c7ea628d8a6b596f915d9c9764e1.tar.bz2
chocolate-doom-ff6493e0efe1c7ea628d8a6b596f915d9c9764e1.zip
Allow port to be specified for client to connect to through -port or
-connect hostname:port. Subversion-branch: /trunk/chocolate-doom Subversion-revision: 479
Diffstat (limited to 'src/net_sdl.c')
-rw-r--r--src/net_sdl.c41
1 files changed, 37 insertions, 4 deletions
diff --git a/src/net_sdl.c b/src/net_sdl.c
index 25e79677..da74f525 100644
--- a/src/net_sdl.c
+++ b/src/net_sdl.c
@@ -1,7 +1,7 @@
// Emacs style mode select -*- C++ -*-
//-----------------------------------------------------------------------------
//
-// $Id: net_sdl.c 467 2006-04-09 02:50:34Z fraggle $
+// $Id: net_sdl.c 479 2006-05-11 12:03:02Z fraggle $
//
// Copyright(C) 2005 Simon Howard
//
@@ -172,6 +172,12 @@ static void NET_SDL_FreeAddress(net_addr_t *addr)
static boolean NET_SDL_InitClient(void)
{
+ int p;
+
+ p = M_CheckParm("-port");
+ if (p > 0)
+ port = atoi(myargv[p+1]);
+
SDLNet_Init();
udpsocket = SDLNet_UDP_Open(0);
@@ -298,15 +304,42 @@ void NET_SDL_AddrToString(net_addr_t *addr, char *buffer, int buffer_len)
net_addr_t *NET_SDL_ResolveAddress(char *address)
{
IPaddress ip;
+ char *addr_hostname;
+ int addr_port;
+ int result;
+ char *colon;
+
+ colon = strchr(address, ':');
+
+ if (colon != NULL)
+ {
+ addr_hostname = strdup(address);
+ addr_hostname[colon - address] = '\0';
+ addr_port = atoi(colon + 1);
+ }
+ else
+ {
+ addr_hostname = address;
+ addr_port = port;
+ }
- if (SDLNet_ResolveHost(&ip, address, port))
+ result = SDLNet_ResolveHost(&ip, addr_hostname, addr_port);
+
+ if (addr_hostname != address)
+ {
+ free(addr_hostname);
+ }
+
+ if (result)
{
// unable to resolve
return NULL;
}
-
- return NET_SDL_FindAddress(&ip);
+ else
+ {
+ return NET_SDL_FindAddress(&ip);
+ }
}
// Complete module