Advertisement
NovaViper

Untitled

Jun 18th, 2017
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-# VARIABLE DECLARATION #-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#
  2. $currentLocation = Split-Path -parent $PSCommandPath
  3. $ui = (Get-Host).UI.RawUI
  4. $consoleName = "Console Master"
  5. $consoleVersion = '1.0'
  6. $prefix = "$consoleName $consoleVersion"
  7. $quitConsole = $false
  8. $configFileName = "config.json"
  9. #-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-# POWERSHELL CUSTOMIZATION #-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#
  10. $ui.WindowTitle = "$prefix"
  11. Set-Location $currentLocation
  12. #-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-# FUNCTION DECLARATION #-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#
  13.  
  14. function Setup-Console(){
  15.     Clear-Host
  16.     $ui.WindowTitle = "$prefix+: Server Running (Jar: , MC )"
  17.     Write-Host "Welcome To $consoleName!!"
  18.     Write-Host ''
  19.    
  20.     $jarFile = Check-Jar "Please enter the name of the server's .jar file (w/o the extension)"
  21.     $mcVersion = Check-Version "Please enter the Minecraft version your server is using"
  22.     $maxRAM = Check-Integer "Please enter your maximum amount of RAM (Random Access Memory) to use"
  23.  
  24.     $basicInfo = @{
  25.         Jar_File = "$jarFile"
  26.         Minecraft_Version = "$mcVersion"
  27.         Java_Flags = "-Xmx$maxRAM"
  28.         Server_Options = "-o true"
  29.    
  30.     }
  31.  
  32.     New-Item $configFileName -ItemType "file" | Out-Null
  33.     $basicInfo | ConvertTo-Json | Add-Content $configFileName
  34. }
  35.  
  36.  
  37. function Main-Menu() {
  38.     #Load data from JSON
  39.     $INFO = Get-Content -Path $configFileName -Raw | ConvertFrom-Json
  40.  
  41.     Clear-Host
  42.     Write-Host @"
  43. ---------------------------------- Main Menu ----------------------------------
  44.  
  45.                    1. Start Server and Ngrok
  46.                    2. Configurations Menu
  47.                        
  48.                    3. Exit the Console
  49.  
  50. -------------------------------------------------------------------------------
  51. "@
  52.  
  53.     $answer = Read-Host "Please Make a Selection"
  54.     switch($answer){
  55.         '1' {
  56.             Clear-Host
  57.             Start-Server
  58.         }
  59.         '2' {
  60.             Clear-Host
  61.             Settings-Menu
  62.         }
  63.         '3' {
  64.             Exit-Script
  65.         }
  66.         default {
  67.             Invaild-Choice
  68.             Main-Menu
  69.         }
  70.     }
  71. }
  72.  
  73. function Start-Server(){
  74.     $consoleServerPrefix = "["+$consoleName+"]:"
  75.     $ui.WindowTitle = "$prefix+: Server Running (Jar: , MC )"
  76.     Write-Host @"
  77. ------------------------------- SERVER LOG START -------------------------------
  78. $consoleServerPrefix Server Starting!
  79. "@
  80.     #-#-#-#-# Ngrok Checking here #-#-#-#-#
  81.     #Write-Host "$consoleServerPrefix Checking for Ngrok process..."
  82.  
  83.     ##Already Started
  84.     #Write-Host "$consoleServerPrefix Ngrok is Already Running! Skipping Ngrok Startup..."
  85.  
  86.     #Not Started
  87.     #Write-Host "$consoleServerPrefix Ngrok Not Running! Starting Ngrok..."
  88.     #start powershell {ngrok tcp 25565}
  89.     #Write-Host "$consoleServerPrefix Ngrok Started!"
  90.     #-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#
  91.  
  92.     Write-Host "$consoleServerPrefix Loading Java Arguments..."
  93.     #start-process java -ArgumentList '-Xms1G -Xmx1G -jar C:\Users\novag\Documents\Powershell\forge.jar' -Wait -NoNewWindow
  94.  
  95.     java $INFO.Java_Flags -jar $INFO.Jar_File $INFO.Server_Options
  96.  
  97.  
  98. }
  99.  
  100.  
  101. function Settings-Menu() {
  102.     Clear-Host
  103.     Write-Host @"
  104. -------------------------------- Settings Menu --------------------------------
  105.  
  106.    1. Change Version - Change the saved Minecraft version to match
  107.                        what the jar file uses
  108.    2. RAM Allocation - Set the amount of RAM (Random Access Memory)
  109.                        to reserve to the server [!]
  110.    3. Custom Arguments - Set custom arguments besides the RAM [!!]
  111.    4. Factory Reset - Erase all user defined settings and boot to
  112.                        first-time setup [!!!]
  113.  
  114.    5. Return To Main Menu
  115.  
  116. -------------------------------------------------------------------------------
  117. "@
  118.  
  119.     $answer = Read-Host "Please Make a Selection"
  120.     switch($answer){
  121.         '1' {
  122.             Clear-Host
  123.             Change-Minecraft-Version
  124.         }
  125.         '2' {
  126.             Clear-Host
  127.             Change-RAM
  128.         }
  129.         '3' {
  130.             Clear-Host
  131.             Confirm-Change-Args
  132.         }
  133.         '4' {
  134.             Clear-Host
  135.              Confirm-Factory-Reset
  136.         }
  137.         '5' {Return-Main-Menu}
  138.         default {
  139.             Invaild-Choice
  140.             Settings-Menu
  141.         }
  142.     }
  143. }
  144.  
  145. function Change-Minecraft-Version(){
  146.  
  147. }
  148.  
  149. function Change-RAM(){
  150.     #Write-Host "Please Enter Your Minimum Amount Of RAM To Use Followed By 'M' For Megabytes Or  'G' For Gigabytes"
  151.    
  152.  
  153. }
  154.  
  155. function Confirm-Change-Args(){
  156.  
  157. }
  158.  
  159. function Confirm-Factory-Reset(){
  160.     Write-Host "Are you SURE you want to reset back to factory default? This process CANNOT be reversed!!" -ForegroundColor Red
  161.     $answer = Read-Host "(Y)es or (N)o"
  162.     switch($answer.ToUpper()){
  163.         'Y' {
  164.             Clear-Host
  165.             Perform-Factory-Reset
  166.         }
  167.         'N' {
  168.             Clear-Host
  169.             Return-Settings-Menu
  170.         }
  171.         default {
  172.             Invaild-Choice
  173.             Confirm-Factory-Reset
  174.         }
  175.     }
  176. }
  177.  
  178. function Perform-Factory-Reset(){
  179.     Write-Host "Deleting Preferences..." -BackgroundColor Red
  180.     #Delete Preference Method Here
  181.     Write-Host "Factory Reset Completed!"
  182.     Write-Host ""
  183.     Write-Host "Returning to First-Time Setup..." -BackgroundColor Red
  184.     Sleep -Seconds 2
  185.     Setup-Console
  186. }
  187.  
  188.  
  189. function Exit-Script(){
  190.     Write-Host ""
  191.     Write-Host "Exiting Script..." -BackgroundColor Red
  192.     Start-Sleep -Seconds 5
  193.     $quitConsole = $true
  194. }
  195.  
  196. function Return-Main-Menu(){
  197.     Write-Host ""
  198.     Write-Host "Returning to Main Menu..." -BackgroundColor Red
  199.     Sleep -Seconds 2
  200.     Main-Menu
  201. }
  202.  
  203. function Return-Settings-Menu(){
  204.     Write-Host ""
  205.     Write-Host "Returning to Settings Menu..." -BackgroundColor Red
  206.     Sleep -Seconds 2
  207.     Settings-Menu
  208. }
  209.  
  210. function Invaild-Choice(){
  211.     [Console]::Beep(1000, 100)
  212.     Write-Host "INVALID CHOICE! PLEASE ENTER ONE OF THE CHOICES LISTED!" -ForegroundColor Red
  213.     Sleep -Seconds 2
  214. }
  215.  
  216. function Check-Jar([string]$promptMessage){
  217.     Do{
  218.         [string]$data = Read-Host -Prompt $promptMessage
  219.         if ((-not $null -eq $data) -and (-not $data -eq '')){
  220.             return $data+'.jar'
  221.             $loop = $false
  222.         }else{
  223.             Write-Output ''
  224.             [Console]::Beep(1000, 100)
  225.             Write-Host "You cannot enter a null/empty name!" -ForegroundColor Red
  226.             Sleep -Seconds 2
  227.             $loop = $true
  228.         }      
  229.  
  230.     } Until($loop = $false)
  231. }
  232.  
  233. function Check-Version([string]$promptMessage){
  234.     Do{
  235.         $data = Read-Host -Prompt $promptMessage
  236.         $minVer = [version]'1.0.0'
  237.         $maxVer = [version]'999.999.999'
  238.  
  239.         if (($minVer -le $data) -and ($data -le $maxVer) -and ($data.Revision -lt 0)){
  240.             return $data
  241.             $loop = $false
  242.         }else{
  243.             [Console]::Beep(1000, 100)
  244.             Write-Host "The value [$data] MUST be a version (major, minor, build) ranging between $min to $max!" -ForegroundColor Red
  245.             $loop = $true
  246.         }
  247.     }Until($loop = $false)
  248. }
  249.  
  250. function Check-Integer([string]$promptMessage){
  251.     While($loopRAM = $false){
  252.         $answerRAM = Read-Host -Prompt "Would you like to use [G]igabytes or [M]egabytes?"
  253.         switch($answerRAM.ToUpper()){
  254.             'M' {
  255.                 $ramType = "m".ToUpper()
  256.                 $loopRAM = $false
  257.             }
  258.             'G' {
  259.                 $ramType = "g".ToUpper()
  260.                 $loopRAM = $false
  261.             }
  262.             default {
  263.                 Invaild-Choice
  264.                 $loopRAM = $true
  265.             }
  266.         }
  267.     }Until($loopRAM = $false)
  268.  
  269.     Do{
  270.         [int]$data = Read-Host -Prompt $promptMessage
  271.         $min = 1
  272.         $max = [int]::MaxValue
  273.  
  274.         if(($null -eq $data) -or ($data -eq '') -or ($data -eq '0')){
  275.             Write-Host ''
  276.             [Console]::Beep(1000, 100)
  277.             Write-Host "The value [$data] cannot be null, empty or 0!" -ForegroundColor Red
  278.             Sleep -Seconds 2
  279.             $loop = $true
  280.         }
  281.  
  282.         if(-not ($data -notmatch '[^\d]')){
  283.             Write-Output ''
  284.             [Console]::Beep(1000, 100)
  285.             Write-Host "The value [$data] MUST be an integer!" -ForegroundColor Red
  286.             Sleep -Seconds 2
  287.             Setup-Console
  288.             $loop = $true
  289.         }
  290.  
  291.         #$result = -Join ($data, $ramType)
  292.         #return $result
  293.         return $data
  294.         $loop = $false
  295.        
  296.  
  297.     }Until($loop = $false)
  298. }
  299.  
  300. #-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#   BEGIN FUNCTION CALLS   #-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#
  301.  
  302. Do{
  303.     Clear-Host
  304.     #-#-#-#-# Setup Checking here #-#-#-#-#
  305.     If (!(Test-Path $configFileName)) {
  306.         Setup-Console
  307.     }else{
  308.         Main-Menu
  309.     }
  310.  
  311.    
  312.     #If there are no basic files
  313.  
  314.     #If there are basic files
  315.     #-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#
  316. } Until ($quitConsole = $true)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement