0.1 -> 0.2
Application
Host and port to run are now passed in the Application.run
method
import cubes
app = cubes.Application('127.0.0.1', 25565)
app.run()
import cubes
app = cubes.Application()
app.run('127.0.0.1', 25565)
Now packet_id
is passed to the packet handlers as the first arguments
import cubes
async def handler(packet: cubes.ReadBuffer):
pass
import cubes
async def handler(packet_id: int, packet: cubes.ReadBuffer):
pass
The value returned by the handler is now ignored. You must send all packets yourself
import cubes
async def handler(packet: cubes.ReadBuffer) -> Optional[cubes.WriteBuffer]:
"""Process Status Ping."""
return cubes.WriteBuffer().pack_varint(0x01).write(packet.read(8))
import cubes
async def handler(packet_id: int, packet: cubes.ReadBuffer) -> None:
"""Process Status Ping."""
await packet.connection.send(
cubes.WriteBuffer().pack_varint(0x01).write(packet_read(8)
)
ReadBuffer
Now the connection
argument is required for initialization
import cubes
...
buff = cubes.ReadBuffer()
import cubes
import cubes.abc
...
conn: cubes.abc.AbstractConnection
buff = cubes.ReadBuffer(conn)
The same argument appeared for the from_reader
method
import asyncio
import cubes
...
reader: asyncio.StreamReader
buff = await cubes.ReadBuffer.from_reader(reader)
import asyncio
import cubes
import cubes.abc
...
conn: cubes.abc.AbstractConnection
reader: asyncio.StreamReader
buff = await cubes.ReadBuffer.from_reader(conn, reader)
Connection
The Сonnection
class has been replaced with PlayerConnection
.
When initializing it, you must pass an Application
instance
import asyncio
import cubes
...
reader: asyncio.StreamReader
writer: asyncio.StreamWriter
conn = cubes.Connection(reader, writer)
import asyncio
import cubes
import cubes.abc
...
reader: asyncio.StreamReader
writer: asyncio.StreamWriter
app: cubes.abc.Application
conn = cubes.Connection(reader, writer, app)
An optional argument reason
has been added to theclose
method and the СloseConnection
exception
import cubes
...
conn: cubes.PlayerConnection
reason: str
await conn.close(reason)
import cubes
...
reason: str
raise cubes.CloseConnection(reason)
Removed set_current
and get_current
methods. Instead of get_current
, use the instance from the connection
property of ReadBuffer
import cubes
...
async def handler(packet: cubes.ReadBuffer):
conn = cubes.Connection.get_current()
import cubes
...
async def handler(packet_id: int, packet: cubes.ReadBuffer):
conn = packet.connection