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 }
class C4Network2ClientList * pParent
class C4TableGraph * pstatPing
C4Network2IOConnection * pDataConn
C4Network2Client * pNext
C4Network2ClientStatus eStatus
C4Network2IOConnection * pMsgConn

◆ ~C4Network2Client()

C4Network2Client::~C4Network2Client ( )

Definition at line 41 of file C4Network2Client.cpp.

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

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
C4Network2IOConnection * pDataConn
C4Network2IOConnection * pMsgConn
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.

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

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

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 }
class C4Network2ClientList * pParent
bool hasAddr(const C4Network2Address &addr) const
C4NetIOPacket MkC4NetIOPacket(char cStatus, const class C4PacketBase &Pkt, const C4NetIO::addr_t &addr=C4NetIO::addr_t())
Definition: C4PacketBase.h:40
C4Network2Address Addr[C4ClientMaxAddr]
const int32_t C4ClientMaxAddr
int32_t AddrAttempts[C4ClientMaxAddr]
int32_t getID() const
bool BroadcastMsgToConnClients(const C4NetIOPacket &rPkt)
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.

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 getDataConn(), and C4Network2::OnPuncherConnect().

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:833
C4NetIO::addr_t IPv6AddrFromPuncher
void SetPort(uint16_t port)
Definition: C4NetIO.cpp:531
C4ConfigNetwork Network
Definition: C4Config.h:255
uint16_t GetPort() const
Definition: C4NetIO.cpp:547
int32_t PortTCP
Definition: C4Config.h:153
bool AddAddr(const C4Network2Address &addr, bool fAnnounce)
AddressFamily GetFamily() const
Definition: C4NetIO.cpp:520
int32_t PortUDP
Definition: C4Config.h:153
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.

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

Referenced by getDataConn(), and C4Network2::InitNetIO().

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 }
void SetAddress(const sockaddr *addr)
Definition: C4NetIO.cpp:364
static std::vector< HostAddress > GetLocalAddresses()
Definition: C4NetIO.cpp:631
std::set< int > InterfaceIDs
void SetPort(uint16_t port)
Definition: C4NetIO.cpp:531
int GetScopeId() const
Definition: C4NetIO.cpp:296
bool AddAddr(const C4Network2Address &addr, bool fAnnounce)
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.

References iAddrCnt.

Referenced by getDataConn().

218 {
219  iAddrCnt = 0;
220 }
Here is the caller graph for this function:

◆ ClearGraphs()

void C4Network2Client::ClearGraphs ( )

Definition at line 312 of file C4Network2Client.cpp.

References Game, C4Game::pNetworkStatistics, and pstatPing.

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

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
class C4TableGraph * pstatPing
std::unique_ptr< C4Network2Stats > pNetworkStatistics
Definition: C4Game.h:95
Here is the caller graph for this function:

◆ CloseConns()

void C4Network2Client::CloseConns ( const char *  szMsg)

Definition at line 89 of file C4Network2Client.cpp.

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

Referenced by C4Network2ClientList::DeleteClient(), and getDataConn().

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 }
void RemoveConn(C4Network2IOConnection *pConn)
bool Send(const C4NetIOPacket &rPkt)
C4NetIOPacket MkC4NetIOPacket(char cStatus, const class C4PacketBase &Pkt, const C4NetIO::addr_t &addr=C4NetIO::addr_t())
Definition: C4PacketBase.h:40
C4Network2IOConnection * pMsgConn
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.

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

Referenced by C4Network2Stats::C4Network2Stats(), and getDataConn().

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);
307  pstatPing->SetTitle(getName());
308  // register into stat module
309  if (Game.pNetworkStatistics) Game.pNetworkStatistics->statPings.AddGraph(pstatPing);
310 }
C4Game Game
Definition: C4Globals.cpp:52
class C4TableGraph * pstatPing
const char * getName() const
int32_t getID() const
std::unique_ptr< C4Network2Stats > pNetworkStatistics
Definition: C4Game.h:95
uint32_t DWORD
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.

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 getDataConn(), and C4Network2ClientList::HandlePacket().

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 }
C4Network2Client * GetLocal() const
class C4Network2ClientList * pParent
const C4ClientCore & getCore() const
Definition: C4Client.h:104
bool isLocal() const
C4Network2IOConnection * getDataConn() const
C4Network2IOProtocol getProtocol() const
Definition: C4Network2IO.h:265
C4Network2IOConnection * getMsgConn() const
C4Network2IOProtocol getProtocol() const
bool LogSilentF(const char *strMessage,...)
Definition: C4Log.cpp:270
C4Network2 Network
Definition: C4Globals.cpp:53
C4Network2Address Addr[C4ClientMaxAddr]
const int32_t C4NetClientConnectInterval
C4Network2IOConnection * pDataConn
const int32_t C4NetClientConnectAttempts
C4Network2ClientList Clients
Definition: C4Network2.h:116
bool DoTCPSimultaneousOpen(class C4Network2IO *pIO, const C4Network2Address &addr)
const char * getName() const
int32_t AddrAttempts[C4ClientMaxAddr]
int32_t getID() const
C4Network2IOConnection * pMsgConn
const std::set< int > & getInterfaceIDs() const
std::unique_ptr< C4NetIOTCP::Socket > TcpSimOpenSocket
const C4NetIO::addr_t & getAddr() const
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.

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(), getDataConn(), and C4Network2ClientList::HandlePacket().

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 }
bool isIPNull() const
C4Network2Client * GetLocal() const
class C4Network2ClientList * pParent
bool SendMsg(C4NetIOPacket rPkt) const
const C4ClientCore & getCore() const
Definition: C4Client.h:104
C4NetIO::addr_t IPv6AddrFromPuncher
StdStrBuf ToString(int flags=0) const
Definition: C4NetIO.cpp:604
C4Network2IOConnection * getMsgConn() const
C4Network2IOProtocol getProtocol() const
bool LogSilentF(const char *strMessage,...)
Definition: C4Log.cpp:270
C4NetIOPacket MkC4NetIOPacket(char cStatus, const class C4PacketBase &Pkt, const C4NetIO::addr_t &addr=C4NetIO::addr_t())
Definition: C4PacketBase.h:40
void SetPort(uint16_t port)
Definition: C4NetIO.cpp:531
const char * getData() const
Definition: StdBuf.h:442
bool DoTCPSimultaneousOpen(class C4Network2IO *pIO, const C4Network2Address &addr)
const char * getName() const
int32_t getID() const
std::unique_ptr< C4NetIOTCP::Socket > TcpSimOpenSocket
const C4NetIO::addr_t & getAddr() const
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.

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

94 { return Addr[i]; }
C4Network2Address Addr[C4ClientMaxAddr]
Here is the caller graph for this function:

◆ getAddrCnt()

int32_t C4Network2Client::getAddrCnt ( ) const
inline

Definition at line 93 of file C4Network2Client.h.

References iAddrCnt.

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

93 { return iAddrCnt; }
Here is the caller graph for this function:

◆ getClient()

C4Client* C4Network2Client::getClient ( ) const
inline

Definition at line 84 of file C4Network2Client.h.

References pClient.

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

84 { return pClient; }
Here is the caller graph for this function:

◆ getCore()

const C4ClientCore& C4Network2Client::getCore ( ) const
inline

Definition at line 85 of file C4Network2Client.h.

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

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

85 { return getClient()->getCore(); }
C4Client * getClient() const
const C4ClientCore & getCore() const
Definition: C4Client.h:104
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.

References AddAddr(), AddAddrFromPuncher(), AddLocalAddrs(), ClearAddr(), ClearGraphs(), CloseConns(), CreateGraphs(), DoConnectAttempt(), DoTCPSimultaneousOpen(), hasAddr(), hasConn(), pDataConn, RemoveConn(), SendAddresses(), SendData(), SendMsg(), SetDataConn(), and SetMsgConn().

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

116 { return pDataConn; }
C4Network2IOConnection * pDataConn
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getID()

int32_t C4Network2Client::getID ( ) const
inline

Definition at line 86 of file C4Network2Client.h.

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

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

86 { return getCore().getID(); }
const C4ClientCore & getCore() const
int32_t getID() const
Definition: C4Client.h:57
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.

References InterfaceIDs.

Referenced by DoConnectAttempt(), and C4Network2::InitialConnect::Execute().

96 { return InterfaceIDs; }
std::set< int > InterfaceIDs
Here is the caller graph for this function:

◆ getLastActivity()

int32_t C4Network2Client::getLastActivity ( ) const
inline

Definition at line 107 of file C4Network2Client.h.

References iLastActivity.

107 { return iLastActivity; }

◆ getMsgConn()

C4Network2IOConnection* C4Network2Client::getMsgConn ( ) const
inline

Definition at line 115 of file C4Network2Client.h.

References pMsgConn.

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

115 { return pMsgConn; }
C4Network2IOConnection * pMsgConn
Here is the caller graph for this function:

◆ getName()

const char* C4Network2Client::getName ( ) const
inline

Definition at line 89 of file C4Network2Client.h.

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

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

89 { return getCore().getName(); }
const char * getName() const
Definition: C4Client.h:69
const C4ClientCore & getCore() const
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.

References iNextConnAttempt.

106 { return iNextConnAttempt; }

◆ getStatPing()

class C4TableGraph* C4Network2Client::getStatPing ( ) const
inline

Definition at line 108 of file C4Network2Client.h.

References pstatPing.

Referenced by C4Network2Stats::ExecuteSecond().

108 { return pstatPing; }
class C4TableGraph * pstatPing
Here is the caller graph for this function:

◆ getStatus()

C4Network2ClientStatus C4Network2Client::getStatus ( ) const
inline

Definition at line 98 of file C4Network2Client.h.

References eStatus.

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

98 { return eStatus; }
C4Network2ClientStatus eStatus
Here is the caller graph for this function:

◆ hasAddr()

bool C4Network2Client::hasAddr ( const C4Network2Address addr) const

Definition at line 208 of file C4Network2Client.cpp.

References Addr, and iAddrCnt.

Referenced by AddAddr(), and getDataConn().

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 }
C4Network2Address Addr[C4ClientMaxAddr]
Here is the caller graph for this function:

◆ hasConn()

bool C4Network2Client::hasConn ( C4Network2IOConnection pConn)

Definition at line 49 of file C4Network2Client.cpp.

References pDataConn, and pMsgConn.

Referenced by C4Network2::CheckConn(), and getDataConn().

50 {
51  return pMsgConn == pConn || pDataConn == pConn;
52 }
C4Network2IOConnection * pDataConn
C4Network2IOConnection * pMsgConn
Here is the caller graph for this function:

◆ hasJoinData()

bool C4Network2Client::hasJoinData ( ) const
inline

Definition at line 99 of file C4Network2Client.h.

References getStatus(), and NCS_Joining.

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

99 { return getStatus() != NCS_Joining; }
C4Network2ClientStatus getStatus() const
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.

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

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

90 { return getCore().isActivated(); }
bool isActivated() const
Definition: C4Client.h:59
const C4ClientCore & getCore() const
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.

References getStatus(), and NCS_Chasing.

Referenced by C4Network2::UpdateChaseTarget().

100 { return getStatus() == NCS_Chasing; }
C4Network2ClientStatus getStatus() const
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.

References pMsgConn.

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

105 { return !! pMsgConn; }
C4Network2IOConnection * pMsgConn
Here is the caller graph for this function:

◆ isHost()

bool C4Network2Client::isHost ( ) const
inline

Definition at line 88 of file C4Network2Client.h.

References C4ClientIDHost, and getID().

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

88 { return getID() == C4ClientIDHost; }
int32_t getID() const
const int32_t C4ClientIDHost
Definition: C4Client.h:25
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.

References C4Client::isLocal().

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

87 { return pClient->isLocal(); }
bool isLocal() const
Definition: C4Client.h:116
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.

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

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

91 { return getCore().isObserver(); }
bool isObserver() const
Definition: C4Client.h:60
const C4ClientCore & getCore() const
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.

References getStatus(), and NCS_Ready.

Referenced by C4Network2ClientDlg::UpdateText().

101 { return getStatus() == NCS_Ready; }
C4Network2ClientStatus getStatus() const
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.

References getStatus(), and NCS_Remove.

Referenced by C4Network2::HandleStatusAck().

103 { return getStatus() == NCS_Remove; }
C4Network2ClientStatus getStatus() const
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.

References getStatus(), NCS_NotReady, and NCS_Ready.

Referenced by C4Network2::HandleActivateReq().

102 { return getStatus() == NCS_NotReady || getStatus() == NCS_Ready; }
C4Network2ClientStatus getStatus() const
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.

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

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

79 {
80  if (pConn == pMsgConn)
81  { pMsgConn->DelRef(); pMsgConn = nullptr; }
82  if (pConn == pDataConn)
83  { pDataConn->DelRef(); pDataConn = nullptr; }
86 }
void SetMsgConn(C4Network2IOConnection *pConn)
void SetDataConn(C4Network2IOConnection *pConn)
C4Network2IOConnection * pDataConn
C4Network2IOConnection * pMsgConn
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.

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

Referenced by getDataConn(), and C4Network2ClientList::GetLocal().

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 }
class C4Network2ClientList * pParent
bool Send(const C4NetIOPacket &rPkt)
C4NetIOPacket MkC4NetIOPacket(char cStatus, const class C4PacketBase &Pkt, const C4NetIO::addr_t &addr=C4NetIO::addr_t())
Definition: C4PacketBase.h:40
C4Network2Address Addr[C4ClientMaxAddr]
const C4NetIO::addr_t & getPeerAddr() const
Definition: C4Network2IO.h:266
const C4Network2Address & getAddr(int32_t i) const
int GetScopeId() const
Definition: C4NetIO.cpp:296
int32_t getID() const
bool BroadcastMsgToConnClients(const C4NetIOPacket &rPkt)
const C4NetIO::addr_t & getAddr() const
Here is the call graph for this function:
Here is the caller graph for this function:

◆ SendData()

bool C4Network2Client::SendData ( C4NetIOPacket  rPkt) const

Definition at line 111 of file C4Network2Client.cpp.

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

Referenced by getDataConn().

112 {
113  return getDataConn() && getDataConn()->Send(rPkt);
114 }
bool Send(const C4NetIOPacket &rPkt)
C4Network2IOConnection * getDataConn() const
Here is the call graph for this function:
Here is the caller graph for this function:

◆ SendMsg()

bool C4Network2Client::SendMsg ( C4NetIOPacket  rPkt) const

Definition at line 106 of file C4Network2Client.cpp.

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

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

107 {
108  return getMsgConn() && getMsgConn()->Send(rPkt);
109 }
bool Send(const C4NetIOPacket &rPkt)
C4Network2IOConnection * getMsgConn() const
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.

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

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

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 }
void SetMsgConn(C4Network2IOConnection *pConn)
C4Network2IOConnection * pDataConn
C4Network2IOConnection * pMsgConn
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.

Referenced by C4Client::SetActivated().

113 { iLastActivity = iTick; }
Here is the caller graph for this function:

◆ SetMsgConn()

void C4Network2Client::SetMsgConn ( C4Network2IOConnection pConn)

Definition at line 54 of file C4Network2Client.cpp.

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

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

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 }
void SetDataConn(C4Network2IOConnection *pConn)
C4Network2IOConnection * pDataConn
C4Network2IOConnection * pMsgConn
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.

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

112 { eStatus = enStatus; }
C4Network2ClientStatus eStatus
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(), 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().

◆ iAddrCnt

int32_t C4Network2Client::iAddrCnt
protected

◆ iLastActivity

int32_t C4Network2Client::iLastActivity
protected

Definition at line 68 of file C4Network2Client.h.

Referenced by getLastActivity().

◆ 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

Definition at line 77 of file C4Network2Client.h.

Referenced by AddAddr(), DoConnectAttempt(), DoTCPSimultaneousOpen(), and SendAddresses().

◆ 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: