SpiffyTek
/
SMACheck
Archived
1
0
Fork 0
This repository has been archived on 2022-05-13. You can view files and clone it, but cannot push or open issues or pull requests.
SMACheck/includes/functions.inc.au3

220 lines
6.7 KiB
AutoIt

; Copyright (c) 2012-2015 SpiffyTek (http://spiffytek.de).
; All rights reserved.
;
; Redistribution and use in source and binary forms, with or without
; modification, are permitted provided that the following conditions are met:
; * Redistributions of source code must retain the above copyright
; notice, this list of conditions and the following disclaimer.
; * Redistributions in binary form must reproduce the above copyright
; notice, this list of conditions and the following disclaimer in the
; documentation and/or other materials provided with the distribution.
; * Neither the name SpiffyTek nor the
; names of its contributors may be used to endorse or promote products
; derived from this software without specific prior written permission.
;
; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
; ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
; WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
; DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
; DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
; (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
; ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
; (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
; SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include-once
;; SMAC XML APi
Func lookupSteamId($input)
Local $agent = "SMACheck/" & FileGetVersion(@ScriptName, "FileVersion")
Local $oXML = ObjCreate("winhttp.winhttprequest.5.1")
$oXML.Open("GET", $iniApiUrl & $input, False)
$oXML.SetTimeouts($iniResolveTimeout, $iniConnectTimeout, $iniSendTimeout, $iniReceiveTimeout)
$oXML.SetRequestHeader("User-Agent", $agent)
$oXML.Send()
$oXML = $oXML.ResponseText
$oXML = _XMLLoadXML($oXML)
If @error <> 0 Then
_printError("noapi")
Return "ERROR_HANDELED"
EndIf
If NOT StringLeft($oXML, 13) = "<?xml version" Then
_printError("noapi")
Return "ERROR_HANDELED"
EndIf
Local $pStatus = _XMLGetValue('/isbanned/status')
If IsArray($pStatus) <> 1 Then
_printError("noapi")
Return "ERROR_HANDELED"
EndIf
If @Compiled <> 0 Then
Local $curVersion = FileGetVersion(@ScriptName, "FileVersion")
Local $pMinVersion = _XMLGetValue("/isbanned/smaCheck/minVersion")
Local $pActVersion = _XMLGetValue("/isbanned/smaCheck/actVersion")
Global $gVersionChecked
If IsArray($pMinVersion) Then
If $curVersion < $pActVersion[1] Then
If ($curVersion < $pMinVersion[1]) And ($iniDisableMinVer < 1) Then
_printError("update_force")
Return "ERROR_HANDELED"
EndIf
If $gVersionChecked < 1 Then
_printError("update")
$gVersionChecked = 1
EndIf
EndIf
EndIf
EndIf
If IsArray($pStatus) Then
Local $bReason = _XMLGetValue("/isbanned/reason")
Local $bNick = _XMLGetValue("/isbanned/nickname")
Local $bTime = _XMLGetValue("/isbanned/banTime")
Local $bVac = _XMLGetValue("/isbanned/vacStatus")
Local $bMod = _XMLGetValue("/isbanned/mod")
Local $bCc = _XMLGetValue("/isbanned/country")
Local $bEac[2]
$bEac[1] = -1
Local $bEsea = _XMLGetValue("/isbanned/eseaStatus")
Local $bKac = _XMLGetValue("/isbanned/kacStatus")
Local $bEsl[2]
$bEsl[1] = -1
Local $validate[10] = [$bReason, $bNick, $bTime, $bVac, $bMod, $bCc, $bEac, $bEsea, $bKac, $bEsl]
If _isArrayAll($validate) <> 1 Then
_printError("noapi")
Return "ERROR_HANDELED"
EndIf
If $bCc[1] = "" Then
$bCc[1] = "nocountry"
EndIf
If $pStatus[1] = "Y" Then
Local $oStatus = "1"
Local $return[12]
$return[0] = $oStatus
$return[1] = _xmlentitiesDecode($bNick[1])
$return[2] = $bReason[1]
$return[3] = $bTime[1]
$return[4] = $pStatus[1]
$return[5] = $bVac[1]
$return[6] = $bMod[1]
$return[7] = $bCc[1]
$return[8] = $bEac[1]
$return[9] = $bEsea[1]
$return[10] = $bKac[1]
$return[11] = $bEsl[1]
Else
Local $oStatus = "0"
Local $return[12]
$return[0] = $oStatus
$return[1] = _xmlentitiesDecode($bNick[1])
$return[2] = "-"
$return[3] = "-"
$return[4] = $pStatus[1]
$return[5] = $bVac[1]
$return[6] = "-"
$return[7] = "nocountry"
$return[8] = $bEac[1]
$return[9] = $bEsea[1]
$return[10] = $bKac[1]
$return[11] = $bEsl[1]
EndIf
If $pStatus[1] = -1 Then
$return[0] = "-1"
EndIf
Else
_printError("noapi")
Return "ERROR_HANDELED"
EndIf
Return $return
EndFunc
;; SteamID Convert
Dim Const $COMM_ID_START = 76561197960265728
Func steamId64ToSteamId($sComID)
$sComID = Number($sComID)
$a = ($sComID - $COMM_ID_START) / 2
$b = Floor($a)
$c = Round( Mod($a,Floor($a)) )
Return "STEAM_0:" & String( $c ) & ":" & String( $b )
EndFunc
Func steamIdToCommunityId($sSteamID)
Local $sResult, $expl, $serverid, $accountid
$expl = StringSplit($sSteamID,":")
if (UBound($expl) == 4) Then
$serverid = Number($expl[2])
$accountid = Number($expl[3])
$sResult = ($accountid * 2) + $COMM_ID_START + $serverid
EndIf
Return $sResult
EndFunc
;; Misc
Func resetInput($iID)
GUICtrlSetData($iID, "")
EndFunc
Func _printError($id = false)
Switch $id
Case "noapi"
MsgBox(16, "SMACheck - ERROR", "API not available.")
Case "update_force"
MsgBox(16, "SMACheck - Required Update available", "Required Update available." & @CRLF & @CRLF & "Please download new Version from smacbans.com.")
Case "update"
MsgBox(48, "SMACheck - Update available", "New Update available." & @CRLF & @CRLF & "Visit smacbans.com for more Info and Download.")
Case "wrongid"
MsgBox(16, "SMACheck - ERROR", "Please enter a SteamId or SteamId64.")
Case Else
Return
EndSwitch
EndFunc
Func _setStatusIcon($ctrlId, $status)
If $status = "1" Then
_ResourceSetImageToCtrl($ctrlId, "error.png", $RT_RCDATA)
ElseIf $status = "-1" Then
_ResourceSetImageToCtrl($ctrlId, "warning.png", $RT_RCDATA)
Else
_ResourceSetImageToCtrl($ctrlId, "tick.png", $RT_RCDATA)
EndIf
EndFunc
Func _xmlentitiesDecode($string)
Local $replace[6] = ["", '"', "&", "<", ">", "'"]
Local $find[6] = ["", "&quot;", "&amp;", "&lt;", "&gt;", "&apos;"]
For $iCC = 1 To UBound($replace) - 1
$string = StringReplace($string, $find[$iCC], $replace[$iCC])
Next
Return $string
EndFunc
Func _isArrayAll($arrays)
For $arr in $arrays
If IsArray($arr) <> true Then
Return 0
EndIf
Next
Return 1
EndFunc