OpenClonk
C4LeagueClient Class Reference

#include <C4League.h>

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

Public Types

enum  ResponseType { NoPreference , XML }
 

Public Member Functions

 C4LeagueClient ()
 
const char * getCSID () const
 
C4LeagueAction getCurrentAction () const
 
void ResetCurrentAction ()
 
bool Start (const C4Network2Reference &Ref)
 
bool GetStartReply (StdStrBuf *pMessage, StdStrBuf *pLeague, StdStrBuf *pStreamingAddr, int32_t *pSeed, int32_t *pMaxPlayers)
 
bool Update (const C4Network2Reference &Ref)
 
bool GetUpdateReply (StdStrBuf *pMessage, C4ClientPlayerInfos *pPlayerLeagueInfos)
 
bool End (const C4Network2Reference &Ref, const char *szRecordName, const BYTE *pRecordSHA)
 
bool GetEndReply (StdStrBuf *pMessage, class C4RoundResultsPlayers *pRoundResults)
 
bool Auth (const C4PlayerInfo &PlrInfo, const char *szAccount, const char *szPassword, const char *szNewAccount=nullptr, const char *szNewPassword=nullptr, bool fRememberLogin=false)
 
bool GetAuthReply (StdStrBuf *pMessage, StdStrBuf *pAUID, StdStrBuf *pAccount, bool *pRegister, StdStrBuf *pLoginToken)
 
bool AuthCheck (const C4PlayerInfo &PlrInfo)
 
bool GetAuthCheckReply (StdStrBuf *pMessage, const char *szLeague, class C4PlayerInfo *pPlrInfo)
 
bool ReportDisconnect (const C4ClientPlayerInfos &rSendPlayerFBIDs, C4LeagueDisconnectReason eReason)
 
bool GetReportDisconnectReply (StdStrBuf *pMessage)
 
bool QueryReferences ()
 
bool GetReferences (C4Network2Reference **&rpReferences, int32_t &rRefCount)
 
bool Init ()
 
bool Query (const StdBuf &Data, bool fBinary)
 
bool Query (const char *szData, bool fBinary)
 
bool isBusy () const
 
bool isConnected () const
 
bool isSuccess () const
 
size_t getTotalSize () const
 
size_t getDownloadedSize () const
 
const StdBufgetResultBin () const
 
const char * getResultString () const
 
const char * getURL () const
 
const char * getServerName () const
 
const C4NetIO::addr_tgetServerAddress () const
 
virtual const char * GetError () const
 
void ResetError ()
 
void Cancel (const char *szReason)
 
void Clear ()
 
bool SetServer (const char *szServerAddress)
 
void SetExpectedResponseType (ResponseType type)
 
void SetNotify (class C4InteractiveThread *pnNotify)
 
bool Execute (int iMaxTime=-1, pollfd *readyfds=nullptr) override
 
C4TimeMilliseconds GetNextTick (C4TimeMilliseconds tNow) override
 
void GetFDs (std::vector< struct pollfd > &) override
 
bool ExecuteUntil (int iTimeout=-1)
 
bool IsSignaled ()
 
virtual bool IsLowPriority ()
 
virtual bool IsNotify ()
 
virtual uint32_t TimerInterval ()
 

Protected Member Functions

void SetError (const char *strnError)
 
void Changed ()
 

Protected Attributes

StdCopyBuf ResultBin
 
StdCopyStrBuf ResultString
 
StdCopyStrBuf Error
 

Detailed Description

Definition at line 205 of file C4League.h.

Member Enumeration Documentation

◆ ResponseType

Enumerator
NoPreference 
XML 

Definition at line 103 of file C4HTTP.h.

103 { NoPreference, XML };
@ NoPreference
Definition: C4HTTP.h:103

Constructor & Destructor Documentation

◆ C4LeagueClient()

C4LeagueClient::C4LeagueClient ( )
inline

Definition at line 214 of file C4League.h.

214 : C4Network2RefClient(), CSID() { }

Member Function Documentation

◆ Auth()

bool C4LeagueClient::Auth ( const C4PlayerInfo PlrInfo,
const char *  szAccount,
const char *  szPassword,
const char *  szNewAccount = nullptr,
const char *  szNewPassword = nullptr,
bool  fRememberLogin = false 
)

Definition at line 405 of file C4League.cpp.

406 {
407  // Build header
408  eCurrAction = C4LA_PlrAuth;
409  C4LeagueRequestHead Head(eCurrAction);
410  Head.SetAuth(szAccount, szPassword, fRememberLogin);
411  if (szNewAccount)
412  Head.SetNewAccount(szNewAccount);
413  if (szNewPassword)
414  Head.SetNewPassword(szNewPassword);
415  // Create query
416  StdStrBuf QueryText = DecompileToBuf<StdCompilerINIWrite>(
418  mkNamingAdapt(Head, "Request"),
419  mkNamingAdapt(mkDecompileAdapt(PlrInfo), "PlrInfo"),
420  false));
421  // Perform query
422  return Query(QueryText.getData(), false);
423 }
@ C4LA_PlrAuth
Definition: C4League.h:41
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
StdNamingAdapt< T > mkNamingAdapt(T &&rValue, const char *szName)
Definition: StdAdaptors.h:92
bool Query(const StdBuf &Data, bool fBinary)
Definition: C4HTTP.cpp:158
const char * getData() const
Definition: StdBuf.h:442

References C4LA_PlrAuth, StdStrBuf::getData(), mkDecompileAdapt(), mkInsertAdapt(), mkNamingAdapt(), C4HTTPClient::Query(), C4LeagueRequestHead::SetAuth(), C4LeagueRequestHead::SetNewAccount(), and C4LeagueRequestHead::SetNewPassword().

Referenced by C4Network2::LeaguePlrAuth().

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

◆ AuthCheck()

