¿How can I read all content of the web? because the web will change everyday and I want to save the content into a file.
Here is my code:
Code:
#include <amxmodx>
#include <sockets>
new const CGT_VERSION[] = "1.00"
new const CGT_HOST[] = "www.cgtworld.com"
new gSocket
new updated = 0
public plugin_init() {
register_plugin("CGT Match Info", CGT_VERSION, "CGT Dev Team")
register_cvar("cgt_version", CGT_VERSION, FCVAR_SERVER)
register_srvcmd("cgt_update", "update")
set_task(3600.0,"update")
update()
//register_event("HLTV", "update", "a")
}
public update() {
server_print("Actualizando...")
if(!updated) {
new socket_error = 0
gSocket = socket_open(CGT_BL_HOST, 80, SOCKET_TCP, socket_error)
if(socket_error != 0) {
switch (socket_error)
{
case 1:
server_print("Error en crear conexion")
case 2:
server_print("Error en resolver el nombre del servidor")
case 3:
server_print("Error en intentar a conectarse")
}
return PLUGIN_CONTINUE
}
new send[256]
formatex(send, 255, "GET /match/id-1/info.txt HTTP/1.1^r^nHost: %s^r^nConnection: close^r^n^r^n", CGT_HOST)
socket_send(gSocket, send, strlen(send))
if(!task_exists(5048)) set_task(0.25, "write_cgt", 5048, _, _, "b")
} else server_print("CGT ya ha sido actualizado recientemente")
return PLUGIN_CONTINUE
}
public write_cgt() {
new head[174]
if(socket_change(gSocket)) {
socket_recv(gSocket, head, 173)
new lines[7][174]
ExplodeString(lines, 50, 119, head, 13)
new value[10]
new variable[30]
parse(lines[6], variable, 29, value, 9)
new const rSize = str_to_num(value)
new receive[1024]
socket_recv(gSocket, receive, 1023)
new info
info = fopen("info.dat", "a")
fprintf(info, receive)
fclose(info)
updated = 1
remove_task(5048)
socket_close(gSocket)
server_print("CGT ha sido actualizado correctamente")
}
}
stock ExplodeString( p_szOutput[][], p_nMax, p_nSize, p_szInput[], p_szDelimiter ) { // Function by xeroblood
new nIdx = 0, l = strlen(p_szInput)
new nLen = (1 + copyc( p_szOutput[nIdx], p_nSize, p_szInput, p_szDelimiter ))
while( (nLen < l) && (++nIdx < p_nMax) )
nLen += (1 + copyc( p_szOutput[nIdx], p_nSize, p_szInput[nLen], p_szDelimiter ))
return nIdx
}
Thanks!