diff --git a/Client/Client.csproj b/Client/Client.csproj
index 06e182f..0db82be 100644
--- a/Client/Client.csproj
+++ b/Client/Client.csproj
@@ -66,7 +66,7 @@
true
- true
+ false
diff --git a/Client/Forms/FormMain.cs b/Client/Forms/FormMain.cs
index 44db08b..377336f 100644
--- a/Client/Forms/FormMain.cs
+++ b/Client/Forms/FormMain.cs
@@ -247,7 +247,7 @@ void AddRoomCard(Room room)
// 최근 채팅 존재 유무에 따른 표시
if (room.lastChat == null)
- cardRoom.UpdateInfo(new Chat(ChatType.Text, DateTime.MinValue, room.id, 0, ""));
+ cardRoom.UpdateInfo(new Chat(ChatType.Text, DateTime.MinValue, room, 0, ""));
else
cardRoom.UpdateInfo(room.lastChat);
@@ -278,18 +278,19 @@ void ReceiveChat(Packet p)
if (cp.chats.Count == 0) return;
// 채팅 패킷을 받으면 해당 룸이 켜져있을 경우 해당 룸으로 채팅들을 넘겨줌
- if (formChats.ContainsKey(cp.chats[0].roomId))
- formChats[cp.chats[0].roomId].ReceiveChat(cp.chats);
+ if (formChats.ContainsKey(cp.chats[0].room.id))
+ formChats[cp.chats[0].room.id].ReceiveChat(cp.chats);
// 해당 룸이 안켜져 있을 경우 카드만 업데이트 한다
// 이때 카드도 없을 경우 생성 한다
else
{
- if (roomCards.ContainsKey(cp.chats[0].roomId))
- roomCards[cp.chats[0].roomId].UpdateInfo(cp.chats[cp.chats.Count - 1]);
+ if (roomCards.ContainsKey(cp.chats[0].room.id))
+ roomCards[cp.chats[0].room.id].UpdateInfo(cp.chats[cp.chats.Count - 1]);
else
{
- // TODO ChatsPacket 안에 Room 정보 넣어서 그걸로 새로운 룸 카드 만들기
+ cp.chats[0].room.lastChat = cp.chats[0];
+ Invoke(new MethodInvoker(() => AddRoomCard(cp.chats[0].room)));
}
}
}
diff --git a/Client/Forms/FormRoom.cs b/Client/Forms/FormRoom.cs
index 7fbeae3..04987b2 100644
--- a/Client/Forms/FormRoom.cs
+++ b/Client/Forms/FormRoom.cs
@@ -58,7 +58,7 @@ private void picImage_Click(object sender, EventArgs e)
if (ofd.ShowDialog() == DialogResult.OK)
{
- Chat chat = new Chat(ChatType.Image, DateTime.Now, room.id,
+ Chat chat = new Chat(ChatType.Image, DateTime.Now, room,
Program.employee.id, Image.FromFile(ofd.FileName));
AddChatCard(chat);
@@ -81,7 +81,7 @@ private void picSend_Click(object sender, EventArgs e)
if (string.IsNullOrEmpty(txtChat.Text))
return;
- Chat chat = new Chat(ChatType.Text, DateTime.Now, room.id,
+ Chat chat = new Chat(ChatType.Text, DateTime.Now, room,
Program.employee.id, txtChat.Text);
AddChatCard(chat);
diff --git a/Client/Program.cs b/Client/Program.cs
index 16a7a0a..f2e2a3b 100644
--- a/Client/Program.cs
+++ b/Client/Program.cs
@@ -16,7 +16,7 @@ static class Program
public static object locker = new object(); // 송신 뮤택스
public static TcpClient client; // 서버와 연결된 TCP 소켓
public static NetworkStream ns; // 네트워크 스트림
- public static readonly string hostname = "www.ygh.kr"; // 접속할 서버 주소
+ public static readonly string hostname = "127.0.0.1"; // 접속할 서버 주소
public static readonly ushort port = 6756; // 접속할 서버 포트
public static Thread recvThread; // 서버로부터 수신을 대기하는 스레드
public static Dictionary> callback; // 타입에 따른 콜백 메소드
diff --git a/OSTLibrary/Chats/Chat.cs b/OSTLibrary/Chats/Chat.cs
index 4355f52..6dbff00 100644
--- a/OSTLibrary/Chats/Chat.cs
+++ b/OSTLibrary/Chats/Chat.cs
@@ -13,26 +13,26 @@ public class Chat : IComparable
{
public ChatType type;
public DateTime date;
- public string roomId;
+ public Room room;
public int empId;
// 데이터들
public Image image;
public string text;
- public Chat(ChatType type, DateTime date, string roomId, int empId, Image image)
+ public Chat(ChatType type, DateTime date, Room room, int empId, Image image)
{
this.type = type;
this.date = date;
- this.roomId = roomId;
+ this.room = room;
this.empId = empId;
this.image = image;
}
- public Chat(ChatType type, DateTime date, string roomId, int empId, string text)
+ public Chat(ChatType type, DateTime date, Room room, int empId, string text)
{
this.type = type;
this.date = date;
- this.roomId = roomId;
+ this.room = room;
this.empId = empId;
this.text = text;
}
diff --git a/Server/Classes/Client.cs b/Server/Classes/Client.cs
index 3218c73..1ba7b33 100644
--- a/Server/Classes/Client.cs
+++ b/Server/Classes/Client.cs
@@ -174,13 +174,13 @@ public void Recieve()
while (!Database.AddRoom(p.room));
Send(p);
+ Employee targetEmp = null;
if (p.room.scopeIdx == 3)
{
-
int otherEmpId = p.room.FindOtherEmployeeId(employee);
if (Program.employees.ContainsKey(otherEmpId))
{
- Employee targetEmp = Program.employees[p.room.FindOtherEmployeeId(employee)];
+ targetEmp = Program.employees[p.room.FindOtherEmployeeId(employee)];
Log("Room", $"{Room.Scope[p.room.scopeIdx]} 채팅방 생성 : {targetEmp.name}({targetEmp.id})");
}
else
@@ -193,6 +193,10 @@ public void Recieve()
// 룸과 사원 관계 Map에도 저장, 새로 만드는 방이니깐 기존에 정보가 없었을 것임
Program.roomEmps.Add(p.room.id, new List(new int[] { employee.id }));
+ if (targetEmp != null && Program.clients.ContainsKey(targetEmp.id) &&
+ !Program.roomEmps[p.room.id].Exists(e => e == targetEmp.id))
+ Program.roomEmps[p.room.id].Add(targetEmp.id);
+
}
else if (p.roomType == RoomType.Chats)
{
@@ -231,8 +235,8 @@ public void Recieve()
// p.chats[0].type == ChatType.Image ? "사진" : "Blob");
// 같은 Room에 있는 다른 클라들한테 채팅 전송
- if (Program.roomEmps.ContainsKey(p.chats[0].roomId))
- Program.roomEmps[p.chats[0].roomId]
+ if (Program.roomEmps.ContainsKey(p.chats[0].room.id))
+ Program.roomEmps[p.chats[0].room.id]
.FindAll(eid => eid != employee.id)
.ForEach(eid => {
if (Program.clients.ContainsKey(eid))
diff --git a/Server/Classes/Database.cs b/Server/Classes/Database.cs
index c6edbf9..3b63292 100644
--- a/Server/Classes/Database.cs
+++ b/Server/Classes/Database.cs
@@ -229,7 +229,7 @@ public static bool AddChat(Chat chat)
using (MemoryStream ms = new MemoryStream())
{
- cmd.Parameters.AddWithValue("@room_id", chat.roomId);
+ cmd.Parameters.AddWithValue("@room_id", chat.room.id);
cmd.Parameters.AddWithValue("@chat_date", chat.date);
cmd.Parameters.AddWithValue("@employee_id", chat.empId);
@@ -275,7 +275,8 @@ public static Chat GetLastChat(Room room)
byte[] dataBytes = new byte[rdr.GetInt32("data_length")];
rdr.GetBytes(rdr.GetOrdinal("data"), 0, dataBytes, 0, dataBytes.Length);
- Chat chat = new Chat(ct, rdr.GetDateTime("chat_date"), rdr.GetString("room_id"),
+ room.id = rdr.GetString("room_id");
+ Chat chat = new Chat(ct, rdr.GetDateTime("chat_date"), room,
rdr.GetInt32("employee_id"), "");
if (ct == ChatType.Image)
@@ -304,7 +305,8 @@ public static List GetChats(Room room, DateTime until)
byte[] dataBytes = new byte[rdr.GetInt32("data_length")];
rdr.GetBytes(rdr.GetOrdinal("data"), 0, dataBytes, 0, dataBytes.Length);
- Chat chat = new Chat(ct, rdr.GetDateTime("chat_date"), rdr.GetString("room_id"),
+ room.id = rdr.GetString("room_id");
+ Chat chat = new Chat(ct, rdr.GetDateTime("chat_date"), room,
rdr.GetInt32("employee_id"), "");
if (ct == ChatType.Image)