Skip to content

Commit

Permalink
Fix bug where characters that have not logged in for a while (and hav…
Browse files Browse the repository at this point in the history
…e completed skills) are always marked as Alpha.
  • Loading branch information
peterhaneve committed Oct 7, 2018
1 parent e12ff20 commit 151604d
Show file tree
Hide file tree
Showing 8 changed files with 103 additions and 33 deletions.
10 changes: 10 additions & 0 deletions src/EVEMon.Common/Constants/NetworkConstants.resx
Original file line number Diff line number Diff line change
Expand Up @@ -611,4 +611,14 @@
<data name="GoogleCalendarSetup" xml:space="preserve">
<value>https://www.google.com/search?q=google%20calendar%20get%20calendar%20id</value>
</data>
<data name="SSOLoginPKCE" xml:space="preserve">
<value>authorize/?response_type=code&amp;redirect_uri={0}&amp;client_id={3}&amp;scope={2}&amp;state={1}&amp;code_challenge_method=S256&amp;code_challenge={4}</value>
</data>
<data name="SSODefaultAppID" xml:space="preserve">
<value>NOTVALIDNOTVALID</value>
<comment>PKCE mode</comment>
</data>
<data name="PostDataPKCEToken" xml:space="preserve">
<value>grant_type=authorization_code&amp;code={0}&amp;client_id={1}&amp;code_verifier={2}</value>
</data>
</root>
27 changes: 27 additions & 0 deletions src/EVEMon.Common/Constants/NetworkConstants1.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 21 additions & 17 deletions src/EVEMon.Common/Helpers/CharacterScratchpad.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ namespace EVEMon.Common.Helpers
public sealed class CharacterScratchpad : BaseCharacter
{
private readonly CharacterAttributeScratchpad[] m_attributes = new CharacterAttributeScratchpad[5];
private readonly Int64[] m_skillLevels;
private readonly Int64[] m_skillSP;
private readonly long[] m_skillLevels;
private readonly long[] m_skillSP;

private readonly BaseCharacter m_character;
private Int64 m_skillPoints;
private long m_skillPoints;

/// <summary>
/// Constructor from a character.
Expand All @@ -33,8 +33,8 @@ public CharacterScratchpad(BaseCharacter character)
TrainedSkills = new Collection<StaticSkillLevel>();
TrainingTime = TimeSpan.Zero;
m_character = character;
m_skillSP = new Int64[StaticSkills.ArrayIndicesCount];
m_skillLevels = new Int64[StaticSkills.ArrayIndicesCount];
m_skillSP = new long[StaticSkills.ArrayIndicesCount];
m_skillLevels = new long[StaticSkills.ArrayIndicesCount];

for (int i = 0; i < m_attributes.Length; i++)
{
Expand All @@ -47,7 +47,8 @@ public CharacterScratchpad(BaseCharacter character)
/// <summary>
/// Gets Alpha/Omega status for this character.
/// </summary>
public override AccountStatus CharacterStatus {
public override AccountStatus CharacterStatus
{
get
{
if(m_character != null)
Expand All @@ -56,7 +57,10 @@ public override AccountStatus CharacterStatus {
}
return base.CharacterStatus;
}
protected set => base.CharacterStatus = value;
protected set
{
base.CharacterStatus = value;
}
}

#region Attributes
Expand Down Expand Up @@ -129,15 +133,15 @@ public void ClearImplants()
/// Gets the total skill points.
/// </summary>
/// <returns></returns>
protected override Int64 TotalSkillPoints => m_skillPoints;
protected override long TotalSkillPoints => m_skillPoints;

/// <summary>
/// Gets the current level of the given skill.
/// </summary>
/// <param name="skill"></param>
/// <returns></returns>
/// <exception cref="System.ArgumentNullException">skill</exception>
public override Int64 GetSkillLevel(StaticSkill skill)
public override long GetSkillLevel(StaticSkill skill)
{
skill.ThrowIfNull(nameof(skill));

Expand All @@ -150,7 +154,7 @@ public override Int64 GetSkillLevel(StaticSkill skill)
/// <param name="skill"></param>
/// <returns></returns>
/// <exception cref="System.ArgumentNullException">skill</exception>
public override Int64 GetSkillPoints(StaticSkill skill)
public override long GetSkillPoints(StaticSkill skill)
{
skill.ThrowIfNull(nameof(skill));

Expand Down Expand Up @@ -253,7 +257,7 @@ public void Train(ISkillLevel training)
/// </summary>
/// <param name="skill"></param>
/// <param name="level"></param>
public void Train(StaticSkill skill, Int64 level)
public void Train(StaticSkill skill, long level)
{
SetSkillLevel(skill, level, LearningOptions.UpgradeOnly);
}
Expand All @@ -264,7 +268,7 @@ public void Train(StaticSkill skill, Int64 level)
/// <param name="skill">The skill.</param>
/// <param name="level">The level.</param>
/// <param name="options">The options.</param>
private void SetSkillLevel(StaticSkill skill, Int64 level, LearningOptions options = LearningOptions.None)
private void SetSkillLevel(StaticSkill skill, long level, LearningOptions options = LearningOptions.None)
{
int index = skill.ArrayIndex;

Expand Down Expand Up @@ -314,10 +318,10 @@ private void SetSkillLevel(StaticSkill skill, Int64 level, LearningOptions optio
/// </summary>
/// <param name="staticSkill"></param>
/// <param name="level"></param>
private void UpdateSP(StaticSkill staticSkill, Int64 level)
private void UpdateSP(StaticSkill staticSkill, long level)
{
Int64 targetSP = staticSkill.GetPointsRequiredForLevel(level);
Int64 difference = targetSP - m_skillSP[staticSkill.ArrayIndex];
long targetSP = staticSkill.GetPointsRequiredForLevel(level);
long difference = targetSP - m_skillSP[staticSkill.ArrayIndex];

m_skillSP[staticSkill.ArrayIndex] = targetSP;
m_skillPoints += difference;
Expand Down Expand Up @@ -410,8 +414,8 @@ private void ResetFromCharacter()
m_skillPoints = 0;
foreach (StaticSkill skill in StaticSkills.AllSkills)
{
Int64 sp = m_character.GetSkillPoints(skill);
Int64 level = m_character.GetSkillLevel(skill);
long sp = m_character.GetSkillPoints(skill);
long level = m_character.GetSkillLevel(skill);

m_skillPoints += sp;
m_skillSP[skill.ArrayIndex] = sp;
Expand Down
26 changes: 14 additions & 12 deletions src/EVEMon.Common/Models/Character.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,43 +93,41 @@ public void UpdateAccountStatus(AccountStatus.AccountStatusType statusType =

if (skill != null && skill.IsTraining)
{
if(SkillPoints > EveConstants.MaxAlphaSkillTraining)
if (SkillPoints > EveConstants.MaxAlphaSkillTraining)
{
statusType = AccountStatus.AccountStatusType.Omega;
}
else {
else
{
// Try to determine account status based on training time
var hoursToTrain = (skill.EndTime - skill.StartTime).TotalHours;
var spToTrain = skill.EndSP - skill.StartSP;
if (hoursToTrain > 0 && spToTrain > 0)
{
// spPerHour must be greater than zero since numerator and denominator are
// spPerHour must be greater than zero since both the numerator and
// denominator are
var spPerHour = spToTrain / hoursToTrain;
double rate = GetOmegaSPPerHour(skill.Skill) / spPerHour;
// Allow for small margin of error, important on skills nearing completion.
// Allow for small margin of error
if (rate < 1.2 && rate > 0.8)
{
statusType = AccountStatus.AccountStatusType.Omega;
}
else if (rate > 1.1)
{
statusType = AccountStatus.AccountStatusType.Alpha;
}
}
}
}

foreach(var sk in Skills)
foreach (var sk in Skills)
{
// Is the skill level being limited by alpha status?
if(sk.ActiveLevel < sk.Level)
if (sk.ActiveLevel < sk.Level)
{
// Active level is being limited by alpha status.
statusType = AccountStatus.AccountStatusType.Alpha;
break;
}
// Has the skill alpha limit been exceeded?
if(sk.ActiveLevel > sk.StaticData.AlphaLimit)
if (sk.ActiveLevel > sk.StaticData.AlphaLimit)
{
// Active level is greater than alpha limit, only on Omega.
statusType = AccountStatus.AccountStatusType.Omega;
Expand Down Expand Up @@ -870,9 +868,13 @@ internal void Import(EsiAPISkills skills, EsiAPISkillQueue queue)
var queuedSkill = dict[skill.ID];
if (queuedSkill.IsCompleted)
{
// The active level could be less than the skill level if the character
// finished an omega skill level (e.g. Repair Systems V) and then went
// alpha without logging in. However, the alternative is to leave
// ActiveLevel too low which breaks omega detection 100%
skill.ActiveLevel = Math.Max(skill.ActiveLevel, queuedSkill.Level);
// Queued skill is completed, so make sure the imported skill is
// updated
//skill.ActiveLevel = Math.Max(skill.ActiveLevel, queuedSkill.Level);
skill.Level = Math.Max(skill.Level, queuedSkill.Level);
skill.Skillpoints = Math.Max(skill.Skillpoints, queuedSkill.EndSP);
}
Expand Down
6 changes: 4 additions & 2 deletions src/EVEMon.Common/Models/ESIKey.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ public ESIKey(long id)
/// <summary>
/// Gets the character identities for this API key.
/// </summary>
public IEnumerable<CharacterIdentity> CharacterIdentities
=> EveMonClient.CharacterIdentities.Where(characterID => characterID.ESIKeys.Contains(this));
public IEnumerable<CharacterIdentity> CharacterIdentities => EveMonClient.
CharacterIdentities.Where(characterID => characterID.ESIKeys.Contains(this));

/// <summary>
/// Gets or sets a value indicating whether this <see cref="ESIKey"/> is monitored.
Expand Down Expand Up @@ -212,6 +212,8 @@ private void OnAccessToken(JsonResult<AccessResponse> result)
else
{
AccessToken = response.AccessToken;
// PKCE routinely updates refresh tokens
RefreshToken = response.RefreshToken;
m_keyExpires = response.ExpiryUTC;
// Have to make a second request for the character information!
SSOAuthenticationService.GetTokenInfo(AccessToken, OnTokenInfo);
Expand Down
2 changes: 1 addition & 1 deletion src/EVEMon.Common/Resources/MD5Sums.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ ac5cb0e021653cc4f9e3b27528741b2c *eve-items-en-US.xml.gzip
3668b50996fc40a0c0853fec427b5712 *eve-masteries-en-US.xml.gzip
d74b9e0d0a28ac14fea54abb29fca45c *eve-properties-en-US.xml.gzip
f1bf6c569f131eb478e080ebe3a68762 *eve-reprocessing-en-US.xml.gzip
8684157679e5345a8b91d5ce15e0dd4f *eve-skills-en-US.xml.gzip
8ae1b941516ea580cf4724d9ea3b6999 *eve-skills-en-US.xml.gzip
Binary file modified src/EVEMon.Common/Resources/eve-skills-en-US.xml.gzip
Binary file not shown.
27 changes: 26 additions & 1 deletion src/EVEMon.Common/Util.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Net;
using System.Net.NetworkInformation;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Json;
Expand Down Expand Up @@ -1138,5 +1137,31 @@ internal static YamlNode ParseYaml(string text)
return yStream.Documents.First().RootNode;
}
}

/// <summary>
/// Converts the binary data to URL-safe Base 64 encoding.
/// </summary>
/// <param name="data">The byte data to convert.</param>
/// <returns>The URL safe encoded version.</returns>
public static string URLSafeBase64(byte[] data)
{
return Convert.ToBase64String(data).Replace('+', '-').Replace('/', '_').
Replace('=', '.');
}

/// <summary>
/// Computes the Base-64 URL safe SHA-256 hash of the data.
/// </summary>
/// <param name="data">The encoded data to hash.</param>
/// <returns>The URL safe encoded SHA-256 hash of that data.</returns>
public static string SHA256Base64(byte[] data)
{
string hash;
using (var sha = new SHA256Managed())
{
hash = URLSafeBase64(sha.ComputeHash(data));
}
return hash;
}
}
}

0 comments on commit 151604d

Please sign in to comment.