bool C4LeagueClient::AuthCheck ( const C4PlayerInfo PlrInfo)

Definition at line 455 of file C4League.cpp.

456 {
457  assert(CSID.getLength());
458  // Build header
459  eCurrAction = C4LA_PlrAuthCheck;
460  C4LeagueRequestHead Head(eCurrAction, CSID.getData(), PlrInfo.getAuthID());
461  // Create query
462  StdStrBuf QueryText = DecompileToBuf<StdCompilerINIWrite>(
464  mkNamingAdapt(Head, "Request"),
465  mkNamingAdapt(mkDecompileAdapt(PlrInfo), "PlrInfo"),
466  false));
467  // Perform query
468  return Query(QueryText.getData(), false);
469 }
@ C4LA_PlrAuthCheck
Definition: C4League.h:38
const char * getAuthID() const
Definition: C4PlayerInfo.h:183
size_t getLength() const
Definition: StdBuf.h:445

References C4LA_PlrAuthCheck, C4PlayerInfo::getAuthID(), StdStrBuf::getData(), StdStrBuf::getLength(), mkDecompileAdapt(), mkInsertAdapt(), mkNamingAdapt(), and C4HTTPClient::Query().

Referenced by C4Network2::LeaguePlrAuthCheck().

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

◆ Cancel()

void C4HTTPClient::Cancel ( const char *  szReason)
inherited

Definition at line 277 of file C4HTTP.cpp.

278 {
279  if (CurlHandle)
280  {
281  curl_multi_remove_handle(MultiHandle, CurlHandle);
282  curl_easy_cleanup(CurlHandle);
283  CurlHandle = nullptr;
284  }
285  fBinary = false;
286  iDownloadedSize = iTotalSize = 0;
287  Error = szReason;
288 }
StdCopyStrBuf Error
Definition: C4HTTP.h:79

References C4HTTPClient::Error.

Referenced by C4HTTPClient::Clear(), C4StartupNetListEntry::Execute(), C4HTTPClient::Query(), C4DownloadDlg::UserClose(), and C4HTTPClient::~C4HTTPClient().

Here is the caller graph for this function:

◆ Changed()

void StdSchedulerProc::Changed ( )
protectedinherited

Definition at line 108 of file StdScheduler.cpp.

109 {
110  auto s = scheduler;
111  if (s)
112  s->Changed(this);
113 }
#define s

References s.

Referenced by C4NetIOTCP::Accept(), C4NetIOTCP::AddConnectWait(), C4NetIOUDP::AddPeer(), C4NetIOTCP::Listen(), and CStdTimerProc::SetDelay().

Here is the caller graph for this function:

◆ Clear()

void C4HTTPClient::Clear ( )
inherited

Definition at line 290 of file C4HTTP.cpp.

291 {
292  Cancel(nullptr);
293  ServerAddr.Clear();
294  ResultBin.Clear();
296 }
StdCopyStrBuf ResultString
Definition: C4HTTP.h:78
StdCopyBuf ResultBin
Definition: C4HTTP.h:77
void Cancel(const char *szReason)
Definition: C4HTTP.cpp:277
void Clear()
Definition: StdBuf.h:190
void Clear()
Definition: StdBuf.h:466

References C4HTTPClient::Cancel(), StdBuf::Clear(), StdStrBuf::Clear(), C4NetIO::EndpointAddress::Clear(), C4HTTPClient::ResultBin, and C4HTTPClient::ResultString.

Referenced by C4Network2::StreamOut().

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

◆ End()

bool C4LeagueClient::End ( const C4Network2Reference Ref,
const char *  szRecordName,
const BYTE pRecordSHA 
)

Definition at line 375 of file C4League.cpp.

376 {
377  assert(CSID.getLength());
378  // Create query
379  eCurrAction = C4LA_End;
380  C4LeagueRequestHeadEnd Head(eCurrAction, CSID.getData(), szRecordName, pRecordSHA);
381  StdStrBuf QueryText = DecompileToBuf<StdCompilerINIWrite>(
383  mkNamingAdapt(Head, "Request"),
384  mkNamingAdapt(mkDecompileAdapt(Ref), "Reference"),
385  false));
386  // Perform query
387  return Query(QueryText.getData(), false);
388 }
@ C4LA_End
Definition: C4League.h:37

References C4LA_End, StdStrBuf::getData(), StdStrBuf::getLength(), mkDecompileAdapt(), mkInsertAdapt(), mkNamingAdapt(), and C4HTTPClient::Query().

Referenced by C4Network2::LeagueEnd().

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

◆ Execute()

bool C4HTTPClient::Execute ( int  iMaxTime = -1,
pollfd *  readyfds = nullptr 
)
overridevirtualinherited

Implements StdSchedulerProc.

Definition at line 59 of file C4HTTP.cpp.

60 {
61  int running;
62 #ifdef STDSCHEDULER_USE_EVENTS
63  // On Windows, StdScheduler doesn't inform us about which fd triggered the
64  // event, so we have to check manually.
65  if (WaitForSingleObject(Event, 0) == WAIT_OBJECT_0)
66  {
67  // sockets might be modified during the call to curl_multi_socket_action() below.
68  auto sockets_tmp = sockets;
69  for (const auto& kv : sockets_tmp)
70  {
71  auto socket = kv.first;
72  WSANETWORKEVENTS NetworkEvents;
73  if (WSAEnumNetworkEvents(socket, Event, &NetworkEvents) != SOCKET_ERROR)
74  {
75  int ev_bitmask = 0;
76  if (NetworkEvents.lNetworkEvents & (FD_READ|FD_ACCEPT|FD_CLOSE)) ev_bitmask |= CURL_CSELECT_IN;
77  if (NetworkEvents.lNetworkEvents & (FD_WRITE|FD_CONNECT)) ev_bitmask |= CURL_CSELECT_OUT;
78  curl_multi_socket_action(MultiHandle, socket, ev_bitmask, &running);
79  }
80  }
81  }
82 #else
83  if (readyfd)
84  {
85  int ev_bitmask = 0;
86  if (readyfd->revents & POLLIN) ev_bitmask |= CURL_CSELECT_IN;
87  if (readyfd->revents & POLLOUT) ev_bitmask |= CURL_CSELECT_OUT;
88  if (readyfd->revents & POLLERR) ev_bitmask |= CURL_CSELECT_ERR;
89  curl_multi_socket_action(MultiHandle, readyfd->fd, ev_bitmask, &running);
90  }
91 #endif
92  else
93  {
94  curl_multi_socket_action(MultiHandle, CURL_SOCKET_TIMEOUT, 0, &running);
95  }
96 
97  CURLMsg *m;
98  do {
99  int msgq = 0;
100  m = curl_multi_info_read(MultiHandle, &msgq);
101  if(m && (m->msg == CURLMSG_DONE)) {
102  CURL *e = m->easy_handle;
103  assert(e == CurlHandle);
104  CurlHandle = nullptr;
105  curl_multi_remove_handle(MultiHandle, e);
106 
107  // Check for errors and notify listeners. Note that curl fills
108  // the Error buffer automatically.
109  fSuccess = m->data.result == CURLE_OK;
110  if (!fSuccess && !*Error.getData())
111  Error.Copy(curl_easy_strerror(m->data.result));
112  char *ip;
113  curl_easy_getinfo(e, CURLINFO_PRIMARY_IP, &ip);
114  ServerAddr.SetHost(StdStrBuf(ip));
115  if (pNotify)
116  pNotify->PushEvent(Ev_HTTP_Response, this);
117 
118  curl_easy_cleanup(e);
119  }
120  } while(m);
121 
122  return true;
123 }
@ Ev_HTTP_Response
#define SOCKET_ERROR
Definition: C4NetIO.cpp:47
bool PushEvent(C4InteractiveEventType eEventType, void *pData=nullptr)
void Copy()
Definition: StdBuf.h:467
void SetHost(const sockaddr *addr)
Definition: C4NetIO.cpp:346

References StdStrBuf::Copy(), C4HTTPClient::Error, Ev_HTTP_Response, StdStrBuf::getData(), C4InteractiveThread::PushEvent(), C4NetIO::HostAddress::SetHost(), and SOCKET_ERROR.

Referenced by C4Game::InitNetworkFromAddress(), C4Network2::LeagueEnd(), C4Network2::LeaguePlrAuth(), C4Network2::LeaguePlrAuthCheck(), C4Network2::LeagueStart(), C4Network2::LeagueWaitNotBusy(), and C4DownloadDlg::OnIdle().

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

◆ ExecuteUntil()

bool StdSchedulerProc::ExecuteUntil ( int  iTimeout = -1)
inherited

Definition at line 33 of file StdScheduler.cpp.

34 {
35  // Infinite?
36  if (iTimeout < 0)
37  for (;;)
38  if (!Execute())
39  return false;
40  // Calculate endpoint
41  C4TimeMilliseconds tStopTime = C4TimeMilliseconds::Now() + iTimeout;
42  for (;;)
43  {
44  // Call execute with given timeout
45  if (!Execute(std::max(iTimeout, 0)))
46  return false;
47  // Calculate timeout
49  if (tTime >= tStopTime)
50  break;
51  iTimeout = tStopTime - tTime;
52  }
53  // All ok.
54  return true;
55 }
static C4TimeMilliseconds Now()
virtual bool Execute(int iTimeout=-1, pollfd *readyfds=nullptr)=0

References StdSchedulerProc::Execute(), and C4TimeMilliseconds::Now().

Referenced by main().

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

◆ GetAuthCheckReply()

bool C4LeagueClient::GetAuthCheckReply ( StdStrBuf pMessage,
const char *  szLeague,
class C4PlayerInfo pPlrInfo 
)

Definition at line 471 of file C4League.cpp.

472 {
473  // Parse response head
475  if (!CompileFromBuf_LogWarn<StdCompilerINIRead>(mkNamingAdapt(Head, "Response"), ResultString, "Auth Check Reply"))
476  return false;
477  // Get message and additional data
478  if (pMessage)
479  pMessage->Copy(Head.getMessage());
480  if (szLeague && pPlrInfo)
481  pPlrInfo->SetLeagueData(Head.getAccount(), Head.getClanTag(), Head.getScore(szLeague), Head.getRank(szLeague), Head.getRankSymbol(szLeague), Head.getProgressData(szLeague));
482  return Head.isSuccess();
483 }
int32_t getRank(const char *szLeague) const
Definition: C4League.cpp:154
int32_t getRankSymbol(const char *szLeague) const
Definition: C4League.cpp:162
const char * getClanTag() const
Definition: C4League.h:178
int32_t getScore(const char *szLeague) const
Definition: C4League.cpp:146
const char * getProgressData(const char *szLeague) const
Definition: C4League.cpp:170
bool isSuccess() const
Definition: C4League.h:121
const char * getAccount() const
Definition: C4League.h:123
const char * getMessage() const
Definition: C4League.h:120

References StdStrBuf::Copy(), C4LeagueResponseHead::getAccount(), C4LeagueResponseHeadAuthCheck::getClanTag(), C4LeagueResponseHead::getMessage(), C4LeagueResponseHeadAuthCheck::getProgressData(), C4LeagueResponseHeadAuthCheck::getRank(), C4LeagueResponseHeadAuthCheck::getRankSymbol(), C4LeagueResponseHeadAuthCheck::getScore(), C4LeagueResponseHead::isSuccess(), mkNamingAdapt(), C4HTTPClient::ResultString, and C4PlayerInfo::SetLeagueData().

Referenced by C4Network2::LeaguePlrAuthCheck().

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

◆ GetAuthReply()

bool C4LeagueClient::GetAuthReply ( StdStrBuf pMessage,
StdStrBuf pAUID,
StdStrBuf pAccount,
bool *  pRegister,
StdStrBuf pLoginToken 
)

Definition at line 425 of file C4League.cpp.

426 {
428  if (!CompileFromBuf_LogWarn<StdCompilerINIRead>(mkNamingAdapt(Head, "Response"), ResultString, "Auth Reply"))
429  return false;
430  // Get message & account
431  if (pMessage)
432  pMessage->Copy(Head.getMessage());
433  if (pAccount)
434  pAccount->Copy(Head.getAccount());
435  if (pRegister)
436  *pRegister = Head.isStatusRegister();
437  if (pLoginToken)
438  pLoginToken->Copy(Head.getLoginToken());
439  // No success?
440  if (!Head.isSuccess())
441  return false;
442  // Check AUID
443  if (!Head.getAUID() || !*Head.getAUID())
444  {
445  pMessage->Ref(LoadResStr("IDS_MSG_LEAGUESERVERREPLYWITHOUTA"));
446  return false;
447  }
448  // Success
449  if (pAUID)
450  pAUID->Copy(Head.getAUID());
451  FBIDList.AddFBID(Head.getFBID(), Head.getAccount());
452  return true;
453 }
const char * LoadResStr(const char *id)
Definition: C4Language.h:83
void AddFBID(const char *szFBID, const char *szAccount)
Definition: C4League.cpp:237
bool isStatusRegister() const
Definition: C4League.h:122
const char * getAUID() const
Definition: C4League.h:124
const char * getFBID() const
Definition: C4League.h:125
const char * getLoginToken() const
Definition: C4League.h:126
void Ref(const char *pnData)
Definition: StdBuf.h:455

References C4LeagueFBIDList::AddFBID(), StdStrBuf::Copy(), C4LeagueResponseHead::getAccount(), C4LeagueResponseHead::getAUID(), C4LeagueResponseHead::getFBID(), C4LeagueResponseHead::getLoginToken(), C4LeagueResponseHead::getMessage(), C4LeagueResponseHead::isStatusRegister(), C4LeagueResponseHead::isSuccess(), LoadResStr(), mkNamingAdapt(), StdStrBuf::Ref(), and C4HTTPClient::ResultString.

Referenced by C4Network2::LeaguePlrAuth().

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

◆ getCSID()

const char* C4LeagueClient::getCSID ( ) const
inline

Definition at line 215 of file C4League.h.

215 { return CSID.getData(); }

References StdStrBuf::getData().

Here is the call graph for this function:

◆ getCurrentAction()

C4LeagueAction C4LeagueClient::getCurrentAction ( ) const
inline

Definition at line 216 of file C4League.h.

216 { return eCurrAction; }

Referenced by C4Network2::Execute(), C4Network2::LeagueUpdateProcessReply(), and C4Network2::LeagueWaitNotBusy().

Here is the caller graph for this function:

◆ getDownloadedSize()

size_t C4HTTPClient::getDownloadedSize ( ) const
inlineinherited

Definition at line 90 of file C4HTTP.h.

90 { return iDownloadedSize; }

Referenced by C4DownloadDlg::OnIdle().

Here is the caller graph for this function:

◆ GetEndReply()

bool C4LeagueClient::GetEndReply ( StdStrBuf pMessage,
class C4RoundResultsPlayers pRoundResults 
)

Definition at line 390 of file C4League.cpp.

391 {
392  // Parse response head
394  if (!CompileFromBuf_LogWarn<StdCompilerINIRead>(mkNamingAdapt(Head, "Response"), ResultString, "End Reply"))
395  return false;
396  // Get message
397  if (pMessage)
398  pMessage->Copy(Head.getMessage());
399  if (pRoundResults)
400  CompileFromBuf_LogWarn<StdCompilerINIRead>(mkNamingAdapt(mkNamingAdapt(*pRoundResults, "PlayerInfos"), "Response"), ResultString, "Round Results");
401  // Done
402  return Head.isSuccess();
403 }

References StdStrBuf::Copy(), C4LeagueResponseHead::getMessage(), C4LeagueResponseHead::isSuccess(), mkNamingAdapt(), and C4HTTPClient::ResultString.

Referenced by C4Network2::LeagueEnd().

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

◆ GetError()

virtual const char* C4HTTPClient::GetError ( ) const
inlinevirtualinherited

Definition at line 96 of file C4HTTP.h.

96 { return Error.getData(); }

References C4HTTPClient::Error, and StdStrBuf::getData().

Referenced by C4DownloadDlg::GetError(), C4Network2::InitLeague(), C4Game::InitNetworkFromAddress(), C4Network2::LeagueEnd(), C4Network2::LeaguePlrAuthCheck(), C4Network2::LeagueStart(), C4Network2::LeagueUpdate(), C4Network2::LeagueUpdateProcessReply(), C4StartupNetListEntry::OnReference(), and C4StartupNetListEntry::SetRefQuery().

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

◆ GetFDs()

void C4HTTPClient::GetFDs ( std::vector< struct pollfd > &  pollfds)
overridevirtualinherited

Reimplemented from StdSchedulerProc.

Definition at line 135 of file C4HTTP.cpp.

136 {
137  for (const auto& kv : sockets)
138  {
139  pollfd pfd;
140  pfd.fd = kv.first;
141  pfd.revents = 0;
142  switch (kv.second)
143  {
144  case CURL_POLL_IN:
145  pfd.events = POLLIN; break;
146  case CURL_POLL_OUT:
147  pfd.events = POLLOUT; break;
148  case CURL_POLL_INOUT:
149  pfd.events = POLLIN | POLLOUT; break;
150  default:
151  pfd.events = 0;
152  }
153  pollfds.push_back(pfd);
154  }
155 }

