001: /*
002: * Larry and Daryl's EnhyDraw! Poker
003: * A sample Enhydra Application
004: *
005: * EnhyDraw!, beta 4, 5/21/99
006: *
007: * Copyright 1999, Larry Wolcot & Daryl Tempesta
008: * ALL rights reserved. Not for commercial use
009: * without written permission from both authors.
010: *
011: *
012: */
013:
014: package poker;
015:
016: import java.io.*;
017: import java.math.BigDecimal;
018: import java.util.Enumeration;
019: import com.lutris.util.*;
020: import com.lutris.logging.Logger;
021: import com.lutris.logging.LogChannel;
022: import com.lutris.appserver.server.session.*;
023: import com.lutris.appserver.server.user.*;
024: import com.lutris.appserver.server.*;
025: import com.lutris.appserver.server.httpPresentation.*;
026:
027: import poker.spec.*;
028:
029: import com.lutris.util.Config;
030:
031: import javax.servlet.http.Cookie;
032:
033: /**
034: * This is the main application object
035: * that handles the appication wide data,
036: * like the GameManager.
037: */
038: public class Poker extends StandardApplication implements
039: java.io.Serializable {
040:
041: private static GameManager gameManager = null;
042:
043: private static FortuneManager fortuneManager = null;
044:
045: // This is where you should enable the use of DODS_Objects
046: // instead of Vector Objects for persistance
047: private boolean useDB = false;
048:
049: // private boolean useDB = true;
050:
051: public void startup(Config appConfig) throws ApplicationException {
052:
053: try {
054: // This is where you should enable the use of DODS_Objects
055: // instead of Vector Objects for persistance
056: useDB = appConfig.getBoolean("EnhyDrawApplication.useDB",
057: false);
058: } catch (ConfigException e) {
059: logChannel.write(Logger.INFO, "poker.conf errror:"
060: + e.toString());
061: }
062:
063: super .startup(appConfig);
064:
065: //Yea, this needs to be finished
066: try {
067: fortuneManager = FortuneManagerFactory
068: .getFortuneManager("poker.business.FortuneManagerImpl");
069: gameManager = GameManagerFactory
070: .getGameManager("poker.business.GameManagerImpl");
071:
072: fortuneManager.addFortune("Who's there?!");
073: fortuneManager.addFortune("What do you want?!");
074: fortuneManager
075: .addFortune("Don't come in here with loco motives!");
076: fortuneManager.addFortune("Whats the secret knock?!");
077: fortuneManager.addFortune("I don't like your looks?!");
078: fortuneManager
079: .addFortune("Come to play poker or tiddly winks?");
080: fortuneManager
081: .addFortune("BEA sure your app runs this nice!");
082: fortuneManager.addFortune("Watch your step, pal...");
083: fortuneManager.addFortune("Are you talking to me?");
084: fortuneManager
085: .addFortune("I'll J-Run your ass right outta town!");
086: fortuneManager.addFortune("Feeling lucky? I hope so..");
087: } catch (Exception e) {
088:
089: }
090: //This is tells the gameManager to use the DB instead of memory.
091: //FIX: Still need to add the useDB key into the
092: // Poker.conf configuration file..
093:
094: try {
095: gameManager.setUseDB(useDB);
096: } catch (Exception e) {
097: logChannel.write(Logger.INFO, "EnhyDraw! DB errror:"
098: + e.toString());
099: //There was a problem with the DB init
100: }
101:
102: if (logChannel != null)
103: logChannel.write(Logger.INFO,
104: "EnhyDraw Poker now starting!");
105: state = RUNNING;
106: }
107:
108: /**
109: * This is an optional function, used only by the Multiserver's graphical
110: * administration. This bit of HTML appears in the status page for this
111: * application. In this case, it displays the House Statistics
112: * which include total earnings, total players, etc.
113: *
114: * @return HTML that is displayed in the status page of the Multiserver.
115: */
116: public String toHtml() {
117:
118: GameManager g = GameManagerFactory
119: .getGameManager("poker.business.GameManagerImpl");
120:
121: String n = new Integer(gameManager.getCount()).toString();
122: String m = "Welcome to Larry and Daryl's EnhyDraw Poker!<br>";
123: m += "<table border=\"1\" cellpadding=\"3\" cellspacing=\"0\"";
124: m += "width=\"271\"><tr><td width=\"171\">Total Players Cataloged";
125: m += "</td><td width=\"84\">" + g.getTotalPlayers()
126: + "</td></tr><tr>";
127: m += "<td width=\"171\">Total Hands Dealt</td>";
128: m += "<td width=\"84\">" + g.getTotalHandsDealt()
129: + "</td></tr><tr>";
130: m += "<td width=\"171\">Total Hands Won</td>";
131: m += "<td width=\"84\">" + g.getTotalHandsWon()
132: + "</td></tr><tr>";
133: m += "<td width=\"171\">Total Hands Lost</td>";
134: m += "<td width=\"84\">" + g.getTotalHandsLost()
135: + "</td></tr><tr>";
136: m += "<td width=\"171\">Total Server Profit</td>";
137: m += "<td width=\"84\">" + g.getHouseProfit()
138: + "</td></tr><tr>";
139: m += "<td width=\"171\">Total Players Bankrupt</td>";
140: m += "<td width=\"84\">" + g.getTotalBankrupt()
141: + "</td></tr></table>";
142: m += "</div>";
143: return m;
144: }
145:
146: /**
147: * Return the game manager for this application.
148: */
149: public GameManager getGameManager() {
150: return gameManager;
151: }
152:
153: public FortuneManager getFortuneManager() {
154: return fortuneManager;
155: }
156:
157: /**
158: * Shutdown the application.
159: */
160: public void shutdown() {
161: super .shutdown();
162: }
163:
164: /**
165: * This method pre processes all requests
166: */
167: public boolean requestPreprocessor(HttpPresentationComms comms)
168: throws Exception {
169: super .requestPreprocessor(comms);
170:
171: if (!(comms.request.getRequestURI().toLowerCase().endsWith(
172: ".gif") || comms.request.getRequestURI().toLowerCase()
173: .endsWith(".jpg")))
174: comms.session.getSessionData().set("app", this );
175: String pp = comms.request.getApplicationPath();
176: if (!pp.endsWith("/"))
177: pp += "/";
178: String loginDir = pp + "login/";
179: String mediaDir = pp + "media/";
180: String page = comms.request.getRequestURI();
181: if (page.startsWith(loginDir) || page.startsWith(mediaDir)) {
182: /*
183: * Let them go to the login and logout areas whether or not
184: * they are logged in. Also let them get media on welcomepage.
185: */
186: return false;
187: } else {
188:
189: //We need to allow poker_pres to be dynamic , so if the requested url is poker_pres user dont need to be logged
190: String uri = comms.request.getRequestURI();
191: boolean is = uri.startsWith("/poker_pres");
192:
193: /*
194: * All other pages require the user to be logged in.
195: */
196: if (is)
197:
198: return false;
199:
200: else {
201: if (comms.session.getUser() != null)
202: // It's ok, they are logged in already.
203: return false;
204: else {
205: // They are not logged in! Redirect to login page.
206: String url = pp + "login/StartPresentation.po";
207: throw new ClientPageRedirectException(url);
208: }
209: }
210: }
211: }
212: }
|