【问题标题】:Ruby and Minecraft PacketsRuby 和 Minecraft 数据包
【发布时间】:2012-12-27 07:53:31
【问题描述】:

我需要创建一个数据包并将其发送到 Minecraft 服务器。数据包需要以特定方式打包。我在 python 中管理了这个,但 ruby​​ 似乎让我失望了。

这是打包它的 Python 代码:

def short(data):
    return pack('>h',data)
def shortchar(data):
    return pack('>H',ord(data))
def string16(data):
    chars = ''.join([shortchar(i) for i in data])
    return short(len(data))+chars

packetbytes = '\x02\x33' + string16(name) + string16(host) + '\x00\x00\x63\xdd'

Ruby 怎么办?

【问题讨论】:

    标签: python ruby hex packet minecraft


    【解决方案1】:

    试试这个:

    def string_16(data)
      [data.size].pack('s>') + data.split('').map(&:ord).pack('S>*')
    end
    
    packet_bytes = "\x02\x33" + string_16(name) + string_16(host) + "\x00\x00\x63\xdd"
    

    【讨论】:

      猜你喜欢
      • 2012-03-25
      • 1970-01-01
      • 2012-08-28
      • 2020-09-03
      • 1970-01-01
      • 1970-01-01
      • 2012-09-02
      • 2012-06-07
      • 2022-09-27
      相关资源
      最近更新 更多