📄 clientmanager.java
字号:
formPanel_02_right.add(pfield1);
ALabel alabel2 = new ALabel(currentProfileConfig.getLogin()+"-"+currentProfileConfig.getKey());
alabel2.setFont(f.deriveFont(16f));
formPanel_02_right.add(alabel2);
mainPanel_02.add(formPanel_02_right);
leftPanel.add(mainPanel_02);
// *** Right Panel ***
b_delProfile.addActionListener(new ActionListener() {
public void actionPerformed (ActionEvent e) {
char charPasswd[] = pfield1.getPassword();
String passwd = "";
if (charPasswd.length < 4) {
JOptionPane.showMessageDialog( ClientManager.this, "Password must have at least 5 characters !", "New Password", JOptionPane.ERROR_MESSAGE);
} else {
for (int i=0; i<charPasswd.length; i++) {
passwd += charPasswd[i];
}
currentServerConfig = serverConfigManager.getServerConfig(currentProfileConfig.getServerID());
JDeleteAccountDialog jdconnect = new JDeleteAccountDialog( ClientManager.this,
currentServerConfig.getServerName(), currentServerConfig.getAccountServerPort(),
currentServerConfig.getServerID(),
currentProfileConfig.getLogin()+"-"+
currentProfileConfig.getOriginalServerID()+"-"+
currentProfileConfig.getLocalClientID(), passwd );
if ( jdconnect.hasSucceeded() ) {
Debug.signal( Debug.NOTICE, this, "Account deleted.");
// Save accounts informations
if( !profileConfigList.removeProfile(currentProfileConfig) )
Debug.signal( Debug.ERROR, this, "Failed to delete player profile !" );
else
profileConfigList.save();
}
start(MAIN_SCREEN); // return to main screen
}
}
}
);
rightPanel.add(b_delProfile);
b_cancel.addActionListener(new ActionListener() {
public void actionPerformed (ActionEvent e) {
start(MAIN_SCREEN);
}
});
rightPanel.add(b_cancel);
// *** Adding the panels ***
setLeftPanel(leftPanel);
setRightPanel(rightPanel);
showScreen();
break;
// *********************************
// *** Recover an existing account ****
// *********************************
case RECOVER_ACCOUNT_SCREEN:
setTitle("Wotlas - Recover Login");
// Create panels
leftPanel = new JPanel();
leftPanel.setLayout(new BoxLayout(leftPanel, BoxLayout.Y_AXIS));
rightPanel = new JPanel();
// Create buttons
b_ok = new JButton(im_okup);
b_ok.setRolloverIcon(im_okdo);
b_ok.setPressedIcon(im_okdo);
b_ok.setDisabledIcon(im_okun);
b_ok.setBorderPainted(false);
b_ok.setContentAreaFilled(false);
b_ok.setFocusPainted(false);
b_cancel = new JButton(im_cancelup);
b_cancel.setRolloverIcon(im_canceldo);
b_cancel.setPressedIcon(im_canceldo);
b_cancel.setDisabledIcon(im_cancelun);
b_cancel.setBorderPainted(false);
b_cancel.setContentAreaFilled(false);
b_cancel.setFocusPainted(false);
// *** Left JPanel ***
label1 = new ALabel("To recover an existing account, please enter :");
label1.setAlignmentX(Component.CENTER_ALIGNMENT);
label1.setFont(f.deriveFont(18f));
leftPanel.add(label1);
leftPanel.add(Box.createRigidArea(new Dimension(0,10)));
JPanel mainPanel_03 = new JPanel();
mainPanel_03.setBackground(Color.white);
JPanel formPanel_03_left = new JPanel(new GridLayout(2,1,5,5));
formPanel_03_left.setBackground(Color.white);
formPanel_03_left.add(new JLabel(ClientDirector.getResourceManager().getImageIcon("your-key.gif")));
formPanel_03_left.add(new JLabel(ClientDirector.getResourceManager().getImageIcon("enter-password.gif")));
mainPanel_03.add(formPanel_03_left);
JPanel formPanel_03_right = new JPanel(new GridLayout(2,1,5,10));
formPanel_03_right.setBackground(Color.white);
atf_key = new ATextField(10);
formPanel_03_right.add(atf_key);
pfield1 = new APasswordField(10);
pfield1.setFont(f.deriveFont(18f));
pfield1.addKeyListener(new KeyAdapter() {
public void keyReleased(KeyEvent e) {
if ( e.getKeyCode()==KeyEvent.VK_ENTER )
b_ok.doClick();
}
});
formPanel_03_right.add(pfield1);
mainPanel_03.add(formPanel_03_right);
leftPanel.add(mainPanel_03);
// *** Right Panel ***
b_ok.addActionListener(new ActionListener() {
public void actionPerformed (ActionEvent e) {
char charPasswd[] = pfield1.getPassword();
if (charPasswd.length < 4) {
JOptionPane.showMessageDialog( ClientManager.this, "Password must have at least 5 characters !", "Password", JOptionPane.ERROR_MESSAGE);
} else {
currentProfileConfig = new ProfileConfig();
String tempKey = atf_key.getText();
int index = tempKey.indexOf('-');
if (index<0) {
JOptionPane.showMessageDialog( ClientManager.this, "Your key must have the following format : login-xx-yy.\nExample: bob-1-36", "Bad Format", JOptionPane.ERROR_MESSAGE);
start(MAIN_SCREEN);
return;
}
currentProfileConfig.setLogin(tempKey.substring(0,index));
currentProfileConfig.setPlayerName("");
currentProfileConfig.setPassword(new String(charPasswd));
tempKey = tempKey.substring(index+1);
index = tempKey.indexOf('-');
if (index<0) {
JOptionPane.showMessageDialog( ClientManager.this, "Your key must have the following format : login-xx-yy.\nExample: bob-1-36", "Bad Format", JOptionPane.ERROR_MESSAGE);
start(MAIN_SCREEN);
return;
}
try {
currentProfileConfig.setServerID(Integer.parseInt(tempKey.substring(0,index)));
currentProfileConfig.setOriginalServerID(Integer.parseInt(tempKey.substring(0,index)));
currentProfileConfig.setLocalClientID(Integer.parseInt(tempKey.substring(index+1)));
} catch (NumberFormatException nfes) {
JOptionPane.showMessageDialog( ClientManager.this, "Your key must have the following format : login-xx-yy.\nExample: bob-1-36", "Bad Format", JOptionPane.ERROR_MESSAGE);
start(MAIN_SCREEN);
return;
}
ClientDirector.getDataManager().setCurrentProfileConfig(currentProfileConfig);
currentServerConfig = serverConfigManager.getServerConfig(currentProfileConfig.getServerID());
if(currentServerConfig==null) {
JOptionPane.showMessageDialog( ClientManager.this, "Failed to find the associated server.", "ERROR", JOptionPane.ERROR_MESSAGE);
start(MAIN_SCREEN);
return;
}
JGameConnectionDialog jgconnect = new JGameConnectionDialog( ClientManager.this,
currentServerConfig.getServerName(), currentServerConfig.getGameServerPort(),
currentServerConfig.getServerID(),
currentProfileConfig.getLogin(), new String(charPasswd), currentProfileConfig.getLocalClientID(),
currentProfileConfig.getOriginalServerID(), ClientDirector.getDataManager());
if ( jgconnect.hasSucceeded() ) {
Debug.signal( Debug.NOTICE, null, "ClientManager connected to GameServer");
jgconnect.getConnection().queueMessage(new AccountRecoverMessage( atf_key.getText()) );
start(DATAMANAGER_DISPLAY);
} else {
Debug.signal( Debug.ERROR, this, "ClientManager ejected from GameServer");
start(MAIN_SCREEN);
}
}
}
}
);
rightPanel.add(b_ok);
b_cancel.addActionListener(new ActionListener() {
public void actionPerformed (ActionEvent e) {
start(MAIN_SCREEN);
}
}
);
rightPanel.add(b_cancel);
// *** Adding the panels ***
setLeftPanel(leftPanel);
setRightPanel(rightPanel);
showScreen();
break;
// ***********************************
// *** Connection to AccountServer ***
// ***********************************
case ACCOUNT_CREATION_SCREEN:
serverConfigManager.getLatestConfigFiles(this);
// Launching Wizard
hide();
JAccountCreationWizard accountCreationWz = new JAccountCreationWizard();
break;
// **************************************
// *** A new account has been created ***
// **************************************
case ACCOUNT_INFO_SCREEN:
setTitle("Wotlas - Account creation...");
if( currentProfileConfig==null ) {
start(MAIN_SCREEN);
break;
}
// Set the appropriate server config.
currentServerConfig = serverConfigManager.getServerConfig(currentProfileConfig.getServerID());
// Create panels
leftPanel = new JPanel();
//leftPanel.setLayout(new BoxLayout(leftPanel, BoxLayout.Y_AXIS));
leftPanel.setLayout(new GridLayout(1,1,5,5));
rightPanel = new JPanel(new FlowLayout(FlowLayout.CENTER, getRightWidth(), 10));
// Create buttons
b_ok = new JButton(im_okup);
b_ok.setRolloverIcon(im_okdo);
b_ok.setPressedIcon(im_okdo);
b_ok.setDisabledIcon(im_okun);
b_ok.setBorderPainted(false);
b_ok.setContentAreaFilled(false);
b_ok.setFocusPainted(false);
b_cancel = new JButton(im_cancelup);
b_cancel.setRolloverIcon(im_canceldo);
b_cancel.setPressedIcon(im_canceldo);
b_cancel.setDisabledIcon(im_cancelun);
b_cancel.setBorderPainted(false);
b_cancel.setContentAreaFilled(false);
b_cancel.setFocusPainted(false);
// *** Left Panel ***/
JEditorPane editorPane = new JEditorPane("text/html","<html>Your new account has been <br>"
+ "successfully created! <br>"
+ "Remember your key to access <br>"
+ "wotlas from anywhere : <b>" + currentProfileConfig.getLogin()+"-"+currentProfileConfig.getKey()
+ "</b><br>Click OK to enter WOTLAS....</html>");
leftPanel.add(editorPane, BorderLayout.CENTER);
editorPane.setEditable(false);
// *** Right Panel ***/
b_ok.addActionListener(new ActionListener() {
public void actionPerformed (ActionEvent e) {
JGameConnectionDialog jgconnect = new JGameConnectionDialog( ClientManager.this,
currentServerConfig.getServerName(), currentServerConfig.getGameServerPort(),
currentServerConfig.getServerID(),
currentProfileConfig.getLogin(), currentProfileConfig.getPassword(),
currentProfileConfig.getLocalClientID(), currentProfileConfig.getOriginalServerID(),
ClientDirector.getDataManager());
if ( jgconnect.hasSucceeded() ) {
Debug.signal( Debug.NOTICE, null, "ClientManager connected to GameServer");
start(DATAMANAGER_DISPLAY);
} else {
Debug.signal( Debug.ERROR, this, "ClientManager ejected from GameServer");
}
}
}
);
rightPanel.add(b_ok);
b_cancel.addActionListener(new ActionListener() {
public void actionPerformed (ActionEvent e) {
start(MAIN_SCREEN);
}
}
);
rightPanel.add(b_cancel);
// *** Adding the panels ***
setLeftPanel(leftPanel);
setRightPanel(rightPanel);
showScreen();
break;
// ********************
// *** Final screen ***
// ********************
case DATAMANAGER_DISPLAY:
hide();
Thread heavyProcessThread = new Thread() {
public void run() {
ClientDirector.getDataManager().showInterface();
}
};
heavyProcessThread.start();
break;
default:
// We should never arrive here
// --> return to main screen
start(MAIN_SCREEN);
}
}
/*------------------------------------------------------------------------------------*/
/** To add a new profile to the player's profile list. This method is called by
* the AccountCreationEndedMsgBehaviour when an account has been successfully created.
*/
public void addNewProfile( int clientID, int serverID, String login, String password, String playerName) {
currentProfileConfig = new ProfileConfig();
// Set profile data
currentProfileConfig.setPlayerName(playerName);
currentProfileConfig.setLogin(login);
currentProfileConfig.setPassword(password);
currentProfileConfig.setLocalClientID(clientID);
currentProfileConfig.setOriginalServerID(serverID);
currentProfileConfig.setServerID(serverID);
// Save profile informations
profileConfigList.addProfile(currentProfileConfig);
profileConfigList.save();
// Set Data Manager ready
ClientDirector.getDataManager().setCurrentProfileConfig(currentProfileConfig);
}
/*------------------------------------------------------------------------------------*/
/** Timer Event interception
* @param e supposed timer event
*/
public void actionPerformed( ActionEvent e) {
Debug.signal(Debug.WARNING,null,"Wotlas Web Server unreachable. Trying again... ("+nbTry+"/12)");
nbTry++;
}
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -