예제 #1
0
        public async Task <bool> UploadFileAsync(TreeNode node, FileInfo file)
        {
            Directory_Info dir = (Directory_Info)node.Tag;

            socket.CryptoSend(BlindNetUtil.StructToByte(dir), PacketType.DocFileUpload);

            File_Info fi = new File_Info();

            fi.id      = 0;
            fi.name    = file.Name;
            fi.size    = (uint)file.Length;
            fi.modDate = file.LastWriteTime.ToString();
            fi.type    = Path.GetExtension(file.FullName).Replace(".", "");
            socket.CryptoSend(BlindNetUtil.StructToByte(fi), PacketType.Info);

            FileStream fs = file.OpenRead();

            byte[] buffer = new byte[fs.Length];
            await fs.ReadAsync(buffer, 0, (int)fs.Length);

            fs.Close();

            SendFile(buffer);
            BlindPacket packet = socket.CryptoReceive();

            if (packet.header == PacketType.Fail)
            {
                return(false);
            }

            return(true);
        }
예제 #2
0
        public Invitation_Form(int _roomID)
        {
            InitializeComponent();
            this.StartPosition = FormStartPosition.Manual;

            this.isMove  = false;
            this._roomID = _roomID;
            _UserCount   = 0;
            _userList    = BlindChat.GetUserList(this._roomID);

            btn_Invite.BackColor    = btn_Cancel.BackColor = BlindColor.DarkGreen;
            lbl_UserCount.BackColor = label1.BackColor = btn_close.BackColor = BlindColor.DarkGreen;
            lbl_UserCount.ForeColor = label1.ForeColor = BlindColor.Light;
            btn_Cancel.ForeColor    = btn_Invite.ForeColor = BlindColor.Light;

            panel5.BackColor = BlindColor.Light;
            panel4.BackColor = BlindColor.Gray;

            InvitationItem_LayoutPanel.BackColor = BlindColor.Gray;

            BlindNetUtil.SetEllipse(this, 5);
            BlindNetUtil.SetEllipse(panel5, 5);

            BlindNetUtil.SetEllipse(btn_Invite, 15);
            BlindNetUtil.SetEllipse(btn_Cancel, 15);
        }
예제 #3
0
        public CreateRoomForm(uint _UserID)
        {
            InitializeComponent();

            this.StartPosition = FormStartPosition.CenterParent;
            this._UserID       = _UserID;
            _UserCount         = 1;

            this.BackColor          = Color.Black;
            lbl_UserCount.BackColor = button1.BackColor = lbl_FormName.BackColor = panel4.BackColor = BlindColor.DarkGreen;
            label1.BackColor        = lbl_FormName.ForeColor = panel4.ForeColor = BlindColor.Light;

            btn_Cancel.BackColor        = btn_Confirm.BackColor = BlindColor.DarkGreen;
            tableLayoutPanel1.BackColor = btn_Cancel.ForeColor = btn_Confirm.ForeColor = BlindColor.Light;

            CreateRoomIItem_LayoutPanel.BackColor = BlindColor.Gray;
            panel3.BackColor = BlindColor.Light;

            lbl_UserCount.ForeColor = BlindColor.Light;
            panel7.BackColor        = tb_RoomName.BackColor = BlindColor.Light;

            BlindNetUtil.SetEllipse(this, 5);
            BlindNetUtil.SetEllipse(tableLayoutPanel1, 5);
            BlindNetUtil.SetEllipse(panel4, 10);
            BlindNetUtil.SetEllipse(btn_Confirm, 15);
            BlindNetUtil.SetEllipse(btn_Cancel, 15);
        }
