lobby-svn Mailing List for Lobby (Page 2)
Brought to you by:
yuranet
You can subscribe to this list here.
2006 |
Jan
|
Feb
|
Mar
|
Apr
|
May
(9) |
Jun
(3) |
Jul
|
Aug
(2) |
Sep
|
Oct
|
Nov
|
Dec
|
---|---|---|---|---|---|---|---|---|---|---|---|---|
2007 |
Jan
|
Feb
(8) |
Mar
(10) |
Apr
(2) |
May
(96) |
Jun
(33) |
Jul
(113) |
Aug
(24) |
Sep
(35) |
Oct
(17) |
Nov
(36) |
Dec
(1) |
2008 |
Jan
(10) |
Feb
|
Mar
(35) |
Apr
(14) |
May
(2) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2010 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
(1) |
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2012 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
(6) |
Aug
(23) |
Sep
(19) |
Oct
(13) |
Nov
(59) |
Dec
(42) |
2013 |
Jan
(7) |
Feb
(10) |
Mar
(29) |
Apr
(10) |
May
(28) |
Jun
(3) |
Jul
(7) |
Aug
(5) |
Sep
|
Oct
|
Nov
|
Dec
(9) |
2014 |
Jan
(7) |
Feb
(1) |
Mar
(11) |
Apr
|
May
|
Jun
|
Jul
(3) |
Aug
(3) |
Sep
|
Oct
|
Nov
(1) |
Dec
(3) |
2015 |
Jan
(10) |
Feb
|
Mar
(5) |
Apr
(1) |
May
|
Jun
|
Jul
|
Aug
(1) |
Sep
(2) |
Oct
(1) |
Nov
(1) |
Dec
(1) |
2016 |
Jan
(2) |
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
(1) |
Sep
|
Oct
|
Nov
|
Dec
|
2017 |
Jan
(3) |
Feb
(1) |
Mar
(1) |
Apr
|
May
|
Jun
(2) |
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2018 |
Jan
|
Feb
|
Mar
|
Apr
|
May
(1) |
Jun
|
Jul
|
Aug
(3) |
Sep
(7) |
Oct
(4) |
Nov
|
Dec
(16) |
2019 |
Jan
(2) |
Feb
(3) |
Mar
(4) |
Apr
|
May
|
Jun
(2) |
Jul
(2) |
Aug
|
Sep
(3) |
Oct
(8) |
Nov
(3) |
Dec
(6) |
2020 |
Jan
|
Feb
|
Mar
(4) |
Apr
(11) |
May
(12) |
Jun
(12) |
Jul
(8) |
Aug
(10) |
Sep
(3) |
Oct
(11) |
Nov
(7) |
Dec
|
2021 |
Jan
|
Feb
|
Mar
(5) |
Apr
(7) |
May
(1) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
(19) |
Dec
(15) |
2022 |
Jan
(2) |
Feb
(2) |
Mar
|
Apr
|
May
(3) |
Jun
(2) |
Jul
(2) |
Aug
(1) |
Sep
|
Oct
(2) |
Nov
(1) |
Dec
(3) |
2023 |
Jan
(1) |
Feb
|
Mar
|
Apr
(5) |
May
(4) |
Jun
(4) |
Jul
(1) |
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2024 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
(1) |
Sep
|
Oct
|
Nov
|
Dec
(3) |
2025 |
Jan
|
Feb
(1) |
Mar
(1) |
Apr
(3) |
May
(7) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: <yu...@us...> - 2023-04-15 14:14:12
|
Revision: 1034 http://sourceforge.net/p/lobby/code/1034 Author: yuranet Date: 2023-04-15 14:14:08 +0000 (Sat, 15 Apr 2023) Log Message: ----------- also fix escaping for current turn player Modified Paths: -------------- trunk/src_client/net/yura/lobby/client/LobbyClientGUI.java Modified: trunk/src_client/net/yura/lobby/client/LobbyClientGUI.java =================================================================== --- trunk/src_client/net/yura/lobby/client/LobbyClientGUI.java 2023-04-15 14:04:52 UTC (rev 1033) +++ trunk/src_client/net/yura/lobby/client/LobbyClientGUI.java 2023-04-15 14:14:08 UTC (rev 1034) @@ -379,7 +379,7 @@ buffer.append("<br>"); buffer.append("WhosTurn: "); - buffer.append(game.getWhosTurn()); + buffer.append(XMLUtils.escapeXml(String.valueOf(game.getWhosTurn()))); buffer.append("<br>"); buffer.append("Players: "); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <yu...@us...> - 2023-04-15 14:04:54
|
Revision: 1033 http://sourceforge.net/p/lobby/code/1033 Author: yuranet Date: 2023-04-15 14:04:52 +0000 (Sat, 15 Apr 2023) Log Message: ----------- handle html in usernames better Modified Paths: -------------- trunk/lib/UtilME.jar trunk/src_client/net/yura/lobby/client/LobbyClientGUI.java Modified: trunk/lib/UtilME.jar =================================================================== (Binary files differ) Modified: trunk/src_client/net/yura/lobby/client/LobbyClientGUI.java =================================================================== --- trunk/src_client/net/yura/lobby/client/LobbyClientGUI.java 2023-04-15 02:12:42 UTC (rev 1032) +++ trunk/src_client/net/yura/lobby/client/LobbyClientGUI.java 2023-04-15 14:04:52 UTC (rev 1033) @@ -105,6 +105,7 @@ import javax.swing.tree.DefaultTreeModel; import javax.swing.tree.TreeCellRenderer; import javax.swing.tree.TreePath; +import net.yura.io.XMLUtils; import net.yura.lobby.client.eyecandy.TranslucentJButton; import net.yura.lobby.client.eyecandy.TranslucentJPanel; import net.yura.lobby.client.eyecandy.TranslucentJScrollPane; @@ -394,7 +395,9 @@ else { buffer.append(icon); } - buffer.append(player); + + //String playerString = HtmlEscapers.htmlEscaper().escape(String.valueOf(player)); + buffer.append(XMLUtils.escapeXml(String.valueOf(player))); buffer.append(" "); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <yu...@us...> - 2023-04-15 02:12:46
|
Revision: 1032 http://sourceforge.net/p/lobby/code/1032 Author: yuranet Date: 2023-04-15 02:12:42 +0000 (Sat, 15 Apr 2023) Log Message: ----------- show if user is blocked or flagged in main UI Modified Paths: -------------- trunk/src_client/net/yura/lobby/client/LobbyClientGUI.java trunk/src_client/net/yura/lobby/client/PlayerList.java Added Paths: ----------- trunk/src_client/net/yura/lobby/client/icons/EmojiIcon.java Modified: trunk/src_client/net/yura/lobby/client/LobbyClientGUI.java =================================================================== --- trunk/src_client/net/yura/lobby/client/LobbyClientGUI.java 2023-04-06 00:54:20 UTC (rev 1031) +++ trunk/src_client/net/yura/lobby/client/LobbyClientGUI.java 2023-04-15 02:12:42 UTC (rev 1032) @@ -385,9 +385,15 @@ Iterator it = game.getPlayers().iterator(); while (it.hasNext()) { Player player = (Player)it.next(); - buffer.append("<img src=\""); - buffer.append(PlayerList.getPlayerIcon(player)); - buffer.append("\"/>"); + Icon icon = PlayerList.getPlayerIcon(player, isUser(Player.PLAYER_MODERATOR)); + if (icon instanceof ImageIcon) { + buffer.append("<img src=\""); + buffer.append(icon); + buffer.append("\"/>"); + } + else { + buffer.append(icon); + } buffer.append(player); buffer.append(" "); } @@ -477,7 +483,7 @@ inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_BACK_SPACE, 0), DELETE); actionMap.put(DELETE, new AbstractAction() { public void actionPerformed(ActionEvent e) { - if (playerType >= Player.PLAYER_MODERATOR) { + if (isUser(Player.PLAYER_MODERATOR)) { int[] selections = games.getSelectedRows(); Game[] gamesToRemove = new Game[selections.length]; int startedGameCount = 0; @@ -602,7 +608,7 @@ JPanel topInfoPanel = new TranslucentJPanel(0.5f); - onlineState = new JButton(PlayerList.ICON_GREEN); + onlineState = new JButton(PlayerList.ICON_ONLINE); onlineState.setBorderPainted(false); onlineState.setContentAreaFilled(false); onlineState.setBorder(null); // so the border does not take up any space @@ -700,6 +706,10 @@ */ } + + public boolean isUser(int type) { + return playerType >= type; + } private LobbyGameChatListener makeListener(final int id) { return new LobbyGameChatListener() { @@ -922,7 +932,7 @@ myusernameLabel.setText(username); playerType = type; - adminButton.setVisible(playerType >= Player.PLAYER_MODERATOR); + adminButton.setVisible(isUser(Player.PLAYER_MODERATOR)); cardlayout.show(playersactions, type == Player.PLAYER_GUEST ? NOTLOGGEDIN_PANEL : LOGGEDIN_PANEL); PlayerInfoWindow piw = playerinfo == null ? null : (PlayerInfoWindow)playerinfo.remove(oldUsername); @@ -1164,7 +1174,7 @@ infoWindow = new PlayerInfoWindow(this, mycom, false); infoWindow.setUsername(user); - infoWindow.showPanels(user.equals(myusername), playerType >= Player.PLAYER_MODERATOR); + infoWindow.showPanels(user.equals(myusername), isUser(Player.PLAYER_MODERATOR)); infoWindow.setSize(500, 450); infoWindow.setLocationRelativeTo(this); @@ -1860,7 +1870,7 @@ public boolean isCellEditable(int row, int column) { if (column == 1 || column == 2) { - return playerType >= Player.PLAYER_MODERATOR; + return isUser(Player.PLAYER_MODERATOR); } return (column== (colnames.length-1) ); } @@ -1917,7 +1927,7 @@ @Override public void setValueAt(Object aValue, int row, int column) { if (column == 1) { - if (playerType >= Player.PLAYER_MODERATOR) { + if (isUser(Player.PLAYER_MODERATOR)) { Game game = getGame(row); String newName = (String) aValue; if (!game.getName().equals(newName)) { @@ -2000,7 +2010,7 @@ int x = 0; if (!players.isEmpty()) { for (Player player : players) { - Icon icon = PlayerList.getPlayerIcon(player); + Icon icon = PlayerList.getPlayerIcon(player, isUser(Player.PLAYER_MODERATOR)); icon.paintIcon(this, g, x, (getHeight() - icon.getIconHeight()) / 2); x += icon.getIconWidth(); @@ -2028,7 +2038,7 @@ list.setCellRenderer(new DefaultListCellRenderer() { public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { Component renderer = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); - setIcon(PlayerList.getPlayerIcon((Player)value)); + setIcon(PlayerList.getPlayerIcon((Player)value, isUser(Player.PLAYER_MODERATOR))); return renderer; } }); Modified: trunk/src_client/net/yura/lobby/client/PlayerList.java =================================================================== --- trunk/src_client/net/yura/lobby/client/PlayerList.java 2023-04-06 00:54:20 UTC (rev 1031) +++ trunk/src_client/net/yura/lobby/client/PlayerList.java 2023-04-15 02:12:42 UTC (rev 1032) @@ -31,6 +31,7 @@ import java.util.Map; import javax.swing.DefaultListCellRenderer; import javax.swing.DefaultListModel; +import javax.swing.Icon; import javax.swing.ImageIcon; import javax.swing.JLabel; import javax.swing.JList; @@ -39,20 +40,27 @@ import net.yura.lobby.client.eyecandy.TranslucentJList; import net.yura.lobby.client.eyecandy.TranslucentJPanel; import net.yura.lobby.client.eyecandy.TranslucentJScrollPane; +import net.yura.lobby.client.icons.EmojiIcon; import net.yura.lobby.model.Player; public class PlayerList extends TranslucentJPanel { - public static final ImageIcon ICON_ARROW = new ImageIcon(PlayerList.class.getResource("icons/arrow.gif")); + public static final Icon ICON_ARROW = new ImageIcon(PlayerList.class.getResource("icons/arrow.gif")); - public static final ImageIcon ICON_BLUE = new ImageIcon(PlayerList.class.getResource("icons/blue.gif")); - public static final ImageIcon ICON_CYAN = new ImageIcon(PlayerList.class.getResource("icons/cyan.gif")); - public static final ImageIcon ICON_GRAY = new ImageIcon(PlayerList.class.getResource("icons/gray.gif")); - public static final ImageIcon ICON_GREEN = new ImageIcon(PlayerList.class.getResource("icons/green.gif")); - public static final ImageIcon ICON_MAGENTA = new ImageIcon(PlayerList.class.getResource("icons/magenta.gif")); - public static final ImageIcon ICON_RED = new ImageIcon(PlayerList.class.getResource("icons/red.gif")); - public static final ImageIcon ICON_YELLOW = new ImageIcon(PlayerList.class.getResource("icons/yellow.gif")); - + public static final Icon ICON_ONLINE = new ImageIcon(PlayerList.class.getResource("icons/green.gif")); + + public static final Icon ICON_BLOCKED = new EmojiIcon("\u26D4"); + public static final Icon ICON_FLAGGED = new EmojiIcon("\uD83D\uDEA9"); + + //public static final Icon ICON_GUEST = new EmojiIcon("\u26AA"); // should we use emoji for all?? + public static final Icon ICON_GUEST = new ImageIcon(PlayerList.class.getResource("icons/gray.gif")); + public static final Icon ICON_NORMAL = new ImageIcon(PlayerList.class.getResource("icons/yellow.gif")); + public static final Icon ICON_SUBSCRIBER = new ImageIcon(PlayerList.class.getResource("icons/cyan.gif")); + + public static final Icon ICON_MODERATOR = new ImageIcon(PlayerList.class.getResource("icons/blue.gif")); + public static final Icon ICON_ADMIN = new ImageIcon(PlayerList.class.getResource("icons/magenta.gif")); + public static final Icon ICON_GOD = new ImageIcon(PlayerList.class.getResource("icons/red.gif")); + private JList lobbyPlayers; private DefaultListModel playersModel; @@ -193,14 +201,21 @@ lobbyPlayers.repaint(); } - public static ImageIcon getPlayerIcon(Player pl) { + public static Icon getPlayerIcon(Player pl, boolean mod) { + if (mod) { + switch(pl.getType()) { + case Player.PLAYER_BLOCKED: return ICON_BLOCKED; + case Player.PLAYER_FLAGGED: return ICON_FLAGGED; + } + } + switch(pl.getType()) { - case Player.PLAYER_GOD: return ICON_RED; - case Player.PLAYER_ADMIN: return ICON_MAGENTA; - case Player.PLAYER_MODERATOR: return ICON_BLUE; - case Player.PLAYER_SUBSCRIBER: return ICON_GREEN; - case Player.PLAYER_NORMAL: return ICON_YELLOW; - default: return ICON_GRAY; // Player.PLAYER_GUEST + case Player.PLAYER_GOD: return ICON_GOD; + case Player.PLAYER_ADMIN: return ICON_ADMIN; + case Player.PLAYER_MODERATOR: return ICON_MODERATOR; + case Player.PLAYER_SUBSCRIBER: return ICON_SUBSCRIBER; + case Player.PLAYER_NORMAL: return ICON_NORMAL; + default: return ICON_GUEST; // Player.PLAYER_GUEST } } @@ -229,7 +244,7 @@ Player player = (Player)value; - setIcon( getPlayerIcon( player ) ); + setIcon( getPlayerIcon(player, false) ); //if(retValue instanceof JComponent) // ((JComponent)retValue).setOpaque(false); @@ -251,7 +266,9 @@ g.translate(-gap,0); //} - if (drawArraw) { g.drawImage(ICON_ARROW.getImage(),4,(getHeight()-ICON_ARROW.getIconHeight())/2,this); } + if (drawArraw) { + ICON_ARROW.paintIcon(this, g, 4, (getHeight() - ICON_ARROW.getIconHeight()) / 2); + } } // adds a extra bit to the size Added: trunk/src_client/net/yura/lobby/client/icons/EmojiIcon.java =================================================================== --- trunk/src_client/net/yura/lobby/client/icons/EmojiIcon.java (rev 0) +++ trunk/src_client/net/yura/lobby/client/icons/EmojiIcon.java 2023-04-15 02:12:42 UTC (rev 1032) @@ -0,0 +1,47 @@ +package net.yura.lobby.client.icons; + +import java.awt.Component; +import java.awt.Font; +import java.awt.FontMetrics; +import java.awt.Graphics; +import java.awt.Toolkit; +import javax.swing.Icon; +import javax.swing.UIManager; + +public class EmojiIcon implements Icon { + + private FontMetrics metrics; + private String emoji; + + public EmojiIcon(String emoji) { + this(emoji, null); + } + + public EmojiIcon(String emoji, Font font) { + if (font == null) { + font = UIManager.getDefaults().getFont("Label.font"); + } + this.metrics = Toolkit.getDefaultToolkit().getFontMetrics(font); + this.emoji = emoji; + } + + @Override + public void paintIcon(Component c, Graphics g, int x, int y) { + g.drawString(emoji, x, y + metrics.getAscent()); + } + + @Override + public int getIconWidth() { + return metrics.stringWidth(emoji); + } + + @Override + public int getIconHeight() { + return metrics.getHeight(); + } + + @Override + public String toString() { + return emoji; + } +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <yu...@us...> - 2023-04-06 00:54:21
|
Revision: 1031 http://sourceforge.net/p/lobby/code/1031 Author: yuranet Date: 2023-04-06 00:54:20 +0000 (Thu, 06 Apr 2023) Log Message: ----------- typo fix Modified Paths: -------------- trunk/src_server/META-INF/persistence.xml Modified: trunk/src_server/META-INF/persistence.xml =================================================================== --- trunk/src_server/META-INF/persistence.xml 2023-04-06 00:02:52 UTC (rev 1030) +++ trunk/src_server/META-INF/persistence.xml 2023-04-06 00:54:20 UTC (rev 1031) @@ -29,10 +29,12 @@ utf8mb4_0900_ai_ci - unicode standard 9.0 (MySQL 8.0+) utf8mb4_unicode_520_ci - unicode standard 5.20 (MySQL 5.6+) utf8mb4_unicode_ci - unicode standard 4.0 (MySQL 5.5+) - utf8mb4_general_ci - not using unicode standard (MySQL 5.5+) + utf8mb4_general_ci - honors some rules but uses a simplified algorithm favoring speed over accuracy. (MySQL 5.5+) + utf8mb4_bin - sorts data by its binary notation and does not consider any language-specific rules. --> - <property name="datanucleus.rdbms.mysql.collation" value=" utf8mb4_general_ci"/> + <!-- ci = case-insensitive ai = accent-insensitivity --> + <property name="datanucleus.rdbms.mysql.collation" value="utf8mb4_general_ci"/> <property name="datanucleus.rdbms.mysql.characterSet" value="utf8mb4"/> <property name="datanucleus.schema.autoCreateAll" value="true"/> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <yu...@us...> - 2023-04-06 00:02:54
|
Revision: 1030 http://sourceforge.net/p/lobby/code/1030 Author: yuranet Date: 2023-04-06 00:02:52 +0000 (Thu, 06 Apr 2023) Log Message: ----------- fix to support emoji in names Modified Paths: -------------- trunk/src_server/META-INF/persistence.xml trunk/src_server/net/yura/lobby/server/GameLobby.java Modified: trunk/src_server/META-INF/persistence.xml =================================================================== --- trunk/src_server/META-INF/persistence.xml 2023-01-17 18:38:19 UTC (rev 1029) +++ trunk/src_server/META-INF/persistence.xml 2023-04-06 00:02:52 UTC (rev 1030) @@ -14,14 +14,27 @@ <properties> <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver" /> + <!-- if we get "Illegal mix of collations" then add &connectionCollation=utf8mb4_general_ci --> + <!-- the default seems to be utf8mb4_general_ci on mysql 5.7 and utf8mb4_0900_ai_ci on mysql 8.0 --> <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/lobby?autoReconnect=true&useUnicode=yes&characterEncoding=UTF-8"/> <property name="javax.persistence.jdbc.user" value="root" /> <property name="javax.persistence.jdbc.password" value="password"/> <!-- starting the server prints out that these 2 lines are ignored, but they are actually not --> - <property name="datanucleus.rdbms.mysql.collation" value="utf8_general_ci"/> - <property name="datanucleus.rdbms.mysql.characterSet" value="utf8"/> + <!-- we need to use utf8mb4 and utf8mb4_general_ci to support emoji --> + <!-- + The choice of collation to use determins how sorting is done in MySQL + + utf8mb4_0900_ai_ci - unicode standard 9.0 (MySQL 8.0+) + utf8mb4_unicode_520_ci - unicode standard 5.20 (MySQL 5.6+) + utf8mb4_unicode_ci - unicode standard 4.0 (MySQL 5.5+) + utf8mb4_general_ci - not using unicode standard (MySQL 5.5+) + + --> + <property name="datanucleus.rdbms.mysql.collation" value=" utf8mb4_general_ci"/> + <property name="datanucleus.rdbms.mysql.characterSet" value="utf8mb4"/> + <property name="datanucleus.schema.autoCreateAll" value="true"/> <!-- these are false by default anyway --> Modified: trunk/src_server/net/yura/lobby/server/GameLobby.java =================================================================== --- trunk/src_server/net/yura/lobby/server/GameLobby.java 2023-01-17 18:38:19 UTC (rev 1029) +++ trunk/src_server/net/yura/lobby/server/GameLobby.java 2023-04-06 00:02:52 UTC (rev 1030) @@ -978,6 +978,8 @@ } } + + // TODO if we reported user X, do NOT show them my messages for (LobbySession reciever: toWho) { if (fromWho == null || // system messages (fromWho.getPlayerType() >= Player.PLAYER_GUEST && !reporters.contains(reciever.getUsername())) || This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <yu...@us...> - 2023-01-17 18:38:21
|
Revision: 1029 http://sourceforge.net/p/lobby/code/1029 Author: yuranet Date: 2023-01-17 18:38:19 +0000 (Tue, 17 Jan 2023) Log Message: ----------- support reporting game with no users Modified Paths: -------------- trunk/src_server/net/yura/lobby/server/LobbyController.java trunk/test/net/yura/lobby/server/ServerTest.java trunk/test/net/yura/lobby/util/LobbyConnection.java Modified: trunk/src_server/net/yura/lobby/server/LobbyController.java =================================================================== --- trunk/src_server/net/yura/lobby/server/LobbyController.java 2022-12-23 23:22:51 UTC (rev 1028) +++ trunk/src_server/net/yura/lobby/server/LobbyController.java 2023-01-17 18:38:19 UTC (rev 1029) @@ -363,15 +363,15 @@ } else if (ProtoLobby.REQUEST_FLAG_USER.equals(command)) { Map request = (Map)param; - Integer optionalGameId = (Integer)request.get("game_id"); + Integer optionalGameId = (Integer)request.get("game_id"); // may be null if (optionalGameId != null) { gameId = optionalGameId; } String text = (String)request.get("message"); - String username = (String)request.get("username"); + String optionalUsername = (String)request.get("username"); // may be null - if (session.getUsername().equals(username)) { - throw new IllegalArgumentException("you can not report yourself: " + username); + if (session.getUsername().equals(optionalUsername)) { + throw new IllegalArgumentException("you can not report yourself: " + optionalUsername); } User user, reporter; @@ -378,19 +378,24 @@ try { lobby.database.startTransaction(); // get user id NOW in case they change there username later - user = lobby.database.getUserByUsername(username); + user = optionalUsername == null ? null : lobby.database.getUserByUsername(optionalUsername); reporter = lobby.database.getUserByUsername(session.getUsername()); - user.getReporters().add(reporter); - lobby.database.saveUser(user); + if (user != null) { + user.getReporters().add(reporter); + lobby.database.saveUser(user); + } } finally { lobby.database.endTransaction(); } + + String subject = "flagged " + (user == null ? " game " + optionalGameId : user.getId()); + String flaggedString = user == null ? "" : ("flagged=" + toAdminString(user) + "\n "); + String messageString = "gameId=" + gameId + " message=" + text + "\n "; + String reporterString = "reporter=" + toAdminString(reporter); - Alert.sendAlert("flagged " + user.getId(), "reporter=" + session.getUsername() + " (" + reporter.getId() +") <" + reporter.getEmail() + ">\n" + - " gameId=" + gameId + " message=" + text + "\n" + - " flagged=" + username + " (" + user.getId() + ") <" + user.getEmail() + ">", lobby.database); + Alert.sendAlert(subject, flaggedString + messageString + reporterString, lobby.database); } // ############################################################################################# ADMIN else if (ProtoLobby.REQUEST_DEL_GAME.equals(command)) { @@ -426,6 +431,10 @@ LobbyLogger.log(gameId, Level.WARNING, "error dealing with "+session+" "+command+" "+param, ex); } } + + private static String toAdminString(User user) { + return user.getName() + " (" + user.getId() + ")" + (user.getEmail() == null ? "" : " <" + user.getEmail() + ">"); + } // HACK/TODO: find better way of getting game id before command is processed private static int getGameId(Object obj) { Modified: trunk/test/net/yura/lobby/server/ServerTest.java =================================================================== --- trunk/test/net/yura/lobby/server/ServerTest.java 2022-12-23 23:22:51 UTC (rev 1028) +++ trunk/test/net/yura/lobby/server/ServerTest.java 2023-01-17 18:38:19 UTC (rev 1029) @@ -3,6 +3,7 @@ import net.yura.lobby.util.LobbyConnection; import java.lang.management.ManagementFactory; import java.util.List; +import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; import javax.management.JMX; @@ -424,7 +425,30 @@ mycom1.disconnect(); } + + @Test + public void testFlaggedGame() throws Exception { + LobbyConnection mycom1 = new LobbyConnection(id1); + Player player = mycom1.connect(server, port).get(); + GameType type = getMockGameType(mycom1.getGameTypes().get()); + mycom1.getGames(type); // do not call get, as no games are returned + Game game = new Game("my game", BLACKJACK_OPTIONS, 1, 1000); + game.setType(type); + Game newGame = mycom1.createNewGame(game).get(); + System.out.println("game object: " + mycom1.playGame(newGame.getId()).get()); + + game = mycom1.leaveGame(newGame.getId()).get(); + Assert.assertEquals(0, game.getMaxPlayers()); + Assert.assertEquals(0, game.getPlayers().size()); + + CompletableFuture<Void> flagFuture = mycom1.flagGame(newGame.getId(), "my game"); + sleep(1000); + Assert.assertFalse(flagFuture.isCompletedExceptionally()); + + mycom1.disconnect(); + } + { // TODO: new test Modified: trunk/test/net/yura/lobby/util/LobbyConnection.java =================================================================== --- trunk/test/net/yura/lobby/util/LobbyConnection.java 2022-12-23 23:22:51 UTC (rev 1028) +++ trunk/test/net/yura/lobby/util/LobbyConnection.java 2023-01-17 18:38:19 UTC (rev 1029) @@ -97,8 +97,15 @@ return newGame; } - public void leaveGame(int gameId) { + public CompletableFuture<Game> leaveGame(int gameId) { + CompletableFuture<Game> gameFuture = new CompletableFuture(); + client.gameFuture = gameFuture; + + // as the user is not a player in this game any more, we need to force this future to finish with this game + client.gameQueue.consume(game -> gameFuture.complete(game)); + mycom.leaveGame(gameId); + return gameFuture; } public void closeGame(int gameId) { @@ -136,12 +143,32 @@ mycom.sendGameMessage(id, obj); } - public void flagUser(String name) { + public CompletableFuture<Void> flagUser(String name) { + CompletableFuture<Void> flagFuture = new CompletableFuture(); + client.flagFuture = flagFuture; + Map request = new HashMap(); request.put("username", name); mycom.sendAdminCommand(ProtoLobby.REQUEST_FLAG_USER, request); + + return flagFuture; } + /** + * flag a game that currently has no users in it, but is still showing in the lobby + */ + public CompletableFuture<Void> flagGame(int gameId, String message) { + CompletableFuture<Void> flagFuture = new CompletableFuture(); + client.flagFuture = flagFuture; + + Map request = new HashMap(); + request.put("message", message); + request.put("game_id", gameId); + mycom.sendAdminCommand(ProtoLobby.REQUEST_FLAG_USER, request); + + return flagFuture; + } + public static class LoggingClient implements LobbyClient, PushLobbyClient { public String username; @@ -159,6 +186,7 @@ CompletableFuture<Object> playGameFuture; CompletableFuture<String> chatFuture; CompletableFuture<Void> disconnectFuture; + CompletableFuture<Void> flagFuture; @Override public void connected() { @@ -198,6 +226,9 @@ if (playerInfoFuture != null && !playerInfoFuture.isDone()) { playerInfoFuture.completeExceptionally(new Exception(error)); } + if (flagFuture != null && !flagFuture.isDone()) { + flagFuture.completeExceptionally(new Exception(error)); + } } @Override This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <yu...@us...> - 2022-12-23 23:22:53
|
Revision: 1028 http://sourceforge.net/p/lobby/code/1028 Author: yuranet Date: 2022-12-23 23:22:51 +0000 (Fri, 23 Dec 2022) Log Message: ----------- try to ignore OptimisticLockException for removing games Modified Paths: -------------- trunk/src_server/net/yura/lobby/database/impl/JPADatabase.java Modified: trunk/src_server/net/yura/lobby/database/impl/JPADatabase.java =================================================================== --- trunk/src_server/net/yura/lobby/database/impl/JPADatabase.java 2022-12-19 19:50:48 UTC (rev 1027) +++ trunk/src_server/net/yura/lobby/database/impl/JPADatabase.java 2022-12-23 23:22:51 UTC (rev 1028) @@ -14,8 +14,10 @@ import javax.persistence.EntityManagerFactory; import javax.persistence.EntityTransaction; import javax.persistence.NoResultException; +import javax.persistence.OptimisticLockException; import javax.persistence.Persistence; import javax.persistence.Query; +import javax.persistence.RollbackException; import net.yura.lobby.database.Database; import net.yura.lobby.database.GameRoom; import net.yura.lobby.database.GameTypeRoom; @@ -180,9 +182,22 @@ @Override public void removeGame(GameRoom gameRoom) { - remove(gameRoom); + try { + // TODO what we want to do is do deleteById + remove(gameRoom); + } + catch (RollbackException rollback) { + // we are trying to remove a game, we do not care about + // OptimisticLocking, so we will retry + if (rollback.getCause() instanceof OptimisticLockException) { + remove(getGame(gameRoom.getId())); + } + else { + throw rollback; + } + } } - + @Override public GameTypeRoom getGameType(int id) { return find(GameTypeRoom.class, id); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <yu...@us...> - 2022-12-19 19:50:51
|
Revision: 1027 http://sourceforge.net/p/lobby/code/1027 Author: yuranet Date: 2022-12-19 19:50:48 +0000 (Mon, 19 Dec 2022) Log Message: ----------- fixed bug, not loading any game that is over 1MB Modified Paths: -------------- trunk/src/net/yura/lobby/client/LobbyCom.java trunk/src/net/yura/lobby/client/TcpClient.java trunk/src_server/net/yura/lobby/database/impl/MemoryDatabase.java Added Paths: ----------- trunk/src/net/yura/lobby/util/ByteBufferUtil.java trunk/test/net/yura/lobby/util/ByteBufferUtilTest.java Modified: trunk/src/net/yura/lobby/client/LobbyCom.java =================================================================== --- trunk/src/net/yura/lobby/client/LobbyCom.java 2022-12-19 15:57:25 UTC (rev 1026) +++ trunk/src/net/yura/lobby/client/LobbyCom.java 2022-12-19 19:50:48 UTC (rev 1027) @@ -37,6 +37,7 @@ import net.yura.lobby.model.Message; import net.yura.lobby.model.Player; import net.yura.lobby.util.ByteBufferInputStream; +import net.yura.lobby.util.ByteBufferUtil; import net.yura.mobile.util.StringUtil; public class LobbyCom implements Connection, ProtoAccess.ObjectProvider { @@ -444,6 +445,13 @@ client = new TcpClient() { // ByteInputStream data = new ByteInputStream(); int size = -1; + + /** + * most messages are read directly from the read buffer, but big ones need to be loaded into their own buffer + * we want to keep a ByteBuffer instead of byte[] to keep track of how much we have written to it + */ + ByteBuffer messageBuffer; + protected void onRead(final ByteBuffer buf) throws Exception { // byte[] bytes = new byte[ buf.remaining() ]; // buf.get(bytes); @@ -452,13 +460,36 @@ while (true) { if (size==-1 && data.available() >= 4) { size = data.readInt(); + + // if this message is not going to be able to be read directly from the read buffer + if (size > buf.capacity()) { + messageBuffer = ByteBuffer.allocate(size); + } } - else if (size>=0 && data.available() >= size) { + else if (messageBuffer != null && data.available() > 0) { + // read as much as possible into the messageBuffer + ByteBufferUtil.transferAsMuchAsPossible(buf, messageBuffer); + + // if messageBuffer is full (pos == lim == cap), load and process the message + if (messageBuffer.position() == messageBuffer.capacity()) { + messageBuffer.flip(); // get buffer ready for reading + ByteBufferInputStream data2 = new ByteBufferInputStream(messageBuffer); + messageBuffer = null; + Message message = (Message)access.load(data2, size); + size = -1; + messageFromServer(message); + } + } + else if (size >= 0 && data.available() >= size) { Message message = (Message)access.load(data, size); size = -1; messageFromServer(message); } else { + // a read buffer is full when position == 0 && limit == capacity + if (buf.remaining() == buf.capacity()) { + System.err.println("Buffer full!!! and yet we are not doing anything?!? " + buf); + } break; } } Modified: trunk/src/net/yura/lobby/client/TcpClient.java =================================================================== --- trunk/src/net/yura/lobby/client/TcpClient.java 2022-12-19 15:57:25 UTC (rev 1026) +++ trunk/src/net/yura/lobby/client/TcpClient.java 2022-12-19 19:50:48 UTC (rev 1027) @@ -44,15 +44,15 @@ private long reconnectInterval = INITIAL_RECONNECT_INTERVAL; - private ByteBuffer readBuf = ByteBuffer.allocateDirect(READ_BUFFER_SIZE); // 1Mb - private ByteBuffer writeBuf = ByteBuffer.allocateDirect(WRITE_BUFFER_SIZE); // 1Mb + private ByteBuffer readBuf = ByteBuffer.allocateDirect(READ_BUFFER_SIZE); // 1Mb (1,048,576 Bytes) + private ByteBuffer writeBuf = ByteBuffer.allocateDirect(WRITE_BUFFER_SIZE); // 1Mb (1,048,576 Bytes) private final Thread thread = new Thread(null,this,"TCP-Client",100000000); - + // we store as String and int as android does not allow the creating of a new InetSocketAddress in the event thread private String address; private int port; - + private Selector selector; private SocketChannel channel; Added: trunk/src/net/yura/lobby/util/ByteBufferUtil.java =================================================================== --- trunk/src/net/yura/lobby/util/ByteBufferUtil.java (rev 0) +++ trunk/src/net/yura/lobby/util/ByteBufferUtil.java 2022-12-19 19:50:48 UTC (rev 1027) @@ -0,0 +1,22 @@ +package net.yura.lobby.util; + +import java.nio.ByteBuffer; + +public class ByteBufferUtil { + + public static int transferAsMuchAsPossible(ByteBuffer src, ByteBuffer dest) { + int nTransfer = Math.min(dest.remaining(), src.remaining()); + if (nTransfer > 0) { + if (dest.remaining() >= src.remaining()) { + dest.put(src); + } + else { + ByteBuffer srcCopy = src.duplicate(); + srcCopy.limit(srcCopy.position() + nTransfer); + dest.put(srcCopy); + src.position(src.position() + nTransfer); + } + } + return nTransfer; + } +} Modified: trunk/src_server/net/yura/lobby/database/impl/MemoryDatabase.java =================================================================== --- trunk/src_server/net/yura/lobby/database/impl/MemoryDatabase.java 2022-12-19 15:57:25 UTC (rev 1026) +++ trunk/src_server/net/yura/lobby/database/impl/MemoryDatabase.java 2022-12-19 19:50:48 UTC (rev 1027) @@ -16,6 +16,8 @@ */ package net.yura.lobby.database.impl; +import java.nio.file.Files; +import java.nio.file.Paths; import java.util.Collection; import java.util.Collections; import java.util.HashMap; @@ -81,7 +83,7 @@ startTransaction(); - saveGameType(makeNewGame( + saveGameType(makeNewGameType( 1, "Risk", "RiskClient.jar", @@ -91,7 +93,7 @@ "board.map,aa.map,godstorm.map,luca.map,risk.map,risk2.map,risk2210.map,roman_empire.map,sersom.map,teg.map,tube.map,uk.map,world.map" )); - saveGameType(makeNewGame( + saveGameType(makeNewGameType( 2, "Rescue! Max", "Rescue/RescueClient.jar", @@ -101,7 +103,7 @@ "rescuemax.xml,rescue.xml,newmax.xml" )); - saveGameType(makeNewGame( + saveGameType(makeNewGameType( 3, "Blackjack", "BlackjackClient.jar", @@ -121,11 +123,14 @@ saveUser(makeNewUser("test-mod", Player.PLAYER_MODERATOR)); saveUser(makeNewUser("test-blocked", Player.PLAYER_BLOCKED)); saveUser(makeNewUser("test-flagged", Player.PLAYER_FLAGGED)); - + + // setup any initial games + //saveGame(makeDominationGame()); + endTransaction(); } - private static GameTypeRoom makeNewGame(int id,String name,String clientJar,String clientClass,String serverJar,String serverClass,String newgameoptions) { + private static GameTypeRoom makeNewGameType(int id,String name,String clientJar,String clientClass,String serverJar,String serverClass,String newgameoptions) { GameTypeRoom gtr = new GameTypeRoom(); gtr.setId(id); gtr.setName(name); @@ -146,7 +151,7 @@ } public static GameTypeRoom makeDominationGameType() { - return makeNewGame( + return makeNewGameType( 4, "Domination", "Domination/DominationClient.jar", @@ -156,6 +161,28 @@ "luca.map,ameroki.map,eurasien.map,geoscape.map,lotr.map,risk.map,RiskEurope.map,roman_empire.map,sersom.map,teg.map,tube.map,uk.map,world.map" ); } + + public GameRoom makeDominationGame() { + GameRoom testGame = new GameRoom(); + testGame.setName("test game"); + testGame.setOptions("0\n" + + "0\n" + + "4\n" + + "choosemap Classic World Domination Missions.map\n" + + "startgame domination increasing recycle"); + testGame.setMaxPlayers(1); + testGame.setUsers(Collections.singleton(registeredPeople.get("test-guest"))); + testGame.setTimeout(86_400); // 1 day + gameTypes.get(4).createNewGame(testGame); + try { + byte[] gameData = Files.readAllBytes(Paths.get("game2432769.save")); + testGame.setGameData(gameData); + } + catch (Exception ex) { + throw new RuntimeException(ex); + } + return testGame; + } @Override public Collection<GameTypeRoom> getGameTypes() { @@ -165,7 +192,7 @@ @Override public Collection<GameRoom> getGameRooms() { checkTransaction(); - return Collections.EMPTY_LIST; + return games.values(); } @Override Added: trunk/test/net/yura/lobby/util/ByteBufferUtilTest.java =================================================================== --- trunk/test/net/yura/lobby/util/ByteBufferUtilTest.java (rev 0) +++ trunk/test/net/yura/lobby/util/ByteBufferUtilTest.java 2022-12-19 19:50:48 UTC (rev 1027) @@ -0,0 +1,49 @@ +package net.yura.lobby.util; + +import java.nio.ByteBuffer; +import static org.junit.Assert.assertTrue; +import org.junit.Test; + +public class ByteBufferUtilTest { + + /** + * https://stackoverflow.com/questions/570168/transferring-bytes-from-one-bytebuffer-to-another + * + * @see ByteBufferUtil#transferAsMuchAsPossible(java.nio.ByteBuffer, java.nio.ByteBuffer) + */ + @Test + public void transferTest() { + ByteBuffer bb1 = ByteBuffer.allocate(256); + ByteBuffer bb2 = ByteBuffer.allocate(50); + for (int i = 0; i < 100; ++i) + { + bb1.put((byte)i); + } + bb1.flip(); + bb1.position(5); + ByteBuffer bb1a = bb1.slice(); + bb1a.position(2); + // bb3 includes the 5-100 range + bb2.put((byte)77); + // something to see this works when bb2 isn't empty + int n = ByteBufferUtil.transferAsMuchAsPossible(bb1a, bb2); + boolean itWorked = (n == 49); + + if (bb1a.position() != 51) + itWorked = false; + if (bb2.position() != 50) + itWorked = false; + bb2.rewind(); + if (bb2.get() != 77) + itWorked = false; + for (int i = 0; i < 49; ++i) + { + if (bb2.get() != i+7) + { + itWorked = false; + break; + } + } + assertTrue(itWorked); + } +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <yu...@us...> - 2022-12-19 15:57:27
|
Revision: 1026 http://sourceforge.net/p/lobby/code/1026 Author: yuranet Date: 2022-12-19 15:57:25 +0000 (Mon, 19 Dec 2022) Log Message: ----------- netty update to last fat jar 4.1.68.Final Modified Paths: -------------- trunk/lib/netty-all-4.1.Final.jar Modified: trunk/lib/netty-all-4.1.Final.jar =================================================================== (Binary files differ) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <yu...@us...> - 2022-11-09 17:00:36
|
Revision: 1025 http://sourceforge.net/p/lobby/code/1025 Author: yuranet Date: 2022-11-09 17:00:34 +0000 (Wed, 09 Nov 2022) Log Message: ----------- do not allow flagged users to join game Modified Paths: -------------- trunk/src_server/net/yura/lobby/server/GameLobby.java trunk/test/net/yura/lobby/server/ServerTest.java Modified: trunk/src_server/net/yura/lobby/server/GameLobby.java =================================================================== --- trunk/src_server/net/yura/lobby/server/GameLobby.java 2022-10-09 16:43:56 UTC (rev 1024) +++ trunk/src_server/net/yura/lobby/server/GameLobby.java 2022-11-09 17:00:34 UTC (rev 1025) @@ -1022,15 +1022,21 @@ } String username = session.getUsername(); + User user = database.getUserByUsername(username); - User user = database.getUserByUsername(username); - if (user.getType() <= Player.PLAYER_BLOCKED) { - throw new RuntimeException(); - } int noGames = user.getGames().size(); if (maxGames >= 0 && noGames >= maxGames) { throw new IllegalArgumentException(username + " in too many games: " + noGames); } + + // if someone in this game has blocked this user + if (!Collections.disjoint(game.getPlayers(), user.getReporters())) { + throw new RuntimeException("unable to join private game"); + } + + if (user.getType() <= Player.PLAYER_BLOCKED) { + throw new RuntimeException(); + } } public GameRoom createGame(Game game, LobbySession session) { Modified: trunk/test/net/yura/lobby/server/ServerTest.java =================================================================== --- trunk/test/net/yura/lobby/server/ServerTest.java 2022-10-09 16:43:56 UTC (rev 1024) +++ trunk/test/net/yura/lobby/server/ServerTest.java 2022-11-09 17:00:34 UTC (rev 1025) @@ -256,7 +256,7 @@ sleep(1000); try { - Assert.assertEquals(false, chatFuture.isDone()); + Assert.assertFalse(chatFuture.isDone()); } catch(AssertionError error) { Assert.fail("chatFuture has result " + chatFuture.get()); @@ -266,7 +266,38 @@ //sleep(1000); // TODO we need to wait as if both diconnect happen at same time, 2 DB transations happen at the same time mycom2.disconnect(); } + + @Test + public void testFlaggedUserJoinGame() throws Exception { + LobbyConnection mycom1 = new LobbyConnection(id1); + Player user1 = mycom1.connect(server, port).get(); + GameType type1 = getMockGameType(mycom1.getGameTypes().get()); + mycom1.getGames(type1); // do not call get, as no games are returned + Game game1 = new Game("my game name", BLACKJACK_OPTIONS, 2, 1000); + game1.setType(type1); + game1 = mycom1.createNewGame(game1).get(); + + LobbyConnection mycom2 = new LobbyConnection(id2); + Player user2 = mycom2.connect(server, port).get(); + + mycom1.flagUser(user2.getName()); + + GameType type2 = getMockGameType(mycom2.getGameTypes().get()); + Game game2 = mycom2.getGames(type2).take(); + + try { + mycom2.joinGame(game2.getId(), null).get(); + Assert.fail("should not allow join"); + } + catch (ExecutionException ex) { + MatcherAssert.assertThat(ex.toString(), CoreMatchers.containsString("unable to join private game")); + } + + mycom1.disconnect(); + mycom2.disconnect(); + } + @Test public void testOldClientForceUpgrade() throws Exception { LobbyConnection mycom1 = new LobbyConnection("test-guest-uuid", "0"); // BlackJack does not support version 0 @@ -345,7 +376,7 @@ Assert.fail("should not allow join"); } catch (ExecutionException ex) { - Assert.assertThat(ex.toString(), CoreMatchers.containsString("You didn't say the Magic Word!")); + MatcherAssert.assertThat(ex.toString(), CoreMatchers.containsString("You didn't say the Magic Word!")); } mycom2.disconnect(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <yu...@us...> - 2022-10-09 16:43:57
|
Revision: 1024 http://sourceforge.net/p/lobby/code/1024 Author: yuranet Date: 2022-10-09 16:43:56 +0000 (Sun, 09 Oct 2022) Log Message: ----------- fix the build Modified Paths: -------------- trunk/src/net/yura/lobby/client/TcpClient.java Modified: trunk/src/net/yura/lobby/client/TcpClient.java =================================================================== --- trunk/src/net/yura/lobby/client/TcpClient.java 2022-10-09 16:41:30 UTC (rev 1023) +++ trunk/src/net/yura/lobby/client/TcpClient.java 2022-10-09 16:43:56 UTC (rev 1024) @@ -336,6 +336,7 @@ protected void onRead(ByteBuffer buf) throws Exception { buf.position(buf.limit()); } protected void onDisconnected() { } protected void onConnected() throws Exception { } + protected void onConnectionError(Exception ex) { } }; client.setAddress("127.0.0.1", 20001); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <yu...@us...> - 2022-10-09 16:41:40
|
Revision: 1023 http://sourceforge.net/p/lobby/code/1023 Author: yuranet Date: 2022-10-09 16:41:30 +0000 (Sun, 09 Oct 2022) Log Message: ----------- log connection errors to UI Modified Paths: -------------- trunk/build.xml trunk/src/net/yura/lobby/client/LobbyClient.java trunk/src/net/yura/lobby/client/LobbyCom.java trunk/src/net/yura/lobby/client/TcpClient.java trunk/src_server/net/yura/lobby/server/GameLobby.java Modified: trunk/build.xml =================================================================== --- trunk/build.xml 2022-08-02 16:54:01 UTC (rev 1022) +++ trunk/build.xml 2022-10-09 16:41:30 UTC (rev 1023) @@ -102,6 +102,7 @@ <!-- TARGET NEEDS TO BE 1.8 for DataNucleus to work if it is newer (or older) the DataNucleus enhancer will fail +(DataNucleus 5.2.0 - Support for Java 11 bytecode) (DataNucleus 5.2.2 - Support for Java 13 and Java 14 bytecode) currently we are unable to upgrade to anything newer then DataNucleus 5.0.2 Modified: trunk/src/net/yura/lobby/client/LobbyClient.java =================================================================== --- trunk/src/net/yura/lobby/client/LobbyClient.java 2022-08-02 16:54:01 UTC (rev 1022) +++ trunk/src/net/yura/lobby/client/LobbyClient.java 2022-10-09 16:41:30 UTC (rev 1023) @@ -41,7 +41,8 @@ void connecting(String message); /** - * some error + * some error, this can happen at any point. + * This needs to popup an error to the user */ void error(String error); Modified: trunk/src/net/yura/lobby/client/LobbyCom.java =================================================================== --- trunk/src/net/yura/lobby/client/LobbyCom.java 2022-08-02 16:54:01 UTC (rev 1022) +++ trunk/src/net/yura/lobby/client/LobbyCom.java 2022-10-09 16:41:30 UTC (rev 1023) @@ -466,6 +466,9 @@ protected void onConnected() throws Exception { connected(); } + protected void onConnectionError(Exception ex) { + myclient.connecting("Error: " + ex); + } protected void onDisconnected() { disconnected(); size = -1; // reset the read size var Modified: trunk/src/net/yura/lobby/client/TcpClient.java =================================================================== --- trunk/src/net/yura/lobby/client/TcpClient.java 2022-08-02 16:54:01 UTC (rev 1022) +++ trunk/src/net/yura/lobby/client/TcpClient.java 2022-10-09 16:41:30 UTC (rev 1023) @@ -150,6 +150,8 @@ */ protected abstract void onConnected() throws Exception; + protected abstract void onConnectionError(Exception ex); + /** * Override with something meaningful */ @@ -184,12 +186,16 @@ } } catch (IOException e) { LOG.log(Level.INFO,"io exception", e); // ConnectException extends SocketException extends IOException + onConnectionError(e); } catch (UnresolvedAddressException e) { LOG.log(Level.INFO,"exception", e); + onConnectionError(e); } catch (CancelledKeyException e) { LOG.log(Level.INFO,"CancelledKeyException", e); // happens when i restart the server + onConnectionError(e); } catch (Exception e) { LOG.log(Level.WARNING,"exception", e); + onConnectionError(e); } finally { connected.set(false); onDisconnected(); // TODO this can accedently throw/clear the InterruptedException Modified: trunk/src_server/net/yura/lobby/server/GameLobby.java =================================================================== --- trunk/src_server/net/yura/lobby/server/GameLobby.java 2022-08-02 16:54:01 UTC (rev 1022) +++ trunk/src_server/net/yura/lobby/server/GameLobby.java 2022-10-09 16:41:30 UTC (rev 1023) @@ -1110,9 +1110,19 @@ game.setWhosTurn( sgame.getWhosTurn() ); game.setInGame( sgame.getAllClients().size() ); } - if (!checkIAm(session, Player.PLAYER_GOD)) { + + + + // TODO this check is not good enough as we send the object in another thread + // so setting it based on the session may affect other send operations + //User whoWeAreSendingTo = getUser(session); + //if (whoWeAreSendingTo.getReporters().containsAnyOf(game.getPlayers())) { + // //game.setMagicWord("yes"); + // return; // maybe we should not send this game at all, but what if user X just joined? we just wont update the game? so it will still have space available? + //} + //if (!checkIAm(session, Player.PLAYER_GOD)) { game.setMagicWord(game.getMagicWord() == null ? null : "yes"); - } + //} send(session, ProtoAccess.COMMAND_ADD_OR_UPDATE_GAME, game, gameId); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <yu...@us...> - 2022-08-02 16:54:02
|
Revision: 1022 http://sourceforge.net/p/lobby/code/1022 Author: yuranet Date: 2022-08-02 16:54:01 +0000 (Tue, 02 Aug 2022) Log Message: ----------- we want to still work even if we cant encrypt Modified Paths: -------------- trunk/src/net/yura/lobby/client/LobbyCom.java Modified: trunk/src/net/yura/lobby/client/LobbyCom.java =================================================================== --- trunk/src/net/yura/lobby/client/LobbyCom.java 2022-07-29 08:58:34 UTC (rev 1021) +++ trunk/src/net/yura/lobby/client/LobbyCom.java 2022-08-02 16:54:01 UTC (rev 1022) @@ -243,7 +243,7 @@ return encrypt.doFinal(bytes); } catch (Exception ex) { - throw new RuntimeException("unable to encrypt " + value, ex); + logger.log(Level.WARNING, "unable to encrypt " + value, ex); } } return value; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <yu...@us...> - 2022-07-29 08:58:36
|
Revision: 1021 http://sourceforge.net/p/lobby/code/1021 Author: yuranet Date: 2022-07-29 08:58:34 +0000 (Fri, 29 Jul 2022) Log Message: ----------- better DB alert errors Modified Paths: -------------- trunk/src_server/net/yura/lobby/database/impl/JPADatabase.java Modified: trunk/src_server/net/yura/lobby/database/impl/JPADatabase.java =================================================================== --- trunk/src_server/net/yura/lobby/database/impl/JPADatabase.java 2022-07-05 21:35:45 UTC (rev 1020) +++ trunk/src_server/net/yura/lobby/database/impl/JPADatabase.java 2022-07-29 08:58:34 UTC (rev 1021) @@ -104,7 +104,7 @@ } catch (Throwable ex) { logger.log(Level.WARNING, "endTransaction rollback error " + in, ex); - error(String.valueOf(ex)); + error("rollback error: " + ex); success = false; } @@ -113,7 +113,7 @@ } catch (Throwable ex) { logger.log(Level.WARNING, "endTransaction close error " + in, ex); - error(String.valueOf(ex)); + error("close error: " + ex); success = false; } @@ -123,7 +123,7 @@ } catch (Throwable ex) { logger.log(Level.WARNING, "endTransaction error " + in, ex); - error(String.valueOf(ex)); + error("remove error: " + ex); success = false; } @@ -303,7 +303,7 @@ return in.em.find(type, id); } catch (RuntimeException ex) { - error(String.valueOf(ex)); + error("find error: " + ex); throw ex; } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <yu...@us...> - 2022-07-05 21:35:47
|
Revision: 1020 http://sourceforge.net/p/lobby/code/1020 Author: yuranet Date: 2022-07-05 21:35:45 +0000 (Tue, 05 Jul 2022) Log Message: ----------- return true if push worked Modified Paths: -------------- trunk/src_server/net/yura/lobby/database/impl/JPADatabase.java trunk/src_server/net/yura/lobby/server/GameLobby.java trunk/src_server/net/yura/lobby/server/LobbyServerMXBean.java trunk/src_server/net/yura/lobby/service/PushNotifications.java Modified: trunk/src_server/net/yura/lobby/database/impl/JPADatabase.java =================================================================== --- trunk/src_server/net/yura/lobby/database/impl/JPADatabase.java 2022-06-19 16:21:10 UTC (rev 1019) +++ trunk/src_server/net/yura/lobby/database/impl/JPADatabase.java 2022-07-05 21:35:45 UTC (rev 1020) @@ -65,6 +65,10 @@ } } + /** + * we can NOT nest transactions, if we wanted to add that functionality we may want to use: + * @see java.sql.Savepoint + */ @Override public void startTransaction() { // if we have come here then we are guaranteed to get the endTransaction call Modified: trunk/src_server/net/yura/lobby/server/GameLobby.java =================================================================== --- trunk/src_server/net/yura/lobby/server/GameLobby.java 2022-06-19 16:21:10 UTC (rev 1019) +++ trunk/src_server/net/yura/lobby/server/GameLobby.java 2022-07-05 21:35:45 UTC (rev 1020) @@ -1666,8 +1666,8 @@ } @Override - public void pushSend(String username, String msg) { - PushNotifications.pushSend(database, username, msg); + public boolean pushSend(String username, String msg) { + return PushNotifications.pushSend(database, username, msg); } /** Modified: trunk/src_server/net/yura/lobby/server/LobbyServerMXBean.java =================================================================== --- trunk/src_server/net/yura/lobby/server/LobbyServerMXBean.java 2022-06-19 16:21:10 UTC (rev 1019) +++ trunk/src_server/net/yura/lobby/server/LobbyServerMXBean.java 2022-07-05 21:35:45 UTC (rev 1020) @@ -46,7 +46,7 @@ //void joinGame(int gameId, String username, String magicWord); void leaveGame(int gameId, String username); - void pushSend(String username, String message); + boolean pushSend(String username, String message); void sendSystemMessage(String message); void sendChatRoomMessage(int gameId, String message); Modified: trunk/src_server/net/yura/lobby/service/PushNotifications.java =================================================================== --- trunk/src_server/net/yura/lobby/service/PushNotifications.java 2022-06-19 16:21:10 UTC (rev 1019) +++ trunk/src_server/net/yura/lobby/service/PushNotifications.java 2022-07-05 21:35:45 UTC (rev 1020) @@ -14,11 +14,11 @@ */ public class PushNotifications { - public static void pushSend(Database database, String username, String message) { - PushNotifications.pushSend(database, username, Collections.singletonMap(PushLobbyClient.MESSAGE, message), LobbyLogger.NO_GAME_ID); + public static boolean pushSend(Database database, String username, String message) { + return PushNotifications.pushSend(database, username, Collections.singletonMap(PushLobbyClient.MESSAGE, message), LobbyLogger.NO_GAME_ID); } - public static void pushSend(Database database, String username, Map<String, String> data, int correlationId) { + public static boolean pushSend(Database database, String username, Map<String, String> data, int correlationId) { try { database.startTransaction(); @@ -33,9 +33,11 @@ String appleToken = registrationToken.substring(ApplePushNotificationService.TOKEN_PREFIX.length()); ApplePushNotificationService.send(appleToken, data, correlationId); + return true; } else { GoogleFCM.send(registrationToken, data, correlationId); + return true; } } else { @@ -48,5 +50,6 @@ finally { database.endTransaction(); } + return false; } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <yu...@us...> - 2022-06-19 16:21:12
|
Revision: 1019 http://sourceforge.net/p/lobby/code/1019 Author: yuranet Date: 2022-06-19 16:21:10 +0000 (Sun, 19 Jun 2022) Log Message: ----------- auto clear old games Modified Paths: -------------- trunk/src_server/net/yura/lobby/database/GameRoom.java trunk/src_server/net/yura/lobby/server/GameLobby.java trunk/src_server/net/yura/lobby/server/LobbyServerMXBean.java Modified: trunk/src_server/net/yura/lobby/database/GameRoom.java =================================================================== --- trunk/src_server/net/yura/lobby/database/GameRoom.java 2022-06-04 12:23:29 UTC (rev 1018) +++ trunk/src_server/net/yura/lobby/database/GameRoom.java 2022-06-19 16:21:10 UTC (rev 1019) @@ -1,6 +1,7 @@ package net.yura.lobby.database; import java.util.Collection; +import java.util.Date; import java.util.Set; import javax.persistence.Column; import javax.persistence.Entity; @@ -13,6 +14,8 @@ import javax.persistence.ManyToMany; import javax.persistence.ManyToOne; import javax.persistence.Table; +import javax.persistence.Temporal; +import javax.persistence.TemporalType; import javax.persistence.Transient; import javax.persistence.UniqueConstraint; import javax.persistence.Version; @@ -25,6 +28,7 @@ @Table(name="games") public class GameRoom implements Comparable<GameRoom> { + private Date createdTime; private GameTypeRoom gameTypeRoom; private final Game game; private byte[] gameData; @@ -57,6 +61,7 @@ //if (game.getWhosTurn() != null) { // throw new IllegalArgumentException("current player already set " + game.getWhosTurn()); //} + createdTime = new Date(); } @Id @@ -87,6 +92,20 @@ } /** + * we use DATETIME because we want bigger range and no timezone + * TIMESTAMP is here to tell Datanucleus we want to store time AND date info + */ + @Column(name = "created_time", columnDefinition="DATETIME") + @Temporal(TemporalType.TIMESTAMP) + public Date getCreatedTime() { + return createdTime; + } + + public void setCreatedTime(Date createdTime) { + this.createdTime = createdTime; + } + + /** * current longest game options is 164 for long map name */ @Column(name="options", nullable=false, length=200) Modified: trunk/src_server/net/yura/lobby/server/GameLobby.java =================================================================== --- trunk/src_server/net/yura/lobby/server/GameLobby.java 2022-06-04 12:23:29 UTC (rev 1018) +++ trunk/src_server/net/yura/lobby/server/GameLobby.java 2022-06-19 16:21:10 UTC (rev 1019) @@ -4,6 +4,8 @@ import java.io.PrintWriter; import java.io.StringWriter; import java.lang.management.ManagementFactory; +import java.time.Instant; +import java.time.temporal.ChronoUnit; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; @@ -115,6 +117,9 @@ if (!success) { Alert.sendAlert("DB", "save fail", database); } + + // clean up old private games + removeVeryOldNonStartedPrivateGames(); } }, 1, 1, TimeUnit.DAYS); } @@ -1611,8 +1616,31 @@ } return badGames.size(); } + + @Override + public int removeVeryOldNonStartedPrivateGames() { + Date longTimeAgo = Date.from(Instant.now().minus(30, ChronoUnit.DAYS)); + + Collection<Integer> badGames = new ArrayList(); + try { + database.startTransaction(); + Collection<GameRoom> games = database.getGameRooms(); + for (GameRoom game : games) { + if (game.getMagicWord() != null && game.getNumOfPlayers() < game.getMaxPlayers() && game.getCreatedTime() != null && game.getCreatedTime().before(longTimeAgo)) { + badGames.add(game.getId()); + } + } + } + finally { + database.endTransaction(); + } + + for (int id : badGames) { + removeGame(id); + } + return badGames.size(); + } - public void assertAmMod(LobbySession session) { if (!checkIAm(session, Player.PLAYER_MODERATOR)) { throw new SecurityException("what do you think you are doing!"); Modified: trunk/src_server/net/yura/lobby/server/LobbyServerMXBean.java =================================================================== --- trunk/src_server/net/yura/lobby/server/LobbyServerMXBean.java 2022-06-04 12:23:29 UTC (rev 1018) +++ trunk/src_server/net/yura/lobby/server/LobbyServerMXBean.java 2022-06-19 16:21:10 UTC (rev 1019) @@ -58,6 +58,8 @@ void kickUser(String username); void resignFromAllGames(String username); void setUserType(String username, int type); + + int removeVeryOldNonStartedPrivateGames(); // Hacks for removing broken games, should not be needed. int removeCurrentPlayerNotInGameGames(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <yu...@us...> - 2022-06-04 12:23:31
|
Revision: 1018 http://sourceforge.net/p/lobby/code/1018 Author: yuranet Date: 2022-06-04 12:23:29 +0000 (Sat, 04 Jun 2022) Log Message: ----------- alert system update Modified Paths: -------------- trunk/lib/Grasshopper.jar trunk/src_server/net/yura/lobby/service/Alert.java Modified: trunk/lib/Grasshopper.jar =================================================================== (Binary files differ) Modified: trunk/src_server/net/yura/lobby/service/Alert.java =================================================================== --- trunk/src_server/net/yura/lobby/service/Alert.java 2022-05-14 14:05:50 UTC (rev 1017) +++ trunk/src_server/net/yura/lobby/service/Alert.java 2022-06-04 12:23:29 UTC (rev 1018) @@ -40,7 +40,8 @@ } if (db != null && PUSH_ALERT_ACCOUNT != null) { - PushNotifications.pushSend(db, PUSH_ALERT_ACCOUNT, type + " " + text); + // TODO only 4 lines are displayed untill you open the notification + PushNotifications.pushSend(db, PUSH_ALERT_ACCOUNT, type + " - " + text); } }); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <yu...@us...> - 2022-05-14 14:05:53
|
Revision: 1017 http://sourceforge.net/p/lobby/code/1017 Author: yuranet Date: 2022-05-14 14:05:50 +0000 (Sat, 14 May 2022) Log Message: ----------- code cleanup Modified Paths: -------------- trunk/src_server/net/yura/lobby/server/GameLobby.java trunk/src_server/net/yura/lobby/service/ProfileServer.java Modified: trunk/src_server/net/yura/lobby/server/GameLobby.java =================================================================== --- trunk/src_server/net/yura/lobby/server/GameLobby.java 2022-05-14 13:42:44 UTC (rev 1016) +++ trunk/src_server/net/yura/lobby/server/GameLobby.java 2022-05-14 14:05:50 UTC (rev 1017) @@ -39,9 +39,7 @@ import net.yura.lobby.model.Message; import net.yura.lobby.model.Player; import net.yura.lobby.service.Alert; -import net.yura.lobby.service.ApplePushNotificationService; import net.yura.lobby.service.ProfileServer; -import net.yura.lobby.service.GoogleFCM; import net.yura.lobby.service.PushNotifications; /** @@ -65,6 +63,7 @@ return JMX.newMBeanProxy(ManagementFactory.getPlatformMBeanServer(), OBJECT_NAME, LobbyServerMXBean.class); } + final SocketServer server; final Database database; // this is loaded at the start and never changes @@ -73,13 +72,12 @@ private final ConcurrentMap<Integer,Collection<LobbySession>> gameTypeRooms = new ConcurrentHashMap(); private final Map<Integer,ServerGame> runningGames = new ConcurrentHashMap(); - private boolean doPushSend; - private boolean saveOnShutdown=true; - private String welcomeMessage,newHost; + private String welcomeMessage, newHost; private int maxGames = 5; - private boolean sendGameStats = true; - final SocketServer server; + private boolean doPushSend = false; // this starts as false, but is enabled after games are loaded from DB + private boolean saveOnShutdown = true; + private boolean sendGameStatsToProfileServer = false; public GameLobby(SocketServer sserver, Database database) { this.server = sserver; @@ -867,12 +865,12 @@ @Override public void setSendGameStats(boolean sendGameStats) { - this.sendGameStats = sendGameStats; + this.sendGameStatsToProfileServer = sendGameStats; } @Override public boolean getSendGameStats() { - return sendGameStats; + return sendGameStatsToProfileServer; } @Override @@ -1485,7 +1483,7 @@ @Override public boolean gameFinished(String winner) { - if (sendGameStats) { + if (sendGameStatsToProfileServer) { // TODO this start time can also be the time the server started up and loaded the game from the DB ProfileServer.sendGame(theGame, startTime, winner); } Modified: trunk/src_server/net/yura/lobby/service/ProfileServer.java =================================================================== --- trunk/src_server/net/yura/lobby/service/ProfileServer.java 2022-05-14 13:42:44 UTC (rev 1016) +++ trunk/src_server/net/yura/lobby/service/ProfileServer.java 2022-05-14 14:05:50 UTC (rev 1017) @@ -24,11 +24,6 @@ * @deprecated */ public class ProfileServer { - - /** - * @see net.yura.lobby.server.GameLobby#sendGameStats - */ - private static final boolean ENABLED = false; private static final String URL = "https://domination.blo.re/v1/stats"; private static final String api_token = "LOBBY_TEST_API_TOKEN"; @@ -36,11 +31,11 @@ private static final SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); public static void sendGame(Game game, Date startTime, String winner) { - - if (!ENABLED) { - return; + + if (true) { + return; // DISABLED! this server does not exist any more } - + JSONGameAccess json = new JSONGameAccess() { @Override protected void saveObject(JSONWriter serializer, Object object) throws IOException { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <yu...@us...> - 2022-05-14 13:42:47
|
Revision: 1016 http://sourceforge.net/p/lobby/code/1016 Author: yuranet Date: 2022-05-14 13:42:44 +0000 (Sat, 14 May 2022) Log Message: ----------- use push alert as well as email Modified Paths: -------------- trunk/src_server/net/yura/lobby/database/impl/JPADatabase.java trunk/src_server/net/yura/lobby/server/GameLobby.java trunk/src_server/net/yura/lobby/server/LobbyController.java trunk/src_server/net/yura/lobby/server/LobbyServerMXBean.java trunk/src_server/net/yura/lobby/server/TurnBasedGame.java trunk/src_server/net/yura/lobby/service/Alert.java trunk/src_server/net/yura/lobby/service/ApplePushNotificationService.java trunk/src_server/net/yura/lobby/service/GoogleFCM.java trunk/src_server/net/yura/lobby/service/SphericalLabs.java trunk/test/net/yura/lobby/service/AlertTest.java Added Paths: ----------- trunk/src_server/net/yura/lobby/service/PushNotifications.java Modified: trunk/src_server/net/yura/lobby/database/impl/JPADatabase.java =================================================================== --- trunk/src_server/net/yura/lobby/database/impl/JPADatabase.java 2022-05-12 22:32:43 UTC (rev 1015) +++ trunk/src_server/net/yura/lobby/database/impl/JPADatabase.java 2022-05-14 13:42:44 UTC (rev 1016) @@ -129,7 +129,7 @@ private void error(String message) { int count = errorCount.incrementAndGet(); if (count == 1) { - Alert.sendAlert("DB", getStatus() + " - " + message); + Alert.sendAlert("DB", getStatus() + " - " + message, this); } } Modified: trunk/src_server/net/yura/lobby/server/GameLobby.java =================================================================== --- trunk/src_server/net/yura/lobby/server/GameLobby.java 2022-05-12 22:32:43 UTC (rev 1015) +++ trunk/src_server/net/yura/lobby/server/GameLobby.java 2022-05-14 13:42:44 UTC (rev 1016) @@ -13,6 +13,7 @@ import java.util.Iterator; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; @@ -41,6 +42,7 @@ import net.yura.lobby.service.ApplePushNotificationService; import net.yura.lobby.service.ProfileServer; import net.yura.lobby.service.GoogleFCM; +import net.yura.lobby.service.PushNotifications; /** * @author Yura Mamyrin @@ -113,7 +115,7 @@ boolean success = saveToDB(); if (!success) { - Alert.sendAlert("DB", "save fail"); + Alert.sendAlert("DB", "save fail", database); } } }, 1, 1, TimeUnit.DAYS); @@ -473,7 +475,7 @@ User user = getUser(session); // if there is something to change. - if (!LobbyController.equals(pushSystemToken, user.getPushToken())) { + if (!Objects.equals(pushSystemToken, user.getPushToken())) { User gcmUser = pushSystemToken == null ? null : database.getUserByPushToken(pushSystemToken); if (gcmUser != null && user.getType() == Player.PLAYER_GUEST && user.getGames().isEmpty() && session.playingOrWatchingGame.isEmpty()) { // the user has not started using there new account @@ -797,66 +799,6 @@ } @Override - public void pushSend(String username, String msg) { - pushSend(username, msg, null, null); - } - - public void pushSend(String username, Game game) { - int gameId = game.getId(); - LobbyLogger.log(gameId, Level.INFO, "PushSend " + doPushSend + " to " + username + " " + game); - if (doPushSend) { - pushSend(username, "It is your go: " + game.getName(), gameId, game.getOptions()); - } - } - - public void pushSend(String username, String msg, Integer gameId, String options) { - - int gameIdForLog = gameId == null ? LobbyLogger.NO_GAME_ID : gameId; - Map<String, String> data = null; - - try { - database.startTransaction(); - User user = database.getUserByUsername(username); - if (user == null) { - throw new IllegalStateException("can not find user " + username); - } - String registrationToken = user.getPushToken(); - - if (registrationToken != null) { - - data = new HashMap(); - if (msg != null) { - data.put(PushLobbyClient.MESSAGE, msg); - } - if (gameId != null) { - data.put(PushLobbyClient.GAME_ID, String.valueOf(gameId)); - } - if (options != null) { - data.put(PushLobbyClient.OPTIONS, options); - } - - if (registrationToken.startsWith(ApplePushNotificationService.TOKEN_PREFIX)) { - - String token = registrationToken.substring(ApplePushNotificationService.TOKEN_PREFIX.length()); - ApplePushNotificationService.send(username, token, data, gameIdForLog); - } - else { - GoogleFCM.send(username, registrationToken, data, gameIdForLog); - } - } - else { - LobbyLogger.log(gameIdForLog, Level.INFO, "no push token for user " + username); - } - } - catch (Exception ex) { - LobbyLogger.log(gameIdForLog, Level.WARNING, "Push error sending to: " + username + " data: " + data, ex); - } - finally { - database.endTransaction(); - } - } - - @Override public void sendChatRoomMessage(int game_id, String message) { sendPublicChatMessage(game_id, null, message); } @@ -1186,12 +1128,12 @@ game = getGame(gameId); canJoinGame(game.getGame(), session); - + // checks to know if the player has permission to join if (game.getMagicWord() != null && magicWord == null) { throw new IllegalArgumentException("Private game, Please update your game."); } - if (!LobbyController.equals(game.getMagicWord(), magicWord)) { + if (!Objects.equals(game.getMagicWord(), magicWord)) { throw new IllegalArgumentException("You didn't say the Magic Word!"); } @@ -1232,7 +1174,7 @@ catch (RuntimeException ex) { StringWriter sw = new StringWriter(); ex.printStackTrace(new PrintWriter(sw)); - Alert.sendAlert("StartGameError", sw.toString()); + Alert.sendAlert("StartGameError", sw.toString(), database); //leaveGame(gameId, username); // there may be other players, we dont want to leave them there removeGame(gameId); @@ -1683,11 +1625,35 @@ return session.getPlayerType() >= playerType; } + public void pushSend(String username, Game game) { + int gameId = game.getId(); + LobbyLogger.log(gameId, Level.INFO, "PushSend " + doPushSend + " to " + username + " " + game); + if (doPushSend) { + + Map<String, String> data = new HashMap(3); + data.put(PushLobbyClient.MESSAGE, "It is your go: " + game.getName()); + data.put(PushLobbyClient.GAME_ID, String.valueOf(gameId)); + data.put(PushLobbyClient.OPTIONS, game.getOptions()); + + PushNotifications.pushSend(database, username, data, gameId); + } + } + + @Override + public void pushSend(String username, String msg) { + PushNotifications.pushSend(database, username, msg); + } + /** - * to test that alerts are actually working from the main server + * to test that alerts are actually working from JMX */ @Override - public void sendAlert(String subject, String message) { - Alert.sendAlert(subject, message); + public void sendAlert(String message) { + try { + Alert.sendAlert("Test", message, database).get(); + } + catch (Exception ex) { + throw new RuntimeException("alert test failed", ex); + } } } Modified: trunk/src_server/net/yura/lobby/server/LobbyController.java =================================================================== --- trunk/src_server/net/yura/lobby/server/LobbyController.java 2022-05-12 22:32:43 UTC (rev 1015) +++ trunk/src_server/net/yura/lobby/server/LobbyController.java 2022-05-14 13:42:44 UTC (rev 1016) @@ -12,10 +12,8 @@ import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; -import java.util.HashSet; import java.util.List; import java.util.Map; -import java.util.Set; import java.util.logging.Level; import javax.crypto.Cipher; import net.yura.lobby.client.ProtoAccess; @@ -392,7 +390,7 @@ Alert.sendAlert("flagged " + user.getId(), "reporter=" + session.getUsername() + " (" + reporter.getId() +") <" + reporter.getEmail() + ">\n" + " gameId=" + gameId + " message=" + text + "\n" + - " flagged=" + username + " (" + user.getId() + ") <" + user.getEmail() + ">"); + " flagged=" + username + " (" + user.getId() + ") <" + user.getEmail() + ">", lobby.database); } // ############################################################################################# ADMIN else if (ProtoLobby.REQUEST_DEL_GAME.equals(command)) { @@ -469,7 +467,7 @@ @Override public Object getObjectId(Object object) { if (object instanceof GameType) { - return new Integer( ((GameType)object).getId() ); + return Integer.valueOf(((GameType)object).getId()); } throw new IllegalArgumentException("what is this object? "+object ); } @@ -552,12 +550,4 @@ e.printStackTrace(); } } - - /** - * added in java7, we need to move to newer datanucleus to switch to java7 - * @see java.util.Objects#equals(java.lang.Object, java.lang.Object) - */ - public static boolean equals(Object a, Object b) { - return (a == b) || (a != null && a.equals(b)); - } } Modified: trunk/src_server/net/yura/lobby/server/LobbyServerMXBean.java =================================================================== --- trunk/src_server/net/yura/lobby/server/LobbyServerMXBean.java 2022-05-12 22:32:43 UTC (rev 1015) +++ trunk/src_server/net/yura/lobby/server/LobbyServerMXBean.java 2022-05-14 13:42:44 UTC (rev 1016) @@ -63,5 +63,5 @@ int removeCurrentPlayerNotInGameGames(); int removeRunningGameNotFoundGames(); - void sendAlert(String subject, String message); + void sendAlert(String message); } Modified: trunk/src_server/net/yura/lobby/server/TurnBasedGame.java =================================================================== --- trunk/src_server/net/yura/lobby/server/TurnBasedGame.java 2022-05-12 22:32:43 UTC (rev 1015) +++ trunk/src_server/net/yura/lobby/server/TurnBasedGame.java 2022-05-14 13:42:44 UTC (rev 1016) @@ -24,6 +24,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.concurrent.ConcurrentSkipListSet; import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; @@ -131,7 +132,7 @@ }, timeout + 10, TimeUnit.SECONDS); // add 10 seconds for bad ping } - if (!LobbyController.equals(oldPlayer, whoiwantinputfrom)) { + if (!Objects.equals(oldPlayer, whoiwantinputfrom)) { // the first time we need input from a user we know the game has finished setup // is now started/ready to be opened Modified: trunk/src_server/net/yura/lobby/service/Alert.java =================================================================== --- trunk/src_server/net/yura/lobby/service/Alert.java 2022-05-12 22:32:43 UTC (rev 1015) +++ trunk/src_server/net/yura/lobby/service/Alert.java 2022-05-14 13:42:44 UTC (rev 1016) @@ -7,9 +7,12 @@ import java.util.concurrent.Future; import java.util.logging.Level; import net.yura.grasshopper.BugSubmitter; +import net.yura.lobby.database.Database; import net.yura.lobby.server.LobbyLogger; public class Alert { + + private static final String PUSH_ALERT_ACCOUNT = null; /** * we use a ExecutorService as if the alert server is down, the doPost can get stuck for a while @@ -17,26 +20,28 @@ */ static ExecutorService executor = Executors.newSingleThreadExecutor(); - public static Future<?> sendAlert(String type, String text) { + public static Future<?> sendAlert(String type, String text, Database db) { - return executor.submit(new Runnable() { - @Override - public void run() { - try { - LobbyLogger.logger.info("sending alert " + type + " " + text); - - Map<String, String> map = new HashMap(); - map.put("recipient", "yu...@yu..."); - map.put("subject", "Lobby Alert - " + type); - map.put("email", "yu...@lo..."); - map.put("text", String.valueOf(text)); - map.put("env_report", "REMOTE_HOST,HTTP_USER_AGENT"); - BugSubmitter.doPost(BugSubmitter.FORM_MAIL_URL, map); - } - catch (Exception ex) { - LobbyLogger.logger.log(Level.WARNING, "failed to send alert " + text, ex); - } + return executor.submit(() -> { + // email alert does not require DB, less things can go wrong, send this first + try { + LobbyLogger.logger.info("sending alert " + type + " " + text); + + Map<String, String> map = new HashMap(); + map.put("recipient", "yu...@yu..."); + map.put("subject", "Lobby Alert - " + type); + map.put("email", "yu...@lo..."); + map.put("text", String.valueOf(text)); + map.put("env_report", "REMOTE_HOST,HTTP_USER_AGENT"); + BugSubmitter.doPost(BugSubmitter.FORM_MAIL_URL, map); } + catch (Exception ex) { + LobbyLogger.logger.log(Level.WARNING, "failed to send alert " + text, ex); + } + + if (db != null && PUSH_ALERT_ACCOUNT != null) { + PushNotifications.pushSend(db, PUSH_ALERT_ACCOUNT, type + " " + text); + } }); } } Modified: trunk/src_server/net/yura/lobby/service/ApplePushNotificationService.java =================================================================== --- trunk/src_server/net/yura/lobby/service/ApplePushNotificationService.java 2022-05-12 22:32:43 UTC (rev 1015) +++ trunk/src_server/net/yura/lobby/service/ApplePushNotificationService.java 2022-05-14 13:42:44 UTC (rev 1016) @@ -72,7 +72,7 @@ final CompletableFuture<Void> closeFuture2 = developmentApnsClient.close(); } - public static void send(String username, String token, Map<String, String> data, int correlationId) throws Exception { + public static void send(String token, Map<String, String> data, int correlationId) throws Exception { ApnsClient apnsClient; if (token.startsWith(SANDBOX_PREFIX)) { @@ -100,23 +100,15 @@ SimpleApnsPushNotification pushNotification = new SimpleApnsPushNotification(token, TOPIC, payload); PushNotificationFuture<SimpleApnsPushNotification, PushNotificationResponse<SimpleApnsPushNotification>> sendNotificationFuture = apnsClient.sendNotification(pushNotification); - - try { - PushNotificationResponse<SimpleApnsPushNotification> pushNotificationResponse = sendNotificationFuture.get(); - if (pushNotificationResponse.isAccepted()) { - LobbyLogger.log(correlationId, Level.INFO, "Push notification to " + username + " accepted by APNs gateway."); - } - else { - LobbyLogger.log(correlationId, Level.WARNING, "Notification to " + username + " rejected by the APNs gateway: " + pushNotificationResponse.getRejectionReason()); + PushNotificationResponse<SimpleApnsPushNotification> pushNotificationResponse = sendNotificationFuture.get(); - pushNotificationResponse.getTokenInvalidationTimestamp().ifPresent(timestamp -> { - LobbyLogger.log(correlationId, Level.WARNING, "\t…and the token is invalid as of " + timestamp); - }); - } + if (pushNotificationResponse.isAccepted()) { + LobbyLogger.log(correlationId, Level.INFO, "Push notification to " + token + " accepted by APNs gateway."); } - catch (ExecutionException e) { - LobbyLogger.log(correlationId, Level.WARNING, "Failed to send push notification to " + username, e); + else { + throw new Exception("Notification rejected by the APNs gateway: " + pushNotificationResponse.getRejectionReason() + + "\t…and the token is invalid as of " + pushNotificationResponse.getTokenInvalidationTimestamp()); } } } Modified: trunk/src_server/net/yura/lobby/service/GoogleFCM.java =================================================================== --- trunk/src_server/net/yura/lobby/service/GoogleFCM.java 2022-05-12 22:32:43 UTC (rev 1015) +++ trunk/src_server/net/yura/lobby/service/GoogleFCM.java 2022-05-14 13:42:44 UTC (rev 1016) @@ -29,7 +29,7 @@ } } - public static void send(String username, String registrationToken, Map<String, String> data, int gameIdForLog) { + public static void send(String registrationToken, Map<String, String> data, int gameIdForLog) throws Exception { try { Message message = Message.builder() .putAllData(data) @@ -39,10 +39,10 @@ String messageId = FirebaseMessaging.getInstance().send(message); // Response is a message ID string. - LobbyLogger.log(gameIdForLog, Level.INFO, "FCM Successfully sent to: " + username + " messageId: " + messageId); + LobbyLogger.log(gameIdForLog, Level.INFO, "FCM Successfully sent to: " + registrationToken + " messageId: " + messageId); } catch (FirebaseMessagingException ex) { - LobbyLogger.log(gameIdForLog, Level.WARNING, "FCM fail sending to: " + username + " error: " + ex.getErrorCode(), ex); + throw new Exception("FCM fail sending to: " + registrationToken + " error: " + ex.getErrorCode(), ex); } } } Added: trunk/src_server/net/yura/lobby/service/PushNotifications.java =================================================================== --- trunk/src_server/net/yura/lobby/service/PushNotifications.java (rev 0) +++ trunk/src_server/net/yura/lobby/service/PushNotifications.java 2022-05-14 13:42:44 UTC (rev 1016) @@ -0,0 +1,52 @@ +package net.yura.lobby.service; + +import java.util.Collections; +import java.util.Map; +import java.util.logging.Level; +import net.yura.lobby.client.PushLobbyClient; +import net.yura.lobby.database.Database; +import net.yura.lobby.database.User; +import net.yura.lobby.server.LobbyLogger; + +/** + * This class handles sending push notifications to all systems + * token lookup from DB, all push related errors + */ +public class PushNotifications { + + public static void pushSend(Database database, String username, String message) { + PushNotifications.pushSend(database, username, Collections.singletonMap(PushLobbyClient.MESSAGE, message), LobbyLogger.NO_GAME_ID); + } + + public static void pushSend(Database database, String username, Map<String, String> data, int correlationId) { + + try { + database.startTransaction(); + User user = database.getUserByUsername(username); + if (user == null) { + throw new IllegalStateException("can not find user " + username); + } + String registrationToken = user.getPushToken(); + + if (registrationToken != null) { + if (registrationToken.startsWith(ApplePushNotificationService.TOKEN_PREFIX)) { + + String appleToken = registrationToken.substring(ApplePushNotificationService.TOKEN_PREFIX.length()); + ApplePushNotificationService.send(appleToken, data, correlationId); + } + else { + GoogleFCM.send(registrationToken, data, correlationId); + } + } + else { + LobbyLogger.log(correlationId, Level.INFO, "no push token for user " + username); + } + } + catch (Throwable ex) { + LobbyLogger.log(correlationId, Level.WARNING, "Push error sending to: " + username + " data: " + data, ex); + } + finally { + database.endTransaction(); + } + } +} Modified: trunk/src_server/net/yura/lobby/service/SphericalLabs.java =================================================================== --- trunk/src_server/net/yura/lobby/service/SphericalLabs.java 2022-05-12 22:32:43 UTC (rev 1015) +++ trunk/src_server/net/yura/lobby/service/SphericalLabs.java 2022-05-14 13:42:44 UTC (rev 1016) @@ -92,7 +92,7 @@ // something has gone very wrong with the server, give up enabled = false; - Alert.sendAlert("SphericalLabs", "rejectedExecution! queueSize=" + getQueueSize() + " poolSize=" + getActiveThreadPoolSize() + " hitsPerSecond=" + getHitsPerSecond() + " lastError=" + lastError); + Alert.sendAlert("SphericalLabs", "rejectedExecution! queueSize=" + getQueueSize() + " poolSize=" + getActiveThreadPoolSize() + " hitsPerSecond=" + getHitsPerSecond() + " lastError=" + lastError, null); } @Override Modified: trunk/test/net/yura/lobby/service/AlertTest.java =================================================================== --- trunk/test/net/yura/lobby/service/AlertTest.java 2022-05-12 22:32:43 UTC (rev 1015) +++ trunk/test/net/yura/lobby/service/AlertTest.java 2022-05-14 13:42:44 UTC (rev 1016) @@ -3,8 +3,9 @@ import org.junit.Test; public class AlertTest { + @Test - public void testSend() { - Alert.sendAlert("test", "junit test alert"); + public void testSend() throws Exception { + Alert.sendAlert("test", "junit test alert", null).get(); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <yu...@us...> - 2022-05-12 22:32:45
|
Revision: 1015 http://sourceforge.net/p/lobby/code/1015 Author: yuranet Date: 2022-05-12 22:32:43 +0000 (Thu, 12 May 2022) Log Message: ----------- allow version check to be specific to game Modified Paths: -------------- trunk/nbproject/project.properties trunk/src/net/yura/lobby/util/ByteInputStream.java trunk/src_blackjack/net/yura/blackjack/server/BlackJack.java trunk/src_server/net/yura/lobby/server/GameLobby.java trunk/src_server/net/yura/lobby/server/LobbyController.java trunk/src_server/net/yura/lobby/server/LobbyLogger.java trunk/src_server/net/yura/lobby/server/LobbyServerMXBean.java trunk/src_server/net/yura/lobby/server/ServerGame.java trunk/src_server/net/yura/lobby/server/TurnBasedGame.java trunk/src_server/net/yura/lobby/service/Alert.java trunk/test/net/yura/lobby/model/GameTest.java trunk/test/net/yura/lobby/server/ServerTest.java trunk/test/net/yura/lobby/util/ByteInputStreamTest.java trunk/test/net/yura/lobby/util/LobbyConnection.java trunk/test/net/yura/util/CallCounterTest.java Modified: trunk/nbproject/project.properties =================================================================== --- trunk/nbproject/project.properties 2022-02-06 19:16:57 UTC (rev 1014) +++ trunk/nbproject/project.properties 2022-05-12 22:32:43 UTC (rev 1015) @@ -26,6 +26,7 @@ javadoc.splitindex=true jlink.launcher=false jlink.launcher.name=Lobby +run.jvmargs=-javaagent:lib/datanucleus-core-5.0.2.jar=-api=JPA,net.yura.lobby.database run.modulepath=\ ${javac.modulepath} run.test.modulepath=\ Modified: trunk/src/net/yura/lobby/util/ByteInputStream.java =================================================================== --- trunk/src/net/yura/lobby/util/ByteInputStream.java 2022-02-06 19:16:57 UTC (rev 1014) +++ trunk/src/net/yura/lobby/util/ByteInputStream.java 2022-05-12 22:32:43 UTC (rev 1015) @@ -109,5 +109,4 @@ return count - pos; // ByteArrayInputStream } - } Modified: trunk/src_blackjack/net/yura/blackjack/server/BlackJack.java =================================================================== --- trunk/src_blackjack/net/yura/blackjack/server/BlackJack.java 2022-02-06 19:16:57 UTC (rev 1014) +++ trunk/src_blackjack/net/yura/blackjack/server/BlackJack.java 2022-05-12 22:32:43 UTC (rev 1015) @@ -14,7 +14,6 @@ when we get a 21 after a split, if we split aces we should not get blackjack, but if we split 10s we should */ - public class BlackJack extends TurnBasedGame implements Runnable { private static final int STATE_PLACE_BET=0; @@ -44,6 +43,18 @@ public BlackJack() { } + @Override + public boolean isSupportedClient(LobbySession session) { + String appNameVersion = session.getClientVersion(); + int space = appNameVersion.indexOf(' '); + String appName = appNameVersion.substring(0, space); + String appVersion = appNameVersion.substring(space + 1, appNameVersion.length()); + + int version = Integer.parseInt(appVersion); + + return version > 0; + } + public void createNewGame(String startGameOptions, String[] playersArray) { String[] options = split(startGameOptions,' '); @@ -63,16 +74,13 @@ for (int c=0;c<playersArray.length;c++) { players.addElement( new BJPlayer(playersArray[c],multiplayer?new Chips(chips.getChips()):chips) ); - } for (int c=0;c<numbots;c++) { players.addElement( new BJPlayer("BJBot"+c,multiplayer?new Chips(chips.getChips()):chips) ); - } currentplayer = null; - } @Override @@ -89,7 +97,8 @@ * options in this form: "10 0 1 0 0" */ @Override - public void startGame(String startGameOptions, String[] players) { + public void startGame(String[] players) { + String startGameOptions = this.startGameOptions; String[] parts = startGameOptions.split("\\ "); int availableDecks = Integer.parseInt(parts[0]); // 1 to 10 @@ -111,7 +120,6 @@ // TODO gameFinished("TODO"); - } @Override @@ -211,7 +219,6 @@ BJPlayer player = (BJPlayer)players.elementAt(c); updateClientString(player.getName(), player.dealCard() ); - } // card for dealer @@ -226,7 +233,6 @@ // ask them if they want insurance newStateAndInputNeeded(STATE_INSURANCE); - } if ( dealer.checkForBlackJack() ) { @@ -242,7 +248,6 @@ if (z!=0) { updateWinnings( "insurance",z ); } currentplayer.finalPayOut(21); - } // no options are given to the player, go to next round @@ -269,7 +274,6 @@ updateWinnings( "blackjack",currentplayer.payOutBlackJackCurrentHand() ); } - } @@ -277,9 +281,6 @@ // give player options newStateAndInputNeeded(STATE_HIT_STICK); - - - } if ( someonehasCardsLeft() ) { @@ -301,18 +302,13 @@ updateWinnings("result",z[i]); } - } } - } catch (CardDeckEmptyException ex) { - ex.printStackTrace(); - } } - } private void updateWinnings(String type, int num) { @@ -323,16 +319,13 @@ send = send+" push"; } else if (num>0) { - send = send+" win "+num; } else { - send = send+" lose "+ (-num); } sendStringToAllClient(send); - } private void newStateAndInputNeeded(int a) { @@ -353,7 +346,6 @@ } } } - } private boolean someonehasCardsLeft() { @@ -363,9 +355,7 @@ currentplayer = (BJPlayer)players.elementAt(c); if ( currentplayer.hasHandsToPlay() ) { - return true; - } } return false; @@ -372,12 +362,10 @@ } private void printout() { - System.out.println("Round:"+round+" "+dealer); for (int c=0;c<players.size();c++) { System.out.println( ((BJPlayer)players.elementAt(c)).toString() ); } - } private void updateClientString(String username, Card c) { @@ -409,30 +397,22 @@ } else if ( STOP.equals(message) ) { - keepplaying=false; } - } else if (state == STATE_INSURANCE) { if ( YES.equals(message) ) { - currentplayer.insuranceYes(); - } else if ( NO.equals(message) ) { - currentplayer.insuranceNo(); - } } else if (state == STATE_HIT_STICK) { if ( STAND.equals(message) ) { - currentplayer.moveToNextHand(); - } else if ( DOUBLE.equals(message) ) { @@ -447,9 +427,7 @@ } } catch (CardDeckEmptyException ex) { - ex.printStackTrace(); - } } @@ -465,9 +443,7 @@ } } catch (CardDeckEmptyException ex) { - ex.printStackTrace(); - } } else if ( HIT.equals(message) ) { @@ -482,20 +458,15 @@ } catch (CardDeckEmptyException ex) { - ex.printStackTrace(); - } } } synchronized(this) { notify(); } - } else { - System.out.println("BAD!!! BAD!!! BAD!!!"); - } // else something has gone wrong } @@ -509,29 +480,21 @@ String command = "command"; if (state==STATE_PLACE_BET) { - command = command+ " "+BET+" "+STOP; - } else if (state==STATE_INSURANCE) { - command = command+" "+YES+" "+NO; - } else { - command = command+" "+STAND+" "+HIT; if (currentplayer.canDouble()) { - command = command +" "+DOUBLE; } if (currentplayer.canSplit()) { - command = command +" "+SPLIT; } - } //System.out.println(currentplayer+"\ncommand: "+command); @@ -540,11 +503,9 @@ try { synchronized(this) { wait(); } } catch (InterruptedException ex) { } - } public int getState() { - return state; } @@ -583,10 +544,9 @@ public void logGameMove(String a,String b) {} }); + bj.setOptions("1 0 0 0 0"); + bj.startGame(new String[] {"player"} ); - bj.startGame( "1 0 0 0 0", new String[] {"player"} ); - - java.io.InputStreamReader in = new java.io.InputStreamReader(System.in); java.io.BufferedReader br = new java.io.BufferedReader(in); String input; @@ -598,9 +558,7 @@ System.out.print( ((bj.getState()==STATE_PLACE_BET)?("place bet?"):( (bj.getState()==STATE_INSURANCE)?("insurance?"):("hit stand?") )) +">"); input = br.readLine(); bj.stringFromPlayer("player", input ); - } - } public static String[] split(String string,char ch) { @@ -624,15 +582,11 @@ stringList.copyInto(array); return array; - } public void renamePlayer(String oldser,String newuser) { - // TODO - - } - + } } Modified: trunk/src_server/net/yura/lobby/server/GameLobby.java =================================================================== --- trunk/src_server/net/yura/lobby/server/GameLobby.java 2022-02-06 19:16:57 UTC (rev 1014) +++ trunk/src_server/net/yura/lobby/server/GameLobby.java 2022-05-12 22:32:43 UTC (rev 1015) @@ -293,27 +293,6 @@ } } - // TODO replace this logic with a lookup from DB - private int minAndroidVersion = 61; - public int getMinAndroidVersion() { - return minAndroidVersion; - } - public void setMinAndroidVersion(int minAndroidVersion) { - this.minAndroidVersion = minAndroidVersion; - } - - void checkClientVersion(String appName, String appVersion) { - if ("AndroidDomination".equals(appName)) { - try { - int androidVersion = Integer.parseInt(appVersion); - if (androidVersion < minAndroidVersion) { - throw new RuntimeException("Game too old, please update!"); - } - } - catch (NumberFormatException ex) {} - } - } - // still used by Android <= 64 and PC/Mac <= 1.1.1.7 // TODO remove when no more of these clients left public void connected_LEGACY_DEL_ME(LobbySession session,String uuid,byte[] key) { @@ -1083,34 +1062,40 @@ /** * Called before a game is created to make sure a user has the right to join the game + * This method MUST be called from inside a transaction */ - public void canJoinGame(String username) { + public void canJoinGame(Game game, LobbySession session) { if (newHost != null) { // should never normally get here, unless its a old version of the app throw new IllegalStateException("please update your app"); } - try { - database.startTransaction(); + // client version check + ServerGame serverGame = newServerGame(game); + if (!serverGame.isSupportedClient(session)) { + throw new IllegalStateException("please update your app"); + } - User user = database.getUserByUsername(username); - if (user.getType() <= Player.PLAYER_BLOCKED) { - throw new RuntimeException(); - } - int noGames = user.getGames().size(); - if (maxGames >= 0 && noGames >= maxGames) { - throw new IllegalArgumentException(username + " in too many games: " + noGames); - } + String username = session.getUsername(); + + User user = database.getUserByUsername(username); + if (user.getType() <= Player.PLAYER_BLOCKED) { + throw new RuntimeException(); } - finally { - database.endTransaction(); + int noGames = user.getGames().size(); + if (maxGames >= 0 && noGames >= maxGames) { + throw new IllegalArgumentException(username + " in too many games: " + noGames); } } - public GameRoom createGame(Game game) { + public GameRoom createGame(Game game, LobbySession session) { try { database.startTransaction(); + // if we will not be able to join it, then we dont want to create it + // this check will happen again when we call lobby.joinGame(...) + canJoinGame(game, session); + GameRoom gameRoom = new GameRoom(game); GameTypeRoom gameTypeRoom = database.getGameType( game.getType().getId() ); gameTypeRoom.createNewGame(gameRoom); @@ -1186,14 +1171,13 @@ send(session, ProtoAccess.COMMAND_ADD_OR_UPDATE_GAME, game, gameId); } - @Override - public void joinGame(int gameId, String username, String magicWord) { - GameRoom game = joinGame(gameId, username, magicWord, null); + public void joinGame(int gameId, LobbySession session, String magicWord) { + GameRoom game = joinGame(gameId, session, magicWord, null); gameChanged(game); } - public GameRoom joinGame(int gameId, String username, String magicWord, LobbySession creator) { - + public GameRoom joinGame(int gameId, LobbySession session, String magicWord, LobbySession creator) { + String username = session.getUsername(); ServerGame serverGame = runningGames.get(gameId); GameRoom game; @@ -1200,6 +1184,8 @@ try { database.startTransaction(); game = getGame(gameId); + + canJoinGame(game.getGame(), session); // checks to know if the player has permission to join if (game.getMagicWord() != null && magicWord == null) { @@ -1214,7 +1200,7 @@ // this may throw an exception if the available slot was just wipped out serverGame.playerJoined(username); // TODO case may be wrong!! } - + User user = database.getUserByUsername(username); // as this game is already started and serverGame.playerJoined was successfull @@ -1241,7 +1227,7 @@ } try { - serverGame.startGame(game.getOptions(), playerNames); + serverGame.startGame(playerNames); } catch (RuntimeException ex) { StringWriter sw = new StringWriter(); @@ -1332,6 +1318,9 @@ if (session.getUsername() == null) { throw new IllegalStateException("session is not logged in yet"); } + if (!serverGame.isSupportedClient(session)) { + throw new IllegalStateException("Please update your app to play"); + } // this will now send the game object to the client serverGame.clientEntered( session ); @@ -1499,18 +1488,35 @@ } return count; } - - private ServerGame createServerGame(GameRoom game, final LobbySession creator) { - try { - GameType gameType = classLoaders.get( game.getGameTypeRoom().getId() ); + + private ServerGame newServerGame(Game game) { + try { + GameType gameType = classLoaders.get( game.getType().getId() ); ClassLoader loader = gameType.getClassLoader( new File(".").toURI().toASCIIString() ); ServerGame serverGame = (ServerGame) Class.forName( gameType.getClassName(), true, loader ).newInstance(); serverGame.setId(game.getId()); serverGame.setTimeout(game.getTimeout()); + serverGame.setOptions(game.getOptions()); + return serverGame; + } + catch (Exception ex) { + throw new RuntimeException(ex); + } + } + + /** + * this is called in two cases: + * 1) we are creating a new game to play + * 2) we are loading a game from the DB + */ + private ServerGame createServerGame(GameRoom game, final LobbySession creator) { + + final Game theGame = game.getGame(); + ServerGame serverGame = newServerGame(theGame); + runningGames.put(game.getId(), serverGame); final Date startTime = new Date(); - final Game theGame = game.getGame(); final ServerGame sg = serverGame; serverGame.addServerGameListener(new ServerGameListener() { @@ -1600,10 +1606,6 @@ public void logGameMove(String user, String move) { } }); return serverGame; - } - catch (Exception ex) { - throw new RuntimeException(ex); - } } public GameType getGameType(int gameTypeId) { Modified: trunk/src_server/net/yura/lobby/server/LobbyController.java =================================================================== --- trunk/src_server/net/yura/lobby/server/LobbyController.java 2022-02-06 19:16:57 UTC (rev 1014) +++ trunk/src_server/net/yura/lobby/server/LobbyController.java 2022-05-12 22:32:43 UTC (rev 1015) @@ -41,7 +41,7 @@ */ public class LobbyController implements ObjectProvider { - private static final int PROTOCOL_VERSION = 1; + private static final int PROTOCOL_MIN_VERSION = 1; public static String[] args = new String[0]; public static final String NEW_HOST_ARG = "--newHost="; @@ -104,9 +104,10 @@ String java = (String)request.get("java"); session.setClientInfo(appName + " " + appVersion, locale, java + " " + os); - lobby.checkClientVersion(appName, appVersion); + // we dont check the version here any more, the game itself will check + //lobby.checkClientVersion(appName, appVersion); - if (version.intValue() == PROTOCOL_VERSION) { + if (version.intValue() >= PROTOCOL_MIN_VERSION) { // TODO: remove old system, if we get uuid here, log them in directly String uuid = (String)request.get("uuid"); @@ -118,7 +119,7 @@ } } else { - throw new RuntimeException("version miss match, server="+PROTOCOL_VERSION+" client="+version); + throw new RuntimeException("version miss match, server=" + PROTOCOL_MIN_VERSION + " client=" + version); } } else if (ProtoAccess.REQUEST_LOGIN.equals(command)) { @@ -289,11 +290,11 @@ } if (game.getPlayers().isEmpty()) { - lobby.canJoinGame(session.getUsername()); - GameRoom gameRoom = lobby.createGame(game); + GameRoom gameRoom = lobby.createGame(game, session); gameId = gameRoom.getId(); - lobby.joinGame(gameId, session.getUsername(), game.getMagicWord()); // sends the game to all clients + lobby.joinGame(gameId, session, game.getMagicWord()); // sends the game to all clients } +/* else { // Do all checks to make sure we can create this game. Set<Player> players = game.getPlayers(); @@ -320,14 +321,14 @@ // tell everyone about the game. lobby.gameChanged(gameRoom); } +*/ } } else if (ProtoLobby.REQUEST_JOIN_GAME.equals(command)) { Map map = (Map)param; - lobby.canJoinGame(session.getUsername()); gameId = (Integer)map.get("game_id"); String magicWord = (String)map.get("magic_word"); - lobby.joinGame(gameId, session.getUsername(), magicWord); + lobby.joinGame(gameId, session, magicWord); } else if (ProtoLobby.REQUEST_LEAVE_GAME.equals(command)) { Map map = (Map)param; Modified: trunk/src_server/net/yura/lobby/server/LobbyLogger.java =================================================================== --- trunk/src_server/net/yura/lobby/server/LobbyLogger.java 2022-02-06 19:16:57 UTC (rev 1014) +++ trunk/src_server/net/yura/lobby/server/LobbyLogger.java 2022-05-12 22:32:43 UTC (rev 1015) @@ -252,10 +252,14 @@ return (LobbyHandler)handler; } } - throw new IllegalStateException(); + //throw new IllegalStateException("can not find LobbyHandler for defualt Logger " + Arrays.toString(logger.getHandlers())); + return null; // this does not exist in unit tests, but thats ok } public static void closeGameHandler(int correlationId) { - getLobbyHandler().close(correlationId); + LobbyHandler lobbyHandler = getLobbyHandler(); + if (lobbyHandler != null) { + lobbyHandler.close(correlationId); + } } } Modified: trunk/src_server/net/yura/lobby/server/LobbyServerMXBean.java =================================================================== --- trunk/src_server/net/yura/lobby/server/LobbyServerMXBean.java 2022-02-06 19:16:57 UTC (rev 1014) +++ trunk/src_server/net/yura/lobby/server/LobbyServerMXBean.java 2022-05-12 22:32:43 UTC (rev 1015) @@ -28,9 +28,6 @@ void setSendGameStats(boolean sendGameStats); boolean getSendGameStats(); - public int getMinAndroidVersion(); - public void setMinAndroidVersion(int minAndroidVersion); - // operations String getGameOptions(String gameName); @@ -46,7 +43,7 @@ int countFinishedGames(); void setNick(String oldName, String newName); - void joinGame(int gameId, String username, String magicWord); + //void joinGame(int gameId, String username, String magicWord); void leaveGame(int gameId, String username); void pushSend(String username, String message); Modified: trunk/src_server/net/yura/lobby/server/ServerGame.java =================================================================== --- trunk/src_server/net/yura/lobby/server/ServerGame.java 2022-02-06 19:16:57 UTC (rev 1014) +++ trunk/src_server/net/yura/lobby/server/ServerGame.java 2022-05-12 22:32:43 UTC (rev 1015) @@ -26,14 +26,16 @@ void setId(int id); int getId(); void setTimeout(int seconds); + void setOptions(String startGameOptions); // connections + boolean isSupportedClient(LobbySession session); void clientEntered(LobbySession player); void clientLeaves(LobbySession player); Collection<LobbySession> getAllClients(); // life cycle - void startGame(String startGameOptions, String[] players); + void startGame(String[] players); void loadGame(byte[] gameData); byte[] saveGameState(); void destroyServerGame(); Modified: trunk/src_server/net/yura/lobby/server/TurnBasedGame.java =================================================================== --- trunk/src_server/net/yura/lobby/server/TurnBasedGame.java 2022-02-06 19:16:57 UTC (rev 1014) +++ trunk/src_server/net/yura/lobby/server/TurnBasedGame.java 2022-05-12 22:32:43 UTC (rev 1015) @@ -51,16 +51,22 @@ protected boolean finished,startGameCalled; String whoiwantinputfrom; + + protected int id; + /** * in seconds */ - int timeout; + protected int timeout; + + protected String startGameOptions; + Map<String,Integer> skips = new HashMap(); // ################################### abstract methods #################################### // life cycle of a game - @Override public abstract void startGame(String startGameOptions, String[] players); + @Override public abstract void startGame(String[] players); @Override public abstract void loadGame(byte[] gameData); public abstract void destroyGame(); @@ -181,10 +187,9 @@ // ################################### implementation of ServerGame #################################### - int id; @Override public void setId(int id) { - this.id=id; + this.id = id; } @Override @@ -200,6 +205,11 @@ this.timeout = 60; // a turn based game MUST have a timeout to give players a time to take there turn } } + + @Override + public void setOptions(String startGameOptions) { + this.startGameOptions = startGameOptions; + } @Override public final void addServerGameListener(ServerGameListener l) { @@ -227,7 +237,7 @@ // we tell everyone currently in the game this person is joining listoner.sendChatroomMessage(username + " has entered the game"); - + // we add this new player as a spectator to make sure we do not miss any messages // from the game that can happen between clientHasJoined() and spectators.add() spectators.add(session); Modified: trunk/src_server/net/yura/lobby/service/Alert.java =================================================================== --- trunk/src_server/net/yura/lobby/service/Alert.java 2022-02-06 19:16:57 UTC (rev 1014) +++ trunk/src_server/net/yura/lobby/service/Alert.java 2022-05-12 22:32:43 UTC (rev 1015) @@ -2,6 +2,9 @@ import java.util.HashMap; import java.util.Map; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.Future; import java.util.logging.Level; import net.yura.grasshopper.BugSubmitter; import net.yura.lobby.server.LobbyLogger; @@ -8,20 +11,32 @@ public class Alert { - public static void sendAlert(String type, String text) { - try { - LobbyLogger.logger.info("sending alert " + type + " " + text); + /** + * we use a ExecutorService as if the alert server is down, the doPost can get stuck for a while + * and we dont want to slow the whole system down because we are trying to send an alert + */ + static ExecutorService executor = Executors.newSingleThreadExecutor(); + + public static Future<?> sendAlert(String type, String text) { - Map<String, String> map = new HashMap(); - map.put("recipient", "yu...@yu..."); - map.put("subject", "Lobby Alert - " + type); - map.put("email", "yu...@lo..."); - map.put("text", String.valueOf(text)); - map.put("env_report", "REMOTE_HOST,HTTP_USER_AGENT"); - BugSubmitter.doPost(BugSubmitter.FORM_MAIL_URL, map); - } - catch (Exception ex) { - LobbyLogger.logger.log(Level.WARNING, "failed to send alert " + text, ex); - } + return executor.submit(new Runnable() { + @Override + public void run() { + try { + LobbyLogger.logger.info("sending alert " + type + " " + text); + + Map<String, String> map = new HashMap(); + map.put("recipient", "yu...@yu..."); + map.put("subject", "Lobby Alert - " + type); + map.put("email", "yu...@lo..."); + map.put("text", String.valueOf(text)); + map.put("env_report", "REMOTE_HOST,HTTP_USER_AGENT"); + BugSubmitter.doPost(BugSubmitter.FORM_MAIL_URL, map); + } + catch (Exception ex) { + LobbyLogger.logger.log(Level.WARNING, "failed to send alert " + text, ex); + } + } + }); } } Modified: trunk/test/net/yura/lobby/model/GameTest.java =================================================================== --- trunk/test/net/yura/lobby/model/GameTest.java 2022-02-06 19:16:57 UTC (rev 1014) +++ trunk/test/net/yura/lobby/model/GameTest.java 2022-05-12 22:32:43 UTC (rev 1015) @@ -36,6 +36,11 @@ public void tearDown() { } + @Test + public void dummyTest() throws Exception { + // TODO add some model tests here + } + /** * Test of clone method, of class Game. * (this test is not used any more as clone is not used any more) Modified: trunk/test/net/yura/lobby/server/ServerTest.java =================================================================== --- trunk/test/net/yura/lobby/server/ServerTest.java 2022-02-06 19:16:57 UTC (rev 1014) +++ trunk/test/net/yura/lobby/server/ServerTest.java 2022-05-12 22:32:43 UTC (rev 1015) @@ -247,14 +247,20 @@ mycom2.flagUser(user1.getName()); + sleep(500); // there is no responce for flagging a user, so we just have to wait a bit to make sure it happens - // check we no longer get messaes from user1 chatFuture = mycom2.getChatMessage(); mycom1.sendChat(game1.getId(), "test123"); mycom1.sendChat(user2.getName(), "fred"); + sleep(1000); - Assert.assertEquals(false, chatFuture.isDone()); + try { + Assert.assertEquals(false, chatFuture.isDone()); + } + catch(AssertionError error) { + Assert.fail("chatFuture has result " + chatFuture.get()); + } mycom1.disconnect(); //sleep(1000); // TODO we need to wait as if both diconnect happen at same time, 2 DB transations happen at the same time @@ -262,6 +268,29 @@ } @Test + public void testOldClientForceUpgrade() throws Exception { + LobbyConnection mycom1 = new LobbyConnection("test-guest-uuid", "0"); // BlackJack does not support version 0 + + try { + Player player = mycom1.connect(server, port).get(); + Assert.assertEquals("test-guest", player.getName()); + GameType type = getMockGameType(mycom1.getGameTypes().get()); + mycom1.getGames(type); // do not call get, as no games are returned + Game game = new Game("my game name", BLACKJACK_OPTIONS, 2, 1000); + game.setType(type); + + String errorMessage = Assert.assertThrows(ExecutionException.class, () -> { + mycom1.createNewGame(game).get(); + }).getMessage(); + + Assert.assertTrue(errorMessage.contains("please update your app")); + } + finally { + mycom1.disconnect(); + } + } + + @Test public void testPlayGame() throws Exception { System.out.println("mock game class " + net.yura.blackjack.server.BlackJack.class); @@ -332,7 +361,7 @@ MatcherAssert.assertThat(playerInfo, CoreMatchers.hasItem(new PlayerInfo("OAuthLogin", "no", false))); MatcherAssert.assertThat(playerInfo, CoreMatchers.hasItem(new PlayerInfo("pushToken", "no", false))); MatcherAssert.assertThat(playerInfo, CoreMatchers.hasItem(new PlayerInfo("type", "PLAYER_GUEST", false))); - MatcherAssert.assertThat(playerInfo, CoreMatchers.hasItem(new PlayerInfo("app", "JUnit-Test 2", false))); + MatcherAssert.assertThat(playerInfo, CoreMatchers.hasItem(new PlayerInfo("app", "JUnit-Test 3", false))); MatcherAssert.assertThat(playerInfo, CoreMatchers.hasItem(new PlayerInfo("games", "[]", false))); //Assert.assertThat(playerInfo, CoreMatchers.hasItem(new PlayerInfo("locale", "en_GB", false))); // this will depend on system Modified: trunk/test/net/yura/lobby/util/ByteInputStreamTest.java =================================================================== --- trunk/test/net/yura/lobby/util/ByteInputStreamTest.java 2022-02-06 19:16:57 UTC (rev 1014) +++ trunk/test/net/yura/lobby/util/ByteInputStreamTest.java 2022-05-12 22:32:43 UTC (rev 1015) @@ -1,20 +1,11 @@ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ package net.yura.lobby.util; import java.util.UUID; -import net.yura.lobby.util.ByteInputStream; import org.junit.AfterClass; import org.junit.Test; import static org.junit.Assert.*; import org.junit.BeforeClass; -/** - * - * @author Administrator - */ public class ByteInputStreamTest { public ByteInputStreamTest() { @@ -51,7 +42,6 @@ assertEquals(2, in.available()); assertEquals(41, in.read()); assertEquals(1, in.available()); assertEquals(11, in.read()); assertEquals(0, in.available()); assertEquals(-1, in.read()); - } @Test @@ -87,6 +77,5 @@ assertEquals(6, in.available()); assertEquals(5, in.skip(5)); assertEquals(1, in.available()); assertEquals(11, in.read()); assertEquals(0, in.available()); assertEquals(-1, in.read()); - } } Modified: trunk/test/net/yura/lobby/util/LobbyConnection.java =================================================================== --- trunk/test/net/yura/lobby/util/LobbyConnection.java 2022-02-06 19:16:57 UTC (rev 1014) +++ trunk/test/net/yura/lobby/util/LobbyConnection.java 2022-05-12 22:32:43 UTC (rev 1015) @@ -26,8 +26,12 @@ private BlockingQueue<Integer> removedGames = new LinkedBlockingQueue<>(); public LobbyConnection(String clientId) { + this(clientId, "3"); + } + + public LobbyConnection(String clientId, String version) { client = new LoggingClient(); - mycom = new LobbyCom(clientId, "JUnit-Test", "3"); + mycom = new LobbyCom(clientId, "JUnit-Test", version); mycom.addEventListener(client); mycom.addPushEventListener(client); } Modified: trunk/test/net/yura/util/CallCounterTest.java =================================================================== --- trunk/test/net/yura/util/CallCounterTest.java 2022-02-06 19:16:57 UTC (rev 1014) +++ trunk/test/net/yura/util/CallCounterTest.java 2022-05-12 22:32:43 UTC (rev 1015) @@ -17,11 +17,11 @@ } int count = instance.getCount(); - assertTrue("count is too high", 100 >= count); - assertTrue("count is too low", 99 <= count); + assertTrue("count is too high " + count, 100 >= count); + assertTrue("count is too low " + count, 90 <= count); int max = instance.getMax(); - assertTrue("max is too high", 100 >= max); - assertTrue("max is too low", 99 <= max); + assertTrue("max is too high " + count, 100 >= max); + assertTrue("max is too low " + count, 90 <= max); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <yu...@us...> - 2022-02-06 19:17:00
|
Revision: 1014 http://sourceforge.net/p/lobby/code/1014 Author: yuranet Date: 2022-02-06 19:16:57 +0000 (Sun, 06 Feb 2022) Log Message: ----------- send status in alert Modified Paths: -------------- trunk/src_server/net/yura/lobby/database/impl/JPADatabase.java Modified: trunk/src_server/net/yura/lobby/database/impl/JPADatabase.java =================================================================== --- trunk/src_server/net/yura/lobby/database/impl/JPADatabase.java 2022-02-06 18:39:59 UTC (rev 1013) +++ trunk/src_server/net/yura/lobby/database/impl/JPADatabase.java 2022-02-06 19:16:57 UTC (rev 1014) @@ -125,14 +125,14 @@ return success; } - + private void error(String message) { int count = errorCount.incrementAndGet(); if (count == 1) { - Alert.sendAlert("DB", "error count up: " + message); + Alert.sendAlert("DB", getStatus() + " - " + message); } } - + private Interaction getTransaction() { Interaction in = interactions.get(); if (in == null) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <yu...@us...> - 2022-02-06 18:40:01
|
Revision: 1013 http://sourceforge.net/p/lobby/code/1013 Author: yuranet Date: 2022-02-06 18:39:59 +0000 (Sun, 06 Feb 2022) Log Message: ----------- more errors will add to error count Modified Paths: -------------- trunk/src_server/net/yura/lobby/database/Database.java trunk/src_server/net/yura/lobby/database/impl/JPADatabase.java trunk/src_server/net/yura/lobby/database/impl/JPADatabaseMXBean.java trunk/src_server/net/yura/lobby/server/GameLobby.java Modified: trunk/src_server/net/yura/lobby/database/Database.java =================================================================== --- trunk/src_server/net/yura/lobby/database/Database.java 2022-01-15 16:33:11 UTC (rev 1012) +++ trunk/src_server/net/yura/lobby/database/Database.java 2022-02-06 18:39:59 UTC (rev 1013) @@ -16,6 +16,10 @@ GameTypeRoom getGameType(int id); void saveGameType(GameTypeRoom gtr); + /** + * @param id of the game + * @return the game or null if it can not be found + */ GameRoom getGame(int id); void saveGame(GameRoom gameRoom); void removeGame(GameRoom gameRoom); Modified: trunk/src_server/net/yura/lobby/database/impl/JPADatabase.java =================================================================== --- trunk/src_server/net/yura/lobby/database/impl/JPADatabase.java 2022-01-15 16:33:11 UTC (rev 1012) +++ trunk/src_server/net/yura/lobby/database/impl/JPADatabase.java 2022-02-06 18:39:59 UTC (rev 1013) @@ -171,8 +171,7 @@ @Override public GameRoom getGame(int id) { - Interaction in = getTransaction(); - return in.em.find(GameRoom.class, id); + return find(GameRoom.class, id); } @Override @@ -182,15 +181,13 @@ @Override public GameTypeRoom getGameType(int id) { - Interaction in = getTransaction(); - return in.em.find(GameTypeRoom.class, id); + return find(GameTypeRoom.class, id); } @Override public User getUserByUsername(String username) { - Interaction in = getTransaction(); if (username.toUpperCase().startsWith("GUEST")) { - User user = in.em.find(User.class, Integer.parseInt(username.substring("GUEST".length())) ); + User user = find(User.class, Integer.parseInt(username.substring("GUEST".length())) ); // user.getName() always returns the correct name, so we need to make sure it matches if (username.equalsIgnoreCase( user.getName() )) { return user; @@ -197,6 +194,7 @@ } } else { + Interaction in = getTransaction(); Query q1 = in.em.createQuery("SELECT u FROM User u WHERE u.name = ?1"); q1.setParameter(1, username); try { @@ -295,6 +293,17 @@ save(gr); } + private <T> T find(Class<T> type, Object id) { + Interaction in = getTransaction(); + try { + return in.em.find(type, id); + } + catch (RuntimeException ex) { + error(String.valueOf(ex)); + throw ex; + } + } + private void save(Object obj) { Interaction in = getTransaction(); if (NucleusJPAHelper.isDetached(obj)) { @@ -333,6 +342,11 @@ return errorCount.get(); } + @Override + public void resetErrorCount() { + errorCount.set(0); + } + private PersistenceNucleusContext getContext() { // datanucleus v3 (in case we need to rollback again) //JPAEntityManagerFactory dnemf = (JPAEntityManagerFactory)emf; @@ -378,7 +392,7 @@ if (errors == 0 && interactions >= 0 && connections >= 0) { return "all ok"; } - return "ERR=" + errors + " i=" + interactions + " c=" + connections; + return "ERR=" + errors + " int=" + interactions + " con=" + connections; } /* Modified: trunk/src_server/net/yura/lobby/database/impl/JPADatabaseMXBean.java =================================================================== --- trunk/src_server/net/yura/lobby/database/impl/JPADatabaseMXBean.java 2022-01-15 16:33:11 UTC (rev 1012) +++ trunk/src_server/net/yura/lobby/database/impl/JPADatabaseMXBean.java 2022-02-06 18:39:59 UTC (rev 1013) @@ -9,6 +9,7 @@ int getInteractionsCount(); int getErrorCount(); + void resetErrorCount(); FactoryStatistics getStatistics(); Modified: trunk/src_server/net/yura/lobby/server/GameLobby.java =================================================================== --- trunk/src_server/net/yura/lobby/server/GameLobby.java 2022-01-15 16:33:11 UTC (rev 1012) +++ trunk/src_server/net/yura/lobby/server/GameLobby.java 2022-02-06 18:39:59 UTC (rev 1013) @@ -407,16 +407,17 @@ Map responce = loginResponce(user); send(session, ProtoAccess.COMMAND_LOGIN_OK, responce, LobbyLogger.NO_GAME_ID); - - if (checkIAm(session, Player.PLAYER_MODERATOR)) { - Map map = new HashMap(); - map.put("message", "DB Status: " + database.getStatus()); - send(session, ProtoAccess.COMMAND_CHAT_MESSAGE, map, LobbyLogger.NO_GAME_ID); - } } finally { database.endTransaction(); } + + // send info AFTER endTransaction, so current transaction is not included in the counts + if (checkIAm(session, Player.PLAYER_MODERATOR)) { + Map map = new HashMap(); + map.put("message", "DB Status: " + database.getStatus()); + send(session, ProtoAccess.COMMAND_CHAT_MESSAGE, map, LobbyLogger.NO_GAME_ID); + } } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <yu...@us...> - 2022-01-15 16:33:13
|
Revision: 1012 http://sourceforge.net/p/lobby/code/1012 Author: yuranet Date: 2022-01-15 16:33:11 +0000 (Sat, 15 Jan 2022) Log Message: ----------- Apple push support added Modified Paths: -------------- trunk/build.xml trunk/nbproject/project.properties trunk/src_server/META-INF/MANIFEST.MF trunk/src_server/net/yura/lobby/server/GameLobby.java trunk/src_server/net/yura/lobby/server/LobbyController.java Added Paths: ----------- trunk/lib/fast-uuid-0.2.0.jar trunk/lib/pushy-0.15.0.jar trunk/src_server/net/yura/lobby/service/ApplePushNotificationService.java Modified: trunk/build.xml =================================================================== --- trunk/build.xml 2022-01-09 14:53:59 UTC (rev 1011) +++ trunk/build.xml 2022-01-15 16:33:11 UTC (rev 1012) @@ -130,7 +130,7 @@ source="1.8" target="1.8" - classpath="${basedir}/lib/UtilME.jar:${basedir}/lib/QuickServer.jar:${basedir}/lib/javax.persistence-2.2.4.jar:${basedir}/lib/datanucleus-core-5.0.2.jar:${basedir}/lib/datanucleus-api-jpa-5.0.2.jar:${basedir}/lib/Grasshopper.jar:${basedir}/lib/gcm-server.jar:${basedir}/lib/netty-all-4.1.Final.jar:${basedir}/lib/google-api-client-1.24.1.jar:${basedir}/lib/google-http-client-1.24.1.jar:${basedir}/lib/google-http-client-gson-1.24.1.jar:${basedir}/lib/google-oauth-client-1.24.1.jar:${basedir}/lib/google-auth-library-oauth2-http-0.17.1.jar:${basedir}/lib/google-auth-library-credentials-0.18.0.jar:${basedir}/lib/firebase-admin-6.13.0.jar:${basedir}/lib/guava-26.0-android.jar" + classpath="${basedir}/lib/UtilME.jar:${basedir}/lib/QuickServer.jar:${basedir}/lib/javax.persistence-2.2.4.jar:${basedir}/lib/datanucleus-core-5.0.2.jar:${basedir}/lib/datanucleus-api-jpa-5.0.2.jar:${basedir}/lib/Grasshopper.jar:${basedir}/lib/gcm-server.jar:${basedir}/lib/netty-all-4.1.Final.jar:${basedir}/lib/google-api-client-1.24.1.jar:${basedir}/lib/google-http-client-1.24.1.jar:${basedir}/lib/google-http-client-gson-1.24.1.jar:${basedir}/lib/google-oauth-client-1.24.1.jar:${basedir}/lib/google-auth-library-oauth2-http-0.17.1.jar:${basedir}/lib/google-auth-library-credentials-0.18.0.jar:${basedir}/lib/firebase-admin-6.13.0.jar:${basedir}/lib/guava-26.0-android.jar:${basedir}/lib/pushy-0.15.0.jar" /> Added: trunk/lib/fast-uuid-0.2.0.jar =================================================================== (Binary files differ) Index: trunk/lib/fast-uuid-0.2.0.jar =================================================================== --- trunk/lib/fast-uuid-0.2.0.jar 2022-01-09 14:53:59 UTC (rev 1011) +++ trunk/lib/fast-uuid-0.2.0.jar 2022-01-15 16:33:11 UTC (rev 1012) Property changes on: trunk/lib/fast-uuid-0.2.0.jar ___________________________________________________________________ Added: svn:mime-type ## -0,0 +1 ## +application/octet-stream \ No newline at end of property Added: trunk/lib/pushy-0.15.0.jar =================================================================== (Binary files differ) Index: trunk/lib/pushy-0.15.0.jar =================================================================== --- trunk/lib/pushy-0.15.0.jar 2022-01-09 14:53:59 UTC (rev 1011) +++ trunk/lib/pushy-0.15.0.jar 2022-01-15 16:33:11 UTC (rev 1012) Property changes on: trunk/lib/pushy-0.15.0.jar ___________________________________________________________________ Added: svn:mime-type ## -0,0 +1 ## +application/octet-stream \ No newline at end of property Modified: trunk/nbproject/project.properties =================================================================== --- trunk/nbproject/project.properties 2022-01-09 14:53:59 UTC (rev 1011) +++ trunk/nbproject/project.properties 2022-01-15 16:33:11 UTC (rev 1012) @@ -15,6 +15,7 @@ file.reference.javax.persistence-2.2.4.jar=lib/javax.persistence-2.2.4.jar file.reference.mysql-connector-java-8.0.26.jar=lib/mysql-connector-java-8.0.26.jar file.reference.netty-all-4.1.Final.jar=lib/netty-all-4.1.Final.jar +file.reference.pushy-0.15.0.jar=lib/pushy-0.15.0.jar javac.external.vm=false javac.modulepath= javac.processormodulepath= @@ -103,7 +104,8 @@ ${file.reference.netty-all-4.1.Final.jar}:\ ${file.reference.google-auth-library-credentials-0.18.0.jar}:\ ${file.reference.google-auth-library-oauth2-http-0.17.1.jar}:\ - ${file.reference.guava-26.0-android.jar} + ${file.reference.guava-26.0-android.jar}:\ + ${file.reference.pushy-0.15.0.jar} javadoc.noindex=false annotation.processing.enabled.in.editor=false javadoc.private=false Modified: trunk/src_server/META-INF/MANIFEST.MF =================================================================== --- trunk/src_server/META-INF/MANIFEST.MF 2022-01-09 14:53:59 UTC (rev 1011) +++ trunk/src_server/META-INF/MANIFEST.MF 2022-01-15 16:33:11 UTC (rev 1012) @@ -2,4 +2,4 @@ Created-By: Yura Mamyrin (yu...@yu...) Main-Class: net.yura.lobby.netty.Server Class-Path: lib/QuickServer.jar lib/UtilME.jar lib/javax.persistence-2.2.4.jar lib/mysql-connector-java-8.0.26.jar lib/datanucleus-core-5.0.2.jar lib/datanucleus-rdbms-5.0.2.jar lib/datanucleus-api-jpa-5.0.2.jar lib/javax.jdo-3.2.0-release.jar lib/asm-4.0.jar lib/Grasshopper.jar lib/gcm-server.jar lib/json_simple-1.1.jar lib/netty-all-4.1.Final.jar lib/google-api-client-1.24.1.jar lib/google-http-client-1.24.1.jar lib/google-http-client-gson-1.24.1.jar lib/google-oauth-client-1.24.1.jar lib/gson-2.1.jar - lib/firebase-admin-6.13.0.jar lib/google-http-client-jackson2-1.33.0.jar lib/jackson-core-2.10.0.jar lib/slf4j-api-1.7.25.jar lib/google-auth-library-oauth2-http-0.17.1.jar lib/google-auth-library-credentials-0.18.0.jar lib/guava-26.0-android.jar lib/api-common-1.8.1.jar + lib/firebase-admin-6.13.0.jar lib/google-http-client-jackson2-1.33.0.jar lib/jackson-core-2.10.0.jar lib/slf4j-api-1.7.25.jar lib/google-auth-library-oauth2-http-0.17.1.jar lib/google-auth-library-credentials-0.18.0.jar lib/guava-26.0-android.jar lib/api-common-1.8.1.jar lib/pushy-0.15.0.jar lib/fast-uuid-0.2.0.jar Modified: trunk/src_server/net/yura/lobby/server/GameLobby.java =================================================================== --- trunk/src_server/net/yura/lobby/server/GameLobby.java 2022-01-09 14:53:59 UTC (rev 1011) +++ trunk/src_server/net/yura/lobby/server/GameLobby.java 2022-01-15 16:33:11 UTC (rev 1012) @@ -38,6 +38,7 @@ import net.yura.lobby.model.Message; import net.yura.lobby.model.Player; import net.yura.lobby.service.Alert; +import net.yura.lobby.service.ApplePushNotificationService; import net.yura.lobby.service.ProfileServer; import net.yura.lobby.service.GoogleFCM; @@ -854,8 +855,10 @@ data.put(PushLobbyClient.OPTIONS, options); } - if (registrationToken.startsWith("Apple-")) { - // TODO do apple send + if (registrationToken.startsWith(ApplePushNotificationService.TOKEN_PREFIX)) { + + String token = registrationToken.substring(ApplePushNotificationService.TOKEN_PREFIX.length()); + ApplePushNotificationService.send(username, token, data, gameIdForLog); } else { GoogleFCM.send(username, registrationToken, data, gameIdForLog); Modified: trunk/src_server/net/yura/lobby/server/LobbyController.java =================================================================== --- trunk/src_server/net/yura/lobby/server/LobbyController.java 2022-01-09 14:53:59 UTC (rev 1011) +++ trunk/src_server/net/yura/lobby/server/LobbyController.java 2022-01-15 16:33:11 UTC (rev 1012) @@ -31,6 +31,7 @@ import net.yura.lobby.model.Player; import net.yura.lobby.model.PlayerInfo; import net.yura.lobby.service.Alert; +import net.yura.lobby.service.ApplePushNotificationService; import net.yura.lobby.service.FileSystem; import net.yura.lobby.service.SphericalLabs; @@ -175,7 +176,7 @@ token = decrypt(request.get("token")); } if (token != null && PushLobbyClient.PUSH_SYSTEM_APN.equals(system)) { - token = "Apple-" + token; + token = ApplePushNotificationService.TOKEN_PREFIX + token; } lobby.registerPushToken(session, token); Added: trunk/src_server/net/yura/lobby/service/ApplePushNotificationService.java =================================================================== --- trunk/src_server/net/yura/lobby/service/ApplePushNotificationService.java (rev 0) +++ trunk/src_server/net/yura/lobby/service/ApplePushNotificationService.java 2022-01-15 16:33:11 UTC (rev 1012) @@ -0,0 +1,122 @@ +package net.yura.lobby.service; + +import com.eatthepath.pushy.apns.ApnsClient; +import com.eatthepath.pushy.apns.ApnsClientBuilder; +import com.eatthepath.pushy.apns.PushNotificationResponse; +import com.eatthepath.pushy.apns.auth.ApnsSigningKey; +import com.eatthepath.pushy.apns.util.ApnsPayloadBuilder; +import com.eatthepath.pushy.apns.util.SimpleApnsPayloadBuilder; +import com.eatthepath.pushy.apns.util.SimpleApnsPushNotification; +import com.eatthepath.pushy.apns.util.concurrent.PushNotificationFuture; +import java.io.File; +import java.util.Map; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ExecutionException; +import java.util.logging.Level; +import java.util.logging.Logger; +import net.yura.lobby.client.PushLobbyClient; +import net.yura.lobby.server.LobbyLogger; + +/** + * https://developer.apple.com/documentation/usernotifications/sending_push_notifications_using_command-line_tools + * notnoop/java-apns + * jchambers/pushy + * CleverTap/apns-http2 + */ +public class ApplePushNotificationService { + + public static final String TOKEN_PREFIX = "Apple-"; + public static final String SANDBOX_PREFIX = "sandbox-"; + + public static final String TEAM_ID = "GP37R5KJ29"; + public static final String KEY_ID = "8FY494X349"; + + private static final String TOPIC = "net.yura.domination"; + + private static ApnsClient productionApnsClient, developmentApnsClient; + + static { + + try { +/* + // certificate-based (slower but simpler then token based) + + //% openssl s_client -connect "${APNS_HOST_NAME}":443 -cert "${CERTIFICATE_FILE_NAME}" -certform DER -key "${CERTIFICATE_KEY_FILE_NAME}" -keyform PEM + //% curl -v --header "apns-topic: ${TOPIC}" --header "apns-push-type: alert" --cert "${CERTIFICATE_FILE_NAME}" --cert-type DER --key "${CERTIFICATE_KEY_FILE_NAME}" --key-type PEM --data '{"aps":{"alert":"test"}}' --http2 https://${APNS_HOST_NAME}/3/device/${DEVICE_TOKEN} + + // TLS authentication + apnsClient = new ApnsClientBuilder() + .setApnsServer(ApnsClientBuilder.DEVELOPMENT_APNS_HOST) + .setClientCredentials(new File("/path/to/certificate.p12"), "p12-file-password") + .build(); +*/ + + // Token authentication + productionApnsClient = new ApnsClientBuilder() + .setApnsServer(ApnsClientBuilder.PRODUCTION_APNS_HOST) + .setSigningKey(ApnsSigningKey.loadFromPkcs8File(new File("AuthKey_8FY494X349.p8"), + TEAM_ID, KEY_ID)).build(); + + developmentApnsClient = new ApnsClientBuilder() + .setApnsServer(ApnsClientBuilder.DEVELOPMENT_APNS_HOST) + .setSigningKey(ApnsSigningKey.loadFromPkcs8File(new File("AuthKey_8FY494X349.p8"), + TEAM_ID, KEY_ID)).build(); + } + catch (Exception ex) { + Logger.getLogger(ApplePushNotificationService.class.getName()).log(Level.SEVERE, "APNs init error. Did you forget to set the AuthKey file location?", ex); + } + } + + public static void shutdown() { + final CompletableFuture<Void> closeFuture1 = productionApnsClient.close(); + final CompletableFuture<Void> closeFuture2 = developmentApnsClient.close(); + } + + public static void send(String username, String token, Map<String, String> data, int correlationId) throws Exception { + + ApnsClient apnsClient; + if (token.startsWith(SANDBOX_PREFIX)) { + token = token.substring(SANDBOX_PREFIX.length()); + apnsClient = developmentApnsClient; + } + else { + apnsClient = productionApnsClient; + } + + final ApnsPayloadBuilder payloadBuilder = new SimpleApnsPayloadBuilder(); + + for (Map.Entry<String, String> entry : data.entrySet()) { + if (PushLobbyClient.MESSAGE.equals(entry.getKey())) { + payloadBuilder.setAlertBody(entry.getValue()); + } + else { + payloadBuilder.addCustomProperty(entry.getKey(), entry.getValue()); + } + } + + final String payload = payloadBuilder.build(); + //final String token = TokenUtil.sanitizeTokenString("<efc7492 bdbd8209>"); + + SimpleApnsPushNotification pushNotification = new SimpleApnsPushNotification(token, TOPIC, payload); + + PushNotificationFuture<SimpleApnsPushNotification, PushNotificationResponse<SimpleApnsPushNotification>> sendNotificationFuture = apnsClient.sendNotification(pushNotification); + + try { + PushNotificationResponse<SimpleApnsPushNotification> pushNotificationResponse = sendNotificationFuture.get(); + + if (pushNotificationResponse.isAccepted()) { + LobbyLogger.log(correlationId, Level.INFO, "Push notification to " + username + " accepted by APNs gateway."); + } + else { + LobbyLogger.log(correlationId, Level.WARNING, "Notification to " + username + " rejected by the APNs gateway: " + pushNotificationResponse.getRejectionReason()); + + pushNotificationResponse.getTokenInvalidationTimestamp().ifPresent(timestamp -> { + LobbyLogger.log(correlationId, Level.WARNING, "\t…and the token is invalid as of " + timestamp); + }); + } + } + catch (ExecutionException e) { + LobbyLogger.log(correlationId, Level.WARNING, "Failed to send push notification to " + username, e); + } + } +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <yu...@us...> - 2022-01-09 14:54:01
|
Revision: 1011 http://sourceforge.net/p/lobby/code/1011 Author: yuranet Date: 2022-01-09 14:53:59 +0000 (Sun, 09 Jan 2022) Log Message: ----------- catch more types of crypto errors Modified Paths: -------------- trunk/src/net/yura/lobby/client/LobbyCom.java Modified: trunk/src/net/yura/lobby/client/LobbyCom.java =================================================================== --- trunk/src/net/yura/lobby/client/LobbyCom.java 2021-12-14 12:24:51 UTC (rev 1010) +++ trunk/src/net/yura/lobby/client/LobbyCom.java 2022-01-09 14:53:59 UTC (rev 1011) @@ -76,7 +76,7 @@ // when the server tries to decrypt it, it throws a BadPaddingException encrypt = Cipher.getInstance("RSA/ECB/PKCS1Padding"); } - catch (Exception e) { + catch (Throwable e) { // can be NoClassDefFoundError e.printStackTrace(); } gameTypeMap = new HashMap(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <yu...@us...> - 2021-12-14 12:24:54
|
Revision: 1010 http://sourceforge.net/p/lobby/code/1010 Author: yuranet Date: 2021-12-14 12:24:51 +0000 (Tue, 14 Dec 2021) Log Message: ----------- only datanucleus 5.0.2 left, all other versions removed Modified Paths: -------------- trunk/build.xml trunk/nbproject/project.properties trunk/resources/runLobbyServer.cmd trunk/src_server/META-INF/persistence.xml Removed Paths: ------------- trunk/lib/datanucleus-api-jpa-3.1.3.jar trunk/lib/datanucleus-api-jpa-5.2.8.jar trunk/lib/datanucleus-core-3.1.3.jar trunk/lib/datanucleus-core-5.2.8.jar trunk/lib/datanucleus-enhancer-3.1.3.jar trunk/lib/datanucleus-rdbms-3.1.3.jar trunk/lib/datanucleus-rdbms-5.2.9.jar Modified: trunk/build.xml =================================================================== --- trunk/build.xml 2021-12-12 13:35:46 UTC (rev 1009) +++ trunk/build.xml 2021-12-14 12:24:51 UTC (rev 1010) @@ -102,6 +102,7 @@ <!-- TARGET NEEDS TO BE 1.8 for DataNucleus to work if it is newer (or older) the DataNucleus enhancer will fail +(DataNucleus 5.2.2 - Support for Java 13 and Java 14 bytecode) currently we are unable to upgrade to anything newer then DataNucleus 5.0.2 as newer version use a new connection pool (DBCP2) and this does not work. Deleted: trunk/lib/datanucleus-api-jpa-3.1.3.jar =================================================================== (Binary files differ) Deleted: trunk/lib/datanucleus-api-jpa-5.2.8.jar =================================================================== (Binary files differ) Deleted: trunk/lib/datanucleus-core-3.1.3.jar =================================================================== (Binary files differ) Deleted: trunk/lib/datanucleus-core-5.2.8.jar =================================================================== (Binary files differ) Deleted: trunk/lib/datanucleus-enhancer-3.1.3.jar =================================================================== (Binary files differ) Deleted: trunk/lib/datanucleus-rdbms-3.1.3.jar =================================================================== (Binary files differ) Deleted: trunk/lib/datanucleus-rdbms-5.2.9.jar =================================================================== (Binary files differ) Modified: trunk/nbproject/project.properties =================================================================== --- trunk/nbproject/project.properties 2021-12-12 13:35:46 UTC (rev 1009) +++ trunk/nbproject/project.properties 2021-12-14 12:24:51 UTC (rev 1010) @@ -2,9 +2,9 @@ ${run.modulepath} debug.test.modulepath=\ ${run.test.modulepath} -file.reference.datanucleus-api-jpa-5.2.8.jar=lib/datanucleus-api-jpa-5.2.8.jar -file.reference.datanucleus-core-5.2.8.jar=lib/datanucleus-core-5.2.8.jar -file.reference.datanucleus-rdbms-5.2.9.jar=lib/datanucleus-rdbms-5.2.9.jar +file.reference.datanucleus-api-jpa-5.0.2.jar=lib/datanucleus-api-jpa-5.0.2.jar +file.reference.datanucleus-core-5.0.2.jar=lib/datanucleus-core-5.0.2.jar +file.reference.datanucleus-rdbms-5.0.2.jar=lib/datanucleus-rdbms-5.0.2.jar file.reference.firebase-admin-6.8.1.jar=lib/firebase-admin-6.8.1.jar file.reference.firebase-admin-6.13.0.jar=lib/firebase-admin-6.13.0.jar file.reference.google-auth-library-credentials-0.18.0.jar=lib/google-auth-library-credentials-0.18.0.jar @@ -61,7 +61,6 @@ dist.dir=dist manifest.file=manifest.mf javac.source=1.8 -run.jvmargs=-javaagent:lib/datanucleus-core-5.2.8.jar=-api=JPA,net.yura.lobby.database src.src_client.dir=src_client javac.test.processorpath=${javac.test.classpath} run.test.classpath=\ @@ -85,12 +84,12 @@ ${file.reference.UtilME.jar}:\ ${file.reference.asm-4.0.jar}:\ ${file.reference.commons-pool.jar}:\ - ${file.reference.datanucleus-core-5.2.8.jar}:\ - ${file.reference.datanucleus-api-jpa-5.2.8.jar}:\ - ${file.reference.datanucleus-rdbms-5.2.9.jar}:\ ${file.reference.mysql-connector-java-8.0.26.jar}:\ ${file.reference.javax.persistence-2.2.4.jar}:\ ${file.reference.javax.jdo-3.2.0-release.jar}:\ + ${file.reference.datanucleus-core-5.0.2.jar}:\ + ${file.reference.datanucleus-rdbms-5.0.2.jar}:\ + ${file.reference.datanucleus-api-jpa-5.0.2.jar}:\ ${file.reference.javax.annotation-api-1.3.2.jar}:\ ${file.reference.gcm-server.jar}:\ ${file.reference.firebase-admin-6.13.0.jar}:\ Modified: trunk/resources/runLobbyServer.cmd =================================================================== --- trunk/resources/runLobbyServer.cmd 2021-12-12 13:35:46 UTC (rev 1009) +++ trunk/resources/runLobbyServer.cmd 2021-12-14 12:24:51 UTC (rev 1010) @@ -1,3 +1,3 @@ cd %~dp0 -java -server -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.port=4567 -javaagent:lib/datanucleus-core-5.2.8.jar=-api=JPA,net.yura.lobby.database -jar LobbyServer.jar %* +java -server -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.port=4567 -javaagent:lib/datanucleus-core-5.0.2.jar=-api=JPA,net.yura.lobby.database -jar LobbyServer.jar %* pause Modified: trunk/src_server/META-INF/persistence.xml =================================================================== --- trunk/src_server/META-INF/persistence.xml 2021-12-12 13:35:46 UTC (rev 1009) +++ trunk/src_server/META-INF/persistence.xml 2021-12-14 12:24:51 UTC (rev 1010) @@ -13,17 +13,6 @@ <properties> - <!-- DN v3 --> - <property name="datanucleus.ConnectionDriverName" value="com.mysql.jdbc.Driver"/> - <property name="datanucleus.ConnectionURL" value="jdbc:mysql://localhost:3306/lobby?useUnicode=yes&characterEncoding=UTF-8"/> - <property name="datanucleus.ConnectionUserName" value="root"/> - <property name="datanucleus.ConnectionPassword" value="pass"/> - <property name="datanucleus.autoCreateSchema" value="true"/> - <property name="datanucleus.validateTables" value="false"/> - <property name="datanucleus.validateConstraints" value="false"/> - - - <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver" /> <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/lobby?autoReconnect=true&useUnicode=yes&characterEncoding=UTF-8"/> <property name="javax.persistence.jdbc.user" value="root" /> @@ -35,13 +24,21 @@ <property name="datanucleus.schema.autoCreateAll" value="true"/> + <!-- these are false by default anyway --> <property name="datanucleus.schema.validateTables" value="false"/> <property name="datanucleus.schema.validateConstraints" value="false"/> + <!-- this is the cache thats shared between interactions/EntityManager + if we have this enabled direct DB updates do not seem to get picked up --> <property name="datanucleus.cache.level2.type" value="none"/> + <!-- to view database info from visualVM --> <property name="datanucleus.enableStatistics" value="true"/> <property name="datanucleus.jmxType" value="default"/> + + <!-- DBCP2 (dbcp2-builtin) does not seem to work, so we will stick to DBCP + as new versions of datanucleus do not have this, maybe we can move to c3p0 --> + <property name="datanucleus.connectionPoolingType" value="dbcp-builtin"/> </properties> </persistence-unit> </persistence> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |