Skip to content
This repository has been archived by the owner on Mar 10, 2019. It is now read-only.

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
devgianlu committed Feb 21, 2018
2 parents 5ad4afa + df06381 commit edea939
Show file tree
Hide file tree
Showing 89 changed files with 519 additions and 383 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ target
.idea/
WebContent/node_modules/
WebContent/.backup/
*.iml
.old/
preferences.json
server.sqlite
8 changes: 0 additions & 8 deletions WebContent/css/cards.css
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,6 @@
overflow-wrap: break-word;
}

#whiteCards {
width: 100%;
}

#hand > .list > .mdc-card.pyx-card {
flex-shrink: 0;
}

.mdc-card.pyx-card .card-details {
min-height: 0;
}
Expand Down
9 changes: 9 additions & 0 deletions WebContent/css/game.css
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
#gameLayout {
width: 100%;
display: flex;
}

#gameLayout > .message {
margin-top: 48px;
}

#whiteCards {
flex-grow: 1;
}

#hand > .list > .mdc-card.pyx-card {
flex-shrink: 0;
}

#drawer > .mdc-drawer__drawer {
padding: 16px;
display: flex;
Expand Down
4 changes: 2 additions & 2 deletions WebContent/game.html
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,9 @@ <h1 class="message mdc-typography--headline">No suggested game options.</h1>
</main>
</div>

<aside class="bottom-sheet" id="hand">
<aside class="bottom-sheet" id="hand" style="display: none">
<div class="_toggleHand_mask" style="flex-grow: 1"></div>
<div class="mdc-elevation--z16 mdc-toolbar" style="display: none">
<div class="mdc-elevation--z16 mdc-toolbar">
<div class="mdc-toolbar__row">
<section class="mdc-toolbar__section mdc-toolbar__section--align-start">
<div class="mdc-toolbar__title">
Expand Down
14 changes: 11 additions & 3 deletions WebContent/js/game.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ class GameManager {
this.drawer = new mdc.drawer.MDCPersistentDrawer($('#drawer')[0]);
$('.mdc-toolbar__menu-icon').on('click', () => this.toggleDrawer());

this._lobbyMessage = this.root.find('#gameLayout .message');

this._leaveGame = this.root.find('#leaveGame');
this._leaveGame.on('click', () => this.leave());

Expand Down Expand Up @@ -470,23 +472,26 @@ class GameManager {
this.blackCard = null;
this.addHandCards([], true);
this.addTableCards([], true);

this.toggleStartButton(this.amHost);
this.toggleHandVisibility(false);
this._lobbyMessage.show();
break;
case "p":
this.blackCard = data.bc;
this.updateHandInfo(this.bc.PK - this.bc.D, this.bc.D);
this.toggleStartButton(false);
this.addTableCards([], true);
this.toggleHandVisibility(this.getPlayerStatus(this.user.n) === "sp");
this._lobbyMessage.hide();
break;
case "j":
this.addTableCards(data.wc, true);
this.toggleStartButton(false);
this.toggleHandVisibility(false);
this._lobbyMessage.hide();
break;
case "ro":
this._lobbyMessage.hide();
this._highlightWinningCards(data.WC);
if (data.wl) {
// Someone won the game
Expand Down Expand Up @@ -523,8 +528,8 @@ class GameManager {
}

toggleHandVisibility(visible) {
if (visible) this._hand_toolbar.show();
else this._hand_toolbar.hide();
if (visible) this._hand.show();
else this._hand.hide();
this._reloadDrawerPadding();
}

Expand All @@ -542,6 +547,9 @@ class GameManager {
this._title.text(this.info.gi.H + " - PYX Reloaded");
document.title = this.info.gi.H + " - PYX Reloaded";

if (this.info.gi.gs === "l") this._lobbyMessage.show();
else this._lobbyMessage.hide();

this.toggleStartButton(this.amHost && this.info.gi.gs === "l");
this.toggleHandVisibility(this.getPlayerStatus(this.user.n) === "sp");

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>com.gianlu.pyxreloaded</groupId>
<artifactId>server</artifactId>
<version>0.2.0</version>
<version>0.2.1</version>
<packaging>jar</packaging>

<name>pyx-reloaded</name>
Expand Down
3 changes: 2 additions & 1 deletion preferences.json.default
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"maxUsers": 100,
"cacheEnabled": true,
"webContent": "./WebContent",
"pyxDb": "pyx.sqlite",
"pyxDbUrl": "jdbc:sqlite:pyx.sqlite",
"serverDbUrl": "jdbc:sqlite:server.sqlite",
"maxSkipsBeforeKick": 2,
"roundIntermission": 8,
"minBlackCards": 50,
Expand Down
10 changes: 8 additions & 2 deletions src/main/java/com/gianlu/pyxreloaded/Consts.java
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,13 @@ public enum ErrorCode {
/**
* The user has already suggested a modification.
*/
ALREADY_SUGGESTED("AS");
ALREADY_SUGGESTED("AS"),
/**
* SQL error, fatal.
* <p>
* FIXME: Remove this error
*/
SQL_ERROR("sqle");

private final String code;

Expand Down Expand Up @@ -1068,7 +1074,7 @@ public String toString() {
/**
* Can be used in responses as key
*/
interface ReturnableKey {
public interface ReturnableKey {
}

/**
Expand Down
29 changes: 19 additions & 10 deletions src/main/java/com/gianlu/pyxreloaded/Server.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package com.gianlu.pyxreloaded;

import com.gianlu.pyxreloaded.cardcast.CardcastService;
import com.gianlu.pyxreloaded.data.ConnectedUsers;
import com.gianlu.pyxreloaded.data.Game;
import com.gianlu.pyxreloaded.data.GameManager;
import com.gianlu.pyxreloaded.db.LoadedCards;
import com.gianlu.pyxreloaded.servlets.*;
import com.gianlu.pyxreloaded.servlets.Provider;
import com.gianlu.pyxreloaded.game.Game;
import com.gianlu.pyxreloaded.game.GameManager;
import com.gianlu.pyxreloaded.paths.AjaxPath;
import com.gianlu.pyxreloaded.paths.EventsPath;
import com.gianlu.pyxreloaded.server.Annotations;
import com.gianlu.pyxreloaded.server.CustomResourceHandler;
import com.gianlu.pyxreloaded.server.HttpsRedirect;
import com.gianlu.pyxreloaded.server.Provider;
import com.gianlu.pyxreloaded.singletons.*;
import com.gianlu.pyxreloaded.task.BroadcastGameListUpdateTask;
import com.gianlu.pyxreloaded.task.RefreshAdminTokenTask;
import com.gianlu.pyxreloaded.task.UserPingTask;
Expand Down Expand Up @@ -45,11 +48,17 @@ public static void main(String[] args) throws IOException, SQLException, Unrecov

Providers.add(Annotations.Preferences.class, (Provider<Preferences>) () -> preferences);

LoadedCards.load(preferences.getString("pyxDb", "pyx.sqlite"));
LoadedCards loadedCards = new LoadedCards(preferences.getString("pyxDbUrl", "jdbc:sqlite:pyx.sqlite"));
Providers.add(Annotations.LoadedCards.class, (Provider<LoadedCards>) () -> loadedCards);

ConnectedUsers connectedUsers = new ConnectedUsers(false, maxUsers);
Providers.add(Annotations.ConnectedUsers.class, (Provider<ConnectedUsers>) () -> connectedUsers);

ServerDatabase serverDatabase = new ServerDatabase(preferences.getString("serverDbUrl", "jdbc:sqlite:server.sqlite"));

BanList banList = new BanList(serverDatabase);
Providers.add(Annotations.BanList.class, (Provider<BanList>) () -> banList);

BroadcastGameListUpdateTask updateGameListTask = new BroadcastGameListUpdateTask(connectedUsers);
globalTimer.scheduleAtFixedRate(updateGameListTask, BROADCAST_UPDATE_START_DELAY, BROADCAST_UPDATE_DELAY, TimeUnit.MILLISECONDS);

Expand All @@ -61,13 +70,13 @@ public static void main(String[] args) throws IOException, SQLException, Unrecov
CardcastService cardcastService = new CardcastService();
Providers.add(Annotations.CardcastService.class, (Provider<CardcastService>) () -> cardcastService);

GameManager gameManager = new GameManager((manager, options) -> new Game(GameManager.generateGameId(), options, connectedUsers, manager, globalTimer, preferences, cardcastService), 100, updateGameListTask);
GameManager gameManager = new GameManager((manager, options) -> new Game(GameManager.generateGameId(), options, connectedUsers, manager, loadedCards, globalTimer, preferences, cardcastService), 100, updateGameListTask);
Providers.add(Annotations.GameManager.class, (Provider<GameManager>) () -> gameManager);

ResourceHandler resourceHandler = new CustomResourceHandler(preferences);
PathHandler pathHandler = new PathHandler(resourceHandler);
pathHandler.addExactPath("/AjaxServlet", new BaseAjaxHandler())
.addExactPath("/Events", Handlers.websocket(new EventsHandler()));
pathHandler.addExactPath("/AjaxServlet", new AjaxPath())
.addExactPath("/Events", Handlers.websocket(new EventsPath()));

RoutingHandler router = new RoutingHandler();
router.setFallbackHandler(pathHandler)
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/gianlu/pyxreloaded/Utils.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.gianlu.pyxreloaded;

import com.gianlu.pyxreloaded.data.WhiteCard;
import com.gianlu.pyxreloaded.cards.WhiteCard;
import com.google.gson.JsonArray;
import org.jetbrains.annotations.NotNull;

Expand Down
11 changes: 0 additions & 11 deletions src/main/java/com/gianlu/pyxreloaded/cardcast/CardIdUtils.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.gianlu.pyxreloaded.cardcast;

import com.gianlu.pyxreloaded.data.BlackCard;
import com.gianlu.pyxreloaded.cards.BlackCard;


public class CardcastBlackCard extends BlackCard {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.gianlu.pyxreloaded.cardcast;

import com.gianlu.pyxreloaded.data.CardSet;
import com.gianlu.pyxreloaded.cards.CardSet;

import java.util.HashSet;
import java.util.Set;
Expand Down
12 changes: 10 additions & 2 deletions src/main/java/com/gianlu/pyxreloaded/cardcast/CardcastService.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,21 @@
import java.lang.ref.SoftReference;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.regex.Pattern;


public class CardcastService {
private final static AtomicInteger cardId = new AtomicInteger(Integer.MIN_VALUE);
private static final Logger LOG = Logger.getLogger(CardcastService.class);
private static final String HOSTNAME = "api.cardcastgame.com";

public static int getNewCardId() {
synchronized (cardId) {
return cardId.decrementAndGet();
}
}

/**
* Base URL to the Cardcast API.
*/
Expand Down Expand Up @@ -132,7 +140,7 @@ public CardcastDeck loadSet(String setId) {
String text = StringUtils.join(strs, "____");
int pick = strs.size() - 1;
int draw = (pick >= 3 ? pick - 1 : 0);
deck.getBlackCards().add(new CardcastBlackCard(CardIdUtils.getNewId(), StringEscapeUtils.escapeXml11(text), draw, pick, setId));
deck.getBlackCards().add(new CardcastBlackCard(getNewCardId(), StringEscapeUtils.escapeXml11(text), draw, pick, setId));
}
}
}
Expand Down Expand Up @@ -168,7 +176,7 @@ public CardcastDeck loadSet(String setId) {
String text = StringUtils.join(strs, "");
// don't add blank cards, they don't do anything
if (!text.isEmpty())
deck.getWhiteCards().add(new CardcastWhiteCard(CardIdUtils.getNewId(), StringEscapeUtils.escapeXml11(text), setId));
deck.getWhiteCards().add(new CardcastWhiteCard(getNewCardId(), StringEscapeUtils.escapeXml11(text), setId));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.gianlu.pyxreloaded.cardcast;

import com.gianlu.pyxreloaded.data.WhiteCard;
import com.gianlu.pyxreloaded.cards.WhiteCard;


public class CardcastWhiteCard extends WhiteCard {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.gianlu.pyxreloaded.data;
package com.gianlu.pyxreloaded.cards;

import com.gianlu.pyxreloaded.Consts;
import com.gianlu.pyxreloaded.JsonWrapper;
import com.gianlu.pyxreloaded.data.JsonWrapper;

public abstract class BlackCard {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
package com.gianlu.pyxreloaded.data;
package com.gianlu.pyxreloaded.cards;

import com.gianlu.pyxreloaded.game.OutOfCardsException;

import java.util.*;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.gianlu.pyxreloaded.data;
package com.gianlu.pyxreloaded.cards;

import org.jetbrains.annotations.Nullable;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.gianlu.pyxreloaded.data;
package com.gianlu.pyxreloaded.cards;

import com.gianlu.pyxreloaded.Consts;
import com.gianlu.pyxreloaded.JsonWrapper;
import com.gianlu.pyxreloaded.data.JsonWrapper;

import java.util.Set;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
package com.gianlu.pyxreloaded.db;

import com.gianlu.pyxreloaded.data.BlackCard;
package com.gianlu.pyxreloaded.cards;

import java.sql.ResultSet;
import java.sql.SQLException;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.gianlu.pyxreloaded.db;
package com.gianlu.pyxreloaded.cards;

import com.gianlu.pyxreloaded.data.CardSet;
import com.gianlu.pyxreloaded.singletons.LoadedCards;

import java.sql.ResultSet;
import java.sql.SQLException;
Expand Down Expand Up @@ -31,9 +31,9 @@ public PyxCardSet(ResultSet resultSet) throws SQLException {
whiteCards = new HashSet<>();
}

public static List<PyxCardSet> loadCardSets(Set<Integer> ids) {
public static List<PyxCardSet> loadCardSets(LoadedCards loadedCards, Set<Integer> ids) {
List<PyxCardSet> sets = new ArrayList<>();
for (PyxCardSet set : LoadedCards.getLoadedSets())
for (PyxCardSet set : loadedCards.getLoadedSets())
if (ids.contains(set.id)) sets.add(set);

return sets;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
package com.gianlu.pyxreloaded.db;

import com.gianlu.pyxreloaded.data.WhiteCard;
package com.gianlu.pyxreloaded.cards;

import java.sql.ResultSet;
import java.sql.SQLException;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.gianlu.pyxreloaded.data;
package com.gianlu.pyxreloaded.cards;

import com.gianlu.pyxreloaded.Consts;
import com.gianlu.pyxreloaded.JsonWrapper;
import com.gianlu.pyxreloaded.data.JsonWrapper;


public abstract class WhiteCard {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
package com.gianlu.pyxreloaded.data;
package com.gianlu.pyxreloaded.cards;

import com.gianlu.pyxreloaded.game.OutOfCardsException;

import java.util.*;

Expand All @@ -18,7 +20,7 @@ public class WhiteDeck {
/**
* Create a new white card deck, loading the cards from the database and shuffling them.
*/
WhiteDeck(Collection<CardSet> cardSets, int numBlanks) {
public WhiteDeck(Collection<CardSet> cardSets, int numBlanks) {
Set<WhiteCard> allCards = new HashSet<>();
for (CardSet cardSet : cardSets) allCards.addAll(cardSet.getWhiteCards());
deck = new ArrayList<>(allCards);
Expand Down
Loading

0 comments on commit edea939

Please sign in to comment.