From e5d926a945933d438b43a53c14e2be3dfa0b6687 Mon Sep 17 00:00:00 2001 From: Rohit Suthar Date: Fri, 2 Aug 2019 22:47:27 +0530 Subject: [PATCH] Fix logout left message on server --- src/com/chatroom/server/Server.java | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/com/chatroom/server/Server.java b/src/com/chatroom/server/Server.java index 7235f8b..ded6404 100755 --- a/src/com/chatroom/server/Server.java +++ b/src/com/chatroom/server/Server.java @@ -145,7 +145,7 @@ public void run() break; case 3: //for logout - logout(clientThread,request); + logout(clientThread,request,1); break; case 4: //create room @@ -249,14 +249,15 @@ public void run() } } - public static void logout(ClientThread clientThread, Request request) { + public static void logout(ClientThread clientThread, Request request,int temp) { Response response = new Response( Response.Type.LOGOUT.ordinal() , true, "Logout Succesfully"); Server.responseMakerQueue.add(new ResponseHolder(response, clientThread.objectOutputStream)); - if(request.getRoomId() != -1) - Server.roomsHolder.get(request.getRoomId()).remove(request.getClientId()); - - Server.clientHolder.remove(request.getClientId()); + if(temp == 1) { + if(request.getRoomId() != -1) + Server.roomsHolder.get(request.getRoomId()).remove(request.getClientId()); + Server.clientHolder.remove(request.getClientId()); + } if( Server.responseMaker.getState() == State.WAITING ) { @@ -414,7 +415,7 @@ public void run() { if( request.getContents().equals("sv_logout") ) { - RequestAnalyser.logout(ct,request); + RequestAnalyser.logout(ct,request,0); } } } @@ -439,6 +440,10 @@ public void run() Set set1 = Server.roomsHolder.get(request.getRoomId()); set1.remove(request.getClientId()); } + else if(request.getContents().equals("sv_logout")) { + Server.roomsHolder.get(request.getRoomId()).remove(request.getClientId()); + Server.clientHolder.remove(request.getClientId()); + } } catch (Exception e) { e.printStackTrace(new PrintWriter(Server.errors));