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 30 of file C4Network2Reference.cpp.

31  : Icon(0), GameMode(), Time(0), Frame(0), StartTime(0), LeaguePerformance(0),
32  JoinAllowed(true), ObservingAllowed(true), PasswordNeeded(false), OfficialServer(false),
33  IsEditor(false), iAddrCnt(0), NetpuncherGameID(C4NetpuncherID())
34 {
35 
36 }
C4Network2Reference::~C4Network2Reference ( )

Definition at line 38 of file C4Network2Reference.cpp.

39 {
40 
41 }

Member Function Documentation

void C4Network2Reference::CompileFunc ( StdCompiler pComp)

Definition at line 110 of file C4Network2Reference.cpp.

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

111 {
112  pComp->Value(mkNamingAdapt(Icon, "Icon", 0));
113  pComp->Value(mkNamingAdapt(Title, "Title", "No title"));
114  pComp->Value(mkNamingAdapt(mkParAdapt(GameMode, StdCompiler::RCT_IdtfAllowEmpty), "GameMode", ""));
115  pComp->Value(mkParAdapt(GameStatus, true));
116  pComp->Value(mkNamingAdapt(Time, "Time", 0));
117  pComp->Value(mkNamingAdapt(Frame, "Frame", 0));
118  pComp->Value(mkNamingAdapt(StartTime, "StartTime", 0));
119  pComp->Value(mkNamingAdapt(LeaguePerformance, "LeaguePerformance",0));
120  pComp->Value(mkNamingAdapt(Comment, "Comment", ""));
121  pComp->Value(mkNamingAdapt(JoinAllowed, "JoinAllowed", true));
122  pComp->Value(mkNamingAdapt(ObservingAllowed, "ObservingAllowed", true));
123  pComp->Value(mkNamingAdapt(PasswordNeeded, "PasswordNeeded", false));
124  pComp->Value(mkNamingAdapt(IsEditor, "IsEditor", false));
125  pComp->Value(mkNamingAdapt(mkIntPackAdapt(iAddrCnt), "AddressCount", 0));
126  iAddrCnt = std::min<uint8_t>(C4ClientMaxAddr, iAddrCnt);
127  pComp->Value(mkNamingAdapt(mkArrayAdapt(Addrs, iAddrCnt, C4Network2Address()), "Address"));
128  pComp->Value(mkNamingAdapt(Game.sEngineName, "Game", "None"));
129  pComp->Value(mkNamingAdapt(mkArrayAdaptDM(Game.iVer,0),"Version" ));
130  pComp->Value(mkNamingAdapt(OfficialServer, "OfficialServer", false));
131  pComp->Value(mkNamingAdapt(NetpuncherGameID, "NetpuncherID", C4NetpuncherID(), false, false));
132  pComp->Value(mkNamingAdapt(NetpuncherAddr, "NetpuncherAddr", "", false, false));
133  pComp->Value(mkNamingAdapt(mkParAdapt(Statistics, StdCompiler::RCT_All), "Statistics", "", false, false));
134 
135  pComp->Value(Parameters);
136 }
C4Game Game
Definition: C4Globals.cpp:52
StdNamingAdapt< T > mkNamingAdapt(T &&rValue, const char *szName)
Definition: StdAdaptors.h:93
StdArrayAdapt< T > mkArrayAdapt(T *pArray, int iSize)
Definition: StdAdaptors.h:308
const int32_t C4ClientMaxAddr
void Value(const T &rStruct)
Definition: StdCompiler.h:171
#define mkArrayAdaptDM(A, D)
Definition: StdAdaptors.h:361
StdIntPackAdapt< T > mkIntPackAdapt(T &rVal)
Definition: StdAdaptors.h:757
StdParameterAdapt< T, P > mkParAdapt(T &&rObj, P &&rPar)
Definition: StdAdaptors.h:456
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:450

Here is the call graph for this function:

Here is the caller graph for this function:

StdStrBuf C4Network2Reference::getGameGoalString ( ) const

Definition at line 156 of file C4Network2Reference.cpp.

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

Referenced by C4StartupNetListEntry::SetReference().

157 {
158  if (GameMode.getLength() > 0)
159  {
160  // Prefer to derive string from game mode
161  return FormatString("%s: %s", LoadResStr("IDS_MENU_CPGOALS"), GameMode.getData());
162  }
163  else
164  {
165  // If not defined, fall back to goal string
166  return Parameters.GetGameGoalString();
167  }
168 }
const char * getData() const
Definition: StdBuf.h:450
const char * LoadResStr(const char *id)
Definition: C4Language.h:83
StdStrBuf GetGameGoalString() const
size_t getLength() const
Definition: StdBuf.h:453
C4GameParameters Parameters
StdStrBuf FormatString(const char *szFmt,...)
Definition: StdBuf.cpp:277

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

139 {
140  C4GameVersion verThis;
141  int iOrder = 0;
142  // Official server
143  if (isOfficialServer() && !Config.Network.UseAlternateServer) iOrder += 50;
144  // Joinable
145  if (isJoinAllowed() && (getGameVersion() == verThis)) iOrder += 25;
146  // League game
147  if (Parameters.isLeague()) iOrder += 5;
148  // In lobby
149  if (getGameStatus().isLobbyActive()) iOrder += 3;
150  // No password needed
151  if (!isPasswordNeeded()) iOrder += 1;
152  // Done
153  return iOrder;
154 }
C4Config Config
Definition: C4Config.cpp:837
C4Network2Status getGameStatus() const
bool isPasswordNeeded() const
C4ConfigNetwork Network
Definition: C4Config.h:256
bool isJoinAllowed() const
bool isLobbyActive() const
Definition: C4Network2.h:87
bool isOfficialServer() const
bool isLeague() const
int32_t UseAlternateServer
Definition: C4Config.h:153
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:450

Here is the call graph for this function:

Here is the caller graph for this function:

void C4Network2Reference::InitLocal ( )

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

51 {
52  // Copy all game parameters
54 
55  // Discard player resources (we don't want these infos in the reference)
56  // Add league performance (but only after game end)
57  C4ClientPlayerInfos *pClientInfos; C4PlayerInfo *pPlayerInfo;
58  int32_t i, j;
59  for (i = 0; (pClientInfos = Parameters.PlayerInfos.GetIndexedInfo(i)); i++)
60  for (j = 0; (pPlayerInfo = pClientInfos->GetPlayerInfo(j)); j++)
61  {
62  pPlayerInfo->DiscardResource();
63  if(::Game.GameOver)
64  pPlayerInfo->SetLeaguePerformance(::Game.RoundResults.GetLeaguePerformance(pPlayerInfo->GetID()));
65  }
66 
67  // Special additional information in reference
68  Icon = ::Game.C4S.Head.Icon;
70  GameMode = ::Game.C4S.Game.Mode;
71  GameStatus = ::Network.Status;
72  Time = ::Game.Time;
73  Frame = ::Game.FrameCounter;
74  StartTime = ::Game.StartTime;
75  LeaguePerformance = ::Game.RoundResults.GetLeaguePerformance();
76  Comment = Config.Network.Comment;
77  JoinAllowed = ::Network.isJoinAllowed();
78  ObservingAllowed = ::Network.isObservingAllowed();
79  PasswordNeeded = ::Network.isPassworded();
80  IsEditor = !!::Application.isEditor;
81  NetpuncherGameID = ::Network.getNetpuncherGameID();
82  NetpuncherAddr = ::Network.getNetpuncherAddr();
83  Statistics = ::Game.RoundResults.GetStatistics();
84  Game.Set();
85 
86  // Addresses
87  C4Network2Client *pLocalNetClient = ::Game.Clients.getLocal()->getNetClient();
88  iAddrCnt = pLocalNetClient->getAddrCnt();
89  for (i = 0; i < iAddrCnt; i++)
90  Addrs[i] = pLocalNetClient->getAddr(i);
91 
92 }
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:837
C4Game Game
Definition: C4Globals.cpp:52
C4Scenario C4S
Definition: C4Game.h:76
C4NetpuncherID::value & getNetpuncherGameID(C4NetIO::HostAddress::AddressFamily family)
StdCopyStrBuf ScenarioTitle
Definition: C4Game.h:105
ValidatedStdCopyStrBuf< C4InVal::VAL_Comment > Comment
Definition: C4Config.h:147
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:69
C4ClientPlayerInfos * GetIndexedInfo(int32_t iIndex) const
Definition: C4PlayerInfo.h:361
StdCopyStrBuf GetStatistics() const
int32_t FrameCounter
Definition: C4Game.h:130
C4PlayerInfo * GetPlayerInfo(int32_t iIndex) const
C4Network2 Network
Definition: C4Globals.cpp:53
int32_t StartTime
Definition: C4Game.h:134
bool GameOver
Definition: C4Game.h:116
int32_t Time
Definition: C4Game.h:133
C4ConfigNetwork Network
Definition: C4Config.h:256
C4Network2Status Status
Definition: C4Network2.h:122
C4RoundResults & RoundResults
Definition: C4Game.h:75
void SetLeaguePerformance(int32_t iNewPerf)
Definition: C4PlayerInfo.h:140
C4PlayerInfoList PlayerInfos
C4SGame Game
Definition: C4Scenario.h:232
C4ClientList & Clients
Definition: C4Game.h:71
bool isPassworded() const
Definition: C4Network2.h:218
int32_t GetID() const
Definition: C4PlayerInfo.h:197
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 43 of file C4Network2Reference.cpp.

References C4ClientMaxAddr, and C4Network2Address::SetAddr().

44 {
45  source = ip;
46  if (iAddrCnt < C4ClientMaxAddr)
47  Addrs[++iAddrCnt].SetAddr(ip);
48 }
const int32_t C4ClientMaxAddr
void SetAddr(C4NetIO::addr_t naddr)

Here is the call graph for this function:

void C4Network2Reference::SortNullIPsBack ( )

Definition at line 94 of file C4Network2Reference.cpp.

95 {
96  // Sort all addresses with zero IP to back of list
97  int iSortAddrCnt = iAddrCnt;
98  for (int i = 0; i < iSortAddrCnt; i++)
99  if (Addrs[i].isIPNull())
100  {
101  C4Network2Address Addr = Addrs[i];
102  for (int j = i + 1; j < iAddrCnt; j++)
103  Addrs[j - 1] = Addrs[j];
104  Addrs[iAddrCnt - 1] = Addr;
105  // Correct position
106  i--; iSortAddrCnt--;
107  }
108 }

Member Data Documentation


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