OpenClonk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
C4Network2Reference Class Reference

#include <C4Network2Reference.h>

Collaboration diagram for C4Network2Reference:
[legend]

Public Member Functions

 C4Network2Reference ()
 
 ~C4Network2Reference ()
 
const C4Network2AddressgetAddr (int i) const
 
C4Network2AddressgetAddr (int i)
 
int getAddrCnt () const
 
const char * getTitle () const
 
int32_t getIcon () const
 
C4Network2Status getGameStatus () const
 
const char * getComment () const
 
const C4GameVersiongetGameVersion () const
 
bool isPasswordNeeded () const
 
bool isJoinAllowed () const
 
bool isOfficialServer () const
 
int32_t getSortOrder () const
 
int32_t getTime () const
 
int32_t getStartTime () const
 
StdStrBuf getGameGoalString () const
 
bool isEditor () const
 
C4NetpuncherID getNetpuncherGameID () const
 
StdStrBuf getNetpuncherAddr () const
 
void SetSourceAddress (const C4NetIO::EndpointAddress &ip)
 
const C4NetIO::EndpointAddressGetSourceAddress () const
 
void InitLocal ()
 
void SortNullIPsBack ()
 
void CompileFunc (StdCompiler *pComp)
 

Public Attributes

C4GameParameters Parameters
 

Detailed Description

Definition at line 30 of file C4Network2Reference.h.

Constructor & Destructor Documentation

C4Network2Reference::C4Network2Reference ( )

Definition at line 27 of file C4Network2Reference.cpp.

28  : GameMode(), NetpuncherGameID(C4NetpuncherID())
29 {
30 
31 }
C4Network2Reference::~C4Network2Reference ( )
default

Member Function Documentation

void C4Network2Reference::CompileFunc ( StdCompiler pComp)

Definition at line 102 of file C4Network2Reference.cpp.

References C4ClientMaxAddr, Game, mkArrayAdapt(), mkArrayAdaptDM, mkIntPackAdapt(), mkNamingAdapt(), mkParAdapt(), Parameters, StdCompiler::RCT_All, StdCompiler::RCT_IdtfAllowEmpty, and StdCompiler::Value().

103 {
104  pComp->Value(mkNamingAdapt(Icon, "Icon", 0));
105  pComp->Value(mkNamingAdapt(Title, "Title", "No title"));
106  pComp->Value(mkNamingAdapt(mkParAdapt(GameMode, StdCompiler::RCT_IdtfAllowEmpty), "GameMode", ""));
107  pComp->Value(mkParAdapt(GameStatus, true));
108  pComp->Value(mkNamingAdapt(Time, "Time", 0));
109  pComp->Value(mkNamingAdapt(Frame, "Frame", 0));
110  pComp->Value(mkNamingAdapt(StartTime, "StartTime", 0));
111  pComp->Value(mkNamingAdapt(LeaguePerformance, "LeaguePerformance",0));
112  pComp->Value(mkNamingAdapt(Comment, "Comment", ""));
113  pComp->Value(mkNamingAdapt(JoinAllowed, "JoinAllowed", true));
114  pComp->Value(mkNamingAdapt(ObservingAllowed, "ObservingAllowed", true));
115  pComp->Value(mkNamingAdapt(PasswordNeeded, "PasswordNeeded", false));
116  pComp->Value(mkNamingAdapt(IsEditor, "IsEditor", false));
117  pComp->Value(mkNamingAdapt(mkIntPackAdapt(iAddrCnt), "AddressCount", 0));
118  iAddrCnt = std::min<uint8_t>(C4ClientMaxAddr, iAddrCnt);
119  pComp->Value(mkNamingAdapt(mkArrayAdapt(Addrs, iAddrCnt, C4Network2Address()), "Address"));
120  pComp->Value(mkNamingAdapt(Game.sEngineName, "Game", "None"));
121  pComp->Value(mkNamingAdapt(mkArrayAdaptDM(Game.iVer,0),"Version" ));
122  pComp->Value(mkNamingAdapt(OfficialServer, "OfficialServer", false));
123  pComp->Value(mkNamingAdapt(NetpuncherGameID, "NetpuncherID", C4NetpuncherID(), false, false));
124  pComp->Value(mkNamingAdapt(NetpuncherAddr, "NetpuncherAddr", "", false, false));
125  pComp->Value(mkNamingAdapt(mkParAdapt(Statistics, StdCompiler::RCT_All), "Statistics", "", false, false));
126 
127  pComp->Value(Parameters);
128 }
C4Game Game
Definition: C4Globals.cpp:52
StdNamingAdapt< T > mkNamingAdapt(T &&rValue, const char *szName)
Definition: StdAdaptors.h:92
StdArrayAdapt< T > mkArrayAdapt(T *pArray, int iSize)
Definition: StdAdaptors.h:310
const int32_t C4ClientMaxAddr
void Value(const T &rStruct)
Definition: StdCompiler.h:161
#define mkArrayAdaptDM(A, D)
Definition: StdAdaptors.h:363
StdIntPackAdapt< T > mkIntPackAdapt(T &rVal)
Definition: StdAdaptors.h:759
StdParameterAdapt< T, P > mkParAdapt(T &&rObj, P &&rPar)
Definition: StdAdaptors.h:458
C4GameParameters Parameters

Here is the call graph for this function:

const C4Network2Address& C4Network2Reference::getAddr ( int  i) const
inline

Definition at line 68 of file C4Network2Reference.h.

Referenced by C4StartupNetListEntry::IsSameAddress(), and C4StartupNetListEntry::SetReference().

68 { return Addrs[i]; }

Here is the caller graph for this function:

C4Network2Address& C4Network2Reference::getAddr ( int  i)
inline

Definition at line 69 of file C4Network2Reference.h.

69 { return Addrs[i]; }
int C4Network2Reference::getAddrCnt ( ) const
inline

Definition at line 70 of file C4Network2Reference.h.

Referenced by C4StartupNetListEntry::IsSameAddress(), and C4StartupNetListEntry::SetReference().

70 { return iAddrCnt; }

Here is the caller graph for this function:

const char* C4Network2Reference::getComment ( ) const
inline

Definition at line 74 of file C4Network2Reference.h.

References StdStrBuf::getData().

Referenced by C4StartupNetListEntry::KeywordMatch(), and C4StartupNetListEntry::SetReference().

74 { return Comment.getData(); }
const char * getData() const
Definition: StdBuf.h:442

Here is the call graph for this function:

Here is the caller graph for this function:

StdStrBuf C4Network2Reference::getGameGoalString ( ) const

Definition at line 148 of file C4Network2Reference.cpp.

References FormatString(), StdStrBuf::getData(), C4GameParameters::GetGameGoalString(), StdStrBuf::getLength(), LoadResStr(), and Parameters.

Referenced by C4StartupNetListEntry::SetReference().

149 {
150  if (GameMode.getLength() > 0)
151  {
152  // Prefer to derive string from game mode
153  return FormatString("%s: %s", LoadResStr("IDS_MENU_CPGOALS"), GameMode.getData());
154  }
155  else
156  {
157  // If not defined, fall back to goal string
158  return Parameters.GetGameGoalString();
159  }
160 }
const char * getData() const
Definition: StdBuf.h:442
const char * LoadResStr(const char *id)
Definition: C4Language.h:83
StdStrBuf GetGameGoalString() const
size_t getLength() const
Definition: StdBuf.h:445
C4GameParameters Parameters
StdStrBuf FormatString(const char *szFmt,...)
Definition: StdBuf.cpp:270

Here is the call graph for this function:

Here is the caller graph for this function:

C4Network2Status C4Network2Reference::getGameStatus ( ) const
inline

Definition at line 73 of file C4Network2Reference.h.

Referenced by getSortOrder(), and C4StartupNetListEntry::SetReference().

73 { return GameStatus; }

Here is the caller graph for this function:

const C4GameVersion& C4Network2Reference::getGameVersion ( ) const
inline

Definition at line 75 of file C4Network2Reference.h.

Referenced by C4StartupNetDlg::DoOK(), getSortOrder(), and C4StartupNetListEntry::SetReference().

75 { return Game; }
C4Game Game
Definition: C4Globals.cpp:52

Here is the caller graph for this function:

int32_t C4Network2Reference::getIcon ( ) const
inline

Definition at line 72 of file C4Network2Reference.h.

Referenced by C4StartupNetListEntry::SetReference().

72 { return Icon; }

Here is the caller graph for this function:

StdStrBuf C4Network2Reference::getNetpuncherAddr ( ) const
inline

Definition at line 85 of file C4Network2Reference.h.

85 { return NetpuncherAddr; }
C4NetpuncherID C4Network2Reference::getNetpuncherGameID ( ) const
inline

Definition at line 84 of file C4Network2Reference.h.

84 { return NetpuncherGameID; }
int32_t C4Network2Reference::getSortOrder ( ) const

Definition at line 130 of file C4Network2Reference.cpp.

References Config, getGameStatus(), getGameVersion(), isJoinAllowed(), C4GameParameters::isLeague(), C4Network2Status::isLobbyActive(), isOfficialServer(), isPasswordNeeded(), C4Config::Network, Parameters, and C4ConfigNetwork::UseAlternateServer.

Referenced by C4StartupNetListEntry::OnReference(), and C4StartupNetListEntry::SetReference().

131 {
132  C4GameVersion verThis;
133  int iOrder = 0;
134  // Official server
135  if (isOfficialServer() && !Config.Network.UseAlternateServer) iOrder += 50;
136  // Joinable
137  if (isJoinAllowed() && (getGameVersion() == verThis)) iOrder += 25;
138  // League game
139  if (Parameters.isLeague()) iOrder += 5;
140  // In lobby
141  if (getGameStatus().isLobbyActive()) iOrder += 3;
142  // No password needed
143  if (!isPasswordNeeded()) iOrder += 1;
144  // Done
145  return iOrder;
146 }
C4Config Config
Definition: C4Config.cpp:833
C4Network2Status getGameStatus() const
bool isPasswordNeeded() const
C4ConfigNetwork Network
Definition: C4Config.h:255
bool isJoinAllowed() const
bool isLobbyActive() const
Definition: C4Network2.h:87
bool isOfficialServer() const
bool isLeague() const
int32_t UseAlternateServer
Definition: C4Config.h:152
const C4GameVersion & getGameVersion() const
C4GameParameters Parameters

Here is the call graph for this function:

Here is the caller graph for this function:

const C4NetIO::EndpointAddress& C4Network2Reference::GetSourceAddress ( ) const
inline

Definition at line 88 of file C4Network2Reference.h.

88 { return source; }
int32_t C4Network2Reference::getStartTime ( ) const
inline

Definition at line 81 of file C4Network2Reference.h.

81 { return StartTime; }
int32_t C4Network2Reference::getTime ( ) const
inline

Definition at line 80 of file C4Network2Reference.h.

Referenced by C4StartupNetListEntry::SetReference().

80 { return Time; }

Here is the caller graph for this function:

const char* C4Network2Reference::getTitle ( ) const
inline

Definition at line 71 of file C4Network2Reference.h.

References StdStrBuf::getData().

Referenced by C4Game::InitNetworkFromReference(), C4StartupNetListEntry::KeywordMatch(), and C4StartupNetListEntry::SetReference().

71 { return Title.getData(); }
const char * getData() const
Definition: StdBuf.h:442

Here is the call graph for this function:

Here is the caller graph for this function:

void C4Network2Reference::InitLocal ( )

Definition at line 42 of file C4Network2Reference.cpp.

