Skip to content

Commit

Permalink
Fix logout left message on server
Browse files Browse the repository at this point in the history
  • Loading branch information
iamrohitsuthar committed Aug 2, 2019
1 parent d88cd55 commit e5d926a
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions src/com/chatroom/server/Server.java
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ public void run()
break;
case 3:
//for logout
logout(clientThread,request);
logout(clientThread,request,1);
break;
case 4:
//create room
Expand Down Expand Up @@ -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 )
{
Expand Down Expand Up @@ -414,7 +415,7 @@ public void run()
{
if( request.getContents().equals("sv_logout") )
{
RequestAnalyser.logout(ct,request);
RequestAnalyser.logout(ct,request,0);
}
}
}
Expand All @@ -439,6 +440,10 @@ public void run()
Set<Integer> 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));
Expand Down

0 comments on commit e5d926a

Please sign in to comment.