1 package poker.presentation.login; 2 3 import java.io.*; 4 import java.net.*; 5 import com.lutris.http.*; 6 import com.lutris.appserver.server.httpPresentation.*; 7 import com.lutris.appserver.server.user.*; 8 import com.lutris.util.*; 9 import poker.spec.*; 10 import poker.Poker; 11 12 import poker.presentation.main.FirstDealHTML; 13 14 28 public class CreationProcessorPresentation implements HttpPresentation{ 29 30 31 private final String homePage = "main/PlaceBetPresentation.po"; 32 private final String loginPage = "login/CreatePlayerPresentation.po"; 33 private GameManager gameManager; 34 35 public void run(HttpPresentationComms comms) throws Exception { 36 37 38 Poker application = (Poker)comms.application; 39 gameManager = application.getGameManager(); 40 41 String username = comms.request.getParameter("username"); 42 String pw = comms.request.getParameter("pw"); 43 String email = comms.request.getParameter("email"); 44 String cashAsString = comms.request.getParameter("cash"); 45 46 String redirect = loginPage + "?" + "password=" + pw + "&" + 47 "username=" + username + "&" + 48 "cash=" + cashAsString; 49 50 String deck = comms.request.getParameter("deck"); 51 String thisDeck = "deck1"; 52 if (deck.equals("2")) { 53 thisDeck = "deck2"; 54 } 55 else if (deck.equals("3")) { 56 thisDeck = "deck3"; 57 } 58 else if (deck.equals("4")) { 59 thisDeck = "deck4"; 60 } 61 else if (deck.equals("5")) { 62 thisDeck = "deck5"; 63 } 64 65 if( username==null || pw==null ) { 66 comms.session.getSessionData().set("error", 67 "You must specify a username and password to login."); 68 throw new ClientPageRedirectException( 69 comms.request.getAppFileURIPath(redirect)); 70 } 71 72 int cash = 0; 73 if(cashAsString != null && !cashAsString.equals("")) { 74 try { 75 cash = Integer.parseInt(cashAsString); 76 } 77 catch( NumberFormatException e ) { 78 comms.session.getSessionData().set("error", 79 "Invalid input in cash field!"); 80 throw new ClientPageRedirectException( 81 comms.request.getAppFileURIPath(redirect)); 82 } 83 } 84 85 if( cash < 0 || cash > 1000000 ) { 86 comms.session.getSessionData().set("error", 87 "Cash amount can't be negative or greather than 1000000!"); 88 throw new ClientPageRedirectException( 89 comms.request.getAppFileURIPath(redirect)); 90 } 91 92 boolean auth = true; 93 94 String id = comms.session.getSessionKey(); 95 99 100 try{ 101 if ((!username.equals("")) && (!pw.equals(""))){ 102 103 104 auth = gameManager.getIsNameUsed(username); 105 106 if (auth) 107 comms.session.getSessionData().set("error", "Name is already used!"); 108 else { 109 110 PokerGame newGame = PokerGameFactory.getPokerGame("poker.business.PokerGameImpl",username, pw, id, cash); 111 112 GameManager g = application.getGameManager(); 113 newGame.setDeck(thisDeck); 114 newGame.setEmail(email); 115 gameManager.addGame(newGame); 116 comms.session.setUser((User)newGame.getPlayer()); 117 comms.session.getSessionData().set("game", newGame); 118 comms.session.getSessionData().set("error", ""); 119 redirect = homePage; 120 } 121 } 122 else 123 comms.session.getSessionData().set("error", "Incorrect username or password!"); 124 125 126 127 }catch (NullPointerException e){ 128 throw new ClientPageRedirectException( 129 comms.request.getAppFileURIPath(homePage)); 130 } 131 throw new ClientPageRedirectException(comms.request.getAppFileURIPath(redirect)); 132 } 133 } 134 | Popular Tags |