| 1770 | //------------------------------------------------------------------------- |
| 1771 | |
| 1772 | BZF_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 |
no test coverage detected