Changeset 25703
- Timestamp:
- 12/02/08 20:43:03 (5 weeks ago)
- Location:
- lang/java/IRCKit/trunk/src/com/mac/tarchan/irc/client
- Files:
-
- 1 added
- 2 modified
-
IRCClient.java (modified) (3 diffs)
-
IRCConsole.java (added)
-
IRCNetwork.java (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
lang/java/IRCKit/trunk/src/com/mac/tarchan/irc/client/IRCClient.java
r25169 r25703 10 10 import java.net.MalformedURLException; 11 11 import java.util.ArrayList; 12 import java.util.Properties; 12 13 13 14 /** … … 17 18 public class IRCClient 18 19 { 19 /**20 * @param args21 */22 public static void main(String[] args)23 {24 System.out.println("Welcome to IRCKit!");25 try26 {27 IRCClient irc = new IRCClient();28 irc.setUseSystemProxies(true);29 irc.registerHandler(new IRCMessageHandler()30 {31 /**32 * 受信したメッセージを表示します。33 *34 * @param msg メッセージ35 */36 public void privmsg(IRCMessage msg)37 {38 // TODO 受信したメッセージを表示39 }40 });41 irc.registerNetwork("tokyo", "http://irc.tokyo.wide.ad.jp:6667", "tarchan", "");42 // irc.registerNetwork("tokyo", "http://irc.mozilla.org:6667", "tarchan", "");43 irc.join("tokyo", "#dameTunes", "");44 irc.privmsg("tokyo", "#dameTunes", "テスト");45 irc.quit();46 }47 catch (MalformedURLException e)48 {49 e.printStackTrace();50 }51 52 53 54 // try55 // {56 // BufferedReader in = new BufferedReader(new InputStreamReader(System.in));57 // while (true)58 // {59 // String input = in.readLine();60 // System.out.println("echo: " + input);61 // }62 // }63 // catch (IOException e)64 // {65 // e.printStackTrace();66 // }67 }68 69 20 /** メッセージハンドラ */ 70 21 protected ArrayList<IRCMessageHandler> handlers = new ArrayList<IRCMessageHandler>(); … … 80 31 System.out.println("java.version=" + ver); 81 32 System.setProperty("java.net.useSystemProxies", Boolean.valueOf(useSystemProxies).toString()); 33 } 34 35 /** 36 * デフォルトのプロパティーを返します。 37 * 38 * @return デフォルトのプロパティー 39 */ 40 public Properties createDefaultProperties() 41 { 42 return IRCNetwork.createDefaultProperties(); 82 43 } 83 44 -
lang/java/IRCKit/trunk/src/com/mac/tarchan/irc/client/IRCNetwork.java
r25169 r25703 306 306 protected URL url; 307 307 308 /** ユーザプロパティー */ 309 protected Properties prof; 310 308 311 /** ユーザ名 */ 309 312 protected String username; 310 313 311 314 /** パスワード */ 312 protected String pas word;315 protected String password; 313 316 314 317 /** … … 316 319 * 317 320 * @param address サーバアドレス 318 * @param username ユーザ名 319 * @param password パスワード 321 * @param prof ユーザプロパティー 320 322 * @throws IllegalArgumentException 指定された文字列が RFC 2396 に違反する場合 321 323 * @throws MalformedURLException URL のプロトコルハンドラが見つからなかった場合、または URL の構築中にその他の何らかのエラーが発生した場合 322 324 */ 323 public IRCNetwork(String address, String username, String password) throws MalformedURLException325 public IRCNetwork(String address, Properties prof) throws MalformedURLException 324 326 { 325 327 URI uri = URI.create(address); 326 328 url = uri.toURL(); 327 this.username = username; 328 this.pasword = password; 329 this.prof = prof; 329 330 System.out.println("host=" + url.getHost() + ", port=" + url.getPort()); 331 } 332 333 /** 334 * デフォルトのプロパティーを返します。 335 * 336 * @return デフォルトのプロパティー 337 */ 338 public static Properties createDefaultProperties() 339 { 340 Properties def = new Properties(); 341 String username = System.getProperty("user.name"); 342 def.setProperty("irc.user.name", username); 343 def.setProperty("irc.user.password", ""); 344 def.setProperty("irc.user.mode", "0"); 345 def.setProperty("irc.nick.name", username); 346 def.setProperty("irc.real.name", username); 347 348 return new Properties(def); 330 349 } 331 350 … … 342 361 public static void register(String groupName, String address, String username, String password) throws MalformedURLException 343 362 { 344 IRCNetwork network = new IRCNetwork(address, username, password); 363 Properties prof = createDefaultProperties(); 364 prof.setProperty("irc.user.name", username); 365 prof.setProperty("irc.real.name", username); 366 prof.setProperty("irc.nick.name", username); 367 prof.setProperty("irc.user.password", password); 368 IRCNetwork network = new IRCNetwork(address, prof); 345 369 groups.put(groupName, network); 346 370 } … … 378 402 */ 379 403 public void login() throws IOException 404 { 405 String username = prof.getProperty("irc.user.name"); 406 String password = prof.getProperty("irc.user.password"); 407 int mode = Integer.parseInt(prof.getProperty("irc.user.mode")); 408 String realname = prof.getProperty("irc.real.name"); 409 String nickname = prof.getProperty("irc.nick.name"); 410 login(username, password, mode, realname, nickname); 411 } 412 413 /** 414 * IRC ネットワークを接続します。 415 * 416 * @param username ユーザ名 417 * @param password パスワード 418 * @param mode 接続モード 419 * @param realname 本名 420 * @param nickname ニックネーム 421 * @throws IOException 接続エラーが発生した場合 422 */ 423 public void login(String username, String password, int mode, String realname, String nickname) throws IOException 380 424 { 381 425 // TODO IRCサーバに接続 382 426 System.out.println("connect to " + url); 383 427 URLConnection conn = url.openConnection(); 428 System.out.println("conn=" + conn); 384 429 conn.setDoInput(true); 385 430 conn.setDoOutput(true); 431 conn.connect(); 386 432 // TODO IRCサーバにログイン 387 PrintWriter out = new PrintWriter(new OutputStreamWriter(conn.getOutputStream()), true); 388 if (pasword != null && pasword.trim().length() > 0) out.printf(PASS + CRLF, pasword); 433 PrintWriter out = new PrintWriter(new OutputStreamWriter(conn.getOutputStream(), "ISO-2022-JP"), true); 434 if (password.trim().length() > 0) out.printf(PASS + CRLF, password); 435 out.flush(); 389 436 out.printf(NICK + CRLF, username); 437 out.flush(); 390 438 out.printf(USER + CRLF, username, 0, username); 391 //out.flush();439 out.flush(); 392 440 BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream())); 393 441 while (true)
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)