|
Joined: Aug 2005
Posts: 32
Ameglian cow
|
OP
Ameglian cow
Joined: Aug 2005
Posts: 32 |
Hello, i'm a n00b to this programming language! :tongue: I mainly program in PHP. I can create a PHP script that can get data from a mySQL database on request and display it for an IRC bot to read the data from. I was wondering how can i get the IRC bot to goto an address like http://localhost:6080/s3h/getdetails.php?requestedusernamerequestedusername is what the IRC user who puts in !data requestedusername has specified as a user. If that makes sense, i can program the PHP code to display the data in Tables or just a list on a simple page and it will display something like this: Username Details: requestedusername Generated: <<TIME>> Invisibility Shields: xxx Black Powder Missiles: xxx e.t.c. the weapons keep going on (there is around 36 from memory) But how would i get the "xxx" details from it to display what weapons of each type have been damaged? :P If that makes sense, all i need to know is how to get data from a page, and what would be the best way to setout the page! xD
|
|
|
|
Joined: Dec 2002
Posts: 3,547
Hoopy frood
|
Hoopy frood
Joined: Dec 2002
Posts: 3,547 |
I have no idea if this works dude, don't have the files and such. So, you'll have to test it and come back with any results..
alias lh {
%un = $$1
sockopen lh localhost 6080
}
on *:sockopen:lh: {
sockwrite -n $sockname GET $+(/s3h/getdetails.php?,%un) HTTP/1.1
sockwrite -n $sockname Host: $+(localhost,$crlf,$crlf)
}
on 1:sockread:lh: {
if ($sockerr > 0) return
:nextread
sockread %lh
if ($sockbr == 0) return
if (%lh == $null) %lh = -
if (Generated* iswm %lh) return
if (: isin %lh) echo -a $gettok(%lh,2,58)
goto nextread
}
-Andy
|
|
|
|
Joined: Sep 2004
Posts: 200
Fjord artisan
|
Fjord artisan
Joined: Sep 2004
Posts: 200 |
/help sockets thats about all you need, also http headers for firefox is usefull as well, to see what firefox sent the server (the webpage) it.
|
|
|
|
Joined: Aug 2005
Posts: 32
Ameglian cow
|
OP
Ameglian cow
Joined: Aug 2005
Posts: 32 |
I have modified the coding a little, basically just the URL of: alias lh {
%un = $$1
sockopen lh localhost 6080
}
on *:sockopen:lh: {
sockwrite -n $sockname GET $+(/s3h/getdetails.php?name=,%un) HTTP/1.1
sockwrite -n $sockname Host: $+(localhost,$crlf,$crlf)
}
on 1:sockread:lh: {
if ($sockerr > 0) return
:nextread
sockread %lh
if ($sockbr == 0) return
if (%lh == $null) %lh = -
if (Generated* iswm %lh) return
if (: isin %lh) echo -a $gettok(%lh,2,58)
goto nextread
} I have made the file that outputs the data like this (if you look at the source code, if you view it with IE or a browser it's just 1 continous line: --- Sabotage Details of rshield --- Blackpowder Missiles: 0, Invisibility Shields: 0 Excaliburs: 0, Battle Axes: 0, Dragons: 0, Flaming Arrows: 0, Dragonskins: 0 Steeds: 0, Hammers of Thor: 0, Wargs: 0 Mithrils: 0, Gauntlets: 0, Heavy Shields: 0, Elven Cloaks: 0 Broadswords: 0, Warhammers: 0, Warblades: 0, Steel Bows: 0, Plate Armors: 0 Lances: 0, Maces: 0, Spears: 0, Longbows: 0, Chainmails: 0 Long Sword: 0, Pikes: 1, Clubs: 0, Crossbows: 0, Shields: 0 Staves: 0, Hatchets: 0, Slings: 0, Short Bows: 0 Helmets: 0, Knives: , Sticks: 0 --- Powered By Hawk Works --- Now i'm a total n00b and i'd like to test it straight away! :P I've been Working on Hawk Works for ages. So how would i get the code above to react on !sabdetails <<requestedname>> then it goes to http://localhost:6080/s3h/getdetails.php?name=<<requestedname>> then gets the details and messages it back to the Channel Window? I don't really care if the script grabs the data straight away and messages it or if it saves the data to a text file somewhere and then opens the file, reading line by line the message and sending it! :P If you have no idea how to do the above, how would you grab data from a text file and read it line by line and messaging it? Because if i open a socket connection with that page and then get the PHP script to write it to a file it might be easier coding.
|
|
|
|
Joined: Aug 2005
Posts: 32
Ameglian cow
|
OP
Ameglian cow
Joined: Aug 2005
Posts: 32 |
Since i can't edit my last post here is what i've gotten up to: on *:text:!sabdetails*:* {
%un = $2
/sockopen bot http://localhost:6080 6080
}
on *:sockopen:bot: {
sockwrite -n $sockname GET /s3h/getdetails.php?name=,%un
sockwrite -n $sockname Host: http://localhost:6080
sockwrite -n $sockname User-Agent: $version
sockwrite -n $sockname $crlf
}
on 1:sockread:bot: {
if ($sockerr > 0) return
:nextread
sockread %bot
if ($sockbr == 0) return
if (%bot == $null) %bot = -
if (Generated* iswm %bot) return
if (: isin %bot) echo -a $gettok(%bot,2,58)
goto nextread
} But it doesn't work, yet it doesn't return any errors! When a user puts in !sabdetails rshield for example! Can i get some help please? BTW the PHP script is outputting the data just like a notepad file with new lines in each, just if loaded in Internet Explorer, it comes up as one line.
|
|
|
|
Joined: Apr 2003
Posts: 701
Hoopy frood
|
Hoopy frood
Joined: Apr 2003
Posts: 701 |
Don't edit your previous post, about everything you changed since then is wrong... red = wrong, green = good, blue = comment on *:text:!sabdetails*:* {
%un = [color:green]$2[/color]
[color:red]/[/color]sockopen bot [color:red]http://localhost:6080[/color] 6080
[color:blue]; above is not an ip or named address, it's a HTTP request
;the slash isn't needed in a script[/color]
}
on *:sockopen:bot: {
sockwrite -n $sockname GET [color:red]/s3h/getdetails.php?name=,%un [/color]
[color:blue]; The previous snippet appended the contents of %un using $+, this code
; really sends that url, %un will just be percent u n[/color]
sockwrite -n $sockname Host: [color:red]http://localhost:6080 [/color]
[color:blue]; again, this is not a host, it's a http request[/color]
[color:red]sockwrite -n $sockname User-Agent: $version[/color]
[color:blue]; not needed[/color]
sockwrite -n $sockname [color:red]$crlf [/color]
[color:blue]; you really need 2 $crlf's right after another, only one means
; the server will wait a few seconds/minutes for the end of the request that is never sent[/color]
}
[color:blue]; rest omitted[/color]
|
|
|
|
Joined: Aug 2005
Posts: 32
Ameglian cow
|
OP
Ameglian cow
Joined: Aug 2005
Posts: 32 |
OK here is what i've got fixing the errors and stuff: on *:text:!sabdetails*:* {
%un = $2
sockopen bot 192.168.1.2 6080
}
on *:sockopen:bot: {
sockwrite -n $sockname GET $+(/s3h/getdetails.php?name=,%un)
sockwrite -n $sockname Host: $+(192.168.1.2,$crlf,$crlf)
}
on 1:sockread:bot: {
if ($sockerr > 0) return
:nextread
sockread %bot
if ($sockbr == 0) return
if (%bot == $null) %bot = -
if (Generated* iswm %bot) return
if (: isin %bot) echo -a $gettok(%bot,2,58)
goto nextread
} Just a question, is that going to the url http://192.168.1.2:6080/s3h/getdetails.php?name=%unWhere $un is the second word after !sabdetails ? My web server only runs on port 6080 because port 80 is blocked by my ISP to stop hacking attempts. Anyway, here is what i did in another IRC window: [11:19:54] *** Initial topic: [11:19:54] *** #alien: r_alien- ~alien- [11:19:58] alien-: r_alien- has just arrived! r_alien- is the Owner of this bot. [11:19:58] *** Mode change "+v r_alien-" for channel #alien by alien-. [11:20:00] *** #alien was created on Sun Sep 04 01:03:27 2005. [11:20:39] r_alien-: !shutdown [11:20:56] *** alien- has joined #alien. [11:20:58] *** Mode change "+qo alien- alien-" for channel #alien by ChanServ. [11:22:28] r_alien-: !sabdetails rshield [11:30:06] r_alien-: !shutdown [11:30:07] *** alien- has signed off IRC (Quit: Alien IRC Bot 1.0 based on YBBot> You cannot get this bot May i interest you in Hawk Works instead at http://220.237.150.18:6080/s3h/).[11:30:19] *** alien- has joined #alien. [11:30:21] *** Mode change "+qo alien- alien-" for channel #alien by ChanServ. [11:31:02] r_alien-: !sabdetails rshield When i typed the !shutdown commands the bot exits and i save the code and reload mIRC. Anway, i typed !sabdetails rshield and nothing comes up! Nothing in the window, and nothing in the mIRC connection window saying there is an error! >.< I programmed the PHP script to write to a log file just quickly to tell me when it ran, i typed the !sabdetails rshield command again, and nothing showed up in the log, which means that the PHP file wasn't executed! The log file would have recieved an extra line even if the name= parameter wasn't filled!
|
|
|
|
Joined: Dec 2002
Posts: 1,245
Hoopy frood
|
Hoopy frood
Joined: Dec 2002
Posts: 1,245 |
we cannot connect to your server to test this but you might change the sockread to be more "generic" so that you are only changing one thing at a time
on 1:sockread:bot: {
if ($sockerr > 0) return
:nextread
sockread %bot
if ($sockbr == 0) return
if (%bot == $null) %bot = -
echo -a %bot
goto nextread
}
when you have that working then you can tweak the output with a $remove() or whatever
|
|
|
|
Joined: Dec 2002
Posts: 1,245
Hoopy frood
|
Hoopy frood
Joined: Dec 2002
Posts: 1,245 |
alias bot sockopen bot 220.237.150.18 6080
on *:sockopen:bot: {
sockwrite -n bot GET http://220.237.150.18:6080/s3h/getdetails.php?name=rshield
}
on 1:sockread:bot: {
if ($sockerr > 0) return
:nextread
sockread %bot
if ($sockbr == 0) return
if (%bot == $null) %bot = -
echo -a %bot
goto nextread
}
I used the above and connected, here is the output: [quote] --- Sabotage Details of rshield --- Blackpowder Missiles: 0, Invisibility Shields: 0 Excaliburs: 0, Battle Axes: 0, Dragons: 0, Flaming Arrows: 0, Dragonskins: 0 Steeds: 0, Hammers of Thor: 0, Wargs: 0 Mithrils: 0, Gauntlets: 0, Heavy Shields: 0, Elven Cloaks: 0 Broadswords: 0, Warhammers: 0, Warblades: 0, Steel Bows: 0, Plate Armors: 0 Lances: 0, Maces: 0, Spears: 0, Longbows: 0, Chainmails: 0 Long Sword: 0, Pikes: 1, Clubs: 0, Crossbows: 0, Shields: 0 Staves: 0, Hatchets: 0, Slings: 0, Short Bows: 0 Helmets: 0, Knives: 0, Sticks: 0 [quote]
|
|
|
|
Joined: Aug 2005
Posts: 32
Ameglian cow
|
OP
Ameglian cow
Joined: Aug 2005
Posts: 32 |
I put your code in so it looks like this and still no message popped up in the window. on *:text:!sabdetails*:* {
%un = $2
sockopen bot 220.237.150.18 6080
}
;on *:sockopen:bot: {
; sockwrite -n $sockname GET $+(/s3h/getdetails.php?name=,%un)
; sockwrite -n $sockname Host: $+(192.168.1.2,$crlf,$crlf)
;}
alias bot sockopen bot 220.237.150.18 6080
on *:sockopen:bot: {
sockwrite -n bot GET http://220.237.150.18:6080/s3h/getdetails.php?name=rshield
}
on 1:sockread:bot: {
if ($sockerr > 0) return
:nextread
sockread %bot
if ($sockbr == 0) return
if (%bot == $null) %bot = -
echo -a %bot
goto nextread
}
} Just two questions here, how can i get !sabdetails <<a username>> to trigger it and then the URL is http://220.237.150.18:6080/s3h/getdetails.php?name=<<a username>> Well that link is for you anyway, i'll change the IP address to internal IP's later. And why doesn't my above code work! *cries*
Last edited by r_alien; 04/09/05 03:06 AM.
|
|
|
|
Joined: Dec 2002
Posts: 1,245
Hoopy frood
|
Hoopy frood
Joined: Dec 2002
Posts: 1,245 |
on *:text:!sabdetails*:*: { %un = $2 sockopen bot 220.237.150.18 6080 }
you left off a :
|
|
|
|
Joined: Dec 2002
Posts: 1,245
Hoopy frood
|
Hoopy frood
Joined: Dec 2002
Posts: 1,245 |
here is what I just tested
on *:text:!sabdetails*:*: {
set %un $2
set %chan $chan
sockopen bot 220.237.150.18 6080
}
alias bot sockopen bot 220.237.150.18 6080
on *:sockopen:bot: {
sockwrite -n bot GET http://220.237.150.18:6080/s3h/getdetails.php?name= $+ %un
}
on 1:sockread:bot: {
if ($sockerr > 0) return
:nextread
sockread %bot
if ($sockbr == 0) return
if (%bot == $null) %bot = -
msg %chan %bot
goto nextread
}
and the channel output <buzz44> !sabdetails rshield <MikeChat> --- Sabotage Details of rshield --- <MikeChat> Blackpowder Missiles: 0, Invisibility Shields: 0 <MikeChat> Excaliburs: 0, Battle Axes: 0, Dragons: 0, Flaming Arrows: 0, Dragonskins: 0 <MikeChat> Steeds: 0, Hammers of Thor: 0, Wargs: 0 <MikeChat> Mithrils: 0, Gauntlets: 0, Heavy Shields: 0, Elven Cloaks: 0 <MikeChat> Broadswords: 0, Warhammers: 0, Warblades: 0, Steel Bows: 0, Plate Armors: 0 <MikeChat> Lances: 0, Maces: 0, Spears: 0, Longbows: 0, Chainmails: 0 <MikeChat> Long Sword: 0, Pikes: 1, Clubs: 0, Crossbows: 0, Shields: 0 <MikeChat> Staves: 0, Hatchets: 0, Slings: 0, Short Bows: 0 <MikeChat> Helmets: 0, Knives: 0, Sticks: 0
|
|
|
|
Joined: Aug 2005
Posts: 32
Ameglian cow
|
OP
Ameglian cow
Joined: Aug 2005
Posts: 32 |
I still have nothing! on *:text:!sabdetails*:*: {
%un = $2
sockopen bot 192.168.1.2 6080
}
;on *:sockopen:bot: {
; sockwrite -n $sockname GET $+(/s3h/getdetails.php?name=,%un)
; sockwrite -n $sockname Host: $+(192.168.1.2,$crlf,$crlf)
;}
alias bot sockopen bot 192.168.1.2 6080
on *:sockopen:bot: {
sockwrite -n bot GET http://192.168.1.2:6080/s3h/getdetails.php?name=rshield
}
on 1:sockread:bot: {
if ($sockerr > 0) return
:nextread
sockread %bot
if ($sockbr == 0) return
if (%bot == $null) %bot = -
echo -a %bot
goto nextread
} Thats my code! xD [13:30:54] *** alien- has joined #alien. [13:30:56] *** Mode change "+qo alien- alien-" for channel #alien by ChanServ. [13:31:01] r_alien-: !sabdetails [13:31:17] r_alien-: !sabdetails rshield Still nothing
|
|
|
|
Joined: Dec 2002
Posts: 1,245
Hoopy frood
|
Hoopy frood
Joined: Dec 2002
Posts: 1,245 |
change to this:
on *:text:!sabdetails*:*: {
[color:red]set %un $2[/color]
sockopen bot 192.168.1.2 6080
}
[color:blue]
remove this completely
;on *:sockopen:bot: {
; sockwrite -n $sockname GET $+(/s3h/getdetails.php?name=,%un)
; sockwrite -n $sockname Host: $+(192.168.1.2,$crlf,$crlf)
;} [/color]
also change the next red part
on *:sockopen:bot: {
sockwrite -n bot GET http://192.168.1.2:6080/s3h/getdetails.php?name=[color:red] $+ %un [/color]
}
on 1:sockread:bot: {
if ($sockerr > 0) return
:nextread
sockread %bot
if ($sockbr == 0) return
if (%bot == $null) %bot = -
echo -a %bot
goto nextread
}
|
|
|
|
Joined: Aug 2005
Posts: 32
Ameglian cow
|
OP
Ameglian cow
Joined: Aug 2005
Posts: 32 |
Ok i changed the code to: on *:text:!sabdetails*:*: {
set %un $2
sockopen bot 192.168.1.2 6080
}
alias bot sockopen bot 192.168.1.2 6080
on *:sockopen:bot: {
sockwrite -n bot GET http://192.168.1.2:6080/s3h/getdetails.php?name= $+ %un
}
on 1:sockread:bot: {
if ($sockerr > 0) return
:nextread
sockread %bot
if ($sockbr == 0) return
if (%bot == $null) %bot = -
echo -a %bot
goto nextread
} And still nothing! No messages in the channel where it was requested, an no errors in mIRC. [15:07:13] *** Initial topic: [15:07:13] *** #alien: r_alien- ~alien- [15:07:19] alien-: r_alien- has just arrived! r_alien- is the Owner of this bot. [15:07:19] *** Mode change "+v r_alien-" for channel #alien by alien-. [15:07:22] *** #alien was created on Sun Sep 04 14:55:36 2005. [15:07:30] r_alien-: !shutdown [15:07:45] *** alien- has joined #alien. [15:07:47] *** Mode change "+qo alien- alien-" for channel #alien by ChanServ. [15:08:16] r_alien-: !sabdetails r_alien [15:08:25] r_alien-: !sabdetails rshield [15:10:03] r_alien-: !shutdown [15:10:04] *** alien- has signed off IRC (Quit: Alien IRC Bot 1.0 based on YBBot> You cannot get this bot May i interest you in Hawk Works instead at http://220.237.150.18:6080/s3h/).[15:10:15] *** alien- has joined #alien. [15:10:17] *** Mode change "+qo alien- alien-" for channel #alien by ChanServ. [15:10:55] r_alien-: !sabdetails rshield Any ideas now?
|
|
|
|
Joined: Apr 2003
Posts: 701
Hoopy frood
|
Hoopy frood
Joined: Apr 2003
Posts: 701 |
on *:text:!sabdetails*:*: {
set %un $2
sockopen bot 192.168.1.2 6080
}
alias bot sockopen bot 192.168.1.2 6080
; Why this alias? It doesn't set %un, might be ok if it's for testing now and you didn't unset %un.
on *:sockopen:bot: {
sockwrite -n bot GET http://192.168.1.2:6080/s3h/getdetails.php?name= $+ %un [color:green]HTTP/1.0
sockwrite bot $str($crlf,2)[/color]
}
on 1:sockread:bot: {
if ($sockerr > 0) return
:nextread
sockread %bot
if ($sockbr == 0) return
if (%bot == $null) %bot = -
echo -a %bot
goto nextread
} If it still doesn't work, download ethereal (or some other sniffer) and find out what your script sends, and what a browser sends. Then find out what the differences are and see if they are preventing the script or not. Not all headers from your browser are necessary, some can even make it more difficult (chunked encoding, deflate, ...)
|
|
|
|
Joined: Aug 2005
Posts: 32
Ameglian cow
|
OP
Ameglian cow
Joined: Aug 2005
Posts: 32 |
OK, i have now modified my script a little. It reads: on *:text:!sabdetails*:*: {
set %un $2
sockopen bot 192.168.1.2 6080
}
alias bot sockopen bot 192.168.1.2 6080
on *:sockopen:bot: {
sockwrite -n bot GET /s3h/getdetails.php?name= $+ %un HTTP/1.1
sockwrite -n bot Host: 192.168.1.2
sockwrite -n bot User-Agent: Omg dont block this T_T I love you!!!! :P
sockwrite -n bot $str($crlf,2)
}
on 1:sockread:bot: {
if ($sockerr > 0) return
:nextread
sockread %bot
if ($sockbr == 0) return
if (%bot == $null) %bot = -
echo -a %bot
goto nextread
} I typed !sabdetails rshield into one window with another account and the script executed, however it displayed the data in the topmost channel window in the mIRC window. It displayed this: HTTP/1.1 200 OK Date: Sun, 04 Sep 2005 08:44:00 GMT Server: Apache/2.0.54 (Win32) PHP/5.0.4 X-Powered-By: PHP/5.0.4 Content-Length: 569 Content-Type: text/html - --- Sabotage Details of rshield --- Blackpowder Missiles: 0, Invisibility Shields: 0 Excaliburs: 0, Battle Axes: 0, Dragons: 0, Flaming Arrows: 0, Dragonskins: 0 Steeds: 0, Hammers of Thor: 0, Wargs: 0 Mithrils: 0, Gauntlets: 0, Heavy Shields: 0, Elven Cloaks: 0 Broadswords: 0, Warhammers: 0, Warblades: 0, Steel Bows: 0, Plate Armors: 0 Lances: 0, Maces: 0, Spears: 0, Longbows: 0, Chainmails: 0 Long Sword: 0, Pikes: 1, Clubs: 0, Crossbows: 0, Shields: 0 Staves: 0, Hatchets: 0, Slings: 0, Short Bows: 0 Helmets: 0, Knives: 0, Sticks: 0 Now i'm wondering how do i get that data after the first bit which just has some info, so from --- Sabotage details of <<username>> --- to the end of the data, sent to the channel window, where it was requested from? Sorry, i'm a n00b to this IRC langauge! xD Oh and i put the host socket line back in because someone i konw suggested putting it in because his won't work withouth it! :P
|
|
|
|
Joined: Apr 2003
Posts: 701
Hoopy frood
|
Hoopy frood
Joined: Apr 2003
Posts: 701 |
The display used echo -a , that is echo the active window... Added a var %untarget that keeps the channel or query window where it was typed. Used /sockmark to tell when the headers are gone (empty line) on *:text:!sabdetails*:*: {
set %un $2
set %untarget $target
sockopen bot 192.168.1.2 6080
}
alias bot sockopen bot 192.168.1.2 6080
on *:sockopen:bot: {
sockwrite -n bot GET /s3h/getdetails.php?name= $+ %un HTTP/1.1
sockwrite -n bot Host: 192.168.1.2
sockwrite -n bot User-Agent: Omg dont block this T_T I love you!!!! :P
sockwrite -n bot $str($crlf,2)
}
on 1:sockread:bot: {
if ($sockerr > 0) return
sockread %bot
while (($sockbr) && (!$sockerr)) {
if ($sock($sockname).mark) echo %untarget $iif(%bot != $null,%bot,-)
elseif (%bot == $null) sockmark $sockname 1
sockread %bot
}
}
|
|
|
|
Joined: Aug 2005
Posts: 32
Ameglian cow
|
OP
Ameglian cow
Joined: Aug 2005
Posts: 32 |
OK, i have that script, and it returns it to the window in mIRC, but it doesn't send it as a messge! How do i get it to do that? so that EVERYONE in that channel can see it? Sorry, i'm a real n00b, and getting tired now
|
|
|
|
|