Help with plugin modification.
I want to add Polish records in this plugin but after my changes when I sad /pl command on server plugin don't show any record from http://kzpl.kampno.pl/demos.txt
Please help me, because author of plugin doesn't answer.
kz_records.sma: (bold verses are added by me)
Code:
#include <amxmodx>
#include <httpdl>
#pragma semicolon 1
#define PLUGIN "KZ Records"
#define VERSION "1.6b"
#define AUTHOR "SchlumPF"
#define ADMIN_FLAG ADMIN_KICK
#define MAX 13
#define SAY 2
#define EXT 6
new g_CountryAdjective[MAX][] =
{
"World",
"German",
"French",
"Estonian",
"Russian",
"Slovakian",
"Norwegian",
"Swedish",
"Danish",
"Bulgarien",
"Romanian",
"Brazilian",
"Polish"
};
new g_SayCommands[MAX][SAY][] =
{
{ "/xj", "/wr" },
{ "/cg", "/de" },
{ "/fr", "" },
{ "/ee", "" },
{ "/ru", "" },
{ "/sk", "" },
{ "/no", "" },
{ "/se", "" },
{ "/dk", "" },
{ "/bg", "" },
{ "/ro", "" },
{ "/br", "" },
{ "/pl", "" }
};
new g_DownloadLink[MAX][] =
{
"http://xtreme-jumps.eu/demos.txt",
"http://climbers-germany.de/demos.txt",
"http://kzfr.net/demos.txt",
"http://kreedz.pri.ee/demos.txt",
"http://climbers.cpms.ru/records.txt",
"http://kzsk.sk/demos/demos.txt",
"http://kz-scandinavia.com/demos_no.txt",
"http://kz-scandinavia.com/demos_se.txt",
"http://kz-scandinavia.com/demos_dk.txt",
"http://bulgarian-kreedz.net/demos.txt",
"http://romanian-jumpers.com/demos.txt",
"http://bra-records.vndv.com/demos.txt",
"http://kzpl.kampno.pl/demos.txt"
};
new g_RecordsFileSuffix[MAX][] =
{
"xj",
"cg",
"fr",
"ee",
"ru",
"sk",
"no",
"se",
"dk",
"bg",
"ro",
"br",
"pl"
};
new g_Skip[][] =
{
"Xtreme-Jumps.eu ",
"Climbers-Germany Record Script v2.0",
"FOR KZFR BY REMYY",
"http://kreedz.pri.ee #KZ.ee",
"",
"",
"",
"",
"",
"",
"",
"Romanian-Jumpers.com & #KZRO @ Quakenet",
"Brazilian Records",
"KZPL Records"
};
new g_flRecordsFile[MAX][256];
new g_iColors[3] = { 255, 0, 255 };
new Float:g_fShowtime = 5.0;
new Float:g_fCoords[2] = { 0.01, 0.2 };
public plugin_init( )
{
register_plugin( PLUGIN, VERSION, AUTHOR );
register_clcmd( "say", "hookSay" );
register_concmd( "kz_records_coords", "cmdChangeShowtime" );
register_concmd( "kz_records_coords", "cmdChangeCoords" );
register_concmd( "kz_records_color", "cmdChangeColor" );
}
public plugin_cfg( )
{
new temp[256];
get_localinfo( "amxx_datadir", temp, 255 );
format( temp, 255, "%s/kz_records", temp );
if( !dir_exists( temp ) )
{
mkdir( temp );
}
for( new i ; i < MAX ; i++ )
{
format( g_flRecordsFile[i], 255, "%s/demos_%s.txt", temp, g_RecordsFileSuffix[i] );
}
format( temp, 255, "%s/last_update.ini", temp );
if( !file_exists( temp ) )
{
fnUpdate( );
return PLUGIN_CONTINUE;
}
new year, month, day;
date( year, month, day );
new f = fopen( temp, "rt" );
fgets( f, temp, 255 );
fclose( f );
if( str_to_num( temp[0] ) > year || str_to_num( temp[5] ) > month || str_to_num( temp[8] ) > day )
{
fnUpdate( );
return PLUGIN_CONTINUE;
}
return PLUGIN_CONTINUE;
}
public hookSay( plr )
{
static msg[512], cmd[32], map[32];
read_args( cmd, 31 );
remove_quotes( cmd );
if( !cmd[0] || strlen( cmd ) != 3 )
{
return PLUGIN_CONTINUE;
}
for( new i ; i < MAX ; i++ )
{
for( new j ; j < SAY ; j++ )
{
if( !equali( cmd, g_SayCommands[i][j], 3 ) )
{
continue;
}
static author[EXT][32], kztime[8], extension[EXT][8], len, founds;
if( cmd[4] )
{
founds = get_record_data( i, cmd[4], author, kztime, extension );
len = format( msg, 511, "%s Record of %s:", g_CountryAdjective[i], cmd[4] );
}
else
{
get_mapname( map, 31 );
founds = get_record_data( i, map, author, kztime, extension );
len = format( msg, 511, "%s Record of %s:", g_CountryAdjective[i], map );
}
if( author[0][0] )
{
for( new x ; x < founds ; x++ )
{
if( !author[x][0] )
{
break;
}
if( extension[x][0] )
{
len += format( msg[len], 511 - len, "^n [%s] %s (%i:%02i) ", extension[x], author[x], ( kztime[x] / 60 ), ( kztime[x] % 60 ) );
}
else
{
len += format( msg[len], 511 - len, "^n %s (%i:%02i) ", author[x], ( kztime[x] / 60 ), ( kztime[x] % 60 ) );
}
}
}
else
{
len += format( msg[len], 511 - len, "^n N/A (**:**)" );
}
set_hudmessage( g_iColors[0], g_iColors[1], g_iColors[2], g_fCoords[0], g_fCoords[1], _, _, g_fShowtime, _, _, -1 );
show_hudmessage( plr, msg );
return PLUGIN_HANDLED;
}
}
return PLUGIN_CONTINUE;
}
public get_record_data( i, map[], author[][32], kztime[8], extension[][8] )
{
static data[256], _map[64], _kztime[8], f;
new founds, len;
f = fopen( g_flRecordsFile[i], "rt" );
while( !feof( f ) )
{
fgets( f, data, 255 );
if( equali( data, g_Skip[i] ) )
{
continue;
}
if( !equali( data, map, strlen( map ) ) )
{
continue;
}
len += 1 + copyc( _map, 63, data[len], ' ' );
len += 1 + copyc( _kztime, 7, data[len], ' ' );
kztime[founds] = str_to_num( _kztime );
copy( author[founds], 32, data[len] );
replace( author[founds], 31, "^n", "" );
if( containi( _map, "[" ) && containi( _map, "]" ) )
{
for( new i ; i < strlen( _map ) ; i++ )
{
if( !equali( _map[i], "[", 1 ) )
{
continue;
}
len = i + 1;
copyc( extension[founds], 8, _map[len], ']' );
break;
}
}
founds++;
}
fclose( f );
return founds;
}
public fnUpdate( )
{
for( new i ; i < MAX ; i++ )
{
download( g_DownloadLink[i], g_flRecordsFile[i] );
}
new temp[256];
get_localinfo( "amxx_datadir", temp, 255 );
format( temp, 255, "%s/kz_records/last_update.ini", temp );
new year, month, day;
date( year, month, day );
if( file_exists( temp ) )
{
delete_file( temp );
}
new f = fopen( temp, "wt" );
format( temp, 255, "%04ix%02ix%02i", year, month, day );
fputs( f, temp );
fclose( f );
}
public cmdChangeShowTime( plr )
{
if( !( get_user_flags( plr ) & ADMIN_FLAG ) )
{
client_print( plr, print_console, "* You have no access to this command" );
return PLUGIN_HANDLED;
}
if( read_argc( ) != 2 )
{
client_print( plr, print_console, "Usage: kz_godmode_showtime <time>" );
return PLUGIN_HANDLED;
}
new showtime[32];
read_argv( 1, showtime, 31 );
g_fShowtime = floatclamp( str_to_float( showtime ), 0.0, 1000000.0 );
client_print( plr, print_console, "kz_godmode_showtime changed to ^"%f^"", g_fShowtime );
return PLUGIN_HANDLED;
}
public cmdChangeCoords( plr )
{
if( !( get_user_flags( plr ) & ADMIN_FLAG ) )
{
client_print( plr, print_console, "* You have no access to this command" );
return PLUGIN_HANDLED;
}
if( read_argc( ) != 3 )
{
client_print( plr, print_console, "Usage: kz_records_coords <x> <y>" );
return PLUGIN_HANDLED;
}
new x_str[6], y_str[6];
read_argv( 1, x_str, 5 );
read_argv( 2, y_str, 5 );
g_fCoords[0] = floatclamp( str_to_float( x_str ), -1.0, 1.0 );
g_fCoords[1] = floatclamp( str_to_float( y_str ), -1.0, 1.0 );
client_print( plr, print_console, "kz_records_coords changed to ^"%f %f^"", g_fCoords[0], g_fCoords[1] );
return PLUGIN_HANDLED;
}
public cmdChangeColor( plr )
{
if( !( get_user_flags( plr ) & ADMIN_FLAG ) )
{
client_print( plr, print_console, "* You have no access to this command" );
return PLUGIN_HANDLED;
}
if( read_argc( ) != 4 )
{
client_print( plr, print_console, "Usage: kz_records_color <red> <green> <blue>" );
return PLUGIN_HANDLED;
}
new r_str[4], g_str[4], b_str[4];
read_argv( 1, r_str, 3 );
read_argv( 2, g_str, 3 );
read_argv( 3, b_str, 3 );
g_iColors[0] = clamp( str_to_num( r_str ), 0, 255 );
g_iColors[1] = clamp( str_to_num( g_str ), 0, 255 );
g_iColors[2] = clamp( str_to_num( b_str ), 0, 255 );
client_print( plr, print_console, "kz_records_color changed to ^"%i %i %i^"", g_iColors[0], g_iColors[1], g_iColors[2] );
return PLUGIN_HANDLED;
}
httpdl.sma:
Code:
/**
*
* (c)2007, Bentski
* Homepage: http://kzlt.bentski.lt/
* Server: cs.bentski.lt:27015
*
* HTTP downloader. Allows to download files from the web.
*
*/
#include <amxmodx>
#include <sockets>
#include <httpdl>
new dlinfo[MAX_DOWNLOADS][5];
new dlpath[MAX_DOWNLOADS][2][256];
new dlfirstpack[MAX_DOWNLOADS][DOWNLOAD_SPEED_IN_MS];
new dlfirstpack_len[MAX_DOWNLOADS];
new dltimeout[MAX_DOWNLOADS];
new ndownloading;
new fwd_dlcomplete, fwd_result;
public plugin_init()
{
register_plugin("HTTP Download", "1.0", "Bentski & Numb");
fwd_dlcomplete = CreateMultiForward("dlcomplete", ET_IGNORE, FP_CELL, FP_STRING, FP_STRING, FP_CELL);
}
public plugin_natives()
{
register_library("httpdl");
register_native("download", "native_download", 1);
}
public native_download(url[], path[])
{
if( equali(url, "http://") )
{
server_print("Invalid download link - no link at all (^"http://^")");
return 0;
}
new slot;
while( slot<=MAX_DOWNLOADS && dlinfo[slot][0]!=0 )
slot++;
if( slot==MAX_DOWNLOADS )
{
server_print("Download limit reached (%d)", MAX_DOWNLOADS);
return 0;
}
param_convert(1);
param_convert(2);
new u[256], p[256], len;
if( equali(url, "http://", 7) )
len = copy(u, 248, url[7]);
else
len = copy(u, 255, url);
new pos = contain(u, "/");
if( pos==(len-1) )
{
u[pos] = 0;
p[0] = 0;
}
else if( pos!=-1 )
{
copy(p, 255, u[pos+1]);
u[pos] = 0;
}
new error;
new socket = dlinfo[slot][2] = socket_open(u, 80, SOCKET_TCP, error);
switch(error)
{
case 0:
{
new buffer[512];
formatex(buffer, 511, "GET /%s HTTP/1.1^r^nHost: %s^r^n^r^n", p, u);
dlinfo[slot][4] = -1;
dlfirstpack_len[slot] = 0;
socket_send(socket, buffer, 512);
copy(dlpath[slot][0], 255, path);
copy(dlpath[slot][1], 255, url);
formatex(buffer, 511, "%s.downloading", path);
if( file_exists(buffer) )
delete_file(buffer);
if( !(dlinfo[slot][3]=fopen(buffer, "wb")) )
{
socket_close(socket);
server_print("[HTTP] Error writing file ^"%s^"", buffer);
return 0;
}
dlinfo[slot][0] = 1;
ndownloading++;
if( ndownloading==1 )
set_task(0.1, "download_task", (MAX_DOWNLOADS+1), _, _, "b");
static dlid;
dlid++;
dlinfo[slot][1] = dlid;
dltimeout[slot] = 0;
return dlinfo[slot][1];
}
case 1: server_print("[HTTP] Error creating socket");
case 2: server_print("[HTTP] Could not resolve hostname");
case 3: server_print("[HTTP] Could not connect to ^"%s:80^"", u);
}
return 0;
}
public download_task()
{
static buffer[DOWNLOAD_SPEED_IN_MS];
static socket, f, len, byte_to_write, pos;
for( new i; i<MAX_DOWNLOADS; i++ )
{
if( dlinfo[i][0]<1 )
continue;
socket = dlinfo[i][2];
f = dlinfo[i][3];
if( socket_change(socket) )
{
if( (len=socket_recv(socket, buffer, DOWNLOAD_SPEED_IN_MS))<1 ) // this is wierd, but ah...
{
if( dltimeout[i]++<=DOWNLOAD_TIMEOUT_IN_MS )
continue;
}
else
{
if( len==DOWNLOAD_SPEED_IN_MS )
server_print("[HTTP] File ^"%s^" can contain errors - your speed is higher than %dbytes/second", dlpath[i][0], (DOWNLOAD_SPEED_IN_MS*10));
dltimeout[i] = 0;
if( dlinfo[i][4]==-1 )
{
if( DOWNLOAD_SPEED_IN_MS<=dlfirstpack_len[i] )
{
dlfirstpack[i][0] = dlfirstpack[i][dlfirstpack_len[i]-3];
dlfirstpack[i][1] = dlfirstpack[i][dlfirstpack_len[i]-2];
dlfirstpack[i][2] = dlfirstpack[i][dlfirstpack_len[i]-1];
dlfirstpack[i][3] = 0;
dlfirstpack_len[i] = 3;
}
copy(dlfirstpack[i][dlfirstpack_len[i]], (DOWNLOAD_SPEED_IN_MS-dlfirstpack_len[i]), buffer);
pos = contain(dlfirstpack[i], "^r^n^r^n");
if( pos!=-1 )
{
byte_to_write = (pos+4-dlfirstpack_len[i]);
for( dlinfo[i][4]=(len-byte_to_write); byte_to_write<len; byte_to_write++ )
fputc(f, buffer[byte_to_write]);
}
else
dlfirstpack_len[i] = strlen(dlfirstpack[i]);
continue;
}
dlinfo[i][4] += len;
//fputs(f, buffer);
for( byte_to_write=0; byte_to_write<len; byte_to_write++ )
fputc(f, buffer[byte_to_write]);
continue;
}
}
else if( dltimeout[i]++<=DOWNLOAD_TIMEOUT_IN_MS )
continue;
fclose(f);
set_task(0.1, "dl_rename", i);
dlinfo[i][0] = -1;
ndownloading--;
if( ndownloading==0 )
remove_task((MAX_DOWNLOADS+1));
socket_close(socket);
}
}
public dl_rename(dl_id)
{
if( file_exists(dlpath[dl_id][0]) )
delete_file(dlpath[dl_id][0]);
new buffer[512];
formatex(buffer, 511, "%s.downloading", dlpath[dl_id][0]);
if( rename_file(buffer, dlpath[dl_id][0], 1) )
copy(buffer, 511, dlpath[dl_id][0]);
dlinfo[dl_id][0] = 0;
ExecuteForward(fwd_dlcomplete, fwd_result, dlinfo[dl_id][1], buffer, dlpath[dl_id][1], dlinfo[dl_id][4]);
}
httpdl.inc:
Code:
/**
*
* (c)2007, Bentski
* Homepage: http://kzlt.bentski.lt/
* Server: cs.bentski.lt:27015
*
* HTTP downloader. Allows to download files from the web.
*
*/
#if defined _httpdl_included
#endinput
#endif
#define _httpdl_included
#pragma library httpdl
#define MAX_DOWNLOADS 32
#define DOWNLOAD_TIMEOUT_IN_MS 10 // 1sec = 10
#define DOWNLOAD_SPEED_IN_MS 104857 // 1024 = 10kb/s
/* Forwards */
// Called when download is finished
// * id - download id
// * file - path + filename of downloaded file
forward dlcomplete(id, file[], url[], bytes_downloaded);
/* Natives */
// Downloads a file
// Returns download id or 0 if something failed
// * url - address of remote file (eg. "http://bentski.lt/something.zip")
// * dlpath - where to place downloaded file (eg. "addons/amxmodx/data/something.zip")
native download(url[], dlpath[]);
readme.txt:
Code:
KZ Records
Description
A small plugin to get the current worldrecord or a specific countryrecord.
This plugin will automatically update the required files once per day (on the first mapchange after midnight).
Requirements
None
Commands - Key ( <...> = parameter | [...] = optional )
kz_records_showtime <time> - manages how long the message should be shown in seconds
kz_records_coords <x> <y> - changes the position on screen on which the hudmessage is shown
kz_records_color <r> <g> <b> - changes the color of the hudmessage
say /wr - shows the worldrecord of the current map
say /wr [mapname] - shows the worldrecord of kz_cliffez
other provided commands: /xj, /cg, /de, /fr, /ee, /ru, /sk, /no, /se, / dk, /bg, /ro, /br
Changelog - Key ( + added | - removed | c changed | f fixed )
08/19/2008 - v1.5
+: added new countrys
11/07/2008 - v1.6
+: added another country
c: manual updating is not required anymore
c: changed the url to the french record file
f: fixed a bug which made messages like '/noclip' show the norwegian record
-: removed 'kz_records_update'
11/15/2008 - v1.6b
c: optimized the plugin a bit
Credits
eMTi - Because I love him and he provides me with some webspace on his ftp <3
Bentski - For releasing httpdl.amxx
oO3ddyOo - Forced TROUbl3m4ker to create a small script for the german demos.txt :)
NumB - For finding a fix for the old httpdl.amxx
|