Timing out users out of ChatRoom.

This commit is contained in:
marcins78@gmail.com
2011-09-14 20:45:44 +00:00
parent a17b887888
commit 311ba79f82
5 changed files with 28 additions and 6 deletions

View File

@@ -3,11 +3,13 @@ package com.gempukku.lotro;
import com.gempukku.lotro.chat.ChatMessage;
import com.gempukku.lotro.chat.ChatRoomListener;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;
public class GatheringChatRoomListener implements ChatRoomListener {
private List<ChatMessage> _messages = new LinkedList<ChatMessage>();
private Date _lastConsumed = new Date();
@Override
public void messageReceived(ChatMessage message) {
@@ -17,6 +19,11 @@ public class GatheringChatRoomListener implements ChatRoomListener {
public List<ChatMessage> consumeMessages() {
List<ChatMessage> messages = _messages;
_messages = new LinkedList<ChatMessage>();
_lastConsumed = new Date();
return messages;
}
public Date getLastConsumed() {
return _lastConsumed;
}
}

View File

@@ -13,7 +13,7 @@ import java.util.List;
public class GatheringParticipantCommunicationChannel implements GameStateListener {
private List<GameEvent> _events = new LinkedList<GameEvent>();
private String _self;
private Date _lastConsumed;
private Date _lastConsumed = new Date();
public GatheringParticipantCommunicationChannel(String self) {
_self = self;

View File

@@ -11,6 +11,8 @@ public class ChatRoomMediator {
private Map<String, GatheringChatRoomListener> _listeners = new HashMap<String, GatheringChatRoomListener>();
private final int _channelInactivityTimeoutPeriod = 1000 * 10; // 10 seconds
public synchronized List<ChatMessage> joinUser(String playerId) {
GatheringChatRoomListener value = new GatheringChatRoomListener();
_listeners.put(playerId, value);
@@ -33,4 +35,16 @@ public class ChatRoomMediator {
public synchronized void sendMessage(String playerId, String message) {
_chatRoom.postMessage(playerId, message);
}
public synchronized void cleanup() {
long currentTime = System.currentTimeMillis();
for (Map.Entry<String, GatheringChatRoomListener> playerListener : _listeners.entrySet()) {
String playerId = playerListener.getKey();
GatheringChatRoomListener listener = playerListener.getValue();
if (currentTime > listener.getLastConsumed().getTime() + _channelInactivityTimeoutPeriod) {
_chatRoom.partChatRoom(playerId);
_listeners.remove(playerId);
}
}
}
}

View File

@@ -37,7 +37,8 @@ public class ChatServer {
}
private void cleanup() {
// TODO cleanup server
for (ChatRoomMediator chatRoomMediator : _chatRooms.values())
chatRoomMediator.cleanup();
}
private class CleaningTask implements Runnable {
@@ -47,7 +48,7 @@ public class ChatServer {
while (_running) {
cleanup();
try {
Thread.sleep(100);
Thread.sleep(1000);
} catch (InterruptedException e) {
// Ignore
}

View File

@@ -1,11 +1,10 @@
TO DO:
17. Timeout users from ChatServer the same way they are timed out of GameServer.
9. Add checkbox option to auto-pass if there is no actions to be played.
8. Add checkbox option to auto-accept choices on the client, also allow to cancel selection to reset to none-selected
and go with different selection.
9. Add checkbox option to auto-pass if there is no actions to be played.
15. Add join game screen, where players can choose to play and get paired automatically when a pair becomes available.
16. Add an option to view an ongoing game.
18. Add display of site where player is on adventure path.
16. Add an option to view an ongoing game.
13. Add dead/discard pile displays.
14. Add hand/deck card count displays.
@@ -28,3 +27,4 @@ with Filters.sameCard(...) filter.
11. Merge Shadow and FP support area on the UI and extend the Shadow and FP characters window.
12. Add rule of 4.
6. Change how the assignments and skirmish are displayed in the user interface, to avoid using Dialogs.
17. Timeout users from ChatServer the same way they are timed out of GameServer.