fixes, allow to run as server
This commit is contained in:
parent
a5b82cb8a6
commit
3cee338ca5
4 changed files with 26 additions and 21 deletions
|
@ -6,6 +6,7 @@ from .mc.proto.play.clientbound import PacketChat
|
||||||
from .mc.token import Token
|
from .mc.token import Token
|
||||||
from .dispatcher import ConnectionState
|
from .dispatcher import ConnectionState
|
||||||
from .client import Client
|
from .client import Client
|
||||||
|
from .server import MinecraftServer
|
||||||
from .util.helpers import parse_chat
|
from .util.helpers import parse_chat
|
||||||
|
|
||||||
async def idle():
|
async def idle():
|
||||||
|
@ -13,6 +14,12 @@ async def idle():
|
||||||
await asyncio.sleep(1)
|
await asyncio.sleep(1)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
logging.basicConfig(level=logging.DEBUG)
|
||||||
|
|
||||||
|
if sys.argv[1] == "--server":
|
||||||
|
serv = MinecraftServer("0.0.0.0", 25565)
|
||||||
|
serv.run() # will block and start asyncio event loop
|
||||||
|
else:
|
||||||
username = sys.argv[1]
|
username = sys.argv[1]
|
||||||
pwd = sys.argv[2]
|
pwd = sys.argv[2]
|
||||||
server = sys.argv[3]
|
server = sys.argv[3]
|
||||||
|
@ -26,8 +33,6 @@ if __name__ == "__main__":
|
||||||
host = server.strip()
|
host = server.strip()
|
||||||
port = 25565
|
port = 25565
|
||||||
|
|
||||||
logging.basicConfig(level=logging.INFO)
|
|
||||||
|
|
||||||
client = Client(host, port, username=username, password=pwd)
|
client = Client(host, port, username=username, password=pwd)
|
||||||
|
|
||||||
@client.on_packet(PacketChat, ConnectionState.PLAY)
|
@client.on_packet(PacketChat, ConnectionState.PLAY)
|
||||||
|
|
|
@ -142,11 +142,11 @@ class Client:
|
||||||
loop.run_until_complete(self.start())
|
loop.run_until_complete(self.start())
|
||||||
|
|
||||||
async def idle():
|
async def idle():
|
||||||
while self._processing: # TODO don't busywait even if it doesn't matter much
|
while True: # TODO don't busywait even if it doesn't matter much
|
||||||
await asyncio.sleep(self.options["poll-timeout"])
|
await asyncio.sleep(self.options["poll-timeout"])
|
||||||
|
|
||||||
try:
|
try:
|
||||||
loop.run_forever(idle())
|
loop.run_until_complete(idle())
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
self._logger.info("Received SIGINT, stopping...")
|
self._logger.info("Received SIGINT, stopping...")
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -6,7 +6,7 @@ from typing import Tuple, Dict, Any
|
||||||
from .types import Type, VarInt
|
from .types import Type, VarInt
|
||||||
|
|
||||||
class Packet:
|
class Packet:
|
||||||
__slots__ = 'id', 'definition', '_processed', '_protocol', '_state'
|
__slots__ = 'definition', '_processed', '_protocol', '_state'
|
||||||
|
|
||||||
id : int
|
id : int
|
||||||
definition : Tuple[Tuple[str, Type]]
|
definition : Tuple[Tuple[str, Type]]
|
||||||
|
|
|
@ -105,7 +105,7 @@ class PacketClassWriter:
|
||||||
name=self.title,
|
name=self.title,
|
||||||
ids='{\n\t\t' + ',\n\t\t'.join(self.ids) + '\n\t}\n',
|
ids='{\n\t\t' + ',\n\t\t'.join(self.ids) + '\n\t}\n',
|
||||||
definitions='{\n\t\t' + '\n\t\t'.join(self.slots) + '\n\t}\n',
|
definitions='{\n\t\t' + '\n\t\t'.join(self.slots) + '\n\t}\n',
|
||||||
slots=', '.join(f"'{x}'" for x in self.attrs) + ' ,',
|
slots=', '.join(f"'{x}'" for x in (list(self.attrs) + ["id"])), # TODO de-jank!
|
||||||
fields='\n\t'.join(self.fields),
|
fields='\n\t'.join(self.fields),
|
||||||
state=self.state,
|
state=self.state,
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in a new issue