Advertisement
Guest User

CreateINI - by F4keName

a guest
May 31st, 2011
578
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.57 KB | None | 0 0
  1. package net.server;
  2.  
  3. import java.io.Console;
  4. import java.io.FileOutputStream;
  5. import java.io.IOException;
  6.  
  7. /**
  8.  *
  9.  * @author kevintjuh93
  10.  */
  11. public class CreateINI {
  12.     public static void main(String args[]) {
  13.         StringBuilder sb = new StringBuilder();
  14.         String nextline = "\r\n";//Because I can, and it's free.
  15.         byte worlds;
  16.         Console con = System.console();
  17.  
  18.         System.out.println("Welcome to CrystalMS's .ini creator\r\n\r\n");
  19.  
  20.         sb.append("#CrystalMS INI file. Do NOT modify it if you are an idiot (:\r\n");
  21.         sb.append("#Flag types: 0 = nothing, 1 = event, 2 = new, 3 = hot\r\n\r\n");
  22.  
  23.         System.out.println("Flag types: 0 = nothing, 1 = event, 2 = new, 3 = hot\r\n\r\n");
  24.  
  25.         worlds = Byte.parseByte(con.readLine("Number of worlds: "));
  26.         sb.append("worlds=").append(worlds).append("\r\n\r\n");
  27.  
  28.         System.out.println("\r\n");
  29.  
  30.  
  31.         for (byte b = 0; b < worlds; b++) {
  32.             sb.append("#Properties for world ").append(b).append("\r\n");
  33.  
  34.             System.out.println("Properties for world " + b);
  35.             if (b > 2) System.out.println("Make sure you create a npc folder for this world!");
  36.             sb.append("flag").append(b).append("=").append(
  37.                     Byte.parseByte(con.readLine("   Flag: "))).append("\r\n");
  38.  
  39.             sb.append("eventmessage").append(b).append("=").append(
  40.                     con.readLine("   Event message: ")).append("\r\n");
  41.  
  42.             sb.append("channels").append(b).append("=").append(
  43.                     Integer.parseInt(con.readLine("   Number of channels: "))).append("\r\n");
  44.  
  45.             sb.append("exprate").append(b).append("=").append(
  46.                     Integer.parseInt(con.readLine("   Exp rate: "))).append("\r\n");
  47.            
  48.             sb.append("droprate").append(b).append("=").append(
  49.                     Integer.parseInt(con.readLine("   Drop rate: "))).append("\r\n");
  50.            
  51.             sb.append("mesorate").append(b).append("=").append(
  52.                     Integer.parseInt(con.readLine("   Meso rate: "))).append("\r\n");
  53.  
  54.             sb.append("bossdroprate").append(b).append("=").append(
  55.                     Integer.parseInt(con.readLine("   Boss drop rate: "))).append("\r\n");
  56.            
  57.             System.out.println(nextline);
  58.             sb.append("\r\n");
  59.         }
  60.        
  61.         sb.append("\r\n").append("gmserver=").append(Boolean.parseBoolean(con.readLine("Do you want a GM Server? (true/false)")));
  62.         FileOutputStream out = null;
  63.         try {
  64.             out = new FileOutputStream("crystal.ini", false);
  65.             out.write(sb.toString().getBytes());
  66.         } catch (Exception ex) {
  67.         } finally {
  68.             try {
  69.                 if (out != null) out.close();
  70.             } catch (IOException ex) {
  71.             }
  72.         }
  73.  
  74.         sb = new StringBuilder();
  75.         try {
  76.             System.out.println("\r\nYou are about to set the Java Heap Size, if you don't know what it is, type '?'.");
  77.             String heapsize = con.readLine("Java Heap Size (in MB): ");
  78.             while (heapsize.equals("?")) {
  79.                 System.out.println("\r\n");
  80.                 System.out.println("WikiAnswers: Java heap is the heap size allocated to JVM applications which takes care of the new objects being created. If the objects being created exceed the heap size, it will throw an error saying memoryOutof Bound\r\n\r\n");
  81.                 heapsize = con.readLine("Java Heap Size (in MB): ");
  82.             }
  83.             String linux = con.readLine("\r\nAre you using a Linux platform or not? (y/n):");
  84.             while (!linux.equals("y") && !linux.equals("n")) {
  85.                 System.out.println("Type 'y' if you use linux else type 'n'.");
  86.                 linux = con.readLine("Are you using a Linux platform or not? (y/n):");
  87.             }
  88.             if (linux.equals("n")) {
  89.                 out = new FileOutputStream("launch_server.bat", false);
  90.                 sb.append("@echo off").append("\r\n").append("@title CrystalMS Server v83").append("\r\n");
  91.                 sb.append("set CLASSPATH=.;dist\\*\r\n");
  92.                 sb.append("java -Xmx").append(heapsize).append("m -Dwzpath=wz\\ -Djavax.net.ssl.keyStore=filename.keystore -Djavax.net.ssl.keyStorePassword=passwd -Djavax.net.ssl.trustStore=filename.keystore -Djavax.net.ssl.trustStorePassword=passwd net.server.Server\r\n");
  93.                 sb.append("pause");
  94.             } else {//test
  95.                 out = new FileOutputStream("launch_server.sh", false);
  96.                 sb.append("#!/bin/sh").append("\r\n\r\n");
  97.                 sb.append("export CLASSPATH=\".:dist/*\" \r\n\r\n");
  98.                 sb.append("java -Dwzpath=wz/ \\\r\n").append("-Djavax.net.ssl.keyStore=filename.keystore \\\r\n-Djavax.net.ssl.keyStorePassword=passwd \\\r\n-Djavax.net.ssl.trustStore=filename.keystore \\\r\n-Djavax.net.ssl.trustStorePassword=passwd \\\r\n");
  99.                 sb.append("-Xmx").append(heapsize).append("m ").append("net.server.Server");
  100.                 System.out.println("Use DOS2UNIX command to convert the .sh file once again.");
  101.             }
  102.             out.write(sb.toString().getBytes());
  103.         } catch (Exception ex) {
  104.         } finally {
  105.             try {
  106.                 if (out != null) out.close();
  107.             } catch (IOException ex) {
  108.             }
  109.         }
  110.         System.out.println("\r\nMake sure that ServerConstants in modified too, and clean+compiled before you start the server.");
  111.         System.out.println("If you want other settings; restart this .bat or modify the crystal.ini");
  112.     }
  113. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement