liquidrock

DayZ Chat Notifications (requires CF)

Mar 19th, 2021
471
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.68 KB | None | 0 0
  1. modded class Chat
  2. {
  3.     private autoptr TStringArray m_SystemMessages = {};
  4.     private autoptr TStringArray m_AdminMessages = {};
  5.     private autoptr TStringArray m_BEMessages = {};
  6.     private ref Timer m_SystemMessagesTimer;
  7.     private ref Timer m_AdminMessagesTimer;
  8.     private ref Timer m_BEMessagesTimer;
  9.  
  10.     override void AddInternal( ChatMessageEventParams params )
  11.     {
  12.         int messageChannel = params.param1;
  13.         string messageFrom = params.param2;
  14.         string messageText = params.param3;
  15.  
  16.         //Print( "[ChatNotifications] Chat::AddInternal messageChannel=" + messageChannel + " messageFrom=" + messageFrom + " messageText=" + messageText );
  17.  
  18.         if ( ( messageFrom == "" && messageText.IndexOf( "[ZomBerry]" ) == 0 ) || !GetGame() || !GetGame().GetPlayer() )
  19.         {
  20.             string channel_name;
  21.             /*!
  22.                 channel type, possible values
  23.                 CCSystem(1)
  24.                 CCAdmin(2)
  25.                 CCDirect(4)
  26.                 CCMegaphone(8)
  27.                 CCTransmitter(16)
  28.                 CCPublicAddressSystem(32)
  29.                 CCBattlEye(64)
  30.             */
  31.             switch ( messageChannel )
  32.             {
  33.                 case CCSystem:
  34.                     channel_name = "CCSystem";
  35.                     break;
  36.                 case CCAdmin:
  37.                     channel_name = "CCAdmin";
  38.                     break;
  39.                 case CCDirect:
  40.                     channel_name = "CCDirect";
  41.                     break;
  42.                 case CCMegaphone:
  43.                     channel_name = "CCMegaphone";
  44.                     break;
  45.                 case CCTransmitter:
  46.                     channel_name = "CCTransmitter";
  47.                     break;
  48.                 case CCPublicAddressSystem:
  49.                     channel_name = "CCPublicAddressSystem";
  50.                     break;
  51.                 case CCBattlEye:  // Same as ExpansionChatChannels.CCTransport
  52.                     channel_name = "CCBattlEye";
  53.                     break;
  54.             }
  55.             Print( "[ChatNotifications] Chat::AddInternal -> super.AddInternal channel=" + channel_name + " from=" + messageFrom + " text=" + messageText );
  56.             super.AddInternal( params );
  57.             return;
  58.         }
  59.  
  60.         switch ( messageChannel )
  61.         {
  62.             case CCSystem:
  63.                 Print( "[ChatNotifications] Channel=CCSystem" );
  64.                 m_SystemMessages.Insert( messageText );
  65.                 if ( !m_SystemMessagesTimer || !m_SystemMessagesTimer.IsRunning() )
  66.                 {
  67.                     Print( "[ChatNotifications] Channel=CCSystem Timer" );
  68.                     m_SystemMessagesTimer   = new Timer( CALL_CATEGORY_GUI );
  69.                     m_SystemMessagesTimer.Run( 0.1, this, "CreateCollectedMessagesNotification", new Param3<string, TStringArray, int>( "Server", m_SystemMessages, ARGB( 255, 52, 152, 219 ) ) );
  70.                 }
  71.                 break;
  72.             case CCAdmin:
  73.                 Print( "[ChatNotifications] Channel=CCAdmin" );
  74.                 m_AdminMessages.Insert( messageText );
  75.                 if ( !m_AdminMessagesTimer || !m_AdminMessagesTimer.IsRunning() )
  76.                 {
  77.                     Print( "[ChatNotifications] Channel=CCAdmin Timer" );
  78.                     m_AdminMessagesTimer    = new Timer( CALL_CATEGORY_GUI );
  79.                     m_AdminMessagesTimer.Run( 0.1, this, "CreateCollectedMessagesNotification", new Param3<string, TStringArray, int>( "Admin", m_AdminMessages, ARGB(255, 192, 57, 43) ) );
  80.                 }
  81.                 break;
  82.             case CCBattlEye:  // Same as ExpansionChatChannels.CCTransport so we need to check
  83.                 Print( "[ChatNotifications] Channel=CCBattlEye" );
  84.                 if ( messageFrom == "BattlEye" && messageText.IndexOf( "(Global) Admin: " ) == 0 )
  85.                 {
  86.                     Print( "[ChatNotifications] Channel=CCBattlEye Admin" );
  87.                     m_BEMessages.Insert( messageText.Substring( 16, messageText.Length() - 16 ) );
  88.                     if ( !m_BEMessagesTimer || !m_BEMessagesTimer.IsRunning() )
  89.                     {
  90.                         Print( "[ChatNotifications] Channel=CCBattlEye Timer" );
  91.                         m_BEMessagesTimer   = new Timer( CALL_CATEGORY_GUI );
  92.                         m_BEMessagesTimer.Run( 0.1, this, "CreateCollectedMessagesNotification", new Param3<string, TStringArray, int>( "Remote Console", m_BEMessages, ARGB(255, 192, 57, 43) ) );
  93.                     }
  94.                     break;
  95.                 }
  96.             default:
  97.                 //Print( "[ChatNotifications] Chat::AddInternal -> super.AddInternal" );
  98.                 super.AddInternal( params );
  99.                 break;
  100.         }
  101.     }
  102.  
  103.     void CreateCollectedMessagesNotification( string title, TStringArray messages, int color )
  104.     {
  105.         string previousTitle;
  106.         string messageText;
  107.  
  108.         for ( int i = 0; i < messages.Count(); i++ )
  109.         {
  110.             string message = messages[i];
  111.             int idx = message.IndexOf( ":" );
  112.             if ( idx > -1 )
  113.             {
  114.                 string prefix = message.Substring( 0, idx );
  115.                 if ( ( !prefix.Contains( " " ) || prefix.Length() < 24 ) && ( i == 0 || prefix == previousTitle ) )
  116.                 {
  117.                     title = prefix;
  118.                     previousTitle = title;
  119.                     message = message.Substring( idx + 1, message.Length() - idx - 1 ).Trim();
  120.                 }
  121.             }
  122.             messageText += message + "\n";
  123.         }
  124.  
  125.         messages.Clear();
  126.  
  127.         if ( !GetGame() || !GetGame().GetPlayer() )
  128.         {
  129.             Print( "[ChatNotifications] Chat::CreateCollectedMessagesNotification -> super.AddInternal title=" + title + " messageText=" + messageText );
  130.             int channel = CCSystem;
  131.             switch ( title )
  132.             {
  133.                 case "Server":
  134.                     channel = CCSystem;
  135.                     break;
  136.                 case "Admin":
  137.                     channel = CCAdmin;
  138.                     break;
  139.                 case "Remote Console":
  140.                     channel = CCBattlEye;
  141.                     break;
  142.             }
  143.             ChatMessageEventParams params = new ChatMessageEventParams( channel, "", messageText, "" );
  144.             super.AddInternal( params );
  145.         }
  146.         else
  147.         {
  148.             Print( "[ChatNotifications] Chat::CreateCollectedMessagesNotification title=" + title + " messageText=" + messageText );
  149.             title.Replace( "%", "%%" );
  150.             messageText.Replace( "%", "%%" );
  151.             StringLocaliser locTitle = new StringLocaliser( title );
  152.             StringLocaliser locMessageText = new StringLocaliser( messageText );
  153.             locTitle.SetTranslates( false );
  154.             locMessageText.SetTranslates( false );
  155.             #ifdef EXPANSIONMOD
  156.             string icon = EXPANSION_NOTIFICATION_ICON_INFO;
  157.             #else
  158.             string icon;
  159.             #endif
  160.             //GetNotificationSystem().CreateNotification( new StringLocaliser( title ), new StringLocaliser( messageText ), icon, color, 14 );
  161.             NotificationSystem.Create( locTitle, locMessageText, icon, color, 14, NULL );
  162.         }
  163.     }
  164. }
  165.  
Advertisement
Add Comment
Please, Sign In to add comment