Exemplo n.º 1
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);
        }
Exemplo n.º 2
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("유효하지 않은 토큰입니다.");
                }
            }
        }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
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);
        }