mIRC 套接字从 url 读取文本
mIRC socket read text from url
我一直在尝试使用 mIRC 从 url 中读取一小段文本,并在有人键入 !test 时将其回显/写入聊天。
套接字主机是 XXXXXXXXXXXX,因为它在我的 PC 上 运行 on wamp。
页面上的数据不长,这里是页面。
SnOwEfLaKe's Battlefield 4(pc) Stats | Rank: 140 | Kills: 66393 | K/D:
2 | W/L: 1.38 | Score: 60646533 | Time Played: 53.27 days | Accuracy:
14.17%
alias demo {
var %user = $, %chan = , %sockname = demo. $+ $ticks
hfree -w %sockname | hmake %sockname
hadd %sockname user %user
hadd %sockname chan %chan
hadd %sockname host XXXXXXXXX
hadd %sockname port 80
hadd %sockname request /nb/bf4stats.php
sockopen -e %sockname $hget(%sockname,host) $hget(%sockname,port)
}
on *:text:!test:#:{
demo #
}
on *:sockopen:demo.*: {
var %<< = sockwrite -nt $sockname
%<< GET $hget($sockname,request) HTTP/1.0
%<< Host: $sock($sockname).addr
%<< $crlf
}
on *:sockread:demo.*: {
var %header, %content
if (!$hget($sockname,header.complete)) {
sockread %header
while (%header != $null) {
if (HTTP/* 2?? * iswm %header) { hadd $sockname following $true }
elseif (HTTP/* 4?? * iswm %header) { hadd $sockname following $false }
;echo -ag %header
sockread %header
}
if ($sockbr) hadd $sockname header.complete $true
}
if ($hget($sockname,header.complete)) {
while ($sockbr) {
sockread -f %content
;if (%content != $null) echo -ag %content
}
}
}
on *:sockclose:demo.*:{
if ($hget($sockname,following)) { var %msg = Following }
else { var %msg = Not following }
if ($hget($sockname,chan)) { msg $v1 %msg }
else { echo -ag %msg }
hfree $sockname
}
我运气不好
我知道怎么做了。
on *:TEXT:*:#blood_wolf89:{
if ($strip() === !bf4stats) {
var %user = $iif(, $strip(), Blood_Wolff89)
var %urlSafeUser = $regsubex(%user, /[^a-z\d_-]/gi, % $+ $base($asc(\t), 10, 16, 2))
var %url = http://api.bf4stats.com/api/playerInfo?plat=pc&name= $+ %urlSafeuser
JSONOpen -ud bf4stat %url
var %name = $JSON(bf4stat, player, name)
var %rank = $JSON(bf4stat, player, rank, nr)
var %score = $JSON(bf4stat, player, score)
var %kills = $JSON(bf4stat, stats, kills)
var %deaths = $JSON(bf4stat, stats, deaths)
var %kdRatio = $round($calc(%kills / %deaths), 2)
var %wins = $JSON(bf4stat, stats, numWins)
var %losses = $JSON(bf4stat, stats, numLosses)
var %wlRatio = $round($calc(%wins / %losses), 2)
var %played = $duration($JSON(bf4stat, stats, timePlayed))
var %hits = $JSON(bf4stat, stats, shotsHit)
var %misses = $JSON(bf4stat, stats, shotsFired)
var %accuracy = $round($calc(%hits / %misses * 100),2) $+ %
if ((%user == %name) || (%urlSafeuser == %name)) { msg # [BF4Stats]: %name $+ 's Battlefield 4(PC) Stats $(|,0) Rank: %rank $(|,0) Kills: %kills $(|,0) K/D: %kdRatio $(|,0) W/L: %wlRatio $(|,0) Score: %score $(|,0) Time Played: %played $(|,0) Accuracy: %accuracy }
if ((%urlSafeuser !== %name)) { msg # [BF4Stats]: Invalid Battlefield 4 Name. }
}
}
然后我从这里得到了一个 JSON 解析器:http://hawkee.com/snippet/10194
我一直在尝试使用 mIRC 从 url 中读取一小段文本,并在有人键入 !test 时将其回显/写入聊天。
套接字主机是 XXXXXXXXXXXX,因为它在我的 PC 上 运行 on wamp。
页面上的数据不长,这里是页面。
SnOwEfLaKe's Battlefield 4(pc) Stats | Rank: 140 | Kills: 66393 | K/D: 2 | W/L: 1.38 | Score: 60646533 | Time Played: 53.27 days | Accuracy: 14.17%
alias demo {
var %user = $, %chan = , %sockname = demo. $+ $ticks
hfree -w %sockname | hmake %sockname
hadd %sockname user %user
hadd %sockname chan %chan
hadd %sockname host XXXXXXXXX
hadd %sockname port 80
hadd %sockname request /nb/bf4stats.php
sockopen -e %sockname $hget(%sockname,host) $hget(%sockname,port)
}
on *:text:!test:#:{
demo #
}
on *:sockopen:demo.*: {
var %<< = sockwrite -nt $sockname
%<< GET $hget($sockname,request) HTTP/1.0
%<< Host: $sock($sockname).addr
%<< $crlf
}
on *:sockread:demo.*: {
var %header, %content
if (!$hget($sockname,header.complete)) {
sockread %header
while (%header != $null) {
if (HTTP/* 2?? * iswm %header) { hadd $sockname following $true }
elseif (HTTP/* 4?? * iswm %header) { hadd $sockname following $false }
;echo -ag %header
sockread %header
}
if ($sockbr) hadd $sockname header.complete $true
}
if ($hget($sockname,header.complete)) {
while ($sockbr) {
sockread -f %content
;if (%content != $null) echo -ag %content
}
}
}
on *:sockclose:demo.*:{
if ($hget($sockname,following)) { var %msg = Following }
else { var %msg = Not following }
if ($hget($sockname,chan)) { msg $v1 %msg }
else { echo -ag %msg }
hfree $sockname
}
我运气不好
我知道怎么做了。
on *:TEXT:*:#blood_wolf89:{
if ($strip() === !bf4stats) {
var %user = $iif(, $strip(), Blood_Wolff89)
var %urlSafeUser = $regsubex(%user, /[^a-z\d_-]/gi, % $+ $base($asc(\t), 10, 16, 2))
var %url = http://api.bf4stats.com/api/playerInfo?plat=pc&name= $+ %urlSafeuser
JSONOpen -ud bf4stat %url
var %name = $JSON(bf4stat, player, name)
var %rank = $JSON(bf4stat, player, rank, nr)
var %score = $JSON(bf4stat, player, score)
var %kills = $JSON(bf4stat, stats, kills)
var %deaths = $JSON(bf4stat, stats, deaths)
var %kdRatio = $round($calc(%kills / %deaths), 2)
var %wins = $JSON(bf4stat, stats, numWins)
var %losses = $JSON(bf4stat, stats, numLosses)
var %wlRatio = $round($calc(%wins / %losses), 2)
var %played = $duration($JSON(bf4stat, stats, timePlayed))
var %hits = $JSON(bf4stat, stats, shotsHit)
var %misses = $JSON(bf4stat, stats, shotsFired)
var %accuracy = $round($calc(%hits / %misses * 100),2) $+ %
if ((%user == %name) || (%urlSafeuser == %name)) { msg # [BF4Stats]: %name $+ 's Battlefield 4(PC) Stats $(|,0) Rank: %rank $(|,0) Kills: %kills $(|,0) K/D: %kdRatio $(|,0) W/L: %wlRatio $(|,0) Score: %score $(|,0) Time Played: %played $(|,0) Accuracy: %accuracy }
if ((%urlSafeuser !== %name)) { msg # [BF4Stats]: Invalid Battlefield 4 Name. }
}
}
然后我从这里得到了一个 JSON 解析器:http://hawkee.com/snippet/10194