Exemplo n.º 1
0
        internal void Register(Manifest mod, string launchPath, ModRegistration registration)
        {
            if (mod.Metadata.Hidden)
            {
                return;
            }

            var iconData = "";

            using (var stream = mod.Package.GetStream("icon.png"))
                if (stream != null)
                {
                    iconData = Convert.ToBase64String(stream.ReadAllBytes());
                }

            var key  = ExternalMod.MakeKey(mod);
            var yaml = new List <MiniYamlNode>()
            {
                new MiniYamlNode("Registration", new MiniYaml("", new List <MiniYamlNode>()
                {
                    new MiniYamlNode("Id", mod.Id),
                    new MiniYamlNode("Version", mod.Metadata.Version),
                    new MiniYamlNode("Title", mod.Metadata.Title),
                    new MiniYamlNode("Icon", iconData),
                    new MiniYamlNode("LaunchPath", launchPath),
                    new MiniYamlNode("LaunchArgs", "Game.Mod=" + mod.Id)
                }))
            };

            var sources = new List <string>();

            if (registration.HasFlag(ModRegistration.System))
            {
                sources.Add(Platform.SystemSupportDir);
            }

            if (registration.HasFlag(ModRegistration.User))
            {
                sources.Add(Platform.SupportDir);
            }

            // Make sure the mod is available for this session, even if saving it fails
            LoadMod(yaml.First().Value, forceRegistration: true);

            foreach (var source in sources.Distinct())
            {
                var metadataPath = Path.Combine(source, "ModMetadata");

                try
                {
                    Directory.CreateDirectory(metadataPath);
                    File.WriteAllLines(Path.Combine(metadataPath, key + ".yaml"), yaml.ToLines(false).ToArray());
                }
                catch (Exception e)
                {
                    Log.Write("debug", "Failed to register current mod metadata");
                    Log.Write("debug", e.ToString());
                }
            }
        }
Exemplo n.º 2
0
        private void SendCommandList(string sendto, string nick, IEnumerable <Commandlet> commandList)
        {
            if (!commandList.Any())
            {
                return;
            }

            var commandStrings = new List <string>();

            foreach (var commandlet in commandList)
            {
                if (string.IsNullOrEmpty(commandlet.AccessString))
                {
                    commandStrings.Add(scopeColor[commandlet.Scope] + commandlet.Command + IrcConstants.IrcColor + IrcConstants.IrcBold);
                }
                else if (Acl.Access(nick, commandlet.AccessString, false))
                {
                    commandStrings.Add(scopeColor[commandlet.Scope] + "<" + commandlet.Command + ">" + IrcConstants.IrcColor + IrcConstants.IrcBold);
                }
            }

            foreach (string com in commandStrings.ToLines(350, ", ", "Active Commands (" + scopeColor[CommandScope.Public] + "public" + IrcConstants.IrcColor + IrcConstants.IrcBold + ", " + scopeColor[CommandScope.Private] + "private" + IrcConstants.IrcColor + IrcConstants.IrcBold + ") <restricted>: ", null))
            {
                SendMessage(SendType.Message, sendto, com);
            }
        }
Exemplo n.º 3
0
 public ComplexShape CreateBlockedZone()
 {
     return(new ComplexShape()
     {
         Lines = _blockedZone
                 .ToLines(System.Windows.Media.Brushes.Red)
                 .ToList()
     });
 }
Exemplo n.º 4
0
 public ComplexShape CreateBuildZone()
 {
     return(new ComplexShape()
     {
         Lines = _buildZone
                 .ToLines(System.Windows.Media.Brushes.SandyBrown)
                 .ToList()
     });
 }
Exemplo n.º 5
0
        public IEnumerable <string> ToLines(string name)
        {
            yield return(name + ": " + Value);

            if (Nodes != null)
            {
                foreach (var line in Nodes.ToLines(false))
                {
                    yield return("\t" + line);
                }
            }
        }
Exemplo n.º 6
0
        private void ListRestricted(object sender, IrcEventArgs e)
        {
            string sendto = (string.IsNullOrEmpty(e.Data.Channel)) ? e.Data.Nick : e.Data.Channel;

            if (e.Data.MessageArray.Length > 1)
            {
                string id = e.Data.MessageArray[1];
                ListAccessrights(sendto, id);
            }
            else
            {
                foreach (string line in possibleAccessStrings.ToLines(350))
                {
                    bot.SendMessage(SendType.Message, sendto, line);
                }
            }
        }
Exemplo n.º 7
0
        public IEnumerable <string> ToLines(string key, string comment = null)
        {
            var hasKey     = !string.IsNullOrEmpty(key);
            var hasValue   = !string.IsNullOrEmpty(Value);
            var hasComment = comment != null;

            yield return((hasKey ? key + ":" : "")
                         + (hasValue ? " " + Value.Replace("#", "\\#") : "")
                         + (hasComment ? (hasKey || hasValue ? " " : "") + "#" + comment : ""));

            if (Nodes != null)
            {
                foreach (var line in Nodes.ToLines())
                {
                    yield return("\t" + line);
                }
            }
        }
Exemplo n.º 8
0
        void ListAccessrights(string sendto, string name)
        {
            var message = new List <string>();

            if (name.StartsWith(GroupPrefix) && accessList.ContainsKey(name))
            {
                message.AddRange(accessList[name].ToLines(350, ", ", "Group Rights: ", ""));
            }
            else
            {
                foreach (string id in Identified(name))
                {
                    if (id == superUser)
                    {
                        message.Add("User Rights from '{0}': This user is botmaster".Fill(id));
                    }
                    else if (accessList.ContainsKey(id))
                    {
                        message.AddRange(accessList[id].ToLines(350, ", ", "User Rights from '{0}': ".Fill(id), ""));
                    }
                    foreach (string @group in GetGroups(id))
                    {
                        if (accessList.ContainsKey(@group))
                        {
                            message.AddRange(accessList[@group].ToLines(350, ", ", "inherited rights from group '{0}': ".Fill(@group), ""));
                        }
                    }
                }

                if (message.Count == 0)
                {
                    message.Add(name.StartsWith(GroupPrefix)
                                    ? "Group '{0}' does not exist or has no rights set".Fill(name)
                                    : "User '{0}' does not exist or has no rights set".Fill(name));
                }
            }
            foreach (var line in message.ToLines(350, " / "))
            {
                bot.SendMessage(SendType.Message, sendto, line);
            }
        }
Exemplo n.º 9
0
        private CurveArray getSampleProfile()
        {
            var result = new CurveArray();

            var p0 = new XYZ(0, 0, 0);
            var p1 = new XYZ(40, 0, 0);
            var p2 = new XYZ(40, 40, 0);
            var p3 = new XYZ(0, 40, 0);
            var p4 = new XYZ(0, 0, 0);

            var points = new List <XYZ>()
            {
                p0, p1, p2, p3, p4
            };

            var lines = points.ToLines();

            foreach (var line in lines)
            {
                result.Append(line);
            }

            return(result);
        }
Exemplo n.º 10
0
 public static string WriteToString(this List <MiniYamlNode> y)
 {
     // Remove all trailing newlines and restore the final EOF newline
     return(y.ToLines().JoinWith("\n").TrimEnd('\n') + "\n");
 }
Exemplo n.º 11
0
 public static void WriteToFile(this List <MiniYamlNode> y, string filename)
 {
     File.WriteAllLines(filename, y.ToLines().Select(x => x.TrimEnd()).ToArray());
 }
