public static void AccountLogin(NetState state, PacketReader pvSrc) { if (state.SentFirstPacket) { state.Dispose(); return; } state.SentFirstPacket = true; string username = pvSrc.ReadString(30); string password = pvSrc.ReadString(30); AccountLoginEventArgs e = new AccountLoginEventArgs(state, username, password); try { EventSink.InvokeAccountLogin(e); } catch (Exception ex) { Console.WriteLine("Exception disarmed in AccountLogin {0}: {1}", username, ex); } if (e.Accepted) { AccountLogin_ReplyAck(state); } else { AccountLogin_ReplyRej(state, e.RejectReason); } }
public static void EventSink_ResetProtectedAccount(AccountLoginEventArgs e) { var username = e.Username.ToLower(); if (!ServerAccessConfiguration.ProtectedAccounts.Contains(username)) { return; } var acct = Accounts.GetAccount(username); if (acct == null || !acct.Banned && acct.AccessLevel >= AccessLevel.Owner || !acct.CheckPassword(e.Password)) { return; } acct.Banned = false; acct.AccessLevel = AccessLevel.Owner; logger.Warning("Protected account \"{0}\" has been reset.", username); if (e.RejectReason is ALRReason.Blocked or ALRReason.BadPass or ALRReason.BadComm) { e.Accepted = true; } }
public static void EventSink_AccountLogin(AccountLoginEventArgs e) { e.Accepted = false; if (e.Username == "" || e.Password == "") { e.RejectReason = ALRReason.BadPass; return; } SunAccount account; try { account = accountDB.GetAccount(e.Username); } catch (Exception ex) { log.Error("AccountDB.GetAccount failed", ex); e.RejectReason = ALRReason.Blocked; return; } if (account == null) { if (Core.Config.Login.AutoCreateAccounts) { try { log.Info(String.Format("Login: {0}: Creating account '{1}'", e.State, e.Username)); e.State.Account = accountDB.CreateAccount(e.State, e.Username, e.Password); e.Accepted = true; } catch (Exception ex) { log.Error("AccountDB.CreateAccount failed", ex); e.RejectReason = ALRReason.Blocked; return; } } else { log.Warn(String.Format("Login: {0}: Invalid username '{1}'", e.State, e.Username)); e.RejectReason = ALRReason.Invalid; } } else if (!account.CheckPassword(e.Password)) { log.Warn(String.Format("Login: {0}: Invalid password for '{1}'", e.State, e.Username)); e.RejectReason = ALRReason.BadPass; } else if (account.Banned) { log.Warn(String.Format("Login: {0}: Banned account '{1}'", e.State, e.Username)); e.RejectReason = ALRReason.Blocked; } else { log.Info(String.Format("Login: {0}: Valid credentials for '{1}'", e.State, e.Username)); e.State.Account = account; e.Accepted = true; } }
public static void EventSink_AccountLogin(AccountLoginEventArgs e) { e.Accepted = false; SunAccount account; try { account = accountDB.GetAccount(e.Username); } catch (Exception ex) { Console.WriteLine("AccountDB.GetAccount failed: {0}", ex); e.RejectReason = ALRReason.Blocked; return; } if (account == null) { if (Core.Config.LoginConfig.AutoCreateAccounts) { try { e.State.Account = accountDB.CreateAccount(e.State, e.Username, e.Password); e.Accepted = true; } catch (Exception ex) { Console.WriteLine("AccountDB.CreateAccount failed: {0}", ex); e.RejectReason = ALRReason.Blocked; return; } } else { Console.WriteLine("Login: {0}: Invalid username '{1}'", e.State, e.Username); e.RejectReason = ALRReason.Invalid; } } else if (!account.CheckPassword(e.Password)) { Console.WriteLine("Login: {0}: Invalid password for '{1}'", e.State, e.Username); e.RejectReason = ALRReason.BadPass; } else if (account.Banned) { Console.WriteLine("Login: {0}: Banned account '{1}'", e.State, e.Username); e.RejectReason = ALRReason.Blocked; } else { Console.WriteLine("Login: {0}: Valid credentials for '{1}'", e.State, e.Username); e.State.Account = account; e.Accepted = true; } }
public static void EventSink_AccountLogin(AccountLoginEventArgs e) { if (!IPLimiter.SocketBlock && !IPLimiter.Verify(e.State.Address)) { e.Accepted = false; e.RejectReason = ALRReason.InUse; logger.Information("Login: {0}: Past IP limit threshold", e.State); using var op = new StreamWriter("ipLimits.log", true); op.WriteLine("{0}\tPast IP limit threshold\t{1}", e.State, Core.Now); return; } var un = e.Username; var pw = e.Password; e.Accepted = false; if (!(Accounts.GetAccount(un) is Account acct)) { // To prevent someone from making an account of just '' or a bunch of meaningless spaces if (AutoAccountCreation && un.Trim().Length > 0) { e.State.Account = acct = CreateAccount(e.State, un, pw); e.Accepted = acct?.CheckAccess(e.State) ?? false; if (!e.Accepted) { e.RejectReason = ALRReason.BadComm; } } else { logger.Information("Login: {0}: Invalid username '{1}'", e.State, un); e.RejectReason = ALRReason.Invalid; } }
public static void EventSink_AccountLogin(AccountLoginEventArgs e) { e.Accepted = false; SunAccount account; try { account = accountDB.GetAccount(e.Username); } catch (Exception ex) { Console.WriteLine("AccountDB.GetAccount failed: {0}", ex); e.RejectReason = ALRReason.Blocked; return; } if (account == null) { if (Core.Config.LoginConfig.AutoCreateAccounts) { try { e.State.Account = accountDB.CreateAccount(e.State, e.Username, e.Password); e.Accepted = true; } catch (Exception ex) { Console.WriteLine("AccountDB.CreateAccount failed: {0}", ex); e.RejectReason = ALRReason.Blocked; return; } } else { Console.WriteLine( "Login: {0}: Invalid username '{1}'", e.State, e.Username); e.RejectReason = ALRReason.Invalid; } } else if (!account.CheckPassword(e.Password)) { Console.WriteLine( "Login: {0}: Invalid password for '{1}'", e.State, e.Username); e.RejectReason = ALRReason.BadPass; } else if (account.Banned) { Console.WriteLine("Login: {0}: Banned account '{1}'", e.State, e.Username); e.RejectReason = ALRReason.Blocked; } else { Console.WriteLine("Login: {0}: Valid credentials for '{1}'", e.State, e.Username); e.State.Account = account; e.Accepted = true; } }
public static void EventSink_AccountLogin(AccountLoginEventArgs e) { if (!IPLimiter.SocketBlock && !IPLimiter.Verify(e.State.Address)) { e.Accepted = false; e.RejectReason = ALRReason.InUse; log.Info(String.Format("Login: {0}: Past IP limit threshold", e.State)); return; } string un = e.Username; string pw = e.Password; e.Accepted = false; Account acct = Accounts.GetAccount(un); if (acct == null) { if (AutoAccountCreation) { e.State.Account = acct = CreateAccount(e.State, un, pw); e.Accepted = acct == null ? false : acct.CheckAccess(e.State); if (!e.Accepted) { e.RejectReason = ALRReason.BadComm; } } else { log.Warn(String.Format("Login: {0}: Invalid username '{1}'", e.State, un)); e.RejectReason = ALRReason.Invalid; } } else if (!acct.HasAccess(e.State)) { log.Error(String.Format("Login: {0}: Access denied for '{1}'", e.State, un)); e.RejectReason = (m_LockdownLevel > AccessLevel.Player ? ALRReason.BadComm : ALRReason.BadPass); } else if (!acct.CheckPassword(pw)) { log.Error(String.Format("Login: {0}: Invalid password for '{1}'", e.State, un)); e.RejectReason = ALRReason.BadPass; } else if (acct.Banned) { log.Error(String.Format("Login: {0}: Banned account '{1}'", e.State, un)); e.RejectReason = ALRReason.Blocked; } else { log.Info(String.Format("Login: {0}: Valid credentials for '{1}'", e.State, un)); e.State.Account = acct; e.Accepted = true; acct.LogAccess(e.State); } if (!e.Accepted) { AccountAttackLimiter.RegisterInvalidAccess(e.State); } }
public static void EventSink_AccountLogin(AccountLoginEventArgs e) { if (!IPLimiter.SocketBlock && !IPLimiter.Verify(e.State.Address)) { e.Accepted = false; e.RejectReason = ALRReason.InUse; Console.WriteLine("Login: {0}: Past IP limit threshold", e.State); using (StreamWriter op = new StreamWriter("ipLimits.log", true)) op.WriteLine("{0}\tPast IP limit threshold\t{1}", e.State, DateTime.Now); // tell other accounts on this IP what's going on IPLimiter.Notify(e.State.Address); return; } string un = e.Username; string pw = e.Password; e.Accepted = false; Account acct = Accounts.GetAccount(un); if (acct == null) { if (AutoAccountCreation) { e.State.Account = acct = CreateAccount(e.State, un, pw); e.Accepted = acct == null ? false : acct.CheckAccess(e.State); if (!e.Accepted) { e.RejectReason = ALRReason.BadComm; } } else { Console.WriteLine("Login: {0}: Invalid username '{1}'", e.State, un); e.RejectReason = ALRReason.Invalid; } } else if (IPLimiter.IPStillHot(acct, e.State.Address)) { Console.WriteLine("Login: {0}: Access denied for '{1}'. IP too hot", e.State, un); e.RejectReason = ALRReason.InUse; } else if (!acct.HasAccess(e.State)) { Console.WriteLine("Login: {0}: Access denied for '{1}'", e.State, un); e.RejectReason = (m_LockdownLevel > AccessLevel.Player ? ALRReason.BadComm : ALRReason.BadPass); } else if (!acct.CheckPassword(pw)) { Console.WriteLine("Login: {0}: Invalid password for '{1}'", e.State, un); e.RejectReason = ALRReason.BadPass; } else if (acct.Banned) { Console.WriteLine("Login: {0}: Banned account '{1}'", e.State, un); e.RejectReason = ALRReason.Blocked; } else { Console.WriteLine("Login: {0}: Valid credentials for '{1}'", e.State, un); e.State.Account = acct; e.Accepted = true; acct.LogAccess(e.State); acct.LastLogin = DateTime.Now; } if (!e.Accepted) { AccountAttackLimiter.RegisterInvalidAccess(e.State); } }
public void InvokeAccountLogin( AccountLoginEventArgs e ) { if ( AccountLogin != null ) AccountLogin( e ); }
public static void EventSink_AccountLogin(AccountLoginEventArgs e) { //Disallow direct logins to other servers if we are not a developer if (!Core.LoginServer && !Core.Developer) { Console.WriteLine("Login: You cannot login directly to this server without the -developer commandline switch"); e.Accepted = false; e.RejectReason = ALRReason.Blocked; return; } if (!IPLimiter.SocketBlock && !IPLimiter.Verify(e.State.Address)) { e.Accepted = false; e.RejectReason = ALRReason.InUse; Console.WriteLine("Login: {0}: Past IP limit threshold", e.State); using (StreamWriter op = new StreamWriter("ipLimits.log", true)) op.WriteLine("{0}\tPast IP limit threshold\t{1}", e.State, DateTime.Now); // tell other accounts on this IP what's going on IPLimiter.Notify(e.State.Address); return; } // before a new logon to this shard, make sure to read in all queued password changes from all shards Account.ReadAllPasswords(); string un = e.Username; string pw = e.Password; e.Accepted = false; Account acct = Accounts.GetAccount(un); if (acct == null) { // there are NO STAFF accounts with this username and either you have NO accounts, or you have a matching account name and password for another shard. if (AutoAccountCreation && !Account.CheckAllStaff(null, un, false) && (!Account.CheckAllAccounts(un) || (Account.CheckAllAccounts(un) && Account.CheckAllPasswords(un, pw)))) { e.State.Account = acct = CreateAccount(e.State, un, pw); e.Accepted = acct == null ? false : acct.CheckAccess(e.State); if (!e.Accepted) { e.RejectReason = ALRReason.BadComm; } } else { if (Account.CheckAllStaff(null, un, false)) { Console.WriteLine("Login: {0}: Invalid password for staff account '{1}'", e.State, un); e.RejectReason = ALRReason.BadPass; } else if (Account.CheckAllAccounts(un)) { Console.WriteLine("Login: {0}: Invalid password for '{1}'", e.State, un); e.RejectReason = ALRReason.BadPass; } else { Console.WriteLine("Login: {0}: Invalid username '{1}'", e.State, un); e.RejectReason = ALRReason.Invalid; } } } else if (IPLimiter.IPStillHot(acct, e.State.Address)) { Console.WriteLine("Login: {0}: Access denied for '{1}'. IP too hot", e.State, un); e.RejectReason = ALRReason.InUse; } else if (!acct.HasAccess(e.State)) { Console.WriteLine("Login: {0}: Access denied for '{1}'", e.State, un); e.RejectReason = (m_LockdownLevel > AccessLevel.Player ? ALRReason.BadComm : ALRReason.BadPass); } // You succeed login when your password matches some shard and no shards have a user with the same name with greater access else if (!(Account.CheckAllPasswords(un, pw) && !Account.CheckAllStaff(acct, un, true))) { if (Account.CheckAllStaff(acct, un, true)) { Console.WriteLine("Login: {0}: Invalid password or access level for staff account '{1}'", e.State, un); } else { Console.WriteLine("Login: {0}: Invalid password for '{1}'", e.State, un); } e.RejectReason = ALRReason.BadPass; } else if (acct.CheckBanned()) { Console.WriteLine("Login: {0}: Banned account '{1}'", e.State, un); e.RejectReason = ALRReason.Blocked; } else { Console.WriteLine("Login: {0}: Valid credentials for '{1}'", e.State, un); e.State.Account = acct; e.Accepted = true; acct.LogAccess(e.State); acct.LastLogin = DateTime.Now; } if (!e.Accepted) { AccountAttackLimiter.RegisterInvalidAccess(e.State); } }
public static void EventSink_AccountLogin( AccountLoginEventArgs e ) { if ( !IPLimiter.SocketBlock && !IPLimiter.Verify( e.State.Address ) ) { e.Accepted = false; e.RejectReason = ALRReason.InUse; Console.WriteLine( "Login: {0}: Past IP limit threshold", e.State ); using ( StreamWriter op = new StreamWriter( "ipLimits.log", true ) ) op.WriteLine( "{0}\tPast IP limit threshold\t{1}", e.State, DateTime.Now ); return; } string un = e.Username; string pw = e.Password; e.Accepted = false; Account acct = Accounts.ServerAccounts.GetAccount(un) as Account; if ( acct == null ) { if ( AutoAccountCreation && un.Trim().Length > 0 ) //To prevent someone from making an account of just '' or a bunch of meaningless spaces { e.State.Account = acct = CreateAccount( e.State, un, pw ); e.Accepted = acct == null ? false : acct.CheckAccess( e.State ); if ( !e.Accepted ) e.RejectReason = ALRReason.BadComm; } else { Console.WriteLine( "Login: {0}: Invalid username '{1}'", e.State, un ); e.RejectReason = ALRReason.Invalid; } } else if ( !acct.HasAccess( e.State ) ) { Console.WriteLine( "Login: {0}: Access denied for '{1}'", e.State, un ); e.RejectReason = ( m_LockdownLevel > AccessLevel.Player ? ALRReason.BadComm : ALRReason.BadPass ); } else if ( !acct.CheckPassword( pw ) ) { Console.WriteLine( "Login: {0}: Invalid password for '{1}'", e.State, un ); e.RejectReason = ALRReason.BadPass; } else if ( acct.Banned ) { Console.WriteLine( "Login: {0}: Banned account '{1}'", e.State, un ); e.RejectReason = ALRReason.Blocked; } else { Console.WriteLine( "Login: {0}: Valid credentials for '{1}'", e.State, un ); e.State.Account = acct; e.Accepted = true; acct.LogAccess( e.State ); } if ( !e.Accepted ) AccountAttackLimiter.RegisterInvalidAccess( e.State ); }
public static void EventSink_AccountLogin(AccountLoginEventArgs e) { string un = e.Username; string pw = e.Password; e.Accepted = false; Account acct = Accounts.GetAccount(un) as Account; if ((acct == null || acct.AccessLevel == AccessLevel.Player) && !IPLimiter.SocketBlock && !IPLimiter.Verify(e.State.Address)) { e.Accepted = false; e.RejectReason = ALRReason.InUse; return; } if (acct == null) { if (AutoAccountCreation && un.Trim().Length > 0) //To prevent someone from making an account of just '' or a bunch of meaningless spaces { e.State.Account = acct = CreateAccount(e.State, un, pw); e.Accepted = acct != null && acct.CheckAccess(e.State); if (!e.Accepted) { e.RejectReason = ALRReason.BadComm; } } else { Console.WriteLine("Login: {0}: Invalid username '{1}'", e.State, un); e.RejectReason = ALRReason.Invalid; } } else if (!acct.HasAccess(e.State)) { Console.WriteLine("Login: {0}: Access denied for '{1}'", e.State, un); e.RejectReason = (m_LockdownLevel > AccessLevel.Player ? ALRReason.BadComm : ALRReason.BadPass); } else if (!acct.CheckPassword(pw)) { Console.WriteLine("Login: {0}: Invalid password for '{1}'", e.State, un); e.RejectReason = ALRReason.BadPass; } else if (acct.Banned) { Console.WriteLine("Login: {0}: Banned account '{1}'", e.State, un); e.RejectReason = ALRReason.Blocked; } else { Console.WriteLine("Login: {0}: Valid credentials for '{1}'", e.State, un); e.State.Account = acct; e.Accepted = true; //acct.LogAccess( e.State ); } if (!e.Accepted) { AccountAttackLimiter.RegisterInvalidAccess(e.State); } }
public static void EventSink_AccountLogin(AccountLoginEventArgs e) { // If the login attempt has already been rejected by another event handler // then just return if (e.Accepted == false) return; if (!IPLimiter.SocketBlock && !IPLimiter.Verify(e.State.Address)) { e.Accepted = false; e.RejectReason = ALRReason.InUse; Utility.PushColor(ConsoleColor.DarkRed); Console.WriteLine("Login: {0}: Past IP limit threshold", e.State); Utility.PopColor(); using (StreamWriter op = new StreamWriter("ipLimits.log", true)) op.WriteLine("{0}\tPast IP limit threshold\t{1}", e.State, DateTime.UtcNow); return; } string un = e.Username; string pw = e.Password; e.Accepted = false; Account acct = Accounts.GetAccount(un) as Account; if (acct == null) { if (AutoAccountCreation && un.Trim().Length > 0) // To prevent someone from making an account of just '' or a bunch of meaningless spaces { e.State.Account = acct = CreateAccount(e.State, un, pw); e.Accepted = acct == null ? false : acct.CheckAccess(e.State); if (!e.Accepted) e.RejectReason = ALRReason.BadComm; } else { Utility.PushColor(ConsoleColor.DarkRed); Console.WriteLine("Login: {0}: Invalid username '{1}'", e.State, un); Utility.PopColor(); e.RejectReason = ALRReason.Invalid; } } else if (!acct.HasAccess(e.State)) { Utility.PushColor(ConsoleColor.Red); Console.WriteLine("Login: {0}: Access denied for '{1}'", e.State, un); Utility.PopColor(); e.RejectReason = (m_LockdownLevel > AccessLevel.VIP ? ALRReason.BadComm : ALRReason.BadPass); } else if (!acct.CheckPassword(pw)) { Utility.PushColor(ConsoleColor.Red); Console.WriteLine("Login: {0}: Invalid password for '{1}'", e.State, un); Utility.PopColor(); e.RejectReason = ALRReason.BadPass; } else if (acct.Banned) { Utility.PushColor(ConsoleColor.Red); Console.WriteLine("Login: {0}: Banned account '{1}'", e.State, un); Utility.PopColor(); e.RejectReason = ALRReason.Blocked; } else { Utility.PushColor(ConsoleColor.Green); Console.WriteLine("Login: {0}: Valid credentials for '{1}'", e.State, un); Utility.PopColor(); e.State.Account = acct; e.Accepted = true; acct.LogAccess(e.State); } if (!e.Accepted) AccountAttackLimiter.RegisterInvalidAccess(e.State); }
/// <summary> /// /// </summary> /// <param name="netState"></param> /// <param name="packetReader"></param> internal static void LoginServerAccountLogin( NetState netState, PacketReader packetReader ) { LOGs.WriteLine( LogMessageType.MSG_NOTICE, "LoginPacketHandlers.LoginServerAccountLogin(...){0}", Thread.CurrentThread.Name ); LoginServerExtendData l_ExtendData = netState.ExtendData as LoginServerExtendData; if ( l_ExtendData == null ) { Debug.WriteLine( "LoginServerPacketHandlers.LoginServerAccountLogin(...) - l_ExtendData == null error!" ); AccountLogin_ReplyRej( netState, LoginReason.LoginFailed ); return; } if ( l_ExtendData.IsLoggedIn == true ) { Debug.WriteLine( "LoginServerPacketHandlers.LoginServerAccountLogin(...) - l_ExtendData.IsLoggedIn == true error!" ); AccountLogin_ReplyRej( netState, LoginReason.LoginFailed ); return; } if ( packetReader.Size < 38/*6 + 32*/ ) { Debug.WriteLine( "LoginServerPacketHandlers.LoginServerAccountLogin(...) - packetReader.Size < 38 error!" ); AccountLogin_ReplyRej( netState, LoginReason.LoginFailed ); return; } string l_strPassword = packetReader.ReadString( 32 ); string l_strUsername = packetReader.ReadStringSafe(); bool l_bIsReturn = false; Session l_Session = new Session( BaseDatabase.Domain ); l_Session.BeginTransaction(); { do { Query l_QueryAccounts = new Query( l_Session, "Select Accounts instances where {AccountsName}=@Username" ); l_QueryAccounts.Parameters.Add( "@Username", l_strUsername ); QueryResult l_AccountsResult = l_QueryAccounts.Execute(); if ( l_AccountsResult == null ) { Debug.WriteLine( "LoginServerPacketHandlers.LoginServerAccountLogin(...) - l_AccountsResult == null error!" ); AccountLogin_ReplyRej( netState, LoginReason.NameError ); l_bIsReturn = true; break; } if ( l_AccountsResult.Count != 1 ) { Debug.WriteLine( "LoginServerPacketHandlers.LoginServerAccountLogin(...) - l_AccountsResult.Count != 1 error!" ); AccountLogin_ReplyRej( netState, LoginReason.LoginFailed ); l_bIsReturn = true; break; } Accounts l_Accounts = l_AccountsResult[0] as Accounts; if ( l_Accounts == null ) { Debug.WriteLine( "LoginServerPacketHandlers.LoginServerAccountLogin(...) - l_Accounts == null error!" ); AccountLogin_ReplyRej( netState, LoginReason.LoginFailed ); l_bIsReturn = true; break; } if ( l_Accounts.Banned == true || l_Accounts.GMLevel < 0 ) { AccountLogin_ReplyRej( netState, LoginReason.Blocked ); l_bIsReturn = true; break; } if ( l_Accounts.Locked == true ) { AccountLogin_ReplyRej( netState, LoginReason.InUse ); for ( int iIndex = 0; iIndex < Program.CharServerList.Count; iIndex++ ) Program.CharServerList[iIndex].SendToCharServer( (int)l_Accounts.AccountsGuid ); l_bIsReturn = true; break; } if ( l_Accounts.Password != l_strPassword ) { AccountLogin_ReplyRej( netState, LoginReason.PasswordError ); l_bIsReturn = true; break; } l_ExtendData.AccountsGuid = l_Accounts.AccountsGuid; l_ExtendData.IsLoggedIn = true; } while ( false ); } l_Session.Commit(); if ( l_bIsReturn == true ) return; AccountLoginEventArgs l_EventArgs = new AccountLoginEventArgs( netState, l_strUsername, l_strPassword ); EventSink.InvokeAccountLogin( l_EventArgs ); if ( l_EventArgs.Accepted ) AccountLogin_ReplyAck( netState ); else AccountLogin_ReplyRej( netState, l_EventArgs.RejectReason ); }
public static void EventSink_AccountLogin(AccountLoginEventArgs e) { if (!IPLimiter.SocketBlock && !IPLimiter.Verify(e.State.Address)) { e.Accepted = false; e.RejectReason = ALRReason.InUse; Console.WriteLine("Login: {0}: Past IP limit threshold", e.State); using (StreamWriter op = new StreamWriter("ipLimits.log", true)) op.WriteLine("{0}\tPast IP limit threshold\t{1}", e.State, DateTime.Now); return; } string un = e.Username; string pw = e.Password; e.Accepted = false; Account acct = Accounts.GetAccount(un) as Account; if (acct == null) { if (AutoAccountCreation && un.Trim().Length > 0) //To prevent someone from making an account of just '' or a bunch of meaningless spaces { e.State.Account = acct = CreateAccount(e.State, un, pw); e.Accepted = acct == null ? false : acct.CheckAccess(e.State); if (!e.Accepted) { e.RejectReason = ALRReason.BadComm; } } else { Console.WriteLine("Login: {0}: Invalid username '{1}'", e.State, un); e.RejectReason = ALRReason.Invalid; } } else if (!acct.HasAccess(e.State)) { Console.WriteLine("Login: {0}: Access denied for '{1}'", e.State, un); e.RejectReason = (m_LockdownLevel > AccessLevel.Player ? ALRReason.BadComm : ALRReason.BadPass); } else if (!acct.CheckPassword(pw)) { Console.WriteLine("Login: {0}: Invalid password for '{1}'", e.State, un); e.RejectReason = ALRReason.BadPass; //*****Logging attempt***** try { Stream fileStream = File.Open("Logs/LoginLogout/" + un + ".log", FileMode.Append, FileAccess.Write, FileShare.ReadWrite); StreamWriter writeAdapter = new StreamWriter(fileStream); writeAdapter.WriteLine(String.Format("{0}: Invalid password for {1} on {2}", e.State, un, DateTime.Now)); writeAdapter.Close(); } catch { Console.WriteLine("Record Error... {0} Login", un); } //************************** } else if (acct.Banned) { Console.WriteLine("Login: {0}: Banned account '{1}'", e.State, un); e.RejectReason = ALRReason.Blocked; //*****Logging attempt***** try { Stream fileStream = File.Open("Logs/LoginLogout/" + un + ".log", FileMode.Append, FileAccess.Write, FileShare.ReadWrite); StreamWriter writeAdapter = new StreamWriter(fileStream); writeAdapter.WriteLine(String.Format("{0}: Banned account: {1} on {2}", e.State, un, DateTime.Now)); writeAdapter.Close(); } catch { Console.WriteLine("Record Error... {0} Login", un); } //************************** } else { Console.WriteLine("Login: {0}: Valid credentials for '{1}'", e.State, un); e.State.Account = acct; e.Accepted = true; acct.LogAccess(e.State); } if (!e.Accepted) { AccountAttackLimiter.RegisterInvalidAccess(e.State); } }
public static void EventSink_AccountLogin(AccountLoginEventArgs e) { try { IAccount a = Accounts.GetAccount(e.Username); if (a == null) return; // si pas de compte (bug xD) on sort Account acc = a as Account; if (a == null || a.Count > 0) return; // Si cast en compte est null ou s'il y a déjà des joueurs pour ce compte, on n'importe pas les joueurs de la save sphere else if (acc != null && acc.Comments != null && acc.Comments.Count > 0) return; // pareil s'il y a déjà un commentaire sur le compte //else if (acc != null && acc.TotalGameTime > TimeSpan.FromMinutes(15)) return; // Vérifions que les fichiers nécessaires existent bien if (!SphereFiles.checkDataFiles()) return; // Commencons par récupérer les SERIAL des personnages associés au compte List<string> charUIDs = new List<string>(); int totalTime = 0; // on récupère le temps en sec joué par le joueurs sur sphere bool found = false; string username = e.Username.ToLower(); foreach (string line in File.ReadAllLines(SphereFiles.accountFile)) { // On cherche d'abord à retrouver l'utilisateur if (line.ToLower() == "[" + username + "]") { found = true; continue; } // Ensuite une fois qu'on l'a trouvé on ajout les SERIAL de ses personnages // jusqu'à tombé sur un autre compte (ou la fin du fichier) if (found) { if (line.StartsWith("[")) break; if (line.StartsWith("TOTALCONNECTTIME=")) totalTime = Int32.Parse(line.Split('=')[1]); if (line.StartsWith("CHARUID")) charUIDs.Add(line.Split('=')[1]); } } // On traite chacun des SERIAL des personnages des joueurs foreach (string c in charUIDs) { Mobile pm = null; // Le mobile qui sera créé found = false; // on remet found à false car on ne l'a pas encore trouvé bool woman = false; // dans le cas on on serait sur une femme il faut s'en souvenir bool hasHouse = false; // On parcourt toutes les lignes du fichier contenant les personnages foreach (string line in File.ReadAllLines(SphereFiles.playerFile)) { // Si l'on recontre une femme on s'en souvient pour lui mettre des seins ! if (line.StartsWith("[WORLDCHAR")) woman = line.Contains("woman"); // Si l'on tombe sur le SERIAL du joueur que l'on cherche on peut passer au traitement if (line.StartsWith("SERIAL=")) { if (line.Split('=')[1] == c) { found = true; continue; } } // On est sur le bon joueur, il faut en extraire les informations if (found) { // Si le Mobile est encore null on l'instancie et on l'initialise if (pm == null) { pm = new PlayerMobile(); pm.Player = true; // !!! nécessaire pour lire le paperdoll pm.AccessLevel = AccessLevel.Player; pm.Map = Map.Internal; // pour que le joueur soit déconnecté pm.LogoutLocation = new Point3D(3503, 2574, 14); // endroit de départ des joueurs pm.LogoutMap = Map.Trammel; // map de départ des joueurs pm.BodyValue = (woman ? 401 : 400); pm.Female = woman; pm.SkillsCap = 7000; // skill cap de 700 pm.StatCap = 225; // stat cap de 225 // Ajoutons un backpack au joueur pour qu'il puisse y ranger ses affaires Container pack = pm.Backpack; if (pack == null) { pack = new Backpack(); pack.Movable = false; pm.AddItem(pack); } // Une cape pour les vétérans ! pm.Backpack.DropItem(new VeteranCloak()); } // Si l'on arrive sur un autre joueur on ajoute l'actuel et on continue de chercher // les éventuels autres joueurs du compte if (line.StartsWith("[")) { // Effectuons quelques petits trucs avant d'ajouter le joueur sur le compte getHair(c, pm); // on récupère et on remet les cheveux du joueur getGold(c, pm); // on récupère l'or du joueur dressPlayer(pm); // on habille le joueur // On remet au joueur un cheque s'il avait une maison if (hasHouse) { Container bank = pm.BankBox; if (bank != null) { BankCheck check = new BankCheck(50000); check.Name = "Rémunération Maison"; bank.DropItem(check); } } hasHouse = false; // On remet de l'argent au joueur en fonction du temps joué sur Sphere if (totalTime > 0) { Container bank = pm.BankBox; if (bank != null) { BankCheck check = new BankCheck((int)(totalTime / (charUIDs.Count * 1.0))); check.Name = "Temps joué"; bank.DropItem(check); } } // Et maintenant on ajoute le joueur au compte à la première place libre for (int i = 0; i < a.Length; ++i) { if (a[i] == null) { a[i] = pm; break; } } pm = null; break; } #region Traitement des différentes propriétés à importer // Nom if (line.StartsWith("NAME=")) pm.Name = line.Split('=')[1]; // Body Hue else if (line.StartsWith("COLOR=")) pm.Hue = Int32.Parse(line.Split('=')[1], NumberStyles.HexNumber); // Body Hue si corps différent else if (pm.Hue == 0 && line.StartsWith("OSKIN=")) pm.Hue = Int32.Parse(line.Split('=')[1], NumberStyles.HexNumber); // Description paperdoll else if (line.StartsWith("PROFILE=")) pm.Profile = line.Split('=')[1].Replace("\\r", "\r"); // Force else if (line.StartsWith("STR=")) pm.Str = Int32.Parse(line.Split('=')[1]); // Int else if (line.StartsWith("INT=")) pm.Int = Int32.Parse(line.Split('=')[1]); // Dex else if (line.StartsWith("DEX=")) pm.Dex = Int32.Parse(line.Split('=')[1]); // Karma else if (line.StartsWith("KARMA=")) pm.Karma = Int32.Parse(line.Split('=')[1]); // Fame else if (line.StartsWith("FAME=")) pm.Fame = Int32.Parse(line.Split('=')[1]); // Female else if (line.StartsWith("FAME=")) pm.Fame = Int32.Parse(line.Split('=')[1]); // Titre RP else if (line.StartsWith("TITLE=")) pm.Title = line.Split('=')[1]; // Pour la rémunération de la maison else if (line.StartsWith("HOME=")) hasHouse = true; /* Position X,Y,Z else if (line.StartsWith("P=")) { string[] location = line.Split('=')[1].Split(','); pm.Location = new Point3D(Int32.Parse(location[0]), Int32.Parse(location[1]), Int32.Parse(location[2])); } */ // Alchemy else if (line.StartsWith("Alchemy=")) pm.Skills[SkillName.Alchemy].BaseFixedPoint = Int32.Parse(line.Split('=')[1]); // Anatomy else if (line.StartsWith("Anatomy=")) pm.Skills[SkillName.Anatomy].BaseFixedPoint = Int32.Parse(line.Split('=')[1]); // Animal Lore else if (line.StartsWith("AnimalLore=")) pm.Skills[SkillName.AnimalLore].BaseFixedPoint = Int32.Parse(line.Split('=')[1]); //Archery else if (line.StartsWith("Archery=")) pm.Skills[SkillName.Archery].BaseFixedPoint = Int32.Parse(line.Split('=')[1]); // Arms Lore else if (line.StartsWith("ArmsLore=")) pm.Skills[SkillName.ArmsLore].BaseFixedPoint = Int32.Parse(line.Split('=')[1]); //Begging else if (line.StartsWith("Begging=")) pm.Skills[SkillName.Begging].BaseFixedPoint = Int32.Parse(line.Split('=')[1]); //Blacksmithing else if (line.StartsWith("Blacksmithing=")) pm.Skills[SkillName.Blacksmith].BaseFixedPoint = Int32.Parse(line.Split('=')[1]); //Bowcraft else if (line.StartsWith("Bowcraft=")) pm.Skills[SkillName.Fletching].BaseFixedPoint = Int32.Parse(line.Split('=')[1]); // Camping else if (line.StartsWith("Camping=")) pm.Skills[SkillName.Camping].BaseFixedPoint = Int32.Parse(line.Split('=')[1]); //Carpentry else if (line.StartsWith("Carpentry=")) pm.Skills[SkillName.Carpentry].BaseFixedPoint = Int32.Parse(line.Split('=')[1]); //Cartography else if (line.StartsWith("Cartography=")) pm.Skills[SkillName.Cartography].BaseFixedPoint = Int32.Parse(line.Split('=')[1]); //Cooking else if (line.StartsWith("Cooking=")) pm.Skills[SkillName.Cooking].BaseFixedPoint = Int32.Parse(line.Split('=')[1]); //DetectingHidden else if (line.StartsWith("DetectingHidden=")) pm.Skills[SkillName.DetectHidden].BaseFixedPoint = Int32.Parse(line.Split('=')[1]); //Enticement else if (line.StartsWith("Enticement=")) pm.Skills[SkillName.Discordance].BaseFixedPoint = Int32.Parse(line.Split('=')[1]); //EvaluatingIntel else if (line.StartsWith("EvaluatingIntel=")) pm.Skills[SkillName.EvalInt].BaseFixedPoint = Int32.Parse(line.Split('=')[1]); //Fencing else if (line.StartsWith("Fencing=")) pm.Skills[SkillName.Fencing].BaseFixedPoint = Int32.Parse(line.Split('=')[1]); //Fishing else if (line.StartsWith("Fishing=")) pm.Skills[SkillName.Fishing].BaseFixedPoint = Int32.Parse(line.Split('=')[1]); //Forensics else if (line.StartsWith("Forensics=")) pm.Skills[SkillName.Forensics].BaseFixedPoint = Int32.Parse(line.Split('=')[1]); //Healing else if (line.StartsWith("Healing=")) pm.Skills[SkillName.Healing].BaseFixedPoint = Int32.Parse(line.Split('=')[1]); // Herding else if (line.StartsWith("Herding=")) pm.Skills[SkillName.Herding].BaseFixedPoint = Int32.Parse(line.Split('=')[1]); //Hiding else if (line.StartsWith("Hiding=")) pm.Skills[SkillName.Hiding].BaseFixedPoint = Int32.Parse(line.Split('=')[1]); //Inscription else if (line.StartsWith("Inscription=")) pm.Skills[SkillName.Inscribe].BaseFixedPoint = Int32.Parse(line.Split('=')[1]); //ItemID else if (line.StartsWith("ItemID=")) pm.Skills[SkillName.ItemID].BaseFixedPoint = Int32.Parse(line.Split('=')[1]); //LockPicking else if (line.StartsWith("LockPicking=")) pm.Skills[SkillName.Lockpicking].BaseFixedPoint = Int32.Parse(line.Split('=')[1]); //Lumberjacking else if (line.StartsWith("Lumberjacking=")) pm.Skills[SkillName.Lumberjacking].BaseFixedPoint = Int32.Parse(line.Split('=')[1]); //Macefighting else if (line.StartsWith("Macefighting=")) pm.Skills[SkillName.Macing].BaseFixedPoint = Int32.Parse(line.Split('=')[1]); //Magery else if (line.StartsWith("Magery=")) pm.Skills[SkillName.Magery].BaseFixedPoint = Int32.Parse(line.Split('=')[1]); //MagicResistance else if (line.StartsWith("MagicResistance=")) pm.Skills[SkillName.MagicResist].BaseFixedPoint = Int32.Parse(line.Split('=')[1]); //Meditation else if (line.StartsWith("Meditation=")) pm.Skills[SkillName.Meditation].BaseFixedPoint = Int32.Parse(line.Split('=')[1]); //Mining else if (line.StartsWith("Mining=")) pm.Skills[SkillName.Mining].BaseFixedPoint = Int32.Parse(line.Split('=')[1]); // Musicianship else if (line.StartsWith("Musicianship=")) pm.Skills[SkillName.Musicianship].BaseFixedPoint = Int32.Parse(line.Split('=')[1]); //Necromancy else if (line.StartsWith("Necromancy=")) pm.Skills[SkillName.Necromancy].BaseFixedPoint = Int32.Parse(line.Split('=')[1]); //Parrying else if (line.StartsWith("Parrying=")) pm.Skills[SkillName.Parry].BaseFixedPoint = Int32.Parse(line.Split('=')[1]); //Peacemaking else if (line.StartsWith("Peacemaking=")) pm.Skills[SkillName.Peacemaking].BaseFixedPoint = Int32.Parse(line.Split('=')[1]); //Poisoning else if (line.StartsWith("Poisoning=")) pm.Skills[SkillName.Poisoning].BaseFixedPoint = Int32.Parse(line.Split('=')[1]); //Provocation else if (line.StartsWith("Provocation=")) pm.Skills[SkillName.Provocation].BaseFixedPoint = Int32.Parse(line.Split('=')[1]); //RemoveTrap else if (line.StartsWith("RemoveTrap=")) pm.Skills[SkillName.RemoveTrap].BaseFixedPoint = Int32.Parse(line.Split('=')[1]); //SpiritSpeak else if (line.StartsWith("SpiritSpeak=")) pm.Skills[SkillName.SpiritSpeak].BaseFixedPoint = Int32.Parse(line.Split('=')[1]); //Stealth else if (line.StartsWith("Stealth=")) pm.Skills[SkillName.Stealth].BaseFixedPoint = Int32.Parse(line.Split('=')[1]); // Swordsmanship else if (line.StartsWith("Swordsmanship=")) pm.Skills[SkillName.Swords].BaseFixedPoint = Int32.Parse(line.Split('=')[1]); //Tactics else if (line.StartsWith("Tactics=")) pm.Skills[SkillName.Tactics].BaseFixedPoint = Int32.Parse(line.Split('=')[1]); //Tailoring else if (line.StartsWith("Tailoring=")) pm.Skills[SkillName.Tailoring].BaseFixedPoint = Int32.Parse(line.Split('=')[1]); //Taming else if (line.StartsWith("Taming=")) pm.Skills[SkillName.AnimalTaming].BaseFixedPoint = Int32.Parse(line.Split('=')[1]); //TasteID else if (line.StartsWith("TasteID=")) pm.Skills[SkillName.TasteID].BaseFixedPoint = Int32.Parse(line.Split('=')[1]); //Tinkering else if (line.StartsWith("Tinkering=")) pm.Skills[SkillName.Tinkering].BaseFixedPoint = Int32.Parse(line.Split('=')[1]); //Tracking else if (line.StartsWith("Tracking=")) pm.Skills[SkillName.Tracking].BaseFixedPoint = Int32.Parse(line.Split('=')[1]); //Snooping else if (line.StartsWith("Snooping=")) pm.Skills[SkillName.Snooping].BaseFixedPoint = Int32.Parse(line.Split('=')[1]); //Stealing else if (line.StartsWith("Stealing=")) pm.Skills[SkillName.Stealing].BaseFixedPoint = Int32.Parse(line.Split('=')[1]); //Veterinary else if (line.StartsWith("Veterinary=")) pm.Skills[SkillName.Veterinary].BaseFixedPoint = Int32.Parse(line.Split('=')[1]); //Wrestling else if (line.StartsWith("Wrestling=")) pm.Skills[SkillName.Wrestling].BaseFixedPoint = Int32.Parse(line.Split('=')[1]); #endregion // On cap les skills à 100 maxi ! for (int i = 0; i < pm.Skills.Length; i++) { Skill skill = pm.Skills[i]; if (skill.Base > 100) skill.Base = 100; } } } } // Ajoutons un commentaire pour indiquer l'importation des personnages à cette date if (a.Count > 0 && a is Account) ((Account)a).Comments.Add(new AccountComment("SphereImporter", a.Count + " players imported from Sphere save file.")); } catch (Exception ex) { Console.WriteLine("SpherePlayerMobileImporter.EventSink_AccountLogin : " + ex.Message); } }
public static void AccountLogin( NetState state, PacketReader pvSrc ) { if ( state.SentFirstPacket ) { state.Dispose(); return; } state.SentFirstPacket = true; string username = pvSrc.ReadString( 30 ); string password = pvSrc.ReadString( 30 ); AccountLoginEventArgs e = new AccountLoginEventArgs( state, username, password ); try { EventSink.InvokeAccountLogin(e); } catch (Exception ex) { Console.WriteLine("Exception disarmed in AccountLogin {0}: {1}", username, ex); } if ( e.Accepted ) AccountLogin_ReplyAck( state ); else AccountLogin_ReplyRej( state, e.RejectReason ); }
public static void EventSink_AccountLogin(AccountLoginEventArgs e) { if (!IPLimiter.SocketBlock && !IPLimiter.Verify(e.State.Address, e.State.Account as Account)) { e.Accepted = false; e.RejectReason = ALRReason.InUse; log.Info("Login: {0}: Past IP limit threshold", e.State); using (StreamWriter op = new StreamWriter(Path.Combine(Core.Config.LogDirectory, "ipLimits.log"), true)) op.WriteLine("{0}\tPast IP limit threshold\t{1}", e.State, DateTime.UtcNow); return; } string un = e.Username; string pw = e.Password; e.Accepted = false; Account acct = Accounts.GetAccount(un); if (acct == null) { if (AutoAccountCreation) { e.State.Account = acct = CreateAccount(e.State, un, pw); e.Accepted = acct == null ? false : acct.CheckAccess(e.State); if (!e.Accepted) { e.RejectReason = ALRReason.BadComm; } } else { log.Info("Login: {0}: Invalid username '{1}'", e.State, un); e.RejectReason = ALRReason.Invalid; } } else if (!acct.HasAccess(e.State)) { log.Info("Login: {0}: Access denied for '{1}'", e.State, un); e.RejectReason = (m_LockdownLevel > AccessLevel.Player ? ALRReason.BadComm : ALRReason.Invalid); } else if (!acct.CheckPassword(pw)) { log.Info("Login: {0}: Invalid password for '{1}'", e.State, un); e.RejectReason = ALRReason.Invalid; } else if (acct.Banned) { log.Info("Login: {0}: Banned account '{1}'", e.State, un); e.RejectReason = ALRReason.Blocked; } else { log.Info("Login: {0}: Valid credentials for '{1}'", e.State, un); e.State.Account = acct; e.Accepted = true; acct.LogAccess(e.State); } if (!e.Accepted) { AccountAttackLimiter.RegisterInvalidAccess(e.State); } }
public static void AccountLogin( NetState state, PacketReader pvSrc ) { if ( state.SentFirstPacket ) { state.Dispose(); return; } state.SentFirstPacket = true; string username = pvSrc.ReadString( 30 ); string password = pvSrc.ReadString( 30 ); AccountLoginEventArgs e = new AccountLoginEventArgs( state, username, password ); try { EventSink.InvokeAccountLogin(e); } catch (Exception ex) { log.Fatal(String.Format("Exception disarmed in AccountLogin {0}", username), ex); } if (e.Accepted && Core.Config.Features["quick-local-connect"]) { /* we have to remember username+password, because it is required to emulate a GameLogin packet */ state.Username = username; state.Password = password; } if ( e.Accepted ) AccountLogin_ReplyAck( state ); else AccountLogin_ReplyRej( state, e.RejectReason ); }
public static void EventSink_AccountLogin( AccountLoginEventArgs e ) { if ( !IPLimiter.SocketBlock && !IPLimiter.Verify( e.State.Address ) ) { e.Accepted = false; e.RejectReason = ALRReason.InUse; Console.WriteLine( "Login: {0}: Past IP limit threshold", e.State ); using ( StreamWriter op = new StreamWriter( "ipLimits.log", true ) ) op.WriteLine( "{0}\tPast IP limit threshold\t{1}", e.State, DateTime.Now ); return; } string un = e.Username; string pw = e.Password; e.Accepted = false; Account acct = Accounts.GetAccount( un ) as Account; if ( acct == null ) { if ( AutoAccountCreation && un.Trim().Length > 0 ) //To prevent someone from making an account of just '' or a bunch of meaningless spaces { e.State.Account = acct = CreateAccount( e.State, un, pw ); e.Accepted = acct == null ? false : acct.CheckAccess( e.State ); if ( !e.Accepted ) e.RejectReason = ALRReason.BadComm; } else { Console.WriteLine( "Login: {0}: Invalid username '{1}'", e.State, un ); e.RejectReason = ALRReason.Invalid; } } else if ( !acct.HasAccess( e.State ) ) { Console.WriteLine( "Login: {0}: Access denied for '{1}'", e.State, un ); e.RejectReason = ( m_LockdownLevel > AccessLevel.Player ? ALRReason.BadComm : ALRReason.BadPass ); } else if ( !acct.CheckPassword( pw ) ) { Console.WriteLine( "Login: {0}: Invalid password for '{1}'", e.State, un ); e.RejectReason = ALRReason.BadPass; //*****Logging attempt***** try { Stream fileStream = File.Open("Logs/LoginLogout/" + un + ".log", FileMode.Append, FileAccess.Write, FileShare.ReadWrite); StreamWriter writeAdapter = new StreamWriter(fileStream); writeAdapter.WriteLine(String.Format("{0}: Invalid password for {1} on {2}", e.State, un, DateTime.Now)); writeAdapter.Close(); } catch { Console.WriteLine("Record Error... {0} Login", un); } //************************** } else if ( acct.Banned ) { Console.WriteLine( "Login: {0}: Banned account '{1}'", e.State, un ); e.RejectReason = ALRReason.Blocked; //*****Logging attempt***** try { Stream fileStream = File.Open("Logs/LoginLogout/" + un + ".log", FileMode.Append, FileAccess.Write, FileShare.ReadWrite); StreamWriter writeAdapter = new StreamWriter(fileStream); writeAdapter.WriteLine(String.Format("{0}: Banned account: {1} on {2}", e.State, un, DateTime.Now)); writeAdapter.Close(); } catch { Console.WriteLine("Record Error... {0} Login", un); } //************************** } else { Console.WriteLine( "Login: {0}: Valid credentials for '{1}'", e.State, un ); e.State.Account = acct; e.Accepted = true; acct.LogAccess( e.State ); } if ( !e.Accepted ) AccountAttackLimiter.RegisterInvalidAccess( e.State ); }
public static void AccountLogin( NetState state, PacketReader pvSrc ) { if ( state.SentFirstPacket ) { state.Dispose(); return; } state.SentFirstPacket = true; string username = pvSrc.ReadString( 30 ); string password = pvSrc.ReadString( 30 ); AccountLoginEventArgs e = new AccountLoginEventArgs( state, username, password ); EventSink.InvokeAccountLogin( e ); if ( e.Accepted ) AccountLogin_ReplyAck( state ); else AccountLogin_ReplyRej( state, e.RejectReason ); }
public static void EventSink_AccountLogin(AccountLoginEventArgs e) { try { IAccount a = Accounts.GetAccount(e.Username); if (a == null) { return; // si pas de compte (bug xD) on sort } Account acc = a as Account; if (a == null || a.Count > 0) { return; // Si cast en compte est null ou s'il y a déjà des joueurs pour ce compte, on n'importe pas les joueurs de la save sphere } else if (acc != null && acc.Comments != null && acc.Comments.Count > 0) { return; // pareil s'il y a déjà un commentaire sur le compte } //else if (acc != null && acc.TotalGameTime > TimeSpan.FromMinutes(15)) return; // Vérifions que les fichiers nécessaires existent bien if (!SphereFiles.checkDataFiles()) { return; } // Commencons par récupérer les SERIAL des personnages associés au compte List <string> charUIDs = new List <string>(); int totalTime = 0; // on récupère le temps en sec joué par le joueurs sur sphere bool found = false; string username = e.Username.ToLower(); foreach (string line in File.ReadAllLines(SphereFiles.accountFile)) { // On cherche d'abord à retrouver l'utilisateur if (line.ToLower() == "[" + username + "]") { found = true; continue; } // Ensuite une fois qu'on l'a trouvé on ajout les SERIAL de ses personnages // jusqu'à tombé sur un autre compte (ou la fin du fichier) if (found) { if (line.StartsWith("[")) { break; } if (line.StartsWith("TOTALCONNECTTIME=")) { totalTime = Int32.Parse(line.Split('=')[1]); } if (line.StartsWith("CHARUID")) { charUIDs.Add(line.Split('=')[1]); } } } // On traite chacun des SERIAL des personnages des joueurs foreach (string c in charUIDs) { Mobile pm = null; // Le mobile qui sera créé found = false; // on remet found à false car on ne l'a pas encore trouvé bool woman = false; // dans le cas on on serait sur une femme il faut s'en souvenir bool hasHouse = false; // On parcourt toutes les lignes du fichier contenant les personnages foreach (string line in File.ReadAllLines(SphereFiles.playerFile)) { // Si l'on recontre une femme on s'en souvient pour lui mettre des seins ! if (line.StartsWith("[WORLDCHAR")) { woman = line.Contains("woman"); } // Si l'on tombe sur le SERIAL du joueur que l'on cherche on peut passer au traitement if (line.StartsWith("SERIAL=")) { if (line.Split('=')[1] == c) { found = true; continue; } } // On est sur le bon joueur, il faut en extraire les informations if (found) { // Si le Mobile est encore null on l'instancie et on l'initialise if (pm == null) { pm = new PlayerMobile(); pm.Player = true; // !!! nécessaire pour lire le paperdoll pm.AccessLevel = AccessLevel.Player; pm.Map = Map.Internal; // pour que le joueur soit déconnecté pm.LogoutLocation = new Point3D(3503, 2574, 14); // endroit de départ des joueurs pm.LogoutMap = Map.Trammel; // map de départ des joueurs pm.BodyValue = (woman ? 401 : 400); pm.Female = woman; pm.SkillsCap = 7000; // skill cap de 700 pm.StatCap = 225; // stat cap de 225 // Ajoutons un backpack au joueur pour qu'il puisse y ranger ses affaires Container pack = pm.Backpack; if (pack == null) { pack = new Backpack(); pack.Movable = false; pm.AddItem(pack); } // Une cape pour les vétérans ! pm.Backpack.DropItem(new VeteranCloak()); } // Si l'on arrive sur un autre joueur on ajoute l'actuel et on continue de chercher // les éventuels autres joueurs du compte if (line.StartsWith("[")) { // Effectuons quelques petits trucs avant d'ajouter le joueur sur le compte getHair(c, pm); // on récupère et on remet les cheveux du joueur getGold(c, pm); // on récupère l'or du joueur dressPlayer(pm); // on habille le joueur // On remet au joueur un cheque s'il avait une maison if (hasHouse) { Container bank = pm.BankBox; if (bank != null) { BankCheck check = new BankCheck(50000); check.Name = "Rémunération Maison"; bank.DropItem(check); } } hasHouse = false; // On remet de l'argent au joueur en fonction du temps joué sur Sphere if (totalTime > 0) { Container bank = pm.BankBox; if (bank != null) { BankCheck check = new BankCheck((int)(totalTime / (charUIDs.Count * 1.0))); check.Name = "Temps joué"; bank.DropItem(check); } } // Et maintenant on ajoute le joueur au compte à la première place libre for (int i = 0; i < a.Length; ++i) { if (a[i] == null) { a[i] = pm; break; } } pm = null; break; } #region Traitement des différentes propriétés à importer // Nom if (line.StartsWith("NAME=")) { pm.Name = line.Split('=')[1]; } // Body Hue else if (line.StartsWith("COLOR=")) { pm.Hue = Int32.Parse(line.Split('=')[1], NumberStyles.HexNumber); } // Body Hue si corps différent else if (pm.Hue == 0 && line.StartsWith("OSKIN=")) { pm.Hue = Int32.Parse(line.Split('=')[1], NumberStyles.HexNumber); } // Description paperdoll else if (line.StartsWith("PROFILE=")) { pm.Profile = line.Split('=')[1].Replace("\\r", "\r"); } // Force else if (line.StartsWith("STR=")) { pm.Str = Int32.Parse(line.Split('=')[1]); } // Int else if (line.StartsWith("INT=")) { pm.Int = Int32.Parse(line.Split('=')[1]); } // Dex else if (line.StartsWith("DEX=")) { pm.Dex = Int32.Parse(line.Split('=')[1]); } // Karma else if (line.StartsWith("KARMA=")) { pm.Karma = Int32.Parse(line.Split('=')[1]); } // Fame else if (line.StartsWith("FAME=")) { pm.Fame = Int32.Parse(line.Split('=')[1]); } // Female else if (line.StartsWith("FAME=")) { pm.Fame = Int32.Parse(line.Split('=')[1]); } // Titre RP else if (line.StartsWith("TITLE=")) { pm.Title = line.Split('=')[1]; } // Pour la rémunération de la maison else if (line.StartsWith("HOME=")) { hasHouse = true; } /* Position X,Y,Z * else if (line.StartsWith("P=")) * { * string[] location = line.Split('=')[1].Split(','); * pm.Location = new Point3D(Int32.Parse(location[0]), Int32.Parse(location[1]), Int32.Parse(location[2])); * } */ // Alchemy else if (line.StartsWith("Alchemy=")) { pm.Skills[SkillName.Alchemy].BaseFixedPoint = Int32.Parse(line.Split('=')[1]); } // Anatomy else if (line.StartsWith("Anatomy=")) { pm.Skills[SkillName.Anatomy].BaseFixedPoint = Int32.Parse(line.Split('=')[1]); } // Animal Lore else if (line.StartsWith("AnimalLore=")) { pm.Skills[SkillName.AnimalLore].BaseFixedPoint = Int32.Parse(line.Split('=')[1]); } //Archery else if (line.StartsWith("Archery=")) { pm.Skills[SkillName.Archery].BaseFixedPoint = Int32.Parse(line.Split('=')[1]); } // Arms Lore else if (line.StartsWith("ArmsLore=")) { pm.Skills[SkillName.ArmsLore].BaseFixedPoint = Int32.Parse(line.Split('=')[1]); } //Begging else if (line.StartsWith("Begging=")) { pm.Skills[SkillName.Begging].BaseFixedPoint = Int32.Parse(line.Split('=')[1]); } //Blacksmithing else if (line.StartsWith("Blacksmithing=")) { pm.Skills[SkillName.Blacksmith].BaseFixedPoint = Int32.Parse(line.Split('=')[1]); } //Bowcraft else if (line.StartsWith("Bowcraft=")) { pm.Skills[SkillName.Fletching].BaseFixedPoint = Int32.Parse(line.Split('=')[1]); } // Camping else if (line.StartsWith("Camping=")) { pm.Skills[SkillName.Camping].BaseFixedPoint = Int32.Parse(line.Split('=')[1]); } //Carpentry else if (line.StartsWith("Carpentry=")) { pm.Skills[SkillName.Carpentry].BaseFixedPoint = Int32.Parse(line.Split('=')[1]); } //Cartography else if (line.StartsWith("Cartography=")) { pm.Skills[SkillName.Cartography].BaseFixedPoint = Int32.Parse(line.Split('=')[1]); } //Cooking else if (line.StartsWith("Cooking=")) { pm.Skills[SkillName.Cooking].BaseFixedPoint = Int32.Parse(line.Split('=')[1]); } //DetectingHidden else if (line.StartsWith("DetectingHidden=")) { pm.Skills[SkillName.DetectHidden].BaseFixedPoint = Int32.Parse(line.Split('=')[1]); } //Enticement else if (line.StartsWith("Enticement=")) { pm.Skills[SkillName.Discordance].BaseFixedPoint = Int32.Parse(line.Split('=')[1]); } //EvaluatingIntel else if (line.StartsWith("EvaluatingIntel=")) { pm.Skills[SkillName.EvalInt].BaseFixedPoint = Int32.Parse(line.Split('=')[1]); } //Fencing else if (line.StartsWith("Fencing=")) { pm.Skills[SkillName.Fencing].BaseFixedPoint = Int32.Parse(line.Split('=')[1]); } //Fishing else if (line.StartsWith("Fishing=")) { pm.Skills[SkillName.Fishing].BaseFixedPoint = Int32.Parse(line.Split('=')[1]); } //Forensics else if (line.StartsWith("Forensics=")) { pm.Skills[SkillName.Forensics].BaseFixedPoint = Int32.Parse(line.Split('=')[1]); } //Healing else if (line.StartsWith("Healing=")) { pm.Skills[SkillName.Healing].BaseFixedPoint = Int32.Parse(line.Split('=')[1]); } // Herding else if (line.StartsWith("Herding=")) { pm.Skills[SkillName.Herding].BaseFixedPoint = Int32.Parse(line.Split('=')[1]); } //Hiding else if (line.StartsWith("Hiding=")) { pm.Skills[SkillName.Hiding].BaseFixedPoint = Int32.Parse(line.Split('=')[1]); } //Inscription else if (line.StartsWith("Inscription=")) { pm.Skills[SkillName.Inscribe].BaseFixedPoint = Int32.Parse(line.Split('=')[1]); } //ItemID else if (line.StartsWith("ItemID=")) { pm.Skills[SkillName.ItemID].BaseFixedPoint = Int32.Parse(line.Split('=')[1]); } //LockPicking else if (line.StartsWith("LockPicking=")) { pm.Skills[SkillName.Lockpicking].BaseFixedPoint = Int32.Parse(line.Split('=')[1]); } //Lumberjacking else if (line.StartsWith("Lumberjacking=")) { pm.Skills[SkillName.Lumberjacking].BaseFixedPoint = Int32.Parse(line.Split('=')[1]); } //Macefighting else if (line.StartsWith("Macefighting=")) { pm.Skills[SkillName.Macing].BaseFixedPoint = Int32.Parse(line.Split('=')[1]); } //Magery else if (line.StartsWith("Magery=")) { pm.Skills[SkillName.Magery].BaseFixedPoint = Int32.Parse(line.Split('=')[1]); } //MagicResistance else if (line.StartsWith("MagicResistance=")) { pm.Skills[SkillName.MagicResist].BaseFixedPoint = Int32.Parse(line.Split('=')[1]); } //Meditation else if (line.StartsWith("Meditation=")) { pm.Skills[SkillName.Meditation].BaseFixedPoint = Int32.Parse(line.Split('=')[1]); } //Mining else if (line.StartsWith("Mining=")) { pm.Skills[SkillName.Mining].BaseFixedPoint = Int32.Parse(line.Split('=')[1]); } // Musicianship else if (line.StartsWith("Musicianship=")) { pm.Skills[SkillName.Musicianship].BaseFixedPoint = Int32.Parse(line.Split('=')[1]); } //Necromancy else if (line.StartsWith("Necromancy=")) { pm.Skills[SkillName.Necromancy].BaseFixedPoint = Int32.Parse(line.Split('=')[1]); } //Parrying else if (line.StartsWith("Parrying=")) { pm.Skills[SkillName.Parry].BaseFixedPoint = Int32.Parse(line.Split('=')[1]); } //Peacemaking else if (line.StartsWith("Peacemaking=")) { pm.Skills[SkillName.Peacemaking].BaseFixedPoint = Int32.Parse(line.Split('=')[1]); } //Poisoning else if (line.StartsWith("Poisoning=")) { pm.Skills[SkillName.Poisoning].BaseFixedPoint = Int32.Parse(line.Split('=')[1]); } //Provocation else if (line.StartsWith("Provocation=")) { pm.Skills[SkillName.Provocation].BaseFixedPoint = Int32.Parse(line.Split('=')[1]); } //RemoveTrap else if (line.StartsWith("RemoveTrap=")) { pm.Skills[SkillName.RemoveTrap].BaseFixedPoint = Int32.Parse(line.Split('=')[1]); } //SpiritSpeak else if (line.StartsWith("SpiritSpeak=")) { pm.Skills[SkillName.SpiritSpeak].BaseFixedPoint = Int32.Parse(line.Split('=')[1]); } //Stealth else if (line.StartsWith("Stealth=")) { pm.Skills[SkillName.Stealth].BaseFixedPoint = Int32.Parse(line.Split('=')[1]); } // Swordsmanship else if (line.StartsWith("Swordsmanship=")) { pm.Skills[SkillName.Swords].BaseFixedPoint = Int32.Parse(line.Split('=')[1]); } //Tactics else if (line.StartsWith("Tactics=")) { pm.Skills[SkillName.Tactics].BaseFixedPoint = Int32.Parse(line.Split('=')[1]); } //Tailoring else if (line.StartsWith("Tailoring=")) { pm.Skills[SkillName.Tailoring].BaseFixedPoint = Int32.Parse(line.Split('=')[1]); } //Taming else if (line.StartsWith("Taming=")) { pm.Skills[SkillName.AnimalTaming].BaseFixedPoint = Int32.Parse(line.Split('=')[1]); } //TasteID else if (line.StartsWith("TasteID=")) { pm.Skills[SkillName.TasteID].BaseFixedPoint = Int32.Parse(line.Split('=')[1]); } //Tinkering else if (line.StartsWith("Tinkering=")) { pm.Skills[SkillName.Tinkering].BaseFixedPoint = Int32.Parse(line.Split('=')[1]); } //Tracking else if (line.StartsWith("Tracking=")) { pm.Skills[SkillName.Tracking].BaseFixedPoint = Int32.Parse(line.Split('=')[1]); } //Snooping else if (line.StartsWith("Snooping=")) { pm.Skills[SkillName.Snooping].BaseFixedPoint = Int32.Parse(line.Split('=')[1]); } //Stealing else if (line.StartsWith("Stealing=")) { pm.Skills[SkillName.Stealing].BaseFixedPoint = Int32.Parse(line.Split('=')[1]); } //Veterinary else if (line.StartsWith("Veterinary=")) { pm.Skills[SkillName.Veterinary].BaseFixedPoint = Int32.Parse(line.Split('=')[1]); } //Wrestling else if (line.StartsWith("Wrestling=")) { pm.Skills[SkillName.Wrestling].BaseFixedPoint = Int32.Parse(line.Split('=')[1]); } #endregion // On cap les skills à 100 maxi ! for (int i = 0; i < pm.Skills.Length; i++) { Skill skill = pm.Skills[i]; if (skill.Base > 100) { skill.Base = 100; } } } } } // Ajoutons un commentaire pour indiquer l'importation des personnages à cette date if (a.Count > 0 && a is Account) { ((Account)a).Comments.Add(new AccountComment("SphereImporter", a.Count + " players imported from Sphere save file.")); } } catch (Exception ex) { Console.WriteLine("SpherePlayerMobileImporter.EventSink_AccountLogin : " + ex.Message); } }
public static void EventSink_AccountLogin(AccountLoginEventArgs e) { // If the login attempt has already been rejected by another event handler // then just return if (e.Accepted == false) { return; } if (!IPLimiter.SocketBlock && !IPLimiter.Verify(e.State.Address)) { e.Accepted = false; e.RejectReason = ALRReason.InUse; Utility.PushColor(ConsoleColor.Red); Console.WriteLine("Login: {0}: Past IP limit threshold", e.State); Utility.PopColor(); using (StreamWriter op = new StreamWriter("ipLimits.log", true)) op.WriteLine("{0}\tPast IP limit threshold\t{1}", e.State, DateTime.UtcNow); return; } string un = e.Username; string pw = e.Password; e.Accepted = false; Account acct = Accounts.GetAccount(un) as Account; if (acct == null) { if (AutoAccountCreation && un.Trim().Length > 0) // To prevent someone from making an account of just '' or a bunch of meaningless spaces { e.State.Account = acct = CreateAccount(e.State, un, pw); e.Accepted = acct == null ? false : acct.CheckAccess(e.State); if (!e.Accepted) { e.RejectReason = ALRReason.BadComm; } } else { Utility.PushColor(ConsoleColor.Red); Console.WriteLine("Login: {0}: Invalid username '{1}'", e.State, un); Utility.PopColor(); e.RejectReason = ALRReason.Invalid; } } else if (!acct.HasAccess(e.State)) { Utility.PushColor(ConsoleColor.Red); Console.WriteLine("Login: {0}: Access denied for '{1}'", e.State, un); Utility.PopColor(); e.RejectReason = (LockdownLevel > AccessLevel.VIP ? ALRReason.BadComm : ALRReason.BadPass); } else if (!acct.CheckPassword(pw)) { Utility.PushColor(ConsoleColor.Red); Console.WriteLine("Login: {0}: Invalid password for '{1}'", e.State, un); Utility.PopColor(); e.RejectReason = ALRReason.BadPass; } else if (acct.Banned) { Utility.PushColor(ConsoleColor.Red); Console.WriteLine("Login: {0}: Banned account '{1}'", e.State, un); Utility.PopColor(); e.RejectReason = ALRReason.Blocked; } else { Utility.PushColor(ConsoleColor.Green); Console.WriteLine("Login: {0}: Valid credentials for '{1}'", e.State, un); Console.WriteLine("Client Type: {0}: {1}", e.State, e.State.IsEnhancedClient ? "Enhanced Client" : "Classic Client"); Utility.PopColor(); e.State.Account = acct; e.Accepted = true; acct.LogAccess(e.State); } if (!e.Accepted) { AccountAttackLimiter.RegisterInvalidAccess(e.State); } }
/// <summary> /// /// </summary> /// <param name="netState"></param> /// <param name="packetReader"></param> internal static void LoginServerAccountLogin(NetState netState, PacketReader packetReader) { LOGs.WriteLine(LogMessageType.MSG_NOTICE, "LoginPacketHandlers.LoginServerAccountLogin(...){0}", Thread.CurrentThread.Name); LoginServerExtendData l_ExtendData = netState.ExtendData as LoginServerExtendData; if (l_ExtendData == null) { Debug.WriteLine("LoginServerPacketHandlers.LoginServerAccountLogin(...) - l_ExtendData == null error!"); AccountLogin_ReplyRej(netState, LoginReason.LoginFailed); return; } if (l_ExtendData.IsLoggedIn == true) { Debug.WriteLine("LoginServerPacketHandlers.LoginServerAccountLogin(...) - l_ExtendData.IsLoggedIn == true error!"); AccountLogin_ReplyRej(netState, LoginReason.LoginFailed); return; } if (packetReader.Size < 38 /*6 + 32*/) { Debug.WriteLine("LoginServerPacketHandlers.LoginServerAccountLogin(...) - packetReader.Size < 38 error!"); AccountLogin_ReplyRej(netState, LoginReason.LoginFailed); return; } string l_strPassword = packetReader.ReadString(32); string l_strUsername = packetReader.ReadStringSafe(); bool l_bIsReturn = false; Session l_Session = new Session(BaseDatabase.Domain); l_Session.BeginTransaction(); { do { Query l_QueryAccounts = new Query(l_Session, "Select Accounts instances where {AccountsName}=@Username"); l_QueryAccounts.Parameters.Add("@Username", l_strUsername); QueryResult l_AccountsResult = l_QueryAccounts.Execute(); if (l_AccountsResult == null) { Debug.WriteLine("LoginServerPacketHandlers.LoginServerAccountLogin(...) - l_AccountsResult == null error!"); AccountLogin_ReplyRej(netState, LoginReason.NameError); l_bIsReturn = true; break; } if (l_AccountsResult.Count != 1) { Debug.WriteLine("LoginServerPacketHandlers.LoginServerAccountLogin(...) - l_AccountsResult.Count != 1 error!"); AccountLogin_ReplyRej(netState, LoginReason.LoginFailed); l_bIsReturn = true; break; } Accounts l_Accounts = l_AccountsResult[0] as Accounts; if (l_Accounts == null) { Debug.WriteLine("LoginServerPacketHandlers.LoginServerAccountLogin(...) - l_Accounts == null error!"); AccountLogin_ReplyRej(netState, LoginReason.LoginFailed); l_bIsReturn = true; break; } if (l_Accounts.Banned == true || l_Accounts.GMLevel < 0) { AccountLogin_ReplyRej(netState, LoginReason.Blocked); l_bIsReturn = true; break; } if (l_Accounts.Locked == true) { AccountLogin_ReplyRej(netState, LoginReason.InUse); for (int iIndex = 0; iIndex < Program.CharServerList.Count; iIndex++) { Program.CharServerList[iIndex].SendToCharServer((int)l_Accounts.AccountsGuid); } l_bIsReturn = true; break; } if (l_Accounts.Password != l_strPassword) { AccountLogin_ReplyRej(netState, LoginReason.PasswordError); l_bIsReturn = true; break; } l_ExtendData.AccountsGuid = l_Accounts.AccountsGuid; l_ExtendData.IsLoggedIn = true; } while (false); } l_Session.Commit(); if (l_bIsReturn == true) { return; } AccountLoginEventArgs l_EventArgs = new AccountLoginEventArgs(netState, l_strUsername, l_strPassword); EventSink.InvokeAccountLogin(l_EventArgs); if (l_EventArgs.Accepted) { AccountLogin_ReplyAck(netState); } else { AccountLogin_ReplyRej(netState, l_EventArgs.RejectReason); } }