Permalink
Browse files

implementing kick

  • Loading branch information...
1 parent d2c3315 commit 7b1381165307b3f22cba65f07f47b106828aaec6 @jkallunki committed Mar 13, 2012
Showing with 177 additions and 4 deletions.
  1. +60 −1 Swirc/src/swirc/Channel.java
  2. +48 −2 Swirc/src/swirc/ChannelTab.java
  3. +16 −1 Swirc/src/swirc/IrcGateway.java
  4. +53 −0 Swirc/src/swirc/SwircModel.java
@@ -57,6 +57,18 @@ public void addMsg(String sender, String msg) {
}
/**
+ * Adds a row to the channel message list
+ * @param sender Sender of the message
+ * @param msg Message to be sent to channel
+ */
+ public void addRow(String row) {
+ this.contents = this.contents + "\n" + row;
+ this.setChanged();
+ this.notifyObservers("message");
+ }
+
+
+ /**
* Returns contents of channel
* @return Contents of channel
*/
@@ -86,7 +98,7 @@ public void userJoins(String nick, String login, String hostname) {
}
/**
- * Kikcs given user from the channel
+ * Kicks given user from the channel
* @param nick User to be kicked from the channel
*/
public void kick(String nick) {
@@ -102,4 +114,51 @@ public void ban(String nick) {
nick = nick.replace("@", "").replace("+", "");
model.ban(this.server, name, nick + "!*@*");
}
+
+ /**
+ * Ops given user
+ * @param nick User to be opped
+ */
+ public void op(String nick) {
+ nick = nick.replace("@", "").replace("+", "");
+ model.op(this.server, name, nick);
+ }
+
+ /**
+ * De-ops given user
+ * @param nick User to be de-opped
+ */
+ public void deOp(String nick) {
+ nick = nick.replace("@", "").replace("+", "");
+ model.deOp(this.server, name, nick);
+ }
+
+ /**
+ * Voices given user
+ * @param nick User to be voiced
+ */
+ public void voice(String nick) {
+ nick = nick.replace("@", "").replace("+", "");
+ model.voice(this.server, name, nick);
+ }
+
+ /**
+ * De-voices given user
+ * @param nick User to be de-voiced
+ */
+ public void deVoice(String nick) {
+ nick = nick.replace("@", "").replace("+", "");
+ model.deVoice(this.server, name, nick);
+ }
+
+ public void removeUser(String nick) {
+ Object[] nicks = users.toArray();
+ for(int i = 0; i < nicks.length; i++) {
+ String n = (String) nicks[i];
+ String n2 = n.replace("@", "").replace("+", "");
+ if(n2.equals(nick)) {
+ users.removeElement(n);
+ }
+ }
+ }
}
@@ -47,7 +47,6 @@ public void actionPerformed(ActionEvent e) {
String nick = (String) users.getSelectedValue();
channel.kick(nick);
}
-
});
userMenu.add(item);
@@ -59,7 +58,54 @@ public void actionPerformed(ActionEvent e) {
String nick = (String) users.getSelectedValue();
channel.ban(nick);
}
-
+ });
+ userMenu.add(item);
+
+ userMenu.addSeparator();
+
+ item = new JMenuItem("Op");
+ item.setActionCommand("op");
+ item.addActionListener(new ActionListener() {
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ String nick = (String) users.getSelectedValue();
+ channel.op(nick);
+ }
+ });
+ userMenu.add(item);
+
+ item = new JMenuItem("De-op");
+ item.setActionCommand("deOp");
+ item.addActionListener(new ActionListener() {
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ String nick = (String) users.getSelectedValue();
+ channel.deOp(nick);
+ }
+ });
+ userMenu.add(item);
+
+ userMenu.addSeparator();
+
+ item = new JMenuItem("Voice");
+ item.setActionCommand("voice");
+ item.addActionListener(new ActionListener() {
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ String nick = (String) users.getSelectedValue();
+ channel.voice(nick);
+ }
+ });
+ userMenu.add(item);
+
+ item = new JMenuItem("De-voice");
+ item.setActionCommand("deVoice");
+ item.addActionListener(new ActionListener() {
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ String nick = (String) users.getSelectedValue();
+ channel.deVoice(nick);
+ }
});
userMenu.add(item);
@@ -58,7 +58,6 @@ protected void onJoin(String channelName, String joinedNick, String login, Strin
Channel c;
// We joined a channel
- System.out.println("onJoin()");
if(joinedNick.equals(this.getNick())) {
System.out.println("it was us!");
c = new Channel(channelName, this.getServer(), this.model);
@@ -81,6 +80,22 @@ protected void onUserList(String channel, User[] users) {
}
}
+ @Override
+ protected void onKick(String channel, String kickerNick, String kickerLogin, String kickerHostname, String recipientNick, String reason) {
+ Channel c = this.getChannel(channel);
+ if(c != null) {
+ // We got kicked
+ if(recipientNick.equals(this.getNick())) {
+ System.out.println("it was us!");
+ }
+ // Someone else got kicked
+ else {
+ c.removeUser(nick);
+ c.addRow(recipientNick + " was kicked by " + kickerNick);
+ }
+ }
+ }
+
/**
* Initializes the connection
*/
@@ -268,6 +268,59 @@ public void ban(String server, String channel, String nick) {
gw.ban(channel, nick + "!*@*");
}
}
+
+ public void op(String server, String channel, String nick) {
+ // Get the correct connection
+ IrcGateway gw = this.getGateway(server);
+
+ if(gw != null) {
+ // Remove mode symbols
+ nick = nick.replace("@", "").replace("+", "");
+
+ // Op the user
+ gw.op(channel, nick);
+ }
+ }
+
+ public void deOp(String server, String channel, String nick) {
+ // Get the correct connection
+ IrcGateway gw = this.getGateway(server);
+
+ if(gw != null) {
+ // Remove mode symbols
+ nick = nick.replace("@", "").replace("+", "");
+
+ // Op the user
+ gw.deOp(channel, nick);
+ }
+ }
+
+ public void voice(String server, String channel, String nick) {
+ // Get the correct connection
+ IrcGateway gw = this.getGateway(server);
+
+ if(gw != null) {
+ // Remove mode symbols
+ nick = nick.replace("@", "").replace("+", "");
+
+ // Ban only the nick without hostmask
+ gw.voice(channel, nick);
+ }
+ }
+
+
+ public void deVoice(String server, String channel, String nick) {
+ // Get the correct connection
+ IrcGateway gw = this.getGateway(server);
+
+ if(gw != null) {
+ // Remove mode symbols
+ nick = nick.replace("@", "").replace("+", "");
+
+ // Ban only the nick without hostmask
+ gw.deVoice(channel, nick);
+ }
+ }
/**
* Returns configuration object

0 comments on commit 7b13811

Please sign in to comment.