diff options
| author | Skipper <[email protected]> | 2025-02-14 08:55:23 +0000 |
|---|---|---|
| committer | Skipper <[email protected]> | 2025-02-14 08:56:31 +0000 |
| commit | f664470829ea834de36194a311f08f691005ee01 (patch) | |
| tree | f4076310cb3f2bc2edf8fd3608ebb0eecc30c179 /plugins | |
| parent | 7e74ceff2b7d32c934fa2e42fefaee45cfab4ff9 (diff) | |
Added chat weather plugin
- Set new chat commands for fog r,g,b
- day/night commands
- visibility command
Diffstat (limited to 'plugins')
| -rw-r--r-- | plugins/chat_weather_setter.py | 52 |
1 files changed, 52 insertions, 0 deletions
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 |