예제 #4
0
        public MessageRoom(uint userID, ChatRoom room, List <ChatMessage> messageList)
        {
            InitializeComponent();

            isMove       = false;
            _userID      = userID;
            _room        = room;
            _messageList = messageList;
            this.Name    = room.ID.ToString();
            this.Text    = this.lbl_Title.Text = _room.Name;
            if (lbl_Title.Text.Length > 8)
            {
                lbl_Title.Text = lbl_Title.Text.Substring(0, 8) + "...";
            }
            this.StartPosition = FormStartPosition.Manual;

            panel1.BackColor              = lbl_Title.BackColor = btn_menu.BackColor = button1.BackColor = BlindColor.DarkGreen;
            lbl_Title.ForeColor           = button1.ForeColor = BlindColor.Light;
            panel4.BackColor              = btn_Send.ForeColor = BlindColor.Light;
            btn_Send.BackColor            = BlindColor.DarkGreen;
            panel5.BackColor              = tb_Message.BackColor = BlindColor.Light;
            message_LayoutPanel.BackColor = BlindColor.DarkGray;

            BlindNetUtil.SetEllipse(this, 5);
            //BlindNetUtil.SetEllipse(btn_Send, 5);
            BlindNetUtil.SetEllipse(panel4, 5);
            BlindNetUtil.SetEllipse(btn_menu, 20);
        }
예제 #5
0
        public void Run()
        {
            BS = new BlindSocket();
            BP = new BlindPacket();
            BS.ConnectWithECDH(BlindNetConst.ServerIP, BlindNetConst.WebDevicePort);

            while (true)
            {
                try
                {
                    BP = BS.CryptoReceive();// 아이디에 따른 장치제어 결과 받아옴
                }
                catch
                {
                    break;
                }
                BP.data = BlindNetUtil.ByteTrimEndNull(BP.data);
                string ReceiveByteToStringGender = Encoding.Default.GetString(BP.data);// 변환 바이트 -> string = default,GetString | string -> 바이트 = utf8,GetBytes

                //11 : USB,CAM 차단 | 10: USB만 차단 | 01: 웹캠만 차단 | 00 : 모두허용
                DeviceToggle(ReceiveByteToStringGender);

                Thread.Sleep(1000);
            }
        }
예제 #6
0
        void UpdateDir(uint dirID)
        {
            string          command   = "SELECT id, parent_id, name, modified_date FROM directorys_info WHERE parent_id = " + dirID.ToString() + ";";
            MySqlCommand    commander = new MySqlCommand(command, connection);
            MySqlDataReader reader    = commander.ExecuteReader();

            while (reader.Read())
            {
                Directory_Info dir = new Directory_Info();
                dir.id        = (uint)reader["id"];
                dir.parent_id = (uint)reader["parent_id"];
                dir.name      = (string)reader["name"];
                dir.modDate   = ((DateTime)reader["modified_date"]).ToString();
                socket.CryptoSend(BlindNetUtil.StructToByte(dir), PacketType.Sending);
            }
            reader.Close();
            socket.CryptoSend(null, PacketType.EOF);

            command   = "SELECT id, name, modified_date, UPPER(type), size FROM files_info WHERE dir_id = " + dirID.ToString() + ";";
            commander = new MySqlCommand(command, connection);
            reader    = commander.ExecuteReader();
            while (reader.Read())
            {
                File_Info file = new File_Info();
                file.id      = (uint)reader["id"];
                file.name    = (string)reader["name"];
                file.modDate = reader["modified_date"].ToString();
                file.type    = (string)reader["UPPER(type)"];
                file.size    = (uint)reader["size"];
                socket.CryptoSend(BlindNetUtil.StructToByte(file), PacketType.Sending);
            }
            reader.Close();
            socket.CryptoSend(null, PacketType.EOF);
        }
예제 #7
0
        void UpdateRoot()
        {
            if (!connection.Ping())
            {
                Console.WriteLine("ERROR : [UID : " + uid + "] Database connection is terminate");
                return;
            }

            SetAccessibleDirs();
            if (accessibleDirs.Length < 1)
            {
                socket.CryptoSend(null, PacketType.EOF);
                return;
            }

            string          command   = "SELECT id, parent_id, name FROM directorys_info WHERE id IN (" + UintArrToString(accessibleDirs) + ");";
            MySqlCommand    commander = new MySqlCommand(command, connection);
            MySqlDataReader reader    = commander.ExecuteReader();

            while (reader.Read())
            {
                Directory_Info dir = new Directory_Info();
                dir.id        = (uint)reader["id"];
                dir.parent_id = (uint)reader["parent_id"];
                dir.name      = (string)reader["name"];
                socket.CryptoSend(BlindNetUtil.StructToByte(dir), PacketType.Sending);
            }
            reader.Close();
            socket.CryptoSend(null, PacketType.EOF);
        }
예제 #8
0
        private void MainForm_Load(object sender, EventArgs e)
        {
            this.FormClosed += MainForm_FormClosed; //폼 종료되는 것 연결

            if (!BlindNetUtil.IsConnectedInternet())
            {
                MessageBox.Show("There is no internet connection", "확인", MessageBoxButtons.OK);
                Close();
            }

            bool result = mainSocket.ConnectWithECDH();

            if (!result)
            {
                MessageBox.Show("Main socket connection failed.", "확인", MessageBoxButtons.OK);
                Close();
            }

            //단축키&타이머 등록
            BlindLockTimer.Enabled = true;
            RegisterHotKey(this.Handle, 0, KeyModifiers.Windows, Keys.L);
            RegisterHotKey(this.Handle, 1, KeyModifiers.Alt, Keys.L);

            ActivateControl(MainControl.Document);
        }
예제 #9
0
        static byte[] AddDataToFile(uint id, byte[] data)
        {
            uint timestemp = uint.Parse(DateTime.Now.ToString("yyyyMMdd"));

            byte[] result = BlindNetUtil.MergeArray(BitConverter.GetBytes(timestemp), data);
            result = BlindNetUtil.MergeArray(BitConverter.GetBytes(id), result);
            return(result);
        }
예제 #10
0
        public async Task <bool> DownloadDir(ListViewItem item)
        {
            form.label_fName.Text = "(압축중)" + form.selected.FullPath + "\\" + item.Text;
            form.label_fName.Update();

            uint id = (uint)item.Tag;

            socket.CryptoSend(BitConverter.GetBytes(id), PacketType.DocDirDownload);

            BlindPacket packet = await Task.Run(() => { return(socket.CryptoReceive()); });

            if (packet.header == PacketType.Fail)
            {
                return(false);
            }

            form.label_fName.Text = form.selected.FullPath + "\\" + item.Text;
            form.label_fName.Update();

            string fileName = dPath + item.Text + ".zip";

            byte[] data     = null;
            bool   recvMode = false;

            do
            {
                packet = socket.CryptoReceive(recvMode);
                if (packet.header == PacketType.Disconnect)
                {
                    return(false);
                }
                data = BlindNetUtil.MergeArray <byte>(data, packet.data);
                form.progressBar.PerformStep();
                if (form.progressBar.Value < form.progressBar.Maximum)
                {
                    form.progressBar.Value += 1;
                }
                form.progressBar.Value -= 1;
                form.label_percent.Text = (form.progressBar.Value * 100 / form.progressBar.Maximum) + "%";
                form.label_percent.Update();
                recvMode = true;
            } while (packet.header == PacketType.Sending);
            data = BlindNetUtil.ByteTrimEndNull(data);

            FileInfo file = new FileInfo(fileName);
            int      tmp  = 1;

            while (file.Exists)
            {
                file = new FileInfo(file.DirectoryName + "\\" + Path.GetFileNameWithoutExtension(fileName) + "(" + tmp++ + ")" + file.Extension);
            }
            FileStream fs = file.OpenWrite();

            fs.Write(data, 0, data.Length);
            fs.Close();
            return(true);
        }
예제 #11
0
        public User_Category(string department)
        {
            InitializeComponent();
            Lbl_Category.Text      = department;
            Lbl_Category.ForeColor = BlindColor.Light;
            //Lbl_Category.BackColor = BlindColor.Info;

            BlindNetUtil.SetEllipse(this, 3);
        }
예제 #12
0
        public static T ChatPacketToStruct <T>(ChatPacket chatPack) where T : struct
        {
            byte[] chatPackByte = new byte[Marshal.SizeOf(typeof(T))];
            Array.Copy(chatPack.Data, chatPackByte, chatPackByte.Length);

            T data = BlindNetUtil.ByteToStruct <T>(chatPackByte);

            return(data);
        }
예제 #13
0
        public void Run()
        {
            this.hDB = new MySqlConnection("Server=" + BlindNetConst.DatabaseIP + ";Database=BlindChat;Uid=root;Pwd=kit2020;");
            this.hDB.Open();

            recvSock = GetChatRecvSocket();
            sendSock = GetChatSendSocket();

            IPEndPoint iep = (IPEndPoint)(recvSock.socket.RemoteEndPoint);

            logger = new Logger(UserID, iep.Address.ToString(), LogService.Chat);


            SetOnline((int)UserStat.Online);

            byte[] data;
            while (true)
            {
                data = recvSock.CryptoReceiveMsg();

                if (data == null)
                {
                    recvSock.Close();
                    sendSock.Close();
                    SetOnline((int)UserStat.Offline);
                    global.ListBlindChat.Remove(this);
                    logger.Log(LogRank.INFO, "BlindChat Disconnected");
                    return;
                }

                ChatPacket chatPacket = BlindNetUtil.ByteToStruct <ChatPacket>(data);
                if (chatPacket.Type == ChatType.Time)
                {
                    ClientUpdateData(chatPacket);
                    logger.Log(LogRank.INFO, "Chat Data Synchronized");
                }
                else if (chatPacket.Type == ChatType.NewRoom)
                {
                    ExecuteNewRoom(chatPacket);
                    logger.Log(LogRank.INFO, "Created New Chat Room");
                }
                else if (chatPacket.Type == ChatType.Message)
                {
                    MessageToParticipants(chatPacket);
                }
                else if (chatPacket.Type == ChatType.RoomJoined)
                {
                    ExecuteInvitation(chatPacket);
                }
                else if (chatPacket.Type == ChatType.Exit)
                {
                    ExecuteExit(chatPacket);
                }
            }
        }
예제 #14
0
        public Room_Item(ChatRoom Room)
        {
            InitializeComponent();
            lbl_Name.Cursor = Cursors.Hand;

            this.BackColor     = BlindColor.Primary;
            lbl_Time.ForeColor = lbl_Name.ForeColor = BlindColor.Light;
            BlindNetUtil.SetEllipse(this, 15);

            _Room = Room;
        }
예제 #15
0
        public User_Item(User user)
        {
            InitializeComponent();
            Lbl_UserPosition.Cursor = Cursors.Hand;
            Lbl_UserName.Cursor     = Cursors.Hand;
            BlindNetUtil.SetEllipse(this, 10);

            this.BackColor             = BlindColor.Gray;
            Lbl_UserPosition.ForeColor = BlindColor.Primary;

            _user = user;
        }
예제 #16
0
        public Menu_item(string name)
        {
            InitializeComponent();

            BlindNetUtil.SetEllipse(this, 5);
            this.BackColor     = BlindColor.Primary;
            lbl_name.ForeColor = BlindColor.Light;
            lbl_name.BackColor = BlindColor.Primary;

            userName      = name;
            lbl_name.Text = userName;
        }
예제 #17
0
        public void UpdateDir(TreeNode node)
        {
            form.listview_File.BeginUpdate();
            form.listview_File.Items.Clear();
            node.Nodes.Clear();

            socket.CryptoSend(BitConverter.GetBytes(((Directory_Info)(node.Tag)).id), PacketType.DocDirInfo);
            while (true)
            {
                BlindPacket packet = socket.CryptoReceive();
                if (packet.header == PacketType.EOF)
                {
                    break;
                }

                Directory_Info dir     = BlindNetUtil.ByteToStruct <Directory_Info>(BlindNetUtil.ByteTrimEndNull(packet.data));
                TreeNode       subNode = new TreeNode();
                subNode.Tag                = dir;
                subNode.Text               = dir.name;
                subNode.ImageIndex         = 0;
                subNode.SelectedImageIndex = 0;
                node.Nodes.Add(subNode);

                ListViewItem item = new ListViewItem();
                item.Text = dir.name;
                item.SubItems.Add(dir.modDate);
                item.SubItems.Add(string.Empty);
                item.Tag        = dir.id;
                item.ImageIndex = 0;
                form.listview_File.Items.Add(item);
            }

            while (true)
            {
                BlindPacket packet = socket.CryptoReceive();
                if (packet.header == PacketType.EOF)
                {
                    break;
                }

                File_Info    file = BlindNetUtil.ByteToStruct <File_Info>(BlindNetUtil.ByteTrimEndNull(packet.data));
                ListViewItem item = new ListViewItem();
                item.Text       = file.name;
                item.ImageIndex = 1;
                item.SubItems.Add(file.modDate);
                item.SubItems.Add(file.type);
                item.SubItems.Add(ConvertSize(file.size));
                item.Tag = file.id;
                form.listview_File.Items.Add(item);
            }
            form.listview_File.EndUpdate();
        }
예제 #18
0
        public void ExecuteNewRoom(ChatPacket chatPack)
        {
            string        timeNow = System.DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss");
            NewRoomStruct newroom = BlindChatUtil.ChatPacketToStruct <NewRoomStruct>(chatPack);

            //DB에 방 정보 추가
            string sql = $"insert into ChatRoom (Name, Time, LastMessageTime) values (\'{newroom.Name}\',\'{timeNow}\', \'{timeNow}\');";

            ExecuteQuery(sql);

            //방금 생성한 방 정보 불러오기(roomid를 알아오기 위해)
            sql = $"select * from ChatRoom where Time = \'{timeNow}\';";
            MySqlDataReader rdr = ExecuteSelect(sql);

            if (rdr.Read())
            {
                int RoomID = int.Parse(rdr["ID"].ToString());
                rdr.Close();
                //방에 속한 사용자를 등록한다.
                for (int i = 0; newroom.UserID[i] != 0; i++)
                {
                    sql = $"insert into ChatRoomJoined (UserID, RoomID, Time) values ({newroom.UserID[i]}, {RoomID}, \'{timeNow}\');";
                    ExecuteQuery(sql);
                }
                //방에 속한 사용자들에게 전송
                ClientUpdateNewRoom(RoomID);

                for (int i = 0; newroom.UserID[i] != 0; i++)
                {
                    ChatMessage message = new ChatMessage();
                    message.RoomID = RoomID;
                    message.UserID = 0;
                    message.Time   = timeNow;

                    sql = $"select * from User where ID = {newroom.UserID[i]}";
                    MySqlDataAdapter adpt = new MySqlDataAdapter(sql, hDB);
                    DataSet          ds   = new DataSet();
                    adpt.Fill(ds);
                    foreach (DataRow row in ds.Tables[0].Rows)
                    {
                        User userInfo = (User)GetStructFromDB <User>(row);
                        message.Message = $"{userInfo.Name}님이 입장하셨습니다.";
                    }
                    byte[]     _data   = BlindNetUtil.StructToByte(message);
                    ChatPacket _packet = BlindChatUtil.ByteToChatPacket(_data, ChatType.Message);
                    SendChatPacketToParticipants(_packet, message.RoomID);

                    //시간을 수정한 메시지를 DB에 등록
                    AddToDBTimeNow <ChatMessage>(_packet);
                }
            }
        }
예제 #19
0
        public ChatPacket ChatPacketReceive()
        {
            byte[] data = recvSock.CryptoReceiveMsg();
            if (data == null)
            {
                recvSock.Close();
                sendSock.Close();
                MessageBox.Show("disconnected");
            }
            ChatPacket chatPack = BlindNetUtil.ByteToStruct <ChatPacket>(data);

            return(chatPack);
        }
예제 #20
0
 public void ChatPacketSend(ChatPacket chatPacket)
 {
     if (chatPacket.Data.Length > BlindChatConst.CHATDATASIZE)
     {
         Console.WriteLine("data size must be 2048 bytes!");
         return;
     }
     else
     {
         byte[] packData = BlindNetUtil.StructToByte(chatPacket);
         sendSock.CryptoSend(packData, PacketType.Info);
     }
 }
예제 #21
0
        public bool CopyDir(uint srcDir, uint file, uint dstDir)
        {
            SrcDstInfo info = new SrcDstInfo(srcDir, file, dstDir);

            socket.CryptoSend(BlindNetUtil.StructToByte(info), PacketType.DocCopyDir);
            BlindPacket packet = socket.CryptoReceive();

            if (packet.header != PacketType.OK)
            {
                return(false);
            }
            return(true);
        }
예제 #22
0
        public void Run()
        {
            connection = new MySqlConnection("Server = " + BlindNetConst.DatabaseIP + "; Port = 3306; Database = document_center; Uid = root; Pwd = kit2020");
            mainSocket = new BlindServerScoket(BlindNetConst.ServerIP, BlindNetConst.OPENNERPORT);
            mainSocket.BindListen();
            while (true)
            {
                BlindSocket client = mainSocket.AcceptWithECDH();
                IPEndPoint  iep    = (IPEndPoint)(client.socket.RemoteEndPoint);
                Console.WriteLine("Accepted {0} : {1}", iep.Address, iep.Port);
                if (client == null)
                {
                    continue;
                }

                byte[] data = BlindNetUtil.ByteTrimEndNull(client.CryptoReceiveMsg());
                byte[] tmp  = new byte[4];
                Array.Copy(data, 0, tmp, 0, data.Length);
                string ext = GetExt(BitConverter.ToUInt32(tmp, 0));
                if (ext == null)
                {
                    client.CryptoSend(null, PacketType.Disconnect);
                    continue;
                }
                client.CryptoSend(Encoding.UTF8.GetBytes(ext), PacketType.Info);

                data = BlindNetUtil.ByteTrimEndNull(client.CryptoReceiveMsg());
                tmp  = new byte[4];
                Array.Copy(data, 0, tmp, 0, data.Length);
                int    encryptDate = BitConverter.ToInt32(tmp, 0);
                byte[] key, iv;
                if (!GetSpecifyKeyPair(out key, out iv, encryptDate))
                {
                    client.CryptoSend(null, PacketType.Disconnect);
                    continue;
                }
                client.CryptoSend(key, PacketType.Info);
                client.CryptoSend(iv, PacketType.Info);

                byte[] latestKey, latestIv;
                if (!GetLatestKeyPair(out latestKey, out latestIv))
                {
                    client.CryptoSend(null, PacketType.Disconnect);
                    continue;
                }
                client.CryptoSend(latestKey, PacketType.Info);
                client.CryptoSend(latestIv, PacketType.Info);

                client.Close();
            }
        }
예제 #23
0
        public bool UpdateNameDir(TreeNode node, string name)
        {
            Directory_Info dir = (Directory_Info)(node.Tag);

            dir.name = name;
            socket.CryptoSend(BlindNetUtil.StructToByte(dir), PacketType.DocChngNameDir);

            BlindPacket packet = socket.CryptoReceive();

            if (packet.header == PacketType.Fail)
            {
                return(false);
            }
            return(true);
        }
예제 #24
0
        private void MainForm_Shown(object sender, EventArgs e)
        {
            VPNClass = new VPN_Class();
            //클라이언트 cid 서버로부터 받아오기
            //ClientID = "test1";
            string SendMsg = ClientID + "," + isInner;                             //아이디 + 내부 외부 보내서 외부면 vpn로그남김 (isInner bool형. 디버그했을때 실질적인 값 : true -> "True" | false -> "False")

            byte[] SendStringToByteGender = Encoding.UTF8.GetBytes(SendMsg);       // String -> bytes 변환
            mainSocket.CryptoSend(SendStringToByteGender, PacketType.Response);    //서버로 클라이언트 id 보냄
            blindClientCidPacket = mainSocket.CryptoReceive();                     // 서버로부터 cid받아옴
            byte[] data = BlindNetUtil.ByteTrimEndNull(blindClientCidPacket.data); // 넑값 지움
            byte[] tmp  = new byte[4];
            Array.Copy(data, 0, tmp, 0, data.Length);
            uint ClintCID = BitConverter.ToUInt32(tmp, 0);

            if (ClintCID == 0) //서버에서 아이디를 조회못했을때 0반환
            {
                MessageBox.Show("서버로부터 id를 받지 못하였거나 등록되지 않은 아이디입니다." + Environment.NewLine + "\t           관리자에게 문의하십시요.");
                mainSocket.Close();
                Application.Exit();
                return;
            }

            //각 기능 객체 및 Task 생성
            TaskScheduler scheduler = TaskScheduler.Default;

            token = new CancellationTokenSource();

            documentCenter = new Doc_Center(document_Center, isInner);
            documentCenter.Run();
            document_Center.docCenter = documentCenter;

            _ChatMain      = new ChatMain(ClintCID);
            _ChatMain.Dock = DockStyle.Fill;
            MainControlPanel.Controls.Add(_ChatMain);

            //Func
            chat  = new BlindChat(ClintCID, ref _ChatMain, this);
            tChat = Task.Factory.StartNew(() => chat.Run(), token.Token, TaskCreationOptions.LongRunning, scheduler);

            //ScreenLocking
            lockForm = new LockForm(isInner, ClientID);
            lockForm.connect();
            MessageBox.Show("락 연결!");

            deviceDriver  = new DeviceDriverHelper();
            tDeviceDriver = Task.Factory.StartNew(() => deviceDriver.Run(), token.Token, TaskCreationOptions.LongRunning, scheduler);
        }
예제 #25
0
        public CreateRoom_Item(User user)
        {
            InitializeComponent();
            _User      = user;
            _isClicked = false;

            this.BackColor   = BlindColor.LightGreen;
            panel1.BackColor = BlindColor.Primary;
            panel2.BackColor = btn_Check.BackColor = BlindColor.Light;


            BlindNetUtil.SetEllipse(this, 10);
            BlindNetUtil.SetEllipse(panel1, 30);
            BlindNetUtil.SetEllipse(panel2, 40);
            BlindNetUtil.SetEllipse(btn_Check, 40);
        }
예제 #26
0
        public void ClientUpdateUser(string Time)//새로 추가된 사용자가 있을 경우 전송
        {
            string          sql = $"select * from User where time > \'{Time}\' order by time asc";
            MySqlDataReader rdr = ExecuteSelect(sql);

            while (rdr.Read())
            {
                User user = (User)GetStructFromDB <User>(rdr);

                byte[] data = BlindNetUtil.StructToByte(user);

                ChatPacket chatPacket = BlindChatUtil.ByteToChatPacket(data, ChatType.User);
                ChatPacketSend(chatPacket);
            }
            rdr.Close();
        }
예제 #27
0
        public void Run()
        {
            BlindSocket socket;

            socket = _Main.lockPortSock.AcceptWithECDH();

            IPEndPoint iep = (IPEndPoint)(socket.socket.RemoteEndPoint);

            logger = new Logger(_cid, iep.Address.ToString(), LogService.ScreenLock);

            while (true)
            {
                byte[] data = socket.CryptoReceiveMsg();
                if (data == null)
                {
                    socket.Close();
                    logger.Log(LogRank.INFO, "BlindLock Disconnected");
                    return;
                }

                //인증 여기서
                LockPacket packet = BlindNetUtil.ByteToStruct <LockPacket>(data);
                if (packet.Type == lockType.INFO)
                {
                    logger.Log(LogRank.INFO, "Unlock try from out of Local");
                    LockInfo info = BlindNetUtil.ByteToStruct <LockInfo>(packet.data);
                    if (CheckUserValid(info.userName, info.password))
                    {
                        logger.Log(LogRank.INFO, "Unlock try Succeed!");
                        packet.Type = lockType.SUCCESS;
                        packet.data = new byte[60];
                        data        = BlindNetUtil.StructToByte(packet);

                        socket.CryptoSend(data, PacketType.MSG);
                    }
                    else
                    {
                        logger.Log(LogRank.WARN, "Unlock try Failed!");
                        packet.Type = lockType.FAILED;
                        packet.data = new byte[60];
                        data        = BlindNetUtil.StructToByte(packet);

                        socket.CryptoSend(data, PacketType.MSG);
                    }
                }
            }
        }
예제 #28
0
        void AddDir(Directory_Info dir)
        {
            try
            {
                string       command   = "INSERT INTO directorys_info values(0, '" + dir.name + "', " + dir.parent_id + ", DEFAULT, NULL);";
                MySqlCommand commander = new MySqlCommand(command, connection);
                if (commander.ExecuteNonQuery() != 1)
                {
                    socket.CryptoSend(null, PacketType.Fail);
                }

                commander.CommandText = "SELECT MAX(id) FROM directorys_info;";
                MySqlDataReader reader = commander.ExecuteReader();
                reader.Read();
                dir.id = (uint)reader["MAX(id)"];
                reader.Close();

                commander.CommandText = "SELECT path FROM directorys_info WHERE id = " + dir.parent_id + ";";
                reader = commander.ExecuteReader();
                reader.Read();
                string path = (string)reader["path"] + dir.id;
                reader.Close();

                commander.CommandText = "UPDATE directorys_info SET path = '" + RemakePath(path, true) + "' WHERE id = " + dir.id + ";";
                if (commander.ExecuteNonQuery() != 1)
                {
                    socket.CryptoSend(null, PacketType.Fail);
                }

                DirectoryInfo di = new DirectoryInfo(path);
                if (di.Exists)
                {
                    socket.CryptoSend(null, PacketType.Fail);
                    return;
                }
                UpdateModDate(dir.parent_id);

                di.Create();
                socket.CryptoSend(BlindNetUtil.StructToByte(dir), PacketType.OK);
                logger.Log(LogRank.INFO, "Created directory(" + dir.id + ")");
            }
            catch
            {
                socket.CryptoSend(null, PacketType.Fail);
            }
        }
예제 #29
0
        public User_Info()
        {
            InitializeComponent();

            this.BackColor = BlindColor.Gray;
            tableLayoutPanel1.BackColor = lbl_Name.BackColor = BlindColor.Primary;
            panel2.BackColor            = BlindColor.Gray;
            lbl_Department.ForeColor    = lbl_Birth.ForeColor = lbl_Email.ForeColor = lbl_Phone.ForeColor = lbl_Position.ForeColor = BlindColor.Primary;
            BlindNetUtil.SetEllipse(panel3, 20);

            panel9.Width  = panel10.Width;
            panel14.Width = panel11.Width;
            panel15.Width = panel12.Width;
            panel16.Width = panel13.Width;
            panel19.Width = panel18.Width;

            panel9.BackColor = panel14.BackColor = panel15.BackColor = panel16.BackColor = panel19.BackColor = BlindColor.LightGreen;
        }
예제 #30
0
        public bool AddDir(TreeNode node, string name)
        {
            Directory_Info dir = new Directory_Info();

            dir.id        = 0;
            dir.parent_id = ((Directory_Info)(node.Parent.Tag)).id;
            dir.name      = name;

            socket.CryptoSend(BlindNetUtil.StructToByte(dir), PacketType.DocAddDir);
            BlindPacket packet = socket.CryptoReceive();

            if (packet.header != PacketType.OK)
            {
                return(false);
            }
            node.Tag = BlindNetUtil.ByteToStruct <Directory_Info>(BlindNetUtil.ByteTrimEndNull(packet.data));
            return(true);
        }