Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using bdoEmu.Common;
- using bdoEmu.Common.Extensions;
- using bdoEmu.Common.Models;
- using bdoEmu.Game.Configs;
- using bdoEmu.Game.Messages;
- using bdoEmu.Game.Models.Mappings;
- using bdoEmu.Game.Network;
- using FluentNHibernate.Cfg;
- using FluentNHibernate.Cfg.Db;
- using NHibernate;
- using NHibernate.Tool.hbm2ddl;
- using NLog;
- using System;
- using System.Diagnostics;
- using System.Text;
- using System.Threading.Tasks;
- namespace bdoEmu.Game.Processors
- {
- public class AuthProcessor : IProcessor
- {
- /// <summary>
- /// Logger for this class
- /// </summary>
- private static readonly Logger Log = LogManager.GetCurrentClassLogger();
- /// <summary>
- /// Login server dao factory
- /// </summary>
- private static ISessionFactory _lsDbFactory;
- /// <summary>
- /// Initilize service action
- /// </summary>
- /// <param name="previousInstanceContext"></param>
- public void OnLoad(object previousInstanceContext)
- {
- var config = Fluently.Configure().Database(MySQLConfiguration.Standard.ConnectionString(cs => cs.Is(
- $"Server={DatabaseConfig.DB_HOST};" +
- $"Database={DatabaseConfig.LOGINSERVER_DB_NAME};" +
- $"User={DatabaseConfig.DB_USER}" +
- $";Password={DatabaseConfig.DB_PASS};" +
- "CharSet=utf8"))).Mappings(m =>
- {
- m.FluentMappings.AddFromNamespaceOf<AccountsMap>();
- });
- config.ExposeConfiguration(x =>
- {
- x.SetInterceptor(new SqlStatementInterceptor());
- });
- var export = new SchemaUpdate(config.BuildConfiguration());
- export.Execute(false, true);
- _lsDbFactory = config.BuildSessionFactory();
- }
- public void AuthProcess(Connection connection, string accountId)
- {
- Log.Fatal("CONTENTS OF \"accountId\" = {0}", accountId);
- using (var db = _lsDbFactory.OpenSession())
- {
- int intToString = Convert.ToInt32(accountId);
- Log.Fatal("CONTENTS OF \"intToString\" = {0}", intToString);
- var model = db.QueryOver<Accounts>()
- .Where(p => p.AccountName == "test").Take(1).SingleOrDefault(); //CANT USE ID,NEED TO USE ACCOUNTID
- if (model == null)
- {
- connection.Disconnect($"AuthProcessor could not find the following account by ID: {accountId}");
- return;
- }
- connection.Account = model; // set the account for the current connection.
- connection.Send(new SMGetContentServiceInfo());
- connection.Send(new SMChargeUser());
- Core.Act(s => s.LobbyProcessor.GetCharacterList(connection));
- }
- }
- public object OnUnload()
- {
- return null;
- }
- public class SqlStatementInterceptor : EmptyInterceptor
- {
- public override NHibernate.SqlCommand.SqlString OnPrepareStatement(NHibernate.SqlCommand.SqlString sql)
- {
- Log.Warn(sql.ToString());
- return sql;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement