| 530 | }; |
| 531 | |
| 532 | IServerBrowserHttp *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 | } |