001: package poker.presentation.login;
002:
003: import java.io.*;
004: import java.net.*;
005: import com.lutris.http.*;
006: import com.lutris.appserver.server.httpPresentation.*;
007: import com.lutris.appserver.server.user.*;
008: import com.lutris.util.*;
009: import poker.spec.*;
010: import poker.Poker;
011:
012: import poker.presentation.main.FirstDealHTML;
013:
014: /**
015: * Presentation Object that processes the creation request and redirects
016: * to the appropriate page.
017: *
018: *
019: * EnhyDraw!, beta 4, 5/21/99
020: *
021: * Copyright 1999, Larry Wolcot & Daryl Tempesta
022: * ALL rights reserved. Not for commercial use
023: * without written permission from both authors.
024: *
025: * @author Larry Wolcott
026: * @version $Revision: 1.1 $
027: */
028: public class CreationProcessorPresentation implements HttpPresentation {
029:
030: private final String homePage = "main/PlaceBetPresentation.po";
031: private final String loginPage = "login/CreatePlayerPresentation.po";
032: private GameManager gameManager;
033:
034: public void run(HttpPresentationComms comms) throws Exception {
035:
036: Poker application = (Poker) comms.application;
037: gameManager = application.getGameManager();
038:
039: String username = comms.request.getParameter("username");
040: String pw = comms.request.getParameter("pw");
041: String email = comms.request.getParameter("email");
042: String cashAsString = comms.request.getParameter("cash");
043:
044: String redirect = loginPage + "?" + "password=" + pw + "&"
045: + "username=" + username + "&" + "cash=" + cashAsString;
046:
047: String deck = comms.request.getParameter("deck");
048: String this Deck = "deck1";
049: if (deck.equals("2")) {
050: this Deck = "deck2";
051: } else if (deck.equals("3")) {
052: this Deck = "deck3";
053: } else if (deck.equals("4")) {
054: this Deck = "deck4";
055: } else if (deck.equals("5")) {
056: this Deck = "deck5";
057: }
058:
059: if (username == null || pw == null) {
060: comms.session
061: .getSessionData()
062: .set("error",
063: "You must specify a username and password to login.");
064: throw new ClientPageRedirectException(comms.request
065: .getAppFileURIPath(redirect));
066: }
067:
068: int cash = 0;
069: if (cashAsString != null && !cashAsString.equals("")) {
070: try {
071: cash = Integer.parseInt(cashAsString);
072: } catch (NumberFormatException e) {
073: comms.session.getSessionData().set("error",
074: "Invalid input in cash field!");
075: throw new ClientPageRedirectException(comms.request
076: .getAppFileURIPath(redirect));
077: }
078: }
079:
080: if (cash < 0 || cash > 1000000) {
081: comms.session
082: .getSessionData()
083: .set("error",
084: "Cash amount can't be negative or greather than 1000000!");
085: throw new ClientPageRedirectException(comms.request
086: .getAppFileURIPath(redirect));
087: }
088:
089: boolean auth = true;
090:
091: String id = comms.session.getSessionKey();
092: /*
093: *catch Null pointer exception ( we canot make a instances of classes from business layer when we run poker_pres )
094: *We need to allow poker_pres to be dynamic , so if the requested url is /poker_pres/..... we dont need to chack user
095: */
096:
097: try {
098: if ((!username.equals("")) && (!pw.equals(""))) {
099:
100: auth = gameManager.getIsNameUsed(username);
101:
102: if (auth)
103: comms.session.getSessionData().set("error",
104: "Name is already used!");
105: else {
106:
107: PokerGame newGame = PokerGameFactory.getPokerGame(
108: "poker.business.PokerGameImpl", username,
109: pw, id, cash);
110:
111: GameManager g = application.getGameManager();
112: newGame.setDeck(this Deck);
113: newGame.setEmail(email);
114: gameManager.addGame(newGame);
115: comms.session.setUser((User) newGame.getPlayer());
116: comms.session.getSessionData().set("game", newGame);
117: comms.session.getSessionData().set("error", "");
118: redirect = homePage;
119: }
120: } else
121: comms.session.getSessionData().set("error",
122: "Incorrect username or password!");
123:
124: } catch (NullPointerException e) {
125: throw new ClientPageRedirectException(comms.request
126: .getAppFileURIPath(homePage));
127: }
128: throw new ClientPageRedirectException(comms.request
129: .getAppFileURIPath(redirect));
130: }
131: }
|