Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

91 lines
3.0 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #include "cbase.h"
  8. #include "tf_xp_source.h"
  9. #include "gcsdk/enumutils.h"
  10. #include "schemainitutils.h"
  11. // memdbgon must be the last include file in a .cpp file!!!
  12. #ifdef GC
  13. IMPLEMENT_CLASS_MEMPOOL( CXPSource, 1000, UTLMEMORYPOOL_GROW_SLOW );
  14. #endif
  15. #include "tier0/memdbgon.h"
  16. using namespace GCSDK;
  17. CXPSource::CXPSource()
  18. {
  19. Obj().set_account_id( 0 );
  20. Obj().set_amount( 0 );
  21. Obj().set_match_id( 0 );
  22. Obj().set_type( CMsgTFXPSource_XPSourceType_NUM_SOURCE_TYPES ); // Invalid
  23. Obj().set_match_group( EMatchGroup::k_nMatchGroup_Invalid );
  24. }
  25. #ifdef GC
  26. CXPSource::CXPSource( CMsgTFXPSource msg )
  27. {
  28. Obj() = msg;
  29. }
  30. bool CXPSource::BYieldingAddInsertToTransaction( GCSDK::CSQLAccess & sqlAccess )
  31. {
  32. CSchPlayerXPSources schXPSource;
  33. WriteToRecord( &schXPSource );
  34. return CSchemaSharedObjectHelper::BYieldingAddInsertToTransaction( sqlAccess, &schXPSource );
  35. }
  36. bool CXPSource::BYieldingAddWriteToTransaction( GCSDK::CSQLAccess & sqlAccess, const CUtlVector< int > &fields )
  37. {
  38. CSchPlayerXPSources schXPSource;
  39. WriteToRecord( &schXPSource );
  40. CColumnSet csDatabaseDirty( schXPSource.GetPSchema()->GetRecordInfo() );
  41. csDatabaseDirty.MakeEmpty();
  42. FOR_EACH_VEC( fields, nField )
  43. {
  44. switch ( fields[nField] )
  45. {
  46. case CMsgTFXPSource::kAccountIdFieldNumber : csDatabaseDirty.BAddColumn( CSchPlayerXPSources::k_iField_unAccountID ); break;
  47. case CMsgTFXPSource::kAmountFieldNumber : csDatabaseDirty.BAddColumn( CSchPlayerXPSources::k_iField_unAmount ); break;
  48. case CMsgTFXPSource::kTypeFieldNumber : csDatabaseDirty.BAddColumn( CSchPlayerXPSources::k_iField_eSource ); break;
  49. case CMsgTFXPSource::kMatchGroupFieldNumber : csDatabaseDirty.BAddColumn( CSchPlayerXPSources::k_iField_eMatchGroup ); break;
  50. case CMsgTFXPSource::kMatchIdFieldNumber : csDatabaseDirty.BAddColumn( CSchPlayerXPSources::k_iField_unMatchID ); break;
  51. default:
  52. Assert( false );
  53. }
  54. }
  55. return CSchemaSharedObjectHelper::BYieldingAddWriteToTransaction( sqlAccess, &schXPSource, csDatabaseDirty );
  56. }
  57. bool CXPSource::BYieldingAddRemoveToTransaction( GCSDK::CSQLAccess & sqlAccess )
  58. {
  59. CSchPlayerXPSources schXPSource;
  60. WriteToRecord( &schXPSource );
  61. return CSchemaSharedObjectHelper::BYieldingAddRemoveToTransaction( sqlAccess, &schXPSource );
  62. }
  63. void CXPSource::WriteToRecord( CSchPlayerXPSources *pXPSource ) const
  64. {
  65. pXPSource->m_unAccountID = Obj().account_id();
  66. pXPSource->m_eSource = Obj().type();
  67. pXPSource->m_eMatchGroup = Obj().match_group();
  68. pXPSource->m_unAmount = Obj().amount();
  69. pXPSource->m_unMatchID = Obj().match_id();
  70. }
  71. void CXPSource::ReadFromRecord( const CSchPlayerXPSources & xpSource )
  72. {
  73. Obj().set_account_id( xpSource.m_unAccountID );
  74. Obj().set_type( ( CMsgTFXPSource::XPSourceType )xpSource.m_eSource );
  75. Obj().set_match_group( xpSource.m_eMatchGroup );
  76. Obj().set_amount( xpSource.m_unAmount );
  77. Obj().set_match_id( xpSource.m_unMatchID );
  78. }
  79. #endif