Advertisement
Papadopolis

Untitled

May 30th, 2012
292
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 7.45 KB | None | 0 0
  1. #include <a_samp>
  2. #include <Dini>
  3. #include <a_http>
  4.  
  5. #define DIALOG_SHOUTCASTAPI 12455
  6. #define DIALOG_REPAGINATION 12456
  7. #define DIALOG_SHOUTCASTAPI_CLICK 12457
  8. #define DIALOG_SHOUTCASTAPI_SEARCH 12458
  9.  
  10. #define SHOUTCAST_API_FILE "ShoutCastAPIOutput"
  11.  
  12. new
  13.     _DialogCurrentPage[MAX_PLAYERS],
  14.     _DialogClose[MAX_PLAYERS],
  15.     _DialogGlobListItem[MAX_PLAYERS],
  16.     _DialogRowsPerPage,
  17.     _DialogCallback[MAX_PLAYERS],
  18.     _DialogCaption[MAX_PLAYERS][50],
  19.     IsPlayerListeningRadio[MAX_PLAYERS],
  20.     _SCAPIRequestPlayer,
  21.     _SCAPIFilePath[MAX_PLAYERS][50]
  22. ;
  23.  
  24. new _DialogArrayCount;
  25.  
  26. //----------------------------------------------------------------------------------------------------------------------------------------
  27. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  28. {
  29.     new key[128];
  30.  
  31.     if(dialogid == DIALOG_REPAGINATION) {
  32.         if(response == 1) {
  33.             if(_DialogClose[playerid] == 1 && listitem == 0) return 0;
  34.             else {
  35.                 if(listitem > 0) {
  36.                     _DialogGlobListItem[playerid] = listitem - 1;
  37.                     OnDialogResponse(playerid, _DialogCallback[playerid], 1, ((_DialogCurrentPage[playerid] - 1) * _DialogRowsPerPage + listitem) - 1, inputtext);
  38.                 } else {
  39.                     _DialogCurrentPage[playerid]--;
  40.                     OnDialogResponse(playerid, DIALOG_REPAGINATION, 2, 0, "");
  41.                 }
  42.             }
  43.         } else if(response == 0) {
  44.             if(_DialogClose[playerid] == 2) return 0;
  45.             else {
  46.                 if(listitem > 0) {
  47.                     _DialogGlobListItem[playerid] = listitem - 1;
  48.                     OnDialogResponse(playerid, _DialogCallback[playerid], 1, ((_DialogCurrentPage[playerid] - 1) * _DialogRowsPerPage + listitem) - 1, inputtext);
  49.                 } else {
  50.                     _DialogCurrentPage[playerid]++;
  51.                     OnDialogResponse(playerid, DIALOG_REPAGINATION, 2, 0, "");
  52.                 }
  53.             }
  54.         } else if(response == 2) {
  55.             new Rows, CurrentList[700], _DialogLimitFrom, temp[60];
  56.  
  57.             _DialogRowsPerPage = 10;
  58.  
  59.             _DialogLimitFrom = (_DialogCurrentPage[playerid] - 1) * _DialogRowsPerPage;
  60.  
  61.             format(CurrentList, sizeof(CurrentList), "{FFFFFF}Name {00FF00}Listeners\r\n", CurrentList);
  62.  
  63.             for(new i = _DialogLimitFrom; i < (_DialogLimitFrom + _DialogRowsPerPage); ++i) {
  64.                 format(key, sizeof(key), "s%dname", i);
  65.                 format(CurrentList, sizeof(CurrentList), "%s {FFFFFF}%s", CurrentList, dini_Get(_SCAPIFilePath[playerid], key));
  66.  
  67.                 format(key, sizeof(key), "s%dlisteners", i);
  68.                 format(CurrentList, sizeof(CurrentList), "%s {00FF00}%s", CurrentList, dini_Get(_SCAPIFilePath[playerid], key));
  69.  
  70.                 format(CurrentList, sizeof(CurrentList), "%s\r\n", CurrentList);
  71.                 ++Rows;
  72.             }
  73.  
  74.             if(Rows == 0) {
  75.                 format(CurrentList, sizeof(CurrentList), "%s\r\n{FF0000}No stations found", CurrentList);
  76.             }
  77.  
  78.             format(temp, sizeof(temp), "%s - Page %d", _DialogCaption[playerid], _DialogCurrentPage[playerid]);
  79.             if(Rows < _DialogRowsPerPage && _DialogCurrentPage[playerid] == 1) {
  80.                 _DialogClose[playerid] = 1;
  81.                 ShowPlayerDialog(playerid, DIALOG_REPAGINATION, DIALOG_STYLE_LIST, temp, CurrentList, "Close", "");
  82.             } else if(Rows == _DialogRowsPerPage && _DialogCurrentPage[playerid] == 1) {
  83.                 _DialogClose[playerid] = 1;
  84.                 ShowPlayerDialog(playerid, DIALOG_REPAGINATION, DIALOG_STYLE_LIST, temp, CurrentList, "Close", "Next >>");
  85.             } else if(_DialogArrayCount < (_DialogLimitFrom + Rows) + 1) {
  86.                 _DialogClose[playerid] = 2;
  87.                 ShowPlayerDialog(playerid, DIALOG_REPAGINATION, DIALOG_STYLE_LIST, temp, CurrentList, "<< Previous", "Close");
  88.             } else {
  89.                 _DialogClose[playerid] = 0;
  90.                 ShowPlayerDialog(playerid, DIALOG_REPAGINATION, DIALOG_STYLE_LIST, temp, CurrentList, "<< Previous", "Next >>");
  91.             }
  92.         }
  93.     } else if(dialogid == DIALOG_SHOUTCASTAPI_CLICK) {
  94.         new url, name[50], listeners, nowplaying[80], output[200], play[60];
  95.  
  96.         format(key, sizeof(key), "s%did", listitem);            url = dini_Int(_SCAPIFilePath[playerid], key);
  97.         format(key, sizeof(key), "s%dlisteners", listitem);     listeners = dini_Int(_SCAPIFilePath[playerid], key);
  98.         format(key, sizeof(key), "s%dname", listitem);          format(name, sizeof(name), "%s", dini_Get(_SCAPIFilePath[playerid], key));
  99.         format(key, sizeof(key), "s%dnowplaying", listitem);    format(nowplaying, sizeof(nowplaying), "%s", dini_Get(_SCAPIFilePath[playerid], key));
  100.  
  101.         format(output, sizeof(output), "You are listening the radio %s. (Listeners: %d, Now playing: %s)", name, listeners, nowplaying);
  102.         SendClientMessage(playerid, 0xFF0000FF, output);
  103.  
  104.         format(play, sizeof(play), "http://yp.shoutcast.com/sbin/tunein-station.pls?id=%d", url);
  105.  
  106.         if(IsPlayerListeningRadio[playerid] == 1) {
  107.             StopAudioStreamForPlayer(playerid);
  108.         }
  109.  
  110.         PlayAudioStreamForPlayer(playerid, play);
  111.         IsPlayerListeningRadio[playerid] = 1;
  112.     } else if(dialogid == DIALOG_SHOUTCASTAPI_SEARCH) {
  113.         if(strlen(inputtext) > 0) {
  114.             _SCAPIRequestPlayer = playerid;
  115.             format(key, sizeof(key), "brazucas-dev.com/ShoutCastAPI.php?show=id|name|listeners&count=20&field=listeners&order=desc&search=%s", inputtext);
  116.             HTTP(playerid, HTTP_GET, key, "", "ShoutCastAPIResponse");
  117.         }
  118.     } else {
  119.         _DialogCurrentPage[playerid] = strval(inputtext);
  120.         OnDialogResponse(playerid, DIALOG_REPAGINATION, 2, 0, "");
  121.     }
  122.     return 0;
  123. }
  124. //----------------------------------------------------------------------------------------------------------------------------------------
  125. public OnPlayerCommandText(playerid, cmdtext[])
  126. {
  127.     new cmd[128];
  128.     new idx;
  129.     cmd = strtok(cmdtext,idx);
  130.  
  131.     if (strcmp("/showtopstations", cmd, true, 11) == 0) {
  132.         _SCAPIRequestPlayer = playerid;
  133.         HTTP(playerid, HTTP_GET, "brazucas-dev.com/ShoutCastAPI.php?show=id|name|listeners&count=20&field=listeners&order=desc", "", "ShoutCastAPIResponse");
  134.  
  135.         return 1;
  136.     } else if (strcmp("/searchstation", cmd, true, 11) == 0) {
  137.         _DialogArrayCount = dini_Int(_SCAPIFilePath[playerid], "count");
  138.  
  139.         ShowPlayerDialog(playerid, DIALOG_SHOUTCASTAPI_SEARCH, DIALOG_STYLE_INPUT, "Search stations", "Type a part of an station name", "Search", "Cancel");
  140.  
  141.         return 1;
  142.     } else if (strcmp("/stopradio", cmd, true, 11) == 0) {
  143.         IsPlayerListeningRadio[playerid] = 0;
  144.         StopAudioStreamForPlayer(playerid);
  145.  
  146.         return 1;
  147.     }
  148.  
  149.     return 0;
  150. }
  151. //----------------------------------------------------------------------------------------------------------------------------------------
  152. forward ShowPlayerList(playerid, dialogid, caption[], startpage);
  153. public ShowPlayerList(playerid, dialogid, caption[], startpage) {
  154.     _DialogCurrentPage[playerid]    = 1;
  155.     _DialogCallback[playerid]       = dialogid;
  156.  
  157.     format(_DialogCaption[playerid], 50, "%s", caption);
  158.  
  159.     OnDialogResponse(playerid, DIALOG_REPAGINATION, 2, 0, "");
  160.     return 1;
  161. }
  162. //----------------------------------------------------------------------------------------------------------------------------------------
  163. forward ShoutCastAPIResponse(index, response_code, data[]);
  164. public ShoutCastAPIResponse(index, response_code, data[]) {
  165.     format(_SCAPIFilePath[_SCAPIRequestPlayer], sizeof(_SCAPIFilePath), "%s%d.ini", SHOUTCAST_API_FILE, _SCAPIRequestPlayer);
  166.  
  167.     new File:temp = fopen(_SCAPIFilePath[_SCAPIRequestPlayer], io_write);
  168.     if(temp) {
  169.         fwrite(temp, data);
  170.         fclose(temp);
  171.     }
  172.  
  173.     _DialogArrayCount = dini_Int(_SCAPIFilePath[_SCAPIRequestPlayer], "count");
  174.     ShowPlayerList(_SCAPIRequestPlayer, DIALOG_SHOUTCASTAPI_CLICK, "ShoutCast - Stations List", 1);
  175.  
  176.     return 1;
  177. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement