|< Day Day Up >|
Hack 90 Access IRC with Java Applets
Even if visitors to your web site don't have an IRC client installed, you can still try to persuade them to join your IRC channel by using a Java Applet client.
PJIRC (http://www.pjirc.com) is an IRC client that can be run as a Java Applet. This means you can embed it on web pages and most people will be able to run it through their web browser without having to install a standalone IRC client.
Before you upload PJIRC to your web server, you should edit the HTML in SimpleApplet.html to tell it to join the server that you want. The only line that you have to change is the one specifying the host:
<param name="host" value="irc.freenode.net">
Now you can run it by pointing your web browser at http://yourserver.com/pjirc-installation/SimpleApplet.html. This will cause the PJIRC client to connect you to the freenode IRC network. You will need to join channels manually (for example, /join #irchacks). At this point, you can do anything you like: join channels, message people, notice people, and even change to a different server. You can see PJIRC running in Figure 14-5.
Figure 14-5. The PJIRC client running inside a web page
14.6.1 Customizing PJIRC
If you want people to be able to connect to your server and join a channel automatically, a little customization is needed. This is done by passing parameters to the Applet in SimpleApplet.html.
When somebody uses PJIRC to connect to the chosen IRC network, the nick parameter specifies which nickname to use. On web-based IRC clients, it is common to use the nickname "Guest" to indicate the temporary nature of the IRC client—more regular users of IRC tend to install their own standalone IRC clients.
<param name="nick" value="Guest">
Because all nicknames used on an IRC network must be unique, you must specify an alternative nickname in case "Guest" is already in use. The alternativenick parameter is used to specify this. Using ? in the name will allow PJIRC to replace this with a random number so that a name can be found that is not in use, for example:
<param name="alternatenick" value="Guest???">
If you want to make the PJIRC client connect to a different server, just change the host parameter as shown earlier:
<param name="host" value="irc.darkmyst.org">
If the IRC server could not be found, you can specify a list of additional servers to try. These must be numbered in ascending order, for example:
<param name="alternateserver1" value="irc.us.freenode.net 6667"> <param name="alternateserver2" value="irc.eu.freenode.net 6667">
You can tell the PJIRC client to automatically execute a list of commands when it successfully connects to an IRC server. These must be numbered in ascending order. This is a useful way of making the client automatically join a channel, for example:
<param name="command1" value="/join #irchacks">
If you want to restrict the list of channels that the client can join, you can change the authorizedjoinlist parameter. In this example, the client will be allowed to join only the channel #irchacks:
<param name="authorizedjoinlist" value="none+#irchacks">
You can even restrict the set of commands that the client is allowed to use. In this case, the user will be able to use only the /me and /msg commands:
<param name="authorizedcommandlist" value="none+me+msg">
14.6.2 The Results
Now you have a customized IRC client that people can use from your web site. They will be allowed only in your channel, and they can only chat with the people in the channel, send private messages, or perform specified actions.
|< Day Day Up >|