[Half-Life AMXX] / wr.sma Repository:
ViewVC logotype

View of /wr.sma

Parent Directory Parent Directory | Revision Log Revision Log


Revision 14 - (download) (annotate)
Wed Nov 7 03:16:55 2007 UTC (13 years, 1 month ago) by ian
File size: 3884 byte(s)
Save to data instead of configs.
Removed amxmisc dependency.
/* 
* THX to ShOrTy making the auto update function :D (he modified DarkSnows tutorialhttp://forums.alliedmods.net/showthread.php?t=41913) all credits for that go to him!
* All credits for the /wr function go to dajrokan! i was to lazy to code it my<self so i just copyed his code into this plugin!
* I know the code is crappy but it does what i should do, doesnt it? :P
*/

#include <amxmodx>
#include <sockets>

#define SCRIPT_NAME "/demos.txt"
#define REMOTE_HOST "xtreme-jumps.eu" //port d.80

#define LOCAL_FILE "demos.txt" //saved to /configs/

new g_sckweb //socket "id"
new timeout
new dir[128]
new bool:write_now
new bool:file_open
new file_handler

new wr[256]

new SVC_SAYTEXT

public plugin_init() {
	register_plugin("WR_demos.txt_autoupdate", "2.0" ,"SchlumPF*")
	set_task(5.0,"connect_web")
	
	register_clcmd("say /wr","show_wr")
	register_clcmd("say /worldrecord","show_wr")

	get_localinfo( "amxx_datadir", dir, 127 )
	format(dir,127,"%s/%s",dir,LOCAL_FILE)
	
	SVC_SAYTEXT = get_user_msgid( "SayText" )
}

public connect_web() {
	new error = 0
	new constring[512]

	g_sckweb = socket_open(REMOTE_HOST, 80, SOCKET_TCP, error)
	if (g_sckweb > 0) {
		format(constring,511,"GET %s HTTP/1.1^nHost: %s^n^n",SCRIPT_NAME,REMOTE_HOST)
		write_web(constring)
		read_web()
	} else {
		switch (error) {
			case 1: { server_print("Error creating socket"); }
			case 2: { server_print("Error resolving remote hostname"); }
			case 3: { server_print("Error connecting socket"); }
		}
	}
	return PLUGIN_CONTINUE
}

public read_web() {
	new buf[512]
	if (socket_change(g_sckweb, 100)) {
		timeout=0
		socket_recv(g_sckweb, buf, 511)
		if (!write_now) { //search first data to cut header infos
			new search = strfind(buf,"Xtreme-Jumps.eu",0,0)
			if(search != -1) {
				copy(buf,511,buf[search])
				write_now=true
			}
		}
		if(write_now) {
			if(!file_open) {
				file_handler=fopen(dir,"w+")
				file_open=true
			}
			if(file_open)
				fputs(file_handler,buf)
		}
	} else {
		timeout++
	}
	if (timeout >= 5)
		disconnect_web()
	else
		set_task(0.1, "read_web")
	return PLUGIN_CONTINUE
}

public write_web(text[512]) {
	socket_send(g_sckweb, text, 511)
}

public disconnect_web() {
	if(!write_now) {
		log_amx("Error getting HTTP data")
	}
	if (file_open)
		fclose(file_handler)
	socket_close(g_sckweb)
	
	get_wr()

	return PLUGIN_HANDLED
}

public get_wr() {
	if (file_exists(dir) == 1) {
		new line, stxtsize
		new data[64]
		new cMap[32]
		get_mapname(cMap, 31)
		new MapName[32], jumper[32], t[16], tnum = 0, len, pMap[32], ext[16]

		while ((line = read_file(dir,line,data,63,stxtsize)) != 0)
		{
			parse(data, MapName, 31, t, 15, jumper, 31)
			if (containi(MapName, "[") != -1) {
				replace(MapName, 31, "[", " ")
				replace(MapName, 31, "]", " ")
				parse(MapName, pMap, 31, ext, 15)
				MapName = pMap
			} else
				ext= ""
			if (equal(MapName, cMap)) {
				if (!tnum) {
					tnum = str_to_num(t)
					//len = format(wr, 255, "World Record:^n   Map: %s^n   Author: %s (%d:%02d) %s", cMap, jumper, tnum/60, tnum%60, ext)
					len = format(wr, 255, "^x03^t^tThe world record for ^x04%s ^x03is ^x04%d:%02d^x03 by: ^x04%s^x03  %s", cMap, tnum/60, tnum%60, jumper, ext)
				} else {
					tnum = str_to_num(t)
					//len += format(wr[len], 255-len, "^n               %s (%d:%02d) %s", jumper, tnum/60, tnum%60, ext)
					len += format(wr[len], 255-len, "^x03%s (%d:%02d) %s", jumper, tnum/60, tnum%60, ext)
				}
			}
		}
		if (!tnum)
			format(wr, 255, "World Record:^n   Map: %s^n   Author: N/A", cMap)
	}
	else
		wr = "Failed to load database!"

	return PLUGIN_CONTINUE
}

public show_wr(id) {
	message_begin( MSG_ALL, SVC_SAYTEXT, _, id)
	write_byte( id )
	write_string( wr )
	message_end()
	
	return PLUGIN_CONTINUE
}

Contact
ViewVC Help
Powered by ViewVC 1.0.4