#include "pch.h"
const DWORD CFLMission::c_dwID = 19680815; CFLMission::CFLMission(CFLServer * pServer, CFLClient * pClientCreator) :
m_plmi(NULL),
m_dwID(c_dwID),
m_pServer(pServer),
m_cPlayers(0),
m_pClientCreator(pClientCreator),
m_fNotifiedCreator(false)
{
assert(m_pServer);
char szRemote[16];
g_pLobbyApp->GetFMServers().GetIPAddress(*m_pServer->GetConnection(), szRemote);
g_pLobbyApp->GetSite()->LogEvent(
EVENTLOG_INFORMATION_TYPE, LE_MissionCreated,
GetCookie(), m_pServer->GetConnection()->GetName(), szRemote,
m_pServer->GetPlayerCount(),
pClientCreator ? pClientCreator->GetConnection()->GetName() : "<ops>");
}
CFLMission::~CFLMission()
{
g_pLobbyApp->GetSite()->LogEvent(
EVENTLOG_INFORMATION_TYPE, LE_MissionGone,
GetCookie(),
m_pServer->GetConnection()->GetName(),
m_pServer->GetPlayerCount());
BEGIN_PFM_CREATE(g_pLobbyApp->GetFMClients(), pfmMissionGone, LS, MISSION_GONE)
END_PFM_CREATE
pfmMissionGone->dwCookie = GetCookie();
g_pLobbyApp->GetFMClients().SendMessages(g_pLobbyApp->GetFMClients().Everyone(), FM_GUARANTEED, FM_FLUSH);
if (m_plmi)
HeapFree(GetProcessHeap(), 0, m_plmi);
}
void CFLMission::SetLobbyInfo(FMD_LS_LOBBYMISSIONINFO * plmi)
{
HANDLE hHeap = GetProcessHeap();
if (m_plmi)
{
HeapFree(hHeap, 0, m_plmi);
}
plmi->dwStartTime += Time::Now().clock();
CFLMission * pMission = CFLMission::FromCookie(plmi->dwCookie);
if (pMission)
{
debugf("!!! Got FMD_LS_LOBBYMISSIONINFO for mission (cookie=%x) that I don't know about\n", plmi->dwCookie);
CFLServer * pServer = pMission->GetServer();
assert(pServer);
m_plmi = (FMD_LS_LOBBYMISSIONINFO*) HeapAlloc(hHeap, 0, plmi->cbmsg);
CopyMemory(m_plmi, plmi, plmi->cbmsg);
if (!pServer->GetPaused() && (g_pLobbyApp->EnforceCDKey() || m_plmi->nNumPlayers > 0 || m_plmi->fMSArena ||
(!g_pLobbyApp->IsFreeLobby() && strcmp(FM_VAR_REF(m_plmi,szIGCStaticFile),"zone_core")) ))
{ FedMessaging & fmClients = g_pLobbyApp->GetFMClients();
fmClients.ForwardMessage(fmClients.Everyone(), plmi, FM_GUARANTEED);
}
}
}
void CFLMission::AddPlayer()
{
m_pServer->AddPlayer();
++m_cPlayers;
}
void CFLMission::RemovePlayer()
{
m_pServer->RemovePlayer();
--m_cPlayers;
assert (m_cPlayers >= 0);
}
void CFLMission::NotifyCreator()
{
if (!m_fNotifiedCreator && GetCreator())
{
BEGIN_PFM_CREATE(g_pLobbyApp->GetFMClients(), pfmJoinMission, L, JOIN_MISSION)
END_PFM_CREATE
char szServer[16];
g_pLobbyApp->GetFMServers().GetIPAddress(*GetServer()->GetConnection(), szServer);
assert(lstrlen(szServer) < sizeof(pfmJoinMission->szServer)); lstrcpy(pfmJoinMission->szServer, szServer);
pfmJoinMission->dwCookie = GetCookie();
pfmJoinMission->dwPort = GetServer()->GetServerPort(); g_pLobbyApp->GetFMClients().SendMessages(GetCreator()->GetConnection(), FM_GUARANTEED, FM_FLUSH);
}
m_fNotifiedCreator = true;
}