This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
hbar's profile picture

IRCCC, an IRC client for ComputerCraft

Started by hbar, 19 April 2014 - 10:05 PM
hbar #1
Posted 20 April 2014 - 12:05 AM
As most of you probably know, the HTTP API severely limits on what can be done with ComputerCraft and internet. After watching this DEFCON talk (links to the relevant part at around 5:43) I wanted to try how well the HTTP protocol could be used in CC to connect to an IRC server. Unsurprisingly not very well. You can connect, but sending data is impossible.

Anyway, this little test led me to look into the problem a bit more more. Getting ComputerCraft to connect to some IRC server has been done before, but it usually has required an additional mod peripheral or setting up your own IRC-HTTP proxy. My solution uses the services already provided by many IRC servers and should work out of the box.

Several IRC servers provide a webchat interface you can use to connect to the server within your browser. So, it should be possible to connect to the same interface with ComputerCraft. A popular webchat client is qwebirc which is conveniently open source. Going through the javascript code revealed how the client communicates with the backend and it was fairly easy to replicate with CC.

So, I wrote a basic client that can connect to any (probably) qwebirc webchat server. A lot of the FTB related channels are on espernet which fortunately has a suitable webchat.

Get the client here or

pastebin get gaSL8HZC irc

Screenshots.

By default the client connects to espernet, but you can change that by editing the file. Look at the instructions at the beginning.

The client supports windows for different channels and private chats. You can cycle through the windows with the tab key. Use /help for a list of available commands.

Although it works pretty well (and I'm just a little proud of the asynchronous and parallel design I made), the client is pretty bare bones. But, you can use it as a proof of concept to base your own programs on, if you want to. Someone on #computercraft with a better understanding of the IRC protocol already was planning on separating the IRC connection part into a separate API, so look for that.

You can also use this to access Twitch chat with some tinkering.
Edited on 17 February 2015 - 11:10 AM
Wojbie #2
Posted 20 April 2014 - 08:52 AM
Interesting…
Will need to remember to test it later but if it works as good as it looks you have just made computercraft history!
Congratulations on doing something no-one ever (to my knowledge) did right :D/> Even my attempt was read-only :)/>
DannySMc #3
Posted 05 February 2015 - 12:46 PM
As most of you probably know, the HTTP API severely limits on what can be done with ComputerCraft and internet. After watching this DEFCON talk (links to the relevant part at around 5:43) I wanted to try how well the HTTP protocol could be used in CC to connect to an IRC server. Unsurprisingly not very well. You can connect, but sending data is impossible.

Anyway, this little test led me to look into the problem a bit more more. Getting ComputerCraft to connect to some IRC server has been done before, but it usually has required an additional mod peripheral or setting up your own IRC-HTTP proxy. My solution uses the services already provided by many IRC servers and should work out of the box.

Several IRC servers provide a webchat interface you can use to connect to the server within your browser. So, it should be possible to connect to the same interface with ComputerCraft. A popular webchat client is qwebirc which is conveniently open source. Going through the javascript code revealed how the client communicates with the backend and it was fairly easy to replicate with CC.

So, I wrote a basic client that can connect to any (probably) qwebirc webchat server. A lot of the FTB related channels are on espernet which fortunately has a suitable webchat.

Get the client here or

pastebin get gaSL8HZC irc

Screenshots.

By default the client connects to espernet, but you can change that by editing the file. Look at the instructions at the beginning.

The client supports windows for different channels and private chats. You can cycle through the windows with the tab key. Use /help for a list of available commands.

Although it works pretty well (and I'm just a little proud of the asynchronous and parallel design I made), the client is pretty bare bones. But, you can use it as a proof of concept to base your own programs on, if you want to. Someone on #computercraft with a better understanding of the IRC protocol already was planning on separating the IRC connection part into a separate API, so look for that.

It errors :/ Could you help? as I wish to use this! :P/> thanks!
Bomb Bloke #4
Posted 05 February 2015 - 02:55 PM
Providing your CC version number, along with the error, might make it a bit easier to help you.

I'm going to take a shot-in-the-dark guess and assume you haven't configured ComputerCraft to be able to connect to the target domain (webchat.esper.net).
DannySMc #5
Posted 06 February 2015 - 09:35 AM
Providing your CC version number, along with the error, might make it a bit easier to help you.

I'm going to take a shot-in-the-dark guess and assume you haven't configured ComputerCraft to be able to connect to the target domain (webchat.esper.net).

CC: 1.65

Error: irc:275: Failed to load string [ return "-\u00034IMPORTANT: EsperNet serves many communities.\u0003"] in JSON4Lua.decode_scanString at position 5255 : 5317

and configured? My http-whitelist is * to allow all sites as I use a similar program for my blog updates on the screens in my server…?
Edited on 06 February 2015 - 08:37 AM
hbar #6
Posted 15 February 2015 - 07:57 PM
CC: 1.65

Error: irc:275: Failed to load string [ return "-\u00034IMPORTANT: EsperNet serves many communities.\u0003"] in JSON4Lua.decode_scanString at position 5255 : 5317

and configured? My http-whitelist is * to allow all sites as I use a similar program for my blog updates on the screens in my server…?

Thanks for the report. Can you tell which server you are trying to connect to when you get that error? The default one? I haven't touched this particular program in a while and honestly can't quite remember how it works, but I'll take a look as soon as I have the time. On a quick glance it seems to be a bug/feature in the JSON library I'm using.
DannySMc #7
Posted 15 February 2015 - 10:11 PM
CC: 1.65

Error: irc:275: Failed to load string [ return "-\u00034IMPORTANT: EsperNet serves many communities.\u0003"] in JSON4Lua.decode_scanString at position 5255 : 5317

and configured? My http-whitelist is * to allow all sites as I use a similar program for my blog updates on the screens in my server…?

Thanks for the report. Can you tell which server you are trying to connect to when you get that error? The default one? I haven't touched this particular program in a while and honestly can't quite remember how it works, but I'll take a look as soon as I have the time. On a quick glance it seems to be a bug/feature in the JSON library I'm using.

Yeah and it is esper, I quite like it so I would love if you could get it working :D/>
Drazlak #8
Posted 16 February 2015 - 12:23 PM
Is there a way to make it work with twitch?
Creeper9207 #9
Posted 17 February 2015 - 03:11 AM
amazing.. works fabulous in cc1.7
hbar #10
Posted 17 February 2015 - 10:16 AM
Is there a way to make it work with twitch?

I think you would need to set up a qwebirc instance yourself that connects to irc.twitch.tv. I'm not sure if Twitch has some clause in their TOS that prohibits that, but if you keep the instance private, I see no reason why that wouldn't be allowed. This might be feasible (I haven't tested), you just need a webserver that's running the qwebirc (for example your own computer).

EDIT: solution and instructions below
Edited on 17 February 2015 - 01:58 PM
hbar #11
Posted 17 February 2015 - 10:29 AM
Error: irc:275: Failed to load string [ return "-\u00034IMPORTANT: EsperNet serves many communities.\u0003"] in JSON4Lua.decode_scanString at position 5255 : 5317

I took a look (no fix yet) and it seems that the Lua loadstring method fails on those escaped unicode sequences. Can you tell me what did you do to encounter that error? I'm not sure what is the best way to handle this. Maybe just lazily regexp for those unicode escapes and replace them with some other character (question mark maybe) before feeding the json to the parser? Suggestions are welcome.
hbar #12
Posted 17 February 2015 - 12:09 PM
Is there a way to make it work with twitch?

So I went and tried it out: yes you can make it work with Twitch!

Here's how:
  1. Download the client using the pastebin in the OP (I updated the program a bit to work with this).
  2. Dowload and install qwebirc on your computer (or a remote machine). Follow the installation instructions but with the following changes:
    • Before running the compile.py you need to change the auth.js file (located in the js folder). Set qwebirc.auth.enabled and qwebirc.auth.bouncerAuth to return true, and set qwebirc.auth.quakeNetAuth and qwebirc.auth.passAuth to return false.
  3. Start qwebirc and go to http://localhost:9090 (or the address of the remote machine you are using) to verify that the service is running.
  4. You need to generate an OAUTH token to access the Twitch irc server. You can find instructions on how to do this in the Twitch Irc guide.
  5. Edit the irc program by changing the line local baseUrl = "http://webchat.esper.net/" to local baseUrl = "http://localhost:9090/" (or the address of the remote machine).
  6. Run the irc program with
     irc username password 
    where the username is your Twitch username and password is your OAUTH token (which looks like "oauth:sdhi42p0x92bpd7u4n88s3d6oyoucl").
  7. Connect to the channel and tell everyone how awesome it is to chat from inside Minecraft!
Unfortunately not as out-of-the-box as I would like, but relatively easy. Would be even easier if someone would set up a dedicated qwebirc portal to Twitch.
DannySMc #13
Posted 17 February 2015 - 12:54 PM
Error: irc:275: Failed to load string [ return "-\u00034IMPORTANT: EsperNet serves many communities.\u0003"] in JSON4Lua.decode_scanString at position 5255 : 5317

I took a look (no fix yet) and it seems that the Lua loadstring method fails on those escaped unicode sequences. Can you tell me what did you do to encounter that error? I'm not sure what is the best way to handle this. Maybe just lazily regexp for those unicode escapes and replace them with some other character (question mark maybe) before feeding the json to the parser? Suggestions are welcome.

I did nothing, this is just starting the program… it errors while connecting, I didn't get chance to press anything…
hbar #14
Posted 17 February 2015 - 02:31 PM
I did nothing, this is just starting the program… it errors while connecting, I didn't get chance to press anything…

Ugh, one of those bugs. This is gonna be hard to figure out as I can't reproduce this error myself. Can you try it on CC 1.7? Also, what OS are you on?
DannySMc #15
Posted 18 February 2015 - 09:25 AM
Ahh well, I shall have a go but I am at work currently, it doesn't work on Ubuntu 14.04 (Linux) or Windows 8.1, or any type of emulator, I keep getting the same error. If you want I could have a look at the code? I have multiple programs that use online based requests? Cheers
hbar #16
Posted 18 February 2015 - 10:48 AM
Ahh well, I shall have a go but I am at work currently, it doesn't work on Ubuntu 14.04 (Linux) or Windows 8.1, or any type of emulator, I keep getting the same error. If you want I could have a look at the code? I have multiple programs that use online based requests? Cheers

I tried it also with Windows 8.1 and it works perfectly well… I have no idea what's going on. If you want to take a look, I'm more than happy to get help on this. If you figure it out, feel free to send me a "pull request" and I'll update the original program. In the mean time I'll do some more debugging of my own, maybe try a few emulators and try to reproduce the bug.
DannySMc #17
Posted 18 February 2015 - 05:32 PM
I use CCEmu? This causes the error?
Bomb Bloke #18
Posted 18 February 2015 - 11:21 PM
Didn't you previously say you'd confirmed the error under CC 1.65?
Geforce Fan #19
Posted 19 February 2015 - 12:49 AM
This is incredible
Nice work. It should be in Programs, though.
Edited on 18 February 2015 - 11:49 PM
hbar #20
Posted 19 February 2015 - 02:33 PM
I use CCEmu? This causes the error?

Probably. I tried it in CCEmuRedux, the successor of CCEmu and there was no error. Unfortunately I can't get my hands on the old emulator, so can't try it there (the download is no longer available). However, as it seems to be the fault of the emulator, I think I can file this under "won't fix".

This is incredible
Nice work. It should be in Programs, though.

You know, I never realised that Programs was a forum on it's own and always just went to one of the subforums. How silly of me…
DannySMc #21
Posted 20 February 2015 - 10:28 AM
I use CCEmu? This causes the error?

Probably. I tried it in CCEmuRedux, the successor of CCEmu and there was no error. Unfortunately I can't get my hands on the old emulator, so can't try it there (the download is no longer available). However, as it seems to be the fault of the emulator, I think I can file this under "won't fix".

This is incredible
Nice work. It should be in Programs, though.

You know, I never realised that Programs was a forum on it's own and always just went to one of the subforums. How silly of me…

I have the emulator if you wish to test it? and yes will try it thanks!
hbar #22
Posted 23 February 2015 - 01:05 PM
I have the emulator if you wish to test it? and yes will try it thanks!

I think I have it on my old laptop somewhere, but thanks for offering. The program seems to work just fine everywhere else, so I think I won't try to fix it on the old emulator. Hopefully you can get it to work, do tell if you run into more problems.
iAd4m #23
Posted 17 April 2015 - 08:05 PM
Wonderful program works great :)/>
Got it setup on a big monitor
Edited on 17 April 2015 - 06:05 PM