void CFSShip::QueueLoadoutChange(bool bForce)
{
  const PartListIGC*  pplist = GetIGCShip()->GetParts();
  const ShipListIGC*  pslist = GetIGCShip()->GetChildShips();

  BEGIN_PFM_CREATE(g.fm, pfmLoadoutChange, S, LOADOUT_CHANGE)
      FM_VAR_PARM(NULL, GetIGCShip()->ExportShipLoadout(NULL))
      FM_VAR_PARM(NULL, pslist->n() * sizeof(PassengerData))
  END_PFM_CREATE

  GetIGCShip()->ExportShipLoadout((ShipLoadout*)(FM_VAR_REF(pfmLoadoutChange, loadout)));

  pfmLoadoutChange->sidShip = bForce ? NA : GetIGCShip()->GetObjectID();

  //Queue any children and their positions
  {
      PassengerData*   pd = (PassengerData*)(FM_VAR_REF(pfmLoadoutChange, rgPassengers));
      for (ShipLinkIGC*   psl = pslist->first();
           (psl != NULL);
           psl = psl->next())
      {
          pd->shipID = psl->data()->GetObjectID();
          pd->turretID = psl->data()->GetTurretID();

          pd++;
      }
  }
}
/*-------------------------------------------------------------------------
 * AnnounceExit
 *-------------------------------------------------------------------------
 * Purpose:
 *    Somebody left. Let everybody know.
 * 
 * Returns:
 *    nothing
 */
void CFSShip::AnnounceExit(IclusterIGC* pclusterOld, ShipDeleteReason sdr)
{
  if ((SDR_DOCKED == sdr || SDR_LEFTSECTOR == sdr) && (m_pShip->GetParentShip() != NULL))
    return;

  BEGIN_PFM_CREATE(g.fm, pfmShipDelete, S, SHIP_DELETE)
  END_PFM_CREATE
  pfmShipDelete->shipID = GetShipID();
  pfmShipDelete->sdr = sdr;
  CFMRecipient * prcp = NULL;
  if (SDR_DOCKED == sdr || SDR_LEFTSECTOR == sdr)
  {
    assert (pclusterOld);
    prcp = GetGroupSectorFlying(pclusterOld);
  }
  else
  {
    ImissionIGC*    pm = GetIGCShip()->GetMission();
    
    if (pm && pm->GetPrivateData())
    {
      CFSMission * pfsMission = (CFSMission *)(pm->GetPrivateData());
      prcp = pfsMission->GetGroupMission();
    }
  }

  if (prcp)
    g.fm.SendMessages(prcp, FM_GUARANTEED, FM_FLUSH);
  else
    g.fm.PurgeOutBox();
}
Esempio n. 3
0
bool CLobbyApp::BootPlayersByCDKey(const ZString& strCDKey, const ZString& strNameExclude, ZString& strOldPlayer)
{
  PlayerByCDKey::iterator iterPlayerByCDKey = m_playerByCDKey.find(strCDKey);
  bool bBootedSomeone = false;

  // if we think that player is already logged on...
  while (iterPlayerByCDKey != m_playerByCDKey.end()
      && (*iterPlayerByCDKey).first == strCDKey)
  {
    // boot all old copies
    if ((*iterPlayerByCDKey).second.GetName() != strNameExclude)
    {
        CFLMission * pMissionOld = (*iterPlayerByCDKey).second.GetMission();
    
        BEGIN_PFM_CREATE(m_fmServers, pfmRemovePlayer, L, REMOVE_PLAYER)
          FM_VAR_PARM((PCC)(*iterPlayerByCDKey).second.GetName(), CB_ZTS)
          FM_VAR_PARM((PCC)(strNameExclude), CB_ZTS)
        END_PFM_CREATE
        pfmRemovePlayer->dwMissionCookie = pMissionOld->GetCookie();
        pfmRemovePlayer->reason = RPR_duplicateCDKey;    
        m_fmServers.SendMessages(pMissionOld->GetServer()->GetConnection(), 
          FM_GUARANTEED, FM_FLUSH);

        // note: only returns the name of the last player we booted.
        strOldPlayer = (*iterPlayerByCDKey).second.GetName();
        bBootedSomeone = true;
    }

    ++iterPlayerByCDKey;
  }

  return bBootedSomeone;
}
void CFSPlayer::SetShipUpdate(const ClientShipUpdate& su)
{
    if (su.time > m_timeUpdate)
    {
        ShipUpdateStatus sus = GetIGCShip()->ProcessShipUpdate(su);
        if (sus == c_susAccepted)
        {
            m_ucLastUpdate = c_ucShipUpdate;

            m_su = su;
            m_timeUpdate = su.time;

            if (m_warpState == warpNoUpdate)
            {
                m_warpState = warpWaiting;
                m_timeNextWarp = g.timeNow + 2.0f;  //Some fudge factor
            }
            else if ((m_warpState == warpWaiting) && (g.timeNow >= m_timeNextWarp))
                m_warpState = warpReady;
        }
        else if (sus == c_susRejected)
        {
            BEGIN_PFM_CREATE(g.fm, pfmSR, S, SHIP_RESET)
            END_PFM_CREATE

            GetIGCShip()->ExportShipUpdate(&(pfmSR->shipupdate));
            pfmSR->cookie = NewCookie();

            g.fm.SendMessages(GetConnection(), FM_GUARANTEED, FM_FLUSH);
        }
    }
}
//This should only be called from the ChangeCluster() callback.
void CFSShip::SetCluster(IclusterIGC * pcluster, bool   bViewOnly)
{
    if (pcluster)
    {
        IshipIGC* pshipParent = m_pShip->GetParentShip();

        if ((pshipParent == NULL) && !bViewOnly)
        {
            //Everyone already in the sector now knows about the player's ship
            //(assuming the player is not in a turret)
            QueueLoadoutChange();

            BEGIN_PFM_CREATE(g.fm, pfmSSU, S, SINGLE_SHIP_UPDATE)
            END_PFM_CREATE

            m_pShip->ExportShipUpdate(&(pfmSSU->shipupdate));

            {
                ImodelIGC*  pmodelTarget = m_pShip->GetCommandTarget(c_cmdCurrent);
                if (pmodelTarget)
                {
                    pfmSSU->otTarget = pmodelTarget->GetObjectType();
                    pfmSSU->oidTarget = pmodelTarget->GetObjectID();
                }
                else
                {
                    pfmSSU->otTarget = NA;
                    pfmSSU->oidTarget = NA;
                }                    
            }

            pfmSSU->bIsRipcording = m_pShip->fRipcordActive();

            g.fm.SendMessages(GetGroupSectorFlying(pcluster), FM_GUARANTEED, FM_FLUSH);

            SetDeviation(0.0f);
        }

        // if this is a drone that has arrived in a sector to which it was told
        // to go, clear its objective.
        if (!IsPlayer())
        {
            for (Command i = 0; i < c_cmdMax; i++)
            {
                ImodelIGC* ptarget = m_pShip->GetCommandTarget(i);
                
                // if this command has a cluster buoy in this cluster...
                if (ptarget && ptarget->GetObjectType() == OT_buoy 
                    && ((IbuoyIGC*)ptarget)->GetBuoyType() == c_buoyCluster
                    && ((IbuoyIGC*)ptarget)->GetCluster() == pcluster)
                {
                    // clear the command
                    m_pShip->SetCommand(i, NULL, c_cidNone);
                }
            }
        }
    }
}
Esempio n. 6
0
HRESULT LobbyServerSite::OnNewConnection(FedMessaging * pthis, CFMConnection & cnxn) 
{
  char szRemote[16];
  pthis->GetIPAddress(cnxn, szRemote);
  CFLServer * pServer = new CFLServer(&cnxn);
  g_pLobbyApp->GetSite()->LogEvent(EVENTLOG_INFORMATION_TYPE, LE_ServerConnected, cnxn.GetName(), szRemote);

  // tell them what token to use
  BEGIN_PFM_CREATE(*pthis, pfmToken, L, TOKEN)
    FM_VAR_PARM(g_pLobbyApp->GetToken(), CB_ZTS)
  END_PFM_CREATE
  pthis->SendMessages(&cnxn, FM_GUARANTEED, FM_FLUSH);
  return S_OK;
}
Esempio n. 7
0
STDMETHODIMP CPigShip::put_WingID(short Val)
{
    // Validate the specified WingID
    if (0 > Val || Val > 9)
        return E_INVALIDARG;

    if (m_pPig->BaseClient::GetNetwork()->IsConnected())
    {
        m_pPig->BaseClient::SetMessageType(BaseClient::c_mtGuaranteed);
        BEGIN_PFM_CREATE(*m_pPig->BaseClient::GetNetwork(), pfm, CS, SET_WINGID)
        END_PFM_CREATE
        pfm->shipID = GetIGC()->GetObjectID();
        pfm->wingID = Val;
    }
    return S_OK;
}
void CFSPlayer::Dock(IstationIGC * pstation)
{
  IshipIGC * pship = GetIGCShip();

  CFSCluster*       pfsCluster = (CFSCluster*)(pstation->GetCluster()->GetPrivateData());
  SetDPGroup(pfsCluster, false);

  ShipStatus* pss = GetShipStatus(pship->GetSide()->GetObjectID());
  pss->SetStationID(pstation->GetObjectID());
  pss->SetSectorID(pstation->GetCluster()->GetObjectID());

  // Tell them what station they're at
  BEGIN_PFM_CREATE(g.fm, pfmDocked, S, DOCKED)
  END_PFM_CREATE
  pfmDocked->stationID = pstation->GetObjectID();
  g.fm.SendMessages(GetConnection(), FM_GUARANTEED, FM_FLUSH);

  //CFSShip::Dock(pstation);
}
Esempio n. 9
0
STDMETHODIMP CPigShip::put_AutoDonate(IAGCShip* pShip)
{
    if (m_pPig->BaseClient::GetNetwork()->IsConnected())
    {
        AGCObjectID shipID;
        if (!pShip)
            shipID = NA;
        else
            RETURN_FAILED(pShip->get_ObjectID(&shipID))

            if (GetIGC() && GetIGC()->GetObjectID() == shipID)
                shipID = NA;

        m_pPig->BaseClient::SetMessageType(BaseClient::c_mtGuaranteed);
        BEGIN_PFM_CREATE(*m_pPig->BaseClient::GetNetwork(), pfm, C, AUTODONATE)
        END_PFM_CREATE
        pfm->sidDonateTo = shipID;
        pfm->amount = m_pPig->BaseClient::GetMoney();
        m_pPig->BaseClient::SetMoney(0);

        //Do not set the ship's autodonate ... happens on the echo from the server.
    }
Esempio n. 10
0
void CLobbyApp::BootPlayersByName(const ZString& strName)
{
  PlayerByName::iterator iterPlayer = m_playerByName.find(strName);

  // if we think that player is already logged on...
  while (iterPlayer != m_playerByName.end()
      && (*iterPlayer).first == strName)
  {
    // boot all old copies
    CFLMission * pMissionOld = (*(*iterPlayer).second).second.GetMission();
    
    BEGIN_PFM_CREATE(m_fmServers, pfmRemovePlayer, L, REMOVE_PLAYER)
      FM_VAR_PARM((PCC)strName, CB_ZTS)
      FM_VAR_PARM(NULL, 0)
    END_PFM_CREATE
    pfmRemovePlayer->dwMissionCookie = pMissionOld->GetCookie();
    pfmRemovePlayer->reason = RPR_duplicateName;
    m_fmServers.SendMessages(pMissionOld->GetServer()->GetConnection(), 
      FM_GUARANTEED, FM_FLUSH);

    ++iterPlayer;
  }
}
Esempio n. 11
0
void CFLServer::Pause(bool fPause)
{
  if (m_fPaused == fPause)
    return;

  m_fPaused = fPause;
  MissionList::Iterator iter(m_missions);
  
  if (m_fPaused) // hide the games
  {
    g_pLobbyApp->GetSite()->LogEvent(EVENTLOG_INFORMATION_TYPE, LE_ServerPause,
        GetConnection()->GetName());

    while (!iter.End())
    { 
      BEGIN_PFM_CREATE(g_pLobbyApp->GetFMClients(), pfmMissionGone, LS, MISSION_GONE)
      END_PFM_CREATE
      pfmMissionGone->dwCookie = iter.Value()->GetCookie();
      iter.Next();
    } 
    g_pLobbyApp->GetFMClients().SendMessages(g_pLobbyApp->GetFMClients().Everyone(), FM_GUARANTEED, FM_FLUSH);
  }
  else // show the games
  {
    g_pLobbyApp->GetSite()->LogEvent(EVENTLOG_INFORMATION_TYPE, LE_ServerContinue, 
        GetConnection()->GetName());

    while (!iter.End())
    {
      FMD_LS_LOBBYMISSIONINFO * plmi = iter.Value()->GetMissionInfo();
      if (plmi)
        g_pLobbyApp->GetFMClients().QueueExistingMsg(plmi);
      iter.Next();
    }
    g_pLobbyApp->GetFMClients().SendMessages(g_pLobbyApp->GetFMClients().Everyone(), FM_GUARANTEED, FM_FLUSH);
  }
}
Esempio n. 12
0
int CLobbyApp::Run()
{
  const DWORD c_dwUpdateInterval = 200; // milliseconds
  DWORD dwSleep = c_dwUpdateInterval;
  DWORD dwWait = WAIT_TIMEOUT;
  InitializeCriticalSectionAndSpinCount(&HttpCriticalSection, 0x00000400);
  InitializeCriticalSectionAndSpinCount(GetLogonCS(), 0x00000400);
  m_plas->LogEvent(EVENTLOG_INFORMATION_TYPE, LE_Running);
  puts("---------Press Q to exit---------");
   printf("Ready for clients/servers.\n");
  CTempTimer timerIterations("between iterations", .25f);
  timerIterations.Start();
  CTempTimer timerReceiveClientsMessages("in clients ReceiveMessages()", .05f);
  CTempTimer timerReceiveServersMessages("in servers ReceiveMessages()", .05f);
  Time timeLastQueueCheck = Time::Now();
  Time timeLastGameInfo = Time::Now();

  while (true)
  {
    timerIterations.Stop();
    timerIterations.Start();

    if (ProcessMsgPump() || (_kbhit() && toupper(_getch()) == 'Q')) {
		//Imago #111 7/10
		if(g_pAutoUpdate)
		{ 
			char szFileName[MAX_PATH+16];
			strcpy(szFileName, _Module.GetModulePath());
			Strcat(szFileName, "FileList.txt");
			g_pAutoUpdate->LoadCRC(szFileName);
			FedMessaging * pfm = &g_pLobbyApp->GetFMClients();
			int count = pfm->GetConnectionCount();
			ListConnections::Iterator iterCnxn(*pfm->GetConnections());
			while (!iterCnxn.End()) {
				BEGIN_PFM_CREATE(*pfm, pfmAutoUpdate, L, AUTO_UPDATE_INFO)
				  FM_VAR_PARM(g_pAutoUpdate->GetFTPServer(), CB_ZTS)
				  FM_VAR_PARM(g_pAutoUpdate->GetFTPInitialDir(), CB_ZTS)
				  FM_VAR_PARM(g_pAutoUpdate->GetFTPAccount(), CB_ZTS)
				  FM_VAR_PARM(g_pAutoUpdate->GetFTPPassword(), CB_ZTS)
				END_PFM_CREATE
				pfmAutoUpdate->crcFileList = g_pAutoUpdate->GetFileListCRC();
				pfmAutoUpdate->nFileListSize = g_pAutoUpdate->GetFileListSize();
				pfm->SendMessages(iterCnxn.Value(), FM_GUARANTEED, FM_FLUSH);
				iterCnxn.Next();
			}
		}
      return 0;
	}

    SetNow();

    m_pCounters->timeInnerLoop = timerIterations.LastInterval();

    // receive any messages in the queue
    timerReceiveClientsMessages.Start();
    m_fmClients.ReceiveMessages();
    timerReceiveClientsMessages.Stop();

    timerReceiveServersMessages.Start();
    m_fmServers.ReceiveMessages();
    timerReceiveServersMessages.Stop();

    if (GetNow() - timeLastQueueCheck >= 1.0f)
    {
      // count the fairly expensive stuff no more than once a second
      UpdatePerfCounters();
      timeLastQueueCheck = GetNow();
      if (GetNow() - timeLastGameInfo >= (float) m_sGameInfoInterval)
      {
        SendGameInfo();
        timeLastGameInfo = GetNow();
      }

      // Do a periodic roll call. If we haven't heard from anyone for two roll calls in a row, waste 'em
      static Time timeRollCall = Time::Now();
      if (GetNow() - timeRollCall >= 5.0f)
      {
        RollCall();
        timeRollCall = GetNow();
      }
    }
    Sleep(1);
  }
  DeleteCriticalSection(GetLogonCS());
  DeleteCriticalSection(&HttpCriticalSection);
  return 0;
}
/*-------------------------------------------------------------------------
 * CaptureStation
 *-------------------------------------------------------------------------
 * Purpose:
 *    Handle a station being captured by a ship
 */
void CFSShip::CaptureStation(IstationIGC * pstation)
{
  {
    //Fudge the hitpoints of the station
    //All those guns inside damage the hull
    pstation->SetFraction(pstation->GetFraction() * 0.5f);

    //But the heroic engineer's get the shields up.
    pstation->SetShieldFraction(0.8f); //pstation->GetShieldFraction() + 0.5f);
  }

  {
      GetPlayerScoreObject()->CaptureBase(true);
      for (ShipLinkIGC* psl = GetIGCShip()->GetChildShips()->first();
           (psl != NULL);
           psl = psl->next())
      {
         CFSShip*      ps = (CFSShip*)(psl->data()->GetPrivateData());
         ps->GetPlayerScoreObject()->CaptureBase(false);
      }
  }

  IsideIGC * pside = GetSide();
  pside->AddBaseCapture();

  SideID iSide = pside->GetObjectID();
  IsideIGC* psideOld = pstation->GetSide();

  StationID stationID = pstation->GetObjectID();
  BEGIN_PFM_CREATE(g.fm, pfmStationCapture, S, STATION_CAPTURE)
  END_PFM_CREATE
  pfmStationCapture->stationID = stationID;
  pfmStationCapture->sidOld = psideOld->GetObjectID();
  pfmStationCapture->sidNew = iSide;
  pfmStationCapture->shipIDCredit = GetIGCShip()->GetObjectID();
  g.fm.SendMessages(GetMission()->GetGroupRealSides(), FM_GUARANTEED, FM_FLUSH);

  pstation->SetSide(pside);
  // TE: Fire AGCEvent when base is captured
  CFSMission * pfsMission = this->GetMission();
  LPCSTR pszContext = pfsMission->GetIGCMission() ? pfsMission->GetIGCMission()->GetContextName() : NULL;
  _AGCModule.TriggerContextEvent(NULL, EventID_StationChangesSides, pszContext,
    GetName(), GetShipID(), pside->GetUniqueID(), -1, 4,
	"GameID"	 , VT_I4   , pfsMission->GetMissionID(),
	"OldTeam"    , VT_I4   , psideOld->GetUniqueID(),
    "OldTeamName", VT_LPSTR, psideOld->GetName(),
	"StationName", VT_LPSTR, pstation->GetName());
  // TE end

	// yp: Add event for players who were involved in the capture of an enemy base.
    // mmf commented this out for now pending additional testing
#if 0
	 ZString pszPlayerList = ""; // this creates a new ZString object and set its value to "", it's not a pointer to ""
	 if(m_pfsMission->GetIGCMission() && m_pfsMission->GetIGCMission()->GetShips())
	 {
		ShipLinkIGC * pShiplink = m_pfsMission->GetIGCMission()->GetShips()->first();
		while (pShiplink)
		{
			CFSShip * pfsShip = (CFSShip *) pShiplink->data()->GetPrivateData();
			if (pfsShip && pfsShip->IsPlayer())
			{
				// this logic might need to be tweeked to include the ship that did the capture if its
				if(pfsShip->GetSide()		&& pfsShip->GetSide()->GetObjectID()	== iSide && // if they are on the side that did the Capture. and..
					pfsShip->GetPlayer()->GetIGCShip()->GetObjectID() == GetIGCShip()->GetObjectID() ||	// they are the ship that did the caputure. or
				   pfsShip->GetCluster()	&& pstation->GetCluster()	&& pfsShip->GetCluster()->GetObjectID() == pstation->GetCluster()->GetObjectID()) // they are in this sector
				{
					pszPlayerList = pszPlayerList + ";" + ZString(pfsShip->GetPlayer()->GetName()); // players name
					// The distance the player is from the station that was destroyed.
					if(pfsShip->GetPlayer()->GetIGCShip() )
					{
						pszPlayerList = pszPlayerList +  ":" + ZString( (pstation->GetPosition() - pfsShip->GetPlayer()->GetIGCShip()->GetPosition()).Length()); // the distance
					}
				}
			}
			pShiplink = pShiplink->next();
		}
	 }
	 
	 // Fire AGCEvent listing players in the sector
	// TODO: Might want to add into the event weither or not this was a VICTORY capture.. should we track that as well?
	_AGCModule.TriggerContextEvent(NULL, EventID_StationChangesSides, pszContext,
						GetName(), GetShipID(), pside->GetUniqueID(), -1, 4,
						"GameID"	 , VT_I4   , pfsMission->GetMissionID(),
						"OldTeam"    , VT_I4   , psideOld->GetUniqueID(),
						"OldTeamName", VT_LPSTR, psideOld->GetName(),
						"zPlayerList", VT_LPSTR, pszPlayerList); // pszPlayerList should look like ";player@squad:1500;player2@squad:500"
 // yp:end
#endif



  //Possibly the built themselves to a victory
  IsideIGC*   psideWin = m_pfsMission->CheckForVictoryByStationCapture(pside, psideOld);
  if (psideWin)
  {
      static char szReason[100];     //Make this static so we only need to keep a pointer to it around
      sprintf(szReason, "%s won because %s captured %s", psideWin->GetName(), GetIGCShip()->GetName(), pstation->GetName());
      m_pfsMission->GameOver(psideWin, szReason);
  }
  else if (psideOld->GetActiveF())						//RESET OUR EYE HERE?  IMAGO CAPTURE EYE BUG FIX?  REVIEW 7/23/09
      m_pfsMission->VacateStation(pstation);
}
Esempio n. 14
0
HRESULT LobbyServerSite::OnAppMessage(FedMessaging * pthis, CFMConnection & cnxnFrom, FEDMESSAGE * pfm)
{
  CFLServer * pServer = CFLServer::FromConnection(cnxnFrom);
  assert(pServer);

  cnxnFrom.ResetAbsentCount();

  switch (pfm->fmid)
  {
    case FM_S_LOGON_LOBBY:
    {
      CASTPFM(pfmLogon, S, LOGON_LOBBY, pfm);
	  pfmLogon->cbvStaticCoreInfo;
	  char szRemote[16];
      if (pfmLogon->verLobby == LOBBYVER_LS)
      {
        if(pfmLogon->dwPort != 0)						// A port of 0 means the server couldn't find out its listening port
          pServer->SetServerPort(pfmLogon->dwPort);
        else
          pServer->SetServerPort(6073);				// Tell the client to enum the old fashioned way
		//KGJV #114
		// fill in StaticCoreInfo
		StaticCoreInfo* pcoreinfo  = (StaticCoreInfo*)FM_VAR_REF(pfmLogon, vStaticCoreInfo);
		pServer->SetStaticCoreInfo(pfmLogon->cStaticCoreInfo, pcoreinfo);
		//Imago: reorganized some stuff to get a better debug message		
		// location
		char * szLoc =  FM_VAR_REF(pfmLogon, szLocation);
		pServer->SetLocation(szLoc);
		//Imago #2 6/10
		char * szPrivilegedUsers =  FM_VAR_REF(pfmLogon, szPrivilegedUsers);
		pServer->SetPrivilegedUsers(szPrivilegedUsers);
		//Imago #62 6/10
		char * szVersion =  FM_VAR_REF(pfmLogon, szServerVersion);
		pServer->SetVersion(szVersion);
		// max games
		pServer->SetMaxGamesAllowed(pfmLogon->MaxGames);
		
		// current games (allow servers to update) - Imago 6/25/08
		pServer->SetCurrentGamesCount(pfmLogon->CurGames);

		// rebuild the master core list
		g_pLobbyApp->BuildStaticCoreInfo();
		// break; mmf took out break so we can check ip below
		// KGJV moved mmf's stuff inside lobby version check
		// mmf add check to see if they are an allowed or blocked server

		  pthis->GetIPAddress(cnxnFrom, szRemote);
		  debugf("FM_S_LOGON_LOBBY: %s:%d loc:%s #games:%i\n",&szRemote,pfmLogon->dwPort,pServer->GetLocation(),pfmLogon->CurGames);
		  if (!strncmp("127.0.0.1",szRemote,9)) break;  // check for loopback and always allow
		  if (IsServerAllowed(szRemote)) break;
	  }

	  char * szReason;

	  // if we got this far we are not on the approved list fall through to reject below
	  szReason = "Your server IP address is not approved for connection to this Lobby.  Please contact the Lobby Admin."; //Imago fix typo 6/10
	  // end mmf
	  
      if (pfmLogon->verLobby > LOBBYVER_LS)
        szReason = "The Public Lobby server that you connected to is older than your version.  The Zone needs to update their lobby server.  Please try again later.";
      if (pfmLogon->verLobby < LOBBYVER_LS) // mmf took out the else and made this an explicit if for above szReason
        szReason = "Your server's version did not get auto-updated properly.  Please try again later.";

      BEGIN_PFM_CREATE(*pthis, pfmNewMissionAck, L, LOGON_SERVER_NACK)
          FM_VAR_PARM((char *)szReason, CB_ZTS)
      END_PFM_CREATE
      pthis->SendMessages(&cnxnFrom, FM_GUARANTEED, FM_FLUSH);
      pthis->DeleteConnection(cnxnFrom);
      break;
    }

    case FM_S_NEW_MISSION:
    {
      // a server has created a mission of their own volition. We need to map it into our "cookie space"
      CASTPFM(pfmNewMission, S, NEW_MISSION, pfm);
      CFLMission * pMission = pServer->CreateMission(NULL); // NULL = no client created this
      BEGIN_PFM_CREATE(*pthis, pfmNewMissionAck, L, NEW_MISSION_ACK)
      END_PFM_CREATE
      pfmNewMissionAck->dwIGCMissionID = pfmNewMission->dwIGCMissionID;
      pfmNewMissionAck->dwCookie = (DWORD) pMission;
      pthis->SendMessages(&cnxnFrom, FM_GUARANTEED, FM_FLUSH);
      // we won't broadcast it until the server sends us a lobby mission info, when it's good and ready
	  debugf("FM_S_NEW_MISSION id:%d cookie:%d\n",pfmNewMissionAck->dwIGCMissionID,pfmNewMissionAck->dwCookie);
    }
    break;

    case FM_LS_LOBBYMISSIONINFO:
    {
      CASTPFM(pfmLobbyMissionInfo, LS, LOBBYMISSIONINFO, pfm);
      CFLMission * pMission = CFLMission::FromCookie(pfmLobbyMissionInfo->dwCookie);
      if (pMission) // if it's already gone away--just ignore it. 
      {		  
		  //Imago 6/26/08
		  //Moved this code inside the mission check
		  //now the lobby does not crash trying to find a disconnected server's IP


			//KGJV #114 - server didnt fill szServerAddr but only reserved the bits. We fill it here.
			debugf("FM_LS_LOBBYMISSIONINFO:%d (pmission:%x cookie:%x) sent cookie:%x connected?%i\n",pfmLobbyMissionInfo->dwPort,pMission,pfmLobbyMissionInfo->dwCookie,pfmLobbyMissionInfo->dwCookie,(pthis->IsConnected()) ? 1 : 0);  
			char szAddr[16];
			pthis->GetIPAddress(cnxnFrom, szAddr); // get the real addr
			debugf("\tFM_LS_LOBBYMISSIONINFO:%s sent port %d\n",&szAddr,pfmLobbyMissionInfo->dwPort);		
			char *pfmdata = FM_VAR_REF(pfmLobbyMissionInfo, szServerAddr); // get the addr in the message	  
			Strcpy(pfmdata,szAddr); // overwrite with the real addr

			//end move code

        pMission->SetLobbyInfo(pfmLobbyMissionInfo);
        pMission->NotifyCreator();
      }
      // else TODO: do something about waiting client, if there is one
    }
    break;

    case FM_LS_MISSION_GONE:
    {
      CASTPFM(pfmMissionGone, LS, MISSION_GONE, pfm);
      CFLMission * pMission = CFLMission::FromCookie(pfmMissionGone->dwCookie);
	  debugf("deleting GONE mission: %x\n",pfmMissionGone->dwCookie);
      pServer->DeleteMission(pMission);
    }
    break;

    case FM_S_HEARTBEAT:
      // don't boot for missing roll call until we get one from them
      pServer->SetHere();
    break;
    
    case FM_S_PLAYER_JOINED:
    {
      CASTPFM(pfmPlayerJoined, S, PLAYER_JOINED, pfm);
      CFLMission * pMission = CFLMission::FromCookie(pfmPlayerJoined->dwMissionCookie);
      const char* szCharacterName = FM_VAR_REF(pfmPlayerJoined, szCharacterName);
      const char* szCDKey = FM_VAR_REF(pfmPlayerJoined, szCDKey);

      if (NULL == szCharacterName || '\0' != szCharacterName[pfmPlayerJoined->cbszCharacterName-1])
          /* || NULL == szCDKey || '\0' != szCDKey[pfmPlayerJoined->cbszCDKey-1]  
		  Imago 6/25/08 removed above
		  */ 
      {
        // corrupt data
        g_pLobbyApp->GetSite()->LogEvent(EVENTLOG_ERROR_TYPE, LE_CorruptPlayerJoinMsg,
          cnxnFrom.GetName());
      }
      else if (NULL == pMission)
      {
        // the requested game does not exist
        g_pLobbyApp->GetSite()->LogEvent(EVENTLOG_WARNING_TYPE, LE_PlayerJoinInvalidMission,
          szCharacterName, cnxnFrom.GetName(), pfmPlayerJoined->dwMissionCookie);
      }
      else
      {
        if (g_pLobbyApp->EnforceCDKey())
        {
          char * szUnencryptedCDKey = (char*)_alloca(strlen(szCDKey) + 1);
          ZUnscramble(szUnencryptedCDKey, szCDKey, szCharacterName);

          szCDKey = szUnencryptedCDKey;
        }

        g_pLobbyApp->SetPlayerMission(szCharacterName, szCDKey, pMission);
      }
    }
    break;

    case FM_S_PLAYER_QUIT:
    {
      CASTPFM(pfmPlayerQuit, S, PLAYER_QUIT, pfm);
      CFLMission * pMission = CFLMission::FromCookie(pfmPlayerQuit->dwMissionCookie);
      const char* szCharacterName = FM_VAR_REF(pfmPlayerQuit, szCharacterName);

      if (NULL == szCharacterName || '\0' != szCharacterName[pfmPlayerQuit->cbszCharacterName-1])
      {
        // corrupt data
        g_pLobbyApp->GetSite()->LogEvent(EVENTLOG_ERROR_TYPE, LE_CorruptPlayerQuitMsg,
          cnxnFrom.GetName());
      }
      else
        g_pLobbyApp->RemovePlayerFromMission(szCharacterName, pMission);
    }
    break;

    case FM_S_PAUSE:
    {
      CASTPFM(pfmPause, S, PAUSE, pfm);
      pServer->Pause(pfmPause->fPause);
	  // KGJV #114 cant create game on paused server
      g_pLobbyApp->BuildStaticCoreInfo();
      break;
    }      

    default:
      ZError("unknown message\n");
  }
  return S_OK;
}
//This should only be called from the ChangeCluster() callback.
void CFSPlayer::SetCluster(IclusterIGC* pcluster, bool bViewOnly)
{
  CFSShip::SetCluster(pcluster, bViewOnly);

  if (pcluster)
  {
    SetDPGroup((CFSCluster*)(pcluster->GetPrivateData()), true);

    IshipIGC*   pshipParent = GetIGCShip()->GetParentShip();
    if ((pshipParent == NULL) || bViewOnly)
    {
        ShipID      shipID = GetIGCShip()->GetObjectID();
        assert(0 == g.fm.CbUsedSpaceInOutbox());
        if (!bViewOnly)
        {
            //Move the player to his destination
            BEGIN_PFM_CREATE(g.fm, pfmSetCluster, S, SET_CLUSTER)
            END_PFM_CREATE
            pfmSetCluster->sectorID = pcluster->GetObjectID();

            //Send the position of the parent ship if we are a child, otherwise our position
            IshipIGC*   pshipSource = pshipParent ? pshipParent : GetIGCShip();
            pshipSource->ExportShipUpdate(&(pfmSetCluster->shipupdate));
            pfmSetCluster->cookie = NewCookie();
        }

        {
            for (ShipLinkIGC*   pshiplink = pcluster->GetShips()->first(); pshiplink; pshiplink = pshiplink->next())
            {
                IshipIGC * pshipExist = pshiplink->data();
                if ((pshipExist != GetIGCShip()) && (pshipExist != pshipParent))
                {
                  IshipIGC*   pshipExistParent = pshipExist->GetParentShip();

                  //Tell the new player where the existing ship is/was
                  //provided the existing ship is not the child of some other ship
                  //and is not the parent of the new ship
                  if (pshipExistParent == NULL) 
                  {
                    CFSShip * pfsShipExist = (CFSShip *) pshipExist->GetPrivateData();

                    pfsShipExist->QueueLoadoutChange();

                    BEGIN_PFM_CREATE(g.fm, pfmSSU, S, SINGLE_SHIP_UPDATE)
                    END_PFM_CREATE

                    //Always use the ship update based on the server's current view of the universe
                    //(this shouldn't be a lot worse than anything the player sent and it is easier)
                    pshipExist->ExportShipUpdate(&(pfmSSU->shipupdate));

                    {
                        ImodelIGC*  pmodelTarget = pshipExist->GetCommandTarget(c_cmdCurrent);
                        if (pmodelTarget)
                        {
                            pfmSSU->otTarget = pmodelTarget->GetObjectType();
                            pfmSSU->oidTarget = pmodelTarget->GetObjectID();
                        }
                        else
                        {
                            pfmSSU->otTarget = NA;
                            pfmSSU->oidTarget = NA;
                        }                    
                    }
                    pfmSSU->bIsRipcording = pshipExist->fRipcordActive();
                  }
                }
            }
        }

        {
            // Let's build up a list of station updates so we can batch 'em down
            IsideIGC* pside = GetIGCShip()->GetSide();

            {
                const StationListIGC * pstnlist = pcluster->GetStations();
                int nStations = 0;
                {
                    //Count the number of visible stations
                    for (StationLinkIGC* pstnlink = pstnlist->first(); pstnlink; pstnlink = pstnlink->next())
                    {
                        IstationIGC*  pstation = pstnlink->data();
                        if (pstation->SeenBySide(pside))
                            nStations++;
                    }
                }

                if (nStations != 0)
                {
                    // tell the client what happened
                    BEGIN_PFM_CREATE(g.fm, pfmStationsUpdate, S, STATIONS_UPDATE)
                      FM_VAR_PARM(NULL, nStations * sizeof(StationState))
                    END_PFM_CREATE

                    StationState* pss = (StationState*)(FM_VAR_REF(pfmStationsUpdate, rgStationStates));
                    for (StationLinkIGC* pstnlink = pstnlist->first(); pstnlink; pstnlink = pstnlink->next())
                    {
                        IstationIGC * pstation = pstnlink->data();
                        if (pstation->SeenBySide(pside))
                        {
                            pss->stationID            = pstation->GetObjectID();
                            pss->bpHullFraction       = pstation->GetFraction();
                            (pss++)->bpShieldFraction = pstation->GetShieldFraction();
                        }
                    }
                }
            }

            {
                //Let's build up a list of probe updates and batch them on down (only damage & visible probes)
                const ProbeListIGC * pprblist = pcluster->GetProbes();
                int nProbes = 0;
                {
                    for (ProbeLinkIGC* pprblink = pprblist->first(); pprblink; pprblink = pprblink->next())
                    {
                        if (pprblink->data()->SeenBySide(pside))
                            nProbes++;
                    }
                }

                if (nProbes != 0)
                {
                    BEGIN_PFM_CREATE(g.fm, pfmProbesUpdate, S, PROBES_UPDATE)
                      FM_VAR_PARM(NULL, nProbes * sizeof(ProbeState))
                    END_PFM_CREATE

                    ProbeState* pps = (ProbeState*)(FM_VAR_REF(pfmProbesUpdate, rgProbeStates));
                    for (ProbeLinkIGC* pprblink = pprblist->first(); pprblink; pprblink = pprblink->next())
                    {
                        IprobeIGC * pprobe = pprblink->data();

                        if (pprobe->SeenBySide(pside))
                        {
                            pps->probeID        = pprobe->GetObjectID();
                            (pps++)->bpFraction = pprobe->GetFraction();
                        }
                    }
                }
            }

            {
                //Let's build up a list of asteroid updates and batch them on down
                const AsteroidListIGC * pastlist = pcluster->GetAsteroids();
                int nAsteroids = 0;
                {
                    for (AsteroidLinkIGC* pastlink = pastlist->first(); pastlink; pastlink = pastlink->next())
                    {
                        if (pastlink->data()->SeenBySide(pside))
                            nAsteroids++;
                    }
                }

                if (nAsteroids != 0)
                {
                    BEGIN_PFM_CREATE(g.fm, pfmAsteroidsUpdate, S, ASTEROIDS_UPDATE)
                      FM_VAR_PARM(NULL, nAsteroids * sizeof(AsteroidState))
                    END_PFM_CREATE

                    AsteroidState* pas = (AsteroidState*)(FM_VAR_REF(pfmAsteroidsUpdate, rgAsteroidStates));
                    for (AsteroidLinkIGC* pastlink = pastlist->first(); pastlink; pastlink = pastlink->next())
                    {
                        IasteroidIGC * pasteroid = pastlink->data();

                        if (pasteroid->SeenBySide(pside))
                        {
                            pas->asteroidID         = pasteroid->GetObjectID();
                            pas->ore                = short(pasteroid->GetOre());
                            pas->co.Set(pasteroid->GetOrientation());
                            (pas++)->bpFraction     = pasteroid->GetFraction();
                        }
                    }
                }
            }
        }
    
        //Also send the identical message to all of the ship's children]
		if (!bViewOnly) //TheRock 4-1-2010 fixed ships overlaying in f3 while on a turret
        {
            for (ShipLinkIGC*   psl = GetIGCShip()->GetChildShips()->first(); (psl != NULL); psl = psl->next())
            {
                CFSShip*    pfsShip = (CFSShip*)(psl->data()->GetPrivateData());
                assert (pfsShip->IsPlayer());
                pfsShip->GetPlayer()->ResetLastUpdate();
                g.fm.SendMessages(pfsShip->GetPlayer()->GetConnection(), FM_GUARANTEED, FM_DONT_FLUSH);
            }
        }
        g.fm.SendMessages(GetConnection(), FM_GUARANTEED, FM_FLUSH);
    }
  }
  else if (bViewOnly)
  {
    IstationIGC*    pstation = GetIGCShip()->GetStation();
    assert (pstation);

    CFSCluster*     pfsCluster = (CFSCluster*)(pstation->GetCluster()->GetPrivateData());
    SetDPGroup(pfsCluster, false);
  }
  else
    SetDPGroup(NULL, false);
}
Esempio n. 16
0
HRESULT FedSrvLobbySite::OnAppMessage(FedMessaging * pthis, CFMConnection & cnxnFrom, FEDMESSAGE * pfm)
{
	HRESULT hr = S_OK;
	assert(&g.fmLobby == pthis);

	static CTempTimer timerOnAppMessage("in FedSrvLobbySite::OnAppMessage", .02f);
	timerOnAppMessage.Start();

	switch (pfm->fmid)
	{
		// KGJV #114 - reactivate create mission
	  //#if !defined(ALLSRV_STANDALONE)
	case FM_L_CREATE_MISSION_REQ:
	{
#if !defined(SRV_CHILD)
		CASTPFM(pfmCreateMissionReq, L, CREATE_MISSION_REQ, pfm);
		MissionParams mp;
		Strcpy(mp.strGameName, ZString(FM_VAR_REF(pfmCreateMissionReq, GameName)));// + "'s game");
		Strcpy(mp.szIGCStaticFile, ZString(FM_VAR_REF(pfmCreateMissionReq, IGCStaticFile)));
		mp.bScoresCount = false;// dont set to true till clients can change this!
		mp.iMaxImbalance = 0x7ffe;// added
		assert(!mp.Invalid());
#endif

		//Imago - give birth right here, feed it and off it goes...

#if defined(SRV_PARENT)
		//start missions as thier own process
		STARTUPINFO si;
		PROCESS_INFORMATION pi;
		ZeroMemory(&si, sizeof(si));
		si.cb = sizeof(si);
		ZeroMemory(&pi, sizeof(pi));
		char szCmd[255]; char szName[32]; char szFile[32];
		ZString strName = mp.strGameName;
		ZString strFile = mp.szIGCStaticFile;
		si.lpTitle = mp.strGameName;
		Strcpy(szName, (PCC)strName);
		Strcpy(szFile, (PCC)strFile);
		sprintf(szCmd, "AllSrv.exe \"%s\" %s %x", szName, szFile, pfmCreateMissionReq->dwCookie);

		// Create a NULL dacl to give "everyone" access
		SECURITY_DESCRIPTOR sd;
		SECURITY_ATTRIBUTES sa = { sizeof(sa), &sd, false };
		InitializeSecurityDescriptor(&sd, SECURITY_DESCRIPTOR_REVISION);
		SetSecurityDescriptorDacl(&sd, true, NULL, FALSE);

		if (!CreateProcess(
			NULL,                   // No module name (use command line). 
			szCmd,
			NULL,
			NULL,
			FALSE,                  // Set handle inheritance to FALSE. 
			CREATE_NEW_PROCESS_GROUP | CREATE_NEW_CONSOLE, // we're destined to do amazing things
			NULL,                   // Use parent's environment block. 
			NULL,                   // Use parent's starting directory. 
			&si,                    // Pointer to STARTUPINFO structure.
			&pi)                   // Pointer to PROCESS_INFORMATION structure.
			)
		{
			debugf("CreateProcess failed (%d).\n", GetLastError());
		}

		// check to make sure the child is ready before restart
		char strFilename[10] = "\0";
		sprintf(strFilename, "%d.pid", pi.dwProcessId);
		HANDLE hFile = (HANDLE)CreateFile(strFilename, 0, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_FLAG_NO_BUFFERING, NULL);
		DWORD dwError = GetLastError();
		int i = 0;
		while (hFile == INVALID_HANDLE_VALUE || dwError == ERROR_FILE_NOT_FOUND) {
			if (i >= 14) //30s
				break;

			Sleep(2500);
			hFile = (HANDLE)CreateFile(strFilename, 0, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_FLAG_NO_BUFFERING, NULL);
			dwError = GetLastError();
			i++;
		}
		_Module.AddPID(pi.dwProcessId);
		CloseHandle(hFile);
		CloseHandle(pi.hProcess);
		CloseHandle(pi.hThread);
		g.bRestarting = true;
		PostQuitMessage(0);

#endif 

#if !defined(SRV_CHILD)
#if !defined(SRV_PARENT)
		// pkk 2011-07-24 - Create games only with IGCs from cores.txt
		bool ValidCore = false;
		for (int i = 0; i < g.cStaticCoreInfo; i++)
		{
			if (!strcmpi(mp.szIGCStaticFile, g.vStaticCoreInfo[i].cbIGCFile))
			{
				ValidCore = true;
				break; // quit loop
			}
		}
		if (ValidCore == true)
		{
			//Imago - start the mission in this thread as usual 
			FedSrvSite * psiteFedSrv = new FedSrvSite();
			CFSMission * pfsMissionNew = new CFSMission(mp, "", psiteFedSrv, psiteFedSrv, NULL, NULL);
			pfsMissionNew->SetCookie(pfmCreateMissionReq->dwCookie);
		}
		else
		{
			debugf("Lobby sent invalid core information %s, ignoring message\n", mp.szIGCStaticFile);
		}
		// pkk end
#endif
#endif
	} //Imago 6/22/08
	break;
	//#endif -- reactivate create mission

	case FM_L_NEW_MISSION_ACK:
	{
		CASTPFM(pfmNewMissionAck, L, NEW_MISSION_ACK, pfm);
		CFSMission * pfsm = CFSMission::GetMissionFromIGCMissionID(pfmNewMissionAck->dwIGCMissionID);
		if (pfsm)
		{
			pfsm->SetCookie(pfmNewMissionAck->dwCookie);
			// If we already have players (e.g. reconnect), tell the lobby who's in the game
			const ShipListIGC * plistShip = pfsm->GetIGCMission()->GetShips();
			for (ShipLinkIGC * plinkShip = plistShip->first(); plinkShip; plinkShip = plinkShip->next())
			{
				IshipIGC * pShip = plinkShip->data();
				CFSShip * pfsShip = GETFSSHIP(pShip);
				if (pfsShip->IsPlayer() && !pShip->IsGhost())
				{
					CFSPlayer* pfsPlayer = pfsShip->GetPlayer();
					BEGIN_PFM_CREATE(g.fmLobby, pfmPlayerJoined, S, PLAYER_JOINED)
						FM_VAR_PARM(pfsPlayer->GetName(), CB_ZTS)
						END_PFM_CREATE
						pfmPlayerJoined->dwMissionCookie = pfsm->GetCookie();
				}
			}
			HRESULT hr = pthis->SendMessages(pthis->GetServerConnection(), FM_GUARANTEED, FM_FLUSH);
		}
	}
	break;

	case FM_L_TOKEN:
	{
		CASTPFM(pfmToken, L, TOKEN, pfm);
		Strcpy(g.m_szToken, FM_VAR_REF(pfmToken, Token));
	}
	break;

	case FM_L_REMOVE_PLAYER:
	{
		CASTPFM(pfmRemovePlayer, L, REMOVE_PLAYER, pfm);
		CFSMission * pfsMission = CFSMission::GetMission(pfmRemovePlayer->dwMissionCookie);
		const char* szCharacterName = FM_VAR_REF(pfmRemovePlayer, szCharacterName);
		const char* szMessageParam = FM_VAR_REF(pfmRemovePlayer, szMessageParam);

		// try to find the player in question
		if (!pfsMission)
		{
			debugf("Asked to boot character %s from mission %x by lobby, "
				"but the mission was not found.\n",
				szCharacterName, pfmRemovePlayer->dwMissionCookie);
		}
		else if (!pfsMission->RemovePlayerByName(szCharacterName,
			(pfmRemovePlayer->reason == RPR_duplicateCDKey) ? QSR_DuplicateCDKey : QSR_DuplicateRemoteLogon,
			szMessageParam))
		{
			debugf("Asked to boot character %s from mission %x by lobby, "
				"but the character was not found.\n",
				szCharacterName, pfmRemovePlayer->dwMissionCookie);
		}
	}
	break;

	case FM_L_LOGON_SERVER_NACK:
	{
		char * szReason;

		CASTPFM(pfmLogonNack, L, LOGON_SERVER_NACK, pfm);

		szReason = FM_VAR_REF(pfmLogonNack, Reason);

		OnMessageBox(pthis, szReason ? szReason : "Error while try to log onto server.", "Allegiance Server Error", MB_SERVICE_NOTIFICATION);
		// TODO: consider firing out an event message
		PostQuitMessage(-1);
	}

	// BT - 12/21/2010 ACSS - The lobby server will relay the rank details back to the game server.
	case FM_LS_PLAYER_RANK:
	{
		CQLogonStats * pquery = new CQLogonStats(GotLogonDetails);
		CQLogonStatsData * pqd = pquery->GetData();

		CASTPFM(pfmPlayerRank, LS, PLAYER_RANK, pfm);

		Strcpy(pqd->szCDKey, FM_VAR_REF(pfmPlayerRank, szCDKey));
		Strcpy(pqd->szCharacterName, FM_VAR_REF(pfmPlayerRank, szCharacterName));
		Strcpy(pqd->szPassword, FM_VAR_REF(pfmPlayerRank, szPassword));
		Strcpy(pqd->szReason, FM_VAR_REF(pfmPlayerRank, szReason));

		pqd->characterID = pfmPlayerRank->characterID;
		pqd->fCanCheat = pfmPlayerRank->fCanCheat;
		pqd->fRetry = pfmPlayerRank->fRetry;
		pqd->dwCookie = pfmPlayerRank->dwCookie;
		pqd->fValid = pfmPlayerRank->fValid;
		pqd->dwConnectionID = pfmPlayerRank->dwConnectionID;

		pqd->rank = pfmPlayerRank->rank;
		pqd->sigma = pfmPlayerRank->sigma;
		pqd->mu = pfmPlayerRank->mu;
		pqd->commandRank = pfmPlayerRank->commandRank;
		pqd->commandSigma = pfmPlayerRank->commandSigma;
		pqd->commandMu = pfmPlayerRank->commandMu;

		PostThreadMessage(g.idReceiveThread, wm_sql_querydone, (WPARAM)NULL, (LPARAM)pquery);
		break;
	}

	break;
	}

	timerOnAppMessage.Stop("...for message type %s\n", g_rgszMsgNames[pfm->fmid]);
	return hr;
}
Esempio n. 17
0
void CLobbyApp::SetPlayerMission(const char* szPlayerName, const char* szCDKey, CFLMission* pMission, const char* szAddress)
{

	debugf("SetPlayerMission(): Setting player mission for: %s, CDKey: %s", szPlayerName, szCDKey);

  ZString strPlayerName = szPlayerName;
  ZString strCDKey = szCDKey;
  ZString strAddress = szAddress;

  // boot any old copies of this player
#ifdef USECLUB
  BootPlayersByName(strPlayerName);
#endif

  // BT - 7/15 - CSS Integration
  if (IsCssAuthenticationEnabled() == true)
  {
	  // BT - 9/11/2010 - Readding CD Key Auth on player join to the Allegiance server.
	int resultMessageLength = 1024;
	char resultMessage[1024];

	debugf("SetPlayerMission(): checking valid key for: %s, cdKey: %s, IP: %s\r\n", szPlayerName, szCDKey, szAddress);

	bool cdKeyIsValid = true; //CDKeyIsValid(szPlayerName, szCDKey, szAddress, resultMessage, resultMessageLength);

	debugf("SetPlayerMission(): keycheck for: %s, key: %s, address: %s, result: %s, succeeded: %s\r\n", szPlayerName, szCDKey, szAddress, resultMessage, (cdKeyIsValid == true) ? "true" : "false");

    if (cdKeyIsValid == false)
    {
      BEGIN_PFM_CREATE(m_fmServers, pfmRemovePlayer, L, REMOVE_PLAYER)
        FM_VAR_PARM(szPlayerName, CB_ZTS)
		FM_VAR_PARM(resultMessage, CB_ZTS)
      END_PFM_CREATE
      pfmRemovePlayer->dwMissionCookie = pMission->GetCookie();
      pfmRemovePlayer->reason = RPR_duplicateCDKey;    
      m_fmServers.SendMessages(pMission->GetServer()->GetConnection(), 
        FM_GUARANTEED, FM_FLUSH);
      GetSite()->LogEvent(EVENTLOG_WARNING_TYPE, LE_BadCDKey, szCDKey,
          pMission->GetServer()->GetConnection()->GetName(), szPlayerName);
    }
    else // BT - 9/11/2010 - End.
	{
		ZString strOldPlayer;

		if (BootPlayersByCDKey(strCDKey, szPlayerName, strOldPlayer))
		{
		  BEGIN_PFM_CREATE(m_fmServers, pfmRemovePlayer, L, REMOVE_PLAYER)
			FM_VAR_PARM(szPlayerName, CB_ZTS)
			FM_VAR_PARM((PCC)strOldPlayer, CB_ZTS)
		  END_PFM_CREATE
		  pfmRemovePlayer->dwMissionCookie = pMission->GetCookie();
		  pfmRemovePlayer->reason = RPR_duplicateCDKey;    
		  m_fmServers.SendMessages(pMission->GetServer()->GetConnection(), 
			FM_GUARANTEED, FM_FLUSH);
		}
	}
  }

  // create a new player by creating entries in the maps
  PlayerByCDKey::iterator iterPlayerByCDKey = 
      m_playerByCDKey.insert(PlayerByCDKey::value_type(strCDKey, PlayerLocInfo(strPlayerName, pMission)));
  m_playerByName.insert(PlayerByName::value_type(strPlayerName, iterPlayerByCDKey));

  pMission->AddPlayer();
}
Esempio n. 18
0
/*-------------------------------------------------------------------------
 * CAdminGames::Add()
 *-------------------------------------------------------------------------
 * Purpose:
 *   Add to the collection of Games
 *
 * Parameters:
 *   pGameParameters: a pointer to a CGameParameters interface.
 *                        This houses the mission params.
 *
 */
	STDMETHODIMP CAdminGames::Add(IAGCGameParameters* pGameParameters)
{
	if (!pGameParameters)
		return Error("Creation Parameters was Null");

	// Cannot create a game on a paused server
	if (!g.strLobbyServer.IsEmpty() && !g.fmLobby.IsConnected())
		return Error(IDS_E_GAME_SERVER_PAUSED, IID_IAdminGames);

	IAGCPrivatePtr spPrivate(pGameParameters);
	assert(NULL != spPrivate);

	CGameParamData * pMissionParams = (CGameParamData *)spPrivate->GetIGCVoid();
	assert(pMissionParams);

#if defined(ALLSRV_STANDALONE)
	// Standalone server only supports a single game
	const ListFSMission * plistMission = CFSMission::GetMissions();
	if (plistMission->n())
		return Error(IDS_E_ONE_GAME_PER_SERVER, IID_IAdminGames);

	// Standalone server only support a maximum of c_cMaxPlayersPerGame players total
	if (pMissionParams->nTotalMaxPlayersPerGame > c_cMaxPlayersPerGame)
		pMissionParams->nTotalMaxPlayersPerGame = c_cMaxPlayersPerGame;

	// Standalone games always have a min players per team of 1 and max 
	// players per team of maxPlayerPerGame / nTeams.
	// XXX Note that the training mission #7 uses the server with a
	// XXX nTotalMaxPlayers setting of 1, and we need to handle that.
	pMissionParams->nMinPlayersPerTeam = 1;
	if (pMissionParams->nTotalMaxPlayersPerGame == 1)
		pMissionParams->nMaxPlayersPerTeam = 1;
	else
		pMissionParams->nMaxPlayersPerTeam = pMissionParams->nTotalMaxPlayersPerGame / pMissionParams->nTeams;
#else
	// The maximum players per side must be no more than max per game / nTeams
	if (pMissionParams->nMaxPlayersPerTeam > pMissionParams->nTotalMaxPlayersPerGame / pMissionParams->nTeams)
		pMissionParams->nMaxPlayersPerTeam = pMissionParams->nTotalMaxPlayersPerGame / pMissionParams->nTeams;
	if (pMissionParams->nMinPlayersPerTeam > pMissionParams->nMaxPlayersPerTeam)
		pMissionParams->nMinPlayersPerTeam = pMissionParams->nMaxPlayersPerTeam;
#endif // defined(ALLSRV_STANDALONE)

	// make sure params are valid, if not tell user why
	const char * szInvalid = pMissionParams->Invalid();
	if (szInvalid)
		return Error(szInvalid);

	// Creation through this method always indicates object model created
	// KGJV : hack fix for AllSrvUI created game
	// since bObjectModelCreated isnt exposed thru the AGC interface we use bAllowEmptyTeams
	// so if bAllowEmptyTeams, game will be like a player created game
	pMissionParams->bObjectModelCreated = !pMissionParams->bAllowEmptyTeams;

	// Get the story text of the specified AGCGameParameters object
	CComBSTR bstrStoryText;
	RETURN_FAILED(pGameParameters->get_StoryText(&bstrStoryText));
	USES_CONVERSION;
	const char* pszStoryText = bstrStoryText.Length() ? OLE2CA(bstrStoryText) : NULL;

	//
	// Create a new mission first
	//
	FedSrvSite * psiteFedSrv = new FedSrvSite();
	CFSMission * pfsMissionNew = new CFSMission(*pMissionParams,
		NULL, // NULL means use description in the params
		psiteFedSrv,
		psiteFedSrv,
		pMissionParams,
		pszStoryText);
	if (g.fmLobby.IsConnected())
	{
		BEGIN_PFM_CREATE(g.fmLobby, pfmNewMission, S, NEW_MISSION)
			END_PFM_CREATE
			pfmNewMission->dwIGCMissionID = pfsMissionNew->GetIGCMission()->GetMissionID();

		g.fmLobby.SendMessages(g.fmLobby.GetServerConnection(), FM_GUARANTEED, FM_FLUSH);
	}
	return S_OK;
}
void CFSPlayer::SetAutoDonate(CFSPlayer* pplayer, Money amount, bool bSend)
{
  assert (pplayer != this);

  ShipID    sidDonateBy = GetShipID();
  ShipID    sidDonateTo;

  IshipIGC* pship;
  if (pplayer)
  {
      pship = pplayer->GetIGCShip()->GetAutoDonate();
      if (pship == NULL)
          pship = pplayer->GetIGCShip();
      else
      {
          assert (pship->GetAutoDonate() == NULL);

          CFSPlayer*    pplayerNew = ((CFSShip*)(pship->GetPrivateData()))->GetPlayer();

          if (pplayerNew == this)
          {
              //We are trying to autodonate to someone who is already autodonating to us
              //Tell them to stop first (but don't send any messages)
              pplayer->SetAutoDonate(NULL, 0, false);

              //and then set our autodonate to go to them anyhow
              pship = pplayer->GetIGCShip();
          }
          else
          {
              //The person we would like to donate to was already donating to someone else
              //donate to who ever they were donating to.
              pplayer = pplayerNew;
          }
      }

      assert (pship->GetAutoDonate() == NULL);
      assert (pplayer->GetIGCShip() == pship);

      sidDonateTo = pship->GetObjectID();

      if (amount != 0)
      {
          TrapHack(GetMoney() >= amount);
          pplayer->SetMoney(amount + pplayer->GetMoney());
          SetMoney(GetMoney() - amount);
      }
  }
  else
  {
      pship = NULL;
      sidDonateTo = NA;
  }

  GetIGCShip()->SetAutoDonate(pship);

  BEGIN_PFM_CREATE(g.fm, pfmAD, S, AUTODONATE)
  END_PFM_CREATE
  pfmAD->sidDonateBy = sidDonateBy;
  pfmAD->sidDonateTo = sidDonateTo;
  pfmAD->amount = amount;

  if (bSend)
    g.fm.SendMessages(CFSSide::FromIGC(GetSide())->GetGroup(), FM_GUARANTEED, FM_FLUSH);
}
Esempio n. 20
0
    bool OnButtonTeleport()
    {
        ImodelIGC* pDestination = (ImodelIGC*)(m_plistPaneDestinations->GetSelection());
        IstationIGC* pstation = NULL;

        if (pDestination == NULL || trekClient.MyMission() == NULL 
            || trekClient.GetShip()->GetCluster() != NULL)
            return true;


        if (pDestination->GetObjectType() == OT_ship)
        {
            // if this is a ship, try boarding it.
            IshipIGC* pship;
            CastTo(pship, pDestination);

            if (trekClient.GetShip()->GetParentShip() != NULL)
            {
                trekClient.DisembarkAndBoard(pship);
            }
            else
            {
                trekClient.BoardShip(pship);
            }
            trekClient.PlaySoundEffect(personalJumpSound);
        }
        else
        {
            // try teleporting to that station
            IstationIGC* pstation;
            CastTo(pstation, pDestination);

            if (trekClient.GetShip()->GetParentShip() != NULL)
            {
                // if they are already there, just get off of the ship
                if (pstation == trekClient.GetShip()->GetParentShip()->GetStation())
                {
                    trekClient.BoardShip(NULL);
                }
                else
                {
                    trekClient.DisembarkAndTeleport(pstation);
                }
            }
            else
            {
                if (pstation != trekClient.GetShip()->GetStation())
                {
                    trekClient.SetMessageType(BaseClient::c_mtGuaranteed);
                    BEGIN_PFM_CREATE(trekClient.m_fm, pfmDocked, C, DOCKED)
                    END_PFM_CREATE

                    pfmDocked->stationID = pstation->GetObjectID();

                    trekClient.StartLockDown(
                        "Teleporting to " + ZString(pstation->GetName()) + "....", 
                        BaseClient::lockdownTeleporting);
                }
            }
        }

        // dismiss the teleport pane.
        GetWindow()->TurnOffOverlayFlags(ofTeleportPane);

        return true;
    }