Unreal Tournament '99

Starttiskripti

' **************************************************************************
' * Start-up script for Unreal Tournament Server
' * (C) PLZI 2007
' * 
' * Arguments:
' *
' * reli[cs] - start game with relics
' * exc[essive] - start game in excessive mode
' * lis[t] - list known maps only
' * [N] given a number, start the game from map N
' *
' * Examples: 
' *
' * cscript start.vbs exc 4 (start excessive, map 4, no mutators, no relics)
' * cscript start.vbs reli exc (start excessive, random map, relics)
' **************************************************************************

Dim Args
Dim TrueMap(31) ' map name array
Dim Pointer
Dim RunOnly ' Run the server or list maps and given options (debug)
Dim Mutators ' Mutator list string
Dim GameType ' GameType string
Dim SelectNum ' Selected map number
Dim PreMutatorList ' Defines the mutators
Dim GamePath ' Path to UCC
Dim UCC ' UCC Server command
Dim ComLine ' Command Line
Dim ListenOn ' Multihomed computer IP listener address

GamePath = "E:\UnrealTournament\System\"
UCC = "UCC server"

' multihome string. space is necessary.
ListenOn =  " multihome=62.220.235.179"

' Mutator list, edit if necessary
PreMutatorList= "Relics.RelicDefense,Relics.RelicRedemption,_
                 Relics.RelicRegen,Relics.RelicSpeed,Relics.RelicStrength"

Set Args = WScript.Arguments

' We will always be playing deathmatch game, if nothing else is specified.

GameType = "Botpack.DeathMatchPlus"


' No mutators, if none given.
Mutators = ""

Selectnum = -1
RunOnly = True

' Check for arguments.
If Args.Count >0 Then
	For Each X in Args'
	If IsExcessive(X) Then gametype="Excessive.ExcessiveDeathMatchPlus"
	If IsRelics(X) Then Mutators = PreMutatorList
	If IsNumeric(X) Then SelectNum = CInt(X)
	If IsList(X) Then RunOnly = False
	Next
End If

Wscript.Echo "Selected game type: " & gametype
WScript.Echo "Selected mutators list: " & Mutators
WScript.Echo "Selected Map: " & Selectnum

' Get the map names from UnrealTournament.ini
' Also get rid of empty lines possibly present
Pointer=0
For F=0 to 30 
	MapString="Maps[" & F & "]"
	' WScript.Echo MapString
	Map = GetINIString("Botpack.TDMmaplist", MapString, "-", GamePath & "UnrealTournament.ini")
	
	If Map <> "-" Then 
		Truemap(Pointer) = Map
		Pointer = Pointer +1
	End If
Next

For F= 0 to Pointer-1
	WScript.Echo F & ": " & Truemap(F)
Next
Randomize
If Selectnum <>-1 And Selectnum < Pointer Then
	Selected = Truemap(Selectnum)
Else
	Selected = Truemap(Int(Rnd*Pointer))
End If


Set objApp = CreateObject("WScript.Shell")
' Build the command line. Example given below.
' DM-UrbanArena][.unr?game=Excessive.ExcessiveDeathMatchPlus?mutator=Relics.RelicDefense,
' Relics.RelicRedemption,Relics.RelicRegen,Relics.RelicSpeed,Relics.RelicStrength"

comline = GamePath & UCC & Selected & "?game=" & gametype & "?mutator=" & Mutators & ListenOn

wscript.echo "Starting server with command line: " & comline

If RunOnly Then 
	objApp.Run comline
Else
	WScript.Echo "Not really starting, debug mode."
End If

' **************************************************************************
' Helper functions
' **************************************************************************

Function IsList(N)
If Instr(lcase(N),"lis") Then IsList=True Else IsList=False
End Function

Function IsExcessive(N)
If Instr(lcase(N),"exc") Then IsExcessive=True Else IsExcessive=False
End Function

Function IsRelics(N)
If Instr(lcase(N), "reli") Then IsRelics=True Else IsRelics=False
End Function

Function GetINIString(Section, KeyName, Default, FileName)
  Dim INIContents, PosSection, PosEndSection, sContents, Value, Found
  
  'Get contents of the INI file As a string
  INIContents = GetFile(FileName)
  'WScript.Echo INIContents
  'Find section
  PosSection = InStr(1, INIContents, "[" & Section & "]", vbTextCompare)
  If PosSection>0 Then
    'Section exists. Find end of section
    PosEndSection = InStr(PosSection, INIContents, vbCrLf & "[")
    '?Is this last section?
    If PosEndSection = 0 Then PosEndSection = Len(INIContents)+1
    
    'Separate section contents
    sContents = Mid(INIContents, PosSection, PosEndSection - PosSection)
    'WScript.Echo sContents
    If InStr(1, sContents, vbCrLf & KeyName & "=", vbTextCompare)>0 Then
      Found = True
      'Separate value of a key.
      Value = SeparateField(sContents, vbCrLf & KeyName & "=", vbCrLf)
    End If
  End If
  If isempty(Found) Then Value = Default
  GetINIString = Value
End Function

'Separates one field between sStart And sEnd
Function SeparateField(ByVal sFrom, ByVal sStart, ByVal sEnd)
  Dim PosB: PosB = InStr(1, sFrom, sStart, 1)
  If PosB > 0 Then
    PosB = PosB + Len(sStart)
    Dim PosE: PosE = InStr(PosB, sFrom, sEnd, 1)
    If PosE = 0 Then PosE = InStr(PosB, sFrom, vbCrLf, 1)
    If PosE = 0 Then PosE = Len(sFrom) + 1
    SeparateField = Mid(sFrom, PosB, PosE - PosB)
  End If
End Function


'File functions
Function GetFile(ByVal FileName)
  Dim FS: Set FS = CreateObject("Scripting.FileSystemObject")
  'Go To windows folder If full path Not specified.
  If InStr(FileName, ":\") = 0 And Left (FileName,2)<>"\\" Then 
    FileName = FS.GetSpecialFolder(0) & "\" & FileName
  End If
  On Error Resume Next

  GetFile = FS.OpenTextFile(FileName).ReadAll
End Function

Function WriteFile(ByVal FileName, ByVal Contents)
  
  Dim FS: Set FS = CreateObject("Scripting.FileSystemObject")
  'On Error Resume Next

  'Go To windows folder If full path Not specified.
  If InStr(FileName, ":\") = 0 And Left (FileName,2)<>"\\" Then 
    FileName = FS.GetSpecialFolder(0) & "\" & FileName
  End If

  Dim OutStream: Set OutStream = FS.OpenTextFile(FileName, 2, True)
  OutStream.Write Contents
End Function