Making chat smarter, trying to resume communication by itself.
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
package com.gempukku.lotro.common;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class ApplicationRoot {
|
||||
private static File _root;
|
||||
|
||||
public static void setRoot(File file) {
|
||||
_root = file;
|
||||
}
|
||||
|
||||
public static File getRoot() {
|
||||
return _root;
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.gempukku.lotro.logic.modifiers;
|
||||
|
||||
import com.gempukku.lotro.common.ApplicationRoot;
|
||||
import com.gempukku.lotro.game.PhysicalCard;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
@@ -18,7 +19,7 @@ public class LoggingThreadLocal {
|
||||
private static synchronized void initializeOutputStream() {
|
||||
if (_fos == null) {
|
||||
try {
|
||||
_fos = new FileOutputStream(new File("/etc/gemp-lotr/longActions.txt"));
|
||||
_fos = new FileOutputStream(new File(ApplicationRoot.getRoot(), "longActions.txt"));
|
||||
} catch (IOException exp) {
|
||||
throw new RuntimeException(exp);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.gempukku.lotro.game;
|
||||
|
||||
import com.gempukku.lotro.common.ApplicationRoot;
|
||||
import com.gempukku.lotro.db.GameHistoryDAO;
|
||||
import com.gempukku.lotro.game.state.EventSerializer;
|
||||
import com.gempukku.lotro.game.state.GameEvent;
|
||||
@@ -71,7 +72,7 @@ public class GameRecorder {
|
||||
}
|
||||
|
||||
private File getRecordingFile(String playerId, String gameId) {
|
||||
File gameReplayFolder = new File("/etc/gemp-lotr/replay");
|
||||
File gameReplayFolder = new File(ApplicationRoot.getRoot(), "replay");
|
||||
File playerReplayFolder = new File(gameReplayFolder, playerId);
|
||||
return new File(playerReplayFolder, gameId + ".xml");
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import com.gempukku.lotro.cards.packs.PackBox;
|
||||
import com.gempukku.lotro.chat.ChatMessage;
|
||||
import com.gempukku.lotro.chat.ChatRoomMediator;
|
||||
import com.gempukku.lotro.chat.ChatServer;
|
||||
import com.gempukku.lotro.common.ApplicationRoot;
|
||||
import com.gempukku.lotro.common.Side;
|
||||
import com.gempukku.lotro.db.CollectionDAO;
|
||||
import com.gempukku.lotro.db.DbAccess;
|
||||
@@ -39,6 +40,7 @@ import javax.ws.rs.core.StreamingOutput;
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
@@ -61,6 +63,11 @@ public class ServerResource {
|
||||
private PackBox _packBox;
|
||||
|
||||
public ServerResource() {
|
||||
if (!_test)
|
||||
ApplicationRoot.setRoot(new File("/etc/gemp-lotr"));
|
||||
else
|
||||
ApplicationRoot.setRoot(new File("i:\\gemp-lotr"));
|
||||
|
||||
_logger.debug("starting resource");
|
||||
|
||||
try {
|
||||
@@ -693,7 +700,7 @@ public class ServerResource {
|
||||
public Document postMessage(
|
||||
@PathParam("room") String room,
|
||||
@FormParam("participantId") String participantId,
|
||||
@FormParam("message") String message,
|
||||
@FormParam("message") List<String> messages,
|
||||
@Context HttpServletRequest request) throws ParserConfigurationException {
|
||||
if (!_test)
|
||||
participantId = getLoggedUser(request);
|
||||
@@ -702,8 +709,12 @@ public class ServerResource {
|
||||
if (chatRoom == null)
|
||||
sendError(Response.Status.NOT_FOUND);
|
||||
|
||||
if (message != null && message.trim().length() > 0)
|
||||
chatRoom.sendMessage(participantId, StringEscapeUtils.escapeHtml(message));
|
||||
if (messages != null) {
|
||||
for (String message : messages) {
|
||||
if (message != null && message.trim().length() > 0)
|
||||
chatRoom.sendMessage(participantId, StringEscapeUtils.escapeHtml(message));
|
||||
}
|
||||
}
|
||||
|
||||
List<ChatMessage> chatMessages = chatRoom.getPendingMessages(participantId);
|
||||
Set<String> usersInRoom = chatRoom.getUsersInRoom();
|
||||
|
||||
@@ -8,25 +8,38 @@ var ChatBoxUI = Class.extend({
|
||||
showTimestamps: false,
|
||||
talkBoxHeight: 25,
|
||||
chatUpdateInterval: 1000,
|
||||
unsentMessages: null,
|
||||
processingMessages: null,
|
||||
|
||||
init: function(name, div, url, showList) {
|
||||
var that = this;
|
||||
this.name = name;
|
||||
this.div = div;
|
||||
this.unsentMessages = new Array();
|
||||
this.communication = new GempLotrCommunication(url, function(xhr, ajaxOptions, thrownError) {
|
||||
if (thrownError != "abort") {
|
||||
if (xhr != null) {
|
||||
if (xhr.status == 401) {
|
||||
that.appendMessage("Chat problem - You're not logged in, go to the <a href='index.html'>main page</a> to log in", "warningMessage");
|
||||
that.appendMessage("You're not logged in, go to the <a href='index.html'>main page</a> to log in", "warningMessage");
|
||||
return;
|
||||
} else if (xhr.status == 404) {
|
||||
that.appendMessage("Chat room was closed, please go to the Game Hall.", "warningMessage");
|
||||
return;
|
||||
} else if (xhr.status == 503) {
|
||||
that.appendMessage("Server is being restarted, please wait for the restart to finish and try again later.", "warningMessage");
|
||||
return;
|
||||
} else {
|
||||
that.appendMessage("Chat had a problem communicating with the server (" + xhr.status + "), no new messages will be displayed, but your messages still might get sent.", "warningMessage");
|
||||
that.appendMessage("Reload the browser page (press F5) to resume the chat.", "warningMessage");
|
||||
that.appendMessage("Chat had a problem communicating with the server (error " + xhr.statis + "). Retrying...", "systemMessage");
|
||||
setTimeout(function() {
|
||||
that.updateChatMessages();
|
||||
}, that.chatUpdateInterval);
|
||||
return;
|
||||
}
|
||||
}
|
||||
that.appendMessage("Chat had a problem communicating with the server, no new messages will be displayed, but your messages still might get sent.", "warningMessage");
|
||||
that.appendMessage("Reload the browser page (press F5) to resume the chat.", "warningMessage");
|
||||
that.appendMessage("Chat had an unknown problem communicating with the server. Retrying...", "systemMessage");
|
||||
setTimeout(function() {
|
||||
that.updateChatMessages();
|
||||
}, that.chatUpdateInterval);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -103,6 +116,7 @@ var ChatBoxUI = Class.extend({
|
||||
processMessages: function(xml, processAgain) {
|
||||
var root = xml.documentElement;
|
||||
if (root.tagName == 'chat') {
|
||||
this.processingMessages = null;
|
||||
var messages = root.getElementsByTagName("message");
|
||||
for (var i = 0; i < messages.length; i++) {
|
||||
var message = messages[i];
|
||||
@@ -143,16 +157,26 @@ var ChatBoxUI = Class.extend({
|
||||
updateChatMessages: function(xml) {
|
||||
var that = this;
|
||||
|
||||
this.communication.updateChat(this.name, function(xml) {
|
||||
that.processMessages(xml, true);
|
||||
});
|
||||
if (this.processingMessages != null) {
|
||||
this.communication.sendChatMessage(this.name, this.processingMessages, function(xml) {
|
||||
that.processMessages(xml, true);
|
||||
});
|
||||
} else if (this.unsentMessages.length > 0) {
|
||||
this.communication.sendChatMessage(this.name, this.unsentMessages, function(xml) {
|
||||
that.processMessages(xml, true);
|
||||
});
|
||||
this.processingMessages = this.unsentMessages;
|
||||
this.unsentMessages = new Array();
|
||||
} else {
|
||||
this.communication.updateChat(this.name, function(xml) {
|
||||
that.processMessages(xml, true);
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
sendMessage: function(message) {
|
||||
var that = this;
|
||||
|
||||
this.communication.sendChatMessage(this.name, message, function(xml) {
|
||||
that.processMessages(xml, false);
|
||||
});
|
||||
this.unsentMessages.push(message);
|
||||
}
|
||||
});
|
||||
@@ -220,15 +220,16 @@ var GempLotrCommunication = Class.extend({
|
||||
dataType: "xml"
|
||||
});
|
||||
},
|
||||
sendChatMessage: function(room, message, callback) {
|
||||
sendChatMessage: function(room, messages, callback) {
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: this.url + "/chat/" + room,
|
||||
cache: false,
|
||||
data: {
|
||||
participantId: getUrlParam("participantId"),
|
||||
message: message},
|
||||
message: messages},
|
||||
success: callback,
|
||||
traditional: true,
|
||||
error: this.failure,
|
||||
dataType: "xml"
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user