Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- modded class Chat
- {
- private autoptr TStringArray m_SystemMessages = {};
- private autoptr TStringArray m_AdminMessages = {};
- private autoptr TStringArray m_BEMessages = {};
- private ref Timer m_SystemMessagesTimer;
- private ref Timer m_AdminMessagesTimer;
- private ref Timer m_BEMessagesTimer;
- override void AddInternal( ChatMessageEventParams params )
- {
- int messageChannel = params.param1;
- string messageFrom = params.param2;
- string messageText = params.param3;
- //Print( "[ChatNotifications] Chat::AddInternal messageChannel=" + messageChannel + " messageFrom=" + messageFrom + " messageText=" + messageText );
- if ( ( messageFrom == "" && messageText.IndexOf( "[ZomBerry]" ) == 0 ) || !GetGame() || !GetGame().GetPlayer() )
- {
- string channel_name;
- /*!
- channel type, possible values
- CCSystem(1)
- CCAdmin(2)
- CCDirect(4)
- CCMegaphone(8)
- CCTransmitter(16)
- CCPublicAddressSystem(32)
- CCBattlEye(64)
- */
- switch ( messageChannel )
- {
- case CCSystem:
- channel_name = "CCSystem";
- break;
- case CCAdmin:
- channel_name = "CCAdmin";
- break;
- case CCDirect:
- channel_name = "CCDirect";
- break;
- case CCMegaphone:
- channel_name = "CCMegaphone";
- break;
- case CCTransmitter:
- channel_name = "CCTransmitter";
- break;
- case CCPublicAddressSystem:
- channel_name = "CCPublicAddressSystem";
- break;
- case CCBattlEye: // Same as ExpansionChatChannels.CCTransport
- channel_name = "CCBattlEye";
- break;
- }
- Print( "[ChatNotifications] Chat::AddInternal -> super.AddInternal channel=" + channel_name + " from=" + messageFrom + " text=" + messageText );
- super.AddInternal( params );
- return;
- }
- switch ( messageChannel )
- {
- case CCSystem:
- Print( "[ChatNotifications] Channel=CCSystem" );
- m_SystemMessages.Insert( messageText );
- if ( !m_SystemMessagesTimer || !m_SystemMessagesTimer.IsRunning() )
- {
- Print( "[ChatNotifications] Channel=CCSystem Timer" );
- m_SystemMessagesTimer = new Timer( CALL_CATEGORY_GUI );
- m_SystemMessagesTimer.Run( 0.1, this, "CreateCollectedMessagesNotification", new Param3<string, TStringArray, int>( "Server", m_SystemMessages, ARGB( 255, 52, 152, 219 ) ) );
- }
- break;
- case CCAdmin:
- Print( "[ChatNotifications] Channel=CCAdmin" );
- m_AdminMessages.Insert( messageText );
- if ( !m_AdminMessagesTimer || !m_AdminMessagesTimer.IsRunning() )
- {
- Print( "[ChatNotifications] Channel=CCAdmin Timer" );
- m_AdminMessagesTimer = new Timer( CALL_CATEGORY_GUI );
- m_AdminMessagesTimer.Run( 0.1, this, "CreateCollectedMessagesNotification", new Param3<string, TStringArray, int>( "Admin", m_AdminMessages, ARGB(255, 192, 57, 43) ) );
- }
- break;
- case CCBattlEye: // Same as ExpansionChatChannels.CCTransport so we need to check
- Print( "[ChatNotifications] Channel=CCBattlEye" );
- if ( messageFrom == "BattlEye" && messageText.IndexOf( "(Global) Admin: " ) == 0 )
- {
- Print( "[ChatNotifications] Channel=CCBattlEye Admin" );
- m_BEMessages.Insert( messageText.Substring( 16, messageText.Length() - 16 ) );
- if ( !m_BEMessagesTimer || !m_BEMessagesTimer.IsRunning() )
- {
- Print( "[ChatNotifications] Channel=CCBattlEye Timer" );
- m_BEMessagesTimer = new Timer( CALL_CATEGORY_GUI );
- m_BEMessagesTimer.Run( 0.1, this, "CreateCollectedMessagesNotification", new Param3<string, TStringArray, int>( "Remote Console", m_BEMessages, ARGB(255, 192, 57, 43) ) );
- }
- break;
- }
- default:
- //Print( "[ChatNotifications] Chat::AddInternal -> super.AddInternal" );
- super.AddInternal( params );
- break;
- }
- }
- void CreateCollectedMessagesNotification( string title, TStringArray messages, int color )
- {
- string previousTitle;
- string messageText;
- for ( int i = 0; i < messages.Count(); i++ )
- {
- string message = messages[i];
- int idx = message.IndexOf( ":" );
- if ( idx > -1 )
- {
- string prefix = message.Substring( 0, idx );
- if ( ( !prefix.Contains( " " ) || prefix.Length() < 24 ) && ( i == 0 || prefix == previousTitle ) )
- {
- title = prefix;
- previousTitle = title;
- message = message.Substring( idx + 1, message.Length() - idx - 1 ).Trim();
- }
- }
- messageText += message + "\n";
- }
- messages.Clear();
- if ( !GetGame() || !GetGame().GetPlayer() )
- {
- Print( "[ChatNotifications] Chat::CreateCollectedMessagesNotification -> super.AddInternal title=" + title + " messageText=" + messageText );
- int channel = CCSystem;
- switch ( title )
- {
- case "Server":
- channel = CCSystem;
- break;
- case "Admin":
- channel = CCAdmin;
- break;
- case "Remote Console":
- channel = CCBattlEye;
- break;
- }
- ChatMessageEventParams params = new ChatMessageEventParams( channel, "", messageText, "" );
- super.AddInternal( params );
- }
- else
- {
- Print( "[ChatNotifications] Chat::CreateCollectedMessagesNotification title=" + title + " messageText=" + messageText );
- title.Replace( "%", "%%" );
- messageText.Replace( "%", "%%" );
- StringLocaliser locTitle = new StringLocaliser( title );
- StringLocaliser locMessageText = new StringLocaliser( messageText );
- locTitle.SetTranslates( false );
- locMessageText.SetTranslates( false );
- #ifdef EXPANSIONMOD
- string icon = EXPANSION_NOTIFICATION_ICON_INFO;
- #else
- string icon;
- #endif
- //GetNotificationSystem().CreateNotification( new StringLocaliser( title ), new StringLocaliser( messageText ), icon, color, 14 );
- NotificationSystem.Create( locTitle, locMessageText, icon, color, 14, NULL );
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment