httpMsgMgr.js 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /**
  2. * 房间管理http接口
  3. */
  4. 'use strict';
  5. var F = require('../common/function');
  6. var C = require('../config/index');
  7. var _ = require('underscore');
  8. _.str = require('underscore.string');
  9. _.v = require('validator');
  10. var co = require('co');
  11. module.exports = function (app) {
  12. var mgr_map = app.common_mgr.mgr_map;
  13. var http_app = app.app;
  14. /**
  15. *
  16. */
  17. http_app.regPost('/imroom/:apiVer/pushUserMsg', function* (ctx) {
  18. yield F.checkParamsNull(ctx, "msg_info");
  19. let msg_info = ctx.I.msg_info;
  20. yield F.assertParamNull(msg_info, "room_id,uid,custom");
  21. let uid = msg_info.uid;
  22. let user_socket_list = yield mgr_map.redis.getUserSocketList(uid);
  23. co(mgr_map.notice.push(user_socket_list, 'sendMessageReport', msg_info));
  24. F.setResJson(ctx, 0);
  25. });
  26. /**
  27. * 4.25.http:往单个房间推送自定义消息(Java→IM)军圣
  28. */
  29. http_app.regPost('/imroom/:apiVer/pushRoomMsg', function* (ctx) {
  30. yield F.checkParamsNull(ctx, "msg_info"); // room_info参数不能为空
  31. let msg_info = ctx.I.msg_info;
  32. yield F.assertParamNull(msg_info, "room_id,custom"); // room_info里的uid 不能为空
  33. let room_id = msg_info.room_id;
  34. if (room_id >= 1 && room_id <= 4) {
  35. yield mgr_map.publicRoom.sendPublicMsgNotice(msg_info);
  36. } else {
  37. let room_socket = yield mgr_map.redis.getRoomSocketList(room_id);
  38. co(mgr_map.notice.push(room_socket, 'sendMessageReport', msg_info));
  39. }
  40. F.setResJson(ctx, 0);
  41. });
  42. /**
  43. * 4.26.http:往所有房间推送自定义消息(Java→IM)军圣
  44. */
  45. http_app.regPost('/imroom/:apiVer/pushAllRoomMsg', function* (ctx) {
  46. yield F.checkParamsNull(ctx, "msg_info"); // room_info参数不能为空
  47. let msg_info = ctx.I.msg_info;
  48. let intercept_room_list = ctx.I.intercept_room_list;
  49. if (F.isNull(intercept_room_list)) {
  50. intercept_room_list = [];
  51. }
  52. let roomid_list = yield mgr_map.redis.getRoomIdsByOnlineNum(1);
  53. if (F.isNull(roomid_list)) {
  54. F.addWebErrLogs("[ 发送全服消息 ] 无超过3人以上的房间。")
  55. F.setResJson(ctx, 0);
  56. }
  57. F.log("err", "%s", [roomid_list]);
  58. for (let i = 0; i < roomid_list.length; i++) {
  59. if (F.isNull(roomid_list[i])) {
  60. continue;
  61. }
  62. if (F.in_array(roomid_list[i], intercept_room_list)) {
  63. F.addDebugLogs(["[ 发送全服消息 ]该房间在过滤列表中", intercept_room_list, roomid_list[i]]);
  64. continue;
  65. }
  66. let room_socket = yield mgr_map.redis.getRoomSocketList(roomid_list[i]);
  67. co(mgr_map.notice.push(room_socket, 'sendMessageReport', msg_info));
  68. }
  69. F.setResJson(ctx, 0);
  70. });
  71. };