Exemplo n.º 1
0
        public UserInfo EndRoom(UserInfo userInfo, RoomInfo roomInfo, bool isMeeting)
        {
            //userInfo.RoomId = "";

            ChatHistoryInfo chatHistoryInfo = Database.GetInstance().FindChatHistory(userInfo.ChatHistoryId);

            if (chatHistoryInfo != null)
            {
                chatHistoryInfo.EndTime = DateTime.Now;

                Database.GetInstance().UpdateChatHistory(chatHistoryInfo);
            }

            PointHistoryInfo pointHistoryInfo = Database.GetInstance().FindPointHistory(userInfo.PointHistoryId);

            if (pointHistoryInfo != null)
            {
                pointHistoryInfo.AgreeTime = DateTime.Now;

                Database.GetInstance().UpdatePointHistory(pointHistoryInfo);
            }

            //if (userInfo.GameId != null)
            //    Game.GetInstance().OutGame(userInfo);

            userInfo.RoomId = roomInfo.Id; // 2013-12-29: GreenRose
            if (isMeeting == true)
            {
                Server.GetInstance().Send(userInfo.Socket, NotifyType.Reply_OutMeeting, userInfo);
            }
            else
            {
                Server.GetInstance().Send(userInfo.Socket, NotifyType.Reply_OutRoom, userInfo);
            }

            //ReplyRoomDetailInfo(roomInfo.Id);

            //List<UserInfo> roomUsers = Users.GetInstance().GetRoomUsers(roomInfo.Id);

            //if (roomUsers.Count == 0)
            //{
            //    if (isMeeting == true)
            //    {
            //        //_Meetings.Remove(roomInfo);
            //    }
            //    else
            //    {
            //        _Rooms.Remove(roomInfo);
            //    }
            //}

            //ReplyRoomList();

            //Users.GetInstance().ReplyUserList(null);

            View._isUpdateUserList = true;
            View._isUpdateRoomList = true;

            string str = string.Format("{0} 님이 {1} 방에서 나갔습니다.", userInfo.Id, roomInfo.Id);

            LogView.AddLogString(str);

            return(userInfo);
        }
Exemplo n.º 2
0
        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:
            {
                RoomInfo roomInfo = (RoomInfo)baseInfo;
                UserInfo userInfo = OutMeeting(socket, roomInfo);

                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_RoomInfo:
            {
                RoomInfo enterInfo = (RoomInfo)baseInfo;

                UserInfo userInfo = Users.GetInstance().FindUser(socket);

                if (userInfo == null)
                {
                    Main.ReplyError(socket);
                    return;
                }

                //RoomInfo roomInfo = FindRoom(userInfo.RoomId);
                RoomInfo roomInfo = FindRoom(enterInfo.Id);

                if (roomInfo == null)
                {
                    //roomInfo = FindMeeting(userInfo.RoomId);
                    roomInfo = FindMeeting(enterInfo.Id);
                }

                if (roomInfo == null)
                {
                    Main.ReplyError(socket);
                    return;
                }

                roomInfo.Cash = enterInfo.Cash;

                BroadCast(enterInfo.Id, NotifyType.Reply_RoomInfo, enterInfo, null);

                ReplyRoomList();
            }
            break;

            case NotifyType.Request_RoomPrice:
            {
                UserInfo userInfo = Users.GetInstance().FindUser(socket);

                if (userInfo == null)
                {
                    Main.ReplyError(socket);
                    return;
                }

                RoomInfo replyInfo = (RoomInfo)baseInfo;

                bool     bMeeting = false;
                RoomInfo roomInfo = Chat.GetInstance().FindRoom(replyInfo.Id);

                if (roomInfo == null)
                {
                    roomInfo = Chat.GetInstance().FindMeeting(replyInfo.Id);
                    bMeeting = true;
                }

                if (roomInfo == null)
                {
                    BaseInfo.SetError(ErrorType.Unknown_User, "알수 없는 사용자가 선물하려고 합니다.");
                    Main.ReplyError(socket);
                    return;
                }

                if (Cash.GetInstance().ProcessChatCash(userInfo, roomInfo, bMeeting) == false)
                {
                    Main.ReplyError(socket);
                    return;
                }

                userInfo.WaitSecond = -1;
                userInfo.CashTime   = DateTime.Now.AddMinutes(1);
                //BroadCast(roomPrice.RoomId, NotifyType.Reply_RoomPrice, roomPrice, null);
            }
            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 );
                BroadCast(stringInfo.strRoomID, NotifyType.Reply_StringChat, stringInfo, stringInfo.UserId);
            }
            break;

            case NotifyType.Request_SendIP:
            {
                AVMsg avMsg = (AVMsg)baseInfo;

                UserInfo userInfo = users.FindUser(socket);

                if (userInfo == null)
                {
                    BaseInfo.SetError(ErrorType.Unknown_User, "알수 없는 사용자가 채팅하려고 합니다.");
                    Main.ReplyError(socket);
                    return;
                }

                BroadCast(avMsg._strRoomID, NotifyType.Reply_SendIP, avMsg, userInfo.Id);
            }
            break;

            case NotifyType.Request_VideoInfo:
            {
                AVMsg avMsg = (AVMsg)baseInfo;

                UserInfo userInfo = users.FindUser(socket);

                if (userInfo == null)
                {
                    BaseInfo.SetError(ErrorType.Unknown_User, "알수 없는 사용자가 채팅하려고 합니다.");
                    Main.ReplyError(socket);
                    return;
                }

                BroadCast(avMsg._strRoomID, NotifyType.Reply_VideoInfo, avMsg, userInfo.Id);
            }
            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);
                BroadCast(presentInfo.strRoomID, 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;
            }
        }
Exemplo n.º 3
0
        public UserInfo StartRoom(UserInfo userInfo, RoomInfo roomInfo, AskChatInfo askChatInfo)
        {
            userInfo = Users.GetInstance().FindUser(userInfo.Id);
            List <UserInfo> roomUsers = Users.GetInstance().GetRoomUsers(roomInfo.Id);

            //if (userInfo.Kind == (int)UserKind.ServiceWoman)
            //{
            //    if ( roomUsers.Count > 0 )
            //    {
            //        SetError(ErrorType.Already_Serviceman, "이미 봉사자가 들어있는 방입니다.");
            //        return null;
            //    }

            //    roomInfo.Owner = userInfo.Id;
            //}
            //else
            //{
            //    if ( roomUsers.Count <= 0 )
            //    {
            //        SetError(ErrorType.Notallow_NoServiceman, "봉사자가 없는 방에 먼저 들어갈수 없습니다.");
            //        return null;
            //    }

            //    if (roomInfo.Cash > 0 && userInfo.Cash < roomInfo.Cash)
            //    {
            //        SetError(ErrorType.Notenough_Cash, string.Format("{0}님의 캐쉬가 작아 채팅을 할수 없습니다.", userInfo.Id));
            //        return null;
            //    }

            //    if (roomInfo.Point > 0 && userInfo.Point < roomInfo.Point)
            //    {
            //        SetError(ErrorType.Notenough_Point, string.Format("{0}님의 포인트가 작아 채팅을 할수 없습니다.", userInfo.Point));
            //        return null;
            //    }
            //}

            // 2013-12-17: GreenRose
            if (roomUsers.Count <= 0)
            {
                roomInfo.Owner = userInfo.Id;
            }

            userInfo.RoomId     = roomInfo.Id;
            userInfo.EnterTime  = DateTime.Now;
            userInfo.CashTime   = userInfo.EnterTime;
            userInfo.WaitSecond = 0;

            //if (askChatInfo == null)
            //{
            //    if (FindRoom(roomInfo.Id) == null)
            //    {
            //        _Rooms.Add(roomInfo);

            //        if (roomInfo.Point <= 0)
            //        {
            //            GameInfo gameInfo = Database.GetInstance().FindGameSource(GameSource.Dice);
            //            gameInfo.GameId = roomInfo.Id;

            //            GameTable gameTable = Game.GetInstance().MakeTable(gameInfo);

            //            if (gameTable != null)
            //            {
            //                roomInfo.IsGame = 1;
            //                roomInfo._GameInfo = gameInfo;
            //            }
            //        }
            //    }

            //    ReplyRoomList();

            //    Server.GetInstance().Send(userInfo.Socket, NotifyType.Reply_EnterRoom, roomInfo);
            //}
            //else
            {
                if (FindMeeting(roomInfo.Id) == null)
                {
                    _Meetings.Add(roomInfo);
                }
                askChatInfo.MeetingInfo = roomInfo;

                Server.GetInstance().Send(userInfo.Socket, NotifyType.Reply_EnterMeeting, askChatInfo);
            }

            //if (roomInfo._GameInfo != null)
            //{
            //    //userInfo.GameId = roomInfo._GameInfo.GameId;
            //    Game.GetInstance().NotifyOccured(NotifyType.Request_EnterGame, userInfo.Socket, roomInfo._GameInfo);
            //    Game.GetInstance().NotifyOccured(NotifyType.Request_PlayerEnter, userInfo.Socket, userInfo);
            //}

            //Users.GetInstance().ReplyUserList(null);
            //ReplyRoomDetailInfo(roomInfo.Id);

            View._isUpdateUserList = true;
            View._isUpdateRoomList = true;

            string str = string.Format("{0} 님이 {1}방에 들어갔습니다.", userInfo.Id, roomInfo.Id);

            LogView.AddLogString(str);

            if (userInfo.Kind != (int)UserKind.ServiceWoman)
            {
                if (roomInfo.Cash > 0)
                {
                    ChatHistoryInfo chatHistoryInfo = new ChatHistoryInfo();

                    chatHistoryInfo.RoomId       = roomInfo.Id;
                    chatHistoryInfo.BuyerId      = userInfo.Id;
                    chatHistoryInfo.ServicemanId = roomInfo.Owner;
                    chatHistoryInfo.ServicePrice = roomInfo.Cash;
                    chatHistoryInfo.StartTime    = userInfo.EnterTime;
                    chatHistoryInfo.EndTime      = userInfo.EnterTime;

                    userInfo.ChatHistoryId = Database.GetInstance().AddChatHistory(chatHistoryInfo);
                }

                if (roomInfo.Point > 0)
                {
                    PointHistoryInfo pointHistoryInfo = new PointHistoryInfo();

                    pointHistoryInfo.TargetId  = userInfo.Id;
                    pointHistoryInfo.AgreeTime = DateTime.Now;
                    pointHistoryInfo.Content   = string.Format("{0}과 무료채팅", roomInfo.Owner);

                    userInfo.PointHistoryId = Database.GetInstance().AddPointHistory(pointHistoryInfo);
                }
            }

            return(userInfo);
        }
