Browse Source

Import JC 0.9.23

Bernhard Fröhlich 13 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 @@
1
+
2
+## JC (Java ChatServer)
3
+
4
+### INSTALL
5
+
6
+    >> Windows
7
+        - edit HTTP_BASE in config/jc.properties
8
+        - start jc.bat
9
+        - take a look at http://localhost:6667/
10
+        
11
+    >> Linux/Unix
12
+        - edit JC.sh
13
+            JAVA_HOME      (path to JRE 1.4.2 or JRE 1.5.0)
14
+            JC_HOME        (path to the base directory of JC)
15
+            JC_USER        (you can run JC as root - but at your own risk!)
16
+            JC_STARTUP_LOG (the logfile)
17
+            JC_PID         (the pid file of your choice)
18
+        
19
+        - run it ...
20
+            ./jc.sh start
21
+        
22
+        - take a look at http://localhost:6667/
23
+        
24
+        - stop it
25
+            ./jc.sh stop
26
+
27
+
28
+### CONFIG Files
29
+
30
+    >> jc.properties
31
+        - HTTP_BASE       (default: localhost)
32
+        - PORT            (default: 6667)
33
+        - MAX_SILENT_TIME (default: 3600)
34
+        - CHARSET         (default: ISO-8859-1)
35
+        
36
+        HTTP_BASE is your domain - eg. chat.yourdomain.com
37
+        PORT where the chat listens to
38
+
39
+
40
+### LICENSE
41
+
42
+    This library is free software; you can redistribute it and/or 
43
+    modify it under the terms of the GNU Lesser General Public
44
+    License as published by the Free Software Foundation; either
45
+    version 2.1 of the License, or (at your option) any later version.
46
+    
47
+    This library is distributed in the hope that it will be useful,
48
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
49
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
50
+    Lesser General Public License for more details.
51
+
52
+
53
+Copyright (c) 2005  Bernhard Fröhlich <decke@bluelife.at>

+ 6
- 0
config/jc.properties View File

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

+ 1
- 0
jc.bat View File

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

BIN
jc.jar View File


+ 22
- 0
jc.jardesc View File

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

+ 51
- 0
jc.sh View File

@@ -0,0 +1,51 @@
1
+#!/bin/sh
2
+
3
+JAVA_HOME=/usr/java/jre1.5.0_01
4
+export JAVA_HOME
5
+
6
+JC_HOME=/usr/local/jc
7
+JC_USER=jcdaemon
8
+JC_LOG=/var/log/jc.log
9
+JC_PID=/var/run/jc.pid
10
+
11
+startJC() {
12
+        su -c "$*" $JC_USER  2>/dev/null > $JC_LOG &
13
+        hpid=$!
14
+        echo $hpid
15
+        /bin/ps h $hpid >/dev/null 2>&1
16
+        echo $hpid > $JC_PID
17
+}
18
+
19
+start() {
20
+        echo -n "Starting JC: "
21
+        startJC $JAVA_HOME/bin/java -jar $JC_HOME/jc.jar -b=$JC_HOME
22
+}
23
+stop() {
24
+        echo -n "Shutting down JC: "
25
+        if [ -f $JC_PID ] ; then
26
+                pid=`head -1 $JC_PID`
27
+                kill -SIGTERM $pid && echo "KILLED"
28
+        else
29
+                echo "NOT RUNNING"
30
+        fi
31
+        rm -f $JC_PID
32
+}
33
+
34
+# See how we were called
35
+case "$1" in
36
+  start)
37
+        start
38
+        ;;
39
+  stop)
40
+        stop
41
+        ;;
42
+  restart)
43
+        stop
44
+        sleep 5
45
+        start
46
+        ;;
47
+  *)
48
+        echo "Usage: $0 {start|stop|restart}"
49
+esac
50
+
51
+exit 0

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

@@ -0,0 +1,120 @@
1
+/* ************************************************************************** */
2
+/*   Project : JC (Java ChatServer)                                           */
3
+/*                                                                            */
4
+/*   Author  : Bernhard Fröhlich <decke@users.sourceforge.net>                */
5
+/*   Homepage: http://decke.staticip.de/                                      */
6
+/*   Copyright (c) 2005  Bernhard Fröhlich <decke@users.sourceforge.net>      */
7
+/*                                                                            */
8
+/*   This library is free software; you can redistribute it and/or            */   
9
+/*   modify it under the terms of the GNU Lesser General Public               */
10
+/*   License as published by the Free Software Foundation; either             */
11
+/*   version 2.1 of the License, or (at your option) any later version.       */
12
+/*                                                                            */
13
+/*   This library is distributed in the hope that it will be useful,          */
14
+/*   but WITHOUT ANY WARRANTY; without even the implied warranty of           */
15
+/*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU        */
16
+/*   Lesser General Public License for more details.                          */
17
+/*                                                                            */
18
+/* ************************************************************************** */
19
+
20
+package at.bluenet.jc.ChatCore;
21
+
22
+import at.bluenet.jc.Requests.IRequest;
23
+import at.bluenet.jc.Requests.IResponse;
24
+import at.bluenet.jc.ChatCore.UserPool;
25
+import at.bluenet.jc.ChatCore.auth.IAuthenticator;
26
+
27
+import java.util.Map;
28
+import java.util.Collections;
29
+import java.util.HashMap;
30
+import java.util.Random;
31
+import java.util.Date;
32
+import java.util.Iterator;
33
+import java.lang.IllegalStateException;
34
+
35
+/**
36
+ * <p>Title: </p>
37
+ *
38
+ * <p>Description: </p>
39
+ *
40
+ * <p>Copyright: Copyright (c) 2005</p>
41
+ *
42
+ * <p>Company: </p>
43
+ *
44
+ * @author Bernhard Fröhlich
45
+ * @version 1.0
46
+ */
47
+public class LoginManager
48
+{
49
+    Map openSessions;
50
+    IAuthenticator auth;
51
+    UserPool userpool;
52
+
53
+    public LoginManager(UserPool userpool, IAuthenticator auth)
54
+    {
55
+        this.userpool = userpool;
56
+        this.auth = auth;
57
+        this.openSessions = Collections.synchronizedMap(new HashMap());
58
+    }
59
+
60
+    public String login(String username, String password, String color)
61
+    {
62
+        // check ob bereits im Userpool vorhanden
63
+        if(userpool.isOnline(username) || username.length() < 3)
64
+            return null;
65
+
66
+        // check ob Passwort stimmt
67
+        User user = auth.login(username, password);
68
+        if(user == null)
69
+            return null;
70
+
71
+        user.setSession(generateRandomSession());
72
+        user.setSessionCreateDate(new Date());
73
+        user.setColor(color);
74
+        openSessions.put(user.getSession(), user);
75
+
76
+        return user.getSession();
77
+    }
78
+
79
+    public boolean canLogin(String session)
80
+    {
81
+        return openSessions.containsKey(session);
82
+    }
83
+
84
+    public void login(String session, IRequest request, IResponse response) throws java.lang.IllegalStateException
85
+    {
86
+        cleanup();
87
+
88
+        if(canLogin(session))
89
+        {
90
+            User user = (User)openSessions.get(session);
91
+            openSessions.remove(session);
92
+            user.setRequest(request);
93
+            user.setResponse(response);
94
+            user.setLoginDate(new Date());
95
+            user.setLastMessageDate();
96
+
97
+            userpool.addUser(user);
98
+        }
99
+        else
100
+            throw new IllegalStateException("Invalid Session");
101
+    }
102
+
103
+    private String generateRandomSession()
104
+    {
105
+        Random generator = new Random();
106
+        return Integer.toString(Math.abs(generator.nextInt() + generator.nextInt()));
107
+    }
108
+
109
+    private void cleanup()
110
+    {
111
+        Iterator users = openSessions.values().iterator();
112
+
113
+        while(users.hasNext())
114
+        {
115
+            User user = (User)users.next();
116
+            if(at.bluenet.util.DateDiff.diff(user.getSessionCreateDate()) > 15)
117
+                openSessions.remove(user.getSession());
118
+        }
119
+    }
120
+}

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

@@ -0,0 +1,227 @@
1
+/* ************************************************************************** */
2
+/*   Project : JC (Java ChatServer)                                           */
3
+/*                                                                            */
4
+/*   Author  : Bernhard Fröhlich <decke@users.sourceforge.net>                */
5
+/*   Homepage: http://decke.staticip.de/                                      */
6
+/*   Copyright (c) 2005  Bernhard Fröhlich <decke@users.sourceforge.net>      */
7
+/*                                                                            */
8
+/*   This library is free software; you can redistribute it and/or            */   
9
+/*   modify it under the terms of the GNU Lesser General Public               */
10
+/*   License as published by the Free Software Foundation; either             */
11
+/*   version 2.1 of the License, or (at your option) any later version.       */
12
+/*                                                                            */
13
+/*   This library is distributed in the hope that it will be useful,          */
14
+/*   but WITHOUT ANY WARRANTY; without even the implied warranty of           */
15
+/*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU        */
16
+/*   Lesser General Public License for more details.                          */
17
+/*                                                                            */
18
+/* ************************************************************************** */
19
+
20
+package at.bluenet.jc.ChatCore;
21
+
22
+import at.bluenet.jc.Requests.IRequest;
23
+import at.bluenet.jc.Requests.IResponse;
24
+import at.bluenet.util.Queue;
25
+import java.util.Date;
26
+import java.io.IOException;
27
+import java.io.BufferedOutputStream;
28
+
29
+/**
30
+ * <p>Title: </p>
31
+ *
32
+ * <p>Description: </p>
33
+ *
34
+ * <p>Copyright: Copyright (c) 2005</p>
35
+ *
36
+ * <p>Company: </p>
37
+ *
38
+ * @author Bernhard Fröhlich
39
+ * @version 1.0
40
+ */
41
+public class User extends Thread
42
+{
43
+    private String username = null;
44
+    private String password = null;
45
+    private String color = "#000000";
46
+    private String session = null;
47
+    private Date sessionCreateDate = null;
48
+    private Date loginDate = null;
49
+    private Date lastMessageDate = null;
50
+    private IRequest request;
51
+    private IResponse response;
52
+    private Queue messages = new Queue();
53
+
54
+    public User(String username)
55
+    {
56
+        this.username = username;
57
+    }
58
+
59
+    public User(String username, IRequest request, IResponse response)
60
+    {
61
+        this.username = username;
62
+        this.request = request;
63
+        this.response = response;
64
+    }
65
+
66
+    public User(String username, String password, IRequest request, IResponse response)
67
+    {
68
+        this.username = username;
69
+        this.password = password;
70
+        this.request = request;
71
+        this.response = response;
72
+    }
73
+
74
+    public User(String username, String password, String color, IRequest request, IResponse response)
75
+    {
76
+        this.username = username;
77
+        this.password = password;
78
+        this.color = color;
79
+        this.request = request;
80
+        this.response = response;
81
+    }
82
+    
83
+    public void run()
84
+    {
85
+        while(!isInterrupted())
86
+        {
87
+            try
88
+            {
89
+                synchronized(messages)
90
+                {
91
+                	try
92
+                    {
93
+                		String message = (String)messages.get();
94
+                		
95
+                		if(message != null)
96
+                		{
97
+                            BufferedOutputStream out = response.getBufferedOutputStream();           
98
+                            out.write(message.getBytes());
99
+                            out.flush();
100
+                		}
101
+                		
102
+                        messages.wait(10000);
103
+                    }
104
+                    catch (IOException e)
105
+                    {
106
+                        close();
107
+                    }
108
+                }
109
+            }
110
+            catch (InterruptedException e)
111
+            {
112
+                interrupt();
113
+                break;
114
+            }
115
+            catch (Exception e)
116
+            {
117
+                System.out.println(this.getClass().getName() + "::run(): " + e.getMessage());
118
+                e.printStackTrace();
119
+            }
120
+        }
121
+    }
122
+
123
+    public void send(String message)
124
+    {
125
+    	synchronized(messages)
126
+    	{  	
127
+    		messages.add(message);
128
+    		messages.notifyAll();
129
+    	}
130
+    }
131
+
132
+    public void setRequest(IRequest request)
133
+    {
134
+        this.request = request;
135
+    }
136
+
137
+    public void setResponse(IResponse response)
138
+    {
139
+        this.response = response;
140
+    }
141
+
142
+    public void setSessionCreateDate(Date create)
143
+    {
144
+        this.sessionCreateDate = create;
145
+    }
146
+
147
+    public void setLoginDate(Date login)
148
+    {
149
+        loginDate = login;
150
+    }
151
+
152
+    public void setLastMessageDate(Date lastMessageDate)
153
+    {
154
+        this.lastMessageDate = lastMessageDate;
155
+    }
156
+
157
+    public void setLastMessageDate()
158
+    {
159
+        this.lastMessageDate = new Date();
160
+    }
161
+
162
+    public void setSession(String session)
163
+    {
164
+        this.session = session;
165
+    }
166
+
167
+    public void setColor(String color)
168
+    {
169
+        this.color = color;
170
+    }
171
+
172
+    public String getUsername()
173
+    {
174
+        return username;
175
+    }
176
+
177
+    public String getColor()
178
+    {
179
+        return color;
180
+    }
181
+
182
+    public String getPassword()
183
+    {
184
+        return password;
185
+    }
186
+
187
+    public String getSession()
188
+    {
189
+        return session;
190
+    }
191
+
192
+    public Date getSessionCreateDate()
193
+    {
194
+        return this.sessionCreateDate;
195
+    }
196
+
197
+    public Date getLoginDate()
198
+    {
199
+        return this.loginDate;
200
+    }
201
+
202
+    public Date getLastMessageDate()
203
+    {
204
+        return this.lastMessageDate;
205
+    }
206
+
207
+    public String getHeader(String header)
208
+    {
209
+        return request.getHeader(header);
210
+    }
211
+
212
+    public String getIP()
213
+    {
214
+        return request.getIP().getHostAddress();
215
+    }
216
+
217
+    public boolean isSocketClosed()
218
+    {
219
+        return response.isSocketClosed();
220
+    }
221
+
222
+    public void close()
223
+    {
224
+        response.close();
225
+        this.interrupt();
226
+    }
227
+}

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

@@ -0,0 +1,220 @@
1
+/* ************************************************************************** */
2
+/*   Project : JC (Java ChatServer)                                           */
3
+/*                                                                            */
4
+/*   Author  : Bernhard Fröhlich <decke@users.sourceforge.net>                */
5
+/*   Homepage: http://decke.staticip.de/                                      */
6
+/*   Copyright (c) 2005  Bernhard Fröhlich <decke@users.sourceforge.net>      */
7
+/*                                                                            */
8
+/*   This library is free software; you can redistribute it and/or            */   
9
+/*   modify it under the terms of the GNU Lesser General Public               */
10
+/*   License as published by the Free Software Foundation; either             */
11
+/*   version 2.1 of the License, or (at your option) any later version.       */
12
+/*                                                                            */
13
+/*   This library is distributed in the hope that it will be useful,          */
14
+/*   but WITHOUT ANY WARRANTY; without even the implied warranty of           */
15
+/*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU        */
16
+/*   Lesser General Public License for more details.                          */
17
+/*                                                                            */
18
+/* ************************************************************************** */
19
+
20
+package at.bluenet.jc.ChatCore;
21
+
22
+import at.bluenet.jc.Commands.Messages.IMessage;
23
+import at.bluenet.jc.Commands.Messages.LogoutMessage;
24
+import at.bluenet.jc.Commands.Messages.MessageParser;
25
+import at.bluenet.jc.Commands.Messages.WelcomeMessage;
26
+import at.bluenet.util.DateDiff;
27
+
28
+import java.util.Vector;
29
+import java.util.Enumeration;
30
+import java.util.Hashtable;
31
+
32
+
33
+/**
34
+ * <p>Title: </p>
35
+ *
36
+ * <p>Description: </p>
37
+ *
38
+ * <p>Copyright: Copyright (c) 2005</p>
39
+ *
40
+ * <p>Company: </p>
41
+ *
42
+ * @author Bernhard Fröhlich
43
+ * @version 1.0
44
+ */
45
+public class UserPool extends Thread
46
+{
47
+    private Hashtable userpool = new Hashtable();
48
+    private Vector vUserPool = new Vector();
49
+    private Vector messages = new Vector();
50
+    private MessageParser parser;
51
+
52
+    public UserPool(MessageParser messageParser)
53
+    {
54
+        parser = messageParser;
55
+    }
56
+
57
+    public boolean isOnline(String username)
58
+    {
59
+        if(username == null)
60
+            return false;
61
+
62
+        synchronized(userpool)
63
+        {
64
+            return userpool.containsKey(username.toLowerCase());
65
+        }
66
+    }
67
+
68
+    public synchronized Enumeration getUsers()
69
+    {
70
+        return userpool.elements();
71
+    }
72
+
73
+    public synchronized Vector getUsersVector()
74
+    {
75
+        return vUserPool;
76
+    }
77
+
78
+    public synchronized User getUser(String username)
79
+    {
80
+        return (User)userpool.get(username.toLowerCase());
81
+    }
82
+
83
+    public void addUser(User user)
84
+    {
85
+        System.out.println("USERPOOL --- Adding User: " + user.getUsername());
86
+        user.setLastMessageDate();
87
+
88
+        synchronized(userpool)
89
+        {
90
+        	user.start();
91
+            userpool.put(user.getUsername().toLowerCase(), user);
92
+            userpool.notifyAll();
93
+        }
94
+        synchronized(vUserPool)
95
+        {
96
+            vUserPool.add(user);
97
+        }
98
+        addMessage(new WelcomeMessage(user, vUserPool));
99
+    }
100
+
101
+    public void logoutUser(User user, String reason)
102
+    {
103
+        System.out.println("USERPOOL --- Logout User: '" + user.getUsername() + "' Reason: " + reason);
104
+        if(reason.length() > 0)
105
+            user.send("--logout (Reason: " + reason + ")");
106
+
107
+        synchronized(userpool)
108
+        {
109
+            userpool.remove(user.getUsername().toLowerCase());
110
+        }
111
+
112
+        synchronized(vUserPool)
113
+        {
114
+            vUserPool.remove(user);
115
+        }
116
+
117
+        user.close();
118
+        addMessage(new LogoutMessage(user, vUserPool));
119
+    }
120
+
121
+    public void addMessage(User user, String rawMessage)
122
+    {
123
+        user.setLastMessageDate();
124
+        Vector msges = parser.parse(user, rawMessage);
125
+
126
+        synchronized(messages)
127
+        {
128
+            messages.addAll(msges);
129
+            messages.notifyAll();
130
+        }
131
+    }
132
+
133
+    public void addMessage(IMessage message)
134
+    {
135
+        synchronized(messages)
136
+        {
137
+            messages.add(message);
138
+            messages.notifyAll();
139
+        }
140
+    }
141
+
142
+    public void run()
143
+    {
144
+        while(!isInterrupted())
145
+        {
146
+            try
147
+            {
148
+                synchronized (messages)
149
+                {
150
+                    while (messages.size() != 0)
151
+                    {
152
+                        IMessage message = (IMessage) messages.remove(messages.size()-1);
153
+                        Enumeration users = message.getRecipients().elements();
154
+
155
+                        while (users.hasMoreElements())
156
+                        {
157
+                            ((User) users.nextElement()).send(message.toRawMessage());
158
+                        }
159
+                    }
160
+                    messages.wait(10000);
161
+                    cleanup();
162
+                }
163
+            }
164
+            catch (InterruptedException e)
165
+            {
166
+                interrupt();
167
+            }
168
+            catch (Exception e)
169
+            {
170
+                System.out.println(this.getClass().getName() + "::run(): " + e.getMessage());
171
+                e.printStackTrace();
172
+            }
173
+        }
174
+        System.out.println("UserPool: OUT OF RUN()");
175
+    }
176
+
177
+    public void close()
178
+    {
179
+        try
180
+        {
181
+            synchronized(userpool)
182
+            {
183
+                for(int i=0; i < userpool.size(); i++)
184
+                {
185
+                    Enumeration users = userpool.elements();
186
+
187
+                    while(users.hasMoreElements())
188
+                    {
189
+                        logoutUser((User)users.nextElement(), "Server Shutdown");
190
+                    }
191
+                }
192
+            }
193
+
194
+            interrupt();
195
+        }
196
+        catch(Exception e)
197
+        {
198
+            System.out.println("UserPool: failed closing(). " + e.getMessage());
199
+        }
200
+    }
201
+
202
+    private void cleanup()
203
+    {
204
+        synchronized(userpool)
205
+        {
206
+            Enumeration users = userpool.elements();
207
+
208
+            while(users.hasMoreElements())
209
+            {
210
+                User user = (User)users.nextElement();
211
+
212
+                if(user.isSocketClosed())
213
+                    logoutUser(user, "Socket broken");
214
+
215
+                if(DateDiff.diff(user.getLastMessageDate()) > Integer.parseInt(at.bluenet.jc.Kernel.CONFIG.get("MAX_SILENT_TIME", "900")))
216
+                    logoutUser(user, "Silet for more than " + at.bluenet.jc.Kernel.CONFIG.get("MAX_SILENT_TIME", "900") + " Seconds.");
217
+            }
218
+        }
219
+    }
220
+}

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

@@ -0,0 +1,41 @@
1
+/* ************************************************************************** */
2
+/*   Project : JC (Java ChatServer)                                           */
3
+/*                                                                            */
4
+/*   Author  : Bernhard Fröhlich <decke@users.sourceforge.net>                */
5
+/*   Homepage: http://decke.staticip.de/                                      */
6
+/*   Copyright (c) 2005  Bernhard Fröhlich <decke@users.sourceforge.net>      */
7
+/*                                                                            */
8
+/*   This library is free software; you can redistribute it and/or            */   
9
+/*   modify it under the terms of the GNU Lesser General Public               */
10
+/*   License as published by the Free Software Foundation; either             */
11
+/*   version 2.1 of the License, or (at your option) any later version.       */
12
+/*                                                                            */
13
+/*   This library is distributed in the hope that it will be useful,          */
14
+/*   but WITHOUT ANY WARRANTY; without even the implied warranty of           */
15
+/*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU        */
16
+/*   Lesser General Public License for more details.                          */
17
+/*                                                                            */
18
+/* ************************************************************************** */
19
+
20
+package at.bluenet.jc.ChatCore.auth;
21
+
22
+import at.bluenet.jc.ChatCore.User;
23
+/**
24
+ * <p>Title: </p>
25
+ *
26
+ * <p>Description: </p>
27
+ *
28
+ * <p>Copyright: Copyright (c) 2005</p>
29
+ *
30
+ * <p>Company: </p>
31
+ *
32
+ * @author Bernhard Fröhlich
33
+ * @version 1.0
34
+ */
35
+public interface IAuthenticator
36
+{
37
+        // check ob bereits im Userpool vorhanden
38
+        // check ob Passwort stimmt
39
+        // dann _eventuellen_ Logout eines gleichnamigen Users
40
+        public abstract User login(String username, String password);
41
+}

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

@@ -0,0 +1,57 @@
1
+/* ************************************************************************** */
2
+/*   Project : JC (Java ChatServer)                                           */
3
+/*                                                                            */
4
+/*   Author  : Bernhard Fröhlich <decke@users.sourceforge.net>                */
5
+/*   Homepage: http://decke.staticip.de/                                      */
6
+/*   Copyright (c) 2005  Bernhard Fröhlich <decke@users.sourceforge.net>      */
7
+/*                                                                            */
8
+/*   This library is free software; you can redistribute it and/or            */   
9
+/*   modify it under the terms of the GNU Lesser General Public               */
10
+/*   License as published by the Free Software Foundation; either             */
11
+/*   version 2.1 of the License, or (at your option) any later version.       */
12
+/*                                                                            */
13
+/*   This library is distributed in the hope that it will be useful,          */
14
+/*   but WITHOUT ANY WARRANTY; without even the implied warranty of           */
15
+/*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU        */
16
+/*   Lesser General Public License for more details.                          */
17
+/*                                                                            */
18
+/* ************************************************************************** */
19
+
20
+package at.bluenet.jc.ChatCore.auth;
21
+
22
+import at.bluenet.jc.ChatCore.User;
23
+
24
+/**
25
+ * <p>Title: </p>
26
+ *
27
+ * <p>Description: </p>
28
+ *
29
+ * <p>Copyright: Copyright (c) 2005</p>
30
+ *
31
+ * <p>Company: </p>
32
+ *
33
+ * @author Bernhard Fröhlich
34
+ * @version 1.0
35
+ */
36
+public class NoAuthenticator implements IAuthenticator
37
+{
38
+    //UserPool userpool;
39
+
40
+    public NoAuthenticator()
41
+    {
42
+        //userpool = pool;
43
+    }
44
+
45
+    /**
46
+     * login
47
+     *
48
+     * @param username String
49
+     * @param password String
50
+     * @return IUser
51
+     * @todo Implement this at.bluenet.www.JC.ChatCore.IAuthenticator method
52
+     */
53
+    public User login(String username, String password)
54
+    {
55
+        return new User(username);
56
+    }
57
+}

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

@@ -0,0 +1,61 @@
1
+/* ************************************************************************** */
2
+/*   Project : JC (Java ChatServer)                                           */
3
+/*                                                                            */
4
+/*   Author  : Bernhard Fröhlich <decke@users.sourceforge.net>                */
5
+/*   Homepage: http://decke.staticip.de/                                      */
6
+/*   Copyright (c) 2005  Bernhard Fröhlich <decke@users.sourceforge.net>      */
7
+/*                                                                            */
8
+/*   This library is free software; you can redistribute it and/or            */   
9
+/*   modify it under the terms of the GNU Lesser General Public               */
10
+/*   License as published by the Free Software Foundation; either             */
11
+/*   version 2.1 of the License, or (at your option) any later version.       */
12
+/*                                                                            */
13
+/*   This library is distributed in the hope that it will be useful,          */
14
+/*   but WITHOUT ANY WARRANTY; without even the implied warranty of           */
15
+/*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU        */
16
+/*   Lesser General Public License for more details.                          */
17
+/*                                                                            */
18
+/* ************************************************************************** */
19
+
20
+package at.bluenet.jc.Commands;
21
+
22
+import at.bluenet.jc.ChatCore.User;
23
+
24
+import java.util.Vector;
25
+
26
+/**
27
+ * <p>Title: </p>
28
+ *
29
+ * <p>Description: </p>
30
+ *
31
+ * <p>Copyright: Copyright (c) 2005</p>
32
+ *
33
+ * <p>Company: </p>
34
+ *
35
+ * @author Bernhard Fröhlich
36
+ * @version 1.0
37
+ */
38
+public abstract class AbstractCommand implements ICommand
39
+{
40
+    protected String command;
41
+
42
+    /**
43
+     * getCommand
44
+     *
45
+     * @return String
46
+     * @todo Implement this at.bluenet.www.JC.Commands.ICommand method
47
+     */
48
+    public String getCommand() {
49
+        return command;
50
+    }
51
+
52
+    /**
53
+     * parse
54
+     *
55
+     * @param user User
56
+     * @param rawMessage String
57
+     * @return IMessage
58
+     * @todo Implement this at.bluenet.www.JC.Commands.ICommand method
59
+     */
60
+    public abstract Vector parse(User user, String rawMessage);
61
+}

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

@@ -0,0 +1,42 @@
1
+/* ************************************************************************** */
2
+/*   Project : JC (Java ChatServer)                                           */
3
+/*                                                                            */
4
+/*   Author  : Bernhard Fröhlich <decke@users.sourceforge.net>                */
5
+/*   Homepage: http://decke.staticip.de/                                      */
6
+/*   Copyright (c) 2005  Bernhard Fröhlich <decke@users.sourceforge.net>      */
7
+/*                                                                            */
8
+/*   This library is free software; you can redistribute it and/or            */   
9
+/*   modify it under the terms of the GNU Lesser General Public               */
10
+/*   License as published by the Free Software Foundation; either             */
11
+/*   version 2.1 of the License, or (at your option) any later version.       */
12
+/*                                                                            */
13
+/*   This library is distributed in the hope that it will be useful,          */
14
+/*   but WITHOUT ANY WARRANTY; without even the implied warranty of           */
15
+/*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU        */
16
+/*   Lesser General Public License for more details.                          */
17
+/*                                                                            */
18
+/* ************************************************************************** */
19
+
20
+package at.bluenet.jc.Commands;
21
+
22
+import at.bluenet.jc.ChatCore.User;
23
+
24
+import java.util.Vector;
25
+
26
+/**
27
+ * <p>Title: </p>
28
+ *
29
+ * <p>Description: </p>
30
+ *
31
+ * <p>Copyright: Copyright (c) 2005</p>
32
+ *
33
+ * <p>Company: </p>
34
+ *
35
+ * @author Bernhard Fröhlich
36
+ * @version 1.0
37
+ */
38
+public interface ICommand
39
+{
40
+    public abstract String getCommand();
41
+    public abstract Vector parse(User user, String rawMessage);
42
+}

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

@@ -0,0 +1,62 @@
1
+/* ************************************************************************** */
2
+/*   Project : JC (Java ChatServer)                                           */
3
+/*                                                                            */
4
+/*   Author  : Bernhard Fröhlich <decke@users.sourceforge.net>                */
5
+/*   Homepage: http://decke.staticip.de/                                      */
6
+/*   Copyright (c) 2005  Bernhard Fröhlich <decke@users.sourceforge.net>      */
7
+/*                                                                            */
8
+/*   This library is free software; you can redistribute it and/or            */   
9
+/*   modify it under the terms of the GNU Lesser General Public               */
10
+/*   License as published by the Free Software Foundation; either             */
11
+/*   version 2.1 of the License, or (at your option) any later version.       */
12
+/*                                                                            */
13
+/*   This library is distributed in the hope that it will be useful,          */
14
+/*   but WITHOUT ANY WARRANTY; without even the implied warranty of           */
15
+/*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU        */
16
+/*   Lesser General Public License for more details.                          */
17
+/*                                                                            */
18
+/* ************************************************************************** */
19
+
20
+package at.bluenet.jc.Commands;
21
+
22
+import java.util.Vector;
23
+
24
+import at.bluenet.jc.ChatCore.User;
25
+import at.bluenet.jc.ChatCore.UserPool;
26
+
27
+/**
28
+ * <p>Title: </p>
29
+ *
30
+ * <p>Description: </p>
31
+ *
32
+ * <p>Copyright: Copyright (c) 2005</p>
33
+ *
34
+ * <p>Company: </p>
35
+ *
36
+ * @author Bernhard Fröhlich
37
+ * @version 1.0
38
+ */
39
+public class LogoutCommand extends AbstractCommand
40
+{
41
+    private UserPool pool;
42
+
43
+    public LogoutCommand(UserPool pool)
44
+    {
45
+        this.pool = pool;
46
+        this.command = "/q";
47
+    }
48
+
49
+    /**
50
+     * parse
51
+     *
52
+     * @param user User
53
+     * @param rawMessage String
54
+     * @return Vector
55
+     * @todo Implement this at.bluenet.www.JC.Commands.ICommand method
56
+     */
57
+    public Vector parse(User user, String rawMessage)
58
+    {
59
+        pool.logoutUser(user, "Normal Logout");
60
+        return null;
61
+    }
62
+}

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

@@ -0,0 +1,100 @@
1
+/* ************************************************************************** */
2
+/*   Project : JC (Java ChatServer)                                           */
3
+/*                                                                            */
4
+/*   Author  : Bernhard Fröhlich <decke@users.sourceforge.net>                */
5
+/*   Homepage: http://decke.staticip.de/                                      */
6
+/*   Copyright (c) 2005  Bernhard Fröhlich <decke@users.sourceforge.net>      */
7
+/*                                                                            */
8
+/*   This library is free software; you can redistribute it and/or            */   
9
+/*   modify it under the terms of the GNU Lesser General Public               */
10
+/*   License as published by the Free Software Foundation; either             */
11
+/*   version 2.1 of the License, or (at your option) any later version.       */
12
+/*                                                                            */
13
+/*   This library is distributed in the hope that it will be useful,          */
14
+/*   but WITHOUT ANY WARRANTY; without even the implied warranty of           */
15
+/*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU        */
16
+/*   Lesser General Public License for more details.                          */
17
+/*                                                                            */
18
+/* ************************************************************************** */
19
+
20
+package at.bluenet.jc.Commands.Messages;
21
+
22
+import java.util.Vector;
23
+
24
+import at.bluenet.jc.ChatCore.*;
25
+
26
+/**
27
+ * <p>Title: </p>
28
+ *
29
+ * <p>Description: </p>
30
+ *
31
+ * <p>Copyright: Copyright (c) 2005</p>
32
+ *
33
+ * <p>Company: </p>
34
+ *
35
+ * @author Bernhard Fröhlich
36
+ * @version 1.0
37
+ */
38
+public abstract class AbstractMessage implements IMessage
39
+{
40
+    protected User sender;
41
+    private Vector recipients = new Vector();
42
+    protected String message;
43
+
44
+    /**
45
+     * addRecipients
46
+     *
47
+     * @param users Vector
48
+     * @todo Implement this at.bluenet.www.JC.Messages.IMessage method
49
+     */
50
+    public void addRecipients(Vector vUsers)
51
+    {
52
+        //Enumeration users = vUsers.elements();
53
+        //while(users.hasMoreElements())
54
+        //    recipients.add(users.nextElement());
55
+        recipients.addAll(vUsers);
56
+    }
57
+
58
+    public void addRecipient(User user)
59
+    {
60
+        recipients.add(user);
61
+    }
62
+
63
+    /**
64
+     * getMessage
65
+     *
66
+     * @return String
67
+     * @todo Implement this at.bluenet.www.JC.Messages.IMessage method
68
+     */
69
+    public String getMessage() {
70
+        return message;
71
+    }
72
+
73
+    /**
74
+     * getRecipients
75
+     *
76
+     * @return Vector
77
+     * @todo Implement this at.bluenet.www.JC.Messages.IMessage method
78
+     */
79
+    public Vector getRecipients() {
80
+        return recipients;
81
+    }
82
+
83
+    /**
84
+     * getSender
85
+     *
86
+     * @return User
87
+     * @todo Implement this at.bluenet.www.JC.Messages.IMessage method
88
+     */
89
+    public User getSender() {
90
+        return sender;
91
+    }
92
+
93
+    /**
94
+     * toRawMessage
95
+     *
96
+     * @return String
97
+     * @todo Implement this at.bluenet.www.JC.Messages.IMessage method
98
+     */
99
+    abstract public String toRawMessage();
100
+}

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

