Commit e41ca8ff by hxw

生成是删除在内存中的存档

parent beff5956
#
# qa问答地址 ## qa问答地址
qa_url=http://192.168.1.78:59000/game #qa_url=http://192.168.1.78:59000/game
#
# 中控url ## 中控url
cc_url=http://localhost:8070/api/update/data #cc_url=http://localhost:8070/api/update/data
#
# condition后台url ## condition后台url
condition_backend_url=http://192.168.1.82:6636/api #condition_backend_url=http://192.168.1.82:6636/api
#
# action生成指定的后台地址 ## action生成指定的后台地址
service_url=http://192.168.1.178:8081/bot/dialog #service_url=http://192.168.1.178:8081/bot/dialog
#qa_url=http://localhost:59100/game qa_url=http://localhost:59100/game
#cc_url=http://localhost:8070/api/update/data cc_url=http://localhost:8070/api/update/data
#condition_backend_url=http://localhost:6636/api condition_backend_url=http://localhost:6636/api
#service_url=http://localhost:8081/bot/dialog service_url=http://localhost:8081/bot/dialog
chatcache_time_out=300000 chatcache_time_out=300000
...@@ -183,8 +183,8 @@ backup_error=备份失败 ...@@ -183,8 +183,8 @@ backup_error=备份失败
# --------------------------话术---------------------------------------- # --------------------------话术----------------------------------------
script_npc_intro=[人名]:[属性值] script_npc_intro=[属性值]
script_item_intro=[物品名]:[属性值] script_item_intro=[属性值]
script_npc_in_place=[地点名]上有[人物列表] script_npc_in_place=[地点名]上有[人物列表]
script_item_in_place=[地点名]上有[物品列表] script_item_in_place=[地点名]上有[物品列表]
script_all_in_place=[地点名]上有[人物物品列表] script_all_in_place=[地点名]上有[人物物品列表]
...@@ -227,6 +227,7 @@ public class ChatCacheController { ...@@ -227,6 +227,7 @@ public class ChatCacheController {
//ChatCache chatCache = keyCacheMap.get(curInfoPoint.get("userKey")); //ChatCache chatCache = keyCacheMap.get(curInfoPoint.get("userKey"));
//chatCache.setInfoPoint(historyInfoPoint); //chatCache.setInfoPoint(historyInfoPoint);
//chatCache.setGameEnv(gameEnv); //chatCache.setGameEnv(gameEnv);
System.out.println(chatCache.getUserKey());
context.setAttribute("chatCache", keyCacheMap); context.setAttribute("chatCache", keyCacheMap);
} }
...@@ -241,11 +242,16 @@ public class ChatCacheController { ...@@ -241,11 +242,16 @@ public class ChatCacheController {
SqlHelper helper; SqlHelper helper;
Map<String, String> infoPoints = new HashMap<String, String>(); Map<String, String> infoPoints = new HashMap<String, String>();
try { try {
helper = new SqlHelper(); helper = new SqlHelper();
if (context.getAttribute("chatCache") != null) { if (context.getAttribute("chatCache") != null) {
chatCacheMap = (HashMap<String, ChatCache>)context.getAttribute("chatCache"); chatCacheMap = (HashMap<String, ChatCache>)context.getAttribute("chatCache");
System.out.println("context:" + userKey);
if (chatCacheMap.containsKey(userKey)) { if (chatCacheMap.containsKey(userKey)) {
System.out.println("contain:" + userKey);
chatCache = chatCacheMap.get(userKey); chatCache = chatCacheMap.get(userKey);
...@@ -254,6 +260,7 @@ public class ChatCacheController { ...@@ -254,6 +260,7 @@ public class ChatCacheController {
findFlag = true; findFlag = true;
saveChatCache(chatCache, helper); saveChatCache(chatCache, helper);
chatCacheMap.remove(userKey); chatCacheMap.remove(userKey);
System.out.println("save:" + userKey);
} }
...@@ -263,7 +270,7 @@ public class ChatCacheController { ...@@ -263,7 +270,7 @@ public class ChatCacheController {
if (!findFlag) { if (!findFlag) {
System.out.println("sql:" + userKey);
archiveInfo = helper.queryUserLastGameArchive(userKey); archiveInfo = helper.queryUserLastGameArchive(userKey);
helper.destroy(); helper.destroy();
...@@ -275,14 +282,38 @@ public class ChatCacheController { ...@@ -275,14 +282,38 @@ public class ChatCacheController {
e.printStackTrace(); e.printStackTrace();
findFlag = false; findFlag = false;
} }
System.out.println("finalFlag" + findFlag);
return findFlag; return findFlag;
} }
public static Boolean deleteChatCache(SqlHelper helper, String botAccount){ public static Boolean deleteChatCache(SqlHelper helper, String botAccount, ServletContext context){
Map<String, ChatCache> chatCacheMap = null;
String userKey = "";
Boolean sqlDeleteFlag = helper.deleteArchiveByBotAccount(botAccount); Boolean sqlDeleteFlag = helper.deleteArchiveByBotAccount(botAccount);
if (context.getAttribute("chatCache") != null) {
chatCacheMap = (HashMap<String, ChatCache>) context.getAttribute("chatCache");
Iterator<String> iter = chatCacheMap.keySet().iterator();
while (iter.hasNext()) {
userKey = iter.next();
if (userKey.endsWith(botAccount)) {
iter.remove();
}
}
}
Boolean fileDeleteFlag = FileFinder.deleteGameArchive(CHAT_CACHE_DIR, botAccount); Boolean fileDeleteFlag = FileFinder.deleteGameArchive(CHAT_CACHE_DIR, botAccount);
return sqlDeleteFlag && fileDeleteFlag; return sqlDeleteFlag && fileDeleteFlag;
......
...@@ -26,6 +26,7 @@ public class FindCacheServlet extends HttpServlet { ...@@ -26,6 +26,7 @@ public class FindCacheServlet extends HttpServlet {
try { try {
exist = ChatCacheController.findChatCache(userKey, context); exist = ChatCacheController.findChatCache(userKey, context);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
exist = false; exist = false;
......
...@@ -25,9 +25,7 @@ import java.time.LocalDateTime; ...@@ -25,9 +25,7 @@ import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
import java.util.*; import java.util.*;
import static com.qiwu.chatbotbackend.Config.Config.GAME_CONDITION_CATEGORY; import static com.qiwu.chatbotbackend.Config.Config.*;
import static com.qiwu.chatbotbackend.Config.Config.GAME_WELCOME_TEXT;
import static com.qiwu.chatbotbackend.Config.Config.KEYWORD_DIR;
@WebServlet(name = "GameDesignServlet", urlPatterns = {"/gameDesign"}) @WebServlet(name = "GameDesignServlet", urlPatterns = {"/gameDesign"})
...@@ -107,7 +105,7 @@ public class GameDesignServlet extends HttpServlet { ...@@ -107,7 +105,7 @@ public class GameDesignServlet extends HttpServlet {
//清空之前生成的配置条目 //清空之前生成的配置条目
flag = botInit(botId, botAccount, userinfo, helper); flag = botInit(botId, botAccount, userinfo, helper, context);
StringBuffer mergedConfigText = new StringBuffer(); StringBuffer mergedConfigText = new StringBuffer();
...@@ -257,14 +255,14 @@ public class GameDesignServlet extends HttpServlet { ...@@ -257,14 +255,14 @@ public class GameDesignServlet extends HttpServlet {
out.flush(); out.flush();
} }
public boolean botInit(int botId, String botAccount, UserInfo userInfo, SqlHelper helper) throws SQLException, IOException { public boolean botInit(int botId, String botAccount, UserInfo userInfo, SqlHelper helper, ServletContext context) throws SQLException, IOException {
boolean deleteConfigFlag = helper.deleteConfigByBotId(botId); boolean deleteConfigFlag = helper.deleteConfigByBotId(botId);
boolean deleteVariableFlag = helper.deleteVariableByBotId(botId); boolean deleteVariableFlag = helper.deleteVariableByBotId(botId);
boolean deleteCategoryFlag = helper.deleteCategoryByBotId(botId); boolean deleteCategoryFlag = helper.deleteCategoryByBotId(botId);
boolean insertCategoryFlag = helper.batchInsertCategoryByBotId(botId, categoryMap); boolean insertCategoryFlag = helper.batchInsertCategoryByBotId(botId, categoryMap);
boolean deteteConditionFlag = helper.deleteConditionByBotId(botId); boolean deteteConditionFlag = helper.deleteConditionByBotId(botId);
boolean deleteArchiveFlag = ChatCacheController.deleteChatCache(helper, botAccount); boolean deleteArchiveFlag = ChatCacheController.deleteChatCache(helper, botAccount, context);
return deleteConfigFlag && deleteVariableFlag; return deleteConfigFlag && deleteVariableFlag;
......
...@@ -36,7 +36,13 @@ public class GameBotUtil extends BasicBotUtil{ ...@@ -36,7 +36,13 @@ public class GameBotUtil extends BasicBotUtil{
} }
/**
* 对表单数据做预处理
* @param receiveParameters
* @param context
* @return
* @throws IOException
*/
@Override @Override
public boolean preprocessing(Map<String, String[]> receiveParameters, ServletContext context) throws IOException { public boolean preprocessing(Map<String, String[]> receiveParameters, ServletContext context) throws IOException {
Boolean debugFlag = super.infoPointPreprocessing(receiveParameters, context, false); Boolean debugFlag = super.infoPointPreprocessing(receiveParameters, context, false);
...@@ -63,6 +69,7 @@ public class GameBotUtil extends BasicBotUtil{ ...@@ -63,6 +69,7 @@ public class GameBotUtil extends BasicBotUtil{
// historyInfoPoint.put("current_plot_site", historyInfoPoint.get("site")); // historyInfoPoint.put("current_plot_site", historyInfoPoint.get("site"));
//将上一轮使用的nextStep(condition)放在临时变量中
String activeList[] = chatCache.getInfoPoint().get("activeList").split("\\|"); String activeList[] = chatCache.getInfoPoint().get("activeList").split("\\|");
if(activeList.length == 0){ if(activeList.length == 0){
chatCache.getInfoPoint().put("临时变量condition", "yaobuyao"); chatCache.getInfoPoint().put("临时变量condition", "yaobuyao");
...@@ -84,6 +91,8 @@ public class GameBotUtil extends BasicBotUtil{ ...@@ -84,6 +91,8 @@ public class GameBotUtil extends BasicBotUtil{
//将自动跳转文本、qa文本、查询文本拼接 //将自动跳转文本、qa文本、查询文本拼接
String queryList[] = { "plot_jump_text" ,"common_answer","map_query", "goods_query", "npc_query", "plot_text", "error_message"}; String queryList[] = { "plot_jump_text" ,"common_answer","map_query", "goods_query", "npc_query", "plot_text", "error_message"};
String queryResult; String queryResult;
//有些特殊文本在开头是不加npc名字和情绪的
Set<String> keepNoSpeaker = new HashSet<String>(){ Set<String> keepNoSpeaker = new HashSet<String>(){
{ {
add("sendData:archiveList"); add("sendData:archiveList");
...@@ -104,20 +113,24 @@ public class GameBotUtil extends BasicBotUtil{ ...@@ -104,20 +113,24 @@ public class GameBotUtil extends BasicBotUtil{
switch (queryName){ switch (queryName){
case "common_answer": case "common_answer":
//qa返回结果不为No answer,就添加到回答文本
if(!queryResult.equals("no answer")) if(!queryResult.equals("no answer"))
finalText.append(queryResult); finalText.append(queryResult);
break; break;
case "plot_jump_text": case "plot_jump_text":
//添加剧情自动跳转文本
finalText.append(queryResult); finalText.append(queryResult);
break; break;
case "map_query": case "map_query":
case "goods_query": case "goods_query":
case "npc_query": case "npc_query":
case "error_message": case "error_message":
//这四类文本(查询+错误信息)都是动态生成的,没有npc和情绪信息,所以需要添加npc和情绪
queryResult = appendTalker(findRelateTalkers(false).get(0), queryResult, chatCache.getInfoPoint(), chatCache.getGameEnv()); queryResult = appendTalker(findRelateTalkers(false).get(0), queryResult, chatCache.getInfoPoint(), chatCache.getGameEnv());
finalText.append(queryResult); finalText.append(queryResult);
break; break;
case "plot_text": case "plot_text":
//有以下剧情文本是
if(keepNoSpeaker.contains(plotText)){ //不需要添加人名和情绪 if(keepNoSpeaker.contains(plotText)){ //不需要添加人名和情绪
finalText.setLength(0); finalText.setLength(0);
finalText.append(plotText); finalText.append(plotText);
...@@ -529,6 +542,14 @@ public class GameBotUtil extends BasicBotUtil{ ...@@ -529,6 +542,14 @@ public class GameBotUtil extends BasicBotUtil{
} }
/**
* 判断文本类型
* 1. direct_return:不需要额外处理,直接返回
* 2. less_talker:文本数据不完整,文本开头缺少【%s@%s】
* 3. to_unknown: 用unknown无匹配文本作为回答
* @param reply
* @return
*/
String plotTextFilt(String reply){ String plotTextFilt(String reply){
String textType, returnText = "plot text filt error", plotLastTalker; String textType, returnText = "plot text filt error", plotLastTalker;
String site = chatCache.getInfoPoint().get("site"); String site = chatCache.getInfoPoint().get("site");
...@@ -542,8 +563,11 @@ public class GameBotUtil extends BasicBotUtil{ ...@@ -542,8 +563,11 @@ public class GameBotUtil extends BasicBotUtil{
returnText = reply; returnText = reply;
break; break;
case "less_talker": case "less_talker":
//没有npc就添加npc
return appendTalker(findRelateTalkers(false).get(0), reply, chatCache.getInfoPoint(), chatCache.getGameEnv()); return appendTalker(findRelateTalkers(false).get(0), reply, chatCache.getInfoPoint(), chatCache.getGameEnv());
case "to_unknown": case "to_unknown":
//先设置一个默认答案,在本地点没有可以回答unknown
returnText = NO_ONE_CAN_REPLY_UNKNOWN; returnText = NO_ONE_CAN_REPLY_UNKNOWN;
Set<String> candidates = new HashSet<String>(); Set<String> candidates = new HashSet<String>();
Map<String, List<String>> npcTextMap = null; Map<String, List<String>> npcTextMap = null;
...@@ -551,6 +575,7 @@ public class GameBotUtil extends BasicBotUtil{ ...@@ -551,6 +575,7 @@ public class GameBotUtil extends BasicBotUtil{
String fieldList[] = {"unknownTextList", "finalUnknownText"}; String fieldList[] = {"unknownTextList", "finalUnknownText"};
String lastReply = chatCache.getInfoPoint().get("lastReply"); String lastReply = chatCache.getInfoPoint().get("lastReply");
//找到上一个回答,
plotLastTalker = findTextLastTalker(lastReply, site); plotLastTalker = findTextLastTalker(lastReply, site);
for(String unknownField:fieldList){ for(String unknownField:fieldList){
...@@ -622,6 +647,12 @@ public class GameBotUtil extends BasicBotUtil{ ...@@ -622,6 +647,12 @@ public class GameBotUtil extends BasicBotUtil{
} }
/**
* 找到文本中最后一个可以说话的人, 可以说话是指npc处于玩家所在地点,不是离线模式等
* @param text 文本
* @param site 玩家当前所在地点
* @return
*/
private String findTextLastTalker(String text, String site){ private String findTextLastTalker(String text, String site){
Matcher m = findTalker(text); Matcher m = findTalker(text);
String npc, lastTalker = ""; String npc, lastTalker = "";
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment