OpenClonk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
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 ( )
default
C4ClientList::~C4ClientList ( )

Definition at line 165 of file C4Client.cpp.

References Clear().

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

Here is the call graph for this function:

Member Function Documentation

void C4ClientList::Add ( C4Client pClient)
protected

Definition at line 181 of file C4Client.cpp.

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

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

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 }
C4Client * pLocal
Definition: C4Client.h:152
int32_t getID() const
Definition: C4Client.h:105
class C4Network2ClientList * pNetClients
Definition: C4Client.h:155
C4Network2Client * RegClient(C4Client *pClient)
C4Client * getClientByID(int32_t iID) const
Definition: C4Client.cpp:200
bool isLocal() const
Definition: C4Client.h:116
C4Client * pFirst
Definition: C4Client.h:149

Here is the call graph for this function:

Here is the caller graph for this function:

C4Client * C4ClientList::Add ( const C4ClientCore Core)

Definition at line 297 of file C4Client.cpp.

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

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 }
int32_t getID() const
Definition: C4Client.h:57
C4Client * getClientByID(int32_t iID) const
Definition: C4Client.cpp:200
bool Log(const char *szMessage)
Definition: C4Log.cpp:192
void Add(C4Client *pClient)
Definition: C4Client.cpp:181

Here is the call graph for this function:

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

Definition at line 308 of file C4Client.cpp.

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

Referenced by Init().

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 }
C4Client * pLocal
Definition: C4Client.h:152
void SetLocal()
Definition: C4Client.cpp:141
void SetLocal(int32_t iID, bool fnActivated, bool fnObserver)
Definition: C4Client.cpp:38
void Add(C4Client *pClient)
Definition: C4Client.cpp:181

Here is the call graph for this function:

Here is the caller graph for this function:

void C4ClientList::Clear ( )

Definition at line 170 of file C4Client.cpp.

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

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

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

Here is the call graph for this function:

Here is the caller graph for this function:

void C4ClientList::ClearNetwork ( )

Definition at line 262 of file C4Client.cpp.

References C4Network2ClientList::Clear(), and pNetClients.

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

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

Here is the call graph for this function:

Here is the caller graph for this function:

void C4ClientList::CompileFunc ( StdCompiler pComp)

Definition at line 393 of file C4Client.cpp.

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

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:976
StdNamingAdapt< T > mkNamingAdapt(T &&rValue, const char *szName)
Definition: StdAdaptors.h:92
void Clear()
Definition: C4Client.cpp:170
void Value(const T &rStruct)
Definition: StdCompiler.h:161
virtual bool isDeserializer()
Definition: StdCompiler.h:53
int32_t getClientCnt() const
Definition: C4Client.cpp:224
C4Client * pFirst
Definition: C4Client.h:149
void Add(C4Client *pClient)
Definition: C4Client.cpp:181

Here is the call graph for this function:

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

Definition at line 333 of file C4Client.cpp.

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

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 }
C4Client * pLocal
Definition: C4Client.h:152
bool isHost() const
Definition: C4Client.h:106
C4Network2Client * getNetClient() const
Definition: C4Client.h:117
int32_t getID() const
Definition: C4Client.h:105
C4GameControl Control
void DoInput(C4PacketType eCtrlType, C4ControlPacket *pPkt, C4ControlDeliveryType eDelivery)
void SetStatus(C4Network2ClientStatus enStatus)

Here is the call graph for this function:

Here is the caller graph for this function:

StdStrBuf C4ClientList::GetAllClientNames ( ) const

Definition at line 232 of file C4Client.cpp.

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

Referenced by C4StartupNetListEntry::SetReference().

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 }
void Append(const char *pnData, size_t iChars)
Definition: StdBuf.h:519
size_t getSize() const
Definition: StdBuf.h:444
C4Client * pFirst
Definition: C4Client.h:149

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 160 of file C4Client.h.

References pFirst.

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

160 { return pAfter ? pAfter->pNext : pFirst; }
C4Client * pFirst
Definition: C4Client.h:149

Here is the caller graph for this function:

C4Client * C4ClientList::getClientByID ( int32_t  iID) const

Definition at line 200 of file C4Client.cpp.

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

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

Here is the caller graph for this function:

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

Definition at line 216 of file C4Client.cpp.

References pFirst, and SEqual().

Referenced by C4MessageInput::ProcessCommand().

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
C4Client * pFirst
Definition: C4Client.h:149

