OpenClonk
C4ClientList Class Reference

#include <C4Client.h>

Collaboration diagram for C4ClientList:
[legend]

Public Member Functions

 C4ClientList ()
 
 ~C4ClientList ()
 
C4ClientListoperator= (const C4ClientList &List)
 
void Clear ()
 
C4ClientgetClient (const C4Client *pAfter=nullptr) const
 
C4ClientgetLocal () const
 
C4ClientgetClientByID (int32_t iID) const
 
C4ClientgetHost () const
 
C4ClientgetNextClientByID (int32_t iAfterID) const
 
C4ClientgetClientByName (const char *szName) const
 
int32_t getClientCnt () const
 
const C4ClientCoregetLocalCore () const
 
const char * getLocalName () const
 
int32_t getLocalID () const
 
StdStrBuf GetAllClientNames () const
 
bool Init (int32_t iLocalClientID=C4ClientIDHost)
 
void InitNetwork (class C4Network2ClientList *pNetClients)
 
void ClearNetwork ()
 
bool Remove (C4Client *pClient, bool fTemporary=false)
 
C4ClientAdd (const C4ClientCore &Core)
 
C4ClientAddLocal (int32_t iID, bool fActivated, bool fObserver)
 
void SetLocalID (int32_t iID)
 
void CtrlRemove (const C4Client *pClient, const char *szReason)
 
void RemoveRemote ()
 
void CompileFunc (StdCompiler *pComp)
 

Protected Member Functions

void Add (C4Client *pClient)
 

Protected Attributes

C4ClientpFirst {nullptr}
 
C4ClientpLocal {nullptr}
 
class C4Network2ClientListpNetClients {nullptr}
 

Detailed Description

Definition at line 137 of file C4Client.h.

Constructor & Destructor Documentation

◆ C4ClientList()

C4ClientList::C4ClientList ( )
default

◆ ~C4ClientList()

C4ClientList::~C4ClientList ( )

Definition at line 165 of file C4Client.cpp.

166 {
167  Clear();
168 }
void Clear()
Definition: C4Client.cpp:170

References Clear().

Here is the call graph for this function:

Member Function Documentation

◆ Add() [1/2]

void C4ClientList::Add ( C4Client pClient)
protected

Definition at line 181 of file C4Client.cpp.

182 {
183  // local client?
184  if (pClient->isLocal()) pLocal = pClient;
185  // already in list?
186  assert(!getClientByID(pClient->getID()));
187  // find insert position
188  C4Client *pPos = pFirst, *pPrev = nullptr;
189  for (; pPos; pPrev = pPos, pPos = pPos->pNext)
190  if (pPos->getID() > pClient->getID())
191  break;
192  // add to list
193  pClient->pNext = pPos;
194  (pPrev ? pPrev->pNext : pFirst) = pClient;
195  // register to network
196  if (pNetClients)
197  pClient->pNetClient = pNetClients->RegClient(pClient);
198 }
bool isLocal() const
Definition: C4Client.h:116
int32_t getID() const
Definition: C4Client.h:105
C4Client * pFirst
Definition: C4Client.h:149
C4Client * getClientByID(int32_t iID) const
Definition: C4Client.cpp:200
class C4Network2ClientList * pNetClients
Definition: C4Client.h:155
C4Client * pLocal
Definition: C4Client.h:152
C4Network2Client * RegClient(C4Client *pClient)

References getClientByID(), C4Client::getID(), C4Client::isLocal(), pFirst, pLocal, pNetClients, and C4Network2ClientList::RegClient().

Referenced by Add(), AddLocal(), CompileFunc(), C4Network2::HostConnect(), operator=(), and SetLocalID().

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

◆ Add() [2/2]

C4Client * C4ClientList::Add ( const C4ClientCore Core)

Definition at line 297 of file C4Client.cpp.

298 {
299  // client with same ID in list?
300  if (getClientByID(Core.getID()))
301  { Log("ClientList: Duplicated client ID!"); return nullptr; }
302  // create, add
303  C4Client *pClient = new C4Client(Core);
304  Add(pClient);
305  return pClient;
306 }
bool Log(const char *szMessage)
Definition: C4Log.cpp:204
int32_t getID() const
Definition: C4Client.h:57
void Add(C4Client *pClient)
Definition: C4Client.cpp:181

