📄 openchat.java
字号:
// Decompiled by Jad v1.5.8f. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3)
// Source File Name: OpenCHAT.java
import java.io.*;
import java.net.*;
import java.util.*;
class OpenCHAT
{
OpenCHAT()
{
}
public static void p(String s)
{
System.out.println(s);
}
public static void log(String s)
{
System.out.println(s);
}
static void loadProps()
{
String dirs[] = {
File.separator + "etc" + File.separator, "."
};
if(props.isEmpty())
{
readConfFile(props, dirs, "OpenCHAT.conf");
if(props.getProperty("CHAT_ROOT_DIR") == null)
props.setProperty("CHAT_ROOT_DIR", File.separator + "etc" + File.separator + "OpenCHAT");
if(props.getProperty("CHAT_MAX_USERS") == null)
props.setProperty("CHAT_MAX_USERS", "1000");
if(props.getProperty("CHAT_ROOM_MAX_USERS") == null)
props.setProperty("CHAT_ROOM_MAX_USERS", "40");
if(props.getProperty("CHAT_FREE_ROOM_OPEN") == null)
props.setProperty("CHAT_ROOM_MAX_USERS", "40");
if(props.getProperty("CHAT_SERVER_PORT") == null)
props.setProperty("CHAT_SERVER_PORT", "8080");
if(props.getProperty("CHAT_SERVER_WORKERS") == null)
props.setProperty("CHAT_SERVER_WORKERS", "5");
if(props.getProperty("CHAT_CLIENT_TIMEOUT") == null)
props.setProperty("CHAT_CLIENT_TIMEOUT", "30000");
if(props.getProperty("CHAT_WITH_NOMADE") == null)
props.setProperty("CHAT_WITH_NOMADE", "0");
if(props.getProperty("CHAT_READER_WELCOME_MESSAGE") == null)
props.setProperty("CHAT_READER_WELCOME_MESSAGE", "<font face=arial><b>Welcome to OpenCHAT</b></font><br>");
if(props.getProperty("CHAT_DEFAULT_CHARSET") == null)
props.setProperty("CHAT_DEFAULT_CHARSET", "ISO-8859-1");
if(props.getProperty("CHAT_VIRTUAL_ROOT") == null)
props.setProperty("CHAT_VIRTUAL_ROOT", "");
if(props.getProperty("CHAT_DEFAULT_LANGUAGE") == null)
props.setProperty("CHAT_DEFAULT_LANGUAGE", "en");
}
if(lang.isEmpty())
{
lang.put("en", new Properties());
((Properties)lang.get("en")).put("langName", "English");
((Properties)lang.get("en")).put("Language", "Language");
((Properties)lang.get("en")).put("privatly", "privatly");
((Properties)lang.get("en")).put("private", "private");
((Properties)lang.get("en")).put("All", "All");
((Properties)lang.get("en")).put("Talk", "Talk");
((Properties)lang.get("en")).put("talks_to", "talks to");
((Properties)lang.get("en")).put("to", "to");
((Properties)lang.get("en")).put("Nick_name", "Nick name");
((Properties)lang.get("en")).put("Room", "Room");
((Properties)lang.get("en")).put("logged_in_the_room", "logged in the room");
((Properties)lang.get("en")).put("logged_out_the_room", "logged out the room");
((Properties)lang.get("en")).put("User_not_found", "User not found.");
((Properties)lang.get("en")).put("Internal_Server_Error", "Internal Server Error");
((Properties)lang.get("en")).put("File_server_not_enabled", "OpenCHAT file server not enabled");
((Properties)lang.get("en")).put("User_error", "User error");
((Properties)lang.get("en")).put("check_your_charset", "Please check your browser Charset encoding and try again");
((Properties)lang.get("en")).put("Unknown_error", "Unknown error");
((Properties)lang.get("en")).put("serial_or_pass_cant_be_null", "Conection \"serial\" or \"pass\" number can not be null");
readLangConf(lang, dirs, "OpenCHAT.lang");
}
if(!lang.containsKey(props.getProperty("CHAT_DEFAULT_LANGUAGE")))
{
p("Language '" + props.getProperty("CHAT_DEFAULT_LANGUAGE") + "' is configured as OpenCHAT default but there is no reference to it at OpenCHAT.lang config file. Setting default to 'en'.");
props.setProperty("CHAT_DEFAULT_LANGUAGE", "en");
}
Root = new Root();
}
static String getProperty(String property)
{
return props.containsKey(property) ? props.getProperty(property) : null;
}
static void printProps()
{
p("OpenCHAT server up and running using Port " + getProperty("CHAT_SERVER_PORT") + ", " + "Server Root: " + getProperty("CHAT_FILESERVER_ROOT") + ", " + "Client Timeout: " + getProperty("CHAT_CLIENT_TIMEOUT") + ", " + "Init Workers: " + getProperty("CHAT_SERVER_WORKERS"));
p("Accepting HTTP connections on port " + getProperty("CHAT_SERVER_PORT") + "...");
if(System.getProperty("user.name").equals("root"))
p("WARNING! OpenCHAT server is runnig as root! It may be very unsecure...");
}
public static void main(String a[])
throws Exception
{
loadProps();
printProps();
int port = Integer.parseInt(getProperty("CHAT_SERVER_PORT"));
if(a.length > 0)
port = Integer.parseInt(a[0]);
for(int i = 0; i < Integer.parseInt(getProperty("CHAT_SERVER_WORKERS")); i++)
{
Worker w = new Worker();
(new Thread(w, "worker #" + i)).start();
threads.addElement(w);
}
try
{
ServerSocket ss = new ServerSocket(port);
do
{
java.net.Socket s = ss.accept();
Worker w = null;
synchronized(threads)
{
if(threads.isEmpty())
{
Worker ws = new Worker();
ws.setSocket(s);
(new Thread(ws, "additional worker")).start();
} else
{
w = (Worker)threads.elementAt(0);
threads.removeElementAt(0);
w.setSocket(s);
}
}
} while(true);
}
catch(BindException e)
{
p("Could not open the ServerSocket. Propably the address (port:" + port + ") is already in use.");
}
System.exit(1);
}
public static boolean readLangConf(Properties props, String dirs[])
{
return readLangConf(props, dirs, "OpenCHAT.lang");
}
public static boolean readLangConf(Properties props, String dirs[], String fileName)
{
Properties allLangs = new Properties();
readConfFile(allLangs, dirs, fileName);
String key[];
for(Enumeration e = allLangs.keys(); e.hasMoreElements(); ((Properties)props.get(key[0])).put(key[1], allLangs.get(key[0] + "." + key[1])))
{
key = ((String)e.nextElement()).split("\\.");
if(!props.containsKey(key[0]))
props.put(key[0], new Properties());
}
return true;
}
public static boolean readConfString(Properties props, String text)
{
boolean confRead = false;
String pairs[] = text.split("[, ]+");
for(int i = 0; i < pairs.length; i++)
{
String keyval[] = pairs[i].split("=", 2);
if(keyval.length == 2)
props.put(keyval[0], keyval[1]);
confRead = true;
}
return confRead;
}
public static boolean readConfFile(Properties props, String dirs[], String fileName)
{
boolean confRead = false;
for(int i = 0; i < dirs.length; i++)
try
{
File f = new File(dirs[i] + File.separator + fileName);
if(f.exists())
{
InputStream is = new BufferedInputStream(new FileInputStream(f));
props.load(is);
is.close();
p("Loaded " + dirs[i] + File.separator + fileName + " conf file.");
confRead = true;
}
}
catch(IOException e) { }
return confRead;
}
public static boolean readMLConfFile(Properties props, String dirs[], String fileName)
{
return readMLConfFile(props, dirs, fileName, null);
}
public static boolean readMLConfFile(Properties props, String dirs[], String fileName, String domainName)
{
boolean confRead = false;
for(int i = 0; i < dirs.length; i++)
try
{
File f = new File(dirs[i] + File.separator + fileName);
if(!f.exists())
continue;
BufferedReader is = new BufferedReader(new InputStreamReader(new FileInputStream(f)));
String inputLine = new String();
String nowProp = null;
do
{
if((inputLine = is.readLine()) == null)
break;
if(domainName == null && inputLine.matches("\\s*\\[Template\\s+[aA-zZ\\*\\.]+\\s+[aA-zZ0-9/%]+\\s*\\]\\s*") || domainName != null && inputLine.matches("\\s*\\[Template\\s+" + domainName + "\\s+[aA-zZ0-9/%]+\\s+\\]\\s*"))
{
String tName[] = inputLine.replaceAll("\\[|\\]", "").split("\\s+");
tName[2] = URLDecoder.decode(tName[2], getProperty("CHAT_DEFAULT_CHARSET"));
try
{
if(tName[2].startsWith("Comment/"))
{
nowProp = null;
} else
{
props.put(tName[2], "");
nowProp = tName[2];
}
}
catch(ArrayIndexOutOfBoundsException e)
{
p("Syntax error on " + dirs[i] + File.separator + fileName + " conf file");
p("at line: \"" + inputLine + "\"");
p("Remaining data will be ignored untill the next correct section mark.");
nowProp = null;
}
} else
if(nowProp != null)
props.put(nowProp, props.get(nowProp) + inputLine);
} while(true);
is.close();
p("Loaded " + dirs[i] + File.separator + fileName + " conf file.");
confRead = true;
}
catch(IOException e) { }
return confRead;
}
static String apllyLang(Properties lang, String text)
{
lang.setProperty( getProperty("CHAT_DEFAULT_LANGUAGE") ,text);
for(Enumeration e = ((Properties)lang.get(lang)).keys(); e.hasMoreElements();)
{
String key = (String)e.nextElement();
text = text.replaceAll("<OpenCHAT:lang:" + key + ">", (String)((Properties)lang.get(lang)).get(key));
}
return text;
}
public static Properties props = new Properties();
public static Properties lang = new Properties();
static Vector threads = new Vector();
public static Root Root;
static File root;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -