Java and IRC. What Is IRC? Nicks, Channels and Operators. Using IRC. What Is an IRC Bot? IRC Protocol



Similar documents
IRC - Internet Relay Chat

3.5. cmsg Developer s Guide. Data Acquisition Group JEFFERSON LAB. Version

Transparent Redirection of Network Sockets 1

Server Setup. Basic Settings

/helpop <command> you can get the detailed help for one single command.

Manual. Programmer's Guide for Java API

Transparent Redirection of Network Sockets 1

LAB4 Making Classes and Objects

Division of Informatics, University of Edinburgh

The Java Series. Java Essentials I What is Java? Basic Language Constructs. Java Essentials I. What is Java?. Basic Language Constructs Slide 1

New York University Computer Science Department Courant Institute of Mathematical Sciences

Crash Course in Java

First Java Programs. V. Paúl Pauca. CSC 111D Fall, Department of Computer Science Wake Forest University. Introduction to Computer Science

1.00 Lecture 1. Course information Course staff (TA, instructor names on syllabus/faq): 2 instructors, 4 TAs, 2 Lab TAs, graders

Developing an Inventory Management System for Second Life

2- Electronic Mail (SMTP), File Transfer (FTP), & Remote Logging (TELNET)

IRC-Client. IRC Group: Arne Bochem, Benjamin Maas, David Weiss

Java Language Tools COPYRIGHTED MATERIAL. Part 1. In this part...

What really is a Service?

Forming a P2P System In order to form a P2P system, the 'central-server' should be created by the following command.

1001ICT Introduction To Programming Lecture Notes

Programming in Python. Basic information. Teaching. Administration Organisation Contents of the Course. Jarkko Toivonen. Overview of Python

Java CPD (I) Frans Coenen Department of Computer Science

#Celine_Dion - EFnet - IRC Tutorial

Implementing an IRC Server Using an Object- Oriented Programming Model for Concurrency

CS170 Lab 11 Abstract Data Types & Objects

Free Java textbook available online. Introduction to the Java programming language. Compilation. A simple java program

Chapter 14 Analyzing Network Traffic. Ed Crowley

CS506 Web Design and Development Solved Online Quiz No. 01

JAVAMAIL API - SMTP SERVERS

Installing Java (Windows) and Writing your First Program

Troubleshooting / FAQ

The HoneyNet Project Scan Of The Month Scan 27

Mail User Agent Project

(For purposes of this Agreement, "You", " users", and "account holders" are used interchangeably, and where applicable).

HelpSystems Web Server User Guide

How to Install Java onto your system

latest Release 0.2.6

Free Java textbook available online. Introduction to the Java programming language. Compilation. A simple java program

AP Computer Science Static Methods, Strings, User Input

Chapter 46 Terminal Server

W3Perl A free logfile analyzer

History OOP languages Year Language 1967 Simula Smalltalk

