Ejemplo n.º 1
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);

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

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

            RoomInfo roomInfo = new RoomInfo();

            roomInfo.Id        = (_Meetings.Count + 1).ToString();
            roomInfo.Name      = string.Format("{0} - {1}", userInfo.Nickname, targetInfo.Nickname);
            roomInfo.Owner     = targetInfo.Id;
            roomInfo.UserCount = 2;
            roomInfo.MaxUsers  = 2;
            roomInfo.Cash      = askChatInfo.Price;

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

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

            return(roomInfo);
        }
Ejemplo 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;
            }
        }
Ejemplo 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);
        }
Ejemplo 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);
        }