MCPcopy Create free account
hub / github.com/BZFlag-Dev/bzflag / bz_sendFetchResMessage

Function bz_sendFetchResMessage

src/bzfs/bzfsAPI.cpp:1772–1812  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1770//-------------------------------------------------------------------------
1771
1772BZF_API bool bz_sendFetchResMessage(int playerID, const char* URL) {
1773 if (playerID == BZ_SERVER || !URL) {
1774 return false;
1775 }
1776
1777 teResourceType resType = eFile;
1778
1779 std::vector < std::string > temp = TextUtils::tokenize(TextUtils::tolower(std::string(URL)), std::string("."));
1780
1781 std::string ext = temp[temp.size() - 1];
1782 if (ext == "wav") {
1783 resType = eSound;
1784 }
1785 else if (ext == "png") {
1786 resType = eImage;
1787 }
1788
1789 NetMessage netMsg;
1790
1791 netMsg.packUInt16(1); // the count
1792 netMsg.packUInt8(1); // overwrite
1793 netMsg.packUInt16((short)resType);
1794 netMsg.packUInt16((unsigned short)strlen(URL));
1795 netMsg.packString(URL, strlen(URL));
1796
1797 if (playerID == BZ_ALLUSERS) {
1798 for (int i = 0; i < curMaxPlayers; i++) {
1799 GameKeeper::Player* p = GameKeeper::Player::getPlayerByIndex(i);
1800 if (p && p->caps.canDownloadResources) {
1801 netMsg.send(p->netHandler, MsgFetchResources);
1802 }
1803 }
1804 }
1805 else {
1806 GameKeeper::Player* player = GameKeeper::Player::getPlayerByIndex(playerID);
1807 if (player && player->caps.canDownloadResources) {
1808 netMsg.send(player->netHandler, MsgFetchResources);
1809 }
1810 }
1811 return true;
1812}
1813
1814//-------------------------------------------------------------------------
1815

Callers 2

SendFetchResourceFunction · 0.85
Player_fetchResourceFunction · 0.85

Calls 8

tolowerFunction · 0.85
packUInt16Method · 0.80
packUInt8Method · 0.80
packStringMethod · 0.80
tokenizeFunction · 0.50
getPlayerByIndexFunction · 0.50
sizeMethod · 0.45
sendMethod · 0.45

Tested by

no test coverage detected