public string ApplySwitchBanker(string param) { JObject jobj = JObject.Parse(param); string userCode = jobj["UserCode"].TryParseString(); string targetUserCode = jobj["TargetUserCode"].TryParseString(); string tableCode = jobj["TableCode"].Value <string>(); CGameUser user = GameRecordBll.Instance.GetUser(userCode, tableCode); CGameUser targetUser = GameRecordBll.Instance.GetUser(targetUserCode, tableCode); SendApplySwitchBankerNotice(user, targetUser); return(JsonStringResult.SuccessResult()); }
/// <summary> /// 친구 초대 요청하기 /// </summary> /// <param name="msg"></param> void invite_friend(CPacket msg) { string name = msg.pop_string(); for (int i = 0; i < this.owner.battle_room.get_player_count(); i++) { if (this.owner.battle_room.get_players()[i].player_name.Equals(name)) { CPacket reply = CPacket.create((short)PROTOCOL.DENY_FRIEND_ACK); reply.push(2); //이미 초대 this.owner.send(reply); //초대한 사람에게 거절 메시지 보냄 return; } } CGameUser invite = Program.find_user(name); if (invite != null) { if (invite.battle_room != null) { CPacket reply = CPacket.create((short)PROTOCOL.DENY_FRIEND_ACK); reply.push(4); //이미 게임중 this.owner.send(reply); //초대한 사람에게 거절 메시지 보냄 } else if (this.owner.battle_room.get_player_count() < 4) { this.owner.battle_room.add_player(invite.player); //방에 초대 invite.enter_room(this.owner.battle_room); //방 정보를 줌 CPacket reply = CPacket.create((short)PROTOCOL.INVITE_FRIEND); reply.push(this.owner.player.player_name); invite.send(reply); } else { CPacket deny3 = CPacket.create((short)PROTOCOL.DENY_FRIEND_ACK); deny3.push(3); //최대 인원 this.owner.send(deny3); } } else { CPacket deny1 = CPacket.create((short)PROTOCOL.DENY_FRIEND_ACK); deny1.push(1); //검색 실패 this.owner.send(deny1); } }
public string Settlement(string param) { JObject jobj = JObject.Parse(param); string userCode = jobj["UserCode"].TryParseString(); string targetUserCode = jobj["TargetUserCode"].TryParseString(); string tableCode = jobj["TableCode"].Value <string>(); decimal money = jobj["Money"].TryParseDecimal(2); var result = GameBll.Instance.Settlement(userCode, targetUserCode, tableCode, money); if (result.code == (int)OperateResCodeEnum.成功) { CGameUser user = GameRecordBll.Instance.GetUser(targetUserCode, tableCode); if (user.GameStyle == (int)GameStyleEnum.庄家模式) { Clients.Group(user.GameCode, new string[0]).settlementNotice(targetUserCode, JsonConvert.SerializeObject(user), money); } else if (user.GameStatus == (int)GameStatusEnum.已开始) { Clients.Group(user.GameCode, new string[0]).allReady("游戏已经重新开始!"); } } return(JsonConvert.SerializeObject(result)); }
/// <summary> /// 占座儿 /// </summary> /// <param name="gameTableID"></param> /// <param name="userCode"></param> /// <returns></returns> public APIResultBase ZhanZuoEr(string tableCode, string userCode, string password) { if (tableCode.IsNullOrEmpty() || userCode.IsNullOrEmpty()) { return(JsonModelResult.PackageFail(OperateResCodeEnum.参数错误)); } var lstTables = _repository.GetList(c => c.TableCode == tableCode && c.Password == password).Result; if (lstTables.TotalItemsCount < 1) { return(JsonModelResult.PackageFail(OperateResCodeEnum.参数错误)); } var gameTable = lstTables.Items.First(); //if (gameTable.TableStatus != (int)TableStatusEnum.正常) //{ // return JsonModelResult.PackageFail(OperateResCodeEnum.参数错误); //} if (_repository.Get(c => (c.PlayerUserCode == userCode || c.CreateUserCode == userCode) && c.TableCode != tableCode && c.TableStatus == (int)TableStatusEnum.正常).Result.TotalItemsCount > 0) { return(JsonModelResult.PackageFail(OperateResCodeEnum.时只能创建或占用一个游戏房间)); } CGameUser recordRes = null; using (FriendshipFirstContext context = new FriendshipFirstContext()) { var game = GameBll.Instance.GetGame(gameTable.TableCode); if (game != null) { var data = GameRecordBll.Instance.GetUsers(game.GameCode, context); recordRes = data.FirstOrDefault(c => c.RoundCode == game.CurrentRoundCode && c.UserCode == userCode); if (game.GameStatus == (int)GameStatusEnum.结算中) { //if (recordRes != null) //{ // return JsonModelResult.PackageFail(OperateResCodeEnum.游戏已经开始); //} if (recordRes == null) { return(JsonModelResult.PackageFail(OperateResCodeEnum.游戏已经开始)); } if (recordRes.PlayerStatus != (int)PlayerStatusEnum.已下注) { return(JsonModelResult.PackageFail(OperateResCodeEnum.游戏已经开始)); } } if (recordRes == null) { context.ff_gamerecord.Add(new FF_GameRecord { AddTime = DateTime.Now, BetMoney = 0, IsBanker = false, PlayerStatus = game.GameStyle == (int)GameStyleEnum.自由模式 ? (int)PlayerStatusEnum.已下注 : (int)PlayerStatusEnum.未准备, RoundCode = game.CurrentRoundCode, UserCode = userCode, WinMoney = 0, Balance = 0, GameCode = game.GameCode, IsActivity = true, RoomIndex = data.Count(c => c.RoundCode == game.CurrentRoundCode) }); } else { if (!recordRes.IsActivity) { recordRes.IsActivity = true; } } context.SaveChanges(); if (recordRes == null) { recordRes = context.ff_gamerecord.Join(context.ff_user, g => g.UserCode, u => u.UserCode, (g, u) => new CGameUser { UserName = u.UserName, NickName = u.NickName, HeadImg = u.HeadImg, OpenID = u.OpenID, UserCode = u.UserCode, Balance = g.Balance, BetMoney = g.BetMoney, IsBanker = g.IsBanker, PlayerStatus = g.PlayerStatus, RoundCode = g.RoundCode, WinMoney = g.WinMoney, GameCode = g.GameCode, AddTime = g.AddTime, RoomIndex = g.RoomIndex }).Where(c => c.UserCode == userCode && c.GameCode == game.GameCode).OrderByDescending(c => c.AddTime).FirstOrDefault(); } } //var game = GameBll.Instance.GetGame(gameTable.TableCode); //FF_GameRecord record = null; //if (game != null) //{ // var recordRes = GameRecordBll.Instance.GetRecord(game.CurrentRoundCode, userCode); // if (game.GameStatus == (int)GameStatusEnum.结算中) // { // if (recordRes.code == (int)OperateResCodeEnum.查询不到需要的数据) // { // return JsonModelResult.PackageFail(OperateResCodeEnum.游戏已经开始); // } // var tempRec = ((APISingleModelResult<FF_GameRecord>)recordRes).data; // if (tempRec.PlayerStatus != (int)PlayerStatusEnum.已下注) // { // return JsonModelResult.PackageFail(OperateResCodeEnum.游戏已经开始); // } // } // if (recordRes.code == (int)OperateResCodeEnum.查询不到需要的数据) // { // record = new FF_GameRecord // { // AddTime = DateTime.Now, // BetMoney = 0, // IsBanker = false, // PlayerStatus = (int)PlayerStatusEnum.未准备, // RoundCode = game.CurrentRoundCode, // UserCode = userCode, // WinMoney = 0, // Balance = 0, // GameCode = game.GameCode, // IsActivity = true // }; // GameRecordBll.Instance.Insert(record); // } // else // { // record = ((APISingleModelResult<FF_GameRecord>)recordRes).data; // if (!record.IsActivity) // { // record.IsActivity = true; // GameRecordBll.Instance.Update(record); // } // } //} return(JsonModelResult.PackageSuccess(recordRes)); } }
public CUserPlayState(CGameUser owner) { this.owner = owner; }
public CUserLobbyState(CGameUser owner) { this.owner = owner; }
private void SendReadyStatusNotice(string roomName, string message, string senderUserCode, CGameUser user) { Clients.Group(roomName, new string[0]).receiveReadyNotice(message, senderUserCode, JsonConvert.SerializeObject(user)); }
public void SendOnlineNotice(CGameUser user, string roomName, string chatContent) { Clients.Group(roomName, new string[0]).receiveOnlineNotice(chatContent, JsonConvert.SerializeObject(user)); }
private void SendSwitchBankerNotice(CGameUser user, CGameUser targetUser) { Clients.Group(user.GameCode, new string[0]).receiveSwitchBanker(JsonConvert.SerializeObject(user), JsonConvert.SerializeObject(targetUser)); }
/// <summary> /// 结算 /// </summary> /// <param name="userCode"></param> /// <param name="targetUserCode"></param> /// <param name="gameCode"></param> /// <param name="money"></param> /// <returns></returns> public APIResultBase Settlement(string userCode, string targetUserCode, string gameCode, decimal money) { FF_Game game = null; CGameUser gameUser = null; using (FriendshipFirstContext context = new FriendshipFirstContext()) { game = context.ff_game.Where(c => c.GameCode == gameCode).OrderByDescending(c => c.AddTime).FirstOrDefault(); if (game.GameStatus != (int)GameStatusEnum.已开始 && game.GameStatus != (int)GameStatusEnum.结算中) { return(JsonModelResult.PackageFail(OperateResCodeEnum.参数错误)); } game.GameStatus = (int)GameStatusEnum.结算中; var lstRec = context.ff_gamerecord.Where(c => c.RoundCode == game.CurrentRoundCode); var record = lstRec.FirstOrDefault(c => c.RoundCode == game.CurrentRoundCode && c.UserCode == userCode); var targetRecord = lstRec.FirstOrDefault(c => c.RoundCode == game.CurrentRoundCode && c.UserCode == targetUserCode); record.BetMoney = 0; record.Balance += money; record.WinMoney += money; bool isAllSettlemented = false; if (game.GameStyle == (int)GameStyleEnum.庄家模式) { if (record.IsBanker == false) { record.PlayerStatus = (int)PlayerStatusEnum.已结算; } else if (lstRec.Count(c => c.IsBanker == false && c.PlayerStatus != (int)PlayerStatusEnum.已结算) <= 1) { record.PlayerStatus = (int)PlayerStatusEnum.已结算; } targetRecord.Balance -= money; targetRecord.WinMoney -= money; if (targetRecord.IsBanker == false) { targetRecord.PlayerStatus = (int)PlayerStatusEnum.已结算; } else if (lstRec.Count(c => c.IsBanker == false && c.PlayerStatus != (int)PlayerStatusEnum.已结算) <= 1) { targetRecord.PlayerStatus = (int)PlayerStatusEnum.已结算; } isAllSettlemented = (record.PlayerStatus == (int)PlayerStatusEnum.已结算 && targetRecord.PlayerStatus == (int)PlayerStatusEnum.已结算); } else { record.PlayerStatus = (int)PlayerStatusEnum.已结算; targetRecord.Balance -= money; targetRecord.WinMoney -= money; targetRecord.PlayerStatus = (int)PlayerStatusEnum.已结算; isAllSettlemented = !lstRec.Any(c => c.PlayerStatus != (int)PlayerStatusEnum.已结算 && c.UserCode != userCode && c.UserCode != targetUserCode); } if (isAllSettlemented) { DateTime now = DateTime.Now; var lst = lstRec.ToList(); game.CurrentRoundCode = game.NextRoundCode; game.NextRoundCode = SignUtil.CreateSign(game.BankerCode + RandomUtil.CreateRandomStr(8) + now.Ticks); if (game.GameStyle == (int)GameStyleEnum.庄家模式) { game.GameStatus = (int)GameStatusEnum.已结算; AddUserToNextBankerRound(lst, game, now, context); } else { game.GameStatus = (int)GameStatusEnum.已开始; AddUserToNextFreeModelRound(lst, game, now, context); } } context.SaveChanges(); gameUser = GameRecordBll.Instance.GetUser(userCode, game.GameCode, context); //gameUser = data.Where(c => c.UserCode == userCode && c.GameCode == gameCode).OrderByDescending(c => c.AddTime).FirstOrDefault(); } return(JsonModelResult.PackageSuccess(gameUser)); }