[ictk-cvs] ictk/src/ictk/boardgame/chess/net/ics/fics FICSProtocolHandler.java,1.22,1.23
chess library in java, PGN, FEN, ICS
Brought to you by:
jvarsoke
|
From: <jva...@us...> - 2003-09-30 17:27:42
|
Update of /cvsroot/ictk/ictk/src/ictk/boardgame/chess/net/ics/fics
In directory sc8-pr-cvs1:/tmp/cvs-serv13891/src/ictk/boardgame/chess/net/ics/fics
Modified Files:
FICSProtocolHandler.java
Log Message:
Challenge event also knows of "abuser" status now.
Index: FICSProtocolHandler.java
===================================================================
RCS file: /cvsroot/ictk/ictk/src/ictk/boardgame/chess/net/ics/fics/FICSProtocolHandler.java,v
retrieving revision 1.22
retrieving revision 1.23
diff -C2 -d -r1.22 -r1.23
*** FICSProtocolHandler.java 30 Sep 2003 10:40:41 -0000 1.22
--- FICSProtocolHandler.java 30 Sep 2003 17:27:37 -0000 1.23
***************
*** 57,60 ****
--- 57,61 ----
protected int SOCKET_DELAY = 1000;
+ //FIXME: this stuff is WAY too server specific
protected String LOGIN_PROMPT = "login:",
PASSWD_PROMPT = "password:",
***************
*** 68,105 ****
//common regex phrases
protected final static String REGEX_handle = "([\\w]+)",
! REGEX_acct_type = "(\\(\\S*\\))?",
! REGEX_rating = "\\(\\s*([0-9+-]+[EP]?)\\)";
!
! //NEED: RATING - UNR is a possiblity
!
! //colors
! public final static char ESC = '\u001B';
! public final static String BLACK = "[0;30",
! RED = "[0;31m",
! GREEN = "[0;32m",
! YELLOW = "[0;33m",
! BLUE = "[0;34m",
! MAGENTA = "[0;35m",
! CYAN = "[0;36m",
! WHITE = "[0;37m",
! BOLD_BLACK = "[1;30m",
! BOLD_RED = "[1;31m",
! BOLD_GREEN = "[1;32m",
! BOLD_YELLOW = "[1;33m",
! BOLD_BLUE = "[1;34m",
! BOLD_MAGENTA = "[1;35m",
! BOLD_CYAN = "[1;36m",
! BOLD_WHITE = "[1;37m",
! PLAIN = "[0;m";
! static final protected Pattern
! takebackPattern,
! availInfoPattern;
final protected ICSEventParser[] eventFactories;
- /** Telnet connection to server */
- // boolean loggedIn = false;
-
/** is block_mode turned on for the server protocol. */
boolean isBlockMode = false;
--- 69,81 ----
//common regex phrases
protected final static String REGEX_handle = "([\\w]+)",
! REGEX_acct_type = "(\\(\\S*\\))?";
! //FIXME: RATING - UNR is a possiblity
+ /** parsers for various events from the server.
+ ** The order of the parsers should be optimized by frequency
+ ** of events. */
final protected ICSEventParser[] eventFactories;
/** is block_mode turned on for the server protocol. */
boolean isBlockMode = false;
***************
*** 113,150 ****
CharBuffer buffer = CharBuffer.allocate(BUFFER_SIZE);
- //constructor//////////////////////////////////////////////////////////
- static {
- //patterns
- takebackPattern = Pattern.compile("^(" //beginning
- + REGEX_handle //player
- + "\\swould like to take back\\s"
- + "(\\d+)" //number of half moves
- + "\\shalf move\\(s\\)\\."
- + ")" //end match
- , Pattern.MULTILINE | Pattern.DOTALL);
-
- availInfoPattern = Pattern.compile("^(" //beginning
- + REGEX_handle //player
- + REGEX_acct_type
- + "\\s"
- + "(Blitz\\s?"
- + REGEX_rating
- + ", Std\\s?"
- + REGEX_rating
- + ", Wild\\s?"
- + REGEX_rating
- + ", Light\\s?"
- + REGEX_rating
- + ", Bug\\s?"
- + REGEX_rating
- + ")?"
- + ".*is"
- + "(.+)" //"now" or "no longer"
- + "\\savailable for matches\\."
- + ")"
- , Pattern.MULTILINE | Pattern.DOTALL);
- }
-
-
//constructors/////////////////////////////////////////////////////////////
public FICSProtocolHandler () {
--- 89,92 ----
***************
*** 393,399 ****
//isBlockMode = true;
sendCommand("set prompt", false);
- sendCommand("set interface " + INTERFACE_NAME, false);
- sendCommand("iset ms 1", false);
sendCommand("set style 12", false);
sendCommand("set bell 0", false);
}
--- 335,341 ----
//isBlockMode = true;
sendCommand("set prompt", false);
sendCommand("set style 12", false);
+ sendCommand("iset ms 1", false);
+ sendCommand("set interface " + INTERFACE_NAME, false);
sendCommand("set bell 0", false);
}
***************
*** 427,438 ****
while ((b = in.read()) != -1) {
! //FIXME: diagnostics
//out of range invisible characters
//10 is \n
//13 is \r ?
if (b!= 10 && b!=13 && (b < 32 || b > 126)) {
String foo = "[" + b + "]";
for (int z=0;z<foo.length();z++)
buffer.put(foo.charAt(z));
}
--- 369,382 ----
while ((b = in.read()) != -1) {
! //diagnostics
//out of range invisible characters
//10 is \n
//13 is \r ?
if (b!= 10 && b!=13 && (b < 32 || b > 126)) {
+ /*
String foo = "[" + b + "]";
for (int z=0;z<foo.length();z++)
buffer.put(foo.charAt(z));
+ */
}
***************
*** 476,480 ****
e.printStackTrace();
}
- //System.out.println("FICSProtocolHandler: socket connection closed");
}
--- 420,423 ----
***************
*** 593,597 ****
e.printStackTrace();
}
- //System.out.println("FICSProtocolHandler: socket connection closed");
}
--- 536,539 ----
***************
*** 660,670 ****
}
! if (found) { /*no-op*/ }
! else if ((matcher = match(takebackPattern, str)) != null)
! sendTakeBackEvent(matcher);
! else if ((matcher = match(availInfoPattern, str)) != null)
! sendAvailInfoEvent(matcher);
!
! else
System.out.println(str);
--- 602,606 ----
}
! if (!found)
System.out.println(str);
***************
*** 679,682 ****
--- 615,619 ----
}
+ /*
protected Matcher match (Pattern p, CharSequence str) {
Matcher m = null;
***************
*** 688,694 ****
return null;
}
//parseResponse/////////////////////////////////////////////////////////////
! protected void parseResponse (int id, int cmd, CharSequence str) {
/*
ICSEvent icsEvent = null;
--- 625,634 ----
return null;
}
+ */
//parseResponse/////////////////////////////////////////////////////////////
! /** <b>used for blockmode, currently disabled</b>
! */
! private void parseResponse (int id, int cmd, CharSequence str) {
/*
ICSEvent icsEvent = null;
***************
*** 720,753 ****
+ str.toString() + "</BLOCK>");
*/
- }
-
-
- //actions//////////////////////////////////////////////////////////////////
- protected void sendConnectionEvent (Matcher m) {
- System.out.println(ESC + BOLD_BLACK + m.group() + ESC + PLAIN);
- }
-
- protected void sendBoardEvent (Matcher m) {
- System.out.println(ESC + YELLOW + m.group() + ESC + PLAIN);
- }
-
- protected void sendMoveListEvent (Matcher m) {
- System.out.println(ESC + YELLOW + m.group() + ESC + PLAIN);
- debugGroupDump(m);
- }
-
- protected void sendTakeBackEvent (Matcher m) {
- System.out.println(ESC + RED + m.group() + ESC + PLAIN);
- }
-
- protected void sendAvailInfoEvent (Matcher m) {
- System.out.println(ESC + BOLD_BLACK + m.group() + ESC + PLAIN);
- }
-
- //debug functions////////////////////////////////////////////////////////
- private void debugGroupDump (Matcher m) {
- for(int i=0; i<=m.groupCount(); i++) {
- System.out.println(i + ": " + m.group(i));
- }
}
}
--- 660,663 ----
|