Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <a_samp>
- #include <Dini>
- #include <a_http>
- #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],
- _SCAPIRequestPlayer,
- _SCAPIFilePath[MAX_PLAYERS][50]
- ;
- new _DialogArrayCount;
- //----------------------------------------------------------------------------------------------------------------------------------------
- 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}Name {00FF00}Listeners\r\n", CurrentList);
- for(new i = _DialogLimitFrom; i < (_DialogLimitFrom + _DialogRowsPerPage); ++i) {
- format(key, sizeof(key), "s%dname", i);
- 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 {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}No stations found", CurrentList);
- }
- format(temp, sizeof(temp), "%s - Page %d", _DialogCaption[playerid], _DialogCurrentPage[playerid]);
- if(Rows < _DialogRowsPerPage && _DialogCurrentPage[playerid] == 1) {
- _DialogClose[playerid] = 1;
- ShowPlayerDialog(playerid, DIALOG_REPAGINATION, DIALOG_STYLE_LIST, temp, CurrentList, "Close", "");
- } else if(Rows == _DialogRowsPerPage && _DialogCurrentPage[playerid] == 1) {
- _DialogClose[playerid] = 1;
- ShowPlayerDialog(playerid, DIALOG_REPAGINATION, DIALOG_STYLE_LIST, temp, CurrentList, "Close", "Next >>");
- } else if(_DialogArrayCount < (_DialogLimitFrom + Rows) + 1) {
- _DialogClose[playerid] = 2;
- ShowPlayerDialog(playerid, DIALOG_REPAGINATION, DIALOG_STYLE_LIST, temp, CurrentList, "<< Previous", "Close");
- } else {
- _DialogClose[playerid] = 0;
- ShowPlayerDialog(playerid, DIALOG_REPAGINATION, DIALOG_STYLE_LIST, temp, CurrentList, "<< Previous", "Next >>");
- }
- }
- } 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), "You are listening the radio %s. (Listeners: %d, Now playing: %s)", name, listeners, nowplaying);
- SendClientMessage(playerid, 0xFF0000FF, output);
- 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) {
- _SCAPIRequestPlayer = playerid;
- format(key, sizeof(key), "brazucas-dev.com/ShoutCastAPI.php?show=id|name|listeners&count=20&field=listeners&order=desc&search=%s", inputtext);
- HTTP(playerid, HTTP_GET, key, "", "ShoutCastAPIResponse");
- }
- } else {
- _DialogCurrentPage[playerid] = strval(inputtext);
- OnDialogResponse(playerid, DIALOG_REPAGINATION, 2, 0, "");
- }
- return 0;
- }
- //----------------------------------------------------------------------------------------------------------------------------------------
- public OnPlayerCommandText(playerid, cmdtext[])
- {
- new cmd[128];
- new idx;
- cmd = strtok(cmdtext,idx);
- if (strcmp("/showtopstations", cmd, true, 11) == 0) {
- _SCAPIRequestPlayer = playerid;
- HTTP(playerid, HTTP_GET, "brazucas-dev.com/ShoutCastAPI.php?show=id|name|listeners&count=20&field=listeners&order=desc", "", "ShoutCastAPIResponse");
- return 1;
- } else if (strcmp("/searchstation", cmd, true, 11) == 0) {
- _DialogArrayCount = dini_Int(_SCAPIFilePath[playerid], "count");
- ShowPlayerDialog(playerid, DIALOG_SHOUTCASTAPI_SEARCH, DIALOG_STYLE_INPUT, "Search stations", "Type a part of an station name", "Search", "Cancel");
- return 1;
- } else if (strcmp("/stopradio", 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[_SCAPIRequestPlayer], sizeof(_SCAPIFilePath), "%s%d.ini", SHOUTCAST_API_FILE, _SCAPIRequestPlayer);
- new File:temp = fopen(_SCAPIFilePath[_SCAPIRequestPlayer], io_write);
- if(temp) {
- fwrite(temp, data);
- fclose(temp);
- }
- _DialogArrayCount = dini_Int(_SCAPIFilePath[_SCAPIRequestPlayer], "count");
- ShowPlayerList(_SCAPIRequestPlayer, DIALOG_SHOUTCASTAPI_CLICK, "ShoutCast - Stations List", 1);
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement