public void CallBack(object state) { //倒计时后自动解散牌桌用户体验不好, 应倒计时后自动为玩家选择确定 var countdownInfo = state as CountdownInfo; RoomClear r = Gongyong.roomclear.Find(u => u.RoomID == countdownInfo.roomID); if (r == null) { return; } int messageNum = (GameInformationBase.BASEAGREEMENTNUMBER + 5005); List <SendJsInfo> list = new List <SendJsInfo>(); foreach (var item in r.RoomPeo) { var jsInfo = SendJSIdea.CreateBuilder().SetRoomid(countdownInfo.roomID).SetOpenid(item).SetState(1).Build(); byte[] rbyte = jsInfo.ToByteArray(); list.Add(new SendJsInfo { data = rbyte, OpenID = item }); } foreach (var item in list) { new ClearByUser().ExecuteCommand(Gongyong.userlist.Find(u => u.openid.Equals(item.OpenID)).session, new ProtobufRequestInfo { Body = item.data, Key = messageNum.ToString(), Messagelength = item.data.Length, MessageNum = messageNum, MessageResNum = 0 }); } }
/// <summary> /// 解散牌桌 /// </summary> /// <param name="roomId"></param> /// <param name="MessageNum"></param> public void DisbandTable(object state) { var countdownInfo = state as CountdownInfo; RoomClear r = Gongyong.roomclear.Find(u => u.RoomID == countdownInfo.roomID); if (r == null) { return; } ThreadUtility.RemoveManagedThreadByRoomID(countdownInfo.roomID);//取消托管 List <mjuser> listmj = Gongyong.mulist.FindAll(u => u.RoomID == countdownInfo.roomID); var senddjs = ReturnDJS.CreateBuilder(); CardUser card = Gongyong.FKUser.Find(u => u.roomid == countdownInfo.roomID); string userWinLose = string.Empty; foreach (var item in listmj) { UserInfo gamer = Gongyong.userlist.Find(u => u.openid == item.Openid); if (gamer == null) { continue; } var users = Userinfo.CreateBuilder().SetHeadimg(gamer.headimg).SetNickname(gamer.nickname).SetOpenid(gamer.openid).SetSex(int.Parse(gamer.sex)).SetUserFW(item.ZS_Fw).SetUserBean(0).SetUserGold(0).SetUserID(gamer.UserID).Build(); var jsddr = UserAJS.CreateBuilder(); jsddr.SetUser(users); jsddr.SetZdou(item.zwd_count); jsddr.SetZimo(item.zm_count); jsddr.SetAndou(item.ad_count); jsddr.SetMdou(item.MD_count); jsddr.SetDianpao(item.dp_count); switch (item.ZS_Fw) { case 1: jsddr.SetScare(card == null ? 0 : card.dong); break; case 2: jsddr.SetScare(card == null ? 0 : card.nan); break; case 3: jsddr.SetScare(card == null ? 0 : card.xi); break; case 4: jsddr.SetScare(card == null ? 0 : card.bei); break; default: break; } senddjs.AddUserjs(jsddr); senddjs.SetState(2); if (!string.IsNullOrEmpty(userWinLose)) { userWinLose += "|"; } userWinLose += gamer.UserID + "," + jsddr.Scare; } senddjs.SetState(2); Gongyong.mulist.RemoveAll(u => u.RoomID == countdownInfo.roomID); var roomInfo = Gongyong.roomlist.Find(w => w.RoomID == countdownInfo.roomID); Gongyong.roomlist.RemoveAll(u => u.RoomID == countdownInfo.roomID); var alldata = ReturnAllIdea.CreateBuilder().SetState(1).SetMessgaeType(3).Build(); byte[] bytesss = alldata.ToByteArray(); byte[] bsenddjs = senddjs.Build().ToByteArray(); foreach (var item in listmj) { UserInfo user = Gongyong.userlist.Find(u => u.openid == item.Openid); if (user != null) { user.session.TrySend(new ArraySegment <byte>(CreateHead.CreateMessage(GameInformationBase.BASEAGREEMENTNUMBER + 5007, bytesss.Length, countdownInfo.MessageNum, bytesss)));//yi user.session.TrySend(new ArraySegment <byte>(CreateHead.CreateMessage(GameInformationBase.BASEAGREEMENTNUMBER + 5014, bsenddjs.Length, countdownInfo.MessageNum, bsenddjs))); RedisUtility.Remove(RedisUtility.GetKey(GameInformationBase.COMMUNITYUSERGAME, user.openid, user.unionid)); } } foreach (var item in Gongyong.msg.FindAll(w => w.RoomID == r.RoomID)) { Gongyong.msg.Remove(item); } RedisUtility.Remove(RedisUtility.GetKey(GameInformationBase.COMMUNITYROOMINFO, r.RoomID.ToString(), "")); new RoomInfoDAL().UpdateEndRoomInfoByRoomInfoID(new RoomInfo { RoomInfoID = roomInfo.RoomInfoID, EndTime = DateTime.Now, EndStatus = 3, UserWinLose = userWinLose }); foreach (var item in listmj) { UserInfo user = Gongyong.userlist.Find(u => u.openid == item.Openid); new userRecordLOGDAL().Add(new userRecordlogLOG { UserID = user.UserID, RoomInfoID = roomInfo.RoomInfoID, UserWinLose = userWinLose, EndTime = DateTime.Now, CreateDate = roomInfo.CreateDate, RoomID = r.RoomID }); } }
public void ExecuteCommand(GameSession session, ProtobufRequestInfo requestInfo) { if (!Gongyong.userlist.Any(w => w.session.SessionID.Equals(session.SessionID))) { session.Logger.Debug("ClearByUser : 非法连接"); session.Close(); return; } var getdata = SendJSIdea.ParseFrom(requestInfo.Body); session.Logger.Debug(getdata.ToString()); RoomClear r = Gongyong.roomclear.Find(u => u.RoomID == getdata.Roomid); if (r == null) { return; } else { if (getdata.State == 1) { r.RoomPeo.RemoveAll(u => u == getdata.Openid); if (ThreadUtility.IsExist(r.RoomID.ToString())) { ThreadUtility.StartCountdownRemoveRoomThread(r.RoomID.ToString()); } } else { r.Status = 0; r.RoomPeo.RemoveAll(u => u == getdata.Openid); ThreadUtility.StartCountdownRemoveRoomThread(r.RoomID.ToString()); } List <mjuser> listmj = Gongyong.mulist.FindAll(u => u.RoomID == getdata.Roomid); if (listmj.Count == 0) { return; } int fw = listmj.Find(w => w.Openid.Equals(getdata.Openid)).ZS_Fw; var rdatabyone = ReturnJSByOnew.CreateBuilder().SetNickName(Gongyong.userlist.Find(u => u.openid == getdata.Openid).nickname).SetState(getdata.State).SetFw(fw).Build(); byte[] rd = rdatabyone.ToByteArray(); foreach (var item in listmj) { UserInfo user = Gongyong.userlist.Find(u => u.openid == item.Openid); user.session.Send(new ArraySegment <byte>(CreateHead.CreateMessage(GameInformationBase.BASEAGREEMENTNUMBER + 5006, rd.Length, requestInfo.MessageNum, rd))); } if (r.RoomPeo.Count == 0) { #region 旧代码 /* * //var senddjs = ReturnDJS.CreateBuilder(); * //CardUser card = Gongyong.FKUser.Find(u => u.roomid == getdata.Roomid); * //foreach (var item in Gongyong.mulist.FindAll(u => u.RoomID == getdata.Roomid)) * //{ * // UserInfo gamer = Gongyong.userlist.Find(u => u.openid == item.Openid); * // var users = Userinfo.CreateBuilder().SetHeadimg(gamer.headimg).SetNickname(gamer.nickname).SetOpenid(gamer.openid).SetSex(int.Parse(gamer.sex)).SetUserFW(item.ZS_Fw).SetUserBean(0).SetUserGold(0).Build(); * // var jsddr = UserAJS.CreateBuilder(); * // jsddr.SetUser(users); * // jsddr.SetZdou(item.zwd_count); * // jsddr.SetZimo(item.zm_count); * // jsddr.SetAndou(item.ad_count); * // jsddr.SetMdou(item.MD_count); * // jsddr.SetDianpao(item.dp_count); * * // switch (item.ZS_Fw) * // { * // case 1: * // jsddr.SetScare(card.dong); * // break; * // case 2: * // jsddr.SetScare(card.nan); * // break; * // case 3: * // jsddr.SetScare(card.xi); * // break; * // case 4: * // jsddr.SetScare(card.bei); * // break; * // default: * // break; * // } * // senddjs.AddUserjs(jsddr); * // senddjs.SetState(2); * * //} * * * * * //Gongyong.mulist.RemoveAll(u => u.RoomID == getdata.Roomid); * //Gongyong.roomlist.RemoveAll(u => u.RoomID == getdata.Roomid); * //var alldata = ReturnAllIdea.CreateBuilder().SetState(1).Build(); * //byte[] bytesss = alldata.ToByteArray(); * //byte[] bsenddjs = senddjs.Build().ToByteArray(); * //foreach (var item in listmj) * //{ * // UserInfo user = Gongyong.userlist.Find(u => u.openid == item.Openid); * * // user.session.TrySend(new ArraySegment<byte>(CreateHead.CreateMessage(GameInformationBase.BASEAGREEMENTNUMBER + 5007, bytesss.Length, requestInfo.MessageNum, bytesss))); * // user.session.TrySend(new ArraySegment<byte>(CreateHead.CreateMessage(GameInformationBase.BASEAGREEMENTNUMBER + 5014, bsenddjs.Length, requestInfo.MessageNum, bsenddjs))); * // RedisUtility.GetClient().Remove(RedisUtility.GetKey(GameInformationBase.COMMUNITYUSERGAME, user.openid, user.unionid)); * //} * //RedisUtility.GetClient().Remove(RedisUtility.GetKey(GameInformationBase.COMMUNITYROOMINFO, r.RoomID.ToString(), "")); */ #endregion if (r.Status == 1) { ThreadUtility.RemoveCountdownRemoveRoomThread(r.RoomID.ToString()); CountdownLogic countdownLogic = new CountdownLogic(); countdownLogic.DisbandTable(new CountdownInfo { roomID = r.RoomID, MessageNum = requestInfo.MessageNum }); } else { ThreadUtility.RemoveCountdownRemoveRoomThread(r.RoomID.ToString()); var alldata = ReturnAllIdea.CreateBuilder().SetState(0).SetMessgaeType(0).Build(); byte[] bytesss = alldata.ToByteArray(); foreach (var item in listmj) { UserInfo user = Gongyong.userlist.Find(u => u.openid == item.Openid); user.session.TrySend(new ArraySegment <byte>(CreateHead.CreateMessage(GameInformationBase.BASEAGREEMENTNUMBER + 5007, bytesss.Length, requestInfo.MessageNum, bytesss))); } } Gongyong.roomclear.Remove(r); } } }
/// <summary> /// Removes Listener from RoomClear-Event for this Room /// </summary> /// <param name="listener">Listener to remove</param> public void RemoveRoomClearListener(RoomClear listener) { clearedRoom -= listener; }
/// <summary> /// Adds Listener to RoomClear-Event for this Room /// </summary> /// <param name="listener">Listener to add</param> public void AddRoomClearListener(RoomClear listener) { clearedRoom += listener; }
public void ExecuteCommand(GameSession session, ProtobufRequestInfo requestInfo) { if (!Gongyong.userlist.Any(w => w.session.SessionID.Equals(session.SessionID))) { session.Logger.Debug("RemoveRoom : 非法连接"); session.Close(); return; } var getdata = SendJS.ParseFrom(requestInfo.Body); mjuser rst = Gongyong.mulist.Find(u => u.Openid == getdata.Openid); int roomid = getdata.Roomid; Room r = Gongyong.roomlist.Find(u => u.RoomID == roomid); if (rst == null) { if (r != null) { if (!Gongyong.mulist.Any(w => w.RoomID == roomid)) { Gongyong.roomlist.Remove(r); RedisUtility.Remove(RedisUtility.GetKey(GameInformationBase.COMMUNITYROOMINFO, r.RoomID.ToString(), "")); } } RedisUtility.Remove(RedisUtility.GetKey(GameInformationBase.COMMUNITYUSERGAME, getdata.Openid, getdata.Unionid)); return; } if (r == null) { return; } int fw = Gongyong.mulist.Find(u => u.Openid == getdata.Openid).ZS_Fw; session.Logger.Debug(Name + "|" + getdata.ToString()); string nickname = Gongyong.userlist.Find(u => u.openid == getdata.Openid).nickname; var disbandedRoomInfo = RedisUtility.Get <DisbandedRoomInfo>((RedisUtility.GetKey(GameInformationBase.COMMUNITYDISBANDED, getdata.Openid, getdata.Unionid))); List <mjuser> listuser = Gongyong.mulist.FindAll(u => u.RoomID == roomid); ///判断游戏是否开始(未开始直接解散,开始则发送消息) if (r.startgame != 1 && rst.IsHomeowner) { new UserExitLogic().DissolutionRoom(r, requestInfo.MessageNum, 1); } else if (disbandedRoomInfo != null && (DateTime.Now - disbandedRoomInfo.Time).TotalSeconds < 5)// { var data = ReturnDisbandedFailure.CreateBuilder().SetStatus(1).Build().ToByteArray(); session.TrySend(new ArraySegment <byte>(CreateHead.CreateMessage(GameInformationBase.BASEAGREEMENTNUMBER + 5010, data.Length, requestInfo.MessageNum, data))); } else { if (disbandedRoomInfo == null) { var disbandedRoom = new DisbandedRoomInfo { OpenID = getdata.Openid, RoomID = roomid, Time = DateTime.Now }; RedisUtility.Set(RedisUtility.GetKey(GameInformationBase.COMMUNITYDISBANDED, getdata.Openid, getdata.Unionid), disbandedRoom, 1); } if (!Gongyong.roomclear.Any(w => w.RoomID == roomid)) { RoomClear rc = new RoomClear() { Status = 1, RoomID = roomid }; var Rdata = ReturnJSMsg.CreateBuilder().SetFw(fw).SetNickName(nickname); byte[] Rtbyte = Rdata.Build().ToByteArray(); foreach (var item in listuser) { if (item.Openid != getdata.Openid) { rc.RoomPeo.Add(item.Openid); } UserInfo user = Gongyong.userlist.Find(u => u.openid == item.Openid); user.session.TrySend(new ArraySegment <byte>(CreateHead.CreateMessage(GameInformationBase.BASEAGREEMENTNUMBER + 5004, Rtbyte.Length, requestInfo.MessageNum, Rtbyte))); } Gongyong.roomclear.Add(rc); ThreadUtility.AddCountdownRemoveRoomThread(roomid.ToString());//当有用户申请解散房间,倒计时开始。 } else { var data = SendJSIdea.CreateBuilder().SetOpenid(getdata.Openid).SetRoomid(roomid).SetState(1).Build().ToByteArray(); // new ArraySegment<byte>(CreateHead.CreateMessage(GameInformationBase.BASEAGREEMENTNUMBER + 5005, data.Length, requestInfo.MessageNum, data)); new ClearByUser().ExecuteCommand(session, new ProtobufRequestInfo { Body = data, Key = (GameInformationBase.BASEAGREEMENTNUMBER + 5005).ToString(), Messagelength = data.Length, MessageNum = GameInformationBase.BASEAGREEMENTNUMBER + 5005, MessageResNum = 0 }); } // ThreadUtility.StartCountdownRemoveRoomThread(roomid.ToString()); } }