Created
October 10, 2014 02:05
-
-
Save pedropapa/bd7a2831b89ceb1e1524 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <a_samp> | |
#include <Dini> | |
#include <a_http> | |
#include <a_mysql> | |
/** | |
* --------------- 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://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 DIALOG_RADIO 12459 | |
#define SHOUTCAST_API_FILE "ShoutCast/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], | |
str[7][128] | |
; | |
new _RADIO_TITULO[64], | |
_MUSICA_ATUAL[64], | |
_OUVINTES[3], | |
_MAXIMO_OUVINTES[3], | |
_OUVINTES_LISTA[480], | |
_TOTAL_VISITAS[5], | |
_RADIO_LIGADA[2], | |
_DJ[24]; | |
//---------------------------------------------------------------------------------------------------------------------------------------- | |
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%Listeners", 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], nick[MAX_PLAYER_NAME]; | |
GetPlayerName(playerid, nick, sizeof(nick)); | |
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%dCurrentTrack", 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); | |
} | |
format(output, sizeof(output), "contas_mgs/%s.txt", nick); | |
dini_IntSet(output, "radioid", url); | |
dini_Set(output, "radionome", name); | |
dini_IntSet(output, "radioouvintes", listeners); | |
format(output, sizeof(output), "O jogador %s está ouvindo agora a rádio '%s' (Tocando agora: %s | Ouvintes: %d)", nick, name, nowplaying, listeners); | |
SendClientMessageToAll(0xEE4000FF, output); | |
format(output, sizeof(output), "Para ouvir esta rádio digite /radio ouvirradio %d. Para procurar outras rádios digite /radio procurarradios", playerid); | |
SendClientMessageToAll(0xEE4000FF, output); | |
SendClientMessage(playerid, 0x0000FF00, "Caso você não esteja ouvindo a rádio, pressione ESC > Opções > Audio e aumente o volume da rádio."); | |
PlayAudioStreamForPlayer(playerid, play); | |
IsPlayerListeningRadio[playerid] = 1; | |
} else if(dialogid == DIALOG_SHOUTCASTAPI_SEARCH) { | |
if(strlen(inputtext) > 0) { | |
format(key, sizeof(key), "brazucas-server.com/ShoutCastAPI.php?count=15&show=ID|Listeners|Name|CurrentTrack&song=%s", inputtext); | |
HTTP(playerid, HTTP_GET, key, "", "ShoutCastAPIResponse"); | |
} | |
} else if(dialogid == DIALOG_RADIO) { | |
if(response == 1) { | |
switch(listitem) { | |
case 0: { // top 10 | |
DialogRadio(playerid, "top10radios"); | |
} | |
case 1: { // Procurar | |
DialogRadio(playerid, "procurarradios"); | |
} | |
case 2: { // Parar | |
DialogRadio(playerid, "pararradio"); | |
} | |
case 3: { // Ouvir rádio de jogador | |
DialogRadio(playerid, "ouvirradio"); | |
} | |
case 4: { // Ouvir Rádio'BRZ | |
DialogRadio(playerid, "brz"); | |
} | |
case 5: { | |
DialogRadio(playerid, "stats"); | |
} | |
} | |
} | |
} | |
return 0; | |
} | |
//---------------------------------------------------------------------------------------------------------------------------------------- | |
forward DialogRadio(playerid, cmd[]); | |
public DialogRadio(playerid, cmd[]) { | |
new tmp[128], idx; | |
if(strfind(cmd, "top10radios", true) != -1) { | |
HTTP(playerid, HTTP_GET, "brazucas-dev.com/ShoutCastAPI.php?show=id|name|listeners|nowplaying&count=10&field=listeners&order=desc", "", "ShoutCastAPIResponse"); | |
} else if(strfind(cmd, "procurarradios", true) != -1) { | |
ShowPlayerDialog(playerid, DIALOG_SHOUTCASTAPI_SEARCH, DIALOG_STYLE_INPUT, "Procurar Rádios", "Digite uma palavra chave:", "Procurar", "Cancelar"); | |
} else if(strfind(cmd, "pararradio", true) != -1) { | |
IsPlayerListeningRadio[playerid] = 0; | |
StopAudioStreamForPlayer(playerid); | |
} else if(strfind(cmd, "ouvirradio", true) != -1) { | |
new plrid, url, play[100], nick[MAX_PLAYER_NAME], output[200], ouvintes, radio_nome[50], jog[MAX_PLAYER_NAME]; | |
tmp = strtok(cmd, idx); | |
if(!strlen(tmp)) return SendClientMessage(playerid,0xEE4000FF,"/radio ouvirradio [playerid]"); | |
format(str[0],24,"%s",tmp); | |
plrid = strval(str[0]); | |
if(playerid == plrid) return SendClientMessage(playerid,0xEE4000FF, "Digite um id diferente."); | |
if(!IsPlayerConnected(plrid)) return SendClientMessage(playerid,0xEE4000FF,"Este jogador não está conectado."); | |
GetPlayerName(plrid, nick, sizeof(nick)); | |
GetPlayerName(playerid, jog, sizeof(jog)); | |
format(output, sizeof(output), "contas_mgs/%s.txt", nick); | |
url = dini_Int(output, "radioid"); | |
ouvintes = dini_Int(output, "radioouvintes"); | |
format(radio_nome, sizeof(radio_nome), "%s", dini_Get(output, "radionome")); | |
if(url == 0) return SendClientMessage(playerid,0xEE4000FF, "Este jogador não está ouvindo uma rádio."); | |
if(IsPlayerListeningRadio[playerid] == 1) { | |
StopAudioStreamForPlayer(playerid); | |
} | |
format(play, sizeof(play), "http://yp.shoutcast.com/sbin/tunein-station.pls?id=%d", url); | |
PlayAudioStreamForPlayer(playerid, play); | |
IsPlayerListeningRadio[playerid] = 1; | |
format(output, sizeof(output), "O jogador %s está ouvindo a mesma rádio que %s (Nome: %s | Ouvintes: %d)", jog, nick, radio_nome, ouvintes); | |
SendClientMessageToAll(0xEE4000FF, output); | |
format(output, sizeof(output), "Para ouvir a mesma rádio que eles digite /r ouvirradio %d", plrid); | |
SendClientMessageToAll(0xEE4000FF, output); | |
} else if(strfind(cmd, "brz", true) != -1) { | |
new play[100], jog[MAX_PLAYER_NAME], output[200]; | |
format(play, sizeof(play), "http://198.211.116.169:8000"); | |
PlayAudioStreamForPlayer(playerid, play); | |
IsPlayerListeningRadio[playerid] = 1; | |
GetPlayerName(playerid, jog, sizeof(jog)); | |
format(output, sizeof(output), "O jogador %s está ouvindo a Rádio'BRZ!", jog); | |
SendClientMessageToAll(0xEE4000FF, output); | |
} else if(strfind(cmd, "stats", true) != -1) { | |
ShowRadioStats(playerid); | |
} else { | |
SendClientMessage(playerid, 0xFF000000, "Uso: /radio [procurarradios|pararradio|ouvirradio|brz]"); | |
} | |
return 1; | |
} | |
public OnPlayerCommandText(playerid, cmdtext[]) | |
{ | |
new cmd[128]; | |
new tmp[128]; | |
new idx; | |
cmd = strtok(cmdtext,idx); | |
if(strcmp("/radio", cmd, true) == 0 || strcmp("/r", cmd, true) == 0) { | |
tmp = strtok(cmdtext, idx); | |
if(!strlen(tmp)) return ShowPlayerDialog(playerid, DIALOG_RADIO, DIALOG_STYLE_LIST, "Rádio", "Top 10 Rádios\nProcurar Rádios\nParar Rádio\nOuvir Rádio do Jogador\nOuvir Rádio'BRZ\nEstatísticas da Rádio'BRZ", "Cancelar", ""); | |
format(str[0],24,"%s",tmp); | |
DialogRadio(playerid, str[0]); | |
} | |
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; | |
} | |
//---------------------------------------------------------------------------------------------------------------------------------------- | |
enum RadioInfo{ | |
RADIO_TITULO[64], | |
MUSICA_ATUAL[64], | |
OUVINTES[3], | |
MAXIMO_OUVINTES[3], | |
OUVINTES_LISTA[480], | |
TOTAL_VISITAS[5], | |
RADIO_LIGADA[2], | |
DJ[24] | |
} | |
//------------------------------------------------------------------------------------------------------------------------------------------ | |
new RadioStats[RadioInfo]; | |
stock BarToLine(text[]){ | |
new idx = 0; | |
while(text[idx] != '\0') | |
{ | |
switch(text[idx]) | |
{ | |
case '|': text[idx] = '\n'; | |
} | |
idx++; | |
} | |
return 1; | |
} | |
forward GetPlayerRadioStatus(playerid); | |
public GetPlayerRadioStatus(playerid){ | |
return IsPlayerListeningRadio[playerid]; | |
} | |
//---------------------------------------------------------------------------------------------------------------------------------------- | |
forward GetRadioStats(); | |
public GetRadioStats(){ | |
new Query[511]; | |
mysql_format(1, Query,sizeof(Query),"SELECT * FROM RADIO_INFO LIMIT 0,1"); | |
new Cache:mysqlFetch = mysql_query(1, Query); | |
if(cache_num_rows() > 0) { | |
cache_get_field_content(0, "RADIO_TITULO", _RADIO_TITULO); | |
cache_get_field_content(0, "MUSICA_ATUAL", _MUSICA_ATUAL); | |
cache_get_field_content(0, "OUVINTES", _OUVINTES); | |
cache_get_field_content(0, "MAXIMO_OUVINTES", _MAXIMO_OUVINTES); | |
cache_get_field_content(0, "OUVINTES_LISTA", _OUVINTES_LISTA); | |
cache_get_field_content(0, "TOTAL_VISITAS", _TOTAL_VISITAS); | |
cache_get_field_content(0, "RADIO_LIGADA", _RADIO_LIGADA); | |
cache_get_field_content(0, "DJ", _DJ); | |
} | |
cache_delete(mysqlFetch); | |
BarToLine(_OUVINTES_LISTA); | |
if(strlen(_MUSICA_ATUAL)) dini_Set("brazucas.brz","MusicaTocando",_MUSICA_ATUAL); else dini_Set("brazucas.brz","MusicaTocando","Nenhuma musica tocando..."); | |
return 1; | |
} | |
//------------------------------------------------------------------------------------------------------------------------------------------ | |
forward ShowRadioStats(forplayerid); | |
public ShowRadioStats(forplayerid){ | |
GetRadioStats(); | |
if(strval(_RADIO_LIGADA)==1){ | |
new StrStats[640]; | |
format(StrStats,sizeof(StrStats),"{37DB45}Nome: {FFFFFF}%s\n\n",_RADIO_TITULO); | |
format(StrStats,sizeof(StrStats),"%s{37DB45}DJ: {FFFFFF}%s\n\n",StrStats,_DJ); | |
format(StrStats,sizeof(StrStats),"%s{37DB45}Musica atual: {FFFFFF}%s\n\n",StrStats,_MUSICA_ATUAL); | |
format(StrStats,sizeof(StrStats),"%s{37DB45}Ouvintes(%d/%d):\n{FFFFFF}%s\n\n",StrStats,strval(_OUVINTES),strval(_MAXIMO_OUVINTES),_OUVINTES_LISTA); | |
format(StrStats,sizeof(StrStats),"%s{37DB45}Visitas: {FFFFFF}%d",StrStats,strval(_TOTAL_VISITAS)); | |
ShowPlayerDialog(forplayerid,DIALOG_RADIO,DIALOG_STYLE_MSGBOX,"Brazucas'Radio Stats",StrStats,"Ok",""); | |
} | |
else{ | |
ShowPlayerDialog(forplayerid,DIALOG_RADIO,DIALOG_STYLE_MSGBOX,"Brazucas'Radio Stats","{FF0000}Desligada","Ok",""); | |
} | |
return 1; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment