Beispiel #1
0
        public void ConfigureOAuth(IAppBuilder app)
        {
            OAuthAuthorizationServerOptions OAuthServerOptions = new OAuthAuthorizationServerOptions()
            {
                AllowInsecureHttp         = true,
                TokenEndpointPath         = new PathString("/token"),
                AccessTokenExpireTimeSpan = TimeSpan.FromDays(1),
                Provider = new SimpleAuthorizationServerProvider()
            };

            // Token Generation
            app.UseOAuthAuthorizationServer(OAuthServerOptions);
            app.UseOAuthBearerAuthentication(new OAuthBearerAuthenticationOptions());

            CreateRoles.Execute();
            Seed.Execute();

            var bookRepo    = new BooksRepository();
            var libraryRepo = new LibrariesRepository();


            bookRepo.GetBookBorrowExpirations();
            SchedulerService.StartAction(24, bookRepo.GetBookBorrowExpirations);

            libraryRepo.GetMembershipExpirations();
            SchedulerService.StartAction(24, libraryRepo.GetMembershipExpirations);

            bookRepo.GetBookReservationExpirations();
            SchedulerService.StartAction(2, bookRepo.GetBookReservationExpirations);
        }
        public static List <CreateRoles> getAllRolesFromDB()
        {
            SqlDataReader reader     = null;
            SqlConnection connection = new SqlConnection();

            connection.ConnectionString = "Data Source=.;Initial Catalog=TECAirlines;Integrated Security=SSPI";

            SqlCommand sqlCmd = new SqlCommand();

            sqlCmd.CommandType = CommandType.Text;

            var query = "SELECT * FROM Rol";



            sqlCmd.CommandText = query;

            sqlCmd.Connection = connection;
            connection.Open();
            reader = sqlCmd.ExecuteReader();
            List <CreateRoles> listaRol = new List <CreateRoles>();
            CreateRoles        roles    = null;

            while (reader.Read())
            {
                roles         = new CreateRoles();
                roles.tnumero = Convert.ToInt32(reader.GetValue(0));
                roles.trol    = reader.GetValue(1).ToString();
                listaRol.Add(roles);
            }
            connection.Close();
            return(listaRol);
        }
        public static bool addRolesDB(CreateRoles rol)
        {
            var connectionString = "Data Source=.;Initial Catalog=TECAirlines;Integrated Security=SSPI";

            var query = "INSERT INTO Rol (Numero, Rol) VALUES ('@Numero', @Rol)";

            query = query.Replace("@Numero", rol.tnumero.ToString())
                    .Replace("@Rol", rol.trol);



            SqlConnection connection = new SqlConnection(connectionString);

            try
            {
                connection.Open();
                SqlCommand command = new SqlCommand(query, connection);
                command.ExecuteNonQuery();
                command.Dispose();
                connection.Close();
                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
        public static CreateRoles getRolesFromDB(int numero)
        {
            SqlDataReader reader     = null;
            SqlConnection connection = new SqlConnection();

            connection.ConnectionString = "Data Source=.;Initial Catalog=TECAirlines;Integrated Security=SSPI";

            SqlCommand sqlCmd = new SqlCommand();

            sqlCmd.CommandType = CommandType.Text;

            var query = "SELECT * FROM Rol WHERE Numero='@numero'";

            query = query.Replace("@numero", numero.ToString());

            sqlCmd.CommandText = query;

            sqlCmd.Connection = connection;
            connection.Open();
            reader = sqlCmd.ExecuteReader();
            CreateRoles roles = null;

            while (reader.Read())
            {
                roles         = new CreateRoles();
                roles.tnumero = Convert.ToInt32(reader.GetValue(0));
                roles.trol    = reader.GetValue(1).ToString();
            }
            connection.Close();
            return(roles);
        }
Beispiel #5
0
        public async Task <IActionResult> CreateRole([FromBody] CreateRoles roles)
        {
            await Task.WhenAll(
                roles.Roles.Select(r => { return(AddRole(r)); }).ToArray()
                );

            return(Ok());
        }
Beispiel #6
0
        // For more information on configuring authentication, please visit https://go.microsoft.com/fwlink/?LinkId=301864
        public void ConfigureAuth(IAppBuilder app)
        {
            // Configure the db context, user manager and signin manager to use a single instance per request
            app.CreatePerOwinContext(ApplicationDbContext.Create);
            app.CreatePerOwinContext <ApplicationUserManager>(ApplicationUserManager.Create);
            app.CreatePerOwinContext <ApplicationSignInManager>(ApplicationSignInManager.Create);

            CreateRoles cr = new CreateRoles();

            cr.createRoles();

            // Enable the application to use a cookie to store information for the signed in user
            // and to use a cookie to temporarily store information about a user logging in with a third party login provider
            // Configure the sign in cookie
            app.UseCookieAuthentication(new CookieAuthenticationOptions
            {
                AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
                LoginPath          = new PathString("/Account/Login"),
                Provider           = new CookieAuthenticationProvider
                {
                    // Enables the application to validate the security stamp when the user logs in.
                    // This is a security feature which is used when you change a password or add an external login to your account.
                    OnValidateIdentity = SecurityStampValidator.OnValidateIdentity <ApplicationUserManager, ApplicationUser>(
                        validateInterval: TimeSpan.FromMinutes(30),
                        regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager))
                }
            });
            app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);

            // Enables the application to temporarily store user information when they are verifying the second factor in the two-factor authentication process.
            app.UseTwoFactorSignInCookie(DefaultAuthenticationTypes.TwoFactorCookie, TimeSpan.FromMinutes(5));

            // Enables the application to remember the second login verification factor such as phone or email.
            // Once you check this option, your second step of verification during the login process will be remembered on the device where you logged in from.
            // This is similar to the RememberMe option when you log in.
            app.UseTwoFactorRememberBrowserCookie(DefaultAuthenticationTypes.TwoFactorRememberBrowserCookie);

            // Uncomment the following lines to enable logging in with third party login providers
            //app.UseMicrosoftAccountAuthentication(
            //    clientId: "",
            //    clientSecret: "");

            //app.UseTwitterAuthentication(
            //   consumerKey: "",
            //   consumerSecret: "");

            //app.UseFacebookAuthentication(
            //   appId: "",
            //   appSecret: "");

            //app.UseGoogleAuthentication(new GoogleOAuth2AuthenticationOptions()
            //{
            //    ClientId = "",
            //    ClientSecret = ""
            //});
        }
Beispiel #7
0
 public bool Post(CreateRoles roles)
 {
     if (roles != null)
     {
         return(CreateRolesRepository.addRolesDB(roles));
     }
     else
     {
         return(false);
     }
 }
Beispiel #8
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IServiceProvider serviceProvider)
        {
            _loggerFactory = new LoggerFactory();
            _moduleLogger  = _loggerFactory.CreateLogger("Logger");

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseDatabaseErrorPage();

                // Enable middleware to serve generated Swagger as a JSON endpoint.
                app.UseSwagger();

                // specifying the Swagger JSON endpoint.
                app.UseSwaggerUI(c =>
                {
                    c.SwaggerEndpoint("/swagger/v1/swagger.json", "Atiendeme API");
                });
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
                // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
                app.UseHsts();
            }
            app.UseHttpsRedirection();
            app.UseStaticFiles();

            app.UseRouting();

            app.UseAuthentication();
            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllerRoute(
                    name: "default",
                    pattern: "{controller=Home}/{action=Index}/{id?}");
                endpoints.MapRazorPages();
            });

            CreateRoles.Configure(serviceProvider, _moduleLogger);
        }
Beispiel #9
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IServiceProvider serviceProvider)
        {
            var context = serviceProvider.GetService <ApplicationDbContext>();

            context.Database.Migrate();

            CreateRoles.Default(serviceProvider);

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseDatabaseErrorPage();
            }
            else
            {
                app.UseExceptionHandler("/Error");
                app.UseHsts();
            }

            //app.UseHttpsRedirection();
            //app.UseCors(c => c.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader().AllowCredentials());
            app.UseCors("CorsPolicy");

            app.UseStaticFiles();
            app.UseSession();

            app.UseRouting();

            app.UseAuthentication();
            app.UseAuthorization();

            app.UseSerilogRequestLogging();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapRazorPages();
                endpoints.MapControllers();
            });
        }
        public async Task <IActionResult> CreateRolesAdmin(CreateRoles createRoles)
        {
            var roles = createRoles.Roles;

            foreach (var role in roles)
            {
                var roleExist = await _context.Roles.AnyAsync(r => r.Name == role);

                if (!roleExist)
                {
                    // We just need to specify a unique role name to create a new role
                    IdentityRole identityRole = new IdentityRole
                    {
                        Name = role
                    };

                    await _roleManager.CreateAsync(identityRole);

                    await _context.SaveChangesAsync();
                }
            }
            return(Ok());
        }
Beispiel #11
0
        public void ThreadFuncation2()
        {
            int szOfest = 11;

            //autoEvent.WaitOne();
            while (true)
            {
                if (m_MoveDataList.Count > 0)
                {
                    mutex.WaitOne();
                    try
                    {
                        TCPOutPacket szTCPOutPacket = null;

                        szTCPOutPacket = m_MoveDataList.Dequeue();

                        string[] fields = null;
                        if (szTCPOutPacket.PacketCmdID < 30000)
                        {
                            fields = Encoding.Default.GetString(szTCPOutPacket.GetPacketBytes(), szOfest, szTCPOutPacket.PacketDataSize - szOfest).Trim().Split(':');
                        }
                        switch (szTCPOutPacket.PacketCmdID)
                        {
                        case (int)TCPServerCmds.CMD_LOGIN_ON1:
                        {
                            m_LNetClient.Disconnect();
                            m_LNetClient.Destroy();

                            if (!fields[0].Equals("0"))
                            {
                                g_Thread1.Start();
                                g_Acc = fields[0];
                                SendRoleData(fields[0]);
                            }
                            else
                            {
                                SysConOut.WriteLine("登陆失败");
                            }
                            break;
                        }

                        case (int)TCPServerCmds.CMD_NTF_EACH_ROLE_ALLOW_CHANGE_NAME:
                        {
                            SysConOut.WriteLine("==============CHANGE_NAME===============");
                            foreach (var s in fields)
                            {
                                SysConOut.WriteLine(s);
                            }
                            break;
                        }

                        case (int)CommandID.CMD_GET_ROLE_LIST:
                        {
                            SysConOut.WriteLine("==============CMD_ROLE_LIST 30003===============");
                            //反序列化
                            MemoryStream        msRecvData            = new MemoryStream(szTCPOutPacket.GetPacketBytes(), szOfest, szTCPOutPacket.PacketDataSize - szOfest);
                            GetRolesListReponse szGetRolesListReponse = Serializer.Deserialize <GetRolesListReponse>(msRecvData);
                            SysConOut.WriteLine("get Role state = " + szGetRolesListReponse.State.ToString());
                            foreach (var i in szGetRolesListReponse.SubRoleinfo)
                            {
                                SysConOut.WriteLine("get Role Role = " + i.RoleID.ToString());
                            }
                            if (szGetRolesListReponse.State == (int)ErrorCode.ERROR_INVALID_ROLE)
                            {
                                var         szRandom      = new Random().Next(100);
                                CreateRoles szCreateRoles = new CreateRoles();
                                szCreateRoles.Acc      = g_Acc;
                                szCreateRoles.UserName = g_Acc + szRandom.ToString();
                                szCreateRoles.Sex      = 0;
                                szCreateRoles.occup    = 0;
                                szCreateRoles.ZoneID   = 0;
                                m_tcpOutPacketPool.Push(szTCPOutPacket);

                                MemoryStream msResult = new MemoryStream();
                                Serializer.Serialize <CreateRoles>(msResult, szCreateRoles);
                                byte[] msSendData = msResult.ToArray();
                                szTCPOutPacket = TCPOutPacket.MakeTCPOutPacket(m_GSNetClient.OutPacketPool, msSendData, 0, msSendData.Length, 30002);
                                if (m_GSNetClient.SendData(szTCPOutPacket))
                                {
                                    SysConOut.WriteLine("发送创建角色列表数据成功");
                                }
                                else
                                {
                                    SysConOut.WriteLine("发送创建角色列表数据失败");
                                }

                                m_GSNetClient.OutPacketPool.Push(szTCPOutPacket);
                            }
                            else
                            {
                                foreach (var Roleinfo in szGetRolesListReponse.SubRoleinfo)
                                {
                                    g_RoleID = Roleinfo.RoleID.ToString();
                                    break;
                                }
                                SendInitGame(g_Acc, g_RoleID);
                                Console.Title = "机器人---" + g_RoleID;
                            }
                            break;
                        }

                        case (int)TCPServerCmds.CMD_ROLE_LIST:
                        {
                            SysConOut.WriteLine("==============CMD_ROLE_LIST===============");
                            if (fields[0].Equals("0"))
                            {
                                var szRandom = new Random().Next(100);
                                var result   = StringUtil.substitute("{0}:{1}:{2}:{3}:{4}:{5}:{6}", g_Acc, g_Acc + szRandom.ToString(), 0, 0,
                                                                     String.Format("{0}${1}", g_Acc + szRandom.ToString(), 0), 0, 1);

                                TCPOutPacket _TCPOutPacket = TCPOutPacket.MakeTCPOutPacket(m_GSNetClient.OutPacketPool, result,
                                                                                           (int)TCPServerCmds.CMD_CREATE_ROLE);
                                //创建角色
                                if (m_GSNetClient.SendData(_TCPOutPacket))
                                {
                                    SysConOut.WriteLine("发送创建角色数据成功");
                                }
                                else
                                {
                                    SysConOut.WriteLine("发送创建角色数据失败");
                                }
                                m_GSNetClient.OutPacketPool.Push(_TCPOutPacket);
                            }
                            else
                            {
                                string[] fieldsData = fields[1].Split('$');
                                g_RoleID = fieldsData[0];
                                SendInitGame(g_Acc, g_RoleID);
                                Console.Title = "机器人---" + g_RoleID;
                            }
                            break;
                        }

                        case (int)CommandID.CMD_CREATE_ROLE:
                        {
                            SysConOut.WriteLine("====CMD_CREATE_ROLE  30002=====");
                            MemoryStream       msRecvData           = new MemoryStream(szTCPOutPacket.GetPacketBytes(), szOfest, szTCPOutPacket.PacketDataSize - szOfest);
                            CreateRolesReponse szCreateRolesReponse = Serializer.Deserialize <CreateRolesReponse>(msRecvData);
                            if (szCreateRolesReponse.State == (int)ErrorCode.ERROR_OK)
                            {
                                SendRoleData(g_Acc);
                            }
                            m_tcpOutPacketPool.Push(szTCPOutPacket);
                            break;
                        }

                        case (int)TCPServerCmds.CMD_CREATE_ROLE:
                        {
                            SysConOut.WriteLine("====CMD_CREATE_ROLE=====");

                            if (!fields[0].Equals("0"))
                            {
                                SendRoleData(g_Acc);
                            }
                            break;
                        }

                        case (int)CommandID.CMD_INIT_GAME:
                        {
                            SysConOut.WriteLine("==============CMD_INIT_GAME 30004===============");

                            MemoryStream       msRecvData           = new MemoryStream(szTCPOutPacket.GetPacketBytes(), szOfest, szTCPOutPacket.PacketDataSize - szOfest);
                            InitialGameReponse szInitialGameReponse = Serializer.Deserialize <InitialGameReponse>(msRecvData);

                            SysConOut.WriteLine("CMD_INIT_GAME RoleID = " + szInitialGameReponse.SubRoleinfo.RoleID.ToString() + "  Role = " + g_RoleID.ToString());
                            SendPlayGame(g_RoleID);
                            m_tcpOutPacketPool.Push(szTCPOutPacket);
                            break;
                        }

                        case (int)TCPServerCmds.CMD_INIT_GAME:
                        {
                            SysConOut.WriteLine("==============CMD_INIT_GAME===============");

                            RoleData szRoleData = DataHelper.BytesToObject <RoleData>(szTCPOutPacket.GetPacketBytes(), szOfest, szTCPOutPacket.PacketDataSize - szOfest);
                            SysConOut.WriteLine("CMD_INIT_GAME RoleID = " + szRoleData.RoleID.ToString());
                            SendPlayGame(g_RoleID);
                            break;
                        }

                        case (int)CommandID.CMD_PLAY_GAME:
                        {
                            SysConOut.WriteLine("==============CMD_PLAY_GAME 30005===============");
                            MemoryStream    msRecvData        = new MemoryStream(szTCPOutPacket.GetPacketBytes(), szOfest, szTCPOutPacket.PacketDataSize - szOfest);
                            PlayGameReponse szPlayGameReponse = Serializer.Deserialize <PlayGameReponse>(msRecvData);

                            SysConOut.WriteLine("CMD_PLAY_GAME RoleID = " + szPlayGameReponse.RoleID.ToString());

                            if (g_Thread == null)
                            {
                                g_Thread = new Thread(new ThreadStart(ThreadFuncation));
                            }
                            g_Thread.Start();
                            m_tcpOutPacketPool.Push(szTCPOutPacket);
                            break;
                        }

                        case (int)TCPServerCmds.CMD_PLAY_GAME:
                        {
                            SysConOut.WriteLine("==============CMD_PLAY_GAME===============");

                            if (g_Thread == null)
                            {
                                g_Thread = new Thread(new ThreadStart(ThreadFuncation));
                            }
                            g_Thread.Start();
                            break;
                        }

                        case (int)CommandID.CMD_GAME_MOVE:
                        {
                            SysConOut.WriteLine("==============CMD_GAME_MOVE 30006===============");
                            MemoryStream msRecvData   = new MemoryStream(szTCPOutPacket.GetPacketBytes(), szOfest, szTCPOutPacket.PacketDataSize - szOfest);
                            SpriteMove   szSpriteMove = Serializer.Deserialize <SpriteMove>(msRecvData);


                            SysConOut.WriteLine("CMD_SPR_MOVE Role = " + szSpriteMove.RoleID.ToString()
                                                + " Mapcode = " + szSpriteMove.MapCode.ToString()
                                                + " action = " + szSpriteMove.action.ToString()
                                                + " pathString = " + szSpriteMove.pathString);
                            m_tcpOutPacketPool.Push(szTCPOutPacket);
                            break;
                        }

                        case (int)TCPServerCmds.CMD_SPR_MOVE:
                        {
                            SpriteNotifyOtherMoveData moveData = DataHelper.BytesToObject <SpriteNotifyOtherMoveData>(szTCPOutPacket.GetPacketBytes(), 11, szTCPOutPacket.PacketDataSize - 11);

                            SysConOut.WriteLine("CMD_SPR_MOVE Role = " + moveData.roleID.ToString()
                                                + " Mapcode = " + moveData.mapCode.ToString()
                                                + " action = " + moveData.action.ToString()
                                                + " pathString = " + moveData.pathString);
                            m_tcpOutPacketPool.Push(szTCPOutPacket);
                            break;
                        }
                        }
                    }
                    catch (Exception ex)
                    {
                        SysConOut.WriteLine(ex.Message);
                    }


                    mutex.Release();
                }
                Thread.Sleep(100);
            }
        }
Beispiel #12
0
            public Bot()
            {
                BotUser = new DiscordClient(x =>
                {
                    x.LogLevel = LogSeverity.Info;
                });
                BotUser.Log.Message += (s, e) => Console.WriteLine($"[{e.Severity}] {e.Source}: {e.Message}");

                BotUser.UsingCommands(x =>
                {
                    x.PrefixChar         = '-';
                    x.AllowMentionPrefix = true;
                });
                commands = BotUser.GetService <CommandService>();
                RoleManagementCommands    rmc = new RoleManagementCommands(BotUser, commands);
                AccountManagementCommands amc = new AccountManagementCommands(BotUser, commands);
                RoleManagementTrigger     roleManagementTrigger = new RoleManagementTrigger(BotUser, commands);
                RegionCommands            regionCommands        = new RegionCommands(BotUser, commands);
                RoleCommand          roleCommand        = new RoleCommand(BotUser, commands);
                ManagementTools      managementTools    = new ManagementTools(BotUser, commands);
                ServerInfoCommands   serverInfoCommands = new ServerInfoCommands(BotUser, commands);
                MasteryCommands      masteryCommands    = new MasteryCommands(BotUser, commands);
                ServerManagement     serverManagement   = new ServerManagement(BotUser, commands);
                RankCommands         rankCommands       = new RankCommands(BotUser, commands);
                SummonerInfo         summonerInfo       = new SummonerInfo(commands);
                BotManagement        botManagement      = new BotManagement(commands, BotUser);
                Interaction          inter               = new Interaction(BotUser, commands);
                CreateRoles          createRoles         = new CreateRoles(commands);
                Matchmaking_Settings matchmakingSettings = new Matchmaking_Settings(commands);
                CoachCommands        coachCommands       = new CoachCommands(commands);
                Stopwatch            stopwatch           = new Stopwatch();

                stopwatch.Start();
                MatchmakingTrigger  trigger             = new MatchmakingTrigger(BotUser, commands);
                MatchmakingCommands matchmakingCommands = new MatchmakingCommands(commands, BotUser, trigger);

                new HelpCommand(BotUser, commands);
                Task.Run(() => trigger.TimedClear(stopwatch));
                matchmakingCommands.CreateCommands();
                matchmakingSettings.ChannelSettings();
                coachCommands.CreateCommands();
                createRoles.CreateRank();
                summonerInfo.SelfInfo();
                summonerInfo.OtherInfo();
                serverManagement.ServerAdded();
                serverManagement.VerifyServer();
                serverInfoCommands.InviteLink();
                amc.ClaimAccount();
                amc.Claim();
                rankCommands.GetRank();
                new Universal_Role(BotUser, commands).UniversalRole();
                regionCommands.GetRegion();
                roleCommand.GetRole();
                rmc.Update();
                rmc.GetRoles();
                managementTools.ChangeType();
                managementTools.ChangeCommandAllowed();
                managementTools.OverrideSystem();
                serverInfoCommands.ServerInfo();
                serverInfoCommands.Description();
                serverManagement.CheckForNewServer();
                managementTools.Admin();
                roleCommand.GetRoleParameter();
                Legal();
                roleManagementTrigger.JoiningRoleGive();
                masteryCommands.GetMasteryPoints();
                managementTools.AdminMastery();

                Test();
                BotUser.ExecuteAndWait(async() =>
                {
                    await BotUser.Connect(global::Keys.Keys.discordKey, TokenType.Bot);
                });
            }