private void onRecvProtocol(HttpExchange httpExchange, String params) throws Exception { // 调试打印 HawkLog.debugPrintln("HttpParams: " + params); // 参数分析 String token = "", data = ""; String[] kvPairs = params.split("&"); for (String kv : kvPairs) { String[] pair = kv.split("="); if (pair.length != 2) { continue; } if (pair[0].equals("token")) { token = pair[1]; } if (pair[0].equals("data")) { data = pair[1]; } } if (token != null && data != null && data.length() > 0) { HawkOSOperator.sendHttpResponse( httpExchange, HawkOSOperator.randomString(HawkRand.randInt(64, 2048))); } }
public static void doReport(Map<String, String> params) throws Exception { if (params != null) { String time = params.containsKey("time") ? params.get("time") : HawkTime.getTimeString(); String value = String.format( "'%s', '%s', '%s', '%s', '%s', '%s', %s, %s, %s, '%s', %s, %s, '%s', '%s'", params.get("game"), params.get("platform"), params.get("server"), CollectorServices.getChannelFromPuid(params.get("puid")), params.get("puid"), params.get("device"), params.get("playerid"), params.get("playerlevel"), params.get("changetype"), params.get("changeaction"), params.get("goldtype"), params.get("gold"), time, time.substring(0, 10)); String sql = String.format( "INSERT INTO gold(game, platform, server, channel, puid, device, playerid, playerlevel, changetype, changeaction, goldtype, gold, time, date) VALUES(%s);", value); DBManager.getInstance().executeSql(params.get("game"), sql); HawkLog.logPrintln("report_gold: " + value); } }
/** * 注册协议文件 * * @param protoType * @param protocol * @return */ public final boolean registerPacket(int type, HawkPacket packet) { if (packetStub.containsKey(type)) { HawkLog.errPrintln("register duplicate packet, type: " + type); return false; } packetStub.put(type, packet); return true; }
@Override @SuppressWarnings("unused") public void handle(HttpExchange httpExchange) throws IOException { try { String contentBody = HawkOSOperator.readRequestBody(httpExchange).replace("\r", ""); int pos = contentBody.indexOf("\n"); if (pos > 0) { int index = 0; String header = contentBody.substring(0, pos).trim(); String items[] = header.split("\\^"); if (items.length >= 7) { String md5 = ""; int stackPos = contentBody.indexOf("stack traceback"); if (stackPos > 0) { md5 = HawkMd5.makeMD5(contentBody.substring(stackPos)); } else { md5 = HawkMd5.makeMD5(contentBody); } if (logMd5Map.containsKey(md5)) { return; } logMd5Map.put(md5, md5); HawkLog.logPrintln("\r\nUserLog: " + contentBody); String game = items[index++]; String logtype = items[index++]; String platform = items[index++]; String serverid = items[index++]; String puid = items[index++]; String phoneinfo = items[index++]; String sysinfo = items[index++]; if (game.length() > 0 && logtype.length() > 0 && platform.length() > 0 && serverid.length() > 0 && puid.length() > 0) { // 创建日志目录 String dir = HawkOSOperator.getWorkPath() + "userlog/" + game + "/" + logtype + "/"; HawkOSOperator.createDir(dir); SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd.HHmmss"); String tm = sdf.format(HawkTime.getDate()); String fileName = String.format("%s%s.%s.%s.%s", dir, platform, serverid, puid, tm); HawkOSOperator.saveAsFile(contentBody, fileName); } } } } catch (Exception e) { HawkException.catchException(e); } }