◆ GetNextTick()

C4TimeMilliseconds C4HTTPClient::GetNextTick ( C4TimeMilliseconds  tNow)
overridevirtualinherited

Reimplemented from StdSchedulerProc.

Definition at line 125 of file C4HTTP.cpp.

126 {
127  long timeout;
128  curl_multi_timeout(MultiHandle, &timeout);
129  if (timeout < 0)
130  timeout = 1000;
131  return tNow + timeout;
132 }

◆ GetReferences()

bool C4Network2RefClient::GetReferences ( C4Network2Reference **&  rpReferences,
int32_t &  rRefCount 
)
inherited

Definition at line 292 of file C4Network2Reference.cpp.

293 {
294  // Sanity check
295  if (isBusy() || !isSuccess()) return false;
296  // local update test
297  try
298  {
299  // Create compiler
300  StdCompilerINIRead Comp;
301  Comp.setInput(ResultString);
302  Comp.Begin();
303  // Read reference count
304  Comp.Value(mkNamingCountAdapt(rRefCount, "Reference"));
305  // Create reference array and initialize
306  rpReferences = new C4Network2Reference *[rRefCount];
307  for (int i = 0; i < rRefCount; i++)
308  rpReferences[i] = nullptr;
309  // Get references
310  Comp.Value(mkNamingAdapt(mkArrayAdaptMap(rpReferences, rRefCount, mkPtrAdaptNoNull<C4Network2Reference>), "Reference"));
311  mkPtrAdaptNoNull<C4Network2Reference>(*rpReferences);
312  // Done
313  Comp.End();
314  }
315  catch (StdCompiler::Exception *pExc)
316  {
317  SetError(pExc->Msg.getData());
318  return false;
319  }
320  // Set source ip
321  for (int i = 0; i < rRefCount; i++)
322  rpReferences[i]->SetSourceAddress(getServerAddress());
323  // Done
324  ResetError();
325  return true;
326 }
StdArrayAdapt< T, M > mkArrayAdaptMap(T *pArray, int iSize, M &&map)
Definition: StdAdaptors.h:340
StdNamingCountAdapt< int_t > mkNamingCountAdapt(int_t &iCount, const char *szName)
Definition: StdAdaptors.h:1008
void SetError(const char *strnError)
Definition: C4HTTP.h:80
bool isSuccess() const
Definition: C4HTTP.h:88
void ResetError()
Definition: C4HTTP.h:97
const C4NetIO::addr_t & getServerAddress() const
Definition: C4HTTP.h:95
bool isBusy() const
Definition: C4HTTP.h:86
void Value(const T &rStruct)
Definition: StdCompiler.h:161
void End() override
void setInput(const InT &In)
Definition: StdCompiler.h:630
void Begin() override

References StdCompilerINIRead::Begin(), StdCompilerINIRead::End(), StdStrBuf::getData(), C4HTTPClient::getServerAddress(), C4HTTPClient::isBusy(), C4HTTPClient::isSuccess(), mkArrayAdaptMap(), mkNamingAdapt(), mkNamingCountAdapt(), StdCompiler::Exception::Msg, C4HTTPClient::ResetError(), C4HTTPClient::ResultString, C4HTTPClient::SetError(), StdCompilerINIRead::setInput(), and StdCompiler::Value().

Referenced by C4Game::InitNetworkFromAddress(), and C4StartupNetListEntry::OnReference().

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

◆ GetReportDisconnectReply()

bool C4LeagueClient::GetReportDisconnectReply ( StdStrBuf pMessage)

Definition at line 500 of file C4League.cpp.

501 {
502  // Parse response head
504  if (!CompileFromBuf_LogWarn<StdCompilerINIRead>(mkNamingAdapt(Head, "Response"), ResultString, "Report Disconnect"))
505  return false;
506  // Get message
507  if (pMessage)
508  pMessage->Copy(Head.getMessage());
509  // Done
510  return Head.isSuccess();
511 }

References StdStrBuf::Copy(), C4LeagueResponseHead::getMessage(), C4LeagueResponseHead::isSuccess(), mkNamingAdapt(), and C4HTTPClient::ResultString.

Referenced by C4Network2::LeagueNotifyDisconnect().

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

◆ getResultBin()

const StdBuf& C4HTTPClient::getResultBin ( ) const
inlineinherited

Definition at line 91 of file C4HTTP.h.

91 { assert(fBinary); return ResultBin; }

References C4HTTPClient::ResultBin.

Referenced by C4DownloadDlg::ShowModal().

Here is the caller graph for this function:

◆ getResultString()

const char* C4HTTPClient::getResultString ( ) const
inlineinherited

Definition at line 92 of file C4HTTP.h.

92 { assert(!fBinary); return ResultString.getData(); }

References StdStrBuf::getData(), and C4HTTPClient::ResultString.

Here is the call graph for this function:

◆ getServerAddress()

const C4NetIO::addr_t& C4HTTPClient::getServerAddress ( ) const
inlineinherited

Definition at line 95 of file C4HTTP.h.

95 { return ServerAddr; }

Referenced by C4Network2RefClient::GetReferences().

Here is the caller graph for this function:

◆ getServerName()

const char* C4HTTPClient::getServerName ( ) const
inlineinherited

Definition at line 94 of file C4HTTP.h.

94 { return ServerName.getData(); }

References StdStrBuf::getData().

Referenced by C4StartupNetListEntry::GetJoinAddress(), C4Network2::LeagueEnd(), C4Network2::LeaguePlrAuth(), C4Network2::LeagueStart(), and C4StartupNetListEntry::SetRefQuery().

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

◆ GetStartReply()

bool C4LeagueClient::GetStartReply ( StdStrBuf pMessage,
StdStrBuf pLeague,
StdStrBuf pStreamingAddr,
int32_t *  pSeed,
int32_t *  pMaxPlayers 
)

Definition at line 312 of file C4League.cpp.

313 {
314  if (!isSuccess() || eCurrAction != C4LA_Start) return false;
315  // Parse response head
317  if (!CompileFromBuf_LogWarn<StdCompilerINIRead>(mkNamingAdapt(Head, "Response"), ResultString, "Start Reply"))
318  return false;
319  // Get message, league and seed
320  if (pMessage)
321  pMessage->Copy(Head.getMessage());
322  if (pLeague)
323  pLeague->Copy(Head.getLeague());
324  if (pStreamingAddr)
325  pStreamingAddr->Copy(Head.getStreamingAddr());
326  if (pSeed && Head.haveSeed())
327  *pSeed = Head.getSeed();
328  if (pMaxPlayers)
329  *pMaxPlayers = Head.getMaxPlayers();
330  // No success?
331  if (!Head.isSuccess())
332  return false;
333  // Got no CSID or empty CSID?
334  if (!Head.getCSID() || !*Head.getCSID() || *Head.getCSID() == '\0')
335  {
336  if (pMessage)
337  pMessage->Copy(LoadResStr("IDS_LGA_INVALIDRESPONSE3"));
338  return false;
339  }
340  // So save back CSID
341  CSID = Head.getCSID();
342  return true;
343 }
@ C4LA_Start
Definition: C4League.h:35
const char * getCSID() const
Definition: C4League.h:119
const char * getStreamingAddr() const
Definition: C4League.h:142
const char * getLeague() const
Definition: C4League.h:141
bool haveSeed() const
Definition: C4League.h:143
int32_t getSeed() const
Definition: C4League.h:144
int32_t getMaxPlayers() const
Definition: C4League.h:145

References C4LA_Start, StdStrBuf::Copy(), C4LeagueResponseHead::getCSID(), C4LeagueResponseHeadStart::getLeague(), C4LeagueResponseHeadStart::getMaxPlayers(), C4LeagueResponseHead::getMessage(), C4LeagueResponseHeadStart::getSeed(), C4LeagueResponseHeadStart::getStreamingAddr(), C4LeagueResponseHeadStart::haveSeed(), C4HTTPClient::isSuccess(), C4LeagueResponseHead::isSuccess(), LoadResStr(), mkNamingAdapt(), and C4HTTPClient::ResultString.

Referenced by C4Network2::LeagueStart().

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

◆ getTotalSize()

size_t C4HTTPClient::getTotalSize ( ) const
inlineinherited

Definition at line 89 of file C4HTTP.h.

89 { return iTotalSize; }

Referenced by C4DownloadDlg::OnIdle().

Here is the caller graph for this function:

◆ GetUpdateReply()

bool C4LeagueClient::GetUpdateReply ( StdStrBuf pMessage,
C4ClientPlayerInfos pPlayerLeagueInfos 
)

Definition at line 360 of file C4League.cpp.

361 {
363  if (!CompileFromBuf_LogWarn<StdCompilerINIRead>(mkNamingAdapt(Reply, "Response"), ResultString, "Update Reply"))
364  return false;
365  // Get message
366  if (pMessage)
367  pMessage->Copy(Reply.getMessage());
368  // get plr infos
369  if (pPlayerLeagueInfos)
370  *pPlayerLeagueInfos = Reply.GetPlrInfos();
371  // Success
372  return true;
373 }
const C4ClientPlayerInfos & GetPlrInfos() const
Definition: C4League.h:158

References StdStrBuf::Copy(), C4LeagueResponseHead::getMessage(), C4LeagueResponseHeadUpdate::GetPlrInfos(), mkNamingAdapt(), and C4HTTPClient::ResultString.

Referenced by C4Network2::LeagueUpdateProcessReply().

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

◆ getURL()

const char* C4HTTPClient::getURL ( ) const
inlineinherited

Definition at line 93 of file C4HTTP.h.

93 { return URL.getData(); }

References StdStrBuf::getData().

Referenced by C4DownloadDlg::OnIdle().

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

◆ Init()

bool C4HTTPClient::Init ( )
inherited

Definition at line 42 of file C4HTTP.cpp.

43 {
44  MultiHandle = curl_multi_init();
45  if (!MultiHandle) return false;
46 #ifdef STDSCHEDULER_USE_EVENTS
47  if ((Event = WSACreateEvent()) == WSA_INVALID_EVENT)
48  {
49  SetError("could not create socket event");
50  curl_multi_cleanup(MultiHandle);
51  return false;
52  }
53 #endif
54  curl_multi_setopt(MultiHandle, CURLMOPT_SOCKETFUNCTION, &C4HTTPClient::SSocketCallback);
55  curl_multi_setopt(MultiHandle, CURLMOPT_SOCKETDATA, this);
56  return true;
57 }

References C4HTTPClient::SetError().

Referenced by C4StartupNetDlg::CheckVersionUpdate(), C4Network2::InitLeague(), C4Game::InitNetworkFromAddress(), C4StartupNetListEntry::SetRefQuery(), C4DownloadDlg::ShowModal(), and C4Network2::StartStreaming().

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

◆ isBusy()

◆ isConnected()

bool C4HTTPClient::isConnected ( ) const
inlineinherited

Definition at line 87 of file C4HTTP.h.

87 { return iDownloadedSize + iTotalSize != 0; }

Referenced by C4DownloadDlg::OnIdle().

Here is the caller graph for this function:

◆ IsLowPriority()

virtual bool StdSchedulerProc::IsLowPriority ( )
inlinevirtualinherited

Definition at line 82 of file StdScheduler.h.

82 { return false; }

◆ IsNotify()

virtual bool StdSchedulerProc::IsNotify ( )
inlinevirtualinherited

Reimplemented in CStdNotifyProc, and C4NetIO.

Definition at line 83 of file StdScheduler.h.

