OpenClonk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
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

C4GameLobby::Countdown::Countdown ( int32_t  iStartTimer)

Definition at line 714 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.

714  : iStartTimer(iStartTimer)
715  {
716  // only on network hosts
717  assert(::Network.isHost());
718  // ctor: Init; sends initial countdown packet
719  C4PacketCountdown pck(iStartTimer);
721  // also process on host
722  MainDlg *pLobby = ::Network.GetLobby();
723  if (pLobby)
724  {
725  pLobby->OnCountdownPacket(pck);
726  }
727  else
728  {
729  // no lobby: Message to log for dedicated/console hosts
730  Log(pck.GetCountdownMsg().getData());
731  }
732 
733  // init timer callback
734  Application.Add(this);
735  }
class C4GameLobby::MainDlg * GetLobby() const
Definition: C4Network2.h:216
bool isHost() const
Definition: C4Network2.h:209
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
C4Network2ClientList Clients
Definition: C4Network2.h:116
bool Log(const char *szMessage)
Definition: C4Log.cpp:192
C4Application Application
Definition: C4Globals.cpp:44

Here is the call graph for this function:

C4GameLobby::Countdown::~Countdown ( )
override

Definition at line 737 of file C4GameLobby.cpp.

References Application, and StdScheduler::Remove().

738  {
739  // release timer
740  Application.Remove(this);
741  }
void Remove(StdSchedulerProc *pProc)
C4Application Application
Definition: C4Globals.cpp:44

Here is the call graph for this function:

Member Function Documentation

void C4GameLobby::Countdown::Abort ( )

Definition at line 782 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.

Referenced by C4Network2::AbortLobbyCountdown().

783  {
784  // host sends packets
785  if (!::Network.isHost()) return;
786  C4PacketCountdown pck(C4PacketCountdown::Abort);
788  // also process on host
789  MainDlg *pLobby = ::Network.GetLobby();
790  if (pLobby)
791  {
792  pLobby->OnCountdownPacket(pck);
793  }
794  else
795  {
796  // no lobby: Message to log for dedicated/console hosts
797  Log(LoadResStr("IDS_PRC_STARTABORTED"));
798  }
799  }
class C4GameLobby::MainDlg * GetLobby() const
Definition: C4Network2.h:216
bool isHost() const
Definition: C4Network2.h:209
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
C4Network2ClientList Clients
Definition: C4Network2.h:116
bool Log(const char *szMessage)
Definition: C4Log.cpp:192

Here is the call graph for this function:

Here is the caller graph for this function:

void C4GameLobby::Countdown::OnSec1Timer ( )
overridevirtual

Implements C4ApplicationSec1Timer.

Definition at line 743 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().

744  {
745  // count down
746  iStartTimer = std::max<int32_t>(iStartTimer - 1, 0);
747  // only send "important" start timer numbers to all clients
748  if (iStartTimer <= AlmostStartCountdownTime || // last seconds
749  (iStartTimer <= 600 && !(iStartTimer % 10)) || // last minute: 10s interval
750  !(iStartTimer % 60)) // otherwise, minute interval
751  {
752  C4PacketCountdown pck(iStartTimer);
754  // also process on host
755  MainDlg *pLobby = ::Network.GetLobby();
756  if (pLobby)
757  pLobby->OnCountdownPacket(pck);
758  else if (iStartTimer)
759  {
760  // no lobby: Message to log for dedicated/console hosts
761  Log(pck.GetCountdownMsg().getData());
762  }
763  }
764  // countdown done
765  if (!iStartTimer)
766  {
767 #ifdef USE_CONSOLE
768  // Dedicated server: if there are not enough players for this game, abort and quit the application
770  || ::Network.Clients.Count() <= 2)
771  {
772  Log(LoadResStr("IDS_MSG_NOTENOUGHPLAYERSFORTHISRO")); // it would also be nice to send this message to all clients...
773  Application.Quit();
774  }
775  // Start the game
776  else
777 #endif // USE_CONSOLE
778  ::Network.Start();
779  }
780  }
class C4GameLobby::MainDlg * GetLobby() const
Definition: C4Network2.h:216
bool Start()
Definition: C4Network2.cpp:505
int32_t GetPlayerCount() const
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
void Quit() override
C4Network2ClientList Clients
Definition: C4Network2.h:116
C4PlayerInfoList & PlayerInfos
Definition: C4Game.h:71
bool Log(const char *szMessage)
Definition: C4Log.cpp:192
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: