|
|
@@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSON;
|
|
|
import com.izouma.nineth.domain.PublicScreenChat;
|
|
|
import com.izouma.nineth.domain.PurchaseLevel;
|
|
|
import com.izouma.nineth.domain.User;
|
|
|
+import com.izouma.nineth.dto.PublicScreenChatExceptionMsg;
|
|
|
import com.izouma.nineth.exception.BusinessException;
|
|
|
import com.izouma.nineth.repo.PublicScreenChatRepo;
|
|
|
import com.izouma.nineth.repo.UserRepo;
|
|
|
@@ -64,12 +65,12 @@ public class PublicScreenChatWebsocket extends WebsocketCommon {
|
|
|
// 判断当前玩家是否在其他地方登陆
|
|
|
if (clients.containsKey(PREFIX.concat(userId))) {
|
|
|
String msg = String.format("已在别处登陆,sessionId为[%S],正在为您关闭本连接", session.getId());
|
|
|
- exceptionHandle(userId, msg);
|
|
|
+ exceptionHandle(userId, new PublicScreenChatExceptionMsg(1, msg));
|
|
|
try {
|
|
|
log.info("关闭session连接");
|
|
|
clients.get(PREFIX.concat(userId)).close();
|
|
|
} catch (Exception e) {
|
|
|
- exceptionHandle(userId, String.format("session close throw exception[%S]", e));
|
|
|
+ exceptionHandle(userId, new PublicScreenChatExceptionMsg(1, String.format("session close throw exception[%S]", e)));
|
|
|
return;
|
|
|
}
|
|
|
}
|
|
|
@@ -81,7 +82,7 @@ public class PublicScreenChatWebsocket extends WebsocketCommon {
|
|
|
publicScreenChat = savePublicScreenChat(userId, format, true);
|
|
|
} catch (Exception e) {
|
|
|
String errMsg = String.format("玩家进入大厅,保存信息发生异常[%S]", e);
|
|
|
- exceptionHandle(userId, errMsg);
|
|
|
+ exceptionHandle(userId, new PublicScreenChatExceptionMsg(2, errMsg));
|
|
|
return;
|
|
|
}
|
|
|
sendMessageToOther(clients, JSON.toJSONString(publicScreenChat), PREFIX.concat(userId));
|
|
|
@@ -103,7 +104,7 @@ public class PublicScreenChatWebsocket extends WebsocketCommon {
|
|
|
publicScreenChat = savePublicScreenChat(userId, format, true);
|
|
|
} catch (Exception e) {
|
|
|
String errMsg = String.format("玩家离开大厅,保存信息发生异常[%S]", e);
|
|
|
- exceptionHandle(userId, errMsg);
|
|
|
+ exceptionHandle(userId, new PublicScreenChatExceptionMsg(2, errMsg));
|
|
|
return;
|
|
|
}
|
|
|
sendMessageToOther(clients, JSON.toJSONString(publicScreenChat), PREFIX.concat(userId));
|
|
|
@@ -115,12 +116,12 @@ public class PublicScreenChatWebsocket extends WebsocketCommon {
|
|
|
init();
|
|
|
if (StringUtils.isBlank(message)) {
|
|
|
String errMsg = "Illegal parameter : message can not be null";
|
|
|
- exceptionHandle(userId, errMsg);
|
|
|
+ exceptionHandle(userId, new PublicScreenChatExceptionMsg(4, errMsg));
|
|
|
return;
|
|
|
}
|
|
|
if (!contentAuditService.auditText(message)) {
|
|
|
savePublicScreenChat(userId, message, false);
|
|
|
- exceptionHandle(userId, "消息包含非法内容");
|
|
|
+ exceptionHandle(userId, new PublicScreenChatExceptionMsg(3, "消息包含非法内容"));
|
|
|
return;
|
|
|
}
|
|
|
PublicScreenChat publicScreenChat;
|
|
|
@@ -128,7 +129,7 @@ public class PublicScreenChatWebsocket extends WebsocketCommon {
|
|
|
publicScreenChat = savePublicScreenChat(userId, message, true);
|
|
|
} catch (Exception e) {
|
|
|
String errMsg = String.format("玩家发送消息,保存信息发生异常[%S]", e);
|
|
|
- exceptionHandle(userId, errMsg);
|
|
|
+ exceptionHandle(userId, new PublicScreenChatExceptionMsg(2, errMsg));
|
|
|
return;
|
|
|
}
|
|
|
sendMessageToAll(clients, JSON.toJSONString(publicScreenChat), PREFIX.concat(userId));
|
|
|
@@ -173,8 +174,8 @@ public class PublicScreenChatWebsocket extends WebsocketCommon {
|
|
|
return publicScreenChatRepo.save(publicScreenChat);
|
|
|
}
|
|
|
|
|
|
- private void exceptionHandle(String userId, String msg) {
|
|
|
- log.error(msg);
|
|
|
+ private void exceptionHandle(String userId, PublicScreenChatExceptionMsg msg) {
|
|
|
+ log.error(JSON.toJSONString(msg));
|
|
|
// 推送消息给该玩家
|
|
|
sendMessageTo(clients, JSON.toJSONString(msg), PREFIX.concat(userId));
|
|
|
}
|