package msg import ( "log" "rocommon" "rocommon/util" "roserver/baseserver/model" model2 "roserver/fruit/model" "roserver/serverproto" ) func init() { log.Println("fruit msg init ..") serverproto.Handle_FRUIT_SSPlayerOnlineNtf = model.HandleBackendMessage(func(ev rocommon.ProcEvent, cliId model.ClientID) { msg := ev.Msg().(*serverproto.SSPlayerOnlineNtf) util.InfoF("receive SSPlayerOnlineNtf msg:%v", msg) player := model2.RoomMgr.AddPlayer(msg.BriefInfo.Uid, msg.BriefInfo.NickName) player.Online = true }) serverproto.Handle_FRUIT_SSPlayerOfflineNtf = model.HandleBackendMessage(func(ev rocommon.ProcEvent, cliId model.ClientID) { msg := ev.Msg().(*serverproto.SSPlayerOfflineNtf) util.InfoF("receive SSPlayerOfflineNtf msg:%v", msg) player := model2.RoomMgr.GetPlayer(msg.Uid) if player != nil { player.Online = false } liveRoom, _ := model2.RoomMgr.GetLiveRoomByUid(msg.Uid) if liveRoom != nil { liveRoom.Leave(msg.Uid) } }) serverproto.Handle_FRUIT_SSGameRoleAddItemListAck = model.HandleBackendMessage(func(ev rocommon.ProcEvent, cliId model.ClientID) { msg := ev.Msg().(*serverproto.SSGameRoleAddItemListAck) util.InfoF("FRUIT: receive SSGameRoleAddItemListAck msg:%v", msg) player := model2.RoomMgr.GetPlayer(msg.Uid) for _, v := range msg.ItemList { if v.Key == int32(serverproto.ResType_Res_Rmb) { player.CoinNum = uint32(v.Value) } else if v.Key == int32(serverproto.ResType_Res_Game_Chip) { player.GameChipNum = uint32(v.Value) } } }) serverproto.Handle_FRUIT_SSGameRoleDeleteItemListAck = model.HandleBackendMessage(func(ev rocommon.ProcEvent, cliId model.ClientID) { msg := ev.Msg().(*serverproto.SSGameRoleDeleteItemListAck) util.InfoF("FRUIT: receive SSGameRoleDeleteItemListAck msg:%v", msg) player := model2.RoomMgr.GetPlayer(msg.Uid) for _, v := range msg.ItemList { if v.Key == int32(serverproto.ResType_Res_Rmb) { player.CoinNum = uint32(v.Value) } else if v.Key == int32(serverproto.ResType_Res_Game_Chip) { player.GameChipNum = uint32(v.Value) } } }) serverproto.Handle_FRUIT_CSFruitJoinReq = model.HandleBackendMessage(func(ev rocommon.ProcEvent, cliId model.ClientID) { msg := ev.Msg().(*serverproto.CSFruitJoinReq) util.InfoF("receive CSFruitJoinReq msg:%v", msg) player := model2.RoomMgr.GetPlayer(msg.Uid) player.Name = msg.Nickname player.HeadId = msg.HeadId player.Level = uint32(msg.Level) player.CoinNum = uint32(msg.ChipNum) fruitGameRoom := model2.RoomMgr.GetFruitGameRoom(msg.Uid) fruitGameRoom.Join(msg.Uid) totalBetInfo := make([]*serverproto.FruitSlotInfo, 0) for slot := 1; slot <= 8; slot++ { betNum := fruitGameRoom.TotalBetInfo[int32(slot)] totalBetInfo = append(totalBetInfo, &serverproto.FruitSlotInfo{ Slot: int32(slot), Num: betNum, }) } myBetInfo := make([]*serverproto.FruitSlotInfo, 0) for slot := 1; slot <= 8; slot++ { betNum := player.CurrBetInfo[int32(slot)] myBetInfo = append(myBetInfo, &serverproto.FruitSlotInfo{ Slot: int32(slot), Num: betNum, }) } ackMsg := &serverproto.SCFruitJoinAck{ Uid: msg.Uid, Error: 0, Stage: fruitGameRoom.Stage, Sec: fruitGameRoom.Sec, MyChipNum: int32(player.CoinNum), PoolChipNum: fruitGameRoom.PoolChipNum, TotalBetInfo: totalBetInfo, MyBetInfo: myBetInfo, SettleHistory: fruitGameRoom.SettleHistory, CurrAwardSlots: fruitGameRoom.CurrAwardSlots, CurrTargetSlot: fruitGameRoom.CurrTargetSlot, PlayerAwardRank: fruitGameRoom.CurrPlayerAwardRank, } model.ServiceReplay(ev, ackMsg) }) serverproto.Handle_FRUIT_CSFruitLeaveReq = model.HandleBackendMessage(func(ev rocommon.ProcEvent, cliId model.ClientID) { msg := ev.Msg().(*serverproto.CSFruitLeaveReq) util.InfoF("receive CSFruitLeaveReq msg:%v", msg) fruitGameRoom := model2.RoomMgr.GetFruitGameRoom(msg.Uid) fruitGameRoom.Leave(msg.Uid) ackMsg := &serverproto.SCFruitLeaveAck{ Uid: msg.Uid, Error: 0, } model.ServiceReplay(ev, ackMsg) }) serverproto.Handle_FRUIT_CSFruitBetReq = model.HandleBackendMessage(func(ev rocommon.ProcEvent, cliId model.ClientID) { msg := ev.Msg().(*serverproto.CSFruitBetReq) util.InfoF("receive CSFruitBetReq msg:%v", msg) uid := msg.Uid fruitGameRoom := model2.RoomMgr.GetFruitGameRoom(msg.Uid) errCode := fruitGameRoom.Bet(msg.Uid, msg.GetBetInfo()) player := model2.RoomMgr.GetPlayer(uid) totalBetInfo := make([]*serverproto.FruitSlotInfo, 0) myBetInfo := make([]*serverproto.FruitSlotInfo, 0) var i int32 for i = 1; i <= 8; i++ { slotTotalBetNum := fruitGameRoom.TotalBetInfo[i] myBetNum := player.CurrBetInfo[i] totalBetInfo = append(totalBetInfo, &serverproto.FruitSlotInfo{ Slot: i, Num: slotTotalBetNum, }) myBetInfo = append(myBetInfo, &serverproto.FruitSlotInfo{ Slot: i, Num: myBetNum, }) } ackMsg := &serverproto.SCFruitBetAck{ Uid: msg.Uid, Error: int32(errCode), MyChipNum: int32(player.CoinNum), PoolChipNum: uint32(fruitGameRoom.PoolChipNum), TotalBetInfo: totalBetInfo, MyBetInfo: myBetInfo, } model.ServiceReplay(ev, ackMsg) }) serverproto.Handle_FRUIT_CSFruitChatReq = model.HandleBackendMessage(func(ev rocommon.ProcEvent, cliId model.ClientID) { msg := ev.Msg().(*serverproto.CSFruitChatReq) util.InfoF("receive CSFruitChatReq msg:%v", msg) fruitGameRoom := model2.RoomMgr.GetFruitGameRoom(msg.Uid) fruitGameRoom.SendChat(msg.Uid, msg.ChatContent) }) serverproto.Handle_FRUIT_CSLiveRoomJoinReq = model.HandleBackendMessage(func(ev rocommon.ProcEvent, cliId model.ClientID) { msg := ev.Msg().(*serverproto.CSLiveRoomJoinReq) util.InfoF("receive CSLiveRoomJoinReq msg:%v", msg) player := model2.RoomMgr.GetPlayer(msg.Uid) player.Name = msg.PlayerInfo.Nickname player.HeadId = msg.PlayerInfo.HeadId player.Level = msg.PlayerInfo.Level player.VipLevel = msg.PlayerInfo.VipLevel player.CoinNum = msg.CoinNum player.GameChipNum = msg.GameChipNum oldRoom, _ := model2.RoomMgr.GetLiveRoomByUid(msg.Uid) if oldRoom != nil { oldRoom.Leave(msg.Uid) } liveRoom, err := model2.RoomMgr.FindLiveRoom(msg.Uid, msg.RoomType) if err != nil { ackMsg := &serverproto.SCLiveRoomJoinAck{ Uid: msg.Uid, Error: int32(serverproto.ErrorCode_ERROR_LIVEROOM_NOT_FIND_ROOM), } model.ServiceReplay(ev, ackMsg) return } liveRoom.Join(msg.Uid) ackMsg := &serverproto.SCLiveRoomJoinAck{ Uid: msg.Uid, Error: int32(serverproto.ErrorCode_ERROR_OK), RoomType: liveRoom.RoomType(), RoomId: liveRoom.RoomId(), Heart: liveRoom.Heart(), StageSec: liveRoom.StageSec(), StageTimerSec: liveRoom.StageTimerSec(), Stage: liveRoom.Stage(), IsReady: liveRoom.IsReady(msg.Uid), GiftRecords: liveRoom.GiftRecords(), ChatDatas: liveRoom.ChatRecords(), RoomState: liveRoom.RoomState(), ReadyPlayerInfoList: liveRoom.GetReadyPlayerInfoList(msg.Uid), RoomUserNum: liveRoom.RoomUserNum(), RoomUserHeads: liveRoom.RoomUserHeads(), } model.ServiceReplay(ev, ackMsg) }) serverproto.Handle_FRUIT_CSLiveRoomLeaveReq = model.HandleBackendMessage(func(ev rocommon.ProcEvent, cliId model.ClientID) { msg := ev.Msg().(*serverproto.CSLiveRoomLeaveReq) util.InfoF("receive CSLiveRoomLeaveReq msg:%v", msg) liveRoom, _ := model2.RoomMgr.GetLiveRoomByRoomId(msg.RoomId) if liveRoom != nil { liveRoom.Leave(msg.Uid) ackMsg := &serverproto.SCLiveRoomLeaveAck{ Uid: msg.Uid, RoomId: liveRoom.RoomId(), Error: 0, } model.ServiceReplay(ev, ackMsg) } }) serverproto.Handle_FRUIT_CSLiveRoomChatReq = model.HandleBackendMessage(func(ev rocommon.ProcEvent, cliId model.ClientID) { msg := ev.Msg().(*serverproto.CSLiveRoomChatReq) util.InfoF("receive CSLiveRoomChatReq msg:%v", msg) liveRoom, _ := model2.RoomMgr.GetLiveRoomByRoomId(msg.RoomId) if liveRoom != nil { liveRoom.SendChat(msg.Uid, msg.ChatContent) } }) serverproto.Handle_FRUIT_CSLiveRoomGetReadyReq = model.HandleBackendMessage(func(ev rocommon.ProcEvent, cliId model.ClientID) { msg := ev.Msg().(*serverproto.CSLiveRoomGetReadyReq) util.InfoF("receive CSLiveRoomGetReadyReq msg:%v", msg) liveRoom, _ := model2.RoomMgr.GetLiveRoomByRoomId(msg.RoomId) if liveRoom != nil { errCode := int32(serverproto.ErrorCode_ERROR_OK) if liveRoom.GetReady(msg.Uid) == false { errCode = int32(serverproto.ErrorCode_ERROR_FAIL) } ackMsg := &serverproto.SCLiveRoomGetReadyAck{ Uid: msg.Uid, Error: errCode, IsReady: liveRoom.IsReady(msg.Uid), } model.ServiceReplay(ev, ackMsg) } }) serverproto.Handle_FRUIT_CSLiveRoomSendGiftReq = model.HandleBackendMessage(func(ev rocommon.ProcEvent, cliId model.ClientID) { msg := ev.Msg().(*serverproto.CSLiveRoomSendGiftReq) util.InfoF("receive CSLiveRoomSendGiftReq msg:%v", msg) liveRoom, _ := model2.RoomMgr.GetLiveRoomByRoomId(msg.RoomId) if liveRoom != nil { errCode := int32(serverproto.ErrorCode_ERROR_OK) errCode = liveRoom.SendGift(msg.Uid, msg.GiftId) ackMsg := &serverproto.SCLiveRoomSendGiftAck{ Uid: msg.Uid, RoomId: msg.RoomId, Error: errCode, GiftId: msg.GiftId, } model.ServiceReplay(ev, ackMsg) } }) serverproto.Handle_FRUIT_CSLiveRoomAddHeartReq = model.HandleBackendMessage(func(ev rocommon.ProcEvent, cliId model.ClientID) { msg := ev.Msg().(*serverproto.CSLiveRoomAddHeartReq) util.InfoF("receive CSLiveRoomAddHeartReq msg:%v", msg) liveRoom, _ := model2.RoomMgr.GetLiveRoomByRoomId(msg.RoomId) if liveRoom != nil { heart := liveRoom.AddHeart() ackMsg := &serverproto.SCLiveRoomAddHeartAck{ Uid: msg.Uid, RoomId: msg.RoomId, Heart: heart, } model.ServiceReplay(ev, ackMsg) } }) serverproto.Handle_FRUIT_CSLiveRoomGiftRankReq = model.HandleBackendMessage(func(ev rocommon.ProcEvent, cliId model.ClientID) { msg := ev.Msg().(*serverproto.CSLiveRoomGiftRankReq) util.InfoF("receive CSLiveRoomGiftRankReq msg:%v", msg) liveRoom, _ := model2.RoomMgr.GetLiveRoomByRoomId(msg.RoomId) if liveRoom != nil { ackMsg := &serverproto.SCLiveRoomGiftRankAck{ Uid: msg.Uid, RoomId: msg.RoomId, GiftRank: liveRoom.GiftRank(), } model.ServiceReplay(ev, ackMsg) } }) serverproto.Handle_FRUIT_CSLiveRoomShowSubmitReq = model.HandleBackendMessage(func(ev rocommon.ProcEvent, cliId model.ClientID) { msg := ev.Msg().(*serverproto.CSLiveRoomShowSubmitReq) util.InfoF("receive CSLiveRoomSubmitReq msg:%v", msg) liveRoom, _ := model2.RoomMgr.GetLiveRoomByRoomId(msg.RoomId) if liveRoom != nil { errCode := int32(serverproto.ErrorCode_ERROR_OK) submitResult := liveRoom.ShowSubmit(msg.Uid, msg.SubmitData) if submitResult == nil { errCode = int32(serverproto.ErrorCode_ERROR_FAIL) } ackMsg := &serverproto.SCLiveRoomShowSubmitAck{ Uid: msg.Uid, Error: errCode, SubmitResult: submitResult, } model.ServiceReplay(ev, ackMsg) } }) }