25.07.2012, 04:35
Chat Web x Servidor
Fiz rбpidinho, sу pra ajudar um gringo aн. Mas jб serve para o pessoal que quer
aprender PHP ou comeзar pelo bбsico.
Coloque isto em um filterscript:
pawn Код:
#include a_samp
#include a_http
public OnPlayerText(playerid, text[]) {
static
szUrl[255]
;
//
szUrl = "127.0.0.1/page.php?textoServer=";
strcat(szUrl, urlencode(text), 255);
//
HTTP(playerid, HTTP_GET, szUrl, "", "NULL");
//
return true;
}
/**
* Url encodes a specific string
* @param string string. FUNC BY DRACOBLUE
*/
stock urlencode(string[]) {
new ret[MAX_STRING];
ret[0] = 0;
new i = 0;
new p = 0;
new s = 0;
while (string[i] != 0) {
if (
(string[i] >= 'A' && string[i] <='Z')
|| (string[i] >= 'a' && string[i] <='z')
|| (string[i] >= '0' && string[i] <='9')
|| (string[i] == '-')
|| (string[i] == '_')
|| (string[i] == '.')
) {
ret[p] = string[i];
} else {
//
ret[p] = '%';
p++;
s = (string[i] % 16); //
ret[p+1] = (s>9) ? (55+s) : (48+s); // 64 - 9 = 55
s = floatround((string[i] - s)/16);
ret[p] = (s>9) ? (55+s) : (48+s); // 64 - 9 = 55
p++;
}
p++;
i++;
}
return ret;
}
PHP код:
<?php
if(isset($_GET['textoServer'])) {
$fp = fopen("chat.txt", "a+");
fwrite($fp, $_GET['textoServer'] ."</br>" );
fclose($fp);
}
if(isset($_GET['chatserver'])) {
$fp = fopen("chat.txt", "a+");
fwrite($fp, $_GET['chatserver'] ."</br>" );
fclose($fp);
enviarComandoRCON("127.0.0.1", 7777, "SUASENHARCON", "say " . $_GET['chatserver']);
}
echo @ file_get_contents("chat.txt");
function enviarComandoRCON($ip, $porta, $rcon, $cmd, $timeout = 5) {
$packet = 'SAMP';
$ipArr = explode('.', $ip);
$packet .= chr($ipArr[0]) . chr($ipArr[1]) . chr($ipArr[2]) . chr($ipArr[3]) . chr($porta & 255) . chr($porta >> 8 & 255);
$packet .= 'x'.chr(strlen($rcon) & 255).chr(strlen($rcon) >> 8 & 255).$rcon.chr(strlen($cmd) & 255).chr(strlen($cmd) >> 8 & 255) .$cmd;
$socket = fsockopen('udp://'.$ip, $porta, $erroval, $errostr, $timeout);
if($socket) {
fwrite($socket, $packet);
fclose($socket);
return true;
}
return false;
}
?>
<form method="GET">
<input name="chatserver" id="texto"/><input type="submit" name="value">
</form>
<script>
setTimeout("release()", 2000);
function release() {
if(document.getElementById("texto").value == '') {
location.href = 'http://127.0.0.1/page.php';
}
}
</script>
- Comunicaзгo total entre servidor e pбgina
- Seguro. Sу precisa verificar se o que se escreve nгo й XSS
- Atualiza automaticamente se nгo estiver digitando.
- Simples e fбcil modificaзгo
- se disserem que й cуdigo pequeno/ъtil nгo posto mais porr nenhuma
Post original:
http://forum.sa-mp.com/showpost.php?...3&postcount=13
Criado por Bruno da Silva @ [iPs]TeaM 2010 2012
