packet_out.py 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. from packet import *
  2. from protocol import *
  3. def emote(emoteId):
  4. emote_packet = PacketOut(CMSG_PLAYER_EMOTE)
  5. emote_packet.write_int8(emoteId)
  6. return str(emote_packet)
  7. def whisper(nick, message):
  8. whisp_packet = PacketOut(CMSG_CHAT_WHISPER)
  9. whisp_packet.write_int16(len(message) + 28)
  10. whisp_packet.write_string(nick, 24)
  11. whisp_packet.write_string(message, len(message))
  12. return str(whisp_packet)
  13. def chat(text):
  14. chat_packet = PacketOut(CMSG_CHAT_MESSAGE)
  15. mes = player_node.name + " : " + text
  16. chat_packet.write_int16(len(mes) + 4 + 1)
  17. chat_packet.write_string(mes, len(mes) + 1)
  18. return str(chat_packet)
  19. def sit(val):
  20. sit_packet = PacketOut(CMSG_PLAYER_CHANGE_ACT)
  21. sit_packet.write_int32(0)
  22. if val == True:
  23. sit_packet.write_int8(2)
  24. else:
  25. sit_packet.write_int8(3)
  26. return str(sit_packet)
  27. def trade_request(being_id):
  28. trade_req_packet = PacketOut(CMSG_TRADE_REQUEST)
  29. trade_req_packet.write_int32(being_id)
  30. return str(trade_req_packet)
  31. def trade_respond(accept):
  32. trade_respond_packet = PacketOut(CMSG_TRADE_RESPONSE)
  33. if accept == True:
  34. trade_respond_packet.write_int8(3)
  35. elif accept == False:
  36. trade_respond_packet.write_int8(4)
  37. return str(trade_respond_packet)
  38. def trade_add_item(item_index, amount):
  39. trade_add_packet = PacketOut(CMSG_TRADE_ITEM_ADD_REQUEST)
  40. trade_add_packet.write_int16(item_index + inventory_offset)
  41. trade_add_packet.write_int32(amount)
  42. return str(trade_add_packet)