diff options
| author | oy <Tom_Adams@web.de> | 2011-03-28 20:11:28 +0200 |
|---|---|---|
| committer | oy <Tom_Adams@web.de> | 2011-03-28 20:11:28 +0200 |
| commit | 34a9ca20a75db36d63549a8a9dfe2cc5e21f338d (patch) | |
| tree | c183c859ea5c61f332c01dc95fd29ddb6c900fe0 /src/engine | |
| parent | 63d2019b1913f6d467901022d460edfea62b2c6f (diff) | |
| download | zcatch-34a9ca20a75db36d63549a8a9dfe2cc5e21f338d.tar.gz zcatch-34a9ca20a75db36d63549a8a9dfe2cc5e21f338d.zip | |
added ipv6 support from the old lua branch
Diffstat (limited to 'src/engine')
| -rw-r--r-- | src/engine/client/client.cpp | 28 | ||||
| -rw-r--r-- | src/engine/client/serverbrowser.cpp | 6 | ||||
| -rw-r--r-- | src/engine/server.h | 2 | ||||
| -rw-r--r-- | src/engine/server/server.cpp | 51 | ||||
| -rw-r--r-- | src/engine/server/server.h | 2 | ||||
| -rw-r--r-- | src/engine/serverbrowser.h | 2 | ||||
| -rw-r--r-- | src/engine/shared/network_client.cpp | 10 | ||||
| -rw-r--r-- | src/engine/shared/network_server.cpp | 2 |
8 files changed, 54 insertions, 49 deletions
diff --git a/src/engine/client/client.cpp b/src/engine/client/client.cpp index 198f5f1a..a39bfb5b 100644 --- a/src/engine/client/client.cpp +++ b/src/engine/client/client.cpp @@ -692,20 +692,8 @@ void CClient::Connect(const char *pAddress) m_pConsole->Print(IConsole::OUTPUT_LEVEL_STANDARD, "client", aBuf); ServerInfoRequest(); - str_copy(aBuf, m_aServerAddressStr, sizeof(aBuf)); - for(int k = 0; aBuf[k]; k++) - { - if(aBuf[k] == ':') - { - Port = str_toint(aBuf+k+1); - aBuf[k] = 0; - break; - } - } - - // TODO: IPv6 support - if(net_host_lookup(aBuf, &m_ServerAddress, NETTYPE_IPV4) != 0) + if(net_host_lookup(m_aServerAddressStr, &m_ServerAddress, NETTYPE_ALL) != 0) { char aBufMsg[256]; str_format(aBufMsg, sizeof(aBufMsg), "could not find the address of %s, connecting to localhost", aBuf); @@ -714,7 +702,8 @@ void CClient::Connect(const char *pAddress) } m_RconAuthed = 0; - m_ServerAddress.port = Port; + if(m_ServerAddress.port == 0) + m_ServerAddress.port = Port; m_NetClient.Connect(&m_ServerAddress); SetState(IClient::STATE_CONNECTING); @@ -1119,9 +1108,7 @@ void CClient::ProcessConnlessPacket(CNetChunk *pPacket) Info.m_NumPlayers < 0 || Info.m_NumPlayers > Info.m_NumClients || Info.m_MaxPlayers < 0 || Info.m_MaxPlayers > Info.m_MaxClients) return; - str_format(Info.m_aAddress, sizeof(Info.m_aAddress), "%d.%d.%d.%d:%d", - pPacket->m_Address.ip[0], pPacket->m_Address.ip[1], pPacket->m_Address.ip[2], - pPacket->m_Address.ip[3], pPacket->m_Address.port); + net_addr_str(&pPacket->m_Address, Info.m_aAddress, sizeof(Info.m_aAddress)); for(int i = 0; i < Info.m_NumClients; i++) { @@ -1868,7 +1855,12 @@ void CClient::Run() { NETADDR BindAddr; mem_zero(&BindAddr, sizeof(BindAddr)); - m_NetClient.Open(BindAddr, 0); + BindAddr.type = NETTYPE_ALL; + if(!m_NetClient.Open(BindAddr, 0)) + { + dbg_msg("client", "couldn't start network"); + return; + } } // connect to the server if wanted diff --git a/src/engine/client/serverbrowser.cpp b/src/engine/client/serverbrowser.cpp index d4efe975..55d25f8a 100644 --- a/src/engine/client/serverbrowser.cpp +++ b/src/engine/client/serverbrowser.cpp @@ -492,12 +492,10 @@ void CServerBrowser::Refresh(int Type) mem_copy(Buffer, SERVERBROWSE_GETINFO, sizeof(SERVERBROWSE_GETINFO)); Buffer[sizeof(SERVERBROWSE_GETINFO)] = m_CurrentToken; + /* do the broadcast version */ Packet.m_ClientID = -1; mem_zero(&Packet, sizeof(Packet)); - Packet.m_Address.ip[0] = 255; - Packet.m_Address.ip[1] = 255; - Packet.m_Address.ip[2] = 255; - Packet.m_Address.ip[3] = 255; + Packet.m_Address.type = NETTYPE_ALL|NETTYPE_LINK_BROADCAST; Packet.m_Flags = NETSENDFLAG_CONNLESS; Packet.m_DataSize = sizeof(Buffer); Packet.m_pData = Buffer; diff --git a/src/engine/server.h b/src/engine/server.h index 7e11d865..c8e55110 100644 --- a/src/engine/server.h +++ b/src/engine/server.h @@ -30,7 +30,7 @@ public: virtual int ClientCountry(int ClientID) = 0; virtual bool ClientIngame(int ClientID) = 0; virtual int GetClientInfo(int ClientID, CClientInfo *pInfo) = 0; - virtual void GetClientIP(int ClientID, char *pIPString, int Size) = 0; + virtual void GetClientAddr(int ClientID, char *pAddrStr, int Size) = 0; virtual int *LatestInput(int ClientID, int *pSize) = 0; virtual int SendMsg(CMsgPacker *pMsg, int Flags, int ClientID) = 0; diff --git a/src/engine/server/server.cpp b/src/engine/server/server.cpp index c3ba583b..f1d2e6e1 100644 --- a/src/engine/server/server.cpp +++ b/src/engine/server/server.cpp @@ -333,12 +333,13 @@ int CServer::GetClientInfo(int ClientID, CClientInfo *pInfo) return 0; } -void CServer::GetClientIP(int ClientID, char *pIPString, int Size) +void CServer::GetClientAddr(int ClientID, char *pAddrStr, int Size) { if(ClientID >= 0 && ClientID < MAX_CLIENTS && m_aClients[ClientID].m_State == CClient::STATE_INGAME) { NETADDR Addr = m_NetServer.ClientAddr(ClientID); - str_format(pIPString, Size, "%d.%d.%d.%d", Addr.ip[0], Addr.ip[1], Addr.ip[2], Addr.ip[3]); + Addr.port = 0; + net_addr_str(&Addr, pAddrStr, Size); } } @@ -587,12 +588,10 @@ int CServer::DelClientCallback(int ClientID, const char *pReason, void *pUser) CServer *pThis = (CServer *)pUser; NETADDR Addr = pThis->m_NetServer.ClientAddr(ClientID); + char aAddrStr[NETADDR_MAXSTRSIZE]; + net_addr_str(&Addr, aAddrStr, sizeof(aAddrStr)); char aBuf[256]; - str_format(aBuf, sizeof(aBuf), "client dropped. cid=%d ip=%d.%d.%d.%d reason=\"%s\"", - ClientID, - Addr.ip[0], Addr.ip[1], Addr.ip[2], Addr.ip[3], - pReason - ); + str_format(aBuf, sizeof(aBuf), "client dropped. cid=%d addr=%s reason='%s'", ClientID, aAddrStr, pReason); pThis->Console()->Print(IConsole::OUTPUT_LEVEL_ADDINFO, "server", aBuf); // notify the mod about the drop @@ -732,10 +731,11 @@ void CServer::ProcessClientPacket(CNetChunk *pPacket) if(m_aClients[ClientID].m_State == CClient::STATE_CONNECTING) { Addr = m_NetServer.ClientAddr(ClientID); + char aAddrStr[NETADDR_MAXSTRSIZE]; + net_addr_str(&Addr, aAddrStr, sizeof(aAddrStr)); char aBuf[256]; - str_format(aBuf, sizeof(aBuf), "player is ready. ClientID=%x ip=%d.%d.%d.%d", - ClientID, Addr.ip[0], Addr.ip[1], Addr.ip[2], Addr.ip[3]); + str_format(aBuf, sizeof(aBuf), "player is ready. ClientID=%x addr=%s", ClientID, aAddrStr); Console()->Print(IConsole::OUTPUT_LEVEL_ADDINFO, "server", aBuf); m_aClients[ClientID].m_State = CClient::STATE_READY; GameServer()->OnClientConnected(ClientID); @@ -747,10 +747,11 @@ void CServer::ProcessClientPacket(CNetChunk *pPacket) if(m_aClients[ClientID].m_State == CClient::STATE_READY && GameServer()->IsClientReady(ClientID)) { Addr = m_NetServer.ClientAddr(ClientID); + char aAddrStr[NETADDR_MAXSTRSIZE]; + net_addr_str(&Addr, aAddrStr, sizeof(aAddrStr)); char aBuf[256]; - str_format(aBuf, sizeof(aBuf), "player has entered the game. ClientID=%x ip=%d.%d.%d.%d", - ClientID, Addr.ip[0], Addr.ip[1], Addr.ip[2], Addr.ip[3]); + str_format(aBuf, sizeof(aBuf), "player has entered the game. ClientID=%x addr=%s", ClientID, aAddrStr); Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "server", aBuf); m_aClients[ClientID].m_State = CClient::STATE_INGAME; GameServer()->OnClientEnter(ClientID); @@ -1102,9 +1103,8 @@ int CServer::Run() } // start server - // TODO: IPv6 support NETADDR BindAddr; - if(g_Config.m_SvBindaddr[0] && net_host_lookup(g_Config.m_SvBindaddr, &BindAddr, NETTYPE_IPV4) == 0) + if(g_Config.m_SvBindaddr[0] && net_host_lookup(g_Config.m_SvBindaddr, &BindAddr, NETTYPE_ALL) == 0) { // sweet! BindAddr.port = g_Config.m_SvPort; @@ -1112,6 +1112,7 @@ int CServer::Run() else { mem_zero(&BindAddr, sizeof(BindAddr)); + BindAddr.type = NETTYPE_ALL; BindAddr.port = g_Config.m_SvPort; } @@ -1342,8 +1343,11 @@ void CServer::ConUnban(IConsole::IResult *pResult, void *pUser) if(net_addr_from_str(&Addr, pStr) == 0 && !pServer->BanRemove(Addr)) { + char aAddrStr[NETADDR_MAXSTRSIZE]; + net_addr_str(&Addr, aAddrStr, sizeof(aAddrStr)); + char aBuf[256]; - str_format(aBuf, sizeof(aBuf), "unbanned %d.%d.%d.%d", Addr.ip[0], Addr.ip[1], Addr.ip[2], Addr.ip[3]); + str_format(aBuf, sizeof(aBuf), "unbanned %s", aAddrStr); pServer->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "server", aBuf); } else if(StrAllnum(pStr)) @@ -1354,8 +1358,11 @@ void CServer::ConUnban(IConsole::IResult *pResult, void *pUser) pServer->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "server", "invalid ban index"); else if(!pServer->BanRemove(Info.m_Addr)) { + char aAddrStr[NETADDR_MAXSTRSIZE]; + net_addr_str(&Info.m_Addr, aAddrStr, sizeof(aAddrStr)); + char aBuf[256]; - str_format(aBuf, sizeof(aBuf), "unbanned %d.%d.%d.%d", Info.m_Addr.ip[0], Info.m_Addr.ip[1], Info.m_Addr.ip[2], Info.m_Addr.ip[3]); + str_format(aBuf, sizeof(aBuf), "unbanned %s", aAddrStr); pServer->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "server", aBuf); } } @@ -1367,6 +1374,7 @@ void CServer::ConBans(IConsole::IResult *pResult, void *pUser) { unsigned Now = time_timestamp(); char aBuf[1024]; + char aAddrStr[NETADDR_MAXSTRSIZE]; CServer* pServer = (CServer *)pUser; int Num = pServer->m_NetServer.BanNum(); @@ -1375,15 +1383,16 @@ void CServer::ConBans(IConsole::IResult *pResult, void *pUser) CNetServer::CBanInfo Info; pServer->m_NetServer.BanGet(i, &Info); NETADDR Addr = Info.m_Addr; + net_addr_str(&Addr, aAddrStr, sizeof(aAddrStr)); if(Info.m_Expires == -1) { - str_format(aBuf, sizeof(aBuf), "#%d %d.%d.%d.%d for life", i, Addr.ip[0], Addr.ip[1], Addr.ip[2], Addr.ip[3]); + str_format(aBuf, sizeof(aBuf), "#%s for life", i, aAddrStr); } else { unsigned t = Info.m_Expires - Now; - str_format(aBuf, sizeof(aBuf), "#%d %d.%d.%d.%d for %d minutes and %d seconds", i, Addr.ip[0], Addr.ip[1], Addr.ip[2], Addr.ip[3], t/60, t%60); + str_format(aBuf, sizeof(aBuf), "#%s for %d minutes and %d seconds", i, aAddrStr, t/60, t%60); } pServer->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "Server", aBuf); } @@ -1396,6 +1405,7 @@ void CServer::ConStatus(IConsole::IResult *pResult, void *pUser) int i; NETADDR Addr; char aBuf[1024]; + char aAddrStr[NETADDR_MAXSTRSIZE]; CServer* pServer = (CServer *)pUser; for(i = 0; i < MAX_CLIENTS; i++) @@ -1403,13 +1413,12 @@ void CServer::ConStatus(IConsole::IResult *pResult, void *pUser) if(pServer->m_aClients[i].m_State != CClient::STATE_EMPTY) { Addr = pServer->m_NetServer.ClientAddr(i); + net_addr_str(&Addr, aAddrStr, sizeof(aAddrStr)); if(pServer->m_aClients[i].m_State == CClient::STATE_INGAME) - str_format(aBuf, sizeof(aBuf), "id=%d addr=%d.%d.%d.%d:%d name='%s' score=%d", - i, Addr.ip[0], Addr.ip[1], Addr.ip[2], Addr.ip[3], Addr.port, + str_format(aBuf, sizeof(aBuf), "id=%d addr=%s name='%s' score=%d", i, aAddrStr, pServer->m_aClients[i].m_aName, pServer->m_aClients[i].m_Score); else - str_format(aBuf, sizeof(aBuf), "id=%d addr=%d.%d.%d.%d:%d connecting", - i, Addr.ip[0], Addr.ip[1], Addr.ip[2], Addr.ip[3], Addr.port); + str_format(aBuf, sizeof(aBuf), "id=%d addr=%s connecting", i, aAddrStr); pServer->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "Server", aBuf); } } diff --git a/src/engine/server/server.h b/src/engine/server/server.h index 848b485a..00c1c648 100644 --- a/src/engine/server/server.h +++ b/src/engine/server/server.h @@ -141,7 +141,7 @@ public: bool IsAuthed(int ClientID); int GetClientInfo(int ClientID, CClientInfo *pInfo); - void GetClientIP(int ClientID, char *pIPString, int Size); + void GetClientAddr(int ClientID, char *pAddrStr, int Size); const char *ClientName(int ClientID); const char *ClientClan(int ClientID); int ClientCountry(int ClientID); diff --git a/src/engine/serverbrowser.h b/src/engine/serverbrowser.h index f0310421..1ac22056 100644 --- a/src/engine/serverbrowser.h +++ b/src/engine/serverbrowser.h @@ -44,7 +44,7 @@ public: char m_aName[64]; char m_aMap[32]; char m_aVersion[32]; - char m_aAddress[24]; + char m_aAddress[NETADDR_MAXSTRSIZE]; CClient m_aClients[MAX_CLIENTS]; }; diff --git a/src/engine/shared/network_client.cpp b/src/engine/shared/network_client.cpp index d3adfd20..82a09474 100644 --- a/src/engine/shared/network_client.cpp +++ b/src/engine/shared/network_client.cpp @@ -5,11 +5,17 @@ bool CNetClient::Open(NETADDR BindAddr, int Flags) { + // open socket + NETSOCKET Socket; + Socket = net_udp_create(BindAddr); + if(!Socket.type) + return false; + // clean it mem_zero(this, sizeof(*this)); - // open socket - m_Socket = net_udp_create(BindAddr); + // init + m_Socket = Socket; m_Connection.Init(m_Socket); return true; } diff --git a/src/engine/shared/network_server.cpp b/src/engine/shared/network_server.cpp index 3b5ef317..88aac789 100644 --- a/src/engine/shared/network_server.cpp +++ b/src/engine/shared/network_server.cpp @@ -33,7 +33,7 @@ bool CNetServer::Open(NETADDR BindAddr, int MaxClients, int MaxClientsPerIP, int // open socket m_Socket = net_udp_create(BindAddr); - if(m_Socket == NETSOCKET_INVALID) + if(!m_Socket.type) return false; // clamp clients |