|
@@ -168,33 +168,6 @@ public class DCCManager implements ActionListener {
|
168
|
168
|
return domain;
|
169
|
169
|
}
|
170
|
170
|
|
171
|
|
- /**
|
172
|
|
- * Ask a question, if the answer is the answer required, then recall handleProcessEvent.
|
173
|
|
- *
|
174
|
|
- * @param question Question to ask
|
175
|
|
- * @param title Title of question dialog
|
176
|
|
- * @param desiredAnswer Answer required
|
177
|
|
- * @param type Actiontype to pass back
|
178
|
|
- * @param format StringBuffer to pass back
|
179
|
|
- * @param arguments arguments to pass back
|
180
|
|
- */
|
181
|
|
- public void askQuestion(final String question, final String title,
|
182
|
|
- final int desiredAnswer, final ActionType type,
|
183
|
|
- final StringBuffer format, final Object... arguments) {
|
184
|
|
- // New thread to ask the question in to stop us locking the UI
|
185
|
|
- new Thread(new Runnable() {
|
186
|
|
-
|
187
|
|
- @Override
|
188
|
|
- public void run() {
|
189
|
|
- final int result = JOptionPane.showConfirmDialog(null, question,
|
190
|
|
- title, JOptionPane.YES_NO_OPTION);
|
191
|
|
- if (result == desiredAnswer) {
|
192
|
|
- handleProcessEvent(type, format, true, arguments);
|
193
|
|
- }
|
194
|
|
- }
|
195
|
|
- }, "QuestionThread: " + title).start();
|
196
|
|
- }
|
197
|
|
-
|
198
|
171
|
/**
|
199
|
172
|
* Ask the location to save a file, then start the download.
|
200
|
173
|
*
|
|
@@ -402,10 +375,10 @@ public class DCCManager implements ActionListener {
|
402
|
375
|
if ("DCC".equalsIgnoreCase((String) arguments[2])) {
|
403
|
376
|
if ("chat".equalsIgnoreCase(ctcpData[0])
|
404
|
377
|
&& ctcpData.length > 3) {
|
405
|
|
- handleChat(type, format, dontAsk, ctcpData, arguments);
|
|
378
|
+ handleChat(dontAsk, ctcpData, arguments);
|
406
|
379
|
} else if ("send".equalsIgnoreCase(ctcpData[0])
|
407
|
380
|
&& ctcpData.length > 3) {
|
408
|
|
- handleSend(type, format, dontAsk, ctcpData, arguments);
|
|
381
|
+ handleSend(dontAsk, ctcpData, arguments);
|
409
|
382
|
} else if (("resume".equalsIgnoreCase(ctcpData[0])
|
410
|
383
|
|| "accept".equalsIgnoreCase(ctcpData[0]))
|
411
|
384
|
&& ctcpData.length > 2) {
|
|
@@ -418,64 +391,59 @@ public class DCCManager implements ActionListener {
|
418
|
391
|
/**
|
419
|
392
|
* Handles a DCC chat request.
|
420
|
393
|
*
|
421
|
|
- * @param type The type of the event to process
|
422
|
|
- * @param format Format of messages that are about to be sent. (May be null)
|
423
|
394
|
* @param dontAsk Don't ask any questions, assume yes.
|
424
|
395
|
* @param ctcpData CTCP data bits
|
425
|
396
|
* @param arguments The arguments for the event
|
426
|
397
|
*/
|
427
|
|
- private void handleChat(final ActionType type, final StringBuffer format,
|
428
|
|
- final boolean dontAsk, final String[] ctcpData,
|
|
398
|
+ private void handleChat(final boolean dontAsk, final String[] ctcpData,
|
429
|
399
|
final Object... arguments) {
|
430
|
400
|
final String nickname = ((ClientInfo) arguments[1]).getNickname();
|
431
|
401
|
if (dontAsk) {
|
432
|
|
- final DCCChat chat = new DCCChat();
|
433
|
|
- try {
|
434
|
|
- chat.setAddress(Long.parseLong(ctcpData[2]),
|
435
|
|
- Integer.parseInt(ctcpData[3]));
|
436
|
|
- } catch (NumberFormatException nfe) {
|
437
|
|
- return;
|
438
|
|
- }
|
439
|
|
- final String myNickname = ((Connection) arguments[0]).getParser()
|
440
|
|
- .getLocalClient().getNickname();
|
441
|
|
- final DCCFrameContainer f = new ChatContainer(
|
442
|
|
- getContainer(),
|
443
|
|
- chat,
|
444
|
|
- config,
|
445
|
|
- commandController,
|
446
|
|
- "Chat: " + nickname,
|
447
|
|
- myNickname,
|
448
|
|
- nickname,
|
449
|
|
- tabCompleterFactory,
|
450
|
|
- messageSinkManager,
|
451
|
|
- urlBuilder,
|
452
|
|
- eventBus);
|
453
|
|
- windowManager.addWindow(getContainer(), f);
|
454
|
|
- f.addLine("DCCChatStarting", nickname, chat.getHost(),
|
455
|
|
- chat.getPort());
|
456
|
|
- chat.connect();
|
|
402
|
+ handleDCCChat(((Connection) arguments[0]).getParser(), nickname, ctcpData);
|
457
|
403
|
} else {
|
458
|
404
|
eventBus.post(new DccChatRequestEvent((Connection) arguments[0], nickname));
|
459
|
|
- askQuestion("User " + nickname + " on "
|
460
|
|
- + ((Connection) arguments[0]).getAddress()
|
461
|
|
- + " would like to start a DCC Chat with you.\n\n"
|
462
|
|
- + "Do you want to continue?",
|
463
|
|
- "DCC Chat Request", JOptionPane.YES_OPTION,
|
464
|
|
- type, format, arguments);
|
|
405
|
+ new ChatRequestDialog(mainWindow, this, (Connection) arguments[0], nickname, ctcpData)
|
|
406
|
+ .display();
|
465
|
407
|
}
|
466
|
408
|
}
|
467
|
409
|
|
|
410
|
+ void handleDCCChat(final Parser parser, final String nickname, final String[] ctcpData) {
|
|
411
|
+ long ipAddress;
|
|
412
|
+ int port;
|
|
413
|
+ try {
|
|
414
|
+ ipAddress = Long.parseLong(ctcpData[2]);
|
|
415
|
+ port = Integer.parseInt(ctcpData[3]);
|
|
416
|
+ } catch (NumberFormatException nfe) {
|
|
417
|
+ return;
|
|
418
|
+ }
|
|
419
|
+ final DCCChat chat = new DCCChat();
|
|
420
|
+ chat.setAddress(ipAddress, port);
|
|
421
|
+ final String myNickname = parser.getLocalClient().getNickname();
|
|
422
|
+ final DCCFrameContainer f = new ChatContainer(
|
|
423
|
+ getContainer(),
|
|
424
|
+ chat,
|
|
425
|
+ config,
|
|
426
|
+ commandController,
|
|
427
|
+ "Chat: " + nickname,
|
|
428
|
+ myNickname,
|
|
429
|
+ nickname,
|
|
430
|
+ tabCompleterFactory,
|
|
431
|
+ messageSinkManager,
|
|
432
|
+ urlBuilder,
|
|
433
|
+ eventBus);
|
|
434
|
+ windowManager.addWindow(getContainer(), f);
|
|
435
|
+ f.addLine("DCCChatStarting", nickname, chat.getHost(), chat.getPort());
|
|
436
|
+ chat.connect();
|
|
437
|
+ }
|
|
438
|
+
|
468
|
439
|
/**
|
469
|
440
|
* Handles a DCC send request.
|
470
|
441
|
*
|
471
|
|
- * @param type The type of the event to process
|
472
|
|
- * @param format Format of messages that are about to be sent. (May be null)
|
473
|
442
|
* @param dontAsk Don't ask any questions, assume yes.
|
474
|
443
|
* @param ctcpData CTCP data bits
|
475
|
444
|
* @param arguments The arguments for the event
|
476
|
445
|
*/
|
477
|
|
- private void handleSend(final ActionType type, final StringBuffer format,
|
478
|
|
- final boolean dontAsk, final String[] ctcpData,
|
|
446
|
+ private void handleSend(final boolean dontAsk, final String[] ctcpData,
|
479
|
447
|
final Object... arguments) {
|
480
|
448
|
final String nickname = ((ClientInfo) arguments[1]).getNickname();
|
481
|
449
|
final String filename;
|
|
@@ -530,51 +498,47 @@ public class DCCManager implements ActionListener {
|
530
|
498
|
&& !ctcpData[i + 1].equals("T")) ? ctcpData[++i] : "";
|
531
|
499
|
|
532
|
500
|
// Ignore incorrect ports, or non-numeric IP/Port
|
|
501
|
+ long ipLong;
|
|
502
|
+ int portInt;
|
533
|
503
|
try {
|
534
|
|
- final int portInt = Integer.parseInt(port);
|
|
504
|
+ portInt = Integer.parseInt(port);
|
535
|
505
|
if (portInt > 65535 || portInt < 0) {
|
536
|
506
|
return;
|
537
|
507
|
}
|
538
|
|
- Long.parseLong(ip);
|
|
508
|
+ ipLong = Long.parseLong(ip);
|
539
|
509
|
} catch (NumberFormatException nfe) {
|
540
|
510
|
return;
|
541
|
511
|
}
|
542
|
512
|
|
543
|
|
- DCCTransfer send = DCCTransfer.findByToken(token);
|
544
|
|
-
|
545
|
|
- if (send == null && !dontAsk) {
|
|
513
|
+ if (DCCTransfer.findByToken(token) == null && !dontAsk) {
|
546
|
514
|
if (!token.isEmpty() && !port.equals("0")) {
|
547
|
515
|
// This is a reverse DCC Send that we no longer care about.
|
548
|
516
|
} else {
|
549
|
517
|
eventBus.post(
|
550
|
518
|
new DccSendRequestEvent((Connection) arguments[0], nickname, filename));
|
551
|
|
- askQuestion("User " + nickname + " on "
|
552
|
|
- + ((Connection) arguments[0]).getAddress()
|
553
|
|
- + " would like to send you a file over DCC.\n\nFile: "
|
554
|
|
- + filename + "\n\nDo you want to continue?",
|
555
|
|
- "DCC Send Request", JOptionPane.YES_OPTION, type,
|
556
|
|
- format, arguments);
|
|
519
|
+ new SendRequestDialog(mainWindow, this, token, ipLong, portInt, filename, size,
|
|
520
|
+ nickname, (Connection) arguments[0]).display();
|
557
|
521
|
}
|
|
522
|
+ }
|
|
523
|
+ }
|
|
524
|
+
|
|
525
|
+ void handleDCCSend(final String token, final long ip, final int port, final String filename,
|
|
526
|
+ final long size, final String nickname, final Parser parser) {
|
|
527
|
+ DCCTransfer send = DCCTransfer.findByToken(token);
|
|
528
|
+ final boolean newSend = send == null;
|
|
529
|
+ if (newSend) {
|
|
530
|
+ send = new DCCTransfer(config.getOptionInt(getDomain(), "send.blocksize"));
|
|
531
|
+ send.setTurbo(config.getOptionBool(getDomain(), "send.forceturbo"));
|
558
|
532
|
} else {
|
559
|
|
- final boolean newSend = send == null;
|
560
|
|
- if (newSend) {
|
561
|
|
- send = new DCCTransfer(config.getOptionInt(getDomain(),
|
562
|
|
- "send.blocksize"));
|
563
|
|
- send.setTurbo(config.getOptionBool(getDomain(), "send.forceturbo"));
|
564
|
|
- }
|
565
|
|
- try {
|
566
|
|
- send.setAddress(Long.parseLong(ip), Integer.parseInt(port));
|
567
|
|
- } catch (NumberFormatException nfe) {
|
568
|
|
- return;
|
569
|
|
- }
|
570
|
|
- if (newSend) {
|
571
|
|
- send.setFileName(filename);
|
572
|
|
- send.setFileSize(size);
|
573
|
|
- saveFile(nickname, send, ((Connection) arguments[0]).getParser(),
|
574
|
|
- "0".equals(port), token);
|
575
|
|
- } else {
|
576
|
|
- send.connect();
|
577
|
|
- }
|
|
533
|
+ return;
|
|
534
|
+ }
|
|
535
|
+ send.setAddress(ip, port);
|
|
536
|
+ if (newSend) {
|
|
537
|
+ send.setFileName(filename);
|
|
538
|
+ send.setFileSize(size);
|
|
539
|
+ saveFile(nickname, send, parser, port == 0, token);
|
|
540
|
+ } else {
|
|
541
|
+ send.connect();
|
578
|
542
|
}
|
579
|
543
|
}
|
580
|
544
|
|