Editing IRC Client

Jump to navigation Jump to search
Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then publish the changes below to finish undoing the edit.

Latest revision Your text
Line 2: Line 2:


A goal of this is to create a base resource of knowledge around IRC and specifically the capturing the knowledge for both building and using IRC Clients.
A goal of this is to create a base resource of knowledge around IRC and specifically the capturing the knowledge for both building and using IRC Clients.
Basics of IRC Client communication.
IRC is protocol that operates over a TCP/IP socket connection with ASCII encoding typically on port 6667.
In order to connect an IRC Server a socket must first be opened on the appropriate portThis is done in AS3 by using the flash.net.Socket class, and passing the hostname as a string (DNS host name or IP) and a port number as an integer.
<pre>
var socket:flash.net.Socket = new flash.net.Socket("irc.freenode.net", 6667);
</pre>
The Socket class generates an Event.CONNECT when the connection is established, several other error events can be generated if the connection fails.
Once the socket is open the Client needs to register the connection by sending a NICK and USER command, all messages are sent to the server with the Socket method writeUTFBytes, all messages must be terminated with the ASCII character pair of CRLF (\r\n), and the flush method is called to send the queued data.
<pre>
socket.writeUTFBytes("NICK the-x\r\n");
socket.writeUTFBytes("USER thex experimental irc.freenode.net :John Doe\r\n");
</pre>
Upon successful registration the server will respond with a numeric messages 001..004.
This is the complete code for a basic "bot" that tests some code and tells teh time
<pre>
package
{
import flash.display.Sprite;
import flash.net.Socket;
import flash.events.Event;
import flash.events.ProgressEvent;
import flash.events.KeyboardEvent;
import flash.text.TextField;
public class IRCc extends Sprite
{
public var keyHit:Sprite;
public var text_txt:TextField;
private var socket:Socket;
private var hostPath:String = "irc.freenode.net";
private var hostPort:int = 6667;
private var nickname:String = "debugUser";
private var username:String = "Test User";
private var hostname:String = "TEST-HOST";
private var realname:String = "NO NAME";
private var connectionState:String = "INIT";
public function IRCc()
{
text_txt.addEventListener(KeyboardEvent.KEY_DOWN, keyHandler);
initSocket();
}
private function initSocket():void
{
socket = new Socket(hostPath, hostPort);
socket.addEventListener(Event.CONNECT, connectHandler);
socket.addEventListener(Event.CLOSE, closeHandler);
socket.addEventListener(ProgressEvent.SOCKET_DATA, socketDataHandler);
connectionState = "CONNECTING";
}
private function sendNick():void
{
/*
Command: NICK
  Parameters: <nickname> [ <hopcount> ]
Command: USER
Parameters: <username> <hostname> <servername> <realname>
*/
// connectionState = "HANDSHAKE";
socket.writeUTFBytes("NICK " + nickname + "\r\n");
socket.writeUTFBytes("USER " + username + " " + hostname + " " + hostPath + ": " + realname + "\r\n");
socket.flush();
}
private function quit():void
{
trace("quit");
connectionState = "QUIT";
socket.writeUTFBytes("QUIT :i quit there 4...\r\n");
socket.flush();
}
private function joinChannel(channel:String):void
{
trace("JOIN: " + channel);
socket.writeUTFBytes("JOIN " + channel + "\r\n");
socket.flush();
}
private function sendMessage(msg:String):void
{
trace("MSG: " + msg);
socket.writeUTFBytes("PRIVMSG #fort :test\r\n");
socket.flush();
}
private function sendTime():void
{
var now:Date = new Date();
trace("TIME: " + now.toString());
socket.writeUTFBytes("PRIVMSG #fort :teh time is now " + now.toString() + "\r\n");
socket.flush();
}
private function pongServer(daemon:String):void
{
trace("PONG: *" + daemon + "*");
socket.writeUTFBytes("PONG " + daemon + "\r\n");
socket.flush();
}
private function readData():void
{
var socketData:String = socket.readUTFBytes(socket.bytesAvailable);
trace(socketData);
if (socketData.split(' ', 1)[0] == "PING")
{
// PING Command, send PONG
pongServer(socketData.split(':')[1]);
}
else
{
var msg:String = socketData.substr(socketData.lastIndexOf(":"));
trace("MSG: " + msg);
if (msg.toLowerCase().indexOf("time") >= 0)
{
sendTime();
}
else if (msg.toLowerCase().indexOf("test") >= 0)
{
sendMessage("test");
}
}
}
private function socketDataHandler(e:ProgressEvent):void
{
trace("Data");
readData();
}
private function connectHandler(e:Event):void
{
trace("Connect");
connectionState = "CONNECTED";
sendNick();
}
private function closeHandler(e:Event):void
{
trace("Close");
connectionState = "CLOSED";
}
private function keyHandler(e:KeyboardEvent):void
{
trace("key: " + e.keyCode);
if (e.keyCode == 74)
{
joinChannel("#fort");
}
else if (e.keyCode == 77)
{
sendMessage("test");
}
else if (e.keyCode == 84)
{
sendTime();
}
else if (e.keyCode == 81)
{
quit();
}
}
}
}
</pre>


Sample connection to irc.freenode.net, captured socket data to/from babel client.
Sample connection to irc.freenode.net, captured socket data to/from babel client.
Line 264: Line 73:
:lindbohm.freenode.net 372 [jc] :- and agree to adhere to our policies and procedures as per
:lindbohm.freenode.net 372 [jc] :- and agree to adhere to our policies and procedures as per


:lindbohm.freenode.net 372 [jc] :- the website (http://freenode.net)We would like to remind
:lindbohm.freenode.net 372 [jc] :- the website (http://freenode.net). We would like to remind


:lindbohm.freenode.net 372 [jc] :- you that unauthorized public logging of channels on the
:lindbohm.freenode.net 372 [jc] :- you that unauthorized public logging of channels on the


:lindbohm.freenode.net 372 [jc] :- network is prohibitedPublic channel logging should only
:lindbohm.freenode.net 372 [jc] :- network is prohibited. Public channel logging should only


:lindbohm.freenode.net 372 [jc] :- take place where the channel ownJOIN #fort
:lindbohm.freenode.net 372 [jc] :- take place where the channel ownJOIN #fort
Line 282: Line 91:
:lindbohm.freenode.net 372 [jc] :-   
:lindbohm.freenode.net 372 [jc] :-   


:lindbohm.freenode.net 372 [jc] :- freenode runs an open proxy scanner. [http://vcsc.cs.uh.edu/second- url:computing/show_user.php?userid=2557 docx] For details on
:lindbohm.freenode.net 372 [jc] :- freenode runs an open proxy scanner. Your use of the network
 
:lindbohm.freenode.net 372 [jc] :- indicates your acceptance of this policy. For details on


:lindbohm.freenode.net 372 [jc] :- freenode network policy, please take a look at our policy
:lindbohm.freenode.net 372 [jc] :- freenode network policy, please take a look at our policy


:lindbohm.freenode.net 372 [jc] :- page (http://freenode.net/policy.shtml)Thank you for using
:lindbohm.freenode.net 372 [jc] :- page (http://freenode.net/policy.shtml). Thank you for using


:lindbohm.freenode.net 372 [jc] :- the network!
:lindbohm.freenode.net 372 [jc] :- the network!
Line 355: Line 166:
00000020  2e 66 72 65 65 6e 6f 64  65 2e 6e 65 74 20 3a 4a .freenod e.net :J
00000020  2e 66 72 65 65 6e 6f 64  65 2e 6e 65 74 20 3a 4a .freenod e.net :J
00000030  2e 43 2e 0d 0a                                  .C...
00000030  2e 43 2e 0d 0a                                  .C...
     00000000  3a 73 65 6e 64 61 6b 2e  66 72 65 65 6e 6f 64 65 :sendakfreenode
     00000000  3a 73 65 6e 64 61 6b 2e  66 72 65 65 6e 6f 64 65 :sendak. freenode
     00000010  2e 6e 65 74 20 4e 4f 54  49 43 45 20 2a 20 3a 2a .net NOT ICE * :*
     00000010  2e 6e 65 74 20 4e 4f 54  49 43 45 20 2a 20 3a 2a .net NOT ICE * :*
     00000020  2a 2a 20 4c 6f 6f 6b 69  6e 67 20 75 70 20 79 6f ** Looki ng up yo
     00000020  2a 2a 20 4c 6f 6f 6b 69  6e 67 20 75 70 20 79 6f ** Looki ng up yo
     00000030  75 72 20 68 6f 73 74 6e  61 6d 65 2e 2e 2e 0d 0a ur hostn ame.....
     00000030  75 72 20 68 6f 73 74 6e  61 6d 65 2e 2e 2e 0d 0a ur hostn ame.....
     00000040  3a 73 65 6e 64 61 6b 2e  66 72 65 65 6e 6f 64 65 :sendakfreenode
     00000040  3a 73 65 6e 64 61 6b 2e  66 72 65 65 6e 6f 64 65 :sendak. freenode
     00000050  2e 6e 65 74 20 4e 4f 54  49 43 45 20 2a 20 3a 2a .net NOT ICE * :*
     00000050  2e 6e 65 74 20 4e 4f 54  49 43 45 20 2a 20 3a 2a .net NOT ICE * :*
     00000060  2a 2a 20 43 68 65 63 6b  69 6e 67 20 49 64 65 6e ** Check ing Iden
     00000060  2a 2a 20 43 68 65 63 6b  69 6e 67 20 49 64 65 6e ** Check ing Iden
     00000070  74 0d 0a                                        t..
     00000070  74 0d 0a                                        t..
     00000073  3a 73 65 6e 64 61 6b 2e  66 72 65 65 6e 6f 64 65 :sendakfreenode
     00000073  3a 73 65 6e 64 61 6b 2e  66 72 65 65 6e 6f 64 65 :sendak. freenode
     00000083  2e 6e 65 74 20 4e 4f 54  49 43 45 20 2a 20 3a 2a .net NOT ICE * :*
     00000083  2e 6e 65 74 20 4e 4f 54  49 43 45 20 2a 20 3a 2a .net NOT ICE * :*
     00000093  2a 2a 20 46 6f 75 6e 64  20 79 6f 75 72 20 68 6f ** Found  your ho
     00000093  2a 2a 20 46 6f 75 6e 64  20 79 6f 75 72 20 68 6f ** Found  your ho
     000000A3  73 74 6e 61 6d 65 0d 0a                          stname.
     000000A3  73 74 6e 61 6d 65 0d 0a                          stname..  
</pre>
</pre>


Line 372: Line 183:


IRC
IRC
http://tools.ietf.org/html/rfc1459.html
http://tools.ietf.org/html/rfc1413




Socket based connection
Socket based connection IRC Server
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/Socket.html
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/Socket.html
Please note that all contributions to Noisebridge are considered to be released under the Creative Commons Attribution-NonCommercial-ShareAlike (see Noisebridge:Copyrights for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource. Do not submit copyrighted work without permission!

To protect the wiki against automated edit spam, we kindly ask you to solve the following CAPTCHA:

Cancel Editing help (opens in new window)