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); }
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); }
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); }
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); } } }
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); } }
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); }
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); }
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(); }
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); } } } }
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); } }
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); }
public void ExecuteExit(ChatPacket chatPack) { string timeNow = System.DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"); ChatRoomJoined roomJoined = BlindChatUtil.ChatPacketToStruct <ChatRoomJoined>(chatPack); SendChatPacketToParticipants(chatPack, roomJoined.RoomID); string sql = $"delete from ChatRoomJoined where UserID = {roomJoined.UserID} and RoomID = {roomJoined.RoomID};"; ExecuteQuery(sql); ChatMessage message = new ChatMessage(); message.RoomID = roomJoined.RoomID; message.UserID = 0; message.Time = timeNow; sql = $"select * from User where ID = {roomJoined.UserID}"; ChatMessage _message = new ChatMessage(); message.RoomID = roomJoined.RoomID; message.UserID = 0; message.Time = timeNow; sql = $"select * from User where ID = {roomJoined.UserID}"; MySqlDataAdapter adpt = new MySqlDataAdapter(sql, hDB); DataSet ds = new DataSet(); adpt.Fill(ds); DataRow r = ds.Tables[0].Rows[0]; User userInfo = (User)GetStructFromDB <User>(r); message.Message = $"{userInfo.Name}님이 나갔습니다."; byte[] _data = BlindNetUtil.StructToByte(message); ChatPacket _packet = BlindChatUtil.ByteToChatPacket(_data, ChatType.Message); SendChatPacketToParticipants(_packet, message.RoomID); //시간을 수정한 메시지를 DB에 등록 AddToDBTimeNow <ChatMessage>(_packet); }
public void ClientUpdateMessage(string Time) { string sql = $"select * from ChatMessage " + $"where RoomID in (select roomID from ChatRoomJoined where userID = {UserID}) " + $"and Time > \'{Time}\' order by Time asc"; MySqlDataReader rdr = ExecuteSelect(sql); while (rdr.Read()) { ChatMessage message = (ChatMessage)GetStructFromDB <ChatMessage>(rdr); byte[] data = BlindNetUtil.StructToByte(message); ChatPacket chatPacket = BlindChatUtil.ByteToChatPacket(data, ChatType.Message); ChatPacketSend(chatPacket); } rdr.Close(); }
public void ClientUpdateChatRoom(string Time) { string sql = $"select * from ChatRoom " + $"where ID in " + $"(select RoomID from ChatRoomJoined where UserID={this.UserID}) " + $"and Time > \'{Time}\' order by Time asc"; MySqlDataReader rdr = ExecuteSelect(sql); while (rdr.Read()) { ChatRoom room = (ChatRoom)GetStructFromDB <ChatRoom>(rdr); byte[] data = BlindNetUtil.StructToByte(room); ChatPacket chatPacket = BlindChatUtil.ByteToChatPacket(data, ChatType.Room); ChatPacketSend(chatPacket); } rdr.Close(); }
public async Task <TreeNode> UploadDirAsync(TreeNode node, string path) { Directory_Info dir = new Directory_Info(); dir.id = 0; dir.parent_id = ((Directory_Info)node.Tag).id; dir.name = Path.GetFileName(path); socket.CryptoSend(BlindNetUtil.StructToByte(dir), PacketType.DocAddDir); BlindPacket packet = await Task.Run(() => socket.CryptoReceive()); if (packet.header == PacketType.Fail) { return(null); } Directory_Info newDir = BlindNetUtil.ByteToStruct <Directory_Info>(BlindNetUtil.ByteTrimEndNull(packet.data)); TreeNode newNode = new TreeNode(); newNode.Tag = newDir; newNode.Text = newDir.name; newNode.ImageIndex = 0; newNode.SelectedImageIndex = 0; 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) + "%"; #if DEBUG form.label_percent.Text = form.progressBar.Value.ToString(); #endif form.label_percent.Update(); return(newNode); }
public void MessageToParticipants(ChatPacket chatPack) { //메시지의 시간을 수정한다. string timeNow = System.DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"); ChatMessage message = BlindChatUtil.ChatPacketToStruct <ChatMessage>(chatPack); message.Time = timeNow; byte[] data = BlindNetUtil.StructToByte(message); ChatPacket pack = BlindChatUtil.ByteToChatPacket(data, ChatType.Message); //시간을 수정한 메시지를 DB에 등록 AddToDBTimeNow <ChatMessage>(pack); //방데이터에 최신 메시지 시간 수정 string sql = $"update ChatRoom set LastMessageTime = \'{message.Time}\' where ID = {message.RoomID}"; ExecuteQuery(sql); //방에 속한 사용자들에게 메시지 전송 SendChatPacketToParticipants(pack, message.RoomID); }
public void ClientRoomsWithRoomID <T>(int RoomID) { string sql; ChatType Type; if (typeof(T) == typeof(ChatRoom)) { sql = $"select * from ChatRoom where ID = {RoomID};"; Type = ChatType.Room; } else if (typeof(T) == typeof(ChatRoomJoined)) { sql = $"select * from ChatRoomJoined where RoomID ={RoomID}"; Type = ChatType.RoomJoined; } else { return; } //MySqlDataReader rdr = ExecuteSelect(sql); MySqlDataAdapter adpt = new MySqlDataAdapter(sql, hDB); DataSet ds = new DataSet(); adpt.Fill(ds); foreach (DataRow row in ds.Tables[0].Rows) { T st = (T)GetStructFromDB <T>(row); byte[] data = BlindNetUtil.StructToByte(st); ChatPacket chatPacket = BlindChatUtil.ByteToChatPacket(data, Type); SendChatPacketToParticipants(chatPacket, RoomID); } }
public static ChatPacket StructToChatPacket(ChatRoomJoined roomJoined, ChatType type = ChatType.RoomJoined) { byte[] data = BlindNetUtil.StructToByte(roomJoined); return(BlindChatUtil.ByteToChatPacket(data, type)); }
public void ExecuteInvitation(ChatPacket chatPack) { ChatRoomJoined roomJoined = BlindChatUtil.ChatPacketToStruct <ChatRoomJoined>(chatPack); //사용자 등록 string timeNow = System.DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"); string sql = $"insert into ChatRoomJoined (UserID, RoomID, Time) values ({roomJoined.UserID},{roomJoined.RoomID},\'{timeNow}\');"; ExecuteQuery(sql); //새로 추가한 사용자 검색 sql = $"select * from ChatRoomJoined where Time = \'{timeNow}\' and UserID={ roomJoined.UserID }"; MySqlDataReader rdr = ExecuteSelect(sql); byte[] data; if (rdr.Read()) { roomJoined = (ChatRoomJoined)GetStructFromDB <ChatRoomJoined>(rdr); rdr.Close(); { sql = $"select * from ChatRoom where ID = {roomJoined.RoomID}"; rdr = ExecuteSelect(sql); if (rdr.Read()) { ChatRoom room = (ChatRoom)GetStructFromDB <ChatRoom>(rdr); rdr.Close(); data = BlindNetUtil.StructToByte(room); ChatPacket chatPacket = BlindChatUtil.ByteToChatPacket(data, ChatType.Room); SendChatPacketToUser(chatPacket, roomJoined.UserID); } } //방 인원 전송 { sql = $"select * from ChatRoomJoined " + $"where RoomID = {roomJoined.RoomID} order by Time asc"; MySqlDataAdapter adptr = new MySqlDataAdapter(sql, hDB); DataSet dst = new DataSet(); adptr.Fill(dst); foreach (DataRow dr in dst.Tables[0].Rows) { ChatRoomJoined chatRoomJoined = (ChatRoomJoined)GetStructFromDB <ChatRoomJoined>(dr); if (chatRoomJoined.UserID != roomJoined.UserID) { data = BlindNetUtil.StructToByte(chatRoomJoined); ChatPacket chatPacket = BlindChatUtil.ByteToChatPacket(data, ChatType.RoomJoined); SendChatPacketToUser(chatPacket, roomJoined.UserID); } } rdr.Close(); } data = BlindNetUtil.StructToByte(roomJoined); //방 사용자들에게 전송 ChatPacket packet = BlindChatUtil.ByteToChatPacket(data, ChatType.RoomJoined); SendChatPacketToParticipants(packet, roomJoined.RoomID); ChatMessage message = new ChatMessage(); message.RoomID = roomJoined.RoomID; message.UserID = 0; message.Time = timeNow; sql = $"select * from User where ID = {roomJoined.UserID}"; MySqlDataAdapter adpt = new MySqlDataAdapter(sql, hDB); DataSet ds = new DataSet(); adpt.Fill(ds); DataRow r = ds.Tables[0].Rows[0]; User userInfo = (User)GetStructFromDB <User>(r); message.Message = $"{userInfo.Name}님이 입장하셨습니다."; byte[] _data = BlindNetUtil.StructToByte(message); ChatPacket _packet = BlindChatUtil.ByteToChatPacket(_data, ChatType.Message); SendChatPacketToParticipants(_packet, message.RoomID); //시간을 수정한 메시지를 DB에 등록 AddToDBTimeNow <ChatMessage>(_packet); Console.WriteLine("invite successed"); } else { Console.WriteLine("cant find the user"); } }
public static ChatPacket StructToChatPacket(ChatRoom room) { byte[] data = BlindNetUtil.StructToByte(room); return(BlindChatUtil.ByteToChatPacket(data, ChatType.Room)); }
public static ChatPacket StructToChatPacket(Invitation inv) { byte[] data = BlindNetUtil.StructToByte(inv); return(BlindChatUtil.ByteToChatPacket(data, ChatType.Invitation)); }
public static ChatPacket StructToChatPacket(NewRoomStruct newRoom) { byte[] data = BlindNetUtil.StructToByte(newRoom); return(BlindChatUtil.ByteToChatPacket(data, ChatType.NewRoom)); }
public static ChatPacket StructToChatPacket(ChatTimeStamp time) { byte[] data = BlindNetUtil.StructToByte(time); return(BlindChatUtil.ByteToChatPacket(data, ChatType.Time)); }
public static ChatPacket StructToChatPacket(ChatMessage message) { byte[] data = BlindNetUtil.StructToByte(message); return(BlindChatUtil.ByteToChatPacket(data, ChatType.Message)); }
private void btn_Unlock_Click(object sender, EventArgs e) { if (!isInner)//vpn으로 연결되어 있는 경우 { MessageBox.Show("VPN용 락"); //서버로 정보 전송 LockInfo info = new LockInfo(); info.userName = UserID; info.password = tb_Password.Text; byte[] data = BlindNetUtil.StructToByte(info); LockPacket packet = new LockPacket(); packet.Type = lockType.INFO; packet.data = data; MessageBox.Show("패킷 생성"); byte[] packetData = BlindNetUtil.StructToByte(packet); lockSock.CryptoSend(packetData, PacketType.Info); MessageBox.Show("send msg"); //서버로부터 받은 성공여부로 스크린락 해제 data = lockSock.CryptoReceiveMsg(); MessageBox.Show("received msg"); packet = BlindNetUtil.ByteToStruct <LockPacket>(data); if (packet.Type == lockType.SUCCESS) { tb_Password.Text = ""; ActivateWhenUnlock(); } else { MessageBox.Show("서버로부터의 인증에 실패하셨습니다."); tb_Password.Text = ""; tb_Password.Focus(); return; } } else//로컬에서 인증하는 경우 { int token; bool result; if (tb_Password.Text == "unlock") { result = true; } else { result = LogonUser(Environment.UserName, "Blind2A", tb_Password.Text, 8, 0, out token); } if (result) { tb_Password.Text = ""; ActivateWhenUnlock(); } else { MessageBox.Show("로컬에서 인증을 실패하셨습니다."); return; } } }
public static ChatPacket StructToChatPacket(User user) { byte[] data = BlindNetUtil.StructToByte(user); return(BlindChatUtil.ByteToChatPacket(data, ChatType.User)); }