more versatile disconnect reasons

This commit is contained in:
ac-stef
2017-06-27 15:15:21 +02:00
parent 1ca4ce54eb
commit 25deee5287
8 changed files with 58 additions and 23 deletions
+37
View File
@@ -438,3 +438,40 @@ int msgsizelookup(int msg)
return msg >= 0 && msg < SV_NUM ? sizetable[msg] : -1;
}
const char *disc_reason(int reason)
{
static const char *prot[] = { "terminated by enet", "end of packet", "client num", "tag type", "duplicate connection", "overflow", "random", "voodoo", "sync" },
*refused[] = { "connection refused", "due to ban", "due to blacklisting", "wrong password", "server FULL", "server mastermode is \"private\"" },
*removed[] = { "removed from server", "failed admin login", "inappropriate nickname", "annoyance limit exceeded", "SPAM", "DOS", "ludicrous speed", "fishslapped", "afk" },
*kick[] = { "kicked", "banned", "kicked by vote", "banned by vote", "kicked by server operator", "banned by server operator",
"auto kicked - teamkilling", "auto banned - teamkilling", "auto kicked - friendly fire", "auto banned - friendly fire", "auto kick", "auto ban" };
static string res;
const int prot_n = constarraysize(prot), ref_n = constarraysize(refused), rem_n = constarraysize(removed), kick_n = constarraysize(kick);
if(reason >= DISC_PROTOCOL && reason < DISC_REFUSED)
{ // protocol related errors
if(reason < DISC_PROTOCOL + prot_n) return prot[reason];
else formatstring(res)("network protocol error '%d'", reason);
}
else if(reason >= DISC_REFUSED && reason < DISC_REMOVED)
{ // connection refused
if(reason < DISC_REFUSED + ref_n) return refused[reason - DISC_REFUSED];
else formatstring(res)("connection refused '%d'", reason);
}
else if(reason >= DISC_REMOVED && reason < DISC_KICK)
{ // player removed from server
if(reason < DISC_REMOVED + rem_n) return removed[reason - DISC_REMOVED];
else formatstring(res)("removed from server '%d'", reason);
}
else if(reason >= DISC_KICK && reason < DISC_UNKNOWN)
{ // kicks & bans
reason -= DISC_KICK;
if(reason < kick_n) return kick[reason];
else formatstring(res)("%s '%d'", reason & 1 ? "banned" : "kicked", reason + DISC_KICK);
}
else
{ // unknown reasons
formatstring(res)("unknown '%d'", reason);
}
return res;
}