⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 serveraddresssetup.java

📁 Vyger offers a D & D and Rogue-like environment in a graphical online roleplay game.
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        // File Tranfer Working Directory :
           JPanel group6 = new JPanel(new GridLayout(2,1,0,0));
           group6.setAlignmentX(LEFT_ALIGNMENT);
           group6.setBackground(Color.white);

           JLabel text6 = new JLabel("Enter your command line's working directory : ");
           text6.setAlignmentX(LEFT_ALIGNMENT);

           String cmdWorkDirList[] = {
           	   ServerDirector.getRemoteServersProperties().getProperty("transfer.fileTransferWorkingDir",""),
           	   "../bin/win32",
           	   "../bin/unix"
           	   };

           c_workdir = new JComboBox(cmdWorkDirList);
           c_workdir.setEditable(true);
           c_workdir.setAlignmentX(LEFT_ALIGNMENT);
           group6.add( text6 );
           group6.add( c_workdir );
           stepPanel.add( group6 );
       }

     /* -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  */

     /** Called each time the step is shown on screen.
      */
       protected void onShow(Object context, JWizard wizard) {
       }

     /* -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  */

     /** Called when the "Next" button is clicked.
      *  Use the wizard's setNextStep() method to set the next step to be displayed.
      *  @return return true to validate the "Next" button action, false to cancel it...
      */
       protected boolean onNext(Object context, JWizard wizard) {

              int value = JOptionPane.showConfirmDialog(null, "Save this config ? (required for transfer)", "Server Address Config", JOptionPane.YES_NO_OPTION);

              if( value != JOptionPane.YES_OPTION ) {
                  wizard.setNextStep(  TransferWizardStep.getStaticParameters()  );
                  return true;
              }

       	      password = new String(t_passw.getPassword());

       	   // 1 - we retrieve the data and save it to disk.
       	      ServerDirector.getRemoteServersProperties().setProperty( "transfer.serverHomeLogin", t_login.getText() );
       	      ServerDirector.getRemoteServersProperties().setProperty( "transfer.fileTransferProgram", c_prog.getSelectedItem().toString() );
       	      ServerDirector.getRemoteServersProperties().setProperty( "tranfer.fileTransferOptions", c_options.getSelectedItem().toString() );
       	      ServerDirector.getRemoteServersProperties().setProperty( "transfer.fileTransferWorkingDir", c_workdir.getSelectedItem().toString() );

              if( !ServerDirector.getResourceManager().saveText( serverAddressFile, t_ipAddress.getText() ) ) {
                  JOptionPane.showMessageDialog( null, "Failed to save IP address to\n"+serverAddressFile,
                                                        "Error", JOptionPane.ERROR_MESSAGE);
                  return false;
              }

           // 2 - we move on to the next step
              wizard.setNextStep(  TransferWizardStep.getStaticParameters()  );
              return true;
       }

     /* -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  */

     /** Called when Previous button is clicked.
      *  Use the wizard's setNextStep() method to set the next step to be displayed.
      *  @return return true to validate the "Previous" button action, false to cancel it...
      */
       protected boolean onPrevious(Object context, JWizard wizard) {
             return false; // should never been reached
       }

     /* -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  */

    }

 /*------------------------------------------------------------------------------------*/

    public static class TransferWizardStep extends JWizardStep {
     /* -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  */

      /** Button To launch transfer
       */
        private JButton b_transfer;

     /* -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  */

     /** This is a static JWizardStep, to build it more simply this method
      *  returns the JWizardStepParameters needed for the JWizard.
      */
       public static JWizardStepParameters getStaticParameters() {
          JWizardStepParameters param = new JWizardStepParameters( 
                          "wotlas.server.setup.ServerAddressSetup$TransferWizardStep",
                          "Server Config Transfer" );

          param.setIsLastStep(true);
          return param;
       }

     /* -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  */
     
     /** Constructor.
      */
       public TransferWizardStep() {
           super();

           JPanel group1 = new JPanel(new BorderLayout());
           group1.setAlignmentX(LEFT_ALIGNMENT);
           group1.setBackground(Color.white);
           JTextArea taInfo = new JTextArea("\n\n\n      We will now run the command line you entered in the previous step. "
                                    +"It will send your 'server-"+serverID+".cfg.adr' file to the "
                                    +"web server hosting the following URL : "
                                    +ServerDirector.getRemoteServersProperties().getProperty("info.remoteServerHomeURL")
                                    +"\n\n      Your '.adr' file will be available at this URL. "
                                    +"This way other servers/client will be able to discover your server and connect to it.\n\n"
                                    +"If the transfer doesn't work take a look at server-side questions in our FAQ.\n\n");

           taInfo.setAlignmentX(LEFT_ALIGNMENT);
           taInfo.setLineWrap(true);
           taInfo.setWrapStyleWord(true);
           taInfo.setEditable(false);
           taInfo.setBackground(Color.white);
           group1.add( taInfo, BorderLayout.NORTH );

           b_transfer = new JButton("Click here to launch file tranfer !");
           b_transfer.setPreferredSize(new Dimension(250,30));
           group1.add( b_transfer, BorderLayout.SOUTH );
           add(group1);

           b_transfer.addActionListener(new ActionListener()
           {
              public void actionPerformed (ActionEvent e)
              {
                 // We get the full program path
                    StringBuffer fullCmd = new StringBuffer("");
                    boolean wrapFilePath = false; // need to wrap file path between " " ? (winXP needs it)

                    String prog = ServerDirector.getRemoteServersProperties().getProperty("transfer.fileTransferProgram","");

                    if( prog.startsWith("\"") && prog.endsWith("\"") ) {
                        wrapFilePath = true;
                        fullCmd.append("\"");
                        prog = prog.substring(1,prog.length()-1);
                    }

                    try{
                      fullCmd.append( new File( prog ).getCanonicalPath() );
                    }catch(Exception ex ) {
                      ex.printStackTrace();
                      fullCmd.append( prog );
                    }

                    if(wrapFilePath)
                        fullCmd.append("\" ");
                    else
                        fullCmd.append(" "); // separator between program name & options

                 // We check the options command
                    String cmd = ServerDirector.getRemoteServersProperties().getProperty("tranfer.fileTransferOptions","");
                    cmd += " "; // makes our job easier
                 
                    if( cmd.indexOf("$FILE$")<0 ) {
                        JOptionPane.showMessageDialog( null, "No $FILE$ tag found in command line.",
                                                        "Error", JOptionPane.ERROR_MESSAGE);
                    	return;
                    }

                    if( cmd.indexOf("$LOGIN$")<0 ) {
                        JOptionPane.showMessageDialog( null, "No $LOGIN$ tag found in command line.",
                                                        "Error", JOptionPane.ERROR_MESSAGE);
                    	return;
                    }

                    if( cmd.indexOf("$PASSW$")<0 ) {
                        JOptionPane.showMessageDialog( null, "No $PASSW$ tag found in command line.",
                                                        "Error", JOptionPane.ERROR_MESSAGE);
                    	return;
                    }

                 // We complete the options command
                    int ind1 = cmd.indexOf("$FILE$");

                    fullCmd.append( cmd.substring(0,ind1) );

                    if(wrapFilePath)
                       fullCmd.append("\""); // beginning " wrapper

                    try{
                       fullCmd.append( new File(serverAddressFile).getCanonicalPath() );
                    }catch(Exception ex ) {
                       ex.printStackTrace();
                       fullCmd.append( new File(serverAddressFile).getAbsolutePath() );
                    }

                    if(wrapFilePath)
                       fullCmd.append("\""); // ending " wrapper

                    fullCmd.append( cmd.substring(ind1+6,cmd.length()) );
                    cmd = fullCmd.toString();
                    fullCmd = new StringBuffer("");

                    ind1 = cmd.indexOf("$LOGIN$");

                    fullCmd.append( cmd.substring(0,ind1) );
                    fullCmd.append( ServerDirector.getRemoteServersProperties().getProperty("transfer.serverHomeLogin","") );
                    fullCmd.append( cmd.substring(ind1+7,cmd.length() ) );
                    cmd = fullCmd.toString();
                    fullCmd = new StringBuffer("");

                    ind1 = cmd.indexOf("$PASSW$");

                    fullCmd.append( cmd.substring(0,ind1) );
                    fullCmd.append( password );
                    fullCmd.append( cmd.substring(ind1+7,cmd.length() ) );

                 // Runtime... we execute the transfert command
                    int result=1;
                    String workingDir = ServerDirector.getRemoteServersProperties().getProperty("transfer.fileTransferWorkingDir");
                    File workingDirPath = null;
                    
                    if(workingDir.length()!=0)
                       workingDirPath = new File(workingDir);

                    Debug.signal(Debug.NOTICE,null,"Command run :\n"+cmd);
                    System.out.println("\nThis is the command we are trying to run (the $PASSW$ has been replaced by your password) :\n\n");
                    System.out.println(""+cmd);

                    try{
                       Process pr = Runtime.getRuntime().exec( fullCmd.toString(), null, workingDirPath );
                       result = pr.waitFor();
                    }
                    catch( Exception ex ) {
                        JOptionPane.showMessageDialog( null, "Command Line Failed :\n"+ex.getMessage(),
                                                        "Error", JOptionPane.ERROR_MESSAGE);
                        return;
                    }

                    if(result==0)
                        JOptionPane.showMessageDialog( null, "Transfer done ! You can\nnow start your server!",
                                                       "Success", JOptionPane.INFORMATION_MESSAGE);
                    else
                        JOptionPane.showMessageDialog( null, "Transfer has failed. Please check (1) if the destination\n"
                                                            +"web server is running, (2) if you have setup your firewall\n"
                                                            +"properly, (3) if the command line is correct, (4) for pscp\n"
                                                            +"users the encryption key of your target web server may have\n"
                                                            +"changed, try to use pscp in a shell window to connect to\n"
                                                            +"your web server, (5) ask the wotlas manager to check your\n"
                                                            +"rights on the web server.",
                                                        "Error", JOptionPane.ERROR_MESSAGE);
              }
           });
       }

     /* -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  */

     /** Called each time the step is shown on screen.
      */
       protected void onShow(Object context, JWizard wizard) {
       }

     /* -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  */

     /** Called when the "Next" button is clicked.
      *  Use the wizard's setNextStep() method to set the next step to be displayed.
      *  @return return true to validate the "Next" button action, false to cancel it...
      */
       protected boolean onNext(Object context, JWizard wizard) {
              return true;
       }

     /* -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  */

     /** Called when Previous button is clicked.
      *  Use the wizard's setNextStep() method to set the next step to be displayed.
      *  @return return true to validate the "Previous" button action, false to cancel it...
      */
       protected boolean onPrevious(Object context, JWizard wizard) {
           // we return to the previous step
              wizard.setNextStep(  AddressWizardStep.getStaticParameters()  );
              return true;
       }

     /* -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  */

    }

 /*------------------------------------------------------------------------------------*/

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -