1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.xnap.plugin.pircbot;
21
22 import java.awt.event.ActionEvent;
23
24 import javax.swing.*;
25
26 import org.xnap.net.*;
27 import org.xnap.peer.AbstractPeer;
28 import org.xnap.peer.action.*;
29 import org.xnap.peer.action.AbstractWhoisAction;
30 import org.xnap.transfer.*;
31 import org.xnap.util.*;
32
33 /***
34 * This class represents a PircBot user.
35 */
36 public class PircBotPeer extends AbstractPeer {
37
38
39
40 private String host;
41
42 private PircBotServer server;
43
44
45
46 public PircBotPeer(PircBotServer server, String nick)
47 {
48 super(nick);
49
50 this.server = server;
51 }
52
53
54
55 public Action[] getActions()
56 {
57 return new Action[] {
58 new WhoisAction(), new ChatAction(), new SendFileAction(),
59 };
60 }
61
62 public int getLocalDownloadCount()
63 {
64 return 0;
65 }
66
67 public int getLocalUploadCount()
68 {
69 return 0;
70 }
71
72 public String getHost()
73 {
74 return host;
75 }
76
77 public PircBotServer getServer()
78 {
79 return server;
80 }
81
82 public String getStatus()
83 {
84 return null;
85 }
86
87 public void setHost(String host)
88 {
89 this.host = host;
90 }
91
92
93
94 private class ChatAction extends AbstractChatAction {
95
96 public void actionPerformed(ActionEvent event)
97 {
98 getServer().getBot().getPrivateChannelByName
99 (PircBotPeer.this.getName());
100 }
101
102 }
103
104 private class SendFileAction extends AbstractSendFileAction {
105
106 public void actionPerformed(ActionEvent event)
107 {
108 JFileChooser chooser = new JFileChooser();
109 if (chooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
110 DccUpload u = new DccUpload
111 (PircBotPeer.this, chooser.getSelectedFile());
112 UploadManager.getInstance().add(u);
113 u.start();
114 if (u.getLocalPort() != 0) {
115 long ip = NetHelper.ipToLongHiFirst
116 (getServer().getBot().getInetAddress().getAddress());
117 getServer().getBot().sendCTCPCommand
118 (getName(),
119 "DCC SEND " + FileHelper.toAscii(u.getFilename())
120 + " " + ip
121 + " " + u.getLocalPort()
122 + " " + u.getFilesize());
123 }
124 }
125 }
126
127 }
128
129 /***
130 * Not supported by PircBot.
131 */
132 private class WhoisAction extends AbstractWhoisAction {
133
134 public void actionPerformed(ActionEvent event)
135 {
136 getServer().getBot().whois(PircBotPeer.this.getName());
137 }
138
139 }
140
141 }