OpenClonk
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 28 of file C4Network2Reference.h.

Constructor & Destructor Documentation

◆ C4Network2Reference()

C4Network2Reference::C4Network2Reference ( )

Definition at line 25 of file C4Network2Reference.cpp.

26  : GameMode(), NetpuncherGameID(C4NetpuncherID())
27 {
28 
29 }

◆ ~C4Network2Reference()

C4Network2Reference::~C4Network2Reference ( )
default

Member Function Documentation

◆ CompileFunc()

void C4Network2Reference::CompileFunc ( StdCompiler pComp)

Definition at line 100 of file C4Network2Reference.cpp.

101 {
102  pComp->Value(mkNamingAdapt(Icon, "Icon", 0));
103  pComp->Value(mkNamingAdapt(Title, "Title", "No title"));
104  pComp->Value(mkNamingAdapt(mkParAdapt(GameMode, StdCompiler::RCT_IdtfAllowEmpty), "GameMode", ""));
105  pComp->Value(mkParAdapt(GameStatus, true));
106  pComp->Value(mkNamingAdapt(Time, "Time", 0));
107  pComp->Value(mkNamingAdapt(Frame, "Frame", 0));
108  pComp->Value(mkNamingAdapt(StartTime, "StartTime", 0));
109  pComp->Value(mkNamingAdapt(LeaguePerformance, "LeaguePerformance",0));
110  pComp->Value(mkNamingAdapt(Comment, "Comment", ""));
111  pComp->Value(mkNamingAdapt(JoinAllowed, "JoinAllowed", true));
112  pComp->Value(mkNamingAdapt(ObservingAllowed, "ObservingAllowed", true));
113  pComp->Value(mkNamingAdapt(PasswordNeeded, "PasswordNeeded", false));
114  pComp->Value(mkNamingAdapt(IsEditor, "IsEditor", false));
115  pComp->Value(mkNamingAdapt(mkIntPackAdapt(iAddrCnt), "AddressCount", 0));
116  iAddrCnt = std::min<uint8_t>(C4ClientMaxAddr, iAddrCnt);
117  pComp->Value(mkNamingAdapt(mkArrayAdapt(Addrs, iAddrCnt, C4Network2Address()), "Address"));
118  pComp->Value(mkNamingAdapt(Game.sEngineName, "Game", "None"));
119  pComp->Value(mkNamingAdapt(mkArrayAdaptDM(Game.iVer,0),"Version" ));
120  pComp->Value(mkNamingAdapt(OfficialServer, "OfficialServer", false));
121  pComp->Value(mkNamingAdapt(NetpuncherGameID, "NetpuncherID", C4NetpuncherID(), false, false));
122  pComp->Value(mkNamingAdapt(NetpuncherAddr, "NetpuncherAddr", "", false, false));
123  pComp->Value(mkNamingAdapt(mkParAdapt(Statistics, StdCompiler::RCT_All), "Statistics", "", false, false));
124 
125  pComp->Value(Parameters);
126 }
const int32_t C4ClientMaxAddr
StdArrayDefaultAdapt< T, D > mkArrayAdaptDM(T(&array)[size], const D &rDefault)
Definition: StdAdaptors.h:392
StdArrayAdapt< T > mkArrayAdapt(T *pArray, int iSize)
Definition: StdAdaptors.h:336
StdIntPackAdapt< T > mkIntPackAdapt(T &rVal)
Definition: StdAdaptors.h:791
StdParameterAdapt< T, P > mkParAdapt(T &&rObj, P &&rPar)
Definition: StdAdaptors.h:490
StdNamingAdapt< T > mkNamingAdapt(T &&rValue, const char *szName)
Definition: StdAdaptors.h:92
C4GameParameters Parameters
void Value(const T &rStruct)
Definition: StdCompiler.h:161
@ RCT_IdtfAllowEmpty
Definition: StdCompiler.h:140
int32_t iVer[2]
Definition: C4GameVersion.h:27
ValidatedStdCopyStrBuf< C4InVal::VAL_NameAllowEmpty > sEngineName
Definition: C4GameVersion.h:26

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

Here is the call graph for this function:

◆ getAddr() [1/2]

C4Network2Address& C4Network2Reference::getAddr ( int  i)
inline

Definition at line 67 of file C4Network2Reference.h.

67 { return Addrs[i]; }

◆ getAddr() [2/2]

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

Definition at line 66 of file C4Network2Reference.h.

66 { return Addrs[i]; }

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

Here is the caller graph for this function:

◆ getAddrCnt()

int C4Network2Reference::getAddrCnt ( ) const
inline

Definition at line 68 of file C4Network2Reference.h.

68 { return iAddrCnt; }

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

Here is the caller graph for this function:

◆ getComment()

const char* C4Network2Reference::getComment ( ) const
inline

Definition at line 72 of file C4Network2Reference.h.

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

References StdStrBuf::getData().

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

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

◆ getGameGoalString()

StdStrBuf C4Network2Reference::getGameGoalString ( ) const

Definition at line 146 of file C4Network2Reference.cpp.

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

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

Referenced by C4StartupNetListEntry::SetReference().

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

◆ getGameStatus()

C4Network2Status C4Network2Reference::getGameStatus ( ) const
inline

Definition at line 71 of file C4Network2Reference.h.

71 { return GameStatus; }

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

Here is the caller graph for this function:

◆ getGameVersion()

const C4GameVersion& C4Network2Reference::getGameVersion ( ) const
inline

Definition at line 73 of file C4Network2Reference.h.

73 { return Game; }

References Game.

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

Here is the caller graph for this function:

◆ getIcon()

int32_t C4Network2Reference::getIcon ( ) const
inline

Definition at line 70 of file C4Network2Reference.h.

70 { return Icon; }

Referenced by C4StartupNetListEntry::SetReference().

Here is the caller graph for this function:

◆ getNetpuncherAddr()

StdStrBuf C4Network2Reference::getNetpuncherAddr ( ) const
inline

Definition at line 83 of file C4Network2Reference.h.

83 { return NetpuncherAddr; }

◆ getNetpuncherGameID()

C4NetpuncherID C4Network2Reference::getNetpuncherGameID ( ) const
inline

Definition at line 82 of file C4Network2Reference.h.

82 { return NetpuncherGameID; }

◆ getSortOrder()

int32_t C4Network2Reference::getSortOrder ( ) const

Definition at line 128 of file C4Network2Reference.cpp.

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

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

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

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

◆ GetSourceAddress()

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

Definition at line 86 of file C4Network2Reference.h.

86 { return source; }

◆ getStartTime()

int32_t C4Network2Reference::getStartTime ( ) const
inline

Definition at line 79 of file C4Network2Reference.h.

79 { return StartTime; }

◆ getTime()

int32_t C4Network2Reference::getTime ( ) const
inline

Definition at line 78 of file C4Network2Reference.h.

78 { return Time; }

Referenced by C4StartupNetListEntry::SetReference().

Here is the caller graph for this function:

◆ getTitle()

const char* C4Network2Reference::getTitle ( ) const
inline

Definition at line 69 of file C4Network2Reference.h.

69 { return Title.getData(); }

References StdStrBuf::getData().

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

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

◆ InitLocal()

void C4Network2Reference::InitLocal ( )

Definition at line 40 of file C4Network2Reference.cpp.

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

References Application, C4ConfigNetwork::Comment, Config, ValidatedStdCopyStrBufBase::CopyValidated(), C4PlayerInfo::DiscardResource(), C4Network2Client::getAddr(), C4Network2Client::getAddrCnt(), C4PlayerInfo::GetID(), C4PlayerInfoList::GetIndexedInfo(), C4Network2::getNetpuncherAddr(), C4Network2::getNetpuncherGameID(), C4ClientPlayerInfos::GetPlayerInfo(), C4Application::isEditor, C4Network2::isJoinAllowed(), C4Network2::isObservingAllowed(), C4Network2::isPassworded(), Network, C4Config::Network, Parameters, C4GameParameters::PlayerInfos, C4GameVersion::Set(), C4PlayerInfo::SetLeaguePerformance(), and C4Network2::Status.

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

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

◆ isEditor()

bool C4Network2Reference::isEditor ( ) const
inline

Definition at line 81 of file C4Network2Reference.h.

81 { return IsEditor; }

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

Here is the caller graph for this function:

◆ isJoinAllowed()

bool C4Network2Reference::isJoinAllowed ( ) const
inline

Definition at line 75 of file C4Network2Reference.h.

75 { return JoinAllowed; }

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

Here is the caller graph for this function:

◆ isOfficialServer()

bool C4Network2Reference::isOfficialServer ( ) const
inline

Definition at line 76 of file C4Network2Reference.h.

76 { return OfficialServer; }

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

Here is the caller graph for this function:

◆ isPasswordNeeded()

bool C4Network2Reference::isPasswordNeeded ( ) const
inline

Definition at line 74 of file C4Network2Reference.h.

74 { return PasswordNeeded; }

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

Here is the caller graph for this function:

◆ SetSourceAddress()

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

Definition at line 33 of file C4Network2Reference.cpp.

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

References C4ClientMaxAddr, and C4Network2Address::SetAddr().

Here is the call graph for this function:

◆ SortNullIPsBack()

void C4Network2Reference::SortNullIPsBack ( )

Definition at line 84 of file C4Network2Reference.cpp.

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

Member Data Documentation

◆ Parameters


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