2011-12-25 03:37:45 +00:00
|
|
|
/**
|
|
|
|
* Event handlers from long-poll operations.
|
|
|
|
*
|
|
|
|
* @author ajanata
|
|
|
|
*/
|
|
|
|
|
|
|
|
cah.longpoll.ErrorCodeHandlers.not_registered = function(data) {
|
|
|
|
cah.longpoll.Resume = false;
|
|
|
|
cah.log.error("The server seems to have restarted. Any in-progress games have been lost.");
|
|
|
|
cah.log.error("You will need to refresh the page to start a new game.");
|
2012-01-19 08:34:55 +00:00
|
|
|
$("input").attr("disabled", "disabled");
|
2011-12-25 03:37:45 +00:00
|
|
|
};
|
|
|
|
|
2012-01-13 05:36:31 +00:00
|
|
|
cah.longpoll.EventHandlers[cah.$.LongPollEvent.NEW_PLAYER] = function(data) {
|
2012-01-12 21:07:19 +00:00
|
|
|
// don't display our own join
|
|
|
|
if (data.nickname != cah.nickname) {
|
|
|
|
cah.log.status(data.nickname + " has connected.");
|
|
|
|
}
|
2011-12-25 03:37:45 +00:00
|
|
|
};
|
|
|
|
|
2012-01-13 05:36:31 +00:00
|
|
|
cah.longpoll.EventHandlers[cah.$.LongPollEvent.PLAYER_LEAVE] = function(data) {
|
2012-01-06 23:53:04 +00:00
|
|
|
var friendly_reason = "Leaving";
|
|
|
|
switch (data.reason) {
|
2012-01-13 04:05:39 +00:00
|
|
|
case cah.$.DisconnectReason.KICKED:
|
|
|
|
friendly_reason = "Kicked by server";
|
|
|
|
break;
|
|
|
|
case cah.$.DisconnectReason.MANUAL:
|
2012-01-06 23:53:04 +00:00
|
|
|
friendly_reason = "Leaving";
|
|
|
|
break;
|
2012-01-13 04:05:39 +00:00
|
|
|
case cah.$.DisconnectReason.PING_TIMEOUT:
|
2012-01-06 23:53:04 +00:00
|
|
|
friendly_reason = "Ping timeout";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
cah.log.status(data.nickname + " has disconnected (" + friendly_reason + ").");
|
|
|
|
};
|
|
|
|
|
2012-01-13 05:36:31 +00:00
|
|
|
cah.longpoll.EventHandlers[cah.$.LongPollEvent.NOOP] = function(data) {
|
2011-12-25 03:37:45 +00:00
|
|
|
// pass
|
|
|
|
};
|
|
|
|
|
2012-01-13 05:36:31 +00:00
|
|
|
cah.longpoll.EventHandlers[cah.$.LongPollEvent.CHAT] = function(data) {
|
2011-12-25 03:37:45 +00:00
|
|
|
// TODO deal with multiple channels eventually
|
|
|
|
// don't display our own chat
|
|
|
|
if (data.from != cah.nickname) {
|
2012-01-23 07:54:58 +00:00
|
|
|
cah.log.status("<" + data.from + "> " + data.message);
|
2011-12-25 03:37:45 +00:00
|
|
|
}
|
|
|
|
};
|
2012-01-18 05:58:09 +00:00
|
|
|
|
|
|
|
cah.longpoll.EventHandlers[cah.$.LongPollEvent.GAME_REFRESH] = function(data) {
|
|
|
|
cah.GameList.instance.refreshGames();
|
|
|
|
};
|