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 ()
 

Private Member Functions

bool Execute (int, pollfd *) override
 
void Set ()
 
void SetDelay (uint32_t inDelay)
 
bool CheckAndReset ()
 
C4TimeMilliseconds GetNextTick (C4TimeMilliseconds tNow) override
 
uint32_t TimerInterval () override
 
void Changed ()
 
bool ExecuteUntil (int iTimeout=-1)
 
virtual void GetFDs (std::vector< struct pollfd > &)
 
bool IsSignaled ()
 
virtual bool IsLowPriority ()
 
virtual bool IsNotify ()
 

Detailed Description

Definition at line 168 of file C4GameLobby.h.

Constructor & Destructor Documentation

◆ Countdown()

C4GameLobby::Countdown::Countdown ( int32_t  iStartTimer)

Definition at line 736 of file C4GameLobby.cpp.

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

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  }
bool BroadcastMsgToClients(const C4NetIOPacket &rPkt)
void OnCountdownPacket(const C4PacketCountdown &Pkt)
void Add(StdSchedulerProc *pProc)
C4Network2 Network
Definition: C4Globals.cpp:53
C4NetIOPacket MkC4NetIOPacket(char cStatus, const class C4PacketBase &Pkt, const C4NetIO::addr_t &addr=C4NetIO::addr_t())
Definition: C4PacketBase.h:40
class C4GameLobby::MainDlg * GetLobby() const
Definition: C4Network2.h:216
C4Network2ClientList Clients
Definition: C4Network2.h:116
bool isHost() const
Definition: C4Network2.h:209
bool Log(const char *szMessage)
Definition: C4Log.cpp:202
C4Application Application
Definition: C4Globals.cpp:44
Here is the call graph for this function:

◆ ~Countdown()

C4GameLobby::Countdown::~Countdown ( )
override

Definition at line 759 of file C4GameLobby.cpp.

References Application, and StdScheduler::Remove().

760  {
761  // release timer
762  Application.Remove(this);
763  }
void Remove(StdSchedulerProc *pProc)
C4Application Application
Definition: C4Globals.cpp:44
Here is the call graph for this function:

Member Function Documentation

◆ Abort()

void C4GameLobby::Countdown::Abort ( )

Definition at line 804 of file C4GameLobby.cpp.

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

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  }
bool BroadcastMsgToClients(const C4NetIOPacket &rPkt)
void OnCountdownPacket(const C4PacketCountdown &Pkt)
const char * LoadResStr(const char *id)
Definition: C4Language.h:83
C4Network2 Network
Definition: C4Globals.cpp:53
C4NetIOPacket MkC4NetIOPacket(char cStatus, const class C4PacketBase &Pkt, const C4NetIO::addr_t &addr=C4NetIO::addr_t())
Definition: C4PacketBase.h:40
class C4GameLobby::MainDlg * GetLobby() const
Definition: C4Network2.h:216
C4Network2ClientList Clients
Definition: C4Network2.h:116
bool isHost() const
Definition: C4Network2.h:209
bool Log(const char *szMessage)
Definition: C4Log.cpp:202
Here is the call graph for this function:

◆ OnSec1Timer()

void C4GameLobby::Countdown::OnSec1Timer ( )
overridevirtual

Implements C4ApplicationSec1Timer.

Definition at line 765 of file C4GameLobby.cpp.

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().

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  }
bool Start()
Definition: C4Network2.cpp:505
C4Game Game
Definition: C4Globals.cpp:52
C4Scenario C4S
Definition: C4Game.h:74
bool BroadcastMsgToClients(const C4NetIOPacket &rPkt)
void OnCountdownPacket(const C4PacketCountdown &Pkt)
int32_t GetMinPlayer()
Definition: C4Scenario.cpp:141
const char * LoadResStr(const char *id)
Definition: C4Language.h:83
C4Network2 Network
Definition: C4Globals.cpp:53
C4NetIOPacket MkC4NetIOPacket(char cStatus, const class C4PacketBase &Pkt, const C4NetIO::addr_t &addr=C4NetIO::addr_t())
Definition: C4PacketBase.h:40
class C4GameLobby::MainDlg * GetLobby() const
Definition: C4Network2.h:216
void Quit() override
C4Network2ClientList Clients
Definition: C4Network2.h:116
C4PlayerInfoList & PlayerInfos
Definition: C4Game.h:71
bool Log(const char *szMessage)
Definition: C4Log.cpp:202
int32_t GetPlayerCount() const
C4Application Application
Definition: C4Globals.cpp:44
const int32_t AlmostStartCountdownTime
Definition: C4GameLobby.h:27
Here is the call graph for this function:

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