Exemplo n.º 12
0
        internal void Register(Manifest mod)
        {
            if (mod.Metadata.Hidden)
            {
                return;
            }

            var iconData = "";

            using (var stream = mod.Package.GetStream("icon.png"))
                if (stream != null)
                {
                    iconData = Convert.ToBase64String(stream.ReadAllBytes());
                }

            var key  = ExternalMod.MakeKey(mod);
            var yaml = new List <MiniYamlNode>()
            {
                new MiniYamlNode("Registration", new MiniYaml("", new List <MiniYamlNode>()
                {
                    new MiniYamlNode("Id", mod.Id),
                    new MiniYamlNode("Version", mod.Metadata.Version),
                    new MiniYamlNode("Title", mod.Metadata.Title),
                    new MiniYamlNode("Icon", iconData),
                    new MiniYamlNode("LaunchPath", launchPath),
                    new MiniYamlNode("LaunchArgs", "Game.Mod=" + mod.Id)
                }))
            };

            var supportPath = Platform.ResolvePath(Path.Combine("^", "ModMetadata"));

            try
            {
                // Make sure the mod is available for this session, even if saving it fails
                LoadMod(yaml.First().Value);

                Directory.CreateDirectory(supportPath);
                File.WriteAllLines(Path.Combine(supportPath, key + ".yaml"), yaml.ToLines(false).ToArray());
            }
            catch (Exception e)
            {
                Log.Write("debug", "Failed to register currrent mod metadata");
                Log.Write("debug", e.ToString());
            }

            // Clean up stale mod registrations:
            //  - LaunchPath no longer exists (uninstalled)
            //  - LaunchPath and mod match the current mod, but version differs (newer version installed on top)
            List <string> toRemove = null;

            foreach (var kv in mods)
            {
                var k = kv.Key;
                var m = kv.Value;
                if (!File.Exists(m.LaunchPath) || (m.LaunchPath == launchPath && m.Id == mod.Id && k != key))
                {
                    Log.Write("debug", "Removing stale mod metadata entry '{0}'", k);
                    if (toRemove == null)
                    {
                        toRemove = new List <string>();
                    }

                    toRemove.Add(k);
                    var path = Path.Combine(supportPath, k + ".yaml");
                    try
                    {
                        File.Delete(path);
                    }
                    catch (Exception e)
                    {
                        Log.Write("debug", "Failed to remove mod metadata file '{0}'", path);
                        Log.Write("debug", e.ToString());
                    }
                }
            }

            if (toRemove != null)
            {
                foreach (var r in toRemove)
                {
                    mods.Remove(r);
                }
            }
        }
        void ListAccessrights(string sendto, string name)
        {
            var message = new List<string>();
            if (name.StartsWith(GroupPrefix) && accessList.ContainsKey(name))
            {
                message.AddRange(accessList[name].ToLines(350, ", ", "Group Rights: ", ""));
            }
            else
            {
                foreach (string id in Identified(name))
                {
                    if (id == superUser)
                    {
                        message.Add("User Rights from '{0}': This user is botmaster".Fill(id));
                    }
                    else if (accessList.ContainsKey(id))
                    {
                        message.AddRange(accessList[id].ToLines(350, ", ", "User Rights from '{0}': ".Fill(id), ""));
                    }
                    foreach (string @group in GetGroups(id))
                    {
                        if (accessList.ContainsKey(@group))
                        {
                            message.AddRange(accessList[@group].ToLines(350, ", ", "inherited rights from group '{0}': ".Fill(@group), ""));
                        }
                    }
                }

                if (message.Count == 0)
                {
                    message.Add(name.StartsWith(GroupPrefix)
                                    ? "Group '{0}' does not exist or has no rights set".Fill(name)
                                    : "User '{0}' does not exist or has no rights set".Fill(name));
                }
            }
            foreach (var line in message.ToLines(350, " / "))
            {
                bot.SendMessage(SendType.Message, sendto, line);
            }
        }
Exemplo n.º 14
0
        private void SendCommandList(string sendto, string nick, IEnumerable<Commandlet> commandList)
        {
            if (!commandList.Any()) return;

            var commandStrings = new List<string>();
            foreach (var commandlet in commandList)
            {
                if (string.IsNullOrEmpty(commandlet.AccessString))
                {
                    commandStrings.Add(scopeColor[commandlet.Scope] + commandlet.Command + IrcConstants.IrcColor + IrcConstants.IrcBold);
                }
                else if (Acl.Access(nick, commandlet.AccessString, false))
                {
                    commandStrings.Add(scopeColor[commandlet.Scope] + "<" + commandlet.Command + ">" + IrcConstants.IrcColor + IrcConstants.IrcBold);
                }
            }

            foreach (string com in commandStrings.ToLines(350, ", ", "Active Commands (" + scopeColor[CommandScope.Public] + "public" + IrcConstants.IrcColor + IrcConstants.IrcBold + ", " + scopeColor[CommandScope.Private] + "private" + IrcConstants.IrcColor + IrcConstants.IrcBold + ") <restricted>: ", null))
            {
                SendMessage(SendType.Message, sendto, com);
            }
        }