Counter Strike : Global Offensive Source Code
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.

44 lines
1.3 KiB

  1. //=========== (C) Copyright Valve, L.L.C. All rights reserved. ===========
  2. #include "cbase.h"
  3. #include "ui_nugget.h"
  4. class CUiNuggetPlayerManager : public CUiNuggetBase
  5. {
  6. DECLARE_NUGGET_FN_MAP( CUiNuggetPlayerManager, CUiNuggetBase );
  7. NUGGET_FN( GetLocalPlayer )
  8. {
  9. // Request for local player info
  10. int iController = args->GetInt( "index" );
  11. IPlayerLocal *pLocalPlayer = g_pMatchFramework->GetMatchSystem()->GetPlayerManager()->GetLocalPlayer( iController );
  12. if ( !pLocalPlayer )
  13. return NULL;
  14. return PlayerAsKeyValues( pLocalPlayer, CFmtStr( "localplayer%d", iController ) );
  15. }
  16. NUGGET_FN( JoinFriend )
  17. {
  18. // Request to join a friend
  19. XUID xuid = args->GetUint64( "xuid" );
  20. IPlayerFriend *pFriend = g_pMatchFramework->GetMatchSystem()->GetPlayerManager()->GetFriendByXUID( xuid );
  21. if ( !pFriend )
  22. return NULL;
  23. pFriend->Join();
  24. return NULL;
  25. }
  26. KeyValues * PlayerAsKeyValues( IPlayer *pPlayer, char const *szResultTitle = "" )
  27. {
  28. KeyValues *kv = new KeyValues( szResultTitle );
  29. kv->SetString( "name", pPlayer->GetName() );
  30. kv->SetString( "xuid", CFmtStr( "%llu", pPlayer->GetXUID() ) );
  31. kv->SetInt( "index", pPlayer->GetPlayerIndex() );
  32. kv->SetInt( "state", pPlayer->GetOnlineState() );
  33. return kv;
  34. }
  35. };
  36. UI_NUGGET_FACTORY_SINGLETON( CUiNuggetPlayerManager, "playermanager" );