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
 
C4ClientpLocal
 
class C4Network2ClientListpNetClients
 

Detailed Description

Definition at line 137 of file C4Client.h.

Constructor & Destructor Documentation

C4ClientList::C4ClientList ( )

Definition at line 176 of file C4Client.cpp.

177  : pFirst(nullptr), pLocal(nullptr), pNetClients(nullptr)
178 {
179 
180 }
C4Client * pLocal
Definition: C4Client.h:152
class C4Network2ClientList * pNetClients
Definition: C4Client.h:155
C4Client * pFirst
Definition: C4Client.h:149
C4ClientList::~C4ClientList ( )

Definition at line 182 of file C4Client.cpp.

References Clear().

183 {
184  Clear();
185 }
void Clear()
Definition: C4Client.cpp:187

Here is the call graph for this function:

Member Function Documentation

void C4ClientList::Add ( C4Client pClient)
protected

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

199 {
200  // local client?
201  if (pClient->isLocal()) pLocal = pClient;
202  // already in list?
203  assert(!getClientByID(pClient->getID()));
204  // find insert position
205  C4Client *pPos = pFirst, *pPrev = nullptr;
206  for (; pPos; pPrev = pPos, pPos = pPos->pNext)
207  if (pPos->getID() > pClient->getID())
208  break;
209  // add to list
210  pClient->pNext = pPos;
211  (pPrev ? pPrev->pNext : pFirst) = pClient;
212  // register to network
213  if (pNetClients)
214  pClient->pNetClient = pNetClients->RegClient(pClient);
215 }
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:217
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 314 of file C4Client.cpp.

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

315 {
316  // client with same ID in list?
317  if (getClientByID(Core.getID()))
318  { Log("ClientList: Duplicated client ID!"); return nullptr; }
319  // create, add
320  C4Client *pClient = new C4Client(Core);
321  Add(pClient);
322  return pClient;
323 }
int32_t getID() const
Definition: C4Client.h:57
C4Client * getClientByID(int32_t iID) const
Definition: C4Client.cpp:217
bool Log(const char *szMessage)
Definition: C4Log.cpp:195
void Add(C4Client *pClient)
Definition: C4Client.cpp:198

Here is the call graph for this function:

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

Definition at line 325 of file C4Client.cpp.

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

Referenced by Init().

326 {
327  // only one local client allowed
328  assert(!pLocal);
329  // create core
330  C4ClientCore LocalCore;
331  LocalCore.SetLocal(iID, fActivated, fObserver);
332  // create client
333  C4Client *pClient = new C4Client(LocalCore);
334  pClient->SetLocal();
335  // add
336  Add(pClient);
337  assert(pLocal);
338  return pClient;
339 }
C4Client * pLocal
Definition: C4Client.h:152
void SetLocal()
Definition: C4Client.cpp:154
void SetLocal(int32_t iID, bool fnActivated, bool fnObserver)
Definition: C4Client.cpp:48
void Add(C4Client *pClient)
Definition: C4Client.cpp:198

Here is the call graph for this function:

Here is the caller graph for this function:

void C4ClientList::Clear ( )

Definition at line 187 of file C4Client.cpp.

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

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

188 {
189  ClearNetwork();
190  while (pFirst)
191  {
192  C4Client *pClient = pFirst;
193  Remove(pClient, true);
194  delete pClient;
195  }
196 }
void ClearNetwork()
Definition: C4Client.cpp:279
bool Remove(C4Client *pClient, bool fTemporary=false)
Definition: C4Client.cpp:287
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 279 of file C4Client.cpp.

References C4Network2ClientList::Clear(), and pNetClients.

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

280 {
281  // clear the list (should remove links)
282  C4Network2ClientList *pOldNetClients = pNetClients;
283  pNetClients = nullptr;
284  if (pOldNetClients) pOldNetClients->Clear();
285 }
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 410 of file C4Client.cpp.

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

411 {
412  // Clear existing data
413  bool deserializing = pComp->isDeserializer();
414  if (deserializing) Clear();
415  // Client count
416  uint32_t iClientCnt = getClientCnt();
417  pComp->Value(mkNamingCountAdapt(iClientCnt, "Client"));
418  // Compile all clients
419  if (pComp->isDeserializer())
420  for (uint32_t i = 0; i < iClientCnt; i++)
421  {
422  C4Client *pClient = new C4Client();
423  pComp->Value(mkNamingAdapt(*pClient, "Client"));
424  Add(pClient);
425  }
426  else
427  for (C4Client *pClient = pFirst; pClient; pClient = pClient->pNext)
428  pComp->Value(mkNamingAdapt(*pClient, "Client"));
429 }
StdNamingCountAdapt< int_t > mkNamingCountAdapt(int_t &iCount, const char *szName)
Definition: StdAdaptors.h:977
StdNamingAdapt< T > mkNamingAdapt(T &&rValue, const char *szName)
Definition: StdAdaptors.h:93
void Clear()
Definition: C4Client.cpp:187
void Value(const T &rStruct)
Definition: StdCompiler.h:171
virtual bool isDeserializer()
Definition: StdCompiler.h:63
int32_t getClientCnt() const
Definition: C4Client.cpp:241
C4Client * pFirst
Definition: C4Client.h:149
void Add(C4Client *pClient)
Definition: C4Client.cpp:198

Here is the call graph for this function:

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

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

351 {
352  // host only
353  if (!pLocal || !pLocal->isHost() || !pClient) return;
354  // Net client? flag
355  if (pClient->getNetClient())
356  pClient->getNetClient()->SetStatus(NCS_Remove);
357  // add control
359  new C4ControlClientRemove(pClient->getID(), szReason),
360  CDT_Sync);
361 }
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 249 of file C4Client.cpp.

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

Referenced by C4StartupNetListEntry::SetReference().

250 {
251  StdStrBuf result;
252  for (C4Client *pClient = pFirst; pClient; pClient = pClient->pNext)
253  {
254  if (result.getSize()) result.Append(", ");
255  result.Append(pClient->getName());
256  }
257  return result;
258 }
void Append(const char *pnData, size_t iChars)
Definition: StdBuf.h:527
size_t getSize() const
Definition: StdBuf.h:452
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 217 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().

218 {
219  for (C4Client *pClient = pFirst; pClient; pClient = pClient->pNext)
220  if (pClient->getID() == iID)
221  return pClient;
222  return nullptr;
223 }
C4Client * pFirst
Definition: C4Client.h:149

Here is the caller graph for this function:

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

Definition at line 233 of file C4Client.cpp.

References pFirst, and SEqual().

Referenced by C4MessageInput::ProcessCommand().

234 {
235  for (C4Client *pClient = pFirst; pClient; pClient = pClient->pNext)
236  if (SEqual(pClient->getName(), szName))
237  return pClient;
238  return nullptr;
239 }
bool SEqual(const char *szStr1, const char *szStr2)
Definition: Standard.h:97
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 241 of file C4Client.cpp.

References iCnt, and pFirst.

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

242 {
243  int32_t iCnt = 0;
244  for (C4Client *pClient = pFirst; pClient; pClient = pClient->pNext)
245  iCnt++;
246  return iCnt;
247 }
int iCnt
Definition: TstC4NetIO.cpp:35
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:217
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(), and getLocalCore().

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(), and C4ClientCore::getName().

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 225 of file C4Client.cpp.

References pFirst.

226 {
227  for (C4Client *pClient = pFirst; pClient; pClient = pClient->pNext)
228  if (pClient->getID() > iAfterID)
229  return pClient;
230  return nullptr;
231 }
C4Client * pFirst
Definition: C4Client.h:149
bool C4ClientList::Init ( int32_t  iLocalClientID = C4ClientIDHost)

Definition at line 260 of file C4Client.cpp.

References AddLocal(), and Clear().

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

261 {
262  Clear();
263  // Add local client (activated, not observing)
264  AddLocal(iLocalClientID, true, false);
265  return true;
266 }
C4Client * AddLocal(int32_t iID, bool fActivated, bool fObserver)
Definition: C4Client.cpp:325
void Clear()
Definition: C4Client.cpp:187

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 268 of file C4Client.cpp.

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

Referenced by C4Network2ClientList::Init().

269 {
270  // clear list before
271  pnNetClients->Clear();
272  // set
273  pNetClients = pnNetClients;
274  // copy client list, create links
275  for (C4Client *pClient = pFirst; pClient; pClient = pClient->pNext)
276  pClient->pNetClient = pNetClients->RegClient(pClient);
277 }
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 378 of file C4Client.cpp.

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

379 {
380  // remove clients that are not in the list
381  C4Client *pClient, *pNext;
382  for (pClient = pFirst; pClient; pClient = pNext)
383  {
384  pNext = pClient->pNext;
385  if (!List.getClientByID(pClient->getID()))
386  {
387  Remove(pClient);
388  delete pClient;
389  }
390  }
391  // add all clients
392  for (pClient = List.pFirst; pClient; pClient = pClient->pNext)
393  {
394  // already in list?
395  C4Client *pNewClient = getClientByID(pClient->getID());
396  if (pNewClient)
397  {
398  // core change
399  pNewClient->SetCore(pClient->getCore());
400  }
401  else
402  {
403  // add
404  pNewClient = Add(pClient->getCore());
405  }
406  }
407  return *this;
408 }
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:287
void SetCore(const C4ClientCore &NewCore)
Definition: C4Client.h:119
C4Client * getClientByID(int32_t iID) const
Definition: C4Client.cpp:217
C4Client * pFirst
Definition: C4Client.h:149
void Add(C4Client *pClient)
Definition: C4Client.cpp:198

Here is the call graph for this function:

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

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

288 {
289  // first client in list?
290  if (pClient == pFirst)
291  pFirst = pClient->pNext;
292  else
293  {
294  // find previous
295  C4Client *pPrev;
296  for (pPrev = pFirst; pPrev && pPrev->pNext != pClient; pPrev = pPrev->pNext) {}
297  // not found?
298  if (!pPrev) return false;
299  // unlink
300  pPrev->pNext = pClient->pNext;
301  }
302  if (pClient == pLocal) pLocal = nullptr;
303  if (!fTemporary)
304  {
305  pClient->Remove();
306  // remove network client
307  if (pNetClients && pClient->getNetClient())
309  }
310  // done
311  return true;
312 }
void DeleteClient(C4Network2Client *pClient)
C4Client * pLocal
Definition: C4Client.h:152
C4Network2Client * getNetClient() const
Definition: C4Client.h:117
void Remove()
Definition: C4Client.cpp:160
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 363 of file C4Client.cpp.

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

Referenced by C4GameControl::ChangeToLocal().

364 {
365  // remove all remote clients
366  for (C4Client *pClient = pFirst, *pNext; pClient; pClient = pNext)
367  {
368  pNext = pClient->pNext;
369  // remove all clients except the local client
370  if (!pClient->isLocal())
371  {
372  Remove(pClient);
373  delete pClient;
374  }
375  }
376 }
bool Remove(C4Client *pClient, bool fTemporary=false)
Definition: C4Client.cpp:287
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 341 of file C4Client.cpp.

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

Referenced by C4Network2::HandleJoinData().

342 {
343  if (!pLocal) return;
344  pLocal->SetID(iID);
345  // resort local client
346  C4Client *pSavedLocal = pLocal;
347  Remove(pLocal, true); Add(pSavedLocal);
348 }
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:287
void Add(C4Client *pClient)
Definition: C4Client.cpp:198

Here is the call graph for this function:

Here is the caller graph for this function:

Member Data Documentation

C4Client* C4ClientList::pLocal
protected

Definition at line 152 of file C4Client.h.

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

class C4Network2ClientList* C4ClientList::pNetClients
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: