Minor fixes for Go API client.
* GameId needs to be an *int not an int so we can tell the difference between lack of value and value 0. * Add the description strings to DisconnectReason. * Add Sigil and IdCode to NewPlayer messages. * Add if join/quit events are being broadcast to JavascriptConfigServlet. It works much better if they are but it should still work if they aren't.
This commit is contained in:
parent
f7386c8a09
commit
7375dd8a57
|
@ -113,6 +113,12 @@ cah.$.DisconnectReason.BANNED = "B&";
|
|||
cah.$.DisconnectReason.IDLE_TIMEOUT = "it";
|
||||
cah.$.DisconnectReason.KICKED = "k";
|
||||
cah.$.DisconnectReason.MANUAL = "man";
|
||||
cah.$.DisconnectReason_msg = {};
|
||||
cah.$.DisconnectReason_msg['B&'] = "Banned";
|
||||
cah.$.DisconnectReason_msg['pt'] = "Ping timeout";
|
||||
cah.$.DisconnectReason_msg['it'] = "Kicked due to idle";
|
||||
cah.$.DisconnectReason_msg['k'] = "Kicked by server administrator";
|
||||
cah.$.DisconnectReason_msg['man'] = "Leaving";
|
||||
|
||||
cah.$.ErrorCode = function() {
|
||||
// Dummy constructor to make Eclipse auto-complete.
|
||||
|
|
|
@ -96,38 +96,45 @@ public class Constants {
|
|||
/**
|
||||
* Reason why a client disconnected.
|
||||
*/
|
||||
public enum DisconnectReason {
|
||||
public enum DisconnectReason implements Localizable {
|
||||
/**
|
||||
* The client was banned by the server administrator.
|
||||
*/
|
||||
BANNED("B&"),
|
||||
BANNED("B&", "Banned"),
|
||||
/**
|
||||
* The client made no user-caused requests within the timeout window.
|
||||
*/
|
||||
IDLE_TIMEOUT("it"),
|
||||
IDLE_TIMEOUT("it", "Kicked due to idle"),
|
||||
/**
|
||||
* The client was kicked by the server administrator.
|
||||
*/
|
||||
KICKED("k"),
|
||||
KICKED("k", "Kicked by server administrator"),
|
||||
/**
|
||||
* The user clicked the "log out" button.
|
||||
*/
|
||||
MANUAL("man"),
|
||||
MANUAL("man", "Leaving"),
|
||||
/**
|
||||
* The client failed to make any queries within the timeout window.
|
||||
*/
|
||||
PING_TIMEOUT("pt");
|
||||
PING_TIMEOUT("pt", "Ping timeout");
|
||||
|
||||
private final String reason;
|
||||
private final String message;
|
||||
|
||||
DisconnectReason(final String reason) {
|
||||
DisconnectReason(final String reason, final String message) {
|
||||
this.reason = reason;
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return reason;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getString() {
|
||||
return message;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -518,8 +525,12 @@ public class Constants {
|
|||
@Deprecated
|
||||
@GoDataType("bool")
|
||||
FROM_ADMIN("fa"),
|
||||
// This is explicitly a pointer to the value, and not just the value. We need to be able to tell
|
||||
// the difference between game 0, and lack of game id.
|
||||
// This could be done with an explicit unmarshaller for the type, and a sentinel value, but that
|
||||
// would require significantly more work on the code generation.
|
||||
@DuplicationAllowed
|
||||
@GoDataType("int")
|
||||
@GoDataType("*int")
|
||||
GAME_ID(AjaxResponse.GAME_ID),
|
||||
@DuplicationAllowed
|
||||
@GoDataType("GameInfo")
|
||||
|
|
|
@ -36,6 +36,13 @@ import java.util.concurrent.TimeUnit;
|
|||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Provider;
|
||||
import com.google.inject.Singleton;
|
||||
import com.maxmind.geoip2.model.CityResponse;
|
||||
|
||||
import net.socialgamer.cah.CahModule.BroadcastConnectsAndDisconnects;
|
||||
import net.socialgamer.cah.CahModule.MaxUsers;
|
||||
import net.socialgamer.cah.Constants.DisconnectReason;
|
||||
|
@ -47,13 +54,6 @@ import net.socialgamer.cah.data.QueuedMessage.MessageType;
|
|||
import net.socialgamer.cah.metrics.GeoIP;
|
||||
import net.socialgamer.cah.metrics.Metrics;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Provider;
|
||||
import com.google.inject.Singleton;
|
||||
import com.maxmind.geoip2.model.CityResponse;
|
||||
|
||||
|
||||
/**
|
||||
* Class that holds all users connected to the server, and provides functions to operate on said
|
||||
|
@ -132,6 +132,8 @@ public class ConnectedUsers {
|
|||
final HashMap<ReturnableData, Object> data = new HashMap<ReturnableData, Object>();
|
||||
data.put(LongPollResponse.EVENT, LongPollEvent.NEW_PLAYER.toString());
|
||||
data.put(LongPollResponse.NICKNAME, user.getNickname());
|
||||
data.put(LongPollResponse.SIGIL, user.getSigil().toString());
|
||||
data.put(LongPollResponse.ID_CODE, user.getIdCode());
|
||||
broadcastToAll(MessageType.PLAYER_EVENT, data);
|
||||
}
|
||||
// log them in the metrics
|
||||
|
|
|
@ -36,6 +36,7 @@ import javax.servlet.http.HttpServletResponse;
|
|||
import com.google.inject.Injector;
|
||||
import com.google.inject.Key;
|
||||
|
||||
import net.socialgamer.cah.CahModule.BroadcastConnectsAndDisconnects;
|
||||
import net.socialgamer.cah.CahModule.CookieDomain;
|
||||
import net.socialgamer.cah.CahModule.GlobalChatEnabled;
|
||||
import net.socialgamer.cah.CahModule.InsecureIdAllowed;
|
||||
|
@ -80,9 +81,12 @@ public class JavascriptConfigServlet extends HttpServlet {
|
|||
final Boolean globalChatEnabled = injector.getInstance(Key.get(Boolean.class, GlobalChatEnabled.class));
|
||||
final Boolean insecureIdAllowed = injector
|
||||
.getInstance(Key.get(Boolean.class, InsecureIdAllowed.class));
|
||||
final Boolean broadcastingUsers = injector
|
||||
.getInstance(Key.get(Boolean.class, BroadcastConnectsAndDisconnects.class));
|
||||
builder.append(String.format("cah.COOKIE_DOMAIN = '%s';\n", cookieDomain));
|
||||
builder.append(String.format("cah.GLOBAL_CHAT_ENABLED = %b;\n", globalChatEnabled));
|
||||
builder.append(String.format("cah.INSECURE_ID_ALLOWED = %b;\n", insecureIdAllowed));
|
||||
builder.append(String.format("cah.BROADCASTING_USERS = %b;\n", broadcastingUsers));
|
||||
|
||||
resp.setContentType("text/javascript");
|
||||
final PrintWriter out = resp.getWriter();
|
||||
|
|
Loading…
Reference in New Issue