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 ()
 
 Countdown (int32_t iStartTimer)
 
 ~Countdown ()
 
void Abort ()
 

Private Member Functions

virtual bool Execute (int, pollfd *)
 
void Set ()
 
void SetDelay (uint32_t inDelay)
 
bool CheckAndReset ()
 
virtual C4TimeMilliseconds GetNextTick (C4TimeMilliseconds tNow)
 
virtual uint32_t TimerInterval ()
 
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 715 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.

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

Here is the call graph for this function:

C4GameLobby::Countdown::~Countdown ( )

Definition at line 738 of file C4GameLobby.cpp.

References Application, and StdScheduler::Remove().

739  {
740  // release timer
741  Application.Remove(this);
742  }
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 783 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().

784  {
785  // host sends packets
786  if (!::Network.isHost()) return;
787  C4PacketCountdown pck(C4PacketCountdown::Abort);
789  // also process on host
790  MainDlg *pLobby = ::Network.GetLobby();
791  if (pLobby)
792  {
793  pLobby->OnCountdownPacket(pck);
794  }
795  else
796  {
797  // no lobby: Message to log for dedicated/console hosts
798  Log(LoadResStr("IDS_PRC_STARTABORTED"));
799  }
800  }
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:195

Here is the call graph for this function:

Here is the caller graph for this function:

void C4GameLobby::Countdown::OnSec1Timer ( )
virtual

Implements C4ApplicationSec1Timer.

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

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