Jump to content
Frequently Asked Questions
  • Are you not able to open the client? Try following our getting started guide
  • Still not working? Try downloading and running JarFix
  • Help! My bot doesn't do anything! Enable fresh start in client settings and restart the client
  • How to purchase with PayPal/OSRS/Crypto gold? You can purchase vouchers from other users
  • IRC Listener / Botcontrol


    Roma

    Recommended Posts

    Edit: reuploaded image.

     

    It spares you time, instead of writing a CP/chat room for your farm you can use IRC. Or if you need to receive information from your bots, for example wildy scouts, this way of transfering information is much better than using clan chats.

    • helps you to control your bots (stop, pause etc);
    • you can change script settings by sending commands (change attack style, food etc);
    • you can get information from your bots (current levels, runtime etc).

    It is extremly usefull if you are running a massive bot farm.

     

    fYbDQyS.png

     

    It supports channel messages, private messages and notices. You can also get the whole server message, channel message, sender and so on.

     

    Usage:

       public class MyClass 
                    extends AbstractScript
                    implements IRCListener { 
    
        public static IRCConnection connection;
    
        @Override
        public void onStart() {
            connection = new IRCConnection("#mychannel");
            connection.addListener(this);
            connection.start();
        }
    
        @Override
        public void onExit() {
            connection.closeConnection();
        }
    
        @Override
        public void messageReceived(IRCMessage message) {
            String msg = message.getMessage();
            String sender = message.getSender();
    
            if (sender.equals("your_name")) {
                if (msg.equals(".strlvl")) {
                    connection.sendChannelMessage("My str lvl is " + getSkills().getRealLevel(Skill.STRENGTH));
                } else if (msg.equals(".stopscript")) {
                    getClient().getInstance().getScriptManager().stop();
                }
            }
        }
    }

    Source:

    IRCConnection:

    /**
    * Created by Roma on 21.11.2015
    *
    */
    public class IRCConnection
            extends Thread {
    
        BufferedWriter writer;
        private String server = "irc.SwiftIRC.net";
        Socket socket;
        private boolean running = true;
    
        private ArrayList<IRCListener> listeners;
        private String username;
        private String channel;
        private String channelPassword;
    
        public IRCConnection(String channel) {
            this.listeners = new ArrayList<>();
            this.channel = channel;
            this.username = generateIRCName();
            this.channelPassword = "";
        }
    
        public IRCConnection(String channel, String channelPassword) {
            this.listeners = new ArrayList<>();
            this.channel = channel;
            this.username = generateIRCName();
            this.channelPassword = channelPassword;
        }
    
        public IRCConnection(String username, String channel, String channelPassword){
            this.listeners = new ArrayList<>();
            this.username = username;
            this.channel = channel;
            this.channelPassword = channelPassword;
        }
    
        public IRCConnection(String server, String username, String channel, String channelPassword){
            this.listeners = new ArrayList<>();
            this.channel = channel;
            this.username = username;
            this.server = server;
            this.channelPassword = channelPassword;
        }
    
        @Override
        public void run(){
            try {
                socket = new Socket(server, 6667);
                writer = new BufferedWriter(
                        new OutputStreamWriter(socket.getOutputStream()));
                BufferedReader reader = new BufferedReader(
                        new InputStreamReader(socket.getInputStream()));
    
                writer.write("NICK " + username + "\r\n");
                writer.write("USER " + username + " 8 * : IRC bot\r\n");
                writer.flush();
    
                final long timeout = System.currentTimeMillis() + 10000;
    
                String line;
                while ((line = reader.readLine()) != null) {
                    if (System.currentTimeMillis() >= timeout) {
                        MethodContext.log("Connection timed out");
                        break;
                    }
                    if (line.contains("004")) {
                        break;
                    } else if (line.contains("433")) {
                        MethodContext.log("Nickname is already in use");
                        return;
                    }
                }
    
                writer.write("JOIN " + channel + " " + channelPassword + "\r\n");
                writer.flush();
    
                while ((line = reader.readLine()) != null) {
                    if(!running)
                        break;
    
                    if(line.contains("PING ")) {
                        writer.write("PONG " + line.substring(5) + "\n");
                        writer.flush();
                    } else {
                        addTrigger(new IRCMessage(line));
                    }
                }
            } catch(Exception e) {
                e.printStackTrace();
            }
        }
    
        public void addListener(IRCListener ircListener) { listeners.add(ircListener); }
    
        public void removeListener(IRCListener ircListener) { listeners.remove(ircListener); }
    
        private void addTrigger(IRCMessage message){
            for (IRCListener listener : listeners)
                listener.messageReceived(message);
        }
    
        public void closeConnection() {
            MethodContext.log("Closing connection");
            while (!socket.isClosed()) {
                try {
                    socket.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            running = false;
    
            MethodContext.log("Connection closed");
        }
    
        private void send(String buffer) {
            try {
                this.writer.write(buffer);
                this.writer.flush();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    
        public void sendChannelMessage(String message) { this.send("PRIVMSG " + this.channel + " :" + message + "\n"); }
    
        public void sendPrivateMessage(String name, String message) { this.send("PRIVMSG " + name + " :" + message + "\n"); }
    
        public void sendNotice(String target, String message) { this.send("NOTICE " + target + " :" + message + "\n"); }
    
        private String getRSN() {
            return Client.getClient().getLocalPlayer().getName();
        }
    
        private String generateIRCName() {
            String outputName;
            int t = 0;
            for (int i = 0; i < getRSN().length(); i++) {
                if(Character.isDigit(getRSN().charAt(i)))
                    t++;
                else
                    break;
            }
            outputName = getRSN().substring(t);
    
            if (outputName.contains(" "))
                outputName = outputName.replaceAll(" ", "_");
    
            return outputName;
        }
    }
    

    IRCListener:

    public interface IRCListener {
        void messageReceived(IRCMessage message);
    }
    

    IRCMessage:

    public class IRCMessage {
    
        private String message;
    
        public IRCMessage(String message) { this.message = message; }
    
        public String getServerMessage() { return this.message; }
    
        public String getFormatedMessage() { return getSender() + ": "+ getMessage(); }
    
        public String getSender() { return this.message.split("!~")[0].replace(":", ""); }
    
        public String getMessage() { return this.message.split(" :")[1]; }
    }
    
    
    Link to comment
    Share on other sites

    I wanted to use IRC first but I also wanted to learn more about coding, thats why I went with writing my own Server and Client :P Also when writing your own Server you can have it do the stuff rathee than hooking another irc client up that listens to stuff. 

    Anyways, nice one :)

    Link to comment
    Share on other sites

    I wanted to use IRC first but I also wanted to learn more about coding, thats why I went with writing my own Server and Client :P Also when writing your own Server you can have it do the stuff rathee than hooking another irc client up that listens to stuff. 

    Anyways, nice one :)

    Seen your project it looks cool, i had a similar bot control in 2014~, this is a lazy version  :D

    I will graduade from universtiry in a few days and my project is a big client-server app  :)

    Link to comment
    Share on other sites

    Seen your project it looks cool, i had a similar bot control in 2014~, this is a lazy version  :D

    I will graduade from universtiry in a few days and my project is a big client-server app  :)

    Slasso is working on something like this :)

    Link to comment
    Share on other sites

    • 2 years later...

    @Roma Hi mate, sorry for the gravedig. I have noticed that this is not working anymore. Now the irc server sends a ping to me with a hash, which i assume i must reply to with Pong. However I cannot think where to move this code to to get it working again. Could you share some advice for a newbie?

    Link to comment
    Share on other sites

    Archived

    This topic is now archived and is closed to further replies.

    ×
    ×
    • Create New...

    Important Information

    We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.