private void OnReceiveAddonData(AddonDataPacket packet, NetPeer peer) { if (ClientAddons.TryGetValue(packet.AddonId, out IAddonClient <IConfig> addon)) { addon.OnMessageReceived(new NetDataReader(packet.Data)); } else { Logger.Error($"Failed receiving data while addon with id \"{packet.AddonId}\" is not loaded!"); } }
private void OnUnloadAddons(UnloadAddonPacket packet, NetPeer peer) { foreach (var addon in packet.AddonIds) { if (!InstalledAddons.TryGetValue(addon, out AddonInfo aInfo)) { continue; } if (UnregisterCommandsFromAddon(addon)) { Commands.Remove(addon); } if (ClientAddons.TryGetValue(addon, out IAddonClient <IConfig> cAddon)) { cAddon.OnDisable(); } { Logger.Info($"Disabled RemoteAddon \"{aInfo.AddonName}\" ({aInfo.AddonVersion}) made by {aInfo.AddonAuthor}"); } InstalledAddons.Remove(addon); } }
private void OnReceiveAddons(SendAddonsInfoPacket packet, NetPeer peer) { foreach (var addon in packet.Addons) { if (!InstalledAddons.ContainsKey(addon.AddonId)) { InstalledAddons.Add(addon.AddonId, addon); } List <string> MissingInfo = new List <string>(); if (!plugin.Config.Permissions.ReceivePermissions.Contains(AddonSendPermissionTypes.Everything) && addon.SendPermissions.Any(p => p != (byte)AddonSendPermissionTypes.None)) { foreach (var sendPerm in addon.SendPermissions) { if (!plugin.Config.Permissions.ReceivePermissions.Contains((AddonSendPermissionTypes)sendPerm)) { MissingInfo.Add($" - Missing SEND permission \"{(AddonSendPermissionTypes)sendPerm}\""); } } } if (!plugin.Config.Permissions.SendPermissions.Contains(AddonReceivePermissionTypes.Everything) && addon.ReceivePermissions.Any(p => p != (byte)AddonReceivePermissionTypes.None)) { foreach (var sendPerm in addon.ReceivePermissions) { if (!plugin.Config.Permissions.SendPermissions.Contains((AddonReceivePermissionTypes)sendPerm)) { MissingInfo.Add($" - Missing RECEIVE permission \"{(AddonReceivePermissionTypes)sendPerm}\""); } } } if (MissingInfo.Count != 0) { Logger.Info($"Addon \"{addon.AddonName}\" will not work properly, addon requires these permissions\n{string.Join(Environment.NewLine, MissingInfo)}"); } var config = Encoding.UTF8.GetString(addon.RemoteConfig); if (!File.Exists(Path.Combine(remoteConfigsPath, $"{addon.AddonName}.yml"))) { File.WriteAllText(Path.Combine(remoteConfigsPath, $"{addon.AddonName}.yml"), config); Logger.Info($"Added missing config for addon \"{addon.AddonName}\"!"); } var rawConfig = File.ReadAllText(Path.Combine(remoteConfigsPath, $"{addon.AddonName}.yml")); var receivedConfig = Deserializer.Deserialize <Dictionary <string, object> >(config); var loadedConfig = Deserializer.Deserialize <Dictionary <string, object> >(rawConfig); var _temp = receivedConfig.Except(loadedConfig); foreach (var missingval in _temp) { if (loadedConfig.ContainsKey(missingval.Key)) { continue; } loadedConfig.Add(missingval.Key, missingval.Value); Logger.Info($"Added missing config parameter \"{missingval.Key}\" in addon \"{addon.AddonName}\"!"); } rawConfig = Serializer.Serialize(loadedConfig); File.WriteAllText(Path.Combine(remoteConfigsPath, $"{addon.AddonName}.yml"), rawConfig); if (ClientAddons.TryGetValue(addon.AddonId, out IAddonClient <IConfig> clientAddon)) { clientAddon.OnReady(); } else { Logger.Info($"RemoteAddon \"{addon.AddonName}\" ({addon.AddonVersion}) made by {addon.AddonAuthor} is ready!"); } PacketProcessor.Send <AddonOkPacket>(NetworkListener, new AddonOkPacket() { AddonId = addon.AddonId, RemoteConfig = Encoding.UTF8.GetBytes(rawConfig) }, DeliveryMethod.ReliableOrdered); } }