/** * Ping a message using the {@link GameMessage}. */ public static boolean pingGameMessage( String message, GameMessage gameMessage, String gcmPayloadPingReason) throws IOException { boolean success = false; for (String toHandle : gameMessage.getTo()) { Message msg = new Message.Builder() .collapseKey(gameMessage.getFrom()) .addData(GCM_PAYLOAD_PING_REASON, gcmPayloadPingReason) .addData(GCM_PAYLOAD_FROM_USER_HANDLE, gameMessage.getFrom()) .addData(GCM_PAYLOAD_TO_USER_HANDLE, toHandle) .addData(GCM_PAYLOAD_GAME_ID, gameMessage.getGameId()) .addData(GCM_PAYLOAD_MESSAGE, message) .build(); if (verifyFields(msg)) { DeviceInfo deviceInfo = endpoint.getDeviceInfo(toHandle); if (deviceInfo != null) { LOG.info("Building game message to send to user: "******" from user: "******"The device was not found in registry for user handle " + toHandle); } } else { LOG.warning("Empty fields in the GCM Message. No invites sent."); } } return success; }
/** * Ping the registered devices of the recipients of the notification. * * @param gameMessage contains the information needed for sending and processing the invite * @param gems the number of gems picked up in this game * @param mobsKilled the number of mobiles killed in this game * @param deaths the number of deaths of player in this game * @return {@code true} if delivery to all users were successful; {@code false} otherwise * @throws IOException */ public static boolean pingGamePlayerSendEndScore( GameMessage gameMessage, long gems, long mobsKilled, long deaths) throws IOException { boolean success = false; for (String toHandle : gameMessage.getTo()) { Message msg = new Message.Builder() .collapseKey(gameMessage.getFrom()) .addData(GCM_PAYLOAD_PING_REASON, PING_REASON_PLAYER_END_SCORE) .addData(GCM_PAYLOAD_FROM_USER_HANDLE, gameMessage.getFrom()) .addData(GCM_PAYLOAD_TO_USER_HANDLE, toHandle) .addData(GCM_PAYLOAD_GAME_ID, gameMessage.getGameId()) .addData(GCM_PAYLOAD_MESSAGE, "Here are the endgame scores for this player.") .addData("gems", Long.toString(gems)) .addData("mobs_killed", Long.toString(mobsKilled)) .addData("deaths", Long.toString(deaths)) .build(); if (verifyFields(msg)) { DeviceInfo deviceInfo = endpoint.getDeviceInfo(toHandle); if (deviceInfo != null) { LOG.info("Building game message to send to user: "******" from user: "******"The device was not found in registry for user handle " + toHandle); } } else { LOG.warning("Empty fields in the GCM Message. No invites sent."); } } return success; }