All pastes #640877 Raw Edit

Untitled

public text v1 · immutable
#640877 ·published 2007-07-31 19:19 UTC
rendered paste body
Index: src/plugins/org.drftpd.plugins.sitebot/src/org/drftpd/plugins/sitebot/SiteBot.java
===================================================================
--- src/plugins/org.drftpd.plugins.sitebot/src/org/drftpd/plugins/sitebot/SiteBot.java	(Revision 1754)
+++ src/plugins/org.drftpd.plugins.sitebot/src/org/drftpd/plugins/sitebot/SiteBot.java	(Arbeitskopie)
@@ -49,6 +49,7 @@
 import org.drftpd.commandmanager.CommandManagerInterface;
 import org.drftpd.commandmanager.CommandRequestInterface;
 import org.drftpd.commandmanager.CommandResponseInterface;
+import org.drftpd.commands.UserManagement;
 import org.drftpd.event.LoadPluginEvent;
 import org.drftpd.event.ReloadEvent;
 import org.drftpd.event.UnloadPluginEvent;
@@ -57,6 +58,10 @@
 import org.drftpd.plugins.sitebot.config.ChannelConfig;
 import org.drftpd.plugins.sitebot.config.ServerConfig;
 import org.drftpd.plugins.sitebot.config.SiteBotConfig;
+import org.drftpd.plugins.sitebot.event.InviteEvent;
+import org.drftpd.usermanager.NoSuchUserException;
+import org.drftpd.usermanager.User;
+import org.drftpd.usermanager.UserFileException;
 import org.drftpd.vfs.DirectoryHandle;
 import org.java.plugin.PluginManager;
 import org.java.plugin.registry.Extension;
@@ -208,6 +213,7 @@
 		GlobalContext.getEventService().subscribe(ReloadEvent.class,this);
 		GlobalContext.getEventService().subscribe(LoadPluginEvent.class,this);
 		GlobalContext.getEventService().subscribe(UnloadPluginEvent.class,this);
+		GlobalContext.getEventService().subscribe(InviteEvent.class,this);
 	}
 
 
@@ -1182,7 +1188,28 @@
 	 * 
 	 * @see ReplyConstants
 	 */
-	protected void onServerResponse(int code, String response) {}
+	protected void onServerResponse(int code, String response) {
+		if(code == RPL_WHOISUSER) {
+			//parse the whois for registering user
+			String[] reply = response.split(" ");
+			String nick = reply[1];
+			String ident = nick + "!" + reply[2] + "@" + reply[3];
+			if(_users.containsKey(nick)) {
+				try {
+					User user = GlobalContext.getGlobalContext().getUserManager().getUserByName(_users.get(nick).getFtpUser());
+					_users.get(nick).setIdent(ident);
+					user.getKeyedMap().setObject(UserManagement.IRCIDENT,ident);
+					user.commit();
+				} catch (NoSuchUserException e) {
+					//do nothing
+				} catch (UserFileException ufe) {
+					//do nothing
+				}
+			}
+		}
+	}
 
 
 	/**
@@ -3018,6 +3045,12 @@
 					}
 				}
 			}
+		} else if (event instanceof InviteEvent) {
+			InviteEvent inviteEvent = (InviteEvent) event;
+			UserDetails userDetails = new UserDetails(inviteEvent.getIrcNick(), "", this);
+			userDetails.setFtpUser(inviteEvent.getUser().getName());
+			_users.put(inviteEvent.getIrcNick(), userDetails);
+			sendRawLine("WHOIS " + inviteEvent.getIrcNick());
 		}
 	}
 
Index: src/plugins/org.drftpd.plugins.sitebot/src/org/drftpd/plugins/sitebot/UserDetails.java
===================================================================
--- src/plugins/org.drftpd.plugins.sitebot/src/org/drftpd/plugins/sitebot/UserDetails.java	(Revision 1754)
+++ src/plugins/org.drftpd.plugins.sitebot/src/org/drftpd/plugins/sitebot/UserDetails.java	(Arbeitskopie)
@@ -71,6 +71,10 @@
 		return _ftpUser;
 	}
 
+	protected void setFtpUser(String ftpUser) {
+		_ftpUser = ftpUser;
+	}
+
 	protected Blowfish getBlowCipher() {
 		// If we don't have a cipher for this user then check again as they may have set
 		// one on site since we last checked.
@@ -138,10 +142,18 @@
 		user.commit();
 	}
 
+	public String getNick() {
+		return _nick;
+	}
+
 	protected void setNick(String nick) {
 		_nick = nick;
 	}
 
+	protected void setIdent(String ident) {
+		_ident = ident;
+	}
+
 	protected OutputWriter getOutputWriter() {
 		return _writer;
 	}
@@ -155,8 +167,4 @@
 	protected synchronized void removeCommandSession(ServiceCommand session) {
 		_commandSessions.remove(session);
 	}
-
-	public String getNick() {
-		return _nick;
-	}
 }