OpenClonk
C4ClientCore Class Reference

#include <C4Client.h>

Inheritance diagram for C4ClientCore:
[legend]
Collaboration diagram for C4ClientCore:
[legend]

Public Member Functions

 C4ClientCore ()
 
 ~C4ClientCore () override
 
int32_t getID () const
 
bool isHost () const
 
bool isActivated () const
 
bool isObserver () const
 
bool isLobbyReady () const
 
void SetID (int32_t inID)
 
void SetName (const char *sznName)
 
void SetActivated (bool fnActivated)
 
void SetObserver (bool fnObserver)
 
void SetLobbyReady (bool fnLobbyReady)
 
const char * getName () const
 
const char * getCUID () const
 
const char * getNick () const
 
const char * getRevision () const
 
bool isRegistered () const
 
void SetLocal (int32_t iID, bool fnActivated, bool fnObserver)
 
void SetUnknown (int32_t iID)
 
int32_t getDiffLevel (const C4ClientCore &CCore2) const
 
void CompileFunc (StdCompiler *pComp) override
 
C4NetIOPacket pack (const C4NetIO::addr_t &addr=C4NetIO::addr_t()) const
 
C4NetIOPacket pack (uint8_t cStatus, const C4NetIO::addr_t &addr=C4NetIO::addr_t()) const
 
void unpack (const C4NetIOPacket &Pkt, char *pStatus=nullptr)
 

Protected Attributes

int32_t iID {-1}
 
ValidatedStdCopyStrBuf< C4InVal::VAL_NameNoEmptyName
 
ValidatedStdCopyStrBuf< C4InVal::VAL_NameNoEmptyNick
 
ValidatedStdCopyStrBuf< C4InVal::VAL_NameAllowEmptyCUID
 
ValidatedStdCopyStrBuf< C4InVal::VAL_NameAllowEmptyRevision
 
int iVersion [4]
 
bool fActivated {false}
 
bool fObserver {false}
 
bool fLobbyReady {false}
 

Detailed Description

Definition at line 34 of file C4Client.h.

Constructor & Destructor Documentation

◆ C4ClientCore()

C4ClientCore::C4ClientCore ( )

Definition at line 31 of file C4Client.cpp.

32 {
33  Name.Ref(""); CUID.Ref(""); Nick.Ref("");
34 }
ValidatedStdCopyStrBuf< C4InVal::VAL_NameNoEmpty > Nick
Definition: C4Client.h:44
ValidatedStdCopyStrBuf< C4InVal::VAL_NameAllowEmpty > CUID
Definition: C4Client.h:45
ValidatedStdCopyStrBuf< C4InVal::VAL_NameNoEmpty > Name
Definition: C4Client.h:44
void Ref(const char *pnData)
Definition: StdBuf.h:455

References CUID, Name, Nick, and StdStrBuf::Ref().

Here is the call graph for this function:

◆ ~C4ClientCore()

C4ClientCore::~C4ClientCore ( )
overridedefault

Member Function Documentation

◆ CompileFunc()

void C4ClientCore::CompileFunc ( StdCompiler pComp)
overridevirtual

Implements C4PacketBase.

Definition at line 92 of file C4Client.cpp.

93 {
94  pComp->Value(mkNamingAdapt(iID, "ID", C4ClientIDUnknown));
95  pComp->Value(mkNamingAdapt(fActivated, "Activated", false));
96  pComp->Value(mkNamingAdapt(fObserver, "Observer", false));
97  pComp->Value(mkNamingAdapt(fLobbyReady, "Ready", false));
98  pComp->Value(mkNamingAdapt(Name, "Name", ""));
99  pComp->Value(mkNamingAdapt(CUID, "CUID", ""));
100  pComp->Value(mkNamingAdapt(Nick, "Nick", ""));
101  pComp->Value(mkNamingAdapt(Revision, "Revision", ""));
102 }
const int32_t C4ClientIDUnknown
Definition: C4Client.h:24
StdNamingAdapt< T > mkNamingAdapt(T &&rValue, const char *szName)
Definition: StdAdaptors.h:92
bool fLobbyReady
Definition: C4Client.h:52
int32_t iID
Definition: C4Client.h:43
bool fObserver
Definition: C4Client.h:52
ValidatedStdCopyStrBuf< C4InVal::VAL_NameAllowEmpty > Revision
Definition: C4Client.h:46
bool fActivated
Definition: C4Client.h:52
void Value(const T &rStruct)
Definition: StdCompiler.h:161

References C4ClientIDUnknown, CUID, fActivated, fLobbyReady, fObserver, iID, mkNamingAdapt(), Name, Nick, Revision, and StdCompiler::Value().

Here is the call graph for this function:

◆ getCUID()

const char* C4ClientCore::getCUID ( ) const
inline

Definition at line 70 of file C4Client.h.

70 { return CUID.getData(); }
const char * getData() const
Definition: StdBuf.h:442

References CUID, and StdStrBuf::getData().

Referenced by C4Client::getCUID(), and getDiffLevel().

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

◆ getDiffLevel()

int32_t C4ClientCore::getDiffLevel ( const C4ClientCore CCore2) const

Definition at line 75 of file C4Client.cpp.

76 {
77  // nick & cuid won't ever be changed
78  if (CUID != CCore2.getCUID() || Nick != CCore2.getNick())
80  // identification changed?
81  if (iID != CCore2.getID() || Name != CCore2.getName())
83  // status change?
84  if (fActivated != CCore2.isActivated() || fObserver != CCore2.isObserver() || fLobbyReady != CCore2.isLobbyReady())
86  // otherwise: identical
87  return C4ClientCoreDL_None;
88 }
const int32_t C4ClientCoreDL_Different
Definition: C4Client.h:32
const int32_t C4ClientCoreDL_IDChange
Definition: C4Client.h:31
const int32_t C4ClientCoreDL_None
Definition: C4Client.h:29
const int32_t C4ClientCoreDL_IDMatch
Definition: C4Client.h:30
const char * getNick() const
Definition: C4Client.h:71
bool isObserver() const
Definition: C4Client.h:60
bool isLobbyReady() const
Definition: C4Client.h:61
const char * getName() const
Definition: C4Client.h:69
int32_t getID() const
Definition: C4Client.h:57
const char * getCUID() const
Definition: C4Client.h:70
bool isActivated() const
Definition: C4Client.h:59

References C4ClientCoreDL_Different, C4ClientCoreDL_IDChange, C4ClientCoreDL_IDMatch, C4ClientCoreDL_None, CUID, fActivated, fLobbyReady, fObserver, getCUID(), getID(), getName(), getNick(), iID, isActivated(), isLobbyReady(), isObserver(), Name, and Nick.

Referenced by C4Network2::CheckConn(), C4Network2IO::doAutoAccept(), and C4Network2IO::RemoveAutoAccept().

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

◆ getID()

int32_t C4ClientCore::getID ( ) const
inline

Definition at line 57 of file C4Client.h.

57 { return iID; }

References iID.

Referenced by C4ClientList::Add(), C4Network2::DrawStatus(), C4Network2IOConnection::getClientID(), getDiffLevel(), C4Client::getID(), C4Network2Client::getID(), C4ClientList::getLocalID(), C4Network2::HandleConn(), C4Network2IO::HandleFwdReq(), C4Network2IO::HandlePacket(), C4Network2::Join(), and C4Network2IO::SendConnPackets().

Here is the caller graph for this function:

◆ getName()

const char* C4ClientCore::getName ( ) const
inline

Definition at line 69 of file C4Client.h.

69 { return Name.getData(); }

References StdStrBuf::getData(), and Name.

Referenced by C4Network2::DrawStatus(), getDiffLevel(), C4ClientList::getLocalName(), C4Client::getName(), C4Network2Client::getName(), C4Network2::HandleConn(), and C4Network2::Join().

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

◆ getNick()

const char* C4ClientCore::getNick ( ) const
inline

Definition at line 71 of file C4Client.h.

71 { return Nick.getData(); }

References StdStrBuf::getData(), and Nick.

Referenced by getDiffLevel(), and C4Client::getNick().

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

◆ getRevision()

const char* C4ClientCore::getRevision ( ) const
inline

Definition at line 72 of file C4Client.h.

72 { return Revision.getData(); }

References StdStrBuf::getData(), and Revision.

Referenced by C4Network2::Join().

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

◆ isActivated()

bool C4ClientCore::isActivated ( ) const
inline

Definition at line 59 of file C4Client.h.

59 { return fActivated; }

References fActivated.

Referenced by C4Network2::DrawStatus(), getDiffLevel(), C4Client::isActivated(), and C4Network2Client::isActivated().

Here is the caller graph for this function:

◆ isHost()

bool C4ClientCore::isHost ( ) const
inline

Definition at line 58 of file C4Client.h.

58 { return iID == C4ClientIDHost; }
const int32_t C4ClientIDHost
Definition: C4Client.h:25

References C4ClientIDHost, and iID.

Referenced by C4Network2::DrawStatus(), C4Network2::HostConnect(), C4Client::isHost(), and C4Network2IOConnection::isHost().

Here is the caller graph for this function:

◆ isLobbyReady()

bool C4ClientCore::isLobbyReady ( ) const
inline

Definition at line 61 of file C4Client.h.

61 { return fLobbyReady; }

References fLobbyReady.

Referenced by getDiffLevel(), and C4Client::isLobbyReady().

Here is the caller graph for this function:

◆ isObserver()

bool C4ClientCore::isObserver ( ) const
inline

Definition at line 60 of file C4Client.h.

60 { return fObserver; }

References fObserver.

Referenced by C4Network2::DrawStatus(), getDiffLevel(), C4Client::isObserver(), and C4Network2Client::isObserver().

Here is the caller graph for this function:

◆ isRegistered()

bool C4ClientCore::isRegistered ( ) const
inline

Definition at line 73 of file C4Client.h.

73 { return CUID.getLength()>0; }
size_t getLength() const
Definition: StdBuf.h:445

References CUID, and StdStrBuf::getLength().

Referenced by C4Client::isRegistered().

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

◆ pack() [1/2]

C4NetIOPacket C4PacketBase::pack ( const C4NetIO::addr_t addr = C4NetIO::addr_t()) const
inherited

Definition at line 150 of file C4Packet2.cpp.

151 {
152  return C4NetIOPacket(DecompileToBuf<StdCompilerBinWrite>(*this), addr);
153 }

Referenced by MkC4NetIOPacket().

Here is the caller graph for this function:

◆ pack() [2/2]

C4NetIOPacket C4PacketBase::pack ( uint8_t  cStatus,
const C4NetIO::addr_t addr = C4NetIO::addr_t() 
) const
inherited

Definition at line 155 of file C4Packet2.cpp.

156 {
157  return C4NetIOPacket(DecompileToBuf<StdCompilerBinWrite>(mkInsertAdapt(mkDecompileAdapt(*this), cStatus)), addr);
158 }
StdInsertAdapt< T, I > mkInsertAdapt(T &&rObj, I &&rIns, bool fBefore=true)
Definition: StdAdaptors.h:469
StdDecompileAdapt< T > mkDecompileAdapt(const T &rValue)
Definition: StdAdaptors.h:153

References mkDecompileAdapt(), and mkInsertAdapt().

Here is the call graph for this function:

◆ SetActivated()

void C4ClientCore::SetActivated ( bool  fnActivated)
inline

Definition at line 64 of file C4Client.h.

64 { fActivated = fnActivated; fObserver = false; }

References fActivated, and fObserver.

Referenced by C4Network2::Join(), and C4Client::SetActivated().

Here is the caller graph for this function:

◆ SetID()

void C4ClientCore::SetID ( int32_t  inID)
inline

Definition at line 62 of file C4Client.h.

62 { iID = inID; }

References iID.

Referenced by C4Network2::InitNetIO(), C4Network2::Join(), and C4Client::SetID().

Here is the caller graph for this function:

◆ SetLobbyReady()

void C4ClientCore::SetLobbyReady ( bool  fnLobbyReady)
inline

Definition at line 66 of file C4Client.h.

66 { fLobbyReady = fnLobbyReady; }

References fLobbyReady.

Referenced by C4Client::SetLobbyReady().

Here is the caller graph for this function:

◆ SetLocal()

void C4ClientCore::SetLocal ( int32_t  iID,
bool  fnActivated,
bool  fnObserver 
)

Definition at line 38 of file C4Client.cpp.

39 {
40  // status
41  iID = inID;
42  fActivated = fnActivated;
43  fObserver = fnObserver;
44  // misc
48  {
50  Nick.Copy(Name);
51  }
52  else
53  {
54  const char* position = std::strchr(Config.General.Participants, ';');
55  if (!position)
56  position = Config.General.Participants + std::strlen(Config.General.Participants);
57  if (Config.General.Participants + 4 <= position && std::strncmp(position - 4, ".ocp", 4) == 0)
58  Name.CopyValidated(std::string(Config.General.Participants, position - Config.General.Participants - 4).c_str());
59  else
60  Name.Copy("empty");
61  Nick.Copy(Name);
62  }
63 }
C4Config Config
Definition: C4Config.cpp:930
C4Application Application
Definition: C4Globals.cpp:44
const char * GetRevision() const
Definition: C4Application.h:72
char Participants[CFG_MaxString+1]
Definition: C4Config.h:39
const char * GetRegistrationData(const char *field)
Definition: C4Config.h:285
C4ConfigGeneral General
Definition: C4Config.h:255
C4ConfigNetwork Network
Definition: C4Config.h:259
ValidatedStdCopyStrBuf< C4InVal::VAL_NameAllowEmpty > Nick
Definition: C4Config.h:156
void Copy()
Definition: StdBuf.h:467
void CopyValidated(const char *szFromVal)

References Application, Config, StdStrBuf::Copy(), ValidatedStdCopyStrBufBase::CopyValidated(), CUID, fActivated, fObserver, C4Config::General, StdStrBuf::getLength(), C4Config::GetRegistrationData(), C4Application::GetRevision(), iID, Name, C4Config::Network, C4ConfigNetwork::Nick, Nick, C4ConfigGeneral::Participants, and Revision.

Referenced by C4ClientList::AddLocal().

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

◆ SetName()

void C4ClientCore::SetName ( const char *  sznName)
inline

Definition at line 63 of file C4Client.h.

63 { Name.CopyValidated(sznName); }

References ValidatedStdCopyStrBufBase::CopyValidated(), and Name.

Referenced by C4Network2::Join().

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

◆ SetObserver()

void C4ClientCore::SetObserver ( bool  fnObserver)
inline

Definition at line 65 of file C4Client.h.

65 { fActivated &= !(fObserver = fnObserver); }

References fActivated, and fObserver.

Referenced by C4Network2::Join(), and C4Client::SetObserver().

Here is the caller graph for this function:

◆ SetUnknown()

void C4ClientCore::SetUnknown ( int32_t  iID)

Definition at line 65 of file C4Client.cpp.

66 {
67  // save id
68  iID = inID;
69  // fill everything else with default values
70  Name.Ref("unknown"); CUID.Ref("unknown"); Nick.Ref("unknown");
71  Revision.Ref("unknown");
72  fActivated = fObserver = false;
73 }

References CUID, fActivated, fObserver, iID, Name, Nick, StdStrBuf::Ref(), and Revision.

Here is the call graph for this function:

◆ unpack()

void C4PacketBase::unpack ( const C4NetIOPacket Pkt,
char *  pStatus = nullptr 
)
inherited

Definition at line 160 of file C4Packet2.cpp.

161 {
162  if (pStatus) *pStatus = Pkt.getStatus();
163  CompileFromBuf<StdCompilerBinRead>(*this, pStatus ? Pkt.getPBuf() : Pkt.getRef());
164 }
uint8_t getStatus() const
Definition: C4NetIO.h:319
StdBuf getPBuf() const
Definition: C4NetIO.h:322
C4NetIOPacket getRef() const
Definition: C4NetIO.h:325

References C4NetIOPacket::getPBuf(), C4NetIOPacket::getRef(), and C4NetIOPacket::getStatus().

Referenced by C4IDPacket::C4IDPacket(), and C4Network2IO::HandlePacket().

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

Member Data Documentation

◆ CUID

◆ fActivated

bool C4ClientCore::fActivated {false}
protected

◆ fLobbyReady

bool C4ClientCore::fLobbyReady {false}
protected

Definition at line 52 of file C4Client.h.

Referenced by CompileFunc(), getDiffLevel(), isLobbyReady(), and SetLobbyReady().

◆ fObserver

bool C4ClientCore::fObserver {false}
protected

◆ iID

int32_t C4ClientCore::iID {-1}
protected

Definition at line 43 of file C4Client.h.

Referenced by CompileFunc(), getDiffLevel(), getID(), isHost(), SetID(), SetLocal(), and SetUnknown().

◆ iVersion

int C4ClientCore::iVersion[4]
protected

Definition at line 49 of file C4Client.h.

◆ Name

ValidatedStdCopyStrBuf<C4InVal::VAL_NameNoEmpty> C4ClientCore::Name
protected

Definition at line 44 of file C4Client.h.

Referenced by C4ClientCore(), CompileFunc(), getDiffLevel(), getName(), SetLocal(), SetName(), and SetUnknown().

◆ Nick

ValidatedStdCopyStrBuf<C4InVal::VAL_NameNoEmpty> C4ClientCore::Nick
protected

Definition at line 44 of file C4Client.h.

Referenced by C4ClientCore(), CompileFunc(), getDiffLevel(), getNick(), SetLocal(), and SetUnknown().

◆ Revision

ValidatedStdCopyStrBuf<C4InVal::VAL_NameAllowEmpty> C4ClientCore::Revision
protected

Definition at line 46 of file C4Client.h.

Referenced by CompileFunc(), getRevision(), SetLocal(), and SetUnknown().


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