This commit is contained in:
1 parent
d38015562a
commit
8fbc7fed7d
8 files changed
+10
-29
No files matched your search
@@ -7,9 +7,7 @@ from loon.web.users.models import User
|
|||||||
from loon.web.utils.password import hash_password
|
from loon.web.utils.password import hash_password
|
||||||
|
|
||||||
|
|
||||||
async def change_password_handler(client, userdata, msg):
|
async def change_password_handler(client, userdata, msg, data):
|
||||||
data = json.loads(msg.payload.decode())
|
|
||||||
|
|
||||||
if msg.topic != "loon/register/change_password":
|
if msg.topic != "loon/register/change_password":
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ def get_random(templates, **kwargs):
|
|||||||
return random.choice(templates).format(**kwargs)
|
return random.choice(templates).format(**kwargs)
|
||||||
|
|
||||||
|
|
||||||
async def marquee_handler(client, userdata, msg):
|
async def marquee_handler(client, userdata, msg, data):
|
||||||
prefix = "loon/player/"
|
prefix = "loon/player/"
|
||||||
|
|
||||||
if not msg.topic.startswith(prefix):
|
if not msg.topic.startswith(prefix):
|
||||||
@@ -74,11 +74,6 @@ async def marquee_handler(client, userdata, msg):
|
|||||||
if subtopic not in PLAYER_EVENT_SUFFIXES:
|
if subtopic not in PLAYER_EVENT_SUFFIXES:
|
||||||
return
|
return
|
||||||
|
|
||||||
try:
|
|
||||||
data = json.loads(msg.payload.decode())
|
|
||||||
except json.JSONDecodeError:
|
|
||||||
return
|
|
||||||
|
|
||||||
player = data.get("player")
|
player = data.get("player")
|
||||||
if not isinstance(player, dict):
|
if not isinstance(player, dict):
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -3,9 +3,7 @@ import json
|
|||||||
from loon.web.users.state import user_threads
|
from loon.web.users.state import user_threads
|
||||||
|
|
||||||
|
|
||||||
async def player_handler(client, userdata, msg):
|
async def player_handler(client, userdata, msg, data):
|
||||||
data = json.loads(msg.payload.decode())
|
|
||||||
|
|
||||||
prefix = "loon/player/"
|
prefix = "loon/player/"
|
||||||
|
|
||||||
if not msg.topic.startswith(prefix):
|
if not msg.topic.startswith(prefix):
|
||||||
|
|||||||
@@ -7,9 +7,7 @@ from loon.web.users.models import User
|
|||||||
from loon.web.utils.password import hash_password
|
from loon.web.utils.password import hash_password
|
||||||
|
|
||||||
|
|
||||||
async def register_request_handler(client, userdata, msg):
|
async def register_request_handler(client, userdata, msg, data):
|
||||||
data = json.loads(msg.payload.decode())
|
|
||||||
|
|
||||||
if msg.topic != "loon/register/request":
|
if msg.topic != "loon/register/request":
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|||||||
@@ -3,15 +3,10 @@ import json
|
|||||||
from loon.web.users.state import user_threads
|
from loon.web.users.state import user_threads
|
||||||
|
|
||||||
|
|
||||||
async def server_handler(client, userdata, msg):
|
async def server_handler(client, userdata, msg, data):
|
||||||
if msg.topic != "loon/server/info":
|
if msg.topic != "loon/server/info":
|
||||||
return
|
return
|
||||||
|
|
||||||
try:
|
|
||||||
data = json.loads(msg.payload.decode())
|
|
||||||
except json.JSONDecodeError:
|
|
||||||
return
|
|
||||||
|
|
||||||
envelope = json.dumps({"topic": "server/info", "payload": data})
|
envelope = json.dumps({"topic": "server/info", "payload": data})
|
||||||
|
|
||||||
for queue in list(user_threads.values()):
|
for queue in list(user_threads.values()):
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ from loon.redis.chunk import set_chunk_cache
|
|||||||
from loon.web.users.state import user_threads, user_world_requests
|
from loon.web.users.state import user_threads, user_world_requests
|
||||||
|
|
||||||
|
|
||||||
async def world_handler(client, userdata, msg):
|
async def world_handler(client, userdata, msg, data):
|
||||||
chunk_topic = re.compile(r"^loon/world/chunk/(-?\d+)/(-?\d+)$")
|
chunk_topic = re.compile(r"^loon/world/chunk/(-?\d+)/(-?\d+)$")
|
||||||
|
|
||||||
match = chunk_topic.match(msg.topic)
|
match = chunk_topic.match(msg.topic)
|
||||||
@@ -16,11 +16,6 @@ async def world_handler(client, userdata, msg):
|
|||||||
if not match:
|
if not match:
|
||||||
return
|
return
|
||||||
|
|
||||||
try:
|
|
||||||
data = json.loads(msg.payload.decode())
|
|
||||||
except json.JSONDecodeError:
|
|
||||||
return
|
|
||||||
|
|
||||||
x, z = int(match.group(1)), int(match.group(2))
|
x, z = int(match.group(1)), int(match.group(2))
|
||||||
envelope = json.dumps({"topic": f"world/chunk/{x}/{z}", "payload": data})
|
envelope = json.dumps({"topic": f"world/chunk/{x}/{z}", "payload": data})
|
||||||
coord = (x, z)
|
coord = (x, z)
|
||||||
|
|||||||
@@ -63,11 +63,12 @@ class MQTTManager:
|
|||||||
except json.decoder.JSONDecodeError:
|
except json.decoder.JSONDecodeError:
|
||||||
return
|
return
|
||||||
|
|
||||||
logger.info(f"[Received] {data}.")
|
if settings.mqtt.log_data:
|
||||||
|
logger.info(f"[Received] {data}.")
|
||||||
|
|
||||||
for handler in self.handlers:
|
for handler in self.handlers:
|
||||||
try:
|
try:
|
||||||
await handler(client, userdata, msg)
|
await handler(client, userdata, msg, data)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f'Got exception: {e}')
|
logger.error(f'Got exception: {e}')
|
||||||
|
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ host = 'mqtt.host'
|
|||||||
port = 1883
|
port = 1883
|
||||||
username = 'loon'
|
username = 'loon'
|
||||||
password = 'pwd'
|
password = 'pwd'
|
||||||
|
log_data = false
|
||||||
|
|
||||||
[jwt]
|
[jwt]
|
||||||
secret = 'secret'
|
secret = 'secret'
|
||||||
Reference in new issue
Block a user