| 1509 | } |
| 1510 | |
| 1511 | void CServerBrowser::LoadDDNetServers() |
| 1512 | { |
| 1513 | // Parse communities |
| 1514 | m_vCommunities.clear(); |
| 1515 | m_CommunityServersByAddr.clear(); |
| 1516 | |
| 1517 | if(!m_pDDNetInfo) |
| 1518 | { |
| 1519 | return; |
| 1520 | } |
| 1521 | |
| 1522 | const json_value &Communities = (*m_pDDNetInfo)["communities"]; |
| 1523 | if(Communities.type != json_array) |
| 1524 | { |
| 1525 | return; |
| 1526 | } |
| 1527 | |
| 1528 | for(unsigned CommunityIndex = 0; CommunityIndex < Communities.u.array.length; ++CommunityIndex) |
| 1529 | { |
| 1530 | const json_value &Community = Communities[CommunityIndex]; |
| 1531 | if(Community.type != json_object) |
| 1532 | { |
| 1533 | log_error("serverbrowser", "invalid community (CommunityIndex=%d)", (int)CommunityIndex); |
| 1534 | continue; |
| 1535 | } |
| 1536 | const json_value &Id = Community["id"]; |
| 1537 | if(Id.type != json_string) |
| 1538 | { |
| 1539 | log_error("serverbrowser", "invalid community id (CommunityIndex=%d)", (int)CommunityIndex); |
| 1540 | continue; |
| 1541 | } |
| 1542 | const json_value &Icon = Community["icon"]; |
| 1543 | const json_value &IconSha256 = Icon["sha256"]; |
| 1544 | const json_value &IconUrl = Icon["url"]; |
| 1545 | const json_value &Name = Community["name"]; |
| 1546 | const json_value HasFinishes = Community["has_finishes"]; |
| 1547 | const json_value *pFinishes = &Community["finishes"]; |
| 1548 | const json_value *pServers = &Community["servers"]; |
| 1549 | // We accidentally set finishes/servers to be part of icon in |
| 1550 | // the past, so support that, too. Can be removed once we make |
| 1551 | // a breaking change to the whole thing, necessitating a new |
| 1552 | // endpoint. |
| 1553 | if(pFinishes->type == json_none) |
| 1554 | { |
| 1555 | pServers = &Icon["finishes"]; |
| 1556 | } |
| 1557 | if(pServers->type == json_none) |
| 1558 | { |
| 1559 | pServers = &Icon["servers"]; |
| 1560 | } |
| 1561 | // Backward compatibility. |
| 1562 | if(pFinishes->type == json_none) |
| 1563 | { |
| 1564 | if(str_comp(Id, COMMUNITY_DDNET) == 0) |
| 1565 | { |
| 1566 | pFinishes = &(*m_pDDNetInfo)["maps"]; |
| 1567 | } |
| 1568 | } |
nothing calls this directly
no test coverage detected