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

📄 serversetup.java

📁 Vyger offers a D & D and Rogue-like environment in a graphical online roleplay game.
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
           sconfPanel.setPreferredSize(new Dimension(350,800));
           setLayout( new BorderLayout() );

         // Server Symbolic Name
            ALabel label0 = new ALabel("Server symbolic name (can be any name) :");
            t_serverSymbolicName = new ATextField( config.getServerSymbolicName() );
            sconfPanel.add( label0 );
            sconfPanel.add( t_serverSymbolicName );

         // Server ID ( 0 means standalone )
            ALabel label2 = new ALabel("Server Id :");
            t_serverID = new ATextField( ""+config.getServerID() );
            t_serverID.setEditable(false);
            sconfPanel.add( label2 );
            sconfPanel.add( t_serverID );

         // Server description
            ALabel label3 = new ALabel("Server Description :");
            t_description = new ATextField( config.getDescription() );
            sconfPanel.add( label3 );
            sconfPanel.add( t_description );

         // Players starting location :
            ALabel label12 = new ALabel("Starting location for players :");
            c_worldStartLocation = new JComboBox( TOWNS_NAME );
            c_worldStartLocation.setEditable(false);

            for(int i=0; i<TOWNS_NAME.length; i++ ) {
                if(TOWNS_NEAR_POSITION[i][0]==config.getWorldFirstXPosition()
                   && TOWNS_NEAR_POSITION[i][1]==config.getWorldFirstYPosition()) {
                   // we found the previous location
                      c_worldStartLocation.setSelectedIndex(i);
                      break;
                }
            }

            sconfPanel.add( label12 );
            sconfPanel.add( c_worldStartLocation );

         // Location
            ALabel label4 = new ALabel("Server's country :");
            t_location = new ATextField( config.getLocation() );
            sconfPanel.add( label4 );
            sconfPanel.add( t_location );

         // Email
            ALabel label5 = new ALabel("Server Administrator Email :");
            t_adminEmail = new ATextField( config.getAdminEmail() );
            sconfPanel.add( label5 );
            sconfPanel.add( t_adminEmail );

         // Game Server Port
            ALabel label6 = new ALabel("Game Server Port :");
            t_gameServerPort = new ATextField( ""+config.getGameServerPort() );
            sconfPanel.add( label6 );
            sconfPanel.add( t_gameServerPort );

         // Account Server Port
            ALabel label7 = new ALabel("Account Server Port :");
            t_accountServerPort = new ATextField( ""+config.getAccountServerPort() );
            sconfPanel.add( label7 );
            sconfPanel.add( t_accountServerPort );

         // Gateway Server Port
            ALabel label8 = new ALabel("Gateway Server Port :");
            t_gatewayServerPort = new ATextField( ""+config.getGatewayServerPort() );
            sconfPanel.add( label8 );
            sconfPanel.add( t_gatewayServerPort );

         // maxNumberOfGameConnections
            ALabel label9 = new ALabel("Maximum number of connections on the Game Server:");
            t_maxNumberOfGameConnections = new ATextField( ""+config.getMaxNumberOfGameConnections() );
            sconfPanel.add( label9 );
            sconfPanel.add( t_maxNumberOfGameConnections );

         // maxNumberOfAccountConnections
            ALabel label10 = new ALabel("Maximum number of connections on the Account Server:");
            t_maxNumberOfAccountConnections = new ATextField( ""+config.getMaxNumberOfAccountConnections() );
            sconfPanel.add( label10 );
            sconfPanel.add( t_maxNumberOfAccountConnections );

         // maxNumberOfGatewayConnections
            ALabel label11 = new ALabel("Maximum number of connections on the Gateway Server:");
            t_maxNumberOfGatewayConnections = new ATextField( ""+config.getMaxNumberOfGatewayConnections() );
            sconfPanel.add( label11 );
            sconfPanel.add( t_maxNumberOfGatewayConnections );

         // ScrollPane to wrap the main panel
            JScrollPane scrollPane =  new JScrollPane( sconfPanel );
            scrollPane.setBorder(BorderFactory.createEmptyBorder(10,15,0,15));
            scrollPane.setBackground(Color.white);
            add( scrollPane, BorderLayout.CENTER );
       }

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

     /** 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) {

         // we retrieve the config's data
            config.setServerSymbolicName( t_serverSymbolicName.getText() );
            config.setServerName( null );
            config.setDescription( t_description.getText() );
            config.setLocation( t_location.getText() );
            config.setAdminEmail( t_adminEmail.getText() );
            config.setConfigVersion();

            try{
               int val1 = Integer.parseInt( t_serverID.getText() );
               int val2 = Integer.parseInt( t_accountServerPort.getText() );
               int val3 = Integer.parseInt( t_gameServerPort.getText() );
               int val4 = Integer.parseInt( t_gatewayServerPort.getText() );
               int val5 = Integer.parseInt( t_maxNumberOfGameConnections.getText() );
               int val6 = Integer.parseInt( t_maxNumberOfAccountConnections.getText() );
               int val7 = Integer.parseInt( t_maxNumberOfGatewayConnections.getText() );

               config.setServerID( val1 );
               config.setAccountServerPort( val2 );
               config.setGameServerPort( val3 );
               config.setGatewayServerPort( val4 );
               config.setMaxNumberOfGameConnections( val5 );
               config.setMaxNumberOfAccountConnections( val6 );
               config.setMaxNumberOfGatewayConnections( val7 );

               config.setWorldFirstXPosition( TOWNS_NEAR_POSITION[c_worldStartLocation.getSelectedIndex()][0] );
               config.setWorldFirstYPosition( TOWNS_NEAR_POSITION[c_worldStartLocation.getSelectedIndex()][1] );
            }
            catch(Exception ee) {
                  Debug.signal( Debug.ERROR, this, ""+ee );
                  JOptionPane.showMessageDialog( null, "Bad number format !","Error", JOptionPane.ERROR_MESSAGE);
                  return false;
            }

         // We save the config
            if( !serverConfigManager.saveServerConfig(config) ) {
                JOptionPane.showMessageDialog( null, "Failed to save server config in database",
                                               "Error", JOptionPane.ERROR_MESSAGE);
                return false;
            }

         // set this server as default ?
            int value = JOptionPane.showConfirmDialog(null, "Set this server as default ?", "Update Startup Config", JOptionPane.YES_NO_OPTION);

            if( value == JOptionPane.YES_OPTION )
                ServerDirector.getServerProperties().setProperty( "init.serverID", ""+serverID );

            wizard.setNextStep(  FinalWizardStep.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) {
            wizard.setNextStep(  ServerInterfaceWizardStep.getStaticParameters()  );
            return true;
       }

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

    }

 /*------------------------------------------------------------------------------------*/
 /**
  * Second Step of our JWizard. Register choices.
  */
  public static class FinalWizardStep extends JWizardStepInfo {

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

     /** 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.ServerSetup$FinalWizardStep",
                          "Server Config Saved" );

          param.setIsPrevButtonEnabled(true);
          param.setIsLastStep(true);
          param.setIsDynamic(true);

          if(serverID==0) {
             param.setProperty("init.info0", "\n      Your server config has been successfully saved."
                                           +" You can now start your server. Because your server is"
                                           +" local you don't need to use the setup program.");
          } else {
             param.setProperty("init.info0", "\n      Your server config has been successfully saved.\n\n"
                                           +"      You must now send it to the wotlas manager : just"
                                           +" attach the \""+ServerDirector.getResourceManager().getExternalServerConfigsDir()
                                           +"server-"+serverID+".cfg\" file"
                                           +" to a mail and send it to the address "
                                           +ServerDirector.getServerProperties().getProperty("info.remoteServerAdminEmail","")
                                           +". You will then receive the up- to-date universe data and be"
                                           +" able to start your server." );
          }

          return param;
       }

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

     /** Constructor.
      */
       public FinalWizardStep() {
           super();
       }

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

     /** 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) {
         // We create a default address file
           String text = "localhost";

           String publishAddress = ServerDirector.getServerProperties().getProperty("init.publishAddress");
           
           if( publishAddress!=null && publishAddress.length()!=0 )
               text = publishAddress;

           ServerDirector.getResourceManager().saveText(
                ServerDirector.getResourceManager().getExternalServerConfigsDir()
                +ServerConfigManager.SERVERS_PREFIX+serverID
                +ServerConfigManager.SERVERS_SUFFIX+ServerConfigManager.SERVERS_ADDRESS_SUFFIX,
                text );

           if( ServerDirector.getServerProperties().getProperty("init.automaticUpdate","").equals("false") )
               return true; // no need to configure script

           String oldScript = ServerAdminGUI.getTransferScript().getText();

           if( oldScript==null ) {
               Debug.signal( Debug.ERROR, this, "Failed to get transfer script !" );
               return true;
           }

           oldScript = FileTools.updateProperty( "SET SERVER_ID", ""+serverID, oldScript );

           ServerAdminGUI.getTransferScript().setText(oldScript);
           ServerAdminGUI.getTransferScript().save();
       	   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) {
            wizard.setNextStep( ServerConfigWizardStep.getStaticParameters() );
            return true;
       }

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

    }

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

}


⌨️ 快捷键说明

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