mirror of
https://github.com/kuitoi/kuitoi-Server.git
synced 2026-06-18 22:51:03 +00:00
Refactor kick and tcp_send in Client
This commit is contained in:
+10
-8
@@ -42,13 +42,14 @@ class Client:
|
|||||||
self.alive = False
|
self.alive = False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def kick(self, reason):
|
async def kick(self, reason):
|
||||||
self.log.info(f"Client: \"IP: {self.addr!r}; ID: {self.cid}\" - kicked with reason: \"{reason}\"")
|
self.log.info(f"Client: \"IP: {self.addr!r}; ID: {self.cid}\" - kicked with reason: \"{reason}\"")
|
||||||
self.tcp_send(b"K" + bytes(reason, "utf-8"))
|
await self.tcp_send(b"K" + bytes(reason, "utf-8"))
|
||||||
self.socket.close()
|
# self.writer.close()
|
||||||
|
# await self.writer.wait_closed()
|
||||||
self.alive = False
|
self.alive = False
|
||||||
|
|
||||||
def tcp_send(self, data):
|
async def tcp_send(self, data):
|
||||||
|
|
||||||
# TNetwork.cpp; Line: 383
|
# TNetwork.cpp; Line: 383
|
||||||
# BEAMP TCP protocol sends a header of 4 bytes, followed by the data.
|
# BEAMP TCP protocol sends a header of 4 bytes, followed by the data.
|
||||||
@@ -56,12 +57,13 @@ class Client:
|
|||||||
# ^------^^---...-^
|
# ^------^^---...-^
|
||||||
# size data
|
# size data
|
||||||
|
|
||||||
data = data.replace(b" ", b"_")
|
self.log.debug(f"tcp_send({data})")
|
||||||
if len(data) == 10:
|
if len(data) == 10:
|
||||||
data += b"."
|
data += b"."
|
||||||
header = len(data).to_bytes(4, "little")
|
header = len(data).to_bytes(4, "little", signed=True)
|
||||||
self.log.debug(f'len(data) {len(data)}; header: {header}; send {header + data}')
|
self.log.debug(f'len(data) {len(data)}; send {header + data}')
|
||||||
self.socket.send(header + data)
|
self.writer.write(header + data)
|
||||||
|
await self.writer.drain()
|
||||||
|
|
||||||
|
|
||||||
class Core:
|
class Core:
|
||||||
|
|||||||
Reference in New Issue
Block a user