SHARE
TWEET

[FS] Sistema de Procurar e Ouvir Radio

Chip7 Jun 4th, 2012 325 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*VISITE NOSSO SITE: http://www.sampknd.com/
  2.   SAMP KND MELHOR BLOG DE SAMP DO BRASIL
  3. */
  4.  
  5. #include <a_samp>
  6. #include <Dini>
  7. #include <a_http>
  8.  
  9. /**
  10.  * --------------- Sistema para procurar e ouvir rádios do ShoutCast In-Game ---------------
  11.  *
  12.  * @author: Pedro P. L. Papadópolis (a.k.a Mandrakke).
  13.  * @copyright: Não há.
  14.  *
  15.  * Brazucas'Server - Desde 2006;
  16.  * http://brazucas-server.com
  17.  *
  18.  * Ferramenta para ver todos os objetos do SA-MP, incluindo os objetos adicionados no SA-MP 0.3e (em inglês);
  19.  * http://brazucas-server.com/$objetos
  20.  *
  21.  *
  22.  *
  23.  * Mais informações sobre a API do ShoutCast pode ser encontrada no tópico oficial no fórum do SA-MP (em inglês);
  24.  * http://forum.sa-mp.com/showthread.php?t=347016
  25.  *
  26.  *
  27.  *
  28.  * Versão: R1 Beta
  29.  *
  30.  * -------------------------------------------------------------------
  31.  */
  32.  
  33. #define DIALOG_SHOUTCASTAPI 12455
  34. #define DIALOG_REPAGINATION 12456
  35. #define DIALOG_SHOUTCASTAPI_CLICK 12457
  36. #define DIALOG_SHOUTCASTAPI_SEARCH 12458
  37.  
  38. #define SHOUTCAST_API_FILE "ShoutCastAPIOutput"
  39.  
  40. new
  41.         _DialogCurrentPage[MAX_PLAYERS],
  42.         _DialogClose[MAX_PLAYERS],
  43.         _DialogGlobListItem[MAX_PLAYERS],
  44.         _DialogRowsPerPage,
  45.         _DialogCallback[MAX_PLAYERS],
  46.         _DialogCaption[MAX_PLAYERS][50],
  47.         IsPlayerListeningRadio[MAX_PLAYERS],
  48.         _SCAPIFilePath[MAX_PLAYERS][50]
  49. ;
  50.  
  51. //----------------------------------------------------------------------------------------------------------------------------------------
  52. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  53. {
  54.         new key[128];
  55.  
  56.     if(dialogid == DIALOG_REPAGINATION) {
  57.             if(response == 1) {
  58.                         if(_DialogClose[playerid] == 1 && listitem == 0) return 0;
  59.                         else {
  60.                             if(listitem > 0) {
  61.                                         _DialogGlobListItem[playerid] = listitem - 1;
  62.                                 OnDialogResponse(playerid, _DialogCallback[playerid], 1, ((_DialogCurrentPage[playerid] - 1) * _DialogRowsPerPage + listitem) - 1, inputtext);
  63.                             } else {
  64.                                 _DialogCurrentPage[playerid]--;
  65.                         OnDialogResponse(playerid, DIALOG_REPAGINATION, 2, 0, "");
  66.                             }
  67.                         }
  68.             } else if(response == 0) {
  69.                 if(_DialogClose[playerid] == 2) return 0;
  70.                 else {
  71.                     if(listitem > 0) {
  72.                         _DialogGlobListItem[playerid] = listitem - 1;
  73.                         OnDialogResponse(playerid, _DialogCallback[playerid], 1, ((_DialogCurrentPage[playerid] - 1) * _DialogRowsPerPage + listitem) - 1, inputtext);
  74.                             } else {
  75.                                 _DialogCurrentPage[playerid]++;
  76.                                 OnDialogResponse(playerid, DIALOG_REPAGINATION, 2, 0, "");
  77.                             }
  78.                 }
  79.             } else if(response == 2) {
  80.                 new Rows, CurrentList[700], _DialogLimitFrom, temp[60];
  81.  
  82.                 _DialogRowsPerPage = 10;
  83.  
  84.                         _DialogLimitFrom = (_DialogCurrentPage[playerid] - 1) * _DialogRowsPerPage;
  85.  
  86.                         format(CurrentList, sizeof(CurrentList), "{FFFFFF}Nome \t\t\t{00FF00}Ouvintes\r\n", CurrentList);
  87.                         for(new i = _DialogLimitFrom; i < (_DialogLimitFrom + _DialogRowsPerPage); ++i) {
  88.                                 format(key, sizeof(key), "s%dname", i);
  89.                                
  90.                                 if(strlen(dini_Get(_SCAPIFilePath[playerid], key))) {
  91.                                 format(CurrentList, sizeof(CurrentList), "%s {FFFFFF}%s", CurrentList, dini_Get(_SCAPIFilePath[playerid], key));
  92.  
  93.                                 format(key, sizeof(key), "s%dlisteners", i);
  94.                                 format(CurrentList, sizeof(CurrentList), "%s \t{00FF00}%s", CurrentList, dini_Get(_SCAPIFilePath[playerid], key));
  95.  
  96.                                 format(CurrentList, sizeof(CurrentList), "%s\r\n", CurrentList);
  97.                                 ++Rows;
  98.                         }
  99.                         }
  100.  
  101.                         if(Rows == 0) {
  102.                             format(CurrentList, sizeof(CurrentList), "%s\r\n{FF0000}Nenhuma rádio encontrada.", CurrentList);
  103.                         }
  104.  
  105.                         format(temp, sizeof(temp), "%s - Página %d", _DialogCaption[playerid], _DialogCurrentPage[playerid]);
  106.                         if(dini_Int(_SCAPIFilePath[playerid], "count") <= _DialogLimitFrom + _DialogRowsPerPage && _DialogCurrentPage[playerid] == 1) {
  107.                             _DialogClose[playerid] = 1;
  108.                                 ShowPlayerDialog(playerid, DIALOG_REPAGINATION, DIALOG_STYLE_LIST, temp, CurrentList, "Fechar", "");
  109.                         } else if(Rows == _DialogRowsPerPage && dini_Int(_SCAPIFilePath[playerid], "count") > _DialogLimitFrom + _DialogRowsPerPage && _DialogCurrentPage[playerid] == 1) {
  110.                                 _DialogClose[playerid] = 1;
  111.                                 ShowPlayerDialog(playerid, DIALOG_REPAGINATION, DIALOG_STYLE_LIST, temp, CurrentList, "Fechar", "Próxima >>");
  112.                         } else if(dini_Int(_SCAPIFilePath[playerid], "count") <= _DialogLimitFrom + _DialogRowsPerPage) {
  113.                             _DialogClose[playerid] = 2;
  114.                                 ShowPlayerDialog(playerid, DIALOG_REPAGINATION, DIALOG_STYLE_LIST, temp, CurrentList, "<< Anterior", "Fechar");
  115.                         } else {
  116.                             _DialogClose[playerid] = 0;
  117.                                 ShowPlayerDialog(playerid, DIALOG_REPAGINATION, DIALOG_STYLE_LIST, temp, CurrentList, "<< Anterior", "Próxima >>");
  118.                         }
  119.                 }
  120.         } else if(dialogid == DIALOG_SHOUTCASTAPI_CLICK) {
  121.                 new url, name[50], listeners, nowplaying[80], output[200], play[60];
  122.  
  123.         format(key, sizeof(key), "s%did", listitem);                    url = dini_Int(_SCAPIFilePath[playerid], key);
  124.         format(key, sizeof(key), "s%dlisteners", listitem);     listeners = dini_Int(_SCAPIFilePath[playerid], key);
  125.         format(key, sizeof(key), "s%dname", listitem);                  format(name, sizeof(name), "%s", dini_Get(_SCAPIFilePath[playerid], key));
  126.         format(key, sizeof(key), "s%dnowplaying", listitem);    format(nowplaying, sizeof(nowplaying), "%s", dini_Get(_SCAPIFilePath[playerid], key));
  127.  
  128.         format(output, sizeof(output), "{FFFFFF}Rádio: {00FF00}%s\n{FFFFFF}Ouvintes: {00FF00}%d\n{FFFFFF}Tocando agora: {00FF00}%s", name, listeners, nowplaying);
  129.         ShowPlayerDialog(playerid, 25502, DIALOG_STYLE_MSGBOX, "Rádio sintonizada!", output, "ok", "");
  130.  
  131.                 format(play, sizeof(play), "http://yp.shoutcast.com/sbin/tunein-station.pls?id=%d", url);
  132.  
  133.                 if(IsPlayerListeningRadio[playerid] == 1) {
  134.                         StopAudioStreamForPlayer(playerid);
  135.                 }
  136.  
  137.                 PlayAudioStreamForPlayer(playerid, play);
  138.                 IsPlayerListeningRadio[playerid] = 1;
  139.         } else if(dialogid == DIALOG_SHOUTCASTAPI_SEARCH) {
  140.                 if(strlen(inputtext) > 0) {
  141.                         format(key, sizeof(key), "brazucas-dev.com/ShoutCastAPI.php?show=id|name|listeners|nowplaying&count=15&field=listeners&order=desc&search=%s", inputtext);
  142.                         HTTP(playerid, HTTP_GET, key, "", "ShoutCastAPIResponse");
  143.                 }
  144.         }
  145.     return 0;
  146. }
  147. //----------------------------------------------------------------------------------------------------------------------------------------
  148. public OnPlayerCommandText(playerid, cmdtext[])
  149. {
  150.     new cmd[128];
  151.         new idx;
  152.         cmd = strtok(cmdtext,idx);
  153.  
  154.         if (strcmp("/top10radios", cmd, true, 11) == 0) {
  155.                 HTTP(playerid, HTTP_GET, "brazucas-dev.com/ShoutCastAPI.php?show=id|name|listeners|nowplaying&count=10&field=listeners&order=desc", "", "ShoutCastAPIResponse");
  156.  
  157.                 return 1;
  158.         } else if (strcmp("/procurarradios", cmd, true, 11) == 0) {
  159.                 ShowPlayerDialog(playerid, DIALOG_SHOUTCASTAPI_SEARCH, DIALOG_STYLE_INPUT, "Procurar Rádios", "Digite uma palavra chave:", "Search", "Cancel");
  160.  
  161.                 return 1;
  162.         } else if (strcmp("/pararradio", cmd, true, 11) == 0) {
  163.             IsPlayerListeningRadio[playerid] = 0;
  164.             StopAudioStreamForPlayer(playerid);
  165.  
  166.             return 1;
  167.         }
  168.  
  169.         return 0;
  170. }
  171. //----------------------------------------------------------------------------------------------------------------------------------------
  172. forward ShowPlayerList(playerid, dialogid, caption[], startpage);
  173. public ShowPlayerList(playerid, dialogid, caption[], startpage) {
  174.     _DialogCurrentPage[playerid]        = 1;
  175.     _DialogCallback[playerid]           = dialogid;
  176.  
  177.     format(_DialogCaption[playerid], 50, "%s", caption);
  178.  
  179.     OnDialogResponse(playerid, DIALOG_REPAGINATION, 2, 0, "");
  180.     return 1;
  181. }
  182. //----------------------------------------------------------------------------------------------------------------------------------------
  183. forward ShoutCastAPIResponse(index, response_code, data[]);
  184. public ShoutCastAPIResponse(index, response_code, data[]) {
  185.         format(_SCAPIFilePath[index], sizeof(_SCAPIFilePath), "%s%d.ini", SHOUTCAST_API_FILE, index);
  186.  
  187.     new File:temp = fopen(_SCAPIFilePath[index], io_write);
  188.     if(temp) {
  189.         fwrite(temp, data);
  190.         fclose(temp);
  191.     }
  192.    
  193.         ShowPlayerList(index, DIALOG_SHOUTCASTAPI_CLICK, "Lista de rádios online agora", 1);
  194.  
  195.     return 1;
  196. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top