summaryrefslogtreecommitdiff
path: root/game/shared/tf/tf_notification.cpp
diff options
context:
space:
mode:
authorFluorescentCIAAfricanAmerican <[email protected]>2020-04-22 12:56:21 -0400
committerFluorescentCIAAfricanAmerican <[email protected]>2020-04-22 12:56:21 -0400
commit3bf9df6b2785fa6d951086978a3e66f49427166a (patch)
tree2c0f1f0c63c4832882bc93814ebd2c2b1c6224e5 /game/shared/tf/tf_notification.cpp
downloadarchived-source-engine-2018-hl2-src-master.tar.xz
archived-source-engine-2018-hl2-src-master.zip
Diffstat (limited to 'game/shared/tf/tf_notification.cpp')
-rw-r--r--game/shared/tf/tf_notification.cpp176
1 files changed, 176 insertions, 0 deletions
diff --git a/game/shared/tf/tf_notification.cpp b/game/shared/tf/tf_notification.cpp
new file mode 100644
index 0000000..60bd841
--- /dev/null
+++ b/game/shared/tf/tf_notification.cpp
@@ -0,0 +1,176 @@
+//========= Copyright Valve Corporation, All rights reserved. ============//
+//
+// Purpose:
+//
+// $NoKeywords: $
+//=============================================================================//
+
+#include "cbase.h"
+
+#include "tf_notification.h"
+#include "gcsdk/enumutils.h"
+#include "schemainitutils.h"
+// memdbgon must be the last include file in a .cpp file!!!
+#ifdef GC
+IMPLEMENT_CLASS_MEMPOOL( CTFNotification, 1000, UTLMEMORYPOOL_GROW_SLOW );
+#endif
+
+#include "tier0/memdbgon.h"
+
+using namespace GCSDK;
+
+#ifdef GC
+// See LOCALIZED NOTIFICATIONS note in header
+static bool BIsLocalizedNotificationType( CMsgGCNotification_NotificationType eType )
+{
+ switch ( eType )
+ {
+ case CMsgGCNotification_NotificationType_NOTIFICATION_SUPPORT_MESSAGE:
+ return true;
+ case CMsgGCNotification_NotificationType_NOTIFICATION_REPORTED_PLAYER_BANNED:
+ case CMsgGCNotification_NotificationType_NOTIFICATION_CUSTOM_STRING:
+ case CMsgGCNotification_NotificationType_NOTIFICATION_MM_BAN_DUE_TO_EXCESSIVE_REPORTS:
+ case CMsgGCNotification_NotificationType_NOTIFICATION_REPORTED_PLAYER_WAS_BANNED:
+ case CMsgGCNotification_NotificationType_NOTIFICATION_NUM_TYPES:
+ return false;
+ default:
+ Assert( !"Unknown notification type" );
+ return false;
+ }
+}
+
+CTFNotification::CTFNotification()
+ : m_eLocalizedToLanguage( k_Lang_None )
+{
+ Obj().set_notification_id( 0 );
+ Obj().set_account_id( 0 );
+ Obj().set_expiration_time( 0 );
+ Obj().set_type( CMsgGCNotification_NotificationType_NOTIFICATION_NUM_TYPES ); // Invalid
+ Obj().set_notification_string( "" );
+}
+
+CTFNotification::CTFNotification( CMsgGCNotification msg, const char *pUnlocalizedString, ELanguage eLang )
+ : m_eLocalizedToLanguage( k_Lang_None )
+{
+ Obj() = msg;
+
+ if ( BIsLocalizedNotificationType( Obj().type() ) )
+ {
+ m_strUnlocalizedString = pUnlocalizedString;
+ BLocalize( eLang );
+ }
+ else
+ {
+ Obj().set_notification_string( pUnlocalizedString );
+ }
+}
+
+bool CTFNotification::BLocalize( ELanguage eLang )
+{
+ if ( !BIsLocalizedNotificationType( Obj().type() ) || eLang == m_eLocalizedToLanguage )
+ {
+ return false;
+ }
+
+ m_eLocalizedToLanguage = eLang;
+ const char *pLocalized = GGCGameBase()->LocalizeToken( m_strUnlocalizedString.Get(), eLang, false );
+
+ // Try english fallback
+ const ELanguage eFallback = k_Lang_English;
+ if ( !pLocalized && eLang != eFallback )
+ {
+ pLocalized = GGCGameBase()->LocalizeToken( m_strUnlocalizedString.Get(), eFallback, false );
+ if ( pLocalized )
+ {
+ EmitError( SPEW_GC,
+ "Notification has localized token \"%s\" that is not available in language %s, falling back to %s.\n",
+ m_strUnlocalizedString.Get(), GetLanguageShortName( eLang ), GetLanguageShortName( eFallback ) );
+ }
+ }
+
+ if ( !pLocalized )
+ {
+ EmitError( SPEW_GC, "Notification has localized token \"%s\" that was not found in primary language %s *or* fallback to %s.\n",
+ m_strUnlocalizedString.Get(), GetLanguageShortName( eLang ), GetLanguageShortName( eFallback ) );
+ pLocalized = m_strUnlocalizedString.Get();
+ }
+
+ Obj().set_notification_string( pLocalized ? pLocalized : m_strUnlocalizedString.Get() );
+
+ return true;
+}
+
+bool CTFNotification::BYieldingAddInsertToTransaction( GCSDK::CSQLAccess & sqlAccess )
+{
+ CSchNotification schNotification;
+ WriteToRecord( &schNotification );
+ return CSchemaSharedObjectHelper::BYieldingAddInsertToTransaction( sqlAccess, &schNotification );
+}
+
+bool CTFNotification::BYieldingAddWriteToTransaction( GCSDK::CSQLAccess & sqlAccess, const CUtlVector< int > &fields )
+{
+ CSchNotification schNotification;
+ WriteToRecord( &schNotification );
+ CColumnSet csDatabaseDirty( schNotification.GetPSchema()->GetRecordInfo() );
+ csDatabaseDirty.MakeEmpty();
+ FOR_EACH_VEC( fields, nField )
+ {
+ switch ( fields[nField] )
+ {
+ case CMsgGCNotification::kNotificationIdFieldNumber : csDatabaseDirty.BAddColumn( CSchNotification::k_iField_ulNotificationID ); break;
+ case CMsgGCNotification::kAccountIdFieldNumber : csDatabaseDirty.BAddColumn( CSchNotification::k_iField_unAccountID ); break;
+ case CMsgGCNotification::kExpirationTimeFieldNumber : csDatabaseDirty.BAddColumn( CSchNotification::k_iField_RTime32Expiration ); break;
+ case CMsgGCNotification::kTypeFieldNumber : csDatabaseDirty.BAddColumn( CSchNotification::k_iField_unNotificationType ); break;
+ case CMsgGCNotification::kNotificationStringFieldNumber : csDatabaseDirty.BAddColumn( CSchNotification::k_iField_VarCharData ); break;
+ default:
+ Assert( false );
+ }
+ }
+ return CSchemaSharedObjectHelper::BYieldingAddWriteToTransaction( sqlAccess, &schNotification, csDatabaseDirty );
+}
+
+bool CTFNotification::BYieldingAddRemoveToTransaction( GCSDK::CSQLAccess & sqlAccess )
+{
+ CSchNotification schNotification;
+ WriteToRecord( &schNotification );
+ return CSchemaSharedObjectHelper::BYieldingAddRemoveToTransaction( sqlAccess, &schNotification );
+}
+
+void CTFNotification::WriteToRecord( CSchNotification *pNotification ) const
+{
+ // Important: For localized notifications, the DB value is the localization key (#TF_Some_Thing), but the in-memory
+ // shared object value is localized. See LOCALIZED NOTIFICATIONS note in header.
+ pNotification->m_ulNotificationID = Obj().notification_id();
+ pNotification->m_unAccountID = Obj().account_id();
+ pNotification->m_RTime32Expiration = Obj().expiration_time();
+ pNotification->m_unNotificationType = Obj().type();
+ if ( BIsLocalizedNotificationType( Obj().type() ) )
+ {
+ WRITE_VAR_CHAR_FIELD_TRUNC( *pNotification, VarCharData, m_strUnlocalizedString.Get() );
+ }
+ else
+ {
+ WRITE_VAR_CHAR_FIELD_TRUNC( *pNotification, VarCharData, Obj().notification_string().c_str() );
+ }
+}
+
+void CTFNotification::ReadFromRecord( const CSchNotification & schNotification )
+{
+ // Important: For localized notifications, the DB value is the localization key (#TF_Some_Thing), but the in-memory
+ // shared object value is localized. See LOCALIZED NOTIFICATIONS note in header.
+ m_strUnlocalizedString.Clear();
+ m_eLocalizedToLanguage = k_Lang_None;
+
+ Obj().set_notification_id( schNotification.m_ulNotificationID );
+ Obj().set_account_id( schNotification.m_unAccountID );
+ Obj().set_expiration_time( schNotification.m_RTime32Expiration );
+ Obj().set_type( ( CMsgGCNotification::NotificationType ) schNotification.m_unNotificationType );
+ const char *pchNotificationString = READ_VAR_CHAR_FIELD( schNotification, m_VarCharData );
+ Obj().set_notification_string( pchNotificationString );
+ if ( BIsLocalizedNotificationType( Obj().type() ) )
+ {
+ m_strUnlocalizedString = pchNotificationString;
+ }
+}
+
+#endif