MCPcopy Create free account
hub / github.com/ddnet/ddnet / CreateServerBrowserHttp

Function CreateServerBrowserHttp

src/engine/client/serverbrowser_http.cpp:532–567  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

530};
531
532IServerBrowserHttp *CreateServerBrowserHttp(IEngine *pEngine, IStorage *pStorage, IHttp *pHttp, const char *pPreviousBestUrl)
533{
534 char aaUrls[CChooseMaster::MAX_URLS][256];
535 const char *apUrls[CChooseMaster::MAX_URLS] = {nullptr};
536 const char **ppUrls = apUrls;
537 int NumUrls = 0;
538 CLineReader LineReader;
539 if(LineReader.OpenFile(pStorage->OpenFile("ddnet-serverlist-urls.cfg", IOFLAG_READ, IStorage::TYPE_ALL)))
540 {
541 while(const char *pLine = LineReader.Get())
542 {
543 if(NumUrls == CChooseMaster::MAX_URLS)
544 {
545 break;
546 }
547 str_copy(aaUrls[NumUrls], pLine);
548 apUrls[NumUrls] = aaUrls[NumUrls];
549 NumUrls += 1;
550 }
551 }
552 if(NumUrls == 0)
553 {
554 ppUrls = DEFAULT_SERVERLIST_URLS;
555 NumUrls = std::size(DEFAULT_SERVERLIST_URLS);
556 }
557 int PreviousBestIndex = -1;
558 for(int i = 0; i < NumUrls; i++)
559 {
560 if(str_comp(ppUrls[i], pPreviousBestUrl) == 0)
561 {
562 PreviousBestIndex = i;
563 break;
564 }
565 }
566 return new CServerBrowserHttp(pEngine, pHttp, ppUrls, NumUrls, PreviousBestIndex);
567}

Callers 1

OnInitMethod · 0.85

Calls 4

str_compFunction · 0.85
str_copyFunction · 0.50
OpenFileMethod · 0.45
GetMethod · 0.45

Tested by

no test coverage detected