Exemplo n.º 1
0
        private string CreateMessage(int[] data, URMCommand com, bool bc)
        {
            string writeOut = "";

            for (int i = 1; i < regCount + 1; i++)
            {
                if (com != null && ((com.args.Length == 1 && com.args[0] == i) || (com.args.Length > 1 && ((bc && com.args[0] == i) || (!bc && com.args[1] == i)))))
                    writeOut += "<span style=\"background-color: #400000;color: #ffffff;\">" + data[i] + "</span> ";
                else
                    writeOut += data[i] + " ";
            }

            return writeOut;
        }
Exemplo n.º 2
0
        public static URMCommand Parse(string data, out string errormessage)
        {
            if (!(new List<char>{ 'S', 'Z', 'T', 'J' }).Contains(data[0]))
            {
                errormessage = "Unknown Command: '" + data[0] + "'";
                return null;
            }
            else if (data.Length < 2 || data[1] != '(')
            {
                errormessage = "Missing: '('";
                return null;
            }
            else if (data[data.Length - 1] != ')')
            {
                errormessage = "Missing: ')'";
                return null;
            }
            else if (data.Length == 3)
            {
                errormessage = "Missing arguments";
                return null;
            }

            var arglen = 1;
            switch (data[0])
            {
                case 'T':
                    arglen = 2;
                    break;
                case 'J':
                    arglen = 3;
                    break;
            }

            var ret = new URMCommand();
            ret.type = data[0];

            var args = data.Substring(2, data.Length - 3).Split(',');

            if (args.Length != arglen)
            {
                errormessage = "Incorrect argument count, command '" + ret.type + "' requiers " + arglen + " arguments";
                return null;
            }

            ret.args = new int[arglen];
            for(int i = 0;i < arglen;i++)
            {
                try
                {
                    ret.args[i] = int.Parse(args[i]);

                    if(ret.args[i] <= 0)
                    {
                        errormessage = "Argument value has to be higher then 0 at position " + (i + 1);
                        return null;
                    }
                }
                catch
                {
                    errormessage = "Incorrect argument at position: " + (i + 1);
                    return null;
                }
            }

            errormessage = "";
            return ret;
        }