IrcCtcp.java
| Index Score | ||
|---|---|---|
![]() |
![]() |
org.furthurnet.furi |
![]() |
![]() |
Furthurnet |
View: Reasons, Metrics, Source Code
These are the metrics that contribute to the Enerjy Score for this file, ranked by impact. So the metrics listed at the top influence the score to a greater extent that the metrics listed at the bottom.
/*
* FURI - A distributed peer-to-peer file sharing system.
* Copyright (C) 2000 William W. Wong
* williamw@jps.net
*
* This program 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; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.furthurnet.furi;
import java.io.*;
import java.util.*;
public class IrcCtcp // implements IComparable
{
private String localUser = null;
private String remoteUser = null;
private String chatText = null;
private boolean isCtcpValid = true;
private IrcCtcpCmd cmd = new IrcCtcpNullCmd();
private IrcManager ircManager = null;
private static long lastCtcpTime = 0;
public IrcCtcp (String localU, String remoteU, String text, IrcManager mgr)
{
localUser = localU;
remoteUser = remoteU;
chatText = text;
ircManager = mgr;
long t1 = System.currentTimeMillis();
if ((t1 - lastCtcpTime) >= 1500){
lastCtcpTime = t1;
isCtcpValid = true;
}
else {
isCtcpValid = false;
}
}
public boolean isCtcp()
{
boolean retVal = true;
if (chatText.charAt(0) == 0x01){
// ctcp's can be invalidated in the constructor if we get too many
// in a time period (i.e. more than 1/sec). In that case, mark it
// as a ctcp command, but leave it invalid, such that the request will
// be dropped
if (isCtcpValid) {
int lastIndex = chatText.indexOf(0x01, 1);
String text = chatText.substring(0x01,lastIndex).toUpperCase();
if (text.toUpperCase().equals("VERSION") ) {
cmd = new IrcCtcpVersionCmd();
}
else if (text.equals("USERINFO") ) {
cmd = new IrcCtcpUserInfoCmd();
}
else if (text.matches("READ .*")){
// since we put to upper case, lets replace text with the orignal string
// such that we can query properties
text = chatText.substring(0x01,lastIndex);
// find the 1st space and send the substring from the space on
lastIndex = text.indexOf (' ', 1);
cmd = new IrcCtcpReadCmd( text.substring(lastIndex));
}
else {
isCtcpValid = false;
}
}
}
else {
retVal = false;
}
return retVal;
}
public boolean isValid()
{
return isCtcpValid;
}
public void handleRequest()
{
cmd.handle();
}
// public String generateUniqueStamp ()
// {
// //
// ServiceManager.sCfg.mIrcKey
// }
private interface IrcCtcpCmd
{
public void handle();
}
private class IrcCtcpVersionCmd implements IrcCtcpCmd
{
public void handle()
{
String prefix = remoteUser +" :";
ircManager.sendMsg( new MsgIRC(null, "PRIVMSG", prefix + localUser));
ircManager.sendMsg( new MsgIRC(null, "PRIVMSG", prefix + Res.getStr("Main.Title")));
}
}
private class IrcCtcpUserInfoCmd implements IrcCtcpCmd
{
public void handle()
{
String prefix = remoteUser +" :";
ircManager.sendMsg( new MsgIRC(null, "PRIVMSG", prefix + localUser ));
ircManager.sendMsg( new MsgIRC(null, "PRIVMSG", prefix + Res.getStr("Main.Title")));
ircManager.sendMsg( new MsgIRC(null, "PRIVMSG", prefix + "IP address:port: "
+ ServiceManager.getManager().getMainFrame().getEffectiveIP()+ ":"
+ ServiceManager.getListener().getListeningPort()));
ircManager.sendMsg( new MsgIRC(null, "PRIVMSG", prefix + "OS: " + System.getProperty("os.name")));
ircManager.sendMsg( new MsgIRC(null, "PRIVMSG", prefix + "Firewalled: "
+ ServiceManager.getManager().getMainFrame().isFirewall()));
ircManager.sendMsg( new MsgIRC(null, "PRIVMSG", prefix + "Java Version: " + System.getProperty("java.version")));
}
}
private class IrcCtcpNullCmd implements IrcCtcpCmd
{
public void handle()
{
// do nothing
}
}
private class IrcCtcpReadCmd implements IrcCtcpCmd
{
private Properties mProp = null;
private String mCmd;
public IrcCtcpReadCmd (String req)
{
mCmd = req;
try {
File inFile = new File(ServiceManager.getFurthurCfgDir() + File.separator + "furthur.cfg");
mProp = new Properties();
if (inFile.isFile() && inFile.canRead()) {
FileInputStream is = new FileInputStream(inFile);
mProp.load(is);
is.close();
}
}
catch (Exception e) {
e.printStackTrace();
}
}
public void handle()
{
String [] strArray = mCmd.split("\\s+");
String prefix = remoteUser +" :";
String propStr = null;
for (int i = 0; i < strArray.length; i++) {
propStr = mProp.getProperty(strArray[i]);
// if the key value is null, but the key is a *real* string, indicate that
// the requested value does not exist
if (propStr == null) {
if (strArray[i].matches("\\w.*")) {
ircManager.sendMsg( new MsgIRC(null, "PRIVMSG", prefix + strArray[i] + " does not exist"));
}
}
// filter out any **sensitive stuff**
else if ( strArray[i].matches ("mProxyPassword") ||
strArray[i].matches ("mProxyUser") ||
strArray[i].matches ("mNetInvalidHosts") )
{
ircManager.sendMsg( new MsgIRC(null, "PRIVMSG", prefix + strArray[i] + " is not available"));
}
else {
ircManager.sendMsg( new MsgIRC(null, "PRIVMSG", prefix + strArray[i] + "=" + mProp.getProperty(strArray[i])));
}
}
}
}
}
The table below shows all metrics for IrcCtcp.java.




