Skip to content

Commit

Permalink
Developed
Browse files Browse the repository at this point in the history
  • Loading branch information
geoje committed May 31, 2021
1 parent edf35fc commit f1fa7a2
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 22 deletions.
2 changes: 1 addition & 1 deletion Client/Client.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
<GenerateManifests>true</GenerateManifests>
</PropertyGroup>
<PropertyGroup>
<SignManifests>true</SignManifests>
<SignManifests>false</SignManifests>
</PropertyGroup>
<ItemGroup>
<Reference Include="MetroFramework, Version=1.4.0.0, Culture=neutral, PublicKeyToken=5f91a84759bf584a, processorArchitecture=MSIL">
Expand Down
13 changes: 7 additions & 6 deletions Client/Forms/FormMain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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)));
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions Client/Forms/FormRoom.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion Client/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<PacketType, Action<Packet>> callback; // 타입에 따른 콜백 메소드
Expand Down
10 changes: 5 additions & 5 deletions OSTLibrary/Chats/Chat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,26 @@ public class Chat : IComparable<Chat>
{
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;
}
Expand Down
12 changes: 8 additions & 4 deletions Server/Classes/Client.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -193,6 +193,10 @@ public void Recieve()

// 룸과 사원 관계 Map에도 저장, 새로 만드는 방이니깐 기존에 정보가 없었을 것임
Program.roomEmps.Add(p.room.id, new List<int>(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)
{
Expand Down Expand Up @@ -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))
Expand Down
8 changes: 5 additions & 3 deletions Server/Classes/Database.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -304,7 +305,8 @@ public static List<Chat> 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)
Expand Down

0 comments on commit f1fa7a2

Please sign in to comment.