MCPcopy Create free account
hub / github.com/ddnet/ddnet / ProcessClientPacket

Method ProcessClientPacket

src/engine/server/server.cpp:1636–1966  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1634}
1635
1636void CServer::ProcessClientPacket(CNetChunk *pPacket)
1637{
1638 int ClientId = pPacket->m_ClientId;
1639 CUnpacker Unpacker;
1640 Unpacker.Reset(pPacket->m_pData, pPacket->m_DataSize);
1641 CMsgPacker Packer(NETMSG_EX, true);
1642
1643 // unpack msgid and system flag
1644 int Msg;
1645 bool Sys;
1646 CUuid Uuid;
1647
1648 int Result = UnpackMessageId(&Msg, &Sys, &Uuid, &Unpacker, &Packer);
1649 if(Result == UNPACKMESSAGE_ERROR)
1650 {
1651 return;
1652 }
1653
1654 if(m_aClients[ClientId].m_Sixup && (Msg = MsgFromSixup(Msg, Sys)) < 0)
1655 {
1656 return;
1657 }
1658
1659 if(Config()->m_SvNetlimit && Msg != NETMSG_REQUEST_MAP_DATA)
1660 {
1661 int64_t Now = time_get();
1662 int64_t Diff = Now - m_aClients[ClientId].m_TrafficSince;
1663 double Alpha = Config()->m_SvNetlimitAlpha / 100.0;
1664 double Limit = (double)(Config()->m_SvNetlimit * 1024) / time_freq();
1665
1666 if(m_aClients[ClientId].m_Traffic > Limit)
1667 {
1668 m_NetServer.NetBan()->BanAddr(&pPacket->m_Address, 600, "Stressing network", false);
1669 return;
1670 }
1671 if(Diff > 100)
1672 {
1673 m_aClients[ClientId].m_Traffic = (Alpha * ((double)pPacket->m_DataSize / Diff)) + (1.0 - Alpha) * m_aClients[ClientId].m_Traffic;
1674 m_aClients[ClientId].m_TrafficSince = Now;
1675 }
1676 }
1677
1678 if(Result == UNPACKMESSAGE_ANSWER)
1679 {
1680 SendMsg(&Packer, MSGFLAG_VITAL, ClientId);
1681 }
1682
1683 {
1684 bool VitalFlag = (pPacket->m_Flags & NET_CHUNKFLAG_VITAL) != 0;
1685 bool NonVitalMsg = Sys && (Msg == NETMSG_INPUT || Msg == NETMSG_PING || Msg == NETMSG_PINGEX);
1686 if(!VitalFlag && !NonVitalMsg)
1687 {
1688 if(g_Config.m_Debug)
1689 {
1690 log_debug(
1691 "server",
1692 "strange message ClientId=%d msg=%d data_size=%d (missing vital flag)",
1693 ClientId,

Callers

nothing calls this directly

Calls 15

UnpackMessageIdFunction · 0.85
MsgFromSixupFunction · 0.85
time_getFunction · 0.85
time_freqFunction · 0.85
str_compFunction · 0.85
str_formatFunction · 0.85
mem_zeroFunction · 0.85
mem_compFunction · 0.85
mem_copyFunction · 0.85
str_hexFunction · 0.85
GetRawMethod · 0.80
NumNonDefaultKeysMethod · 0.80

Tested by

no test coverage detected