Искал искал, и не как не нашел как можно выдать предмет, в базе прописывал но он не появляется, пытался найти примеры работы с cached, нашел но именно выдача предмета не работает зато работает:
Поделитесь идеями как выдать предмет.
Python:
import socket
import struct
import logging
# Настроим логирование
logging.basicConfig(level=logging.DEBUG)
class CacheD:
def __init__(self, cached_ip, cached_port, webadmin='Admin'):
self.cached_ip = cached_ip
self.cached_port = cached_port
self.webadmin = webadmin
self.connected = False
self.fsockerror = False
self.socketerrors = {
"1": True, "01": False, "02": False, "03": False, "04": False,
"05": False, "06": False, "07": False, "08": False, "09": False,
"010": False, "011": False, "012": False, "013": False, "014": False,
"015": False, "016": False, "017": False, "018": False, "019": False,
"020": False, "021": False, "022": False, "023": False, "024": False,
"025": False, "026": False
}
def tounicode(self, string):
return string.encode('utf-16le') + b'\x00\x00'
def CacheDInteractive(self, buf):
try:
with socket.create_connection((self.cached_ip, self.cached_port), timeout=5) as sock:
self.connected = True
packet_length = struct.pack("<h", len(buf) + 2)
packet = packet_length + buf
sock.sendall(packet)
logging.debug(f"Packet sent: {packet.hex()}")
length_data = sock.recv(2)
length = struct.unpack("<h", length_data)[0]
logging.debug(f"Response length: {length} (raw: {length_data.hex()})")
response_id_data = sock.recv(1)
response_id = struct.unpack("<b", response_id_data)[0]
logging.debug(f"Response ID: {response_id} (raw: {response_id_data.hex()})")
remaining_length = length - 3
response_data = sock.recv(remaining_length)
logging.debug(f"Raw response data: {response_data.hex()}")
rs = ''
for i in range(0, len(response_data), 4):
read_data = response_data[i:i+4]
if len(read_data) < 4:
break
read = struct.unpack("<i", read_data)[0]
rs += str(read)
logging.debug(f"Read: {read} (raw: {read_data.hex()})")
logging.debug(f"Response: {rs}")
result = self.socketerrors.get(rs, False)
return result
except socket.error as e:
logging.error(f"Socket error: {e}")
self.connected = False
return self.fsockerror
def CheckCharacterPacket(self, char_id):
buf = struct.pack("<B", 1) + struct.pack("<I", char_id) + self.tounicode(self.webadmin)
logging.debug(f"Buffer: {buf.hex()}")
return self.CacheDInteractive(buf)
def SetCharacterLocationPacket(self, char_id, xloc, yloc, zloc):
buf = struct.pack("<B", 2) + struct.pack("<I", char_id) + struct.pack("<I", 1) + struct.pack("<I", xloc) + struct.pack("<I", yloc) + struct.pack("<I", zloc) + self.tounicode(self.webadmin)
logging.debug(f"Buffer: {buf.hex()}")
return self.CacheDInteractive(buf)
if __name__ == "__main__":
cached_ip = '127.0.0.1'
cached_port = 2012
cacheD = CacheD(cached_ip, cached_port)
# Проверка метода CheckCharacterPacket
result = cacheD.CheckCharacterPacket(IDCHAR)
print("CheckCharacterPacket result:", result)
# Проверка метода SetCharacterLocationPacket
result = cacheD.SetCharacterLocationPacket(IDCHAR, 100, 200, 300)
print("SetCharacterLocationPacket result:", result)