OpenClonk
C4Network2Client Class Reference

#include <C4Network2Client.h>

Collaboration diagram for C4Network2Client:
[legend]

Public Member Functions

 C4Network2Client (C4Client *pClient)
 
 ~C4Network2Client ()
 
C4ClientgetClient () const
 
const C4ClientCoregetCore () const
 
int32_t getID () const
 
bool isLocal () const
 
bool isHost () const
 
const char * getName () const
 
bool isActivated () const
 
bool isObserver () const
 
int32_t getAddrCnt () const
 
const C4Network2AddressgetAddr (int32_t i) const
 
const std::set< int > & getInterfaceIDs () const
 
C4Network2ClientStatus getStatus () const
 
bool hasJoinData () const
 
bool isChasing () const
 
bool isReady () const
 
bool isWaitedFor () const
 
bool isRemoved () const
 
bool isConnected () const
 
time_t getNextConnAttempt () const
 
int32_t getLastActivity () const
 
class C4TableGraphgetStatPing () const
 
C4Network2ClientgetNext () const
 
void SetStatus (C4Network2ClientStatus enStatus)
 
void SetLastActivity (int32_t iTick)
 
C4Network2IOConnectiongetMsgConn () const
 
C4Network2IOConnectiongetDataConn () const
 
bool hasConn (C4Network2IOConnection *pConn)
 
void SetMsgConn (C4Network2IOConnection *pConn)
 
void SetDataConn (C4Network2IOConnection *pConn)
 
void RemoveConn (C4Network2IOConnection *pConn)
 
void CloseConns (const char *szMsg)
 
bool SendMsg (C4NetIOPacket rPkt) const
 
bool SendData (C4NetIOPacket rPkt) const
 
bool DoConnectAttempt (class C4Network2IO *pIO)
 
bool DoTCPSimultaneousOpen (class C4Network2IO *pIO, const C4Network2Address &addr)
 
bool hasAddr (const C4Network2Address &addr) const
 
void ClearAddr ()
 
void AddAddrFromPuncher (const C4NetIO::addr_t &addr)
 
bool AddAddr (const C4Network2Address &addr, bool fAnnounce)
 
void AddLocalAddrs (int16_t iPortTCP, int16_t iPortUDP)
 
void SendAddresses (C4Network2IOConnection *pConn)
 
void CreateGraphs ()
 
void ClearGraphs ()
 

Protected Attributes

C4ClientpClient
 
C4Network2Address Addr [C4ClientMaxAddr]
 
int32_t AddrAttempts [C4ClientMaxAddr]
 
int32_t iAddrCnt
 
C4NetIO::addr_t IPv6AddrFromPuncher
 
std::set< int > InterfaceIDs
 
C4Network2ClientStatus eStatus
 
int32_t iLastActivity
 
C4Network2IOConnectionpMsgConn
 
C4Network2IOConnectionpDataConn
 
time_t iNextConnAttempt
 
std::unique_ptr< C4NetIOTCP::SocketTcpSimOpenSocket
 
C4Network2ClientpNext
 
class C4Network2ClientListpParent
 
class C4TableGraphpstatPing
 

Friends

class C4Network2ClientList
 

Detailed Description

Definition at line 44 of file C4Network2Client.h.

Constructor & Destructor Documentation

◆ C4Network2Client()

C4Network2Client::C4Network2Client ( C4Client pClient)

Definition at line 30 of file C4Network2Client.cpp.

31  : pClient(pClient),
32  iAddrCnt(0),
34  iLastActivity(0),
35  pMsgConn(nullptr), pDataConn(nullptr),
37  pNext(nullptr), pParent(nullptr), pstatPing(nullptr)
38 {
39 }
@ NCS_Ready
C4Network2IOConnection * pMsgConn
C4Network2Client * pNext
class C4TableGraph * pstatPing
C4Network2IOConnection * pDataConn
C4Network2ClientStatus eStatus
class C4Network2ClientList * pParent

◆ ~C4Network2Client()

C4Network2Client::~C4Network2Client ( )

Definition at line 41 of file C4Network2Client.cpp.

42 {
43  ClearGraphs();
44  if (pMsgConn) { pMsgConn->Close(); pMsgConn->DelRef(); } pMsgConn = nullptr;
45  if (pDataConn) { pDataConn->Close(); pDataConn->DelRef(); } pDataConn = nullptr;
47 }
void UnlinkNetClient()
Definition: C4Client.h:129

References ClearGraphs(), C4Network2IOConnection::Close(), C4Network2IOConnection::DelRef(), pClient, pDataConn, pMsgConn, and C4Client::UnlinkNetClient().

Here is the call graph for this function:

Member Function Documentation

◆ AddAddr()

bool C4Network2Client::AddAddr ( const C4Network2Address addr,
bool  fAnnounce 
)

Definition at line 238 of file C4Network2Client.cpp.

239 {
240  // checks
241  if (iAddrCnt + 1 >= C4ClientMaxAddr) return false;
242  if (hasAddr(addr)) return true;
243  // add
244  Addr[iAddrCnt] = addr; AddrAttempts[iAddrCnt] = 0;
245  iAddrCnt++;
246  // attempt to use this one
247  if (!iNextConnAttempt) iNextConnAttempt = time(nullptr);
248  // announce
249  if (fAnnounce)
251  return false;
252  // done
253  return true;
254 }
const int32_t C4ClientMaxAddr
C4NetIOPacket MkC4NetIOPacket(char cStatus, const class C4PacketBase &Pkt, const C4NetIO::addr_t &addr=C4NetIO::addr_t())
Definition: C4PacketBase.h:40
@ PID_Addr
Definition: C4PacketBase.h:107
C4Network2Address Addr[C4ClientMaxAddr]
bool hasAddr(const C4Network2Address &addr) const
int32_t getID() const
int32_t AddrAttempts[C4ClientMaxAddr]
bool BroadcastMsgToConnClients(const C4NetIOPacket &rPkt)

References Addr, AddrAttempts, C4Network2ClientList::BroadcastMsgToConnClients(), C4ClientMaxAddr, getID(), hasAddr(), iAddrCnt, iNextConnAttempt, MkC4NetIOPacket(), PID_Addr, and pParent.

Referenced by AddAddrFromPuncher(), AddLocalAddrs(), C4Network2::HandleConnRe(), and C4Network2ClientList::HandlePacket().

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

◆ AddAddrFromPuncher()

void C4Network2Client::AddAddrFromPuncher ( const C4NetIO::addr_t addr)

Definition at line 222 of file C4Network2Client.cpp.

223 {
224  AddAddr(C4Network2Address(addr, P_UDP), true);
225  // If the outside port matches the inside port, there is no port translation and the
226  // TCP address will probably work as well.
227  if (addr.GetPort() == Config.Network.PortUDP && Config.Network.PortTCP > 0)
228  {
229  auto tcpAddr = addr;
230  tcpAddr.SetPort(Config.Network.PortTCP);
231  AddAddr(C4Network2Address(tcpAddr, P_TCP), true);
232  }
233  // Save IPv6 address for TCP simultaneous connect.
234  if (addr.GetFamily() == C4NetIO::addr_t::IPv6)
235  IPv6AddrFromPuncher = addr;
236 }
C4Config Config
Definition: C4Config.cpp:930
@ P_UDP
Definition: C4Network2IO.h:31
@ P_TCP
Definition: C4Network2IO.h:31
C4ConfigNetwork Network
Definition: C4Config.h:259
int32_t PortUDP
Definition: C4Config.h:153
int32_t PortTCP
Definition: C4Config.h:153
bool AddAddr(const C4Network2Address &addr, bool fAnnounce)
C4NetIO::addr_t IPv6AddrFromPuncher
uint16_t GetPort() const
Definition: C4NetIO.cpp:547
void SetPort(uint16_t port)
Definition: C4NetIO.cpp:531
AddressFamily GetFamily() const
Definition: C4NetIO.cpp:520

References AddAddr(), Config, C4NetIO::HostAddress::GetFamily(), C4NetIO::EndpointAddress::GetPort(), C4NetIO::HostAddress::IPv6, IPv6AddrFromPuncher, C4Config::Network, P_TCP, P_UDP, C4ConfigNetwork::PortTCP, C4ConfigNetwork::PortUDP, and C4NetIO::EndpointAddress::SetPort().

Referenced by C4Network2::OnPuncherConnect().

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

◆ AddLocalAddrs()

void C4Network2Client::AddLocalAddrs ( int16_t  iPortTCP,
int16_t  iPortUDP 
)

Definition at line 256 of file C4Network2Client.cpp.

257 {
258  C4NetIO::addr_t addr;
259 
260  for (auto& ha : C4NetIO::GetLocalAddresses())
261  {
262  addr.SetAddress(ha);
263  if (iPortTCP)
264  {
265  addr.SetPort(iPortTCP);
266  AddAddr(C4Network2Address(addr, P_TCP), false);
267  }
268  if (iPortUDP)
269  {
270  addr.SetPort(iPortUDP);
271  AddAddr(C4Network2Address(addr, P_UDP), false);
272  }
273  if (addr.GetScopeId())
274  InterfaceIDs.insert(addr.GetScopeId());
275  }
276 }
static std::vector< HostAddress > GetLocalAddresses()
Definition: C4NetIO.cpp:631
std::set< int > InterfaceIDs
void SetAddress(const sockaddr *addr)
Definition: C4NetIO.cpp:364
int GetScopeId() const
Definition: C4NetIO.cpp:296

References AddAddr(), C4NetIO::GetLocalAddresses(), C4NetIO::HostAddress::GetScopeId(), InterfaceIDs, P_TCP, P_UDP, C4NetIO::EndpointAddress::SetAddress(), and C4NetIO::EndpointAddress::SetPort().

Referenced by C4Network2::InitNetIO().

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

◆ ClearAddr()

void C4Network2Client::ClearAddr ( )

Definition at line 217 of file C4Network2Client.cpp.

218 {
219  iAddrCnt = 0;
220 }

References iAddrCnt.

◆ ClearGraphs()

void C4Network2Client::ClearGraphs ( )

Definition at line 312 of file C4Network2Client.cpp.

313 {
314  // del all assigned graphs
315  if (pstatPing)
316  {
317  if (Game.pNetworkStatistics) Game.pNetworkStatistics->statPings.RemoveGraph(pstatPing);
318  delete pstatPing;
319  pstatPing = nullptr;
320  }
321 }
C4Game Game
Definition: C4Globals.cpp:52
std::unique_ptr< C4Network2Stats > pNetworkStatistics
Definition: C4Game.h:95

References Game, C4Game::pNetworkStatistics, and pstatPing.

Referenced by CreateGraphs(), ~C4Network2Client(), and C4Network2Stats::~C4Network2Stats().

Here is the caller graph for this function:

◆ CloseConns()

void C4Network2Client::CloseConns ( const char *  szMsg)

Definition at line 89 of file C4Network2Client.cpp.

90 {
91  C4PacketConnRe Pkt(false, false, szMsg);
93  while ((pConn = pMsgConn))
94  {
95  // send packet, close
96  if (pConn->isOpen())
97  {
98  pConn->Send(MkC4NetIOPacket(PID_ConnRe, Pkt));
99  pConn->Close();
100  }
101  // remove
102  RemoveConn(pConn);
103  }
104 }
@ PID_ConnRe
Definition: C4PacketBase.h:89
void RemoveConn(C4Network2IOConnection *pConn)
bool Send(const C4NetIOPacket &rPkt)

References C4Network2IOConnection::Close(), C4Network2IOConnection::isOpen(), MkC4NetIOPacket(), PID_ConnRe, pMsgConn, RemoveConn(), and C4Network2IOConnection::Send().

Referenced by C4Network2ClientList::DeleteClient().

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

◆ CreateGraphs()

void C4Network2Client::CreateGraphs ( )

Definition at line 296 of file C4Network2Client.cpp.

297 {
298  // del prev
299  ClearGraphs();
300  // get client color
301  static const DWORD ClientDefColors[] = {0xff0000, 0x00ff00, 0xffff00, 0x7f7fff, 0xffffff, 0x00ffff, 0xff00ff, 0x7f7f7f, 0xff7f7f, 0x7fff7f, 0x0000ff};
302  int32_t iClientColorNum = sizeof(ClientDefColors)/sizeof(DWORD);
303  DWORD dwClientClr = ClientDefColors[std::max<int32_t>(getID(), 0) % iClientColorNum];
304  // create graphs
306  pstatPing->SetColorDw(dwClientClr);
308  // register into stat module
309  if (Game.pNetworkStatistics) Game.pNetworkStatistics->statPings.AddGraph(pstatPing);
310 }
uint32_t DWORD
void SetTitle(const char *szNewTitle)
void SetColorDw(DWORD dwClr)
const char * getName() const

References ClearGraphs(), C4TableGraph::DefaultBlockLength, Game, getID(), getName(), C4Game::pNetworkStatistics, pstatPing, C4Graph::SetColorDw(), and C4Graph::SetTitle().

Referenced by C4Network2Stats::C4Network2Stats().

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

◆ DoConnectAttempt()

bool C4Network2Client::DoConnectAttempt ( class C4Network2IO pIO)

Definition at line 116 of file C4Network2Client.cpp.

117 {
118  // local?
119  if (isLocal()) { iNextConnAttempt = 0; return true; }
120  // msg and data connected? Nothing to do
121  if (getMsgConn() != getDataConn()) { iNextConnAttempt = time(nullptr) + 10; return true; }
122  // too early?
123  if (iNextConnAttempt && iNextConnAttempt > time(nullptr)) return true;
124  // find address to try
125  int32_t iBestAddress = -1;
126  for (int32_t i = 0; i < iAddrCnt; i++)
127  // no connection for this protocol?
128  if ((!pDataConn || Addr[i].getProtocol() != pDataConn->getProtocol()) &&
129  (!pMsgConn || Addr[i].getProtocol() != pMsgConn->getProtocol()))
130  // protocol available?
131  if (pIO->getNetIO(Addr[i].getProtocol()))
132  // new best address?
133  if (iBestAddress < 0 || AddrAttempts[i] < AddrAttempts[iBestAddress])
134  iBestAddress = i;
135  // too many attempts or nothing found?
136  if (iBestAddress < 0 || AddrAttempts[iBestAddress] > C4NetClientConnectAttempts)
137  { iNextConnAttempt = time(nullptr) + 10; return true; }
138  // save attempt
139  AddrAttempts[iBestAddress]++; iNextConnAttempt = time(nullptr) + C4NetClientConnectInterval;
140  auto addr = Addr[iBestAddress].getAddr();
141 
142  // try TCP simultaneous open if the stars align right
143  if (addr.GetFamily() == C4NetIO::addr_t::IPv6 && // address needs to be IPv6...
144  !addr.IsLocal() && !addr.IsPrivate() && // ...global unicast...
145  Addr[iBestAddress].getProtocol() == P_TCP && // ...TCP,
146  !TcpSimOpenSocket && // there is no previous request,
147  pParent->GetLocal()->getID() < getID()) // and make sure that only one client per pair initiates a request.
148  {
150  }
151 
152  std::set<int> interfaceIDs;
153  if (addr.IsLocal())
154  interfaceIDs = Network.Clients.GetLocal()->getInterfaceIDs();
155  else
156  interfaceIDs = {0};
157  for (auto id : interfaceIDs)
158  {
159  addr.SetScopeId(id);
160  // log
161  LogSilentF("Network: connecting client %s on %s...", getName(), addr.ToString().getData());
162  // connect
163  if (pIO->Connect(addr, Addr[iBestAddress].getProtocol(), pClient->getCore()))
164  return true;
165  }
166  return false;
167 }
C4Network2 Network
Definition: C4Globals.cpp:53
bool LogSilentF(const char *strMessage,...)
Definition: C4Log.cpp:272
const int32_t C4NetClientConnectAttempts
const int32_t C4NetClientConnectInterval
const C4ClientCore & getCore() const
Definition: C4Client.h:104
const C4NetIO::addr_t & getAddr() const
C4Network2IOProtocol getProtocol() const
bool DoTCPSimultaneousOpen(class C4Network2IO *pIO, const C4Network2Address &addr)
const std::set< int > & getInterfaceIDs() const
C4Network2IOConnection * getDataConn() const
bool isLocal() const
C4Network2IOConnection * getMsgConn() const
std::unique_ptr< C4NetIOTCP::Socket > TcpSimOpenSocket
C4Network2Client * GetLocal() const
C4Network2ClientList Clients
Definition: C4Network2.h:116
C4Network2IOProtocol getProtocol() const
Definition: C4Network2IO.h:265

References Addr, AddrAttempts, C4NetClientConnectAttempts, C4NetClientConnectInterval, C4Network2::Clients, C4Network2IO::Connect(), DoTCPSimultaneousOpen(), C4Network2Address::getAddr(), C4Client::getCore(), getDataConn(), getID(), getInterfaceIDs(), C4Network2ClientList::GetLocal(), getMsgConn(), getName(), C4Network2IO::getNetIO(), C4Network2Address::getProtocol(), C4Network2IOConnection::getProtocol(), iAddrCnt, iNextConnAttempt, C4NetIO::HostAddress::IPv6, isLocal(), LogSilentF(), Network, P_TCP, pClient, pDataConn, pMsgConn, pParent, and TcpSimOpenSocket.

Referenced by C4Network2ClientList::HandlePacket().

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

◆ DoTCPSimultaneousOpen()

bool C4Network2Client::DoTCPSimultaneousOpen ( class C4Network2IO pIO,
const C4Network2Address addr 
)

Definition at line 169 of file C4Network2Client.cpp.

170 {
171  if (!pIO->getNetIO(P_TCP)) return false;
172 
173  // Did we already bind a socket?
174  if (TcpSimOpenSocket)
175  {
176  LogSilentF("Network: connecting client %s on %s with TCP simultaneous open...", getName(), addr.getAddr().ToString().getData());
177  return pIO->ConnectWithSocket(addr.getAddr(), addr.getProtocol(), pClient->getCore(), std::move(TcpSimOpenSocket));
178  }
179  else
180  {
181  // No - bind one, inform peer, and schedule a connection attempt.
182  auto NetIOTCP = dynamic_cast<C4NetIOTCP*>(pIO->getNetIO(P_TCP));
183  auto bindAddr = pParent->GetLocal()->IPv6AddrFromPuncher;
184  // We need to know an address that works.
185  if (bindAddr.IsNull()) return false;
186  bindAddr.SetPort(0);
187  TcpSimOpenSocket = NetIOTCP->Bind(bindAddr);
188  auto boundAddr = TcpSimOpenSocket->GetAddress();
189  LogSilentF("Network: %s TCP simultaneous open request for client %s from %s...", addr.isIPNull() ? "initiating" : "responding to",
190  getName(), boundAddr.ToString().getData());
191  // Send address we bound to to the client.
193  return false;
194  if (!addr.isIPNull())
195  {
196  // We need to delay the connection attempt a bit. Unfortunately,
197  // waiting for the next tick would usually take way too much time.
198  // Instead, we block the main thread for a very short time and hope
199  // that noone notices...
200  int ping = getMsgConn()->getLag();
201  std::this_thread::sleep_for(std::chrono::milliseconds(std::min(ping / 2, 10)));
202  DoTCPSimultaneousOpen(pIO, addr);
203  }
204  return true;
205  }
206 }
@ PID_TCPSimOpen
Definition: C4PacketBase.h:113
bool isIPNull() const
bool SendMsg(C4NetIOPacket rPkt) const
const char * getData() const
Definition: StdBuf.h:442
StdStrBuf ToString(int flags=0) const
Definition: C4NetIO.cpp:604

References C4Network2IO::ConnectWithSocket(), C4Network2Address::getAddr(), C4Client::getCore(), StdStrBuf::getData(), getID(), C4Network2IOConnection::getLag(), C4Network2ClientList::GetLocal(), getMsgConn(), getName(), C4Network2IO::getNetIO(), C4Network2Address::getProtocol(), IPv6AddrFromPuncher, C4Network2Address::isIPNull(), LogSilentF(), MkC4NetIOPacket(), P_TCP, pClient, PID_TCPSimOpen, pParent, SendMsg(), C4NetIO::EndpointAddress::SetPort(), TcpSimOpenSocket, and C4NetIO::EndpointAddress::ToString().

Referenced by DoConnectAttempt(), and C4Network2ClientList::HandlePacket().

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

◆ getAddr()

const C4Network2Address& C4Network2Client::getAddr ( int32_t  i) const
inline

Definition at line 94 of file C4Network2Client.h.

94 { return Addr[i]; }

References Addr.

Referenced by C4Network2Reference::InitLocal(), SendAddresses(), and C4Network2ClientDlg::UpdateText().

Here is the caller graph for this function:

◆ getAddrCnt()

int32_t C4Network2Client::getAddrCnt ( ) const
inline

Definition at line 93 of file C4Network2Client.h.

93 { return iAddrCnt; }

References iAddrCnt.

Referenced by C4Network2Reference::InitLocal(), and C4Network2ClientDlg::UpdateText().

Here is the caller graph for this function:

◆ getClient()

C4Client* C4Network2Client::getClient ( ) const
inline

Definition at line 84 of file C4Network2Client.h.

84 { return pClient; }

References pClient.

Referenced by getCore(), C4Network2::OnClientConnect(), C4Network2::OnClientDisconnect(), and C4Network2::OnGameSynchronized().

Here is the caller graph for this function:

◆ getCore()

const C4ClientCore& C4Network2Client::getCore ( ) const
inline

Definition at line 85 of file C4Network2Client.h.

85 { return getClient()->getCore(); }
C4Client * getClient() const

References getClient(), and C4Client::getCore().

Referenced by C4Network2::CheckConn(), C4Network2ClientList::DeleteClient(), getID(), getName(), C4Network2::HandleConnRe(), isActivated(), and isObserver().

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

◆ getDataConn()

C4Network2IOConnection* C4Network2Client::getDataConn ( ) const
inline

Definition at line 116 of file C4Network2Client.h.

116 { return pDataConn; }

References pDataConn.

Referenced by DoConnectAttempt(), SendData(), C4Network2ClientListBox::Update(), and C4Network2ClientDlg::UpdateText().

Here is the caller graph for this function:

◆ getID()

int32_t C4Network2Client::getID ( ) const
inline

Definition at line 86 of file C4Network2Client.h.

86 { return getCore().getID(); }
int32_t getID() const
Definition: C4Client.h:57
const C4ClientCore & getCore() const

References getCore(), and C4ClientCore::getID().

Referenced by AddAddr(), CreateGraphs(), DoConnectAttempt(), DoTCPSimultaneousOpen(), C4Network2::DrawStatus(), C4Network2ClientList::GetNextClientAfterID(), C4Network2::HandleActivateReq(), isHost(), C4Network2::LeagueNotifyDisconnect(), C4Network2::OnClientDisconnect(), C4MessageInput::ProcessCommand(), C4Network2ClientList::RegClient(), SendAddresses(), and C4Network2::SendJoinData().

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

◆ getInterfaceIDs()

const std::set<int>& C4Network2Client::getInterfaceIDs ( ) const
inline

Definition at line 96 of file C4Network2Client.h.

96 { return InterfaceIDs; }

References InterfaceIDs.

Referenced by DoConnectAttempt().

Here is the caller graph for this function:

◆ getLastActivity()

int32_t C4Network2Client::getLastActivity ( ) const
inline

Definition at line 107 of file C4Network2Client.h.

107 { return iLastActivity; }

References iLastActivity.

◆ getMsgConn()

C4Network2IOConnection* C4Network2Client::getMsgConn ( ) const
inline

Definition at line 115 of file C4Network2Client.h.

115 { return pMsgConn; }

References pMsgConn.

Referenced by C4GameControlNetwork::CalcPerformance(), DoConnectAttempt(), DoTCPSimultaneousOpen(), C4Network2Stats::ExecuteSecond(), C4Network2::HandleActivateReq(), C4Network2::SendJoinData(), SendMsg(), C4Network2ClientList::SendMsgToHost(), C4Network2ClientListBox::Update(), and C4Network2ClientDlg::UpdateText().

Here is the caller graph for this function:

◆ getName()

const char* C4Network2Client::getName ( ) const
inline

Definition at line 89 of file C4Network2Client.h.

89 { return getCore().getName(); }
const char * getName() const
Definition: C4Client.h:69

References getCore(), and C4ClientCore::getName().

Referenced by CreateGraphs(), DoConnectAttempt(), DoTCPSimultaneousOpen(), C4Network2::DrawStatus(), C4Network2::HandleConnRe(), C4Network2::OnClientDisconnect(), C4Network2::OnConnect(), and C4Network2::OnDisconnect().

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

◆ getNext()

C4Network2Client* C4Network2Client::getNext ( ) const
inline

◆ getNextConnAttempt()

time_t C4Network2Client::getNextConnAttempt ( ) const
inline

Definition at line 106 of file C4Network2Client.h.

106 { return iNextConnAttempt; }

References iNextConnAttempt.

◆ getStatPing()

class C4TableGraph* C4Network2Client::getStatPing ( ) const
inline

Definition at line 108 of file C4Network2Client.h.

108 { return pstatPing; }

References pstatPing.

Referenced by C4Network2Stats::ExecuteSecond().

Here is the caller graph for this function:

◆ getStatus()

C4Network2ClientStatus C4Network2Client::getStatus ( ) const
inline

Definition at line 98 of file C4Network2Client.h.

98 { return eStatus; }

References eStatus.

Referenced by hasJoinData(), isChasing(), isReady(), isRemoved(), and isWaitedFor().

Here is the caller graph for this function:

◆ hasAddr()

bool C4Network2Client::hasAddr ( const C4Network2Address addr) const

Definition at line 208 of file C4Network2Client.cpp.

209 {
210  // Note that the host only knows its own address as 0.0.0.0, so if the real address is being added, that can't be sorted out.
211  for (int32_t i = 0; i < iAddrCnt; i++)
212  if (Addr[i] == addr)
213  return true;
214  return false;
215 }

References Addr, and iAddrCnt.

Referenced by AddAddr().

Here is the caller graph for this function:

◆ hasConn()

bool C4Network2Client::hasConn ( C4Network2IOConnection pConn)

Definition at line 49 of file C4Network2Client.cpp.

50 {
51  return pMsgConn == pConn || pDataConn == pConn;
52 }

References pDataConn, and pMsgConn.

Referenced by C4Network2::CheckConn().

Here is the caller graph for this function:

◆ hasJoinData()

bool C4Network2Client::hasJoinData ( ) const
inline

Definition at line 99 of file C4Network2Client.h.

99 { return getStatus() != NCS_Joining; }
@ NCS_Joining
C4Network2ClientStatus getStatus() const

References getStatus(), and NCS_Joining.

Referenced by C4Network2::HandleStatusAck(), C4Network2::OnClientConnect(), C4Network2::OnGameSynchronized(), and C4Network2::SendJoinData().

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

◆ isActivated()

bool C4Network2Client::isActivated ( ) const
inline

Definition at line 90 of file C4Network2Client.h.

90 { return getCore().isActivated(); }
bool isActivated() const
Definition: C4Client.h:59

References getCore(), and C4ClientCore::isActivated().

Referenced by C4Network2::DrawStatus(), and C4Network2::HandleActivateReq().

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

◆ isChasing()

bool C4Network2Client::isChasing ( ) const
inline

Definition at line 100 of file C4Network2Client.h.

100 { return getStatus() == NCS_Chasing; }
@ NCS_Chasing

References getStatus(), and NCS_Chasing.

Referenced by C4Network2::UpdateChaseTarget().

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

◆ isConnected()

bool C4Network2Client::isConnected ( ) const
inline

Definition at line 105 of file C4Network2Client.h.

105 { return !! pMsgConn; }

References pMsgConn.

Referenced by C4Network2::HandleConnRe(), C4Network2::OnConnectFail(), C4Network2::OnDisconn(), C4Network2::OnDisconnect(), C4Network2ClientList::SendMsgToClient(), and C4Network2ClientDlg::UpdateText().

Here is the caller graph for this function:

◆ isHost()

bool C4Network2Client::isHost ( ) const
inline

Definition at line 88 of file C4Network2Client.h.

88 { return getID() == C4ClientIDHost; }
const int32_t C4ClientIDHost
Definition: C4Client.h:25

References C4ClientIDHost, and getID().

