<%-- Copyright (c) 2012, Andy Janata All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --%> <%-- Administration tools. @author Andy Janata (ajanata@socialgamer.net) --%> <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %> <%@ page import="net.socialgamer.cah.HibernateUtil" %> <%@ page import="net.socialgamer.cah.db.BlackCard" %> <%@ page import="net.socialgamer.cah.db.WhiteCard" %> <%@ page import="net.socialgamer.cah.RequestWrapper" %> <%@ page import="org.hibernate.Session" %> <%@ page import="org.hibernate.Transaction" %> <% RequestWrapper wrapper = new RequestWrapper(request); String remoteAddr = wrapper.getRemoteAddr(); // TODO better access control than hard-coding IP addresses. if (!(remoteAddr.equals("0:0:0:0:0:0:0:1") || remoteAddr.equals("127.0.0.1") || remoteAddr.equals("98.248.33.90") || remoteAddr.equals("207.161.39.198"))) { response.sendError(403, "Access is restricted to known hosts"); return; } final String watermark = request.getParameter("watermark") != null ? request.getParameter("watermark") : ""; String error = ""; String status = ""; String field = ""; final String color = request.getParameter("color"); if (color != null) { if ("black".equals(color)) { final String text = request.getParameter("text"); final String pick_s = request.getParameter("pick"); final String draw_s = request.getParameter("draw"); if (text == null || "".equals(text) || pick_s == null || "".equals(pick_s) || draw_s == null || "".equals(draw_s)) { error = "You didn't specify something."; } else { int pick = 0; int draw = 0; try { pick = Integer.parseInt(pick_s); draw = Integer.parseInt(draw_s); } catch (NumberFormatException e) { error = "Something isn't a number."; } if (0 == pick) { error += " Pick can't be 0."; } else { final Session s = HibernateUtil.instance.sessionFactory.openSession(); final Transaction transaction = s.beginTransaction(); transaction.begin(); final BlackCard card = new BlackCard(); card.setText(text); card.setPick(pick); card.setDraw(draw); card.setWatermark(watermark); s.save(card); transaction.commit(); s.close(); status = "Saved '" + text + "'."; field = "black"; } } } else if ("white".equals(color)) { final String text = request.getParameter("text"); if (text == null || "".equals(text)) { error = "You didn't specify something."; } else { final Session s = HibernateUtil.instance.sessionFactory.openSession(); final Transaction transaction = s.beginTransaction(); transaction.begin(); final WhiteCard card = new WhiteCard(); card.setText(text); card.setWatermark(watermark); s.save(card); transaction.commit(); s.close(); status = "Saved '" + text + "'."; field = "white"; } } } %> PYX - Add Cards <%= error %> <%= status %>

Convention is to use four underscores for the blanks on black cards.

Black Card





White Card