Skip to content
This repository has been archived by the owner on May 30, 2019. It is now read-only.

Read server's ISUPPORT and get prefix there #101

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 30 additions & 5 deletions application/src/main/java/indrora/atomic/irc/IRCConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@
import java.util.Collection;
import java.util.Comparator;
import java.util.Date;
import java.util.HashMap;
import java.util.Vector;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.jibble.pircbot.NickAlreadyInUseException;
Expand All @@ -65,6 +67,10 @@ public class IRCConnection extends PircBot {
private ArrayList<String> autojoinChannels;
private Pattern mNickMatch;

private final Pattern isupportSpecial = Pattern.compile("\\\\x(\\p{XDigit}{2})");
private final HashMap<String,String> isupport = new HashMap<>();
private String prefixes = "+%@&~";

private boolean ignoreMOTD = true;
private boolean debugTraffic = false;
private boolean isQuitting = false;
Expand Down Expand Up @@ -1140,6 +1146,28 @@ protected void onServerResponse(int code, String response) {
onRegister();
return;
}
if( code == 5 ) {
// Parse isupport (https://tools.ietf.org/html/draft-brocklesby-irc-isupport-03)
String[] options = response.substring(response.indexOf(' ') + 1).split(" "); // Strip nick and split
for( String option : options ) {
String[] spl = option.split("=", 2);
StringBuffer value = new StringBuffer();

Matcher m = isupportSpecial.matcher(spl[1]);
while( m.find() ) {
int codePoint = Integer.parseInt(m.group(1), 16);
m.appendReplacement(value, String.valueOf((char) codePoint));
}
m.appendTail(value);

isupport.put(spl[0], value.toString());

if( "PREFIX".equalsIgnoreCase(spl[0]) ) {
prefixes = value.substring(value.indexOf(")") + 1);
}
}

}
if( (code == 372 || code == 375) && ignoreMOTD ) {
return;
}
Expand Down Expand Up @@ -1277,12 +1305,9 @@ public String[] getUsersAsStringArray(String channel) {

/* Sort the users by their modes, then their nicknames */
Arrays.sort(users, new Comparator<String>() {
/* Mode list (order: lowest to highest) */
public static final String modes = "+%@&~";

public int compare(String s1, String s2) {
int i1 = modes.indexOf(s1.charAt(0));
int i2 = modes.indexOf(s2.charAt(0));
int i1 = prefixes.indexOf(s1.charAt(0));
int i2 = prefixes.indexOf(s2.charAt(0));

if( i1 == i2 ) {
/* Resort to a case-insensitive comparison */
Expand Down
2 changes: 2 additions & 0 deletions application/src/main/java/org/jibble/pircbot/PircBot.java
Original file line number Diff line number Diff line change
Expand Up @@ -1000,6 +1000,8 @@ protected void handleLine(String line) throws NickAlreadyInUseException, IOExcep

StringTokenizer tokenizer = new StringTokenizer(line);
String senderInfo = tokenizer.nextToken();
if (senderInfo.startsWith("@"))
senderInfo = tokenizer.nextToken();
String command = tokenizer.nextToken();
String target = null;

Expand Down