Only track UserMessage since we only care to log things other players
said; prune any big history when a new message is noted. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@2657 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
//
|
//
|
||||||
// $Id: SpeakProvider.java,v 1.9 2003/06/14 00:59:24 mdb Exp $
|
// $Id: SpeakProvider.java,v 1.10 2003/06/14 01:18:27 mdb Exp $
|
||||||
|
|
||||||
package com.threerings.crowd.chat.server;
|
package com.threerings.crowd.chat.server;
|
||||||
|
|
||||||
@@ -209,10 +209,10 @@ public class SpeakProvider
|
|||||||
// post the message to the relevant object
|
// post the message to the relevant object
|
||||||
speakObj.postMessage(CHAT_NOTIFICATION, new Object[] { msg });
|
speakObj.postMessage(CHAT_NOTIFICATION, new Object[] { msg });
|
||||||
|
|
||||||
// determine to whom this message will be delivered and register
|
// if this is a user message; add it to the heard history of all
|
||||||
// the message with all parties
|
// users that can "hear" it
|
||||||
if (speakObj instanceof SpeakObject) {
|
if (msg instanceof UserMessage && speakObj instanceof SpeakObject) {
|
||||||
_messageMapper.message = msg;
|
_messageMapper.message = (UserMessage)msg;
|
||||||
((SpeakObject)speakObj).applyToListeners(_messageMapper);
|
((SpeakObject)speakObj).applyToListeners(_messageMapper);
|
||||||
_messageMapper.message = null;
|
_messageMapper.message = null;
|
||||||
} else {
|
} else {
|
||||||
@@ -246,12 +246,23 @@ public class SpeakProvider
|
|||||||
* message. If {@link ChatMessage#timestamp} is not already filled in,
|
* message. If {@link ChatMessage#timestamp} is not already filled in,
|
||||||
* it will be.
|
* it will be.
|
||||||
*/
|
*/
|
||||||
protected static void noteMessage (String username, ChatMessage msg)
|
protected static void noteMessage (String username, UserMessage msg)
|
||||||
{
|
{
|
||||||
|
// fill in the message's time stamp if necessary
|
||||||
if (msg.timestamp == 0L) {
|
if (msg.timestamp == 0L) {
|
||||||
msg.timestamp = System.currentTimeMillis();
|
msg.timestamp = System.currentTimeMillis();
|
||||||
}
|
}
|
||||||
getHistoryList(username).add(msg);
|
|
||||||
|
// add the message to this user's chat history
|
||||||
|
ArrayList history = getHistoryList(username);
|
||||||
|
history.add(msg);
|
||||||
|
|
||||||
|
// if the history is big enough, potentially prune it (we always
|
||||||
|
// prune when asked for the history, so this is just to balance
|
||||||
|
// memory usage with CPU expense)
|
||||||
|
if (history.size() > 15) {
|
||||||
|
pruneHistory(msg.timestamp, history);
|
||||||
|
}
|
||||||
// Log.info("Noted that " + username + " heard " + msg + ".");
|
// Log.info("Noted that " + username + " heard " + msg + ".");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -277,6 +288,8 @@ public class SpeakProvider
|
|||||||
if (now - msg.timestamp > HISTORY_EXPIRATION) {
|
if (now - msg.timestamp > HISTORY_EXPIRATION) {
|
||||||
Log.info("Expiring from history " + msg + ".");
|
Log.info("Expiring from history " + msg + ".");
|
||||||
history.remove(ii);
|
history.remove(ii);
|
||||||
|
} else {
|
||||||
|
break; // stop when we get to the first valid message
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -284,7 +297,7 @@ public class SpeakProvider
|
|||||||
/** Used to note the recipients of a chat message. */
|
/** Used to note the recipients of a chat message. */
|
||||||
protected static class MessageMapper implements SpeakObject.ListenerOp
|
protected static class MessageMapper implements SpeakObject.ListenerOp
|
||||||
{
|
{
|
||||||
public ChatMessage message;
|
public UserMessage message;
|
||||||
|
|
||||||
public void apply (int bodyOid) {
|
public void apply (int bodyOid) {
|
||||||
DObject dobj = CrowdServer.omgr.getObject(bodyOid);
|
DObject dobj = CrowdServer.omgr.getObject(bodyOid);
|
||||||
|
|||||||
Reference in New Issue
Block a user