about summary refs log tree commit diff
path: root/src/engine/client
diff options
context:
space:
mode:
authoroy <Tom_Adams@web.de>2011-03-30 12:08:33 +0200
committeroy <Tom_Adams@web.de>2011-03-30 12:08:33 +0200
commit59d56cd332ecc86008c27326631566a4d2d94ecb (patch)
tree9e207d901bd93c86e9e98260479a57a9fef85faa /src/engine/client
parent693bd39e77ee91ec335d8e30350b57edca8056fd (diff)
downloadzcatch-59d56cd332ecc86008c27326631566a4d2d94ecb.tar.gz
zcatch-59d56cd332ecc86008c27326631566a4d2d94ecb.zip
finished IPv6 support (master servers aren't compatible with 0.5 and older). Closes #233
Diffstat (limited to 'src/engine/client')
-rw-r--r--src/engine/client/client.cpp35
-rw-r--r--src/engine/client/serverbrowser.cpp27
2 files changed, 27 insertions, 35 deletions
diff --git a/src/engine/client/client.cpp b/src/engine/client/client.cpp
index a39bfb5b..28c0fad4 100644
--- a/src/engine/client/client.cpp
+++ b/src/engine/client/client.cpp
@@ -698,7 +698,7 @@ void CClient::Connect(const char *pAddress)
 		char aBufMsg[256];
 		str_format(aBufMsg, sizeof(aBufMsg), "could not find the address of %s, connecting to localhost", aBuf);
 		m_pConsole->Print(IConsole::OUTPUT_LEVEL_STANDARD, "client", aBufMsg);
-		net_host_lookup("localhost", &m_ServerAddress, NETTYPE_IPV4);
+		net_host_lookup("localhost", &m_ServerAddress, NETTYPE_ALL);
 	}
 
 	m_RconAuthed = 0;
@@ -1052,34 +1052,31 @@ void CClient::ProcessConnlessPacket(CNetChunk *pPacket)
 		bool Valid = false;
 		for(int i = 0; i < IMasterServer::MAX_MASTERSERVERS; ++i)
 		{
-			NETADDR Addr = m_pMasterServer->GetAddr(i);
-			if(net_addr_comp(&pPacket->m_Address, &Addr) == 0)
+			if(m_pMasterServer->IsValid(i))
 			{
-				Valid = true;
-				break;
+				NETADDR Addr = m_pMasterServer->GetAddr(i);
+				if(net_addr_comp(&pPacket->m_Address, &Addr) == 0)
+				{
+					Valid = true;
+					break;
+				}
 			}
 		}
 		if(!Valid)
 			return;
 
 		int Size = pPacket->m_DataSize-sizeof(SERVERBROWSE_LIST);
-		int Num = Size/sizeof(MASTERSRV_ADDR);
-		MASTERSRV_ADDR *pAddrs = (MASTERSRV_ADDR *)((char*)pPacket->m_pData+sizeof(SERVERBROWSE_LIST));
-		int i;
-
-		for(i = 0; i < Num; i++)
+		int Num = Size/sizeof(CMastersrvAddr);
+		CMastersrvAddr *pAddrs = (CMastersrvAddr *)((char*)pPacket->m_pData+sizeof(SERVERBROWSE_LIST));
+		for(int i = 0; i < Num; i++)
 		{
 			NETADDR Addr;
 
-			// convert address
-			mem_zero(&Addr, sizeof(Addr));
-			Addr.type = NETTYPE_IPV4;
-			Addr.ip[0] = pAddrs[i].m_aIp[0];
-			Addr.ip[1] = pAddrs[i].m_aIp[1];
-			Addr.ip[2] = pAddrs[i].m_aIp[2];
-			Addr.ip[3] = pAddrs[i].m_aIp[3];
-			Addr.port = (pAddrs[i].m_aPort[1]<<8) | pAddrs[i].m_aPort[0];
-
+			// copy address
+			Addr.type = (pAddrs->m_aType[0]<<24) | (pAddrs->m_aType[1]<<16) | (pAddrs->m_aType[2]<<8) | pAddrs->m_aType[3];
+			mem_copy(Addr.ip, pAddrs->m_aIp, sizeof(Addr.ip));
+			Addr.port = (pAddrs->m_aPort[0]<<8) | pAddrs->m_aPort[1];
+			
 			m_ServerBrowser.Set(Addr, IServerBrowser::SET_MASTER_ADD, -1, 0x0);
 		}
 	}
diff --git a/src/engine/client/serverbrowser.cpp b/src/engine/client/serverbrowser.cpp
index 55d25f8a..36447922 100644
--- a/src/engine/client/serverbrowser.cpp
+++ b/src/engine/client/serverbrowser.cpp
@@ -380,15 +380,8 @@ CServerBrowser::CServerEntry *CServerBrowser::Add(const NETADDR &Addr)
 	pEntry->m_Info.m_NetAddr = Addr;
 
 	pEntry->m_Info.m_Latency = 999;
-	str_format(pEntry->m_Info.m_aAddress, sizeof(pEntry->m_Info.m_aAddress), "%d.%d.%d.%d:%d",
-		Addr.ip[0], Addr.ip[1], Addr.ip[2],
-		Addr.ip[3], Addr.port);
-	str_format(pEntry->m_Info.m_aName, sizeof(pEntry->m_Info.m_aName), "%d.%d.%d.%d:%d",
-		Addr.ip[0], Addr.ip[1], Addr.ip[2],
-		Addr.ip[3], Addr.port);
-
-	/*if(serverlist_type == IServerBrowser::TYPE_LAN)
-		pEntry->m_Info.latency = (time_get()-broadcast_time)*1000/time_freq();*/
+	net_addr_str(&Addr, pEntry->m_Info.m_aAddress, sizeof(pEntry->m_Info.m_aAddress));
+	str_copy(pEntry->m_Info.m_aName, pEntry->m_Info.m_aAddress, sizeof(pEntry->m_Info.m_aName));
 
 	// check if it's a favorite
 	for(i = 0; i < m_NumFavoriteServers; i++)
@@ -526,10 +519,10 @@ void CServerBrowser::RequestImpl(const NETADDR &Addr, CServerEntry *pEntry) cons
 
 	if(g_Config.m_Debug)
 	{
+		char aAddrStr[NETADDR_MAXSTRSIZE];
+		net_addr_str(&Addr, aAddrStr, sizeof(aAddrStr));
 		char aBuf[256];
-		str_format(aBuf, sizeof(aBuf),"requesting server info from %d.%d.%d.%d:%d",
-			Addr.ip[0], Addr.ip[1], Addr.ip[2],
-			Addr.ip[3], Addr.port);
+		str_format(aBuf, sizeof(aBuf),"requesting server info from %s", aAddrStr);
 		m_pConsole->Print(IConsole::OUTPUT_LEVEL_DEBUG, "client_srvbrowse", aBuf);
 	}
 
@@ -556,7 +549,7 @@ void CServerBrowser::Request(const NETADDR &Addr) const
 
 void CServerBrowser::Update(bool ForceResort)
 {
-	int64 Timeout = time_freq()/2;	// TODO 0.6: increase this again
+	int64 Timeout = time_freq();
 	int64 Now = time_get();
 	int Count;
 	CServerEntry *pEntry, *pNext;
@@ -578,10 +571,10 @@ void CServerBrowser::Update(bool ForceResort)
 
 		for(i = 0; i < IMasterServer::MAX_MASTERSERVERS; i++)
 		{
-			Addr = m_pMasterServer->GetAddr(i);
-			if(!Addr.ip[0] && !Addr.ip[1] && !Addr.ip[2] && !Addr.ip[3])
+			if(!m_pMasterServer->IsValid(i))
 				continue;
 
+			Addr = m_pMasterServer->GetAddr(i);
 			Packet.m_Address = Addr;
 			m_pNetClient->Send(&Packet);
 		}
@@ -667,8 +660,10 @@ void CServerBrowser::AddFavorite(const NETADDR &Addr)
 
     if(g_Config.m_Debug)
 	{
+		char aAddrStr[NETADDR_MAXSTRSIZE];
+		net_addr_str(&Addr, aAddrStr, sizeof(aAddrStr));
 		char aBuf[256];
-        str_format(aBuf, sizeof(aBuf), "added fav, %d.%d.%d.%d:%d", Addr.ip[0], Addr.ip[1], Addr.ip[2], Addr.ip[3], Addr.port);
+		str_format(aBuf, sizeof(aBuf), "added fav, %s", aAddrStr);
 		m_pConsole->Print(IConsole::OUTPUT_LEVEL_DEBUG, "client_srvbrowse", aBuf);
 	}
 }