diff --git a/src/db/SqlHelper.java b/src/db/SqlHelper.java index 915e678..796817d 100644 --- a/src/db/SqlHelper.java +++ b/src/db/SqlHelper.java @@ -352,7 +352,6 @@ public class SqlHelper { id = rs.getInt(1); categoryMap.put(nameList.get(iterNum), id); iterNum++; - } diff --git a/src/entity/ChatCache.java b/src/entity/ChatCache.java index f1c426f..8f3882f 100644 --- a/src/entity/ChatCache.java +++ b/src/entity/ChatCache.java @@ -17,11 +17,21 @@ public class ChatCache implements DisposableBean { private String chatKey = "不知道"; + private String botAccount = ""; private Map infoPoint = null; private GameEnv gameEnv = null; private boolean reloading = false; + + public String getBotAccount() { + return botAccount; + } + + public void setBotAccount(String botAccount) { + this.botAccount = botAccount; + } + public boolean isReloading() { return reloading; } @@ -76,6 +86,7 @@ public class ChatCache implements DisposableBean { } String k; + this.botAccount = userInfo.botAccount; infoPoint = new HashMap(); Iterator iit = userInfo.varInitialMap.keySet().iterator(); while (iit.hasNext()) { diff --git a/src/gameDesign/PlotConstructor.java b/src/gameDesign/PlotConstructor.java index 4dfe0ec..1de6fe1 100644 --- a/src/gameDesign/PlotConstructor.java +++ b/src/gameDesign/PlotConstructor.java @@ -49,13 +49,15 @@ public class PlotConstructor extends ElementConstructor { public void construct(JSONObject jsonObject, UserInfo userinfo) { try { - + addGameStartPlot(jsonObject); JSONArray plots = jsonObject.getJSONArray("plots"); String start = (String) jsonObject.get("start"), startCondition; JSONObject returnMessage = null; + + this.plots = plots; constructAdjList(plots); @@ -163,17 +165,20 @@ public class PlotConstructor extends ElementConstructor { String startPlace = ((String)root.get("place")).split("\\+")[0]; + String startTaskLine = String.format(PlotConstructor.TASK_LINE, startPlace); String startTaskCondition = String.format(PlotConstructor.TASK_CONDITION, startPlace); String startTaskReply = String.format(PlotConstructor.TASK_REPLY, startPlace); varInitialMap.put("site", startPlace); + varInitialMap.put(startTaskLine, rootId); varInitialMap.put(startTaskCondition, ""); varInitialMap.put(startTaskReply, ""); + conditionDescription.put(startTaskLine, startTaskLine); conditionDescription.put(startTaskCondition,startTaskCondition); conditionDescription.put(startTaskReply, startTaskReply); - generateStartGame(root, jsonObject, startPlace, conditionName); + //generateStartGame(root, jsonObject, startPlace, conditionName); Queue queue = new LinkedList(); Map autoJumpUpdateKnowledge = new HashMap(); @@ -418,6 +423,8 @@ public class PlotConstructor extends ElementConstructor { if (curPremiseList.size() == 0 && historyPremiseList.size() == 0){ unconditionalPlotProcess(jConfig, nextCondition); } + if (branchNode.getBoolean("higherPriority") != null && branchNode.getBoolean("higherPriority")) + jConfig.setAuxiliaryPriority("3"); jConfigList.add(jConfig); @@ -490,12 +497,13 @@ public class PlotConstructor extends ElementConstructor { * 待激活列表,用于qa问答 */ + //处于激活状态,其他的属于待激活状态,jStatus这一条不设为1,而是0 jConfig = new JConfig(" ", " ", "activate,post::gameQA(" + QA_URL+ ")", "", "unknown4,unknown3,unknown2,unknown1,common_answer", ""); jConfig.setNextStepStatus("active"); - jConfig.setjStatus(1); jConfig.setAuxiliaryPriority("0"); jConfigList.add(jConfig); + jConfig = new JConfig( " ", "qa_status::match-Include=not_found", "match,return-0", "{unknownText-2}", " ", "" ); @@ -622,6 +630,46 @@ public class PlotConstructor extends ElementConstructor { } + void addGameStartPlot(JSONObject gameElements){ + JSONObject startPlot = new JSONObject(); + startPlot.put("id", "start"); + startPlot.put("conditionName", "start_options"); + startPlot.put("place", "哪呢? 还没开始呢"); + startPlot.put("branch", new JSONArray()); + + JSONObject branch1 = new JSONObject(); + branch1.put("curPremise", new JSONArray(){ + { + add("start_options::match-Include=+开始+开始游戏+继续游戏+继续+重新开始"); + } + }); + + branch1.get("curPremise"); + branch1.put("higherPriority", true); + branch1.put("hisPremise", new JSONArray()); + branch1.put("reply", gameElements.get("plotStartText")); + branch1.put("updateKnowledge", new JSONObject(){ + { + put("unknownText", gameElements.get("firstUnknownText")); + } + }); + branch1.put("nextPlotId", gameElements.get("start")); + branch1.put("includeCurInfo", false); + if(gameElements.get("startAutoJump") != null) + branch1.put("autoJump", gameElements.get("startAutoJump")); + else + branch1.put("autoJump", false); + + startPlot.getJSONArray("branch").add(branch1); + gameElements.getJSONArray("plots").add(startPlot); + gameElements.put("start", "start"); + gameElements.put("firstUnknownText", "请说开始游戏或者继续游戏"); + + + + + } + //如果是无条件剧情,那么需要跟着一个激活操作 diff --git a/src/processing/ChatCacheController.java b/src/processing/ChatCacheController.java index 0ce3abe..4363424 100644 --- a/src/processing/ChatCacheController.java +++ b/src/processing/ChatCacheController.java @@ -7,6 +7,7 @@ import com.qiwu.chatbotbackend.GameEnvironment.ObjectFileUtil; import com.qiwu.chatbotbackend.GameEnvironment.Util; import com.qiwu.chatbotbackend.entity.ChatCache; import com.qiwu.chatbotbackend.entity.UserInfo; +import org.apache.catalina.User; import javax.servlet.ServletContext; import java.io.*; @@ -24,76 +25,11 @@ public class ChatCacheController { private static String CHAT_CACHE_DIR = "ChatCache"; - private static String ENV_PATH = CHAT_CACHE_DIR + "/%s env.data"; - private static String INFO_PATH = CHAT_CACHE_DIR + "/%s info.data"; - /** - * 通过chat_key获得后台保存的历史信息点 - * chatCache:存储了chatKye相对应的对话记录(历史信息点) - * - * @return 历史信息点,对话过程中引擎提取的用户信息 - */ -// public static synchronized Map getChatCache(String chatKey, ServletContext context) { -// -// GameEnv gameEnv = new GameEnv(chatKey); -// Map historyInfoPoint = null; -// Map> chatCache = null; -// if (context.getAttribute("chatCache") == null) { -// chatCache = new HashMap>(); -// context.setAttribute("chatCache", chatCache); -// } else { -// chatCache = (Map>) context.getAttribute("chatCache"); -// } -// String chatkey; -// -// -// try { -// historyInfoPoint = chatCache.get(chatKey); -// //historyInfoPoint = (Map) context.getAttribute("chat_key+"+userinfo.userName); -// } catch (Exception e) { -// -// //可整合 -// historyInfoPoint = null; -// -// } -// -// return historyInfoPoint; -// } + private static String ENV_PATH = CHAT_CACHE_DIR + "/%s-env.data"; + private static String INFO_PATH = CHAT_CACHE_DIR + "/%s-info.data"; - /** - * chatChche中每个chatkey都有对应的最后更新时间,如果最后更新时间已经是x分钟前(超时),就清除该chatKey的数据 - */ -// public static synchronized void updateChatCache4Delete(ServletContext context) { -// String chatKey; -// long lastChatTime, now; -// Map history = new HashMap(); -// Map> chatCache = (Map>) context.getAttribute("chatCache"); -// -// -// Iterator it = chatCache.keySet().iterator(); -// while (it.hasNext()) { -// chatKey = it.next(); -// history = chatCache.get(chatKey); -// lastChatTime = Long.valueOf(history.get("lastUpdateTime")); -// now = System.currentTimeMillis(); -// if (now - lastChatTime > 300000) { -// it.remove(); -// } -// } -// context.setAttribute("chatCache", chatCache); -// } - - /** - * 根据chatKey更新chatCache的数据,并修改最后更新时间 - */ -// public static synchronized void updateChatCache4Insert(Map curInfoPoint, Map historyInfoPoint, ServletContext context) { -// historyInfoPoint.put("lastUpdateTime", String.valueOf(System.currentTimeMillis())); -// Map> keyCache = (Map>) context.getAttribute("chatCache"); -// keyCache.put(curInfoPoint.get("chat_key")[0], historyInfoPoint); -// context.setAttribute("chatCache", keyCache); -// } - - public static boolean saveChatCache(String chatKey, ChatCache chatCache) throws IOException { + public static synchronized boolean saveChatCache(String chatKey, ChatCache chatCache) throws IOException { LocalDateTime now = LocalDateTime.now(); DateTimeFormatter format = DateTimeFormatter.ofPattern("yyyy-MM-dd hh:mm:ss"); String nowStr = now .format(format); @@ -107,10 +43,10 @@ public class ChatCacheController { if (!dir.exists()) dir.mkdir(); - ObjectFileUtil.writeObjectToFile(chatCache.getGameEnv(), String.format(ENV_PATH, chatKey.split("-")[0])); + ObjectFileUtil.writeObjectToFile(chatCache.getGameEnv(), String.format(ENV_PATH, chatKey)); - File file = new File(String.format(INFO_PATH, chatKey.split("-")[0])); + File file = new File(String.format(INFO_PATH, chatKey)); FileWriter fw = new FileWriter(file); String jsonString = JSON.toJSONString(chatCache.getInfoPoint()); @@ -119,13 +55,14 @@ public class ChatCacheController { } catch (Exception e) { System.out.println("游戏存档时发生异常"); + e.printStackTrace(); saveFlag = false; } return saveFlag; } - public static ChatCache loadChatCache(String chatKey, ServletContext context, UserInfo userInfo, Boolean loadCacheStatus) throws Exception { + public static synchronized ChatCache loadChatCache(String chatKey, ServletContext context, UserInfo userInfo, Boolean loadCacheStatus) throws Exception { ChatCache chatCache = null; GameEnv gameEnv = null; Map infoPoint = null; @@ -171,7 +108,12 @@ public class ChatCacheController { - + /** + * 通过chat_key获得后台保存的历史信息点 + * chatCache:存储了chatKye相对应的对话记录(历史信息点) + * + * @return 历史信息点,对话过程中引擎提取的用户信息 + */ public static synchronized ChatCache getChatCache(String chatKey, ServletContext context, UserInfo userinfo, Map receiveParamters, Boolean loadCacheStatus) throws Exception { Map chatCacheMap = null; ChatCache chatCache = null; @@ -200,16 +142,22 @@ public class ChatCacheController { HashSet restartKeySet = new HashSet(){ { add("重新开始"); + add("新游戏"); } }; + //如果用户之前没有玩过或者有一段时间没有玩 if(chatCache == null){ + //识别到的语义关系包含start_options if(receiveParamters.containsKey("start_options")){ String startKeyword = receiveParamters.get("start_options")[0].split(":", 2)[1]; + //有继续游戏相关的关键词 if(startKeySet.contains(startKeyword)) { + //加载存档 chatCache = loadChatCache(chatKey, context, userinfo, loadCacheStatus); + //没有继续游戏相关的关键词 }else { chatCache = new ChatCache(userinfo); } @@ -217,8 +165,11 @@ public class ChatCacheController { chatCache = new ChatCache(userinfo); } chatCacheMap.put(chatKey, chatCache); + //用户几分钟前还在玩 } else { + //将重新加载的标识重置 chatCache.setReloading(false); + //识别到的语义关系包含start_options if(receiveParamters.containsKey("start_options")){ String startKeyword = receiveParamters.get("start_options")[0].split(":", 2)[1]; if(startKeySet.contains(startKeyword)) { @@ -242,7 +193,7 @@ public class ChatCacheController { /** * chatChche中每个chatkey都有对应的最后更新时间,如果最后更新时间已经是x分钟前(超时),就清除该chatKey的数据 */ - public static synchronized void updateChatCache4Delete(String curChatKey, ServletContext context) throws IOException { + public static synchronized void updateChatCache4Delete(String curChatKey, ServletContext context, UserInfo userInfo) throws IOException { String chatKey; ChatCache chatCache = null; long lastChatTime, now; @@ -273,7 +224,7 @@ public class ChatCacheController { /** * 根据chatKey更新chatCache的数据,并修改最后更新时间 */ - public static synchronized void updateChatCache4Insert(Map curInfoPoint, Map historyInfoPoint, GameEnv gameEnv, ServletContext context) { + public static synchronized void updateChatCache4Insert(Map curInfoPoint, Map historyInfoPoint, GameEnv gameEnv, ServletContext context, UserInfo userInfo) { historyInfoPoint.put("lastUpdateTime", String.valueOf(System.currentTimeMillis())); Map keyCacheMap = (Map) context.getAttribute("chatCache"); ChatCache chatCache = keyCacheMap.get(curInfoPoint.get("chat_key")); @@ -283,7 +234,7 @@ public class ChatCacheController { } - public static synchronized boolean findChatCache(String chatKey, ServletContext context) throws Exception { + public static synchronized boolean findChatCache(String chatKey, ServletContext context, String botAccount) throws Exception { ChatCache chatCache = null; GameEnv gameEnv = null; Map infoPoint = null; @@ -310,6 +261,8 @@ public class ChatCacheController { return false; } + + public static synchronized boolean deleteUnuseChatCache(String chatKey, ServletContext context) throws Exception { try { System.out.println("移除----------------------------"); diff --git a/src/processing/ConditionTableController.java b/src/processing/ConditionTableController.java index c20501d..730fcc0 100644 --- a/src/processing/ConditionTableController.java +++ b/src/processing/ConditionTableController.java @@ -186,12 +186,16 @@ public class ConditionTableController { public static String writeConfigText(String userName, UserInfo userinfo) throws IOException { - System.out.println("p"); - System.out.println(userName); + String CONFIG_DIR = System.getProperty("user.dir") + "/config", configText; String path = CONFIG_DIR + "/" + userName + ".txt"; + + File file = new File(path); File dir = new File(System.getProperty("user.dir") + "/config"); + + System.out.println(userName); + System.out.println("config_dir" + dir.getAbsolutePath()); String returnMessage = "success"; if (!dir.exists()) diff --git a/src/processing/FormsPoster.java b/src/processing/FormsPoster.java index bce3c63..f3c927e 100644 --- a/src/processing/FormsPoster.java +++ b/src/processing/FormsPoster.java @@ -18,7 +18,7 @@ public class FormsPoster { LogWriter logWriter = null; - public static String QA_URL = "http://aliyun-hz1.chewrobot.com:58000/game"; + public static String QA_URL = "http://qcloud-gz1.chewrobot.com:58000/game"; public FormsPoster(LogWriter logWriter) { this.logWriter = logWriter; diff --git a/src/processing/MyFunc.java b/src/processing/MyFunc.java index 2e67210..8bf1e3d 100644 --- a/src/processing/MyFunc.java +++ b/src/processing/MyFunc.java @@ -110,7 +110,9 @@ public class MyFunc { return true; } - public static JSONObject postJSON(String url, JSONObject data, String auth) throws UnsupportedEncodingException { + + + public static JSONObject postJSON(String url, JSON data, String auth) throws UnsupportedEncodingException { JSONObject jobj = new JSONObject(); diff --git a/src/processing/QuestionMatcher.java b/src/processing/QuestionMatcher.java index 557a984..a99c7e4 100644 --- a/src/processing/QuestionMatcher.java +++ b/src/processing/QuestionMatcher.java @@ -841,149 +841,6 @@ public class QuestionMatcher { } - public void updateKnowledge(Condition condition) throws ParseException { - String keyword, variableName, updateValue, returnStr = "1"; - - - Iterator iit = condition.updateKnowledge.keySet().iterator(); - while (iit.hasNext()) { - - variableName = iit.next(); - updateValue = condition.updateKnowledge.get(variableName); - - keyword = historyInfoPoint.get(variableName); - - //如果变量名开头为NPC或者item,就专门交给world处理 - if((userinfo.varInitialMap.get("botType") != null && userinfo.varInitialMap.get("botType").equals("game")) && - (variableName.startsWith("npc_") || variableName.startsWith("goods_") || variableName.startsWith("map_") || variableName.startsWith("place_"))){ - try { - returnStr = worldController.worldOperation(gameEnv, variableName, updateValue, curInfoPoint, historyInfoPoint); - updateValue = returnStr; - }catch (Exception e){ - e.printStackTrace(); - updateValue = "游戏模块处理出错"; - } - }else { - - try { - //做数字加法 - if (updateValue.startsWith("+")) { - if (keyword == null || keyword.equals("")) - keyword = "0"; - if (keyword.matches("\\d{4}年\\d{1,2}月\\d{1,2}日.*")) { - long time = MyFunc.transferToMillisecond(keyword); - int offset = Integer.parseInt(updateValue.substring(1)); - updateValue = MyFunc.transferToStandardTime(time + (1000 * offset)); - } else if (StringUtils.isNumeric(keyword)) { - int number = Integer.parseInt(keyword); - int offset = Integer.parseInt(updateValue.substring(1)); - updateValue = String.valueOf(number + offset); - } - //做数字减法 - } else if (updateValue.startsWith("-")) { - if (keyword == null || keyword.equals("")) - keyword = "0"; - if (keyword.matches("\\d{4}年\\d{1,2}月\\d{1,2}日.*")) { - long time = MyFunc.transferToMillisecond(keyword); - int offset = Integer.parseInt(updateValue.substring(1)); - updateValue = MyFunc.transferToStandardTime(time - (1000 * offset)); - } else if (StringUtils.isNumeric(keyword)) { - int number = Integer.parseInt(keyword); - int offset = Integer.parseInt(updateValue.substring(1)); - updateValue = String.valueOf(number - offset); - } - //做字符串累加 - } else if (updateValue.startsWith("str+")) { - if (keyword == null || keyword.equals("")) - keyword = ""; - updateValue = keyword + updateValue.substring(4); - //做字符串删除 - } else if (updateValue.startsWith("str-")) { - if (keyword == null || keyword.equals("")) - keyword = ""; - updateValue = keyword.replace(updateValue.substring(4), ""); - - } else if (updateValue.startsWith("int+=")) { - if (keyword == null || keyword.equals("")) - keyword = "0"; - if (keyword.matches("\\d{4}年\\d{1,2}月\\d{1,2}日.*")) { - long time = MyFunc.transferToMillisecond(keyword); - int offset = Integer.parseInt(updateValue.substring(1)); - updateValue = MyFunc.transferToStandardTime(time + (1000 * offset)); - } else if (StringUtils.isNumeric(keyword)) { - int number = Integer.parseInt(keyword); - int offset = Integer.parseInt(updateValue.substring(5)); - updateValue = String.valueOf(number + offset); - } - //做数字减法 - } else if (updateValue.startsWith("int-=")) { - if (keyword == null || keyword.equals("")) - keyword = "0"; - if (keyword.matches("\\d{4}年\\d{1,2}月\\d{1,2}日.*")) { - long time = MyFunc.transferToMillisecond(keyword); - int offset = Integer.parseInt(updateValue.substring(5)); - updateValue = MyFunc.transferToStandardTime(time - (1000 * offset)); - } else if (StringUtils.isNumeric(keyword)) { - int number = Integer.parseInt(keyword); - int offset = Integer.parseInt(updateValue.substring(1)); - updateValue = String.valueOf(number - offset); - } - //做字符串累加 - } else if (updateValue.startsWith("str+=")) { - if (keyword == null || keyword.equals("")) - keyword = ""; - updateValue = keyword + updateValue.substring(5); - //做字符串删除 - } else if (updateValue.startsWith("str-=")) { - if (keyword == null || keyword.equals("")) - keyword = ""; - updateValue = keyword.replace(updateValue.substring(5), ""); - - } else if (updateValue.startsWith("var=")) { - String conditionName = updateValue.substring(5, updateValue.length() - 3); - - if (updateValue.endsWith("-1}")) { - if (curInfoPoint.get(conditionName) != null) { - updateValue = curInfoPoint.get(conditionName); - } else { - updateValue = ""; - } - } else if (updateValue.endsWith("-2}")) { - if (historyInfoPoint.get(conditionName) != null) { - updateValue = historyInfoPoint.get(conditionName); - } else { - updateValue = ""; - } - } else if (updateValue.endsWith("nextStep-3}")) { - updateValue = condition.nextStep; - } else if (updateValue.endsWith("reply-3}")) { - updateValue = MyFunc.randStr(condition.answer); - } - if (variableName.startsWith("process-nextStep")) { - condition.nextStep = updateValue; - updateValue = ""; - } - - } - } catch (Exception e) { - e.printStackTrace(); - continue; - } - } - - - if(updateValue.equals("")) { - curInfoPoint.put(variableName + "_backup", curInfoPoint.get(variableName)); //更新答案将某变量设为空时,要将当前信息点也清空,不然后边信息点转移时这个变量的已知信息依然不是空的。 - // 为了避免将当前信息点清空后debug信息显示不完整,现创造一个备份,在appendDebugInfo后会将这个备份清空。 - curInfoPoint.put(variableName, ""); - } - - historyInfoPoint.put(variableName, updateValue); - - } - - - } public void updateKnowledge2(Condition condition) throws ParseException { String keyword, variableName, updateValue, returnStr = "1"; @@ -1118,7 +975,6 @@ public class QuestionMatcher { } - } diff --git a/src/processing/ResponseFilter.java b/src/processing/ResponseFilter.java index 11ddd94..837ff8c 100644 --- a/src/processing/ResponseFilter.java +++ b/src/processing/ResponseFilter.java @@ -160,7 +160,7 @@ public class ResponseFilter { npc = m.group(1); location = worldController.worldOperation(gameEnv, "npc_query", "queryLocationByNPCName:" + npc, curInfoPoint, historyInfoPoint); if (location.equals(site) || location.equals("无处不在") || location.equals("任意地点")){ - if(gameEnv.queryNpcAttrByNpcName(npc, "能否说话").equals("能")){ + if(gameEnv.queryNpcAttrByNpcName(npc, "能否说话") == null || gameEnv.queryNpcAttrByNpcName(npc, "能否说话").equals("能")){ flag = 1; logWriter.record("\"" + reply + "\":匹配", 1); }else { diff --git a/src/servlet/FindCacheServlet.java b/src/servlet/FindCacheServlet.java index ebbd6a7..9fb15eb 100644 --- a/src/servlet/FindCacheServlet.java +++ b/src/servlet/FindCacheServlet.java @@ -12,7 +12,7 @@ import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.io.PrintWriter; -@WebServlet(name = "FindCacheServlet", urlPatterns = {"/findCache"}) +@WebServlet(name = "FindCacheServlet", urlPatterns = {"/findChatCache"}) public class FindCacheServlet extends HttpServlet { protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { ServletContext context = this.getServletContext(); @@ -20,16 +20,18 @@ public class FindCacheServlet extends HttpServlet { request.setCharacterEncoding("UTF-8"); String chatKey = request.getParameter("client_id"); + String botAccount = request.getParameter("aipioneer_username"); Boolean exist = false; try { - exist = ChatCacheController.findChatCache(chatKey, context); + exist = ChatCacheController.findChatCache(chatKey+ "-" + botAccount, context, botAccount); } catch (Exception e) { e.printStackTrace(); } JSONObject responseJSONObject = new JSONObject(); responseJSONObject.put("exist", exist); + responseJSONObject.put("aipioneer_username", botAccount); response.setCharacterEncoding("UTF-8"); response.setContentType("application/json; charset=utf-8"); response.setHeader("Access-Control-Allow-Origin", "*"); diff --git a/src/servlet/GameDesignServlet.java b/src/servlet/GameDesignServlet.java index 74cd9e2..67c3bdb 100644 --- a/src/servlet/GameDesignServlet.java +++ b/src/servlet/GameDesignServlet.java @@ -341,7 +341,7 @@ public class GameDesignServlet extends HttpServlet { } } - } + } diff --git a/src/servlet/GetAnswerServlet.java b/src/servlet/GetAnswerServlet.java index ae551ee..6693993 100644 --- a/src/servlet/GetAnswerServlet.java +++ b/src/servlet/GetAnswerServlet.java @@ -142,12 +142,12 @@ public class GetAnswerServlet extends HttpServlet { matcher.infoTransfer(bestMatch, context, debugFlag); - ChatCacheController.updateChatCache4Insert(curInfoPoint, historyInfoPoint, chatCache.getGameEnv(), context); + ChatCacheController.updateChatCache4Insert(curInfoPoint, historyInfoPoint, chatCache.getGameEnv(), context, userinfo); //清理超时的用户数据 if (context.getAttribute("cacheUpdateTime") == null) context.setAttribute("cacheUpdateTime", System.currentTimeMillis()); if (System.currentTimeMillis() - (long) context.getAttribute("cacheUpdateTime") > ChatCacheController.TIME_OUT) { - ChatCacheController.updateChatCache4Delete(chatKey, context); + ChatCacheController.updateChatCache4Delete(chatKey, context, userinfo); context.setAttribute("cacheUpdateTime", System.currentTimeMillis()); } diff --git a/src/servlet/SaveChatCacheServlet.java b/src/servlet/SaveChatCacheServlet.java index aa41226..fe4877a 100644 --- a/src/servlet/SaveChatCacheServlet.java +++ b/src/servlet/SaveChatCacheServlet.java @@ -1,5 +1,7 @@ package com.qiwu.chatbotbackend.servlet; +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; import com.qiwu.chatbotbackend.entity.ChatCache; import com.qiwu.chatbotbackend.processing.ChatCacheController; @@ -11,28 +13,50 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.io.OutputStream; +import java.io.PrintWriter; import java.util.Map; @WebServlet(name = "SaveChatCacheServlet", urlPatterns = {"/saveChatCache"}) public class SaveChatCacheServlet extends HttpServlet { protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { - - - - } - - protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { request.setCharacterEncoding("UTF-8"); - String chatKey = request.getParameter("chat_key"), message = ""; - OutputStream out = response.getOutputStream(); + String chatKey = request.getParameter("chatKey"), message = ""; ServletContext context = this.getServletContext(); + chatKey = chatKey.split("@")[0]; + Boolean flag = false; Map chatCacheMap = (Map)context.getAttribute("chatCache"); ChatCache chatCache = chatCacheMap.get(chatKey); - //message = ChatCacheController.saveChatCache(chatKey, context); + + if(chatCache != null) { + flag = ChatCacheController.saveChatCache(chatKey, chatCache); + chatCacheMap.remove(chatKey); + } + + System.out.println("调用接口删除" + chatKey); //out.write(message.getBytes()); + + + + + response.setCharacterEncoding("UTF-8"); + response.setContentType("application/json; charset=utf-8"); + + PrintWriter out = response.getWriter(); + + JSONObject retData = new JSONObject(); + retData.put("status", flag); + System.out.println("xx:" + retData.toJSONString()); + out.append(retData.toJSONString()); out.flush(); + + + } + + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + + doPost(request, response); } } diff --git a/src/task/utils/GameBotUtil.java b/src/task/utils/GameBotUtil.java index a9c70e0..8831571 100644 --- a/src/task/utils/GameBotUtil.java +++ b/src/task/utils/GameBotUtil.java @@ -120,7 +120,7 @@ public class GameBotUtil extends BasicBotUtil{ keyword = gameEnv.queryGoodsAttrByGoodsName(nameSeries[2], nameSeries[3]); System.out.println("return" + keyword); }else if (nameSeries.length == 3){ - keyword = gameEnv.queryNpcAttrByNpcName(nameSeries[1], nameSeries[2]); + keyword = gameEnv.queryGoodsAttrByGoodsName(nameSeries[1], nameSeries[2]); } }else if(actionName.startsWith("isNeighbour")){ @@ -146,6 +146,9 @@ public class GameBotUtil extends BasicBotUtil{ } + if(keyword == null) + keyword = ""; + return keyword; };