made bindaddr config work for client and master too. Closes #909

This commit is contained in:
oy 2012-01-06 19:17:14 +01:00
parent 78bb0e3d8c
commit 29738552a6
4 changed files with 36 additions and 23 deletions

View file

@ -1738,8 +1738,11 @@ void CClient::Run()
// open socket // open socket
{ {
NETADDR BindAddr; NETADDR BindAddr;
if(g_Config.m_Bindaddr[0] == 0 || net_host_lookup(g_Config.m_Bindaddr, &BindAddr, NETTYPE_ALL) != 0)
{
mem_zero(&BindAddr, sizeof(BindAddr)); mem_zero(&BindAddr, sizeof(BindAddr));
BindAddr.type = NETTYPE_ALL; BindAddr.type = NETTYPE_ALL;
}
if(!m_NetClient.Open(BindAddr, 0)) if(!m_NetClient.Open(BindAddr, 0))
{ {
dbg_msg("client", "couldn't start network"); dbg_msg("client", "couldn't start network");

View file

@ -1271,7 +1271,7 @@ int CServer::Run()
// start server // start server
NETADDR BindAddr; NETADDR BindAddr;
if(g_Config.m_SvBindaddr[0] && net_host_lookup(g_Config.m_SvBindaddr, &BindAddr, NETTYPE_ALL) == 0) if(g_Config.m_Bindaddr[0] && net_host_lookup(g_Config.m_Bindaddr, &BindAddr, NETTYPE_ALL) == 0)
{ {
// sweet! // sweet!
BindAddr.port = g_Config.m_SvPort; BindAddr.port = g_Config.m_SvPort;

View file

@ -77,7 +77,7 @@ MACRO_CONFIG_INT(GfxThreaded, gfx_threaded, 1, 0, 1, CFGFLAG_SAVE|CFGFLAG_CLIENT
MACRO_CONFIG_INT(InpMousesens, inp_mousesens, 100, 5, 100000, CFGFLAG_SAVE|CFGFLAG_CLIENT, "Mouse sensitivity") MACRO_CONFIG_INT(InpMousesens, inp_mousesens, 100, 5, 100000, CFGFLAG_SAVE|CFGFLAG_CLIENT, "Mouse sensitivity")
MACRO_CONFIG_STR(SvName, sv_name, 128, "unnamed server", CFGFLAG_SERVER, "Server name") MACRO_CONFIG_STR(SvName, sv_name, 128, "unnamed server", CFGFLAG_SERVER, "Server name")
MACRO_CONFIG_STR(SvBindaddr, sv_bindaddr, 128, "", CFGFLAG_SERVER, "Address to bind the server to") MACRO_CONFIG_STR(Bindaddr, bindaddr, 128, "", CFGFLAG_CLIENT|CFGFLAG_SERVER|CFGFLAG_MASTER, "Address to bind the client/server to")
MACRO_CONFIG_INT(SvPort, sv_port, 8303, 0, 0, CFGFLAG_SERVER, "Port to use for the server") MACRO_CONFIG_INT(SvPort, sv_port, 8303, 0, 0, CFGFLAG_SERVER, "Port to use for the server")
MACRO_CONFIG_INT(SvExternalPort, sv_external_port, 0, 0, 0, CFGFLAG_SERVER, "External port to report to the master servers") MACRO_CONFIG_INT(SvExternalPort, sv_external_port, 0, 0, 0, CFGFLAG_SERVER, "External port to report to the master servers")
MACRO_CONFIG_STR(SvMap, sv_map, 128, "dm1", CFGFLAG_SERVER, "Map to use on the server") MACRO_CONFIG_STR(SvMap, sv_map, 128, "dm1", CFGFLAG_SERVER, "Map to use on the server")

View file

@ -2,6 +2,7 @@
/* If you are missing that file, acquire a complete release at teeworlds.com. */ /* If you are missing that file, acquire a complete release at teeworlds.com. */
#include <base/system.h> #include <base/system.h>
#include <engine/config.h>
#include <engine/console.h> #include <engine/console.h>
#include <engine/kernel.h> #include <engine/kernel.h>
#include <engine/storage.h> #include <engine/storage.h>
@ -326,16 +327,40 @@ int main(int argc, const char **argv) // ignore_convention
dbg_logger_stdout(); dbg_logger_stdout();
net_init(); net_init();
mem_copy(m_CountData.m_Header, SERVERBROWSE_COUNT, sizeof(SERVERBROWSE_COUNT));
mem_copy(m_CountDataLegacy.m_Header, SERVERBROWSE_COUNT_LEGACY, sizeof(SERVERBROWSE_COUNT_LEGACY));
IKernel *pKernel = IKernel::Create();
IStorage *pStorage = CreateStorage("Teeworlds", argc, argv);
IConfig *pConfig = CreateConfig();
m_pConsole = CreateConsole(CFGFLAG_MASTER);
bool RegisterFail = !pKernel->RegisterInterface(pStorage);
RegisterFail |= !pKernel->RegisterInterface(m_pConsole);
RegisterFail |= !pKernel->RegisterInterface(pConfig);
if(RegisterFail)
return -1;
pConfig->Init();
m_NetBan.Init(m_pConsole, pStorage);
if(argc > 1) // ignore_convention
m_pConsole->ParseArguments(argc-1, &argv[1]); // ignore_convention
if(g_Config.m_Bindaddr[0] && net_host_lookup(g_Config.m_Bindaddr, &BindAddr, NETTYPE_ALL) == 0)
BindAddr.port = MASTERSERVER_PORT;
else
{
mem_zero(&BindAddr, sizeof(BindAddr)); mem_zero(&BindAddr, sizeof(BindAddr));
BindAddr.type = NETTYPE_ALL; BindAddr.type = NETTYPE_ALL;
BindAddr.port = MASTERSERVER_PORT; BindAddr.port = MASTERSERVER_PORT;
}
if(!m_NetOp.Open(BindAddr, 0)) if(!m_NetOp.Open(BindAddr, 0))
{ {
dbg_msg("mastersrv", "couldn't start network (op)"); dbg_msg("mastersrv", "couldn't start network (op)");
return -1; return -1;
} }
BindAddr.port = MASTERSERVER_PORT+1; BindAddr.port = MASTERSERVER_PORT+1;
if(!m_NetChecker.Open(BindAddr, 0)) if(!m_NetChecker.Open(BindAddr, 0))
{ {
@ -343,21 +368,6 @@ int main(int argc, const char **argv) // ignore_convention
return -1; return -1;
} }
mem_copy(m_CountData.m_Header, SERVERBROWSE_COUNT, sizeof(SERVERBROWSE_COUNT));
mem_copy(m_CountDataLegacy.m_Header, SERVERBROWSE_COUNT_LEGACY, sizeof(SERVERBROWSE_COUNT_LEGACY));
IKernel *pKernel = IKernel::Create();
IStorage *pStorage = CreateStorage("Teeworlds", argc, argv);
m_pConsole = CreateConsole(CFGFLAG_MASTER);
m_NetBan.Init(m_pConsole, pStorage);
bool RegisterFail = !pKernel->RegisterInterface(pStorage);
RegisterFail |= !pKernel->RegisterInterface(m_pConsole);
if(RegisterFail)
return -1;
dbg_msg("mastersrv", "started"); dbg_msg("mastersrv", "started");
while(1) while(1)