manager_main.go 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191
  1. package manager
  2. import (
  3. "bet24.com/log"
  4. "bet24.com/public"
  5. "bet24.com/servers/micros/audioroom/handler/config"
  6. pb "bet24.com/servers/micros/audioroom/proto"
  7. badge "bet24.com/servers/micros/badge/proto"
  8. userservices "bet24.com/servers/micros/userservices/proto"
  9. "encoding/json"
  10. "fmt"
  11. "strconv"
  12. )
  13. func Run() {
  14. getRoomManager()
  15. }
  16. func DumpRoom(param1, param2 string) {
  17. getRoomManager().dumpRoom(param1)
  18. }
  19. func ClearRoomMic() {
  20. getRoomManager().clearRoomMic()
  21. }
  22. func DumpUser(param1, param2 string) {
  23. getRoomManager().dumpUser(param1)
  24. }
  25. // 获取房主信息
  26. func getOwnerInfo(userId int) (badgeIds []badge.BadgePosition, decorations []userservices.UserDecoration) {
  27. u := userservices.GetUserInfo(userId)
  28. if u != nil {
  29. badgeIds = u.Badges
  30. decorations = u.Decorations
  31. }
  32. return
  33. }
  34. // 获取房主信息列表
  35. func getOwnerList(list []*pb.RoomInfo) interface{} {
  36. var ret []pb.Response_RoomInfo
  37. for _, v := range list {
  38. u := userservices.GetUserInfo(v.UserId)
  39. if u == nil {
  40. continue
  41. }
  42. ret = append(ret, pb.Response_RoomInfo{
  43. RoomInfo: v,
  44. Badges: u.Badges,
  45. Decorations: u.Decorations,
  46. })
  47. }
  48. return ret
  49. }
  50. // 退出房间通知
  51. func ExitRoomNotify(userId, roomId int) {
  52. getRoomManager().exitRoom(userId, roomId)
  53. }
  54. // 上麦回调通知
  55. func OnTheMicNotify(userId, roomId int, streamId string) {
  56. getRoomManager().onTheMicNotify(userId, roomId, streamId)
  57. }
  58. // 下麦回调通知
  59. func OffTheMicNotify(userId, roomId int, streamId string) {
  60. getRoomManager().offTheMicNotify(userId, roomId, streamId)
  61. }
  62. // 获取房间基本信息
  63. func GetRoomInfo(roomId int) *pb.RoomInfo {
  64. return getRoomManager().GetRoomInfo(roomId)
  65. }
  66. // 获取房间基本信息
  67. func GetRoomInfoJson(roomId int, data string) string {
  68. retData := ""
  69. var req pb.Request
  70. if err := json.Unmarshal([]byte(data), &req); err != nil {
  71. retData = fmt.Sprintf("user_audioroom.getAudioRoom unmarshal fail %v", err)
  72. log.Release(retData)
  73. return retData
  74. }
  75. var ret pb.Response_RoomInfo
  76. ret.RoomInfo = getRoomManager().GetRoomInfo(req.RoomId)
  77. if ret.RoomInfo != nil {
  78. ret.Badges, ret.Decorations = getOwnerInfo(ret.RoomInfo.UserId)
  79. }
  80. buf, _ := json.Marshal(ret)
  81. return string(buf)
  82. }
  83. // 登录服务器
  84. func LoginServer(userId int, data string) string {
  85. var ret pb.Response_LoginServer
  86. ret.Success, ret.RoomInfo = getRoomManager().loginServer(userId)
  87. buf, _ := json.Marshal(ret)
  88. return string(buf)
  89. }
  90. // 退出服务器
  91. func LogoutServer(userId int, data string) string {
  92. getRoomManager().logoutServer(userId)
  93. return "1"
  94. }
  95. // 获取房间信息
  96. func GetRoomHotInfo(userId int, data string) string {
  97. retData := ""
  98. var req pb.Request
  99. if err := json.Unmarshal([]byte(data), &req); err != nil {
  100. retData = fmt.Sprintf("user_audioroom.GetRoomHotInfo unmarshal fail %v", err)
  101. log.Release(retData)
  102. return retData
  103. }
  104. var ret pb.Response_RoomHotInfo
  105. info := getRoomManager().GetRoomInfo(req.RoomId)
  106. ret.OnlineCount = info.OnlineCount
  107. buf, _ := json.Marshal(ret)
  108. return string(buf)
  109. }
  110. // 是否允许进入房间
  111. func IsEnterRoom(userId int, data string) string {
  112. retData := ""
  113. var req pb.Request_IsEnterRoom
  114. if err := json.Unmarshal([]byte(data), &req); err != nil {
  115. retData = fmt.Sprintf("user_audioroom.IsEnterRoom unmarshal fail %v", err)
  116. log.Release(retData)
  117. return retData
  118. }
  119. retCode := getRoomManager().isEnterRoom(userId, req.RoomId, req.Password)
  120. return strconv.Itoa(retCode)
  121. }
  122. // 进入房间
  123. func EnterRoom(userId int, data string) string {
  124. retData := ""
  125. var req pb.Request
  126. if err := json.Unmarshal([]byte(data), &req); err != nil {
  127. retData = fmt.Sprintf("EnterRoom unmarshal fail %v", err)
  128. log.Release(retData)
  129. return retData
  130. }
  131. var ret pb.Response_RoomInfo
  132. ret.RoomInfo = getRoomManager().enterRoom(userId, req.RoomId)
  133. if ret.RoomInfo != nil {
  134. ret.Badges, ret.Decorations = getOwnerInfo(ret.RoomInfo.UserId)
  135. }
  136. buf, _ := json.Marshal(ret)
  137. return string(buf)
  138. }
  139. // 退出房间
  140. func ExitRoom(userId int, data string) string {
  141. retData := ""
  142. var req pb.Request
  143. if err := json.Unmarshal([]byte(data), &req); err != nil {
  144. retData = fmt.Sprintf("ExitRoom unmarshal fail %v", err)
  145. log.Release(retData)
  146. return retData
  147. }
  148. retCode := getRoomManager().exitRoom(userId, req.RoomId)
  149. return strconv.Itoa(retCode)
  150. }
  151. // 创建房间
  152. func CreateRoom(userId int, data string) string {
  153. retData := ""
  154. var req pb.Request_CreateRoom
  155. if err := json.Unmarshal([]byte(data), &req); err != nil {
  156. retData = fmt.Sprintf("user_audioroom.CreateRoom unmarshal fail %v", err)
  157. log.Release(retData)
  158. return retData
  159. }
  160. var ret pb.Response_RoomInfo
  161. ret.RoomInfo = getRoomManager().createRoom(userId, req.RoomName, req.Country, req.IpAddress, req.RoomImg, req.Announce, req.Tag)
  162. if ret.RoomInfo != nil {
  163. ret.Badges, ret.Decorations = getOwnerInfo(ret.RoomInfo.UserId)
  164. }
  165. buf, _ := json.Marshal(ret)
  166. return string(buf)
  167. }
  168. // 修改房间
  169. func UpdateRoom(userId int, data string) string {
  170. retData := ""
  171. var req pb.Response_RoomInfo
  172. if err := json.Unmarshal([]byte(data), &req.RoomInfo); err != nil {
  173. retData = fmt.Sprintf("user_audioroom.UpdateRoom unmarshal fail %v", err)
  174. log.Release(retData)
  175. return retData
  176. }
  177. retCode := getRoomManager().updateRoom(userId, req.RoomInfo)
  178. return strconv.Itoa(retCode)
  179. }
  180. // 获取房间封面
  181. func GetRoomImg(userId int, data string) string {
  182. retData := ""
  183. var req pb.Request
  184. if err := json.Unmarshal([]byte(data), &req); err != nil {
  185. retData = fmt.Sprintf("user_audioroom.getRoomImg unmarshal fail %v", err)
  186. log.Release(retData)
  187. return retData
  188. }
  189. // 房间存在,返回房间封面
  190. if info := getRoomManager().GetRoomInfo(req.RoomId); info != nil {
  191. return info.RoomImg
  192. }
  193. // 房间不存在,返回封面预览
  194. return getRoomManager().getRoomImg(req.RoomId)
  195. }
  196. // 修改房间封面
  197. func UpdateRoomImg(userId int, data string) string {
  198. getRoomManager().updateRoomImg(userId, userId, data)
  199. return ""
  200. }
  201. // 获取用户在线房间
  202. func GetOnlineRoom(userId int, data string) string {
  203. retCode := getRoomManager().getOnlineRoom(userId)
  204. return strconv.Itoa(retCode)
  205. }
  206. // 获取探索列表
  207. func GetExploreList(userId int, data string) string {
  208. retData := ""
  209. var req pb.Request_GetPageList
  210. if err := json.Unmarshal([]byte(data), &req); err != nil {
  211. retData = fmt.Sprintf("user_audioroom.GetExploreList unmarshal fail %v", err)
  212. log.Release(retData)
  213. return retData
  214. }
  215. var ret pb.Response_GetPageList
  216. exploreList := getRoomManager().getExploreList()
  217. totalCount := len(exploreList)
  218. start, end := public.SlicePage(req.PageIndex, req.PageSize, totalCount)
  219. ret.RecordCount = totalCount
  220. ret.List = getOwnerList(exploreList[start:end])
  221. buf, _ := json.Marshal(ret)
  222. return string(buf)
  223. }
  224. // 获取加入房间列表
  225. func GetJoinList(userId int, data string) string {
  226. retData := ""
  227. var req pb.Request_GetPageList
  228. if err := json.Unmarshal([]byte(data), &req); err != nil {
  229. retData = fmt.Sprintf("user_audioroom.GetJoinList unmarshal fail %v", err)
  230. log.Release(retData)
  231. return retData
  232. }
  233. var ret pb.Response_GetPageList
  234. joinList := getRoomManager().getJoinList(userId)
  235. totalCount := len(joinList)
  236. start, end := public.SlicePage(req.PageIndex, req.PageSize, totalCount)
  237. ret.RecordCount = totalCount
  238. ret.List = getOwnerList(joinList[start:end])
  239. buf, _ := json.Marshal(ret)
  240. return string(buf)
  241. }
  242. // 获取关注房间列表
  243. func GetAttentionList(userId int, data string) string {
  244. retData := ""
  245. var req pb.Request_GetPageList
  246. if err := json.Unmarshal([]byte(data), &req); err != nil {
  247. retData = fmt.Sprintf("user_audioroom.GetAttentionList unmarshal fail %v", err)
  248. log.Release(retData)
  249. return retData
  250. }
  251. var ret pb.Response_GetPageList
  252. attentionList := getRoomManager().getAttentionList(userId)
  253. totalCount := len(attentionList)
  254. start, end := public.SlicePage(req.PageIndex, req.PageSize, totalCount)
  255. ret.RecordCount = totalCount
  256. ret.List = getOwnerList(attentionList[start:end])
  257. buf, _ := json.Marshal(ret)
  258. return string(buf)
  259. }
  260. // 获取浏览房间列表
  261. func GetBrowseList(userId int, data string) string {
  262. retData := ""
  263. var req pb.Request_GetPageList
  264. if err := json.Unmarshal([]byte(data), &req); err != nil {
  265. retData = fmt.Sprintf("user_audioroom.GetBrowseList unmarshal fail %v", err)
  266. log.Release(retData)
  267. return retData
  268. }
  269. var ret pb.Response_GetPageList
  270. browseList := getRoomManager().getBrowseList(userId)
  271. totalCount := len(browseList)
  272. start, end := public.SlicePage(req.PageIndex, req.PageSize, totalCount)
  273. ret.RecordCount = totalCount
  274. ret.List = getOwnerList(browseList[start:end])
  275. buf, _ := json.Marshal(ret)
  276. return string(buf)
  277. }
  278. // 加入(扣费)
  279. func AddJoin(userId int, data string) string {
  280. retData := ""
  281. var req pb.Request_AddJoin
  282. if err := json.Unmarshal([]byte(data), &req); err != nil {
  283. retData = fmt.Sprintf("user_audioroom.AddJoin unmarshal fail %v", err)
  284. log.Release(retData)
  285. return retData
  286. }
  287. retCode := getRoomManager().addJoin(userId, req.RoomId, pb.Role_Member, req.IpAddress)
  288. return strconv.Itoa(retCode)
  289. }
  290. // 取消加入
  291. func DelJoin(userId int, data string) string {
  292. retData := ""
  293. var req pb.Request
  294. if err := json.Unmarshal([]byte(data), &req); err != nil {
  295. retData = fmt.Sprintf("user_audioroom.userId unmarshal fail %v", err)
  296. log.Release(retData)
  297. return retData
  298. }
  299. retCode := getRoomManager().delJoin(userId, req.RoomId)
  300. return strconv.Itoa(retCode)
  301. }
  302. // 关注
  303. func AddAttention(userId int, data string) string {
  304. retData := ""
  305. var req pb.Request
  306. if err := json.Unmarshal([]byte(data), &req); err != nil {
  307. retData = fmt.Sprintf("AddAttention unmarshal fail %v", err)
  308. log.Release(retData)
  309. return retData
  310. }
  311. retCode := getRoomManager().addAttention(userId, req.RoomId)
  312. return strconv.Itoa(retCode)
  313. }
  314. // 取消关注
  315. func DelAttention(userId int, data string) string {
  316. retData := ""
  317. var req pb.Request
  318. if err := json.Unmarshal([]byte(data), &req); err != nil {
  319. retData = fmt.Sprintf("user_audioroom.DelAttention unmarshal fail %v", err)
  320. log.Release(retData)
  321. return retData
  322. }
  323. retCode := getRoomManager().delAttention(userId, req.RoomId)
  324. return strconv.Itoa(retCode)
  325. }
  326. // 发出成员邀请
  327. func InviteJoin(userId int, data string) string {
  328. retData := ""
  329. var req pb.Request_InviteJoin
  330. if err := json.Unmarshal([]byte(data), &req); err != nil {
  331. retData = fmt.Sprintf("user_audioroom.InviteJoin unmarshal fail %v", err)
  332. log.Release(retData)
  333. return retData
  334. }
  335. retCode := getRoomManager().inviteJoin(userId, req.ToUserId, req.RoomId)
  336. return strconv.Itoa(retCode)
  337. }
  338. // 接受成员邀请
  339. func AcceptJoin(userId int, data string) string {
  340. retData := ""
  341. var req pb.Request_AcceptJoin
  342. if err := json.Unmarshal([]byte(data), &req); err != nil {
  343. retData = fmt.Sprintf("user_audioroom.AcceptJoin unmarshal fail %v", err)
  344. log.Release(retData)
  345. return retData
  346. }
  347. retCode := getRoomManager().acceptJoin(userId, req.Code, req.IpAddress)
  348. return strconv.Itoa(retCode)
  349. }
  350. // 获取在线用户列表
  351. func GetOnlineUsers(userId int, data string) string {
  352. retData := ""
  353. var req pb.Request_GetPageList
  354. if err := json.Unmarshal([]byte(data), &req); err != nil {
  355. retData = fmt.Sprintf("user_audioroom.GetOnlineUsers unmarshal fail %v", err)
  356. log.Release(retData)
  357. return retData
  358. }
  359. var ret pb.Response_GetPageList
  360. onlineList := getRoomManager().GetOnlineUsers(req.RoomId)
  361. totalCount := len(onlineList)
  362. start, end := public.SlicePage(req.PageIndex, req.PageSize, totalCount)
  363. ret.RecordCount = totalCount
  364. ret.List = onlineList[start:end]
  365. buf, _ := json.Marshal(ret)
  366. return string(buf)
  367. }
  368. // 查询房间在线用户信息
  369. func SearchUser(userId int, data string) string {
  370. retData := ""
  371. var req pb.Request_ToUser
  372. if err := json.Unmarshal([]byte(data), &req); err != nil {
  373. retData = fmt.Sprintf("user_audioroom.SearchUser unmarshal fail %v", err)
  374. log.Release(retData)
  375. return retData
  376. }
  377. ret := getRoomManager().searchUser(userId, req.ToUserId, req.RoomId)
  378. buf, _ := json.Marshal(ret)
  379. return string(buf)
  380. }
  381. // 获取成员列表
  382. func GetMembers(userId int, data string) string {
  383. retData := ""
  384. var req pb.Request_GetPageList
  385. if err := json.Unmarshal([]byte(data), &req); err != nil {
  386. retData = fmt.Sprintf("user_audioroom.GetMembers unmarshal fail %v", err)
  387. log.Release(retData)
  388. return retData
  389. }
  390. var ret pb.Response_GetPageList
  391. memberList := getRoomManager().getMembers(req.RoomId)
  392. totalCount := len(memberList)
  393. start, end := public.SlicePage(req.PageIndex, req.PageSize, totalCount)
  394. ret.RecordCount = totalCount
  395. ret.List = memberList[start:end]
  396. buf, _ := json.Marshal(ret)
  397. return string(buf)
  398. }
  399. // 搜索
  400. func SearchRoom(userId int, data string) string {
  401. retData := ""
  402. var req pb.Request_GetPageList
  403. if err := json.Unmarshal([]byte(data), &req); err != nil {
  404. retData = fmt.Sprintf("user_audioroom.SearchRoom unmarshal fail %v", err)
  405. log.Release(retData)
  406. return retData
  407. }
  408. var ret pb.Response_GetPageList
  409. roomList := getRoomManager().searchRoom(req.RoomName)
  410. totalCount := len(roomList)
  411. start, end := public.SlicePage(req.PageIndex, req.PageSize, totalCount)
  412. ret.RecordCount = totalCount
  413. var list []pb.Response_RoomInfo
  414. for k := range roomList[start:end] {
  415. v := &roomList[k]
  416. u := userservices.GetUserInfo(v.UserId)
  417. if u == nil {
  418. continue
  419. }
  420. list = append(list, pb.Response_RoomInfo{
  421. RoomInfo: v,
  422. Badges: u.Badges,
  423. Decorations: u.Decorations,
  424. })
  425. }
  426. ret.List = list
  427. buf, _ := json.Marshal(ret)
  428. return string(buf)
  429. }
  430. // 推荐用户
  431. func RecommendUser(userId int, data string) string {
  432. list := getRoomManager().recommendUser()
  433. buf, _ := json.Marshal(list)
  434. return string(buf)
  435. }
  436. // 推荐房间
  437. func RecommendRoom(userId int, data string) string {
  438. list := getOwnerList(getRoomManager().recommendRoom())
  439. buf, _ := json.Marshal(list)
  440. return string(buf)
  441. }
  442. // 根据标签获取房间列表
  443. func RoomListByTag(userId int, data string) string {
  444. retData := ""
  445. var req pb.Request_GetPageList
  446. if err := json.Unmarshal([]byte(data), &req); err != nil {
  447. retData = fmt.Sprintf("user_audioroom.RoomListByTag unmarshal fail %v", err)
  448. log.Release(retData)
  449. return retData
  450. }
  451. var ret pb.Response_GetPageList
  452. roomList := getRoomManager().roomListByTag(req.Tag)
  453. totalCount := len(roomList)
  454. start, end := public.SlicePage(req.PageIndex, req.PageSize, totalCount)
  455. ret.RecordCount = totalCount
  456. ret.List = getOwnerList(roomList[start:end])
  457. buf, _ := json.Marshal(ret)
  458. return string(buf)
  459. }
  460. // 上麦
  461. func OnTheMic(userId int, data string) string {
  462. retData := ""
  463. var req pb.Request_Mic
  464. if err := json.Unmarshal([]byte(data), &req); err != nil {
  465. retData = fmt.Sprintf("user_audioroom.OnTheMic unmarshal fail %v", err)
  466. log.Release(retData)
  467. return retData
  468. }
  469. retCode := getRoomManager().onTheMic(userId, req.RoomId, req.SN)
  470. return strconv.Itoa(retCode)
  471. }
  472. // 邀请上麦
  473. func InviteOnTheMic(userId int, data string) string {
  474. retData := ""
  475. var req pb.Request_Mic
  476. if err := json.Unmarshal([]byte(data), &req); err != nil {
  477. retData = fmt.Sprintf("user_audioroom.InviteOnTheMic unmarshal fail %v", err)
  478. log.Release(retData)
  479. return retData
  480. }
  481. retCode := getRoomManager().inviteOnMic(userId, req.RoomId, req.ToUserId)
  482. return strconv.Itoa(retCode)
  483. }
  484. // 踢麦(强制下麦)
  485. func KickMic(userId int, data string) string {
  486. retData := ""
  487. var req pb.Request_Mic
  488. if err := json.Unmarshal([]byte(data), &req); err != nil {
  489. retData = fmt.Sprintf("user_audioroom.KickMic unmarshal fail %v", err)
  490. log.Release(retData)
  491. return retData
  492. }
  493. retCode := getRoomManager().kickMic(userId, req.RoomId, req.ToUserId)
  494. return strconv.Itoa(retCode)
  495. }
  496. // 加解锁麦(status -1=上锁 0=解锁)
  497. func SetMic(userId int, data string) string {
  498. retData := ""
  499. var req pb.Request_Mic
  500. if err := json.Unmarshal([]byte(data), &req); err != nil {
  501. retData = fmt.Sprintf("user_audioroom.SetMic unmarshal fail %v", err)
  502. log.Release(retData)
  503. return retData
  504. }
  505. retCode := getRoomManager().setMic(userId, req.RoomId, req.SN, req.Status)
  506. return strconv.Itoa(retCode)
  507. }
  508. // 获取麦列表
  509. func GetMicList(userId int, data string) string {
  510. retData := ""
  511. var req pb.Request
  512. if err := json.Unmarshal([]byte(data), &req); err != nil {
  513. retData = fmt.Sprintf("user_audioroom.GetMicList unmarshal fail %v", err)
  514. log.Release(retData)
  515. return retData
  516. }
  517. list := getRoomManager().getMicList(userId, req.RoomId)
  518. buf, _ := json.Marshal(list)
  519. return string(buf)
  520. }
  521. // 获取权限
  522. func GetPermission(userId int, data string) string {
  523. retData := ""
  524. var req pb.Request
  525. if err := json.Unmarshal([]byte(data), &req); err != nil {
  526. retData = fmt.Sprintf("user_audioroom.GetPermission unmarshal fail %v", err)
  527. log.Release(retData)
  528. return retData
  529. }
  530. list := getRoomManager().getPermission(userId, req.RoomId)
  531. buf, _ := json.Marshal(list)
  532. return string(buf)
  533. }
  534. // 设置权限
  535. func SetPermission(userId int, data string) string {
  536. retData := ""
  537. var req pb.Request_SetPermission
  538. if err := json.Unmarshal([]byte(data), &req); err != nil {
  539. retData = fmt.Sprintf("user_audioroom.SetPermission unmarshal fail %v", err)
  540. log.Release(retData)
  541. return retData
  542. }
  543. retCode := getRoomManager().setPermission(userId, req.RoomId, req.PermissionType, req.Enabled)
  544. return strconv.Itoa(retCode)
  545. }
  546. // 获取进入房间条件
  547. func GetEnterCondition(userId int, data string) string {
  548. retData := ""
  549. var req pb.Request
  550. if err := json.Unmarshal([]byte(data), &req); err != nil {
  551. retData = fmt.Sprintf("user_audioroom.GetEnterCondition unmarshal fail %v", err)
  552. log.Release(retData)
  553. return retData
  554. }
  555. var ret pb.Response_GetEnterCondition
  556. ret.EnterCondition = getRoomManager().getEnterCondition(userId, req.RoomId)
  557. buf, _ := json.Marshal(ret)
  558. return string(buf)
  559. }
  560. // 设置进入房间条件
  561. func SetEnterCondition(userId int, data string) string {
  562. retData := ""
  563. var req pb.Request_SetEnterCondition
  564. if err := json.Unmarshal([]byte(data), &req); err != nil {
  565. retData = fmt.Sprintf("user_audioroom.SetEnterCondition unmarshal fail %v", err)
  566. log.Release(retData)
  567. return retData
  568. }
  569. retCode := getRoomManager().setEnterCondition(userId, req.RoomId, req.InviteOnly, req.Password, req.IsHide)
  570. return strconv.Itoa(retCode)
  571. }
  572. // 获取黑名单用户列表
  573. func GetBlackList(userId int, data string) string {
  574. retData := ""
  575. var req pb.Request_GetBlackList
  576. if err := json.Unmarshal([]byte(data), &req); err != nil {
  577. retData = fmt.Sprintf("user_audioroom.GetBlackList unmarshal fail %v", err)
  578. log.Release(retData)
  579. return retData
  580. }
  581. var ret pb.Response_GetPageList
  582. blackList := getRoomManager().getBlackList(userId, req.RoomId, req.BlackType)
  583. totalCount := len(blackList)
  584. start, end := public.SlicePage(req.PageIndex, req.PageSize, totalCount)
  585. ret.RecordCount = totalCount
  586. ret.List = blackList[start:end]
  587. buf, _ := json.Marshal(ret)
  588. return string(buf)
  589. }
  590. // 设置黑名单
  591. func AddBlack(userId int, data string) string {
  592. retData := ""
  593. var req pb.Request_Black
  594. if err := json.Unmarshal([]byte(data), &req); err != nil {
  595. retData = fmt.Sprintf("user_audioroom.AddBlack unmarshal fail %v", err)
  596. log.Release(retData)
  597. return retData
  598. }
  599. retCode := getRoomManager().addBlack(userId, req.RoomId, req.ToUserId, req.BlackType, req.Seconds)
  600. return strconv.Itoa(retCode)
  601. }
  602. // 移除黑名单
  603. func RemoveBlack(userId int, data string) string {
  604. retData := ""
  605. var req pb.Request_Black
  606. if err := json.Unmarshal([]byte(data), &req); err != nil {
  607. retData = fmt.Sprintf("user_audioroom.RemoveBlack unmarshal fail %v", err)
  608. log.Release(retData)
  609. return retData
  610. }
  611. retCode := getRoomManager().removeBlack(userId, req.RoomId, req.ToUserId, req.BlackType)
  612. return strconv.Itoa(retCode)
  613. }
  614. // 操作记录
  615. func GetOperateLog(userId int, data string) string {
  616. retData := ""
  617. var req pb.Request_GetOperateLog
  618. if err := json.Unmarshal([]byte(data), &req); err != nil {
  619. retData = fmt.Sprintf("user_audioroom.GetOperateLog unmarshal fail %v", err)
  620. log.Release(retData)
  621. return retData
  622. }
  623. var ret pb.Response_GetPageList
  624. ret.RecordCount, ret.List = getRoomManager().getOperateLog(userId, req.RoomId, req.ToUserId, req.OperateType, req.PageIndex, req.PageSize)
  625. buf, _ := json.Marshal(ret)
  626. return string(buf)
  627. }
  628. // 添加管理员
  629. func AddAdmin(userId int, data string) string {
  630. retData := ""
  631. var req pb.Request_ToUser
  632. if err := json.Unmarshal([]byte(data), &req); err != nil {
  633. retData = fmt.Sprintf("user_audioroom.AddAdmin unmarshal fail %v", err)
  634. log.Release(retData)
  635. return retData
  636. }
  637. retCode := getRoomManager().addAdmin(userId, req.RoomId, req.ToUserId)
  638. return strconv.Itoa(retCode)
  639. }
  640. // 取消管理员
  641. func DelAdmin(userId int, data string) string {
  642. retData := ""
  643. var req pb.Request_ToUser
  644. if err := json.Unmarshal([]byte(data), &req); err != nil {
  645. retData = fmt.Sprintf("user_audioroom.DelAdmin unmarshal fail %v", err)
  646. log.Release(retData)
  647. return retData
  648. }
  649. retCode := getRoomManager().delAdmin(userId, req.RoomId, req.ToUserId)
  650. return strconv.Itoa(retCode)
  651. }
  652. // 取消会员
  653. func DelMember(userId int, data string) string {
  654. retData := ""
  655. var req pb.Request_ToUser
  656. if err := json.Unmarshal([]byte(data), &req); err != nil {
  657. retData = fmt.Sprintf("user_audioroom.DelMember unmarshal fail %v", err)
  658. log.Release(retData)
  659. return retData
  660. }
  661. retCode := getRoomManager().delMember(userId, req.RoomId, req.ToUserId)
  662. return strconv.Itoa(retCode)
  663. }
  664. // 是否关注过房间
  665. func IsAttention(userId int, data string) string {
  666. retData := ""
  667. var req pb.Request
  668. if err := json.Unmarshal([]byte(data), &req); err != nil {
  669. retData = fmt.Sprintf("user_audioroom.IsAttention unmarshal fail %v", err)
  670. log.Release(retData)
  671. return retData
  672. }
  673. retCode := getRoomManager().isAttention(userId, req.RoomId)
  674. return strconv.Itoa(retCode)
  675. }
  676. // 发送礼物
  677. func SendGiving(userId int, data string) string {
  678. retData := ""
  679. var req pb.Request_SendGiving
  680. if err := json.Unmarshal([]byte(data), &req); err != nil {
  681. retData = fmt.Sprintf("user_audioroom.SendGiving unmarshal fail %v", err)
  682. log.Release(retData)
  683. return retData
  684. }
  685. var ret pb.Response_SendGiving
  686. ret.Request_SendGiving = req
  687. ret.RetCode, ret.Message = getRoomManager().sendGiving(userId, req.RoomId, req.ToUserId, req.GiftId, req.Num)
  688. buf, _ := json.Marshal(ret)
  689. return string(buf)
  690. }
  691. // 获取系统任务
  692. func GetSysTask(userId int, data string) string {
  693. retData := ""
  694. var req pb.Request_SysFlag
  695. if err := json.Unmarshal([]byte(data), &req); err != nil {
  696. retData = fmt.Sprintf("user_audioroom.GetSysTask unmarshal fail %v", err)
  697. log.Release(retData)
  698. return retData
  699. }
  700. var ret pb.Response_GetPageList
  701. ret.List = config.Mgr.GetSysTask(req.SysFlag)
  702. buf, _ := json.Marshal(ret)
  703. return string(buf)
  704. }
  705. // 获取升级配置
  706. func GetUpgradeConfig(userId int, data string) string {
  707. retData := ""
  708. var req pb.Request_SysFlag
  709. if err := json.Unmarshal([]byte(data), &req); err != nil {
  710. retData = fmt.Sprintf("user_audioroom.GetUpgradeConfig unmarshal fail %v", err)
  711. log.Release(retData)
  712. return retData
  713. }
  714. var ret pb.Response_GetPageList
  715. ret.List = config.Mgr.GetUpgradeConfig(req.SysFlag)
  716. buf, _ := json.Marshal(ret)
  717. return string(buf)
  718. }
  719. // 获取房间任务列表
  720. func GetTaskList(userId int, data string) string {
  721. retData := ""
  722. var req pb.Request
  723. if err := json.Unmarshal([]byte(data), &req); err != nil {
  724. retData = fmt.Sprintf("user_audioroom.GetTaskList unmarshal fail %v", err)
  725. log.Release(retData)
  726. return retData
  727. }
  728. var ret pb.Response_GetPageList
  729. ret.List = getRoomManager().getTaskList(userId, req.RoomId)
  730. buf, _ := json.Marshal(ret)
  731. return string(buf)
  732. }
  733. // 获取昨天收集信息
  734. func GetCollect(userId int, data string) string {
  735. retData := ""
  736. var req pb.Request
  737. if err := json.Unmarshal([]byte(data), &req); err != nil {
  738. retData = fmt.Sprintf("user_audioroom.GetCollect unmarshal fail %v", err)
  739. log.Release(retData)
  740. return retData
  741. }
  742. var ret pb.Response_GetPageList
  743. ret.List = getRoomManager().getCollect(userId, req.RoomId)
  744. buf, _ := json.Marshal(ret)
  745. return string(buf)
  746. }
  747. // 领取收集奖励
  748. func GiftCollect(userId int, data string) string {
  749. retData := ""
  750. var req pb.Request
  751. if err := json.Unmarshal([]byte(data), &req); err != nil {
  752. retData = fmt.Sprintf("user_audioroom.GiftCollect unmarshal fail %v", err)
  753. log.Release(retData)
  754. return retData
  755. }
  756. var ret pb.Response_GiftCollect
  757. ret.RetCode, ret.Message, ret.Items = getRoomManager().giftCollect(userId, req.RoomId)
  758. buf, _ := json.Marshal(ret)
  759. return string(buf)
  760. }
  761. // 获取扩展信息
  762. func GetExtInfo(userId int, data string) string {
  763. retData := ""
  764. var req pb.Request
  765. if err := json.Unmarshal([]byte(data), &req); err != nil {
  766. retData = fmt.Sprintf("user_audioroom.GetExtInfo unmarshal fail %v", err)
  767. log.Release(retData)
  768. return retData
  769. }
  770. var ret pb.Response_RoomExtInfo
  771. ret.RoomExtInfo = getRoomManager().getRoomExtInfo(req.RoomId)
  772. buf, _ := json.Marshal(ret)
  773. return string(buf)
  774. }
  775. // 获取用户房间任务列表
  776. func GetUserTaskList(userId int, data string) string {
  777. retData := ""
  778. var req pb.Request
  779. if err := json.Unmarshal([]byte(data), &req); err != nil {
  780. retData = fmt.Sprintf("user_audioroom.GetUserTaskList unmarshal fail %v", err)
  781. log.Release(retData)
  782. return retData
  783. }
  784. var ret pb.Response_GetPageList
  785. ret.List = getRoomManager().getUserTaskList(userId, req.RoomId)
  786. buf, _ := json.Marshal(ret)
  787. return string(buf)
  788. }
  789. // 分享
  790. func Share(userId int, data string) string {
  791. retData := ""
  792. var req pb.Request
  793. if err := json.Unmarshal([]byte(data), &req); err != nil {
  794. retData = fmt.Sprintf("user_audioroom.Share unmarshal fail %v", err)
  795. log.Release(retData)
  796. return retData
  797. }
  798. var ret pb.RetMsg
  799. ret.RetCode, ret.Message = getRoomManager().share(userId, req.RoomId)
  800. buf, _ := json.Marshal(ret)
  801. return string(buf)
  802. }
  803. // 发送短信
  804. func SendMessage(userId int, data string) string {
  805. retData := ""
  806. var req pb.Request
  807. if err := json.Unmarshal([]byte(data), &req); err != nil {
  808. retData = fmt.Sprintf("user_audioroom.SendMessage unmarshal fail %v", err)
  809. log.Release(retData)
  810. return retData
  811. }
  812. var ret pb.RetMsg
  813. ret.RetCode, ret.Message = getRoomManager().sendMessage(userId, req.RoomId)
  814. buf, _ := json.Marshal(ret)
  815. return string(buf)
  816. }
  817. // 用户房间信息
  818. func GetUserRoomInfo(userId int, data string) string {
  819. retData := ""
  820. var req pb.Request
  821. if err := json.Unmarshal([]byte(data), &req); err != nil {
  822. retData = fmt.Sprintf("user_audioroom.GetUserRoomInfo unmarshal fail %v", err)
  823. log.Release(retData)
  824. return retData
  825. }
  826. var ret pb.Response_GetUserRoomInfo
  827. info := getRoomManager().getUserRoomInfo(userId, req.RoomId)
  828. ret.Level = info.Level
  829. ret.Exps = info.Exps
  830. buf, _ := json.Marshal(ret)
  831. return string(buf)
  832. }
  833. // 获取用户任务统计
  834. func GetUserRoomTaskStat(userId int, data string) string {
  835. var ret pb.Response_List
  836. ret.List = getRoomManager().getUserRoomTaskStat(userId)
  837. buf, _ := json.Marshal(ret)
  838. return string(buf)
  839. }
  840. // 获取游戏列表
  841. func GetGameList(userId int, data string) string {
  842. retData := ""
  843. var req pb.Request
  844. if err := json.Unmarshal([]byte(data), &req); err != nil {
  845. retData = fmt.Sprintf("user_audioroom.GetGameList unmarshal fail %v", err)
  846. log.Release(retData)
  847. return retData
  848. }
  849. // 游戏列表
  850. games := config.Mgr.GetGameList()
  851. // 拷贝数据
  852. list := make([]pb.GameConfig, len(games))
  853. copy(list, games)
  854. // 房间是否有游戏信息
  855. for i := 0; i < len(list); i++ {
  856. v := &list[i]
  857. if len(v.GameRules) <= 0 {
  858. continue
  859. }
  860. // 是否有权限
  861. v.IsShow = getRoomManager().isGamePermission(userId, req.RoomId, v.Id)
  862. // 是否开启游戏
  863. if g := getRoomManager().getGameRoomList(req.RoomId, v.Id); len(g) > 0 {
  864. v.StartGameRoom = true
  865. }
  866. }
  867. var ret pb.Response_List
  868. ret.List = list
  869. buf, _ := json.Marshal(ret)
  870. return string(buf)
  871. }
  872. // 获取游戏房间列表
  873. func GetGameRoomList(userId int, data string) string {
  874. var req pb.Request
  875. if err := json.Unmarshal([]byte(data), &req); err != nil {
  876. retData := fmt.Sprintf("user_audioroom.GetGameRoomList unmarshal fail %v", err)
  877. log.Release(retData)
  878. return retData
  879. }
  880. var ret pb.Response_List
  881. ret.List = getRoomManager().getGameRoomList(req.RoomId, req.GameId)
  882. buf, _ := json.Marshal(ret)
  883. return string(buf)
  884. }
  885. // 通知房间
  886. func NotifyRoom(userId int, data string) string {
  887. getRoomManager().notifyRoom(userId)
  888. return ""
  889. }
  890. // 设置屏幕锁(1=锁定,0=解锁)
  891. func SetScreenLock(userId int, data string) string {
  892. retData := ""
  893. var req pb.Request_ScreenLock
  894. if err := json.Unmarshal([]byte(data), &req); err != nil {
  895. retData = fmt.Sprintf("user_audioroom.SetScreenLock unmarshal fail %v", err)
  896. log.Release(retData)
  897. return retData
  898. }
  899. retCode := getRoomManager().setScreenLock(userId, req.RoomId, req.ScreenLock)
  900. return strconv.Itoa(retCode)
  901. }
  902. // 是否禁止发言
  903. func IsBannedSpeak(userId int, data string) string {
  904. retData := "false"
  905. var req pb.Request_ScreenLock
  906. if err := json.Unmarshal([]byte(data), &req); err != nil {
  907. retData = fmt.Sprintf("user_audioroom.IsBannedSpeak unmarshal fail %v", err)
  908. log.Release(retData)
  909. return retData
  910. }
  911. if success := getRoomManager().isBannedSpeak(userId, req.RoomId); success {
  912. return "true"
  913. }
  914. return "false"
  915. }
  916. // 麦位申请列表
  917. func GetOnMicApplyList(userId int, data string) string {
  918. retData := ""
  919. var req pb.Request
  920. if err := json.Unmarshal([]byte(data), &req); err != nil {
  921. retData = fmt.Sprintf("user_audioroom.GetOnMicApplyList unmarshal fail %v", err)
  922. log.Release(retData)
  923. return retData
  924. }
  925. list := getRoomManager().getOnMicApplyList(req.RoomId)
  926. buf, _ := json.Marshal(list)
  927. return string(buf)
  928. }
  929. // 申请上麦
  930. func ApplyOnMic(userId int, data string) string {
  931. retData := "false"
  932. var req pb.Request
  933. if err := json.Unmarshal([]byte(data), &req); err != nil {
  934. retData = fmt.Sprintf("user_audioroom.ApplyOnMic unmarshal fail %v", err)
  935. log.Release(retData)
  936. return retData
  937. }
  938. var ret pb.RetMsg
  939. info := getRoomManager().applyOnMic(userId, req.RoomId)
  940. ret.RetCode = info.RetCode
  941. ret.Message = info.Message
  942. buf, _ := json.Marshal(ret)
  943. return string(buf)
  944. }
  945. // 取消申请上麦
  946. func CancelApplyOnMic(userId int, data string) string {
  947. retData := "false"
  948. var req pb.Request
  949. if err := json.Unmarshal([]byte(data), &req); err != nil {
  950. retData = fmt.Sprintf("user_audioroom.CancelApplyOnMic unmarshal fail %v", err)
  951. log.Release(retData)
  952. return retData
  953. }
  954. var ret pb.RetMsg
  955. info := getRoomManager().cancelApplyOnMic(userId, req.RoomId)
  956. ret.RetCode = info.RetCode
  957. ret.Message = info.Message
  958. buf, _ := json.Marshal(ret)
  959. return string(buf)
  960. }
  961. // 处理申请上麦(1=同意 2=拒绝)
  962. func DealApplyOnMic(userId int, data string) string {
  963. retData := "false"
  964. var req pb.Request_Mic
  965. if err := json.Unmarshal([]byte(data), &req); err != nil {
  966. retData = fmt.Sprintf("user_audioroom.DealApplyOnMic unmarshal fail %v", err)
  967. log.Release(retData)
  968. return retData
  969. }
  970. var ret pb.RetMsg
  971. info := getRoomManager().dealApplyOnMic(userId, req.RoomId, req.ToUserId, req.Status)
  972. ret.RetCode = info.RetCode
  973. ret.Message = info.Message
  974. buf, _ := json.Marshal(ret)
  975. return string(buf)
  976. }
  977. // 创建游戏房间
  978. func CreateGameRoom(userId int, data string) string {
  979. var req pb.Request_CreateGameRoom
  980. if err := json.Unmarshal([]byte(data), &req); err != nil {
  981. retData := fmt.Sprintf("user_audioroom.CreateGameRoom unmarshal fail %v", err)
  982. log.Release(retData)
  983. return retData
  984. }
  985. var ret pb.Response_CreateGameRoom
  986. ret.RetMsg, ret.GameRoomInfo = getRoomManager().createGameRoom(userId, req.RoomId, req.GameId, req.RuleName)
  987. buf, _ := json.Marshal(ret)
  988. return string(buf)
  989. }
  990. // 关闭游戏房间
  991. func CloseGameRoom(userId int, data string) string {
  992. var req pb.Request_CloseGameRoom
  993. if err := json.Unmarshal([]byte(data), &req); err != nil {
  994. retData := fmt.Sprintf("user_audioroom.CloseGameRoom unmarshal fail %v", err)
  995. log.Release(retData)
  996. return retData
  997. }
  998. var ret pb.Response_CloseGameRoom
  999. info := getRoomManager().closeGameRoom(userId, req.RoomId, req.GameId, req.RoomNo)
  1000. ret.RetMsg.RetCode = info.RetCode
  1001. ret.RetMsg.Message = info.Message
  1002. buf, _ := json.Marshal(ret)
  1003. return string(buf)
  1004. }