Browse Source

Import JC 0.9.23

master
Bernhard Fröhlich 14 years ago
commit
2b34553e3e
56 changed files with 5262 additions and 0 deletions
  1. 53
    0
      README.md
  2. 6
    0
      config/jc.properties
  3. 1
    0
      jc.bat
  4. BIN
      jc.jar
  5. 22
    0
      jc.jardesc
  6. 51
    0
      jc.sh
  7. 120
    0
      src/at/bluenet/jc/ChatCore/LoginManager.java
  8. 227
    0
      src/at/bluenet/jc/ChatCore/User.java
  9. 220
    0
      src/at/bluenet/jc/ChatCore/UserPool.java
  10. 41
    0
      src/at/bluenet/jc/ChatCore/auth/IAuthenticator.java
  11. 57
    0
      src/at/bluenet/jc/ChatCore/auth/NoAuthenticator.java
  12. 61
    0
      src/at/bluenet/jc/Commands/AbstractCommand.java
  13. 42
    0
      src/at/bluenet/jc/Commands/ICommand.java
  14. 62
    0
      src/at/bluenet/jc/Commands/LogoutCommand.java
  15. 100
    0
      src/at/bluenet/jc/Commands/Messages/AbstractMessage.java
  16. 49
    0
      src/at/bluenet/jc/Commands/Messages/ErrorMessage.java
  17. 46
    0
      src/at/bluenet/jc/Commands/Messages/IMessage.java
  18. 55
    0
      src/at/bluenet/jc/Commands/Messages/LogoutMessage.java
  19. 86
    0
      src/at/bluenet/jc/Commands/Messages/MessageParser.java
  20. 56
    0
      src/at/bluenet/jc/Commands/Messages/NormalMessage.java
  21. 72
    0
      src/at/bluenet/jc/Commands/Messages/StatsMessage.java
  22. 71
    0
      src/at/bluenet/jc/Commands/Messages/UserInfoMessage.java
  23. 72
    0
      src/at/bluenet/jc/Commands/Messages/UserListMessage.java
  24. 57
    0
      src/at/bluenet/jc/Commands/Messages/VersionMessage.java
  25. 56
    0
      src/at/bluenet/jc/Commands/Messages/WelcomeMessage.java
  26. 58
    0
      src/at/bluenet/jc/Commands/Messages/WhisperFromMessage.java
  27. 57
    0
      src/at/bluenet/jc/Commands/Messages/WhisperToMessage.java
  28. 52
    0
      src/at/bluenet/jc/Commands/StatsCommand.java
  29. 80
    0
      src/at/bluenet/jc/Commands/UserListCommand.java
  30. 60
    0
      src/at/bluenet/jc/Commands/VersionCommand.java
  31. 74
    0
      src/at/bluenet/jc/Commands/WhisperCommand.java
  32. 89
    0
      src/at/bluenet/jc/Config.java
  33. 173
    0
      src/at/bluenet/jc/Kernel.java
  34. 241
    0
      src/at/bluenet/jc/Requests/HttpRequest.java
  35. 362
    0
      src/at/bluenet/jc/Requests/HttpResponse.java
  36. 47
    0
      src/at/bluenet/jc/Requests/IRequest.java
  37. 82
    0
      src/at/bluenet/jc/Requests/IResponse.java
  38. 59
    0
      src/at/bluenet/jc/Requests/RequestHandler/AbstractRequestHandler.java
  39. 110
    0
      src/at/bluenet/jc/Requests/RequestHandler/ChatRequestHandler.java
  40. 100
    0
      src/at/bluenet/jc/Requests/RequestHandler/ChatStreamRequestHandler.java
  41. 83
    0
      src/at/bluenet/jc/Requests/RequestHandler/DefaultRequestHandler.java
  42. 32
    0
      src/at/bluenet/jc/Requests/RequestHandler/IRequestHandler.java
  43. 92
    0
      src/at/bluenet/jc/Requests/RequestHandler/InputRequestHandler.java
  44. 70
    0
      src/at/bluenet/jc/Requests/RequestHandler/MessageRequestHandler.java
  45. 71
    0
      src/at/bluenet/jc/Requests/RequestHandler/RequestHandlerCollector.java
  46. 115
    0
      src/at/bluenet/jc/Requests/RequestHandler/StandardRequestHandler.java
  47. 100
    0
      src/at/bluenet/jc/Requests/RequestHandler/StaticRequestHandler.java
  48. 72
    0
      src/at/bluenet/jc/Requests/RequestThread.java
  49. 77
    0
      src/at/bluenet/util/Config.java
  50. 61
    0
      src/at/bluenet/util/DateDiff.java
  51. 155
    0
      src/at/bluenet/util/DiskUtil.java
  52. 25
    0
      src/at/bluenet/util/Queue.java
  53. 215
    0
      src/at/bluenet/util/StringTools.java
  54. 85
    0
      src/at/bluenet/util/VectorUtils.java
  55. 536
    0
      src/at/bluenet/util/uri/URI.java
  56. 146
    0
      src/at/bluenet/util/uri/UriUtil.java

+ 53
- 0
README.md View File

@@ -0,0 +1,53 @@

## JC (Java ChatServer)

### INSTALL

>> Windows
- edit HTTP_BASE in config/jc.properties
- start jc.bat
- take a look at http://localhost:6667/
>> Linux/Unix
- edit JC.sh
JAVA_HOME (path to JRE 1.4.2 or JRE 1.5.0)
JC_HOME (path to the base directory of JC)
JC_USER (you can run JC as root - but at your own risk!)
JC_STARTUP_LOG (the logfile)
JC_PID (the pid file of your choice)
- run it ...
./jc.sh start
- take a look at http://localhost:6667/
- stop it
./jc.sh stop


### CONFIG Files

>> jc.properties
- HTTP_BASE (default: localhost)
- PORT (default: 6667)
- MAX_SILENT_TIME (default: 3600)
- CHARSET (default: ISO-8859-1)
HTTP_BASE is your domain - eg. chat.yourdomain.com
PORT where the chat listens to


### LICENSE

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library 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
Lesser General Public License for more details.


Copyright (c) 2005 Bernhard Fröhlich <decke@bluelife.at>

+ 6
- 0
config/jc.properties View File

@@ -0,0 +1,6 @@
#Saved last on Sat Oct 08 14:42:50 CEST 2005
#Sat Oct 08 14:42:50 CEST 2005
HTTP_BASE=localhost
MAX_SILENT_TIME=3600
CHARSET=ISO-8859-1
PORT=6667

+ 1
- 0
jc.bat View File

@@ -0,0 +1 @@
java -jar jc.jar

BIN
jc.jar View File


+ 22
- 0
jc.jardesc View File

@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<jardesc>
<jar path="E:/Work/Java/builds/jc/jc.jar"/>
<options overwrite="true" compress="true" exportErrors="true" exportWarnings="true" saveDescription="true" descriptionLocation="/BLUEnetCVS/builds/jc/jc.jardesc" useSourceFolders="false" buildIfNeeded="true" includeDirectoryEntries="false"/>
<manifest manifestVersion="1.0" usesManifest="true" reuseManifest="false" saveManifest="false" generateManifest="true" manifestLocation="" mainClassHandleIdentifier="=BLUEnetCVS/java&lt;at.bluenet.jc{Kernel.java[Kernel">
<sealing sealJar="true">
<packagesToSeal/>
<packagesToUnSeal/>
</sealing>
</manifest>
<selectedElements exportClassFiles="true" exportOutputFolder="false" exportJavaFiles="false">
<javaElement handleIdentifier="=BLUEnetCVS/java&lt;at.bluenet.jc.Commands"/>
<javaElement handleIdentifier="=BLUEnetCVS/java&lt;at.bluenet.jc.Commands.Messages"/>
<javaElement handleIdentifier="=BLUEnetCVS/java&lt;at.bluenet.util"/>
<javaElement handleIdentifier="=BLUEnetCVS/java&lt;at.bluenet.jc"/>
<javaElement handleIdentifier="=BLUEnetCVS/java&lt;at.bluenet.jc.ChatCore.auth"/>
<javaElement handleIdentifier="=BLUEnetCVS/java&lt;at.bluenet.jc.Requests"/>
<javaElement handleIdentifier="=BLUEnetCVS/java&lt;at.bluenet.jc.ChatCore"/>
<javaElement handleIdentifier="=BLUEnetCVS/java&lt;at.bluenet.jc.Requests.RequestHandler"/>
<javaElement handleIdentifier="=BLUEnetCVS/java&lt;at.bluenet.util.uri"/>
</selectedElements>
</jardesc>

+ 51
- 0
jc.sh View File

@@ -0,0 +1,51 @@
#!/bin/sh

JAVA_HOME=/usr/java/jre1.5.0_01
export JAVA_HOME

JC_HOME=/usr/local/jc
JC_USER=jcdaemon
JC_LOG=/var/log/jc.log
JC_PID=/var/run/jc.pid

startJC() {
su -c "$*" $JC_USER 2>/dev/null > $JC_LOG &
hpid=$!
echo $hpid
/bin/ps h $hpid >/dev/null 2>&1
echo $hpid > $JC_PID
}

start() {
echo -n "Starting JC: "
startJC $JAVA_HOME/bin/java -jar $JC_HOME/jc.jar -b=$JC_HOME
}
stop() {
echo -n "Shutting down JC: "
if [ -f $JC_PID ] ; then
pid=`head -1 $JC_PID`
kill -SIGTERM $pid && echo "KILLED"
else
echo "NOT RUNNING"
fi
rm -f $JC_PID
}

# See how we were called
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
sleep 5
start
;;
*)
echo "Usage: $0 {start|stop|restart}"
esac

exit 0

+ 120
- 0
src/at/bluenet/jc/ChatCore/LoginManager.java View File

@@ -0,0 +1,120 @@
/* ************************************************************************** */
/* Project : JC (Java ChatServer) */
/* */
/* Author : Bernhard Fröhlich <decke@users.sourceforge.net> */
/* Homepage: http://decke.staticip.de/ */
/* Copyright (c) 2005 Bernhard Fröhlich <decke@users.sourceforge.net> */
/* */
/* This library is free software; you can redistribute it and/or */
/* modify it under the terms of the GNU Lesser General Public */
/* License as published by the Free Software Foundation; either */
/* version 2.1 of the License, or (at your option) any later version. */
/* */
/* This library 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 */
/* Lesser General Public License for more details. */
/* */
/* ************************************************************************** */
package at.bluenet.jc.ChatCore;
import at.bluenet.jc.Requests.IRequest;
import at.bluenet.jc.Requests.IResponse;
import at.bluenet.jc.ChatCore.UserPool;
import at.bluenet.jc.ChatCore.auth.IAuthenticator;
import java.util.Map;
import java.util.Collections;
import java.util.HashMap;
import java.util.Random;
import java.util.Date;
import java.util.Iterator;
import java.lang.IllegalStateException;
/**
* <p>Title: </p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2005</p>
*
* <p>Company: </p>
*
* @author Bernhard Fröhlich
* @version 1.0
*/
public class LoginManager
{
Map openSessions;
IAuthenticator auth;
UserPool userpool;
public LoginManager(UserPool userpool, IAuthenticator auth)
{
this.userpool = userpool;
this.auth = auth;
this.openSessions = Collections.synchronizedMap(new HashMap());
}
public String login(String username, String password, String color)
{
// check ob bereits im Userpool vorhanden
if(userpool.isOnline(username) || username.length() < 3)
return null;
// check ob Passwort stimmt
User user = auth.login(username, password);
if(user == null)
return null;
user.setSession(generateRandomSession());
user.setSessionCreateDate(new Date());
user.setColor(color);
openSessions.put(user.getSession(), user);
return user.getSession();
}
public boolean canLogin(String session)
{
return openSessions.containsKey(session);
}
public void login(String session, IRequest request, IResponse response) throws java.lang.IllegalStateException
{
cleanup();
if(canLogin(session))
{
User user = (User)openSessions.get(session);
openSessions.remove(session);
user.setRequest(request);
user.setResponse(response);
user.setLoginDate(new Date());
user.setLastMessageDate();
userpool.addUser(user);
}
else
throw new IllegalStateException("Invalid Session");
}
private String generateRandomSession()
{
Random generator = new Random();
return Integer.toString(Math.abs(generator.nextInt() + generator.nextInt()));
}
private void cleanup()
{
Iterator users = openSessions.values().iterator();
while(users.hasNext())
{
User user = (User)users.next();
if(at.bluenet.util.DateDiff.diff(user.getSessionCreateDate()) > 15)
openSessions.remove(user.getSession());
}
}
}

+ 227
- 0
src/at/bluenet/jc/ChatCore/User.java View File

@@ -0,0 +1,227 @@
/* ************************************************************************** */
/* Project : JC (Java ChatServer) */
/* */
/* Author : Bernhard Fröhlich <decke@users.sourceforge.net> */
/* Homepage: http://decke.staticip.de/ */
/* Copyright (c) 2005 Bernhard Fröhlich <decke@users.sourceforge.net> */
/* */
/* This library is free software; you can redistribute it and/or */
/* modify it under the terms of the GNU Lesser General Public */
/* License as published by the Free Software Foundation; either */
/* version 2.1 of the License, or (at your option) any later version. */
/* */
/* This library 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 */
/* Lesser General Public License for more details. */
/* */
/* ************************************************************************** */
package at.bluenet.jc.ChatCore;
import at.bluenet.jc.Requests.IRequest;
import at.bluenet.jc.Requests.IResponse;
import at.bluenet.util.Queue;
import java.util.Date;
import java.io.IOException;
import java.io.BufferedOutputStream;
/**
* <p>Title: </p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2005</p>
*
* <p>Company: </p>
*
* @author Bernhard Fröhlich
* @version 1.0
*/
public class User extends Thread
{
private String username = null;
private String password = null;
private String color = "#000000";
private String session = null;
private Date sessionCreateDate = null;
private Date loginDate = null;
private Date lastMessageDate = null;
private IRequest request;
private IResponse response;
private Queue messages = new Queue();
public User(String username)
{
this.username = username;
}
public User(String username, IRequest request, IResponse response)
{
this.username = username;
this.request = request;
this.response = response;
}
public User(String username, String password, IRequest request, IResponse response)
{
this.username = username;
this.password = password;
this.request = request;
this.response = response;
}
public User(String username, String password, String color, IRequest request, IResponse response)
{
this.username = username;
this.password = password;
this.color = color;
this.request = request;
this.response = response;
}
public void run()
{
while(!isInterrupted())
{
try
{
synchronized(messages)
{
try
{
String message = (String)messages.get();
if(message != null)
{
BufferedOutputStream out = response.getBufferedOutputStream();
out.write(message.getBytes());
out.flush();
}
messages.wait(10000);
}
catch (IOException e)
{
close();
}
}
}
catch (InterruptedException e)
{
interrupt();
break;
}
catch (Exception e)
{
System.out.println(this.getClass().getName() + "::run(): " + e.getMessage());
e.printStackTrace();
}
}
}
public void send(String message)
{
synchronized(messages)
{
messages.add(message);
messages.notifyAll();
}
}
public void setRequest(IRequest request)
{
this.request = request;
}
public void setResponse(IResponse response)
{
this.response = response;
}
public void setSessionCreateDate(Date create)
{
this.sessionCreateDate = create;
}
public void setLoginDate(Date login)
{
loginDate = login;
}
public void setLastMessageDate(Date lastMessageDate)
{
this.lastMessageDate = lastMessageDate;
}
public void setLastMessageDate()
{
this.lastMessageDate = new Date();
}
public void setSession(String session)
{
this.session = session;
}
public void setColor(String color)
{
this.color = color;
}
public String getUsername()
{
return username;
}
public String getColor()
{
return color;
}
public String getPassword()
{
return password;
}
public String getSession()
{
return session;
}
public Date getSessionCreateDate()
{
return this.sessionCreateDate;
}
public Date getLoginDate()
{
return this.loginDate;
}
public Date getLastMessageDate()
{
return this.lastMessageDate;
}
public String getHeader(String header)
{
return request.getHeader(header);
}
public String getIP()
{
return request.getIP().getHostAddress();
}
public boolean isSocketClosed()
{
return response.isSocketClosed();
}
public void close()
{
response.close();
this.interrupt();
}
}

+ 220
- 0
src/at/bluenet/jc/ChatCore/UserPool.java View File

@@ -0,0 +1,220 @@
/* ************************************************************************** */
/* Project : JC (Java ChatServer) */
/* */
/* Author : Bernhard Fröhlich <decke@users.sourceforge.net> */
/* Homepage: http://decke.staticip.de/ */
/* Copyright (c) 2005 Bernhard Fröhlich <decke@users.sourceforge.net> */
/* */
/* This library is free software; you can redistribute it and/or */
/* modify it under the terms of the GNU Lesser General Public */
/* License as published by the Free Software Foundation; either */
/* version 2.1 of the License, or (at your option) any later version. */
/* */
/* This library 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 */
/* Lesser General Public License for more details. */
/* */
/* ************************************************************************** */
package at.bluenet.jc.ChatCore;
import at.bluenet.jc.Commands.Messages.IMessage;
import at.bluenet.jc.Commands.Messages.LogoutMessage;
import at.bluenet.jc.Commands.Messages.MessageParser;
import at.bluenet.jc.Commands.Messages.WelcomeMessage;
import at.bluenet.util.DateDiff;
import java.util.Vector;
import java.util.Enumeration;
import java.util.Hashtable;
/**
* <p>Title: </p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2005</p>
*
* <p>Company: </p>
*
* @author Bernhard Fröhlich
* @version 1.0
*/
public class UserPool extends Thread
{
private Hashtable userpool = new Hashtable();
private Vector vUserPool = new Vector();
private Vector messages = new Vector();
private MessageParser parser;
public UserPool(MessageParser messageParser)
{
parser = messageParser;
}
public boolean isOnline(String username)
{
if(username == null)
return false;
synchronized(userpool)
{
return userpool.containsKey(username.toLowerCase());
}
}
public synchronized Enumeration getUsers()
{
return userpool.elements();
}
public synchronized Vector getUsersVector()
{
return vUserPool;
}
public synchronized User getUser(String username)
{
return (User)userpool.get(username.toLowerCase());
}
public void addUser(User user)
{
System.out.println("USERPOOL --- Adding User: " + user.getUsername());
user.setLastMessageDate();
synchronized(userpool)
{
user.start();
userpool.put(user.getUsername().toLowerCase(), user);
userpool.notifyAll();
}
synchronized(vUserPool)
{
vUserPool.add(user);
}
addMessage(new WelcomeMessage(user, vUserPool));
}
public void logoutUser(User user, String reason)
{
System.out.println("USERPOOL --- Logout User: '" + user.getUsername() + "' Reason: " + reason);
if(reason.length() > 0)
user.send("--logout (Reason: " + reason + ")");
synchronized(userpool)
{
userpool.remove(user.getUsername().toLowerCase());
}
synchronized(vUserPool)
{
vUserPool.remove(user);
}
user.close();
addMessage(new LogoutMessage(user, vUserPool));
}
public void addMessage(User user, String rawMessage)
{
user.setLastMessageDate();
Vector msges = parser.parse(user, rawMessage);
synchronized(messages)
{
messages.addAll(msges);
messages.notifyAll();
}
}
public void addMessage(IMessage message)
{
synchronized(messages)
{
messages.add(message);
messages.notifyAll();
}
}
public void run()
{
while(!isInterrupted())
{
try
{
synchronized (messages)
{
while (messages.size() != 0)
{
IMessage message = (IMessage) messages.remove(messages.size()-1);
Enumeration users = message.getRecipients().elements();
while (users.hasMoreElements())
{
((User) users.nextElement()).send(message.toRawMessage());
}
}
messages.wait(10000);
cleanup();
}
}
catch (InterruptedException e)
{
interrupt();
}
catch (Exception e)
{
System.out.println(this.getClass().getName() + "::run(): " + e.getMessage());
e.printStackTrace();
}
}
System.out.println("UserPool: OUT OF RUN()");
}
public void close()
{
try
{
synchronized(userpool)
{
for(int i=0; i < userpool.size(); i++)
{
Enumeration users = userpool.elements();
while(users.hasMoreElements())
{
logoutUser((User)users.nextElement(), "Server Shutdown");
}
}
}
interrupt();
}
catch(Exception e)
{
System.out.println("UserPool: failed closing(). " + e.getMessage());
}
}
private void cleanup()
{
synchronized(userpool)
{
Enumeration users = userpool.elements();
while(users.hasMoreElements())
{
User user = (User)users.nextElement();
if(user.isSocketClosed())
logoutUser(user, "Socket broken");
if(DateDiff.diff(user.getLastMessageDate()) > Integer.parseInt(at.bluenet.jc.Kernel.CONFIG.get("MAX_SILENT_TIME", "900")))
logoutUser(user, "Silet for more than " + at.bluenet.jc.Kernel.CONFIG.get("MAX_SILENT_TIME", "900") + " Seconds.");
}
}
}
}

+ 41
- 0
src/at/bluenet/jc/ChatCore/auth/IAuthenticator.java View File

@@ -0,0 +1,41 @@
/* ************************************************************************** */
/* Project : JC (Java ChatServer) */
/* */
/* Author : Bernhard Fröhlich <decke@users.sourceforge.net> */
/* Homepage: http://decke.staticip.de/ */
/* Copyright (c) 2005 Bernhard Fröhlich <decke@users.sourceforge.net> */
/* */
/* This library is free software; you can redistribute it and/or */
/* modify it under the terms of the GNU Lesser General Public */
/* License as published by the Free Software Foundation; either */
/* version 2.1 of the License, or (at your option) any later version. */
/* */
/* This library 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 */
/* Lesser General Public License for more details. */
/* */
/* ************************************************************************** */
package at.bluenet.jc.ChatCore.auth;
import at.bluenet.jc.ChatCore.User;
/**
* <p>Title: </p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2005</p>
*
* <p>Company: </p>
*
* @author Bernhard Fröhlich
* @version 1.0
*/
public interface IAuthenticator
{
// check ob bereits im Userpool vorhanden
// check ob Passwort stimmt
// dann _eventuellen_ Logout eines gleichnamigen Users
public abstract User login(String username, String password);
}

+ 57
- 0
src/at/bluenet/jc/ChatCore/auth/NoAuthenticator.java View File

@@ -0,0 +1,57 @@
/* ************************************************************************** */
/* Project : JC (Java ChatServer) */
/* */
/* Author : Bernhard Fröhlich <decke@users.sourceforge.net> */
/* Homepage: http://decke.staticip.de/ */
/* Copyright (c) 2005 Bernhard Fröhlich <decke@users.sourceforge.net> */
/* */
/* This library is free software; you can redistribute it and/or */
/* modify it under the terms of the GNU Lesser General Public */
/* License as published by the Free Software Foundation; either */
/* version 2.1 of the License, or (at your option) any later version. */
/* */
/* This library 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 */
/* Lesser General Public License for more details. */
/* */
/* ************************************************************************** */
package at.bluenet.jc.ChatCore.auth;
import at.bluenet.jc.ChatCore.User;
/**
* <p>Title: </p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2005</p>
*
* <p>Company: </p>
*
* @author Bernhard Fröhlich
* @version 1.0
*/
public class NoAuthenticator implements IAuthenticator
{
//UserPool userpool;
public NoAuthenticator()
{
//userpool = pool;
}
/**
* login
*
* @param username String
* @param password String
* @return IUser
* @todo Implement this at.bluenet.www.JC.ChatCore.IAuthenticator method
*/
public User login(String username, String password)
{
return new User(username);
}
}

+ 61
- 0
src/at/bluenet/jc/Commands/AbstractCommand.java View File

@@ -0,0 +1,61 @@
/* ************************************************************************** */
/* Project : JC (Java ChatServer) */
/* */
/* Author : Bernhard Fröhlich <decke@users.sourceforge.net> */
/* Homepage: http://decke.staticip.de/ */
/* Copyright (c) 2005 Bernhard Fröhlich <decke@users.sourceforge.net> */
/* */
/* This library is free software; you can redistribute it and/or */
/* modify it under the terms of the GNU Lesser General Public */
/* License as published by the Free Software Foundation; either */
/* version 2.1 of the License, or (at your option) any later version. */
/* */
/* This library 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 */
/* Lesser General Public License for more details. */
/* */
/* ************************************************************************** */
package at.bluenet.jc.Commands;
import at.bluenet.jc.ChatCore.User;
import java.util.Vector;
/**
* <p>Title: </p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2005</p>
*
* <p>Company: </p>
*
* @author Bernhard Fröhlich
* @version 1.0
*/
public abstract class AbstractCommand implements ICommand
{
protected String command;
/**
* getCommand
*
* @return String
* @todo Implement this at.bluenet.www.JC.Commands.ICommand method
*/
public String getCommand() {
return command;
}
/**
* parse
*
* @param user User
* @param rawMessage String
* @return IMessage
* @todo Implement this at.bluenet.www.JC.Commands.ICommand method
*/
public abstract Vector parse(User user, String rawMessage);
}

+ 42
- 0
src/at/bluenet/jc/Commands/ICommand.java View File

@@ -0,0 +1,42 @@
/* ************************************************************************** */
/* Project : JC (Java ChatServer) */
/* */
/* Author : Bernhard Fröhlich <decke@users.sourceforge.net> */
/* Homepage: http://decke.staticip.de/ */
/* Copyright (c) 2005 Bernhard Fröhlich <decke@users.sourceforge.net> */
/* */
/* This library is free software; you can redistribute it and/or */
/* modify it under the terms of the GNU Lesser General Public */
/* License as published by the Free Software Foundation; either */
/* version 2.1 of the License, or (at your option) any later version. */
/* */
/* This library 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 */
/* Lesser General Public License for more details. */
/* */
/* ************************************************************************** */
package at.bluenet.jc.Commands;
import at.bluenet.jc.ChatCore.User;
import java.util.Vector;
/**
* <p>Title: </p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2005</p>
*
* <p>Company: </p>
*
* @author Bernhard Fröhlich
* @version 1.0
*/
public interface ICommand
{
public abstract String getCommand();
public abstract Vector parse(User user, String rawMessage);
}

+ 62
- 0
src/at/bluenet/jc/Commands/LogoutCommand.java View File

@@ -0,0 +1,62 @@
/* ************************************************************************** */
/* Project : JC (Java ChatServer) */
/* */
/* Author : Bernhard Fröhlich <decke@users.sourceforge.net> */
/* Homepage: http://decke.staticip.de/ */
/* Copyright (c) 2005 Bernhard Fröhlich <decke@users.sourceforge.net> */
/* */
/* This library is free software; you can redistribute it and/or */
/* modify it under the terms of the GNU Lesser General Public */
/* License as published by the Free Software Foundation; either */
/* version 2.1 of the License, or (at your option) any later version. */
/* */
/* This library 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 */
/* Lesser General Public License for more details. */
/* */
/* ************************************************************************** */
package at.bluenet.jc.Commands;
import java.util.Vector;
import at.bluenet.jc.ChatCore.User;
import at.bluenet.jc.ChatCore.UserPool;
/**
* <p>Title: </p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2005</p>
*
* <p>Company: </p>
*
* @author Bernhard Fröhlich
* @version 1.0
*/
public class LogoutCommand extends AbstractCommand
{
private UserPool pool;
public LogoutCommand(UserPool pool)
{
this.pool = pool;
this.command = "/q";
}
/**
* parse
*
* @param user User
* @param rawMessage String
* @return Vector
* @todo Implement this at.bluenet.www.JC.Commands.ICommand method
*/
public Vector parse(User user, String rawMessage)
{
pool.logoutUser(user, "Normal Logout");
return null;
}
}

+ 100
- 0
src/at/bluenet/jc/Commands/Messages/AbstractMessage.java View File

@@ -0,0 +1,100 @@
/* ************************************************************************** */
/* Project : JC (Java ChatServer) */
/* */
/* Author : Bernhard Fröhlich <decke@users.sourceforge.net> */
/* Homepage: http://decke.staticip.de/ */
/* Copyright (c) 2005 Bernhard Fröhlich <decke@users.sourceforge.net> */
/* */
/* This library is free software; you can redistribute it and/or */
/* modify it under the terms of the GNU Lesser General Public */
/* License as published by the Free Software Foundation; either */
/* version 2.1 of the License, or (at your option) any later version. */
/* */
/* This library 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 */
/* Lesser General Public License for more details. */
/* */
/* ************************************************************************** */
package at.bluenet.jc.Commands.Messages;
import java.util.Vector;
import at.bluenet.jc.ChatCore.*;
/**
* <p>Title: </p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2005</p>
*
* <p>Company: </p>
*
* @author Bernhard Fröhlich
* @version 1.0
*/
public abstract class AbstractMessage implements IMessage
{
protected User sender;
private Vector recipients = new Vector();
protected String message;
/**
* addRecipients
*
* @param users Vector
* @todo Implement this at.bluenet.www.JC.Messages.IMessage method
*/
public void addRecipients(Vector vUsers)
{
//Enumeration users = vUsers.elements();
//while(users.hasMoreElements())
// recipients.add(users.nextElement());
recipients.addAll(vUsers);
}
public void addRecipient(User user)
{
recipients.add(user);
}
/**
* getMessage
*
* @return String
* @todo Implement this at.bluenet.www.JC.Messages.IMessage method
*/
public String getMessage() {
return message;
}
/**
* getRecipients
*
* @return Vector
* @todo Implement this at.bluenet.www.JC.Messages.IMessage method
*/
public Vector getRecipients() {
return recipients;
}
/**
* getSender
*
* @return User
* @todo Implement this at.bluenet.www.JC.Messages.IMessage method
*/
public User getSender() {
return sender;
}
/**
* toRawMessage
*
* @return String
* @todo Implement this at.bluenet.www.JC.Messages.IMessage method
*/
abstract public String toRawMessage();
}

+ 49
- 0
src/at/bluenet/jc/Commands/Messages/ErrorMessage.java View File

@@ -0,0 +1,49 @@
/* ************************************************************************** */
/* Project : JC (Java ChatServer) */
/* */
/* Author : Bernhard Fröhlich <decke@users.sourceforge.net> */
/* Homepage: http://decke.staticip.de/ */
/* Copyright (c) 2005 Bernhard Fröhlich <decke@users.sourceforge.net> */
/* */
/* This library is free software; you can redistribute it and/or */
/* modify it under the terms of the GNU Lesser General Public */
/* License as published by the Free Software Foundation; either */
/* version 2.1 of the License, or (at your option) any later version. */
/* */
/* This library 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 */
/* Lesser General Public License for more details. */
/* */
/* ************************************************************************** */
package at.bluenet.jc.Commands.Messages;
import at.bluenet.jc.ChatCore.User;
/**
* <p>Title: </p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2005</p>
*
* <p>Company: </p>
*
* @author Bernhard Fröhlich
* @version 1.0
*/
public class ErrorMessage extends AbstractMessage
{
public ErrorMessage(User sender, String message)
{
this.sender = sender;
this.message = message;
addRecipient(sender);
}
public String toRawMessage()
{
return "<i><b>" + message + "</b></i><br />";
}
}

+ 46
- 0
src/at/bluenet/jc/Commands/Messages/IMessage.java View File

@@ -0,0 +1,46 @@
/* ************************************************************************** */
/* Project : JC (Java ChatServer) */
/* */
/* Author : Bernhard Fröhlich <decke@users.sourceforge.net> */
/* Homepage: http://decke.staticip.de/ */
/* Copyright (c) 2005 Bernhard Fröhlich <decke@users.sourceforge.net> */
/* */
/* This library is free software; you can redistribute it and/or */
/* modify it under the terms of the GNU Lesser General Public */
/* License as published by the Free Software Foundation; either */
/* version 2.1 of the License, or (at your option) any later version. */
/* */
/* This library 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 */
/* Lesser General Public License for more details. */
/* */
/* ************************************************************************** */
package at.bluenet.jc.Commands.Messages;
import at.bluenet.jc.ChatCore.User;
import java.util.Vector;
/**
* <p>Title: </p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2005</p>
*
* <p>Company: </p>
*
* @author Bernhard Fröhlich
* @version 1.0
*/
public interface IMessage
{
public abstract String toRawMessage();
public abstract String getMessage();
public abstract Vector getRecipients();
public abstract User getSender();
public abstract void addRecipients(Vector users);
public abstract void addRecipient(User user);
}

+ 55
- 0
src/at/bluenet/jc/Commands/Messages/LogoutMessage.java View File

@@ -0,0 +1,55 @@
/* ************************************************************************** */
/* Project : JC (Java ChatServer) */
/* */
/* Author : Bernhard Fröhlich <decke@users.sourceforge.net> */
/* Homepage: http://decke.staticip.de/ */
/* Copyright (c) 2005 Bernhard Fröhlich <decke@users.sourceforge.net> */
/* */
/* This library is free software; you can redistribute it and/or */
/* modify it under the terms of the GNU Lesser General Public */
/* License as published by the Free Software Foundation; either */
/* version 2.1 of the License, or (at your option) any later version. */
/* */
/* This library 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 */
/* Lesser General Public License for more details. */
/* */
/* ************************************************************************** */
package at.bluenet.jc.Commands.Messages;
import java.util.Vector;
import at.bluenet.jc.ChatCore.User;
/**
* <p>Title: </p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2005</p>
*
* <p>Company: </p>
*
* @author Bernhard Fröhlich
* @version 1.0
*/
public class LogoutMessage extends AbstractMessage
{
public LogoutMessage(User sender, Vector recipients)
{
this.sender = sender;
addRecipients(recipients);
}
/**
* toRawMessage
*
* @return String
* @todo Implement this at.bluenet.www.JC.Messages.IMessage method
*/
public String toRawMessage()
{
return "<i><b><a href=\"/\"><font color=\"" + sender.getColor() + "\"><u>" + sender.getUsername() + "</u></font></a></b> verlässt den Chat.</i><br>\n";
}
}

+ 86
- 0
src/at/bluenet/jc/Commands/Messages/MessageParser.java View File

@@ -0,0 +1,86 @@
/* ************************************************************************** */
/* Project : JC (Java ChatServer) */
/* */
/* Author : Bernhard Fröhlich <decke@users.sourceforge.net> */
/* Homepage: http://decke.staticip.de/ */
/* Copyright (c) 2005 Bernhard Fröhlich <decke@users.sourceforge.net> */
/* */
/* This library is free software; you can redistribute it and/or */
/* modify it under the terms of the GNU Lesser General Public */
/* License as published by the Free Software Foundation; either */
/* version 2.1 of the License, or (at your option) any later version. */
/* */
/* This library 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 */
/* Lesser General Public License for more details. */
/* */
/* ************************************************************************** */
package at.bluenet.jc.Commands.Messages;
import at.bluenet.jc.ChatCore.User;
import at.bluenet.jc.ChatCore.UserPool;
import at.bluenet.jc.Commands.ICommand;
import at.bluenet.util.StringTools;
import java.util.Vector;
import java.util.HashMap;
import java.util.Map;
/**
* <p>Title: </p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2005</p>
*
* <p>Company: </p>
*
* @author Bernhard Fröhlich
* @version 1.0
*/
public class MessageParser
{
Map commands = java.util.Collections.synchronizedMap(new HashMap());
UserPool pool;
public MessageParser()
{
}
public void addCommand(ICommand cmd)
{
commands.put(cmd.getCommand().toLowerCase(), cmd);
}
public void setUserPool(UserPool userpool)
{
this.pool = userpool;
}
public Vector parse(User sender, String rawMessage)
{
Vector v = new Vector();
String[] parts = StringTools.split(rawMessage, ' ');
if(parts.length > 0 && commands.containsKey(parts[0]))
{
Vector msges = ((ICommand)commands.get(parts[0])).parse(sender, rawMessage);
if(msges != null)
v.addAll(msges);
}
else
{
if(rawMessage.startsWith("/"))
{
Vector msges = ((ICommand)commands.get("/")).parse(sender, rawMessage);
v.addAll(msges);
}
else
v.add(new NormalMessage(sender, rawMessage, pool.getUsersVector()));
}
return v;
}
}

+ 56
- 0
src/at/bluenet/jc/Commands/Messages/NormalMessage.java View File

@@ -0,0 +1,56 @@
/* ************************************************************************** */
/* Project : JC (Java ChatServer) */
/* */
/* Author : Bernhard Fröhlich <decke@users.sourceforge.net> */
/* Homepage: http://decke.staticip.de/ */
/* Copyright (c) 2005 Bernhard Fröhlich <decke@users.sourceforge.net> */
/* */
/* This library is free software; you can redistribute it and/or */
/* modify it under the terms of the GNU Lesser General Public */
/* License as published by the Free Software Foundation; either */
/* version 2.1 of the License, or (at your option) any later version. */
/* */
/* This library 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 */
/* Lesser General Public License for more details. */
/* */
/* ************************************************************************** */
package at.bluenet.jc.Commands.Messages;
import at.bluenet.jc.ChatCore.User;
import java.util.Vector;
/**
* <p>Title: </p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2005</p>
*
* <p>Company: </p>
*
* @author Bernhard Fröhlich
* @version 1.0
*/
public class NormalMessage extends AbstractMessage
{
public NormalMessage(User sender, String message, Vector recipients)
{
this.sender = sender;
this.message = message;
addRecipients(recipients);
}
/**
* toRawMessage
*
* @return String
*/
public String toRawMessage()
{
return "<font color=\"" + sender.getColor() + "\">(<a href=\"/\"><font color=\"" + sender.getColor() + "\"><u>" + sender.getUsername() + "</u></font></a>) " + message + "</font><br />\n";
}
}

+ 72
- 0
src/at/bluenet/jc/Commands/Messages/StatsMessage.java View File

@@ -0,0 +1,72 @@
/* ************************************************************************** */
/* Project : JC (Java ChatServer) */
/* */
/* Author : Bernhard Fröhlich <decke@users.sourceforge.net> */
/* Homepage: http://decke.staticip.de/ */
/* Copyright (c) 2005 Bernhard Fröhlich <decke@users.sourceforge.net> */
/* */
/* This library is free software; you can redistribute it and/or */
/* modify it under the terms of the GNU Lesser General Public */
/* License as published by the Free Software Foundation; either */
/* version 2.1 of the License, or (at your option) any later version. */
/* */
/* This library 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 */
/* Lesser General Public License for more details. */
/* */
/* ************************************************************************** */
package at.bluenet.jc.Commands.Messages;
import at.bluenet.jc.ChatCore.User;
import java.lang.StringBuffer;
/**
* <p>Title: </p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2005</p>
*
* <p>Company: </p>
*
* @author Bernhard Fröhlich
* @version 1.0
*/
public class StatsMessage extends AbstractMessage
{
public StatsMessage(User user)
{
this.sender = user;
addRecipient(user);
}
/**
* toRawMessage
*
* @return String
* @todo Implement this at.bluenet.www.JC.Commands.Messages.IMessage
* method
*/
public String toRawMessage()
{
StringBuffer sb = new StringBuffer();
Runtime r = Runtime.getRuntime ();
sb.append((new VersionMessage(sender)).toRawMessage());
sb.append("<b>OS:</b> " + System.getProperty("os.name") + " (" + System.getProperty("os.arch") + ")<br />");
sb.append("<b>VM Version:</b> " + System.getProperty("java.version") + "/" + System.getProperty("java.vendor") + "<br />");
sb.append("<b>Default Charset:</b> " + at.bluenet.jc.Kernel.DEFAULT_CHARSET + "<br /><br />");
sb.append("<b>Memory:</b><br />");
sb.append("VM MaxSize: " + ((r.maxMemory()/1024)/1024) + "MB<br />");
sb.append("VM CurSize: " + ((r.totalMemory()/1024)/1024) + "MB<br />");
sb.append("Free: " + ((r.freeMemory()/1024)/1024) + "MB<br />");
sb.append("Used: " + (((r.totalMemory()-r.freeMemory())/1024)/1024) + "MB<br /><br />");
return sb.toString();
}
}

+ 71
- 0
src/at/bluenet/jc/Commands/Messages/UserInfoMessage.java View File

@@ -0,0 +1,71 @@
/* ************************************************************************** */
/* Project : JC (Java ChatServer) */
/* */
/* Author : Bernhard Fröhlich <decke@users.sourceforge.net> */
/* Homepage: http://decke.staticip.de/ */
/* Copyright (c) 2005 Bernhard Fröhlich <decke@users.sourceforge.net> */
/* */
/* This library is free software; you can redistribute it and/or */
/* modify it under the terms of the GNU Lesser General Public */
/* License as published by the Free Software Foundation; either */
/* version 2.1 of the License, or (at your option) any later version. */
/* */
/* This library 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 */
/* Lesser General Public License for more details. */
/* */
/* ************************************************************************** */
package at.bluenet.jc.Commands.Messages;
import at.bluenet.jc.ChatCore.User;
/**
* <p>Title: </p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2005</p>
*
* <p>Company: </p>
*
* @author Bernhard Fröhlich
* @version 1.0
*/
public class UserInfoMessage extends AbstractMessage
{
private User who;
public UserInfoMessage(User from, User who)
{
this.sender = from;
this.who = who;
addRecipient(from);
}
/**
* toRawMessage
*
* @return String
* @todo Implement this at.bluenet.www.JC.Messages.IMessage method
*/
public String toRawMessage()
{
String message = "";
message += "* <font color=\"" + who.getColor() + "\"><b>" + who.getUsername() + "</b></font> , seit dem " + java.text.DateFormat.getDateTimeInstance().format(who.getLoginDate()) + " im Chat.<br />\n";
message += "- still seit " + at.bluenet.util.DateDiff.diff(who.getLastMessageDate()) + " Sekunden<br />\n";
message += "- OS/Browser: " + who.getHeader("User-Agent") + "<br />\n";
message += "- Farbcode: " + who.getColor() + "<br />\n";
if(who.getHeader("X-Forwarded-For") != null)
{
message += "- Proxy IP: " + who.getIP() + "<br />\n";
message += "- Echt IP: " + who.getHeader("X-Forwarded-For") + "<br />\n";
}
else
message += "- Echt IP: " + who.getIP() + "<br />\n";
return message;
}
}

+ 72
- 0
src/at/bluenet/jc/Commands/Messages/UserListMessage.java View File

@@ -0,0 +1,72 @@
/* ************************************************************************** */
/* Project : JC (Java ChatServer) */
/* */
/* Author : Bernhard Fröhlich <decke@users.sourceforge.net> */
/* Homepage: http://decke.staticip.de/ */
/* Copyright (c) 2005 Bernhard Fröhlich <decke@users.sourceforge.net> */
/* */
/* This library is free software; you can redistribute it and/or */
/* modify it under the terms of the GNU Lesser General Public */
/* License as published by the Free Software Foundation; either */
/* version 2.1 of the License, or (at your option) any later version. */
/* */
/* This library 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 */
/* Lesser General Public License for more details. */
/* */
/* ************************************************************************** */
package at.bluenet.jc.Commands.Messages;
import at.bluenet.jc.ChatCore.User;
import java.util.Enumeration;
/**
* <p>Title: </p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2005</p>
*
* <p>Company: </p>
*
* @author Bernhard Fröhlich
* @version 1.0
*/
public class UserListMessage extends AbstractMessage
{
private Enumeration users;
public UserListMessage(User sender, Enumeration users)
{
this.sender = sender;
this.users = users;
addRecipient(sender);
}
/**
* toRawMessage
*
* @return String
* @todo Implement this at.bluenet.www.JC.Messages.IMessage method
*/
public String toRawMessage()
{
int i=0;
String message = "<b>Folgende User befinden sich im Chat:</b><br />\n";
while (this.users.hasMoreElements())
{
User usr = (User) this.users.nextElement();
message += "<b>~ <font color=\"" + usr.getColor() + "\">" + usr.getUsername() + "</font></b>";
message += " still seit " + at.bluenet.util.DateDiff.diff(usr.getLastMessageDate()) + " Sekunden</b><br />\n";
i++;
}
message += "<b>~ " + i + " Chatter</b><br />\n";
return message;
}
}

+ 57
- 0
src/at/bluenet/jc/Commands/Messages/VersionMessage.java View File

@@ -0,0 +1,57 @@
/* ************************************************************************** */
/* Project : JC (Java ChatServer) */
/* */
/* Author : Bernhard Fröhlich <decke@users.sourceforge.net> */
/* Homepage: http://decke.staticip.de/ */
/* Copyright (c) 2005 Bernhard Fröhlich <decke@users.sourceforge.net> */
/* */
/* This library is free software; you can redistribute it and/or */
/* modify it under the terms of the GNU Lesser General Public */
/* License as published by the Free Software Foundation; either */
/* version 2.1 of the License, or (at your option) any later version. */
/* */
/* This library 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 */
/* Lesser General Public License for more details. */
/* */
/* ************************************************************************** */
package at.bluenet.jc.Commands.Messages;
import at.bluenet.jc.ChatCore.User;
/**
* <p>Title: </p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2005</p>
*
* <p>Company: </p>
*
* @author Bernhard Fröhlich
* @version 1.0
*/
public class VersionMessage extends AbstractMessage
{
public VersionMessage(User sender)
{
addRecipient(sender);
}
/**
* toRawMessage
*
* @return String
* @todo Implement this at.bluenet.www.JC.Commands.Messages.IMessage
* method
*/
public String toRawMessage()
{
String v = "<br /><font size=\"+1\"><b><i>JC " + at.bluenet.jc.Kernel.VERSION + "</i></b></font><br /><br />";
v += "<b>Version:</b> " + at.bluenet.jc.Kernel.VERSION_STRING + "<br />";
v += "<b>Author:</b> Bernhard Fröhlich (decke@users.sourceforge.net)<br />";
v += "<b>Homepage:</b> <a href=\"http://decke.staticip.de\" target=\"_blank\">http://decke.staticip.de/</a><br /><br />";
return v;
}
}

+ 56
- 0
src/at/bluenet/jc/Commands/Messages/WelcomeMessage.java View File

@@ -0,0 +1,56 @@
/* ************************************************************************** */
/* Project : JC (Java ChatServer) */
/* */
/* Author : Bernhard Fröhlich <decke@users.sourceforge.net> */
/* Homepage: http://decke.staticip.de/ */
/* Copyright (c) 2005 Bernhard Fröhlich <decke@users.sourceforge.net> */
/* */
/* This library is free software; you can redistribute it and/or */
/* modify it under the terms of the GNU Lesser General Public */
/* License as published by the Free Software Foundation; either */
/* version 2.1 of the License, or (at your option) any later version. */
/* */
/* This library 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 */
/* Lesser General Public License for more details. */
/* */
/* ************************************************************************** */
package at.bluenet.jc.Commands.Messages;
import at.bluenet.jc.ChatCore.User;
import java.util.Vector;
/**
* <p>Title: </p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2005</p>
*
* <p>Company: </p>
*
* @author Bernhard Fröhlich
* @version 1.0
*/
public class WelcomeMessage extends AbstractMessage
{
public WelcomeMessage(User sender, Vector recipients)
{
this.sender = sender;
addRecipients(recipients);
}
/**
* toRawMessage
*
* @return String
* @todo Implement this at.bluenet.www.JC.Messages.IMessage method
*/
public String toRawMessage()
{
return "<i><b><a href=\"/\"><font color=\"" + sender.getColor() + "\"><u>" + sender.getUsername() + "</u></font></a></b> betritt den Chat.</i><br>\n";
}
}

+ 58
- 0
src/at/bluenet/jc/Commands/Messages/WhisperFromMessage.java View File

@@ -0,0 +1,58 @@
/* ************************************************************************** */
/* Project : JC (Java ChatServer) */
/* */
/* Author : Bernhard Fröhlich <decke@users.sourceforge.net> */
/* Homepage: http://decke.staticip.de/ */
/* Copyright (c) 2005 Bernhard Fröhlich <decke@users.sourceforge.net> */
/* */
/* This library is free software; you can redistribute it and/or */
/* modify it under the terms of the GNU Lesser General Public */
/* License as published by the Free Software Foundation; either */
/* version 2.1 of the License, or (at your option) any later version. */
/* */
/* This library 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 */
/* Lesser General Public License for more details. */
/* */
/* ************************************************************************** */
package at.bluenet.jc.Commands.Messages;
import at.bluenet.jc.ChatCore.User;
/**
* <p>Title: </p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2005</p>
*
* <p>Company: </p>
*
* @author Bernhard Fröhlich
* @version 1.0
*/
public class WhisperFromMessage extends AbstractMessage
{
private User to = null;
public WhisperFromMessage(User from, User to, String message)
{
this.sender = from;
this.to = to;
this.message = message;
addRecipient(this.to);
}
/**
* toRawMessage
*
* @return String
* @todo Implement this at.bluenet.www.JC.Messages.IMessage method
*/
public String toRawMessage()
{
return "<i><b><font color=\"" + sender.getColor() + "\">" + sender.getUsername() + "</font></a> flüstert: " + message + "</b></i><br />\n";
}
}

+ 57
- 0
src/at/bluenet/jc/Commands/Messages/WhisperToMessage.java View File

@@ -0,0 +1,57 @@
/* ************************************************************************** */
/* Project : JC (Java ChatServer) */
/* */
/* Author : Bernhard Fröhlich <decke@users.sourceforge.net> */
/* Homepage: http://decke.staticip.de/ */
/* Copyright (c) 2005 Bernhard Fröhlich <decke@users.sourceforge.net> */
/* */
/* This library is free software; you can redistribute it and/or */
/* modify it under the terms of the GNU Lesser General Public */
/* License as published by the Free Software Foundation; either */
/* version 2.1 of the License, or (at your option) any later version. */
/* */
/* This library 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 */
/* Lesser General Public License for more details. */
/* */
/* ************************************************************************** */
package at.bluenet.jc.Commands.Messages;
import at.bluenet.jc.ChatCore.User;
/**
* <p>Title: </p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2005</p>
*
* <p>Company: </p>
*
* @author Bernhard Fröhlich
* @version 1.0
*/
public class WhisperToMessage extends AbstractMessage
{
private User to;
public WhisperToMessage(User from, User to, String message)
{
this.sender = from;
this.to = to;
this.message = message;
addRecipient(from);
}
/**
* toRawMessage
*
* @return String
* @todo Implement this at.bluenet.www.JC.Messages.IMessage method
*/
public String toRawMessage()
{
return "<i><b><font color=\"#000000\">Du flüsterst zu </font></a><font color=\"" + to.getColor() + "\"><u>" + to.getUsername() + "</u></font>: " + message + "</b></i><br>\n";
}
}

+ 52
- 0
src/at/bluenet/jc/Commands/StatsCommand.java View File

@@ -0,0 +1,52 @@
/* ************************************************************************** */
/* Project : JC (Java ChatServer) */
/* */
/* Author : Bernhard Fröhlich <decke@users.sourceforge.net> */
/* Homepage: http://decke.staticip.de/ */
/* Copyright (c) 2005 Bernhard Fröhlich <decke@users.sourceforge.net> */
/* */
/* This library is free software; you can redistribute it and/or */
/* modify it under the terms of the GNU Lesser General Public */
/* License as published by the Free Software Foundation; either */
/* version 2.1 of the License, or (at your option) any later version. */
/* */
/* This library 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 */
/* Lesser General Public License for more details. */
/* */
/* ************************************************************************** */
package at.bluenet.jc.Commands;
import at.bluenet.jc.Commands.Messages.StatsMessage;
import at.bluenet.jc.ChatCore.User;
import java.util.Vector;
/**
* <p>Title: </p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2005</p>
*
* <p>Company: </p>
*
* @author Bernhard Fröhlich
* @version 1.0
*/
public class StatsCommand extends AbstractCommand
{
public StatsCommand()
{
this.command = "/stats";
}
public Vector parse(User user, String message)
{
Vector v = new Vector();
v.add(new StatsMessage(user));
return v;
}
}

+ 80
- 0
src/at/bluenet/jc/Commands/UserListCommand.java View File

@@ -0,0 +1,80 @@
/* ************************************************************************** */
/* Project : JC (Java ChatServer) */
/* */
/* Author : Bernhard Fröhlich <decke@users.sourceforge.net> */
/* Homepage: http://decke.staticip.de/ */
/* Copyright (c) 2005 Bernhard Fröhlich <decke@users.sourceforge.net> */
/* */
/* This library is free software; you can redistribute it and/or */
/* modify it under the terms of the GNU Lesser General Public */
/* License as published by the Free Software Foundation; either */
/* version 2.1 of the License, or (at your option) any later version. */
/* */
/* This library 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 */
/* Lesser General Public License for more details. */
/* */
/* ************************************************************************** */
package at.bluenet.jc.Commands;
import at.bluenet.jc.Commands.Messages.*;
import at.bluenet.jc.ChatCore.*;
import at.bluenet.util.StringTools;
import java.util.Vector;
/**
* <p>Title: </p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2005</p>
*
* <p>Company: </p>
*
* @author Bernhard Fröhlich
* @version 1.0
*/
public class UserListCommand extends AbstractCommand
{
protected UserPool pool = null;
public UserListCommand(UserPool pool)
{
this.pool = pool;
this.command = "/w";
}
/**
* parse
*
* @param user User
* @param rawMessage String
* @return IMessage
* @todo Implement this at.bluenet.www.JC.Commands.ICommand method
*/
public Vector parse(User user, String rawMessage)
{
Vector v = new Vector();
if(rawMessage.equals("/w"))
v.add(new UserListMessage(user, pool.getUsers()));
else
{
if(StringTools.split(rawMessage, ' ').length >= 2)
{
User who = (User)pool.getUser(StringTools.split(rawMessage, ' ')[1]);
if(who != null)
v.add(new UserInfoMessage(user, who));
else
v.add(new ErrorMessage(user, StringTools.split(rawMessage, ' ')[1] + " ist nicht im Chat."));
}
else
v.add(new ErrorMessage(user, "ist nicht im Chat."));
}
return v;
}
}

+ 60
- 0
src/at/bluenet/jc/Commands/VersionCommand.java View File

@@ -0,0 +1,60 @@
/* ************************************************************************** */
/* Project : JC (Java ChatServer) */
/* */
/* Author : Bernhard Fröhlich <decke@users.sourceforge.net> */
/* Homepage: http://decke.staticip.de/ */
/* Copyright (c) 2005 Bernhard Fröhlich <decke@users.sourceforge.net> */
/* */
/* This library is free software; you can redistribute it and/or */
/* modify it under the terms of the GNU Lesser General Public */
/* License as published by the Free Software Foundation; either */
/* version 2.1 of the License, or (at your option) any later version. */
/* */
/* This library 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 */
/* Lesser General Public License for more details. */
/* */
/* ************************************************************************** */
package at.bluenet.jc.Commands;
import java.util.Vector;
import at.bluenet.jc.Commands.Messages.VersionMessage;
import at.bluenet.jc.ChatCore.User;
/**
* <p>Title: </p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2005</p>
*
* <p>Company: </p>
*
* @author Bernhard Fröhlich
* @version 1.0
*/
public class VersionCommand extends AbstractCommand
{
public VersionCommand()
{
this.command = "/version";
}
/**
* parse
*
* @param user User
* @param rawMessage String
* @return Vector
* @todo Implement this at.bluenet.www.JC.Commands.ICommand method
*/
public Vector parse(User user, String rawMessage)
{
Vector v = new Vector();
v.add(new VersionMessage(user));
return v;
}
}

+ 74
- 0
src/at/bluenet/jc/Commands/WhisperCommand.java View File

@@ -0,0 +1,74 @@
/* ************************************************************************** */
/* Project : JC (Java ChatServer) */
/* */
/* Author : Bernhard Fröhlich <decke@users.sourceforge.net> */
/* Homepage: http://decke.staticip.de/ */
/* Copyright (c) 2005 Bernhard Fröhlich <decke@users.sourceforge.net> */
/* */
/* This library is free software; you can redistribute it and/or */
/* modify it under the terms of the GNU Lesser General Public */
/* License as published by the Free Software Foundation; either */
/* version 2.1 of the License, or (at your option) any later version. */
/* */
/* This library 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 */
/* Lesser General Public License for more details. */
/* */
/* ************************************************************************** */
package at.bluenet.jc.Commands;
import at.bluenet.jc.Commands.Messages.*;
import at.bluenet.jc.ChatCore.User;
import at.bluenet.jc.ChatCore.UserPool;
import java.util.Vector;
/**
* <p>Title: </p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2005</p>
*
* <p>Company: </p>
*
* @author Bernhard Fröhlich
* @version 1.0
*/
public class WhisperCommand extends AbstractCommand
{
protected UserPool pool;
public WhisperCommand(UserPool pool)