@@ -0,0 +1,49 @@
1
+/* ************************************************************************** */
2
+/*   Project : JC (Java ChatServer)                                           */
3
+/*                                                                            */
4
+/*   Author  : Bernhard Fröhlich <decke@users.sourceforge.net>                */
5
+/*   Homepage: http://decke.staticip.de/                                      */
6
+/*   Copyright (c) 2005  Bernhard Fröhlich <decke@users.sourceforge.net>      */
7
+/*                                                                            */
8
+/*   This library is free software; you can redistribute it and/or            */   
9
+/*   modify it under the terms of the GNU Lesser General Public               */
10
+/*   License as published by the Free Software Foundation; either             */
11
+/*   version 2.1 of the License, or (at your option) any later version.       */
12
+/*                                                                            */
13
+/*   This library is distributed in the hope that it will be useful,          */
14
+/*   but WITHOUT ANY WARRANTY; without even the implied warranty of           */
15
+/*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU        */
16
+/*   Lesser General Public License for more details.                          */
17
+/*                                                                            */
18
+/* ************************************************************************** */
19
+
20
+package at.bluenet.jc.Commands.Messages;
21
+
22
+import at.bluenet.jc.ChatCore.User;
23
+
24
+/**
25
+ * <p>Title: </p>
26
+ *
27
+ * <p>Description: </p>
28
+ *
29
+ * <p>Copyright: Copyright (c) 2005</p>
30
+ *
31
+ * <p>Company: </p>
32
+ *
33
+ * @author Bernhard Fröhlich
34
+ * @version 1.0
35
+ */
36
+public class ErrorMessage extends AbstractMessage
37
+{
38
+    public ErrorMessage(User sender, String message)
39
+    {
40
+        this.sender = sender;
41
+        this.message = message;
42
+        addRecipient(sender);
43
+    }
44
+
45
+    public String toRawMessage()
46
+    {
47
+        return "<i><b>" + message + "</b></i><br />";
48
+    }
49
+}

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

@@ -0,0 +1,46 @@
1
+/* ************************************************************************** */
2
+/*   Project : JC (Java ChatServer)                                           */
3
+/*                                                                            */
4
+/*   Author  : Bernhard Fröhlich <decke@users.sourceforge.net>                */
5
+/*   Homepage: http://decke.staticip.de/                                      */
6
+/*   Copyright (c) 2005  Bernhard Fröhlich <decke@users.sourceforge.net>      */
7
+/*                                                                            */
8
+/*   This library is free software; you can redistribute it and/or            */   
9
+/*   modify it under the terms of the GNU Lesser General Public               */
10
+/*   License as published by the Free Software Foundation; either             */
11
+/*   version 2.1 of the License, or (at your option) any later version.       */
12
+/*                                                                            */
13
+/*   This library is distributed in the hope that it will be useful,          */
14
+/*   but WITHOUT ANY WARRANTY; without even the implied warranty of           */
15
+/*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU        */
16
+/*   Lesser General Public License for more details.                          */
17
+/*                                                                            */
18
+/* ************************************************************************** */
19
+
20
+package at.bluenet.jc.Commands.Messages;
21
+
22
+import at.bluenet.jc.ChatCore.User;
23
+
24
+import java.util.Vector;
25
+
26
+/**
27
+ * <p>Title: </p>
28
+ *
29
+ * <p>Description: </p>
30
+ *
31
+ * <p>Copyright: Copyright (c) 2005</p>
32
+ *
33
+ * <p>Company: </p>
34
+ *
35
+ * @author Bernhard Fröhlich
36
+ * @version 1.0
37
+ */
38
+public interface IMessage
39
+{
40
+    public abstract String toRawMessage();
41
+    public abstract String getMessage();
42
+    public abstract Vector getRecipients();
43
+    public abstract User getSender();
44
+    public abstract void addRecipients(Vector users);
45
+    public abstract void addRecipient(User user);
46
+}

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

@@ -0,0 +1,55 @@
1
+/* ************************************************************************** */
2
+/*   Project : JC (Java ChatServer)                                           */
3
+/*                                                                            */
4
+/*   Author  : Bernhard Fröhlich <decke@users.sourceforge.net>                */
5
+/*   Homepage: http://decke.staticip.de/                                      */
6
+/*   Copyright (c) 2005  Bernhard Fröhlich <decke@users.sourceforge.net>      */
7
+/*                                                                            */
8
+/*   This library is free software; you can redistribute it and/or            */   
9
+/*   modify it under the terms of the GNU Lesser General Public               */
10
+/*   License as published by the Free Software Foundation; either             */
11
+/*   version 2.1 of the License, or (at your option) any later version.       */
12
+/*                                                                            */
13
+/*   This library is distributed in the hope that it will be useful,          */
14
+/*   but WITHOUT ANY WARRANTY; without even the implied warranty of           */
15
+/*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU        */
16
+/*   Lesser General Public License for more details.                          */
17
+/*                                                                            */
18
+/* ************************************************************************** */
19
+
20
+package at.bluenet.jc.Commands.Messages;
21
+
22
+import java.util.Vector;
23
+
24
+import at.bluenet.jc.ChatCore.User;
25
+
26
+/**
27
+ * <p>Title: </p>
28
+ *
29
+ * <p>Description: </p>
30
+ *
31
+ * <p>Copyright: Copyright (c) 2005</p>
32
+ *
33
+ * <p>Company: </p>
34
+ *
35
+ * @author Bernhard Fröhlich
36
+ * @version 1.0
37
+ */
38
+public class LogoutMessage extends AbstractMessage
39
+{
40
+    public LogoutMessage(User sender, Vector recipients)
41
+    {
42
+        this.sender = sender;
43
+        addRecipients(recipients);
44
+    }
45
+    /**
46
+     * toRawMessage
47
+     *
48
+     * @return String
49
+     * @todo Implement this at.bluenet.www.JC.Messages.IMessage method
50
+     */
51
+    public String toRawMessage()
52
+    {
53
+        return "<i><b><a href=\"/\"><font color=\"" + sender.getColor() + "\"><u>" + sender.getUsername() + "</u></font></a></b> verlässt den Chat.</i><br>\n";
54
+    }
55
+}

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

@@ -0,0 +1,86 @@
1
+/* ************************************************************************** */
2
+/*   Project : JC (Java ChatServer)                                           */
3
+/*                                                                            */
4
+/*   Author  : Bernhard Fröhlich <decke@users.sourceforge.net>                */
5
+/*   Homepage: http://decke.staticip.de/                                      */
6
+/*   Copyright (c) 2005  Bernhard Fröhlich <decke@users.sourceforge.net>      */
7
+/*                                                                            */
8
+/*   This library is free software; you can redistribute it and/or            */   
9
+/*   modify it under the terms of the GNU Lesser General Public               */
10
+/*   License as published by the Free Software Foundation; either             */
11
+/*   version 2.1 of the License, or (at your option) any later version.       */
12
+/*                                                                            */
13
+/*   This library is distributed in the hope that it will be useful,          */
14
+/*   but WITHOUT ANY WARRANTY; without even the implied warranty of           */
15
+/*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU        */
16
+/*   Lesser General Public License for more details.                          */
17
+/*                                                                            */
18
+/* ************************************************************************** */
19
+
20
+package at.bluenet.jc.Commands.Messages;
21
+
22
+import at.bluenet.jc.ChatCore.User;
23
+import at.bluenet.jc.ChatCore.UserPool;
24
+import at.bluenet.jc.Commands.ICommand;
25
+import at.bluenet.util.StringTools;
26
+
27
+import java.util.Vector;
28
+import java.util.HashMap;
29
+import java.util.Map;
30
+
31
+/**
32
+ * <p>Title: </p>
33
+ *
34
+ * <p>Description: </p>
35
+ *
36
+ * <p>Copyright: Copyright (c) 2005</p>
37
+ *
38
+ * <p>Company: </p>
39
+ *
40
+ * @author Bernhard Fröhlich
41
+ * @version 1.0
42
+ */
43
+public class MessageParser
44
+{
45
+    Map commands = java.util.Collections.synchronizedMap(new HashMap());
46
+    UserPool pool;
47
+
48
+    public MessageParser()
49
+    {
50
+    }
51
+
52
+    public void addCommand(ICommand cmd)
53
+    {
54
+        commands.put(cmd.getCommand().toLowerCase(), cmd);
55
+    }
56
+
57
+    public void setUserPool(UserPool userpool)
58
+    {
59
+        this.pool = userpool;
60
+    }
61
+
62
+    public Vector parse(User sender, String rawMessage)
63
+    {
64
+        Vector v = new Vector();
65
+        String[] parts = StringTools.split(rawMessage, ' ');
66
+
67
+        if(parts.length > 0 && commands.containsKey(parts[0]))
68
+        {
69
+            Vector msges = ((ICommand)commands.get(parts[0])).parse(sender, rawMessage);
70
+            if(msges != null)
71
+                v.addAll(msges);
72
+        }
73
+        else
74
+        {
75
+            if(rawMessage.startsWith("/"))
76
+            {
77
+                Vector msges = ((ICommand)commands.get("/")).parse(sender, rawMessage);
78
+                v.addAll(msges);
79
+            }
80
+            else
81
+                v.add(new NormalMessage(sender, rawMessage, pool.getUsersVector()));
82
+        }
83
+
84
+        return v;
85
+    }
86
+}

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

@@ -0,0 +1,56 @@
1
+/* ************************************************************************** */
2
+/*   Project : JC (Java ChatServer)                                           */
3
+/*                                                                            */
4
+/*   Author  : Bernhard Fröhlich <decke@users.sourceforge.net>                */
5
+/*   Homepage: http://decke.staticip.de/                                      */
6
+/*   Copyright (c) 2005  Bernhard Fröhlich <decke@users.sourceforge.net>      */
7
+/*                                                                            */
8
+/*   This library is free software; you can redistribute it and/or            */   
9
+/*   modify it under the terms of the GNU Lesser General Public               */
10
+/*   License as published by the Free Software Foundation; either             */
11
+/*   version 2.1 of the License, or (at your option) any later version.       */
12
+/*                                                                            */
13
+/*   This library is distributed in the hope that it will be useful,          */
14
+/*   but WITHOUT ANY WARRANTY; without even the implied warranty of           */
15
+/*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU        */
16
+/*   Lesser General Public License for more details.                          */
17
+/*                                                                            */
18
+/* ************************************************************************** */
19
+
20
+package at.bluenet.jc.Commands.Messages;
21
+
22
+import at.bluenet.jc.ChatCore.User;
23
+
24
+import java.util.Vector;
25
+
26
+/**
27
+ * <p>Title: </p>
28
+ *
29
+ * <p>Description: </p>
30
+ *
31
+ * <p>Copyright: Copyright (c) 2005</p>
32
+ *
33
+ * <p>Company: </p>
34
+ *
35
+ * @author Bernhard Fröhlich
36
+ * @version 1.0
37
+ */
38
+public class NormalMessage extends AbstractMessage
39
+{
40
+    public NormalMessage(User sender, String message, Vector recipients)
41
+    {
42
+        this.sender = sender;
43
+        this.message = message;
44
+        addRecipients(recipients);
45
+    }
46
+
47
+    /**
48
+     * toRawMessage
49
+     *
50
+     * @return String
51
+     */
52
+    public String toRawMessage()
53
+    {
54
+        return "<font color=\"" + sender.getColor() + "\">(<a href=\"/\"><font color=\"" + sender.getColor() + "\"><u>" + sender.getUsername() + "</u></font></a>) " + message + "</font><br />\n";
55
+    }
56
+}

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

@@ -0,0 +1,72 @@
1
+/* ************************************************************************** */
2
+/*   Project : JC (Java ChatServer)                                           */
3
+/*                                                                            */
4
+/*   Author  : Bernhard Fröhlich <decke@users.sourceforge.net>                */
5
+/*   Homepage: http://decke.staticip.de/                                      */
6
+/*   Copyright (c) 2005  Bernhard Fröhlich <decke@users.sourceforge.net>      */
7
+/*                                                                            */
8
+/*   This library is free software; you can redistribute it and/or            */   
9
+/*   modify it under the terms of the GNU Lesser General Public               */
10
+/*   License as published by the Free Software Foundation; either             */
11
+/*   version 2.1 of the License, or (at your option) any later version.       */
12
+/*                                                                            */
13
+/*   This library is distributed in the hope that it will be useful,          */
14
+/*   but WITHOUT ANY WARRANTY; without even the implied warranty of           */
15
+/*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU        */
16
+/*   Lesser General Public License for more details.                          */
17
+/*                                                                            */
18
+/* ************************************************************************** */
19
+
20
+package at.bluenet.jc.Commands.Messages;
21
+
22
+import at.bluenet.jc.ChatCore.User;
23
+
24
+import java.lang.StringBuffer;
25
+
26
+/**
27
+ * <p>Title: </p>
28
+ *
29
+ * <p>Description: </p>
30
+ *
31
+ * <p>Copyright: Copyright (c) 2005</p>
32
+ *
33
+ * <p>Company: </p>
34
+ *
35
+ * @author Bernhard Fröhlich
36
+ * @version 1.0
37
+ */
38
+public class StatsMessage extends AbstractMessage
39
+{
40
+    public StatsMessage(User user)
41
+    {
42
+        this.sender = user;
43
+        addRecipient(user);
44
+    }
45
+
46
+    /**
47
+     * toRawMessage
48
+     *
49
+     * @return String
50
+     * @todo Implement this at.bluenet.www.JC.Commands.Messages.IMessage
51
+     *   method
52
+     */
53
+    public String toRawMessage()
54
+    {
55
+        StringBuffer sb = new StringBuffer();
56
+        Runtime r = Runtime.getRuntime ();
57
+
58
+        sb.append((new VersionMessage(sender)).toRawMessage());
59
+
60
+        sb.append("<b>OS:</b> " + System.getProperty("os.name") + " (" + System.getProperty("os.arch") + ")<br />");
61
+        sb.append("<b>VM Version:</b> " + System.getProperty("java.version") + "/" + System.getProperty("java.vendor") + "<br />");
62
+        sb.append("<b>Default Charset:</b> " + at.bluenet.jc.Kernel.DEFAULT_CHARSET + "<br /><br />");
63
+
64
+        sb.append("<b>Memory:</b><br />");
65
+        sb.append("VM MaxSize: " + ((r.maxMemory()/1024)/1024) + "MB<br />");
66
+        sb.append("VM CurSize: " + ((r.totalMemory()/1024)/1024) + "MB<br />");
67
+        sb.append("Free: " + ((r.freeMemory()/1024)/1024) + "MB<br />");
68
+        sb.append("Used: " + (((r.totalMemory()-r.freeMemory())/1024)/1024) + "MB<br /><br />");
69
+
70
+        return sb.toString();
71
+    }
72
+}

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

@@ -0,0 +1,71 @@
1
+/* ************************************************************************** */
2
+/*   Project : JC (Java ChatServer)                                           */
3
+/*                                                                            */
4
+/*   Author  : Bernhard Fröhlich <decke@users.sourceforge.net>                */
5
+/*   Homepage: http://decke.staticip.de/                                      */
6
+/*   Copyright (c) 2005  Bernhard Fröhlich <decke@users.sourceforge.net>      */
7
+/*                                                                            */
8
+/*   This library is free software; you can redistribute it and/or            */   
9
+/*   modify it under the terms of the GNU Lesser General Public               */
10
+/*   License as published by the Free Software Foundation; either             */
11
+/*   version 2.1 of the License, or (at your option) any later version.       */
12
+/*                                                                            */
13
+/*   This library is distributed in the hope that it will be useful,          */
14
+/*   but WITHOUT ANY WARRANTY; without even the implied warranty of           */
15
+/*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU        */
16
+/*   Lesser General Public License for more details.                          */
17
+/*                                                                            */
18
+/* ************************************************************************** */
19
+
20
+package at.bluenet.jc.Commands.Messages;
21
+
22
+import at.bluenet.jc.ChatCore.User;
23
+
24
+/**
25
+ * <p>Title: </p>
26
+ *
27
+ * <p>Description: </p>
28
+ *
29
+ * <p>Copyright: Copyright (c) 2005</p>
30
+ *
31
+ * <p>Company: </p>
32
+ *
33
+ * @author Bernhard Fröhlich
34
+ * @version 1.0
35
+ */
36
+public class UserInfoMessage extends AbstractMessage
37
+{
38
+    private User who;
39
+
40
+    public UserInfoMessage(User from, User who)
41
+    {
42
+        this.sender = from;
43
+        this.who = who;
44
+        addRecipient(from);
45
+    }
46
+
47
+    /**
48
+     * toRawMessage
49
+     *
50
+     * @return String
51
+     * @todo Implement this at.bluenet.www.JC.Messages.IMessage method
52
+     */
53
+    public String toRawMessage()
54
+    {
55
+        String message = "";
56
+        message += "* <font color=\"" + who.getColor() + "\"><b>" + who.getUsername() + "</b></font> , seit dem " + java.text.DateFormat.getDateTimeInstance().format(who.getLoginDate()) + " im Chat.<br />\n";
57
+        message += "- still seit " + at.bluenet.util.DateDiff.diff(who.getLastMessageDate()) + " Sekunden<br />\n";
58
+        message += "- OS/Browser: " + who.getHeader("User-Agent") + "<br />\n";
59
+        message += "- Farbcode: " + who.getColor() + "<br />\n";
60
+
61
+        if(who.getHeader("X-Forwarded-For") != null)
62
+        {
63
+            message += "- Proxy IP: " + who.getIP() + "<br />\n";
64
+            message += "- Echt IP: " + who.getHeader("X-Forwarded-For") + "<br />\n";
65
+        }
66
+        else
67
+            message += "- Echt IP: " + who.getIP() + "<br />\n";
68
+
69
+        return message;
70
+    }
71
+}

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

@@ -0,0 +1,72 @@
1
+/* ************************************************************************** */
2
+/*   Project : JC (Java ChatServer)                                           */
3
+/*                                                                            */
4
+/*   Author  : Bernhard Fröhlich <decke@users.sourceforge.net>                */
5
+/*   Homepage: http://decke.staticip.de/                                      */
6
+/*   Copyright (c) 2005  Bernhard Fröhlich <decke@users.sourceforge.net>      */
7
+/*                                                                            */
8
+/*   This library is free software; you can redistribute it and/or            */   
9
+/*   modify it under the terms of the GNU Lesser General Public               */
10
+/*   License as published by the Free Software Foundation; either             */
11
+/*   version 2.1 of the License, or (at your option) any later version.       */
12
+/*                                                                            */
13
+/*   This library is distributed in the hope that it will be useful,          */
14
+/*   but WITHOUT ANY WARRANTY; without even the implied warranty of           */
15
+/*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU        */
16
+/*   Lesser General Public License for more details.                          */
17
+/*                                                                            */
18
+/* ************************************************************************** */
19
+
20
+package at.bluenet.jc.Commands.Messages;
21
+
22
+import at.bluenet.jc.ChatCore.User;
23
+
24
+import java.util.Enumeration;
25
+
26
+/**
27
+ * <p>Title: </p>
28
+ *
29
+ * <p>Description: </p>
30
+ *
31
+ * <p>Copyright: Copyright (c) 2005</p>
32
+ *
33
+ * <p>Company: </p>
34
+ *
35
+ * @author Bernhard Fröhlich
36
+ * @version 1.0
37
+ */
38
+public class UserListMessage extends AbstractMessage
39
+{
40
+    private Enumeration users;
41
+
42
+    public UserListMessage(User sender, Enumeration users)
43
+    {
44
+        this.sender = sender;
45
+        this.users = users;
46
+        addRecipient(sender);
47
+    }
48
+
49
+    /**
50
+     * toRawMessage
51
+     *
52
+     * @return String
53
+     * @todo Implement this at.bluenet.www.JC.Messages.IMessage method
54
+     */
55
+    public String toRawMessage()
56
+    {
57
+        int i=0;
58
+        String message = "<b>Folgende User befinden sich im Chat:</b><br />\n";
59
+
60
+        while (this.users.hasMoreElements())
61
+        {
62
+            User usr = (User) this.users.nextElement();
63
+            message += "<b>~ <font color=\"" + usr.getColor() + "\">" + usr.getUsername() + "</font></b>";
64
+            message += " still seit " + at.bluenet.util.DateDiff.diff(usr.getLastMessageDate()) + " Sekunden</b><br />\n";
65
+            i++;
66
+        }
67
+
68
+        message += "<b>~ " + i + " Chatter</b><br />\n";
69
+
70
+        return message;
71
+    }
72
+}

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

@@ -0,0 +1,57 @@
1
+/* ************************************************************************** */
2
+/*   Project : JC (Java ChatServer)                                           */
3
+/*                                                                            */
4
+/*   Author  : Bernhard Fröhlich <decke@users.sourceforge.net>                */
5
+/*   Homepage: http://decke.staticip.de/                                      */
6
+/*   Copyright (c) 2005  Bernhard Fröhlich <decke@users.sourceforge.net>      */
7
+/*                                                                            */
8
+/*   This library is free software; you can redistribute it and/or            */   
9
+/*   modify it under the terms of the GNU Lesser General Public               */
10
+/*   License as published by the Free Software Foundation; either             */
11
+/*   version 2.1 of the License, or (at your option) any later version.       */
12
+/*                                                                            */
13
+/*   This library is distributed in the hope that it will be useful,          */
14
+/*   but WITHOUT ANY WARRANTY; without even the implied warranty of           */
15
+/*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU        */
16
+/*   Lesser General Public License for more details.                          */
17
+/*                                                                            */
18
+/* ************************************************************************** */
19
+
20
+package at.bluenet.jc.Commands.Messages;
21
+
22
+import at.bluenet.jc.ChatCore.User;
23
+/**
24
+ * <p>Title: </p>
25
+ *
26
+ * <p>Description: </p>
27
+ *
28
+ * <p>Copyright: Copyright (c) 2005</p>
29
+ *
30
+ * <p>Company: </p>
31
+ *
32
+ * @author Bernhard Fröhlich
33
+ * @version 1.0
34
+ */
35
+public class VersionMessage extends AbstractMessage
36
+{
37
+    public VersionMessage(User sender)
38
+    {
39
+        addRecipient(sender);
40
+    }
41
+
42
+    /**
43
+     * toRawMessage
44
+     *
45
+     * @return String
46
+     * @todo Implement this at.bluenet.www.JC.Commands.Messages.IMessage
47
+     *   method
48
+     */
49
+    public String toRawMessage()
50
+    {
51
+        String v = "<br /><font size=\"+1\"><b><i>JC " + at.bluenet.jc.Kernel.VERSION + "</i></b></font><br /><br />";
52
+        v += "<b>Version:</b> " + at.bluenet.jc.Kernel.VERSION_STRING + "<br />";
53
+        v += "<b>Author:</b> Bernhard Fröhlich (decke@users.sourceforge.net)<br />";
54
+        v += "<b>Homepage:</b> <a href=\"http://decke.staticip.de\" target=\"_blank\">http://decke.staticip.de/</a><br /><br />";
55
+        return v;
56
+    }
57
+}

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

@@ -0,0 +1,56 @@
1
+/* ************************************************************************** */
2
+/*   Project : JC (Java ChatServer)                                           */
3
+/*                                                                            */
4
+/*   Author  : Bernhard Fröhlich <decke@users.sourceforge.net>                */
5
+/*   Homepage: http://decke.staticip.de/                                      */
6
+/*   Copyright (c) 2005  Bernhard Fröhlich <decke@users.sourceforge.net>      */
7
+/*                                                                            */
8
+/*   This library is free software; you can redistribute it and/or            */   
9
+/*   modify it under the terms of the GNU Lesser General Public               */
10
+/*   License as published by the Free Software Foundation; either             */
11
+/*   version 2.1 of the License, or (at your option) any later version.       */
12
+/*                                                                            */
13
+/*   This library is distributed in the hope that it will be useful,          */
14
+/*   but WITHOUT ANY WARRANTY; without even the implied warranty of           */
15
+/*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU        */
16
+/*   Lesser General Public License for more details.                          */
17
+/*                                                                            */
18
+/* ************************************************************************** */
19
+
20
+package at.bluenet.jc.Commands.Messages;
21
+
22
+import at.bluenet.jc.ChatCore.User;
23
+
24
+import java.util.Vector;
25
+
26
+/**
27
+ * <p>Title: </p>
28
+ *
29
+ * <p>Description: </p>
30
+ *
31
+ * <p>Copyright: Copyright (c) 2005</p>
32
+ *
33
+ * <p>Company: </p>
34
+ *
35
+ * @author Bernhard Fröhlich
36
+ * @version 1.0
37
+ */
38
+public class WelcomeMessage extends AbstractMessage
39
+{
40
+    public WelcomeMessage(User sender, Vector recipients)
41
+    {
42
+        this.sender = sender;
43
+        addRecipients(recipients);
44
+    }
45
+
46
+    /**
47
+     * toRawMessage
48
+     *
49
+     * @return String
50
+     * @todo Implement this at.bluenet.www.JC.Messages.IMessage method
51
+     */
52
+    public String toRawMessage()
53
+    {
54
+        return "<i><b><a href=\"/\"><font color=\"" + sender.getColor() + "\"><u>" + sender.getUsername() + "</u></font></a></b> betritt den Chat.</i><br>\n";
55
+    }
56
+}

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

@@ -0,0 +1,58 @@
1
+/* ************************************************************************** */
2
+/*   Project : JC (Java ChatServer)                                           */
3
+/*                                                                            */
4
+/*   Author  : Bernhard Fröhlich <decke@users.sourceforge.net>                */
5
+/*   Homepage: http://decke.staticip.de/                                      */
6
+/*   Copyright (c) 2005  Bernhard Fröhlich <decke@users.sourceforge.net>      */
7
+/*                                                                            */
8
+/*   This library is free software; you can redistribute it and/or            */   
9
+/*   modify it under the terms of the GNU Lesser General Public               */
10
+/*   License as published by the Free Software Foundation; either             */
11
+/*   version 2.1 of the License, or (at your option) any later version.       */
12
+/*                                                                            */
13
+/*   This library is distributed in the hope that it will be useful,          */
14
+/*   but WITHOUT ANY WARRANTY; without even the implied warranty of           */
15
+/*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU        */
16
+/*   Lesser General Public License for more details.                          */
17
+/*                                                                            */
18
+/* ************************************************************************** */
19
+
20
+package at.bluenet.jc.Commands.Messages;
21
+
22
+import at.bluenet.jc.ChatCore.User;
23
+
24
+/**
25
+ * <p>Title: </p>
26
+ *
27
+ * <p>Description: </p>
28
+ *
29
+ * <p>Copyright: Copyright (c) 2005</p>
30
+ *
31
+ * <p>Company: </p>
32
+ *
33
+ * @author Bernhard Fröhlich
34
+ * @version 1.0
35
+ */
36
+public class WhisperFromMessage extends AbstractMessage
37
+{
38
+    private User to = null;
39
+
40
+    public WhisperFromMessage(User from, User to, String message)
41
+    {
42
+        this.sender = from;
43
+        this.to = to;
44
+        this.message = message;
45
+        addRecipient(this.to);
46
+    }
47
+
48
+    /**
49
+     * toRawMessage
50
+     *
51
+     * @return String
52
+     * @todo Implement this at.bluenet.www.JC.Messages.IMessage method
53
+     */
54
+    public String toRawMessage()
55
+    {
56
+        return "<i><b><font color=\"" + sender.getColor() + "\">" + sender.getUsername() + "</font></a> flüstert: " + message + "</b></i><br />\n";
57
+    }
58
+}

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

@@ -0,0 +1,57 @@
1
+/* ************************************************************************** */
2
+/*   Project : JC (Java ChatServer)                                           */
3
+/*                                                                            */
4
+/*   Author  : Bernhard Fröhlich <decke@users.sourceforge.net>                */
5
+/*   Homepage: http://decke.staticip.de/                                      */
6
+/*   Copyright (c) 2005  Bernhard Fröhlich <decke@users.sourceforge.net>      */
7
+/*                                                                            */
8
+/*   This library is free software; you can redistribute it and/or            */   
9
+/*   modify it under the terms of the GNU Lesser General Public               */
10
+/*   License as published by the Free Software Foundation; either             */
11
+/*   version 2.1 of the License, or (at your option) any later version.       */
12
+/*                                                                            */
13
+/*   This library is distributed in the hope that it will be useful,          */
14
+/*   but WITHOUT ANY WARRANTY; without even the implied warranty of           */
15
+/*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU        */
16
+/*   Lesser General Public License for more details.                          */
17
+/*                                                                            */
18
+/* ************************************************************************** */
19
+
20
+package at.bluenet.jc.Commands.Messages;
21
+
22
+import at.bluenet.jc.ChatCore.User;
23
+/**
24
+ * <p>Title: </p>
25
+ *
26
+ * <p>Description: </p>
27
+ *
28
+ * <p>Copyright: Copyright (c) 2005</p>
29
+ *
30
+ * <p>Company: </p>
31
+ *
32
+ * @author Bernhard Fröhlich
33
+ * @version 1.0
34
+ */
35
+public class WhisperToMessage extends AbstractMessage
36
+{
37
+    private User to;
38
+
39
+    public WhisperToMessage(User from, User to, String message)
40
+    {
41
+        this.sender = from;
42
+        this.to = to;
43
+        this.message = message;
44
+        addRecipient(from);
45
+    }
46
+
47
+    /**
48
+     * toRawMessage
49
+     *
50
+     * @return String
51
+     * @todo Implement this at.bluenet.www.JC.Messages.IMessage method
52
+     */
53
+    public String toRawMessage()
54
+    {
55
+        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";
56
+    }
57
+}

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

@@ -0,0 +1,52 @@
1
+/* ************************************************************************** */
2
+/*   Project : JC (Java ChatServer)                                           */
3
+/*                                                                            */
4
+/*   Author  : Bernhard Fröhlich <decke@users.sourceforge.net>                */
5
+/*   Homepage: http://decke.staticip.de/                                      */
6
+/*   Copyright (c) 2005  Bernhard Fröhlich <decke@users.sourceforge.net>      */
7
+/*                                                                            */
8
+/*   This library is free software; you can redistribute it and/or            */   
9
+/*   modify it under the terms of the GNU Lesser General Public               */
10
+/*   License as published by the Free Software Foundation; either             */
11
+/*   version 2.1 of the License, or (at your option) any later version.       */
12
+/*                                                                            */
13
+/*   This library is distributed in the hope that it will be useful,          */
14
+/*   but WITHOUT ANY WARRANTY; without even the implied warranty of           */
15
+/*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU        */
16
+/*   Lesser General Public License for more details.                          */
17
+/*                                                                            */
18
+/* ************************************************************************** */
19
+
20
+package at.bluenet.jc.Commands;
21
+
22
+import at.bluenet.jc.Commands.Messages.StatsMessage;
23
+import at.bluenet.jc.ChatCore.User;
24
+
25
+import java.util.Vector;
26
+
27
+/**
28
+ * <p>Title: </p>
29
+ *
30
+ * <p>Description: </p>
31
+ *
32
+ * <p>Copyright: Copyright (c) 2005</p>
33
+ *
34
+ * <p>Company: </p>
35
+ *
36
+ * @author Bernhard Fröhlich
37
+ * @version 1.0
38
+ */
39
+public class StatsCommand extends AbstractCommand
40
+{
41
+    public StatsCommand()
42
+    {
43
+        this.command = "/stats";
44
+    }
45
+
46
+    public Vector parse(User user, String message)
47
+    {
48
+        Vector v = new Vector();
49
+        v.add(new StatsMessage(user));
50
+        return v;
51
+    }
52
+}

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

@@ -0,0 +1,80 @@
1
+/* ************************************************************************** */
2
+/*   Project : JC (Java ChatServer)                                           */
3
+/*                                                                            */
4
+/*   Author  : Bernhard Fröhlich <decke@users.sourceforge.net>                */
5
+/*   Homepage: http://decke.staticip.de/                                      */
6
+/*   Copyright (c) 2005  Bernhard Fröhlich <decke@users.sourceforge.net>      */
7
+/*                                                                            */
8
+/*   This library is free software; you can redistribute it and/or            */   
9
+/*   modify it under the terms of the GNU Lesser General Public               */
10
+/*   License as published by the Free Software Foundation; either             */
11
+/*   version 2.1 of the License, or (at your option) any later version.       */
12
+/*                                                                            */
13
+/*   This library is distributed in the hope that it will be useful,          */
14
+/*   but WITHOUT ANY WARRANTY; without even the implied warranty of           */
15
+/*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU        */
16
+/*   Lesser General Public License for more details.                          */
17
+/*                                                                            */
18
+/* ************************************************************************** */
19
+
20
+package at.bluenet.jc.Commands;
21
+
22
+import at.bluenet.jc.Commands.Messages.*;
23
+import at.bluenet.jc.ChatCore.*;
24
+import at.bluenet.util.StringTools;
25
+
26
+import java.util.Vector;
27
+
28
+/**
29
+ * <p>Title: </p>
30
+ *
31
+ * <p>Description: </p>
32
+ *
33
+ * <p>Copyright: Copyright (c) 2005</p>
34
+ *
35
+ * <p>Company: </p>
36
+ *
37
+ * @author Bernhard Fröhlich
38
+ * @version 1.0
39
+ */
40
+public class UserListCommand extends AbstractCommand
41
+{
42
+    protected UserPool pool = null;
43
+
44
+    public UserListCommand(UserPool pool)
45
+    {
46
+        this.pool = pool;
47
+        this.command = "/w";
48
+    }
49
+
50
+    /**
51
+     * parse
52
+     *
53
+     * @param user User
54
+     * @param rawMessage String
55
+     * @return IMessage
56
+     * @todo Implement this at.bluenet.www.JC.Commands.ICommand method
57
+     */
58
+    public Vector parse(User user, String rawMessage)
59
+    {
60
+        Vector v = new Vector();
61
+
62
+        if(rawMessage.equals("/w"))
63
+            v.add(new UserListMessage(user, pool.getUsers()));
64
+        else
65
+        {
66
+            if(StringTools.split(rawMessage, ' ').length >= 2)
67
+            {
68
+                User who = (User)pool.getUser(StringTools.split(rawMessage, ' ')[1]);
69
+
70
+                if(who != null)
71
+                    v.add(new UserInfoMessage(user, who));
72
+                else
73
+                    v.add(new ErrorMessage(user, StringTools.split(rawMessage, ' ')[1] + " ist nicht im Chat."));
74
+            }
75
+            else
76
+                v.add(new ErrorMessage(user, "ist nicht im Chat."));
77
+        }
78
+        return v;
79
+    }
80
+}

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

@@ -0,0 +1,60 @@
1
+/* ************************************************************************** */
2
+/*   Project : JC (Java ChatServer)                                           */
3
+/*                                                                            */
4
+/*   Author  : Bernhard Fröhlich <decke@users.sourceforge.net>                */
5
+/*   Homepage: http://decke.staticip.de/                                      */
6
+/*   Copyright (c) 2005  Bernhard Fröhlich <decke@users.sourceforge.net>      */
7
+/*                                                                            */
8
+/*   This library is free software; you can redistribute it and/or            */   
9
+/*   modify it under the terms of the GNU Lesser General Public               */
10
+/*   License as published by the Free Software Foundation; either             */
11
+/*   version 2.1 of the License, or (at your option) any later version.       */
12
+/*                                                                            */
13
+/*   This library is distributed in the hope that it will be useful,          */
14
+/*   but WITHOUT ANY WARRANTY; without even the implied warranty of           */
15
+/*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU        */
16
+/*   Lesser General Public License for more details.                          */
17
+/*                                                                            */
18
+/* ************************************************************************** */
19
+
20
+package at.bluenet.jc.Commands;
21
+
22
+import java.util.Vector;
23
+
24
+import at.bluenet.jc.Commands.Messages.VersionMessage;
25
+import at.bluenet.jc.ChatCore.User;
26
+
27
+/**
28
+ * <p>Title: </p>
29
+ *
30
+ * <p>Description: </p>
31
+ *
32
+ * <p>Copyright: Copyright (c) 2005</p>
33
+ *
34
+ * <p>Company: </p>
35
+ *
36
+ * @author Bernhard Fröhlich
37
+ * @version 1.0
38
+ */
39
+public class VersionCommand extends AbstractCommand
40
+{
41
+    public VersionCommand()
42
+    {
43
+        this.command = "/version";
44
+    }
45
+
46
+    /**
47
+     * parse
48
+     *
49
+     * @param user User
50
+     * @param rawMessage String
51
+     * @return Vector
52
+     * @todo Implement this at.bluenet.www.JC.Commands.ICommand method
53
+     */
54
+    public Vector parse(User user, String rawMessage)
55
+    {
56
+        Vector v = new Vector();
57
+        v.add(new VersionMessage(user));
58
+        return v;
59
+    }
60
+}

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

@@ -0,0 +1,74 @@
1
+/* ************************************************************************** */
2
+/*   Project : JC (Java ChatServer)                                           */
3
+/*                                                                            */
4
+/*   Author  : Bernhard Fröhlich <decke@users.sourceforge.net>                */
5
+/*   Homepage: http://decke.staticip.de/                                      */
6
+/*   Copyright (c) 2005  Bernhard Fröhlich <decke@users.sourceforge.net>      */
7
+/*                                                                            */
8
+/*   This library is free software; you can redistribute it and/or            */   
9
+/*   modify it under the terms of the GNU Lesser General Public               */
10
+/*   License as published by the Free Software Foundation; either             */
11
+/*   version 2.1 of the License, or (at your option) any later version.       */
12
+/*                                                                            */
13
+/*   This library is distributed in the hope that it will be useful,          */
14
+/*   but WITHOUT ANY WARRANTY; without even the implied warranty of           */
15
+/*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU        */
16
+/*   Lesser General Public License for more details.                          */
17
+/*                                                                            */
18
+/* ************************************************************************** */
19
+
20
+package at.bluenet.jc.Commands;
21
+
22
+import at.bluenet.jc.Commands.Messages.*;
23
+import at.bluenet.jc.ChatCore.User;
24
+import at.bluenet.jc.ChatCore.UserPool;
25
+
26
+import java.util.Vector;
27
+
28
+/**
29
+ * <p>Title: </p>
30
+ *
31
+ * <p>Description: </p>
32
+ *
33
+ * <p>Copyright: Copyright (c) 2005</p>
34
+ *
35
+ * <p>Company: </p>
36
+ *
37
+ * @author Bernhard Fröhlich
38
+ * @version 1.0
39
+ */
40
+public class WhisperCommand extends AbstractCommand
41
+{
42
+    protected UserPool pool;
43
+
44
+    public WhisperCommand(UserPool pool)
45
+    {
46
+        this.pool = pool;
47
+        this.command = "/";
48
+    }
49
+
50
+    /**
51
+     * parse
52
+     *
53
+     * @param user User
54
+     * @param rawMessage String
55
+     * @return IMessage
56
+     * @todo Implement this at.bluenet.www.JC.Commands.ICommand method
57
+     */
58
+    public Vector parse(User user, String rawMessage)
59
+    {
60
+        Vector v = new Vector();
61
+        User to = pool.getUser(at.bluenet.util.StringTools.firstWord(rawMessage).substring(1));
62
+
63
+        if(to != null)
64
+        {
65
+            String message = rawMessage.substring(to.getUsername().length() + 2);
66
+            v.add(new WhisperToMessage(user, to, message));
67
+            v.add(new WhisperFromMessage(user, to, message));
68
+        }
69
+        else
70
+            v.add(new ErrorMessage(user, at.bluenet.util.StringTools.firstWord(rawMessage).substring(1) + " ist nicht im Chat."));
71
+
72
+        return v;
73
+    }
74
+}

+ 89
- 0
src/at/bluenet/jc/Config.java View File

@@ -0,0 +1,89 @@
1
+/* ************************************************************************** */
2
+/*   Project : JC (Java ChatServer)                                           */
3
+/*                                                                            */
4
+/*   Author  : Bernhard Fröhlich <decke@users.sourceforge.net>                */
5
+/*   Homepage: http://decke.staticip.de/                                      */
6
+/*   Copyright (c) 2005  Bernhard Fröhlich <decke@users.sourceforge.net>      */
7
+/*                                                                            */
8
+/*   This library is free software; you can redistribute it and/or            */   
9
+/*   modify it under the terms of the GNU Lesser General Public               */
10
+/*   License as published by the Free Software Foundation; either             */
11
+/*   version 2.1 of the License, or (at your option) any later version.       */
12
+/*                                                                            */
13
+/*   This library is distributed in the hope that it will be useful,          */
14
+/*   but WITHOUT ANY WARRANTY; without even the implied warranty of           */
15
+/*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU        */
16
+/*   Lesser General Public License for more details.                          */
17
+/*                                                                            */
18
+/* ************************************************************************** */
19
+
20
+package at.bluenet.jc;
21
+
22
+import java.util.Properties;
23
+import java.io.FileInputStream;
24
+import java.io.IOException;
25
+
26
+/**
27
+ * <p>Title: </p>
28
+ *
29
+ * <p>Description: </p>
30
+ *
31
+ * <p>Copyright: Copyright (c) 2005</p>
32
+ *
33
+ * <p>Company: </p>
34
+ *
35
+ * @author Bernhard Fröhlich
36
+ * @version 1.0
37
+ */
38
+public class Config
39
+{
40
+    Properties config;
41
+    String path = null;
42
+
43
+    public Config(String path)
44
+    {
45
+        try
46
+        {
47
+            config = new Properties();
48
+            config.load(new FileInputStream(path));
49
+            this.path = path;
50
+        }
51
+        catch(IOException e)
52
+        {
53
+            System.out.println("Config: Can't load Config File '" + path + "'");
54
+        }
55
+    }
56
+
57
+    public String get(String key, String def)
58
+    {
59
+        return config.getProperty(key, def);
60
+    }
61
+
62
+    public void set(String key, String val)
63
+    {
64
+        config.setProperty(key, val);
65
+    }
66
+
67
+    public boolean contains(String key)
68
+    {
69
+        return config.containsKey(key);
70
+    }
71
+
72
+    public String getHttpBase()
73
+    {
74
+        return get("HTTP_BASE", "localhost") + ":" + get("PORT", "6667");
75
+    }
76
+
77
+    public void save()
78
+    {
79
+        try
80
+        {
81
+            if(path != null)
82
+                config.store(new java.io.FileOutputStream(path), "Saved last on " + new java.util.Date());
83
+        }
84
+        catch(Exception e)
85
+        {
86
+            System.out.println("Config: Error while saving File. " + e.getMessage());
87
+        }
88
+    }
89
+}

+ 173
- 0
src/at/bluenet/jc/Kernel.java View File

@@ -0,0 +1,173 @@
1
+/* ************************************************************************** */
2
+/*   Project : JC (Java ChatServer)                                           */
3
+/*                                                                            */
4
+/*   Author  : Bernhard Froehlich <decke@users.sourceforge.net>               */
5
+/*   Homepage: http://decke.staticip.de/                                      */
6
+/*   Copyright (c) 2005  Bernhard Froehlich <decke@users.sourceforge.net>     */
7
+/*                                                                            */
8
+/*   This library is free software; you can redistribute it and/or            */   
9
+/*   modify it under the terms of the GNU Lesser General Public               */
10
+/*   License as published by the Free Software Foundation; either             */
11
+/*   version 2.1 of the License, or (at your option) any later version.       */
12
+/*                                                                            */
13
+/*   This library is distributed in the hope that it will be useful,          */
14
+/*   but WITHOUT ANY WARRANTY; without even the implied warranty of           */
15
+/*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU        */
16
+/*   Lesser General Public License for more details.                          */
17
+/*                                                                            */
18
+/* ************************************************************************** */
19
+
20
+package at.bluenet.jc;
21
+
22
+import at.bluenet.jc.Commands.Messages.MessageParser;
23
+import at.bluenet.jc.Requests.HttpRequest;
24
+import at.bluenet.jc.Requests.HttpResponse;
25
+import at.bluenet.jc.Requests.RequestThread;
26
+import at.bluenet.jc.Requests.RequestHandler.ChatRequestHandler;
27
+import at.bluenet.jc.Requests.RequestHandler.ChatStreamRequestHandler;
28
+import at.bluenet.jc.Requests.RequestHandler.DefaultRequestHandler;
29
+import at.bluenet.jc.Requests.RequestHandler.InputRequestHandler;
30
+import at.bluenet.jc.Requests.RequestHandler.MessageRequestHandler;
31
+import at.bluenet.jc.Requests.RequestHandler.RequestHandlerCollector;
32
+import at.bluenet.jc.Requests.RequestHandler.StandardRequestHandler;
33
+import at.bluenet.jc.Requests.RequestHandler.StaticRequestHandler;
34
+import at.bluenet.jc.ChatCore.LoginManager;
35
+import at.bluenet.jc.ChatCore.UserPool;
36
+import at.bluenet.jc.ChatCore.auth.NoAuthenticator;
37
+import at.bluenet.jc.Commands.LogoutCommand;
38
+import at.bluenet.jc.Commands.StatsCommand;
39
+import at.bluenet.jc.Commands.UserListCommand;
40
+import at.bluenet.jc.Commands.VersionCommand;
41
+import at.bluenet.jc.Commands.WhisperCommand;
42
+
43
+import java.io.IOException;
44
+import java.net.Socket;
45
+import java.net.ServerSocket;
46
+
47
+
48
+public class Kernel extends Thread
49
+{
50
+    public static final String VERSION = "0.9.23";
51
+    public static final String VERSION_STRING = "jc/" + VERSION;
52
+    public static String DEFAULT_CHARSET = "ISO-8859-1";
53
+    public static String BASE_PATH = "./";
54
+    public static Config CONFIG    = null;
55
+
56
+    private ServerSocket            listener   = null;
57
+    private MessageParser           parser     = null;
58
+    private RequestHandlerCollector collector  = null;
59
+    private UserPool                userpool   = null;
60
+    private LoginManager            manager    = null;
61
+    
62
+
63
+    public Kernel() throws Exception
64
+    {
65
+        CONFIG = new Config(BASE_PATH + "config/jc.properties");
66
+        DEFAULT_CHARSET = CONFIG.get("CHARSET", "ISO-8859-1");
67
+
68
+        parser = new MessageParser();
69
+        userpool = new UserPool(parser);
70
+        manager = new LoginManager(userpool, new NoAuthenticator());
71
+
72
+        parser.addCommand(new UserListCommand(userpool));
73
+        parser.addCommand(new WhisperCommand(userpool));
74
+        parser.addCommand(new LogoutCommand(userpool));
75
+        parser.addCommand(new StatsCommand());
76
+        parser.addCommand(new VersionCommand());
77
+        parser.setUserPool(userpool);
78
+
79
+        collector = new RequestHandlerCollector(new DefaultRequestHandler());
80
+        collector.addHandler("/", new StandardRequestHandler(userpool));
81
+        collector.addHandler("/static/*", new StaticRequestHandler(BASE_PATH + "static/"));
82
+        collector.addHandler("/STREAM", new ChatStreamRequestHandler(manager));
83
+        collector.addHandler("/MSG", new MessageRequestHandler(userpool));
84
+        collector.addHandler("/CHAT", new ChatRequestHandler(manager));
85
+        collector.addHandler("/INPUT", new InputRequestHandler());
86
+
87
+        userpool.start();
88
+
89
+        listener = new ServerSocket(Integer.parseInt(CONFIG.get("PORT", "6667")));
90
+
91
+        Runtime.getRuntime().addShutdownHook(new Thread()
92
+        {
93
+                public void run()
94
+                {
95
+                    close();
96
+                }
97
+        });
98
+    }
99
+
100
+    public void run()
101
+    {
102
+        System.out.println("-- " + VERSION_STRING + " by Bernhard Froehlich (decke@users.sourceforge.net)");
103
+        System.out.println("Kernel Thread waiting for requests ...");
104
+
105
+        while(!isInterrupted())
106
+        {
107
+            try
108
+            {
109
+                Socket s = listener.accept();
110
+                new RequestThread(new HttpRequest(s), new HttpResponse(s), collector).start();
111
+            }
112
+            catch(IOException e)
113
+            {
114
+                break;
115
+            }
116
+            catch(Exception e)
117
+            {
118
+                System.out.println("Kernel Exception:" + e.getMessage());
119
+                e.printStackTrace();
120
+            }
121
+        }
122
+        System.out.println("OUT OF kernel RUN()");
123
+    }
124
+
125
+    protected void close()
126
+    {
127
+        try
128
+        {
129
+            System.out.println("SHUTDOWN INITIALIZED ...");
130
+
131
+            System.out.println("SAVING CONFIG:");
132
+            CONFIG.save();
133
+            System.out.println("Config saved.");
134
+
135
+            System.out.println("SHUTDOWN USERPOOL:");
136
+            userpool.close();
137
+
138
+            System.out.println("SHUTDOWN LISTENER:");
139
+            listener.close();
140
+
141
+        } catch (IOException e) {
142
+            System.out.println("Could not close Kernels ServerSocket");
143
+        }
144
+        System.out.println("SHUTDOWN END.");
145
+    }
146
+    /**
147
+     * @param args the command line arguments
148
+     */
149
+    public static void main(String[] args)
150
+    {
151
+        for (int i = 0; i < args.length; i++)
152
+        {
153
+            if (args[i].startsWith("-b="))
154
+            {
155
+                BASE_PATH = args[0].substring(3);
156
+                if(!BASE_PATH.endsWith("/"))
157
+                    BASE_PATH = BASE_PATH + "/";
158
+            }
159
+        }
160
+
161
+        try
162
+        {
163
+            Kernel server = new Kernel();
164
+            server.setPriority(Thread.MAX_PRIORITY);
165
+            server.start();
166
+        }
167
+        catch(Exception e)
168
+        {
169
+            System.out.println("Core Error:" + e.getMessage());
170
+            e.printStackTrace();
171
+        }
172
+    }
173
+}

+ 241
- 0
src/at/bluenet/jc/Requests/HttpRequest.java View File

@@ -0,0 +1,241 @@
1
+/* ************************************************************************** */
2
+/*   Project : JC (Java ChatServer)                                           */
3
+/*                                                                            */
4
+/*   Author  : Bernhard Fröhlich <decke@users.sourceforge.net>                */
5
+/*   Homepage: http://decke.staticip.de/                                      */
6
+/*   Copyright (c) 2005  Bernhard Fröhlich <decke@users.sourceforge.net>      */
7
+/*                                                                            */
8
+/*   This library is free software; you can redistribute it and/or            */   
9
+/*   modify it under the terms of the GNU Lesser General Public               */
10
+/*   License as published by the Free Software Foundation; either             */
11
+/*   version 2.1 of the License, or (at your option) any later version.       */
12
+/*                                                                            */
13
+/*   This library is distributed in the hope that it will be useful,          */
14
+/*   but WITHOUT ANY WARRANTY; without even the implied warranty of           */
15
+/*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU        */
16
+/*   Lesser General Public License for more details.                          */
17
+/*                                                                            */
18
+/* ************************************************************************** */
19
+
20
+package at.bluenet.jc.Requests;
21
+
22
+import java.net.Socket;
23
+import java.net.InetAddress;
24
+import java.util.Hashtable;
25
+import java.io.BufferedReader;
26
+import java.io.InputStreamReader;
27
+
28
+import java.net.ProtocolException;
29
+import java.io.IOException;
30
+
31
+import at.bluenet.util.uri.URI;
32
+
33
+/**
34
+ *
35
+ * @author Bernhard Fröhlich
36
+ */
37
+public class HttpRequest implements IRequest
38
+{
39
+    private Socket s;
40
+    private Hashtable header = new Hashtable();
41
+    private Hashtable variables = new Hashtable();
42
+    private byte method = -1;
43
+    public BufferedReader in;
44
+    private URI request = null;
45
+
46
+    public HttpRequest(Socket s) throws IOException
47
+    {
48
+        this.s = s;
49
+        in = new BufferedReader(new InputStreamReader(s.getInputStream()));
50
+    }
51
+
52
+    private void parseVariables(String query)
53
+    {
54
+        try
55
+        {
56
+        	String[] parts = at.bluenet.util.StringTools.split(query, '&');
57
+
58
+            for(int i=0; i < parts.length; i++)
59
+            {
60
+                int idx = parts[i].indexOf('=');
61
+                variables.put(parts[i].substring(0, idx).toLowerCase(), (String)parts[i].substring(idx + 1));
62
+            }
63
+        }
64
+        catch(Exception e)
65
+        {
66
+            ;
67
+        }
68
+    }
69
+
70
+    public void parse() throws ProtocolException, IOException
71
+    {
72
+        String line = in.readLine();
73
+        if(line == null)
74
+            throw new ProtocolException("400 Bad Request");
75
+
76
+        String[] firstLine = at.bluenet.util.StringTools.split(line, ' ');
77
+
78
+        // Check if there are 3 parts in first line
79
+        if(firstLine.length != 3)
80
+            throw new ProtocolException("400 Bad Request");
81
+
82
+        // determine Method
83
+        if(firstLine[0].toUpperCase().equals("GET"))
84
+            method = METHOD_GET;
85
+        else if(firstLine[0].toUpperCase().equals("POST"))
86
+            method = METHOD_POST;
87
+        else
88
+            throw new ProtocolException("405 Method Not Allowed");
89
+
90
+        // determine Protocol
91
+        if(!firstLine[2].toUpperCase().equals("HTTP/1.1") && !firstLine[2].toUpperCase().equals("HTTP/1.0"))
92
+            throw new ProtocolException("505 HTTP Version Not Supported");
93
+
94
+        try
95
+        {
96
+            if(firstLine[1].length() > 5120)
97
+            	throw new ProtocolException("414 Request URI too long");
98
+            
99
+            request = new URI(firstLine[1]);
100
+        }
101
+        catch(Exception e)
102
+        {
103
+            throw new ProtocolException("Error creating URI: " + e.getMessage());
104
+        }
105
+
106
+        if(getMethod() == METHOD_GET)
107
+        	parseVariables(request.getQuery());
108
+
109
+
110
+        // Read the header
111
+        int idx;
112
+        while((line = in.readLine()) != null)
113
+        {
114
+            if (line.length() == 0 || line.length() > 255)
115
+                break;
116
+            if((idx = line.indexOf(":")) != -1)
117
+                header.put(line.substring(0, idx).toLowerCase(), line.substring(idx + 2, line.length()));
118
+        }
119
+
120
+        // ok so if you POST we read the content too
121
+        if(getMethod() == METHOD_POST)
122
+        {
123
+            int contentLength;
124
+            try
125
+            {
126
+                contentLength = Integer.parseInt((String)header.get("content-length"));
127
+            }
128
+            catch(Exception e)
129
+            {
130
+                throw new ProtocolException("411 Length Required");
131
+            }
132
+
133
+
134
+            // Read arguments
135
+            StringBuffer args = new StringBuffer();
136
+            for (int ctr = 0; ctr < contentLength; ctr++)
137
+            {
138
+                char c = (char)in.read();
139
+
140
+                // Check for unexpected end of stream