|
From: <cl...@us...> - 2015-04-09 16:48:17
|
Revision: 5375
http://sourceforge.net/p/colossus/code/5375
Author: cleka
Date: 2015-04-09 16:48:13 +0000 (Thu, 09 Apr 2015)
Log Message:
-----------
Set eol-style native on all files in webserver related packages
Modified Paths:
--------------
trunk/Colossus/core/src/main/java/net/sf/colossus/webcommon/ChatMessage.java
trunk/Colossus/core/src/main/java/net/sf/colossus/webcommon/FormatWhen.java
trunk/Colossus/core/src/main/java/net/sf/colossus/webcommon/IGameManager.java
trunk/Colossus/core/src/main/java/net/sf/colossus/webcommon/IManagedGame.java
trunk/Colossus/core/src/main/java/net/sf/colossus/webcommon/IPortProvider.java
trunk/Colossus/core/src/main/java/net/sf/colossus/webcommon/UserDB.java
trunk/Colossus/core/src/main/java/net/sf/colossus/webserver/ChatChannel.java
trunk/Colossus/core/src/main/java/net/sf/colossus/webserver/ChatMsgStorage.java
trunk/Colossus/core/src/main/java/net/sf/colossus/webserver/ClientWatchDog.java
trunk/Colossus/core/src/main/java/net/sf/colossus/webserver/ColossusRegistry.java
trunk/Colossus/core/src/main/java/net/sf/colossus/webserver/GameManager.java
trunk/Colossus/core/src/main/java/net/sf/colossus/webserver/QueuedSocketWriter.java
trunk/Colossus/core/src/main/java/net/sf/colossus/webserver/RoundtripTimeBookkeeper.java
trunk/Colossus/core/src/main/java/net/sf/colossus/webserver/WebServerClient.java
Property Changed:
----------------
trunk/Colossus/core/src/main/java/net/sf/colossus/webcommon/ChatMessage.java
trunk/Colossus/core/src/main/java/net/sf/colossus/webcommon/FormatWhen.java
trunk/Colossus/core/src/main/java/net/sf/colossus/webcommon/IGameManager.java
trunk/Colossus/core/src/main/java/net/sf/colossus/webcommon/IManagedGame.java
trunk/Colossus/core/src/main/java/net/sf/colossus/webcommon/IPortProvider.java
trunk/Colossus/core/src/main/java/net/sf/colossus/webcommon/UserDB.java
trunk/Colossus/core/src/main/java/net/sf/colossus/webserver/ChatChannel.java
trunk/Colossus/core/src/main/java/net/sf/colossus/webserver/ChatMsgStorage.java
trunk/Colossus/core/src/main/java/net/sf/colossus/webserver/ClientWatchDog.java
trunk/Colossus/core/src/main/java/net/sf/colossus/webserver/ColossusRegistry.java
trunk/Colossus/core/src/main/java/net/sf/colossus/webserver/GameManager.java
trunk/Colossus/core/src/main/java/net/sf/colossus/webserver/QueuedSocketWriter.java
trunk/Colossus/core/src/main/java/net/sf/colossus/webserver/RoundtripTimeBookkeeper.java
trunk/Colossus/core/src/main/java/net/sf/colossus/webserver/WebServerClient.java
Modified: trunk/Colossus/core/src/main/java/net/sf/colossus/webcommon/ChatMessage.java
===================================================================
--- trunk/Colossus/core/src/main/java/net/sf/colossus/webcommon/ChatMessage.java 2015-04-09 16:14:41 UTC (rev 5374)
+++ trunk/Colossus/core/src/main/java/net/sf/colossus/webcommon/ChatMessage.java 2015-04-09 16:48:13 UTC (rev 5375)
@@ -1,44 +1,44 @@
-/**
- *
- */
-package net.sf.colossus.webcommon;
-
-
-public class ChatMessage
-{
- String chatId;
- long when;
- String sender;
- String message;
-
- public ChatMessage(String chatId, long when, String sender,
- String message)
- {
- this.chatId = chatId;
- this.when = when;
- this.sender = sender;
- this.message = message;
- }
-
- public String getChatId()
- {
- return this.chatId;
- }
-
- public long getWhen()
- {
- return this.when;
- }
-
- public String getSender()
- {
- return this.sender;
- }
-
- public String getMessage()
- {
- return this.message;
- }
-
-}
-
+/**
+ *
+ */
+package net.sf.colossus.webcommon;
+
+
+public class ChatMessage
+{
+ String chatId;
+ long when;
+ String sender;
+ String message;
+
+ public ChatMessage(String chatId, long when, String sender,
+ String message)
+ {
+ this.chatId = chatId;
+ this.when = when;
+ this.sender = sender;
+ this.message = message;
+ }
+
+ public String getChatId()
+ {
+ return this.chatId;
+ }
+
+ public long getWhen()
+ {
+ return this.when;
+ }
+
+ public String getSender()
+ {
+ return this.sender;
+ }
+
+ public String getMessage()
+ {
+ return this.message;
+ }
+
+}
+
Property changes on: trunk/Colossus/core/src/main/java/net/sf/colossus/webcommon/ChatMessage.java
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Modified: trunk/Colossus/core/src/main/java/net/sf/colossus/webcommon/FormatWhen.java
===================================================================
--- trunk/Colossus/core/src/main/java/net/sf/colossus/webcommon/FormatWhen.java 2015-04-09 16:14:41 UTC (rev 5374)
+++ trunk/Colossus/core/src/main/java/net/sf/colossus/webcommon/FormatWhen.java 2015-04-09 16:48:13 UTC (rev 5375)
@@ -1,63 +1,63 @@
-/**
- *
- */
-package net.sf.colossus.webcommon;
-
-import java.text.SimpleDateFormat;
-import java.util.Date;
-
-public class FormatWhen
-{
- public static final String DATE_FORMAT = "yyyy-MM-dd";
- public static final String TIME_FORMAT = "HH:mm:ss";
-
- private final SimpleDateFormat dateFormatter;
- private final SimpleDateFormat timeFormatter;
-
- private String datePrev;
- private String changedDateString = null;
-
- public FormatWhen()
- {
- datePrev = "";
- dateFormatter = new SimpleDateFormat(DATE_FORMAT);
- timeFormatter = new SimpleDateFormat(TIME_FORMAT);
-
- }
-
- /* call this *after* timeAsString() call
- * It will return the new date, if changed, null otherwise */
-
- public String hasDateChanged()
- {
- return changedDateString;
- }
-
- public String timeAsString(long when)
- {
- Date whenDate = new Date(when);
- String timeNow = timeFormatter.format(whenDate);
- String dateNow = dateFormatter.format(whenDate);
-
- if (!dateNow.equals(datePrev))
- {
- changedDateString = dateNow;
- }
- else
- {
- changedDateString = null;
- }
- datePrev = dateNow;
-
- return timeNow;
- }
-
- public String timeAndDateAsString(long when)
- {
- Date whenDate = new Date(when);
- String timeNow = timeFormatter.format(whenDate);
- String dateNow = dateFormatter.format(whenDate);
-
- return dateNow + " " + timeNow;
- }
+/**
+ *
+ */
+package net.sf.colossus.webcommon;
+
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+public class FormatWhen
+{
+ public static final String DATE_FORMAT = "yyyy-MM-dd";
+ public static final String TIME_FORMAT = "HH:mm:ss";
+
+ private final SimpleDateFormat dateFormatter;
+ private final SimpleDateFormat timeFormatter;
+
+ private String datePrev;
+ private String changedDateString = null;
+
+ public FormatWhen()
+ {
+ datePrev = "";
+ dateFormatter = new SimpleDateFormat(DATE_FORMAT);
+ timeFormatter = new SimpleDateFormat(TIME_FORMAT);
+
+ }
+
+ /* call this *after* timeAsString() call
+ * It will return the new date, if changed, null otherwise */
+
+ public String hasDateChanged()
+ {
+ return changedDateString;
+ }
+
+ public String timeAsString(long when)
+ {
+ Date whenDate = new Date(when);
+ String timeNow = timeFormatter.format(whenDate);
+ String dateNow = dateFormatter.format(whenDate);
+
+ if (!dateNow.equals(datePrev))
+ {
+ changedDateString = dateNow;
+ }
+ else
+ {
+ changedDateString = null;
+ }
+ datePrev = dateNow;
+
+ return timeNow;
+ }
+
+ public String timeAndDateAsString(long when)
+ {
+ Date whenDate = new Date(when);
+ String timeNow = timeFormatter.format(whenDate);
+ String dateNow = dateFormatter.format(whenDate);
+
+ return dateNow + " " + timeNow;
+ }
}
\ No newline at end of file
Property changes on: trunk/Colossus/core/src/main/java/net/sf/colossus/webcommon/FormatWhen.java
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Modified: trunk/Colossus/core/src/main/java/net/sf/colossus/webcommon/IGameManager.java
===================================================================
--- trunk/Colossus/core/src/main/java/net/sf/colossus/webcommon/IGameManager.java 2015-04-09 16:14:41 UTC (rev 5374)
+++ trunk/Colossus/core/src/main/java/net/sf/colossus/webcommon/IGameManager.java 2015-04-09 16:48:13 UTC (rev 5375)
@@ -1,21 +1,21 @@
-package net.sf.colossus.webcommon;
-
-
-import java.rmi.AccessException;
-import java.rmi.NotBoundException;
-import java.rmi.Remote;
-import java.rmi.RemoteException;
-
-
-public interface IGameManager extends Remote
-{
- public void tellEvent(String description) throws RemoteException;
-
- public void registerGame(String gameId) throws RemoteException,
- NotBoundException;
-
- public void unregisterGame(String gameId) throws AccessException,
- NotBoundException, RemoteException;
-}
-
-
+package net.sf.colossus.webcommon;
+
+
+import java.rmi.AccessException;
+import java.rmi.NotBoundException;
+import java.rmi.Remote;
+import java.rmi.RemoteException;
+
+
+public interface IGameManager extends Remote
+{
+ public void tellEvent(String description) throws RemoteException;
+
+ public void registerGame(String gameId) throws RemoteException,
+ NotBoundException;
+
+ public void unregisterGame(String gameId) throws AccessException,
+ NotBoundException, RemoteException;
+}
+
+
Property changes on: trunk/Colossus/core/src/main/java/net/sf/colossus/webcommon/IGameManager.java
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Modified: trunk/Colossus/core/src/main/java/net/sf/colossus/webcommon/IManagedGame.java
===================================================================
--- trunk/Colossus/core/src/main/java/net/sf/colossus/webcommon/IManagedGame.java 2015-04-09 16:14:41 UTC (rev 5374)
+++ trunk/Colossus/core/src/main/java/net/sf/colossus/webcommon/IManagedGame.java 2015-04-09 16:48:13 UTC (rev 5375)
@@ -1,11 +1,11 @@
-package net.sf.colossus.webcommon;
-
-import java.rmi.Remote;
-import java.rmi.RemoteException;
-
-public interface IManagedGame extends Remote
-{
- public String tellStatus() throws RemoteException;
-
-
-}
+package net.sf.colossus.webcommon;
+
+import java.rmi.Remote;
+import java.rmi.RemoteException;
+
+public interface IManagedGame extends Remote
+{
+ public String tellStatus() throws RemoteException;
+
+
+}
Property changes on: trunk/Colossus/core/src/main/java/net/sf/colossus/webcommon/IManagedGame.java
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Modified: trunk/Colossus/core/src/main/java/net/sf/colossus/webcommon/IPortProvider.java
===================================================================
--- trunk/Colossus/core/src/main/java/net/sf/colossus/webcommon/IPortProvider.java 2015-04-09 16:14:41 UTC (rev 5374)
+++ trunk/Colossus/core/src/main/java/net/sf/colossus/webcommon/IPortProvider.java 2015-04-09 16:48:13 UTC (rev 5375)
@@ -1,13 +1,13 @@
-/**
- *
- */
-package net.sf.colossus.webcommon;
-
-
-/**
- *
- */
-public interface IPortProvider
-{
- public abstract int getFreePort(GameInfo gi);
-}
+/**
+ *
+ */
+package net.sf.colossus.webcommon;
+
+
+/**
+ *
+ */
+public interface IPortProvider
+{
+ public abstract int getFreePort(GameInfo gi);
+}
Property changes on: trunk/Colossus/core/src/main/java/net/sf/colossus/webcommon/IPortProvider.java
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Modified: trunk/Colossus/core/src/main/java/net/sf/colossus/webcommon/UserDB.java
===================================================================
--- trunk/Colossus/core/src/main/java/net/sf/colossus/webcommon/UserDB.java 2015-04-09 16:14:41 UTC (rev 5374)
+++ trunk/Colossus/core/src/main/java/net/sf/colossus/webcommon/UserDB.java 2015-04-09 16:48:13 UTC (rev 5375)
@@ -1,416 +1,416 @@
-package net.sf.colossus.webcommon;
-
-
-import java.io.BufferedReader;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.io.PrintWriter;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.LinkedList;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-import net.sf.colossus.webserver.WebServerClient;
-
-
-public class UserDB
-{
- private static final Logger LOGGER = Logger.getLogger(UserDB.class
- .getName());
-
- private final int maxUsers;
-
- private final String usersFile;
-
- private final HashMap<String, User> userMap = new HashMap<String, User>();
- private final HashMap<String, User> loggedInUserMap = new HashMap<String, User>();
-
- private final HashMap<String, User> pendingRegistrations = new HashMap<String, User>();
-
- private long highestExistingId;
-
- public UserDB(String filename, int maxUsersVal)
- {
- maxUsers = maxUsersVal;
- usersFile = filename;
- if (usersFile != null)
- {
- readUsersFromFile();
- }
- }
-
- public int getUserCount()
- {
- synchronized (userMap)
- {
- return userMap.size();
- }
- }
-
- public void updateLoggedinStatus(User u, WebServerClient wsc)
- {
- String username = u.getName();
- synchronized (loggedInUserMap)
- {
- if (wsc == null)
- {
- if (loggedInUserMap.containsKey(username))
- {
- loggedInUserMap.remove(username);
- }
- }
- else
- {
- loggedInUserMap.put(username, u);
- }
- }
-
- }
- public boolean isUserOnline(User u)
- {
- synchronized (loggedInUserMap)
- {
- return loggedInUserMap.containsKey(u.getName());
- }
- }
-
- public Collection<User> getLoggedInUsers()
- {
- synchronized (loggedInUserMap)
- {
- Collection<User> c = new LinkedList<User>();
- c.addAll(loggedInUserMap.values());
- return c;
- }
- }
-
- public User findUserByName(String name)
- {
- synchronized (userMap)
- {
- String nameAllLower = name.toLowerCase();
- return userMap.get(nameAllLower);
- }
- }
-
- public String getLoggedInNamesAsString(String useSeparator)
- {
- String names = "<none>";
- String separator = "";
-
- synchronized (loggedInUserMap)
- {
- if (!loggedInUserMap.isEmpty())
- {
- StringBuilder list = new StringBuilder("");
- for (String key : loggedInUserMap.keySet())
- {
- list.append(separator);
- list.append(key);
- separator = useSeparator;
- }
- names = list.toString();
- }
- }
- return names;
- }
-
- // still dummy
- public int getDeadCount()
- {
- return 0;
- }
-
- // still dummy
- public int getEnrolledCount()
- {
- return 0;
- }
-
- // still dummy
- public int getPlayingCount()
- {
- return 0;
- }
-
- public int getLoggedInCount()
- {
- synchronized (loggedInUserMap)
- {
- return loggedInUserMap.size();
- }
- }
-
- public Collection<User> getAllUsers()
- {
- synchronized (userMap)
- {
- Collection<User> c = new LinkedList<User>();
- c.addAll(userMap.values());
- return c;
- }
- }
-
- /**
- * Given a username and password, verifies that the user
- * is allowed to login with that password.
- * @param username
- * @param password
- * @return reasonLoginFailed (String), null if login ok
- **/
- public String verifyLogin(String username, String password)
- {
- String reasonLoginFailed = null;
-
- User user = findUserByName(username);
-
- if (user == null)
- {
- reasonLoginFailed = "Invalid username";
- }
- else if (password != null && user.isCorrectPassword(password))
- {
- // ok, return null to indicate all is fine
- }
- else
- {
- reasonLoginFailed = "Invalid username/password";
- }
-
- return reasonLoginFailed;
- }
-
- public String registerUser(String username, String password, String email,
- IColossusMail mailObject)
- {
- boolean isAdmin = false;
-
- String usernameAllLc = username;
- usernameAllLc = usernameAllLc.toLowerCase();
- if (usernameAllLc.startsWith("guest")
- || usernameAllLc.startsWith("anonym"))
- {
- String problem = "Usernames starting with 'guest' or 'anonym' "
- + " are reserved for special purposes!";
- return problem;
- }
- User alreadyExisting = findUserByName(username);
- if (alreadyExisting != null)
- {
- String problem = "User " + username + " does already exist.";
- return problem;
- }
- else if (getUserCount() >= maxUsers)
- {
- String problem = "Maximum number of accounts )" + maxUsers
- + ") reached - no more registrations possible,"
- + " until some administrator checks the situation.";
- return problem;
- }
- else
- {
- highestExistingId++;
- User u = new User(highestExistingId, username, password, email,
- isAdmin, null, null, null, 0);
- String cCode = u.getLastConfirmationCode();
- User.LOGGER.fine("Confirmation code for user " + username
- + " is: " + cCode);
-
- String reason = sendConfirmationMail(username, email, cCode,
- mailObject);
- if (reason != null)
- {
- // mail sending failed, for some reason. Let user know it.
- return reason;
- }
-
- pendingRegistrations.put(username, u);
- // so far everything fine. Now client shall request the conf. code
-
- reason = User.PROVIDE_CONFCODE;
- return reason;
- }
- }
-
-
- public String sendConfirmationMail(String username, String email,
- String confCode, IColossusMail mailObject)
- {
- // this is in webcommon package:
- return mailObject.sendConfirmationMail(username, email, confCode);
- }
-
- public String confirmRegistration(String username, String confirmationCode)
- {
- String reason = "";
- if (confirmationCode == null || confirmationCode.equals("null")
- || confirmationCode.equals(""))
- {
- reason = "Missing confirmation code";
- return reason;
- }
-
- String msg = "User " + username + " attempts confirmation "
- + "with code '" + confirmationCode + "'.";
- User.LOGGER.fine(msg);
-
- reason = confirmIfCorrectCode(username, confirmationCode);
- return reason;
- }
-
- private String confirmIfCorrectCode(String username,
- String tryConfirmationCode)
- {
- User u = pendingRegistrations.get(username);
- if (u == null)
- {
- return "No confirmation pending for this username";
- }
-
- if (!u.getLastConfirmationCode().equals(tryConfirmationCode))
- {
- return User.WRONG_CONFCODE;
- }
-
- User.LOGGER.info("Registration confirmed for user '" + username
- + "', email '" + u.getEmail() + "'.");
-
- pendingRegistrations.remove(username);
- storeUser(u);
- storeUsersToFile();
-
- return null;
- }
-
- public String changeProperties(String username, String oldPW,
- String newPW, String email, Boolean isAdmin)
- {
- String reason;
-
- User u = findUserByName(username);
- if (u == null)
- {
- reason = "User does not exist";
- return reason;
- }
- else if ((reason = verifyLogin(username, oldPW)) != null)
- {
- return reason;
- }
- else
- {
- u.setProperties(newPW, email, isAdmin);
- storeUsersToFile();
- return null;
- }
- }
-
- private void readUsersFromFile()
- {
- long maxId = 0;
- try
- {
- BufferedReader users = new BufferedReader(new InputStreamReader(
- new FileInputStream(usersFile)));
-
- String line = null;
- while ((line = users.readLine()) != null)
- {
- if (line.startsWith("#"))
- {
- // ignore comment line
- }
- else if (line.matches("\\s*"))
- {
- // ignore empty line
- }
- else
- {
- User u = User.makeUserFromUserLine(line);
- if (u != null)
- {
- storeUser(u);
- if (u.getId() > maxId)
- {
- maxId = u.getId();
- }
- }
- }
- }
- this.highestExistingId = maxId;
- users.close();
- }
- catch (FileNotFoundException e)
- {
- LOGGER.log(Level.SEVERE,
- "Users file " + usersFile + " not found!", e);
- System.exit(1);
- }
- catch (IOException e)
- {
- LOGGER.log(Level.SEVERE, "IOException while reading users file "
- + usersFile + "!", e);
- System.exit(1);
- }
- }
+package net.sf.colossus.webcommon;
- public void storeUsersToFile()
- {
- if (usersFile == null)
- {
- User.LOGGER.log(Level.SEVERE, "UsersFile name is null!");
- System.exit(1);
- }
-
- // LOGGER.log(Level.FINE, "Storing users back to file " + filename);
-
- PrintWriter out = null;
- try
- {
- out = new PrintWriter(new FileOutputStream(usersFile));
-
- Collection<User> users = new LinkedList<User>();
- users.addAll(getAllUsers());
-
- for (User user : users)
- {
- String line = user.makeLine();
- out.println(line);
- }
- out.close();
- }
- catch (FileNotFoundException e)
- {
- User.LOGGER.log(Level.SEVERE, "Writing users file " + usersFile
- + "failed: FileNotFoundException: ", e);
- System.exit(1);
- }
- }
-
- private void storeUser(User u)
- {
- String name = u.getName();
- String nameAllLower = name.toLowerCase();
- synchronized (userMap)
- {
- userMap.put(nameAllLower, u);
- }
- }
-
- public void cleanup()
- {
- synchronized (userMap)
- {
- userMap.clear();
- }
- synchronized (loggedInUserMap)
- {
- loggedInUserMap.clear();
- }
- }
-
-}
+
+import java.io.BufferedReader;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.PrintWriter;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import net.sf.colossus.webserver.WebServerClient;
+
+
+public class UserDB
+{
+ private static final Logger LOGGER = Logger.getLogger(UserDB.class
+ .getName());
+
+ private final int maxUsers;
+
+ private final String usersFile;
+
+ private final HashMap<String, User> userMap = new HashMap<String, User>();
+ private final HashMap<String, User> loggedInUserMap = new HashMap<String, User>();
+
+ private final HashMap<String, User> pendingRegistrations = new HashMap<String, User>();
+
+ private long highestExistingId;
+
+ public UserDB(String filename, int maxUsersVal)
+ {
+ maxUsers = maxUsersVal;
+ usersFile = filename;
+ if (usersFile != null)
+ {
+ readUsersFromFile();
+ }
+ }
+
+ public int getUserCount()
+ {
+ synchronized (userMap)
+ {
+ return userMap.size();
+ }
+ }
+
+ public void updateLoggedinStatus(User u, WebServerClient wsc)
+ {
+ String username = u.getName();
+ synchronized (loggedInUserMap)
+ {
+ if (wsc == null)
+ {
+ if (loggedInUserMap.containsKey(username))
+ {
+ loggedInUserMap.remove(username);
+ }
+ }
+ else
+ {
+ loggedInUserMap.put(username, u);
+ }
+ }
+
+ }
+ public boolean isUserOnline(User u)
+ {
+ synchronized (loggedInUserMap)
+ {
+ return loggedInUserMap.containsKey(u.getName());
+ }
+ }
+
+ public Collection<User> getLoggedInUsers()
+ {
+ synchronized (loggedInUserMap)
+ {
+ Collection<User> c = new LinkedList<User>();
+ c.addAll(loggedInUserMap.values());
+ return c;
+ }
+ }
+
+ public User findUserByName(String name)
+ {
+ synchronized (userMap)
+ {
+ String nameAllLower = name.toLowerCase();
+ return userMap.get(nameAllLower);
+ }
+ }
+
+ public String getLoggedInNamesAsString(String useSeparator)
+ {
+ String names = "<none>";
+ String separator = "";
+
+ synchronized (loggedInUserMap)
+ {
+ if (!loggedInUserMap.isEmpty())
+ {
+ StringBuilder list = new StringBuilder("");
+ for (String key : loggedInUserMap.keySet())
+ {
+ list.append(separator);
+ list.append(key);
+ separator = useSeparator;
+ }
+ names = list.toString();
+ }
+ }
+ return names;
+ }
+
+ // still dummy
+ public int getDeadCount()
+ {
+ return 0;
+ }
+
+ // still dummy
+ public int getEnrolledCount()
+ {
+ return 0;
+ }
+
+ // still dummy
+ public int getPlayingCount()
+ {
+ return 0;
+ }
+
+ public int getLoggedInCount()
+ {
+ synchronized (loggedInUserMap)
+ {
+ return loggedInUserMap.size();
+ }
+ }
+
+ public Collection<User> getAllUsers()
+ {
+ synchronized (userMap)
+ {
+ Collection<User> c = new LinkedList<User>();
+ c.addAll(userMap.values());
+ return c;
+ }
+ }
+
+ /**
+ * Given a username and password, verifies that the user
+ * is allowed to login with that password.
+ * @param username
+ * @param password
+ * @return reasonLoginFailed (String), null if login ok
+ **/
+ public String verifyLogin(String username, String password)
+ {
+ String reasonLoginFailed = null;
+
+ User user = findUserByName(username);
+
+ if (user == null)
+ {
+ reasonLoginFailed = "Invalid username";
+ }
+ else if (password != null && user.isCorrectPassword(password))
+ {
+ // ok, return null to indicate all is fine
+ }
+ else
+ {
+ reasonLoginFailed = "Invalid username/password";
+ }
+
+ return reasonLoginFailed;
+ }
+
+ public String registerUser(String username, String password, String email,
+ IColossusMail mailObject)
+ {
+ boolean isAdmin = false;
+
+ String usernameAllLc = username;
+ usernameAllLc = usernameAllLc.toLowerCase();
+ if (usernameAllLc.startsWith("guest")
+ || usernameAllLc.startsWith("anonym"))
+ {
+ String problem = "Usernames starting with 'guest' or 'anonym' "
+ + " are reserved for special purposes!";
+ return problem;
+ }
+ User alreadyExisting = findUserByName(username);
+ if (alreadyExisting != null)
+ {
+ String problem = "User " + username + " does already exist.";
+ return problem;
+ }
+ else if (getUserCount() >= maxUsers)
+ {
+ String problem = "Maximum number of accounts )" + maxUsers
+ + ") reached - no more registrations possible,"
+ + " until some administrator checks the situation.";
+ return problem;
+ }
+ else
+ {
+ highestExistingId++;
+ User u = new User(highestExistingId, username, password, email,
+ isAdmin, null, null, null, 0);
+ String cCode = u.getLastConfirmationCode();
+ User.LOGGER.fine("Confirmation code for user " + username
+ + " is: " + cCode);
+
+ String reason = sendConfirmationMail(username, email, cCode,
+ mailObject);
+ if (reason != null)
+ {
+ // mail sending failed, for some reason. Let user know it.
+ return reason;
+ }
+
+ pendingRegistrations.put(username, u);
+ // so far everything fine. Now client shall request the conf. code
+
+ reason = User.PROVIDE_CONFCODE;
+ return reason;
+ }
+ }
+
+
+ public String sendConfirmationMail(String username, String email,
+ String confCode, IColossusMail mailObject)
+ {
+ // this is in webcommon package:
+ return mailObject.sendConfirmationMail(username, email, confCode);
+ }
+
+ public String confirmRegistration(String username, String confirmationCode)
+ {
+ String reason = "";
+ if (confirmationCode == null || confirmationCode.equals("null")
+ || confirmationCode.equals(""))
+ {
+ reason = "Missing confirmation code";
+ return reason;
+ }
+
+ String msg = "User " + username + " attempts confirmation "
+ + "with code '" + confirmationCode + "'.";
+ User.LOGGER.fine(msg);
+
+ reason = confirmIfCorrectCode(username, confirmationCode);
+ return reason;
+ }
+
+ private String confirmIfCorrectCode(String username,
+ String tryConfirmationCode)
+ {
+ User u = pendingRegistrations.get(username);
+ if (u == null)
+ {
+ return "No confirmation pending for this username";
+ }
+
+ if (!u.getLastConfirmationCode().equals(tryConfirmationCode))
+ {
+ return User.WRONG_CONFCODE;
+ }
+
+ User.LOGGER.info("Registration confirmed for user '" + username
+ + "', email '" + u.getEmail() + "'.");
+
+ pendingRegistrations.remove(username);
+ storeUser(u);
+ storeUsersToFile();
+
+ return null;
+ }
+
+ public String changeProperties(String username, String oldPW,
+ String newPW, String email, Boolean isAdmin)
+ {
+ String reason;
+
+ User u = findUserByName(username);
+ if (u == null)
+ {
+ reason = "User does not exist";
+ return reason;
+ }
+ else if ((reason = verifyLogin(username, oldPW)) != null)
+ {
+ return reason;
+ }
+ else
+ {
+ u.setProperties(newPW, email, isAdmin);
+ storeUsersToFile();
+ return null;
+ }
+ }
+
+ private void readUsersFromFile()
+ {
+ long maxId = 0;
+ try
+ {
+ BufferedReader users = new BufferedReader(new InputStreamReader(
+ new FileInputStream(usersFile)));
+
+ String line = null;
+ while ((line = users.readLine()) != null)
+ {
+ if (line.startsWith("#"))
+ {
+ // ignore comment line
+ }
+ else if (line.matches("\\s*"))
+ {
+ // ignore empty line
+ }
+ else
+ {
+ User u = User.makeUserFromUserLine(line);
+ if (u != null)
+ {
+ storeUser(u);
+ if (u.getId() > maxId)
+ {
+ maxId = u.getId();
+ }
+ }
+ }
+ }
+ this.highestExistingId = maxId;
+ users.close();
+ }
+ catch (FileNotFoundException e)
+ {
+ LOGGER.log(Level.SEVERE,
+ "Users file " + usersFile + " not found!", e);
+ System.exit(1);
+ }
+ catch (IOException e)
+ {
+ LOGGER.log(Level.SEVERE, "IOException while reading users file "
+ + usersFile + "!", e);
+ System.exit(1);
+ }
+ }
+
+ public void storeUsersToFile()
+ {
+ if (usersFile == null)
+ {
+ User.LOGGER.log(Level.SEVERE, "UsersFile name is null!");
+ System.exit(1);
+ }
+
+ // LOGGER.log(Level.FINE, "Storing users back to file " + filename);
+
+ PrintWriter out = null;
+ try
+ {
+ out = new PrintWriter(new FileOutputStream(usersFile));
+
+ Collection<User> users = new LinkedList<User>();
+ users.addAll(getAllUsers());
+
+ for (User user : users)
+ {
+ String line = user.makeLine();
+ out.println(line);
+ }
+ out.close();
+ }
+ catch (FileNotFoundException e)
+ {
+ User.LOGGER.log(Level.SEVERE, "Writing users file " + usersFile
+ + "failed: FileNotFoundException: ", e);
+ System.exit(1);
+ }
+ }
+
+ private void storeUser(User u)
+ {
+ String name = u.getName();
+ String nameAllLower = name.toLowerCase();
+ synchronized (userMap)
+ {
+ userMap.put(nameAllLower, u);
+ }
+ }
+
+ public void cleanup()
+ {
+ synchronized (userMap)
+ {
+ userMap.clear();
+ }
+ synchronized (loggedInUserMap)
+ {
+ loggedInUserMap.clear();
+ }
+ }
+
+}
Property changes on: trunk/Colossus/core/src/main/java/net/sf/colossus/webcommon/UserDB.java
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Modified: trunk/Colossus/core/src/main/java/net/sf/colossus/webserver/ChatChannel.java
===================================================================
--- trunk/Colossus/core/src/main/java/net/sf/colossus/webserver/ChatChannel.java 2015-04-09 16:14:41 UTC (rev 5374)
+++ trunk/Colossus/core/src/main/java/net/sf/colossus/webserver/ChatChannel.java 2015-04-09 16:48:13 UTC (rev 5375)
@@ -1,321 +1,321 @@
-package net.sf.colossus.webserver;
-
-
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
-import java.io.PrintWriter;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Date;
-import java.util.List;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-import net.sf.colossus.webcommon.ChatMessage;
-import net.sf.colossus.webcommon.FormatWhen;
-import net.sf.colossus.webcommon.IWebClient;
-import net.sf.colossus.webcommon.User;
-import net.sf.colossus.webcommon.UserDB;
-
-
-public class ChatChannel
-{
- private static final Logger LOGGER = Logger.getLogger(ChatChannel.class
- .getName());
-
- private final UserDB userDB;
- private final String chatId;
- private final ChatMsgStorage storage;
- private final PrintWriter chatLog;
- private final FormatWhen whenFormatter;
-
- private final static String doubledashes = "=========================";
-
- private final static String[] chatHelp = new String[] { "Chat help:", "",
- "/help, /h, /? (show help)", "/ping (notify a certain user)",
- "/contact (how to contact admin)",
- "/userinfo (shows what info server has about you)", "",
- "Use /help <keyword> for detailed help. E.g. /help ping how to use ping." };
-
- private final static String[] pingHelp = new String[] {
- "Using /ping:",
- "",
- "To notify another user (it will give some beeps, and display your given message"
- + "in a popup dialog),",
- "you can use the /ping command:",
- " /ping UserName Here comes the message",
- "If the user's name contains spaces, it must be within double quotes:",
- " /ping \"Lengthy User Name\" Here comes the message" };
-
- private final static String[] contactHelp = new String[] {
- "Using /contact:",
- "",
- "To contact the administrator of this server, send a mail to su...@pl... .",
- "We also encourage you to use the \"General\" forum, the bugs tracker or the feature",
- "request tracker on our project page on Sourceforge:",
- " http://sourceforge.net/projects/colossus/" };
-
- public ChatChannel(String id, WebServerOptions options, UserDB userDB)
- {
- this.userDB = userDB;
- this.chatId = id;
- this.storage = new ChatMsgStorage(this, options);
- this.chatLog = openLogForAppend(options);
- this.whenFormatter = new FormatWhen();
- }
-
- public String getChannelId()
- {
- return chatId;
- }
-
- public void dispose()
- {
- storage.dispose();
- }
-
- public void createWelcomeMessage()
- {
- long now = new Date().getTime();
- ChatMessage startMsg = new ChatMessage(this.chatId, now, "SYSTEM",
- "WebServer started. Welcome!!");
- synchronized(storage)
- {
- storage.storeMessage(startMsg);
- }
- }
-
- /** Send message of the day lines to one client. */
- public void deliverMessageOfTheDayToClient(String chatId,
- IWebClient client, List<String> lines)
- {
- sendLinesToClient(chatId, client, lines, false, "SYSTEM");
- }
-
- public void handleUnknownCommand(String msgAllLower, String chatId,
- IWebClient client)
- {
- String[] lines = new String[] {
- "Sorry, '" + msgAllLower + "' is not a recognized command.",
- "Use /help to get a list of valid commands." };
- sendLinesToClient(chatId, client, Arrays.asList(lines), true, "");
- }
-
- public void sendHelpToClient(String msgAllLower, String chatId,
- IWebClient client)
- {
- List<String> words = Arrays.asList(msgAllLower.split(" +"));
- if (words.size() == 1)
- {
- sendLinesToClient(chatId, client, Arrays.asList(chatHelp), true,
- "");
- }
- else
- {
- if (words.get(1).startsWith("/ping")
- || words.get(1).startsWith("ping"))
- {
- sendLinesToClient(chatId, client, Arrays.asList(pingHelp),
- true, "");
- }
- else if (words.get(1).startsWith("/contact")
- || words.get(1).startsWith("contact"))
- {
- showContactHelp(chatId, client);
- }
- else
- {
- String[] noSuchHelp = new String[] { "Sorry, no specific help available about '"
- + words.get(1) + "'." };
- sendLinesToClient(chatId, client, Arrays.asList(noSuchHelp),
- true, "");
- }
- }
- }
-
- /**
- * @param chatId Id of the chat
- * @param client WebClient connection who requested the contact help
- */
- public void showContactHelp(String chatId, IWebClient client)
- {
- sendLinesToClient(chatId, client, Arrays.asList(contactHelp),
- true, "");
- }
-
- /** Send an arraylist full of lines to one client. */
- public void sendLinesToClient(String chatId, IWebClient client,
- List<String> lines, boolean spacer, String sender)
- {
- long when = new Date().getTime();
- boolean isResent = false;
-
- if (spacer)
- {
- client.chatDeliver(chatId, when, sender, "", isResent);
- }
- for (String line : lines)
- {
- client.chatDeliver(chatId, when, sender, line, isResent);
- }
- if (spacer)
- {
- client.chatDeliver(chatId, when, sender, "", isResent);
- }
-
- }
-
- // handleShowInfo(sender, message, this);
- public void handleShowInfo(IWebClient client, User user)
- {
- List<String> lines = new ArrayList<String>();
- lines.add("Server has following information about you:");
- lines.add(" Name: " + user.getName());
- lines.add(" Email: " + user.getEmail());
- lines.add(" Registered: " + user.getCreated()
- + " [SERVER TIME, i.e. Central European time]");
- long secs = user.getOnlineTime();
- lines.add(" Online time: " + secs + " seconds ("
- + onlineTimeFromSeconds(secs) + ")");
- sendLinesToClient(chatId, client, lines, true, "SYSTEM");
- }
-
- @SuppressWarnings("boxing")
- private String onlineTimeFromSeconds(long totalsecs)
- {
- long total = totalsecs;
- long secs = total % 60;
- total -= secs;
- total /= 60;
- long mins = total % 60;
- total -= mins;
- total /= 60;
- long hours = total % 24;
- total -= hours;
- total /= 24;
- long days = total;
-
- String
- "%d days, %d hours, %d minutes, %d seconds", days, hours, mins,
- secs);
- return onlineTime;
- }
-
- // TODO is this perhaps obsolete nowadays?
- /** Send message of the day lines to one client. */
- public void deliverOldVersionWarning(String chatId, String userName,
- IWebClient client)
- {
- long when = new Date().getTime();
- String sender = "SYSTEM";
- boolean isResent = false;
-
- ArrayList<String> lines = new ArrayList<String>();
- lines.add("");
- lines
- .add("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@");
- lines.add("");
- lines.add(" Hello " + userName + ", please note:");
- lines
- .add(" You are using a Colossus version older than 0.10.3. See message above!");
- lines.add("");
- lines
- .add("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@");
- lines.add("");
-
- for (String line : lines)
- {
- client.chatDeliver(chatId, when, sender, line, isResent);
- }
- }
-
- public void createStoreAndDeliverMessage(String sender, String message)
- {
- long now = new Date().getTime();
- ChatMessage msg = new ChatMessage(this.chatId,
- now, sender, message);
- synchronized (storage)
- {
- storage.storeMessage(msg);
- }
- appendToChatlog(msg);
- deliverMessage(msg, userDB);
- }
-
- private void deliverMessage(ChatMessage msg, UserDB userDB)
- {
- Collection<User> users = userDB.getLoggedInUsers();
- for (User u : users)
- {
- IWebClient client = u.getWebserverClient();
- deliverMessageToClient(msg, client, false);
- }
- }
-
- private void deliverMessageToClient(ChatMessage msg, IWebClient client,
- boolean isResent)
- {
- client.chatDeliver(msg.getChatId(), msg.getWhen(), msg.getSender(),
- msg.getMessage(), isResent);
- }
-
- public void tellLastMessagesToOne(IWebClient client)
- {
- synchronized (storage)
- {
- for (ChatMessage msg : storage.getLastNChatMessages())
- {
- deliverMessageToClient(msg, client, true);
- }
- }
- long now = new Date().getTime();
- client.chatDeliver(chatId, now, null, null, true);
- }
-
- private PrintWriter openLogForAppend(WebServerOptions options)
- {
- String usersFileDirectory = options
- .getStringOption(WebServerConstants.optDataDirectory);
- if (usersFileDirectory == null)
- {
- LOGGER
- .severe("Data Directory (for chat messages log file) is null! Define it in cf file!");
- System.exit(1);
- }
- String filename = "ChatLog-" + getChannelId() + ".txt";
-
- PrintWriter chatLog = null;
- try
- {
- boolean append = true;
- chatLog = new PrintWriter(new FileOutputStream(new File(
- usersFileDirectory, filename), append));
- }
- catch (FileNotFoundException e)
- {
- LOGGER.log(Level.SEVERE, "Writing char messages file " + filename
- + "failed: FileNotFoundException: ", e);
- }
- return chatLog;
- }
-
- private void appendToChatlog(ChatMessage msg)
- {
- String sender = msg.getSender();
- String message = msg.getMessage();
- long when = msg.getWhen();
-
-
- String whenTime = whenFormatter.timeAsString(when);
- String dateChange = whenFormatter.hasDateChanged();
- if (dateChange != null)
- {
- chatLog.println(doubledashes + " " + dateChange + " "
- + doubledashes);
- }
- chatLog.println(whenTime + " " + sender + ": " + message);
- chatLog.flush();
- }
-}
+package net.sf.colossus.webserver;
+
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.PrintWriter;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Date;
+import java.util.List;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import net.sf.colossus.webcommon.ChatMessage;
+import net.sf.colossus.webcommon.FormatWhen;
+import net.sf.colossus.webcommon.IWebClient;
+import net.sf.colossus.webcommon.User;
+import net.sf.colossus.webcommon.UserDB;
+
+
+public class ChatChannel
+{
+ private static final Logger LOGGER = Logger.getLogger(ChatChannel.class
+ .getName());
+
+ private final UserDB userDB;
+ private final String chatId;
+ private final ChatMsgStorage storage;
+ private final PrintWriter chatLog;
+ private final FormatWhen whenFormatter;
+
+ private final static String doubledashes = "=========================";
+
+ private final static String[] chatHelp = new String[] { "Chat help:", "",
+ "/help, /h, /? (show help)", "/ping (notify a certain user)",
+ "/contact (how to contact admin)",
+ "/userinfo (shows what info server has about you)", "",
+ "Use /help <keyword> for detailed help. E.g. /help ping how to use ping." };
+
+ private final static String[] pingHelp = new String[] {
+ "Using /ping:",
+ "",
+ "To notify another user (it will give some beeps, and display your given message"
+ + "in a popup dialog),",
+ "you can use the /ping command:",
+ " /ping UserName Here comes the message",
+ "If the user's name contains spaces, it must be within double quotes:",
+ " /ping \"Lengthy User Name\" Here comes the message" };
+
+ private final static String[] contactHelp = new String[] {
+ "Using /contact:",
+ "",
+ "To contact the administrator of this server, send a mail to su...@pl... .",
+ "We also encourage you to use the \"General\" forum, the bugs tracker or the feature",
+ "request tracker on our project page on Sourceforge:",
+ " http://sourceforge.net/projects/colossus/" };
+
+ public ChatChannel(String id, WebServerOptions options, UserDB userDB)
+ {
+ this.userDB = userDB;
+ this.chatId = id;
+ this.storage = new ChatMsgStorage(this, options);
+ this.chatLog = openLogForAppend(options);
+ this.whenFormatter = new FormatWhen();
+ }
+
+ public String getChannelId()
+ {
+ return chatId;
+ }
+
+ public void dispose()
+ {
+ storage.dispose();
+ }
+
+ public void createWelcomeMessage()
+ {
+ long now = new Date().getTime();
+ ChatMessage startMsg = new ChatMessage(this.chatId, now, "SYSTEM",
+ "WebServer started. Welcome!!");
+ synchronized(storage)
+ {
+ storage.storeMessage(startMsg);
+ }
+ }
+
+ /** Send message of the day lines to one client. */
+ public void deliverMessageOfTheDayToClient(String chatId,
+ IWebClient client, List<String> lines)
+ {
+ sendLinesToClient(chatId, client, lines, false, "SYSTEM");
+ }
+
+ public void handleUnknownCommand(String msgAllLower, String chatId,
+ IWebClient client)
+ {
+ String[] lines = new String[] {
+ "Sorry, '" + msgAllLower + "' is not a recognized command.",
+ "Use /help to get a list of valid commands." };
+ sendLinesToClient(chatId, client, Arrays.asList(lines), true, "");
+ }
+
+ public void sendHelpToClient(String msgAllLower, String chatId,
+ IWebClient client)
+ {
+ List<String> words = Arrays.asList(msgAllLower.split(" +"));
+ if (words.size() == 1)
+ {
+ sendLinesToClient(chatId, client, Arrays.asList(chatHelp), true,
+ "");
+ }
+ else
+ {
+ if (words.get(1).startsWith("/ping")
+ || words.get(1).startsWith("ping"))
+ {
+ sendLinesToClient(chatId, client, Arrays.asList(pingHelp),
+ true, "");
+ }
+ else if (words.get(1).startsWith("/contact")
+ || words.get(1).startsWith("contact"))
+ {
+ showContactHelp(chatId, client);
+ }
+ else
+ {
+ String[] noSuchHelp = new String[] { "Sorry, no specific help available about '"
+ + words.get(1) + "'." };
+ sendLinesToClient(chatId, client, Arrays.asList(noSuchHelp),
+ true, "");
+ }
+ }
+ }
+
+ /**
+ * @param chatId Id of the chat
+ * @param client WebClient connection who requested the contact help
+ */
+ public void showContactHelp(String chatId, IWebClient client)
+ {
+ sendLinesToClient(chatId, client, Arrays.asList(contactHelp),
+ true, "");
+ }
+
+ /** Send an arraylist full of lines to one client. */
+ public void sendLinesToClient(String chatId, IWebClient client,
+ List<String> lines, boolean spacer, String sender)
+ {
+ long when = new Date().getTime();
+ boolean isResent = false;
+
+ if (spacer)
+ {
+ client.chatDeliver(chatId, when, sender, "", isResent);
+ }
+ for (String line : lines)
+ {
+ client.chatDeliver(chatId, when, sender, line, isResent);
+ }
+ if (spacer)
+ {
+ client.chatDeliver(chatId, when, sender, "", isResent);
+ }
+
+ }
+
+ // handleShowInfo(sender, message, this);
+ public void handleShowInfo(IWebClient client, User user)
+ {
+ List<String> lines = new ArrayList<String>();
+ lines.add("Server has following information about you:");
+ lines.add(" Name: " + user.getName());
+ lines.add(" Email: " + user.getEmail());
+ lines.add(" Registered: " + user.getCreated()
+ + " [SERVER TIME, i.e. Central European time]");
+ long secs = user.getOnlineTime();
+ lines.add(" Online time: " + secs + " seconds ("
+ + onlineTimeFromSeconds(secs) + ")");
+ sendLinesToClient(chatId, client, lines, true, "SYSTEM");
+ }
+
+ @SuppressWarnings("boxing")
+ private String onlineTimeFromSeconds(long totalsecs)
+ {
+ long total = totalsecs;
+ long secs = total % 60;
+ total -= secs;
+ total /= 60;
+ long mins = total % 60;
+ total -= mins;
+ total /= 60;
+ long hours = total % 24;
+ total -= hours;
+ total /= 24;
+ long days = total;
+
+ String
+ "%d days, %d hours, %d minutes, %d seconds", days, hours, mins,
+ secs);
+ return onlineTime;
+ }
+
+ // TODO is this perhaps obsolete nowadays?
+ /** Send message of the day lines to one client. */
+ public void deliverOldVersionWarning(String chatId, String userName,
+ IWebClient client)
+ {
+ long when = new Date().getTime();
+ String sender = "SYSTEM";
+ boolean isResent = false;
+
+ ArrayList<String> lines = new ArrayList<String>();
+ lines.add("");
+ lines
+ .add("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@");
+ lines.add("");
+ lines.add(" Hello " + userName + ", please note:");
+ lines
+ .add(" You are using a Colossus version older than 0.10.3. See message above!");
+ lines.add("");
+ lines
+ .add("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@");
+ lines.add("");
+
+ for (String line : lines)
+ {
+ client.chatDeliver(chatId, when, sender, line, isResent);
+ }
+ }
+
+ public void createStoreAndDeliverMessage(String sender, String message)
+ {
+ long now = new Date().getTime();
+ ChatMessage msg = new ChatMessage(this.chatId,
+ now, sender, message);
+ synchronized (storage)
+ {
+ storage.storeMessage(msg);
+ }
+ appendToChatlog(msg);
+ deliverMessage(msg, userDB);
+ }
+
+ private void deliverMessage(ChatMessage msg, UserDB userDB)
+ {
+ Collection<User> users = userDB.getLoggedInUsers();
+ for (User u : users)
+ {
+ IWebClient client = u.getWebserverClient();
+ deliverMessageToClient(msg, client, false);
+ }
+ }
+
+ private void deliverMessageToClient(ChatMessage msg, IWebClient client,
+ boolean isResent)
+ {
+ client.chatDeliver(msg.getChatId(), msg.getWhen(), msg.getSender(),
+ msg.getMessage(), isResent);
+ }
+
+ public void tellLastMessagesToOne(IWebClient client)
+ {
+ synchronized (storage)
+ {
+ for (ChatMessage msg : storage.getLastNChatMessages())
+ {
+ deliverMessageToClient(msg, client, true);
+ }
+ }
+ long now = new Date().getTime();
+ client.chatDeliver(chatId, now, null, null, true);
+ }
+
+ private PrintWriter openLogForAppend(WebServerOptions options)
+ {
+ String usersFileDirectory = options
+ .getStringOption(WebServerConstants.optDataDirectory);
+ if (usersFileDirectory == null)
+ {
+ LOGGER
+ .severe("Data Directory (for chat messages log file) is null! Define it in cf file!");
+ System.exit(1);
+ }
+ String filename = "ChatLog-" + getChannelId() + ".txt";
+
+ PrintWriter chatLog = null;
+ try
+ {
+ boolean append = true;
+ chatLog = new PrintWriter(new FileOutputStream(new File(
+ usersFileDirectory, filename), append));
+ }
+ catch (FileNotFoundException e)
+ {
+ LOGGER.log(Level.SEVERE, "Writing char messages file " + filename
+ + "failed: FileNotFoundException: ", e);
+ }
+ return chatLog;
+ }
+
+ private void appendToChatlog(ChatMessage msg)
+ {
+ String sender = msg.getSender();
+ String message = msg.getMessage();
+ long when = msg.getWhen();
+
+
+ String whenTime = whenFormatter.timeAsString(when);
+ String dateChange = whenFormatter.hasDateChanged();
+ if (dateChange != null)
+ {
+ chatLog.println(doubledashes + " " + dateChange + " "
+ + doubledashes);
+ }
+ chatLog.println(whenTime + " " + sender + ": " + message);
+ chatLog.flush();
+ }
+}
Property changes on: trunk/Colossus/core/src/main/java/net/sf/colossus/webserver/ChatChannel.java
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Modified: trunk/Colossus/core/src/main/java/net/sf/colossus/webserver/ChatMsgStorage.java
===================================================================
--- trunk/Colossus/core/src/main/java/net/sf/colossus/webserver/ChatMsgStorage.java 2015-04-09 16:14:41 UTC (rev 5374)
+++ trunk/Colossus/core/src/main/java/net/sf/colossus/webserver/ChatMsgStorage.java 2015-04-09 16:48:13 UTC (rev 5375)
@@ -1,187 +1,187 @@
-package net.sf.colossus.webserver;
-
-
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.io.OutputStreamWriter;
-import java.io.PrintWriter;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-import net.sf.colossus.webcommon.ChatMessage;
-
-public class ChatMsgStorage
-{
- private static final Logger LOGGER = Logger.getLogger(ChatMsgStorage.class
- .getName());
-
- private final WebServerOptions options;
- private final ChatChannel channel;
- private final List<ChatMessage> lastNChatMessages;
-
- /** Just by coincidence, we use the same separator as for the network
- * transmissions, so then there is no risk of "can't be unambiguely
- * encoded".
- */
- private final static String SEP = " ~ ";
-
- public ChatMsgStorage(ChatChannel theChannel, WebServerOptions options)
- {
- this.options = options;
- this.channel = theChannel;
- LOGGER.fine("Chat Message Storage instantiated for channel "
- + getChannel().getChannelId());
- this.lastNChatMessages = new ArrayList<ChatMessage>();
- restoreMessages();
- }
-
- public void dispose()
- {
- storeMessages();
- LOGGER.fine("disposing - stored " + lastNChatMessages.size()
- + " messages");
- }
-
- public ChatChannel getChannel()
- {
- return channel;
- }
-
- public List<ChatMessage> getLastNChatMessages()
- {
- return Collections.unmodifiableList(lastNChatMessages);
- }
-
- void storeMessage(ChatMessage msg)
- {
- List<ChatMessage> list = lastNChatMessages;
- synchronized (list)
- {
- list.add(msg);
- if (list.size() > WebServerConstants.keepLastNMessages)
- {
- // if longer than max, remove oldest one
- list.remove(0);
- }
- }
- }
-
- /** Store all messages to a permanent storage (Disk file or DB) from where
- * they can be read back when server is restarting
- */
- ...
[truncated message content] |