Here is the call graph for this function:

Here is the caller graph for this function:

int32_t C4ClientList::getClientCnt ( ) const

Definition at line 224 of file C4Client.cpp.

References iCnt, and pFirst.

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

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
C4Client * pFirst
Definition: C4Client.h:149

Here is the caller graph for this function:

C4Client* C4ClientList::getHost ( ) const
inline

Definition at line 163 of file C4Client.h.

References C4ClientIDHost, and getClientByID().

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

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

Here is the call graph for this function:

Here is the caller graph for this function:

C4Client* C4ClientList::getLocal ( ) const
inline

Definition at line 161 of file C4Client.h.

References pLocal.

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

161 { return pLocal; }
C4Client * pLocal
Definition: C4Client.h:152

Here is the caller graph for this function:

const C4ClientCore& C4ClientList::getLocalCore ( ) const
inline

Definition at line 169 of file C4Client.h.

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

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

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

Here is the call graph for this function:

Here is the caller graph for this function:

int32_t C4ClientList::getLocalID ( ) const
inline

Definition at line 171 of file C4Client.h.

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

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

Here is the call graph for this function:

Here is the caller graph for this function:

const char* C4ClientList::getLocalName ( ) const
inline

Definition at line 170 of file C4Client.h.

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

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

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

Here is the call graph for this function:

Here is the caller graph for this function:

C4Client * C4ClientList::getNextClientByID ( int32_t  iAfterID) const

Definition at line 208 of file C4Client.cpp.

References pFirst.

209 {
210  for (C4Client *pClient = pFirst; pClient; pClient = pClient->pNext)
211  if (pClient->getID() > iAfterID)
212  return pClient;
213  return nullptr;
214 }
C4Client * pFirst
Definition: C4Client.h:149
bool C4ClientList::Init ( int32_t  iLocalClientID = C4ClientIDHost)

Definition at line 243 of file C4Client.cpp.

References AddLocal(), and Clear().

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

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
void Clear()
Definition: C4Client.cpp:170

Here is the call graph for this function:

Here is the caller graph for this function:

void C4ClientList::InitNetwork ( class C4Network2ClientList pNetClients)

Definition at line 251 of file C4Client.cpp.

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

Referenced by C4Network2ClientList::Init().

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 }
class C4Network2ClientList * pNetClients
Definition: C4Client.h:155
C4Network2Client * RegClient(C4Client *pClient)
C4Client * pFirst
Definition: C4Client.h:149

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 361 of file C4Client.cpp.

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

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 }
int32_t getID() const
Definition: C4Client.h:105
const C4ClientCore & getCore() const
Definition: C4Client.h:104
bool Remove(C4Client *pClient, bool fTemporary=false)
Definition: C4Client.cpp:270
void SetCore(const C4ClientCore &NewCore)
Definition: C4Client.h:119
C4Client * getClientByID(int32_t iID) const
Definition: C4Client.cpp:200
C4Client * pFirst
Definition: C4Client.h:149
void Add(C4Client *pClient)
Definition: C4Client.cpp:181

Here is the call graph for this function:

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

Definition at line 270 of file C4Client.cpp.

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

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

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 DeleteClient(C4Network2Client *pClient)
C4Client * pLocal
Definition: C4Client.h:152
C4Network2Client * getNetClient() const
Definition: C4Client.h:117
void Remove()
Definition: C4Client.cpp:147
class C4Network2ClientList * pNetClients
Definition: C4Client.h:155
C4Client * pFirst
Definition: C4Client.h:149

Here is the call graph for this function:

Here is the caller graph for this function:

void C4ClientList::RemoveRemote ( )

Definition at line 346 of file C4Client.cpp.

References pFirst, C4GUI::Element::pNext, and Remove().

Referenced by C4GameControl::ChangeToLocal().

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 }
bool Remove(C4Client *pClient, bool fTemporary=false)
Definition: C4Client.cpp:270
C4Client * pFirst
Definition: C4Client.h:149

Here is the call graph for this function:

Here is the caller graph for this function:

void C4ClientList::SetLocalID ( int32_t  iID)

Definition at line 324 of file C4Client.cpp.

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

Referenced by C4Network2::HandleJoinData().

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

Here is the call graph for this function:

Here is the caller graph for this function:

Member Data Documentation

C4Client* C4ClientList::pLocal {nullptr}
protected

Definition at line 152 of file C4Client.h.

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

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: