aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRitabrata Das <[email protected]>2025-02-14 20:44:39 +0530
committerGitHub <[email protected]>2025-02-14 20:44:39 +0530
commit2db93027372bd1b13794f3ab6fc8441eb3e51ebc (patch)
treef4076310cb3f2bc2edf8fd3608ebb0eecc30c179
parent1e37498c1f99c1bea1452ff21e6c549bd301d420 (diff)
parentf664470829ea834de36194a311f08f691005ee01 (diff)
Merge pull request #5 from Skipper-is/plugin_manager
Added chat weather plugin
-rw-r--r--config.py6
-rw-r--r--lib/PacketManager/packets/FSNETCMD_ENVIRONMENT.py34
-rw-r--r--plugins/chat_weather_setter.py52
-rw-r--r--proxy.py6
4 files changed, 83 insertions, 15 deletions
diff --git a/config.py b/config.py
index 1529bc3..4b5daf8 100644
--- a/config.py
+++ b/config.py
@@ -8,9 +8,9 @@ LOGGING_LEVEL = INFO
# Server Configuration
# Replace with the YSFlight server address
SERVER_HOST = "127.0.0.1"
-SERVER_PORT = 7915 # Please put where the normal YSFlight server is running
+SERVER_PORT = 7914 # Please put where the normal YSFlight server is running
# Port for the proxy server
-PROXY_PORT = 9000
+PROXY_PORT = 7915
# Welcome Message to the playe
# For formatting use {username}
@@ -61,7 +61,7 @@ SMOKE_LIFE = 5
# On Modern Linux distros you may need to create a virtual environment to install
# the dependencies
-DISCORD_ENABLED = True
+DISCORD_ENABLED = False
# Make sure to enable read message intent for the bot.
diff --git a/lib/PacketManager/packets/FSNETCMD_ENVIRONMENT.py b/lib/PacketManager/packets/FSNETCMD_ENVIRONMENT.py
index c647229..3ede2ec 100644
--- a/lib/PacketManager/packets/FSNETCMD_ENVIRONMENT.py
+++ b/lib/PacketManager/packets/FSNETCMD_ENVIRONMENT.py
@@ -39,22 +39,38 @@ class FSNETCMD_ENVIRONMENT: #33
flags |= 4
flags |=8
if midair:
- flags += 16
- flags += 32
+ flags |= 16
+ flags |= 32
if can_land_anywhere:
- flags += 64
- flags += 128
+ flags |= 64
+ flags |= 128
buffer = pack("IHHIffff", 33, 0, day_night, flags, *wind, visibility)
if with_size:
return pack("I", len(buffer))+buffer
return buffer
@staticmethod
- def setTime(buffer:bytes, night:bool, with_size:bool = True):
- if with_size:
- values = list(unpack("IHHIffff", buffer[4:]))
+ def set_time(buffer:bytes, night:bool, with_size:bool = True):
+ if len(buffer)>28:
+ values = list(unpack("IHHIffff", buffer[4:]))
else:
- values = list(unpack("IHHIffff", buffer))
+ values = list(unpack("IHHIffff", buffer))
if night: values[2] = 1
elif not night: values[2] = 0
- return pack("IHHIffff", *values)
+ packet = pack("IHHIffff", *values)
+ if with_size:
+ return pack("I", len(packet)) + packet
+ return packet
+
+ @staticmethod
+ def set_visibility(buffer:bytes, visibility:int, with_size:bool = True):
+ if len(buffer)>28: #Full data packet + the size
+ environment = FSNETCMD_ENVIRONMENT(buffer[4:])
+ else:
+ environment = FSNETCMD_ENVIRONMENT(buffer)
+ environment.visibility = visibility
+ packet = FSNETCMD_ENVIRONMENT.encode(environment.day_night, True,
+ environment.flags['blackout'], environment.flags['midair'],
+ environment.flags['can_land_anywhere'],
+ environment.wind, visibility, with_size)
+ return packet \ No newline at end of file
diff --git a/plugins/chat_weather_setter.py b/plugins/chat_weather_setter.py
new file mode 100644
index 0000000..4bcdf0b
--- /dev/null
+++ b/plugins/chat_weather_setter.py
@@ -0,0 +1,52 @@
+"""This plugin will set the weather based on a chat message.
+"""
+from lib.PacketManager.packets import FSNETCMD_SKYCOLOR, FSNETCMD_FOGCOLOR, FSNETCMD_TEXTMESSAGE, FSNETCMD_ENVIRONMENT
+from random import randint
+ENABLED = True
+
+class Plugin:
+ def __init__(self):
+ self.initialWeather = None
+ self.plugin_manager = None
+
+ def register(self, plugin_manager):
+ self.plugin_manager = plugin_manager
+ self.plugin_manager.register_hook('on_chat', self.on_chat)
+ self.plugin_manager.register_hook('on_environment_server', self.on_environment)
+
+ def on_chat(self, data, player, messages_to_client, *args):
+ if ENABLED:
+ message = FSNETCMD_TEXTMESSAGE(data).message
+ if message[:3].lower() == 'fog':
+ #We'll split the fog r,g,b message into a list of 3 integers
+ fog = list(map(int, message[4:].split(',')))
+ fog_colour_packet = FSNETCMD_FOGCOLOR.encode(fog[0], fog[1], fog[2], True)
+ messages_to_client.append(fog_colour_packet)
+
+ if message[:3].lower() == 'sky':
+ sky = list(map(int, message[4:].split(',')))
+ sky_colour_packet = FSNETCMD_SKYCOLOR.encode(sky[0], sky[1], sky[2], True)
+ messages_to_client.append(sky_colour_packet)
+
+ if message[:3].lower() == 'day' and self.initialWeather:
+ packet = FSNETCMD_ENVIRONMENT.set_time(self.initialWeather.buffer, False, True)
+ self.initialWeather = FSNETCMD_ENVIRONMENT(packet[4:])
+ messages_to_client.append(packet)
+
+ if message[:5].lower() == 'night' and self.initialWeather:
+ packet = FSNETCMD_ENVIRONMENT.set_time(self.initialWeather.buffer, True, True)
+ self.initialWeather = FSNETCMD_ENVIRONMENT(packet[4:])
+ messages_to_client.append(packet)
+
+ if message[:3].lower() == 'vis':
+ visibility = int(message[4:])
+ returnpacket = FSNETCMD_ENVIRONMENT.set_visibility(self.initialWeather.buffer, visibility, True)
+ self.initialWeather = FSNETCMD_ENVIRONMENT(returnpacket[4:])
+ messages_to_client.append(returnpacket)
+ return False
+
+ def on_environment(self, data, *args):
+ """Store the initial weather packet for the server."""
+ if ENABLED:
+ self.initialWeather = FSNETCMD_ENVIRONMENT(data)
+ return True
diff --git a/proxy.py b/proxy.py
index 82fe90b..e419123 100644
--- a/proxy.py
+++ b/proxy.py
@@ -192,9 +192,9 @@ async def handle_client(client_reader, client_writer):
asyncio.create_task(discord_send_message(CHANNEL_ID, f"{player.username} has joined the server!"))
elif packet_type == "FSNETCMD_ENVIRONMENT":
- # We set time to night
- pck = FSNETCMD_ENVIRONMENT.setTime(packet, True, False)
- data = pack("I", len(pck)) + pck
+ keep_message = plugin_manager.triggar_hook('on_environment_server', packet, player, message_to_client, message_to_server)
+ if not keep_message:
+ data = None
# Forward the packet to the other endpoint if the data packet still exists.
if data: