Ejemplo n.º 1
0
        public static JObject GetCommentList(int no)
        {
            MysqlNode node = new MysqlNode(Program.mysqlOption, "SELECT * FROM board_writer WHERE parent_no = ?no  ORDER BY no");

            node["no"] = no;
            JObject json = new JObject();

            json["type"] = PacketType.ReadComments;
            json["no"]   = no;
            JArray list = new JArray();

            using (node.ExecuteReader())
            {
                while (node.Read())
                {
                    JObject item = new JObject();
                    item["no"]      = node.GetInt("no");
                    item["content"] = node.GetString("content");
                    item["time"]    = node.GetString("time");
                    item["user_id"] = node.GetInt("user_id");
                    item["name"]    = node.GetString("name");
                    list.Add(item);
                }
            }
            json["list"] = list;
            return(json);
        }
Ejemplo n.º 2
0
        public bool AddFileItem(int no)
        {
            // 해당 번호의 파일이 실제로 있는지 확인 + 파일 정보 불러오기
            MysqlNode node = new MysqlNode(private_data.mysqlOption, "SELECT file.name, file.size, account.name as owner, date FROM file join account on file.owner=account.id where file_no=?no");

            node["no"] = no;
            JObject item = null;

            using (node.ExecuteReader())
            {
                if (node.Read())
                {
                    item          = new JObject();
                    item["type"]  = NetworkProtocol.Inventory_Add;
                    item["no"]    = no;
                    item["size"]  = node.GetInt("size");
                    item["name"]  = node.GetString("name");
                    item["date"]  = node.GetDateTime("date");
                    item["owner"] = node.GetString("owner");
                }
                else
                {
                    return(false);
                }
            }
            node       = new MysqlNode(private_data.mysqlOption, "INSERT INTO inventory(student_id, file_no) VALUES (?id, ?no)");
            node["id"] = ID;
            node["no"] = no;
            if (node.ExecuteInsertQuery() < 0)
            {
                return(false);
            }
            socket.Send(item);
            return(true);
        }
Ejemplo n.º 3
0
        public static JObject RankingList(String category)
        {
            JObject json = new JObject();

            json["type"]     = PacketType.RestaurantRankingList;
            json["category"] = category;
            MysqlNode node = new MysqlNode(Program.mysqlOption, "SELECT * FROM restaurant join rest_likes on restaurant.no=rest_likes.no WHERE category REGEXP (?data) ORDER BY likes desc");

            node["data"] = category.Replace(",", "|");
            JArray list = new JArray();

            json["list"] = list;
            using (node.ExecuteReader())
            {
                while (node.Read())
                {
                    JObject item = new JObject();
                    item["no"]       = node.GetInt("no");
                    item["title"]    = node.GetString("title");
                    item["time"]     = node.GetString("computed_waiting");
                    item["likes"]    = node.GetString("likes");
                    item["category"] = node.GetString("category");

                    list.Add(item);
                }
            }
            return(json);
        }
Ejemplo n.º 4
0
        public static void GetPostList(ESocket socket, int no)
        {
            string id = GachonSocket.GetId(socket);

            if (id != null)
            {
                MysqlNode mysqlNode = new MysqlNode(private_data.mysqlOption, "SELECT * FROM post_name where receiver=?id and no > ?no order by date");
                mysqlNode["no"] = no;
                mysqlNode["id"] = id;
                JArray array = new JArray();
                using (mysqlNode.ExecuteReader())
                {
                    while (mysqlNode.Read())
                    {
                        JObject item = new JObject();
                        item["title"]     = mysqlNode.GetString("title");
                        item["content"]   = mysqlNode.GetString("content");
                        item["no"]        = mysqlNode.GetInt("no");
                        item["sender"]    = mysqlNode.GetString("sender_name");
                        item["sender_id"] = mysqlNode.GetString("sender");
                        item["date"]      = (mysqlNode.GetDateTime("date")).ToString("yyyy-MM-dd HH:mm:ss");
                        array.Add(item);
                    }
                }

                JObject json = new JObject();
                json["type"]  = AndroidProtocol.PostList;
                json["items"] = array;
                socket.Send(json);
                return;
            }
        }
Ejemplo n.º 5
0
        public static JObject WaitingList()
        {
            MysqlNode node = new MysqlNode(Program.mysqlOption, "SELECT * FROM restaurant");

            JObject json = new JObject();

            json["type"] = PacketType.RestaurantWaitingList;
            JArray list = new JArray();

            using (node.ExecuteReader())
            {
                while (node.Read())
                {
                    if (!node.IsNull("mapx"))
                    {
                        JObject item = new JObject();
                        item["no"]    = node.GetInt("no");
                        item["title"] = node.GetString("title");
                        item["time"]  = node.GetString("computed_waiting");
                        item["x"]     = node.GetDouble("mapx");
                        item["y"]     = node.GetDouble("mapy");
                        list.Add(item);
                    }
                }
            }

            json["list"] = list;
            return(json);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// 인벤토리에 있는 아이템을 바탕으로 해당 클라이언트가 강제로 파일을 다운로드 받도록 만듭니다.
        /// </summary>
        /// <param name="no">MYSQL에 등록된 파일 번호입니다</param>
        /// <param name="user_path">해당 클라이언트에 저장될 경로입니다.</param>
        /// <param name="open">클라이언트가 다운로드 완료시 파일 자동 오픈을 요청했는지 여부입니다.</param>
        public bool DownloadItem(int no, string user_path, bool open)
        {
            // 인벤토리에 해당 파일이 존재하는지 확인
            MysqlNode node = new MysqlNode(private_data.mysqlOption, "SELECT * FROM inventory WHERE student_id=?id AND file_no=?no");

            node["id"] = ID;
            node["no"] = no;
            using (node.ExecuteReader())
            {
                if (!node.Read())
                {
                    ToChatMessage("해당 아이템에 대한 권한이 없습니다.", ChatType.Notice);
                    return(false);
                }
            }
            // 파일 정보 불러오기
            node       = new MysqlNode(private_data.mysqlOption, "SELECT * FROM file where file_no=?no");
            node["no"] = no;
            using (node.ExecuteReader())
            {
                if (node.Read())
                {
                    NServerFile file = new NServerFile(socket, node.GetString("path"));
                    JObject     json = new JObject();
                    json["path"] = user_path;
                    json["open"] = open; // 유저가 파일 열기를 눌렀는 지 여부로 반환해준다.
                    socket.SendFile(json, file);
                    return(true);
                }
            }
            return(false);
        }
Ejemplo n.º 7
0
        //맨 처음 서버를 셋팅을 함. 표에 있는 모든 강의를 읽어온다. 이때 읽어올 때는 SQL 테이블에 추가되지 않도록 false
        public static void Initialize()
        {
            //모든 강의 정보를 데이터베이스 Course 테이블에서 읽어옴
            MysqlNode node = new MysqlNode(GachonOption.MysqlOption, "SELECT * FROM course");

            using (node.ExecuteReader())
            {
                while (node.Read())
                {
                    // Format이 맞는지 확인하기 위해 Class type인지 확인
                    bool        isClassType = node.GetString("type") == "Class";
                    GachonClass newclass    = GachonClass.GetObject(node.GetString("name"), node.GetString("no"), isClassType, false); //title , key

                    //해당 강의에 대한 site정보가 있으면 해당 강의에 연결
                    if (!string.IsNullOrEmpty(node.GetString("eclass")))
                    {
                        newclass.CombineSite(new GachonEClass(node.GetString("eclass")), false);
                    }
                    if (!string.IsNullOrEmpty(node.GetString("gcafe")))
                    {
                        newclass.CombineSite(new GachonCafe(node.GetString("gcafe")), false);
                    }
                    if (!string.IsNullOrEmpty(node.GetString("cyber")))
                    {
                        newclass.CombineSite(new GachonCyberCampus(node.GetString("cyber")), false);
                    }
                    if (!string.IsNullOrEmpty(node.GetString("navercafe")))
                    {
                        newclass.CombineSite(new NaverCafe(node.GetString("navercafe")), false);
                    }
                }
            }
        }
Ejemplo n.º 8
0
        public static void GetFile(ESocket socket, JObject message)
        {
            // 파일 다운로드는 게임에서만 지원
            if (User.Items.ContainsKey(socket))
            {
                User user = User.Items[socket];

                // 요청한 파일, 우편이 실제 있는지 확인
                MysqlNode node = new MysqlNode(private_data.mysqlOption, "SELECT 'true' FROM post WHERE no=?no and file=?file_no and receiver=?id");
                node["no"]      = (int)message["post_no"];
                node["file_no"] = (int)message["file_no"];
                node["id"]      = user.ID;
                using (node.ExecuteReader())
                {
                    if (node.Read())
                    {
                        if (user.AddFileItem((int)message["file_no"]))
                        {
                            NetworkMessageList.TipMessage(socket, "우편함의 첨부파일이 인벤토리에 추가되었습니다.");
                        }
                        else
                        {
                            NetworkMessageList.TipMessage(socket, "파일이 이미 인벤토리에 존재합니다.");
                        }
                    }
                    else
                    {
                        NetworkMessageList.TipMessage(socket, "잘못된 요청입니다.");
                    }
                }
            }
        }
Ejemplo n.º 9
0
        //맨 처음 서버를 셋팅을 함. 표에 있는 모든 강의를 읽어온다. 읽어올 때는 SQL 테이블에 추가되지 않도록 false
        public static void Initialize()
        {
            MysqlNode node = new MysqlNode(GachonOption.MysqlOption, "SELECT * FROM course");

            using (node.ExecuteReader())
            {
                while (node.Read())
                {
                    bool        isClassType = node.GetString("type") == "Class";
                    GachonClass newclass    = GachonClass.GetObject(node.GetString("name"), node.GetString("no"), isClassType, false); //title , key
                    if (!string.IsNullOrEmpty(node.GetString("eclass")))
                    {
                        newclass.CombineSite(new GachonEClass(node.GetString("eclass")), false);
                    }
                    if (!string.IsNullOrEmpty(node.GetString("gcafe")))
                    {
                        newclass.CombineSite(new GachonCafe(node.GetString("gcafe")), false);
                    }
                    if (!string.IsNullOrEmpty(node.GetString("cyber")))
                    {
                        newclass.CombineSite(new GachonCyberCampus(node.GetString("cyber")), false);
                    }
                    if (!string.IsNullOrEmpty(node.GetString("navercafe")))
                    {
                        newclass.CombineSite(new NaverCafe(node.GetString("navercafe")), false);
                    }
                }
            }
        }
Ejemplo n.º 10
0
        public static void SendTakesList(ESocket socket)
        {
            string id = GachonSocket.GetId(socket);

            if (id != null)
            {
                MysqlNode node = new MysqlNode(private_data.mysqlOption, "SELECT * FROM takes_course JOIN course ON takes_course.course_no=course.no WHERE student_id=?id");
                node["id"] = id;
                JArray group  = new JArray();
                JArray course = new JArray();
                using (node.ExecuteReader())
                {
                    while (node.Read())
                    {
                        if (node.GetString("type") == "Class")
                        {
                            course.Add(node.GetString("name"));
                        }
                        else if (node.GetString("type") == "Group")
                        {
                            group.Add(node.GetString("name"));
                        }
                    }
                }

                JObject json = new JObject();
                json["type"]  = AndroidProtocol.GroupList;
                json["group"] = group;
                json["class"] = course;
                socket.Send(json);
            }
        }
Ejemplo n.º 11
0
        public static void Init_Load()
        {
            MysqlNode node = new MysqlNode(private_data.mysqlOption, "SELECT * FROM npc");

            using (node.ExecuteReader())
            {
                while (node.Read())
                {
                    NPC npc = new NPC();
                    npc.skin     = node.GetString("skin");
                    npc.name     = node.GetString("name");
                    npc.function = node.GetString("function");
                    npc.position = new Vector4(node.GetFloat("x"), node.GetFloat("y"), node.GetFloat("z"), node.GetFloat("q"));

                    MysqlNode messagenode = new MysqlNode(private_data.mysqlOption, "SELECT * FROM npc_message WHERE npc_no=?no");
                    messagenode["no"] = node.GetInt("npc_no");
                    using (messagenode.ExecuteReader())
                    {
                        while (messagenode.Read())
                        {
                            npc.AddMessage(messagenode.GetString("message"));
                            Console.WriteLine("NPC " + npc.name + " 메세지 입력 -> " + messagenode.GetString("message"));
                        }
                    }
                    npc.Start();
                    Console.WriteLine("NPC " + npc.name + " 추가");
                }
            }


            Group_Load();
        }
Ejemplo n.º 12
0
        public static int GetMessageCount(string id)
        {
            MysqlNode node = new MysqlNode(private_data.mysqlOption, "SELECT count(*) as ncount from post where receiver=?id");

            node["id"] = id;
            using (node.ExecuteReader())
            {
                node.Read();
                return(node.GetInt("ncount"));
            }
        }
Ejemplo n.º 13
0
 private void TableTest(string table)
 {
     try
     {
         MysqlNode node = new MysqlNode(option, "SELECT * FROM " + table);
         using (node.ExecuteReader());
     }
     catch (Exception e)
     {
         Assert.Fail(e.Message);
     }
 }
Ejemplo n.º 14
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);
            }
        }
Ejemplo n.º 15
0
        /// <summary>
        /// 플레이어가 로딩이 끝났을때 다른 플레이어에게 플레이어 입장 소식을 알리고, 이 플레이어에게 정보를 전달합니다.
        /// </summary>
        public override void Start()
        {
            base.Start();
            // 해당 유저에게도 월드에 있는 다른 오브젝트 표시
            foreach (GameObject item in GameObject.Items.Values)
            {
                if (item != this)
                {
                    JObject json = item.InfoData();
                    json["type"] = NetworkProtocol.NewObject;
                    socket.Send(json);
                }
            }
            // 인벤토리 로드
            MysqlNode node = new MysqlNode(private_data.mysqlOption, "SELECT * FROM inventory_items WHERE student_id=?id");

            node["id"] = ID;
            using (node.ExecuteReader())
            {
                while (node.Read())
                {
                    JObject item = new JObject();
                    item["type"]  = NetworkProtocol.Inventory_Add;
                    item["no"]    = node.GetInt("file_no");
                    item["size"]  = node.GetInt("size");
                    item["name"]  = node.GetString("name");
                    item["date"]  = node.GetDateTime("date");
                    item["owner"] = node.GetString("owner");
                    socket.Send(item);
                }
            }
            // 과제 정보 로드
            node       = new MysqlNode(private_data.mysqlOption, "SELECT takes_course.course_no, title, end_date FROM takes_course JOIN homework_list ON takes_course.course_no=homework_list.course_no WHERE student_id=?id and DATE(NOW()) <= DATE(end_date)");
            node["id"] = ID;
            using (node.ExecuteReader())
            {
                while (node.Read())
                {
                    NetworkMessageList.AddHomework(socket,
                                                   GachonObjects.AllClass[node.GetString("course_no")].Title,
                                                   node.GetString("title"),
                                                   node.GetDateTime("end_date"));
                }
            }
            NetworkMessageList.TipMessage(socket, "가천 빌리지에 오신것을 환영합니다!");
            ToChatMessage("가천 빌리지에 오신것을 환영합니다!", ChatType.Notice);
            int NewMessage = PostSystem.GetNewMessageCount(ID);

            if (NewMessage > 0)
            {
                ToChatMessage("[우편함] " + NewMessage + "개의 읽지 않은 우편이 존재합니다!", ChatType.System);
            }
        }
Ejemplo n.º 16
0
        private static void Group_Load()
        {
            MysqlNode node = new MysqlNode(private_data.mysqlOption, "SELECT * FROM course join `group` on group.group_name=course.no");

            using (node.ExecuteReader())
            {
                while (node.Read())
                {
                    Study group = new Study(node.GetString("group_name"), new Vector4(node.GetFloat("x"), node.GetFloat("y"), node.GetFloat("z"), node.GetFloat("q")));
                    group.Start();
                    Console.WriteLine("Group " + group.name + " 추가");
                }
            }
        }
Ejemplo n.º 17
0
        public static JObject Infomation(int id)
        {
            MysqlNode node = new MysqlNode(Program.mysqlOption, "SELECT * FROM restaurant WHERE no = ?no");

            node["no"] = id;

            using (node.ExecuteReader())
            {
                if (node.Read())
                {
                    JObject json = new JObject();
                    json["type"]        = PacketType.RestaurantInfo;
                    json["title"]       = node.GetString("title");
                    json["category"]    = node.GetString("category");
                    json["description"] = node.GetString("description");
                    json["address"]     = node.GetString("roadAddress");
                    json["image"]       = node.GetString("image");
                    if (node.IsNull("computed_waiting"))
                    {
                        json["waiting"] = null;
                    }
                    else
                    {
                        json["waiting"] = node.GetInt("computed_waiting");
                    }

                    JArray    menus     = new JArray();
                    MysqlNode menu_node = new MysqlNode(Program.mysqlOption, "SELECT * FROM menu WHERE restaurant_no = ?no ORDER BY priority");
                    menu_node["no"] = id;
                    using (menu_node.ExecuteReader())
                    {
                        while (menu_node.Read())
                        {
                            JObject menu = new JObject();
                            menu["name"]        = menu_node.GetString("name");
                            menu["price"]       = menu_node.GetString("price");
                            menu["description"] = menu_node.GetString("description");
                            menu["image"]       = menu_node.GetString("image");
                            menus.Add(menu);
                        }
                    }
                    json["menus"] = menus;
                    return(json);
                }
                else
                {
                    return(null);
                }
            }
        }
Ejemplo n.º 18
0
        public static int GetLikes(int restaurant_no)
        {
            MysqlNode node = new MysqlNode(Program.mysqlOption, "SELECT * FROM rest_likes WHERE no = ?no");

            node["no"] = restaurant_no;
            using (node.ExecuteReader())
            {
                if (node.Read())
                {
                    return(node.GetInt("likes"));
                }
            }
            return(0);
        }
Ejemplo n.º 19
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("유효하지 않은 토큰입니다.");
                }
            }
        }
Ejemplo n.º 20
0
        /// <summary>
        /// 이 그룹이 특정 파일을 가지고 있는지 권한을 체크합니다.
        /// </summary>
        /// <param name="no">파일 번호 (Mysql)</param>
        /// <returns></returns>
        public bool HaveItem(int no)
        {
            MysqlNode node = new MysqlNode(private_data.mysqlOption, "SELECT * FROM group_file_info WHERE group_name=?key AND file_no=?no");

            node["key"] = key;
            node["no"]  = no;
            using (node.ExecuteReader())
            {
                if (node.Read())
                {
                    return(true);
                }
            }
            return(false);
        }
Ejemplo n.º 21
0
        public static string GetTitle(int no)
        {
            MysqlNode node = new MysqlNode(Program.mysqlOption, "SELECT * FROM restaurant WHERE no = ?no");

            node["no"] = no;

            using (node.ExecuteReader())
            {
                if (node.Read())
                {
                    return(node.GetString("title"));
                }
            }
            return(null);
        }
Ejemplo n.º 22
0
        public static Position GetPosition(int no)
        {
            MysqlNode node = new MysqlNode(Program.mysqlOption, "SELECT * FROM restaurant WHERE no = ?no");

            node["no"] = no;
            using (node.ExecuteReader())
            {
                if (node.Read())
                {
                    Position position = new Position(node.GetDouble("mapy"), node.GetDouble("mapx"));
                    return(position);
                }
            }
            return(null);
        }
Ejemplo n.º 23
0
        /// <summary>
        /// 이 유저의 인벤토리에 파일이 존재하는지 확인합니다.
        /// </summary>
        /// <param name="no">MYSQL에 등록된 파일 번호입니다.</param>
        /// <returns></returns>
        public bool HaveItem(int no)
        {
            // 해당 번호의 파일이 실제로 있는지 확인 + 파일 정보 불러오기
            MysqlNode node = new MysqlNode(private_data.mysqlOption, "SELECT 'true' FROM inventory WHERE student_id=?id AND file_no=?no");

            node["id"] = ID;
            node["no"] = no;
            using (node.ExecuteReader())
            {
                if (node.Read())
                {
                    return(true);
                }
            }
            return(false);
        }
Ejemplo n.º 24
0
        public static List <int> GetRelatedUser(int no)
        {
            MysqlNode node = new MysqlNode(Program.mysqlOption, "SELECT * FROM board WHERE parent_no = ?no or no = ?no");

            node["no"] = no;
            List <int> list = new List <int>();

            using (node.ExecuteReader())
            {
                while (node.Read())
                {
                    list.Add(node.GetInt("user_id"));
                }
            }
            return(list);
        }
Ejemplo n.º 25
0
        /// <summary>
        /// 해당 그룹의 채팅 기록을 가져옵니다.
        /// </summary>
        /// <param name="limit">끝에서부터 몇번째까지 가져올지 설정합니다.</param>
        /// <returns></returns>
        public string GetChattingData(int limit = 1000)
        {
            string    data = "";
            MysqlNode node = new MysqlNode(private_data.mysqlOption, "SELECT * FROM group_chat_report where group_name=?id ORDER BY no DESC limit ?line");

            node["line"] = limit;
            node["id"]   = key;
            using (node.ExecuteReader())
            {
                while (node.Read())
                {
                    data = "[" + node.GetDateTime("date").ToString("yyyy-MM-dd HH:mm:ss") + "] " + node.GetString("who") + " : " + node.GetString("data") + "\r\n" + data;
                }
            }
            return(data);
        }
Ejemplo n.º 26
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();
                }
            }
        }
Ejemplo n.º 27
0
        public static JObject RecommendList(Position position)
        {
            if (position == null)
            {
                return(null);
            }
            MysqlNode node = new MysqlNode(Program.mysqlOption, "SELECT * FROM restaurant join rest_likes on restaurant.no=rest_likes.no ORDER BY likes DESC");

            JObject json = new JObject();

            json["type"] = PacketType.RestaurantRecommendList;
            JArray list = new JArray();

            using (node.ExecuteReader())
            {
                while (node.Read())
                {
                    if (list.Count == 4)
                    {
                        break;
                    }
                    if (!node.IsNull("mapx"))
                    {
                        Position rest_position = new Position(node.GetDouble("mapy"), node.GetDouble("mapx"));
                        double   meter         = position.DistanceToMeter(rest_position);
                        if (meter < 1000)
                        {
                            JObject item = new JObject();
                            item["no"]    = node.GetInt("no");
                            item["title"] = node.GetString("title");
                            if (node.IsNull("computed_waiting"))
                            {
                                item["time"] = "정보 없음";
                            }
                            else
                            {
                                item["time"] = node.GetInt("computed_waiting") + "분";
                            }
                            item["meter"] = (int)meter + "M";
                            list.Add(item);
                        }
                    }
                }
            }
            json["list"] = list;
            return(json);
        }
Ejemplo n.º 28
0
        public static bool ClickedLikes(OnlineUser user, int restaurant_no)
        {
            MysqlNode node = new MysqlNode(Program.mysqlOption, "SELECT * FROM rest_likes_data WHERE user_id = ?id and restaurant_no = ?no");

            node["no"] = restaurant_no;
            node["id"] = user.id;
            using (node.ExecuteReader())
            {
                if (node.Read())
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
        }
Ejemplo n.º 29
0
        public static JObject GetID(string title)
        {
            MysqlNode node = new MysqlNode(Program.mysqlOption, "SELECT * FROM restaurant WHERE title = ?title");

            node["title"] = title;

            using (node.ExecuteReader())
            {
                if (node.Read())
                {
                    JObject json = new JObject();
                    json["type"] = PacketType.GetRestaurantID;
                    json["no"]   = node.GetInt("no");
                    return(json);
                }
            }
            return(null);
        }
Ejemplo n.º 30
0
        /// <summary>
        /// 가천 라이브러리에서 새로운 게시글이 올라오면 이 함수를 이벤트로 실행시킵니다.
        /// </summary>
        /// <param name="gclass">게시글이 올라온 강의</param>
        /// <param name="postItem">게시글</param>
        public static void NewPost(GachonClass gclass, PostItem postItem)
        {
            MysqlNode node      = new MysqlNode(private_data.mysqlOption, "SELECT * FROM keyword");
            JArray    array     = new JArray();
            string    ignore_id = "";

            using (node.ExecuteReader())
            {
                while (node.Read())
                {
                    if (ignore_id == node.GetString("student_id"))
                    {
                        continue;
                    }
                    string keyword = node.GetString("keyword");
                    if (CheckValid(keyword, gclass.Title, postItem.Title))
                    {
                        ignore_id = node.GetString("student_id");
                        PostSystem.SendPost(
                            string.Format("[{0}] 새로운 게시글 등록", gclass.Title),
                            string.Format("[게시글 정보]\r\n{0} - {1}\r\n\r\n{2}\r\n\r\nURL : {3}", postItem.Title, postItem.Publisher, postItem.Content, postItem.url),
                            "admin_keyword",
                            ignore_id
                            , false);
                        ESocket socket = GachonSocket.GetOnlineUser(ignore_id);
                        if (socket != null)
                        {
                            if (User.Items.ContainsKey(socket))
                            {
                                User.Items[socket].ToChatMessage("[" + gclass.Title + "] 에 새로운 게시글이 등록되었습니다.", ChatType.System);
                                if (postItem.posttype == BoardType.PostType.Homework)
                                {
                                    NetworkMessageList.AddHomework(socket,
                                                                   gclass.Title,
                                                                   postItem.Title,
                                                                   postItem.e_time);
                                }
                            }
                        }
                    }
                }
            }
        }