mirror of
https://github.com/kuitoi/kuitoi-Server.git
synced 2026-10-25 21:50:06 +00:00
[+] Fix onModsSending
This commit is contained in:
1 parent
a16e2e39d9
commit
3dc2232db2
3 files changed
+19
-18
No files matched your search
+17
-16
@@ -287,31 +287,31 @@ class Client:
|
|||||||
await self._tpc_put(None)
|
await self._tpc_put(None)
|
||||||
|
|
||||||
async def _split_load(self, start, end, d_sock, filename, speed_limit=None):
|
async def _split_load(self, start, end, d_sock, filename, speed_limit=None):
|
||||||
real_size = end - start
|
size = end - start
|
||||||
writer = self._down_sock[1] if d_sock else self.__writer
|
writer = self._down_sock[1] if d_sock else self.__writer
|
||||||
who = 'dwn' if d_sock else 'srv'
|
who = 'DSock' if d_sock else 'MSock'
|
||||||
self.log.debug(f"[{who}] Real size: {real_size / MB}mb; {real_size == end}, {real_size * 2 == end}")
|
self.log.debug(f"[{who}] Started; start,end={(start, end)}")
|
||||||
|
|
||||||
with open(filename, 'rb') as f:
|
with open(filename, 'rb') as f:
|
||||||
f.seek(start)
|
f.seek(start)
|
||||||
total_sent = 0
|
total_sent = 0
|
||||||
start_time = time.monotonic()
|
start_time = time.monotonic()
|
||||||
while total_sent < real_size:
|
while total_sent < size:
|
||||||
data = f.read(min(MB, real_size - total_sent)) # read data in chunks of 1MB or less
|
if (size - total_sent) == 0:
|
||||||
|
break
|
||||||
|
data = f.read(min(MB, size - total_sent)) # read data in chunks of 1MB or less
|
||||||
try:
|
try:
|
||||||
writer.write(data)
|
writer.write(data)
|
||||||
async with asyncio.timeout(120): # ~70kb/s
|
async with asyncio.timeout(120): # ~100kb/s
|
||||||
await writer.drain()
|
await writer.drain()
|
||||||
# self.log.debug(f"[{who}] Sent {len(data)} bytes.")
|
# self.log.debug(f"[{who}] Sent {len(data)} bytes.")
|
||||||
except TimeoutError:
|
except TimeoutError:
|
||||||
self.log.debug(f"[{who}] TimeoutError; Sock: {writer}")
|
self.log.debug(f"[{who}] TimeoutError; Sock: {writer}")
|
||||||
self.log.error("TimeoutError")
|
self.log.error("TimeoutError")
|
||||||
await self._send("ETimeoutError")
|
|
||||||
self.__alive = False
|
self.__alive = False
|
||||||
break
|
break
|
||||||
except ConnectionError:
|
except ConnectionError:
|
||||||
await self._send("EConnectionError")
|
self.log.debug(f"[{who}] Disconnected; Sock: {writer}")
|
||||||
self.log.debug(f"[{who}] Disconnected.")
|
|
||||||
self.__alive = False
|
self.__alive = False
|
||||||
break
|
break
|
||||||
total_sent += len(data)
|
total_sent += len(data)
|
||||||
@@ -322,7 +322,7 @@ class Client:
|
|||||||
expected_time = total_sent / (speed_limit * MB)
|
expected_time = total_sent / (speed_limit * MB)
|
||||||
if expected_time > elapsed_time:
|
if expected_time > elapsed_time:
|
||||||
await asyncio.sleep(expected_time - elapsed_time)
|
await asyncio.sleep(expected_time - elapsed_time)
|
||||||
self.log.debug(f"[{who}] Ready.")
|
self.log.debug(f"[{who}] Ready. {total_sent=}")
|
||||||
return total_sent
|
return total_sent
|
||||||
|
|
||||||
async def _sync_resources(self):
|
async def _sync_resources(self):
|
||||||
@@ -342,10 +342,10 @@ class Client:
|
|||||||
size = mod['size']
|
size = mod['size']
|
||||||
self.log.debug("File is accept.")
|
self.log.debug("File is accept.")
|
||||||
break
|
break
|
||||||
self.log.debug(f"Mod size: {size}")
|
# self.log.debug(f"Mod size: {size}")
|
||||||
if size == -1:
|
if size == -1:
|
||||||
await self._send(b"CO")
|
await self._send(b"CO")
|
||||||
await self.kick(f"Not allowed mod: " + file)
|
await self.kick(f"Requested not allowed file: " + file)
|
||||||
return
|
return
|
||||||
await self._send(b"AG")
|
await self._send(b"AG")
|
||||||
t = 0
|
t = 0
|
||||||
@@ -353,17 +353,18 @@ class Client:
|
|||||||
await asyncio.sleep(0.1)
|
await asyncio.sleep(0.1)
|
||||||
t += 1
|
t += 1
|
||||||
if t > 50:
|
if t > 50:
|
||||||
await self.kick("Missing download socket")
|
await self.kick("Error (Missing DSock)")
|
||||||
return
|
return
|
||||||
if config.Options['use_queue']:
|
if config.Options['use_queue']:
|
||||||
while self._core.lock_upload:
|
while self._core.lock_upload:
|
||||||
await asyncio.sleep(.2)
|
await asyncio.sleep(.2)
|
||||||
self._core.lock_upload = True
|
self._core.lock_upload = True
|
||||||
speed = config.Options["speed_limit"] or 10*B
|
speed = config.Options["speed_limit"] or 25*B
|
||||||
if speed:
|
if speed:
|
||||||
speed = speed / 2
|
speed = speed / 2
|
||||||
half_size = math.floor(size / 2)
|
half_size = size // 2
|
||||||
t = time.monotonic()
|
t = time.monotonic()
|
||||||
|
self.log.debug(f"Sending: {size=}; sl0={(0, half_size)}; sl1={(half_size, size)}")
|
||||||
async with asyncio.TaskGroup() as tg:
|
async with asyncio.TaskGroup() as tg:
|
||||||
sl0 = tg.create_task(self._split_load(0, half_size, False, file, speed))
|
sl0 = tg.create_task(self._split_load(0, half_size, False, file, speed))
|
||||||
sl1 = tg.create_task(self._split_load(half_size, size, True, file, speed))
|
sl1 = tg.create_task(self._split_load(half_size, size, True, file, speed))
|
||||||
@@ -378,7 +379,7 @@ class Client:
|
|||||||
sent = sl0 + sl1
|
sent = sl0 + sl1
|
||||||
ok = sent == size
|
ok = sent == size
|
||||||
lost = size - sent
|
lost = size - sent
|
||||||
self.log.debug(f"SplitLoad_0: {sl0}; SplitLoad_1: {sl1}; At all ({ok}): Sent: {sent}; Lost: {lost}")
|
self.log.debug(f"Sent; sl_0: {sl0}; sl_1: {sl1}; size==sent is {ok}: {size}-{sent}={lost}")
|
||||||
if not ok:
|
if not ok:
|
||||||
self.__alive = False
|
self.__alive = False
|
||||||
e = i18n.client_mod_sent_error.format(repr(file))
|
e = i18n.client_mod_sent_error.format(repr(file))
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ __title__ = 'KuiToi-Server'
|
|||||||
__description__ = 'BeamingDrive Multiplayer server compatible with BeamMP clients.'
|
__description__ = 'BeamingDrive Multiplayer server compatible with BeamMP clients.'
|
||||||
__url__ = 'https://github.com/kuitoi/kuitoi-Server'
|
__url__ = 'https://github.com/kuitoi/kuitoi-Server'
|
||||||
__version__ = '0.4.8'
|
__version__ = '0.4.8'
|
||||||
__build__ = 2747 # Я это считаю лог файлами
|
__build__ = 2800 # Я это считаю лог файлами
|
||||||
__author__ = 'SantaSpeen'
|
__author__ = 'SantaSpeen'
|
||||||
__author_email__ = 'admin@anidev.ru'
|
__author_email__ = 'admin@anidev.ru'
|
||||||
__license__ = "FPA"
|
__license__ = "FPA"
|
||||||
|
|||||||
+1
-1
@@ -136,7 +136,7 @@ class Core:
|
|||||||
try:
|
try:
|
||||||
for client in self.clients:
|
for client in self.clients:
|
||||||
ca = f"Ss{len(self.clients_by_id)}/{config.Game['players']}:{self.get_clients_list()}"
|
ca = f"Ss{len(self.clients_by_id)}/{config.Game['players']}:{self.get_clients_list()}"
|
||||||
if not client or not client.alive:
|
if not client or not client.alive or not client.ready:
|
||||||
continue
|
continue
|
||||||
await client._send(ca)
|
await client._send(ca)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|||||||
Reference in new issue
Block a user