Java 7 Recipes. Freddy Guime. vk» (,\['«** g!p#« Carl Dea. Josh Juneau. John O'Conner

An Android-based Instant Message Application

Lab 1 Beginning C Program

PROFESSIONAL. Node.js BUILDING JAVASCRIPT-BASED SCALABLE SOFTWARE. Pedro Teixeira WILEY. John Wiley & Sons, Inc.

Getting Started with the Internet Communications Engine

Java Web Services SDK

HOW TO USE THE File Transfer Protocol SERVER ftp.architekturaibiznes.com.pl

Computer Networks Practicum 2015

Napster and Gnutella: a Comparison of two Popular Peer-to-Peer Protocols. Anthony J. Howe Supervisor: Dr. Mantis Cheng University of Victoria

File Transfer Protocols In Anzio

CrushFTP User Manager

Handout 1. Introduction to Java programming language. Java primitive types and operations. Reading keyboard Input using class Scanner.

User Guide. You will be presented with a login screen which will ask you for your username and password.

High speed networks and distributed systems Oxford Brookes MSc dissertation. IRC distributed bot lending platform: The Loufiz project

Object Oriented Software Design

Appendix A Using the Java Compiler

Remote Online Support

Sample CSE8A midterm Multiple Choice (circle one)

Java with Eclipse: Setup & Getting Started

The Darwin Game 2.0 Programming Guide

Lesson: All About Sockets

Design and Implementation of an Intelligent Network Monitoring and Management Tool in Internet and Intranet

SMTP-32 Library. Simple Mail Transfer Protocol Dynamic Link Library for Microsoft Windows. Version 5.2

USING HDFS ON DISCOVERY CLUSTER TWO EXAMPLES - test1 and test2

BF2CC Daemon Linux Installation Guide

PERFORMANCE COMPARISON OF COMMON OBJECT REQUEST BROKER ARCHITECTURE(CORBA) VS JAVA MESSAGING SERVICE(JMS) BY TEAM SCALABLE

Topics. Introduction. Java History CS 146. Introduction to Programming and Algorithms Module 1. Module Objectives

Java Crash Course Part I

Development of parallel codes using PL-Grid infrastructure.

Welcome to Introduction to programming in Python

Development of a Real-time Customer Service System. Abstract

Creating a Simple, Multithreaded Chat System with Java

Object Oriented Software Design

Java Software Development Kit (JDK 5.0 Update 14) Installation Step by Step Instructions

Networking Applications

Network Communication

Contents. Java - An Introduction. Java Milestones. Java and its Evolution

You are to simulate the process by making a record of the balls chosen, in the sequence in which they are chosen. Typical output for a run would be:

Mobile Push Architectures

Linux MPS Firewall Supplement

NEW AND IMPROVED! INSTALLING an IRC Server (Internet Relay Chat) on your WRT54G,GS,GL Version 1.02 April 2 nd, Rusty Haddock/AE5AE

ERserver. iseries. Securing applications with SSL

The Konversation Handbook. Gary R. Cramblitt

Writing a C-based Client/Server

CipherMail Gateway Quick Setup Guide

Java Cheatsheet. Tim Coppieters Laure Philips Elisa Gonzalez Boix

1) Which of the following is a constant, according to Java naming conventions? a. PI b. Test c. x d. radius

How to use the Eclipse IDE for Java Application Development

OCS Training Workshop LAB14. Setup

Transcription:

What Is IRC? Java and IRC Making a Java IRC Bot With The PircBot Framework IRC stands for Internet Relay Chat Created by Jarkko Oikarinen in 1988 and still growing in popularity An IRC server allows people to chat in channels (rooms or groups), or privately People from all over the world can use it IRC servers can be joined together to provide vast networks with thousands of users Copyright Paul Mutton, http://www.jibble.org/pircbot.php 1 Copyright Paul Mutton, http://www.jibble.org/pircbot.php 2 Using IRC A user runs a client program to connect to the IRC server The client program allows you to send and receive messages to and from other users Some popular IRC clients are: - mirc BitchX xchat Nicks, Channels and Operators Each user must have a unique nickname Commonly referred to as a nick Must not contain certain characters, e.g. spaces Channel names must start with # or & Some users may be channel operators Can kick other users out of their channel Can op and deop other users in the channel Can ban users from entering the channel Copyright Paul Mutton, http://www.jibble.org/pircbot.php 3 Copyright Paul Mutton, http://www.jibble.org/pircbot.php 4 IRC Protocol The IRC protocol is text-based RFC 1459 defines how messages are sent from client to server and server to client TCP sockets are used for connecting Some IRC servers will support extra commands that are not in RFC 1459 The protocol is asynchronous in nature What Is an IRC Bot? Bot is short for robot An IRC Bot is a special type of IRC client Does not require a human user Often responds automatically to certain events One analogy is to think of an IRC Bot as a normal IRC client, but where the human user has been replaced by a program! Copyright Paul Mutton, http://www.jibble.org/pircbot.php 5 Copyright Paul Mutton, http://www.jibble.org/pircbot.php 6 1

What Can IRC Bots Do? Tell people what the time is Pass messages on to other users Display information from TV listings Perform simple mathematics Send and receive files Monitor channels to generate statistics... anything you want! Using Bots Sensibly Never annoy other users with your Bot Only place your Bot in channels where it may be of use or amusement Bots should only speak when spoken to! Make the purpose of your Bot clear Make it clear that you own your Bot Never try to pretend that it s not a Bot! Copyright Paul Mutton, http://www.jibble.org/pircbot.php 7 Copyright Paul Mutton, http://www.jibble.org/pircbot.php 8 What is PircBot? A framework for writing IRC Bots with Java Simplifies the task of writing an IRC Bot No need to worry about the underlying protocol Very simple Bots can be written within minutes! Event-driven architecture Can make a Bot that responds to certain events Where Can I Download PircBot? The PircBot homepage http://www.jibble.org/pircbot.php Documentation changelog PircBot FAQ Examples of some Bots that use PircBot Download the zip file Contains a file named pircbot.jar Also contains a directory full of documentation Copyright Paul Mutton, http://www.jibble.org/pircbot.php 9 Copyright Paul Mutton, http://www.jibble.org/pircbot.php 10 Extending PircBot To use PircBot, you must import its package import org.jibble.pircbot.*; PircBot is an abstract class You cannot instantiate it You must extend it and inherit its functionality You can override some of the methods in the PircBot class to respond to certain events An Example: SimpleBot import org.jibble.pircbot.*; public class SimpleBot extends PircBot { public SimpleBot() { setname( SimpleBot ); Copyright Paul Mutton, http://www.jibble.org/pircbot.php 11 Copyright Paul Mutton, http://www.jibble.org/pircbot.php 12 2

Connecting To an IRC Server public static void main(string[] args) { SimpleBot bot = new SimpleBot(); bot.setverbose(true); try { bot.connect( compsoc1.ukc.ac.uk ); catch (Exception e) { System.out.println( Can t connect: + e); return; bot.joinchannel( #bots ); Some Notes About SimpleBot SimpleBot.java The setname method is inherited from the PircBot class and sets the nick that will be used when the Bot joins an IRC server Connecting to an IRC server setverbose(true) causes everything to be printed out as it arrives from the IRC server Each method in the PircBot class is fully described in the provided API documentation Copyright Paul Mutton, http://www.jibble.org/pircbot.php 13 Copyright Paul Mutton, http://www.jibble.org/pircbot.php 14 Making SimpleBot Tell the Time In your SimpleBot class, override the onmessage method: - public void onmessage(string channel, String sender, String login, String hostname, String message) { if (message.equalsignorecase( time )) { String time = new java.util.date().tostring(); sendmessage(channel, sender + : + time); Running Your IRC Bot pircbot.jar contains the classes for PircBot Add this file to your classpath when you compile or run your IRC Bot manually, e.g. javac classpath pircbot.jar;. *.java java classpath pircbot.jar;. SimpleBot Note: Unix users should use : instead of ; Copyright Paul Mutton, http://www.jibble.org/pircbot.php 15 Copyright Paul Mutton, http://www.jibble.org/pircbot.php 16 Other Built-in PircBot Features DCC send/receive files DCC chat Coloured messages Maintain lists of joined channels and users List all channels on a server Many event-driven methods that may be overridden onconnect, ondisconnect, onjoin, onop, etc. Rejoining a Channel When Kicked public void onkick(string channel, String kickernick, String login, String hostname, String recipientnick, String reason) { if (recipientnick.equalsignorecase(getnick())) { joinchannel(channel); Note that we only attempt to rejoin the channel if it was us that was kicked Copyright Paul Mutton, http://www.jibble.org/pircbot.php 17 Copyright Paul Mutton, http://www.jibble.org/pircbot.php 18 3

Reconnecting to an IRC Server PircBot Ident Server public void ondisconnect() { while (!isconnected()) { try { reconnect(); catch (Exception e) { // Couldn t reconnect. // Pause for a short while before retrying? Some IRC servers require you to connect from a machine that runs an Ident Server PircBot can emulate the functionality of an Ident Server if you do not already run one Provides the IRC server with your Bot s login when it asks for it bot.startidentserver(); Copyright Paul Mutton, http://www.jibble.org/pircbot.php 19 Copyright Paul Mutton, http://www.jibble.org/pircbot.php 20 PircBot Flood Protection Some IRC servers disconnect clients that send too many messages too quickly. PircBot queues most outgoing messages. Queued messages are sent with a small delay between them to prevent flooding You can get the current size of this queue by calling the getoutgoingqueuesize() method Colors and Formatting Examples String chan = #bots ; sendmessage(chan, Colors.BOLD + Hello! ); Hello! sendmessage(chan, Colors.RED + Red text ); Red text sendmessage(chan, Colors.BLUE + Blue text ); Blue text Copyright Paul Mutton, http://www.jibble.org/pircbot.php 21 Copyright Paul Mutton, http://www.jibble.org/pircbot.php 22 Further Text Formatting DCC Send File sendmessage(chan, Colors.BOLD + Colors.RED + Bold and red ); Bold and red sendmessage(chan, Colors.BLUE + Blue + Colors.NORMAL + normal ); Blue normal File file = new File( c:/stuff/elvis.mp3 ); String nick = Dave ; int timeout = 120000; dccsendfile(file, nick, timeout); Target client must be able to establish a TCP connection to your Bot to receive the file Copyright Paul Mutton, http://www.jibble.org/pircbot.php 23 Copyright Paul Mutton, http://www.jibble.org/pircbot.php 24 4

User List Example onuserlist is called after we join a channel This example overrides the onuserlist method and simply prints out each nick public void onuserlist(string channel, User[] users) { for (int i = 0; i < users.length; i++) { User user = users[i]; String nick = user.getnick(); System.out.println(nick); Copyright Paul Mutton, http://www.jibble.org/pircbot.php 25 Multiple Server Support in PircBot An individual instance of a subclass of PircBot can only join one IRC server at a time Multiple server support can be achieved by creating multiple instances Create a class to control a Collection of PircBot objects and allow them to interact Copyright Paul Mutton, http://www.jibble.org/pircbot.php 26 IRC Bots Based On PircBot (1) ComicBot Creates comic strips out of things that people say IRC Bots Based On PircBot (2) Monty The first ever PircBot! Learns from what it sees other people saying Dictionary and thesaurus lookup feature Can remind people to do things after a set time Shows TV schedule listings Performs google searches Calculates results of mathematical expressions etc. Copyright Paul Mutton, http://www.jibble.org/pircbot.php 27 Copyright Paul Mutton, http://www.jibble.org/pircbot.php 28 IRC Bots Based On PircBot (3) SocialNetworkBot Attempts to produce graphical representations of who talks to who on IRC channels An IRC Client Based On PircBot ScreenIRC IRC client with a Swing GUI Can be detached from a server and reconnected without appearing to have ever left Copyright Paul Mutton, http://www.jibble.org/pircbot.php 29 Copyright Paul Mutton, http://www.jibble.org/pircbot.php 30 5

Final Words... If you want to make your own IRC Bot that uses PircBot, then remember that these slides only provide a briefest glimpse into what you may need to know Refer to the API documentation that is included inside the zip file A good starting place is to read the documentation for the PircBot class Copyright Paul Mutton, http://www.jibble.org/pircbot.php 31 6