mission.cpp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /*-------------------------------------------------------------------------
  2. mission.cpp
  3. Per mission stuff implementation
  4. Owner:
  5. Copyright 1986-2000 Microsoft Corporation, All Rights Reserved
  6. *-----------------------------------------------------------------------*/
  7. #include "pch.h"
  8. const DWORD CFLMission::c_dwID = 19680815; // random number to frame the data to recognize a good instance from a bad instance
  9. CFLMission::CFLMission(CFLServer * pServer, CFLClient * pClientCreator) :
  10. m_plmi(NULL),
  11. m_dwID(c_dwID),
  12. m_pServer(pServer),
  13. m_cPlayers(0),
  14. m_pClientCreator(pClientCreator),
  15. m_fNotifiedCreator(false)
  16. {
  17. assert(m_pServer);
  18. char szRemote[16];
  19. g_pLobbyApp->GetFMServers().GetIPAddress(*m_pServer->GetConnection(), szRemote);
  20. g_pLobbyApp->GetSite()->LogEvent(
  21. EVENTLOG_INFORMATION_TYPE, LE_MissionCreated,
  22. GetCookie(), m_pServer->GetConnection()->GetName(), szRemote,
  23. m_pServer->GetPlayerCount(),
  24. pClientCreator ? pClientCreator->GetConnection()->GetName() : "<ops>");
  25. }
  26. CFLMission::~CFLMission()
  27. {
  28. g_pLobbyApp->GetSite()->LogEvent(
  29. EVENTLOG_INFORMATION_TYPE, LE_MissionGone,
  30. GetCookie(),
  31. m_pServer->GetConnection()->GetName(),
  32. m_pServer->GetPlayerCount());
  33. BEGIN_PFM_CREATE(g_pLobbyApp->GetFMClients(), pfmMissionGone, LS, MISSION_GONE)
  34. END_PFM_CREATE
  35. pfmMissionGone->dwCookie = GetCookie();
  36. g_pLobbyApp->GetFMClients().SendMessages(g_pLobbyApp->GetFMClients().Everyone(), FM_GUARANTEED, FM_FLUSH);
  37. if (m_plmi)
  38. HeapFree(GetProcessHeap(), 0, m_plmi);
  39. }
  40. void CFLMission::SetLobbyInfo(FMD_LS_LOBBYMISSIONINFO * plmi)
  41. {
  42. HANDLE hHeap = GetProcessHeap();
  43. if (m_plmi)
  44. {
  45. HeapFree(hHeap, 0, m_plmi);
  46. }
  47. // adjust the start time from an offset of the current time to a real time
  48. plmi->dwStartTime += Time::Now().clock();
  49. CFLMission * pMission = CFLMission::FromCookie(plmi->dwCookie);
  50. if (pMission)
  51. {
  52. debugf("!!! Got FMD_LS_LOBBYMISSIONINFO for mission (cookie=%x) that I don't know about\n", plmi->dwCookie);
  53. // we could just pass the server in to this function, but this seems like a reasonable and cheap check & balance to make sure the mission maps back to the server
  54. CFLServer * pServer = pMission->GetServer();
  55. assert(pServer);
  56. m_plmi = (FMD_LS_LOBBYMISSIONINFO*) HeapAlloc(hHeap, 0, plmi->cbmsg);
  57. CopyMemory(m_plmi, plmi, plmi->cbmsg);
  58. if (!pServer->GetPaused() && // never advertize paused games
  59. (g_pLobbyApp->EnforceCDKey() || m_plmi->nNumPlayers > 0 || m_plmi->fMSArena))
  60. { // don't advertize Allegiance Zone games until someone is actually in it unless it's admin created.
  61. FedMessaging & fmClients = g_pLobbyApp->GetFMClients();
  62. fmClients.ForwardMessage(fmClients.Everyone(), plmi, FM_GUARANTEED);
  63. }
  64. }
  65. }
  66. void CFLMission::AddPlayer()
  67. {
  68. m_pServer->AddPlayer();
  69. ++m_cPlayers;
  70. }
  71. void CFLMission::RemovePlayer()
  72. {
  73. m_pServer->RemovePlayer();
  74. --m_cPlayers;
  75. assert (m_cPlayers >= 0);
  76. }
  77. void CFLMission::NotifyCreator()
  78. {
  79. if (!m_fNotifiedCreator && GetCreator())
  80. {
  81. // Tell the creator so they auto-join
  82. BEGIN_PFM_CREATE(g_pLobbyApp->GetFMClients(), pfmJoinMission, L, JOIN_MISSION)
  83. END_PFM_CREATE
  84. char szServer[16];
  85. g_pLobbyApp->GetFMServers().GetIPAddress(*GetServer()->GetConnection(), szServer);
  86. assert(lstrlen(szServer) < sizeof(pfmJoinMission->szServer)); // as long as szServer is fixed length
  87. lstrcpy(pfmJoinMission->szServer, szServer);
  88. pfmJoinMission->dwCookie = GetCookie();
  89. g_pLobbyApp->GetFMClients().SendMessages(GetCreator()->GetConnection(), FM_GUARANTEED, FM_FLUSH);
  90. }
  91. m_fNotifiedCreator = true;
  92. }