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

Annotation of /wr.sma

Parent Directory Parent Directory | Revision Log Revision Log


Revision 13 - (view) (download)

1 : ian 9 /*
2 :     * 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!
3 :     * 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!
4 :     * I know the code is crappy but it does what i should do, doesnt it? :P
5 :     */
6 :    
7 :     #include <amxmodx>
8 :     #include <amxmisc>
9 :     #include <sockets>
10 :    
11 :     #define SCRIPT_NAME "/demos.txt"
12 :     #define REMOTE_HOST "xtreme-jumps.eu" //port d.80
13 :    
14 :     #define LOCAL_FILE "demos.txt" //saved to /configs/
15 :    
16 :     new g_sckweb //socket "id"
17 :     new timeout
18 :     new dir[128]
19 :     new bool:write_now
20 :     new bool:file_open
21 :     new file_handler
22 :    
23 :     new wr[256]
24 :    
25 : ian 13 new SVC_SAYTEXT
26 :    
27 : ian 9 public plugin_init() {
28 :     register_plugin("WR_demos.txt_autoupdate", "2.0" ,"SchlumPF*")
29 :     set_task(5.0,"connect_web")
30 :    
31 :     register_clcmd("say /wr","show_wr")
32 :     register_clcmd("say /worldrecord","show_wr")
33 :    
34 :     get_configsdir(dir,127)
35 :     format(dir,127,"%s/%s",dir,LOCAL_FILE)
36 : ian 13
37 :     SVC_SAYTEXT = get_user_msgid( "SayText" )
38 : ian 9 }
39 :    
40 :     public connect_web() {
41 :     new error = 0
42 :     new constring[512]
43 :    
44 :     g_sckweb = socket_open(REMOTE_HOST, 80, SOCKET_TCP, error)
45 :     if (g_sckweb > 0) {
46 :     format(constring,511,"GET %s HTTP/1.1^nHost: %s^n^n",SCRIPT_NAME,REMOTE_HOST)
47 :     write_web(constring)
48 :     read_web()
49 :     } else {
50 :     switch (error) {
51 :     case 1: { server_print("Error creating socket"); }
52 :     case 2: { server_print("Error resolving remote hostname"); }
53 :     case 3: { server_print("Error connecting socket"); }
54 :     }
55 :     }
56 :     return PLUGIN_CONTINUE
57 :     }
58 :    
59 :     public read_web() {
60 :     new buf[512]
61 :     if (socket_change(g_sckweb, 100)) {
62 :     timeout=0
63 :     socket_recv(g_sckweb, buf, 511)
64 :     if (!write_now) { //search first data to cut header infos
65 :     new search = strfind(buf,"Xtreme-Jumps.eu",0,0)
66 :     if(search != -1) {
67 :     copy(buf,511,buf[search])
68 :     write_now=true
69 :     }
70 :     }
71 :     if(write_now) {
72 :     if(!file_open) {
73 :     file_handler=fopen(dir,"w+")
74 :     file_open=true
75 :     }
76 :     if(file_open)
77 :     fputs(file_handler,buf)
78 :     }
79 :     } else {
80 :     timeout++
81 :     }
82 :     if (timeout >= 5)
83 :     disconnect_web()
84 :     else
85 :     set_task(0.1, "read_web")
86 :     return PLUGIN_CONTINUE
87 :     }
88 :    
89 :     public write_web(text[512]) {
90 :     socket_send(g_sckweb, text, 511)
91 :     }
92 :    
93 :     public disconnect_web() {
94 :     if(!write_now) {
95 :     log_amx("Error getting HTTP data")
96 :     }
97 :     if (file_open)
98 :     fclose(file_handler)
99 :     socket_close(g_sckweb)
100 :    
101 :     get_wr()
102 :    
103 :     return PLUGIN_HANDLED
104 :     }
105 :    
106 :     public get_wr() {
107 :     if (file_exists(dir) == 1) {
108 :     new line, stxtsize
109 :     new data[64]
110 :     new cMap[32]
111 :     get_mapname(cMap, 31)
112 :     new MapName[32], jumper[32], t[16], tnum = 0, len, pMap[32], ext[16]
113 :    
114 :     while ((line = read_file(dir,line,data,63,stxtsize)) != 0)
115 :     {
116 :     parse(data, MapName, 31, t, 15, jumper, 31)
117 :     if (containi(MapName, "[") != -1) {
118 :     replace(MapName, 31, "[", " ")
119 :     replace(MapName, 31, "]", " ")
120 :     parse(MapName, pMap, 31, ext, 15)
121 :     MapName = pMap
122 :     } else
123 :     ext= ""
124 :     if (equal(MapName, cMap)) {
125 :     if (!tnum) {
126 :     tnum = str_to_num(t)
127 : ian 13 //len = format(wr, 255, "World Record:^n Map: %s^n Author: %s (%d:%02d) %s", cMap, jumper, tnum/60, tnum%60, ext)
128 :     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)
129 : ian 9 } else {
130 :     tnum = str_to_num(t)
131 : ian 13 //len += format(wr[len], 255-len, "^n %s (%d:%02d) %s", jumper, tnum/60, tnum%60, ext)
132 :     len += format(wr[len], 255-len, "^x03%s (%d:%02d) %s", jumper, tnum/60, tnum%60, ext)
133 : ian 9 }
134 :     }
135 :     }
136 :     if (!tnum)
137 :     format(wr, 255, "World Record:^n Map: %s^n Author: N/A", cMap)
138 :     }
139 :     else
140 :     wr = "Failed to load database!"
141 :    
142 :     return PLUGIN_CONTINUE
143 :     }
144 :    
145 :     public show_wr(id) {
146 : ian 13 message_begin( MSG_ALL, SVC_SAYTEXT, _, id)
147 :     write_byte( id )
148 :     write_string( wr )
149 :     message_end()
150 :    
151 :     return PLUGIN_CONTINUE
152 :     }

Contact
ViewVC Help
Powered by ViewVC 1.0.4