Beispiel #1
0
        private async void btnControlsConfigure_Click(object sender, RoutedEventArgs e)
        {
            // get button name
            Button button = (Button)sender;
            string name   = button.Name;

            // remove beginning and end
            name = name.Replace("btn", "").Replace("Configure", "");

            // get the relevant combox
            ComboBox cb = (ComboBox)this.FindName("cmb" + name);

            // get the virtual port number
            string selectedString = cb.SelectionBoxItem.ToString();
            int    portNum        = Convert.ToInt32(selectedString.Replace("Virtual Port ", ""));

            DeviceDefinition dev = new DeviceDefinition();

            switch (name)
            {
            case "Md3ButtonGamepad":
                dev = Md.ThreeButton(portNum);
                break;

            case "Md6ButtonGamepad":
                dev = Md.SixButton(portNum);
                break;

            case "Md2ButtonGamepad":
                dev = Md.TwoButton(portNum);
                break;

            case "MdMegaMouse":
                dev = Md.MegaMouse(portNum);
                break;

            default:
                return;
            }

            mw.ControllerDefinition = dev;

            // launch controller configuration window
            Grid RootGrid = (Grid)mw.FindName("RootGrid");
            await mw.ShowChildWindowAsync(new ConfigureController()
            {
                IsModal         = true,
                AllowMove       = false,
                Title           = "Controller Configuration",
                CloseByEscape   = false,
                CloseOnOverlay  = false,
                ShowCloseButton = false
            }, RootGrid);
        }
Beispiel #2
0
        public void RenderShouldParseSpecification()
        {
            var testDirectory = Directory.GetParent(Directory.GetCurrentDirectory()).Parent?.Parent;

            if (testDirectory != null)
            {
                var mdText   = new StreamReader($"{testDirectory.FullName}\\MarkdownSpec.md").ReadToEnd();
                var htmlText = new StreamReader($"{testDirectory.FullName}\\MarkdownSpec.html").ReadToEnd();
                Md.Render(mdText).Should().Be(htmlText);
            }
        }
        public override string ToString()
        {
            StringBuilder sb = new StringBuilder();

            sb.Append("class PaymentRequest {\n");

            sb.Append(base.ToString());
            sb.Append("    md: ").Append(Md.ToIndentedString()).Append("\n");
            sb.Append("    paResponse: ").Append(PaResponse.ToIndentedString()).Append("\n");
            sb.Append("}");
            return(sb.ToString());
        }
        public ActionResult login(Login login)
        {
            var unitofwork = new UnitOFWork.UnitOfWork(new ApplicationDbContext());

            string role = unitofwork.UserInfo.getUserRole(login.UserId, login.Password);

            if (role == "Man")
            {
                Manager man = unitofwork.Manager.Get(login.UserId);
                Session["username"] = man.Name;
                Session["ui"]       = man.Id;
                Session["bi"]       = man.BranchId;

                return(RedirectToAction("Home", "Managers"));
            }

            else if (role == "Cus")
            {
                Customer cus = unitofwork.Customer.Get(login.UserId);
                Session["username"] = cus.Name;
                Session["ui"]       = cus.Id;
                Session["bi"]       = cus.BranchId;

                return(RedirectToAction("Index", "Customers"));  // dummy dashboard for customer
            }

            else if (role == "Emp")
            {
                Employee emp = unitofwork.Employee.Get(login.UserId);
                Session["username"] = emp.Name;
                Session["ui"]       = emp.Id;
                Session["bi"]       = emp.BranchId;

                return(RedirectToAction("Home", "Employees"));
            }

            else if (role == "md")
            {
                Md md = db.Mds.Find(login.UserId);

                Session["username"] = md.Name;
                Session["ui"]       = md.Id;
                return(RedirectToAction("Index", "Md"));
            }
            else
            {
                Session["error"] = role;
                return(RedirectToAction("login"));
            }
        }
Beispiel #5
0
            public void WhenEnumerable_ThenReturnList()
            {
                string expected =
                    "1. Wrote code" + Environment.NewLine +
                    "2. Wrote unit tests" + Environment.NewLine;

                IEnumerable <string> items = new List <string> {
                    "Wrote code", "Wrote unit tests"
                };

                var result = Md.OrderedList(items);

                Assert.That(result, Is.EqualTo(expected));
            }
Beispiel #6
0
        public void SetUp()
        {
            var neutralizingSymbols = "0123456789".ToCharArray();
            var emTag = new Tag("_", "em", neutralizingSymbols, new List <string> {
                "__"
            });
            var strongTag = new Tag("__", "strong", neutralizingSymbols);
            var tagList   = new List <Tag>
            {
                emTag,
                strongTag
            };

            md = new Md(tagList);
        }
Beispiel #7
0
            public void WhenCodeIsNotNullOrEmpty_ThenReturnCodeBlock()
            {
                var code = "int x = 1;" + Environment.NewLine +
                           "int y = 2;" + Environment.NewLine;

                var expected =
                    "```csharp" + Environment.NewLine +
                    "int x = 1;" + Environment.NewLine +
                    "int y = 2;" + Environment.NewLine +
                    "```" + Environment.NewLine;

                var result = Md.CodeBlock(code, "csharp");

                Assert.That(result, Is.EqualTo(expected));
            }
Beispiel #8
0
        private double GetAverageWorkTime(string rawText, int count)
        {
            var times = new List <long>();
            var watch = new Stopwatch();

            for (var i = 0; i < count; i++)
            {
                watch.Start();
                Md.Render(rawText);
                watch.Stop();
                times.Add(watch.ElapsedTicks);
                watch.Reset();
            }

            return(times.Average());
        }
Beispiel #9
0
            public void WhenEnumerable_ThenReturnList()
            {
                string expected =
                    "- [x] Wrote code" + Environment.NewLine +
                    "- [ ] Wrote unit tests" + Environment.NewLine;

                IEnumerable <TaskListItem> items = new List <TaskListItem>
                {
                    new TaskListItem("Wrote code", true),
                    new TaskListItem("Wrote unit tests")
                };

                var result = Md.TaskList(items);

                Assert.That(result, Is.EqualTo(expected));
            }
        internal static void ScaffoldMdReadMe(this DapperProject project)
        {
            var readMe = new MdDocument();

            readMe.H1("CatFactory ==^^==: Scaffolding Made Easy");

            readMe.WriteLine("How to use this code on your ASP.NET Core Application:");

            readMe.OrderedList(
                "Install SqlClient and Dapper packages",
                "Register the Repositories in ConfigureServices method (Startup class)"
                );

            readMe.H2("Install packages");

            readMe.WriteLine("You can install the NuGet packages in Visual Studio or Windows Command Line, for more info:");

            readMe.WriteLine(
                Md.Link("Install and manage packages with the Package Manager Console in Visual Studio (PowerShell)", "https://docs.microsoft.com/en-us/nuget/consume-packages/install-use-packages-powershell")
                );

            readMe.WriteLine(
                Md.Link(".NET Core CLI", "https://docs.microsoft.com/en-us/dotnet/core/tools/dotnet-add-package")
                );

            readMe.H2("Register Repositories");

            readMe.WriteLine("Add the following code lines in {0} method (Startup class):", Md.Bold("ConfigureServices"));
            readMe.WriteLine("  services.AddScope<{0}, {1}>()", "IDboRepository", "DboRepository");

            readMe.WriteLine("Happy scaffolding!");

            var codeProjectLink = Md.Link("Scaffolding Dapper with CatFactory", "https://www.codeproject.com/Articles/1213355/Scaffolding-Dapper-with-CatFactory");

            readMe.WriteLine("You can check the guide for this package in: {0}", codeProjectLink);

            var gitHubRepositoryLink = Md.Link("GitHub repository", "https://github.com/hherzl/CatFactory.Dapper");

            readMe.WriteLine("Also you can check the source code on {0}", gitHubRepositoryLink);

            readMe.WriteLine("Special Thanks for {0} to let me help to Dapper community", Md.Link("Edson Ferreira", "https://github.com/EdsonF"));

            readMe.WriteLine("CatFactory Development Team ==^^==");

            File.WriteAllText(Path.Combine(project.OutputDirectory, "CatFactory.Dapper.ReadMe.MD"), readMe.ToString());
        }
Beispiel #11
0
        private INode CreateModificatorNode(Md modificatorAttribute, IEnumerable <INode> nodes)
        {
            switch (modificatorAttribute)
            {
            case Md.Emphasis:
                return(new EmphasisModificatorNode(nodes));

            case Md.Strong:
                return(new StrongModificatorNode(nodes));

            case Md.Code:
                return(new CodeModificatorNode(nodes));

            default:
                throw new ArgumentException($"Unknown modificator attribute: {modificatorAttribute}");
            }
        }
        internal static void ScaffoldMdReadMe(this EntityFrameworkCoreProject project)
        {
            var readMe = new MdDocument();

            readMe.H1("CatFactory ==^^==: Scaffolding Made Easy");

            readMe.WriteLine("How to use this code on your ASP.NET Core Application:");

            readMe.OrderedList(
                "Install EntityFrameworkCore.SqlServer package",
                "Register the DbContext and Repositories in ConfigureServices method (Startup class)"
                );

            readMe.H2("Install package");

            readMe.WriteLine("You can install the NuGet packages in Visual Studio or Windows Command Line, for more info:");

            readMe.WriteLine(
                Md.Link("Install and manage packages with the Package Manager Console in Visual Studio (PowerShell)", "https://docs.microsoft.com/en-us/nuget/consume-packages/install-use-packages-powershell")
                );

            readMe.WriteLine(
                Md.Link(".NET Core CLI", "https://docs.microsoft.com/en-us/dotnet/core/tools/dotnet-add-package")
                );

            readMe.H2("Register DbContext and Repositories");

            readMe.WriteLine("Add the following code lines in {0} method (Startup class):", Md.Bold("ConfigureServices"));
            readMe.WriteLine("  services.AddDbContext<{0}>(options => options.UseSqlServer(\"ConnectionString\"));", project.GetDbContextName(project.Database));
            readMe.WriteLine("  services.AddScope<{0}, {1}>()", "IDboRepository", "DboRepository");

            readMe.WriteLine("Happy scaffolding!");

            var codeProjectLink = Md.Link("Scaffolding Entity Framework Core with CatFactory", "https://www.codeproject.com/Articles/1160615/Scaffolding-Entity-Framework-Core-with-CatFactory");

            readMe.WriteLine("You can check the guide for this package in: {0}", codeProjectLink);

            var gitHubRepositoryLink = Md.Link("GitHub repository", "https://github.com/hherzl/CatFactory.EntityFrameworkCore");

            readMe.WriteLine("Also you can check the source code on {0}", gitHubRepositoryLink);

            readMe.WriteLine("CatFactory Development Team ==^^==");

            File.WriteAllText(Path.Combine(project.OutputDirectory, "CatFactory.EntityFrameworkCore.ReadMe.MD"), readMe.ToString());
        }
Beispiel #13
0
        public void Render_WorkLinear(string rawText)
        {
            for (var i = 0; i < 10; i++)
            {
                Md.Render(rawText);
            }

            var averageTimeRawText = GetAverageWorkTime(rawText, 100);

            var oneThousandRawText            = Concate(rawText, rawText, 1000);
            var averageTimeOneThousandRawText = GetAverageWorkTime(oneThousandRawText, 100);

            var twoThousandRawText            = Concate(oneThousandRawText, rawText, 1000);
            var averageTimeTwoThousandRawText = GetAverageWorkTime(twoThousandRawText, 100);

            averageTimeOneThousandRawText.Should().BeLessOrEqualTo(1000 * averageTimeRawText);
            averageTimeTwoThousandRawText.Should().BeLessOrEqualTo(2.5 * averageTimeOneThousandRawText);
        }
Beispiel #14
0
 public void Render_Performance_HandlesTagsInLinearTime(int length, int @const)
 {
     for (var i = 0; i < 5; i++)
     {
         var line       = RandomString(length);
         var secondLine = RandomString(length * @const);
         GC.Collect();
         var watch = System.Diagnostics.Stopwatch.StartNew();
         Md.Render(line);
         watch.Stop();
         var elapsedMs = watch.ElapsedMilliseconds;
         GC.Collect();
         watch = System.Diagnostics.Stopwatch.StartNew();
         Md.Render(secondLine);
         watch.Stop();
         (watch.ElapsedMilliseconds / elapsedMs).Should().BeLessOrEqualTo((long)(@const * 1.5));
     }
 }
Beispiel #15
0
        public override StringBuilder Convert(StringBuilder tagsText, StringBuilder text, int start, int finish)
        {
            var result = new StringBuilder();

            result.Append(TagName);
            foreach (var t in Split(tagsText, ';'))
            {
                AppendElemet(t);
            }
            result.Append(TagName);
            return(FormTags(result));

            void AppendElemet(StringBuilder t)
            {
                result.Append($@"<{Constants.TagHtml.li}>");
                result.Append(Md.Render(t));
                result.Append($@"<\{Constants.TagHtml.li}>");
            }
        }
        public void TestTestsReadMeMd()
        {
            var readme = new MdDocument();

            readme.H1("Tests for Snacks API");

            readme.WriteLine("{0} file contains the following tests for {1}:", Md.Italics("Store API.postman_collection.json"), Md.Bold("Snacks API"));

            readme.Write(
                new MdTable
            {
                Header = new MdTableHeader("Name", "Requires Authentication", "Role", "Description"),
                Rows   =
                {
                    new MdTableRow("Get Products",         "No", "None", "Retrieves products"),
                    new MdTableRow("Get Products by Name", "No", "None", "Retrieves products filtering by name")
                }
            }
                );

            File.WriteAllText("C:\\Temp\\CatFactory\\tests.README.md", readme.ToString());
        }
    public override string ToString()
    {
        var cultureInfo   = CultureInfo.CurrentCulture;
        var listSeparator = TokenizerHelper.GetNumericListSeparator(cultureInfo);

        // Initial capacity [128] is an estimate based on a sum of:
        // 72 = 6x double (twelve digits is generous for the range of values likely)
        //  4 = 4x separator characters
        var sb = new StringBuilder(128);

        sb.Append(Xs.ToString(cultureInfo));
        sb.Append(listSeparator);
        sb.Append(Sm.ToString(cultureInfo));
        sb.Append(listSeparator);
        sb.Append(Md.ToString(cultureInfo));
        sb.Append(listSeparator);
        sb.Append(Lg.ToString(cultureInfo));
        sb.Append(listSeparator);
        sb.Append(Xl.ToString(cultureInfo));
        sb.Append(listSeparator);
        sb.Append(Xxl.ToString(cultureInfo));
        return(sb.ToString());
    }
 public void SetUp()
 {
     mdParser = new Md();
 }
Beispiel #19
0
 public void SetUp()
 {
     renderer = new Md();
 }
Beispiel #20
0
        /// <summary>
        ///     Gets the hash code
        /// </summary>
        /// <returns>Hash code</returns>
        public override int GetHashCode()
        {
            // credit: http://stackoverflow.com/a/263416/677735
            unchecked // Overflow is fine, just wrap
            {
                var hash = 41;
                // Suitable nullity checks etc, of course :)

                if (Side != null)
                {
                    hash = hash * 59 + Side.GetHashCode();
                }

                if (Sv != null)
                {
                    hash = hash * 59 + Sv.GetHashCode();
                }

                if (Pt != null)
                {
                    hash = hash * 59 + Pt.GetHashCode();
                }

                if (Ot != null)
                {
                    hash = hash * 59 + Ot.GetHashCode();
                }

                if (P != null)
                {
                    hash = hash * 59 + P.GetHashCode();
                }

                if (Sc != null)
                {
                    hash = hash * 59 + Sc.GetHashCode();
                }

                if (Rc != null)
                {
                    hash = hash * 59 + Rc.GetHashCode();
                }

                if (S != null)
                {
                    hash = hash * 59 + S.GetHashCode();
                }

                if (Pd != null)
                {
                    hash = hash * 59 + Pd.GetHashCode();
                }

                if (Rac != null)
                {
                    hash = hash * 59 + Rac.GetHashCode();
                }

                if (Md != null)
                {
                    hash = hash * 59 + Md.GetHashCode();
                }

                if (Sl != null)
                {
                    hash = hash * 59 + Sl.GetHashCode();
                }

                if (Avp != null)
                {
                    hash = hash * 59 + Avp.GetHashCode();
                }

                if (Sm != null)
                {
                    hash = hash * 59 + Sm.GetHashCode();
                }

                if (Id != null)
                {
                    hash = hash * 59 + Id.GetHashCode();
                }

                if (Bsp != null)
                {
                    hash = hash * 59 + Bsp.GetHashCode();
                }

                if (Status != null)
                {
                    hash = hash * 59 + Status.GetHashCode();
                }

                if (Sr != null)
                {
                    hash = hash * 59 + Sr.GetHashCode();
                }

                if (Cd != null)
                {
                    hash = hash * 59 + Cd.GetHashCode();
                }

                return(hash);
            }
        }
Beispiel #21
0
 public static void Render_IfAfterOpenUnderscoreFollowWhitespace_DoNotProcess(string text, string expected)
 {
     Md.Render(text)
     .Should()
     .BeEquivalentTo(expected);
 }
Beispiel #22
0
 public static void Render_NotPairedUnderscoresDoNotProcess(string text, string expected)
 {
     Md.Render(text)
     .Should()
     .BeEquivalentTo(expected);
 }
Beispiel #23
0
 public static void Render_UnderscoreBetweenNumbersDoNotProcess(string text, string expected)
 {
     Md.Render(text)
     .Should()
     .BeEquivalentTo(expected);
 }
Beispiel #24
0
 public static void Render_InsideEmphasisedTextCanNotBeBoldText(string text, string expected)
 {
     Md.Render(text)
     .Should()
     .BeEquivalentTo(expected);
 }
Beispiel #25
0
 public static void Render_TextSurroundedByDoubleUnderscore_ShouldBeBolded(string text, string expected)
 {
     Md.Render(text)
     .Should()
     .BeEquivalentTo(expected);
 }
Beispiel #26
0
 public static void Render_AnySymbolCanBeEscaped(string text, string expected)
 {
     Md.Render(text)
     .Should()
     .BeEquivalentTo(expected);
 }
Beispiel #27
0
 public static void Render_IfWhitespaceBeforeCloseUnderscore_DoNotProcess(string text, string expected)
 {
     Md.Render(text)
     .Should()
     .BeEquivalentTo(expected);
 }
Beispiel #28
0
        /// <summary>
        /// Handle the player connection.
        /// </summary>
        /// <param name="request">The <see cref="ConnectionRequest"/> instance.</param>
        private static void HandleConnection(ConnectionRequest request)
        {
            try
            {
                int position = request.Data.Position;
                if (!request.Data.TryGetByte(out byte result1) || !request.Data.TryGetByte(out byte result2) || !request.Data.TryGetByte(out byte result3) || result1 != CustomNetworkManager.Major || result2 != CustomNetworkManager.Minor || result3 != CustomNetworkManager.SyncedRevision)
                {
                    CustomLiteNetLib4MirrorTransport.RequestWriter.Reset();
                    CustomLiteNetLib4MirrorTransport.RequestWriter.Put((byte)3);
                    request.RejectForce(CustomLiteNetLib4MirrorTransport.RequestWriter);
                }
                else
                {
                    bool flag = request.Data.TryGetInt(out int result4);
                    if (!request.Data.TryGetBytesWithLength(out byte[] result5))
                    {
                        flag = false;
                    }
                    if (!flag)
                    {
                        CustomLiteNetLib4MirrorTransport.RequestWriter.Reset();
                        CustomLiteNetLib4MirrorTransport.RequestWriter.Put((byte)15);
                        request.RejectForce(CustomLiteNetLib4MirrorTransport.RequestWriter);
                    }
                    else if (CustomLiteNetLib4MirrorTransport.DelayConnections)
                    {
                        CustomLiteNetLib4MirrorTransport.PreauthDisableIdleMode();
                        CustomLiteNetLib4MirrorTransport.RequestWriter.Reset();
                        CustomLiteNetLib4MirrorTransport.RequestWriter.Put((byte)17);
                        CustomLiteNetLib4MirrorTransport.RequestWriter.Put(CustomLiteNetLib4MirrorTransport.DelayTime);
                        if (CustomLiteNetLib4MirrorTransport.DelayVolume < byte.MaxValue)
                        {
                            ++CustomLiteNetLib4MirrorTransport.DelayVolume;
                        }
                        if (CustomLiteNetLib4MirrorTransport.DelayVolume < CustomLiteNetLib4MirrorTransport.DelayVolumeThreshold)
                        {
                            ServerConsole.AddLog(
                                $"Delayed connection incoming from endpoint {request.RemoteEndPoint} by {CustomLiteNetLib4MirrorTransport.DelayTime} seconds.");
                            request.Reject(CustomLiteNetLib4MirrorTransport.RequestWriter);
                        }
                        else
                        {
                            ServerConsole.AddLog(
                                $"Force delayed connection incoming from endpoint {request.RemoteEndPoint} by {CustomLiteNetLib4MirrorTransport.DelayTime} seconds.");
                            request.RejectForce(CustomLiteNetLib4MirrorTransport.RequestWriter);
                        }
                    }
                    else
                    {
                        if (CustomLiteNetLib4MirrorTransport.UseChallenge)
                        {
                            if (result4 == 0 || result5 == null || result5.Length == 0)
                            {
                                if (!CustomLiteNetLib4MirrorTransport.CheckIpRateLimit(request))
                                {
                                    return;
                                }
                                int    num = 0;
                                string key = string.Empty;
                                for (byte index = 0; index < 3; ++index)
                                {
                                    num = RandomGenerator.GetInt32();
                                    if (num == 0)
                                    {
                                        num = 1;
                                    }
                                    key = request.RemoteEndPoint.Address + "-" + num;
                                    if (CustomLiteNetLib4MirrorTransport.Challenges.ContainsKey(key))
                                    {
                                        if (index == 2)
                                        {
                                            CustomLiteNetLib4MirrorTransport.RequestWriter.Reset();
                                            CustomLiteNetLib4MirrorTransport.RequestWriter.Put((byte)4);
                                            request.RejectForce(CustomLiteNetLib4MirrorTransport.RequestWriter);
                                            ServerConsole.AddLog(
                                                $"Failed to generate ID for challenge for incoming connection from endpoint {request.RemoteEndPoint}.");
                                            return;
                                        }
                                    }
                                    else
                                    {
                                        break;
                                    }
                                }

                                byte[] bytes = RandomGenerator.GetBytes(CustomLiteNetLib4MirrorTransport.ChallengeInitLen + CustomLiteNetLib4MirrorTransport.ChallengeSecretLen, true);
                                ServerConsole.AddLog(
                                    $"Requested challenge for incoming connection from endpoint {request.RemoteEndPoint}.");
                                CustomLiteNetLib4MirrorTransport.RequestWriter.Reset();
                                CustomLiteNetLib4MirrorTransport.RequestWriter.Put((byte)13);
                                CustomLiteNetLib4MirrorTransport.RequestWriter.Put((byte)CustomLiteNetLib4MirrorTransport.ChallengeMode);
                                CustomLiteNetLib4MirrorTransport.RequestWriter.Put(num);
                                switch (CustomLiteNetLib4MirrorTransport.ChallengeMode)
                                {
                                case ChallengeType.MD5:
                                    CustomLiteNetLib4MirrorTransport.RequestWriter.PutBytesWithLength(bytes, 0, CustomLiteNetLib4MirrorTransport.ChallengeInitLen);
                                    CustomLiteNetLib4MirrorTransport.RequestWriter.Put(CustomLiteNetLib4MirrorTransport.ChallengeSecretLen);
                                    CustomLiteNetLib4MirrorTransport.RequestWriter.PutBytesWithLength(Md.Md5(bytes));
                                    CustomLiteNetLib4MirrorTransport.Challenges.Add(key, new PreauthChallengeItem(new ArraySegment <byte>(bytes, CustomLiteNetLib4MirrorTransport.ChallengeInitLen, CustomLiteNetLib4MirrorTransport.ChallengeSecretLen)));
                                    break;

                                case ChallengeType.SHA1:
                                    CustomLiteNetLib4MirrorTransport.RequestWriter.PutBytesWithLength(bytes, 0, CustomLiteNetLib4MirrorTransport.ChallengeInitLen);
                                    CustomLiteNetLib4MirrorTransport.RequestWriter.Put(CustomLiteNetLib4MirrorTransport.ChallengeSecretLen);
                                    CustomLiteNetLib4MirrorTransport.RequestWriter.PutBytesWithLength(Sha.Sha1(bytes));
                                    CustomLiteNetLib4MirrorTransport.Challenges.Add(key, new PreauthChallengeItem(new ArraySegment <byte>(bytes, CustomLiteNetLib4MirrorTransport.ChallengeInitLen, CustomLiteNetLib4MirrorTransport.ChallengeSecretLen)));
                                    break;

                                default:
                                    CustomLiteNetLib4MirrorTransport.RequestWriter.PutBytesWithLength(bytes);
                                    CustomLiteNetLib4MirrorTransport.Challenges.Add(key, new PreauthChallengeItem(new ArraySegment <byte>(bytes)));
                                    break;
                                }

                                request.Reject(CustomLiteNetLib4MirrorTransport.RequestWriter);
                                CustomLiteNetLib4MirrorTransport.PreauthDisableIdleMode();
                                return;
                            }

                            string key1 = request.RemoteEndPoint.Address + "-" + result4;
                            if (!CustomLiteNetLib4MirrorTransport.Challenges.ContainsKey(key1))
                            {
                                ServerConsole.AddLog(
                                    $"Security challenge response of incoming connection from endpoint {request.RemoteEndPoint} has been REJECTED (invalid Challenge ID).");
                                CustomLiteNetLib4MirrorTransport.RequestWriter.Reset();
                                CustomLiteNetLib4MirrorTransport.RequestWriter.Put((byte)14);
                                request.RejectForce(CustomLiteNetLib4MirrorTransport.RequestWriter);
                                return;
                            }

                            ArraySegment <byte> validResponse = CustomLiteNetLib4MirrorTransport.Challenges[key1].ValidResponse;
                            if (!result5.SequenceEqual(validResponse))
                            {
                                ServerConsole.AddLog(
                                    $"Security challenge response of incoming connection from endpoint {request.RemoteEndPoint} has been REJECTED (invalid response).");
                                CustomLiteNetLib4MirrorTransport.RequestWriter.Reset();
                                CustomLiteNetLib4MirrorTransport.RequestWriter.Put((byte)15);
                                request.RejectForce(CustomLiteNetLib4MirrorTransport.RequestWriter);
                                return;
                            }

                            CustomLiteNetLib4MirrorTransport.Challenges.Remove(key1);
                            CustomLiteNetLib4MirrorTransport.PreauthDisableIdleMode();
                            ServerConsole.AddLog(
                                $"Security challenge response of incoming connection from endpoint {request.RemoteEndPoint} has been accepted.");
                        }
                        else if (!CustomLiteNetLib4MirrorTransport.CheckIpRateLimit(request))
                        {
                            return;
                        }

                        if (!CharacterClassManager.OnlineMode)
                        {
                            KeyValuePair <BanDetails, BanDetails> keyValuePair = BanHandler.QueryBan(null, request.RemoteEndPoint.Address.ToString());
                            if (keyValuePair.Value != null)
                            {
                                ServerConsole.AddLog($"Player tried to connect from banned endpoint {request.RemoteEndPoint}.");
                                CustomLiteNetLib4MirrorTransport.RequestWriter.Reset();
                                CustomLiteNetLib4MirrorTransport.RequestWriter.Put((byte)6);
                                CustomLiteNetLib4MirrorTransport.RequestWriter.Put(keyValuePair.Value.Expires);
                                CustomLiteNetLib4MirrorTransport.RequestWriter.Put(keyValuePair.Value?.Reason ?? string.Empty);
                                request.RejectForce(CustomLiteNetLib4MirrorTransport.RequestWriter);
                            }
                            else
                            {
                                request.Accept();
                                CustomLiteNetLib4MirrorTransport.PreauthDisableIdleMode();
                            }
                        }
                        else
                        {
                            if (!request.Data.TryGetString(out string result6) || result6 == string.Empty)
                            {
                                CustomLiteNetLib4MirrorTransport.RequestWriter.Reset();
                                CustomLiteNetLib4MirrorTransport.RequestWriter.Put((byte)5);
                                request.RejectForce(CustomLiteNetLib4MirrorTransport.RequestWriter);
                            }
 public void SetUp()
 {
     md = new Md();
 }
Beispiel #30
0
 public void RenderShouldntConvert_WhenTagsIntersect(string input, string output)
 {
     Md.Render(input).Should().Be(output);
 }