#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.3.8.0
 Author:         Zaziki
 Date:			 28.08.2012

#ce ----------------------------------------------------------------------------
#include <Inet.au3>
#include <Date.au3>

; #VARIABLES# ===================================================================================================================
Const $myVersion = 3
; ===============================================================================================================================


; #UPDATE# ======================================================================================================================
; checkVersion()
; ===============================================================================================================================


; #FUNCTION# ====================================================================================================================
; Name ..........: validate
; Description ...: With this function you can check your code.
; Syntax ........: validate($username, $code[, $method = 0])
; Parameters ....: $username            - The Username where the code is registred
;                  $code                - The Code to validate
;                  $method              - [optional] If the value 1 the it will return a short description.
;										  With a 0 it will return a Number.
;										  Default is 0.
;
; Return values .: http://zaziki.pf-control.de/directConnect.php
; Author ........: Zaziki
; Example .......: content = validate("myUsername", "AAAA-BBBB-CCCC-DDDD", 1)
; ===============================================================================================================================
Func validate($username, $code, $method = 0)
	$answer = _INetGetSource("http://zaziki.pf-control.de/api.php?packet=" & $username & "|status|" & $code)
	if $method = 1 Then
		$answer = answerToStr($answer)
	EndIf

	return $answer
EndFunc

; #FUNCTION# ====================================================================================================================
; Name ..........: create
; Description ...: With this function you can create a dynamic Code
; Syntax ........: create($username[, $code = ""[, $method = 0]])
; Parameters ....: $username            - Your username. The code will be saved under this Username!
;                  $code                - If you don't want a random-Code you can generate your own and insert it here.
;                  $method              - [optional] If the value 1 the it will return a short description.
;										  With a 0 it will return a Number.
;										  Default is 0.
; Return values .: http://zaziki.pf-control.de/directConnect.php
; Author ........: Zaziki
; Example .......: create("myUsername")
; ===============================================================================================================================
Func create($username, $code = "", $method = 0)
	if $code <> "" Then
		$answer = _INetGetSource("http://zaziki.pf-control.de/api.php?packet=" & $username & "|create|" & $code)
	Else
		$answer = _INetGetSource("http://zaziki.pf-control.de/api.php?packet=" & $username & "|create")
	EndIf

	if $method = 1 Then
		$answer = answerToStr($answer)
	EndIf

	return $answer
EndFunc

; #FUNCTION# ====================================================================================================================
; Name ..........: SpecialCreate
; Description ...: This is a special form of Create. Here you can define many options by yourself. For more informations please
;				   visit: http://zaziki.pf-control.de/directConnect.php
; ===============================================================================================================================
Func SpecialCreate($username, $type, $maxuse, $regiononly, $regions, $OSOnly, $OS, $VLK, $startDate, $expireDate, $code = "", $method = 0)
	if $code <> "" Then
		$answer = _INetGetSource("http://zaziki.pf-control.de/api.php?packet=" & $username & "|specialcreate|" & $type & _
					"|" & $maxuse & "|" & $regiononly & "|" & $regions & "|" & $OSOnly & "|" & $OS & "|" & $VLK & _
					"|" & $startDate & "|" & $expireDate & "|" & $code)
	Else
		$answer = _INetGetSource("http://zaziki.pf-control.de/api.php?packet=" & $username & "|specialcreate|" & $type & _
					"|" & $maxuse & "|" & $regiononly & "|" & $regions & "|" & $OSOnly & "|" & $OS & "|" & $VLK & _
					"|" & $startDate & "|" & $expireDate)
	EndIf

	if $method = 1 Then
		$answer = answerToStr($answer)
	EndIf

	return $answer
EndFunc

; #FUNCTION# ====================================================================================================================
; Name ..........: CodeReg
; Description ...: With this function you can register a Code. When this is done, the Code never can be registered again!
; Syntax ........: CodeReg($username, $code[, $method = 0])
; Parameters ....: $username            - Your username.
;                  $code                - The code to register.
;                  $method              - [optional] If the value 1 the it will return a short description.
;										  With a 0 it will return a Number.
;										  Default is 0.
; Return values .: http://zaziki.pf-control.de/directConnect.php
; Author ........: Zaziki
; Example .......: CodeReg("myUsername", "AAAA-BBBB-CCCC-DDDD")
; ===============================================================================================================================
Func CodeReg($username, $code, $method = 0)
	$answer = _INetGetSource("http://zaziki.pf-control.de/api.php?packet=" & $username & "|reg|" & $code)

	if $method = 1 Then
		$answer = answerToStr($answer)
	EndIf

	return $answer
EndFunc

; #INTERNAL_USE_ONLY# ===========================================================================================================
; Name ..........: answerToStr
; Description ...: This function is only used to translate "Number-Answers" to short descriptions.
; ===============================================================================================================================
Func answerToStr($str)
	If $str = "-1" Then
        $str = "No packet"
    ElseIf $str = "-2" Then
        $str = "wrong packet syntax"
    ElseIf $str = "-3" Then
        $str = "server error"
    ElseIf $str = "-4" Then
        $str = "unknown step"
    ElseIf $str = "-5" Then
        $str = "packet not complete"
    ElseIf $str = "-7" Then
        $str = "max regi$strations"
    ElseIf $str = "-8" Then
        $str = "wrong Country"
    ElseIf $str = "-9" Then
        $str = "wrong OS"
    ElseIf $str = "-10" Then
        $str = "wrong Code"
    ElseIf $str = "-11" Then
        $str = "key expired"
    ElseIf $str = "-12" Then
        $str = "key not enabled yet"
    ElseIf $str = "-13" Then
        $str = "unknown useragent"
    ElseIf $str = "-14" Then
        $str = "already createt account (last 24 hours) with this IP"
    ElseIf $str = "-15" Then
        $str = "server error"
    ElseIf $str = "-16" Then
        $str = "not all arguments given"
    ElseIf $str = "-17" Then
        $str = "server error"
    ElseIf $str = "-18" Then
        $str = "already createt account (last 24 hours) with this IP"
    EndIf

	return $str
EndFunc

; #FUNCTION# ====================================================================================================================
; Name ..........: checkVersion
; Description ...: With this function you can check, if this is the last released version.
; Syntax ........: checkVersion()
; Parameters ....:
; Return values .: If is a new version released, the Programm will close.
; Author ........: Zaziki
; ===============================================================================================================================
Func checkVersion()
	$answer = _INetGetSource("http://zaziki.pf-control.de/apiversion.html")
	if $answer > $myVersion Then
		MsgBox(0, "Lizenz-Me nicht weiter unterstützt!", "Da eine neue Version von Lizenz-Me vorhanden ist, wird diese Version nicht mehr unterstützt" & _
				  "Sie müssen warten, bis derjenige der das Programm geschrieben hat die neue Version zur Verfügung stellt!")
		Exit
	EndIf
EndFunc

; #INTERNAL_USE_ONLY# ===========================================================================================================
; Name ..........: time
; Description ...: Only used to make a UNIX-Timestamp.
; Syntax ........: time()
; Parameters ....:
; Return values .: UNIX-Timestamp
; Author ........: Zaziki
; ===============================================================================================================================
Func time()
	return _DateDiff('s', "1970/01/01 00:00:00", _DateAdd("h", -1, _NowCalc()))
EndFunc