References Add(), getClientByID(), C4ClientCore::getID(), and Log().

Here is the call graph for this function:

◆ AddLocal()

C4Client * C4ClientList::AddLocal ( int32_t  iID,
bool  fActivated,
bool  fObserver 
)

Definition at line 308 of file C4Client.cpp.

309 {
310  // only one local client allowed
311  assert(!pLocal);
312  // create core
313  C4ClientCore LocalCore;
314  LocalCore.SetLocal(iID, fActivated, fObserver);
315  // create client
316  C4Client *pClient = new C4Client(LocalCore);
317  pClient->SetLocal();
318  // add
319  Add(pClient);
320  assert(pLocal);
321  return pClient;
322 }
void SetLocal(int32_t iID, bool fnActivated, bool fnObserver)
Definition: C4Client.cpp:38
void SetLocal()
Definition: C4Client.cpp:141

References Add(), pLocal, C4Client::SetLocal(), and C4ClientCore::SetLocal().

Referenced by Init().

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

◆ Clear()

void C4ClientList::Clear ( )

Definition at line 170 of file C4Client.cpp.

171 {
172  ClearNetwork();
173  while (pFirst)
174  {
175  C4Client *pClient = pFirst;
176  Remove(pClient, true);
177  delete pClient;
178  }
179 }
bool Remove(C4Client *pClient, bool fTemporary=false)
Definition: C4Client.cpp:270
void ClearNetwork()
Definition: C4Client.cpp:262

References ClearNetwork(), pFirst, and Remove().

Referenced by C4GameParameters::Clear(), CompileFunc(), Init(), and ~C4ClientList().

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

◆ ClearNetwork()

void C4ClientList::ClearNetwork ( )

Definition at line 262 of file C4Client.cpp.

263 {
264  // clear the list (should remove links)
265  C4Network2ClientList *pOldNetClients = pNetClients;
266  pNetClients = nullptr;
267  if (pOldNetClients) pOldNetClients->Clear();
268 }

References C4Network2ClientList::Clear(), and pNetClients.

Referenced by Clear(), and C4Network2ClientList::Clear().

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

◆ CompileFunc()

void C4ClientList::CompileFunc ( StdCompiler pComp)

Definition at line 393 of file C4Client.cpp.

394 {
395  // Clear existing data
396  bool deserializing = pComp->isDeserializer();
397  if (deserializing) Clear();
398  // Client count
399  uint32_t iClientCnt = getClientCnt();
400  pComp->Value(mkNamingCountAdapt(iClientCnt, "Client"));
401  // Compile all clients
402  if (pComp->isDeserializer())
403  for (uint32_t i = 0; i < iClientCnt; i++)
404  {
405  C4Client *pClient = new C4Client();
406  pComp->Value(mkNamingAdapt(*pClient, "Client"));
407  Add(pClient);
408  }
409  else
410  for (C4Client *pClient = pFirst; pClient; pClient = pClient->pNext)
411  pComp->Value(mkNamingAdapt(*pClient, "Client"));
412 }
StdNamingCountAdapt< int_t > mkNamingCountAdapt(int_t &iCount, const char *szName)
Definition: StdAdaptors.h:1008
StdNamingAdapt< T > mkNamingAdapt(T &&rValue, const char *szName)
Definition: StdAdaptors.h:92
int32_t getClientCnt() const
Definition: C4Client.cpp:224
void Value(const T &rStruct)
Definition: StdCompiler.h:161
virtual bool isDeserializer()
Definition: StdCompiler.h:53

References Add(), Clear(), getClientCnt(), StdCompiler::isDeserializer(), mkNamingAdapt(), mkNamingCountAdapt(), pFirst, and StdCompiler::Value().

Here is the call graph for this function:

◆ CtrlRemove()

void C4ClientList::CtrlRemove ( const C4Client pClient,
const char *  szReason 
)

Definition at line 333 of file C4Client.cpp.

334 {
335  // host only
336  if (!pLocal || !pLocal->isHost() || !pClient) return;
337  // Net client? flag
338  if (pClient->getNetClient())
339  pClient->getNetClient()->SetStatus(NCS_Remove);
340  // add control
342  new C4ControlClientRemove(pClient->getID(), szReason),
343  CDT_Sync);
344 }
C4GameControl Control
@ CDT_Sync
Definition: C4GameControl.h:35
@ NCS_Remove
@ CID_ClientRemove
Definition: C4PacketBase.h:146
C4Network2Client * getNetClient() const
Definition: C4Client.h:117
bool isHost() const
Definition: C4Client.h:106
void DoInput(C4PacketType eCtrlType, C4ControlPacket *pPkt, C4ControlDeliveryType eDelivery)
void SetStatus(C4Network2ClientStatus enStatus)

References CDT_Sync, CID_ClientRemove, Control, C4GameControl::DoInput(), C4Client::getID(), C4Client::getNetClient(), C4Client::isHost(), NCS_Remove, pLocal, and C4Network2Client::SetStatus().

Referenced by ConsoleDlgProc(), C4MainMenu::MenuCommand(), C4Network2::OnClientDisconnect(), C4Network2::OnGameSynchronized(), and C4MessageInput::ProcessCommand().

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

◆ GetAllClientNames()

StdStrBuf C4ClientList::GetAllClientNames ( ) const

Definition at line 232 of file C4Client.cpp.

233 {
234  StdStrBuf result;
235  for (C4Client *pClient = pFirst; pClient; pClient = pClient->pNext)
236  {
237  if (result.getSize()) result.Append(", ");
238  result.Append(pClient->getName());
239  }
240  return result;
241 }
size_t getSize() const
Definition: StdBuf.h:444
void Append(const char *pnData, size_t iChars)
Definition: StdBuf.h:519

References StdStrBuf::Append(), StdStrBuf::getSize(), and pFirst.

Referenced by C4StartupNetListEntry::SetReference().

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

◆ getClient()

C4Client* C4ClientList::getClient ( const C4Client pAfter = nullptr) const
inline

Definition at line 160 of file C4Client.h.

160 { return pAfter ? pAfter->pNext : pFirst; }

References pFirst.

Referenced by C4MainMenu::ActivateMain(), C4GameControlNetwork::CopyClientList(), and C4Network2ClientListBox::Update().

Here is the caller graph for this function:

◆ getClientByID()

C4Client * C4ClientList::getClientByID ( int32_t  iID) const

Definition at line 200 of file C4Client.cpp.

201 {
202  for (C4Client *pClient = pFirst; pClient; pClient = pClient->pNext)
203  if (pClient->getID() == iID)
204  return pClient;
205  return nullptr;
206 }

References pFirst.

Referenced by Add(), ConsoleDlgProc(), C4Network2Players::GetClientChatColor(), C4ControlVote::getDesc(), getHost(), C4Network2::HandleJoinData(), C4Network2Players::HandlePlayerInfo(), C4Game::InitNetworkFromReference(), C4MainMenu::MenuCommand(), C4Network2Players::OnStatusGoReached(), C4Network2::OpenVoteDialog(), operator=(), C4ControlJoinPlayer::PreExecute(), C4PlayerInfoList::RecreatePlayers(), C4PlayerInfoList::SetAsRestoreInfos(), and C4Network2ClientDlg::UpdateText().

Here is the caller graph for this function:

◆ getClientByName()

C4Client * C4ClientList::getClientByName ( const char *  szName) const

Definition at line 216 of file C4Client.cpp.

217 {
218  for (C4Client *pClient = pFirst; pClient; pClient = pClient->pNext)
219  if (SEqual(pClient->getName(), szName))
220  return pClient;
221  return nullptr;
222 }
bool SEqual(const char *szStr1, const char *szStr2)
Definition: Standard.h:93

References pFirst, and SEqual().

Referenced by C4MessageInput::ProcessCommand().

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

◆ getClientCnt()

int32_t C4ClientList::getClientCnt ( ) const

Definition at line 224 of file C4Client.cpp.

225 {
226  int32_t iCnt = 0;
227  for (C4Client *pClient = pFirst; pClient; pClient = pClient->pNext)
228  iCnt++;
229  return iCnt;
230 }
int iCnt
Definition: TstC4NetIO.cpp:32

References iCnt, and pFirst.

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

Here is the caller graph for this function:

◆ getHost()

C4Client* C4ClientList::getHost ( ) const
inline

Definition at line 163 of file C4Client.h.

163 { return getClientByID(C4ClientIDHost); }
const int32_t C4ClientIDHost
Definition: C4Client.h:25

References C4ClientIDHost, and getClientByID().

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

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

◆ getLocal()

C4Client* C4ClientList::getLocal ( ) const
inline

Definition at line 161 of file C4Client.h.

161 { return pLocal; }

References pLocal.

Referenced by C4GameControl::ChangeToLocal(), C4GameControlNetwork::DecideControlDelivery(), getLocalCore(), C4Game::InitControl(), C4Game::InitNetworkFromReference(), C4Game::InitNetworkHost(), C4Network2Players::JoinLocalPlayer(), C4GameControl::Prepare(), and C4Network2::RequestActivate().

Here is the caller graph for this function:

◆ getLocalCore()

const C4ClientCore& C4ClientList::getLocalCore ( ) const
inline

Definition at line 169 of file C4Client.h.

169 { return getLocal()->getCore(); }
const C4ClientCore & getCore() const
Definition: C4Client.h:104
C4Client * getLocal() const
Definition: C4Client.h:161

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

Referenced by getLocalID(), getLocalName(), and C4Network2::InitNetIO().

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

◆ getLocalID()

int32_t C4ClientList::getLocalID ( ) const
inline

Definition at line 171 of file C4Client.h.

171 { return pLocal ? getLocalCore().getID() : C4ClientIDUnknown; }
const int32_t C4ClientIDUnknown
Definition: C4Client.h:24
const C4ClientCore & getLocalCore() const
Definition: C4Client.h:169

References C4ClientIDUnknown, C4ClientCore::getID(), getLocalCore(), and pLocal.

Referenced by C4Network2::EndVote(), C4Network2Players::GetLocalPlayerInfoPacket(), C4Network2::InitHost(), C4GameLobby::MainDlg::OnClientAddPlayer(), C4GameLobby::MainDlg::OnMessage(), C4GameLobby::MainDlg::OnReadyCheck(), C4Network2::OpenVoteDialog(), C4Network2::RetrieveScenario(), C4Console::UpdateNetMenu(), and C4Network2::Vote().

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

◆ getLocalName()

const char* C4ClientList::getLocalName ( ) const
inline

Definition at line 170 of file C4Client.h.

170 { return pLocal ? getLocalCore().getName() : "???"; }
const char * getName() const
Definition: C4Client.h:69

References getLocalCore(), C4ClientCore::getName(), and pLocal.

Referenced by C4PlayerList::FileInUse(), and C4Console::UpdateNetMenu().

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

◆ getNextClientByID()

C4Client * C4ClientList::getNextClientByID ( int32_t  iAfterID) const

Definition at line 208 of file C4Client.cpp.

209 {
210  for (C4Client *pClient = pFirst; pClient; pClient = pClient->pNext)
211  if (pClient->getID() > iAfterID)
212  return pClient;
213  return nullptr;
214 }

References pFirst.

◆ Init()

bool C4ClientList::Init ( int32_t  iLocalClientID = C4ClientIDHost)

Definition at line 243 of file C4Client.cpp.

244 {
245  Clear();
246  // Add local client (activated, not observing)
247  AddLocal(iLocalClientID, true, false);
248  return true;
249 }
C4Client * AddLocal(int32_t iID, bool fActivated, bool fObserver)
Definition: C4Client.cpp:308

References AddLocal(), and Clear().

Referenced by C4Game::InitNetworkFromReference(), and C4Game::InitNetworkHost().

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

◆ InitNetwork()

void C4ClientList::InitNetwork ( class C4Network2ClientList pNetClients)

Definition at line 251 of file C4Client.cpp.

252 {
253  // clear list before
254  pnNetClients->Clear();
255  // set
256  pNetClients = pnNetClients;
257  // copy client list, create links
258  for (C4Client *pClient = pFirst; pClient; pClient = pClient->pNext)
259  pClient->pNetClient = pNetClients->RegClient(pClient);
260 }

References C4Network2ClientList::Clear(), pFirst, pNetClients, and C4Network2ClientList::RegClient().

Referenced by C4Network2ClientList::Init().

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

◆ operator=()

C4ClientList & C4ClientList::operator= ( const C4ClientList List)

Definition at line 361 of file C4Client.cpp.

362 {
363  // remove clients that are not in the list
364  C4Client *pClient, *pNext;
365  for (pClient = pFirst; pClient; pClient = pNext)
366  {
367  pNext = pClient->pNext;
368  if (!List.getClientByID(pClient->getID()))
369  {
370  Remove(pClient);
371  delete pClient;
372  }
373  }
374  // add all clients
375  for (pClient = List.pFirst; pClient; pClient = pClient->pNext)
376  {
377  // already in list?
378  C4Client *pNewClient = getClientByID(pClient->getID());
379  if (pNewClient)
380  {
381  // core change
382  pNewClient->SetCore(pClient->getCore());
383  }
384  else
385  {
386  // add
387  pNewClient = Add(pClient->getCore());
388  }
389  }
390  return *this;
391 }
void SetCore(const C4ClientCore &NewCore)
Definition: C4Client.h:119

References Add(), getClientByID(), C4Client::getCore(), C4Client::getID(), pFirst, Remove(), and C4Client::SetCore().

Here is the call graph for this function:

◆ Remove()

bool C4ClientList::Remove ( C4Client pClient,
bool  fTemporary = false 
)

Definition at line 270 of file C4Client.cpp.

271 {
272  // first client in list?
273  if (pClient == pFirst)
274  pFirst = pClient->pNext;
275  else
276  {
277  // find previous
278  C4Client *pPrev;
279  for (pPrev = pFirst; pPrev && pPrev->pNext != pClient; pPrev = pPrev->pNext) {}
280  // not found?
281  if (!pPrev) return false;
282  // unlink
283  pPrev->pNext = pClient->pNext;
284  }
285  if (pClient == pLocal) pLocal = nullptr;
286  if (!fTemporary)
287  {
288  pClient->Remove();
289  // remove network client
290  if (pNetClients && pClient->getNetClient())
292  }
293  // done
294  return true;
295 }
void Remove()
Definition: C4Client.cpp:147
void DeleteClient(C4Network2Client *pClient)

References C4Network2ClientList::DeleteClient(), C4Client::getNetClient(), pFirst, pLocal, pNetClients, and C4Client::Remove().

Referenced by Clear(), operator=(), RemoveRemote(), and SetLocalID().

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

◆ RemoveRemote()

void C4ClientList::RemoveRemote ( )

Definition at line 346 of file C4Client.cpp.

347 {
348  // remove all remote clients
349  for (C4Client *pClient = pFirst, *pNext; pClient; pClient = pNext)
350  {
351  pNext = pClient->pNext;
352  // remove all clients except the local client
353  if (!pClient->isLocal())
354  {
355  Remove(pClient);
356  delete pClient;
357  }
358  }
359 }

References pFirst, and Remove().

Referenced by C4GameControl::ChangeToLocal().

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

◆ SetLocalID()

void C4ClientList::SetLocalID ( int32_t  iID)

Definition at line 324 of file C4Client.cpp.

325 {
326  if (!pLocal) return;
327  pLocal->SetID(iID);
328  // resort local client
329  C4Client *pSavedLocal = pLocal;
330  Remove(pLocal, true); Add(pSavedLocal);
331 }
void SetID(int32_t iID)
Definition: C4Client.h:120

References Add(), pLocal, Remove(), and C4Client::SetID().

Referenced by C4Network2::HandleJoinData().

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

Member Data Documentation

◆ pFirst

◆ pLocal

C4Client* C4ClientList::pLocal {nullptr}
protected

Definition at line 152 of file C4Client.h.

Referenced by Add(), AddLocal(), CtrlRemove(), getLocal(), getLocalID(), getLocalName(), Remove(), and SetLocalID().

◆ pNetClients

class C4Network2ClientList* C4ClientList::pNetClients {nullptr}
protected

Definition at line 155 of file C4Client.h.

Referenced by Add(), ClearNetwork(), InitNetwork(), and Remove().


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