Что нового

[Сеть, интернет] перекодировка данных в входящем пакете

andreitrane

Новичок
Сообщения
141
Репутация
3
у меня 2 вопроса
1 - когда приходит пакет, из него надо вытащить данные, если данные записаны на английском (<name>AutoIter</name>), то программа вытаскивает данные без проблем и записывает в input без изменений, но если во входящем пакете данные на русском, то они закодированы (<name>%5B%D0%92%D0%91%5D%20%D0%93%D0%95%D0%A5%D0%90</name>) и скрипт записывает эти данные в таком же закодированном виде... как сделать чтобы скрипт перекодировал обратно на русский и записывал (уже на русском) в input?
Код:
$Response = $oHTTP.ResponseText
$Responsetext = BinaryToString($Response)
$sMsgname = StringRegExpReplace($Responsetext, '(?s).*?<name>(.*?)</name>?.*', '\1')
GUICtrlSetData($input, $sMsgname)


2 - с помощью команды StringRegExpReplace можно вынимать из входящего пакета данные, но как я понял если эти данные уникальны... как сделать чтобы можно было вынимать данные, если они повторяются, но значение в них разное?
данные выглядят так
<collection>1</collection>
<collection>2</collection>
<collection>3</collection>
<collection>4</collection>
<collection>5</collection>
<collection>6</collection>
<collection>7</collection>
как видите <collection> повторяются, но данные в них разные, и
Код:
$sMsgcollect = StringRegExpReplace($Response, '(?s).*?<collection>(\d+)</collection>?.*', '\1')

может показать только самое первое, а тоесть <collection>1</collection>
а мне надо полностью все значения...
 

madmasles

Модератор
Глобальный модератор
Сообщения
7,790
Репутация
2,322
andreitrane
1.
Код:
#include <Encoding.au3>

$sString = '<name>%5B%D0%92%D0%91%5D%20%D0%93%D0%95%D0%A5%D0%90</name>'
$sString_1 = '<name><collection>2</collection></name>'
MsgBox(64, 'Results', _Encoding_HexToURL($sString) & @LF & _Encoding_HexToURL($sString_1))
Encoding.au3
2.
Код:
#include <Array.au3>
;...
$aMsgcollect = StringRegExp($Response, '<collection>(\d+)</collection>', 3)
_ArrayDisplay($aMsgcollect)
На будущее, лучше по правилам одна тема - один вопрос.
 
Автор
A

andreitrane

Новичок
Сообщения
141
Репутация
3
спасибо, у меня получился такой код
Код:
if $aMsgcollect[0] = 1 then GUICtrlSetData($butinf1, "найдена")
			if $aMsgcollect[1] = 2 then GUICtrlSetData($butinf2, "найдена")
			if $aMsgcollect[2] = 3 then GUICtrlSetData($butinf3, "найдена")
			if $aMsgcollect[24] = 28 then GUICtrlSetData($presninf1, "найдена")
			if $aMsgcollect[25] = 29 then GUICtrlSetData($presninf2, "найдена")
			if $aMsgcollect[26] = 30 then GUICtrlSetData($presninf3, "найдена")
			if $aMsgcollect[3] = 4 then GUICtrlSetData($krestinf1, "найдена")
			if $aMsgcollect[4] = 5 then GUICtrlSetData($krestinf2, "найдена")
			if $aMsgcollect[5] = 6 then GUICtrlSetData($krestinf3, "найдена")
			if $aMsgcollect[6] = 7 then GUICtrlSetData($vcentrinf1, "найдена")
			if $aMsgcollect[7] = 8 then GUICtrlSetData($vcentrinf2, "найдена")
			if $aMsgcollect[8] = 9 then GUICtrlSetData($vcentrinf3, "найдена")
			if $aMsgcollect[9] = 10 then GUICtrlSetData($tihinf1, "найдена")
			if $aMsgcollect[10] = 11 then GUICtrlSetData($tihinf2, "найдена")
			if $aMsgcollect[11] = 12 then GUICtrlSetData($tihinf3, "найдена")
			if $aMsgcollect[12] = 13 then GUICtrlSetData($pyatinf1, "найдена")
			if $aMsgcollect[13] = 14 then GUICtrlSetData($pyatinf2, "найдена")
			if $aMsgcollect[14] = 15 then GUICtrlSetData($pyatinf3, "найдена")
			if $aMsgcollect[15] = 16 then GUICtrlSetData($lebinf1, "найдена")
			if $aMsgcollect[16] = 17 then GUICtrlSetData($lebinf2, "найдена")
			if $aMsgcollect[17] = 18 then GUICtrlSetData($lebinf3, "найдена")
			if $aMsgcollect[18] = 19 then GUICtrlSetData($ocentrinf1, "найдена")
			if $aMsgcollect[19] = 20 then GUICtrlSetData($ocentrinf2, "найдена")
			if $aMsgcollect[20] = 21 then GUICtrlSetData($ocentrinf3, "найдена")
			if $aMsgcollect[21] = 22 then GUICtrlSetData($delfinf1, "найдена")
			if $aMsgcollect[22] = 23 then GUICtrlSetData($delfinf2, "найдена")
			if $aMsgcollect[23] = 24 then GUICtrlSetData($delfinf3, "найдена")


но он работает если во входящем пакете есть все <collection>(\d+)</collection>, а тоесть от <collection>1<collection> до <collection>30</collection>, но если же в пакете нет хотябы одной <collection>(\d+)</collection>, то вылезает ошибка.... как сделать чтобы ошибка не вылезала, а например если нет $aMsgcollect[18] тогда записывается
Код:
GUICtrlSetData($ocentrinf1, " - ")
 

madmasles

Модератор
Глобальный модератор
Сообщения
7,790
Репутация
2,322
andreitrane [?]
но если же в пакете нет хотябы одной <collection>(\d+)</collection>, то вылезает ошибка
Если между <collection> и </collection> бывают пустые значения или пробелы, или не цифры, то лучше, наверное, так:
Код:
;...
$aMsgcollect = StringRegExp($Response, '<collection>(.*?)</collection>', 3)
For $i = 0 To UBound($aMsgcollect) - 1
	If Not StringIsDigit($aMsgcollect[$i]) Then
		MsgBox(16, $i, 'Не число!')
	EndIf
Next
;...

Код:
;...
If StringIsDigit($aMsgcollect[0]) And $aMsgcollect[0] == 1 Then
	GUICtrlSetData($butinf1, "найдена")
Else
	GUICtrlSetData($butinf1, "не найдена")
EndIf
;...
 
Автор
A

andreitrane

Новичок
Сообщения
141
Репутация
3
Если между <collection> и </collection> бывают пустые значения или пробелы, или не цифры, то лучше, наверное

нет, вы не так поняли, вот полноценный список с которым не бывает проблем
Код:
			<collection>1</collection>
			<collection>2</collection>
			<collection>3</collection>
			<collection>4</collection>
			<collection>5</collection>
			<collection>6</collection>
			<collection>7</collection>
			<collection>8</collection>
			<collection>9</collection>
			<collection>10</collection>
			<collection>11</collection>
			<collection>12</collection>
			<collection>13</collection>
			<collection>14</collection>
			<collection>15</collection>
			<collection>16</collection>
			<collection>17</collection>
			<collection>18</collection>
			<collection>19</collection>
			<collection>20</collection>
			<collection>21</collection>
			<collection>22</collection>
			<collection>23</collection>
			<collection>24</collection>
			<collection>28</collection>
			<collection>29</collection>
			<collection>30</collection>

но бывает и так, с этим уже идут ошибки
Код:
			<collection>1</collection>
			<collection>2</collection>
			<collection>3</collection>
			<collection>4</collection>
                          <collection>11</collection>
			<collection>12</collection>
			<collection>13</collection>
			<collection>19</collection>
			<collection>20</collection>
			<collection>21</collection>

то есть некоторых <collection><collection> вообще нет...
а мне надо сделать чтобы если есть <collection>1<collection>, то идет запись в input1 "найдено", если нет, то запись " - " или ничего не записывается, если есть <collection>2<collection>, идет запись в input2 "найдено", иначе " - " и т.д. надеюсь вы меня поняли
 

madmasles

Модератор
Глобальный модератор
Сообщения
7,790
Репутация
2,322
andreitrane
Может так:
Код:
#include <Array.au3>

$Response = FileRead(@ScriptDir & '\1.txt')
Dim $aMsgcollect[31][2] = [[30]]
For $i = 1 To $aMsgcollect[0][0]
	$aMsgcollect[$i][1] = 'фиг вам'
Next
$aTemp = StringRegExp($Response, '<collection>(\d+)</collection>', 3)
For $i = 0 To UBound($aTemp) - 1
	$aMsgcollect[Number($aTemp[$i])][0] = $aTemp[$i]
	$aMsgcollect[Number($aTemp[$i])][1] = 'нашли'
Next
_ArrayDisplay($aMsgcollect)
 
Автор
A

andreitrane

Новичок
Сообщения
141
Репутация
3
этот не работает, он всегда даже если есть в пакете строчки <collection><collection> показывает "фиг вам"
 

madmasles

Модератор
Глобальный модератор
Сообщения
7,790
Репутация
2,322
andreitrane [?]
этот не работает
Почему?
Код:
#include <GUIConstantsEx.au3>

Dim $aMsgcollect[31][3] = [[30]]

$fYes = False
GUICreate('Test', 200, 640)
For $i = 1 To $aMsgcollect[0][0]
	GUICtrlCreateLabel('Коллекция №' & $i & ':', 10, 5 + 20 * ($i - 1), 100, 16)
	$aMsgcollect[$i][0] = GUICtrlCreateLabel('', 120, 5 + 20 * ($i - 1), 50, 16)
Next
$nButton = GUICtrlCreateButton('GO', 50, 605, 100, 30)
GUISetState()

While 1
	$nMsg = GUIGetMsg()
	Switch $nMsg
		Case $GUI_EVENT_CLOSE
			Exit
		Case $nButton
			For $i = 1 To $aMsgcollect[0][0]
				$aMsgcollect[$i][2] = 'фиг вам'
			Next
			$fYes = Not $fYes
			If $fYes Then
				$Response = FileRead(@ScriptDir & '\1.txt')
			Else
				$Response = FileRead(@ScriptDir & '\2.txt')
			EndIf
			$aTemp = StringRegExp($Response, '<collection>(\d+)</collection>', 3)
			For $i = 0 To UBound($aTemp) - 1
				$aMsgcollect[Number($aTemp[$i])][1] = $aTemp[$i]
				$aMsgcollect[Number($aTemp[$i])][2] = 'нашли'
			Next
			For $i = 1 To $aMsgcollect[0][0]
				GUICtrlSetData($aMsgcollect[$i][0], $aMsgcollect[$i][2])
			Next
	EndSwitch
WEnd
 
Автор
A

andreitrane

Новичок
Сообщения
141
Репутация
3
только щас узнал, в том что ваш скрипт не работает нет вины самого скрипта, просто серв игры не отвечает и неоткуда брать данные
 

madmasles

Модератор
Глобальный модератор
Сообщения
7,790
Репутация
2,322
andreitrane [?]
и неоткуда брать данные
Значит нужно добавить проверку на получение данных или работоспособность сервера и т.д.

andreitrane [?]
что ваш скрипт не работает
Я всегда проверяю работоспособность того, что выкладываю.
 
Автор
A

andreitrane

Новичок
Сообщения
141
Репутация
3
ну вот у меня что получилось
Код:
$Response = FileRead(@ScriptDir & '\1.txt')
			;;;
            Dim $sMsgcollect[31][1] = [[30]]
            $aTemp = StringRegExp($Response, '<collection>(\d+)</collection>', 3)
            For $i = 0 To UBound($aTemp) - 1
            $sMsgcollect[Number($aTemp[$i])][0] = $aTemp[$i]
             Next
             _ArrayDisplay($sMsgcollect)
			if $sMsgcollect[1] = 1 then GUICtrlSetData($butinf1, "найдена")
			if $sMsgcollect[2] = 2 then GUICtrlSetData($butinf2, "найдена")
			if $sMsgcollect[3] = 3 then GUICtrlSetData($butinf3, "найдена")
			if $sMsgcollect[28] = 28 then GUICtrlSetData($presninf1, "найдена")
			if $sMsgcollect[29] = 29 then GUICtrlSetData($presninf2, "найдена")
			if $sMsgcollect[30] = 30 then GUICtrlSetData($presninf3, "найдена")
			if $sMsgcollect[4] = 4 then GUICtrlSetData($krestinf1, "найдена")
			if $sMsgcollect[5] = 5 then GUICtrlSetData($krestinf2, "найдена")
			if $sMsgcollect[6] = 6 then GUICtrlSetData($krestinf3, "найдена")
			if $sMsgcollect[7] = 7 then GUICtrlSetData($vcentrinf1, "найдена")
			if $sMsgcollect[8] = 8 then GUICtrlSetData($vcentrinf2, "найдена")
			if $sMsgcollect[9] = 9 then GUICtrlSetData($vcentrinf3, "найдена")
			if $sMsgcollect[10] = 10 then GUICtrlSetData($tihinf1, "найдена")
			if $sMsgcollect[11] = 11 then GUICtrlSetData($tihinf2, "найдена")
			if $sMsgcollect[12] = 12 then GUICtrlSetData($tihinf3, "найдена")
			if $sMsgcollect[13] = 13 then GUICtrlSetData($pyatinf1, "найдена")
			if $sMsgcollect[14] = 14 then GUICtrlSetData($pyatinf2, "найдена")
			if $sMsgcollect[15] = 15 then GUICtrlSetData($pyatinf3, "найдена")
			if $sMsgcollect[16] = 16 then GUICtrlSetData($lebinf1, "найдена")
			if $sMsgcollect[17] = 17 then GUICtrlSetData($lebinf2, "найдена")
			if $sMsgcollect[18] = 18 then GUICtrlSetData($lebinf3, "найдена")
			if $sMsgcollect[19] = 19 then GUICtrlSetData($ocentrinf1, "найдена")
			if $sMsgcollect[20] = 20 then GUICtrlSetData($ocentrinf2, "найдена")
			if $sMsgcollect[21] = 21 then GUICtrlSetData($ocentrinf3, "найдена")
			if $sMsgcollect[22] = 22 then GUICtrlSetData($delfinf1, "найдена")
			if $sMsgcollect[23] = 23 then GUICtrlSetData($delfinf2, "найдена")
			if $sMsgcollect[24] = 24 then GUICtrlSetData($delfinf3, "найдена")

в array все отлично показывает, но когда array закрываешь, вылетает здесь ошибка
Код:
if $sMsgcollect[1] = 1 then GUICtrlSetData($butinf1, "найдена")

Код:
if $sMsgcollect[1] = 1 then guictrlsetdata($butinf, "найдена")
if ^ ERROR

error: Array variable has incorrect number of subscripts or subscript dimension range exceeded

мне здесь че, вместо $sMsgcollect[**] надо писать че то другое?
 

madmasles

Модератор
Глобальный модератор
Сообщения
7,790
Репутация
2,322
andreitrane
Поменяйте
Код:
Dim $sMsgcollect[31][1] = [[30]]
;на
Dim $sMsgcollect[31] = [30]
;и
$sMsgcollect[Number($aTemp[$i])][0] = $aTemp[$i]
;на
$sMsgcollect[Number($aTemp[$i])] = $aTemp[$i]
 
Верх