| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191 |
- package manager
- import (
- "bet24.com/log"
- "bet24.com/public"
- "bet24.com/servers/micros/audioroom/handler/config"
- pb "bet24.com/servers/micros/audioroom/proto"
- badge "bet24.com/servers/micros/badge/proto"
- userservices "bet24.com/servers/micros/userservices/proto"
- "encoding/json"
- "fmt"
- "strconv"
- )
- func Run() {
- getRoomManager()
- }
- func DumpRoom(param1, param2 string) {
- getRoomManager().dumpRoom(param1)
- }
- func ClearRoomMic() {
- getRoomManager().clearRoomMic()
- }
- func DumpUser(param1, param2 string) {
- getRoomManager().dumpUser(param1)
- }
- // 获取房主信息
- func getOwnerInfo(userId int) (badgeIds []badge.BadgePosition, decorations []userservices.UserDecoration) {
- u := userservices.GetUserInfo(userId)
- if u != nil {
- badgeIds = u.Badges
- decorations = u.Decorations
- }
- return
- }
- // 获取房主信息列表
- func getOwnerList(list []*pb.RoomInfo) interface{} {
- var ret []pb.Response_RoomInfo
- for _, v := range list {
- u := userservices.GetUserInfo(v.UserId)
- if u == nil {
- continue
- }
- ret = append(ret, pb.Response_RoomInfo{
- RoomInfo: v,
- Badges: u.Badges,
- Decorations: u.Decorations,
- })
- }
- return ret
- }
- // 退出房间通知
- func ExitRoomNotify(userId, roomId int) {
- getRoomManager().exitRoom(userId, roomId)
- }
- // 上麦回调通知
- func OnTheMicNotify(userId, roomId int, streamId string) {
- getRoomManager().onTheMicNotify(userId, roomId, streamId)
- }
- // 下麦回调通知
- func OffTheMicNotify(userId, roomId int, streamId string) {
- getRoomManager().offTheMicNotify(userId, roomId, streamId)
- }
- // 获取房间基本信息
- func GetRoomInfo(roomId int) *pb.RoomInfo {
- return getRoomManager().GetRoomInfo(roomId)
- }
- // 获取房间基本信息
- func GetRoomInfoJson(roomId int, data string) string {
- retData := ""
- var req pb.Request
- if err := json.Unmarshal([]byte(data), &req); err != nil {
- retData = fmt.Sprintf("user_audioroom.getAudioRoom unmarshal fail %v", err)
- log.Release(retData)
- return retData
- }
- var ret pb.Response_RoomInfo
- ret.RoomInfo = getRoomManager().GetRoomInfo(req.RoomId)
- if ret.RoomInfo != nil {
- ret.Badges, ret.Decorations = getOwnerInfo(ret.RoomInfo.UserId)
- }
- buf, _ := json.Marshal(ret)
- return string(buf)
- }
- // 登录服务器
- func LoginServer(userId int, data string) string {
- var ret pb.Response_LoginServer
- ret.Success, ret.RoomInfo = getRoomManager().loginServer(userId)
- buf, _ := json.Marshal(ret)
- return string(buf)
- }
- // 退出服务器
- func LogoutServer(userId int, data string) string {
- getRoomManager().logoutServer(userId)
- return "1"
- }
- // 获取房间信息
- func GetRoomHotInfo(userId int, data string) string {
- retData := ""
- var req pb.Request
- if err := json.Unmarshal([]byte(data), &req); err != nil {
- retData = fmt.Sprintf("user_audioroom.GetRoomHotInfo unmarshal fail %v", err)
- log.Release(retData)
- return retData
- }
- var ret pb.Response_RoomHotInfo
- info := getRoomManager().GetRoomInfo(req.RoomId)
- ret.OnlineCount = info.OnlineCount
- buf, _ := json.Marshal(ret)
- return string(buf)
- }
- // 是否允许进入房间
- func IsEnterRoom(userId int, data string) string {
- retData := ""
- var req pb.Request_IsEnterRoom
- if err := json.Unmarshal([]byte(data), &req); err != nil {
- retData = fmt.Sprintf("user_audioroom.IsEnterRoom unmarshal fail %v", err)
- log.Release(retData)
- return retData
- }
- retCode := getRoomManager().isEnterRoom(userId, req.RoomId, req.Password)
- return strconv.Itoa(retCode)
- }
- // 进入房间
- func EnterRoom(userId int, data string) string {
- retData := ""
- var req pb.Request
- if err := json.Unmarshal([]byte(data), &req); err != nil {
- retData = fmt.Sprintf("EnterRoom unmarshal fail %v", err)
- log.Release(retData)
- return retData
- }
- var ret pb.Response_RoomInfo
- ret.RoomInfo = getRoomManager().enterRoom(userId, req.RoomId)
- if ret.RoomInfo != nil {
- ret.Badges, ret.Decorations = getOwnerInfo(ret.RoomInfo.UserId)
- }
- buf, _ := json.Marshal(ret)
- return string(buf)
- }
- // 退出房间
- func ExitRoom(userId int, data string) string {
- retData := ""
- var req pb.Request
- if err := json.Unmarshal([]byte(data), &req); err != nil {
- retData = fmt.Sprintf("ExitRoom unmarshal fail %v", err)
- log.Release(retData)
- return retData
- }
- retCode := getRoomManager().exitRoom(userId, req.RoomId)
- return strconv.Itoa(retCode)
- }
- // 创建房间
- func CreateRoom(userId int, data string) string {
- retData := ""
- var req pb.Request_CreateRoom
- if err := json.Unmarshal([]byte(data), &req); err != nil {
- retData = fmt.Sprintf("user_audioroom.CreateRoom unmarshal fail %v", err)
- log.Release(retData)
- return retData
- }
- var ret pb.Response_RoomInfo
- ret.RoomInfo = getRoomManager().createRoom(userId, req.RoomName, req.Country, req.IpAddress, req.RoomImg, req.Announce, req.Tag)
- if ret.RoomInfo != nil {
- ret.Badges, ret.Decorations = getOwnerInfo(ret.RoomInfo.UserId)
- }
- buf, _ := json.Marshal(ret)
- return string(buf)
- }
- // 修改房间
- func UpdateRoom(userId int, data string) string {
- retData := ""
- var req pb.Response_RoomInfo
- if err := json.Unmarshal([]byte(data), &req.RoomInfo); err != nil {
- retData = fmt.Sprintf("user_audioroom.UpdateRoom unmarshal fail %v", err)
- log.Release(retData)
- return retData
- }
- retCode := getRoomManager().updateRoom(userId, req.RoomInfo)
- return strconv.Itoa(retCode)
- }
- // 获取房间封面
- func GetRoomImg(userId int, data string) string {
- retData := ""
- var req pb.Request
- if err := json.Unmarshal([]byte(data), &req); err != nil {
- retData = fmt.Sprintf("user_audioroom.getRoomImg unmarshal fail %v", err)
- log.Release(retData)
- return retData
- }
- // 房间存在,返回房间封面
- if info := getRoomManager().GetRoomInfo(req.RoomId); info != nil {
- return info.RoomImg
- }
- // 房间不存在,返回封面预览
- return getRoomManager().getRoomImg(req.RoomId)
- }
- // 修改房间封面
- func UpdateRoomImg(userId int, data string) string {
- getRoomManager().updateRoomImg(userId, userId, data)
- return ""
- }
- // 获取用户在线房间
- func GetOnlineRoom(userId int, data string) string {
- retCode := getRoomManager().getOnlineRoom(userId)
- return strconv.Itoa(retCode)
- }
- // 获取探索列表
- func GetExploreList(userId int, data string) string {
- retData := ""
- var req pb.Request_GetPageList
- if err := json.Unmarshal([]byte(data), &req); err != nil {
- retData = fmt.Sprintf("user_audioroom.GetExploreList unmarshal fail %v", err)
- log.Release(retData)
- return retData
- }
- var ret pb.Response_GetPageList
- exploreList := getRoomManager().getExploreList()
- totalCount := len(exploreList)
- start, end := public.SlicePage(req.PageIndex, req.PageSize, totalCount)
- ret.RecordCount = totalCount
- ret.List = getOwnerList(exploreList[start:end])
- buf, _ := json.Marshal(ret)
- return string(buf)
- }
- // 获取加入房间列表
- func GetJoinList(userId int, data string) string {
- retData := ""
- var req pb.Request_GetPageList
- if err := json.Unmarshal([]byte(data), &req); err != nil {
- retData = fmt.Sprintf("user_audioroom.GetJoinList unmarshal fail %v", err)
- log.Release(retData)
- return retData
- }
- var ret pb.Response_GetPageList
- joinList := getRoomManager().getJoinList(userId)
- totalCount := len(joinList)
- start, end := public.SlicePage(req.PageIndex, req.PageSize, totalCount)
- ret.RecordCount = totalCount
- ret.List = getOwnerList(joinList[start:end])
- buf, _ := json.Marshal(ret)
- return string(buf)
- }
- // 获取关注房间列表
- func GetAttentionList(userId int, data string) string {
- retData := ""
- var req pb.Request_GetPageList
- if err := json.Unmarshal([]byte(data), &req); err != nil {
- retData = fmt.Sprintf("user_audioroom.GetAttentionList unmarshal fail %v", err)
- log.Release(retData)
- return retData
- }
- var ret pb.Response_GetPageList
- attentionList := getRoomManager().getAttentionList(userId)
- totalCount := len(attentionList)
- start, end := public.SlicePage(req.PageIndex, req.PageSize, totalCount)
- ret.RecordCount = totalCount
- ret.List = getOwnerList(attentionList[start:end])
- buf, _ := json.Marshal(ret)
- return string(buf)
- }
- // 获取浏览房间列表
- func GetBrowseList(userId int, data string) string {
- retData := ""
- var req pb.Request_GetPageList
- if err := json.Unmarshal([]byte(data), &req); err != nil {
- retData = fmt.Sprintf("user_audioroom.GetBrowseList unmarshal fail %v", err)
- log.Release(retData)
- return retData
- }
- var ret pb.Response_GetPageList
- browseList := getRoomManager().getBrowseList(userId)
- totalCount := len(browseList)
- start, end := public.SlicePage(req.PageIndex, req.PageSize, totalCount)
- ret.RecordCount = totalCount
- ret.List = getOwnerList(browseList[start:end])
- buf, _ := json.Marshal(ret)
- return string(buf)
- }
- // 加入(扣费)
- func AddJoin(userId int, data string) string {
- retData := ""
- var req pb.Request_AddJoin
- if err := json.Unmarshal([]byte(data), &req); err != nil {
- retData = fmt.Sprintf("user_audioroom.AddJoin unmarshal fail %v", err)
- log.Release(retData)
- return retData
- }
- retCode := getRoomManager().addJoin(userId, req.RoomId, pb.Role_Member, req.IpAddress)
- return strconv.Itoa(retCode)
- }
- // 取消加入
- func DelJoin(userId int, data string) string {
- retData := ""
- var req pb.Request
- if err := json.Unmarshal([]byte(data), &req); err != nil {
- retData = fmt.Sprintf("user_audioroom.userId unmarshal fail %v", err)
- log.Release(retData)
- return retData
- }
- retCode := getRoomManager().delJoin(userId, req.RoomId)
- return strconv.Itoa(retCode)
- }
- // 关注
- func AddAttention(userId int, data string) string {
- retData := ""
- var req pb.Request
- if err := json.Unmarshal([]byte(data), &req); err != nil {
- retData = fmt.Sprintf("AddAttention unmarshal fail %v", err)
- log.Release(retData)
- return retData
- }
- retCode := getRoomManager().addAttention(userId, req.RoomId)
- return strconv.Itoa(retCode)
- }
- // 取消关注
- func DelAttention(userId int, data string) string {
- retData := ""
- var req pb.Request
- if err := json.Unmarshal([]byte(data), &req); err != nil {
- retData = fmt.Sprintf("user_audioroom.DelAttention unmarshal fail %v", err)
- log.Release(retData)
- return retData
- }
- retCode := getRoomManager().delAttention(userId, req.RoomId)
- return strconv.Itoa(retCode)
- }
- // 发出成员邀请
- func InviteJoin(userId int, data string) string {
- retData := ""
- var req pb.Request_InviteJoin
- if err := json.Unmarshal([]byte(data), &req); err != nil {
- retData = fmt.Sprintf("user_audioroom.InviteJoin unmarshal fail %v", err)
- log.Release(retData)
- return retData
- }
- retCode := getRoomManager().inviteJoin(userId, req.ToUserId, req.RoomId)
- return strconv.Itoa(retCode)
- }
- // 接受成员邀请
- func AcceptJoin(userId int, data string) string {
- retData := ""
- var req pb.Request_AcceptJoin
- if err := json.Unmarshal([]byte(data), &req); err != nil {
- retData = fmt.Sprintf("user_audioroom.AcceptJoin unmarshal fail %v", err)
- log.Release(retData)
- return retData
- }
- retCode := getRoomManager().acceptJoin(userId, req.Code, req.IpAddress)
- return strconv.Itoa(retCode)
- }
- // 获取在线用户列表
- func GetOnlineUsers(userId int, data string) string {
- retData := ""
- var req pb.Request_GetPageList
- if err := json.Unmarshal([]byte(data), &req); err != nil {
- retData = fmt.Sprintf("user_audioroom.GetOnlineUsers unmarshal fail %v", err)
- log.Release(retData)
- return retData
- }
- var ret pb.Response_GetPageList
- onlineList := getRoomManager().GetOnlineUsers(req.RoomId)
- totalCount := len(onlineList)
- start, end := public.SlicePage(req.PageIndex, req.PageSize, totalCount)
- ret.RecordCount = totalCount
- ret.List = onlineList[start:end]
- buf, _ := json.Marshal(ret)
- return string(buf)
- }
- // 查询房间在线用户信息
- func SearchUser(userId int, data string) string {
- retData := ""
- var req pb.Request_ToUser
- if err := json.Unmarshal([]byte(data), &req); err != nil {
- retData = fmt.Sprintf("user_audioroom.SearchUser unmarshal fail %v", err)
- log.Release(retData)
- return retData
- }
- ret := getRoomManager().searchUser(userId, req.ToUserId, req.RoomId)
- buf, _ := json.Marshal(ret)
- return string(buf)
- }
- // 获取成员列表
- func GetMembers(userId int, data string) string {
- retData := ""
- var req pb.Request_GetPageList
- if err := json.Unmarshal([]byte(data), &req); err != nil {
- retData = fmt.Sprintf("user_audioroom.GetMembers unmarshal fail %v", err)
- log.Release(retData)
- return retData
- }
- var ret pb.Response_GetPageList
- memberList := getRoomManager().getMembers(req.RoomId)
- totalCount := len(memberList)
- start, end := public.SlicePage(req.PageIndex, req.PageSize, totalCount)
- ret.RecordCount = totalCount
- ret.List = memberList[start:end]
- buf, _ := json.Marshal(ret)
- return string(buf)
- }
- // 搜索
- func SearchRoom(userId int, data string) string {
- retData := ""
- var req pb.Request_GetPageList
- if err := json.Unmarshal([]byte(data), &req); err != nil {
- retData = fmt.Sprintf("user_audioroom.SearchRoom unmarshal fail %v", err)
- log.Release(retData)
- return retData
- }
- var ret pb.Response_GetPageList
- roomList := getRoomManager().searchRoom(req.RoomName)
- totalCount := len(roomList)
- start, end := public.SlicePage(req.PageIndex, req.PageSize, totalCount)
- ret.RecordCount = totalCount
- var list []pb.Response_RoomInfo
- for k := range roomList[start:end] {
- v := &roomList[k]
- u := userservices.GetUserInfo(v.UserId)
- if u == nil {
- continue
- }
- list = append(list, pb.Response_RoomInfo{
- RoomInfo: v,
- Badges: u.Badges,
- Decorations: u.Decorations,
- })
- }
- ret.List = list
- buf, _ := json.Marshal(ret)
- return string(buf)
- }
- // 推荐用户
- func RecommendUser(userId int, data string) string {
- list := getRoomManager().recommendUser()
- buf, _ := json.Marshal(list)
- return string(buf)
- }
- // 推荐房间
- func RecommendRoom(userId int, data string) string {
- list := getOwnerList(getRoomManager().recommendRoom())
- buf, _ := json.Marshal(list)
- return string(buf)
- }
- // 根据标签获取房间列表
- func RoomListByTag(userId int, data string) string {
- retData := ""
- var req pb.Request_GetPageList
- if err := json.Unmarshal([]byte(data), &req); err != nil {
- retData = fmt.Sprintf("user_audioroom.RoomListByTag unmarshal fail %v", err)
- log.Release(retData)
- return retData
- }
- var ret pb.Response_GetPageList
- roomList := getRoomManager().roomListByTag(req.Tag)
- totalCount := len(roomList)
- start, end := public.SlicePage(req.PageIndex, req.PageSize, totalCount)
- ret.RecordCount = totalCount
- ret.List = getOwnerList(roomList[start:end])
- buf, _ := json.Marshal(ret)
- return string(buf)
- }
- // 上麦
- func OnTheMic(userId int, data string) string {
- retData := ""
- var req pb.Request_Mic
- if err := json.Unmarshal([]byte(data), &req); err != nil {
- retData = fmt.Sprintf("user_audioroom.OnTheMic unmarshal fail %v", err)
- log.Release(retData)
- return retData
- }
- retCode := getRoomManager().onTheMic(userId, req.RoomId, req.SN)
- return strconv.Itoa(retCode)
- }
- // 邀请上麦
- func InviteOnTheMic(userId int, data string) string {
- retData := ""
- var req pb.Request_Mic
- if err := json.Unmarshal([]byte(data), &req); err != nil {
- retData = fmt.Sprintf("user_audioroom.InviteOnTheMic unmarshal fail %v", err)
- log.Release(retData)
- return retData
- }
- retCode := getRoomManager().inviteOnMic(userId, req.RoomId, req.ToUserId)
- return strconv.Itoa(retCode)
- }
- // 踢麦(强制下麦)
- func KickMic(userId int, data string) string {
- retData := ""
- var req pb.Request_Mic
- if err := json.Unmarshal([]byte(data), &req); err != nil {
- retData = fmt.Sprintf("user_audioroom.KickMic unmarshal fail %v", err)
- log.Release(retData)
- return retData
- }
- retCode := getRoomManager().kickMic(userId, req.RoomId, req.ToUserId)
- return strconv.Itoa(retCode)
- }
- // 加解锁麦(status -1=上锁 0=解锁)
- func SetMic(userId int, data string) string {
- retData := ""
- var req pb.Request_Mic
- if err := json.Unmarshal([]byte(data), &req); err != nil {
- retData = fmt.Sprintf("user_audioroom.SetMic unmarshal fail %v", err)
- log.Release(retData)
- return retData
- }
- retCode := getRoomManager().setMic(userId, req.RoomId, req.SN, req.Status)
- return strconv.Itoa(retCode)
- }
- // 获取麦列表
- func GetMicList(userId int, data string) string {
- retData := ""
- var req pb.Request
- if err := json.Unmarshal([]byte(data), &req); err != nil {
- retData = fmt.Sprintf("user_audioroom.GetMicList unmarshal fail %v", err)
- log.Release(retData)
- return retData
- }
- list := getRoomManager().getMicList(userId, req.RoomId)
- buf, _ := json.Marshal(list)
- return string(buf)
- }
- // 获取权限
- func GetPermission(userId int, data string) string {
- retData := ""
- var req pb.Request
- if err := json.Unmarshal([]byte(data), &req); err != nil {
- retData = fmt.Sprintf("user_audioroom.GetPermission unmarshal fail %v", err)
- log.Release(retData)
- return retData
- }
- list := getRoomManager().getPermission(userId, req.RoomId)
- buf, _ := json.Marshal(list)
- return string(buf)
- }
- // 设置权限
- func SetPermission(userId int, data string) string {
- retData := ""
- var req pb.Request_SetPermission
- if err := json.Unmarshal([]byte(data), &req); err != nil {
- retData = fmt.Sprintf("user_audioroom.SetPermission unmarshal fail %v", err)
- log.Release(retData)
- return retData
- }
- retCode := getRoomManager().setPermission(userId, req.RoomId, req.PermissionType, req.Enabled)
- return strconv.Itoa(retCode)
- }
- // 获取进入房间条件
- func GetEnterCondition(userId int, data string) string {
- retData := ""
- var req pb.Request
- if err := json.Unmarshal([]byte(data), &req); err != nil {
- retData = fmt.Sprintf("user_audioroom.GetEnterCondition unmarshal fail %v", err)
- log.Release(retData)
- return retData
- }
- var ret pb.Response_GetEnterCondition
- ret.EnterCondition = getRoomManager().getEnterCondition(userId, req.RoomId)
- buf, _ := json.Marshal(ret)
- return string(buf)
- }
- // 设置进入房间条件
- func SetEnterCondition(userId int, data string) string {
- retData := ""
- var req pb.Request_SetEnterCondition
- if err := json.Unmarshal([]byte(data), &req); err != nil {
- retData = fmt.Sprintf("user_audioroom.SetEnterCondition unmarshal fail %v", err)
- log.Release(retData)
- return retData
- }
- retCode := getRoomManager().setEnterCondition(userId, req.RoomId, req.InviteOnly, req.Password, req.IsHide)
- return strconv.Itoa(retCode)
- }
- // 获取黑名单用户列表
- func GetBlackList(userId int, data string) string {
- retData := ""
- var req pb.Request_GetBlackList
- if err := json.Unmarshal([]byte(data), &req); err != nil {
- retData = fmt.Sprintf("user_audioroom.GetBlackList unmarshal fail %v", err)
- log.Release(retData)
- return retData
- }
- var ret pb.Response_GetPageList
- blackList := getRoomManager().getBlackList(userId, req.RoomId, req.BlackType)
- totalCount := len(blackList)
- start, end := public.SlicePage(req.PageIndex, req.PageSize, totalCount)
- ret.RecordCount = totalCount
- ret.List = blackList[start:end]
- buf, _ := json.Marshal(ret)
- return string(buf)
- }
- // 设置黑名单
- func AddBlack(userId int, data string) string {
- retData := ""
- var req pb.Request_Black
- if err := json.Unmarshal([]byte(data), &req); err != nil {
- retData = fmt.Sprintf("user_audioroom.AddBlack unmarshal fail %v", err)
- log.Release(retData)
- return retData
- }
- retCode := getRoomManager().addBlack(userId, req.RoomId, req.ToUserId, req.BlackType, req.Seconds)
- return strconv.Itoa(retCode)
- }
- // 移除黑名单
- func RemoveBlack(userId int, data string) string {
- retData := ""
- var req pb.Request_Black
- if err := json.Unmarshal([]byte(data), &req); err != nil {
- retData = fmt.Sprintf("user_audioroom.RemoveBlack unmarshal fail %v", err)
- log.Release(retData)
- return retData
- }
- retCode := getRoomManager().removeBlack(userId, req.RoomId, req.ToUserId, req.BlackType)
- return strconv.Itoa(retCode)
- }
- // 操作记录
- func GetOperateLog(userId int, data string) string {
- retData := ""
- var req pb.Request_GetOperateLog
- if err := json.Unmarshal([]byte(data), &req); err != nil {
- retData = fmt.Sprintf("user_audioroom.GetOperateLog unmarshal fail %v", err)
- log.Release(retData)
- return retData
- }
- var ret pb.Response_GetPageList
- ret.RecordCount, ret.List = getRoomManager().getOperateLog(userId, req.RoomId, req.ToUserId, req.OperateType, req.PageIndex, req.PageSize)
- buf, _ := json.Marshal(ret)
- return string(buf)
- }
- // 添加管理员
- func AddAdmin(userId int, data string) string {
- retData := ""
- var req pb.Request_ToUser
- if err := json.Unmarshal([]byte(data), &req); err != nil {
- retData = fmt.Sprintf("user_audioroom.AddAdmin unmarshal fail %v", err)
- log.Release(retData)
- return retData
- }
- retCode := getRoomManager().addAdmin(userId, req.RoomId, req.ToUserId)
- return strconv.Itoa(retCode)
- }
- // 取消管理员
- func DelAdmin(userId int, data string) string {
- retData := ""
- var req pb.Request_ToUser
- if err := json.Unmarshal([]byte(data), &req); err != nil {
- retData = fmt.Sprintf("user_audioroom.DelAdmin unmarshal fail %v", err)
- log.Release(retData)
- return retData
- }
- retCode := getRoomManager().delAdmin(userId, req.RoomId, req.ToUserId)
- return strconv.Itoa(retCode)
- }
- // 取消会员
- func DelMember(userId int, data string) string {
- retData := ""
- var req pb.Request_ToUser
- if err := json.Unmarshal([]byte(data), &req); err != nil {
- retData = fmt.Sprintf("user_audioroom.DelMember unmarshal fail %v", err)
- log.Release(retData)
- return retData
- }
- retCode := getRoomManager().delMember(userId, req.RoomId, req.ToUserId)
- return strconv.Itoa(retCode)
- }
- // 是否关注过房间
- func IsAttention(userId int, data string) string {
- retData := ""
- var req pb.Request
- if err := json.Unmarshal([]byte(data), &req); err != nil {
- retData = fmt.Sprintf("user_audioroom.IsAttention unmarshal fail %v", err)
- log.Release(retData)
- return retData
- }
- retCode := getRoomManager().isAttention(userId, req.RoomId)
- return strconv.Itoa(retCode)
- }
- // 发送礼物
- func SendGiving(userId int, data string) string {
- retData := ""
- var req pb.Request_SendGiving
- if err := json.Unmarshal([]byte(data), &req); err != nil {
- retData = fmt.Sprintf("user_audioroom.SendGiving unmarshal fail %v", err)
- log.Release(retData)
- return retData
- }
- var ret pb.Response_SendGiving
- ret.Request_SendGiving = req
- ret.RetCode, ret.Message = getRoomManager().sendGiving(userId, req.RoomId, req.ToUserId, req.GiftId, req.Num)
- buf, _ := json.Marshal(ret)
- return string(buf)
- }
- // 获取系统任务
- func GetSysTask(userId int, data string) string {
- retData := ""
- var req pb.Request_SysFlag
- if err := json.Unmarshal([]byte(data), &req); err != nil {
- retData = fmt.Sprintf("user_audioroom.GetSysTask unmarshal fail %v", err)
- log.Release(retData)
- return retData
- }
- var ret pb.Response_GetPageList
- ret.List = config.Mgr.GetSysTask(req.SysFlag)
- buf, _ := json.Marshal(ret)
- return string(buf)
- }
- // 获取升级配置
- func GetUpgradeConfig(userId int, data string) string {
- retData := ""
- var req pb.Request_SysFlag
- if err := json.Unmarshal([]byte(data), &req); err != nil {
- retData = fmt.Sprintf("user_audioroom.GetUpgradeConfig unmarshal fail %v", err)
- log.Release(retData)
- return retData
- }
- var ret pb.Response_GetPageList
- ret.List = config.Mgr.GetUpgradeConfig(req.SysFlag)
- buf, _ := json.Marshal(ret)
- return string(buf)
- }
- // 获取房间任务列表
- func GetTaskList(userId int, data string) string {
- retData := ""
- var req pb.Request
- if err := json.Unmarshal([]byte(data), &req); err != nil {
- retData = fmt.Sprintf("user_audioroom.GetTaskList unmarshal fail %v", err)
- log.Release(retData)
- return retData
- }
- var ret pb.Response_GetPageList
- ret.List = getRoomManager().getTaskList(userId, req.RoomId)
- buf, _ := json.Marshal(ret)
- return string(buf)
- }
- // 获取昨天收集信息
- func GetCollect(userId int, data string) string {
- retData := ""
- var req pb.Request
- if err := json.Unmarshal([]byte(data), &req); err != nil {
- retData = fmt.Sprintf("user_audioroom.GetCollect unmarshal fail %v", err)
- log.Release(retData)
- return retData
- }
- var ret pb.Response_GetPageList
- ret.List = getRoomManager().getCollect(userId, req.RoomId)
- buf, _ := json.Marshal(ret)
- return string(buf)
- }
- // 领取收集奖励
- func GiftCollect(userId int, data string) string {
- retData := ""
- var req pb.Request
- if err := json.Unmarshal([]byte(data), &req); err != nil {
- retData = fmt.Sprintf("user_audioroom.GiftCollect unmarshal fail %v", err)
- log.Release(retData)
- return retData
- }
- var ret pb.Response_GiftCollect
- ret.RetCode, ret.Message, ret.Items = getRoomManager().giftCollect(userId, req.RoomId)
- buf, _ := json.Marshal(ret)
- return string(buf)
- }
- // 获取扩展信息
- func GetExtInfo(userId int, data string) string {
- retData := ""
- var req pb.Request
- if err := json.Unmarshal([]byte(data), &req); err != nil {
- retData = fmt.Sprintf("user_audioroom.GetExtInfo unmarshal fail %v", err)
- log.Release(retData)
- return retData
- }
- var ret pb.Response_RoomExtInfo
- ret.RoomExtInfo = getRoomManager().getRoomExtInfo(req.RoomId)
- buf, _ := json.Marshal(ret)
- return string(buf)
- }
- // 获取用户房间任务列表
- func GetUserTaskList(userId int, data string) string {
- retData := ""
- var req pb.Request
- if err := json.Unmarshal([]byte(data), &req); err != nil {
- retData = fmt.Sprintf("user_audioroom.GetUserTaskList unmarshal fail %v", err)
- log.Release(retData)
- return retData
- }
- var ret pb.Response_GetPageList
- ret.List = getRoomManager().getUserTaskList(userId, req.RoomId)
- buf, _ := json.Marshal(ret)
- return string(buf)
- }
- // 分享
- func Share(userId int, data string) string {
- retData := ""
- var req pb.Request
- if err := json.Unmarshal([]byte(data), &req); err != nil {
- retData = fmt.Sprintf("user_audioroom.Share unmarshal fail %v", err)
- log.Release(retData)
- return retData
- }
- var ret pb.RetMsg
- ret.RetCode, ret.Message = getRoomManager().share(userId, req.RoomId)
- buf, _ := json.Marshal(ret)
- return string(buf)
- }
- // 发送短信
- func SendMessage(userId int, data string) string {
- retData := ""
- var req pb.Request
- if err := json.Unmarshal([]byte(data), &req); err != nil {
- retData = fmt.Sprintf("user_audioroom.SendMessage unmarshal fail %v", err)
- log.Release(retData)
- return retData
- }
- var ret pb.RetMsg
- ret.RetCode, ret.Message = getRoomManager().sendMessage(userId, req.RoomId)
- buf, _ := json.Marshal(ret)
- return string(buf)
- }
- // 用户房间信息
- func GetUserRoomInfo(userId int, data string) string {
- retData := ""
- var req pb.Request
- if err := json.Unmarshal([]byte(data), &req); err != nil {
- retData = fmt.Sprintf("user_audioroom.GetUserRoomInfo unmarshal fail %v", err)
- log.Release(retData)
- return retData
- }
- var ret pb.Response_GetUserRoomInfo
- info := getRoomManager().getUserRoomInfo(userId, req.RoomId)
- ret.Level = info.Level
- ret.Exps = info.Exps
- buf, _ := json.Marshal(ret)
- return string(buf)
- }
- // 获取用户任务统计
- func GetUserRoomTaskStat(userId int, data string) string {
- var ret pb.Response_List
- ret.List = getRoomManager().getUserRoomTaskStat(userId)
- buf, _ := json.Marshal(ret)
- return string(buf)
- }
- // 获取游戏列表
- func GetGameList(userId int, data string) string {
- retData := ""
- var req pb.Request
- if err := json.Unmarshal([]byte(data), &req); err != nil {
- retData = fmt.Sprintf("user_audioroom.GetGameList unmarshal fail %v", err)
- log.Release(retData)
- return retData
- }
- // 游戏列表
- games := config.Mgr.GetGameList()
- // 拷贝数据
- list := make([]pb.GameConfig, len(games))
- copy(list, games)
- // 房间是否有游戏信息
- for i := 0; i < len(list); i++ {
- v := &list[i]
- if len(v.GameRules) <= 0 {
- continue
- }
- // 是否有权限
- v.IsShow = getRoomManager().isGamePermission(userId, req.RoomId, v.Id)
- // 是否开启游戏
- if g := getRoomManager().getGameRoomList(req.RoomId, v.Id); len(g) > 0 {
- v.StartGameRoom = true
- }
- }
- var ret pb.Response_List
- ret.List = list
- buf, _ := json.Marshal(ret)
- return string(buf)
- }
- // 获取游戏房间列表
- func GetGameRoomList(userId int, data string) string {
- var req pb.Request
- if err := json.Unmarshal([]byte(data), &req); err != nil {
- retData := fmt.Sprintf("user_audioroom.GetGameRoomList unmarshal fail %v", err)
- log.Release(retData)
- return retData
- }
- var ret pb.Response_List
- ret.List = getRoomManager().getGameRoomList(req.RoomId, req.GameId)
- buf, _ := json.Marshal(ret)
- return string(buf)
- }
- // 通知房间
- func NotifyRoom(userId int, data string) string {
- getRoomManager().notifyRoom(userId)
- return ""
- }
- // 设置屏幕锁(1=锁定,0=解锁)
- func SetScreenLock(userId int, data string) string {
- retData := ""
- var req pb.Request_ScreenLock
- if err := json.Unmarshal([]byte(data), &req); err != nil {
- retData = fmt.Sprintf("user_audioroom.SetScreenLock unmarshal fail %v", err)
- log.Release(retData)
- return retData
- }
- retCode := getRoomManager().setScreenLock(userId, req.RoomId, req.ScreenLock)
- return strconv.Itoa(retCode)
- }
- // 是否禁止发言
- func IsBannedSpeak(userId int, data string) string {
- retData := "false"
- var req pb.Request_ScreenLock
- if err := json.Unmarshal([]byte(data), &req); err != nil {
- retData = fmt.Sprintf("user_audioroom.IsBannedSpeak unmarshal fail %v", err)
- log.Release(retData)
- return retData
- }
- if success := getRoomManager().isBannedSpeak(userId, req.RoomId); success {
- return "true"
- }
- return "false"
- }
- // 麦位申请列表
- func GetOnMicApplyList(userId int, data string) string {
- retData := ""
- var req pb.Request
- if err := json.Unmarshal([]byte(data), &req); err != nil {
- retData = fmt.Sprintf("user_audioroom.GetOnMicApplyList unmarshal fail %v", err)
- log.Release(retData)
- return retData
- }
- list := getRoomManager().getOnMicApplyList(req.RoomId)
- buf, _ := json.Marshal(list)
- return string(buf)
- }
- // 申请上麦
- func ApplyOnMic(userId int, data string) string {
- retData := "false"
- var req pb.Request
- if err := json.Unmarshal([]byte(data), &req); err != nil {
- retData = fmt.Sprintf("user_audioroom.ApplyOnMic unmarshal fail %v", err)
- log.Release(retData)
- return retData
- }
- var ret pb.RetMsg
- info := getRoomManager().applyOnMic(userId, req.RoomId)
- ret.RetCode = info.RetCode
- ret.Message = info.Message
- buf, _ := json.Marshal(ret)
- return string(buf)
- }
- // 取消申请上麦
- func CancelApplyOnMic(userId int, data string) string {
- retData := "false"
- var req pb.Request
- if err := json.Unmarshal([]byte(data), &req); err != nil {
- retData = fmt.Sprintf("user_audioroom.CancelApplyOnMic unmarshal fail %v", err)
- log.Release(retData)
- return retData
- }
- var ret pb.RetMsg
- info := getRoomManager().cancelApplyOnMic(userId, req.RoomId)
- ret.RetCode = info.RetCode
- ret.Message = info.Message
- buf, _ := json.Marshal(ret)
- return string(buf)
- }
- // 处理申请上麦(1=同意 2=拒绝)
- func DealApplyOnMic(userId int, data string) string {
- retData := "false"
- var req pb.Request_Mic
- if err := json.Unmarshal([]byte(data), &req); err != nil {
- retData = fmt.Sprintf("user_audioroom.DealApplyOnMic unmarshal fail %v", err)
- log.Release(retData)
- return retData
- }
- var ret pb.RetMsg
- info := getRoomManager().dealApplyOnMic(userId, req.RoomId, req.ToUserId, req.Status)
- ret.RetCode = info.RetCode
- ret.Message = info.Message
- buf, _ := json.Marshal(ret)
- return string(buf)
- }
- // 创建游戏房间
- func CreateGameRoom(userId int, data string) string {
- var req pb.Request_CreateGameRoom
- if err := json.Unmarshal([]byte(data), &req); err != nil {
- retData := fmt.Sprintf("user_audioroom.CreateGameRoom unmarshal fail %v", err)
- log.Release(retData)
- return retData
- }
- var ret pb.Response_CreateGameRoom
- ret.RetMsg, ret.GameRoomInfo = getRoomManager().createGameRoom(userId, req.RoomId, req.GameId, req.RuleName)
- buf, _ := json.Marshal(ret)
- return string(buf)
- }
- // 关闭游戏房间
- func CloseGameRoom(userId int, data string) string {
- var req pb.Request_CloseGameRoom
- if err := json.Unmarshal([]byte(data), &req); err != nil {
- retData := fmt.Sprintf("user_audioroom.CloseGameRoom unmarshal fail %v", err)
- log.Release(retData)
- return retData
- }
- var ret pb.Response_CloseGameRoom
- info := getRoomManager().closeGameRoom(userId, req.RoomId, req.GameId, req.RoomNo)
- ret.RetMsg.RetCode = info.RetCode
- ret.RetMsg.Message = info.Message
- buf, _ := json.Marshal(ret)
- return string(buf)
- }
|