add Client Status Packet and allow client to respawn when issuing '/respawn'

This commit is contained in:
TheSnoozer 2017-07-31 14:34:03 +02:00 committed by joo
parent 0dc333237b
commit fecb1d10e9
2 changed files with 26 additions and 4 deletions

View File

@ -861,6 +861,21 @@ class AnimationPacketServerbound(Packet):
HAND_MAIN = 0
HAND_OFF = 1
class ServerClientStatus(Packet):
@staticmethod
def get_id(context):
return 0x04 if context.protocol_version >= 318 else \
0x03 if context.protocol_version >= 80 else \
0x02 if context.protocol_version >= 67 else \
0x17 if context.protocol_version >= 49 else \
0x16
packet_name = "client status"
get_definition = staticmethod(lambda context: [
{'action_id': VarInt}])
RESPAWN = 0
REQUEST_STATS = 1
def state_playing_serverbound(context):
packets = {
@ -868,6 +883,7 @@ def state_playing_serverbound(context):
ChatPacket,
PositionAndLookPacket,
AnimationPacketServerbound,
ServerClientStatus,
}
if context.protocol_version >= 107:
packets |= {

View File

@ -7,7 +7,7 @@ from optparse import OptionParser
from minecraft import authentication
from minecraft.exceptions import YggdrasilError
from minecraft.networking.connection import Connection
from minecraft.networking.packets import ChatMessagePacket, ChatPacket
from minecraft.networking.packets import ChatMessagePacket, ChatPacket, ServerClientStatus
from minecraft.compat import input
@ -77,9 +77,15 @@ def main():
while True:
try:
text = input()
packet = ChatPacket()
packet.message = text
connection.write_packet(packet)
if text == "/respawn":
print("respawning...")
packet = ServerClientStatus()
packet.action_id = ServerClientStatus.RESPAWN
connection.write_packet(packet)
else:
packet = ChatPacket()
packet.message = text
connection.write_packet(packet)
except KeyboardInterrupt:
print("Bye!")
sys.exit()