References Application, C4Game::C4S, C4Game::Clients, C4ConfigNetwork::Comment, Config, ValidatedStdCopyStrBufBase::CopyValidated(), C4PlayerInfo::DiscardResource(), C4Game::FrameCounter, Game, C4Scenario::Game, C4Game::GameOver, C4Network2Client::getAddr(), C4Network2Client::getAddrCnt(), C4PlayerInfo::GetID(), C4PlayerInfoList::GetIndexedInfo(), C4RoundResults::GetLeaguePerformance(), C4ClientList::getLocal(), C4Client::getNetClient(), C4Network2::getNetpuncherAddr(), C4Network2::getNetpuncherGameID(), C4ClientPlayerInfos::GetPlayerInfo(), C4RoundResults::GetStatistics(), C4Scenario::Head, C4SHead::Icon, C4Application::isEditor, C4Network2::isJoinAllowed(), C4Network2::isObservingAllowed(), C4Network2::isPassworded(), C4SGame::Mode, Network, C4Config::Network, Parameters, C4Game::Parameters, C4GameParameters::PlayerInfos, C4Game::RoundResults, C4Game::ScenarioTitle, C4PlayerInfo::SetLeaguePerformance(), C4Game::StartTime, C4Network2::Status, and C4Game::Time.

Referenced by C4Network2::Execute(), C4Network2::LeagueEnd(), C4Network2::LeagueStart(), and C4Network2::LeagueUpdate().

43 {
44  // Copy all game parameters
46 
47  // Discard player resources (we don't want these infos in the reference)
48  // Add league performance (but only after game end)
49  C4ClientPlayerInfos *pClientInfos; C4PlayerInfo *pPlayerInfo;
50  int32_t i, j;
51  for (i = 0; (pClientInfos = Parameters.PlayerInfos.GetIndexedInfo(i)); i++)
52  for (j = 0; (pPlayerInfo = pClientInfos->GetPlayerInfo(j)); j++)
53  {
54  pPlayerInfo->DiscardResource();
55  if(::Game.GameOver)
56  pPlayerInfo->SetLeaguePerformance(::Game.RoundResults.GetLeaguePerformance(pPlayerInfo->GetID()));
57  }
58 
59  // Special additional information in reference
60  Icon = ::Game.C4S.Head.Icon;
62  GameMode = ::Game.C4S.Game.Mode;
63  GameStatus = ::Network.Status;
64  Time = ::Game.Time;
65  Frame = ::Game.FrameCounter;
66  StartTime = ::Game.StartTime;
67  LeaguePerformance = ::Game.RoundResults.GetLeaguePerformance();
68  Comment = Config.Network.Comment;
69  JoinAllowed = ::Network.isJoinAllowed();
70  ObservingAllowed = ::Network.isObservingAllowed();
71  PasswordNeeded = ::Network.isPassworded();
72  IsEditor = !!::Application.isEditor;
73  NetpuncherGameID = ::Network.getNetpuncherGameID();
74  NetpuncherAddr = ::Network.getNetpuncherAddr();
75  Statistics = ::Game.RoundResults.GetStatistics();
76  Game.Set();
77 
78  // Addresses
79  C4Network2Client *pLocalNetClient = ::Game.Clients.getLocal()->getNetClient();
80  iAddrCnt = pLocalNetClient->getAddrCnt();
81  for (i = 0; i < iAddrCnt; i++)
82  Addrs[i] = pLocalNetClient->getAddr(i);
83 
84 }
const C4Network2Address & getAddr(int32_t i) const
StdCopyStrBuf Mode
Definition: C4Scenario.h:121
C4Client * getLocal() const
Definition: C4Client.h:161
int32_t Icon
Definition: C4Scenario.h:68
C4Config Config
Definition: C4Config.cpp:833
C4Game Game
Definition: C4Globals.cpp:52
C4Scenario C4S
Definition: C4Game.h:74
C4NetpuncherID::value & getNetpuncherGameID(C4NetIO::HostAddress::AddressFamily family)
StdCopyStrBuf ScenarioTitle
Definition: C4Game.h:103
ValidatedStdCopyStrBuf< C4InVal::VAL_Comment > Comment
Definition: C4Config.h:146
StdStrBuf getNetpuncherAddr() const
Definition: C4Network2.h:309
bool isJoinAllowed() const
Definition: C4Network2.h:213
C4Network2Client * getNetClient() const
Definition: C4Client.h:117
bool isObservingAllowed() const
Definition: C4Network2.h:214
void DiscardResource()
C4GameParameters & Parameters
Definition: C4Game.h:67
C4ClientPlayerInfos * GetIndexedInfo(int32_t iIndex) const
Definition: C4PlayerInfo.h:358
StdCopyStrBuf GetStatistics() const
int32_t FrameCounter
Definition: C4Game.h:128
C4PlayerInfo * GetPlayerInfo(int32_t iIndex) const
C4Network2 Network
Definition: C4Globals.cpp:53
int32_t StartTime
Definition: C4Game.h:132
bool GameOver
Definition: C4Game.h:114
int32_t Time
Definition: C4Game.h:131
C4ConfigNetwork Network
Definition: C4Config.h:255
C4Network2Status Status
Definition: C4Network2.h:122
C4RoundResults & RoundResults
Definition: C4Game.h:73
void SetLeaguePerformance(int32_t iNewPerf)
Definition: C4PlayerInfo.h:137
C4PlayerInfoList PlayerInfos
C4SGame Game
Definition: C4Scenario.h:232
C4ClientList & Clients
Definition: C4Game.h:69
bool isPassworded() const
Definition: C4Network2.h:218
int32_t GetID() const
Definition: C4PlayerInfo.h:194
C4SHead Head
Definition: C4Scenario.h:230
int32_t getAddrCnt() const
void CopyValidated(const char *szFromVal)
int32_t GetLeaguePerformance(int32_t idPlayer=0) const
C4Application Application
Definition: C4Globals.cpp:44
C4GameParameters Parameters

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4Network2Reference::isEditor ( ) const
inline

Definition at line 83 of file C4Network2Reference.h.

Referenced by C4StartupNetDlg::DoOK(), and C4StartupNetListEntry::SetReference().

83 { return IsEditor; }

Here is the caller graph for this function:

bool C4Network2Reference::isJoinAllowed ( ) const
inline

Definition at line 77 of file C4Network2Reference.h.

Referenced by C4StartupNetDlg::DoOK(), getSortOrder(), and C4StartupNetListEntry::SetReference().

77 { return JoinAllowed; }

Here is the caller graph for this function:

bool C4Network2Reference::isOfficialServer ( ) const
inline

Definition at line 78 of file C4Network2Reference.h.

Referenced by getSortOrder(), and C4StartupNetListEntry::SetReference().

78 { return OfficialServer; }

Here is the caller graph for this function:

bool C4Network2Reference::isPasswordNeeded ( ) const
inline

Definition at line 76 of file C4Network2Reference.h.

Referenced by getSortOrder(), and C4StartupNetListEntry::SetReference().

76 { return PasswordNeeded; }

Here is the caller graph for this function:

void C4Network2Reference::SetSourceAddress ( const C4NetIO::EndpointAddress ip)

Definition at line 35 of file C4Network2Reference.cpp.

References C4ClientMaxAddr, and C4Network2Address::SetAddr().

36 {
37  source = ip;
38  if (iAddrCnt < C4ClientMaxAddr)
39  Addrs[++iAddrCnt].SetAddr(ip);
40 }
const int32_t C4ClientMaxAddr
void SetAddr(C4NetIO::addr_t naddr)

Here is the call graph for this function:

void C4Network2Reference::SortNullIPsBack ( )

Definition at line 86 of file C4Network2Reference.cpp.

87 {
88  // Sort all addresses with zero IP to back of list
89  int iSortAddrCnt = iAddrCnt;
90  for (int i = 0; i < iSortAddrCnt; i++)
91  if (Addrs[i].isIPNull())
92  {
93  C4Network2Address Addr = Addrs[i];
94  for (int j = i + 1; j < iAddrCnt; j++)
95  Addrs[j - 1] = Addrs[j];
96  Addrs[iAddrCnt - 1] = Addr;
97  // Correct position
98  i--; iSortAddrCnt--;
99  }
100 }

Member Data Documentation


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