Advertisement
Papadopolis

Untitled

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