public bool AddAuto(GameInfo gameInfo, UserInfo userInfo, bool bAddMoney) { userInfo.Socket = new System.Net.Sockets.Socket(System.Net.Sockets.AddressFamily.InterNetwork, System.Net.Sockets.SocketType.Stream, System.Net.Sockets.ProtocolType.Tcp); Server.GetInstance()._NotifyHandler(NotifyType.Request_Login, userInfo.Socket, userInfo); userInfo = Users.GetInstance().FindUser(userInfo.Id); if (userInfo == null) { return(false); } Random random = new Random(); // added by usc at 2014/03/19 if (bAddMoney) { int nGameMoney = 0; if (gameInfo.nCashOrPointGame == 0) { nGameMoney = userInfo.Cash; } else { nGameMoney = userInfo.Point; } if (nGameMoney < 10000) { int nAddMoney = 15000 + (random.Next() % 100) * 100; Cash.GetInstance().GiveCashOrPoint(userInfo.Id, nAddMoney, gameInfo); if (gameInfo.nCashOrPointGame == 0) { Cash.GetInstance().GiveChargeSum(userInfo.Id, nAddMoney); } } } Server.GetInstance()._NotifyHandler(NotifyType.Request_EnterGame, userInfo.Socket, gameInfo); Server.GetInstance()._NotifyHandler(NotifyType.Request_PlayerEnter, userInfo.Socket, userInfo); bool bFound = false; for (int i = 0; i < _Autos.Count; i++) { if (_Autos[i].Id == userInfo.Id) { bFound = true; break; } } if (!bFound) { //NicknameInfo nameInfo = Database.GetInstance().GetFreeNicknameInfo(); //if (nameInfo.IsValid() == false) // return false; //userInfo.Nickname = nameInfo.Nickname; //Database.GetInstance().UpdateUser(userInfo); //nameInfo.AutoId = userInfo.Id; //nameInfo.StartTime = DateTime.Now; //Database.GetInstance().UpdateNicknameInfo(nameInfo); userInfo.WaitSecond = random.Next() % 30; _Autos.Add(userInfo); } return(true); }
bool OnUserGiveUp(UserInfo userInfo, AddScoreInfo giveInfo) { int wChairID = ((DzCardTable)_GameTable).GetSeatterIndex(userInfo); if (wChairID == GameDefine.INVALID_CHAIR) { return(true); } DzCardInfo dzCardInfo = (DzCardInfo)_GameTable._TableInfo; //重置状态 dzCardInfo.m_cbPlayStatus[wChairID] = false; dzCardInfo.m_cbShowHand[wChairID] = false; //发送消息 AddScoreInfo GiveUp = giveInfo; GiveUp.wAddScoreUser = wChairID; GiveUp.lAddLessScore = -dzCardInfo.m_lTotalScore[wChairID]; _GameTable.BroadCastGame(NotifyType.Reply_GiveUp, GiveUp); //写入金币 //m_pITableFrame->WriteUserScore(wChairID,-m_lTotalScore[wChairID],0,enScoreKind_Lost); int playerIndex = _GameTable.GetPlayerIndex(userInfo); if (playerIndex >= 0) { _GameTable._TableInfo.m_lUserWinScore[playerIndex] = -dzCardInfo.m_lTotalScore[wChairID]; Cash.GetInstance().ProcessGameCash(playerIndex, _GameTable._GameInfo, _GameTable._TableInfo); _GameTable._TableInfo.m_lUserWinScore[playerIndex] = 0; } //清空下注 dzCardInfo.m_lTableScore[wChairID] = 0; //人数统计 int wPlayerCount = 0; for (int i = 0; i < DzCardDefine.GAME_PLAYER; i++) { if (dzCardInfo.m_cbPlayStatus[i] == true) { wPlayerCount++; } } //判断结束 if (wPlayerCount >= 2) { if (dzCardInfo.m_wCurrentUser == wChairID) { OnUserAddScore(wChairID, 0, true); } } else { //OnEventGameEnd(INVALID_CHAIR, NULL, GER_NO_PLAYER); _isEnd = true; } return(true); }
public void NotifyOccured(NotifyType notifyType, Socket socket, BaseInfo baseInfo) { Database database = Database.GetInstance(); Server server = Server.GetInstance(); Users users = Users.GetInstance(); ResultInfo resultInfo = new ResultInfo(); switch (notifyType) { case NotifyType.Request_EnterMeeting: { UserInfo userInfo = Users.GetInstance().FindUser(socket); if (userInfo == null) { SetError(ErrorType.Unknown_User, "알수 없는 사용자입니다."); Main.ReplyError(socket); return; } AskChatInfo askChatInfo = (AskChatInfo)baseInfo; UserInfo targetInfo = Users.GetInstance().FindUser(askChatInfo.TargetId); if (targetInfo == null) { SetError(ErrorType.Unknown_User, "채팅대상이 존재하지 않습니다."); Main.ReplyError(socket); return; } askChatInfo.TargetId = userInfo.Id; server.Send(targetInfo.Socket, NotifyType.Request_EnterMeeting, askChatInfo); } break; case NotifyType.Reply_EnterMeeting: { AskChatInfo askChatInfo = (AskChatInfo)baseInfo; UserInfo targetInfo = Users.GetInstance().FindUser(askChatInfo.TargetId); if (targetInfo == null) { SetError(ErrorType.Unknown_User, "채팅대상이 존재하지 않습니다."); Main.ReplyError(socket); return; } if (askChatInfo.Agree == 0) { server.Send(targetInfo.Socket, NotifyType.Reply_EnterMeeting, askChatInfo); return; } RoomInfo meetingInfo = EnterMeeting(socket, askChatInfo); if (meetingInfo == null) { Main.ReplyError(socket); return; } } break; case NotifyType.Request_OutMeeting: { UserInfo userInfo = OutMeeting(socket); if (userInfo == null) { Main.ReplyError(socket); } } break; case NotifyType.Request_RoomList: { UserInfo userInfo = Users.GetInstance().FindUser(socket); if (userInfo == null) { SetError(ErrorType.Unknown_User, "알수 없는 사용자가 방목록을 요구하였습니다."); Main.ReplyError(socket); return; } List <RoomInfo> rooms = null; if (userInfo.Kind == (int)UserKind.ServiceWoman) { rooms = database.GetAllRooms(); } else { rooms = GetRooms(); } if (rooms == null) { Main.ReplyError(socket); return; } RoomListInfo roomListInfo = new RoomListInfo(); roomListInfo.Rooms = rooms; server.Send(socket, NotifyType.Reply_RoomList, roomListInfo); } break; case NotifyType.Request_MakeRoom: { RoomInfo roomInfo = (RoomInfo)baseInfo; UserInfo userInfo = users.FindUser(socket); if (userInfo == null) { Main.ReplyError(socket); return; } roomInfo.Owner = userInfo.Id; if (database.AddRoom(roomInfo) == false) { Main.ReplyError(socket); return; } string str = string.Format("{0} 님이 방 {1} 을 만들었습니다.", userInfo.Id, roomInfo.Id); LogView.AddLogString(str); server.Send(socket, NotifyType.Reply_MakeRoom, roomInfo); View._isUpdateRoomList = true; ReplyRoomList(); } break; case NotifyType.Request_UpdateRoom: { RoomInfo updateInfo = (RoomInfo)baseInfo; RoomInfo roomInfo = Database.GetInstance().FindRoom(updateInfo.Id); if (roomInfo == null) { Main.ReplyError(socket); return; } roomInfo.Body = updateInfo; if (Database.GetInstance().UpdateRoom(roomInfo) == false) { Main.ReplyError(socket); return; } server.Send(socket, NotifyType.Reply_UpdateRoom, roomInfo); } break; case NotifyType.Request_DelRoom: { RoomInfo delInfo = (RoomInfo)baseInfo; if (FindRoom(delInfo.Id) != null) { SetError(ErrorType.Live_Room, "유저들이 들어있는 방입니다."); Main.ReplyError(socket); return; } if (Database.GetInstance().FindRoom(delInfo.Id) == null) { SetError(ErrorType.Invalid_RoomId, "삭제하려는 방이 없습니다."); Main.ReplyError(socket); return; } if (Database.GetInstance().DelRoom(delInfo.Id) == false) { Main.ReplyError(socket); return; } server.Send(socket, NotifyType.Reply_DelRoom, delInfo); } break; case NotifyType.Request_EnterRoom: { OutRoom(socket); RoomInfo enterInfo = (RoomInfo)baseInfo; UserInfo userInfo = EnterRoom(socket, enterInfo.Id); if (userInfo == null) { Main.ReplyError(socket); return; } } break; case NotifyType.Request_OutRoom: { if (OutRoom(socket) == null) { Main.ReplyError(socket); break; } } break; case NotifyType.Request_RoomDetail: { RoomInfo roomInfo = (RoomInfo)baseInfo; ReplyRoomDetailInfo(roomInfo.Id); } break; case NotifyType.Request_StringChat: { StringInfo stringInfo = (StringInfo)baseInfo; UserInfo userInfo = users.FindUser(socket); if (userInfo == null) { BaseInfo.SetError(ErrorType.Unknown_User, "알수 없는 사용자가 채팅하려고 합니다."); Main.ReplyError(socket); return; } stringInfo.UserId = userInfo.Id; BroadCast(userInfo.RoomId, NotifyType.Reply_StringChat, stringInfo, null); } break; case NotifyType.Request_VoiceChat: { VoiceInfo voiceInfo = (VoiceInfo)baseInfo; UserInfo userInfo = users.FindUser(socket); if (userInfo == null) { BaseInfo.SetError(ErrorType.Unknown_User, "알수 없는 사용자가 채팅하려고 합니다."); Main.ReplyError(socket); return; } voiceInfo.UserId = userInfo.Id; BroadCast(userInfo.RoomId, NotifyType.Reply_VoiceChat, voiceInfo, userInfo.Id); } break; case NotifyType.Request_VideoChat: { VideoInfo videoInfo = (VideoInfo)baseInfo; UserInfo userInfo = users.FindUser(socket); if (userInfo == null) { BaseInfo.SetError(ErrorType.Unknown_User, "알수 없는 사용자가 채팅하려고 합니다."); Main.ReplyError(socket); return; } videoInfo.UserId = userInfo.Id; BroadCast(userInfo.RoomId, NotifyType.Reply_VideoChat, videoInfo, userInfo.Id); } break; case NotifyType.Request_Give: { UserInfo userInfo = users.FindUser(socket); if (userInfo == null) { BaseInfo.SetError(ErrorType.Unknown_User, "알수 없는 사용자가 선물하려고 합니다."); Main.ReplyError(socket); return; } PresentHistoryInfo presentInfo = (PresentHistoryInfo)baseInfo; presentInfo.SendId = userInfo.Id; UserInfo targetInfo = database.FindUser(presentInfo.ReceiveId); if (targetInfo == null) { BaseInfo.SetError(ErrorType.Unknown_User, "받으려는 사용자정보가 정확치 않습니다."); Main.ReplyError(socket); return; } if (Cash.GetInstance().ProcessPresent(presentInfo) == false) { Main.ReplyError(socket); return; } BroadCast(userInfo.RoomId, NotifyType.Reply_Give, baseInfo, null); ReplyRoomDetailInfo(userInfo.RoomId); users.ReplyUserList(null); View._isUpdateUserList = true; } break; case NotifyType.Request_MusiceInfo: { UserInfo userInfo = users.FindUser(socket); if (userInfo == null) { BaseInfo.SetError(ErrorType.Unknown_User, "不明会员准备删除过照片信息."); Main.ReplyError(socket); return; } MusiceInfo musiceInfo = (MusiceInfo)baseInfo; BroadCast(userInfo.RoomId, NotifyType.Reply_MusiceInfo, musiceInfo, null); //server.Send(socket, NotifyType.Reply_MusiceInfo, musiceInfo); } break; case NotifyType.Request_MusiceStateInfo: { UserInfo userInfo = users.FindUser(socket); if (userInfo == null) { BaseInfo.SetError(ErrorType.Unknown_User, "不明会员准备删除过照片信息."); Main.ReplyError(socket); return; } MusiceStateInfo musiceStateInfo = (MusiceStateInfo)baseInfo; BroadCast(userInfo.RoomId, NotifyType.Reply_MusiceStateInfo, musiceStateInfo, null); //server.Send(socket, NotifyType.Reply_MusiceStateInfo, musiceStateInfo); } break; } }