83 { return false; }

◆ IsSignaled()

bool StdSchedulerProc::IsSignaled ( )
inherited

◆ isSuccess()

bool C4HTTPClient::isSuccess ( ) const
inlineinherited

◆ Query() [1/2]

bool C4HTTPClient::Query ( const char *  szData,
bool  fBinary 
)
inlineinherited

Definition at line 84 of file C4HTTP.h.

84 { return Query(StdBuf(szData, SLen(szData)), fBinary); }
size_t SLen(const char *sptr)
Definition: Standard.h:74
Definition: StdBuf.h:30

References C4HTTPClient::Query(), and SLen().

Referenced by C4HTTPClient::Query().

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

◆ Query() [2/2]

bool C4HTTPClient::Query ( const StdBuf Data,
bool  fBinary 
)
inherited

Definition at line 158 of file C4HTTP.cpp.

159 {
160  if (URL.isNull()) return false;
161  // Cancel previous request
162  if (CurlHandle)
163  Cancel("Cancelled");
164  // No result known yet
166  // store mode
167  this->fBinary = fBinary;
168  // Create request
169  CURL *curl = curl_easy_init();
170  if (!curl) return false;
171 #ifdef C4HTTP_DEBUG
172  curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);
173 #endif
174  curl_easy_setopt(curl, CURLOPT_URL, URL.getData());
175  curl_easy_setopt(curl, CURLOPT_ACCEPT_ENCODING, "");
176  curl_easy_setopt(curl, CURLOPT_USERAGENT, C4ENGINENAME "/" C4VERSION );
177  curl_easy_setopt(curl, CURLOPT_TIMEOUT, C4HTTPQueryTimeout);
178  curl_slist *headers = nullptr;
179  headers = curl_slist_append(headers, "Accept-Charset: utf-8");
180  headers = curl_slist_append(headers, FormatString("Accept-Language: %s", Config.General.LanguageEx).getData());
181  if (!headerAcceptedResponseType.empty())
182  headers = curl_slist_append(headers, headerAcceptedResponseType.c_str());
183 
184  if (Data.getSize())
185  {
186  RequestData = Data;
187  curl_easy_setopt(curl, CURLOPT_POSTFIELDS, RequestData.getData());
188  curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, RequestData.getSize());
189  // Disable the Expect: 100-Continue header which curl automatically
190  // adds for POST requests.
191  headers = curl_slist_append(headers, "Expect:");
192  headers = curl_slist_append(headers, "Content-Type: text/plain; charset=utf-8");
193  }
194 
195  curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
196  curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, &C4HTTPClient::SWriteCallback);
197  curl_easy_setopt(curl, CURLOPT_WRITEDATA, this);
198  curl_easy_setopt(curl, CURLOPT_XFERINFOFUNCTION, &C4HTTPClient::SProgressCallback);
199  curl_easy_setopt(curl, CURLOPT_XFERINFODATA, this);
200  Error.Clear();
201  Error.SetLength(CURL_ERROR_SIZE);
202  *Error.getMData() = '\0';
203  curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, Error.getMData());
204 
205  curl_multi_add_handle(MultiHandle, curl);
206  CurlHandle = curl;
207  iDownloadedSize = iTotalSize = 0;
208 
209  int running;
210  curl_multi_socket_action(MultiHandle, CURL_SOCKET_TIMEOUT, 0, &running);
211 
212  return true;
213 }
C4Config Config
Definition: C4Config.cpp:930
const int C4HTTPQueryTimeout
Definition: C4HTTP.h:30
StdStrBuf FormatString(const char *szFmt,...)
Definition: StdBuf.cpp:270
char LanguageEx[CFG_MaxString+1]
Definition: C4Config.h:38
C4ConfigGeneral General
Definition: C4Config.h:255
size_t getSize() const
Definition: StdBuf.h:101
const void * getData() const
Definition: StdBuf.h:99
void SetLength(size_t iLength)
Definition: StdBuf.h:509
char * getMData()
Definition: StdBuf.h:443
bool isNull() const
Definition: StdBuf.h:441

References C4HTTPQueryTimeout, C4HTTPClient::Cancel(), StdStrBuf::Clear(), Config, C4HTTPClient::Error, FormatString(), C4Config::General, StdBuf::getData(), StdStrBuf::getData(), StdStrBuf::getMData(), StdBuf::getSize(), StdStrBuf::isNull(), C4ConfigGeneral::LanguageEx, C4HTTPClient::ResultString, and StdStrBuf::SetLength().

Referenced by Auth(), AuthCheck(), End(), C4Network2RefClient::QueryReferences(), C4Network2UpdateClient::QueryUpdateURL(), ReportDisconnect(), C4DownloadDlg::ShowModal(), Start(), C4Network2::StreamOut(), and Update().

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

◆ QueryReferences()

bool C4Network2RefClient::QueryReferences ( )
inherited

Definition at line 286 of file C4Network2Reference.cpp.

287 {
288  // Perform an Query query
289  return Query(nullptr, false);
290 }

References C4HTTPClient::Query().

Referenced by C4Game::InitNetworkFromAddress().

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

◆ ReportDisconnect()

bool C4LeagueClient::ReportDisconnect ( const C4ClientPlayerInfos rSendPlayerFBIDs,
C4LeagueDisconnectReason  eReason 
)

Definition at line 485 of file C4League.cpp.

486 {
487  // Build header
488  eCurrAction = C4LA_ReportDisconnect;
489  C4LeagueReportDisconnectHead Head(CSID.getData(), eReason);
490  // Create query
491  StdStrBuf QueryText = DecompileToBuf<StdCompilerINIWrite>(
493  mkNamingAdapt(Head, "Request"),
494  mkNamingAdapt(DisconnectData(FBIDList, rFeedbackClient), "PlayerInfos"),
495  false));
496  // Perform query
497  return Query(QueryText.getData(), false);
498 }
@ C4LA_ReportDisconnect
Definition: C4League.h:43

References C4LA_ReportDisconnect, StdStrBuf::getData(), mkInsertAdapt(), mkNamingAdapt(), and C4HTTPClient::Query().

Referenced by C4Network2::LeagueNotifyDisconnect().

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

◆ ResetCurrentAction()

void C4LeagueClient::ResetCurrentAction ( )
inline

Definition at line 217 of file C4League.h.

217 { eCurrAction = C4LA_None; }
@ C4LA_None
Definition: C4League.h:33

References C4LA_None.

Referenced by C4Network2::LeagueUpdateProcessReply().

Here is the caller graph for this function:

◆ ResetError()

void C4HTTPClient::ResetError ( )
inlineinherited

Definition at line 97 of file C4HTTP.h.

97 { Error.Clear(); }

References StdStrBuf::Clear(), and C4HTTPClient::Error.

Referenced by C4Network2RefClient::GetReferences().

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

◆ SetError()

void C4HTTPClient::SetError ( const char *  strnError)
inlineprotectedinherited

Definition at line 80 of file C4HTTP.h.

80 { Error = strnError; }

References C4HTTPClient::Error.

Referenced by C4Network2RefClient::GetReferences(), C4Network2UpdateClient::GetUpdateURL(), C4Network2UpdateClient::GetVersion(), C4HTTPClient::Init(), and C4HTTPClient::SetServer().

Here is the caller graph for this function:

◆ SetExpectedResponseType()

void C4HTTPClient::SetExpectedResponseType ( C4HTTPClient::ResponseType  type)
inherited

Definition at line 315 of file C4HTTP.cpp.

316 {
317  switch (type)
318  {
319  case C4HTTPClient::ResponseType::XML:
320  headerAcceptedResponseType = "Accept: application/xml";
321  break;
322  case C4HTTPClient::ResponseType::NoPreference: // fallthrough
323  default:
324  headerAcceptedResponseType = "";
325  break;
326  };
327 }

◆ SetNotify()

void C4HTTPClient::SetNotify ( class C4InteractiveThread pnNotify)
inlineinherited

Definition at line 106 of file C4HTTP.h.

106 { pNotify = pnNotify; }

Referenced by C4StartupNetDlg::CheckVersionUpdate(), and C4StartupNetListEntry::SetRefQuery().

Here is the caller graph for this function:

◆ SetServer()

bool C4HTTPClient::SetServer ( const char *  szServerAddress)
inherited

Definition at line 298 of file C4HTTP.cpp.

299 {
300  static std::regex HostnameRegex(R"(^(:?[a-z]+:\/\/)?([^/:]+).*)", std::regex::icase);
301  std::cmatch match;
302  if (std::regex_match(szServerAddress, match, HostnameRegex))
303  {
304  // CURL validates URLs only on connect.
305  URL.Copy(szServerAddress);
306  ServerName.Copy(match[2].str().c_str());
307  return true;
308  }
309  // The HostnameRegex above is pretty stupid, so we will reject only very
310  // malformed URLs immediately.
311  SetError("Malformed URL");
312  return false;
313 }

References StdStrBuf::Copy(), and C4HTTPClient::SetError().

Referenced by C4StartupNetDlg::CheckVersionUpdate(), C4Network2::InitLeague(), C4Game::InitNetworkFromAddress(), C4StartupNetListEntry::SetRefQuery(), C4DownloadDlg::ShowModal(), and C4Network2::StreamOut().

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

◆ Start()

bool C4LeagueClient::Start ( const C4Network2Reference Ref)

Definition at line 298 of file C4League.cpp.

299 {
300  // Create query
301  eCurrAction = C4LA_Start;
302  C4LeagueRequestHead Head(eCurrAction);
303  StdStrBuf QueryText = DecompileToBuf<StdCompilerINIWrite>(
305  mkNamingAdapt(Head, "Request"),
306  mkNamingAdapt(mkDecompileAdapt(Ref), "Reference"),
307  false));
308  // Perform query
309  return Query(QueryText.getData(), false);
310 }

References C4LA_Start, StdStrBuf::getData(), mkDecompileAdapt(), mkInsertAdapt(), mkNamingAdapt(), and C4HTTPClient::Query().

Referenced by C4Network2::LeagueStart().

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

◆ TimerInterval()

virtual uint32_t StdSchedulerProc::TimerInterval ( )
inlinevirtualinherited

Reimplemented in CStdTimerProc.

Definition at line 84 of file StdScheduler.h.

84 { return 0; }

◆ Update()

bool C4LeagueClient::Update ( const C4Network2Reference Ref)

Definition at line 345 of file C4League.cpp.

346 {
347  assert(CSID.getLength());
348  // Create query
349  eCurrAction = C4LA_Update;
350  C4LeagueRequestHead Head(eCurrAction, CSID.getData());
351  StdStrBuf QueryText = DecompileToBuf<StdCompilerINIWrite>(
353  mkNamingAdapt(Head, "Request"),
354  mkNamingAdapt(mkDecompileAdapt(Ref), "Reference"),
355  false));
356  // Perform query
357  return Query(QueryText.getData(), false);
358 }
@ C4LA_Update
Definition: C4League.h:36

References C4LA_Update, StdStrBuf::getData(), StdStrBuf::getLength(), mkDecompileAdapt(), mkInsertAdapt(), mkNamingAdapt(), and C4HTTPClient::Query().

Referenced by C4Network2::LeagueUpdate().

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

Member Data Documentation

◆ Error

◆ ResultBin

StdCopyBuf C4HTTPClient::ResultBin
protectedinherited

Definition at line 77 of file C4HTTP.h.

Referenced by C4HTTPClient::Clear(), and C4HTTPClient::getResultBin().

◆ ResultString


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