[Icemud-commits] IceMUD/src/mud/server Connection.java,1.8,1.9
Status: Alpha
Brought to you by:
gamerscloset
From: <jc...@us...> - 2003-12-12 18:36:33
|
Update of /cvsroot/icemud/IceMUD/src/mud/server In directory sc8-pr-cvs1:/tmp/cvs-serv14629 Modified Files: Connection.java Log Message: Fixed the way in which the player name is chosen. Index: Connection.java =================================================================== RCS file: /cvsroot/icemud/IceMUD/src/mud/server/Connection.java,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** Connection.java 31 Oct 2003 16:28:44 -0000 1.8 --- Connection.java 12 Dec 2003 18:36:29 -0000 1.9 *************** *** 53,57 **** mSocket.setTcpNoDelay(true); mSocket.setSoLinger(false, 0); ! Connection.mGUI = mGUI; mClient = new Interactor(mSocket); } --- 53,57 ---- mSocket.setTcpNoDelay(true); mSocket.setSoLinger(false, 0); ! this.mGUI = mGUI; mClient = new Interactor(mSocket); } *************** *** 105,149 **** private void doLogin() throws SocketException, Exception { ! int mUserID = 0; ! boolean okuser = false; ! ! while (mUser == null && !okuser) { ! mClient.print("By what name do you wish to be known? "); ! if (mClient == null) { ! java.util.logging.Logger.getLogger("warning").logp(java.util.logging.Level.WARNING, ! "Connection", "doLogin","[Warning] Socket was null in doLogin()"); ! return; ! } ! String user = Text.filterAlpha(mClient.readln()); ! ! if (!user.equals("")) { ! user = user.substring(0,1).toUpperCase() + user.substring(1); ! mClient.println(""); ! mUser = DBTools.getUser(user); ! if (mUser == null) { ! okuser = doNewPlayer(user); ! ! } else { ! okuser = doExistingPlayer(user); ! } ! ! } else { ! mClient.println("Huh?"); ! } ! if (okuser) { ! System.out.println("User " + mUser.getName() + " has just logged in."); ! mGUI.setTableValue(mUser.getName() + " playing...", getRow(), 2); ! } else { ! mUser = null; ! } } - } ! private boolean doNewPlayer(String user) throws IOException { - user = getName(user); mUser = DBTools.getUser(user); if (mUser != null) --- 105,129 ---- private void doLogin() throws SocketException, Exception { ! if (mClient == null) { ! java.util.logging.Logger.getLogger("warning").logp(java.util.logging.Level.WARNING, ! "Connection", "doLogin","[Warning] Socket was null in doLogin()"); ! return; ! } ! ! mClient.print("By what name do you wish to be known? "); ! String user = getNameInput(); ! doPlayer(user); ! if (mUser != null) { ! System.out.println("User " + mUser.getName() + " has just logged in."); ! mGUI.setTableValue(mUser.getName() + " playing...", getRow(), 2); ! } else { ! System.err.println("Error getting user input on Connection "+this.getName()); } } ! private boolean doPlayer(String user) throws IOException { mUser = DBTools.getUser(user); if (mUser != null) *************** *** 201,205 **** --- 181,229 ---- return true; } + + private boolean doExistingPlayer(String user) throws IOException { + mUserID = mUser.getUserID(); + mClient.print("Password: "); + String pass = mClient.readln(); + + mClient.println(""); + + if (!pass.equals("")) { + if (DBTools.checkUser(user, pass) != -1) { + mClient.println("Welcome back " + user + "!"); + return true; + } else { + mUserID = 0; + mClient.println("Wrong Password!"); + return false; + } + } else + mClient.println("Nice try!"); + return false; + } + + private String getNameInput() throws IOException{ + String txtIn; + while (true) { + txtIn = Text.filterAlpha(mClient.readln()); + while (txtIn.equals("")) { + mClient.print("Huh? "); + txtIn = Text.filterAlpha(mClient.readln()); + } + txtIn = txtIn.substring(0, 1).toUpperCase() + txtIn.substring(1); + + mClient.print("Did I get that right, " + txtIn + " (Y/N)? "); + int iAnswer = parseYesNoAnswer(); + switch (iAnswer) { + case 0 : return txtIn; + case 1 : { + mClient.print("Please re-enter your name: "); + break; + } + } + } + } + private String getPassword(String user) throws IOException { *************** *** 229,265 **** } - private String getName(String user) throws IOException { - - if (user.equals("")) { - mClient.print("Huh?"); - return getName(mClient.readln()); - } - user = user.substring(0, 1).toUpperCase() + user.substring(1); - while (true) { - - if (user.equals("")) { - mClient.print("Huh?"); - return getName(mClient.readln()); - } - - mClient.print("Did I get that right, " + user + " (Y/N)? "); - int iAnswer = parseYesNo(mClient.readln()); - switch (iAnswer) { - case 0 : - return user; - case 1 : - mClient.print("Okay, what IS it, then? "); - user = mClient.readln(); - break; - case -1 : - mClient.println(""); - mClient.println("Please type Yes or No: "); - break; - } - mClient.println(""); - } - - } - private boolean getSex() throws IOException { --- 253,256 ---- *************** *** 277,297 **** } ! public static synchronized int parseYesNo(String inAnswer) { ! try { ! char arg = inAnswer.toLowerCase().charAt(0); ! switch (arg) { ! case 'y' : ! return 0; ! case 'n' : ! return 1; ! default : ! return -1; } ! } catch (Exception e) { ! return -1; } } ! /* * The code to interpret a sex letter --- 268,284 ---- } ! public synchronized int parseYesNoAnswer() throws IOException { ! char arg = mClient.readln().toLowerCase().charAt(0); ! ! while (true) { switch (arg) { ! case 'y' : return 0; ! case 'n' : return 1; } ! mClient.print("Please enter either y or n: "); ! arg = mClient.readln().toLowerCase().charAt(0); } } ! /* * The code to interpret a sex letter *************** *** 342,368 **** } - private boolean doExistingPlayer(String user) throws IOException { - mUserID = mUser.getUserID(); - - mClient.print("Password: "); - String pass = mClient.readln(); - - mClient.println(""); - - if (!pass.equals("")) { - if (DBTools.checkUser(user, pass) != -1) { - mClient.println("Welcome back " + user + "!"); - return true; - } else { - mUserID = 0; - mClient.println("Wrong Password!"); - return false; - } - } else - mClient.println("Nice try!"); - return false; - - } - public void println(String s) throws IOException { new PrintWriter(mSocket.getOutputStream(), true).println(s); --- 329,332 ---- *************** *** 372,376 **** protected Interactor mClient; protected boolean mAlive = true; ! protected static ServerPanel mGUI; private int mUserID; --- 336,340 ---- protected Interactor mClient; protected boolean mAlive = true; ! protected ServerPanel mGUI; private int mUserID; |