Jump to content




IRCCC, an IRC client for ComputerCraft

utility lua

22 replies to this topic

#1 hbar

  • Members
  • 23 posts

Posted 19 April 2014 - 11:05 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.

You can also use this to access Twitch chat with some tinkering.

Edited by hbar, 17 February 2015 - 12:10 PM.


#2 Wojbie

  • Members
  • 631 posts
  • LocationKinda lost

Posted 20 April 2014 - 07: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 :)

#3 Dahknee

  • Members
  • 1,808 posts
  • Location/home/da

Posted 05 February 2015 - 12:46 PM

View Posthbar, on 19 April 2014 - 11:05 PM, said:

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!

#4 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

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).

#5 Dahknee

  • Members
  • 1,808 posts
  • Location/home/da

Posted 06 February 2015 - 09:35 AM

View PostBomb Bloke, on 05 February 2015 - 02:55 PM, said:

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 by DannySMc, 06 February 2015 - 09:37 AM.


#6 hbar

  • Members
  • 23 posts

Posted 15 February 2015 - 07:57 PM

View PostDannySMc, on 06 February 2015 - 09:35 AM, said:


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.

#7 Dahknee

  • Members
  • 1,808 posts
  • Location/home/da

Posted 15 February 2015 - 10:11 PM

View Posthbar, on 15 February 2015 - 07:57 PM, said:

View PostDannySMc, on 06 February 2015 - 09:35 AM, said:

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

#8 Drazlak

  • Members
  • 6 posts

Posted 16 February 2015 - 12:23 PM

Is there a way to make it work with twitch?

#9 Creeper9207

  • Members
  • 211 posts

Posted 17 February 2015 - 03:11 AM

amazing.. works fabulous in cc1.7

#10 hbar

  • Members
  • 23 posts

Posted 17 February 2015 - 10:16 AM

View PostDrazlak, on 16 February 2015 - 12:23 PM, said:

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 by hbar, 17 February 2015 - 02:58 PM.


#11 hbar

  • Members
  • 23 posts

Posted 17 February 2015 - 10:29 AM

View PostDannySMc, on 06 February 2015 - 09:35 AM, said:

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.

#12 hbar

  • Members
  • 23 posts

Posted 17 February 2015 - 12:09 PM

View PostDrazlak, on 16 February 2015 - 12:23 PM, said:

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:
  • Download the client using the pastebin in the OP (I updated the program a bit to work with this).
  • 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.
  • 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.
  • 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.
  • 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).
  • 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").
  • 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.

#13 Dahknee

  • Members
  • 1,808 posts
  • Location/home/da

Posted 17 February 2015 - 12:54 PM

View Posthbar, on 17 February 2015 - 10:29 AM, said:

View PostDannySMc, on 06 February 2015 - 09:35 AM, said:

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...

#14 hbar

  • Members
  • 23 posts

Posted 17 February 2015 - 02:31 PM

View PostDannySMc, on 17 February 2015 - 12:54 PM, said:

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?

#15 Dahknee

  • Members
  • 1,808 posts
  • Location/home/da

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

#16 hbar

  • Members
  • 23 posts

Posted 18 February 2015 - 10:48 AM

View PostDannySMc, on 18 February 2015 - 09:25 AM, said:

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.

#17 Dahknee

  • Members
  • 1,808 posts
  • Location/home/da

Posted 18 February 2015 - 05:32 PM

I use CCEmu? This causes the error?

#18 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 18 February 2015 - 11:21 PM

Didn't you previously say you'd confirmed the error under CC 1.65?

#19 Geforce Fan

  • Members
  • 846 posts
  • LocationMissouri, United States, America, Earth, Solar System, Milky Way, Universe 42B, Life Street, Multiverse, 4th Dimension

Posted 19 February 2015 - 12:49 AM

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

Edited by Geforce Fan, 19 February 2015 - 12:49 AM.


#20 hbar

  • Members
  • 23 posts

Posted 19 February 2015 - 02:33 PM

View PostDannySMc, on 18 February 2015 - 05:32 PM, said:

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".

View PostGeforce Fan, on 19 February 2015 - 12:49 AM, said:

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...





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users