-
Notifications
You must be signed in to change notification settings - Fork 911
Commit
Fix for issue #404 + added support for steamLoginSecure
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -82,9 +82,14 @@ public IEnumerable<SteamID> FriendsList | |
// The number, in milliseconds, between polls for the trade. | ||
int TradePollingInterval; | ||
|
||
public string MyLoginKey; | ||
public string MyUserNonce; | ||
public string MyUniqueId; | ||
|
||
string sessionId; | ||
string token; | ||
string tokensecure; | ||
bool CookiesAreInvalid = true; | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
BlueRaja
Author
Collaborator
|
||
|
||
bool isprocess; | ||
public bool IsRunning = false; | ||
|
||
|
@@ -218,7 +223,7 @@ public void StopBot() | |
/// </returns> | ||
public bool OpenTrade(SteamID other) | ||
{ | ||
if (CurrentTrade != null) | ||
if (CurrentTrade != null || CheckCookies() == false) | ||
return false; | ||
|
||
SteamTrade.Trade(other); | ||
|
@@ -351,7 +356,7 @@ void HandleSteamMessage(CallbackMsg msg) | |
if (callback.Result == EResult.OK) | ||
{ | ||
MyLoginKey = callback.WebAPIUserNonce; | ||
MyUserNonce = callback.WebAPIUserNonce; | ||
} | ||
else | ||
{ | ||
|
@@ -380,25 +385,9 @@ void HandleSteamMessage(CallbackMsg msg) | |
|
||
msg.Handle<SteamUser.LoginKeyCallback>(callback => | ||
{ | ||
while (true) | ||
{ | ||
bool authd = SteamWeb.Authenticate(callback, SteamClient, out sessionId, out token, MyLoginKey); | ||
MyUniqueId = callback.UniqueID.ToString(); | ||
if (authd) | ||
{ | ||
log.Success("User Authenticated!"); | ||
tradeManager = new TradeManager(apiKey, sessionId, token); | ||
tradeManager.SetTradeTimeLimits(MaximumTradeTime, MaximiumActionGap, TradePollingInterval); | ||
tradeManager.OnTimeout += OnTradeTimeout; | ||
break; | ||
} | ||
else | ||
{ | ||
log.Warn("Authentication failed, retrying in 2s..."); | ||
Thread.Sleep(2000); | ||
} | ||
} | ||
UserWebLogOn(); | ||
if (Trade.CurrentSchema == null) | ||
{ | ||
|
@@ -417,6 +406,22 @@ void HandleSteamMessage(CallbackMsg msg) | |
GetUserHandler(SteamClient.SteamID).OnLoginCompleted(); | ||
}); | ||
|
||
msg.Handle<SteamClient.JobCallback<SteamUser.WebAPIUserNonceCallback>>(jobCallback => | ||
{ | ||
log.Debug("Received new WebAPIUserNonce."); | ||
if (jobCallback.Callback.Result == EResult.OK) | ||
{ | ||
MyUserNonce = jobCallback.Callback.Nonce; | ||
UserWebLogOn(); | ||
} | ||
else | ||
{ | ||
log.Error("WebAPIUserNonce Error: " + jobCallback.Callback.Result); | ||
} | ||
}); | ||
|
||
// handle a special JobCallback differently than the others | ||
if (msg.IsType<SteamClient.JobCallback<SteamUser.UpdateMachineAuthCallback>>()) | ||
{ | ||
|
@@ -515,6 +520,12 @@ void HandleSteamMessage(CallbackMsg msg) | |
|
||
msg.Handle<SteamTrading.TradeProposedCallback>(callback => | ||
{ | ||
if (CheckCookies() == false) | ||
{ | ||
SteamTrade.RespondToTrade(callback.TradeID, false); | ||
return; | ||
} | ||
try | ||
{ | ||
tradeManager.InitializeTrade(SteamUser.SteamID, callback.OtherClient); | ||
|
@@ -604,6 +615,70 @@ void UserLogOn() | |
SteamUser.LogOn(logOnDetails); | ||
} | ||
|
||
void UserWebLogOn() | ||
{ | ||
while (true) | ||
{ | ||
bool authd = SteamWeb.Authenticate(MyUniqueId, SteamClient, out sessionId, out token, out tokensecure, MyUserNonce); | ||
|
||
if (authd) | ||
{ | ||
log.Success("User Authenticated!"); | ||
|
||
tradeManager = new TradeManager(apiKey, sessionId, token); | ||
tradeManager.SetTradeTimeLimits(MaximumTradeTime, MaximiumActionGap, TradePollingInterval); | ||
tradeManager.OnTimeout += OnTradeTimeout; | ||
|
||
CookiesAreInvalid = false; | ||
break; | ||
} | ||
else | ||
{ | ||
log.Warn("Authentication failed, retrying in 2s..."); | ||
Thread.Sleep(2000); | ||
} | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Checks if sessionId and token cookies are still valid. | ||
/// Sets cookie flag if they are invalid. | ||
/// </summary> | ||
/// <returns>true if cookies are valid; otherwise false</returns> | ||
bool CheckCookies() | ||
{ | ||
// We still haven't re-authenticated | ||
if (CookiesAreInvalid) | ||
return false; | ||
|
||
// Construct cookie container | ||
CookieContainer cookies = new CookieContainer(); | ||
cookies.Add(new Cookie("sessionid", sessionId, String.Empty, "steamcommunity.com")); | ||
cookies.Add(new Cookie("steamLogin", token, String.Empty, "steamcommunity.com")); | ||
|
||
try | ||
{ | ||
if (!SteamWeb.VerifyCookies(cookies)) | ||
{ | ||
// Cookies are no longer valid | ||
log.Warn("Cookies are invalid. Need to re-authenticate."); | ||
CookiesAreInvalid = true; | ||
SteamUser.RequestWebAPIUserNonce(); | ||
return false; | ||
} | ||
else | ||
{ | ||
return true; | ||
} | ||
} | ||
catch | ||
{ | ||
// Even if exception is caught, we should still continue. | ||
log.Warn("Cookie check failed. http://steamcommunity.com is possibly down."); | ||
return true; | ||
} | ||
} | ||
|
||
UserHandler GetUserHandler(SteamID sid) | ||
{ | ||
if (!userHandlers.ContainsKey(sid)) | ||
|
The casing in this variable doesn't match the previous ones.
public
variables are capitalized per-word and non-public ones should be alllowercasecamel case.Actually, tokenSecure should be camel case to match sessionId...