Beispiel #1
0
        public static void AddWaitingListener(OnlineUser user, int no)
        {
            if (!get_waiting_queue.ContainsKey(no))
            {
                get_waiting_queue[no] = new CacheList <int>(1800);
            }
            get_waiting_queue[no].Add(user.id);
            // 결과 전송
            user.Send(GetContainsWaitingListener(user, no));
            user.Message("30분간 이 음식점의 대기열 정보를 직접 수신합니다.");

            // 다른 유저들에게 메세지 전송
            JObject json = new JObject();

            json["type"]  = PacketType.RequestWaitingToUser;
            json["no"]    = no;
            json["title"] = GetTitle(no);

            Position position = GetPosition(no);

            foreach (OnlineUser other_user in Program.users.Values)
            {
                if (other_user.position != null && other_user.position.DistanceToMeter(position) < 256)
                {
                    if (!OnlineUser.receive_waiting_user.Contains(other_user.id))
                    {
                        other_user.Send(json);
                    }
                }
            }
        }
Beispiel #2
0
        public void SendHistory(OnlineUser user)
        {
            Packet packet = new Packet();

            packet["messageType"] = "history";
            JsonSharp.JsonArray array = new JsonSharp.JsonArray();
            foreach (Packet message in historyMessage)
            {
                array.elements.Add(message.ToJsonObject());
            }
            packet["messages"] = array;
            user.Send(packet);
        }
Beispiel #3
0
        public static bool WriteArticle(OnlineUser user, string content, int parent_no = 0)
        {
            if (string.IsNullOrEmpty(content))
            {
                user.Message("내용을 입력해주세요.");
                return(false);
            }
            MysqlNode menu_update = new MysqlNode(Program.mysqlOption, "INSERT INTO board (user_id, content, parent_no) VALUES (?user_id, ?content, ?parent_no)");

            menu_update["user_id"] = user.id;
            menu_update["content"] = content;
            if (parent_no == 0)
            {
                menu_update["parent_no"] = null;
            }
            else
            {
                menu_update["parent_no"] = parent_no;
            }
            long result = menu_update.ExecuteInsertQuery();

            if (result > 0)
            {
                if (parent_no == 0)
                {
                    JObject json = new JObject();
                    json["type"] = PacketType.WriteBoardItem;
                    json["item"] = ((JArray)GetList((int)result)["list"])[0];
                    OnlineUser.SendAll(json);
                }
                else
                {
                    user.Send(GetCommentList(parent_no));
                    List <int> RelatedUser = GetRelatedUser(parent_no);
                    foreach (int id in RelatedUser)
                    {
                        if (id != user.id) // 올린 사람은 제외
                        {
                            OnlineUser.Notify(id, "comment", (int)result, "내가 올린 게시글에 답변이 등록되었습니다.", "(" + user.name + ") " + content);
                        }
                    }
                }
                user.Message("등록에 성공했습니다.");
                return(true);
            }
            else
            {
                user.Message("등록에 실패했습니다.");
                return(false);
            }
        }
Beispiel #4
0
 /// <summary>
 /// Send a packet to the indicated user.
 /// </summary>
 /// <param name="user">Indicated user</param>
 /// <param name="packet">The packet to be sent</param>
 void SendPacket(OnlineUser user, Packet packet)
 {
     try
     {
         if (user.Connected)
         {
             user.Send(packet);
         }
     }
     catch (Exception ex)
     {
         Error($"Error occured while sending message to user \"{user.Username}\": {Unescape(ex.ToString())}");
     }
 }
Beispiel #5
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("요청이 실패했습니다.");
            }
        }