Referenced by C4Network2::DrawStatus(), C4Network2::HandlePacket(), C4Network2Players::HandlePacket(), C4Network2::OnClientDisconnect(), and C4Network2::OnConnect().

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

◆ isLocal()

bool C4Network2Client::isLocal ( ) const
inline

Definition at line 87 of file C4Network2Client.h.

87 { return pClient->isLocal(); }
bool isLocal() const
Definition: C4Client.h:116

References C4Client::isLocal(), and pClient.

Referenced by C4GameControlNetwork::CalcPerformance(), DoConnectAttempt(), and C4Network2::HandlePacket().

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

◆ isObserver()

bool C4Network2Client::isObserver ( ) const
inline

Definition at line 91 of file C4Network2Client.h.

91 { return getCore().isObserver(); }
bool isObserver() const
Definition: C4Client.h:60

References getCore(), and C4ClientCore::isObserver().

Referenced by C4Network2::DrawStatus(), C4Viewport::Execute(), and C4Network2::HandleActivateReq().

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

◆ isReady()

bool C4Network2Client::isReady ( ) const
inline

Definition at line 101 of file C4Network2Client.h.

101 { return getStatus() == NCS_Ready; }

References getStatus(), and NCS_Ready.

Referenced by C4Network2ClientDlg::UpdateText().

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

◆ isRemoved()

bool C4Network2Client::isRemoved ( ) const
inline

Definition at line 103 of file C4Network2Client.h.

103 { return getStatus() == NCS_Remove; }
@ NCS_Remove

References getStatus(), and NCS_Remove.

Referenced by C4Network2::HandleStatusAck().

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

◆ isWaitedFor()

bool C4Network2Client::isWaitedFor ( ) const
inline

Definition at line 102 of file C4Network2Client.h.

102 { return getStatus() == NCS_NotReady || getStatus() == NCS_Ready; }
@ NCS_NotReady

References getStatus(), NCS_NotReady, and NCS_Ready.

Referenced by C4Network2::HandleActivateReq().

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

◆ RemoveConn()

void C4Network2Client::RemoveConn ( C4Network2IOConnection pConn)

Definition at line 78 of file C4Network2Client.cpp.

79 {
80  if (pConn == pMsgConn)
81  { pMsgConn->DelRef(); pMsgConn = nullptr; }
82  if (pConn == pDataConn)
83  { pDataConn->DelRef(); pDataConn = nullptr; }
86 }
void SetDataConn(C4Network2IOConnection *pConn)
void SetMsgConn(C4Network2IOConnection *pConn)

References C4Network2IOConnection::DelRef(), pDataConn, pMsgConn, SetDataConn(), and SetMsgConn().

Referenced by CloseConns(), and C4Network2::OnDisconn().

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

◆ SendAddresses()

void C4Network2Client::SendAddresses ( C4Network2IOConnection pConn)

Definition at line 278 of file C4Network2Client.cpp.

279 {
280  // send all addresses
281  for (int32_t i = 0; i < iAddrCnt; i++)
282  {
283  if (Addr[i].getAddr().GetScopeId() && (!pConn || pConn->getPeerAddr().GetScopeId() != Addr[i].getAddr().GetScopeId()))
284  continue;
285  C4Network2Address addr(Addr[i]);
286  addr.getAddr().SetScopeId(0);
288  if (pConn)
289  pConn->Send(Pkt);
290  else
292  }
293 
294 }
const C4Network2Address & getAddr(int32_t i) const
const C4NetIO::addr_t & getPeerAddr() const
Definition: C4Network2IO.h:266

References Addr, C4Network2ClientList::BroadcastMsgToConnClients(), C4Network2Address::getAddr(), getAddr(), getID(), C4Network2IOConnection::getPeerAddr(), C4NetIO::HostAddress::GetScopeId(), iAddrCnt, MkC4NetIOPacket(), PID_Addr, pParent, C4Network2IOConnection::Send(), and C4NetIO::HostAddress::SetScopeId().

Here is the call graph for this function:

◆ SendData()

bool C4Network2Client::SendData ( C4NetIOPacket  rPkt) const

Definition at line 111 of file C4Network2Client.cpp.

112 {
113  return getDataConn() && getDataConn()->Send(rPkt);
114 }

References getDataConn(), and C4Network2IOConnection::Send().

Here is the call graph for this function:

◆ SendMsg()

bool C4Network2Client::SendMsg ( C4NetIOPacket  rPkt) const

Definition at line 106 of file C4Network2Client.cpp.

107 {
108  return getMsgConn() && getMsgConn()->Send(rPkt);
109 }

References getMsgConn(), and C4Network2IOConnection::Send().

Referenced by DoTCPSimultaneousOpen(), C4Network2::HandleStatusAck(), C4Network2::SendJoinData(), C4Network2ClientList::SendMsgToClient(), C4Network2ClientList::SendMsgToHost(), and C4Network2::UpdateChaseTarget().

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

◆ SetDataConn()

void C4Network2Client::SetDataConn ( C4Network2IOConnection pConn)

Definition at line 66 of file C4Network2Client.cpp.

67 {
68  // security
69  if (pConn != pDataConn)
70  {
71  if (pDataConn) pDataConn->DelRef();
72  pDataConn = pConn;
73  pDataConn->AddRef();
74  }
75  if (!pMsgConn) SetMsgConn(pConn);
76 }

References C4Network2IOConnection::AddRef(), C4Network2IOConnection::DelRef(), pDataConn, pMsgConn, and SetMsgConn().

Referenced by C4Network2::HandleConnRe(), RemoveConn(), and SetMsgConn().

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

◆ SetLastActivity()

void C4Network2Client::SetLastActivity ( int32_t  iTick)
inline

Definition at line 113 of file C4Network2Client.h.

113 { iLastActivity = iTick; }

References iLastActivity.

Referenced by C4Client::SetActivated().

Here is the caller graph for this function:

◆ SetMsgConn()

void C4Network2Client::SetMsgConn ( C4Network2IOConnection pConn)

Definition at line 54 of file C4Network2Client.cpp.

55 {
56  // security
57  if (pConn != pMsgConn)
58  {
59  if (pMsgConn) pMsgConn->DelRef();
60  pMsgConn = pConn;
61  pMsgConn->AddRef();
62  }
63  if (!pDataConn) SetDataConn(pConn);
64 }

References C4Network2IOConnection::AddRef(), C4Network2IOConnection::DelRef(), pDataConn, pMsgConn, and SetDataConn().

Referenced by C4Network2::HandleConnRe(), RemoveConn(), and SetDataConn().

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

◆ SetStatus()

void C4Network2Client::SetStatus ( C4Network2ClientStatus  enStatus)
inline

Definition at line 112 of file C4Network2Client.h.

112 { eStatus = enStatus; }

References eStatus.

Referenced by C4ClientList::CtrlRemove(), C4Network2::HandleStatusAck(), C4Network2::Join(), and C4Network2::SendJoinData().

Here is the caller graph for this function:

Friends And Related Function Documentation

◆ C4Network2ClientList

friend class C4Network2ClientList
friend

Definition at line 46 of file C4Network2Client.h.

Member Data Documentation

◆ Addr

C4Network2Address C4Network2Client::Addr[C4ClientMaxAddr]
protected

Definition at line 56 of file C4Network2Client.h.

Referenced by AddAddr(), DoConnectAttempt(), getAddr(), hasAddr(), and SendAddresses().

◆ AddrAttempts

int32_t C4Network2Client::AddrAttempts[C4ClientMaxAddr]
protected

Definition at line 57 of file C4Network2Client.h.

Referenced by AddAddr(), and DoConnectAttempt().

◆ eStatus

C4Network2ClientStatus C4Network2Client::eStatus
protected

Definition at line 65 of file C4Network2Client.h.

Referenced by getStatus(), and SetStatus().

◆ iAddrCnt

int32_t C4Network2Client::iAddrCnt
protected

◆ iLastActivity

int32_t C4Network2Client::iLastActivity
protected

Definition at line 68 of file C4Network2Client.h.

Referenced by getLastActivity(), and SetLastActivity().

◆ iNextConnAttempt

time_t C4Network2Client::iNextConnAttempt
protected

Definition at line 72 of file C4Network2Client.h.

Referenced by AddAddr(), DoConnectAttempt(), and getNextConnAttempt().

◆ InterfaceIDs

std::set<int> C4Network2Client::InterfaceIDs
protected

Definition at line 62 of file C4Network2Client.h.

Referenced by AddLocalAddrs(), and getInterfaceIDs().

◆ IPv6AddrFromPuncher

C4NetIO::addr_t C4Network2Client::IPv6AddrFromPuncher
protected

Definition at line 59 of file C4Network2Client.h.

Referenced by AddAddrFromPuncher(), and DoTCPSimultaneousOpen().

◆ pClient

C4Client* C4Network2Client::pClient
protected

◆ pDataConn

C4Network2IOConnection * C4Network2Client::pDataConn
protected

◆ pMsgConn

◆ pNext

◆ pParent

class C4Network2ClientList* C4Network2Client::pParent
protected

◆ pstatPing

class C4TableGraph* C4Network2Client::pstatPing
protected

Definition at line 80 of file C4Network2Client.h.

Referenced by ClearGraphs(), CreateGraphs(), and getStatPing().

◆ TcpSimOpenSocket

std::unique_ptr<C4NetIOTCP::Socket> C4Network2Client::TcpSimOpenSocket
protected

Definition at line 73 of file C4Network2Client.h.

Referenced by DoConnectAttempt(), and DoTCPSimultaneousOpen().


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