示例#1
0
        public static void UpdateWaiting(OnlineUser user, int no, int time) // 0~1~2
        {
            // 수신 금지 목록에 등록
            OnlineUser.receive_waiting_user.Add(user.id);
            user.Message("소중한 정보 감사합니다.");

            MysqlNode node = new MysqlNode(Program.mysqlOption, "INSERT INTO waiting_data (restaurant_no, user_id, waiting) VALUES (?restaurant_no, ?user_id, ?waiting)");

            node["restaurant_no"] = no;
            node["user_id"]       = user.id;
            if (time < 2)
            {
                node["waiting"] = time * 5;
            }
            else
            {
                node["waiting"] = 15;
            }
            node.ExecuteNonQuery();
            int?result = AutoWaitingComputing.Update(no);

            foreach (int id in GetWaitingListener(no))
            {
                OnlineUser.Notify(id, "waiting", no, GetTitle(no) + " 대기 시간 수신", "예상 시간 : " + result.Value + "분");
            }
        }
        public static void NewKeyword(ESocket socket, string keyword)
        {
            string id = GachonSocket.GetId(socket);

            if (id != null)
            {
                keyword = keyword.Trim();
                if (keyword.Length == 0)
                {
                    NetworkMessageList.TipMessage(socket, "추가하실 키워드를 입력해주세요.");
                    return;
                }
                MysqlNode node = new MysqlNode(private_data.mysqlOption, "INSERT INTO keyword(student_id, keyword) VALUES (?id, ?keyword)");
                node["id"]      = id;
                node["keyword"] = keyword;
                int result = node.ExecuteNonQuery();
                if (result != 1)
                {
                    NetworkMessageList.TipMessage(socket, "이미 등록된 키워드입니다.");
                }
                else if (result == 0)
                {
                    NetworkMessageList.TipMessage(socket, "오류로 인해 키워드 추가가 불가능합니다 (ERROR CODE : " + result + ")");
                }
                else
                {
                    NetworkMessageList.TipMessage(socket, "[키워드] \"" + keyword + "\" 가 추가되었습니다.");
                    KeywordList(socket);
                }
            }
        }
示例#3
0
        /// <summary>
        /// 특정 유저가 파일을 그룹에 추가합니다. (파일은 이미 업로드된 상태)
        /// </summary>
        /// <param name="user">파일을 올릴 유저</param>
        /// <param name="no">파일 번호 (Mysql)</param>
        public void FileUpload(User user, int no)
        {
            // 해당 유저의 권한 체크
            int level = GetLevel(user);

            if (GetLevel(user) < 1)
            {
                user.ToChatMessage("해당 그룹에 파일을 업로드할 권한이 없습니다.", ChatType.Notice);
                return;
            }
            if (!user.HaveItem(no)) // 해당 유저가 그 아이템(파일)을 정말 가지고 있는가
            {
                NetworkMessageList.TipMessage(user.socket, "해당 파일이 인벤토리에 없어서 업로드에 실패했습니다.");
                return;
            }
            // Mysql에 파일 정보 추가
            MysqlNode node = new MysqlNode(private_data.mysqlOption, "INSERT INTO group_file(group_name, file_no, upload_user) VALUES (?group_name, ?file_no, ?user)");

            node["group_name"] = key;
            node["file_no"]    = no;
            node["user"]       = user.ID;
            int result = node.ExecuteNonQuery();

            if (result > 0)
            {
                NetworkMessageList.TipMessage(user.socket, "파일을 스터디에 성공적으로 업로드했습니다.");
                OpenMenu(user, "File");
            }
            else
            {
                NetworkMessageList.TipMessage(user.socket, "예기치 못한 오류로 업로드에 실패했습니다.");
            }
        }
示例#4
0
        public static void AddItem(User user, string keyword)
        {
            keyword = keyword.Trim();
            if (keyword.Length == 0)
            {
                NetworkMessageList.TipMessage(user.socket, "추가하실 키워드를 입력해주세요.");
                return;
            }
            MysqlNode node = new MysqlNode(private_data.mysqlOption, "INSERT INTO keyword(student_id, keyword) VALUES (?id, ?keyword)");

            node["id"]      = user.ID;
            node["keyword"] = keyword;
            int result = node.ExecuteNonQuery();

            if (result != 1)
            {
                NetworkMessageList.TipMessage(user.socket, "이미 등록된 키워드입니다.");
            }
            else if (result == 0)
            {
                NetworkMessageList.TipMessage(user.socket, "오류로 인해 키워드 추가가 불가능합니다 (ERROR CODE : " + result + ")");
            }
            else
            {
                user.ToChatMessage("[키워드] \"" + keyword + "\" 가 추가되었습니다.", ChatType.Notice);
                GetList(user);
            }
        }
 /// <summary>
 /// 동일한 사이트 생성일 경우 기존 객체를 연결시킨다.
 /// </summary>
 /// <param name="site"></param>
 public void CombineSite(Site site, bool want_insert_sql = true)
 {
     lock (Sites)
     {
         if (want_insert_sql)
         {
             MysqlNode node = new MysqlNode(GachonOption.MysqlOption, "UPDATE course set " + site.Type.ToLower() + " = ?site_id where no = ?key ");
             node["site_id"] = site.ID;
             node["key"]     = Key;
             node.ExecuteNonQuery();
         }
         // 이때 동일한 사이트가 존재할 경우 새로 추가하려는 객체를 추가하지 않고
         // 기존 객체를 연결한다.
         if (GachonObjects.AllSite.ContainsKey(site.Type + site.ID))
         {
             site = GachonObjects.AllSite[site.Type + site.ID];
         }
         else
         {
             GachonObjects.AllSite.Add(site.Type + site.ID, site);
             site.Start();
         }
         // 이 강의에 사이트 연결
         Sites.Add(site.Type, site);
         // 해당 사이트에 새로운 게시글이 올라올경우 이벤트 실행
         site.NewPost += Site_NewPost;
     }
 }
示例#6
0
        public static void GetItem(User user, int no)
        {
            MysqlNode node = new MysqlNode(private_data.mysqlOption, "SELECT * FROM post_name where receiver=?receiver and no=?no");

            node["no"]       = no;
            node["receiver"] = user.ID;
            using (node.ExecuteReader())
            {
                if (node.Read() == false)
                {
                    user.ToChatMessage("존재하지 않거나 권한이 없는 우편입니다.", ChatType.System);
                    return;
                }
                if (node.GetInt("read") == 0)
                {
                    // 읽음 표시
                    MysqlNode update = new MysqlNode(private_data.mysqlOption, "UPDATE post SET `read`=1 where no=?no");
                    update["no"] = no;
                    update.ExecuteNonQuery();
                }
                JObject json = new JObject();
                json["type"]      = NetworkProtocol.Post_Detail;
                json["title"]     = node.GetString("title");
                json["content"]   = node.GetString("content");
                json["no"]        = no;
                json["sender"]    = node.GetString("sender_name");
                json["sender_id"] = node.GetString("sender");
                json["content"]   = string.Format("[000000]{0}[-]", json["content"]); // BBCode를 이용해 글씨가 검정색임을 나타낸다.

                if (node.GetString("file") != null)                                   // 스트링으로 null 체크
                {
                    MysqlNode filenode = new MysqlNode(private_data.mysqlOption, "SELECT name FROM file WHERE file_no=?no");
                    filenode["no"] = node.GetInt("file");
                    using (filenode.ExecuteReader())
                    {
                        if (filenode.Read())
                        {
                            json["content"] = string.Format("[000000]첨부 파일[-]\r\n[url={0}][u][B284FF]{1}[-][/u][/url]\r\n\r\n{2}", "file-" + filenode["no"], filenode.GetString("name"), json["content"]);
                        }
                    }
                }
                DateTime date = node.GetDateTime("date");
                if (date.DayOfYear == DateTime.Now.DayOfYear)
                {
                    json["date"] = date.ToString("HH:mm:ss");
                }
                else
                {
                    json["date"] = date.ToString("yyyy-MM-dd");
                }
                user.socket.Send(json);
            }
        }
示例#7
0
        public static void ClickLike(OnlineUser user, int restaurant_no)
        {
            MysqlNode node   = new MysqlNode(Program.mysqlOption, "DELETE FROM rest_likes_data where restaurant_no = ?restaurant_no AND user_id = ?user_id");
            int       result = 0;

            node["restaurant_no"] = restaurant_no;
            node["user_id"]       = user.id;
            result += node.ExecuteNonQuery();
            if (result == 0)
            {
                node.ChangeSql("INSERT INTO rest_likes_data (restaurant_no, user_id) VALUES (?restaurant_no, ?user_id)");
                result += node.ExecuteNonQuery();
            }
            if (result > 0)
            {
                user.Send(StateLikes(user, restaurant_no));
            }
            else
            {
                user.Message("요청이 실패했습니다.");
            }
        }
示例#8
0
        public void Login(string token)
        {
            Program.LogSystem.AddLog(4, "LoginModule", "토큰을 통한 로그인 시도 " + token);

            JObject message = new JObject();

            message["type"] = PacketType.Login;
            if (String.IsNullOrEmpty(token))
            {
                throw new Exception("토큰이 존재하지 않습니다.");
            }
            else
            {
                JObject data = KakaoModule.GetUserInformation(token);
                if (data != null)
                {
                    id   = (int)data["id"];
                    name = (string)data["properties"]["nickname"];
                    img  = (string)data["properties"]["thumbnail_image"];
                    MysqlNode node = new MysqlNode(Program.mysqlOption, "SELECT * FROM user WHERE id = ?id");
                    node["id"] = id;
                    using (node.ExecuteReader())
                    {
                        MysqlNode update = new MysqlNode(Program.mysqlOption, "SQL");

                        if (node.Read())
                        {
                            update.ChangeSql("UPDATE user SET name=?name WHERE id = ?id");
                            if (!node.IsNull("lat") && !node.IsNull("lon"))
                            {
                                position = new Position(node.GetDouble("lat"), node.GetDouble("lon"));
                            }
                        }
                        else
                        {
                            update.ChangeSql("INSERT INTO user (id,name) VALUES (?id, ?name)");
                        }

                        update["id"]   = id;
                        update["name"] = name;
                        update.ExecuteNonQuery();
                    }
                }
                else
                {
                    throw new Exception("유효하지 않은 토큰입니다.");
                }
            }
        }
示例#9
0
        /// <summary>
        /// 해당 학생의 개인정보를 강제로 갱신합니다.
        /// </summary>
        public void GetUserInfo()
        {
            if (LoginOk == false)
            {
                return;                   // 마지막 로그인을 실패했을경우
            }
            // Account table에서 해당 유저의 정보가 있는지 확인
            MysqlNode node = new MysqlNode(GachonOption.MysqlOption, "SELECT * FROM account WHERE id = ?ID");  //수정?

            node["ID"] = ID;

            using (node.ExecuteReader())
            {
                node.Read();
                StudentNumber = node.GetString("studentnumber");

                // 바로 Database에서 얻어온 tuple 정보로 학생 정보를 저장
                if ((!String.IsNullOrEmpty(StudentNumber)) && Int32.Parse(StudentNumber) != 0)
                {
                    Name       = node.GetString("name");
                    Email      = node.GetString("email");
                    Phone      = node.GetString("phone");
                    Department = node.GetString("department");
                }
                else
                {
                    // DB에 없다면 사이버캠퍼스 홈페이지에 들어가서 유저의 정보를 읽어옴
                    HtmlDocument data = WebPacket.Web_GET_Html(Encoding.UTF8, cookie, "https://cyber.gachon.ac.kr/user/user_edit.php");
                    StudentNumber = data.DocumentNode.SelectSingleNode("//div[@class='felement fstatic']").InnerText;
                    Name          = data.GetElementbyId("id_firstname").Attributes["value"].Value;
                    Email         = data.GetElementbyId("id_email").Attributes["value"].Value;
                    Phone         = data.GetElementbyId("id_phone2").Attributes["value"].Value;
                    Department    = data.DocumentNode.SelectSingleNode("//p[@class='department']").InnerText;

                    // 읽은 후 그 정보를 Databse account 테이블에 저장해줌
                    MysqlNode insert = new MysqlNode(GachonOption.MysqlOption, "UPDATE  account SET studentnumber = ?num, name = ?name, department = ?dept" +
                                                     ",phone = ?phone , email = ?email where id = ?id ");
                    insert["id"]    = ID;
                    insert["num"]   = StudentNumber;
                    insert["name"]  = Name;
                    insert["dept"]  = Department;
                    insert["phone"] = Phone;
                    insert["email"] = Email;
                    insert.ExecuteNonQuery();
                }
            }
        }
示例#10
0
        public static void RemoveItem(User user, string keyword)
        {
            MysqlNode node = new MysqlNode(private_data.mysqlOption, "DELETE FROM keyword WHERE student_id=?id and keyword=?keyword");

            node["id"]      = user.ID;
            node["keyword"] = keyword;
            int result = node.ExecuteNonQuery();

            if (result != 1)
            {
                NetworkMessageList.TipMessage(user.socket, "오류로 인해 키워드 삭제가 불가능합니다 (ERROR CODE : " + result + ")");
            }
            else
            {
                user.ToChatMessage("[키워드] \"" + keyword + "\" 가 삭제되었습니다.", ChatType.Notice);
                GetList(user);
            }
        }
示例#11
0
        /// <summary>
        /// 이 유저의 인벤토리에서 아이템을 제거합니다.
        /// </summary>
        /// <param name="no">MYSQL에 등록된 파일 번호입니다</param>
        /// <returns></returns>
        public bool RemoveItem(int no)
        {
            MysqlNode node = new MysqlNode(private_data.mysqlOption, "DELETE FROM inventory WHERE student_id=?id and file_no=?no");

            node["id"] = ID;
            node["no"] = no;
            if (node.ExecuteNonQuery() > 0)
            {
                JObject json = new JObject();
                json["type"] = NetworkProtocol.Inventory_Remove;
                json["no"]   = no;
                socket.Send(json);
                return(true);
            }
            else
            {
                return(false);
            }
        }
示例#12
0
 public static GachonClass GetObject(string Title, string key, bool Formal = false, bool want_insert_sql = true)
 {
     if (GachonObjects.AllClass.ContainsKey(key))
     {
         return(GachonObjects.AllClass[key]);
     }
     else
     {
         if (want_insert_sql)
         {
             MysqlNode node = new MysqlNode(GachonOption.MysqlOption, "INSERT into course (no, type, name) values (?key, 'Class', ?tit)");
             node["key"] = key;
             node["tit"] = Title;
             node.ExecuteNonQuery();
         }
         GachonClass gachonClass = new GachonClass(Title, key, Formal);
         GachonObjects.AllClass.Add(key, gachonClass);
         return(gachonClass);
     }
 }
示例#13
0
        /// <summary>
        /// 이 유저의 인벤토리에 새로운 아이템(파일)을 추가합니다.
        /// </summary>
        /// <param name="no">MYSQL에 등록된 파일 번호입니다</param>
        /// <returns></returns>
        public bool AddFileItem(int no)
        {
            // 해당 번호의 파일이 실제로 있는지 확인 + 파일 정보 불러오기
            JObject item = FileSystem.GetFileItem(no);

            if (item == null)
            {
                return(false);
            }
            MysqlNode node = new MysqlNode(private_data.mysqlOption, "INSERT INTO inventory(student_id, file_no) VALUES (?id, ?no)");

            node["id"] = ID;
            node["no"] = no;
            if (node.ExecuteNonQuery() != 1)
            {
                return(false);
            }
            socket.Send(item);
            return(true);
        }
示例#14
0
        public static void SendPost(string title, string content, string sender, string receiver, bool notice = true)
        {
            DateTime  date = DateTime.Now;
            MysqlNode Node = new MysqlNode(private_data.mysqlOption, "INSERT INTO post(title, content, sender, receiver, date) VALUES (?title, ?content, ?sender, ?receiver, ?date)");

            Node["title"]    = title;
            Node["content"]  = content;
            Node["sender"]   = sender;
            Node["receiver"] = receiver;
            Node["date"]     = date.ToString("yyyy-MM-dd HH:mm:ss");
            Node.ExecuteNonQuery();

            JObject json = new JObject();

            json["type"]     = NetworkProtocol.PostAlarm;
            json["title"]    = title;
            json["content"]  = content;
            json["receiver"] = receiver;
            json["date"]     = date;
            if (notice == true)
            {
                // 받는사람이 게임 또는 스마트폰을 통해 접속중인가
                ESocket socket = GachonSocket.GetOnlineUser(receiver);
                if (socket != null)
                {
                    if (User.Items.ContainsKey(socket))
                    {
                        User.Items[socket].ToChatMessage("[우편함] 새로운 메세지가 도착했습니다.", ChatType.System);
                    }
                    else
                    {
                        socket.Send(json);
                    }
                }
                else
                {
                    AddQueue(receiver, json);
                }
            }
        }
示例#15
0
        /// <summary>
        /// 각 사이트에서 새로운 알림이 올 경우 이 함수가 실행됩니다.
        /// </summary>
        /// <param name="postItem"></param>
        private void Site_NewPost(PostItem postItem)
        {
            // Database Article 테이블에 새로운 post의 tuple을 삽입해줌
            MysqlNode node = new MysqlNode(GachonOption.MysqlOption,
                                           "INSERT INTO article (course_no, board_name, no, category, publisher, title, date, content, url, sitetype, siteid)" +
                                           "VALUES (?course_no, ?board_name, ?no, ?posttype, ?publisher, ?title, ?date, ?content, ?url, ?sitetype, ?siteid) ");

            //일반 게시글의 경우엔 강의번호, 게시판이름, 게시글번호 등의 attribute가 있음
            node["course_no"]  = this.Key;
            node["board_name"] = postItem.board_name;
            node["no"]         = postItem.no;
            node["posttype"]   = (int)postItem.posttype;
            node["publisher"]  = postItem.Publisher;
            node["title"]      = postItem.Title;
            node["date"]       = postItem.time;
            node["content"]    = postItem.Content;
            node["url"]        = postItem.url;
            node["sitetype"]   = postItem.source.Type;
            node["siteid"]     = postItem.source.ID;
            node.ExecuteNonQuery();

            // 게시판의 유형이 레포트 제출실일 경우 형식이 다름
            if (postItem.posttype == BoardType.PostType.Homework)
            {
                // 과제에 관한 게시글은 따로 Homework Table에 저장한다.
                MysqlNode hwnode = new MysqlNode(GachonOption.MysqlOption,
                                                 "INSERT INTO homework (course_no, article_no, start_date, end_date)" +
                                                 "VALUES (?course_no, ?article_no, ?start_date, ?end_date) ");

                // 레포트 게시글이기 때문에 마감기한도 추가
                hwnode["course_no"]  = this.Key;
                hwnode["article_no"] = postItem.no;
                hwnode["start_date"] = postItem.s_time;
                hwnode["end_date"]   = postItem.e_time;
                hwnode.ExecuteNonQuery();
            }

            // 이 객체의 이벤트를 듣고있는 리스너에게 이벤트 메세지 전달.
            NewPost?.Invoke(this, postItem);
        }
示例#16
0
        public static void GetItem(User user, int no)
        {
            MysqlNode node = new MysqlNode(private_data.mysqlOption, "SELECT * FROM post_name where receiver=?receiver and no=?no");

            node["no"]       = no;
            node["receiver"] = user.ID;
            using (node.ExecuteReader())
            {
                if (node.Read() == false)
                {
                    user.ToChatMessage("존재하지 않거나 권한이 없는 우편입니다.", ChatType.System);
                    return;
                }
                if (node.GetInt("read") == 0)
                {
                    // 읽음 표시
                    MysqlNode update = new MysqlNode(private_data.mysqlOption, "UPDATE post SET `read`=1 where no=?no");
                    update["no"] = no;
                    update.ExecuteNonQuery();
                }
                JObject json = new JObject();
                json["type"]      = NetworkProtocol.Post_Detail;
                json["title"]     = node.GetString("title");
                json["content"]   = node.GetString("content");
                json["no"]        = no;
                json["sender"]    = node.GetString("sender_name");
                json["sender_id"] = node.GetString("sender");
                DateTime date = node.GetDateTime("date");
                if (date.DayOfYear == DateTime.Now.DayOfYear)
                {
                    json["date"] = date.ToString("HH:mm:ss");
                }
                else
                {
                    json["date"] = date.ToString("yyyy-MM-dd");
                }
                user.socket.Send(json);
            }
        }
示例#17
0
        public static int?Update(int no)
        {
            MysqlNode update = new MysqlNode(Program.mysqlOption, "UPDATE restaurant SET `computed_waiting` = ?data WHERE no=?no");

            update["no"] = no;
            int time = Compute(DateTime.Now, no);

            if (time == -1)
            {
                update["data"] = null;
            }
            else
            {
                update["data"] = time;
            }

            update.ExecuteNonQuery();
            if (time == -1)
            {
                return(null);
            }
            return(time);
        }
示例#18
0
        /// <summary>
        /// 각 사이트에서 새로운 알림이 올 경우 이 함수가 실행됩니다.
        /// </summary>
        /// <param name="postItem"></param>
        private void Site_NewPost(PostItem postItem)
        {
            //여기에 SQL추가하기~ Insert

            MysqlNode node = new MysqlNode(GachonOption.MysqlOption,
                                           "INSERT INTO article (course_no, board_name, no, category, publisher, title, date, content, url, sitetype, siteid)" +
                                           "VALUES (?course_no, ?board_name, ?no, ?posttype, ?publisher, ?title, ?date, ?content, ?url, ?sitetype, ?siteid) ");

            node["course_no"]  = this.Key;
            node["board_name"] = postItem.board_name;
            node["no"]         = postItem.no;
            node["posttype"]   = (int)postItem.posttype;
            node["publisher"]  = postItem.Publisher;
            node["title"]      = postItem.Title;
            node["date"]       = postItem.time;
            node["content"]    = postItem.Content;
            node["url"]        = postItem.url;
            node["sitetype"]   = postItem.source.Type;
            node["siteid"]     = postItem.source.ID;
            node.ExecuteNonQuery();

            if (postItem.posttype == BoardType.PostType.Homework)
            {
                MysqlNode hwnode = new MysqlNode(GachonOption.MysqlOption,
                                                 "INSERT INTO homework (course_no, article_no, start_date, end_date)" +
                                                 "VALUES (?course_no, ?article_no, ?start_date, ?end_date) ");

                hwnode["course_no"]  = this.Key;
                hwnode["article_no"] = postItem.no;
                hwnode["start_date"] = postItem.s_time;
                hwnode["end_date"]   = postItem.e_time;
                hwnode.ExecuteNonQuery();
            }

            // 이 객체의 이벤트를 듣고있는 리스너에게 이벤트 메세지 전달.
            NewPost?.Invoke(this, postItem);
        }
示例#19
0
 /// <summary>
 /// 해당 강의에 대한 객체를 반환해 줍니다.
 /// </summary>
 /// <param name="Title"></param>
 /// <param name="key"></param>
 /// <param name="Formal"></param>
 /// <param name="want_insert_sql">데이터베이스에 새로운 강의를 등록해야 할 경우</param>
 /// <returns></returns>
 public static GachonClass GetObject(string Title, string key, bool Formal = false, bool want_insert_sql = true)
 {
     // 이미 존재하는 강의일 경우에는 바로 그 강의객체를 찾아 리턴해줌
     if (GachonObjects.AllClass.ContainsKey(key))
     {
         return(GachonObjects.AllClass[key]);
     }
     else
     {
         //새로운 강의일 때 & Database에 Insert하기를 원하는 경우
         if (want_insert_sql)
         {
             //Databse의 Course Table에 Insert
             MysqlNode node = new MysqlNode(GachonOption.MysqlOption, "INSERT into course (no, type, name) values (?key, 'Class', ?tit)");
             node["key"] = key;
             node["tit"] = Title;
             node.ExecuteNonQuery();
         }
         //존재하지 않는 강의이기 때문에 강의 이름, 고유번호를 가진 새로운 객체 생성 후 AllClass 리스트에 추가
         GachonClass gachonClass = new GachonClass(Title, key, Formal);
         GachonObjects.AllClass.Add(key, gachonClass);
         return(gachonClass);
     }
 }
示例#20
0
        /// <summary>
        /// 로그인 세션을 강제로 실행시킵니다.
        /// 주의: 각 함수에서 로그인 세션을 유지되는지 확인후 자동으로 실행하기때문에 따로 이 함수를 실행하지 않아도 됨.
        /// </summary>
        public void Login()
        {
            // 가천대 로그인페이지 접근 시도/ (sson.kyungwon.ac.kr)에서 세션값을 가져오는 과정(GID 오류때문에 반드시 필요)
            VisitPage("https://www.gachon.ac.kr/site/login.jsp");
            string a = WebPacket.Web_POST(cookie,
                                          "https://sson.kyungwon.ac.kr/sso/pmi-sso-login-uid-password2.jsp",
                                          "https://www.gachon.ac.kr/site/login_sso.jsp",
                                          "return_url=&uid=" + ID + "&password="******"&x=41&y=20");

            // 가천대 서버에 접속하지 못한경우 로그인 실패
            if (a == null)
            {
                return;
            }
            if (a.IndexOf("location.href='https://www.gachon.ac.kr:443/site/login.jsp'") >= 0)
            {
                // 사이버 캠퍼스에 로그인을 하면서 강의 정보 불러옴.
                HtmlDocument data = WebPacket.Web_POST_Html(cookie, "https://cyber.gachon.ac.kr/login/index.php", "https://cyber.gachon.ac.kr/login.php", "username="******"&password="******"SELECT id FROM account WHERE id = ?id");
                search_id["id"] = ID;
                bool First_Login = false;
                using (search_id.ExecuteReader())
                {
                    if (!search_id.Read())
                    {
                        MysqlNode idnode = new MysqlNode(GachonOption.MysqlOption, "INSERT INTO account (id) VALUES (?id) ");
                        idnode["id"] = ID;
                        idnode.ExecuteNonQuery();
                        First_Login = true;
                    }
                }
                if (First_Login) // 첫 접속시 수강중인 강의를 새로 등록
                {
                    List <GachonClass> need_eclass_info = new List <GachonClass>();
                    foreach (HtmlNode node in data.DocumentNode.SelectNodes("//div[@class='course_box']"))
                    {
                        JObject box   = ParseSupport.CyberCampusTitle(node.SelectSingleNode(".//div[@class='course-title']/h3").InnerText);
                        string  title = (string)box["title"];
                        string  key   = (string)box["key"];
                        lock (GachonObjects.AllClass)
                        {
                            if (!GachonObjects.AllClass.ContainsKey(key))
                            {
                                GachonClass newclass = GachonClass.GetObject(title, key, true);
                                JObject     urlq     = ParseSupport.UrlQueryParser(node.SelectSingleNode(".//a[@class='course_link']").Attributes["href"].Value);
                                newclass.CombineSite(new GachonCyberCampus(urlq["id"].ToString()));
                                need_eclass_info.Add(newclass);
                            }
                            MysqlNode insertNode = new MysqlNode(GachonOption.MysqlOption,
                                                                 "INSERT into takes_course(student_id, course_no) values (?id, ?course_no)");
                            insertNode["id"]        = ID;
                            insertNode["course_no"] = key;
                            insertNode.ExecuteNonQuery();

                            CombineClass(GachonObjects.AllClass[key]);
                        }
                    }
                    HtmlDocument eclassinfo = null;
                    if (need_eclass_info.Count > 0)
                    {
                        eclassinfo = WebPacket.Web_GET_Html(Encoding.UTF8, cookie, "http://eclass.gachon.ac.kr/index.jsp");
                    }
                    // 새로운 클래스가 생겼으니 eclass 정보를 읽어서 새로 생긴 클래스와 연결한다.
                    foreach (GachonClass newclass in need_eclass_info)
                    {
                        HtmlNode node = eclassinfo.DocumentNode.SelectSingleNode("//a[@title=" + newclass.ID + newclass.Sec_ID + "]");
                        if (node != null)
                        {
                            string e_id = ParseSupport.UrlQueryParser(node.Attributes["href"].Value)["Forum_seq"].ToString();
                            newclass.CombineSite(new GachonEClass(e_id));
                        }
                    }
                }
                else // 첫 접속이 아니면 기존 강의목록을 연결한다.
                {
                    MysqlNode search_course = new MysqlNode(GachonOption.MysqlOption, "SELECT course_no FROM takes_course WHERE student_id = ?id");
                    search_course["id"] = ID;
                    using (search_course.ExecuteReader())
                    {
                        while (search_course.Read())
                        {
                            CombineClass(GachonObjects.AllClass[search_course.GetString("course_no")]);
                        }
                    }
                }
                // 카페 도메인에도 세션을 만들어줌. 없을경우 처음 카페 접속시 리다이렉션 걸림.
                VisitPage("http://cafe.gachon.ac.kr");
                LoginOk = true;
            }
            else
            {
                LoginOk = false;
            }
        }
示例#21
0
        public static void main()
        {
            Program.LogSystem.AddLog(2, "AutoCrawling", "네이버를 통해 음식점 데이터를 갱신합니다");

            foreach (string keyword in keywords)
            {
                Program.LogSystem.AddLog(1, "AutoCrawling", keyword + " 키워드로 검색 시작");
                JObject search_data = NaverAPIModule.SearchPlace((string)ConfigManagement.GetObject("naver_api")["client_id"],
                                                                 (string)ConfigManagement.GetObject("naver_api")["client_secret"],
                                                                 keyword, 300);
                foreach (JObject restaurant in search_data["items"])
                {
                    MysqlNode update = new MysqlNode(Program.mysqlOption, "INSERT INTO restaurant (no, title, description, roadAddress, mapx, mapy, category, image, default_likes) VALUES (?no, ?title, ?description, ?roadAddress, ?mapx, ?mapy, ?category, ?image, ?default_likes)");
                    update["title"]       = Regex.Replace((string)restaurant["title"], "(<[/a-zA-Z]+>)", "");
                    update["roadAddress"] = (string)restaurant["roadAddress"];
                    JObject map = NaverAPIModule.Geocoding((string)ConfigManagement.GetObject("naver_cloud_api")["client_id"],
                                                           (string)ConfigManagement.GetObject("naver_cloud_api")["client_secret"],
                                                           (string)restaurant["roadAddress"]);
                    if (map == null)
                    {
                        update["mapx"] = null;
                        update["mapy"] = null;
                    }
                    else
                    {
                        update["mapx"] = map["x"].ToString();
                        update["mapy"] = map["y"].ToString();
                    }

                    update["category"] = (string)restaurant["category"];

                    update["no"]            = NaverAPIModule.GetPlaceID((string)update["title"], (string)update["roadAddress"], (string)keyword);
                    update["image"]         = NaverAPIModule.GetPlaceImage((int)update["no"]);
                    update["description"]   = NaverAPIModule.GetPlaceDescription((int)update["no"]);
                    update["default_likes"] = NaverAPIModule.GetPlaceReview((int)update["no"]);

                    update.ExecuteNonQuery();
                    Program.LogSystem.AddLog(1, "AutoCrawling", update["title"] + " 를 리스트에 등록");

                    // 메뉴 갱신

                    JArray menus = NaverAPIModule.GetPlaceMenu((int)update["no"]);
                    foreach (JObject json in menus)
                    {
                        MysqlNode menu_update = new MysqlNode(Program.mysqlOption, "INSERT INTO menu (restaurant_no, priority, name, price, description, image) VALUES (?restaurant_no, ?priority, ?name, ?price, ?description, ?image)");
                        menu_update["restaurant_no"] = update["no"];
                        menu_update["priority"]      = (string)json["priority"];
                        menu_update["name"]          = (string)json["name"];
                        menu_update["price"]         = (string)json["price"];

                        if (String.IsNullOrEmpty((string)json["desc"]))
                        {
                            menu_update["description"] = null;
                        }
                        else
                        {
                            menu_update["description"] = (string)json["desc"];
                        }

                        if (((JArray)json["images"]).Count > 0)
                        {
                            menu_update["image"] = (string)json["images"][0];
                        }
                        else
                        {
                            menu_update["image"] = null;
                        }

                        menu_update.ExecuteNonQuery();
                        Program.LogSystem.AddLog(1, "AutoCrawling", json["name"] + " 를 메뉴 리스트에 등록");
                    }
                }
            }
            Program.LogSystem.AddLog(1, "AutoCrawling", "크롤링 완료");
        }
示例#22
0
        public static void NewStudy(User user, JObject message)
        {
            string key = (string)message["name"];

            if (key.Length < 2 || key.Length > 10)
            {
                NetworkMessageList.TipMessage(user.socket, "스터디 이름은 2글자 이상 10글자 이내입니다.");
                return;
            }
            MysqlNode node = new MysqlNode(private_data.mysqlOption, "INSERT INTO course(no,type,name) VALUES (?name,'Group',?name)");

            node["name"] = key;
            int result = node.ExecuteNonQuery();

            if (result == -1)
            {
                NetworkMessageList.TipMessage(user.socket, "이미 같은 이름의 스터디 그룹이 존재합니다.");
                return;
            }
            else if (result <= 0)
            {
                NetworkMessageList.TipMessage(user.socket, "데이터베이스의 예기치 못한 오류가 있습니다.");
                return;
            }
            // 현재 위치를 데이터베이스에 저장
            Vector4 position = user.position;

            node           = new MysqlNode(private_data.mysqlOption, "INSERT INTO `group`(group_name,master,x,y,z,q) VALUES (?name,?master,?x,?y,?z,?q)");
            node["name"]   = key;
            node["master"] = user.ID;
            node["x"]      = position.x;
            node["y"]      = position.y;
            node["z"]      = position.z;
            node["q"]      = position.q;
            node.ExecuteNonQuery();

            node        = new MysqlNode(private_data.mysqlOption, "INSERT INTO takes_course(student_id,course_no) VALUES (?id,?key)");
            node["id"]  = user.ID;
            node["key"] = key;
            node.ExecuteNonQuery();
            // 성공적으로 만들어진경우
            Study group = new Study(key, position);

            group.Start();

            JObject json = new JObject();

            json["type"] = NetworkProtocol.CloseNewStudy;
            user.socket.Send(json);
            NetworkMessageList.TipMessage(user.socket, "스터디 그룹을 성공적으로 만들었습니다!");
            StringBuilder sb = new StringBuilder();

            sb.AppendLine("스터디 이름 : " + key);
            sb.AppendLine("그룹 마스터 : " + user.ID);
            sb.AppendLine("");
            sb.AppendLine("새로운 스터디를 개설하신것을 축하드립니다!!!");
            sb.AppendLine("스터디의 펫말을 통해 새로운 그룹원을 초대하고, 그룹 내에서 진행된 대화를 확인할 수 있습니다.");
            sb.AppendLine("");
            sb.AppendLine("앞으로 더 많은 기능이 추가될 예정이니 많은 관심 부탁드립니다~~");
            sb.AppendLine("");
            sb.AppendLine("만약 스터디 그룹에 대해 문의사항이 있다면");
            sb.AppendLine("스터디 알림(admin_group)으로 메세지를 보내주시기 바랍니다.");
            sb.AppendLine("");
            sb.AppendLine("-가천 빌리지-");
            PostSystem.SendPost("새로운 스터디가 만들어졌습니다.", sb.ToString(), "admin_group", user.ID);
        }