log out button
This commit is contained in:
parent
ce273d533c
commit
9508575949
|
@ -49,6 +49,12 @@
|
|||
padding: 0px;
|
||||
}
|
||||
|
||||
#logout {
|
||||
position: absolute;
|
||||
top: 0px;
|
||||
right: 0px;
|
||||
}
|
||||
|
||||
#chat_submit {
|
||||
width: 50px;
|
||||
height: 19px;
|
||||
|
|
|
@ -31,6 +31,7 @@
|
|||
</div>
|
||||
|
||||
<div id="canvass">
|
||||
<input type="button" id="logout" value="Log out" />
|
||||
<div id="chat_area">
|
||||
<div id="log"></div>
|
||||
<input type="text" id="chat" maxlength="200" />
|
||||
|
|
|
@ -46,3 +46,7 @@ cah.ajax.after_registered = function() {
|
|||
cah.ajax.SuccessHandlers.chat = function(data) {
|
||||
// pass
|
||||
};
|
||||
|
||||
cah.ajax.SuccessHandlers.logout = function(data) {
|
||||
window.location.reload();
|
||||
};
|
||||
|
|
|
@ -15,6 +15,11 @@ $(document).ready(function() {
|
|||
|
||||
$("#chat").keyup(chat_keyup);
|
||||
$("#chat_submit").click(chatsubmit_click);
|
||||
|
||||
// TODO: have some sort of mechanism to alert the server that we have unloaded the page, but
|
||||
// have not expressed an interest in being cleared out yet.
|
||||
// $(window).bind("beforeunload", window_beforeunload);
|
||||
$("#logout").click(logout_click);
|
||||
});
|
||||
|
||||
function nickbox_keyup(e) {
|
||||
|
@ -48,3 +53,7 @@ function chatsubmit_click(e) {
|
|||
$("#chat").val("");
|
||||
$("#chat").focus();
|
||||
}
|
||||
|
||||
function logout_click(e) {
|
||||
cah.Ajax.request("logout", {});
|
||||
}
|
||||
|
|
|
@ -15,6 +15,23 @@ cah.longpoll.EventHandlers.new_player = function(data) {
|
|||
cah.log.status(data.nickname + " has connected.");
|
||||
};
|
||||
|
||||
cah.longpoll.EventHandlers.player_leave = function(data) {
|
||||
var friendly_reason = "Leaving";
|
||||
// see net.socialgamer.cah.data.User.DisconnectReason
|
||||
switch (data.reason) {
|
||||
case "MANUAL":
|
||||
friendly_reason = "Leaving";
|
||||
break;
|
||||
case "PING_TIMEOUT":
|
||||
friendly_reason = "Ping timeout";
|
||||
break;
|
||||
case "KICKED":
|
||||
friendly_reason = "Kicked by server";
|
||||
break;
|
||||
}
|
||||
cah.log.status(data.nickname + " has disconnected (" + friendly_reason + ").");
|
||||
};
|
||||
|
||||
cah.longpoll.EventHandlers.noop = function(data) {
|
||||
// pass
|
||||
};
|
||||
|
|
|
@ -38,7 +38,7 @@ public class QueuedMessage implements Comparable<QueuedMessage> {
|
|||
*
|
||||
*/
|
||||
public enum Type {
|
||||
PING(0), NEW_PLAYER(5), CHAT(5);
|
||||
PING(0), NEW_PLAYER(3), PLAYER_DISCONNECT(3), CHAT(5);
|
||||
|
||||
private final int weight;
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ import java.util.concurrent.PriorityBlockingQueue;
|
|||
|
||||
public class User {
|
||||
|
||||
enum DisconnectReason {
|
||||
public enum DisconnectReason {
|
||||
MANUAL, PING_TIMEOUT, KICKED
|
||||
}
|
||||
|
||||
|
@ -72,6 +72,9 @@ public class User {
|
|||
lastHeardFrom = System.nanoTime();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The time the user was last heard from, in nanoseconds.
|
||||
*/
|
||||
public long getLastHeardFrom() {
|
||||
return lastHeardFrom;
|
||||
}
|
||||
|
|
|
@ -12,6 +12,7 @@ public class Handlers {
|
|||
LIST = new HashMap<String, Class<? extends Handler>>();
|
||||
LIST.put(ChatHandler.OP, ChatHandler.class);
|
||||
LIST.put(FirstLoadHandler.OP, FirstLoadHandler.class);
|
||||
LIST.put(LogoutHandler.OP, LogoutHandler.class);
|
||||
LIST.put(RegisterHandler.OP, RegisterHandler.class);
|
||||
LIST.put(TestHandler.OP, TestHandler.class);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,39 @@
|
|||
package net.socialgamer.cah.handlers;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.servlet.http.HttpSession;
|
||||
|
||||
import net.socialgamer.cah.Server;
|
||||
import net.socialgamer.cah.data.ConnectedUsers;
|
||||
import net.socialgamer.cah.data.User;
|
||||
import net.socialgamer.cah.data.User.DisconnectReason;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
|
||||
|
||||
public class LogoutHandler extends Handler {
|
||||
|
||||
public final static String OP = "logout";
|
||||
|
||||
private final ConnectedUsers users;
|
||||
|
||||
@Inject
|
||||
public LogoutHandler(final Server server) {
|
||||
this.users = server.getConnectedUsers();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> handle(final Map<String, String[]> parameters,
|
||||
final HttpSession session) {
|
||||
final Map<String, Object> data = new HashMap<String, Object>();
|
||||
|
||||
final User user = (User) session.getAttribute("user");
|
||||
assert (user != null);
|
||||
|
||||
users.removeUser(user, DisconnectReason.MANUAL);
|
||||
session.invalidate();
|
||||
return data;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue