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

Method BanExt

src/engine/server/server.cpp:69–129  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

67
68template<class T>
69int CServerBan::BanExt(T *pBanPool, const typename T::CDataType *pData, int Seconds, const char *pReason, bool VerbatimReason)
70{
71 // validate address
72 if(Server()->m_RconClientId >= 0 && Server()->m_RconClientId < MAX_CLIENTS &&
73 Server()->m_aClients[Server()->m_RconClientId].m_State != CServer::CClient::STATE_EMPTY)
74 {
75 if(NetMatch(pData, Server()->ClientAddr(Server()->m_RconClientId)))
76 {
77 Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "net_ban", "ban error (you can't ban yourself)");
78 return -1;
79 }
80
81 for(int i = 0; i < MAX_CLIENTS; ++i)
82 {
83 if(i == Server()->m_RconClientId || Server()->m_aClients[i].m_State == CServer::CClient::STATE_EMPTY)
84 continue;
85
86 if(Server()->GetAuthedState(i) >= Server()->m_RconAuthLevel && NetMatch(pData, Server()->ClientAddr(i)))
87 {
88 Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "net_ban", "ban error (command denied)");
89 return -1;
90 }
91 }
92 }
93 else if(Server()->m_RconClientId == IServer::RCON_CID_VOTE)
94 {
95 for(int i = 0; i < MAX_CLIENTS; ++i)
96 {
97 if(Server()->m_aClients[i].m_State == CServer::CClient::STATE_EMPTY)
98 continue;
99
100 if(Server()->IsRconAuthed(i) && NetMatch(pData, Server()->ClientAddr(i)))
101 {
102 Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "net_ban", "ban error (command denied)");
103 return -1;
104 }
105 }
106 }
107
108 int Result = Ban(pBanPool, pData, Seconds, pReason, VerbatimReason);
109 if(Result != 0)
110 return Result;
111
112 // drop banned clients
113 typename T::CDataType Data = *pData;
114 for(int i = 0; i < MAX_CLIENTS; ++i)
115 {
116 if(Server()->m_aClients[i].m_State == CServer::CClient::STATE_EMPTY)
117 continue;
118
119 if(NetMatch(&Data, Server()->ClientAddr(i)))
120 {
121 CNetHash NetHash(&Data);
122 char aBuf[256];
123 MakeBanInfo(pBanPool->Find(&Data, &NetHash), aBuf, sizeof(aBuf), MSGTYPE_PLAYER);
124 Server()->m_NetServer.Drop(i, aBuf);
125 }
126 }

Callers

nothing calls this directly

Calls 8

BanClass · 0.85
GetAuthedStateMethod · 0.80
IsRconAuthedMethod · 0.80
ServerClass · 0.50
ClientAddrMethod · 0.45
PrintMethod · 0.45
FindMethod · 0.45
DropMethod · 0.45

Tested by

no test coverage detected