Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <a_samp>
- #include <Dini>
- #include <a_http>
- /**
- * --------------- Sistema para procurar e ouvir rádios do ShoutCast In-Game ---------------
- *
- * @author: Pedro P. L. Papadópolis (a.k.a Mandrakke).
- * @copyright: Não há.
- *
- * Brazucas'Server - Desde 2006;
- * http://brazucas-server.com
- *
- * Ferramenta para ver todos os objetos do SA-MP, incluindo os objetos adicionados no SA-MP 0.3e (em inglês);
- * http://samp.brazucas-server.com/$objetos
- *
- *
- *
- * Mais informações sobre a API do ShoutCast pode ser encontrada no tópico oficial no fórum do SA-MP (em inglês);
- * http://forum.sa-mp.com/showthread.php?t=347016
- *
- *
- *
- * Versão: R1 Beta
- *
- * -------------------------------------------------------------------
- */
- #define DIALOG_SHOUTCASTAPI 12455
- #define DIALOG_REPAGINATION 12456
- #define DIALOG_SHOUTCASTAPI_CLICK 12457
- #define DIALOG_SHOUTCASTAPI_SEARCH 12458
- #define SHOUTCAST_API_FILE "ShoutCastAPIOutput"
- new
- _DialogCurrentPage[MAX_PLAYERS],
- _DialogClose[MAX_PLAYERS],
- _DialogGlobListItem[MAX_PLAYERS],
- _DialogRowsPerPage,
- _DialogCallback[MAX_PLAYERS],
- _DialogCaption[MAX_PLAYERS][50],
- IsPlayerListeningRadio[MAX_PLAYERS],
- _SCAPIFilePath[MAX_PLAYERS][50]
- ;
- //----------------------------------------------------------------------------------------------------------------------------------------
- public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
- {
- new key[128];
- if(dialogid == DIALOG_REPAGINATION) {
- if(response == 1) {
- if(_DialogClose[playerid] == 1 && listitem == 0) return 0;
- else {
- if(listitem > 0) {
- _DialogGlobListItem[playerid] = listitem - 1;
- OnDialogResponse(playerid, _DialogCallback[playerid], 1, ((_DialogCurrentPage[playerid] - 1) * _DialogRowsPerPage + listitem) - 1, inputtext);
- } else {
- _DialogCurrentPage[playerid]--;
- OnDialogResponse(playerid, DIALOG_REPAGINATION, 2, 0, "");
- }
- }
- } else if(response == 0) {
- if(_DialogClose[playerid] == 2) return 0;
- else {
- if(listitem > 0) {
- _DialogGlobListItem[playerid] = listitem - 1;
- OnDialogResponse(playerid, _DialogCallback[playerid], 1, ((_DialogCurrentPage[playerid] - 1) * _DialogRowsPerPage + listitem) - 1, inputtext);
- } else {
- _DialogCurrentPage[playerid]++;
- OnDialogResponse(playerid, DIALOG_REPAGINATION, 2, 0, "");
- }
- }
- } else if(response == 2) {
- new Rows, CurrentList[700], _DialogLimitFrom, temp[60];
- _DialogRowsPerPage = 10;
- _DialogLimitFrom = (_DialogCurrentPage[playerid] - 1) * _DialogRowsPerPage;
- format(CurrentList, sizeof(CurrentList), "{FFFFFF}Nome \t\t\t{00FF00}Ouvintes\r\n", CurrentList);
- for(new i = _DialogLimitFrom; i < (_DialogLimitFrom + _DialogRowsPerPage); ++i) {
- format(key, sizeof(key), "s%dname", i);
- if(strlen(dini_Get(_SCAPIFilePath[playerid], key))) {
- format(CurrentList, sizeof(CurrentList), "%s {FFFFFF}%s", CurrentList, dini_Get(_SCAPIFilePath[playerid], key));
- format(key, sizeof(key), "s%dlisteners", i);
- format(CurrentList, sizeof(CurrentList), "%s \t{00FF00}%s", CurrentList, dini_Get(_SCAPIFilePath[playerid], key));
- format(CurrentList, sizeof(CurrentList), "%s\r\n", CurrentList);
- ++Rows;
- }
- }
- if(Rows == 0) {
- format(CurrentList, sizeof(CurrentList), "%s\r\n{FF0000}Nenhuma rádio encontrada.", CurrentList);
- }
- format(temp, sizeof(temp), "%s - Página %d", _DialogCaption[playerid], _DialogCurrentPage[playerid]);
- if(dini_Int(_SCAPIFilePath[playerid], "count") <= _DialogLimitFrom + _DialogRowsPerPage && _DialogCurrentPage[playerid] == 1) {
- _DialogClose[playerid] = 1;
- ShowPlayerDialog(playerid, DIALOG_REPAGINATION, DIALOG_STYLE_LIST, temp, CurrentList, "Fechar", "");
- } else if(Rows == _DialogRowsPerPage && dini_Int(_SCAPIFilePath[playerid], "count") > _DialogLimitFrom + _DialogRowsPerPage && _DialogCurrentPage[playerid] == 1) {
- _DialogClose[playerid] = 1;
- ShowPlayerDialog(playerid, DIALOG_REPAGINATION, DIALOG_STYLE_LIST, temp, CurrentList, "Fechar", "Próxima >>");
- } else if(dini_Int(_SCAPIFilePath[playerid], "count") <= _DialogLimitFrom + _DialogRowsPerPage) {
- _DialogClose[playerid] = 2;
- ShowPlayerDialog(playerid, DIALOG_REPAGINATION, DIALOG_STYLE_LIST, temp, CurrentList, "<< Anterior", "Fechar");
- } else {
- _DialogClose[playerid] = 0;
- ShowPlayerDialog(playerid, DIALOG_REPAGINATION, DIALOG_STYLE_LIST, temp, CurrentList, "<< Anterior", "Próxima >>");
- }
- }
- } else if(dialogid == DIALOG_SHOUTCASTAPI_CLICK) {
- new url, name[50], listeners, nowplaying[80], output[200], play[60];
- format(key, sizeof(key), "s%did", listitem); url = dini_Int(_SCAPIFilePath[playerid], key);
- format(key, sizeof(key), "s%dlisteners", listitem); listeners = dini_Int(_SCAPIFilePath[playerid], key);
- format(key, sizeof(key), "s%dname", listitem); format(name, sizeof(name), "%s", dini_Get(_SCAPIFilePath[playerid], key));
- format(key, sizeof(key), "s%dnowplaying", listitem); format(nowplaying, sizeof(nowplaying), "%s", dini_Get(_SCAPIFilePath[playerid], key));
- format(output, sizeof(output), "{FFFFFF}Rádio: {00FF00}%s\n{FFFFFF}Ouvintes: {00FF00}%d\n{FFFFFF}Tocando agora: {00FF00}%s", name, listeners, nowplaying);
- ShowPlayerDialog(playerid, 25502, DIALOG_STYLE_MSGBOX, "Rádio sintonizada!", output, "ok", "");
- format(play, sizeof(play), "http://yp.shoutcast.com/sbin/tunein-station.pls?id=%d", url);
- if(IsPlayerListeningRadio[playerid] == 1) {
- StopAudioStreamForPlayer(playerid);
- }
- PlayAudioStreamForPlayer(playerid, play);
- IsPlayerListeningRadio[playerid] = 1;
- } else if(dialogid == DIALOG_SHOUTCASTAPI_SEARCH) {
- if(strlen(inputtext) > 0) {
- format(key, sizeof(key), "brazucas-dev.com/ShoutCastAPI.php?show=id|name|listeners|nowplaying&count=15&field=listeners&order=desc&search=%s", inputtext);
- HTTP(playerid, HTTP_GET, key, "", "ShoutCastAPIResponse");
- }
- }
- return 0;
- }
- //----------------------------------------------------------------------------------------------------------------------------------------
- public OnPlayerCommandText(playerid, cmdtext[])
- {
- new cmd[128];
- new idx;
- cmd = strtok(cmdtext,idx);
- if (strcmp("/top10radios", cmd, true, 11) == 0) {
- HTTP(playerid, HTTP_GET, "brazucas-dev.com/ShoutCastAPI.php?show=id|name|listeners|nowplaying&count=10&field=listeners&order=desc", "", "ShoutCastAPIResponse");
- return 1;
- } else if (strcmp("/procurarradios", cmd, true, 11) == 0) {
- ShowPlayerDialog(playerid, DIALOG_SHOUTCASTAPI_SEARCH, DIALOG_STYLE_INPUT, "Procurar Rádios", "Digite uma palavra chave:", "Search", "Cancel");
- return 1;
- } else if (strcmp("/pararradio", cmd, true, 11) == 0) {
- IsPlayerListeningRadio[playerid] = 0;
- StopAudioStreamForPlayer(playerid);
- return 1;
- }
- return 0;
- }
- //----------------------------------------------------------------------------------------------------------------------------------------
- forward ShowPlayerList(playerid, dialogid, caption[], startpage);
- public ShowPlayerList(playerid, dialogid, caption[], startpage) {
- _DialogCurrentPage[playerid] = 1;
- _DialogCallback[playerid] = dialogid;
- format(_DialogCaption[playerid], 50, "%s", caption);
- OnDialogResponse(playerid, DIALOG_REPAGINATION, 2, 0, "");
- return 1;
- }
- //----------------------------------------------------------------------------------------------------------------------------------------
- forward ShoutCastAPIResponse(index, response_code, data[]);
- public ShoutCastAPIResponse(index, response_code, data[]) {
- format(_SCAPIFilePath[index], sizeof(_SCAPIFilePath), "%s%d.ini", SHOUTCAST_API_FILE, index);
- new File:temp = fopen(_SCAPIFilePath[index], io_write);
- if(temp) {
- fwrite(temp, data);
- fclose(temp);
- }
- ShowPlayerList(index, DIALOG_SHOUTCASTAPI_CLICK, "Lista de rádios online agora", 1);
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement