OpenClonk
C4GameLobby::Countdown Class Reference

#include <C4GameLobby.h>

Inheritance diagram for C4GameLobby::Countdown:
[legend]
Collaboration diagram for C4GameLobby::Countdown:
[legend]

Public Member Functions

void OnSec1Timer () override
 
 Countdown (int32_t iStartTimer)
 
 ~Countdown () override
 
void Abort ()
 

Detailed Description

Definition at line 166 of file C4GameLobby.h.

Constructor & Destructor Documentation

◆ Countdown()

C4GameLobby::Countdown::Countdown ( int32_t  iStartTimer)

Definition at line 736 of file C4GameLobby.cpp.

736  : iStartTimer(iStartTimer)
737  {
738  // only on network hosts
739  assert(::Network.isHost());
740  // ctor: Init; sends initial countdown packet
741  C4PacketCountdown pck(iStartTimer);
743  // also process on host
744  MainDlg *pLobby = ::Network.GetLobby();
745  if (pLobby)
746  {
747  pLobby->OnCountdownPacket(pck);
748  }
749  else
750  {
751  // no lobby: Message to log for dedicated/console hosts
752  Log(pck.GetCountdownMsg().getData());
753  }
754 
755  // init timer callback
756  Application.Add(this);
757  }
C4Application Application
Definition: C4Globals.cpp:44
C4Network2 Network
Definition: C4Globals.cpp:53
bool Log(const char *szMessage)
Definition: C4Log.cpp:204
C4NetIOPacket MkC4NetIOPacket(char cStatus, const class C4PacketBase &Pkt, const C4NetIO::addr_t &addr=C4NetIO::addr_t())
Definition: C4PacketBase.h:40
@ PID_LobbyCountdown
Definition: C4PacketBase.h:125
void OnCountdownPacket(const C4PacketCountdown &Pkt)
bool BroadcastMsgToClients(const C4NetIOPacket &rPkt)
class C4GameLobby::MainDlg * GetLobby() const
Definition: C4Network2.h:216
bool isHost() const
Definition: C4Network2.h:209
C4Network2ClientList Clients
Definition: C4Network2.h:116
void Add(StdSchedulerProc *pProc)

References StdScheduler::Add(), Application, C4Network2ClientList::BroadcastMsgToClients(), C4Network2::Clients, C4GameLobby::C4PacketCountdown::GetCountdownMsg(), StdStrBuf::getData(), C4Network2::GetLobby(), C4Network2::isHost(), Log(), MkC4NetIOPacket(), Network, C4GameLobby::MainDlg::OnCountdownPacket(), and PID_LobbyCountdown.

Here is the call graph for this function:

◆ ~Countdown()

C4GameLobby::Countdown::~Countdown ( )
override

Definition at line 759 of file C4GameLobby.cpp.

760  {
761  // release timer
762  Application.Remove(this);
763  }
void Remove(StdSchedulerProc *pProc)

References Application, and StdScheduler::Remove().

Here is the call graph for this function:

Member Function Documentation

◆ Abort()

void C4GameLobby::Countdown::Abort ( )

Definition at line 804 of file C4GameLobby.cpp.

805  {
806  // host sends packets
807  if (!::Network.isHost()) return;
808  C4PacketCountdown pck(C4PacketCountdown::Abort);
810  // also process on host
811  MainDlg *pLobby = ::Network.GetLobby();
812  if (pLobby)
813  {
814  pLobby->OnCountdownPacket(pck);
815  }
816  else
817  {
818  // no lobby: Message to log for dedicated/console hosts
819  Log(LoadResStr("IDS_PRC_STARTABORTED"));
820  }
821  }
const char * LoadResStr(const char *id)
Definition: C4Language.h:83

References C4GameLobby::C4PacketCountdown::Abort, C4Network2ClientList::BroadcastMsgToClients(), C4Network2::Clients, C4Network2::GetLobby(), C4Network2::isHost(), LoadResStr(), Log(), MkC4NetIOPacket(), Network, C4GameLobby::MainDlg::OnCountdownPacket(), and PID_LobbyCountdown.

Referenced by C4Network2::AbortLobbyCountdown().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ OnSec1Timer()

void C4GameLobby::Countdown::OnSec1Timer ( )
overridevirtual

Implements C4ApplicationSec1Timer.

Definition at line 765 of file C4GameLobby.cpp.

766  {
767  // count down
768  iStartTimer = std::max<int32_t>(iStartTimer - 1, 0);
769  // only send "important" start timer numbers to all clients
770  if (iStartTimer <= AlmostStartCountdownTime || // last seconds
771  (iStartTimer <= 600 && !(iStartTimer % 10)) || // last minute: 10s interval
772  !(iStartTimer % 60)) // otherwise, minute interval
773  {
774  C4PacketCountdown pck(iStartTimer);
776  // also process on host
777  MainDlg *pLobby = ::Network.GetLobby();
778  if (pLobby)
779  pLobby->OnCountdownPacket(pck);
780  else if (iStartTimer)
781  {
782  // no lobby: Message to log for dedicated/console hosts
783  Log(pck.GetCountdownMsg().getData());
784  }
785  }
786  // countdown done
787  if (!iStartTimer)
788  {
789 #ifdef USE_CONSOLE
790  // Dedicated server: if there are not enough players for this game, abort and quit the application
792  || ::Network.Clients.Count() <= 2)
793  {
794  Log(LoadResStr("IDS_MSG_NOTENOUGHPLAYERSFORTHISRO")); // it would also be nice to send this message to all clients...
795  Application.Quit();
796  }
797  // Start the game
798  else
799 #endif // USE_CONSOLE
800  ::Network.Start();
801  }
802  }
C4Game Game
Definition: C4Globals.cpp:52
void Quit() override
C4Scenario C4S
Definition: C4Game.h:74
C4PlayerInfoList & PlayerInfos
Definition: C4Game.h:71
bool Start()
Definition: C4Network2.cpp:506
int32_t GetPlayerCount() const
int32_t GetMinPlayer()
Definition: C4Scenario.cpp:141
const int32_t AlmostStartCountdownTime
Definition: C4GameLobby.h:27

References C4GameLobby::AlmostStartCountdownTime, Application, C4Network2ClientList::BroadcastMsgToClients(), C4Game::C4S, C4Network2::Clients, C4Network2ClientList::Count(), Game, C4GameLobby::C4PacketCountdown::GetCountdownMsg(), StdStrBuf::getData(), C4Network2::GetLobby(), C4Scenario::GetMinPlayer(), C4PlayerInfoList::GetPlayerCount(), LoadResStr(), Log(), MkC4NetIOPacket(), Network, C4GameLobby::MainDlg::OnCountdownPacket(), PID_LobbyCountdown, C4Game::PlayerInfos, C4Application::Quit(), and C4Network2::Start().

Here is the call graph for this function:

The documentation for this class was generated from the following files: