📄 accountbuilder.java
字号:
propsKey[i].length() );
// 2 - we get the methodName & text to analyze
String methodName = serverParameters.getStepPropertiesValue()[i];
String text = clientParameters.getProperty("init."+suffix);
// 3 - Check what we have
if(pattern.length()==0 || text==null || methodName.length()==0)
continue; // ignore this bad entry
// 4 - Proceed...
int ind = text.indexOf(pattern);
if(ind<0) continue; // pattern not found
StringBuffer buf = new StringBuffer(text.substring(0,ind));
String result = invokeMethod(methodName);
if(result==null) result="#ERROR#";
buf.append(result);
buf.append( text.substring(ind+pattern.length(),text.length()) );
// 5 - Save our modif
clientParameters.setProperty( "init."+suffix, buf.toString() );
}
}
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
/** A small method to report a step error.
*/
private void sendStepError( String message ) {
connection.queueMessage( new StepErrorMessage( message ) );
Debug.signal( Debug.ERROR, this, "An error occured during account creation : "+message );
}
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
/** To cancel the account's creation.
*/
public void cancelCreation() {
Debug.signal( Debug.NOTICE, this, "Account Creation cancelled..." );
connection.close();
}
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
/** Method called to create the account
* This method sends back to the client a AccountCreationEnded message on success.
*/
public void createAccount() throws AccountException {
AccountManager accountManager = ServerDirector.getDataManager().getAccountManager();
// 1 - We finalize inits
account.setPlayer( player );
account.setLocalClientID( accountServer.getNewLocalClientID() );
account.setOriginalServerID( ServerDirector.getServerID() );
account.setLastConnectionTimeNow();
player.setPrimaryKey( account.getAccountName() );
Inventory inventory = player.getBasicChar().createInventory();
ServerObjectManager objectManager = new ServerObjectManager();
objectManager.setInventory( inventory );
player.setObjectManager( objectManager );
// 2 - We add the account to the game server
if( accountManager.checkAccountName( account.getAccountName() ) )
throw new AccountException("Internal Error. This server was badly configurated.\nPlease mail this server's administrator ! (code: #dupAcID)");
if( accountManager.createAccount( account ) ) {
// we add the player to the world...
player.init();
Debug.signal( Debug.NOTICE, this, "Client account created... ("+player.getPrimaryKey()+")." );
// we send a Success Message
connection.queueMessage( new AccountCreationEndedMessage(account.getLocalClientID(),
account.getOriginalServerID(),
account.getLogin(),
account.getPassword(),
player.getFullPlayerName() ) );
// And close the connection
connection.close();
}
else {
// Account not created for some reason
// we announce the bad news to the client
// but we don't close the connection...
throw new AccountException("Internal Error. This server was badly configurated.\nPlease mail this server's administrator ! (code: #creFaiDisk)");
}
}
/*------------------------------------------------------------------------------------*/
/*------------------------------------------------------------------------------------*/
/***
*** METHODS THAT CAN BE INVOKED DYNAMICALY
***
*** Their prototype must be : public void setXXXX( String data ) throws AccountException
***
***/
/** Method to set the player's login.
*/
public void setLogin( String data ) throws AccountException {
account.setLogin( data );
}
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
/** Method to set the player's password.
*/
public void setPassword( String data ) throws AccountException {
account.setPassword( data );
}
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
/** Method called to set the WotCharacterClass
*/
public void setWotCharacterClass( String data ) throws AccountException {
// 1 - Select Class
String className="wotlas.common.character.";
if(data.equals("Aes Sedai"))
className += "AesSedai";
else if(data.equals("Warder"))
className += "Warder";
else if(data.equals("Children of the Light"))
className += "ChildrenOfTheLight";
else if(data.equals("Wolf Brother"))
className += "WolfBrother";
else if(data.equals("Asha'man"))
className += "Ashaman";
else if(data.equals("Aiel"))
className += "AielWarrior";
else if(data.equals("Darkfriend"))
return;
else if(data.equals("Special Characters"))
return;
else
throw new AccountException("Unknown character class !");
// 2 - Create Instance
Object obj = Tools.getInstance( className );
if( obj==null || !(obj instanceof BasicChar) )
throw new AccountException("Error during character class creation !");
// 3 - Set the player's character
BasicChar wotCharacter = (BasicChar) obj;
player.setBasicChar( wotCharacter );
}
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
/** Method called to set the WotCharacterClass rank.
*/
public void setWotCharacterRank( String data ) throws AccountException {
// 1 - Set the rank
BasicChar wotCharacter = (BasicChar) player.getBasicChar();
if(wotCharacter==null)
throw new AccountException("No character created !");
wotCharacter.setCharacterRank(data);
// 2 - check that it was set
if( !data.equals( wotCharacter.getCharacterRank() ) )
throw new AccountException("Unknown rank for this character class !");
}
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
/** Method called to set the player hair color. (for humans only).
*/
public void setHairColor( String data ) throws AccountException {
// 1 - Get Human character
BasicChar wotCharacter = (BasicChar) player.getBasicChar();
if(wotCharacter==null)
throw new AccountException("No character created !");
if( ! (wotCharacter instanceof Human) )
throw new AccountException("Your character is not Human !");
Human human = (Human) wotCharacter;
human.setHairColor(data);
// 2 - check that it was set
if( !data.equals( human.getHairColor() ) )
throw new AccountException("Unknown hair color !");
}
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
/** Method called to set the player's name.
*/
public void setPlayerName( String data ) throws AccountException {
data = data.trim();
if(data.length()>30)
throw new AccountException("Your nickname should have less than 30 letters !");
player.setPlayerName(data);
}
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
/** Method called to set the player's full name.
*/
public void setFullPlayerName( String data ) throws AccountException {
data = data.trim();
if(data.length()>30)
throw new AccountException("Your full name should have less than 30 letters !");
if(data.length()<5)
throw new AccountException("Your full name should have more than 4 letters !");
player.setFullPlayerName(data);
}
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
/** Method called to set the player's email.
*/
public void setEmail( String data ) throws AccountException {
account.setEmail(data);
}
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
/** Method called to set the player's past.
*/
public void setPlayerPast( String data ) throws AccountException {
player.setPlayerPast(data);
}
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
/** Method called to set the player's past option.
*/
public void setPlayerPastOption( String data ) throws AccountException {
if(data.equals("true"))
player.setPlayerPast(""); // past will be set later
}
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
/** Method called to create special characters
*/
public void setSpecialCharacter( String data ) throws AccountException {
Properties props = ServerDirector.getServerProperties();
if( data.equals( props.getProperty("key.shaitan","shaitan") ) ) {
// We create a great lord of the dark...
player.setBasicChar(new DarkOne());
setPlayerName("Great Lord Of the Dark");
setFullPlayerName("Shai'tan");
setPlayerPast("SERVE ME OR DIE !");
WotlasLocation prison = new WotlasLocation(0,2,0,1,0);
player.setLocation(prison);
player.setX(50);
player.setY(100);
}
else if(data.equals( props.getProperty("key.amyrlin","amyrlin") )) {
// We create an Amyrlin...
player.setBasicChar(new AesSedai());
player.getBasicChar().setCharacterRank("Amyrlin");
}
else if(data.equals( props.getProperty("key.chronicles","chronicles") )) {
// We create a Keeper of chronicles...
player.setBasicChar(new AesSedai());
player.getBasicChar().setCharacterRank("Keeper of the Chronicles");
}
else if(data.equals( props.getProperty("key.mhael","mhael") )) {
// We create a M'Hael...
player.setBasicChar(new Ashaman());
player.getBasicChar().setCharacterRank("M'Hael");
}
else
throw new AccountException("Wrong Special Character Key !");
}
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
/** Method called to set a warder's cloak color. (for warders and blade masters only).
*/
public void setCloakColor( String data ) throws AccountException {
// 1 - Get Human character
BasicChar wotCharacter = (BasicChar) player.getBasicChar();
if(wotCharacter==null)
throw new AccountException("No character created !");
if( ! (wotCharacter instanceof Warder) )
throw new AccountException("Your character is not a Warder !");
Warder warder = (Warder) wotCharacter;
warder.setCloakColor(data);
// 2 - check that it was set
if( warder.getCloakColor()==null )
throw new AccountException("Failed to set cloak color : "+data);
}
/*------------------------------------------------------------------------------------*/
/*------------------------------------------------------------------------------------*/
/** To get the server Name.
*/
public String getServerName() throws AccountException {
return ServerDirector.getServerManager().getServerConfig().getServerSymbolicName();
}
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
/** To get the admin email.
*/
public String getAdminEmail() throws AccountException {
return ServerDirector.getServerManager().getServerConfig().getAdminEmail();
}
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
/** To get the player account summary.
*/
public String getAccountSummary() throws AccountException {
StringBuffer str = new StringBuffer("");
str.append(" Player Name \t: ");
str.append( player.getFullPlayerName() );
str.append("\n Player Class \t: ");
str.append( player.getBasicChar().getCommunityName() );
str.append("\n Player Rank \t: ");
str.append( player.getBasicChar().getCharacterRank() );
return str.toString();
}
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -