Пример #1
0
        internal static void Set_SendNow(CNCGetterSetter setter)
        {
            string scriptContent = "declare Integer NC_UpdateTick for LocalUser = Now; NC_UpdateTick = Now;";

            scriptContent += $"declare Integer NC_EnvironnementTick for LocalUser = Now; NC_EnvironnementTick = {Environment.TickCount};";
            scriptContent += $"declare NC_{setter.varPrefix}_{setter.varName} for LocalUser = {CManialink.ToCValue(setter.Value)};";
            scriptContent += $"NC_{setter.varPrefix}_{setter.varName} = {CManialink.ToCValue(setter.Value)};";
            scriptContent += $"log(NC_{setter.varPrefix}_{setter.varName});";

            string content = $@"
<?xml version={"\"1.0\""} encoding={"\"utf-8\""} standalone={"\"yes\""} ?>
<manialink version={"\"2\""} name={"\"NC2-Var-Updater\""} id={$"\"NC2:gc:({setter.varPrefix}{setter.varName}):time{Environment.TickCount}\""}>
<script><!--
main() {"{"} {scriptContent} {"}"}
--></script>
</manialink>
";

            CManialink manialink = new CManialink(content, null)
            {
                hasCorrectId = true, hasCorrectName = true
            };

            if (setter.Servers == null ||
                setter.Servers.Count() == 0)
            {
                manialink.Send(null, 100, setter.Players);
            }
            else
            {
                manialink.Send(setter.Servers.Select(s => s.Manager).ToArray(), 100, setter.Players);
            }
        }
Пример #2
0
        internal static void Loop()
        {
            try
            {
                foreach (var setter in Setters)
                {
                    Set_SendNow(setter);
                }
                foreach (var _event in Events)
                {
                    string scriptContent = "declare Integer NC_UpdateTick for LocalUser = Now; NC_UpdateTick = Now;";

                    var eventVars = new StringBuilder("[");
                    int index     = 0;
                    foreach (var toAdd in _event.Data)
                    {
                        eventVars.Append('"');
                        eventVars.Append(toAdd);
                        eventVars.Append('"');
                        if (index < _event.Data.Length - 1)
                        {
                            eventVars.Append(',');
                        }
                        index++;
                    }
                    eventVars.Append(']');

                    scriptContent += $"\n// Events part\n";
                    scriptContent += $@"SendCustomEvent(""MNC"", {eventVars.ToString()}); log(""event sent!"");";
                    string content = $@"
<?xml version={"\"1.0\""} encoding={"\"utf-8\""} standalone={"\"yes\""} ?>
<manialink version={"\"2\""} name={"\"NC2-Events\""} id={$"\"NC2:ev:({_event.varPrefix}{_event.varName}):time{Environment.TickCount}\""}>
<script><!--
main() {"{"} {scriptContent} {"}"}
--></script>
</manialink>
";

                    CManialink manialink = new CManialink(content, null)
                    {
                        hasCorrectId = true, hasCorrectName = true
                    };
                    manialink.Send(null, 15000, _event.Players);
                }

                Setters = new List <CNCGetterSetter>();
                Getters = new List <CNCGetterSetter>();
                Events  = new List <CNCEvent>();
            }
            catch (Exception ex)
            {
                bool safe = true;
                if (ex is NullReferenceException)
                {
                    Setters.RemoveAll(o => o == null || o.Value == null || o.varName == null || o.varPrefix == null);
                }
                if (safe)
                {
                    Loop();
                }
            }
        }