/// <summary> /// Determines whether the given username and password are valid to authenticate with. /// </summary> /// <param name="username">The username to challenge</param> /// <param name="password">The password to challenge</param> bool AreCredentialsValid(string username, string password) { #if DEBUG return(true); #endif var context = new BlastersContext(); // Retrieve that user from the db var member = context.blastersmembers.FirstOrDefault(x => x.members_l_username.ToLower() == username.ToLower()); Logger.Instance.Log(Level.Debug, "Finished login query"); if (member == null) { return(false); } // Check if the password is ok var salt = member.members_pass_salt; var hash = member.members_pass_hash; // $hash = md5( md5( $salt ) . md5( $password ) ); var password_x = hash; var password_y = CalculateMD5Hash(CalculateMD5Hash(salt) + CalculateMD5Hash(password)); if (password_x == password_y) { return(true); } return(false); }
public User AddUser(LoginRequestPacket obj, string username) { User result; blastersmember member; // Fetch the member this belongs to using (var context = new BlastersContext()) member = context.blastersmembers.FirstOrDefault(x => x.members_l_username.ToLower() == username.ToLower()); using (var context = new BlastersContext()) result = context.users.FirstOrDefault(x => x.Name.ToLower() == obj.Username.ToLower()); if (result == null) { result = CreateUserAccount(member); } var user = result; result.Connection = obj.Sender; result.BlastersMember = null; ServiceContainer.Users.Add(user.Connection, user); return(user); }
private User CreateUserAccount(blastersmember member) { using (var context = new BlastersContext()) { var user = new User(); user.Name = member.members_display_name; user.BlastersMembersID = member.member_id; user.CreationDate = DateTime.UtcNow; context.users.Add(user); context.SaveChanges(); ((IObjectContextAdapter)context).ObjectContext.Detach(user); return(user); } }
static void Main(string[] args) { // Setup some stuff, because why not Console.Title = "Blasters Lobby Gateway"; Console.WindowWidth = 100; // Write some welcoming info PrintLine(ConsoleColor.Yellow, "********************************************************************"); PrintLine(ConsoleColor.Yellow, "This is beta software. You have been warned. Code by: Vaughan Hilts"); PrintLine(ConsoleColor.Yellow, "********************************************************************\n"); Logger.Instance.Log(Level.Info, "The lobby server has succesfully been started."); // Add services _serviceContainer.RegisterService(_authenticationService); _serviceContainer.RegisterService(_gameSessionService); _serviceContainer.RegisterService(_appServerService); _serviceContainer.RegisterService(_chatService); _serviceContainer.RegisterService(_intentService); AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; ClientNetworkManager.Instance.Update(); // We populate the game with some matches in debug mode #if DEUBG #endif // Thread.Sleep(5000); var context = new BlastersContext(); // Retrieve that user from the db var member = context.blastersmembers.FirstOrDefault(); // Create ten default games for (int i = 0; i < 1; i++) { _gameSessionService.CreateSession(); } var done = false; while (true) { ClientNetworkManager.Instance.Update(); _serviceContainer.PerformUpdates(); Thread.Sleep(1); #if DEBUG_MOCK if (done || _appServerService.ApplicationServers.Count == 0) { continue; } // Dispatch a dummy match to the server in debug mode var _client = new NetClient(new NetPeerConfiguration("Inspire")); _client.Start(); _client.Connect("localhost", 8787); Thread.Sleep(2000); var user = new BlastersShared.Models.User(_client.ServerConnection, "Vaughan"); _authenticationService.AddUser(user); var demoSession = _gameSessionService.CreateSession(); demoSession.Configuration.MaxPlayers = 1; _gameSessionService.AddToSession(user, demoSession); _gameSessionService.ActivateSession(demoSession); done = true; #endif } Console.ReadLine(); }