Add ChatFilter2, OverheadChat, EventGreeting and update several plugins
New plugins: ChatFilter2, OverheadChat, EventGreeting. Updated: HostnameManager, Leader3 (chat and markers), NameFilter2 (plugin and config), PlayerRankings_nohlstats (rank display modes), custom-chatcolors (plugin and ccc.inc), Extend (sm_settimeleft). Add shared includes the plugins build against: Break, ChatFilter2, Couch, EventNotifier, TransmitManager, leader, ripext, unloze_playtime.
This commit is contained in:
@@ -0,0 +1,582 @@
|
|||||||
|
"ChatFilter2"
|
||||||
|
{
|
||||||
|
// a message containing any of these is hidden from players with "Hiding Lennies" on.
|
||||||
|
// key = the character or substring (raw UTF-8), value unused
|
||||||
|
"lennies"
|
||||||
|
{
|
||||||
|
"°" ""
|
||||||
|
"ಠ" ""
|
||||||
|
"⚆" ""
|
||||||
|
"ʖ" ""
|
||||||
|
"͡" ""
|
||||||
|
"͜" ""
|
||||||
|
}
|
||||||
|
|
||||||
|
// ASCII digits/symbols read as letters when matching bad words ("sh1t", "$hit", "a$$").
|
||||||
|
// key = one ASCII digit or symbol, value = the letter it stands for.
|
||||||
|
// symbols at the start or end of a word may also just be punctuation ("shit!"),
|
||||||
|
// so words are tried both with and without them
|
||||||
|
"leet"
|
||||||
|
{
|
||||||
|
"4" "a"
|
||||||
|
"@" "a"
|
||||||
|
"3" "e"
|
||||||
|
"1" "i"
|
||||||
|
"!" "i"
|
||||||
|
"|" "i"
|
||||||
|
"0" "o"
|
||||||
|
"5" "s"
|
||||||
|
"$" "s"
|
||||||
|
"7" "t"
|
||||||
|
}
|
||||||
|
|
||||||
|
// non-ASCII lookalikes read as ASCII letters when matching bad words.
|
||||||
|
// key = one character (raw UTF-8), value = one ASCII letter (case does not matter).
|
||||||
|
// any other non-ASCII character splits words. Lookalikes copied from NameFilter2.cfg
|
||||||
|
"confusables"
|
||||||
|
{
|
||||||
|
// Cyrillic lowercase
|
||||||
|
"а" "a"
|
||||||
|
"е" "e"
|
||||||
|
"о" "o"
|
||||||
|
"р" "p"
|
||||||
|
"с" "c"
|
||||||
|
"у" "y"
|
||||||
|
"х" "x"
|
||||||
|
"і" "i"
|
||||||
|
"ѕ" "s"
|
||||||
|
"ј" "j"
|
||||||
|
// Cyrillic uppercase
|
||||||
|
"А" "A"
|
||||||
|
"В" "B"
|
||||||
|
"Е" "E"
|
||||||
|
"К" "K"
|
||||||
|
"М" "M"
|
||||||
|
"Н" "H"
|
||||||
|
"О" "O"
|
||||||
|
"Р" "P"
|
||||||
|
"С" "C"
|
||||||
|
"Т" "T"
|
||||||
|
"Х" "X"
|
||||||
|
"Ѕ" "S"
|
||||||
|
"І" "I"
|
||||||
|
"Ј" "J"
|
||||||
|
"У" "Y"
|
||||||
|
"З" "3"
|
||||||
|
// Cyrillic mirrored/aesthetic lookalikes
|
||||||
|
"Я" "R"
|
||||||
|
"я" "r"
|
||||||
|
"И" "N"
|
||||||
|
"и" "n"
|
||||||
|
"в" "b"
|
||||||
|
"к" "k"
|
||||||
|
"м" "m"
|
||||||
|
"н" "h"
|
||||||
|
"т" "t"
|
||||||
|
// Cyrillic with diacritics, same lookalikes as their base letters
|
||||||
|
"Ѐ" "E"
|
||||||
|
"Ё" "E"
|
||||||
|
"ѐ" "e"
|
||||||
|
"ё" "e"
|
||||||
|
"Ї" "I"
|
||||||
|
"ї" "i"
|
||||||
|
"Ў" "Y"
|
||||||
|
"ў" "y"
|
||||||
|
"Ѝ" "N"
|
||||||
|
"Й" "N"
|
||||||
|
"ѝ" "n"
|
||||||
|
"й" "n"
|
||||||
|
// Greek
|
||||||
|
"Α" "A"
|
||||||
|
"Β" "B"
|
||||||
|
"Ε" "E"
|
||||||
|
"Ζ" "Z"
|
||||||
|
"Η" "H"
|
||||||
|
"Ι" "I"
|
||||||
|
"Κ" "K"
|
||||||
|
"Μ" "M"
|
||||||
|
"Ν" "N"
|
||||||
|
"Ο" "O"
|
||||||
|
"Ρ" "P"
|
||||||
|
"Τ" "T"
|
||||||
|
"Υ" "Y"
|
||||||
|
"Χ" "X"
|
||||||
|
"α" "a"
|
||||||
|
"ν" "v"
|
||||||
|
"ο" "o"
|
||||||
|
// Greek with tonos/dialytika, same lookalikes as their base letters
|
||||||
|
"Ά" "A"
|
||||||
|
"Έ" "E"
|
||||||
|
"Ή" "H"
|
||||||
|
"Ί" "I"
|
||||||
|
"Ϊ" "I"
|
||||||
|
"Ό" "O"
|
||||||
|
"Ύ" "Y"
|
||||||
|
"Ϋ" "Y"
|
||||||
|
"Ώ" "O"
|
||||||
|
"ά" "a"
|
||||||
|
"ή" "n"
|
||||||
|
"ό" "o"
|
||||||
|
"ώ" "w"
|
||||||
|
// Greek aesthetic lookalikes
|
||||||
|
"Λ" "A"
|
||||||
|
"Σ" "E"
|
||||||
|
"Δ" "A"
|
||||||
|
"Ω" "O"
|
||||||
|
"Θ" "O"
|
||||||
|
"θ" "o"
|
||||||
|
"μ" "u"
|
||||||
|
"ω" "w"
|
||||||
|
"η" "n"
|
||||||
|
// math symbols used as letters
|
||||||
|
"∂" "d"
|
||||||
|
"∑" "E"
|
||||||
|
// accented Latin, read as the base letter
|
||||||
|
"À" "a"
|
||||||
|
"Á" "a"
|
||||||
|
"Â" "a"
|
||||||
|
"Ã" "a"
|
||||||
|
"Ä" "a"
|
||||||
|
"Å" "a"
|
||||||
|
"Ç" "c"
|
||||||
|
"È" "e"
|
||||||
|
"É" "e"
|
||||||
|
"Ê" "e"
|
||||||
|
"Ë" "e"
|
||||||
|
"Ì" "i"
|
||||||
|
"Í" "i"
|
||||||
|
"Î" "i"
|
||||||
|
"Ï" "i"
|
||||||
|
"Ñ" "n"
|
||||||
|
"Ò" "o"
|
||||||
|
"Ó" "o"
|
||||||
|
"Ô" "o"
|
||||||
|
"Õ" "o"
|
||||||
|
"Ö" "o"
|
||||||
|
"Ù" "u"
|
||||||
|
"Ú" "u"
|
||||||
|
"Û" "u"
|
||||||
|
"Ü" "u"
|
||||||
|
"Ý" "y"
|
||||||
|
"à" "a"
|
||||||
|
"á" "a"
|
||||||
|
"â" "a"
|
||||||
|
"ã" "a"
|
||||||
|
"ä" "a"
|
||||||
|
"å" "a"
|
||||||
|
"ç" "c"
|
||||||
|
"è" "e"
|
||||||
|
"é" "e"
|
||||||
|
"ê" "e"
|
||||||
|
"ë" "e"
|
||||||
|
"ì" "i"
|
||||||
|
"í" "i"
|
||||||
|
"î" "i"
|
||||||
|
"ï" "i"
|
||||||
|
"ñ" "n"
|
||||||
|
"ò" "o"
|
||||||
|
"ó" "o"
|
||||||
|
"ô" "o"
|
||||||
|
"õ" "o"
|
||||||
|
"ö" "o"
|
||||||
|
"ù" "u"
|
||||||
|
"ú" "u"
|
||||||
|
"û" "u"
|
||||||
|
"ü" "u"
|
||||||
|
"ý" "y"
|
||||||
|
"ÿ" "y"
|
||||||
|
"Ā" "a"
|
||||||
|
"ā" "a"
|
||||||
|
"Ă" "a"
|
||||||
|
"ă" "a"
|
||||||
|
"Ą" "a"
|
||||||
|
"ą" "a"
|
||||||
|
"Ć" "c"
|
||||||
|
"ć" "c"
|
||||||
|
"Ĉ" "c"
|
||||||
|
"ĉ" "c"
|
||||||
|
"Ċ" "c"
|
||||||
|
"ċ" "c"
|
||||||
|
"Č" "c"
|
||||||
|
"č" "c"
|
||||||
|
"Ď" "d"
|
||||||
|
"ď" "d"
|
||||||
|
"Ē" "e"
|
||||||
|
"ē" "e"
|
||||||
|
"Ĕ" "e"
|
||||||
|
"ĕ" "e"
|
||||||
|
"Ė" "e"
|
||||||
|
"ė" "e"
|
||||||
|
"Ę" "e"
|
||||||
|
"ę" "e"
|
||||||
|
"Ě" "e"
|
||||||
|
"ě" "e"
|
||||||
|
"Ĝ" "g"
|
||||||
|
"ĝ" "g"
|
||||||
|
"Ğ" "g"
|
||||||
|
"ğ" "g"
|
||||||
|
"Ġ" "g"
|
||||||
|
"ġ" "g"
|
||||||
|
"Ģ" "g"
|
||||||
|
"ģ" "g"
|
||||||
|
"Ĥ" "h"
|
||||||
|
"ĥ" "h"
|
||||||
|
"Ĩ" "i"
|
||||||
|
"ĩ" "i"
|
||||||
|
"Ī" "i"
|
||||||
|
"ī" "i"
|
||||||
|
"Ĭ" "i"
|
||||||
|
"ĭ" "i"
|
||||||
|
"Į" "i"
|
||||||
|
"į" "i"
|
||||||
|
"İ" "i"
|
||||||
|
"Ĵ" "j"
|
||||||
|
"ĵ" "j"
|
||||||
|
"Ķ" "k"
|
||||||
|
"ķ" "k"
|
||||||
|
"Ĺ" "l"
|
||||||
|
"ĺ" "l"
|
||||||
|
"Ļ" "l"
|
||||||
|
"ļ" "l"
|
||||||
|
"Ľ" "l"
|
||||||
|
"ľ" "l"
|
||||||
|
"Ń" "n"
|
||||||
|
"ń" "n"
|
||||||
|
"Ņ" "n"
|
||||||
|
"ņ" "n"
|
||||||
|
"Ň" "n"
|
||||||
|
"ň" "n"
|
||||||
|
"Ō" "o"
|
||||||
|
"ō" "o"
|
||||||
|
"Ŏ" "o"
|
||||||
|
"ŏ" "o"
|
||||||
|
"Ő" "o"
|
||||||
|
"ő" "o"
|
||||||
|
"Ŕ" "r"
|
||||||
|
"ŕ" "r"
|
||||||
|
"Ŗ" "r"
|
||||||
|
"ŗ" "r"
|
||||||
|
"Ř" "r"
|
||||||
|
"ř" "r"
|
||||||
|
"Ś" "s"
|
||||||
|
"ś" "s"
|
||||||
|
"Ŝ" "s"
|
||||||
|
"ŝ" "s"
|
||||||
|
"Ş" "s"
|
||||||
|
"ş" "s"
|
||||||
|
"Š" "s"
|
||||||
|
"š" "s"
|
||||||
|
"Ţ" "t"
|
||||||
|
"ţ" "t"
|
||||||
|
"Ť" "t"
|
||||||
|
"ť" "t"
|
||||||
|
"Ũ" "u"
|
||||||
|
"ũ" "u"
|
||||||
|
"Ū" "u"
|
||||||
|
"ū" "u"
|
||||||
|
"Ŭ" "u"
|
||||||
|
"ŭ" "u"
|
||||||
|
"Ů" "u"
|
||||||
|
"ů" "u"
|
||||||
|
"Ű" "u"
|
||||||
|
"ű" "u"
|
||||||
|
"Ų" "u"
|
||||||
|
"ų" "u"
|
||||||
|
"Ŵ" "w"
|
||||||
|
"ŵ" "w"
|
||||||
|
"Ŷ" "y"
|
||||||
|
"ŷ" "y"
|
||||||
|
"Ÿ" "y"
|
||||||
|
"Ź" "z"
|
||||||
|
"ź" "z"
|
||||||
|
"Ż" "z"
|
||||||
|
"ż" "z"
|
||||||
|
"Ž" "z"
|
||||||
|
"ž" "z"
|
||||||
|
}
|
||||||
|
|
||||||
|
// bad words censored for players with safe chat on, one '*' per character.
|
||||||
|
// Each section below is a category; key = the word or phrase, value unused.
|
||||||
|
// Case-insensitive, leet and confusables are applied, and repeated letters match
|
||||||
|
// ("fuuuck" matches "fuck", but "as" does not match "ass").
|
||||||
|
// A plain word only matches a whole word. "*word*" also matches inside a word
|
||||||
|
// (censoring just that part), "word*" only at the start, "*word" only at the end.
|
||||||
|
// Entries with spaces are phrases: each word must be a whole word, in order, with any
|
||||||
|
// spaces or punctuation between them ("kill yourself" matches "KILL... yourself!!" but not
|
||||||
|
// "killyourself", which needs its own entry); '*' is allowed at the start of the first word
|
||||||
|
// and the end of the last.
|
||||||
|
// Words spelled out with one letter per word ("f u c k", "f.u.c.k") are joined and matched too.
|
||||||
|
// List built 2026-10-22 from 366k ZE chat lines (UNLOZE stats DB + 200 UNLOZE/NiDE SourceTV demos).
|
||||||
|
"words"
|
||||||
|
{
|
||||||
|
// slurs and hate
|
||||||
|
"slurs"
|
||||||
|
{
|
||||||
|
// n-word; "*nigg*" covers nigger/nigga/niggas and joined forms like "sandnigger"
|
||||||
|
"*nigg*" ""
|
||||||
|
"nig" ""
|
||||||
|
"nigs" ""
|
||||||
|
"niga" ""
|
||||||
|
"nigas" ""
|
||||||
|
"niger" ""
|
||||||
|
"nigers" ""
|
||||||
|
"nige" ""
|
||||||
|
"nignog*" ""
|
||||||
|
"negro" ""
|
||||||
|
"negros" ""
|
||||||
|
"negroes" ""
|
||||||
|
// homophobic
|
||||||
|
"*fag*" ""
|
||||||
|
"homo" ""
|
||||||
|
"homos" ""
|
||||||
|
"tranny" ""
|
||||||
|
"trannies" ""
|
||||||
|
"troon*" ""
|
||||||
|
"dyke" ""
|
||||||
|
"dykes" ""
|
||||||
|
"pidor*" ""
|
||||||
|
"pidar*" ""
|
||||||
|
"pidr*" ""
|
||||||
|
"maricon*" ""
|
||||||
|
"viado*" ""
|
||||||
|
"schwuchtel*" ""
|
||||||
|
// ableist
|
||||||
|
"*retard*" ""
|
||||||
|
"tard" ""
|
||||||
|
"tards" ""
|
||||||
|
"fucktard*" ""
|
||||||
|
"mongoloid*" ""
|
||||||
|
"spastic*" ""
|
||||||
|
// racial and ethnic
|
||||||
|
"kike" ""
|
||||||
|
"kikes" ""
|
||||||
|
"chink" ""
|
||||||
|
"chinks" ""
|
||||||
|
"spic" ""
|
||||||
|
"spics" ""
|
||||||
|
"gook" ""
|
||||||
|
"gooks" ""
|
||||||
|
"coon" ""
|
||||||
|
"coons" ""
|
||||||
|
"wetback*" ""
|
||||||
|
"beaner*" ""
|
||||||
|
"towelhead*" ""
|
||||||
|
"raghead*" ""
|
||||||
|
"paki" ""
|
||||||
|
"pakis" ""
|
||||||
|
"pajeet*" ""
|
||||||
|
// nazi
|
||||||
|
"heil hitler" ""
|
||||||
|
"sieg heil" ""
|
||||||
|
"1488" ""
|
||||||
|
"white power" ""
|
||||||
|
"gas the jews" ""
|
||||||
|
}
|
||||||
|
|
||||||
|
// general profanity, English then other Latin-script languages
|
||||||
|
"profanity"
|
||||||
|
{
|
||||||
|
"*fuck*" ""
|
||||||
|
"fuk*" ""
|
||||||
|
"dafuk" ""
|
||||||
|
"phuck*" ""
|
||||||
|
"fck*" ""
|
||||||
|
"fk" ""
|
||||||
|
"fks" ""
|
||||||
|
"fking" ""
|
||||||
|
"fkin" ""
|
||||||
|
"fkn" ""
|
||||||
|
"fkng" ""
|
||||||
|
"fked" ""
|
||||||
|
"fker*" ""
|
||||||
|
"idfk" ""
|
||||||
|
"stfu" ""
|
||||||
|
"gtfo" ""
|
||||||
|
"*shit*" ""
|
||||||
|
"*bitch*" ""
|
||||||
|
"*cunt*" ""
|
||||||
|
"ass" ""
|
||||||
|
"asses" ""
|
||||||
|
"arse" ""
|
||||||
|
"*asshole*" ""
|
||||||
|
"dumbass*" ""
|
||||||
|
"fatass*" ""
|
||||||
|
"jackass*" ""
|
||||||
|
"smartass*" ""
|
||||||
|
"bastard*" ""
|
||||||
|
"*wanker*" ""
|
||||||
|
"twat*" ""
|
||||||
|
"prick" ""
|
||||||
|
"pricks" ""
|
||||||
|
"bollocks" ""
|
||||||
|
"tosser*" ""
|
||||||
|
"piss" ""
|
||||||
|
"pissed" ""
|
||||||
|
"pissing" ""
|
||||||
|
"*whore*" ""
|
||||||
|
"*slut*" ""
|
||||||
|
"hoe" ""
|
||||||
|
"hoes" ""
|
||||||
|
"motherf*" ""
|
||||||
|
"mothafuck*" ""
|
||||||
|
// Arabic, transliterated
|
||||||
|
"sharmut*" ""
|
||||||
|
// Russian, transliterated
|
||||||
|
"cyka" ""
|
||||||
|
"suka" ""
|
||||||
|
"blyat*" ""
|
||||||
|
"blyad*" ""
|
||||||
|
"blya" ""
|
||||||
|
"pizda*" ""
|
||||||
|
"pizdec*" ""
|
||||||
|
"pizdets*" ""
|
||||||
|
"nahui" ""
|
||||||
|
"nahuy" ""
|
||||||
|
"nahuj" ""
|
||||||
|
"zaebal*" ""
|
||||||
|
"eblan*" ""
|
||||||
|
"ebat" ""
|
||||||
|
"yebat*" ""
|
||||||
|
// Polish
|
||||||
|
"kurwa*" ""
|
||||||
|
"kurwy" ""
|
||||||
|
"chuj*" ""
|
||||||
|
"jebac*" ""
|
||||||
|
"jebany*" ""
|
||||||
|
"jebane" ""
|
||||||
|
"pierdol*" ""
|
||||||
|
"spierdalaj*" ""
|
||||||
|
"cipa" ""
|
||||||
|
// Czech, Hungarian, Serbo-Croatian, Finnish
|
||||||
|
"kurva" ""
|
||||||
|
"kurac" ""
|
||||||
|
"jebem*" ""
|
||||||
|
"vittu" ""
|
||||||
|
// Spanish, Portuguese
|
||||||
|
"puta" ""
|
||||||
|
"putas" ""
|
||||||
|
"puto" ""
|
||||||
|
"putos" ""
|
||||||
|
"hijueputa" ""
|
||||||
|
"mierda" ""
|
||||||
|
"pendejo*" ""
|
||||||
|
"cabron*" ""
|
||||||
|
"joder" ""
|
||||||
|
"verga" ""
|
||||||
|
"porra" ""
|
||||||
|
"caralho" ""
|
||||||
|
"fdp" ""
|
||||||
|
"merda" ""
|
||||||
|
// German
|
||||||
|
"scheisse" ""
|
||||||
|
"scheiss" ""
|
||||||
|
"hurensohn*" ""
|
||||||
|
"fotze" ""
|
||||||
|
"wichser" ""
|
||||||
|
"arschloch*" ""
|
||||||
|
"missgeburt" ""
|
||||||
|
// French
|
||||||
|
"putain" ""
|
||||||
|
"merde" ""
|
||||||
|
"connard*" ""
|
||||||
|
"connasse" ""
|
||||||
|
"salope*" ""
|
||||||
|
"encule*" ""
|
||||||
|
"ntm" ""
|
||||||
|
// Turkish
|
||||||
|
"amk" ""
|
||||||
|
"aq" ""
|
||||||
|
"orospu*" ""
|
||||||
|
"siktir*" ""
|
||||||
|
"sikerim" ""
|
||||||
|
"sikeyim" ""
|
||||||
|
"yarrak*" ""
|
||||||
|
}
|
||||||
|
|
||||||
|
// telling someone to die or hurt themselves
|
||||||
|
"harassment"
|
||||||
|
{
|
||||||
|
"kys" ""
|
||||||
|
"killyourself" ""
|
||||||
|
"killurself" ""
|
||||||
|
"kill yourself" ""
|
||||||
|
"kill yourselves" ""
|
||||||
|
"kill urself" ""
|
||||||
|
"kill your self" ""
|
||||||
|
"kill ur self" ""
|
||||||
|
"kill yaself" ""
|
||||||
|
"neck yourself" ""
|
||||||
|
"neck urself" ""
|
||||||
|
"hang yourself" ""
|
||||||
|
"hang urself" ""
|
||||||
|
"go die" ""
|
||||||
|
"hope you die" ""
|
||||||
|
"hope u die" ""
|
||||||
|
"die in a fire" ""
|
||||||
|
"get cancer" ""
|
||||||
|
"get aids" ""
|
||||||
|
"drink bleach" ""
|
||||||
|
"get raped" ""
|
||||||
|
}
|
||||||
|
|
||||||
|
// sexual terms
|
||||||
|
"sexual"
|
||||||
|
{
|
||||||
|
"dick" ""
|
||||||
|
"dicks" ""
|
||||||
|
"*dickhead*" ""
|
||||||
|
"cock" ""
|
||||||
|
"cocks" ""
|
||||||
|
"*cocksucker*" ""
|
||||||
|
"pussy*" ""
|
||||||
|
"pussi*" ""
|
||||||
|
"cum" ""
|
||||||
|
"cums" ""
|
||||||
|
"cumming" ""
|
||||||
|
"cuming" ""
|
||||||
|
"cumshot*" ""
|
||||||
|
"*cumslut*" ""
|
||||||
|
"jizz*" ""
|
||||||
|
"rape*" ""
|
||||||
|
"raping" ""
|
||||||
|
"rapist*" ""
|
||||||
|
"earape*" ""
|
||||||
|
"porn*" ""
|
||||||
|
"hentai" ""
|
||||||
|
"penis*" ""
|
||||||
|
"vagina*" ""
|
||||||
|
"tits" ""
|
||||||
|
"titties" ""
|
||||||
|
"boob" ""
|
||||||
|
"boobs" ""
|
||||||
|
"boobies" ""
|
||||||
|
"anal" ""
|
||||||
|
"dildo*" ""
|
||||||
|
"blowjob*" ""
|
||||||
|
"handjob*" ""
|
||||||
|
"horny" ""
|
||||||
|
"fap*" ""
|
||||||
|
"milf*" ""
|
||||||
|
"orgasm*" ""
|
||||||
|
"masturbat*" ""
|
||||||
|
"jerk off" ""
|
||||||
|
"jerking off" ""
|
||||||
|
"jack off" ""
|
||||||
|
"buceta" ""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// never censored even when a wildcard above hits them: a bad word found entirely inside
|
||||||
|
// the part of a word an allow entry matches is skipped. Same syntax as the words, no phrases.
|
||||||
|
"allow"
|
||||||
|
{
|
||||||
|
"*snigger*" ""
|
||||||
|
"scunthorpe" ""
|
||||||
|
"shiitake*" ""
|
||||||
|
"rapeseed*" ""
|
||||||
|
"rapping" ""
|
||||||
|
"rapper*" ""
|
||||||
|
"assess*" ""
|
||||||
|
"yashito" ""
|
||||||
|
}
|
||||||
|
}
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,50 @@
|
|||||||
|
#if defined _ChatFilter2_included_
|
||||||
|
#endinput
|
||||||
|
#endif
|
||||||
|
#define _ChatFilter2_included_
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Censors bad words in a string the same way safe chat does, with every category.
|
||||||
|
*
|
||||||
|
* @param text String to censor in place
|
||||||
|
* @param maxlen Size of text
|
||||||
|
* @return True if anything was censored
|
||||||
|
*/
|
||||||
|
native bool ChatFilter2_CensorText(char[] text, int maxlen);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if a client has safe chat enabled.
|
||||||
|
*
|
||||||
|
* @param client Client index
|
||||||
|
* @return True if safe chat is enabled
|
||||||
|
*/
|
||||||
|
native bool ChatFilter2_IsSafeChatEnabled(int client);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when a client toggles safe chat, and when their cookies load with safe chat enabled.
|
||||||
|
*
|
||||||
|
* @param client Client index
|
||||||
|
* @param enabled True if safe chat is now enabled
|
||||||
|
*/
|
||||||
|
forward void ChatFilter2_OnSafeChatChanged(int client, bool enabled);
|
||||||
|
|
||||||
|
#if !defined CHATFILTER2_CORE
|
||||||
|
public SharedPlugin __pl_ChatFilter2 =
|
||||||
|
{
|
||||||
|
name = "ChatFilter2",
|
||||||
|
file = "ChatFilter2.smx",
|
||||||
|
#if defined REQUIRE_PLUGIN
|
||||||
|
required = 1,
|
||||||
|
#else
|
||||||
|
required = 0,
|
||||||
|
#endif
|
||||||
|
};
|
||||||
|
|
||||||
|
#if !defined REQUIRE_PLUGIN
|
||||||
|
public void __pl_ChatFilter2_SetNTVOptional()
|
||||||
|
{
|
||||||
|
MarkNativeAsOptional("ChatFilter2_CensorText");
|
||||||
|
MarkNativeAsOptional("ChatFilter2_IsSafeChatEnabled");
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
#endif // CHATFILTER2_CORE
|
||||||
@@ -0,0 +1,606 @@
|
|||||||
|
#pragma semicolon 1
|
||||||
|
|
||||||
|
#include <sourcemod>
|
||||||
|
#include <sdktools>
|
||||||
|
#include <sdkhooks>
|
||||||
|
|
||||||
|
#undef REQUIRE_PLUGIN
|
||||||
|
#include <EventNotifier>
|
||||||
|
#define REQUIRE_PLUGIN
|
||||||
|
|
||||||
|
#pragma newdecls required
|
||||||
|
|
||||||
|
#define PLUGIN_VERSION "1.0"
|
||||||
|
|
||||||
|
#define GREETING_TITLE "UNLOZE.com"
|
||||||
|
#define PLACEHOLDER_EVENT "Test Event"
|
||||||
|
#define MAX_NAME_CHARS 64
|
||||||
|
// Skip greetings rather than push a busy map towards the 2048 edict limit.
|
||||||
|
#define EDICT_HEADROOM 1900
|
||||||
|
// Stock model on every client; its "forward" attachment sits on ValveBiped.forward, a child of
|
||||||
|
// Bip01_Head1, so it follows the head of any ValveBiped skeleton it bone-merges onto.
|
||||||
|
#define HELPER_MODEL "models/player/ct_urban.mdl"
|
||||||
|
#define HELPER_ATTACHMENT "forward"
|
||||||
|
#define HELPER_CLASS "prop_dynamic" // created as prop_dynamic_override, which spawns as prop_dynamic
|
||||||
|
|
||||||
|
#define EF_BONEMERGE (1 << 0)
|
||||||
|
#define EF_NOSHADOW (1 << 4)
|
||||||
|
#define EF_NORECEIVESHADOW (1 << 6)
|
||||||
|
#define EF_BONEMERGE_FASTCULL (1 << 7)
|
||||||
|
#define EF_PARENT_ANIMATES (1 << 9)
|
||||||
|
|
||||||
|
#define MOVEMENT_BUTTONS (IN_FORWARD|IN_BACK|IN_MOVELEFT|IN_MOVERIGHT|IN_JUMP|IN_DUCK)
|
||||||
|
|
||||||
|
// sm_eventgreeting_anchor: what the text is parented to
|
||||||
|
enum
|
||||||
|
{
|
||||||
|
ANCHOR_HEAD = 0, // "forward" attachment of a bone-merged helper; sways with the head animation
|
||||||
|
ANCHOR_PLAYER, // the player; offset corrected for pitch and eye height every tick
|
||||||
|
ANCHOR_VIEWMODEL // the viewmodel, at the eyes with the view angles; bobs with the gun
|
||||||
|
}
|
||||||
|
|
||||||
|
ConVar g_cvEventIsOn;
|
||||||
|
ConVar g_cvAnchor;
|
||||||
|
ConVar g_cvDuration;
|
||||||
|
ConVar g_cvOffset;
|
||||||
|
ConVar g_cvSize;
|
||||||
|
ConVar g_cvFont;
|
||||||
|
ConVar g_cvMaxChars;
|
||||||
|
|
||||||
|
bool g_bEventNotifier;
|
||||||
|
bool g_bWorldTextBroken;
|
||||||
|
|
||||||
|
// One greeting per player per map
|
||||||
|
bool g_bGreeted[MAXPLAYERS + 1];
|
||||||
|
int g_iTextRef[MAXPLAYERS + 1] = {INVALID_ENT_REFERENCE, ...};
|
||||||
|
int g_iHelperRef[MAXPLAYERS + 1] = {INVALID_ENT_REFERENCE, ...};
|
||||||
|
float g_flExpireAt[MAXPLAYERS + 1]; // 0 until the player first moves
|
||||||
|
int g_iAnchor[MAXPLAYERS + 1];
|
||||||
|
float g_flLastPitch[MAXPLAYERS + 1];
|
||||||
|
float g_flLastEyeHeight[MAXPLAYERS + 1];
|
||||||
|
|
||||||
|
// Per entity, read by the transmit hook
|
||||||
|
int g_iEntOwner[2049];
|
||||||
|
|
||||||
|
public Plugin myinfo =
|
||||||
|
{
|
||||||
|
name = "EventGreeting",
|
||||||
|
author = "marisakirisame.net",
|
||||||
|
description = "Greets players on their first spawn during events with the active event's name",
|
||||||
|
version = PLUGIN_VERSION,
|
||||||
|
url = ""
|
||||||
|
};
|
||||||
|
|
||||||
|
public void OnPluginStart()
|
||||||
|
{
|
||||||
|
// Owned by VIP_Reward. CreateConVar on an existing cvar would add it to this plugin's list, and
|
||||||
|
// AutoExecConfig would then write sv_event_is_on "0" into EventGreeting.cfg, turning event mode
|
||||||
|
// off every map. So only create it when VIP_Reward hasn't (yet), and keep it out of the cfg.
|
||||||
|
g_cvEventIsOn = FindConVar("sv_event_is_on");
|
||||||
|
if (g_cvEventIsOn == null)
|
||||||
|
g_cvEventIsOn = CreateConVar("sv_event_is_on", "0", "Cvar decides whether event mode is on or not.", FCVAR_DONTRECORD);
|
||||||
|
g_cvEventIsOn.AddChangeHook(OnEventIsOnChanged);
|
||||||
|
|
||||||
|
// lines are centred with space padding, which is only exact in a monospaced font
|
||||||
|
g_cvFont = CreateConVar("sm_eventgreeting_font", "8", "point_worldtext font (8 = Roboto Mono with outline)", 0, true, 0.0, true, 12.0);
|
||||||
|
g_cvSize = CreateConVar("sm_eventgreeting_size", "3.0", "Text size", 0, true, 0.5);
|
||||||
|
g_cvAnchor = CreateConVar("sm_eventgreeting_anchor", "2", "0 = head attachment of a bone-merged helper (sways with the head animation, 2 edicts), 1 = the player (turns at network rate), 2 = the viewmodel (bobs with the gun)", 0, true, 0.0, true, 2.0);
|
||||||
|
g_cvOffset = CreateConVar("sm_eventgreeting_offset", "64 0 0", "Text position \"x y z\" relative to the anchor (x is forward)");
|
||||||
|
g_cvDuration = CreateConVar("sm_eventgreeting_duration", "5.0", "Seconds the greeting stays after the player first moves", 0, true, 0.0);
|
||||||
|
g_cvMaxChars = CreateConVar("sm_eventgreeting_max_chars", "32", "Maximum characters of the event name; longer names end in ...", 0, true, 8.0, true, float(MAX_NAME_CHARS));
|
||||||
|
AutoExecConfig(true, "EventGreeting");
|
||||||
|
|
||||||
|
RegAdminCmd("sm_eventgreeting_test", Cmd_Test, ADMFLAG_RCON, "sm_eventgreeting_test [target] - show the greeting now, ignoring sv_event_is_on and earlier greetings");
|
||||||
|
RegAdminCmd("sm_eventgreeting_debug", Cmd_Debug, ADMFLAG_RCON, "sm_eventgreeting_debug - list live greetings");
|
||||||
|
|
||||||
|
HookEvent("player_spawn", Event_PlayerSpawn);
|
||||||
|
HookEvent("player_death", Event_KillGreeting);
|
||||||
|
HookEvent("player_team", Event_KillGreeting);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void OnPluginEnd()
|
||||||
|
{
|
||||||
|
for (int i = 1; i <= MaxClients; i++)
|
||||||
|
KillGreeting(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void OnAllPluginsLoaded()
|
||||||
|
{
|
||||||
|
g_bEventNotifier = LibraryExists("EventNotifier");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void OnLibraryAdded(const char[] name)
|
||||||
|
{
|
||||||
|
if (StrEqual(name, "EventNotifier"))
|
||||||
|
g_bEventNotifier = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void OnLibraryRemoved(const char[] name)
|
||||||
|
{
|
||||||
|
if (StrEqual(name, "EventNotifier"))
|
||||||
|
g_bEventNotifier = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void OnMapStart()
|
||||||
|
{
|
||||||
|
g_bWorldTextBroken = false;
|
||||||
|
PrecacheModel(HELPER_MODEL);
|
||||||
|
|
||||||
|
// the previous map's entities are gone, so only the bookkeeping needs resetting
|
||||||
|
for (int i = 1; i <= MaxClients; i++)
|
||||||
|
{
|
||||||
|
g_bGreeted[i] = false;
|
||||||
|
g_iTextRef[i] = INVALID_ENT_REFERENCE;
|
||||||
|
g_iHelperRef[i] = INVALID_ENT_REFERENCE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void OnClientConnected(int client)
|
||||||
|
{
|
||||||
|
g_bGreeted[client] = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void OnClientDisconnect(int client)
|
||||||
|
{
|
||||||
|
KillGreeting(client);
|
||||||
|
}
|
||||||
|
|
||||||
|
void OnEventIsOnChanged(ConVar convar, const char[] oldValue, const char[] newValue)
|
||||||
|
{
|
||||||
|
if (convar.BoolValue)
|
||||||
|
return;
|
||||||
|
|
||||||
|
for (int i = 1; i <= MaxClients; i++)
|
||||||
|
KillGreeting(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------------------------------
|
||||||
|
// Spawning
|
||||||
|
//----------------------------------------------------------------------------------------------------
|
||||||
|
public void Event_PlayerSpawn(Event event, const char[] name, bool dontBroadcast)
|
||||||
|
{
|
||||||
|
if (!g_cvEventIsOn.BoolValue)
|
||||||
|
return;
|
||||||
|
|
||||||
|
// eye position and team aren't final during the event
|
||||||
|
RequestFrame(Frame_Greet, event.GetInt("userid"));
|
||||||
|
}
|
||||||
|
|
||||||
|
void Frame_Greet(int userid)
|
||||||
|
{
|
||||||
|
int client = GetClientOfUserId(userid);
|
||||||
|
if (client == 0 || g_bGreeted[client] || IsFakeClient(client) || !g_cvEventIsOn.BoolValue)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (!IsPlayerAlive(client) || GetClientTeam(client) < 2)
|
||||||
|
return;
|
||||||
|
|
||||||
|
char eventName[EVENT_STR_LEN];
|
||||||
|
if (!FindActiveEventName(eventName, sizeof(eventName)))
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (ShowGreeting(client, eventName))
|
||||||
|
g_bGreeted[client] = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Event_KillGreeting(Event event, const char[] name, bool dontBroadcast)
|
||||||
|
{
|
||||||
|
int client = GetClientOfUserId(event.GetInt("userid"));
|
||||||
|
if (client != 0)
|
||||||
|
KillGreeting(client);
|
||||||
|
}
|
||||||
|
|
||||||
|
// The active event is one in progress, else the one whose start is nearest to now (past or future).
|
||||||
|
bool FindActiveEventName(char[] buffer, int maxlen)
|
||||||
|
{
|
||||||
|
if (!g_bEventNotifier || !EventNotifier_HasFetched())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
int now = GetTime();
|
||||||
|
int best = -1;
|
||||||
|
int bestDistance;
|
||||||
|
|
||||||
|
int count = EventNotifier_GetEventCount();
|
||||||
|
for (int i = 0; i < count; i++)
|
||||||
|
{
|
||||||
|
EventInfo ev;
|
||||||
|
if (!EventNotifier_GetEvent(i, ev, sizeof(ev)) || ev.start == 0)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (ev.end > 0 && now >= ev.start && now < ev.end)
|
||||||
|
{
|
||||||
|
best = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
int distance = now > ev.start ? now - ev.start : ev.start - now;
|
||||||
|
if (best == -1 || distance < bestDistance)
|
||||||
|
{
|
||||||
|
best = i;
|
||||||
|
bestDistance = distance;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (best == -1)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
EventInfo ev;
|
||||||
|
EventNotifier_GetEvent(best, ev, sizeof(ev));
|
||||||
|
strcopy(buffer, maxlen, ev.name);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ShowGreeting(int client, const char[] eventName)
|
||||||
|
{
|
||||||
|
KillGreeting(client);
|
||||||
|
|
||||||
|
if (g_bWorldTextBroken || GetEntityCount() >= EDICT_HEADROOM)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
char text[2 * (MAX_NAME_CHARS + 8)];
|
||||||
|
if (!FormatGreeting(eventName, text, sizeof(text)))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
int anchor = g_cvAnchor.IntValue;
|
||||||
|
int parent = client;
|
||||||
|
int helper = -1;
|
||||||
|
if (anchor == ANCHOR_HEAD)
|
||||||
|
{
|
||||||
|
helper = SpawnHelper(client);
|
||||||
|
if (helper == -1)
|
||||||
|
return false;
|
||||||
|
parent = helper;
|
||||||
|
}
|
||||||
|
else if (anchor == ANCHOR_VIEWMODEL)
|
||||||
|
{
|
||||||
|
int viewmodel = GetEntPropEnt(client, Prop_Send, "m_hViewModel", 0);
|
||||||
|
if (viewmodel != -1)
|
||||||
|
parent = viewmodel;
|
||||||
|
else
|
||||||
|
anchor = ANCHOR_PLAYER;
|
||||||
|
}
|
||||||
|
|
||||||
|
int ent = SpawnWorldText(client, parent, anchor, text);
|
||||||
|
if (ent == -1)
|
||||||
|
{
|
||||||
|
if (helper != -1)
|
||||||
|
AcceptEntityInput(helper, "Kill");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
g_iHelperRef[client] = helper != -1 ? EntIndexToEntRef(helper) : INVALID_ENT_REFERENCE;
|
||||||
|
g_iTextRef[client] = EntIndexToEntRef(ent);
|
||||||
|
g_flExpireAt[client] = 0.0;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Invisible copy of the player's skeleton; the text hangs off its head attachment, so the client
|
||||||
|
// keeps it in front of the face it draws without the server moving it.
|
||||||
|
int SpawnHelper(int client)
|
||||||
|
{
|
||||||
|
int ent = CreateEntityByName("prop_dynamic_override");
|
||||||
|
if (ent == -1)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
DispatchKeyValue(ent, "model", HELPER_MODEL);
|
||||||
|
DispatchKeyValue(ent, "solid", "0");
|
||||||
|
DispatchKeyValue(ent, "DisableBoneFollowers", "1");
|
||||||
|
DispatchKeyValue(ent, "disableshadows", "1");
|
||||||
|
DispatchKeyValue(ent, "disablereceiveshadows", "1");
|
||||||
|
if (!DispatchSpawn(ent))
|
||||||
|
{
|
||||||
|
AcceptEntityInput(ent, "Kill");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// RENDER_NONE rather than EF_NODRAW: EF_NODRAW stops the entity being sent at all, and the
|
||||||
|
// client needs it to place the text.
|
||||||
|
SetEntityRenderMode(ent, RENDER_NONE);
|
||||||
|
|
||||||
|
// CBaseEntity::FollowEntity() recipe (see Leader3's glow shell): the client only bone-merges
|
||||||
|
// with EF_BONEMERGE, a move parent and MOVETYPE_NONE.
|
||||||
|
float origin[3], angles[3];
|
||||||
|
GetClientAbsOrigin(client, origin);
|
||||||
|
GetClientAbsAngles(client, angles);
|
||||||
|
TeleportEntity(ent, origin, angles, NULL_VECTOR);
|
||||||
|
|
||||||
|
SetVariantString("!activator");
|
||||||
|
AcceptEntityInput(ent, "SetParent", client, ent);
|
||||||
|
SetEntityMoveType(ent, MOVETYPE_NONE);
|
||||||
|
SetEntProp(ent, Prop_Send, "m_fEffects",
|
||||||
|
EF_BONEMERGE|EF_BONEMERGE_FASTCULL|EF_NOSHADOW|EF_NORECEIVESHADOW|EF_PARENT_ANIMATES);
|
||||||
|
|
||||||
|
g_iEntOwner[ent] = client;
|
||||||
|
SDKHook(ent, SDKHook_SetTransmit, Hook_OwnerOnlyTransmit);
|
||||||
|
return ent;
|
||||||
|
}
|
||||||
|
|
||||||
|
int SpawnWorldText(int client, int parent, int anchor, const char[] text)
|
||||||
|
{
|
||||||
|
int ent = CreateEntityByName("point_worldtext");
|
||||||
|
if (ent == -1)
|
||||||
|
{
|
||||||
|
g_bWorldTextBroken = true;
|
||||||
|
LogMessage("point_worldtext could not be created; event greetings are off for this map.");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
char font[4], size[16];
|
||||||
|
g_cvFont.GetString(font, sizeof(font));
|
||||||
|
g_cvSize.GetString(size, sizeof(size));
|
||||||
|
|
||||||
|
DispatchKeyValue(ent, "message", text);
|
||||||
|
DispatchKeyValue(ent, "font", font);
|
||||||
|
DispatchKeyValue(ent, "textsize", size);
|
||||||
|
DispatchKeyValue(ent, "color", "255 255 255 255");
|
||||||
|
DispatchKeyValue(ent, "orientation", "1");
|
||||||
|
DispatchSpawn(ent);
|
||||||
|
|
||||||
|
float eyes[3];
|
||||||
|
GetClientEyePosition(client, eyes);
|
||||||
|
TeleportEntity(ent, eyes, NULL_VECTOR, NULL_VECTOR);
|
||||||
|
|
||||||
|
SetVariantString("!activator");
|
||||||
|
AcceptEntityInput(ent, "SetParent", parent, ent);
|
||||||
|
if (anchor == ANCHOR_HEAD)
|
||||||
|
{
|
||||||
|
SetVariantString(HELPER_ATTACHMENT);
|
||||||
|
AcceptEntityInput(ent, "SetParentAttachment", ent, ent);
|
||||||
|
}
|
||||||
|
|
||||||
|
g_iAnchor[client] = anchor;
|
||||||
|
SetTextOffset(client, ent);
|
||||||
|
|
||||||
|
g_iEntOwner[ent] = client;
|
||||||
|
SDKHook(ent, SDKHook_SetTransmit, Hook_OwnerOnlyTransmit);
|
||||||
|
return ent;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sets the text's local origin (it is parented, so TeleportEntity sets the local origin).
|
||||||
|
// The client rotates children of the local player by the full view angles about the FEET, so for
|
||||||
|
// ANCHOR_PLAYER the eye height is added in the rotated frame: the world up vector in that frame is
|
||||||
|
// (-sin pitch, 0, cos pitch). The pitch comes from the server, so this is redone as it changes.
|
||||||
|
void SetTextOffset(int client, int ent)
|
||||||
|
{
|
||||||
|
float local[3];
|
||||||
|
GetOffset(local);
|
||||||
|
|
||||||
|
if (g_iAnchor[client] == ANCHOR_PLAYER)
|
||||||
|
{
|
||||||
|
float angles[3];
|
||||||
|
GetClientEyeAngles(client, angles);
|
||||||
|
float eyeHeight = GetEntPropFloat(client, Prop_Send, "m_vecViewOffset[2]");
|
||||||
|
float pitch = DegToRad(angles[0]);
|
||||||
|
|
||||||
|
local[0] -= eyeHeight * Sine(pitch);
|
||||||
|
local[2] += eyeHeight * Cosine(pitch);
|
||||||
|
|
||||||
|
g_flLastPitch[client] = angles[0];
|
||||||
|
g_flLastEyeHeight[client] = eyeHeight;
|
||||||
|
}
|
||||||
|
|
||||||
|
TeleportEntity(ent, local, NULL_VECTOR, NULL_VECTOR);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool PlayerOffsetChanged(int client)
|
||||||
|
{
|
||||||
|
float angles[3];
|
||||||
|
GetClientEyeAngles(client, angles);
|
||||||
|
float eyeHeight = GetEntPropFloat(client, Prop_Send, "m_vecViewOffset[2]");
|
||||||
|
return FloatAbs(angles[0] - g_flLastPitch[client]) > 0.1 || FloatAbs(eyeHeight - g_flLastEyeHeight[client]) > 0.1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void GetOffset(float local[3])
|
||||||
|
{
|
||||||
|
char value[64], parts[3][16];
|
||||||
|
g_cvOffset.GetString(value, sizeof(value));
|
||||||
|
int count = ExplodeString(value, " ", parts, sizeof(parts), sizeof(parts[]));
|
||||||
|
for (int i = 0; i < 3; i++)
|
||||||
|
local[i] = i < count ? StringToFloat(parts[i]) : 0.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Action Hook_OwnerOnlyTransmit(int ent, int client)
|
||||||
|
{
|
||||||
|
return client == g_iEntOwner[ent] ? Plugin_Continue : Plugin_Handled;
|
||||||
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------------------------------
|
||||||
|
// Expiry and cleanup
|
||||||
|
//----------------------------------------------------------------------------------------------------
|
||||||
|
public void OnPlayerRunCmdPost(int client, int buttons)
|
||||||
|
{
|
||||||
|
if (g_iTextRef[client] == INVALID_ENT_REFERENCE || g_flExpireAt[client] != 0.0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (buttons & MOVEMENT_BUTTONS)
|
||||||
|
g_flExpireAt[client] = GetGameTime() + g_cvDuration.FloatValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void OnGameFrame()
|
||||||
|
{
|
||||||
|
float now = GetGameTime();
|
||||||
|
|
||||||
|
for (int client = 1; client <= MaxClients; client++)
|
||||||
|
{
|
||||||
|
if (g_iTextRef[client] == INVALID_ENT_REFERENCE)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (LiveEntRef(g_iTextRef[client]) == -1
|
||||||
|
|| (g_iHelperRef[client] != INVALID_ENT_REFERENCE && LiveEntRef(g_iHelperRef[client], HELPER_CLASS) == -1)
|
||||||
|
|| (g_flExpireAt[client] != 0.0 && now >= g_flExpireAt[client])
|
||||||
|
|| !IsClientInGame(client) || !IsPlayerAlive(client))
|
||||||
|
{
|
||||||
|
// also catches entities the round restart removed
|
||||||
|
KillGreeting(client);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (g_iAnchor[client] == ANCHOR_PLAYER && PlayerOffsetChanged(client))
|
||||||
|
SetTextOffset(client, EntRefToEntIndex(g_iTextRef[client]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void KillGreeting(int client)
|
||||||
|
{
|
||||||
|
KillEntRef(g_iTextRef[client]);
|
||||||
|
KillEntRef(g_iHelperRef[client], HELPER_CLASS);
|
||||||
|
g_iTextRef[client] = INVALID_ENT_REFERENCE;
|
||||||
|
g_iHelperRef[client] = INVALID_ENT_REFERENCE;
|
||||||
|
}
|
||||||
|
|
||||||
|
void KillEntRef(int ref, const char[] expectedClass = "point_worldtext")
|
||||||
|
{
|
||||||
|
int ent = LiveEntRef(ref, expectedClass);
|
||||||
|
if (ent != -1)
|
||||||
|
AcceptEntityInput(ent, "Kill");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Resolves an entity reference, returning -1 unless it is still a live edict of the expected class.
|
||||||
|
int LiveEntRef(int ref, const char[] expectedClass = "point_worldtext")
|
||||||
|
{
|
||||||
|
if (ref == INVALID_ENT_REFERENCE)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
int ent = EntRefToEntIndex(ref);
|
||||||
|
if (ent == INVALID_ENT_REFERENCE || !IsValidEdict(ent))
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
char classname[32];
|
||||||
|
GetEdictClassname(ent, classname, sizeof(classname));
|
||||||
|
return StrEqual(classname, expectedClass) ? ent : -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------------------------------
|
||||||
|
// Text: point_worldtext only draws printable ASCII, so anything else is dropped from the event name.
|
||||||
|
// Both lines are space-padded to the same length so they centre in a monospaced font.
|
||||||
|
//----------------------------------------------------------------------------------------------------
|
||||||
|
bool FormatGreeting(const char[] eventName, char[] output, int maxlen)
|
||||||
|
{
|
||||||
|
char name[MAX_NAME_CHARS + 4];
|
||||||
|
int maxChars = g_cvMaxChars.IntValue;
|
||||||
|
int len = 0;
|
||||||
|
bool truncated = false;
|
||||||
|
|
||||||
|
for (int i = 0; eventName[i] != '\0'; i++)
|
||||||
|
{
|
||||||
|
if (eventName[i] < ' ' || eventName[i] > '~')
|
||||||
|
continue;
|
||||||
|
|
||||||
|
// no leading or doubled spaces left behind by dropped characters
|
||||||
|
if (eventName[i] == ' ' && (len == 0 || name[len - 1] == ' '))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (len >= maxChars)
|
||||||
|
{
|
||||||
|
truncated = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
name[len++] = eventName[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
while (len > 0 && name[len - 1] == ' ')
|
||||||
|
len--;
|
||||||
|
name[len] = '\0';
|
||||||
|
|
||||||
|
if (len == 0)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (truncated)
|
||||||
|
StrCat(name, sizeof(name), "...");
|
||||||
|
|
||||||
|
char title[MAX_NAME_CHARS + 4], line[MAX_NAME_CHARS + 4];
|
||||||
|
int width = strlen(name) > strlen(GREETING_TITLE) ? strlen(name) : strlen(GREETING_TITLE);
|
||||||
|
PadLine(GREETING_TITLE, width, title, sizeof(title));
|
||||||
|
PadLine(name, width, line, sizeof(line));
|
||||||
|
Format(output, maxlen, "%s\n%s", title, line);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void PadLine(const char[] text, int width, char[] output, int maxlen)
|
||||||
|
{
|
||||||
|
int pad = width - strlen(text);
|
||||||
|
int left = pad / 2;
|
||||||
|
|
||||||
|
output[0] = '\0';
|
||||||
|
for (int c = 0; c < left; c++)
|
||||||
|
StrCat(output, maxlen, " ");
|
||||||
|
StrCat(output, maxlen, text);
|
||||||
|
for (int c = left; c < pad; c++)
|
||||||
|
StrCat(output, maxlen, " ");
|
||||||
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------------------------------
|
||||||
|
// Commands
|
||||||
|
//----------------------------------------------------------------------------------------------------
|
||||||
|
public Action Cmd_Test(int client, int args)
|
||||||
|
{
|
||||||
|
int target = client;
|
||||||
|
if (args >= 1)
|
||||||
|
{
|
||||||
|
char arg[64];
|
||||||
|
GetCmdArg(1, arg, sizeof(arg));
|
||||||
|
target = FindTarget(client, arg, false, false);
|
||||||
|
if (target == -1)
|
||||||
|
return Plugin_Handled;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (target == 0 || !IsPlayerAlive(target))
|
||||||
|
{
|
||||||
|
ReplyToCommand(client, "[EventGreeting] The target must be an alive player.");
|
||||||
|
return Plugin_Handled;
|
||||||
|
}
|
||||||
|
|
||||||
|
char eventName[EVENT_STR_LEN];
|
||||||
|
if (FindActiveEventName(eventName, sizeof(eventName)))
|
||||||
|
ReplyToCommand(client, "[EventGreeting] Active event: %s", eventName);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
strcopy(eventName, sizeof(eventName), PLACEHOLDER_EVENT);
|
||||||
|
ReplyToCommand(client, "[EventGreeting] No active event (EventNotifier %s), using \"%s\".",
|
||||||
|
g_bEventNotifier ? "has no events" : "not loaded", eventName);
|
||||||
|
}
|
||||||
|
|
||||||
|
char text[2 * (MAX_NAME_CHARS + 8)];
|
||||||
|
if (FormatGreeting(eventName, text, sizeof(text)))
|
||||||
|
{
|
||||||
|
ReplaceString(text, sizeof(text), "\n", "|\n|");
|
||||||
|
ReplyToCommand(client, "|%s|", text);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ShowGreeting(target, eventName))
|
||||||
|
ReplyToCommand(client, "[EventGreeting] Shown to %N.", target);
|
||||||
|
else
|
||||||
|
ReplyToCommand(client, "[EventGreeting] Could not show the greeting (edicts, worldtext or empty name).");
|
||||||
|
|
||||||
|
return Plugin_Handled;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Action Cmd_Debug(int client, int args)
|
||||||
|
{
|
||||||
|
ReplyToCommand(client, "[EventGreeting] sv_event_is_on %d, EventNotifier %s, entities %d",
|
||||||
|
g_cvEventIsOn.IntValue, g_bEventNotifier ? "loaded" : "missing", GetEntityCount());
|
||||||
|
|
||||||
|
float now = GetGameTime();
|
||||||
|
bool shown = false;
|
||||||
|
for (int i = 1; i <= MaxClients; i++)
|
||||||
|
{
|
||||||
|
if (g_iTextRef[i] == INVALID_ENT_REFERENCE)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
char state[32];
|
||||||
|
if (g_flExpireAt[i] == 0.0)
|
||||||
|
strcopy(state, sizeof(state), "waiting for movement");
|
||||||
|
else
|
||||||
|
FormatEx(state, sizeof(state), "%.1fs left", g_flExpireAt[i] - now);
|
||||||
|
|
||||||
|
ReplyToCommand(client, " %N: text %d, helper %d, %s", i,
|
||||||
|
LiveEntRef(g_iTextRef[i]), LiveEntRef(g_iHelperRef[i], HELPER_CLASS), state);
|
||||||
|
shown = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!shown)
|
||||||
|
ReplyToCommand(client, "[EventGreeting] No live greetings.");
|
||||||
|
|
||||||
|
return Plugin_Handled;
|
||||||
|
}
|
||||||
@@ -87,6 +87,7 @@ public void OnPluginStart()
|
|||||||
{
|
{
|
||||||
RegAdminCmd("sm_extendmap", Command_Extend, ADMFLAG_GENERIC, "Add more time to mp_timelimit");
|
RegAdminCmd("sm_extendmap", Command_Extend, ADMFLAG_GENERIC, "Add more time to mp_timelimit");
|
||||||
RegAdminCmd("sm_extend", Command_ExtendVote, ADMFLAG_GENERIC, "sm_extend [time] - Start an extendvote");
|
RegAdminCmd("sm_extend", Command_ExtendVote, ADMFLAG_GENERIC, "sm_extend [time] - Start an extendvote");
|
||||||
|
RegAdminCmd("sm_settimeleft", Command_SetTimeLeft, ADMFLAG_GENERIC, "sm_settimeleft <minutes> - Set the time left on the map");
|
||||||
|
|
||||||
// Relies on the m_fRoundStartTime gamerules prop, which only Counter-Strike games have
|
// Relies on the m_fRoundStartTime gamerules prop, which only Counter-Strike games have
|
||||||
EngineVersion engine = GetEngineVersion();
|
EngineVersion engine = GetEngineVersion();
|
||||||
@@ -229,6 +230,53 @@ public Action Command_ExtendVote(int client, int argc)
|
|||||||
return Plugin_Handled;
|
return Plugin_Handled;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Action Command_SetTimeLeft(int client, int argc)
|
||||||
|
{
|
||||||
|
if (argc < 1)
|
||||||
|
{
|
||||||
|
ReplyToCommand(client, "[SM] Usage: sm_settimeleft <minutes>");
|
||||||
|
return Plugin_Handled;
|
||||||
|
}
|
||||||
|
|
||||||
|
char sArgs[16];
|
||||||
|
GetCmdArg(1, sArgs, sizeof(sArgs));
|
||||||
|
|
||||||
|
int iTargetMinutes;
|
||||||
|
if (!StringToIntEx(sArgs, iTargetMinutes) || iTargetMinutes < 1)
|
||||||
|
{
|
||||||
|
ReplyToCommand(client, "[SM] Invalid value, minutes must be 1 or more");
|
||||||
|
return Plugin_Handled;
|
||||||
|
}
|
||||||
|
|
||||||
|
int iOldLimit = g_cvarMpTimeLimit.IntValue;
|
||||||
|
int iTimeLeft;
|
||||||
|
if (iOldLimit <= 0 || !GetMapTimeLeft(iTimeLeft) || iTimeLeft == -1)
|
||||||
|
{
|
||||||
|
ReplyToCommand(client, "[SM] There is no time limit on this map, set mp_timelimit instead");
|
||||||
|
return Plugin_Handled;
|
||||||
|
}
|
||||||
|
|
||||||
|
// mp_timelimit counts from map start, so add the time already played.
|
||||||
|
// It only holds whole minutes, so the result is within 30 seconds of the target.
|
||||||
|
int iElapsed = iOldLimit * 60 - iTimeLeft;
|
||||||
|
int iNewLimit = RoundToNearest(float(iElapsed + iTargetMinutes * 60) / 60.0);
|
||||||
|
if (iNewLimit < 1)
|
||||||
|
iNewLimit = 1;
|
||||||
|
|
||||||
|
g_cvarMpTimeLimit.IntValue = iNewLimit;
|
||||||
|
if (iNewLimit > iOldLimit)
|
||||||
|
CancelGameOver();
|
||||||
|
|
||||||
|
int iNewTimeLeft = iNewLimit * 60 - iElapsed;
|
||||||
|
if (iNewTimeLeft < 0)
|
||||||
|
iNewTimeLeft = 0;
|
||||||
|
|
||||||
|
LogAction(client, -1, "\"%L\" set the time left to \"%d\" minutes (mp_timelimit %d -> %d)", client, iTargetMinutes, iOldLimit, iNewLimit);
|
||||||
|
PrintToChatAll("[SM] %N set the time left to %d:%02d.", client, iNewTimeLeft / 60, iNewTimeLeft % 60);
|
||||||
|
|
||||||
|
return Plugin_Handled;
|
||||||
|
}
|
||||||
|
|
||||||
public Action Command_RoundExtend(int client, int argc)
|
public Action Command_RoundExtend(int client, int argc)
|
||||||
{
|
{
|
||||||
float fElapsedTime = (GetGameTime() - GameRules_GetPropFloat("m_fRoundStartTime")) / 60.0;
|
float fElapsedTime = (GetGameTime() - GameRules_GetPropFloat("m_fRoundStartTime")) / 60.0;
|
||||||
|
|||||||
@@ -3,18 +3,26 @@
|
|||||||
#include <sourcemod>
|
#include <sourcemod>
|
||||||
|
|
||||||
#undef REQUIRE_PLUGIN
|
#undef REQUIRE_PLUGIN
|
||||||
|
#include <Couch>
|
||||||
#include <HappyHour>
|
#include <HappyHour>
|
||||||
#include <StageDisplay>
|
#include <StageDisplay>
|
||||||
#define REQUIRE_PLUGIN
|
#define REQUIRE_PLUGIN
|
||||||
|
|
||||||
#pragma newdecls required
|
#pragma newdecls required
|
||||||
|
|
||||||
ConVar g_cvInfoMessage;
|
|
||||||
ConVar g_cvHostname;
|
ConVar g_cvHostname;
|
||||||
ConVar g_cvFormattedHostname;
|
ConVar g_cvFormattedHostname;
|
||||||
|
ConVar g_cvHostIP;
|
||||||
|
ConVar g_cvHostPort;
|
||||||
|
ConVar g_cvPassword;
|
||||||
|
ConVar g_cvMaxLength;
|
||||||
|
ConVar g_cvSendToClients;
|
||||||
|
|
||||||
|
// Dropped in this order while the hostname is longer than sm_hostname_max_length.
|
||||||
|
char g_sFoldOrder[][] = { "LagCompensation", "NoSteam" };
|
||||||
|
|
||||||
|
bool g_bCouchLoaded;
|
||||||
bool g_bHHLoaded;
|
bool g_bHHLoaded;
|
||||||
bool g_bNemesis;
|
|
||||||
bool g_bSDLoaded;
|
bool g_bSDLoaded;
|
||||||
|
|
||||||
|
|
||||||
@@ -34,7 +42,12 @@ public Plugin myinfo =
|
|||||||
public void OnPluginStart()
|
public void OnPluginStart()
|
||||||
{
|
{
|
||||||
g_cvHostname = FindConVar("hostname");
|
g_cvHostname = FindConVar("hostname");
|
||||||
g_cvFormattedHostname = CreateConVar("sm_hostname_format", "{HH}UNLOZE | {GM} | LagCompensation | NoSteam{SD}", "HH = HappyHour, , GM = GameMode, SD = StageDisplay");
|
g_cvHostIP = FindConVar("hostip");
|
||||||
|
g_cvHostPort = FindConVar("hostport");
|
||||||
|
g_cvPassword = FindConVar("sv_password");
|
||||||
|
g_cvFormattedHostname = CreateConVar("sm_hostname_format", "{HH}UNLOZE | {GM} | LagCompensation | NoSteam{SD}", "HH = HappyHour, GM = GameMode (Nemesis Zombie Escape > Couch Escape > Zombie Escape), SD = StageDisplay");
|
||||||
|
g_cvMaxLength = CreateConVar("sm_hostname_max_length", "63", "Fold LagCompensation, then NoSteam, out of the hostname while it is longer than this many bytes (the server browser shows at most 63)", 0, true, 1.0, true, 127.0);
|
||||||
|
g_cvSendToClients = CreateConVar("sm_hostname_send_to_clients", "1", "Send the new hostname to connected clients so their scoreboard updates without a reconnect", 0, true, 0.0, true, 1.0);
|
||||||
|
|
||||||
CreateTimer(60.0, TimerRepeat, INVALID_HANDLE, TIMER_REPEAT);
|
CreateTimer(60.0, TimerRepeat, INVALID_HANDLE, TIMER_REPEAT);
|
||||||
|
|
||||||
@@ -46,17 +59,17 @@ public void OnPluginStart()
|
|||||||
//----------------------------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------------------------
|
||||||
public void OnAllPluginsLoaded()
|
public void OnAllPluginsLoaded()
|
||||||
{
|
{
|
||||||
|
g_bCouchLoaded = LibraryExists("Couch");
|
||||||
g_bHHLoaded = LibraryExists("HappyHour");
|
g_bHHLoaded = LibraryExists("HappyHour");
|
||||||
g_bSDLoaded = LibraryExists("StageDisplay");
|
g_bSDLoaded = LibraryExists("StageDisplay");
|
||||||
|
}
|
||||||
|
|
||||||
if((g_cvInfoMessage = FindConVar("sm_info_message_file")) == INVALID_HANDLE)
|
//----------------------------------------------------------------------------------------------------
|
||||||
SetFailState("Failed to find sm_info_message_file cvar.");
|
// Purpose: server.cfg resets the hostname every map, and this also runs on a late load.
|
||||||
|
//----------------------------------------------------------------------------------------------------
|
||||||
char sFile[PLATFORM_MAX_PATH];
|
public void OnConfigsExecuted()
|
||||||
g_cvInfoMessage.GetString(sFile, sizeof(sFile));
|
{
|
||||||
OnClassesPathChange(g_cvInfoMessage, "", sFile);
|
RefreshHostname();
|
||||||
|
|
||||||
HookConVarChange(g_cvInfoMessage, OnClassesPathChange);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------------------------
|
||||||
@@ -64,6 +77,9 @@ public void OnAllPluginsLoaded()
|
|||||||
//----------------------------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------------------------
|
||||||
public void OnLibraryAdded(const char[] sName)
|
public void OnLibraryAdded(const char[] sName)
|
||||||
{
|
{
|
||||||
|
if (strcmp(sName, "Couch", false) == 0)
|
||||||
|
g_bCouchLoaded = true;
|
||||||
|
|
||||||
if (strcmp(sName, "HappyHour", false) == 0)
|
if (strcmp(sName, "HappyHour", false) == 0)
|
||||||
g_bHHLoaded = true;
|
g_bHHLoaded = true;
|
||||||
|
|
||||||
@@ -76,6 +92,13 @@ public void OnLibraryAdded(const char[] sName)
|
|||||||
//----------------------------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------------------------
|
||||||
public void OnLibraryRemoved(const char[] sName)
|
public void OnLibraryRemoved(const char[] sName)
|
||||||
{
|
{
|
||||||
|
// Unloading Couch doesn't fire Couch_OnCouchRemoved, so drop the couch game mode here.
|
||||||
|
if (strcmp(sName, "Couch", false) == 0)
|
||||||
|
{
|
||||||
|
g_bCouchLoaded = false;
|
||||||
|
RefreshHostname();
|
||||||
|
}
|
||||||
|
|
||||||
if (strcmp(sName, "HappyHour", false) == 0)
|
if (strcmp(sName, "HappyHour", false) == 0)
|
||||||
g_bHHLoaded = false;
|
g_bHHLoaded = false;
|
||||||
|
|
||||||
@@ -130,28 +153,189 @@ public void RefreshHostname()
|
|||||||
else
|
else
|
||||||
ReplaceString(sFormattedHostname, sizeof(sFormattedHostname), "{SD}", "", true);
|
ReplaceString(sFormattedHostname, sizeof(sFormattedHostname), "{SD}", "", true);
|
||||||
|
|
||||||
if (g_bNemesis)
|
if (IsNemesisMap())
|
||||||
ReplaceString(sFormattedHostname, sizeof(sFormattedHostname), "{GM}", "Nemesis Zombie Escape", true);
|
ReplaceString(sFormattedHostname, sizeof(sFormattedHostname), "{GM}", "Nemesis Zombie Escape", true);
|
||||||
|
else if (IsCouchPresent())
|
||||||
|
ReplaceString(sFormattedHostname, sizeof(sFormattedHostname), "{GM}", "Couch Escape", true);
|
||||||
else
|
else
|
||||||
ReplaceString(sFormattedHostname, sizeof(sFormattedHostname), "{GM}", "Zombie Escape", true);
|
ReplaceString(sFormattedHostname, sizeof(sFormattedHostname), "{GM}", "Zombie Escape", true);
|
||||||
|
|
||||||
int iLength = strlen(sFormattedHostname);
|
TidyHostname(sFormattedHostname);
|
||||||
if(iLength > 55) //if too long trim lagcomp
|
|
||||||
ReplaceString(sFormattedHostname, sizeof(sFormattedHostname), "LagCompensation | ", "", true);
|
for (int i = 0; i < sizeof(g_sFoldOrder) && strlen(sFormattedHostname) > g_cvMaxLength.IntValue; i++)
|
||||||
|
{
|
||||||
|
ReplaceString(sFormattedHostname, sizeof(sFormattedHostname), g_sFoldOrder[i], "", true);
|
||||||
|
TidyHostname(sFormattedHostname);
|
||||||
|
}
|
||||||
|
|
||||||
|
char sCurrentHostname[128];
|
||||||
|
g_cvHostname.GetString(sCurrentHostname, sizeof(sCurrentHostname));
|
||||||
|
|
||||||
|
if (strcmp(sFormattedHostname, sCurrentHostname, true) == 0)
|
||||||
|
return;
|
||||||
|
|
||||||
g_cvHostname.SetString(sFormattedHostname, false, false);
|
g_cvHostname.SetString(sFormattedHostname, false, false);
|
||||||
|
|
||||||
|
if (g_cvSendToClients.BoolValue)
|
||||||
|
SendHostname(sFormattedHostname);
|
||||||
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------------------------------
|
||||||
|
// Purpose: The scoreboard only reads the hostname from server_spawn, which the client's engine fires
|
||||||
|
// locally from svc_ServerInfo on connect. Send a copy straight to each client so it never
|
||||||
|
// reaches server-side listeners, and fill every field so other client listeners
|
||||||
|
// (mumble, abuse report, steam share) see the same values they got on connect.
|
||||||
|
//----------------------------------------------------------------------------------------------------
|
||||||
|
void SendHostname(const char[] sHostname)
|
||||||
|
{
|
||||||
|
Event hEvent = CreateEvent("server_spawn", true);
|
||||||
|
if (hEvent == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
int iIP = g_cvHostIP.IntValue;
|
||||||
|
int iPort = g_cvHostPort.IntValue;
|
||||||
|
|
||||||
|
char sAddress[32];
|
||||||
|
Format(sAddress, sizeof(sAddress), "%d.%d.%d.%d:%d", (iIP >>> 24) & 0xFF, (iIP >>> 16) & 0xFF, (iIP >>> 8) & 0xFF, iIP & 0xFF, iPort);
|
||||||
|
|
||||||
|
char sGame[32];
|
||||||
|
GetGameFolderName(sGame, sizeof(sGame));
|
||||||
|
|
||||||
|
char sMap[PLATFORM_MAX_PATH];
|
||||||
|
GetCurrentMap(sMap, sizeof(sMap));
|
||||||
|
|
||||||
|
char sPassword[64];
|
||||||
|
g_cvPassword.GetString(sPassword, sizeof(sPassword));
|
||||||
|
|
||||||
|
hEvent.SetString("hostname", sHostname);
|
||||||
|
hEvent.SetString("address", sAddress);
|
||||||
|
hEvent.SetInt("ip", iIP);
|
||||||
|
hEvent.SetInt("port", iPort);
|
||||||
|
hEvent.SetString("game", sGame);
|
||||||
|
hEvent.SetString("mapname", sMap);
|
||||||
|
hEvent.SetInt("maxplayers", MaxClients);
|
||||||
|
hEvent.SetString("os", "LINUX");
|
||||||
|
hEvent.SetBool("dedicated", IsDedicatedServer());
|
||||||
|
hEvent.SetBool("password", sPassword[0] != '\0');
|
||||||
|
|
||||||
|
for (int client = 1; client <= MaxClients; client++)
|
||||||
|
{
|
||||||
|
if (!IsClientInGame(client) || IsFakeClient(client))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
hEvent.FireToClient(client);
|
||||||
|
}
|
||||||
|
|
||||||
|
// FireToClient does not free the event.
|
||||||
|
hEvent.Cancel();
|
||||||
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------------------------------
|
||||||
|
// Purpose: The couch entity is purged on every round restart and respawned at round start, so a
|
||||||
|
// remembered placement counts too, otherwise the hostname would flicker each round.
|
||||||
|
//----------------------------------------------------------------------------------------------------
|
||||||
|
bool IsCouchPresent()
|
||||||
|
{
|
||||||
|
if (!g_bCouchLoaded)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return Couch_GetCouch() != -1 || Couch_IsPlaced();
|
||||||
}
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------------------------
|
||||||
// Purpose:
|
// Purpose:
|
||||||
//----------------------------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------------------------
|
||||||
public void OnClassesPathChange(ConVar convar, const char[] oldValue, const char[] newValue)
|
public void Couch_OnCouchSpawned(int couch)
|
||||||
{
|
{
|
||||||
char sFile[PLATFORM_MAX_PATH];
|
RefreshHostname();
|
||||||
BuildPath(Path_SM, sFile, sizeof(sFile), "%s", newValue);
|
}
|
||||||
|
|
||||||
if (StrContains(sFile, "nemesis", false) != -1)
|
//----------------------------------------------------------------------------------------------------
|
||||||
g_bNemesis = true;
|
// Purpose: Couch_Remove fires this before it forgets the placement, so wait a frame.
|
||||||
else
|
//----------------------------------------------------------------------------------------------------
|
||||||
g_bNemesis = false;
|
public void Couch_OnCouchRemoved()
|
||||||
|
{
|
||||||
|
RequestFrame(Frame_RefreshHostname);
|
||||||
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------------------------------
|
||||||
|
// Purpose:
|
||||||
|
//----------------------------------------------------------------------------------------------------
|
||||||
|
public void Frame_RefreshHostname(any data)
|
||||||
|
{
|
||||||
|
RefreshHostname();
|
||||||
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------------------------------
|
||||||
|
// Purpose: Empty tokens and folded tags leave separators and spaces behind.
|
||||||
|
//----------------------------------------------------------------------------------------------------
|
||||||
|
void TidyHostname(char[] sText)
|
||||||
|
{
|
||||||
|
DropEmptySeparators(sText);
|
||||||
|
CollapseSpaces(sText);
|
||||||
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------------------------------
|
||||||
|
// Purpose: {SD} brings its own " | ", so a format like "{GM} | {SD}" leaves "| |" with a stage and a
|
||||||
|
// trailing "|" without one. Drop any separator with nothing but spaces on one side.
|
||||||
|
//----------------------------------------------------------------------------------------------------
|
||||||
|
void DropEmptySeparators(char[] sText)
|
||||||
|
{
|
||||||
|
int iOut = 0;
|
||||||
|
for (int i = 0; sText[i] != '\0'; i++)
|
||||||
|
{
|
||||||
|
if (sText[i] == '|')
|
||||||
|
{
|
||||||
|
int iLast = iOut;
|
||||||
|
while (iLast > 0 && sText[iLast - 1] == ' ')
|
||||||
|
iLast--;
|
||||||
|
|
||||||
|
if (iLast == 0 || sText[iLast - 1] == '|')
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
sText[iOut++] = sText[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
while (iOut > 0 && (sText[iOut - 1] == ' ' || sText[iOut - 1] == '|'))
|
||||||
|
iOut--;
|
||||||
|
|
||||||
|
sText[iOut] = '\0';
|
||||||
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------------------------------
|
||||||
|
// Purpose: Tokens that resolve to nothing leave their surrounding spaces behind, so squash any run
|
||||||
|
// of spaces down to one and trim the ends.
|
||||||
|
//----------------------------------------------------------------------------------------------------
|
||||||
|
void CollapseSpaces(char[] sText)
|
||||||
|
{
|
||||||
|
int iOut = 0;
|
||||||
|
for (int i = 0; sText[i] != '\0'; i++)
|
||||||
|
{
|
||||||
|
if (sText[i] == ' ' && (iOut == 0 || sText[iOut - 1] == ' '))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
sText[iOut++] = sText[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (iOut > 0 && sText[iOut - 1] == ' ')
|
||||||
|
iOut--;
|
||||||
|
|
||||||
|
sText[iOut] = '\0';
|
||||||
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------------------------------
|
||||||
|
// Purpose: Looked up every refresh because not every server runs the InfoMessage plugin, and it
|
||||||
|
// may load after us.
|
||||||
|
//----------------------------------------------------------------------------------------------------
|
||||||
|
bool IsNemesisMap()
|
||||||
|
{
|
||||||
|
ConVar cvInfoMessage = FindConVar("sm_info_message_file");
|
||||||
|
if (cvInfoMessage == null)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
char sFile[PLATFORM_MAX_PATH];
|
||||||
|
cvInfoMessage.GetString(sFile, sizeof(sFile));
|
||||||
|
|
||||||
|
return StrContains(sFile, "nemesis", false) != -1;
|
||||||
}
|
}
|
||||||
@@ -15,6 +15,7 @@
|
|||||||
|
|
||||||
#undef REQUIRE_PLUGIN
|
#undef REQUIRE_PLUGIN
|
||||||
#include <AFKManager>
|
#include <AFKManager>
|
||||||
|
#include <ChatFilter2>
|
||||||
#define REQUIRE_PLUGIN
|
#define REQUIRE_PLUGIN
|
||||||
|
|
||||||
#pragma newdecls required
|
#pragma newdecls required
|
||||||
@@ -98,7 +99,15 @@ bool g_bLeaderWhitelisted[MAXPLAYERS + 1];
|
|||||||
bool g_bForceLeaderMute;
|
bool g_bForceLeaderMute;
|
||||||
bool g_bForceMuted[MAXPLAYERS + 1];
|
bool g_bForceMuted[MAXPLAYERS + 1];
|
||||||
|
|
||||||
|
// Our own copy of ZR's zombie flag. ZR_IsClientZombie throws on dead clients and team is
|
||||||
|
// unreliable at death (ZR round-end balancing puts living zombies on CT), so player_death
|
||||||
|
// reads this instead. Set on infection, cleared on spawn/cure/disconnect like ZR's own flag.
|
||||||
|
bool g_bZombie[MAXPLAYERS + 1];
|
||||||
|
|
||||||
bool g_bAFKManager;
|
bool g_bAFKManager;
|
||||||
|
bool g_bChatFilter2;
|
||||||
|
// ChatFilter2 safe chat per client, kept by ChatFilter2_OnSafeChatChanged so transmit hooks need no native call
|
||||||
|
bool g_bSafeChat[MAXPLAYERS + 1];
|
||||||
bool g_bWorldTextBroken;
|
bool g_bWorldTextBroken;
|
||||||
|
|
||||||
GlobalForward g_fwdOnLeaderAdded;
|
GlobalForward g_fwdOnLeaderAdded;
|
||||||
@@ -227,6 +236,13 @@ public void OnPluginStart()
|
|||||||
AddMultiTargetFilter("@!leaders", Filter_NotLeaders, "everyone but the Leaders", false);
|
AddMultiTargetFilter("@!leaders", Filter_NotLeaders, "everyone but the Leaders", false);
|
||||||
AddMultiTargetFilter("@leader", Filter_Leader, "the Primary Leader", false);
|
AddMultiTargetFilter("@leader", Filter_Leader, "the Primary Leader", false);
|
||||||
AddMultiTargetFilter("@!leader", Filter_NotLeader, "everyone but the Primary Leader", false);
|
AddMultiTargetFilter("@!leader", Filter_NotLeader, "everyone but the Primary Leader", false);
|
||||||
|
|
||||||
|
// Late load: pick up zombies infected before we were running.
|
||||||
|
for (int i = 1; i <= MaxClients; i++)
|
||||||
|
{
|
||||||
|
if (IsClientInGame(i))
|
||||||
|
g_bZombie[i] = IsLivingZombie(i);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OnPluginEnd()
|
public void OnPluginEnd()
|
||||||
@@ -240,18 +256,24 @@ public void OnPluginEnd()
|
|||||||
public void OnAllPluginsLoaded()
|
public void OnAllPluginsLoaded()
|
||||||
{
|
{
|
||||||
g_bAFKManager = LibraryExists("AFKManager");
|
g_bAFKManager = LibraryExists("AFKManager");
|
||||||
|
if (LibraryExists("ChatFilter2"))
|
||||||
|
Chat_OnChatFilter2Added();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OnLibraryAdded(const char[] name)
|
public void OnLibraryAdded(const char[] name)
|
||||||
{
|
{
|
||||||
if (StrEqual(name, "AFKManager"))
|
if (StrEqual(name, "AFKManager"))
|
||||||
g_bAFKManager = true;
|
g_bAFKManager = true;
|
||||||
|
else if (StrEqual(name, "ChatFilter2"))
|
||||||
|
Chat_OnChatFilter2Added();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OnLibraryRemoved(const char[] name)
|
public void OnLibraryRemoved(const char[] name)
|
||||||
{
|
{
|
||||||
if (StrEqual(name, "AFKManager"))
|
if (StrEqual(name, "AFKManager"))
|
||||||
g_bAFKManager = false;
|
g_bAFKManager = false;
|
||||||
|
else if (StrEqual(name, "ChatFilter2"))
|
||||||
|
Chat_OnChatFilter2Removed();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OnMapStart()
|
public void OnMapStart()
|
||||||
@@ -357,6 +379,9 @@ public void OnClientDisconnect(int client)
|
|||||||
BaseComm_SetClientMute(client, false);
|
BaseComm_SetClientMute(client, false);
|
||||||
g_bForceMuted[client] = false;
|
g_bForceMuted[client] = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
g_bZombie[client] = false;
|
||||||
|
g_bSafeChat[client] = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Event_RoundStart(Event event, const char[] name, bool dontBroadcast)
|
public void Event_RoundStart(Event event, const char[] name, bool dontBroadcast)
|
||||||
@@ -368,6 +393,12 @@ public void Event_RoundStart(Event event, const char[] name, bool dontBroadcast)
|
|||||||
public void Event_PlayerSpawn(Event event, const char[] name, bool dontBroadcast)
|
public void Event_PlayerSpawn(Event event, const char[] name, bool dontBroadcast)
|
||||||
{
|
{
|
||||||
int userid = event.GetInt("userid");
|
int userid = event.GetInt("userid");
|
||||||
|
|
||||||
|
// Everyone spawns human (ZR clears its flag here too); infection after spawn sets it again.
|
||||||
|
int client = GetClientOfUserId(userid);
|
||||||
|
if (client > 0)
|
||||||
|
g_bZombie[client] = false;
|
||||||
|
|
||||||
// Attach effects slightly late: at spawn time ZR state and position may not be final.
|
// Attach effects slightly late: at spawn time ZR state and position may not be final.
|
||||||
CreateTimer(0.3, Timer_ResumeEffects, userid, TIMER_FLAG_NO_MAPCHANGE);
|
CreateTimer(0.3, Timer_ResumeEffects, userid, TIMER_FLAG_NO_MAPCHANGE);
|
||||||
}
|
}
|
||||||
@@ -386,9 +417,11 @@ public void Event_PlayerDeath(Event event, const char[] name, bool dontBroadcast
|
|||||||
if (client <= 0)
|
if (client <= 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Toll and announce only for an active (human) leader falling; an infected leader dying later as a zombie stays quiet.
|
// Toll and announce only for an active (human) leader falling. A leader who was infected,
|
||||||
// ZR_IsClientHuman throws on dead clients, so go by team: zombified leaders sit on T.
|
// or picked as mother zombie, and then dies as a zombie stays quiet. ZR's fake infection
|
||||||
bool diedAsHuman = GetClientTeam(client) == CS_TEAM_CT;
|
// death fires before ZR_OnClientInfected, so g_bZombie is still false for that one and the
|
||||||
|
// toll marks the infection.
|
||||||
|
bool diedAsHuman = !g_bZombie[client];
|
||||||
|
|
||||||
if (IsLeader(client) && diedAsHuman)
|
if (IsLeader(client) && diedAsHuman)
|
||||||
{
|
{
|
||||||
@@ -421,6 +454,8 @@ public void Event_PlayerTeam(Event event, const char[] name, bool dontBroadcast)
|
|||||||
|
|
||||||
public void ZR_OnClientInfected(int client, int attacker, bool motherInfect, bool respawnOverride, bool respawn)
|
public void ZR_OnClientInfected(int client, int attacker, bool motherInfect, bool respawnOverride, bool respawn)
|
||||||
{
|
{
|
||||||
|
g_bZombie[client] = true;
|
||||||
|
|
||||||
char verb[80];
|
char verb[80];
|
||||||
if (attacker > 0 && attacker <= MaxClients && attacker != client)
|
if (attacker > 0 && attacker <= MaxClients && attacker != client)
|
||||||
Format(verb, sizeof(verb), "has been infected by \x04%N\x01", attacker);
|
Format(verb, sizeof(verb), "has been infected by \x04%N\x01", attacker);
|
||||||
@@ -432,6 +467,8 @@ public void ZR_OnClientInfected(int client, int attacker, bool motherInfect, boo
|
|||||||
|
|
||||||
public void ZR_OnClientHumanPost(int client, bool respawn, bool protect)
|
public void ZR_OnClientHumanPost(int client, bool respawn, bool protect)
|
||||||
{
|
{
|
||||||
|
g_bZombie[client] = false;
|
||||||
|
|
||||||
if (IsEffectsActive(client))
|
if (IsEffectsActive(client))
|
||||||
Effects_Resume(client);
|
Effects_Resume(client);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,6 +18,29 @@ public Action OnClientSayCommand(int client, const char[] command, const char[]
|
|||||||
return Plugin_Handled;
|
return Plugin_Handled;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------------------------------
|
||||||
|
// ChatFilter2 (optional): safe chat players get censored marker titles.
|
||||||
|
//----------------------------------------------------------------------------------------------------
|
||||||
|
public void ChatFilter2_OnSafeChatChanged(int client, bool enabled)
|
||||||
|
{
|
||||||
|
g_bSafeChat[client] = enabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Chat_OnChatFilter2Added()
|
||||||
|
{
|
||||||
|
g_bChatFilter2 = true;
|
||||||
|
for (int i = 1; i <= MaxClients; i++)
|
||||||
|
g_bSafeChat[i] = IsClientInGame(i) && ChatFilter2_IsSafeChatEnabled(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Censored copies stay up but nobody counts as safe chat any more, so everyone sees the raw text.
|
||||||
|
void Chat_OnChatFilter2Removed()
|
||||||
|
{
|
||||||
|
g_bChatFilter2 = false;
|
||||||
|
for (int i = 1; i <= MaxClients; i++)
|
||||||
|
g_bSafeChat[i] = false;
|
||||||
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------------------------
|
||||||
// Force-mute: while any leader is talking, mute everyone without admin access.
|
// Force-mute: while any leader is talking, mute everyone without admin access.
|
||||||
//----------------------------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------------------------
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
//----------------------------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------------------------
|
||||||
// Leader3 markers: unloze_ping prop_dynamic markers with point_worldtext titles.
|
// Leader3 markers: unloze_ping prop_dynamic markers with point_worldtext titles.
|
||||||
// The ArrayList is the authoritative store; entities are respawned from it every round.
|
// The ArrayList is the authoritative store; entities are respawned from it every round.
|
||||||
|
// A title that ChatFilter2 censors gets a second text entity; SetTransmit shows the censored
|
||||||
|
// one to safe chat players and the raw one to everyone else.
|
||||||
//----------------------------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
enum struct Marker
|
enum struct Marker
|
||||||
@@ -10,9 +12,11 @@ enum struct Marker
|
|||||||
int skin;
|
int skin;
|
||||||
float pos[3];
|
float pos[3];
|
||||||
char title[128];
|
char title[128];
|
||||||
|
char censoredTitle[128]; // empty when ChatFilter2 is missing or the title is clean
|
||||||
float placedAt;
|
float placedAt;
|
||||||
int propRef;
|
int propRef;
|
||||||
int textRef;
|
int textRef;
|
||||||
|
int censoredTextRef;
|
||||||
}
|
}
|
||||||
|
|
||||||
ArrayList g_alMarkers;
|
ArrayList g_alMarkers;
|
||||||
@@ -97,9 +101,11 @@ void Marker_Place(int client, int skin)
|
|||||||
marker.skin = skin;
|
marker.skin = skin;
|
||||||
marker.pos = pos;
|
marker.pos = pos;
|
||||||
marker.title[0] = '\0';
|
marker.title[0] = '\0';
|
||||||
|
marker.censoredTitle[0] = '\0';
|
||||||
marker.placedAt = GetGameTime();
|
marker.placedAt = GetGameTime();
|
||||||
marker.propRef = INVALID_ENT_REFERENCE;
|
marker.propRef = INVALID_ENT_REFERENCE;
|
||||||
marker.textRef = INVALID_ENT_REFERENCE;
|
marker.textRef = INVALID_ENT_REFERENCE;
|
||||||
|
marker.censoredTextRef = INVALID_ENT_REFERENCE;
|
||||||
|
|
||||||
int idx = g_alMarkers.PushArray(marker);
|
int idx = g_alMarkers.PushArray(marker);
|
||||||
SpawnMarkerProp(idx);
|
SpawnMarkerProp(idx);
|
||||||
@@ -136,6 +142,9 @@ bool Marker_GetTitle(int client, int skin, char[] buf, int maxlen)
|
|||||||
if (marker.title[0] == '\0')
|
if (marker.title[0] == '\0')
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
if (g_bSafeChat[client] && marker.censoredTitle[0] != '\0')
|
||||||
|
strcopy(buf, maxlen, marker.censoredTitle);
|
||||||
|
else
|
||||||
strcopy(buf, maxlen, marker.title);
|
strcopy(buf, maxlen, marker.title);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -190,6 +199,17 @@ void UppercaseAllLowerTitle(char[] text)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Marker_CensorTitle(Marker marker)
|
||||||
|
{
|
||||||
|
marker.censoredTitle[0] = '\0';
|
||||||
|
if (!g_bChatFilter2 || marker.title[0] == '\0')
|
||||||
|
return;
|
||||||
|
|
||||||
|
strcopy(marker.censoredTitle, sizeof(marker.censoredTitle), marker.title);
|
||||||
|
if (!ChatFilter2_CensorText(marker.censoredTitle, sizeof(marker.censoredTitle)))
|
||||||
|
marker.censoredTitle[0] = '\0';
|
||||||
|
}
|
||||||
|
|
||||||
void Marker_SetTitle(int client, const char[] text)
|
void Marker_SetTitle(int client, const char[] text)
|
||||||
{
|
{
|
||||||
int userid = GetClientUserId(client);
|
int userid = GetClientUserId(client);
|
||||||
@@ -217,6 +237,7 @@ void Marker_SetTitle(int client, const char[] text)
|
|||||||
g_alMarkers.GetArray(lastIdx, marker);
|
g_alMarkers.GetArray(lastIdx, marker);
|
||||||
strcopy(marker.title, sizeof(marker.title), text);
|
strcopy(marker.title, sizeof(marker.title), text);
|
||||||
UppercaseAllLowerTitle(marker.title);
|
UppercaseAllLowerTitle(marker.title);
|
||||||
|
Marker_CensorTitle(marker);
|
||||||
g_alMarkers.SetArray(lastIdx, marker);
|
g_alMarkers.SetArray(lastIdx, marker);
|
||||||
Marker_UpdateText(lastIdx);
|
Marker_UpdateText(lastIdx);
|
||||||
|
|
||||||
@@ -228,7 +249,23 @@ void Marker_SetTitle(int client, const char[] text)
|
|||||||
PrintToChat(client, "%sTitle removed from your \x04%s\x01 marker.", PREFIX, skinName);
|
PrintToChat(client, "%sTitle removed from your \x04%s\x01 marker.", PREFIX, skinName);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (marker.censoredTitle[0] == '\0')
|
||||||
|
{
|
||||||
PrintToChatAll("%s\x04%N\x01 marked \x04%s\x01: \x04%s", PREFIX, client, skinName, marker.title);
|
PrintToChatAll("%s\x04%N\x01 marked \x04%s\x01: \x04%s", PREFIX, client, skinName, marker.title);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 1; i <= MaxClients; i++)
|
||||||
|
{
|
||||||
|
if (!IsClientInGame(i))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (g_bSafeChat[i])
|
||||||
|
PrintToChat(i, "%s\x04%N\x01 marked \x04%s\x01: \x04%s", PREFIX, client, skinName, marker.censoredTitle);
|
||||||
|
else
|
||||||
|
PrintToChat(i, "%s\x04%N\x01 marked \x04%s\x01: \x04%s", PREFIX, client, skinName, marker.title);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------------------------
|
||||||
@@ -266,18 +303,41 @@ void SpawnMarkerText(int idx)
|
|||||||
if (marker.title[0] == '\0' || g_bWorldTextBroken)
|
if (marker.title[0] == '\0' || g_bWorldTextBroken)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
float pos[3];
|
||||||
|
ComputeMarkerTextPos(marker, pos);
|
||||||
|
|
||||||
|
int ent = SpawnWorldText(marker.title, pos);
|
||||||
|
if (ent == -1)
|
||||||
|
return;
|
||||||
|
marker.textRef = EntIndexToEntRef(ent);
|
||||||
|
|
||||||
|
// The raw text is hidden from safe chat players even if the censored copy fails to spawn.
|
||||||
|
if (marker.censoredTitle[0] != '\0')
|
||||||
|
{
|
||||||
|
SDKHook(ent, SDKHook_SetTransmit, Hook_TitleRawTransmit);
|
||||||
|
|
||||||
|
int censored = SpawnWorldText(marker.censoredTitle, pos);
|
||||||
|
if (censored != -1)
|
||||||
|
{
|
||||||
|
SDKHook(censored, SDKHook_SetTransmit, Hook_TitleCensoredTransmit);
|
||||||
|
marker.censoredTextRef = EntIndexToEntRef(censored);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
g_alMarkers.SetArray(idx, marker);
|
||||||
|
}
|
||||||
|
|
||||||
|
int SpawnWorldText(const char[] text, const float pos[3])
|
||||||
|
{
|
||||||
int ent = CreateEntityByName("point_worldtext");
|
int ent = CreateEntityByName("point_worldtext");
|
||||||
if (ent == -1)
|
if (ent == -1)
|
||||||
{
|
{
|
||||||
// Engine build without point_worldtext: titles stay chat-only for this map.
|
// Engine build without point_worldtext: titles stay chat-only for this map.
|
||||||
g_bWorldTextBroken = true;
|
g_bWorldTextBroken = true;
|
||||||
LogMessage("point_worldtext could not be created; marker titles will not render in the world.");
|
LogMessage("point_worldtext could not be created; marker titles will not render in the world.");
|
||||||
return;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
char text[192];
|
|
||||||
Format(text, sizeof(text), "%s", marker.title);
|
|
||||||
|
|
||||||
DispatchKeyValue(ent, "message", text);
|
DispatchKeyValue(ent, "message", text);
|
||||||
DispatchKeyValue(ent, "font", "10");
|
DispatchKeyValue(ent, "font", "10");
|
||||||
DispatchKeyValue(ent, "textsize", "12");
|
DispatchKeyValue(ent, "textsize", "12");
|
||||||
@@ -285,13 +345,18 @@ void SpawnMarkerText(int idx)
|
|||||||
DispatchKeyValue(ent, "orientation", "1");
|
DispatchKeyValue(ent, "orientation", "1");
|
||||||
DispatchKeyValue(ent, "rainbow", "1");
|
DispatchKeyValue(ent, "rainbow", "1");
|
||||||
DispatchSpawn(ent);
|
DispatchSpawn(ent);
|
||||||
|
|
||||||
float pos[3];
|
|
||||||
ComputeMarkerTextPos(marker, pos);
|
|
||||||
TeleportEntity(ent, pos, NULL_VECTOR, NULL_VECTOR);
|
TeleportEntity(ent, pos, NULL_VECTOR, NULL_VECTOR);
|
||||||
|
return ent;
|
||||||
|
}
|
||||||
|
|
||||||
marker.textRef = EntIndexToEntRef(ent);
|
public Action Hook_TitleRawTransmit(int ent, int client)
|
||||||
g_alMarkers.SetArray(idx, marker);
|
{
|
||||||
|
return g_bSafeChat[client] ? Plugin_Handled : Plugin_Continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Action Hook_TitleCensoredTransmit(int ent, int client)
|
||||||
|
{
|
||||||
|
return g_bSafeChat[client] ? Plugin_Continue : Plugin_Handled;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ComputeMarkerTextPos(const Marker marker, float pos[3])
|
void ComputeMarkerTextPos(const Marker marker, float pos[3])
|
||||||
@@ -339,33 +404,42 @@ void Marker_UpdateText(int idx)
|
|||||||
Marker marker;
|
Marker marker;
|
||||||
g_alMarkers.GetArray(idx, marker);
|
g_alMarkers.GetArray(idx, marker);
|
||||||
|
|
||||||
if (marker.title[0] == '\0')
|
int ent = LiveEntRef(marker.textRef, "point_worldtext");
|
||||||
|
int censored = LiveEntRef(marker.censoredTextRef, "point_worldtext");
|
||||||
|
|
||||||
|
// No title, a lost entity, or a title that gained or lost its censored copy: respawn.
|
||||||
|
// The last case is rare, and respawning keeps the transmit hooks in step with the entities.
|
||||||
|
if (marker.title[0] == '\0' || ent == -1 || (marker.censoredTitle[0] != '\0') != (censored != -1))
|
||||||
{
|
{
|
||||||
KillEntRef(marker.textRef, "point_worldtext");
|
KillEntRef(marker.textRef, "point_worldtext");
|
||||||
|
KillEntRef(marker.censoredTextRef, "point_worldtext");
|
||||||
marker.textRef = INVALID_ENT_REFERENCE;
|
marker.textRef = INVALID_ENT_REFERENCE;
|
||||||
|
marker.censoredTextRef = INVALID_ENT_REFERENCE;
|
||||||
g_alMarkers.SetArray(idx, marker);
|
g_alMarkers.SetArray(idx, marker);
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
int ent = LiveEntRef(marker.textRef, "point_worldtext");
|
|
||||||
if (ent == -1)
|
|
||||||
{
|
|
||||||
SpawnMarkerText(idx);
|
SpawnMarkerText(idx);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
SetVariantString(marker.title);
|
|
||||||
AcceptEntityInput(ent, "SetText");
|
|
||||||
|
|
||||||
float pos[3];
|
float pos[3];
|
||||||
ComputeMarkerTextPos(marker, pos);
|
ComputeMarkerTextPos(marker, pos);
|
||||||
|
|
||||||
|
SetVariantString(marker.title);
|
||||||
|
AcceptEntityInput(ent, "SetText");
|
||||||
TeleportEntity(ent, pos, NULL_VECTOR, NULL_VECTOR);
|
TeleportEntity(ent, pos, NULL_VECTOR, NULL_VECTOR);
|
||||||
|
|
||||||
|
if (censored != -1)
|
||||||
|
{
|
||||||
|
SetVariantString(marker.censoredTitle);
|
||||||
|
AcceptEntityInput(censored, "SetText");
|
||||||
|
TeleportEntity(censored, pos, NULL_VECTOR, NULL_VECTOR);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Marker_KillEnts(Marker marker)
|
void Marker_KillEnts(Marker marker)
|
||||||
{
|
{
|
||||||
KillEntRef(marker.propRef, "prop_dynamic");
|
KillEntRef(marker.propRef, "prop_dynamic");
|
||||||
KillEntRef(marker.textRef, "point_worldtext");
|
KillEntRef(marker.textRef, "point_worldtext");
|
||||||
|
KillEntRef(marker.censoredTextRef, "point_worldtext");
|
||||||
}
|
}
|
||||||
|
|
||||||
void KillEntRef(int ref, const char[] expectedClass)
|
void KillEntRef(int ref, const char[] expectedClass)
|
||||||
@@ -400,6 +474,7 @@ void Markers_OnRoundStart()
|
|||||||
g_alMarkers.GetArray(i, marker);
|
g_alMarkers.GetArray(i, marker);
|
||||||
marker.propRef = INVALID_ENT_REFERENCE;
|
marker.propRef = INVALID_ENT_REFERENCE;
|
||||||
marker.textRef = INVALID_ENT_REFERENCE;
|
marker.textRef = INVALID_ENT_REFERENCE;
|
||||||
|
marker.censoredTextRef = INVALID_ENT_REFERENCE;
|
||||||
g_alMarkers.SetArray(i, marker);
|
g_alMarkers.SetArray(i, marker);
|
||||||
|
|
||||||
SpawnMarkerProp(i);
|
SpawnMarkerProp(i);
|
||||||
|
|||||||
@@ -13,7 +13,7 @@
|
|||||||
// at least this many letters/digits is kept as-is, unicode decoration
|
// at least this many letters/digits is kept as-is, unicode decoration
|
||||||
// and all, unless an advert or banned filter matches. An admin can
|
// and all, unless an advert or banned filter matches. An admin can
|
||||||
// target such a name by its typeable part. 0 disables the exemption
|
// target such a name by its typeable part. 0 disables the exemption
|
||||||
"keep_typeable_run" "5"
|
"keep_typeable_run" "4"
|
||||||
|
|
||||||
// non-ASCII characters that are always kept.
|
// non-ASCII characters that are always kept.
|
||||||
// accented Latin letters (À-ÿ, Latin Extended-A) are also kept, but only
|
// accented Latin letters (À-ÿ, Latin Extended-A) are also kept, but only
|
||||||
@@ -55,6 +55,8 @@
|
|||||||
"У" "Y"
|
"У" "Y"
|
||||||
"З" "3"
|
"З" "3"
|
||||||
// Cyrillic mirrored/aesthetic lookalikes
|
// Cyrillic mirrored/aesthetic lookalikes
|
||||||
|
"Ш" "W"
|
||||||
|
"ш" "w"
|
||||||
"Я" "R"
|
"Я" "R"
|
||||||
"я" "r"
|
"я" "r"
|
||||||
"И" "N"
|
"И" "N"
|
||||||
@@ -64,6 +66,18 @@
|
|||||||
"м" "m"
|
"м" "m"
|
||||||
"н" "h"
|
"н" "h"
|
||||||
"т" "t"
|
"т" "t"
|
||||||
|
"є" "e"
|
||||||
|
"Є" "E"
|
||||||
|
"ц" "u"
|
||||||
|
"п" "n"
|
||||||
|
"г" "r"
|
||||||
|
"Г" "r"
|
||||||
|
"ґ" "r"
|
||||||
|
"Ґ" "r"
|
||||||
|
"ь" "b"
|
||||||
|
"Ь" "b"
|
||||||
|
"ч" "4"
|
||||||
|
"Ч" "4"
|
||||||
// Cyrillic with diacritics, same lookalikes as their base letters
|
// Cyrillic with diacritics, same lookalikes as their base letters
|
||||||
"Ѐ" "E"
|
"Ѐ" "E"
|
||||||
"Ё" "E"
|
"Ё" "E"
|
||||||
@@ -110,6 +124,8 @@
|
|||||||
"ό" "o"
|
"ό" "o"
|
||||||
"ώ" "w"
|
"ώ" "w"
|
||||||
// Greek aesthetic lookalikes
|
// Greek aesthetic lookalikes
|
||||||
|
"Ξ" "E"
|
||||||
|
"ξ" "e"
|
||||||
"Λ" "A"
|
"Λ" "A"
|
||||||
"Σ" "E"
|
"Σ" "E"
|
||||||
"Δ" "A"
|
"Δ" "A"
|
||||||
@@ -119,11 +135,110 @@
|
|||||||
"μ" "u"
|
"μ" "u"
|
||||||
"ω" "w"
|
"ω" "w"
|
||||||
"η" "n"
|
"η" "n"
|
||||||
|
"ι" "i"
|
||||||
|
"ρ" "p"
|
||||||
|
"κ" "k"
|
||||||
|
"τ" "t"
|
||||||
|
"υ" "u"
|
||||||
|
"ε" "e"
|
||||||
|
"ς" "c"
|
||||||
|
"χ" "x"
|
||||||
|
"γ" "y"
|
||||||
|
"π" "n"
|
||||||
|
"σ" "o"
|
||||||
// math symbols used as letters
|
// math symbols used as letters
|
||||||
"∂" "d"
|
"∂" "d"
|
||||||
"∑" "E"
|
"∑" "E"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Cyrillic spelled out phonetically (simplified BGN/PCGN), for words that
|
||||||
|
// are really Cyrillic. Runs before "confusables"; a Latin word with only
|
||||||
|
// lookalike Cyrillic mixed in ("аdmin"), or a word mixing in Greek or styled
|
||||||
|
// letters ("ιηƒιηιтє"), is left to the confusables instead, and only its
|
||||||
|
// Cyrillic letters without a confusable are spelled out.
|
||||||
|
// key = the Cyrillic letter (raw UTF-8), value = Latin spelling
|
||||||
|
"transliterate"
|
||||||
|
{
|
||||||
|
// Russian
|
||||||
|
"а" "a"
|
||||||
|
"б" "b"
|
||||||
|
"в" "v"
|
||||||
|
"г" "g"
|
||||||
|
"д" "d"
|
||||||
|
"е" "e"
|
||||||
|
"ё" "e"
|
||||||
|
"ж" "zh"
|
||||||
|
"з" "z"
|
||||||
|
"и" "i"
|
||||||
|
"й" "y"
|
||||||
|
"к" "k"
|
||||||
|
"л" "l"
|
||||||
|
"м" "m"
|
||||||
|
"н" "n"
|
||||||
|
"о" "o"
|
||||||
|
"п" "p"
|
||||||
|
"р" "r"
|
||||||
|
"с" "s"
|
||||||
|
"т" "t"
|
||||||
|
"у" "u"
|
||||||
|
"ф" "f"
|
||||||
|
"х" "kh"
|
||||||
|
"ц" "ts"
|
||||||
|
"ч" "ch"
|
||||||
|
"ш" "sh"
|
||||||
|
"щ" "shch"
|
||||||
|
"ъ" ""
|
||||||
|
"ы" "y"
|
||||||
|
"ь" ""
|
||||||
|
"э" "e"
|
||||||
|
"ю" "yu"
|
||||||
|
"я" "ya"
|
||||||
|
"А" "A"
|
||||||
|
"Б" "B"
|
||||||
|
"В" "V"
|
||||||
|
"Г" "G"
|
||||||
|
"Д" "D"
|
||||||
|
"Е" "E"
|
||||||
|
"Ё" "E"
|
||||||
|
"Ж" "Zh"
|
||||||
|
"З" "Z"
|
||||||
|
"И" "I"
|
||||||
|
"Й" "Y"
|
||||||
|
"К" "K"
|
||||||
|
"Л" "L"
|
||||||
|
"М" "M"
|
||||||
|
"Н" "N"
|
||||||
|
"О" "O"
|
||||||
|
"П" "P"
|
||||||
|
"Р" "R"
|
||||||
|
"С" "S"
|
||||||
|
"Т" "T"
|
||||||
|
"У" "U"
|
||||||
|
"Ф" "F"
|
||||||
|
"Х" "Kh"
|
||||||
|
"Ц" "Ts"
|
||||||
|
"Ч" "Ch"
|
||||||
|
"Ш" "Sh"
|
||||||
|
"Щ" "Shch"
|
||||||
|
"Ъ" ""
|
||||||
|
"Ы" "Y"
|
||||||
|
"Ь" ""
|
||||||
|
"Э" "E"
|
||||||
|
"Ю" "Yu"
|
||||||
|
"Я" "Ya"
|
||||||
|
// Ukrainian/Belarusian
|
||||||
|
"і" "i"
|
||||||
|
"ї" "yi"
|
||||||
|
"є" "ye"
|
||||||
|
"ґ" "g"
|
||||||
|
"ў" "u"
|
||||||
|
"І" "I"
|
||||||
|
"Ї" "Yi"
|
||||||
|
"Є" "Ye"
|
||||||
|
"Ґ" "G"
|
||||||
|
"Ў" "U"
|
||||||
|
}
|
||||||
|
|
||||||
// regexes (case-insensitive) whose matches are REMOVED from the name;
|
// regexes (case-insensitive) whose matches are REMOVED from the name;
|
||||||
// the rest of the name is kept. Applied to the pure-ASCII folded name.
|
// the rest of the name is kept. Applied to the pure-ASCII folded name.
|
||||||
"adverts"
|
"adverts"
|
||||||
@@ -144,7 +259,9 @@
|
|||||||
"6" "@((!?)me|(c?)t(s?)|(!?)admins|(!?)friends|random((c?)t?)|humans|spec|alive|dead|aim|bots)"
|
"6" "@((!?)me|(c?)t(s?)|(!?)admins|(!?)friends|random((c?)t?)|humans|spec|alive|dead|aim|bots)"
|
||||||
}
|
}
|
||||||
|
|
||||||
// replacement names; picked deterministically (client % count, next-free probe)
|
// replacement names; picked by Steam account (account id % count, next-free
|
||||||
|
// probe), so a player keeps the same one across visits. Reordering or
|
||||||
|
// adding names reshuffles who gets which
|
||||||
"names"
|
"names"
|
||||||
{
|
{
|
||||||
"1" "Reimu Hakurei"
|
"1" "Reimu Hakurei"
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
#define MAX_STACKED_MARKS 2 // combining marks allowed on one letter (Vietnamese needs 2)
|
#define MAX_STACKED_MARKS 2 // combining marks allowed on one letter (Vietnamese needs 2)
|
||||||
#define RELOAD_FILE "data/namefilter2_reload.dat"
|
#define RELOAD_FILE "data/namefilter2_reload.dat"
|
||||||
#define RELOAD_MAX_AGE 120 // seconds; older saves are from a previous server run
|
#define RELOAD_MAX_AGE 120 // seconds; older saves are from a previous server run
|
||||||
|
#define MAX_RENAME_RETRIES 2
|
||||||
|
|
||||||
enum struct SavedName
|
enum struct SavedName
|
||||||
{
|
{
|
||||||
@@ -18,10 +19,21 @@ enum struct SavedName
|
|||||||
char sCurrent[MAX_NAME_LENGTH];
|
char sCurrent[MAX_NAME_LENGTH];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// a filtered player who left; their client keeps the name we gave them
|
||||||
|
// (ChangeName runs `name` on the client), so they rejoin wearing it
|
||||||
|
enum struct PastName
|
||||||
|
{
|
||||||
|
char sOriginal[MAX_NAME_LENGTH];
|
||||||
|
char sAssigned[MAX_NAME_LENGTH];
|
||||||
|
bool bReplaced;
|
||||||
|
}
|
||||||
|
|
||||||
char g_sOriginalName[MAXPLAYERS + 1][MAX_NAME_LENGTH];
|
char g_sOriginalName[MAXPLAYERS + 1][MAX_NAME_LENGTH];
|
||||||
char g_sAssignedName[MAXPLAYERS + 1][MAX_NAME_LENGTH]; // the filtered name we gave the player
|
char g_sAssignedName[MAXPLAYERS + 1][MAX_NAME_LENGTH]; // the filtered name we gave the player
|
||||||
|
char g_sBlockEventName[MAXPLAYERS + 1][MAX_NAME_LENGTH]; // raw name whose player_changename to hide
|
||||||
|
int g_iRenameRetries[MAXPLAYERS + 1];
|
||||||
ArrayList g_SavedNames; // original names saved over a plugin reload
|
ArrayList g_SavedNames; // original names saved over a plugin reload
|
||||||
int g_iBlockNameChangeEvents[MAXPLAYERS + 1] = {0, ...};
|
StringMap g_PastNames; // engine auth id -> PastName, for the whole server run
|
||||||
bool g_bFilteredOnConnect[MAXPLAYERS + 1];
|
bool g_bFilteredOnConnect[MAXPLAYERS + 1];
|
||||||
bool g_bReplacedOnConnect[MAXPLAYERS + 1];
|
bool g_bReplacedOnConnect[MAXPLAYERS + 1];
|
||||||
bool g_bLastFilterReplaced; // whether the last FilterName() assigned a replacement name
|
bool g_bLastFilterReplaced; // whether the last FilterName() assigned a replacement name
|
||||||
@@ -31,6 +43,8 @@ ArrayList g_BannedExprs;
|
|||||||
ArrayList g_ReplacementNames;
|
ArrayList g_ReplacementNames;
|
||||||
ArrayList g_ConfusableFrom;
|
ArrayList g_ConfusableFrom;
|
||||||
ArrayList g_ConfusableTo;
|
ArrayList g_ConfusableTo;
|
||||||
|
StringMap g_ConfusableSet; // confusable keys, for spotting spoofed Latin words
|
||||||
|
StringMap g_Transliterate; // Cyrillic letter -> phonetic Latin
|
||||||
ArrayList g_WhitelistCps;
|
ArrayList g_WhitelistCps;
|
||||||
int g_iMinNameLength = 2;
|
int g_iMinNameLength = 2;
|
||||||
int g_iMinSurvivedPct = 50;
|
int g_iMinSurvivedPct = 50;
|
||||||
@@ -52,6 +66,9 @@ public void OnPluginStart()
|
|||||||
RegConsoleCmd("sm_originalname", Command_OriginalName, "Show a player's original name");
|
RegConsoleCmd("sm_originalname", Command_OriginalName, "Show a player's original name");
|
||||||
RegConsoleCmd("sm_changednames", Command_ChangedNames, "List all players whose names were changed");
|
RegConsoleCmd("sm_changednames", Command_ChangedNames, "List all players whose names were changed");
|
||||||
RegAdminCmd("sm_namefilter2_reload", Command_Reload, ADMFLAG_CONFIG, "Reload the NameFilter2 config");
|
RegAdminCmd("sm_namefilter2_reload", Command_Reload, ADMFLAG_CONFIG, "Reload the NameFilter2 config");
|
||||||
|
RegAdminCmd("sm_namefilter2_test", Command_Test, ADMFLAG_CONFIG, "Show what the filter makes of a name");
|
||||||
|
|
||||||
|
g_PastNames = new StringMap();
|
||||||
|
|
||||||
LoadConfig();
|
LoadConfig();
|
||||||
LoadSavedNames();
|
LoadSavedNames();
|
||||||
@@ -88,6 +105,25 @@ public void OnPluginEnd()
|
|||||||
hFile.WriteString(sCurrent, true);
|
hFile.WriteString(sCurrent, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// userid 0 ends the client list; the past names follow
|
||||||
|
hFile.WriteInt32(0);
|
||||||
|
|
||||||
|
StringMapSnapshot snap = g_PastNames.Snapshot();
|
||||||
|
for(int i = 0; i < snap.Length; i++)
|
||||||
|
{
|
||||||
|
char sAuth[64];
|
||||||
|
snap.GetKey(i, sAuth, sizeof(sAuth));
|
||||||
|
|
||||||
|
PastName past;
|
||||||
|
g_PastNames.GetArray(sAuth, past, sizeof(past));
|
||||||
|
|
||||||
|
hFile.WriteString(sAuth, true);
|
||||||
|
hFile.WriteString(past.sOriginal, true);
|
||||||
|
hFile.WriteString(past.sAssigned, true);
|
||||||
|
hFile.WriteInt8(past.bReplaced);
|
||||||
|
}
|
||||||
|
delete snap;
|
||||||
|
|
||||||
delete hFile;
|
delete hFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -106,13 +142,25 @@ void LoadSavedNames()
|
|||||||
if(hFile.ReadInt32(iSaved) && GetTime() - iSaved <= RELOAD_MAX_AGE)
|
if(hFile.ReadInt32(iSaved) && GetTime() - iSaved <= RELOAD_MAX_AGE)
|
||||||
{
|
{
|
||||||
SavedName saved;
|
SavedName saved;
|
||||||
while(hFile.ReadInt32(saved.iUserId)
|
while(hFile.ReadInt32(saved.iUserId) && saved.iUserId
|
||||||
&& hFile.ReadString(saved.sOriginal, sizeof(saved.sOriginal)) != -1
|
&& hFile.ReadString(saved.sOriginal, sizeof(saved.sOriginal)) != -1
|
||||||
&& hFile.ReadString(saved.sAssigned, sizeof(saved.sAssigned)) != -1
|
&& hFile.ReadString(saved.sAssigned, sizeof(saved.sAssigned)) != -1
|
||||||
&& hFile.ReadString(saved.sCurrent, sizeof(saved.sCurrent)) != -1)
|
&& hFile.ReadString(saved.sCurrent, sizeof(saved.sCurrent)) != -1)
|
||||||
{
|
{
|
||||||
g_SavedNames.PushArray(saved);
|
g_SavedNames.PushArray(saved);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char sAuth[64];
|
||||||
|
PastName past;
|
||||||
|
int iReplaced;
|
||||||
|
while(hFile.ReadString(sAuth, sizeof(sAuth)) != -1
|
||||||
|
&& hFile.ReadString(past.sOriginal, sizeof(past.sOriginal)) != -1
|
||||||
|
&& hFile.ReadString(past.sAssigned, sizeof(past.sAssigned)) != -1
|
||||||
|
&& hFile.ReadInt8(iReplaced))
|
||||||
|
{
|
||||||
|
past.bReplaced = iReplaced != 0;
|
||||||
|
g_PastNames.SetArray(sAuth, past, sizeof(past));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
delete hFile;
|
delete hFile;
|
||||||
@@ -145,7 +193,8 @@ bool RestoreSavedName(int client, const char[] sName)
|
|||||||
|
|
||||||
public void OnClientConnected(int client)
|
public void OnClientConnected(int client)
|
||||||
{
|
{
|
||||||
g_iBlockNameChangeEvents[client] = 0;
|
g_sBlockEventName[client][0] = '\0';
|
||||||
|
g_iRenameRetries[client] = 0;
|
||||||
g_bFilteredOnConnect[client] = false;
|
g_bFilteredOnConnect[client] = false;
|
||||||
g_bReplacedOnConnect[client] = false;
|
g_bReplacedOnConnect[client] = false;
|
||||||
g_sAssignedName[client][0] = '\0';
|
g_sAssignedName[client][0] = '\0';
|
||||||
@@ -169,6 +218,12 @@ public void OnClientConnected(int client)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void OnClientAuthorized(int client, const char[] auth)
|
||||||
|
{
|
||||||
|
if(!IsFakeClient(client) && IsClientInGame(client))
|
||||||
|
CheckRejoinedName(client);
|
||||||
|
}
|
||||||
|
|
||||||
public void OnClientPutInServer(int client)
|
public void OnClientPutInServer(int client)
|
||||||
{
|
{
|
||||||
if(IsFakeClient(client))
|
if(IsFakeClient(client))
|
||||||
@@ -177,12 +232,17 @@ public void OnClientPutInServer(int client)
|
|||||||
char sName[MAX_NAME_LENGTH];
|
char sName[MAX_NAME_LENGTH];
|
||||||
GetClientName(client, sName, sizeof(sName));
|
GetClientName(client, sName, sizeof(sName));
|
||||||
|
|
||||||
|
// the client can re-send its raw name during signon, undoing the
|
||||||
|
// OnClientConnected rename (or bringing a new name with it)
|
||||||
|
char sRaw[MAX_NAME_LENGTH];
|
||||||
|
strcopy(sRaw, sizeof(sRaw), sName);
|
||||||
|
|
||||||
if(FilterName(client, sName))
|
if(FilterName(client, sName))
|
||||||
{
|
{
|
||||||
g_bFilteredOnConnect[client] = true;
|
g_bFilteredOnConnect[client] = true;
|
||||||
if(g_bLastFilterReplaced)
|
if(g_bLastFilterReplaced)
|
||||||
g_bReplacedOnConnect[client] = true;
|
g_bReplacedOnConnect[client] = true;
|
||||||
g_iBlockNameChangeEvents[client] = 2;
|
strcopy(g_sOriginalName[client], MAX_NAME_LENGTH, sRaw);
|
||||||
strcopy(g_sAssignedName[client], MAX_NAME_LENGTH, sName);
|
strcopy(g_sAssignedName[client], MAX_NAME_LENGTH, sName);
|
||||||
SetClientName(client, sName);
|
SetClientName(client, sName);
|
||||||
}
|
}
|
||||||
@@ -192,21 +252,100 @@ public void OnClientPutInServer(int client)
|
|||||||
NotifyAdminsFiltered(client, sName, g_bReplacedOnConnect[client]);
|
NotifyAdminsFiltered(client, sName, g_bReplacedOnConnect[client]);
|
||||||
NotifyClientRenamed(client, sName, g_bReplacedOnConnect[client]);
|
NotifyClientRenamed(client, sName, g_bReplacedOnConnect[client]);
|
||||||
}
|
}
|
||||||
|
else if(IsClientAuthorized(client))
|
||||||
|
CheckRejoinedName(client);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OnClientDisconnect(int client)
|
public void OnClientDisconnect(int client)
|
||||||
{
|
{
|
||||||
|
if(!IsFakeClient(client) && IsClientAuthorized(client))
|
||||||
|
{
|
||||||
|
char sAuth[64];
|
||||||
|
if(GetClientAuthId(client, AuthId_Engine, sAuth, sizeof(sAuth)))
|
||||||
|
{
|
||||||
|
if(g_sAssignedName[client][0])
|
||||||
|
{
|
||||||
|
PastName past;
|
||||||
|
strcopy(past.sOriginal, sizeof(past.sOriginal), g_sOriginalName[client]);
|
||||||
|
strcopy(past.sAssigned, sizeof(past.sAssigned), g_sAssignedName[client]);
|
||||||
|
past.bReplaced = IsReplacementName(g_sAssignedName[client]);
|
||||||
|
g_PastNames.SetArray(sAuth, past, sizeof(past));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
g_PastNames.Remove(sAuth);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
g_sOriginalName[client][0] = '\0';
|
g_sOriginalName[client][0] = '\0';
|
||||||
g_sAssignedName[client][0] = '\0';
|
g_sAssignedName[client][0] = '\0';
|
||||||
g_iBlockNameChangeEvents[client] = 0;
|
g_sBlockEventName[client][0] = '\0';
|
||||||
|
g_iRenameRetries[client] = 0;
|
||||||
g_bFilteredOnConnect[client] = false;
|
g_bFilteredOnConnect[client] = false;
|
||||||
g_bReplacedOnConnect[client] = false;
|
g_bReplacedOnConnect[client] = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// a player whose client still carries a name we gave them earlier gets the
|
||||||
|
// notices again, with the original restored when this server run saw it.
|
||||||
|
// Runs once per connection: whichever of auth and put-in-server comes last
|
||||||
|
void CheckRejoinedName(int client)
|
||||||
|
{
|
||||||
|
if(g_sAssignedName[client][0] || g_bFilteredOnConnect[client])
|
||||||
|
return;
|
||||||
|
|
||||||
|
char sName[MAX_NAME_LENGTH];
|
||||||
|
GetClientName(client, sName, sizeof(sName));
|
||||||
|
|
||||||
|
char sAuth[64];
|
||||||
|
PastName past;
|
||||||
|
if(GetClientAuthId(client, AuthId_Engine, sAuth, sizeof(sAuth))
|
||||||
|
&& g_PastNames.GetArray(sAuth, past, sizeof(past))
|
||||||
|
&& StrEqual(sName, past.sAssigned))
|
||||||
|
{
|
||||||
|
strcopy(g_sOriginalName[client], MAX_NAME_LENGTH, past.sOriginal);
|
||||||
|
strcopy(g_sAssignedName[client], MAX_NAME_LENGTH, past.sAssigned);
|
||||||
|
g_bFilteredOnConnect[client] = true;
|
||||||
|
g_bReplacedOnConnect[client] = past.bReplaced;
|
||||||
|
|
||||||
|
NotifyAdminsFiltered(client, sName, past.bReplaced);
|
||||||
|
NotifyClientRenamed(client, sName, past.bReplaced);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(IsReplacementName(sName))
|
||||||
|
{
|
||||||
|
NotifyAdminsUnknownOriginal(client, sName);
|
||||||
|
NotifyClientRenamed(client, sName, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// true if the change from the player's original name to sNewName only
|
||||||
|
// trimmed or collapsed spaces and removed invisible characters
|
||||||
|
bool IsCosmeticChange(int client, const char[] sNewName, bool bReplaced)
|
||||||
|
{
|
||||||
|
if(bReplaced)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
char sTidied[MAX_NAME_LENGTH];
|
||||||
|
strcopy(sTidied, sizeof(sTidied), g_sOriginalName[client]);
|
||||||
|
StripInvisible(sTidied);
|
||||||
|
NormalizeWhitespace(sTidied);
|
||||||
|
|
||||||
|
return StrEqual(sTidied, sNewName);
|
||||||
|
}
|
||||||
|
|
||||||
|
// cosmetic changes get only the server console line
|
||||||
void NotifyAdminsFiltered(int client, const char[] sNewName, bool bReplaced)
|
void NotifyAdminsFiltered(int client, const char[] sNewName, bool bReplaced)
|
||||||
{
|
{
|
||||||
PrintToServer("[NameFilter2] \"%s\" (#%d) was %s \"%s\"", g_sOriginalName[client], GetClientUserId(client),
|
char sOriginal[MAX_NAME_LENGTH];
|
||||||
bReplaced ? "given replacement name" : "renamed to", sNewName);
|
SanitizeForLog(g_sOriginalName[client], sOriginal, sizeof(sOriginal));
|
||||||
|
|
||||||
|
bool bCosmetic = IsCosmeticChange(client, sNewName, bReplaced);
|
||||||
|
|
||||||
|
PrintToServer("[NameFilter2] \"%s\" (#%d) was %s \"%s\"", sOriginal, GetClientUserId(client),
|
||||||
|
bReplaced ? "given replacement name" : bCosmetic ? "tidied to" : "renamed to", sNewName);
|
||||||
|
|
||||||
|
if(bCosmetic)
|
||||||
|
return;
|
||||||
|
|
||||||
for(int i = 1; i <= MaxClients; i++)
|
for(int i = 1; i <= MaxClients; i++)
|
||||||
{
|
{
|
||||||
@@ -216,29 +355,57 @@ void NotifyAdminsFiltered(int client, const char[] sNewName, bool bReplaced)
|
|||||||
if(!CheckCommandAccess(i, "sm_namefilter2_notify", ADMFLAG_GENERIC))
|
if(!CheckCommandAccess(i, "sm_namefilter2_notify", ADMFLAG_GENERIC))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
PrintToChat(i, CHAT_PREFIX ... " \x07FF6060%s\x01 (#%d) was renamed to \x0760FF60%s\x01", g_sOriginalName[client], GetClientUserId(client), sNewName);
|
PrintToChat(i, CHAT_PREFIX ... " \x07FF6060%s\x01 (#%d) was renamed to \x0760FF60%s\x01", sOriginal, GetClientUserId(client), sNewName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void NotifyAdminsUnknownOriginal(int client, const char[] sName)
|
||||||
|
{
|
||||||
|
PrintToServer("[NameFilter2] \"%s\" (#%d) joined with a replacement name, original name unknown", sName, GetClientUserId(client));
|
||||||
|
|
||||||
|
for(int i = 1; i <= MaxClients; i++)
|
||||||
|
{
|
||||||
|
if(!IsClientInGame(i) || IsFakeClient(i))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if(!CheckCommandAccess(i, "sm_namefilter2_notify", ADMFLAG_GENERIC))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
PrintToChat(i, CHAT_PREFIX ... " \x0760FF60%s\x01 (#%d) joined with a replacement name, original name unknown", sName, GetClientUserId(client));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void NotifyClientRenamed(int client, const char[] sNewName, bool bReplaced)
|
void NotifyClientRenamed(int client, const char[] sNewName, bool bReplaced)
|
||||||
{
|
{
|
||||||
|
if(IsCosmeticChange(client, sNewName, bReplaced))
|
||||||
|
return;
|
||||||
|
|
||||||
if(bReplaced)
|
if(bReplaced)
|
||||||
PrintToChat(client, CHAT_PREFIX ... " Your name was unable to be filtered and was replaced with \x0760FF60%s\x01.", sNewName);
|
PrintToChat(client, CHAT_PREFIX ... " Your name was unable to be filtered and was replaced with \x0760FF60%s\x01.", sNewName);
|
||||||
else
|
else
|
||||||
PrintToChat(client, CHAT_PREFIX ... " Your name was filtered to \x0760FF60%s\x01.", sNewName);
|
PrintToChat(client, CHAT_PREFIX ... " Your name was filtered to \x0760FF60%s\x01.", sNewName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// changes to the name we gave the player are ours and stay hidden, as is the
|
||||||
|
// event of a raw change whose SayText2 we filtered. Matching by name instead
|
||||||
|
// of counting messages means a message that never arrives cannot leave a
|
||||||
|
// stale block that lets the player's next rename skip the filter
|
||||||
public Action Event_ChangeName(Event event, const char[] name, bool dontBroadcast)
|
public Action Event_ChangeName(Event event, const char[] name, bool dontBroadcast)
|
||||||
{
|
{
|
||||||
int client = GetClientOfUserId(event.GetInt("userid"));
|
int client = GetClientOfUserId(event.GetInt("userid"));
|
||||||
if(g_iBlockNameChangeEvents[client])
|
if(!client)
|
||||||
{
|
return Plugin_Continue;
|
||||||
g_iBlockNameChangeEvents[client]--;
|
|
||||||
|
char sNewName[MAX_NAME_LENGTH];
|
||||||
|
event.GetString("newname", sNewName, sizeof(sNewName));
|
||||||
|
|
||||||
|
if(g_sBlockEventName[client][0] && StrEqual(sNewName, g_sBlockEventName[client]))
|
||||||
|
g_sBlockEventName[client][0] = '\0';
|
||||||
|
else if(!g_sAssignedName[client][0] || !StrEqual(sNewName, g_sAssignedName[client]))
|
||||||
|
return Plugin_Continue;
|
||||||
|
|
||||||
SetEventBroadcast(event, true);
|
SetEventBroadcast(event, true);
|
||||||
return Plugin_Handled;
|
return Plugin_Handled;
|
||||||
}
|
|
||||||
|
|
||||||
return Plugin_Continue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Action UserMessage_SayText2(UserMsg msg_id, BfRead msg, const int[] players, int playersNum, bool reliable, bool init)
|
public Action UserMessage_SayText2(UserMsg msg_id, BfRead msg, const int[] players, int playersNum, bool reliable, bool init)
|
||||||
@@ -278,16 +445,10 @@ public Action UserMessage_SayText2(UserMsg msg_id, BfRead msg, const int[] playe
|
|||||||
if(client < 1 || client > MaxClients)
|
if(client < 1 || client > MaxClients)
|
||||||
return Plugin_Continue;
|
return Plugin_Continue;
|
||||||
|
|
||||||
if(g_iBlockNameChangeEvents[client])
|
// the name we gave them: SetClientName's own change, or any later echo
|
||||||
{
|
// of it; keep the original it was filtered from
|
||||||
g_iBlockNameChangeEvents[client]--;
|
|
||||||
return Plugin_Handled;
|
|
||||||
}
|
|
||||||
|
|
||||||
// the name we gave them (Timer_ChangeName's re-apply or any later echo of
|
|
||||||
// it); let it broadcast but keep the original it was filtered from
|
|
||||||
if(g_sAssignedName[client][0] && StrEqual(sNewName, g_sAssignedName[client]))
|
if(g_sAssignedName[client][0] && StrEqual(sNewName, g_sAssignedName[client]))
|
||||||
return Plugin_Continue;
|
return Plugin_Handled;
|
||||||
|
|
||||||
strcopy(g_sOriginalName[client], MAX_NAME_LENGTH, sNewName);
|
strcopy(g_sOriginalName[client], MAX_NAME_LENGTH, sNewName);
|
||||||
g_sAssignedName[client][0] = '\0';
|
g_sAssignedName[client][0] = '\0';
|
||||||
@@ -295,14 +456,13 @@ public Action UserMessage_SayText2(UserMsg msg_id, BfRead msg, const int[] playe
|
|||||||
if(FilterName(client, sNewName))
|
if(FilterName(client, sNewName))
|
||||||
{
|
{
|
||||||
strcopy(g_sAssignedName[client], MAX_NAME_LENGTH, sNewName);
|
strcopy(g_sAssignedName[client], MAX_NAME_LENGTH, sNewName);
|
||||||
|
strcopy(g_sBlockEventName[client], MAX_NAME_LENGTH, g_sOriginalName[client]);
|
||||||
|
g_iRenameRetries[client] = 0;
|
||||||
|
|
||||||
// CCSPlayer::ChangeName sends this SayText2 before it fires the event
|
// CCSPlayer::ChangeName sends this SayText2 before it fires the event
|
||||||
// and stores the new name, so a SetClientName from in here is undone
|
// and stores the new name, so a SetClientName from in here is undone
|
||||||
// as soon as we return. Re-apply later instead, even when the filtered
|
// as soon as we return. Re-apply later instead, even when the filtered
|
||||||
// name equals the old one: 3 = this change's event, then the timer's
|
// name equals the old one
|
||||||
// SayText2 and event
|
|
||||||
g_iBlockNameChangeEvents[client] = 3;
|
|
||||||
|
|
||||||
DataPack pack = new DataPack();
|
DataPack pack = new DataPack();
|
||||||
pack.WriteCell(GetClientUserId(client));
|
pack.WriteCell(GetClientUserId(client));
|
||||||
pack.WriteString(sNewName);
|
pack.WriteString(sNewName);
|
||||||
@@ -321,18 +481,51 @@ public Action Timer_ChangeName(Handle timer, any data)
|
|||||||
DataPack pack = view_as<DataPack>(data);
|
DataPack pack = view_as<DataPack>(data);
|
||||||
pack.Reset();
|
pack.Reset();
|
||||||
|
|
||||||
int client = GetClientOfUserId(pack.ReadCell());
|
int iUserId = pack.ReadCell();
|
||||||
|
int client = GetClientOfUserId(iUserId);
|
||||||
char sName[MAX_NAME_LENGTH];
|
char sName[MAX_NAME_LENGTH];
|
||||||
pack.ReadString(sName, sizeof(sName));
|
pack.ReadString(sName, sizeof(sName));
|
||||||
bool bReplaced = view_as<bool>(pack.ReadCell());
|
bool bReplaced = view_as<bool>(pack.ReadCell());
|
||||||
|
|
||||||
delete pack;
|
delete pack;
|
||||||
|
|
||||||
if(client)
|
// a later rename by the player superseded this one
|
||||||
{
|
if(!client || !StrEqual(sName, g_sAssignedName[client]))
|
||||||
|
return Plugin_Stop;
|
||||||
|
|
||||||
SetClientName(client, sName);
|
SetClientName(client, sName);
|
||||||
NotifyAdminsFiltered(client, sName, bReplaced);
|
NotifyAdminsFiltered(client, sName, bReplaced);
|
||||||
NotifyClientRenamed(client, sName, bReplaced);
|
NotifyClientRenamed(client, sName, bReplaced);
|
||||||
|
|
||||||
|
CreateTimer(0.5, Timer_VerifyName, iUserId);
|
||||||
|
|
||||||
|
return Plugin_Stop;
|
||||||
|
}
|
||||||
|
|
||||||
|
// the rename should have taken effect inside SetClientName; if it did not,
|
||||||
|
// say so and try again, so a player never keeps a raw name unnoticed
|
||||||
|
public Action Timer_VerifyName(Handle timer, int iUserId)
|
||||||
|
{
|
||||||
|
int client = GetClientOfUserId(iUserId);
|
||||||
|
if(!client || !g_sAssignedName[client][0])
|
||||||
|
return Plugin_Stop;
|
||||||
|
|
||||||
|
char sName[MAX_NAME_LENGTH];
|
||||||
|
GetClientName(client, sName, sizeof(sName));
|
||||||
|
if(StrEqual(sName, g_sAssignedName[client]))
|
||||||
|
return Plugin_Stop;
|
||||||
|
|
||||||
|
char sSafe[MAX_NAME_LENGTH];
|
||||||
|
SanitizeForLog(sName, sSafe, sizeof(sSafe));
|
||||||
|
|
||||||
|
bool bRetry = g_iRenameRetries[client]++ < MAX_RENAME_RETRIES;
|
||||||
|
PrintToServer("[NameFilter2] rename of #%d to \"%s\" did not stick (name is \"%s\")%s", iUserId,
|
||||||
|
g_sAssignedName[client], sSafe, bRetry ? ", retrying" : "");
|
||||||
|
|
||||||
|
if(bRetry)
|
||||||
|
{
|
||||||
|
SetClientName(client, g_sAssignedName[client]);
|
||||||
|
CreateTimer(0.5, Timer_VerifyName, iUserId);
|
||||||
}
|
}
|
||||||
|
|
||||||
return Plugin_Stop;
|
return Plugin_Stop;
|
||||||
@@ -365,13 +558,11 @@ public Action Command_OriginalName(int client, int args)
|
|||||||
|
|
||||||
for(int i = 0; i < iCount; i++)
|
for(int i = 0; i < iCount; i++)
|
||||||
{
|
{
|
||||||
char sCurrent[MAX_NAME_LENGTH];
|
char sLine[256];
|
||||||
GetClientName(aTargets[i], sCurrent, sizeof(sCurrent));
|
if(DescribeNameChange(aTargets[i], sLine, sizeof(sLine)))
|
||||||
|
ReplyToCommand(client, "[SM] %s", sLine);
|
||||||
if(StrEqual(sCurrent, g_sOriginalName[aTargets[i]]))
|
|
||||||
ReplyToCommand(client, "[SM] %N's name was not changed.", aTargets[i]);
|
|
||||||
else
|
else
|
||||||
ReplyToCommand(client, "[SM] %N's original name: %s", aTargets[i], g_sOriginalName[aTargets[i]]);
|
ReplyToCommand(client, "[SM] %N's name was not changed.", aTargets[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
return Plugin_Handled;
|
return Plugin_Handled;
|
||||||
@@ -380,18 +571,17 @@ public Action Command_OriginalName(int client, int args)
|
|||||||
public Action Command_ChangedNames(int client, int args)
|
public Action Command_ChangedNames(int client, int args)
|
||||||
{
|
{
|
||||||
int iFound = 0;
|
int iFound = 0;
|
||||||
char sCurrent[MAX_NAME_LENGTH];
|
char sLine[256];
|
||||||
|
|
||||||
for(int i = 1; i <= MaxClients; i++)
|
for(int i = 1; i <= MaxClients; i++)
|
||||||
{
|
{
|
||||||
if(!IsClientConnected(i) || IsFakeClient(i))
|
if(!IsClientConnected(i) || IsFakeClient(i))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
GetClientName(i, sCurrent, sizeof(sCurrent));
|
if(!DescribeNameChange(i, sLine, sizeof(sLine)))
|
||||||
if(StrEqual(sCurrent, g_sOriginalName[i]))
|
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
PrintToConsole(client, "%s - original name: %s", sCurrent, g_sOriginalName[i]);
|
PrintToConsole(client, "%s", sLine);
|
||||||
iFound++;
|
iFound++;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -403,6 +593,92 @@ public Action Command_ChangedNames(int client, int args)
|
|||||||
return Plugin_Handled;
|
return Plugin_Handled;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// "<current> - original name: <original>" for a player whose name we changed,
|
||||||
|
// including one who rejoined wearing a replacement name; false otherwise
|
||||||
|
bool DescribeNameChange(int client, char[] sLine, int Length)
|
||||||
|
{
|
||||||
|
char sCurrent[MAX_NAME_LENGTH];
|
||||||
|
GetClientName(client, sCurrent, sizeof(sCurrent));
|
||||||
|
|
||||||
|
char sOriginal[MAX_NAME_LENGTH];
|
||||||
|
SanitizeForLog(g_sOriginalName[client], sOriginal, sizeof(sOriginal));
|
||||||
|
|
||||||
|
if(g_sAssignedName[client][0])
|
||||||
|
{
|
||||||
|
if(StrEqual(sCurrent, g_sAssignedName[client]))
|
||||||
|
FormatEx(sLine, Length, "%s - original name: %s", sCurrent, sOriginal);
|
||||||
|
else
|
||||||
|
FormatEx(sLine, Length, "%s - original name: %s (filter did not stick, expected %s)", sCurrent, sOriginal, g_sAssignedName[client]);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!StrEqual(sCurrent, g_sOriginalName[client]))
|
||||||
|
{
|
||||||
|
FormatEx(sLine, Length, "%s - original name: %s", sCurrent, sOriginal);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(IsReplacementName(sCurrent))
|
||||||
|
{
|
||||||
|
FormatEx(sLine, Length, "%s - original name: unknown (joined with a replacement name)", sCurrent);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// a configured replacement name, or AssignReplacementName's "<name> <userid>"
|
||||||
|
// fallback for when they are all taken
|
||||||
|
bool IsReplacementName(const char[] sName)
|
||||||
|
{
|
||||||
|
char sCandidate[MAX_NAME_LENGTH];
|
||||||
|
for(int i = 0; i < g_ReplacementNames.Length; i++)
|
||||||
|
{
|
||||||
|
g_ReplacementNames.GetString(i, sCandidate, sizeof(sCandidate));
|
||||||
|
|
||||||
|
int iLen = strlen(sCandidate);
|
||||||
|
if(strncmp(sName, sCandidate, iLen) != 0)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if(sName[iLen] == '\0')
|
||||||
|
return true;
|
||||||
|
|
||||||
|
if(sName[iLen] != ' ' || sName[iLen + 1] == '\0')
|
||||||
|
continue;
|
||||||
|
|
||||||
|
int k = iLen + 1;
|
||||||
|
while(IsCharNumeric(sName[k]))
|
||||||
|
k++;
|
||||||
|
if(sName[k] == '\0')
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Action Command_Test(int client, int args)
|
||||||
|
{
|
||||||
|
if(args < 1)
|
||||||
|
{
|
||||||
|
ReplyToCommand(client, "[SM] Usage: sm_namefilter2_test <name>");
|
||||||
|
return Plugin_Handled;
|
||||||
|
}
|
||||||
|
|
||||||
|
char sName[MAX_NAME_LENGTH];
|
||||||
|
GetCmdArgString(sName, sizeof(sName));
|
||||||
|
StripQuotes(sName);
|
||||||
|
|
||||||
|
char sIn[MAX_NAME_LENGTH];
|
||||||
|
SanitizeForLog(sName, sIn, sizeof(sIn));
|
||||||
|
|
||||||
|
// client 0 only steers which replacement name is picked
|
||||||
|
bool bChanged = FilterName(0, sName);
|
||||||
|
ReplyToCommand(client, "[SM] \"%s\" -> \"%s\"%s", sIn, sName,
|
||||||
|
g_bLastFilterReplaced ? " (replacement)" : (bChanged ? "" : " (unchanged)"));
|
||||||
|
|
||||||
|
return Plugin_Handled;
|
||||||
|
}
|
||||||
|
|
||||||
public Action Command_Reload(int client, int args)
|
public Action Command_Reload(int client, int args)
|
||||||
{
|
{
|
||||||
LoadConfig();
|
LoadConfig();
|
||||||
@@ -433,6 +709,8 @@ void LoadConfig()
|
|||||||
delete g_ReplacementNames;
|
delete g_ReplacementNames;
|
||||||
delete g_ConfusableFrom;
|
delete g_ConfusableFrom;
|
||||||
delete g_ConfusableTo;
|
delete g_ConfusableTo;
|
||||||
|
delete g_ConfusableSet;
|
||||||
|
delete g_Transliterate;
|
||||||
delete g_WhitelistCps;
|
delete g_WhitelistCps;
|
||||||
|
|
||||||
static char sConfigFile[PLATFORM_MAX_PATH];
|
static char sConfigFile[PLATFORM_MAX_PATH];
|
||||||
@@ -472,6 +750,7 @@ void LoadConfig()
|
|||||||
|
|
||||||
g_ConfusableFrom = new ArrayList(ByteCountToCells(16));
|
g_ConfusableFrom = new ArrayList(ByteCountToCells(16));
|
||||||
g_ConfusableTo = new ArrayList(ByteCountToCells(16));
|
g_ConfusableTo = new ArrayList(ByteCountToCells(16));
|
||||||
|
g_ConfusableSet = new StringMap();
|
||||||
if(Config.JumpToKey("confusables"))
|
if(Config.JumpToKey("confusables"))
|
||||||
{
|
{
|
||||||
if(Config.GotoFirstSubKey(false))
|
if(Config.GotoFirstSubKey(false))
|
||||||
@@ -486,6 +765,7 @@ void LoadConfig()
|
|||||||
{
|
{
|
||||||
g_ConfusableFrom.PushString(sFrom);
|
g_ConfusableFrom.PushString(sFrom);
|
||||||
g_ConfusableTo.PushString(sBuffer);
|
g_ConfusableTo.PushString(sBuffer);
|
||||||
|
g_ConfusableSet.SetValue(sFrom, true);
|
||||||
}
|
}
|
||||||
} while(Config.GotoNextKey(false));
|
} while(Config.GotoNextKey(false));
|
||||||
Config.GoBack();
|
Config.GoBack();
|
||||||
@@ -493,6 +773,25 @@ void LoadConfig()
|
|||||||
Config.GoBack();
|
Config.GoBack();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
g_Transliterate = new StringMap();
|
||||||
|
if(Config.JumpToKey("transliterate"))
|
||||||
|
{
|
||||||
|
if(Config.GotoFirstSubKey(false))
|
||||||
|
{
|
||||||
|
do
|
||||||
|
{
|
||||||
|
char sFrom[16];
|
||||||
|
Config.GetSectionName(sFrom, sizeof(sFrom));
|
||||||
|
Config.GetString(NULL_STRING, sBuffer, sizeof(sBuffer));
|
||||||
|
|
||||||
|
if(sFrom[0])
|
||||||
|
g_Transliterate.SetString(sFrom, sBuffer);
|
||||||
|
} while(Config.GotoNextKey(false));
|
||||||
|
Config.GoBack();
|
||||||
|
}
|
||||||
|
Config.GoBack();
|
||||||
|
}
|
||||||
|
|
||||||
g_AdvertExprs = new ArrayList();
|
g_AdvertExprs = new ArrayList();
|
||||||
if(Config.JumpToKey("adverts"))
|
if(Config.JumpToKey("adverts"))
|
||||||
{
|
{
|
||||||
@@ -565,8 +864,10 @@ bool FilterName(int client, char[] sName, int Length = MAX_NAME_LENGTH)
|
|||||||
char sBefore[MAX_NAME_LENGTH];
|
char sBefore[MAX_NAME_LENGTH];
|
||||||
strcopy(sBefore, sizeof(sBefore), sName);
|
strcopy(sBefore, sizeof(sBefore), sName);
|
||||||
|
|
||||||
// applies to kept names too, so none can hide characters or pose as another
|
// applies to kept names too, so none can hide characters or pose as
|
||||||
|
// another ("Name " next to "Name")
|
||||||
StripInvisible(sName);
|
StripInvisible(sName);
|
||||||
|
NormalizeWhitespace(sName);
|
||||||
|
|
||||||
char sClean[MAX_NAME_LENGTH];
|
char sClean[MAX_NAME_LENGTH];
|
||||||
strcopy(sClean, sizeof(sClean), sName);
|
strcopy(sClean, sizeof(sClean), sName);
|
||||||
@@ -576,6 +877,7 @@ bool FilterName(int client, char[] sName, int Length = MAX_NAME_LENGTH)
|
|||||||
bool bKeepOriginal = HasTypeableRun(sClean);
|
bool bKeepOriginal = HasTypeableRun(sClean);
|
||||||
bool bContentRemoved = false;
|
bool bContentRemoved = false;
|
||||||
|
|
||||||
|
TransliterateCyrillic(sName, Length);
|
||||||
ApplyConfusables(sName, Length);
|
ApplyConfusables(sName, Length);
|
||||||
|
|
||||||
int iLettersBefore = CountLetters(sName);
|
int iLettersBefore = CountLetters(sName);
|
||||||
@@ -711,6 +1013,34 @@ void StripInvisible(char[] sName)
|
|||||||
sName[w] = '\0';
|
sName[w] = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// copy of a name that is safe to print: invalid UTF-8 and control
|
||||||
|
// characters become '?' (journald hides whole lines containing them)
|
||||||
|
void SanitizeForLog(const char[] sIn, char[] sOut, int Length)
|
||||||
|
{
|
||||||
|
int r = 0;
|
||||||
|
int w = 0;
|
||||||
|
|
||||||
|
while(sIn[r] != '\0')
|
||||||
|
{
|
||||||
|
int rStart = r;
|
||||||
|
int cp = DecodeUTF8Char(sIn, r);
|
||||||
|
|
||||||
|
if(cp < 0 || cp < 0x20 || (cp >= 0x7F && cp <= 0x9F))
|
||||||
|
{
|
||||||
|
if(w + 1 >= Length)
|
||||||
|
break;
|
||||||
|
sOut[w++] = '?';
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(w + (r - rStart) >= Length)
|
||||||
|
break;
|
||||||
|
for(int k = rStart; k < r; k++)
|
||||||
|
sOut[w++] = sIn[k];
|
||||||
|
}
|
||||||
|
sOut[w] = '\0';
|
||||||
|
}
|
||||||
|
|
||||||
bool IsInvisibleCp(int cp)
|
bool IsInvisibleCp(int cp)
|
||||||
{
|
{
|
||||||
return cp < 0x20 || (cp >= 0x7F && cp <= 0x9F) // C0/C1 controls, DEL
|
return cp < 0x20 || (cp >= 0x7F && cp <= 0x9F) // C0/C1 controls, DEL
|
||||||
@@ -741,6 +1071,126 @@ bool IsCombiningMarkCp(int cp)
|
|||||||
|| (cp >= 0xFE20 && cp <= 0xFE2F); // half marks
|
|| (cp >= 0xFE20 && cp <= 0xFE2F); // half marks
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// spells out each word containing Cyrillic phonetically (Киллер -> Killer),
|
||||||
|
// unless it is a Latin word with only lookalike Cyrillic mixed in (a spoof
|
||||||
|
// such as "аdmin") or mixes in other scripts, which ApplyConfusables folds
|
||||||
|
// back to the Latin text it imitates. All-caps words stay all-caps (ЖУК -> ZHUK)
|
||||||
|
void TransliterateCyrillic(char[] sName, int Length)
|
||||||
|
{
|
||||||
|
char sOut[MAX_NAME_LENGTH * 2];
|
||||||
|
int w = 0;
|
||||||
|
int r = 0;
|
||||||
|
|
||||||
|
while(sName[r] != '\0')
|
||||||
|
{
|
||||||
|
if(sName[r] == ' ')
|
||||||
|
{
|
||||||
|
if(w + 1 < sizeof(sOut))
|
||||||
|
sOut[w++] = ' ';
|
||||||
|
r++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
int iEnd = r;
|
||||||
|
while(sName[iEnd] != '\0' && sName[iEnd] != ' ')
|
||||||
|
iEnd++;
|
||||||
|
|
||||||
|
bool bUpper;
|
||||||
|
bool bSpell = IsCyrillicWord(sName, r, iEnd, bUpper);
|
||||||
|
int wStart = w;
|
||||||
|
|
||||||
|
while(r < iEnd)
|
||||||
|
{
|
||||||
|
int rStart = r;
|
||||||
|
int cp = DecodeUTF8Char(sName, r);
|
||||||
|
|
||||||
|
char sChar[8];
|
||||||
|
for(int k = rStart; k < r && k - rStart < sizeof(sChar) - 1; k++)
|
||||||
|
sChar[k - rStart] = sName[k];
|
||||||
|
sChar[r - rStart < sizeof(sChar) ? r - rStart : sizeof(sChar) - 1] = '\0';
|
||||||
|
|
||||||
|
// in a lookalike word, Cyrillic without a confusable is still
|
||||||
|
// spelled out rather than lost when FoldToASCII strips it
|
||||||
|
bool bDummy;
|
||||||
|
char sTo[16];
|
||||||
|
if(!IsCyrillicCp(cp)
|
||||||
|
|| (!bSpell && g_ConfusableSet.GetValue(sChar, bDummy))
|
||||||
|
|| !g_Transliterate.GetString(sChar, sTo, sizeof(sTo)))
|
||||||
|
strcopy(sTo, sizeof(sTo), sChar);
|
||||||
|
|
||||||
|
for(int k = 0; sTo[k] != '\0' && w + 1 < sizeof(sOut); k++)
|
||||||
|
sOut[w++] = sTo[k];
|
||||||
|
}
|
||||||
|
|
||||||
|
if(bSpell && bUpper)
|
||||||
|
{
|
||||||
|
for(int k = wStart; k < w; k++)
|
||||||
|
sOut[k] = CharToUpper(sOut[k]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
sOut[w] = '\0';
|
||||||
|
|
||||||
|
strcopy(sName, Length, sOut);
|
||||||
|
}
|
||||||
|
|
||||||
|
// true if the word in s[iStart, iEnd) should be transliterated: it has
|
||||||
|
// Cyrillic, is not a Latin word whose Cyrillic letters are all confusables,
|
||||||
|
// and has no letters from other scripts. Real Cyrillic words never mix in
|
||||||
|
// Greek or styled letters; a word that does ("ιηƒιηιтє") is decoration that
|
||||||
|
// imitates Latin. bUpper is set when it has two or more Cyrillic letters,
|
||||||
|
// all uppercase
|
||||||
|
bool IsCyrillicWord(const char[] s, int iStart, int iEnd, bool &bUpper)
|
||||||
|
{
|
||||||
|
bool bLatin = false;
|
||||||
|
bool bOtherScript = false;
|
||||||
|
bool bAllConfusable = true;
|
||||||
|
int iCyrillic = 0;
|
||||||
|
int iLower = 0;
|
||||||
|
|
||||||
|
int i = iStart;
|
||||||
|
while(i < iEnd)
|
||||||
|
{
|
||||||
|
int iChar = i;
|
||||||
|
int cp = DecodeUTF8Char(s, i);
|
||||||
|
|
||||||
|
if((cp >= 'a' && cp <= 'z') || (cp >= 'A' && cp <= 'Z'))
|
||||||
|
{
|
||||||
|
bLatin = true;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!IsCyrillicCp(cp))
|
||||||
|
{
|
||||||
|
if(cp >= 0x80 && IsLetterCp(cp))
|
||||||
|
bOtherScript = true;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
iCyrillic++;
|
||||||
|
// basic lowercase block, then upper/lower pairs from U+0460 on
|
||||||
|
if((cp >= 0x430 && cp <= 0x45F) || (cp >= 0x460 && cp & 1))
|
||||||
|
iLower++;
|
||||||
|
|
||||||
|
char sChar[8];
|
||||||
|
int iLen = i - iChar;
|
||||||
|
for(int k = 0; k < iLen && k < sizeof(sChar) - 1; k++)
|
||||||
|
sChar[k] = s[iChar + k];
|
||||||
|
sChar[iLen < sizeof(sChar) ? iLen : sizeof(sChar) - 1] = '\0';
|
||||||
|
|
||||||
|
bool bDummy;
|
||||||
|
if(!g_ConfusableSet.GetValue(sChar, bDummy))
|
||||||
|
bAllConfusable = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bUpper = iCyrillic >= 2 && !iLower;
|
||||||
|
return iCyrillic && !bOtherScript && !(bLatin && bAllConfusable);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool IsCyrillicCp(int cp)
|
||||||
|
{
|
||||||
|
return cp >= 0x400 && cp <= 0x4FF;
|
||||||
|
}
|
||||||
|
|
||||||
void ApplyConfusables(char[] sName, int Length)
|
void ApplyConfusables(char[] sName, int Length)
|
||||||
{
|
{
|
||||||
char sFrom[16];
|
char sFrom[16];
|
||||||
@@ -1135,12 +1585,18 @@ void NormalizeWhitespace(char[] sName)
|
|||||||
TrimString(sName);
|
TrimString(sName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// picked by Steam account, so a player gets the same replacement name on
|
||||||
|
// every visit (unless someone else is wearing it); the slot is the fallback
|
||||||
|
// for clients without one
|
||||||
void AssignReplacementName(int client, char[] sName, int Length)
|
void AssignReplacementName(int client, char[] sName, int Length)
|
||||||
{
|
{
|
||||||
g_bLastFilterReplaced = true;
|
g_bLastFilterReplaced = true;
|
||||||
|
|
||||||
int iCount = g_ReplacementNames.Length;
|
int iCount = g_ReplacementNames.Length;
|
||||||
int iBase = client % iCount;
|
int iSeed = client > 0 ? GetSteamAccountID(client, false) : 0;
|
||||||
|
if(!iSeed)
|
||||||
|
iSeed = client;
|
||||||
|
int iBase = (iSeed & 0x7FFFFFFF) % iCount;
|
||||||
char sCandidate[MAX_NAME_LENGTH];
|
char sCandidate[MAX_NAME_LENGTH];
|
||||||
|
|
||||||
for(int i = 0; i < iCount; i++)
|
for(int i = 0; i < iCount; i++)
|
||||||
@@ -1170,5 +1626,5 @@ void AssignReplacementName(int client, char[] sName, int Length)
|
|||||||
}
|
}
|
||||||
|
|
||||||
g_ReplacementNames.GetString(iBase, sCandidate, sizeof(sCandidate));
|
g_ReplacementNames.GetString(iBase, sCandidate, sizeof(sCandidate));
|
||||||
Format(sName, Length, "%s %d", sCandidate, GetClientUserId(client));
|
Format(sName, Length, "%s %d", sCandidate, client ? GetClientUserId(client) : 0);
|
||||||
}
|
}
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -14,6 +14,7 @@ bool g_bEngineCSGO;
|
|||||||
bool g_bHideCrown[MAXPLAYERS+1];
|
bool g_bHideCrown[MAXPLAYERS+1];
|
||||||
bool g_bHideDialog[MAXPLAYERS+1];
|
bool g_bHideDialog[MAXPLAYERS+1];
|
||||||
bool g_bProtection[MAXPLAYERS+1];
|
bool g_bProtection[MAXPLAYERS+1];
|
||||||
|
bool g_bTitleSet[MAXPLAYERS+1];
|
||||||
|
|
||||||
/* COOKIES */
|
/* COOKIES */
|
||||||
Handle g_hCookie_HideCrown;
|
Handle g_hCookie_HideCrown;
|
||||||
@@ -26,6 +27,18 @@ ConVar g_hCVar_ProtectionMinimal1;
|
|||||||
ConVar g_hCVar_ProtectionMinimal2;
|
ConVar g_hCVar_ProtectionMinimal2;
|
||||||
ConVar g_hCVar_ProtectionMinimal3;
|
ConVar g_hCVar_ProtectionMinimal3;
|
||||||
ConVar g_hCVar_Grenade;
|
ConVar g_hCVar_Grenade;
|
||||||
|
ConVar g_hCVar_Display;
|
||||||
|
ConVar g_hCVar_HudChannel;
|
||||||
|
ConVar g_hCVar_HudX;
|
||||||
|
ConVar g_hCVar_HudY;
|
||||||
|
ConVar g_hCVar_Hostname;
|
||||||
|
ConVar g_hCVar_HostIP;
|
||||||
|
ConVar g_hCVar_HostPort;
|
||||||
|
ConVar g_hCVar_Password;
|
||||||
|
|
||||||
|
/* STRINGS */
|
||||||
|
char g_sRankTitle[MAXPLAYERS+1][128];
|
||||||
|
char g_sTitleSent[MAXPLAYERS+1][128];
|
||||||
|
|
||||||
/* INTERGERS */
|
/* INTERGERS */
|
||||||
int g_iDialogLevel = 100000;
|
int g_iDialogLevel = 100000;
|
||||||
@@ -72,8 +85,17 @@ public void OnPluginStart()
|
|||||||
g_hCVar_ProtectionMinimal2 = CreateConVar("sm_topdefenders_minimal_2", "30", "", FCVAR_NONE, true, 1.0, true, 64.0);
|
g_hCVar_ProtectionMinimal2 = CreateConVar("sm_topdefenders_minimal_2", "30", "", FCVAR_NONE, true, 1.0, true, 64.0);
|
||||||
g_hCVar_ProtectionMinimal3 = CreateConVar("sm_topdefenders_minimal_3", "45", "", FCVAR_NONE, true, 1.0, true, 64.0);
|
g_hCVar_ProtectionMinimal3 = CreateConVar("sm_topdefenders_minimal_3", "45", "", FCVAR_NONE, true, 1.0, true, 64.0);
|
||||||
g_hCVar_Grenade = CreateConVar("sm_topdefenders_grenade", "1", "", FCVAR_NONE, true, 0.0, true, 1.0);
|
g_hCVar_Grenade = CreateConVar("sm_topdefenders_grenade", "1", "", FCVAR_NONE, true, 0.0, true, 1.0);
|
||||||
|
g_hCVar_Display = CreateConVar("sm_topdefenders_display", "2", "Rank display: 0 off, 1 dialog, 2 hudtext, 3 scoreboard title (set sm_hostname_send_to_clients 0 so HostnameManager doesn't overwrite it)", FCVAR_NONE, true, 0.0, true, 3.0);
|
||||||
|
g_hCVar_HudChannel = CreateConVar("sm_topdefenders_hud_channel", "5", "Hudtext channel for the rank display (0-5)", FCVAR_NONE, true, 0.0, true, 5.0);
|
||||||
|
g_hCVar_HudX = CreateConVar("sm_topdefenders_hud_x", "0.01", "Hudtext x position for the rank display (-1 centres)", FCVAR_NONE, true, -1.0, true, 1.0);
|
||||||
|
g_hCVar_HudY = CreateConVar("sm_topdefenders_hud_y", "0.01", "Hudtext y position for the rank display (-1 centres)", FCVAR_NONE, true, -1.0, true, 1.0);
|
||||||
AutoExecConfig(true);
|
AutoExecConfig(true);
|
||||||
|
|
||||||
|
g_hCVar_Hostname = FindConVar("hostname");
|
||||||
|
g_hCVar_HostIP = FindConVar("hostip");
|
||||||
|
g_hCVar_HostPort = FindConVar("hostport");
|
||||||
|
g_hCVar_Password = FindConVar("sv_password");
|
||||||
|
|
||||||
g_hCookie_HideCrown = RegClientCookie("topdefenders_hidecrown", "", CookieAccess_Private);
|
g_hCookie_HideCrown = RegClientCookie("topdefenders_hidecrown", "", CookieAccess_Private);
|
||||||
g_hCookie_HideDialog = RegClientCookie("topdefenders_hidedialog", "", CookieAccess_Private);
|
g_hCookie_HideDialog = RegClientCookie("topdefenders_hidedialog", "", CookieAccess_Private);
|
||||||
g_hCookie_Protection = RegClientCookie("topdefenders_protection", "", CookieAccess_Private);
|
g_hCookie_Protection = RegClientCookie("topdefenders_protection", "", CookieAccess_Private);
|
||||||
@@ -95,6 +117,14 @@ public void OnPluginStart()
|
|||||||
SetCookieMenuItem(MenuHandler_CookieMenu, 0, "Player Rankings");
|
SetCookieMenuItem(MenuHandler_CookieMenu, 0, "Player Rankings");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------------------------------
|
||||||
|
// Purpose: Hand everyone showing a rank title the real hostname back.
|
||||||
|
//----------------------------------------------------------------------------------------------------
|
||||||
|
public void OnPluginEnd()
|
||||||
|
{
|
||||||
|
ResetAllTitles();
|
||||||
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------------------------
|
||||||
// Purpose:
|
// Purpose:
|
||||||
//----------------------------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------------------------
|
||||||
@@ -288,11 +318,21 @@ public void OnClientCookiesCached(int client)
|
|||||||
g_bProtection[client] = false;
|
g_bProtection[client] = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------------------------------
|
||||||
|
// Purpose:
|
||||||
|
//----------------------------------------------------------------------------------------------------
|
||||||
|
public void OnClientPutInServer(int client)
|
||||||
|
{
|
||||||
|
g_bTitleSet[client] = false;
|
||||||
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------------------------
|
||||||
// Purpose:
|
// Purpose:
|
||||||
//----------------------------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------------------------
|
||||||
public void OnClientDisconnect(int client)
|
public void OnClientDisconnect(int client)
|
||||||
{
|
{
|
||||||
|
g_bTitleSet[client] = false;
|
||||||
|
|
||||||
g_iPlayerDamage[client] = 0;
|
g_iPlayerDamage[client] = 0;
|
||||||
g_iPlayerDamageHits[client] = 0;
|
g_iPlayerDamageHits[client] = 0;
|
||||||
g_iPlayerDamageFrom1K[client] = 0;
|
g_iPlayerDamageFrom1K[client] = 0;
|
||||||
@@ -350,9 +390,25 @@ public Action UpdateScoreboard(Handle timer)
|
|||||||
//----------------------------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------------------------
|
||||||
public Action UpdateDialog(Handle timer)
|
public Action UpdateDialog(Handle timer)
|
||||||
{
|
{
|
||||||
if (g_bEngineCSGO || g_iDialogLevel <= 0)
|
int iDisplay = g_hCVar_Display.IntValue;
|
||||||
|
|
||||||
|
if (iDisplay != 3 || g_iDialogLevel <= 0)
|
||||||
|
ResetAllTitles();
|
||||||
|
|
||||||
|
if (g_bEngineCSGO || g_iDialogLevel <= 0 || iDisplay <= 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
// Hudtext (held for 1s) and the scoreboard title only need a refresh every 0.5s, the dialog keeps the 0.1s rate.
|
||||||
|
static int iHudTick;
|
||||||
|
if (iDisplay >= 2 && (iHudTick++ % 5) != 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (iDisplay == 3)
|
||||||
|
{
|
||||||
|
for (int client = 1; client <= MaxClients; client++)
|
||||||
|
g_sRankTitle[client][0] = '\0';
|
||||||
|
}
|
||||||
|
|
||||||
int iSortedList[MAXPLAYERS+1][2];
|
int iSortedList[MAXPLAYERS+1][2];
|
||||||
int iSortedCount;
|
int iSortedCount;
|
||||||
|
|
||||||
@@ -368,16 +424,28 @@ public Action UpdateDialog(Handle timer)
|
|||||||
|
|
||||||
SortCustom2D(iSortedList, iSortedCount, SortRankingsList);
|
SortCustom2D(iSortedList, iSortedCount, SortRankingsList);
|
||||||
|
|
||||||
|
char sBuffer[128];
|
||||||
|
|
||||||
for (int rank = 0; rank < iSortedCount; rank++)
|
for (int rank = 0; rank < iSortedCount; rank++)
|
||||||
{
|
{
|
||||||
switch(rank)
|
switch(rank)
|
||||||
{
|
{
|
||||||
case(0): SendDialog(iSortedList[rank][0], "#%d (D: %d | P: -%d)", g_iDialogLevel, 1, rank + 1, iSortedList[rank][1], iSortedList[rank][1] - iSortedList[rank + 1][1]);
|
case(0): Format(sBuffer, sizeof(sBuffer), "#%d (D: %d | P: -%d)", rank + 1, iSortedList[rank][1], iSortedList[rank][1] - iSortedList[rank + 1][1]);
|
||||||
case(1): SendDialog(iSortedList[rank][0], "#%d (D: %d | N: +%d)", g_iDialogLevel, 1, rank + 1, iSortedList[rank][1], iSortedList[rank - 1][1] - iSortedList[rank][1]);
|
case(1): Format(sBuffer, sizeof(sBuffer), "#%d (D: %d | N: +%d)", rank + 1, iSortedList[rank][1], iSortedList[rank - 1][1] - iSortedList[rank][1]);
|
||||||
default: SendDialog(iSortedList[rank][0], "#%d (D: %d | N: +%d | F: +%d)", g_iDialogLevel, 1, rank + 1, iSortedList[rank][1], iSortedList[rank - 1][1] - iSortedList[rank][1], iSortedList[0][1] - iSortedList[rank][1]);
|
default: Format(sBuffer, sizeof(sBuffer), "#%d (D: %d | N: +%d | F: +%d)", rank + 1, iSortedList[rank][1], iSortedList[rank - 1][1] - iSortedList[rank][1], iSortedList[0][1] - iSortedList[rank][1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (iDisplay == 1)
|
||||||
|
SendDialog(iSortedList[rank][0], "%s", g_iDialogLevel, 1, sBuffer);
|
||||||
|
else if (iDisplay == 2)
|
||||||
|
SendRankHud(iSortedList[rank][0], sBuffer);
|
||||||
|
else
|
||||||
|
Format(g_sRankTitle[iSortedList[rank][0]], sizeof(g_sRankTitle[]), "[UNLOZE] Pos. %s", sBuffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (iDisplay == 3)
|
||||||
|
UpdateTitles();
|
||||||
|
|
||||||
g_iDialogLevel--;
|
g_iDialogLevel--;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1035,6 +1103,151 @@ void SendDialog(int client, const char[] text, const int level, const int time,
|
|||||||
delete kv;
|
delete kv;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------------------------------
|
||||||
|
// Purpose: Rank line as hudtext. ShowHudText on a fixed channel keeps SourceMod's auto channel
|
||||||
|
// picking (sync huds, channel -1) off it while it refreshes.
|
||||||
|
//----------------------------------------------------------------------------------------------------
|
||||||
|
void SendRankHud(int client, const char[] text)
|
||||||
|
{
|
||||||
|
int channel = g_hCVar_HudChannel.IntValue;
|
||||||
|
|
||||||
|
SetHudTextParams(g_hCVar_HudX.FloatValue, g_hCVar_HudY.FloatValue, 1.0, 255, 255, 255, 255, 0, 0.0, 0.0, 0.0);
|
||||||
|
|
||||||
|
if (!g_bHideDialog[client])
|
||||||
|
{
|
||||||
|
ShowHudText(client, channel, "%s", text);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int spec = 1; spec <= MaxClients; spec++)
|
||||||
|
{
|
||||||
|
if (!IsClientInGame(spec) || !IsClientObserver(spec) || g_bHideDialog[spec])
|
||||||
|
continue;
|
||||||
|
|
||||||
|
int specMode = GetClientSpectatorMode(spec);
|
||||||
|
int specTarget = GetClientSpectatorTarget(spec);
|
||||||
|
|
||||||
|
if ((specMode == SPECMODE_FIRSTPERSON || specMode == SPECMODE_THIRDPERSON) && specTarget == client)
|
||||||
|
{
|
||||||
|
ShowHudText(spec, channel, "%s", text);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------------------------------
|
||||||
|
// Purpose: Rank line as the scoreboard title. Unranked spectators see the title of the player they
|
||||||
|
// watch in first or third person, everyone else gets the real hostname back.
|
||||||
|
//----------------------------------------------------------------------------------------------------
|
||||||
|
void UpdateTitles()
|
||||||
|
{
|
||||||
|
for (int client = 1; client <= MaxClients; client++)
|
||||||
|
{
|
||||||
|
if (!IsClientInGame(client) || IsFakeClient(client))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
int source = client;
|
||||||
|
|
||||||
|
if (!g_sRankTitle[client][0] && IsClientObserver(client))
|
||||||
|
{
|
||||||
|
int specMode = GetClientSpectatorMode(client);
|
||||||
|
int specTarget = GetClientSpectatorTarget(client);
|
||||||
|
|
||||||
|
if ((specMode == SPECMODE_FIRSTPERSON || specMode == SPECMODE_THIRDPERSON) && specTarget >= 1 && specTarget <= MaxClients)
|
||||||
|
source = specTarget;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (g_bHideDialog[client] || !g_sRankTitle[source][0])
|
||||||
|
ResetTitle(client);
|
||||||
|
else
|
||||||
|
SetTitle(client, g_sRankTitle[source]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------------------------------
|
||||||
|
// Purpose: Only sends when the title changes.
|
||||||
|
//----------------------------------------------------------------------------------------------------
|
||||||
|
void SetTitle(int client, const char[] title)
|
||||||
|
{
|
||||||
|
if (g_bTitleSet[client] && strcmp(g_sTitleSent[client], title, true) == 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
SendClientHostname(client, title);
|
||||||
|
|
||||||
|
strcopy(g_sTitleSent[client], sizeof(g_sTitleSent[]), title);
|
||||||
|
g_bTitleSet[client] = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------------------------------
|
||||||
|
// Purpose:
|
||||||
|
//----------------------------------------------------------------------------------------------------
|
||||||
|
void ResetTitle(int client)
|
||||||
|
{
|
||||||
|
if (!g_bTitleSet[client])
|
||||||
|
return;
|
||||||
|
|
||||||
|
g_bTitleSet[client] = false;
|
||||||
|
|
||||||
|
if (!IsClientInGame(client))
|
||||||
|
return;
|
||||||
|
|
||||||
|
char sHostname[128];
|
||||||
|
g_hCVar_Hostname.GetString(sHostname, sizeof(sHostname));
|
||||||
|
|
||||||
|
SendClientHostname(client, sHostname);
|
||||||
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------------------------------
|
||||||
|
// Purpose:
|
||||||
|
//----------------------------------------------------------------------------------------------------
|
||||||
|
void ResetAllTitles()
|
||||||
|
{
|
||||||
|
for (int client = 1; client <= MaxClients; client++)
|
||||||
|
ResetTitle(client);
|
||||||
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------------------------------
|
||||||
|
// Purpose: Copied from HostnameManager. The scoreboard only reads the hostname from server_spawn,
|
||||||
|
// which the client's engine fires locally from svc_ServerInfo on connect. Send a copy
|
||||||
|
// straight to the client so it never reaches server-side listeners, and fill every field so
|
||||||
|
// other client listeners (mumble, abuse report, steam share) see the values they got on connect.
|
||||||
|
//----------------------------------------------------------------------------------------------------
|
||||||
|
void SendClientHostname(int client, const char[] hostname)
|
||||||
|
{
|
||||||
|
Event hEvent = CreateEvent("server_spawn", true);
|
||||||
|
if (hEvent == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
int iIP = g_hCVar_HostIP.IntValue;
|
||||||
|
int iPort = g_hCVar_HostPort.IntValue;
|
||||||
|
|
||||||
|
char sAddress[32];
|
||||||
|
Format(sAddress, sizeof(sAddress), "%d.%d.%d.%d:%d", (iIP >>> 24) & 0xFF, (iIP >>> 16) & 0xFF, (iIP >>> 8) & 0xFF, iIP & 0xFF, iPort);
|
||||||
|
|
||||||
|
char sGame[32];
|
||||||
|
GetGameFolderName(sGame, sizeof(sGame));
|
||||||
|
|
||||||
|
char sMap[PLATFORM_MAX_PATH];
|
||||||
|
GetCurrentMap(sMap, sizeof(sMap));
|
||||||
|
|
||||||
|
char sPassword[64];
|
||||||
|
g_hCVar_Password.GetString(sPassword, sizeof(sPassword));
|
||||||
|
|
||||||
|
hEvent.SetString("hostname", hostname);
|
||||||
|
hEvent.SetString("address", sAddress);
|
||||||
|
hEvent.SetInt("ip", iIP);
|
||||||
|
hEvent.SetInt("port", iPort);
|
||||||
|
hEvent.SetString("game", sGame);
|
||||||
|
hEvent.SetString("mapname", sMap);
|
||||||
|
hEvent.SetInt("maxplayers", MaxClients);
|
||||||
|
hEvent.SetString("os", "LINUX");
|
||||||
|
hEvent.SetBool("dedicated", IsDedicatedServer());
|
||||||
|
hEvent.SetBool("password", sPassword[0] != '\0');
|
||||||
|
|
||||||
|
hEvent.FireToClient(client);
|
||||||
|
|
||||||
|
// FireToClient does not free the event.
|
||||||
|
hEvent.Cancel();
|
||||||
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------------------------
|
||||||
// Purpose:
|
// Purpose:
|
||||||
//----------------------------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------------------------
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ public Plugin myinfo =
|
|||||||
//Handle tagForward;
|
//Handle tagForward;
|
||||||
//Handle applicationForward;
|
//Handle applicationForward;
|
||||||
Handle messageForward;
|
Handle messageForward;
|
||||||
|
Handle rewriteForward;
|
||||||
Handle preLoadedForward;
|
Handle preLoadedForward;
|
||||||
Handle loadedForward;
|
Handle loadedForward;
|
||||||
Handle configReloadedForward;
|
Handle configReloadedForward;
|
||||||
@@ -64,6 +65,11 @@ char g_msgName[128];
|
|||||||
char g_msgSender[128];
|
char g_msgSender[128];
|
||||||
char g_msgText[MAX_CHAT_LENGTH];
|
char g_msgText[MAX_CHAT_LENGTH];
|
||||||
char g_msgFinal[255];
|
char g_msgFinal[255];
|
||||||
|
char g_msgTextRaw[MAX_CHAT_LENGTH]; // g_msgText before coloring, for CCC_OnChatMessageRewrite
|
||||||
|
char g_msgFinalRewritten[255];
|
||||||
|
bool g_msgIsAction;
|
||||||
|
int g_msgChatColor;
|
||||||
|
bool g_msgChatAlpha;
|
||||||
bool g_msgIsTeammate;
|
bool g_msgIsTeammate;
|
||||||
|
|
||||||
bool g_Ignored[(MAXPLAYERS + 1) * (MAXPLAYERS + 1)] = {false, ...};
|
bool g_Ignored[(MAXPLAYERS + 1) * (MAXPLAYERS + 1)] = {false, ...};
|
||||||
@@ -140,6 +146,7 @@ public void OnPluginStart()
|
|||||||
//tagForward = CreateGlobalForward("CCC_OnTagApplied", ET_Event, Param_Cell);
|
//tagForward = CreateGlobalForward("CCC_OnTagApplied", ET_Event, Param_Cell);
|
||||||
//applicationForward = CreateGlobalForward("CCC_OnColor", ET_Event, Param_Cell, Param_String, Param_Cell);
|
//applicationForward = CreateGlobalForward("CCC_OnColor", ET_Event, Param_Cell, Param_String, Param_Cell);
|
||||||
messageForward = CreateGlobalForward("CCC_OnChatMessage", ET_Event, Param_Cell, Param_Cell, Param_String);
|
messageForward = CreateGlobalForward("CCC_OnChatMessage", ET_Event, Param_Cell, Param_Cell, Param_String);
|
||||||
|
rewriteForward = CreateGlobalForward("CCC_OnChatMessageRewrite", ET_Event, Param_Cell, Param_String, Param_Cell);
|
||||||
preLoadedForward = CreateGlobalForward("CCC_OnUserConfigPreLoaded", ET_Event, Param_Cell);
|
preLoadedForward = CreateGlobalForward("CCC_OnUserConfigPreLoaded", ET_Event, Param_Cell);
|
||||||
loadedForward = CreateGlobalForward("CCC_OnUserConfigLoaded", ET_Ignore, Param_Cell);
|
loadedForward = CreateGlobalForward("CCC_OnUserConfigLoaded", ET_Ignore, Param_Cell);
|
||||||
configReloadedForward = CreateGlobalForward("CCC_OnConfigReloaded", ET_Ignore);
|
configReloadedForward = CreateGlobalForward("CCC_OnConfigReloaded", ET_Ignore);
|
||||||
@@ -2603,10 +2610,12 @@ public Action Hook_UserMessage(UserMsg msg_id, Handle bf, const int[] players, i
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!g_msgAuthor || HasFlag(g_msgAuthor, Admin_Custom1))
|
strcopy(g_msgTextRaw, sizeof(g_msgTextRaw), g_msgText);
|
||||||
{
|
g_msgIsAction = bIsAction;
|
||||||
CFormatColor(g_msgText, sizeof(g_msgText), g_msgAuthor);
|
g_msgChatColor = xiChatColor;
|
||||||
}
|
g_msgChatAlpha = bChatAlpha;
|
||||||
|
|
||||||
|
ColorChatText(g_msgText, sizeof(g_msgText));
|
||||||
|
|
||||||
if (!bIsAction)
|
if (!bIsAction)
|
||||||
{
|
{
|
||||||
@@ -2662,34 +2671,6 @@ public Action Hook_UserMessage(UserMsg msg_id, Handle bf, const int[] players, i
|
|||||||
Format(g_msgSender, sizeof(g_msgSender), "\x08%08X%s%s", xiTagColor, sAuthorTag, g_msgSender);
|
Format(g_msgSender, sizeof(g_msgSender), "\x08%08X%s%s", xiTagColor, sAuthorTag, g_msgSender);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (g_msgText[0] == '>' && (GetConVarInt(g_hGreenText) == 1 || (GetConVarInt(g_hGreenText) == 2 && CheckCommandAccess(g_msgAuthor, "sm_tag", ADMFLAG_CUSTOM1))))
|
|
||||||
{
|
|
||||||
Format(g_msgText, sizeof(g_msgText), "\x0714C800%s", g_msgText);
|
|
||||||
}
|
|
||||||
else if (xiChatColor == COLOR_NONE || g_bTagToggled[g_msgAuthor])
|
|
||||||
{
|
|
||||||
}
|
|
||||||
else if (xiChatColor == COLOR_TEAM)
|
|
||||||
{
|
|
||||||
Format(g_msgText, sizeof(g_msgText), "\x03%s", g_msgText);
|
|
||||||
}
|
|
||||||
else if (xiChatColor == COLOR_CGREEN)
|
|
||||||
{
|
|
||||||
Format(g_msgText, sizeof(g_msgText), "\x04%s", g_msgText);
|
|
||||||
}
|
|
||||||
else if (xiChatColor == COLOR_OLIVE)
|
|
||||||
{
|
|
||||||
Format(g_msgText, sizeof(g_msgText), "\x05%s", g_msgText);
|
|
||||||
}
|
|
||||||
else if (!bChatAlpha)
|
|
||||||
{
|
|
||||||
Format(g_msgText, sizeof(g_msgText), "\x07%06X%s", xiChatColor, g_msgText);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Format(g_msgText, sizeof(g_msgText), "\x08%08X%s", xiChatColor, g_msgText);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Format(g_msgFinal, sizeof(g_msgFinal), "%t", g_msgName, g_msgSender, g_msgText);
|
Format(g_msgFinal, sizeof(g_msgFinal), "%t", g_msgName, g_msgSender, g_msgText);
|
||||||
@@ -2697,6 +2678,94 @@ public Action Hook_UserMessage(UserMsg msg_id, Handle bf, const int[] players, i
|
|||||||
return Plugin_Handled;
|
return Plugin_Handled;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Applies the author's chat text coloring, using the state Hook_UserMessage stored for this message
|
||||||
|
void ColorChatText(char[] text, int maxlen)
|
||||||
|
{
|
||||||
|
if (!g_msgAuthor || HasFlag(g_msgAuthor, Admin_Custom1))
|
||||||
|
{
|
||||||
|
CFormatColor(text, maxlen, g_msgAuthor);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (g_msgIsAction)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (text[0] == '>' && (GetConVarInt(g_hGreenText) == 1 || (GetConVarInt(g_hGreenText) == 2 && CheckCommandAccess(g_msgAuthor, "sm_tag", ADMFLAG_CUSTOM1))))
|
||||||
|
{
|
||||||
|
Format(text, maxlen, "\x0714C800%s", text);
|
||||||
|
}
|
||||||
|
else if (g_msgChatColor == COLOR_NONE || g_bTagToggled[g_msgAuthor])
|
||||||
|
{
|
||||||
|
}
|
||||||
|
else if (g_msgChatColor == COLOR_TEAM)
|
||||||
|
{
|
||||||
|
Format(text, maxlen, "\x03%s", text);
|
||||||
|
}
|
||||||
|
else if (g_msgChatColor == COLOR_CGREEN)
|
||||||
|
{
|
||||||
|
Format(text, maxlen, "\x04%s", text);
|
||||||
|
}
|
||||||
|
else if (g_msgChatColor == COLOR_OLIVE)
|
||||||
|
{
|
||||||
|
Format(text, maxlen, "\x05%s", text);
|
||||||
|
}
|
||||||
|
else if (!g_msgChatAlpha)
|
||||||
|
{
|
||||||
|
Format(text, maxlen, "\x07%06X%s", g_msgChatColor, text);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Format(text, maxlen, "\x08%08X%s", g_msgChatColor, text);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Lets plugins rewrite the raw message once; on success g_msgFinalRewritten holds the formatted line
|
||||||
|
bool BuildRewrittenMessage()
|
||||||
|
{
|
||||||
|
char sText[MAX_CHAT_LENGTH];
|
||||||
|
strcopy(sText, sizeof(sText), g_msgTextRaw);
|
||||||
|
|
||||||
|
Action result = Plugin_Continue;
|
||||||
|
|
||||||
|
Call_StartForward(rewriteForward);
|
||||||
|
Call_PushCell(g_msgAuthor);
|
||||||
|
Call_PushStringEx(sText, sizeof(sText), SM_PARAM_STRING_UTF8 | SM_PARAM_STRING_COPY, SM_PARAM_COPYBACK);
|
||||||
|
Call_PushCell(sizeof(sText));
|
||||||
|
Call_Finish(result);
|
||||||
|
|
||||||
|
if (result != Plugin_Changed || StrEqual(sText, g_msgTextRaw))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
TrimString(sText);
|
||||||
|
|
||||||
|
if (strlen(sText) == 0)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
ColorChatText(sText, sizeof(sText));
|
||||||
|
Format(g_msgFinalRewritten, sizeof(g_msgFinalRewritten), "%t", g_msgName, g_msgSender, sText);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void SendSayText2(const int[] players, int playersNum, const char[] text)
|
||||||
|
{
|
||||||
|
Handle SayText2 = StartMessage("SayText2", players, playersNum, USERMSG_RELIABLE | USERMSG_BLOCKHOOKS);
|
||||||
|
|
||||||
|
if (GetFeatureStatus(FeatureType_Native, "GetUserMessageType") == FeatureStatus_Available && GetUserMessageType() == UM_Protobuf)
|
||||||
|
{
|
||||||
|
PbSetInt(SayText2, "ent_idx", g_msgAuthor);
|
||||||
|
PbSetBool(SayText2, "chat", g_msgIsChat);
|
||||||
|
PbSetString(SayText2, "text", text);
|
||||||
|
EndMessage();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
BfWriteByte(SayText2, g_msgAuthor);
|
||||||
|
BfWriteByte(SayText2, g_msgIsChat);
|
||||||
|
BfWriteString(SayText2, text);
|
||||||
|
EndMessage();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public Action Event_PlayerSay(Handle event, const char[] name, bool dontBroadcast)
|
public Action Event_PlayerSay(Handle event, const char[] name, bool dontBroadcast)
|
||||||
{
|
{
|
||||||
if (g_msgAuthor == -1 || GetClientOfUserId(GetEventInt(event, "userid")) != g_msgAuthor)
|
if (g_msgAuthor == -1 || GetClientOfUserId(GetEventInt(event, "userid")) != g_msgAuthor)
|
||||||
@@ -2709,54 +2778,40 @@ public Action Event_PlayerSay(Handle event, const char[] name, bool dontBroadcas
|
|||||||
|
|
||||||
int[] players = new int[MaxClients + 1];
|
int[] players = new int[MaxClients + 1];
|
||||||
int playersNum = 0;
|
int playersNum = 0;
|
||||||
|
int[] rewritePlayers = new int[MaxClients + 1];
|
||||||
if (g_msgIsTeammate && g_msgAuthor > 0)
|
int rewritePlayersNum = 0;
|
||||||
{
|
int team = (g_msgIsTeammate && g_msgAuthor > 0) ? GetClientTeam(g_msgAuthor) : -1;
|
||||||
int team = GetClientTeam(g_msgAuthor);
|
|
||||||
|
|
||||||
for (int client = 1; client <= MaxClients; client++)
|
for (int client = 1; client <= MaxClients; client++)
|
||||||
{
|
{
|
||||||
if (IsClientInGame(client) && GetClientTeam(client) == team)
|
if (!IsClientInGame(client) || (team != -1 && GetClientTeam(client) != team))
|
||||||
{
|
continue;
|
||||||
if(!g_Ignored[client * (MAXPLAYERS + 1) + g_msgAuthor] && MessageForward(client, g_msgAuthor, g_msgText) )
|
|
||||||
|
if (g_Ignored[client * (MAXPLAYERS + 1) + g_msgAuthor])
|
||||||
|
continue;
|
||||||
|
|
||||||
|
Action result = MessageForward(client, g_msgAuthor, g_msgText);
|
||||||
|
|
||||||
|
if (result == Plugin_Changed)
|
||||||
|
rewritePlayers[rewritePlayersNum++] = client;
|
||||||
|
else if (result < Plugin_Handled)
|
||||||
players[playersNum++] = client;
|
players[playersNum++] = client;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
// viewers who asked for a rewrite see the normal line when no plugin rewrote it
|
||||||
else
|
if (rewritePlayersNum && !BuildRewrittenMessage())
|
||||||
{
|
{
|
||||||
for (int client = 1; client <= MaxClients; client++)
|
for (int i = 0; i < rewritePlayersNum; i++)
|
||||||
{
|
players[playersNum++] = rewritePlayers[i];
|
||||||
if (IsClientInGame(client))
|
|
||||||
{
|
rewritePlayersNum = 0;
|
||||||
if(!g_Ignored[client * (MAXPLAYERS + 1) + g_msgAuthor] && MessageForward(client, g_msgAuthor, g_msgText) )
|
|
||||||
players[playersNum++] = client;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!playersNum)
|
if (playersNum)
|
||||||
{
|
SendSayText2(players, playersNum, g_msgFinal);
|
||||||
g_msgAuthor = -1;
|
|
||||||
return Plugin_Handled;
|
|
||||||
}
|
|
||||||
|
|
||||||
Handle SayText2 = StartMessage("SayText2", players, playersNum, USERMSG_RELIABLE | USERMSG_BLOCKHOOKS);
|
if (rewritePlayersNum)
|
||||||
|
SendSayText2(rewritePlayers, rewritePlayersNum, g_msgFinalRewritten);
|
||||||
if (GetFeatureStatus(FeatureType_Native, "GetUserMessageType") == FeatureStatus_Available && GetUserMessageType() == UM_Protobuf)
|
|
||||||
{
|
|
||||||
PbSetInt(SayText2, "ent_idx", g_msgAuthor);
|
|
||||||
PbSetBool(SayText2, "chat", g_msgIsChat);
|
|
||||||
PbSetString(SayText2, "text", g_msgFinal);
|
|
||||||
EndMessage();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
BfWriteByte(SayText2, g_msgAuthor);
|
|
||||||
BfWriteByte(SayText2, g_msgIsChat);
|
|
||||||
BfWriteString(SayText2, g_msgFinal);
|
|
||||||
EndMessage();
|
|
||||||
}
|
|
||||||
|
|
||||||
g_msgAuthor = -1;
|
g_msgAuthor = -1;
|
||||||
return Plugin_Handled;
|
return Plugin_Handled;
|
||||||
@@ -2851,7 +2906,7 @@ stock bool ConfigForward(int client)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
stock bool MessageForward(int client, int author, char[] message)
|
stock Action MessageForward(int client, int author, char[] message)
|
||||||
{
|
{
|
||||||
Action result = Plugin_Continue;
|
Action result = Plugin_Continue;
|
||||||
|
|
||||||
@@ -2861,10 +2916,7 @@ stock bool MessageForward(int client, int author, char[] message)
|
|||||||
Call_PushString(message);
|
Call_PushString(message);
|
||||||
Call_Finish(result);
|
Call_Finish(result);
|
||||||
|
|
||||||
if (result >= Plugin_Handled)
|
return result;
|
||||||
return false;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public int Native_GetColor(Handle plugin, int numParams)
|
public int Native_GetColor(Handle plugin, int numParams)
|
||||||
|
|||||||
@@ -137,10 +137,24 @@ native int CCC_ResetTag(int client);
|
|||||||
* @param client Recieving client index
|
* @param client Recieving client index
|
||||||
* @param author Author client index
|
* @param author Author client index
|
||||||
* @param message Message
|
* @param message Message
|
||||||
* @return Plugin_Handled to block message, Plugin_Continue to allow message
|
* @return Plugin_Handled to block message, Plugin_Changed to send this client the
|
||||||
|
* copy rewritten by CCC_OnChatMessageRewrite (or the normal message if
|
||||||
|
* nothing rewrote it), Plugin_Continue to allow message
|
||||||
*/
|
*/
|
||||||
forward Action CCC_OnChatMessage(int client, int author, const char[] message);
|
forward Action CCC_OnChatMessage(int client, int author, const char[] message);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called at most once per chat message, and only if a recipient's CCC_OnChatMessage returned Plugin_Changed.
|
||||||
|
* The message is the raw text, after /me and auto-replace but before coloring.
|
||||||
|
* DO NOT START A NEW USERMESSAGE (i.e. PrintToChat, PrintToChatAll) WITHIN THIS FORWARD
|
||||||
|
*
|
||||||
|
* @param author Author client index
|
||||||
|
* @param message Message buffer to rewrite in place
|
||||||
|
* @param maxlen Size of the message buffer
|
||||||
|
* @return Plugin_Changed if the message was rewritten, Plugin_Continue otherwise
|
||||||
|
*/
|
||||||
|
forward Action CCC_OnChatMessageRewrite(int author, char[] message, int maxlen);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when a client's colors and tag are about to be loaded from the config file
|
* Called when a client's colors and tag are about to be loaded from the config file
|
||||||
* At this point, the client has NO COLORS
|
* At this point, the client has NO COLORS
|
||||||
|
|||||||
@@ -0,0 +1,51 @@
|
|||||||
|
#if defined _Break_include
|
||||||
|
#endinput
|
||||||
|
#endif
|
||||||
|
#define _Break_include
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when a break is started
|
||||||
|
*
|
||||||
|
* @return None
|
||||||
|
*/
|
||||||
|
forward void Break_OnBreakStarted();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when a break is finished
|
||||||
|
*
|
||||||
|
* @return None
|
||||||
|
*/
|
||||||
|
forward void Break_OnBreakFinished();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when a break is cancelled
|
||||||
|
*
|
||||||
|
* @return None
|
||||||
|
*/
|
||||||
|
forward void Break_OnBreakCancelled();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns if a break is active
|
||||||
|
*
|
||||||
|
* @return True when in break, false otherwise
|
||||||
|
*/
|
||||||
|
native bool Break_IsBreakActive();
|
||||||
|
|
||||||
|
public SharedPlugin __pl_Break =
|
||||||
|
{
|
||||||
|
name = "Break",
|
||||||
|
file = "Break.smx",
|
||||||
|
|
||||||
|
#if defined REQUIRE_PLUGIN
|
||||||
|
required = 1
|
||||||
|
#else
|
||||||
|
required = 0
|
||||||
|
#endif
|
||||||
|
};
|
||||||
|
|
||||||
|
#if !defined REQUIRE_PLUGIN
|
||||||
|
public void __pl_Break_SetNTVOptional()
|
||||||
|
{
|
||||||
|
MarkNativeAsOptional("Break_IsBreakActive");
|
||||||
|
}
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,50 @@
|
|||||||
|
#if defined _ChatFilter2_included_
|
||||||
|
#endinput
|
||||||
|
#endif
|
||||||
|
#define _ChatFilter2_included_
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Censors bad words in a string the same way safe chat does, with every category.
|
||||||
|
*
|
||||||
|
* @param text String to censor in place
|
||||||
|
* @param maxlen Size of text
|
||||||
|
* @return True if anything was censored
|
||||||
|
*/
|
||||||
|
native bool ChatFilter2_CensorText(char[] text, int maxlen);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if a client has safe chat enabled.
|
||||||
|
*
|
||||||
|
* @param client Client index
|
||||||
|
* @return True if safe chat is enabled
|
||||||
|
*/
|
||||||
|
native bool ChatFilter2_IsSafeChatEnabled(int client);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when a client toggles safe chat, and when their cookies load with safe chat enabled.
|
||||||
|
*
|
||||||
|
* @param client Client index
|
||||||
|
* @param enabled True if safe chat is now enabled
|
||||||
|
*/
|
||||||
|
forward void ChatFilter2_OnSafeChatChanged(int client, bool enabled);
|
||||||
|
|
||||||
|
#if !defined CHATFILTER2_CORE
|
||||||
|
public SharedPlugin __pl_ChatFilter2 =
|
||||||
|
{
|
||||||
|
name = "ChatFilter2",
|
||||||
|
file = "ChatFilter2.smx",
|
||||||
|
#if defined REQUIRE_PLUGIN
|
||||||
|
required = 1,
|
||||||
|
#else
|
||||||
|
required = 0,
|
||||||
|
#endif
|
||||||
|
};
|
||||||
|
|
||||||
|
#if !defined REQUIRE_PLUGIN
|
||||||
|
public void __pl_ChatFilter2_SetNTVOptional()
|
||||||
|
{
|
||||||
|
MarkNativeAsOptional("ChatFilter2_CensorText");
|
||||||
|
MarkNativeAsOptional("ChatFilter2_IsSafeChatEnabled");
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
#endif // CHATFILTER2_CORE
|
||||||
Symlink
+1
@@ -0,0 +1 @@
|
|||||||
|
../Couch/scripting/include/Couch.inc
|
||||||
@@ -0,0 +1,159 @@
|
|||||||
|
#if defined _EventNotifier_included
|
||||||
|
#endinput
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define _EventNotifier_included
|
||||||
|
|
||||||
|
#define EVENT_STR_LEN 128
|
||||||
|
#define EVENT_URL_LEN 192
|
||||||
|
#define EVENT_MAPS_LEN 1024
|
||||||
|
|
||||||
|
enum struct EventInfo
|
||||||
|
{
|
||||||
|
int number;
|
||||||
|
int start; // unix timestamp (UTC), 0 if unknown
|
||||||
|
int end; // unix timestamp (UTC), 0 if unknown
|
||||||
|
char url[EVENT_URL_LEN]; // forum thread URL, empty if unknown
|
||||||
|
char name[EVENT_STR_LEN];
|
||||||
|
char server[EVENT_STR_LEN];
|
||||||
|
char rewards[EVENT_STR_LEN];
|
||||||
|
char leader[EVENT_STR_LEN];
|
||||||
|
char kickers[EVENT_STR_LEN];
|
||||||
|
char maps[EVENT_MAPS_LEN]; // ", "-joined list
|
||||||
|
}
|
||||||
|
|
||||||
|
#if !defined EVENTNOTIFIER_CORE
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Number of events in the last successful fetch (0 before the first fetch).
|
||||||
|
*
|
||||||
|
* @return Event count.
|
||||||
|
*/
|
||||||
|
native int EventNotifier_GetEventCount();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether at least one fetch has succeeded since the plugin loaded.
|
||||||
|
*
|
||||||
|
* @return True once the event list has been fetched.
|
||||||
|
*/
|
||||||
|
native bool EventNotifier_HasFetched();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Finds an event by its event number.
|
||||||
|
*
|
||||||
|
* @param number Event number.
|
||||||
|
* @return Index into the event list, or -1 if not found.
|
||||||
|
*/
|
||||||
|
native int EventNotifier_FindEventByNumber(int number);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Copies an event into the caller's EventInfo.
|
||||||
|
*
|
||||||
|
* @param index Index into the event list.
|
||||||
|
* @param ev EventInfo to fill.
|
||||||
|
* @param size Size of ev, must be sizeof(EventInfo).
|
||||||
|
* @return True on success, false if index is out of range.
|
||||||
|
* @error Buffer smaller than sizeof(EventInfo).
|
||||||
|
*/
|
||||||
|
native bool EventNotifier_GetEvent(int index, any[] ev, int size = sizeof(EventInfo));
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Starts a fetch of the event list now. No-op if a fetch is already running.
|
||||||
|
*/
|
||||||
|
native void EventNotifier_Refresh();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Formats a timestamp in the client's own timezone (looked up via GeoIP),
|
||||||
|
* e.g. "Thu 01 Oct 2026, 20:00 BST". Clients whose timezone is unknown get
|
||||||
|
* sm_event_fallback_timezone.
|
||||||
|
*
|
||||||
|
* @param client Client index, 0 for the fallback timezone.
|
||||||
|
* @param timestamp Unix timestamp (UTC).
|
||||||
|
* @param buffer Destination buffer.
|
||||||
|
* @param maxlen Size of buffer.
|
||||||
|
* @param withYear Whether to include the year.
|
||||||
|
* @error Invalid client index.
|
||||||
|
*/
|
||||||
|
native void EventNotifier_FormatClientTime(int client, int timestamp, char[] buffer, int maxlen, bool withYear = true);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called after every successful fetch, once the event list has been replaced.
|
||||||
|
*/
|
||||||
|
forward void EventNotifier_OnEventsUpdated();
|
||||||
|
|
||||||
|
#endif // EVENTNOTIFIER_CORE
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
// Display helpers
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Formats a duration in seconds as "1d 2h 3m", "2h 3m" or "3m".
|
||||||
|
*/
|
||||||
|
stock void EventNotifier_FormatDuration(int seconds, char[] buffer, int maxlen)
|
||||||
|
{
|
||||||
|
int days = seconds / 86400;
|
||||||
|
int hours = (seconds % 86400) / 3600;
|
||||||
|
int minutes = (seconds % 3600) / 60;
|
||||||
|
|
||||||
|
if (days > 0)
|
||||||
|
Format(buffer, maxlen, "%dd %dh %dm", days, hours, minutes);
|
||||||
|
else if (hours > 0)
|
||||||
|
Format(buffer, maxlen, "%dh %dm", hours, minutes);
|
||||||
|
else
|
||||||
|
Format(buffer, maxlen, "%dm", minutes);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Formats an event's status relative to now as a "Status: ..." line.
|
||||||
|
*/
|
||||||
|
stock void EventNotifier_FormatRelativeTime(int start, int end, char[] buffer, int maxlen)
|
||||||
|
{
|
||||||
|
int now = GetTime();
|
||||||
|
|
||||||
|
if (end > 0 && now >= start && now < end)
|
||||||
|
{
|
||||||
|
strcopy(buffer, maxlen, "Status: In progress now!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
char span[32];
|
||||||
|
if (now >= start)
|
||||||
|
{
|
||||||
|
EventNotifier_FormatDuration(now - start, span, sizeof(span));
|
||||||
|
Format(buffer, maxlen, "Status: Started %s ago", span);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
EventNotifier_FormatDuration(start - now, span, sizeof(span));
|
||||||
|
Format(buffer, maxlen, "Status: Starts in %s", span);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#if !defined EVENTNOTIFIER_CORE
|
||||||
|
|
||||||
|
public SharedPlugin __pl_EventNotifier =
|
||||||
|
{
|
||||||
|
name = "EventNotifier",
|
||||||
|
file = "EventNotifier.smx",
|
||||||
|
|
||||||
|
#if defined REQUIRE_PLUGIN
|
||||||
|
required = 1
|
||||||
|
#else
|
||||||
|
required = 0
|
||||||
|
#endif
|
||||||
|
};
|
||||||
|
|
||||||
|
#if !defined REQUIRE_PLUGIN
|
||||||
|
public void __pl_EventNotifier_SetNTVOptional()
|
||||||
|
{
|
||||||
|
MarkNativeAsOptional("EventNotifier_GetEventCount");
|
||||||
|
MarkNativeAsOptional("EventNotifier_HasFetched");
|
||||||
|
MarkNativeAsOptional("EventNotifier_FindEventByNumber");
|
||||||
|
MarkNativeAsOptional("EventNotifier_GetEvent");
|
||||||
|
MarkNativeAsOptional("EventNotifier_Refresh");
|
||||||
|
MarkNativeAsOptional("EventNotifier_FormatClientTime");
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif // EVENTNOTIFIER_CORE
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
#if defined _TransmitManager_included
|
||||||
|
#endinput
|
||||||
|
#endif
|
||||||
|
#define _TransmitManager_included
|
||||||
|
|
||||||
|
native void TransmitManager_AddEntityHooks(int entity);
|
||||||
|
native bool TransmitManager_SetEntityOwner(int entity, int target);
|
||||||
|
native bool TransmitManager_SetEntityState(int entity, int client, bool can);
|
||||||
|
native bool TransmitManager_GetEntityState(int entity, int client);
|
||||||
|
native bool TransmitManager_IsEntityHooked(int entity);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* _________________Do not edit below this line!_______________________
|
||||||
|
*/
|
||||||
|
public Extension __ext_transmit =
|
||||||
|
{
|
||||||
|
name = "TransmitManager",
|
||||||
|
file = "TransmitManager.ext",
|
||||||
|
#if defined AUTOLOAD_EXTENSIONS
|
||||||
|
autoload = 1,
|
||||||
|
#else
|
||||||
|
autoload = 0,
|
||||||
|
#endif
|
||||||
|
#if defined REQUIRE_EXTENSIONS
|
||||||
|
required = 1,
|
||||||
|
#else
|
||||||
|
required = 0,
|
||||||
|
#endif
|
||||||
|
};
|
||||||
|
|
||||||
@@ -0,0 +1,90 @@
|
|||||||
|
#if defined _leader_included_
|
||||||
|
#endinput
|
||||||
|
#endif
|
||||||
|
#define _leader_included_
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the current PRIMARY leader.
|
||||||
|
*
|
||||||
|
* @return Client index of the primary leader (-1 = no leader)
|
||||||
|
*/
|
||||||
|
native int Leader_CurrentLeader();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Makes a client the PRIMARY leader. If another primary exists, they are
|
||||||
|
* demoted to sub-leader. If the client is already a sub-leader, they are
|
||||||
|
* promoted.
|
||||||
|
*
|
||||||
|
* @param client Client index to be set as primary leader
|
||||||
|
*/
|
||||||
|
native void Leader_SetLeader(int client);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if a client is currently a leader (primary or sub-leader).
|
||||||
|
*
|
||||||
|
* @param client Client index to check
|
||||||
|
* @return True if the client is a leader
|
||||||
|
*/
|
||||||
|
native bool Leader_Is(int client);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the number of current leaders (primary + sub-leaders).
|
||||||
|
*
|
||||||
|
* @return Leader count
|
||||||
|
*/
|
||||||
|
native int Leader_GetLeaderCount();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the leader at the given roster index.
|
||||||
|
*
|
||||||
|
* @param index Roster index (0 = primary)
|
||||||
|
* @return Client index, or -1 if no leader at that index
|
||||||
|
*/
|
||||||
|
native int Leader_GetLeader(int index);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called after a client becomes a leader.
|
||||||
|
*
|
||||||
|
* @param client The new leader
|
||||||
|
* @param primary True if they became the primary leader
|
||||||
|
*/
|
||||||
|
forward void Leader_OnLeaderAdded(int client, bool primary);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called after a client stops being a leader.
|
||||||
|
*
|
||||||
|
* @param client The removed leader
|
||||||
|
*/
|
||||||
|
forward void Leader_OnLeaderRemoved(int client);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when the primary leader changes.
|
||||||
|
*
|
||||||
|
* @param oldLeader Previous primary (-1 = none)
|
||||||
|
* @param newLeader New primary (-1 = none)
|
||||||
|
*/
|
||||||
|
forward void Leader_OnPrimaryChanged(int oldLeader, int newLeader);
|
||||||
|
|
||||||
|
#if !defined LEADER3_CORE
|
||||||
|
public SharedPlugin __pl_leader =
|
||||||
|
{
|
||||||
|
name = "leader",
|
||||||
|
file = "Leader3.smx",
|
||||||
|
#if defined REQUIRE_PLUGIN
|
||||||
|
required = 1,
|
||||||
|
#else
|
||||||
|
required = 0,
|
||||||
|
#endif
|
||||||
|
};
|
||||||
|
|
||||||
|
#if !defined REQUIRE_PLUGIN
|
||||||
|
public void __pl_leader_SetNTVOptional()
|
||||||
|
{
|
||||||
|
MarkNativeAsOptional("Leader_CurrentLeader");
|
||||||
|
MarkNativeAsOptional("Leader_SetLeader");
|
||||||
|
MarkNativeAsOptional("Leader_Is");
|
||||||
|
MarkNativeAsOptional("Leader_GetLeaderCount");
|
||||||
|
MarkNativeAsOptional("Leader_GetLeader");
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
#endif // LEADER3_CORE
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
#if defined _ripext_included_
|
||||||
|
#endinput
|
||||||
|
#endif
|
||||||
|
#define _ripext_included_
|
||||||
|
|
||||||
|
#include <ripext/json>
|
||||||
|
#include <ripext/http>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Do not edit below this line!
|
||||||
|
*/
|
||||||
|
public Extension __ext_rip =
|
||||||
|
{
|
||||||
|
name = "REST in Pawn",
|
||||||
|
file = "rip.ext",
|
||||||
|
#if defined AUTOLOAD_EXTENSIONS
|
||||||
|
autoload = 1,
|
||||||
|
#else
|
||||||
|
autoload = 0,
|
||||||
|
#endif
|
||||||
|
#if defined REQUIRE_EXTENSIONS
|
||||||
|
required = 1,
|
||||||
|
#else
|
||||||
|
required = 0,
|
||||||
|
#endif
|
||||||
|
};
|
||||||
@@ -0,0 +1,359 @@
|
|||||||
|
enum HTTPStatus
|
||||||
|
{
|
||||||
|
HTTPStatus_Invalid = 0,
|
||||||
|
|
||||||
|
// 1xx Informational
|
||||||
|
HTTPStatus_Continue = 100,
|
||||||
|
HTTPStatus_SwitchingProtocols = 101,
|
||||||
|
|
||||||
|
// 2xx Success
|
||||||
|
HTTPStatus_OK = 200,
|
||||||
|
HTTPStatus_Created = 201,
|
||||||
|
HTTPStatus_Accepted = 202,
|
||||||
|
HTTPStatus_NonAuthoritativeInformation = 203,
|
||||||
|
HTTPStatus_NoContent = 204,
|
||||||
|
HTTPStatus_ResetContent = 205,
|
||||||
|
HTTPStatus_PartialContent = 206,
|
||||||
|
|
||||||
|
// 3xx Redirection
|
||||||
|
HTTPStatus_MultipleChoices = 300,
|
||||||
|
HTTPStatus_MovedPermanently = 301,
|
||||||
|
HTTPStatus_Found = 302,
|
||||||
|
HTTPStatus_SeeOther = 303,
|
||||||
|
HTTPStatus_NotModified = 304,
|
||||||
|
HTTPStatus_UseProxy = 305,
|
||||||
|
HTTPStatus_TemporaryRedirect = 307,
|
||||||
|
HTTPStatus_PermanentRedirect = 308,
|
||||||
|
|
||||||
|
// 4xx Client Error
|
||||||
|
HTTPStatus_BadRequest = 400,
|
||||||
|
HTTPStatus_Unauthorized = 401,
|
||||||
|
HTTPStatus_PaymentRequired = 402,
|
||||||
|
HTTPStatus_Forbidden = 403,
|
||||||
|
HTTPStatus_NotFound = 404,
|
||||||
|
HTTPStatus_MethodNotAllowed = 405,
|
||||||
|
HTTPStatus_NotAcceptable = 406,
|
||||||
|
HTTPStatus_ProxyAuthenticationRequired = 407,
|
||||||
|
HTTPStatus_RequestTimeout = 408,
|
||||||
|
HTTPStatus_Conflict = 409,
|
||||||
|
HTTPStatus_Gone = 410,
|
||||||
|
HTTPStatus_LengthRequired = 411,
|
||||||
|
HTTPStatus_PreconditionFailed = 412,
|
||||||
|
HTTPStatus_RequestEntityTooLarge = 413,
|
||||||
|
HTTPStatus_RequestURITooLong = 414,
|
||||||
|
HTTPStatus_UnsupportedMediaType = 415,
|
||||||
|
HTTPStatus_RequestedRangeNotSatisfiable = 416,
|
||||||
|
HTTPStatus_ExpectationFailed = 417,
|
||||||
|
HTTPStatus_MisdirectedRequest = 421,
|
||||||
|
HTTPStatus_TooEarly = 425,
|
||||||
|
HTTPStatus_UpgradeRequired = 426,
|
||||||
|
HTTPStatus_PreconditionRequired = 428,
|
||||||
|
HTTPStatus_TooManyRequests = 429,
|
||||||
|
HTTPStatus_RequestHeaderFieldsTooLarge = 431,
|
||||||
|
HTTPStatus_UnavailableForLegalReasons = 451,
|
||||||
|
|
||||||
|
// 5xx Server Error
|
||||||
|
HTTPStatus_InternalServerError = 500,
|
||||||
|
HTTPStatus_NotImplemented = 501,
|
||||||
|
HTTPStatus_BadGateway = 502,
|
||||||
|
HTTPStatus_ServiceUnavailable = 503,
|
||||||
|
HTTPStatus_GatewayTimeout = 504,
|
||||||
|
HTTPStatus_HTTPVersionNotSupported = 505,
|
||||||
|
HTTPStatus_VariantAlsoNegotiates = 506,
|
||||||
|
HTTPStatus_NotExtended = 510,
|
||||||
|
HTTPStatus_NetworkAuthenticationRequired = 511,
|
||||||
|
};
|
||||||
|
|
||||||
|
typeset HTTPRequestCallback
|
||||||
|
{
|
||||||
|
function void (HTTPResponse response, any value);
|
||||||
|
function void (HTTPResponse response, any value, const char[] error);
|
||||||
|
};
|
||||||
|
|
||||||
|
typeset HTTPFileCallback
|
||||||
|
{
|
||||||
|
function void (HTTPStatus status, any value);
|
||||||
|
function void (HTTPStatus status, any value, const char[] error);
|
||||||
|
};
|
||||||
|
|
||||||
|
methodmap HTTPRequest < Handle
|
||||||
|
{
|
||||||
|
// Creates an HTTP request.
|
||||||
|
//
|
||||||
|
// The Handle is automatically freed when the request is performed.
|
||||||
|
// Otherwise, the Handle must be freed via delete or CloseHandle().
|
||||||
|
//
|
||||||
|
// @param url URL to the REST API endpoint.
|
||||||
|
public native HTTPRequest(const char[] url);
|
||||||
|
|
||||||
|
// Appends a parameter to the form data.
|
||||||
|
//
|
||||||
|
// The parameter name and value are encoded according to RFC 3986.
|
||||||
|
//
|
||||||
|
// @param name Parameter name.
|
||||||
|
// @param format Formatting rules.
|
||||||
|
// @param ... Variable number of format parameters.
|
||||||
|
public native void AppendFormParam(const char[] name, const char[] format, any ...);
|
||||||
|
|
||||||
|
// Appends a query parameter to the URL.
|
||||||
|
//
|
||||||
|
// The parameter name and value are encoded according to RFC 3986.
|
||||||
|
//
|
||||||
|
// @param name Parameter name.
|
||||||
|
// @param format Formatting rules.
|
||||||
|
// @param ... Variable number of format parameters.
|
||||||
|
public native void AppendQueryParam(const char[] name, const char[] format, any ...);
|
||||||
|
|
||||||
|
// Sets the credentials for HTTP Basic authentication.
|
||||||
|
//
|
||||||
|
// @param username Username to use.
|
||||||
|
// @param password Password to use.
|
||||||
|
public native void SetBasicAuth(const char[] username, const char[] password);
|
||||||
|
|
||||||
|
// Sets an HTTP header.
|
||||||
|
//
|
||||||
|
// @param name Header name.
|
||||||
|
// @param format Formatting rules.
|
||||||
|
// @param ... Variable number of format parameters.
|
||||||
|
public native void SetHeader(const char[] name, const char[] format, any ...);
|
||||||
|
|
||||||
|
// Performs an HTTP GET request.
|
||||||
|
//
|
||||||
|
// This function closes the request Handle after completing.
|
||||||
|
//
|
||||||
|
// @param callback A function to use as a callback when the request has finished.
|
||||||
|
// @param value Optional value to pass to the callback function.
|
||||||
|
public native void Get(HTTPRequestCallback callback, any value = 0);
|
||||||
|
|
||||||
|
// Performs an HTTP POST request.
|
||||||
|
//
|
||||||
|
// This function closes the request Handle after completing.
|
||||||
|
//
|
||||||
|
// @param data JSON data to send.
|
||||||
|
// @param callback A function to use as a callback when the request has finished.
|
||||||
|
// @param value Optional value to pass to the callback function.
|
||||||
|
public native void Post(JSON data, HTTPRequestCallback callback, any value = 0);
|
||||||
|
|
||||||
|
// Performs an HTTP PUT request.
|
||||||
|
//
|
||||||
|
// This function closes the request Handle after completing.
|
||||||
|
//
|
||||||
|
// @param data JSON data to send.
|
||||||
|
// @param callback A function to use as a callback when the request has finished.
|
||||||
|
// @param value Optional value to pass to the callback function.
|
||||||
|
public native void Put(JSON data, HTTPRequestCallback callback, any value = 0);
|
||||||
|
|
||||||
|
// Performs an HTTP PATCH request.
|
||||||
|
//
|
||||||
|
// This function closes the request Handle after completing.
|
||||||
|
//
|
||||||
|
// @param data JSON data to send.
|
||||||
|
// @param callback A function to use as a callback when the request has finished.
|
||||||
|
// @param value Optional value to pass to the callback function.
|
||||||
|
public native void Patch(JSON data, HTTPRequestCallback callback, any value = 0);
|
||||||
|
|
||||||
|
// Performs an HTTP DELETE request.
|
||||||
|
//
|
||||||
|
// This function closes the request Handle after completing.
|
||||||
|
//
|
||||||
|
// @param callback A function to use as a callback when the request has finished.
|
||||||
|
// @param value Optional value to pass to the callback function.
|
||||||
|
public native void Delete(HTTPRequestCallback callback, any value = 0);
|
||||||
|
|
||||||
|
// Downloads a file.
|
||||||
|
//
|
||||||
|
// This function closes the request Handle after completing.
|
||||||
|
//
|
||||||
|
// @param path File path to write to.
|
||||||
|
// @param callback A function to use as a callback when the download has finished.
|
||||||
|
// @param value Optional value to pass to the callback function.
|
||||||
|
public native void DownloadFile(const char[] path, HTTPFileCallback callback, any value = 0);
|
||||||
|
|
||||||
|
// Uploads a file.
|
||||||
|
//
|
||||||
|
// This function performs an HTTP PUT request. The file contents are sent in the request body.
|
||||||
|
// This function closes the request Handle after completing.
|
||||||
|
//
|
||||||
|
// @param path File path to read from.
|
||||||
|
// @param callback A function to use as a callback when the upload has finished.
|
||||||
|
// @param value Optional value to pass to the callback function.
|
||||||
|
public native void UploadFile(const char[] path, HTTPFileCallback callback, any value = 0);
|
||||||
|
|
||||||
|
// Performs an HTTP POST request with form data.
|
||||||
|
//
|
||||||
|
// This function closes the request Handle after completing.
|
||||||
|
//
|
||||||
|
// @param callback A function to use as a callback when the request has finished.
|
||||||
|
// @param value Optional value to pass to the callback function.
|
||||||
|
public native void PostForm(HTTPRequestCallback callback, any value = 0);
|
||||||
|
|
||||||
|
// Connect timeout in seconds. Defaults to 10.
|
||||||
|
property int ConnectTimeout {
|
||||||
|
public native get();
|
||||||
|
public native set(int connectTimeout);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Maximum number of redirects to follow. Defaults to 5.
|
||||||
|
property int MaxRedirects {
|
||||||
|
public native get();
|
||||||
|
public native set(int maxRedirects);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Maximum download speed in bytes per second. Defaults to unlimited speed.
|
||||||
|
property int MaxRecvSpeed {
|
||||||
|
public native get();
|
||||||
|
public native set(int maxSpeed);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Maximum upload speed in bytes per second. Defaults to unlimited speed.
|
||||||
|
property int MaxSendSpeed {
|
||||||
|
public native get();
|
||||||
|
public native set(int maxSpeed);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Timeout in seconds. Defaults to 30.
|
||||||
|
property int Timeout {
|
||||||
|
public native get();
|
||||||
|
public native set(int timeout);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
methodmap HTTPResponse
|
||||||
|
{
|
||||||
|
// Retrieves an HTTP header from the response.
|
||||||
|
//
|
||||||
|
// @param name Header name.
|
||||||
|
// @param buffer String buffer to store value.
|
||||||
|
// @param maxlength Maximum length of the string buffer.
|
||||||
|
// @return True on success, false if the header was not found.
|
||||||
|
public native bool GetHeader(const char[] name, char[] buffer, int maxlength);
|
||||||
|
|
||||||
|
// Retrieves the JSON data of the response.
|
||||||
|
//
|
||||||
|
// @error Invalid JSON response.
|
||||||
|
property JSON Data {
|
||||||
|
public native get();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Retrieves the HTTP status of the response.
|
||||||
|
property HTTPStatus Status {
|
||||||
|
public native get();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Deprecated. Use HTTPRequest instead.
|
||||||
|
methodmap HTTPClient < Handle
|
||||||
|
{
|
||||||
|
// Creates an HTTP client.
|
||||||
|
//
|
||||||
|
// The HTTPClient must be freed via delete or CloseHandle().
|
||||||
|
//
|
||||||
|
// @param baseURL Base URL to the REST API.
|
||||||
|
#pragma deprecated Use HTTPRequest instead.
|
||||||
|
public native HTTPClient(const char[] baseURL);
|
||||||
|
|
||||||
|
// Sets an HTTP header to be used for all requests.
|
||||||
|
//
|
||||||
|
// @param name Header name.
|
||||||
|
// @param value String value to set.
|
||||||
|
#pragma deprecated Use HTTPRequest.SetHeader() instead.
|
||||||
|
public native void SetHeader(const char[] name, const char[] value);
|
||||||
|
|
||||||
|
// Performs an HTTP GET request.
|
||||||
|
//
|
||||||
|
// @param endpoint API endpoint to request.
|
||||||
|
// @param callback A function to use as a callback when the request has finished.
|
||||||
|
// @param value Optional value to pass to the callback function.
|
||||||
|
#pragma deprecated Use HTTPRequest.Get() instead.
|
||||||
|
public native void Get(const char[] endpoint, HTTPRequestCallback callback, any value = 0);
|
||||||
|
|
||||||
|
// Performs an HTTP POST request.
|
||||||
|
//
|
||||||
|
// @param endpoint API endpoint to request.
|
||||||
|
// @param data JSON data to send.
|
||||||
|
// @param callback A function to use as a callback when the request has finished.
|
||||||
|
// @param value Optional value to pass to the callback function.
|
||||||
|
#pragma deprecated Use HTTPRequest.Post() instead.
|
||||||
|
public native void Post(const char[] endpoint, JSON data, HTTPRequestCallback callback, any value = 0);
|
||||||
|
|
||||||
|
// Performs an HTTP PUT request.
|
||||||
|
//
|
||||||
|
// @param endpoint API endpoint to request.
|
||||||
|
// @param data JSON data to send.
|
||||||
|
// @param callback A function to use as a callback when the request has finished.
|
||||||
|
// @param value Optional value to pass to the callback function.
|
||||||
|
#pragma deprecated Use HTTPRequest.Put() instead.
|
||||||
|
public native void Put(const char[] endpoint, JSON data, HTTPRequestCallback callback, any value = 0);
|
||||||
|
|
||||||
|
// Performs an HTTP PATCH request.
|
||||||
|
//
|
||||||
|
// @param endpoint API endpoint to request.
|
||||||
|
// @param data JSON data to send.
|
||||||
|
// @param callback A function to use as a callback when the request has finished.
|
||||||
|
// @param value Optional value to pass to the callback function.
|
||||||
|
#pragma deprecated Use HTTPRequest.Patch() instead.
|
||||||
|
public native void Patch(const char[] endpoint, JSON data, HTTPRequestCallback callback, any value = 0);
|
||||||
|
|
||||||
|
// Performs an HTTP DELETE request.
|
||||||
|
//
|
||||||
|
// @param endpoint API endpoint to request.
|
||||||
|
// @param callback A function to use as a callback when the request has finished.
|
||||||
|
// @param value Optional value to pass to the callback function.
|
||||||
|
#pragma deprecated Use HTTPRequest.Delete() instead.
|
||||||
|
public native void Delete(const char[] endpoint, HTTPRequestCallback callback, any value = 0);
|
||||||
|
|
||||||
|
// Downloads a file.
|
||||||
|
//
|
||||||
|
// @param endpoint API endpoint to download from.
|
||||||
|
// @param path File path to write to.
|
||||||
|
// @param callback A function to use as a callback when the download has finished.
|
||||||
|
// @param value Optional value to pass to the callback function.
|
||||||
|
#pragma deprecated Use HTTPRequest.DownloadFile() instead.
|
||||||
|
public native void DownloadFile(const char[] endpoint, const char[] path, HTTPFileCallback callback, any value = 0);
|
||||||
|
|
||||||
|
// Uploads a file.
|
||||||
|
//
|
||||||
|
// This function performs an HTTP PUT request. The file contents are sent in the request body.
|
||||||
|
//
|
||||||
|
// @param endpoint API endpoint to upload to.
|
||||||
|
// @param path File path to read from.
|
||||||
|
// @param callback A function to use as a callback when the upload has finished.
|
||||||
|
// @param value Optional value to pass to the callback function.
|
||||||
|
#pragma deprecated Use HTTPRequest.UploadFile() instead.
|
||||||
|
public native void UploadFile(const char[] endpoint, const char[] path, HTTPFileCallback callback, any value = 0);
|
||||||
|
|
||||||
|
// Connect timeout in seconds. Defaults to 10.
|
||||||
|
#pragma deprecated Use HTTPRequest.ConnectTimeout instead.
|
||||||
|
property int ConnectTimeout {
|
||||||
|
public native get();
|
||||||
|
public native set(int connectTimeout);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Follow HTTP 3xx redirects. Defaults to true.
|
||||||
|
#pragma deprecated Use HTTPRequest.MaxRedirects instead.
|
||||||
|
property bool FollowLocation {
|
||||||
|
public native get();
|
||||||
|
public native set(bool followLocation);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Timeout in seconds. Defaults to 30.
|
||||||
|
#pragma deprecated Use HTTPRequest.Timeout instead.
|
||||||
|
property int Timeout {
|
||||||
|
public native get();
|
||||||
|
public native set(int timeout);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Maximum upload speed in bytes per second. Defaults to unlimited speed.
|
||||||
|
#pragma deprecated Use HTTPRequest.MaxSendSpeed instead.
|
||||||
|
property int MaxSendSpeed {
|
||||||
|
public native get();
|
||||||
|
public native set(int speed);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Maximum download speed in bytes per second. Defaults to unlimited speed.
|
||||||
|
#pragma deprecated Use HTTPRequest.MaxRecvSpeed instead.
|
||||||
|
property int MaxRecvSpeed {
|
||||||
|
public native get();
|
||||||
|
public native set(int speed);
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -0,0 +1,400 @@
|
|||||||
|
// Decoding flags
|
||||||
|
enum
|
||||||
|
{
|
||||||
|
JSON_REJECT_DUPLICATES = 0x1, /**< Error if any JSON object contains duplicate keys */
|
||||||
|
JSON_DISABLE_EOF_CHECK = 0x2, /**< Allow extra data after a valid JSON array or object */
|
||||||
|
JSON_DECODE_ANY = 0x4, /**< Decode any value */
|
||||||
|
JSON_DECODE_INT_AS_REAL = 0x8, /**< Interpret all numbers as floats */
|
||||||
|
JSON_ALLOW_NUL = 0x10 /**< Allow \u0000 escape inside string values */
|
||||||
|
};
|
||||||
|
|
||||||
|
// Encoding flags
|
||||||
|
enum
|
||||||
|
{
|
||||||
|
JSON_COMPACT = 0x20, /**< Compact representation */
|
||||||
|
JSON_ENSURE_ASCII = 0x40, /**< Escape all Unicode characters outside the ASCII range */
|
||||||
|
JSON_SORT_KEYS = 0x80, /**< Sort object keys */
|
||||||
|
JSON_ENCODE_ANY = 0x200, /**< Encode any value */
|
||||||
|
JSON_ESCAPE_SLASH = 0x400, /**< Escape / with \/ */
|
||||||
|
JSON_EMBED = 0x10000 /**< Omit opening and closing braces of the top-level object */
|
||||||
|
};
|
||||||
|
|
||||||
|
// Maximum indentation
|
||||||
|
static const int JSON_MAX_INDENT = 0x1F;
|
||||||
|
|
||||||
|
// Pretty-print the result, indenting with n spaces
|
||||||
|
stock int JSON_INDENT(int n)
|
||||||
|
{
|
||||||
|
return n & JSON_MAX_INDENT;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Output floats with at most n digits of precision
|
||||||
|
stock int JSON_REAL_PRECISION(int n)
|
||||||
|
{
|
||||||
|
return (n & 0x1F) << 11;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Generic type for encoding JSON.
|
||||||
|
methodmap JSON < Handle
|
||||||
|
{
|
||||||
|
// Writes the JSON string representation to a file.
|
||||||
|
//
|
||||||
|
// @param file File to write to.
|
||||||
|
// @param flags Encoding flags.
|
||||||
|
// @return True on success, false on failure.
|
||||||
|
public native bool ToFile(const char[] file, int flags = 0);
|
||||||
|
|
||||||
|
// Retrieves the JSON string representation.
|
||||||
|
//
|
||||||
|
// @param buffer String buffer to write to.
|
||||||
|
// @param maxlength Maximum length of the string buffer.
|
||||||
|
// @param flags Encoding flags.
|
||||||
|
// @return True on success, false on failure.
|
||||||
|
public native bool ToString(char[] buffer, int maxlength, int flags = 0);
|
||||||
|
};
|
||||||
|
|
||||||
|
methodmap JSONObject < JSON
|
||||||
|
{
|
||||||
|
// Creates a JSON object. A JSON object maps strings (called "keys") to values. Keys in a
|
||||||
|
// JSON object are unique. That is, there is at most one entry in the map for a given key.
|
||||||
|
//
|
||||||
|
// The JSONObject must be freed via delete or CloseHandle().
|
||||||
|
public native JSONObject();
|
||||||
|
|
||||||
|
// Loads a JSON object from a file.
|
||||||
|
//
|
||||||
|
// @param file File to read from.
|
||||||
|
// @param flags Decoding flags.
|
||||||
|
// @return Object handle, or null on failure.
|
||||||
|
// @error Invalid JSON.
|
||||||
|
public static native JSONObject FromFile(const char[] file, int flags = 0);
|
||||||
|
|
||||||
|
// Loads a JSON object from a string.
|
||||||
|
//
|
||||||
|
// @param buffer String buffer to load into the JSON object.
|
||||||
|
// @param flags Decoding flags.
|
||||||
|
// @return Object handle, or null on failure.
|
||||||
|
// @error Invalid JSON.
|
||||||
|
public static native JSONObject FromString(const char[] buffer, int flags = 0);
|
||||||
|
|
||||||
|
// Retrieves an array or object value from the object.
|
||||||
|
//
|
||||||
|
// The JSON must be freed via delete or CloseHandle().
|
||||||
|
//
|
||||||
|
// @param key Key string.
|
||||||
|
// @return Value read.
|
||||||
|
// @error Invalid key.
|
||||||
|
public native JSON Get(const char[] key);
|
||||||
|
|
||||||
|
// Retrieves a boolean value from the object.
|
||||||
|
//
|
||||||
|
// @param key Key string.
|
||||||
|
// @return Value read.
|
||||||
|
// @error Invalid key.
|
||||||
|
public native bool GetBool(const char[] key);
|
||||||
|
|
||||||
|
// Retrieves a float value from the object.
|
||||||
|
//
|
||||||
|
// @param key Key string.
|
||||||
|
// @return Value read.
|
||||||
|
// @error Invalid key.
|
||||||
|
public native float GetFloat(const char[] key);
|
||||||
|
|
||||||
|
// Retrieves an integer value from the object.
|
||||||
|
//
|
||||||
|
// @param key Key string.
|
||||||
|
// @return Value read.
|
||||||
|
// @error Invalid key.
|
||||||
|
public native int GetInt(const char[] key);
|
||||||
|
|
||||||
|
// Retrieves a 64-bit integer value from the object.
|
||||||
|
//
|
||||||
|
// @param key Key string.
|
||||||
|
// @param buffer String buffer to store value.
|
||||||
|
// @param maxlength Maximum length of the string buffer.
|
||||||
|
// @return True on success, false if the key was not found.
|
||||||
|
public native bool GetInt64(const char[] key, char[] buffer, int maxlength);
|
||||||
|
|
||||||
|
// Retrieves a string value from the object.
|
||||||
|
//
|
||||||
|
// @param key Key string.
|
||||||
|
// @param buffer String buffer to store value.
|
||||||
|
// @param maxlength Maximum length of the string buffer.
|
||||||
|
// @return True on success. False if the key was not found, or the value is not a string.
|
||||||
|
public native bool GetString(const char[] key, char[] buffer, int maxlength);
|
||||||
|
|
||||||
|
// Returns whether or not a value in the object is null.
|
||||||
|
//
|
||||||
|
// @param key Key string.
|
||||||
|
// @return True if the value is null, false otherwise.
|
||||||
|
// @error Invalid key.
|
||||||
|
public native bool IsNull(const char[] key);
|
||||||
|
|
||||||
|
// Returns whether or not a key exists in the object.
|
||||||
|
//
|
||||||
|
// @param key Key string.
|
||||||
|
// @return True if the key exists, false otherwise.
|
||||||
|
public native bool HasKey(const char[] key);
|
||||||
|
|
||||||
|
// Sets an array or object value in the object, either inserting a new entry or replacing an old one.
|
||||||
|
//
|
||||||
|
// @param key Key string.
|
||||||
|
// @param value Value to store at this key.
|
||||||
|
// @return True on success, false on failure.
|
||||||
|
public native bool Set(const char[] key, JSON value);
|
||||||
|
|
||||||
|
// Sets a boolean value in the object, either inserting a new entry or replacing an old one.
|
||||||
|
//
|
||||||
|
// @param key Key string.
|
||||||
|
// @param value Value to store at this key.
|
||||||
|
// @return True on success, false on failure.
|
||||||
|
public native bool SetBool(const char[] key, bool value);
|
||||||
|
|
||||||
|
// Sets a float value in the object, either inserting a new entry or replacing an old one.
|
||||||
|
//
|
||||||
|
// @param key Key string.
|
||||||
|
// @param value Value to store at this key.
|
||||||
|
// @return True on success, false on failure.
|
||||||
|
public native bool SetFloat(const char[] key, float value);
|
||||||
|
|
||||||
|
// Sets an integer value in the object, either inserting a new entry or replacing an old one.
|
||||||
|
//
|
||||||
|
// @param key Key string.
|
||||||
|
// @param value Value to store at this key.
|
||||||
|
// @return True on success, false on failure.
|
||||||
|
public native bool SetInt(const char[] key, int value);
|
||||||
|
|
||||||
|
// Sets a 64-bit integer value in the object, either inserting a new entry or replacing an old one.
|
||||||
|
//
|
||||||
|
// @param key Key string.
|
||||||
|
// @param value Value to store at this key.
|
||||||
|
// @return True on success, false on failure.
|
||||||
|
public native bool SetInt64(const char[] key, const char[] value);
|
||||||
|
|
||||||
|
// Sets a null value in the object, either inserting a new entry or replacing an old one.
|
||||||
|
//
|
||||||
|
// @param key Key string.
|
||||||
|
// @return True on success, false on failure.
|
||||||
|
public native bool SetNull(const char[] key);
|
||||||
|
|
||||||
|
// Sets a string value in the object, either inserting a new entry or replacing an old one.
|
||||||
|
//
|
||||||
|
// @param key Key string.
|
||||||
|
// @param value Value to store at this key.
|
||||||
|
// @return True on success, false on failure.
|
||||||
|
public native bool SetString(const char[] key, const char[] value);
|
||||||
|
|
||||||
|
// Removes an entry from the object.
|
||||||
|
//
|
||||||
|
// @param key Key string.
|
||||||
|
// @return True on success, false if the key was not found.
|
||||||
|
public native bool Remove(const char[] key);
|
||||||
|
|
||||||
|
// Clears the object of all entries.
|
||||||
|
// @return True on success, false on failure.
|
||||||
|
public native bool Clear();
|
||||||
|
|
||||||
|
// Returns an iterator for the object's keys. See JSONObjectKeys.
|
||||||
|
public native JSONObjectKeys Keys();
|
||||||
|
|
||||||
|
// Retrieves the size of the object.
|
||||||
|
property int Size {
|
||||||
|
public native get();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A JSONObjectKeys is created via JSONObject.Keys(). It allows the keys of an
|
||||||
|
* object to be iterated. The JSONObjectKeys must be freed with delete or
|
||||||
|
* CloseHandle().
|
||||||
|
*/
|
||||||
|
methodmap JSONObjectKeys < Handle
|
||||||
|
{
|
||||||
|
// Reads an object key, then advances to the next key if any.
|
||||||
|
//
|
||||||
|
// @param buffer String buffer to store key.
|
||||||
|
// @param maxlength Maximum length of the string buffer.
|
||||||
|
// @return True on success, false if there are no more keys.
|
||||||
|
public native bool ReadKey(char[] buffer, int maxlength);
|
||||||
|
};
|
||||||
|
|
||||||
|
methodmap JSONArray < JSON
|
||||||
|
{
|
||||||
|
// Creates a JSON array.
|
||||||
|
//
|
||||||
|
// The JSONArray must be freed via delete or CloseHandle().
|
||||||
|
public native JSONArray();
|
||||||
|
|
||||||
|
// Loads a JSON array from a file.
|
||||||
|
//
|
||||||
|
// @param file File to read from.
|
||||||
|
// @param flags Decoding flags.
|
||||||
|
// @return Array handle, or null on failure.
|
||||||
|
// @error Invalid JSON.
|
||||||
|
public static native JSONArray FromFile(const char[] file, int flags = 0);
|
||||||
|
|
||||||
|
// Loads a JSON array from a string.
|
||||||
|
//
|
||||||
|
// @param buffer String buffer to load into the JSON array.
|
||||||
|
// @param flags Decoding flags.
|
||||||
|
// @return Array handle, or null on failure.
|
||||||
|
// @error Invalid JSON.
|
||||||
|
public static native JSONArray FromString(const char[] buffer, int flags = 0);
|
||||||
|
|
||||||
|
// Retrieves an array or object value from the array.
|
||||||
|
//
|
||||||
|
// The JSON must be freed via delete or CloseHandle().
|
||||||
|
//
|
||||||
|
// @param index Index in the array.
|
||||||
|
// @return Value read.
|
||||||
|
// @error Invalid index.
|
||||||
|
public native JSON Get(int index);
|
||||||
|
|
||||||
|
// Retrieves a boolean value from the array.
|
||||||
|
//
|
||||||
|
// @param index Index in the array.
|
||||||
|
// @return Value read.
|
||||||
|
// @error Invalid index.
|
||||||
|
public native bool GetBool(int index);
|
||||||
|
|
||||||
|
// Retrieves a float value from the array.
|
||||||
|
//
|
||||||
|
// @param index Index in the array.
|
||||||
|
// @return Value read.
|
||||||
|
// @error Invalid index.
|
||||||
|
public native float GetFloat(int index);
|
||||||
|
|
||||||
|
// Retrieves an integer value from the array.
|
||||||
|
//
|
||||||
|
// @param index Index in the array.
|
||||||
|
// @return Value read.
|
||||||
|
// @error Invalid index.
|
||||||
|
public native int GetInt(int index);
|
||||||
|
|
||||||
|
// Retrieves an 64-bit integer value from the array.
|
||||||
|
//
|
||||||
|
// @param index Index in the array.
|
||||||
|
// @param buffer Buffer to copy to.
|
||||||
|
// @param maxlength Maximum size of the buffer.
|
||||||
|
// @error Invalid index.
|
||||||
|
public native void GetInt64(int index, char[] buffer, int maxlength);
|
||||||
|
|
||||||
|
// Retrieves a string value from the array.
|
||||||
|
//
|
||||||
|
// @param index Index in the array.
|
||||||
|
// @param buffer Buffer to copy to.
|
||||||
|
// @param maxlength Maximum size of the buffer.
|
||||||
|
// @return True on success, false if the value is not a string.
|
||||||
|
// @error Invalid index.
|
||||||
|
public native bool GetString(int index, char[] buffer, int maxlength);
|
||||||
|
|
||||||
|
// Returns whether or not a value in the array is null.
|
||||||
|
//
|
||||||
|
// @param index Index in the array.
|
||||||
|
// @return True if the value is null, false otherwise.
|
||||||
|
// @error Invalid index.
|
||||||
|
public native bool IsNull(int index);
|
||||||
|
|
||||||
|
// Sets an array or object value in the array.
|
||||||
|
//
|
||||||
|
// @param index Index in the array.
|
||||||
|
// @param value Value to set.
|
||||||
|
// @return True on success, false on failure.
|
||||||
|
public native bool Set(int index, JSON value);
|
||||||
|
|
||||||
|
// Sets a boolean value in the array.
|
||||||
|
//
|
||||||
|
// @param index Index in the array.
|
||||||
|
// @param value Value to set.
|
||||||
|
// @return True on success, false on failure.
|
||||||
|
public native bool SetBool(int index, bool value);
|
||||||
|
|
||||||
|
// Sets a float value in the array.
|
||||||
|
//
|
||||||
|
// @param index Index in the array.
|
||||||
|
// @param value Value to set.
|
||||||
|
// @return True on success, false on failure.
|
||||||
|
public native bool SetFloat(int index, float value);
|
||||||
|
|
||||||
|
// Sets an integer value in the array.
|
||||||
|
//
|
||||||
|
// @param index Index in the array.
|
||||||
|
// @param value Value to set.
|
||||||
|
// @return True on success, false on failure.
|
||||||
|
public native bool SetInt(int index, int value);
|
||||||
|
|
||||||
|
// Sets a 64 bit integer value in the array.
|
||||||
|
//
|
||||||
|
// @param index Index in the array.
|
||||||
|
// @param value 64-bit integer value to set.
|
||||||
|
// @return True on success, false on failure.
|
||||||
|
public native bool SetInt64(int index, const char[] value);
|
||||||
|
|
||||||
|
// Sets a null value in the array.
|
||||||
|
//
|
||||||
|
// @param index Index in the array.
|
||||||
|
// @return True on success, false on failure.
|
||||||
|
public native bool SetNull(int index);
|
||||||
|
|
||||||
|
// Sets a string value in the array.
|
||||||
|
//
|
||||||
|
// @param index Index in the array.
|
||||||
|
// @param value String value to set.
|
||||||
|
// @return True on success, false on failure.
|
||||||
|
public native bool SetString(int index, const char[] value);
|
||||||
|
|
||||||
|
// Pushes an array or object value onto the end of the array, adding a new index.
|
||||||
|
//
|
||||||
|
// @param value Value to push.
|
||||||
|
// @return True on success, false on failure.
|
||||||
|
public native bool Push(JSON value);
|
||||||
|
|
||||||
|
// Pushes a boolean value onto the end of the array, adding a new index.
|
||||||
|
//
|
||||||
|
// @param value Value to push.
|
||||||
|
// @return True on success, false on failure.
|
||||||
|
public native bool PushBool(bool value);
|
||||||
|
|
||||||
|
// Pushes a float value onto the end of the array, adding a new index.
|
||||||
|
//
|
||||||
|
// @param value Value to push.
|
||||||
|
// @return True on success, false on failure.
|
||||||
|
public native bool PushFloat(float value);
|
||||||
|
|
||||||
|
// Pushes an integer value onto the end of the array, adding a new index.
|
||||||
|
//
|
||||||
|
// @param value Value to push.
|
||||||
|
// @return True on success, false on failure.
|
||||||
|
public native bool PushInt(int value);
|
||||||
|
|
||||||
|
// Pushes a 64-bit integer value onto the end of the array, adding a new index.
|
||||||
|
//
|
||||||
|
// @param value 64-bit integer value to push.
|
||||||
|
// @return True on success, false on failure.
|
||||||
|
public native bool PushInt64(const char[] value);
|
||||||
|
|
||||||
|
// Pushes a null value onto the end of the array, adding a new index.
|
||||||
|
// @return True on success, false on failure.
|
||||||
|
public native bool PushNull();
|
||||||
|
|
||||||
|
// Pushes a string value onto the end of the array, adding a new index.
|
||||||
|
//
|
||||||
|
// @param value String value to push.
|
||||||
|
// @return True on success, false on failure.
|
||||||
|
public native bool PushString(const char[] value);
|
||||||
|
|
||||||
|
// Removes an entry from the array.
|
||||||
|
//
|
||||||
|
// @param index Index in the array to remove.
|
||||||
|
// @return True on success, false on invalid index.
|
||||||
|
public native bool Remove(int index);
|
||||||
|
|
||||||
|
// Clears the array of all entries.
|
||||||
|
// @return True on success, false on failure.
|
||||||
|
public native bool Clear();
|
||||||
|
|
||||||
|
// Retrieves the size of the array.
|
||||||
|
property int Length {
|
||||||
|
public native get();
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
#if defined _unloze_playtime_included_
|
||||||
|
#endinput
|
||||||
|
#endif
|
||||||
|
#define _unloze_playtime_included_
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @returns the average playtime of all connected players excluding autism bots, fakeclients, AFKS and nosteamers
|
||||||
|
*/
|
||||||
|
native int GetAveragePlayerTimeOnServer();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @returns the players rtv amount boost
|
||||||
|
*/
|
||||||
|
native int GetPlayerWorthRTV_boost_(int client);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* returns a players hours for a specific server
|
||||||
|
*
|
||||||
|
* @int the actual client
|
||||||
|
* @int Game time hours that the client has on the server.
|
||||||
|
* @int Game time minutes the client has on the server.
|
||||||
|
*/
|
||||||
|
|
||||||
|
native int GetPlayerTier_native(int client); //just the clients tier
|
||||||
|
forward void GetPlayerHoursServer(int client, int hours, int minutes);
|
||||||
|
forward void GetPlayerTier(int client, int tier);
|
||||||
Reference in New Issue
Block a user