66#pragma semicolon 1
77#pragma newdecls required
88
9- #define PLUGIN_VERSION " 23w31a "
9+ #define PLUGIN_VERSION " 23w31b "
1010
1111#define STR_NO_PROFILE " None"
1212#define STR_PERSONAL " Personal"
@@ -63,14 +63,12 @@ public void OnPluginStart() {
6363 SetCookieMenuItem (ChatTagCookieMenu , 0 , " Chat Tag Settings" );
6464
6565 cvar_settingsMenuEnabled = CreateConVar (" chattag_menu_enabled" , " 1" , " 0=Disable the /settings menu, 1=Enable" , _ , true , 0.0 , true , 1.0 );
66- cvar_settingsMenuEnabled = CreateConVar (" chattag_load_behaviour" , " 2" , " What to do when a client connects. 0=Use last active profil, 1=Use forst matching profile, 2=Like 1 if available profiles changed" , _ , true , 0.0 , true , 2.0 );
66+ cvar_loadBehaviour = CreateConVar (" chattag_load_behaviour" , " 2" , " What to do when a client connects. 0=Use last active profil, 1=Use forst matching profile, 2=Like 1 if available profiles changed" , _ , true , 0.0 , true , 2.0 );
6767
6868 RegAdminCmd (" sm_reloadchattags" , Cmd_Reload , ADMFLAG_CONFIG , " Reload chat tags" );
6969
7070 for (int client = 1 ;client <= MaxClients ;client ++ ) {
71- if (IsClientInGame (client ) && ! IsFakeClient (client ) && ! IsClientReplay (client ) && ! IsClientSourceTV (client ) && IsClientAuthorized (client )) {
72- OnClientAuthorized (client , " " );
73- }
71+ OnClientPostAdminCheck (client );
7472 }
7573}
7674
@@ -80,28 +78,26 @@ public void ChatTagCookieMenu(int client, CookieMenuAction action, any info, cha
8078 }
8179}
8280
83- public Action Cmd_Reload (int admin , int args )
84- {
81+ public Action Cmd_Reload (int admin , int args ) {
8582 LoadConfig ();
8683 for (int client = 1 ;client <= MaxClients ;client ++ ) {
87- if (IsClientInGame (client ) && ! IsFakeClient (client ) && ! IsClientReplay (client ) && ! IsClientSourceTV (client ) && IsClientAuthorized (client )) {
88- OnClientAuthorized (client , " " );
89- }
84+ OnClientPostAdminCheck (client );
9085 }
9186 ReplyToCommand (admin , " [ChatTag] Reloaded %d profiles" , profiles .Length );
9287 return Plugin_Handled ;
9388}
9489
95-
96- public void OnClientAuthorized (int client , const char [] auth ) {
90+ public void OnClientPostAdminCheck (int client ) {
91+ if (! IsClientInGame (client ) || IsFakeClient (client ) || IsClientReplay (client ) || IsClientSourceTV (client ) || ! IsClientAuthorized (client ))
92+ return ;
93+
9794 char tmp [32 ];
98- bool refresh ;
9995 ArrayList list = FindApplicableProfiles (client );
10096
10197 //check profile hash
10298 // // make crc16
10399 int crc ;
104- for (int i ; i <= list .Length ; i ++ ) {
100+ for (int i ; i < list .Length ; i ++ ) {
105101 list .GetString (i , tmp , sizeof (tmp ));
106102 for (int c ; tmp [c ] != 0 ; c += 2 ) {
107103 crc += (tmp [c ]<< 8 )| (tmp [c + 1 ]);
@@ -119,11 +115,14 @@ public void OnClientAuthorized(int client, const char[] auth) {
119115 cvar_loadBehaviour .GetString (tmp , sizeof (tmp ));
120116 int load = StringToInt (tmp );
121117 // // should we refresh?
122- refresh |= ((crc != oldCrc && load == 2 ) || load == 1 );
118+ bool refresh = ((crc != oldCrc && load == 2 ) || load == 1 );
119+
120+ PrintToServer (" [ChatTag] %N %s (%04X -> %04X )" , client , refresh ? " Refresh" : " Keep" , oldCrc , crc );
123121
124122 //if profile should refresh, pick the first match and save
125123 if (refresh && list .Length > 0 ) {
126124 list .GetString (0 , tmp , sizeof (tmp ));
125+ PrintToServer (" [ChatTag] %N active profile now %s " , client , tmp );
127126 mcpct_profile .Set (client , tmp );
128127 mcpct_style .Set (client , " 15" );
129128 }
@@ -147,11 +146,14 @@ void LoadConfig() {
147146 ChatStyle style ;
148147 if (kv .GotoFirstSubKey ()) {
149148 do {
149+ bool isPersonal ;
150150 kv .GetSectionName (buffer , sizeof (buffer ));
151151 if (strncmp (buffer ," STEAM_" ,6 )== 0 || buffer [0 ]== ' [' ) {
152+ isPersonal = true ;
152153 strcopy (style .filter , sizeof (ChatStyle ::filter ), buffer );
153154 style .name = STR_PERSONAL ;
154155 } else {
156+ isPersonal = false ;
155157 kv .GetString (" flag" , style .filter , sizeof (ChatStyle ::filter ), " " );
156158 strcopy (style .name , sizeof (ChatStyle ::name ), buffer );
157159 }
@@ -169,7 +171,14 @@ void LoadConfig() {
169171 kv .GetString (" textcolor" , buffer , sizeof (buffer ), " \x01 " );
170172 TranslateColor (buffer , sizeof (buffer ));
171173 strcopy (style .chat , sizeof (ChatStyle ::chat ), buffer );
172- profiles .PushArray (style );
174+ if (isPersonal ) {
175+ //insert front
176+ profiles .ShiftUp (0 );
177+ profiles .SetArray (0 , style );
178+ } else {
179+ //push back
180+ profiles .PushArray (style );
181+ }
173182 } while (kv .GotoNextKey ());
174183 }
175184
@@ -196,10 +205,11 @@ bool UpdateProfile(int client) {
196205 ChatStyle prof ;
197206 for (int i = profiles .Length - 1 ; i >= 0 ; i -- ) {
198207 profiles .GetArray (i ,prof );
199- if (StrEqual (prof .name , name , false )) {
208+ if ( StrEqual (prof .name , name , false ) ||
209+ (StrEqual (STR_PERSONAL , name ) && (prof .filter [0 ]== ' [' || strncmp (prof .filter , " STEAM_" , 6 )== 0 )) ) {
200210
201211 // can we still use this group?
202- if (! HasPermission (client , prof .filter )) break ;
212+ if (! HasPermission (client , prof .filter )) continue ;
203213
204214 prof .apply (client , style );
205215 return true ;
@@ -210,8 +220,9 @@ bool UpdateProfile(int client) {
210220}
211221
212222void ProcessTagStyle (char [] tag , int taglen , ChatStyleOptions style ) {
223+ PrintToServer (" [ChatTag] Style: %X " , style );
213224 char tagcopy [MCP_MAXLENGTH_NAME ];
214- if (style != CS_NONE ) {
225+ if (( style & CS_PREFIX ) != CS_NONE ) {
215226 strcopy (tagcopy , sizeof (tagcopy ), tag );
216227 if ((style & CS_TAGTEXT )== CS_NONE ) style &=~ CS_TAGCOLOR ; //no point w/o text
217228 switch (style & CS_PREFIX ) {
@@ -274,7 +285,8 @@ ArrayList FindApplicableProfiles(int client) {
274285 return applicable ;
275286 }
276287 ChatStyle prof ;
277- for (int i = profiles .Length - 1 ; i >= 0 ; i -- ) {
288+ int max = profiles .Length ;
289+ for (int i ; i < max ; i ++ ) {
278290 profiles .GetArray (i ,prof );
279291
280292 // can we use this group?
@@ -414,7 +426,7 @@ void ShowChatTagProfileMenu(int client, int page=1) {
414426 int at = choices .FindString (STR_PERSONAL );
415427 if (at >= 0 ) {
416428 choices .Erase (at );
417- if (StrEqual (STR_NO_PROFILE , active )) {
429+ if (StrEqual (STR_PERSONAL , active )) {
418430 FormatEx (buffer , sizeof (buffer ), " [%s ]" , STR_PERSONAL );
419431 menu .AddItem (STR_PERSONAL , buffer , ITEMDRAW_DISABLED );
420432 } else {
0 commit comments