private void REQ_SERVER_CONNECT(ConnectController controller, string msg) { // 서버 허용량 초과하는지 검사 if (connectControllers.Count > ServerCapacity - 1) { SendConnectLostMessage(controller, msg); return; } // 비밀번호, 닉네임, 닉네임색상, 채팅색상 순으로 Splited string[] splitedCSV = msg.Split(','); if (Password != splitedCSV[0]) { SendConnectLostMessage(controller, msg); return; } // 비밀번호가 정확하였을 경우 연결성공 메시지 Send controller.UserNickname = splitedCSV[1]; controller.UserNicknameColor = splitedCSV[2]; controller.UserChatColor = splitedCSV[3]; controller.isConnected = true; string titleMessage = $"{ServerTitle}({connectControllers.Count + 1}/{ServerCapacity}) : {connectControllers.Count + 1}명 연결중"; mainVM.ChangeServerStatus_CreateSuccese(titleMessage); MessageUtil.Instance.SendMessage(SEND_TO_CLIENT_DEFINE.SEND_SERVER_TITLE, titleMessage, controller.transmitStream); SendNoticeToClients($"{controller.UserNickname}이(가) 연결되었습니다."); }
private async Task AsyncStartServer() { IPAddress adress = IPAddress.Parse(serverIP); IPEndPoint ip = new IPEndPoint(adress, 7000); tcpListener = new TcpListener(ip); tcpListener.Start(); string titleMessage = $"{ServerTitle}({connectControllers.Count + 1}/{ServerCapacity}) : {connectControllers.Count + 1}명 연결중"; mainVM.ChangeServerStatus_CreateSuccese(titleMessage); while (true) { try { TcpClient tc = await tcpListener.AcceptTcpClientAsync().ConfigureAwait(false); ConnectController conectController = new ConnectController(); conectController.isConnected = true; conectController.connectedClient = tc; connectControllers.Add(conectController); Task.Factory.StartNew(AsyncReadFromClient, conectController); } catch (Exception e) { return; } } }
private void REQ_CHANGE_CHAT_COLOR(ConnectController controller, string msg) { SendNoticeToClients($"[{controller.UserNickname}] 유저의 채팅색상 이 [{msg}]로 변경되었습니다."); controller.UserChatColor = msg; MessageUtil.Instance.SendMessage(SEND_TO_CLIENT_DEFINE.SEND_SUCCESE_CHANGECHATCOLOR, msg, controller.transmitStream); }
private void REQ_CHANGE_NICKNAME(ConnectController controller, string msg) { SendNoticeToClients($"[{controller.UserNickname}] 유저의 닉네임이 [{msg}]로 변경되었습니다."); controller.UserNickname = msg; MessageUtil.Instance.SendMessage(SEND_TO_CLIENT_DEFINE.SEND_SUCCESE_CHANGENICKNAME, msg, controller.transmitStream); }
private void SendConnectLostMessage(ConnectController controller, string msg) { connectControllers.Remove(controller); controller.isConnected = false; controller.getMessageState = MessageState.LostConnect; MessageUtil.Instance.SendMessage(SEND_TO_CLIENT_DEFINE.SEND_CONNECT_LOST, "서버 허용량 초과", controller.transmitStream); }
private void SEND_CONNECT_LOST(ConnectController controller, string msg) { controller.getMessageState = MessageState.LostConnect; controller.isConnected = false; mainVM.Show_ConnectLostPopup($"서버 연결 종료됨 : {msg}"); mainVM.ChangeServerStatus_LostConnect(); }
private void REQ_CHAT_TRANSMIT(ConnectController controller, string msg) { mainVM.AddChatText(controller.UserNickname, controller.UserNicknameColor, controller.UserChatColor, msg); // 연결된 클라이언트들 Send Message for (int i = 0; i < connectControllers.Count; ++i) { string message = $"{controller.UserNickname},{controller.UserNicknameColor},{controller.UserChatColor},{msg}"; MessageUtil.Instance.SendMessage(SEND_TO_CLIENT_DEFINE.SEND_CHAT_TRANSMIT, message, connectControllers[i].transmitStream); } }
public ControllerManager(Server server) { this.server = server; ConnectController roomController = new ConnectController(); controlDict.Add(roomController.GetRequestCode, roomController); GameController gameController = new GameController(); controlDict.Add(gameController.GetRequestCode, gameController); }
private void REQ_LOST_CONNECT(ConnectController controller, string msg) { connectControllers.Remove(controller); controller.getMessageState = MessageState.LostConnect; controller.isConnected = false; string titleMessage = $"{ServerTitle}({connectControllers.Count + 1}/{ServerCapacity}) : {connectControllers.Count + 1}명 연결중"; mainVM.ChangeServerStatus_CreateSuccese(titleMessage); MessageUtil.Instance.SendMessage(SEND_TO_CLIENT_DEFINE.SEND_CONNECT_LOST, "ConnectLost", controller.transmitStream); // 연결 종료 알림 SendNoticeToClients($"{controller.UserNickname}의 연결이 종료되었습니다."); }
public ClientController(MainViewModel mainVM) { this.mainVM = mainVM; this.connectIP = null; this.connectPassword = null; controller = new ConnectController(); // MSGTYPE에 따른 함수 저장 messageDelegateArray = new MessageDelegate[7]; messageDelegateArray[0] = SEND_CONNECT_LOST; messageDelegateArray[1] = SEND_SERVER_TITLE; messageDelegateArray[2] = SEND_CHAT_TRANSMIT; messageDelegateArray[3] = SEND_SUCCESE_CHANGENICKNAME; messageDelegateArray[4] = SEND_SUCCESE_CHANGENICKNAMECOLOR; messageDelegateArray[5] = SEND_SUCCESE_CHANGECHATCOLOR; }
private async void AsyncReadFromClient(object object_connectController) { ConnectController controller = (ConnectController)object_connectController; TcpClient transmitClient = controller.connectedClient; controller.transmitStream = transmitClient.GetStream(); while (controller.isConnected) { switch (controller.getMessageState) { case MessageState.MessageHeader: { MessageHeader messageHeader = await MessageUtil.Instance.ReadMessageHeader(controller.transmitStream); controller.messageHeader = messageHeader; controller.getMessageState = MessageState.MessageBody; } break; case MessageState.MessageBody: { string msg = await MessageUtil.Instance.ReadMessageBody(controller.transmitStream, controller.messageHeader.BODYLEN); messageDelegateArray[controller.messageHeader.MSGTYPE - 1](controller, msg); controller.getMessageState = MessageState.MessageHeader; } break; default: { break; } } } controller.transmitStream.Close(); controller.connectedClient.Close(); }
public async Task DisconnectStoryAndRoute_OnException() { var service = new Mock <IConnectService>(); service.Setup(s => s.DisconnectStoryAndRoute("sId")) .Throws(new Exception()); ConnectController controller = new ConnectController( service.Object, userManager.Object, logger) { TempData = new TempDataDictionary(httpContext.Object, tempDataProvider.Object) }; var result = await controller.DisconnectStoryAndRoute("sId"); var viewResult = Assert.IsAssignableFrom <RedirectResult>(result); viewResult.Url.ShouldBe("/"); controller.TempData.ContainsKey("notification").ShouldBeTrue(); controller.TempData["notification"].ShouldNotBeNull(); controller.TempData["notification"].ShouldBeOfType <string[]>(); string[] arr = controller.TempData["notification"] as string[]; arr[0].ShouldBe("danger"); }
public async Task DisconnectStoryAndAlbum_OnConnectTrue() { var service = new Mock <IConnectService>(); service.Setup(s => s.DisconnectAlbumAndStory("aId")) .ReturnsAsync(() => true); ConnectController controller = new ConnectController( service.Object, userManager.Object, logger) { TempData = new TempDataDictionary(httpContext.Object, tempDataProvider.Object) }; var result = await controller.DisconnectStoryAndAlbum("aId", "sId"); var viewResult = Assert.IsAssignableFrom <RedirectResult>(result); viewResult.Url.ShouldBe("/Stories/Details/sId"); controller.TempData.ContainsKey("notification").ShouldBeTrue(); controller.TempData["notification"].ShouldNotBeNull(); controller.TempData["notification"].ShouldBeOfType <string[]>(); string[] arr = controller.TempData["notification"] as string[]; arr[0].ShouldBe("success"); }
public void SetController(ConnectController controller) { _controller = controller; }
private void SEND_SERVER_TITLE(ConnectController controller, string msg) { controller.isConnected = true; mainVM.ChangeServerStatus_ConnectSuccese(msg); }
private void SEND_SUCCESE_CHANGECHATCOLOR(ConnectController controller, string msg) { NoticeUserPropertyChanged("채팅색상", mainVM.ChatColor.ToString(), msg); }
private void SEND_SUCCESE_CHANGENICKNAMECOLOR(ConnectController controller, string msg) { NoticeUserPropertyChanged("닉네임색상", mainVM.NicknameColor.ToString(), msg); }
private void SEND_SUCCESE_CHANGENICKNAME(ConnectController controller, string msg) { NoticeUserPropertyChanged("닉네임", mainVM.Nickname, msg); }
/// <summary> /// msg는 닉네임, 닉네임색상, 채팅색상, 채팅내용으로 분리되어 CSV형태로 전달 /// </summary> /// <param name="controller"></param> /// <param name="msg"></param> private void SEND_CHAT_TRANSMIT(ConnectController controller, string msg) { string[] splitedMSG = msg.Split(','); mainVM.AddChatText(splitedMSG[0], splitedMSG[1], splitedMSG[2], splitedMSG[3]); }