I kinda overwritten it. but here is the basic for socket listen
Code:
#include <amxmodx>
#include <sockets_hz>
#define MAXDOWNLOADS 15
new downloadsockets[MAXDOWNLOADS+1]
new sckFastDownload
public plugin_init() {
register_plugin("S_HZTEST", "1.0", "NL)Ramon(NL")
if (cvar_exists("amx_FastDownload_socket")) {
sckFastDownload = get_cvar_num("amx_FastDownload_socket")
}
else{
register_cvar("amx_FastDownload_socket", "0", FCVAR_PROTECTED&FCVAR_UNLOGGED)
connect_FastDownload()
}
register_srvcmd("acceptcall","read_FastDownload")
set_task(0.1,"read_lol",0,"",0,"b")
}
public connect_FastDownload() {
new error = 0
sckFastDownload = socket_listen("10.0.0.127",80,SOCKET_TCP,error)
if (sckFastDownload > 0) {
//read_FastDownload() LOCK THE SERVER UNTIL FIXED
}
else {
switch (error) {
case 1: { server_print("/* Error creating socket */")
}
case 2: { server_print("/* Could not resolve hostname */")
}
case 3: { server_print("/* Could not connect to given host:port */")
}
}
}
}
public read_FastDownload() {
static newClient
newClient = socket_accept(sckFastDownload)
if(newClient) {
new i
while(i<MAXDOWNLOADS) {
if(!downloadsockets[i]) {
server_print("Connect")
downloadsockets[i] = newClient
//nextaccept() LOCKS THE SERVER UNTIL XIF
return PLUGIN_CONTINUE
}
++i
}
log_amx("[FASTDL] MAX SIMILAR DOWNLOADS REACHED, CLIENT CONNECTION REFUSED")
}
//nextaccept() LOCKS THE SERVER UNTIL FIX
return PLUGIN_CONTINUE
}
public nextaccept() {
if (sckFastDownload != 0)
set_task(10.0, "read_FastDownload")
}
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
}
public read_lol() {
new i
while(i<MAXDOWNLOADS) {
if(downloadsockets[i]) {
if (socket_change(downloadsockets[i], 100)) {
new buf[512], lines[10][100], count = 0
socket_recv(downloadsockets[i], buf, 511)
count = ExplodeString(lines, 10, 99, buf, 13)
for(new i=0;i<count;i++) {
server_print(lines[i])
}
connect(lines,i)
}
}
++i
}
}
public write_lol(text[512],dlnum) {
socket_send(downloadsockets[dlnum], text, 511)
}
public disconnect_lol(dlnum) {
downloadsockets[dlnum] = 0
}
public connect(lines[10][100],socketclientarray) {
// do ya stuff here
}
acceptcall in server console will check if there is a client connecting. it will lock the server until somone does, so i didnt make it go automaticly yet.
It will listen on the default http port. 80
if you write acceptcall in console and make IE try to connect it it will show you what IE has send. not more cause i overwriten the small html thingy...