@@ -34,10 +34,12 @@ ArrayList profiles;
3434
3535Cookie mcpct_style ; //what to color
3636Cookie mcpct_profile ; //profile name
37+ Cookie mcpct_crc ; //if the crc changes, we have a new profile
3738
3839GlobalForward mcpct_fwd_change ;
3940
4041ConVar cvar_settingsMenuEnabled ;
42+ ConVar cvar_loadBehaviour ;
4143
4244public APLRes AskPluginLoad2 (Handle myself , bool late , char [] error , int err_max )
4345{
@@ -54,12 +56,14 @@ public void OnPluginStart() {
5456
5557 mcpct_style = new Cookie (" mcpchattag_style" , " Style of MCP Chat Tag" , CookieAccess_Private );
5658 mcpct_profile = new Cookie (" mcpchattag_profile" , " Style of MCP Chat Tag" , CookieAccess_Private );
59+ mcpct_crc = new Cookie (" mcpchattag_checksum" , " CRC of available profiles to detect changes" , CookieAccess_Private );
5760
5861 mcpct_fwd_change = CreateGlobalForward (" MCP_CT_OnProfileChanged" , ET_Event , Param_Cell , Param_String , Param_String , Param_String , Param_CellByRef );
5962
6063 SetCookieMenuItem (ChatTagCookieMenu , 0 , " Chat Tag Settings" );
6164
6265 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 );
6367
6468 RegAdminCmd (" sm_reloadchattags" , Cmd_Reload , ADMFLAG_CONFIG , " Reload chat tags" );
6569
@@ -91,16 +95,39 @@ public Action Cmd_Reload(int admin, int args)
9195
9296public void OnClientAuthorized (int client , const char [] auth ) {
9397 char tmp [32 ];
94- cvar_settingsMenuEnabled .GetString (tmp , sizeof (tmp ));
95- if (StringToInt (tmp )== 0 ) {
96- ArrayList list = FindApplicableProfiles (client );
97- if (list .Length > 0 ) {
98- list .GetString (0 , tmp , sizeof (tmp ));
99- mcpct_profile .Set (client , tmp );
100- mcpct_style .Set (client , " 15" );
98+ bool refresh ;
99+ ArrayList list = FindApplicableProfiles (client );
100+
101+ //check profile hash
102+ // // make crc16
103+ int crc ;
104+ for (int i ; i <= list .Length ; i ++ ) {
105+ list .GetString (i , tmp , sizeof (tmp ));
106+ for (int c ; tmp [c ] != 0 ; c += 2 ) {
107+ crc += (tmp [c ]<< 8 )| (tmp [c + 1 ]);
108+ if ((crc & 0x10000 )!= 0 ) crc = (crc & 0xffff )+ 1 ;
109+ if (tmp [c + 1 ]== 0 ) break ; //next loop would be oob
101110 }
102- delete list ;
103111 }
112+ // // get old hash
113+ mcpct_crc .Get (client , tmp , sizeof (tmp ));
114+ int oldCrc = StringToInt (tmp ,16 );
115+ // // store new hash
116+ FormatEx (tmp , sizeof (tmp ), " %04X " , crc );
117+ mcpct_crc .Set (client , tmp );
118+ // // get load behaviour
119+ cvar_loadBehaviour .GetString (tmp , sizeof (tmp ));
120+ int load = StringToInt (tmp );
121+ // // should we refresh?
122+ refresh |= ((crc != oldCrc && load == 2 ) || load == 1 );
123+
124+ //if profile should refresh, pick the first match and save
125+ if (refresh && list .Length > 0 ) {
126+ list .GetString (0 , tmp , sizeof (tmp ));
127+ mcpct_profile .Set (client , tmp );
128+ mcpct_style .Set (client , " 15" );
129+ }
130+ delete list ;
104131 UpdateProfile (client );
105132}
106133
@@ -395,8 +422,8 @@ void ShowChatTagProfileMenu(int client, int page=1) {
395422 }
396423 }
397424
398- choices .Sort ( Sort_Descending , Sort_String ) ;
399- for (int i = choices . Length - 1 ; i >= 0 ; i -- ) {
425+ int max = choices .Length ;
426+ for (int i = 0 ; i < max ; i += 1 ) {
400427 choices .GetString (i , name , sizeof (name ));
401428 if (StrEqual (name , active )) {
402429 FormatEx (buffer , sizeof (buffer ), " [%s ]" , name );
0 commit comments