NullItem.java
- Code: Select all
package irc.plugin.adnd;
class NullItem
{
}
LoginConfigurationLoader.java
- Code: Select all
/*****************************************************/
/* This java file is a part of the */
/* */
/* - ADnD.com Login Plugin for - */
/* - Plouf's Java IRC Client - */
/* */
/* Copyright (C) 2003 - 2004 Thema */
/* */
/* All contacts : thema@adnd.com */
/* */
/* PJIRC is free software; you can redistribute */
/* it and/or modify it under the terms of the GNU */
/* General Public License as published by the */
/* Free Software Foundation; version 2 or later of */
/* the License. */
/* */
/* PJIRC is distributed in the hope that it will */
/* be useful, but WITHOUT ANY WARRANTY; without */
/* even the implied warranty of MERCHANTABILITY or */
/* FITNESS FOR A PARTICULAR PURPOSE. See the GNU */
/* General Public License for more details. */
/* */
/* You should have received a copy of the GNU */
/* General Public License along with PJIRC; if */
/* not, write to the Free Software Foundation, */
/* Inc., 59 Temple Place, Suite 330, Boston, */
/* MA 02111-1307 USA */
/* */
/*****************************************************/
package irc.plugin.adnd;
import irc.*;
import irc.plugin.*;
import java.util.*;
import java.awt.*;
/**
* Toolkit for Configuration creation.
*/
public class LoginConfigurationLoader
{
private IRCConfiguration _config;
private ParameterProvider _provider;
/**
* Create a new LoginConfigurationLoader.
* @param config the irc configuration.
*/
public LoginConfigurationLoader(IRCConfiguration config)
{
_config=config;
// _provider=new PrefixedParameterProvider(_config.getParameterProvider(),"login:");
}
/**
* Create a new LoginConfiguration object, using the given IRCConfiguration.
* @return a new LoginConfiguration instance.
* @throws Exception if an error occurs.
*/
public LoginConfiguration loadLoginConfiguration() throws Exception
{
return getLoginConfiguration();
}
private String getParameter(String key)
{
return _provider.getParameter(key);
}
private boolean getBoolean(String key,boolean def)
{
String v=getParameter(key);
if(v==null) return def;
v=v.toLowerCase().trim();
if(v.equals("true") || v.equals("on") || v.equals("1")) return true;
return false;
}
private String getString(String key,String def)
{
String v=getParameter(key);
if(v==null) return def;
return v;
}
private int getInt(String key,int def)
{
String v=getParameter(key);
if(v==null) return def;
try
{
return Integer.parseInt(v);
}
catch(Exception e)
{
return def;
}
}
private String[] getArray(String name)
{
Vector v=new Vector();
String cmd;
int i=1;
do
{
cmd=getParameter(name+i);
if(cmd!=null) v.insertElementAt(cmd,v.size());
i++;
}
while(cmd!=null);
String[] ans=new String[v.size()];
for(i=0;i<v.size();i++) ans[i]=(String)v.elementAt(i);
return ans;
}
private LoginConfiguration getLoginConfiguration() throws Exception
{
LoginConfiguration config=new LoginConfiguration(_config);
config.set("loginchan",getString("loginchan",""));
config.set("passwd",getString("passwd",""));
return config;
}
}
LoginConfiguration.java
- Code: Select all
/*****************************************************/
/* This java file is a part of the */
/* */
/* - ADnD.com Login Plugin for - */
/* - Plouf's Java IRC Client - */
/* */
/* Copyright (C) 2003 - 2004 Thema */
/* */
/* All contacts : thema@adnd.com */
/* */
/* PJIRC is free software; you can redistribute */
/* it and/or modify it under the terms of the GNU */
/* General Public License as published by the */
/* Free Software Foundation; version 2 or later of */
/* the License. */
/* */
/* PJIRC is distributed in the hope that it will */
/* be useful, but WITHOUT ANY WARRANTY; without */
/* even the implied warranty of MERCHANTABILITY or */
/* FITNESS FOR A PARTICULAR PURPOSE. See the GNU */
/* General Public License for more details. */
/* */
/* You should have received a copy of the GNU */
/* General Public License along with PJIRC; if */
/* not, write to the Free Software Foundation, */
/* Inc., 59 Temple Place, Suite 330, Boston, */
/* MA 02111-1307 USA */
/* */
/*****************************************************/
package irc.plugin.adnd;
import irc.*;
import irc.plugin.*;
import java.util.*;
public class LoginConfiguration
{
private IRCConfiguration _config;
private NullItem NULL_ITEM=new NullItem();
private Hashtable _htable;
private TextProvider _textProvider;
public LoginConfiguration(IRCConfiguration config)
{
_config=config;
_htable=new Hashtable();
}
public void setTextProvider(TextProvider txt)
{
_textProvider=txt;
}
/**
* Get the high version number.
* @return the high version number.
*/
public int getVersionHigh()
{
return 1;
}
/**
* Get the middle version number.
* @return the middle version number.
*/
public int getVersionMed()
{
return 2;
}
/**
* Get the low version number.
* @return the low version number.
*/
public int getVersionLow()
{
return 1;
}
/**
* Get the version modifiers.
* @return version modifiers.
*/
public String getVersionModifiers()
{
return "Login(beta)";
}
/**
* Get version number as a string.
* @return high.med.lowmod version number.
*/
public String getVersion()
{
return getVersionHigh()+"."+getVersionMed()+"."+getVersionLow()+getVersionModifiers();
}
/**
* Set the given property to the given value. This value may be null.
* @param key property name.
* @param obj property value.
*/
public synchronized void set(String key,Object obj)
{
if(obj==null) obj=NULL_ITEM;
_htable.put(key.toLowerCase(),obj);
}
/**
* Set the given property to the given int value.
* @param key property name.
* @param val property value.
*/
public synchronized void set(String key,int val)
{
set(key,new Integer(val));
}
/**
* Set the given property to the given boolean value.
* @param key property name.
* @param val property value.
*/
public synchronized void set(String key,boolean val)
{
set(key,new Boolean(val));
}
/**
* Get the given property value.
* @param key property name.
* @return the property value.
* @throws RuntimeException if the property is unknown.
*/
public synchronized Object get(String key)
{
Object v=_htable.get(key.toLowerCase());
if(v==null) throw new RuntimeException("Unknown configuration property "+key);
if(v==NULL_ITEM) v=null;
return v;
}
/**
* Get the given property value as an int value.
* @param key property name.
* @return the property value.
* @throws RuntimeException if the property is unknown.
*/
public synchronized int getI(String key)
{
Integer i=(Integer)get(key);
return i.intValue();
}
/**
* Get the given property value as a boolean value.
* @param key property name.
* @return the property value.
* @throws RuntimeException if the property is unknown.
*/
public synchronized boolean getB(String key)
{
Boolean b=(Boolean)get(key);
return b.booleanValue();
}
/**
* Get the given property value as String value.
* @param key property name.
* @return the property value.
* @throws RuntimeException if the property is unknown.
*/
public synchronized String getS(String key)
{
return (String)get(key);
}
public IRCConfiguration getIRCConfiguration()
{
return _config;
}
/**
* Get formatted text associated with the given text code, with no parameter.
* @param code text code.
* @return formatted text.
*/
public synchronized String getText(int code)
{
if(code<TextProvider.USER_BASE) return _config.getText(code);
return _textProvider.getString(code);
}
/**
* Get formatted text associated with the given text code, with one parameter.
* @param code text code.
* @param p1 first parameter.
* @return formatted text.
*/
public synchronized String getText(int code,String p1)
{
if(code<TextProvider.USER_BASE) return _config.getText(code,p1);
return _textProvider.getString(code,p1);
}
/**
* Get formatted text associated with the given text code, with two parameters.
* @param code text code.
* @param p1 first parameter.
* @param p2 second parameter.
* @return formatted text.
*/
public synchronized String getText(int code,String p1,String p2)
{
if(code<TextProvider.USER_BASE) return _config.getText(code,p1,p2);
return _textProvider.getString(code,p1,p2);
}
/**
* Get formatted text associated with the given text code, with three parameters.
* @param code text code.
* @param p1 first parameter.
* @param p2 second parameter.
* @param p3 third parameter.
* @return formatted text.
*/
public synchronized String getText(int code,String p1,String p2,String p3)
{
if(code<TextProvider.USER_BASE) return _config.getText(code,p1,p2,p3);
return _textProvider.getString(code,p1,p2,p3);
}
}
LoginInterpretor.java
- Code: Select all
/*****************************************************/
/* This java file is a part of the */
/* */
/* - ADnD.com Login Plugin for - */
/* - Plouf's Java IRC Client - */
/* */
/* Copyright (C) 2003 - 2004 Thema */
/* */
/* All contacts : thema@adnd.com */
/* */
/* PJIRC is free software; you can redistribute */
/* it and/or modify it under the terms of the GNU */
/* General Public License as published by the */
/* Free Software Foundation; version 2 or later of */
/* the License. */
/* */
/* PJIRC is distributed in the hope that it will */
/* be useful, but WITHOUT ANY WARRANTY; without */
/* even the implied warranty of MERCHANTABILITY or */
/* FITNESS FOR A PARTICULAR PURPOSE. See the GNU */
/* General Public License for more details. */
/* */
/* You should have received a copy of the GNU */
/* General Public License along with PJIRC; if */
/* not, write to the Free Software Foundation, */
/* Inc., 59 Temple Place, Suite 330, Boston, */
/* MA 02111-1307 USA */
/* */
/*****************************************************/
package irc.plugin.adnd;
import irc.*;
import java.util.*;
import irc.plugin.*;
import irc.security.*;
import java.lang.reflect.*;
/**
* Basic interpretor.
*/
public class LoginInterpretor extends RootInterpretor implements Interpretor
{
private IRCConfiguration _ircConfiguration;
// private LoginConfiguration _loginConfiguration;
private String _channel;
private String _passwd;
private String _pseudo;
/*
* Create a new LoginInterpretor without default interpretor.
* @param config the configuration.
*/
public LoginInterpretor(IRCConfiguration config)
{
this(config,null);
}
/**
* Create a new LoginInterpretor.
* @param config the configuration.
* @param next next interpretor to be used if the command is unknown. If null,
* the command will be sent, as is, to the server.
*/
public LoginInterpretor(IRCConfiguration config, Interpretor next)
{
super(config,next);
// _ircConfiguration=config.getIRCConfiguration();
_ircConfiguration=config;
_pseudo="";
_passwd="";
_channel="";
}
/*
* Replace Login variables with correct values
*/
private String replace(String on,String what,String with)
{
int pos=on.indexOf(what);
while(pos>=0)
{
String before=on.substring(0,pos);
String after=on.substring(pos+what.length());
on=before+with+after;
pos=on.indexOf(what);
}
return on;
}
/**
* Handle the received command.
* @param source the source that emitted the command.
* @param cmd the whole command line.
* @param parts the parsed command line.
* @param cumul the cumul parsed command line.
*/
protected void handleCommand(Source source,String cmd,String[] parts,String[] cumul)
{
super.handleCommand(source,cmd,parts,cumul);
}
public synchronized void setPseudo(String str)
{
_pseudo=str;
}
public synchronized void setPasswd(String str)
{
_passwd=str;
}
public synchronized void setChannel(String str)
{
_channel=str;
}
public void sendString(Source source,String str)
{
if (str.indexOf("$passwd")!= -1)
{
if (_passwd!="")
{
str=replace(str,"$passwd",_passwd);
super.sendString(source,str);
}
}
else if (str.indexOf("$loginchan")!= -1)
{
if (_channel!="")
{
if (!_channel.startsWith("#"))
{
_channel="#"+_channel;
}
str=replace(str,"$loginchan",_channel);
super.sendString(source,str);
}
}
else super.sendString(source,str);
}
}
Login.java
- Code: Select all
/*****************************************************/
/* This java file is a part of the */
/* */
/* - Plouf's Java IRC Client - */
/* */
/* Copyright (C) 2002 - 2004 Philippe Detournay */
/* */
/* All contacts : theplouf@yahoo.com */
/* */
/* PJIRC is free software; you can redistribute */
/* it and/or modify it under the terms of the GNU */
/* General Public License as published by the */
/* Free Software Foundation; version 2 or later of */
/* the License. */
/* */
/* PJIRC is distributed in the hope that it will */
/* be useful, but WITHOUT ANY WARRANTY; without */
/* even the implied warranty of MERCHANTABILITY or */
/* FITNESS FOR A PARTICULAR PURPOSE. See the GNU */
/* General Public License for more details. */
/* */
/* You should have received a copy of the GNU */
/* General Public License along with PJIRC; if */
/* not, write to the Free Software Foundation, */
/* Inc., 59 Temple Place, Suite 330, Boston, */
/* MA 02111-1307 USA */
/* */
/*****************************************************/
package irc.plugin.adnd;
import irc.*;
import irc.gui.*;
import irc.plugin.*;
import irc.gui.pbtn.*;
import java.io.*;
import java.awt.*;
import java.awt.image.*;
import java.util.*;
import java.applet.*;
import java.awt.event.*;
/**
* Simple PJIRC Login Interface.
*/
public class Login extends IRCInterface implements ActionListener
{
private IRCConfiguration _config;
private Panel _panel;
private Component _currentGUI;
private CardLayout _GUI;
private Container _container;
private Frame _frame;
private IRCInterface _ircInterface;
private Server _server;
private TextProvider _textProvider;
private int btn_h=25;
private int btn_w=100;
private ImageLoader _loader;
private ImageButton _connect=null;
private String _buttonpath;
private String _buttonext;
private String _pseudo;
private String _passwd;
private String _channel;
/**
* Some display area for the main component.
*/
private TextField _pseudoBuf;
private TextField _passwdBuf;
private TextField _chanBuf;
/**
* The source dictionnary. Allow us to get the source window for
* the given source.
*/
private Hashtable _sources;
/**
* Create a new SDK Interface.
* @param config the global irc configuration.
*/
public Login(IRCConfiguration config) throws Exception
{
super(config);
_config=config;
}
/**
* Load this interface.
*/
public void load()
{
super.load();
System.out.println("Loaded Login v1 (alpha):");
println("PJIRC v-something");
int currentIndex=0;
} //Login
/**
* Release any resources used by this instance. This should be the last
* method call on the instance.
*/
public void unload()
{
_pseudoBuf=null;
_passwdBuf=null;
_connect=null;
_sources.clear();
_sources=null;
_panel.hide();
_container.removeAll();
_panel=null;
_container.setLayout(new FlowLayout());
_container.add(_currentGUI);
_currentGUI.validate();
_currentGUI.doLayout();
super.unload();
} //release
public String getText(int code)
{
return _config.getText(code);
}
public void actionPerformed(ActionEvent e)
{
EventDispatcher.dispatchEventAsync(this,"actionPerformedEff",new Object[] {e});
}
/**
* Internally used.
* @param e
*/
public synchronized void actionPerformedEff(ActionEvent e)
{
if (e.getSource()==_connect)
{
if(_pseudoBuf!=null && !_pseudoBuf.getText().equals(""))
{
_pseudo=_pseudoBuf.getText();
_pseudoBuf.setText("");
}
else return;
if(_passwdBuf!=null && !_passwdBuf.getText().equals(""))
{
_passwd=_passwdBuf.getText();
_passwdBuf.setText("");
}
if(_chanBuf!=null && !_chanBuf.getText().equals(""))
{
_channel=_chanBuf.getText();
if (!_channel.startsWith("#"))
{
_channel="#"+_channel;
}
_chanBuf.setText("");
}
println("Got nick "+_pseudo);
println("Got pass "+_passwd);
println("Got chan "+_channel);
_GUI.show(_container, "Chat");
println("See the GUI!");
_server.execute("CONNECT");
_server.execute("NICK "+_pseudo);
_server.say("nickserv"," identify "+_passwd);
_server.execute("JOIN "+_channel);
}
}
/**
* Notify this interface that a new server has been created.
* @param s the newly created server.
*/
public synchronized void serverCreated(Server s)
{
_server=s;
try
{
_currentGUI=_ircApplication.getIRCInterface().getComponent();
_container=_currentGUI.getParent();
}
catch (Exception ex)
{
ex.printStackTrace();
}
try
{
_pseudo=_server.getNick();
}
catch(Exception e)
{
println("No nick so making one up for now");
_pseudo="guest??";
}
try
{
_sources=new Hashtable();
_GUI=new CardLayout();
_panel=new Panel();
GridBagConstraints c=new GridBagConstraints();
GridBagLayout gridbag=new GridBagLayout();
_panel.setLayout(gridbag);
c.fill=GridBagConstraints.VERTICAL;
c.weightx = 1.0;
Label top = new Label("Chat Login");
top.setAlignment(Label.CENTER);
c.gridwidth=GridBagConstraints.REMAINDER;
gridbag.setConstraints(top, c);
_panel.add(top);
Label textLabel=new Label("If you're not sure then just hit the Connect button");
c.gridwidth=GridBagConstraints.REMAINDER;
gridbag.setConstraints(textLabel, c);
_panel.add(textLabel);
Label nickLabel=new Label("Username");
c.gridwidth=GridBagConstraints.REMAINDER;
gridbag.setConstraints(nickLabel, c);
_panel.add(nickLabel);
_pseudoBuf=new TextField(_pseudo, 40);
c.gridwidth=GridBagConstraints.REMAINDER;
gridbag.setConstraints(_pseudoBuf, c);
_panel.add(_pseudoBuf);
Label passLabel=new Label("Password");
c.gridwidth=GridBagConstraints.REMAINDER;
gridbag.setConstraints(passLabel, c);
_panel.add(passLabel);
_passwdBuf=new TextField("", 40);
c.gridwidth=GridBagConstraints.REMAINDER;
gridbag.setConstraints(_passwdBuf, c);
_panel.add(_passwdBuf);
Label chanLabel=new Label("Channel");
c.gridwidth=GridBagConstraints.REMAINDER;
gridbag.setConstraints(chanLabel, c);
_panel.add(chanLabel);
_chanBuf=new TextField("", 40);
c.gridwidth=GridBagConstraints.REMAINDER;
gridbag.setConstraints(_chanBuf, c);
_panel.add(_chanBuf);
_connect=addButton("Connect", _buttonpath);
_connect.addActionListener(this);
c.fill=GridBagConstraints.NONE;
c.gridwidth=GridBagConstraints.REMAINDER;
gridbag.setConstraints(_connect, c);
_panel.add(_connect);
_panel.setBackground(Color.white);
_connect.repaint();
_container.removeAll();
_container.setLayout(_GUI);
_container.add(_currentGUI,"Chat");
_container.add(_panel,"Login");
_GUI.show(_container, "Login");
_container.validate();
}
catch(Exception ex)
{
ex.printStackTrace();
}
} //serverCreated
/**
* Notify this interface that a new source has been created.
* @param source the newly created source.
* @param bring is true if the newly created source should gain immediate
* focus, false is no particular action is to be taken.
*/
public void sourceCreated(Source source,Boolean bring)
{
source.setInterpretor(new LoginInterpretor(_config,source.getInterpretor()));
} //sourceCreated
/**
* Notify this interface that an existing source has been removed. No further
* call should be performed on this source.
* @param source the removed source.
*/
public void sourceRemoved(Source source)
{
LoginInterpretor inter=(LoginInterpretor)source.getInterpretor();
source.setInterpretor(inter.getNextInterpretor());
} //sourceRemoved
/**
* Notify this interface that an existing server has acheived connection to
* its remote host.
* @param s connected server.
*/
public void serverConnected(Server s)
{
} //serverConnected
/**
* Notify this interface that an existing server has disconnected from its
* remote host.
* @param s disconnected server.
*/
public void serverDisconnected(Server s)
{
} //serverDisconnected
/**
* Notify this interface that an existing server has been removed. No further
* call should be performed on this server.
* @param s removed server.
*/
public void serverRemoved(Server s)
{
} //serverRemoved
/**
* Get the component associated with this interface.
* @return the interface component.
*/
public Component getComponent()
{
return _panel;
} //getComponent
public void println(String string)
{
System.out.println(string);
}
private boolean checkFile(String file)
{
FileHandler _file=_config.getFileHandler();
InputStream stream=_file.getInputStream(file);
if (stream == null)
{
return false;
}
else
{
return true;
}
}
private ImageButton addButton(String txt, String file)
{
int h=-1;
ImageButton btn;
if (checkFile(file+"_up."+_buttonext))
{
Image btn_down = _loader.getImage(file+"_down."+_buttonext);
Image btn_grey = _loader.getImage(file+"_grey."+_buttonext);
Image btn_over = _loader.getImage(file+"_over."+_buttonext);
Image btn_up = _loader.getImage(file+"_up."+_buttonext);
while (h < 0)
{
h = btn_up.getHeight(null);
}
int w = btn_up.getWidth(null);
h = btn_up.getHeight(null);
w = btn_up.getWidth(null);
btn_w=(w > 0) ? w : btn_w;
btn_h=(h > 0) ? h : btn_h;
btn = new ImageButton(btn_over, btn_up, btn_down, btn_w, btn_h, txt);
}
else
{
btn_w=65;
btn_h=16;
btn = new ImageButton(btn_w, btn_h, txt);
}
btn.addActionListener(this);
btn.repaint();
return btn;
}
} //Login
logincompile.bat
- Code: Select all
set pathsave=%classpath%
cd C:\Websites\irc\PJirc2.2.1\src
set classpath=%classpath%;C:\j2sdk1.4.2_05\bin;;C:\j2sdk1.4.2_05\jdk\bin;C:\Websites\irc\PJirc2.2.1\src
set path=%path%;C:\j2sdk1.4.2_05\bin;C:\j2sdk1.4.2_05\jdk\bin
javac -g:none -O -target 1.1 -sourcepath C:\Websites\irc\PJirc2.2.1\src irc\plugin\adnd\Login*.java
C:\j2sdk1.4.2_05\jdk\bin\jar.exe cfm login.jar META-INF/MANIFEST.MF irc\plugin\adnd\Login*.class irc\gui\pbtn\ImageButton.class
cabarc -p -r N login.cab irc\plugin\adnd\Login*.class irc\gui\pbtn\ImageButton.class
set classpath=%pathsave%
set pathsave=
pause
Please note that the ImageButton class from the PBtn GUI is included in the jar because I'm using a 3D ImageButton. I want to ensure that the configuration loader can obtain a path for button images when the rest of the plugin is working better.
The main bugs are:
- Only works once, and won't reload the page when a new server is connected, or when server is reconnected.
- Isn't multi-server friendly yet.
- While connecting it sends something to the server that makes the server think an illegal oper command is being sent.
- Screws with the DSmiley plugin when used with JWS. Can't see why.
- I can't imagine what I was thinking of with the LoginInterpretor class. I may have had some JavaScript, DescBot. or Alias compatibility in mind. So far it seems a bit useless, and isn't really being used.
- Likewise I don't think I'm using the Configuration Loader parameters yet. I think I meant to pre-load values into the login window. Just never got that far I guess.
Please:
Don't quote this lot when you post
Just post the edited lines. I should be able to find where to put them.
