Results 1 to 7 of 7
- 03-05-2012, 06:11 PM #1
Member
- Join Date
- Feb 2012
- Posts
- 9
- Rep Power
- 0
Replying to a PING message in an IRC Bot.
I am making an IRC Bot. The thing is, IRC randomly sends PING messages. I need to filter these and reply to these PING messages with a PONG message.
An usual log of 1 minute is:
(Yes, I am a furry. Deal with it.)Java Code::coyote.furnet.org NOTICE AUTH :*** Looking up your hostname... :coyote.furnet.org NOTICE AUTH :*** Checking ident... :coyote.furnet.org NOTICE AUTH :*** Found your hostname :coyote.furnet.org NOTICE AUTH :*** No ident response; username prefixed with ~ PING :BF005A21 :coyote.furnet.org 451 SnowMurrTestUser :You have not registered
To successfully stay on the server you need to reply to the PING :BF005A21 message with a
PONG :BF005A21 message. The letters and numbers after the : is randomly generated. I figure i need too split the string.
However, i need the other messages to stay intact.
How will i do this?
- 03-05-2012, 06:22 PM #2
Moderator
- Join Date
- Apr 2009
- Posts
- 10,438
- Rep Power
- 16
Re: Replying to a PING message in an IRC Bot.
How are you reading the messages?
If line by line as they come in (which is what that looks like to me) then seeing if it's a PING shouldn't be a problem?Please do not ask for code as refusal often offends.
- 03-05-2012, 07:01 PM #3
Member
- Join Date
- Feb 2012
- Posts
- 9
- Rep Power
- 0
Re: Replying to a PING message in an IRC Bot.
I am reading them one-by-one as they drop in. I have no idea how I will identify if it is an PING message however.
EDIT: I now split them, but for some reason it does not acnowledge that the server sends the PING-command.
My Java Code:
The Log:Java Code:while (true) { //out.println(userInput); line = in.readLine(); if (line != null) { linearray = line.split(":"); System.out.println("PING :" + linearray[1]); //Debug to compare the lines if (linearray[0] == "PING ") { out.println("PONG :" + linearray[1]); System.out.println("Recieved Ping with ID " + linearray[1] + ". Sent PONG with ID " + linearray[1] + "!"); } else { System.out.println(line); } } }
Java Code:Opening connection to irc.furnet.org at port 6667... PING :coyote.furnet.org NOTICE AUTH :coyote.furnet.org NOTICE AUTH :*** Looking up your hostname... PING :coyote.furnet.org NOTICE AUTH :coyote.furnet.org NOTICE AUTH :*** Found your hostname (cached) PING :coyote.furnet.org NOTICE AUTH :coyote.furnet.org NOTICE AUTH :*** Checking ident... PING :coyote.furnet.org NOTICE AUTH :coyote.furnet.org NOTICE AUTH :*** No ident response; username prefixed with ~ PING :8C99AFE2 <----------- Same, that would trigger the PING :8C99AFE2 <----------- action and send "PONG :8C99AFE2" PING :coyote.furnet.org 451 SnowMurrTestUser :coyote.furnet.org 451 SnowMurrTestUser :You have not registered
Last edited by steamruler; 03-05-2012 at 08:48 PM.
- 03-06-2012, 09:47 AM #4
Moderator
- Join Date
- Apr 2009
- Posts
- 10,438
- Rep Power
- 16
Re: Replying to a PING message in an IRC Bot.
Never use '==' to compare objects. ALways (unless you really need to know if they are the same reference) use 'equals()'.Java Code:linearray[0] == "PING "
You could save a bit of processing on the JVMs behald by simply comparing the first 4 characters (using substring) before doing the split, as you are currently splitting lines which don't need to be split.Please do not ask for code as refusal often offends.
- 03-06-2012, 05:54 PM #5
Member
- Join Date
- Feb 2012
- Posts
- 9
- Rep Power
- 0
Re: Replying to a PING message in an IRC Bot.
Okay, done. I am still splitting the lines by the ":" because they are also used before messages (regular messages) recieved.
However, I keep getting an error here on line 5 (ArrayOutOfBoundsException):
The line being read when it is thrown is:Java Code:public static String CreateCompleteMessage(String[] Array) { Integer control = Array.length - 1; Integer beginningoffmessage = 2; //We guess it is 2. Bad practice, I know. Integer shuffling = beginningoffmessage + 1; String returnmessage = Array[beginningoffmessage]; PrintMessage(control.toString()); if (control.equals(beginningoffmessage) == false) { while (shuffling.equals(control) == false) { returnmessage = returnmessage.concat(":"); returnmessage = returnmessage.concat(Array[shuffling]); shuffling = shuffling + 1; } } return returnmessage; }
In order to debug: Split the string and feed it to the function.:foxtaur.furnet.org 003 SnowMurrTestUser :This server was created Sun Jan 31 2010 at 21:57:37 EST
Expected Output: "This server was created Sun Jan 31 2010 at 21:57:37 EST"
Help please :PLast edited by steamruler; 03-06-2012 at 05:56 PM.
- 03-06-2012, 06:12 PM #6
Moderator
- Join Date
- Apr 2009
- Posts
- 10,438
- Rep Power
- 16
Re: Replying to a PING message in an IRC Bot.
Use some printlns to see what the data is.
What is the value of 'control'.
What is the contents of 'Array' (which is a bad name, should be 'array' or preferably a more meaningful description based on what the code is operating on)?
Print that out (useing a for loop).Please do not ask for code as refusal often offends.
- 03-06-2012, 09:34 PM #7
Member
- Join Date
- Feb 2012
- Posts
- 9
- Rep Power
- 0
Re: Replying to a PING message in an IRC Bot.
Heh, got an idea before i saw you replied and remade the function!
Instead of trying to put together strings in a array i got the lenght of the strings i wanted gone and removed them from the string in the end!
No more problems right now, so I consider this solved!Java Code:public static String CreateCompleteMessage(String[] stringarray, String OriginalMessage) { Integer letterno0 = stringarray[0].length(); Integer letterno1 = stringarray[1].length(); Integer letterstoremove = letterno0 + letterno1 + 1; // The extra 1 is to justify the ":" in the beginning of every message. String returnmessage = OriginalMessage.substring(letterstoremove); return returnmessage; }
Similar Threads
-
[Error] Reading mails and replying at the same time
By ravjot28 in forum NetworkingReplies: 23Last Post: 09-24-2010, 08:12 AM -
java message box, how to not show multiple message box with same title or content
By oohay in forum AWT / SwingReplies: 6Last Post: 06-04-2010, 08:43 PM -
Cannot perform a PING
By mnementh64 in forum NetworkingReplies: 1Last Post: 09-17-2009, 04:39 PM -
ping
By Arunmathi in forum JCreatorReplies: 0Last Post: 08-28-2009, 08:24 PM -
ping cmd
By kishi in forum Advanced JavaReplies: 2Last Post: 11-14-2007, 03:27 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks