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

Annotation of /wr.sma

Parent Directory Parent Directory | Revision Log Revision Log


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

Contact
ViewVC Help
Powered by ViewVC 1.0.4