Exemplo n.º 4
0
        public RoomInfo EnterMeeting(Socket socket, AskChatInfo askChatInfo)
        {
            UserInfo userInfo = Users.GetInstance().FindUser(socket);

            if (userInfo == null)
            {
                SetError(ErrorType.Unknown_User, "알수 없는 사용자가 1:1채팅을 하려고 합니다.");
                Main.ReplyError(socket);
                return(null);
            }

            UserInfo targetInfo = Users.GetInstance().FindUser(askChatInfo.TargetId);

            //userInfo = Users.GetInstance().FindUser(userInfo.Id);

            if (targetInfo == null)
            {
                SetError(ErrorType.Unknown_User, "채팅대상이 존재하지 않습니다.");
                return(null);
            }

            //if (targetInfo.RoomId.Trim().Length > 0)
            //{
            //    SetError(ErrorType.Already_Chat, "채팅대상자는 이미 1:1 채팅중입니다.");
            //    return null;
            //}

            // 2013-12-25: GreenRose
            // 이미 사용하였던 방이 존재한다면 방을 창조하지 않는다.
            string roomName = string.Format("{0} - {1}", userInfo.Id, targetInfo.Id);

            RoomInfo roomInfo = null;

            roomInfo = _Meetings.Find(item => item.Name == roomName);

            if (roomInfo == null)
            {
                roomName = string.Format("{0} - {1}", targetInfo.Id, userInfo.Id);
                roomInfo = _Meetings.Find(item => item.Name == roomName);
            }

            if (roomInfo == null)
            {
                roomInfo           = new RoomInfo();
                roomInfo.Id        = (_Meetings.Count + 2).ToString();
                roomInfo.Name      = string.Format("{0} - {1}", userInfo.Id, targetInfo.Id);
                roomInfo.Owner     = targetInfo.Id;
                roomInfo.UserCount = 2;
                roomInfo.MaxUsers  = 2;
                roomInfo.Cash      = 0;// askChatInfo.Price;
                //roomInfo.listUserInfo.Add(userInfo);
                //roomInfo.listUserInfo.Add(targetInfo);
                roomInfo._strUserID   = userInfo.Id;
                roomInfo._strTargetID = targetInfo.Id;

                //MeetingInfo meetingInfo = new MeetingInfo();
                //meetingInfo._strRoomID = roomInfo.Id;
                //meetingInfo._listUserInfo.Add(userInfo);
                //meetingInfo._listUserInfo.Add(targetInfo);

                //_listMeetingInfo.Add(meetingInfo);
            }

            if (StartRoom(targetInfo, roomInfo, askChatInfo) == null)
            {
                return(null);
            }

            if (StartRoom(userInfo, roomInfo, askChatInfo) == null)
            {
                return(null);
            }

            return(roomInfo);
        }
Exemplo n.º 5
0
        public bool ProcessChatCash(UserInfo userInfo, RoomInfo roomInfo, bool bMeeting)
        {
            //List<UserInfo> users = Users.GetInstance().GetRoomUsers(roomInfo.Id);

            //if (users == null)
            //{
            //    ErrorView.AddErrorString();
            //    return false;
            //}

            //bool bUpdate = false;

            //for (int i = 0; i < users.Count; i++)
            //{
            //    UserInfo userInfo = users[i];

            if (userInfo.Kind == (int)UserKind.Manager ||
                userInfo.Kind == (int)UserKind.ServiceWoman ||
                userInfo.Kind == (int)UserKind.ServiceOfficer)
            {
                return(true);
            }

            //bUpdate = true;

            if (roomInfo.Cash > 0)
            {
                if (GiveChatSum(userInfo.Id, -roomInfo.Cash) == false)
                {
                    Chat.GetInstance().OutMeeting(userInfo.Socket, roomInfo);
                    return(false);
                }

                if (userInfo.Auto > 0)
                {
                    return(true);
                }

                //GiveChatSum(userInfo.Id, -roomInfo.Cash);

                if (bMeeting == true)
                {
                    userInfo.CashTime = userInfo.CashTime.AddMinutes(1);
                }
                else
                {
                    userInfo.CashTime = userInfo.CashTime.AddYears(1);
                }

                UserInfo servicer       = Database.GetInstance().FindUser(roomInfo.Owner);
                UserInfo serviceOfficer = Database.GetInstance().FindUser(servicer.Recommender); // Database.GetInstance().GetManager(UserKind.ServiceOfficer);
                UserInfo manager        = Database.GetInstance().GetManager(UserKind.Manager)[0];

                int servicePercent        = servicer.ChatPercent;
                int serviceOfficerPercent = serviceOfficer.ChatPercent;

                if (servicePercent > 100)
                {
                    servicePercent = 100;
                }

                if (serviceOfficerPercent > 100)
                {
                    serviceOfficerPercent = 100;
                }

                if (servicePercent > serviceOfficerPercent)
                {
                    servicePercent = serviceOfficerPercent;
                }

                serviceOfficerPercent -= servicePercent;

                int serviceCash        = ProcessCashPercent(servicer, servicePercent, roomInfo.Cash);
                int serviceOfficerCash = ProcessCashPercent(serviceOfficer, serviceOfficerPercent, roomInfo.Cash);
                int managerCash        = roomInfo.Cash - serviceOfficerCash - serviceCash;

                if (servicer != null)
                {
                    GiveChatSum(servicer.Id, serviceCash);
                }

                if (serviceOfficer != null)
                {
                    GiveChatSum(serviceOfficer.Id, serviceOfficerCash);
                }

                GiveChatSum(manager.Id, managerCash);

                ChatHistoryInfo chatHistoryInfo = Database.GetInstance().FindChatHistory(userInfo.ChatHistoryId);

                if (chatHistoryInfo != null)
                {
                    chatHistoryInfo.OfficerId = serviceOfficer.Id;
                    chatHistoryInfo.ManagerId = manager.Id;

                    chatHistoryInfo.BuyerTotal          -= roomInfo.Cash;
                    chatHistoryInfo.ServicemanTotal     += serviceCash;
                    chatHistoryInfo.ServiceOfficerTotal += serviceOfficerCash;
                    chatHistoryInfo.ManagerTotal        += managerCash;
                    chatHistoryInfo.EndTime              = DateTime.Now;

                    Database.GetInstance().UpdateChatHistory(chatHistoryInfo);
                }

                View._isUpdateRoomList = true;
            }

            if (roomInfo.Point > 0)
            {
                if (userInfo.Point < roomInfo.Point)
                {
                    SetError(ErrorType.Notenough_Point, string.Format("因{0}的账号余额不足 退出聊天频道.", userInfo.Id));
                    Main.ReplyError(userInfo.Socket);

                    Chat.GetInstance().OutMeeting(userInfo.Socket, roomInfo);
                    return(false);
                }

                UserInfo updateInfo = Database.GetInstance().FindUser(userInfo.Id);

                if (updateInfo == null)
                {
                    Chat.GetInstance().OutMeeting(userInfo.Socket, roomInfo);
                    return(false);
                }

                updateInfo.Point -= roomInfo.Point;

                if (Database.GetInstance().UpdateUser(updateInfo) == false)
                {
                    Chat.GetInstance().OutMeeting(userInfo.Socket, roomInfo);
                    return(false);
                }

                userInfo.Point = updateInfo.Point;

                PointHistoryInfo pointHistoryInfo = Database.GetInstance().FindPointHistory(userInfo.PointHistoryId);

                if (pointHistoryInfo != null)
                {
                    pointHistoryInfo.Point    -= roomInfo.Point;
                    pointHistoryInfo.AgreeTime = DateTime.Now;

                    Database.GetInstance().UpdatePointHistory(pointHistoryInfo);
                }

                userInfo.CashTime = userInfo.CashTime.AddMinutes(1);

                View._isUpdateUserList = true;
                View._isUpdateRoomList = true;
            }
            //}

            //if( bUpdate == true )
            Chat.GetInstance().ReplyRoomDetailInfo(roomInfo.Id);

            return(true);
        }
Exemplo n.º 6
0
        public void RefreshRoomList()
        {
            string queryStr = "select * from tblRoom ";

            string contentStr = textContent.Text.Trim();

            if (contentStr.Length > 0)
            {
                string field = "";

                switch (comboKind.SelectedIndex)
                {
                case 0:
                    field += string.Format("Id like '%{0}%'", contentStr);
                    break;

                case 1:
                    field += string.Format("Name like '%{0}%'", contentStr);
                    break;

                case 2:
                    field += string.Format("Owner like '%{0}%'", contentStr);
                    break;
                }

                if (field != "")
                {
                    queryStr += string.Format(" where {0} ", field);
                }
            }

            List <RoomInfo> roomList = Database.GetInstance().GetRoomList(queryStr);

            if (roomList == null)
            {
                MessageBox.Show("不能在资料库获取频道信息.");
                return;
            }

            RoomView.Rows.Clear();

            for (int i = 0; i < roomList.Count; i++)
            {
                RoomInfo roomInfo = roomList[i];

                RoomView.Rows.Add(
                    roomInfo.Id,
                    roomInfo.Name,
                    roomInfo.MaxUsers,
                    roomInfo.Owner,
                    roomInfo.Cash,
                    roomInfo.Point
                    );

                if (roomInfo.Cash == 0 && roomInfo.Point == 0 ||
                    roomInfo.Cash > 0 && roomInfo.Point > 0)
                {
                    RoomView.Rows[RoomView.Rows.Count - 1].DefaultCellStyle.ForeColor = Color.Red;
                }
            }

            labelSummary.Text = string.Format("总数: {0}", roomList.Count);
        }
Exemplo n.º 7
0
        private void buttonOk_Click(object sender, EventArgs e)
        {
            string roomId = textId.Text.Trim();

            if (roomId.Length == 0)
            {
                MessageBox.Show("请输入频道号码.");
                return;
            }

            if (_IsEditMode == false)
            {
                RoomInfo roomInfo = Database.GetInstance().FindRoom(roomId);

                if (roomInfo != null)
                {
                    MessageBox.Show("已存在的频道.");
                    return;
                }
            }

            string roomName = textName.Text.Trim();

            if (roomName.Length == 0)
            {
                MessageBox.Show("请输入频道名称.");
                return;
            }

            string roomOwner = comboOwner.Text.Trim();

            if (roomOwner.Length == 0)
            {
                MessageBox.Show("请选择频道所有者.");
                return;
            }

            if (textMaxUsers.Text.Trim().Length == 0)
            {
                MessageBox.Show("请选择频道人数.");
                return;
            }

            RoomInfo newInfo = new RoomInfo();

            newInfo.Id       = roomId;
            newInfo.Name     = roomName;
            newInfo.Kind     = 0;
            newInfo.Owner    = roomOwner;
            newInfo.Cash     = BaseInfo.ConvToInt(textCash.Text);
            newInfo.Point    = BaseInfo.ConvToInt(textPoint.Text);
            newInfo.MaxUsers = BaseInfo.ConvToInt(textMaxUsers.Text);

            bool ret = false;

            if (_IsEditMode == false)
            {
                ret = Database.GetInstance().AddRoom(newInfo);
            }
            else
            {
                ret = Database.GetInstance().UpdateRoom(newInfo);
            }

            if (ret == false)
            {
                ErrorInfo errorInfo = BaseInfo.GetError();
                MessageBox.Show(errorInfo.ErrorString);
                return;
            }

            this.DialogResult = DialogResult.OK;
        }