Skip to content

Commit d9ce262

Browse files
committed
+added history tab
1 parent 01e499d commit d9ce262

11 files changed

Lines changed: 479 additions & 154 deletions

ChatLogger/AccountLogin.cs

Lines changed: 59 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,20 @@ public class AccountLogin
2222
public static CallbackManager ChatLoggerManager;
2323

2424
public static bool ChatLogger = false;
25+
private static EResult LastLogOnResult;
2526

2627
public static bool IsLoggedIn { get; private set; }
2728
public static bool isRunning = false;
2829

29-
private static int DisconnectedCounter;
30-
private static int MaxDisconnects = 5;
31-
30+
3231
private static string NewloginKey = null;
3332

3433
public static string user, pass;
3534

35+
3636
public static string authCode, twoFactorAuth;
37-
public static string steamID;
37+
public static string steamID, LastMessageSentReceived;
3838

39-
public static string myUserNonce;
40-
public static string myUniqueId;
4139
public static ulong CurrentSteamID = 0;
4240

4341
public static string AvatarPrefix = "http://cdn.akamai.steamstatic.com/steamcommunity/public/images/avatars/";
@@ -76,6 +74,9 @@ public static void Login()
7674

7775
ChatLoggerManager = new CallbackManager(steamClient);
7876

77+
// DebugLog.AddListener(new MyListener());
78+
// DebugLog.Enabled = true;
79+
7980
#region Callbacks
8081
steamUser = steamClient.GetHandler<SteamUser>();
8182
steamFriends = steamClient.GetHandler<SteamFriends>();
@@ -134,7 +135,6 @@ static void OnConnected(SteamClient.ConnectedCallback callback)
134135
else
135136
{
136137
NewloginKey = a.LoginKey;
137-
myUniqueId = a.LoginKey;
138138
File.WriteAllText(Program.AccountsJsonFile, JsonConvert.SerializeObject(list, Formatting.Indented)); // update login key
139139
}
140140
}
@@ -158,8 +158,14 @@ static void OnConnected(SteamClient.ConnectedCallback callback)
158158

159159
static void OnLoggedOn(SteamUser.LoggedOnCallback callback)
160160
{
161+
if (callback == null)
162+
{
163+
throw new ArgumentNullException(nameof(callback));
164+
}
165+
161166
LastLogOnResult = callback.Result;
162167

168+
163169
bool isSteamGuard = callback.Result == EResult.AccountLogonDenied;
164170
bool is2FA = callback.Result == EResult.AccountLoginDeniedNeedTwoFactor;
165171
bool isLoginKey = callback.Result == EResult.InvalidPassword && NewloginKey != null;
@@ -250,7 +256,6 @@ static void OnLoggedOn(SteamUser.LoggedOnCallback callback)
250256

251257
steamID = steamClient.SteamID.ConvertToUInt64().ToString();
252258
CurrentSteamID = steamClient.SteamID.ConvertToUInt64();
253-
myUserNonce = callback.WebAPIUserNonce;
254259
UserCountry = callback.IPCountryCode;
255260

256261
IsLoggedIn = true;
@@ -269,68 +274,50 @@ static void OnLoggedOn(SteamUser.LoggedOnCallback callback)
269274

270275
static void OnDisconnected(SteamClient.DisconnectedCallback callback)
271276
{
272-
if (callback.UserInitiated && !ReconnectOnUserInitiated)
277+
if (callback.UserInitiated)
273278
{
274279
return;
275280
}
276281

282+
EResult lastLogOnResult = LastLogOnResult;
283+
LastLogOnResult = EResult.Invalid;
284+
277285
switch (lastLogOnResult)
278286
{
279287
case EResult.AccountDisabled:
280288
// Do not attempt to reconnect, those failures are permanent
281289
return;
282-
case EResult.InvalidPassword when !string.IsNullOrEmpty(BotDatabase.LoginKey):
283-
BotDatabase.LoginKey = null;
284-
ArchiLogger.LogGenericInfo(Strings.BotRemovedExpiredLoginKey);
285-
286-
break;
287290
case EResult.InvalidPassword:
288291
case EResult.NoConnection:
289292
case EResult.ServiceUnavailable:
290293
case EResult.Timeout:
291294
case EResult.TryAnotherCM:
292295
case EResult.TwoFactorCodeMismatch:
293-
await Task.Delay(5000).ConfigureAwait(false);
296+
//retry
297+
TimeSpan.FromSeconds(5);
298+
steamClient.Connect();
299+
Console.WriteLine("Disconnected from steam, reconnecting in 5 sec... [" + lastLogOnResult + "]");
294300

295301
break;
296-
case EResult.RateLimitExceeded:
297-
298-
302+
case EResult.AccountLoginDeniedNeedTwoFactor:
303+
steamClient.Connect();
299304
break;
300-
}
301-
302-
303-
304-
305-
306305

307-
DisconnectedCounter++;
308-
CurrentPersonaState = 0;
306+
case EResult.RateLimitExceeded:
307+
//retry
308+
Console.WriteLine("Disconnected from steam, please try again in 30min [" + lastLogOnResult + "]");
309309

310-
if (isRunning)
311-
{
312-
if (DisconnectedCounter >= MaxDisconnects)
313-
{
314-
Console.WriteLine("[" + Program.BOTNAME + "] - Too many disconnects occured in a short period of time. Wait 1 minute...");
315-
InfoForm.InfoHelper.CustomMessageBox.Show("Error", "Too many disconnects occured in a short period of time. Wait 1 minute...");
316-
Thread.Sleep(TimeSpan.FromMinutes(1));
317-
DisconnectedCounter = 0;
318-
steamClient.Disconnect();
319-
}
310+
break;
311+
default: //test
312+
TimeSpan.FromSeconds(5);
313+
steamClient.Connect();
314+
Console.WriteLine("Disconnected from steam, reconnecting in 5 sec... [" + lastLogOnResult + "]");
315+
break;
320316
}
321-
322-
323-
Console.WriteLine("[" + Program.BOTNAME + "] - Reconnecting in 1min ...");
324-
Thread.Sleep(TimeSpan.FromMinutes(1));
325-
326-
steamClient.Connect();
327-
328317
}
329318

330319
static void OnLoginKey(SteamUser.LoginKeyCallback callback)
331320
{
332-
myUniqueId = callback.UniqueID.ToString();
333-
334321
steamUser.AcceptNewLoginKey(callback);
335322

336323

@@ -354,6 +341,14 @@ static void OnLoginKey(SteamUser.LoginKeyCallback callback)
354341

355342
static void OnLoggedOff(SteamUser.LoggedOffCallback callback)
356343
{
344+
if (callback == null)
345+
{
346+
throw new ArgumentNullException(nameof(callback));
347+
}
348+
349+
LastLogOnResult = callback.Result;
350+
351+
357352
IsLoggedIn = false;
358353
CurrentPersonaState = 0;
359354
Console.WriteLine("[" + Program.BOTNAME + "] - Logged off of Steam: {0}", callback.Result);
@@ -382,6 +377,8 @@ static void OnFriendMsg(SteamFriends.FriendMsgCallback callback)
382377
{
383378
if (callback.EntryType == EChatEntryType.ChatMsg)
384379
{
380+
String hourMinuteSec = DateTime.Now.ToString("HH:mm:ss");
381+
385382
var Settingslist = JsonConvert.DeserializeObject<ChatLoggerSettings>(File.ReadAllText(Program.SettingsJsonFile));
386383

387384

@@ -396,6 +393,10 @@ static void OnFriendMsg(SteamFriends.FriendMsgCallback callback)
396393

397394
string FinalMsg = "[" + DateTime.Now + "] " + FriendName + ": " + Message;
398395

396+
// Console.WriteLine("\nYou received a message by " + FriendName + "\n Telling you: " + Message);
397+
398+
LastMessageSentReceived = "[" + hourMinuteSec + "] " + FriendName.Replace(":", "") + ": "+Message;
399+
399400
if (!Directory.Exists(Settingslist.PathLogs + @"\" + steamClient.SteamID.ConvertToUInt64()))
400401
{
401402
Directory.CreateDirectory(Settingslist.PathLogs + @"\" + steamClient.SteamID.ConvertToUInt64());
@@ -430,6 +431,7 @@ static void OnFriendEchoMsg(SteamFriends.FriendMsgEchoCallback callback)
430431
{
431432
if (callback.EntryType == EChatEntryType.ChatMsg)
432433
{
434+
433435
var Settingslist = JsonConvert.DeserializeObject<ChatLoggerSettings>(File.ReadAllText(Program.SettingsJsonFile));
434436

435437
ulong FriendID = callback.Recipient;
@@ -444,6 +446,8 @@ static void OnFriendEchoMsg(SteamFriends.FriendMsgEchoCallback callback)
444446

445447
string FinalMsg = "[" + DateTime.Now + "] " + steamFriends.GetPersonaName() + ": " + Message;
446448

449+
Console.WriteLine("\nYou sent a message to " + FriendName + "\n Saying: " + Message);
450+
447451
if (!Directory.Exists(Settingslist.PathLogs + @"\" + steamClient.SteamID.ConvertToUInt64()))
448452
{
449453
Directory.CreateDirectory(Settingslist.PathLogs + @"\" + steamClient.SteamID.ConvertToUInt64());
@@ -500,11 +504,19 @@ public static void Logout()
500504
isRunning = false;
501505
IsLoggedIn = false;
502506
steamUser.LogOff();
503-
DisconnectedCounter = 0;
504507
CurrentPersonaState = 0;
505508
CurrentUsername = null;
506509

507-
510+
508511
}
509512
}
513+
514+
}
515+
516+
class MyListener : IDebugListener
517+
{
518+
public void WriteLine(string category, string msg)
519+
{
520+
Console.WriteLine("[IDebug] 💔 " + category + ": " + msg);
521+
}
510522
}

ChatLogger/AddAcc.Designer.cs

Lines changed: 5 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ChatLogger/App.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
</dependentAssembly>
2929
<dependentAssembly>
3030
<assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
31-
<bindingRedirect oldVersion="0.0.0.0-4.0.6.0" newVersion="4.0.6.0" />
31+
<bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
3232
</dependentAssembly>
3333
<dependentAssembly>
3434
<assemblyIdentity name="System.Collections.Immutable" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />

ChatLogger/ChatLogger.csproj

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,21 @@
1313
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
1414
<FileAlignment>512</FileAlignment>
1515
<TargetFrameworkProfile />
16+
<IsWebBootstrapper>false</IsWebBootstrapper>
17+
<PublishUrl>publish\</PublishUrl>
18+
<Install>true</Install>
19+
<InstallFrom>Disk</InstallFrom>
20+
<UpdateEnabled>false</UpdateEnabled>
21+
<UpdateMode>Foreground</UpdateMode>
22+
<UpdateInterval>7</UpdateInterval>
23+
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
24+
<UpdatePeriodically>false</UpdatePeriodically>
25+
<UpdateRequired>false</UpdateRequired>
26+
<MapFileExtensions>true</MapFileExtensions>
27+
<ApplicationRevision>0</ApplicationRevision>
28+
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
29+
<UseApplicationTrust>false</UseApplicationTrust>
30+
<BootstrapperEnabled>true</BootstrapperEnabled>
1631
</PropertyGroup>
1732
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
1833
<PlatformTarget>AnyCPU</PlatformTarget>
@@ -23,6 +38,7 @@
2338
<DefineConstants>DEBUG;TRACE</DefineConstants>
2439
<ErrorReport>prompt</ErrorReport>
2540
<WarningLevel>4</WarningLevel>
41+
<Prefer32Bit>true</Prefer32Bit>
2642
</PropertyGroup>
2743
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
2844
<PlatformTarget>AnyCPU</PlatformTarget>
@@ -101,8 +117,8 @@
101117
<HintPath>..\packages\System.Numerics.Vectors.4.5.0\lib\net46\System.Numerics.Vectors.dll</HintPath>
102118
<Private>True</Private>
103119
</Reference>
104-
<Reference Include="System.Runtime.CompilerServices.Unsafe, Version=4.0.6.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
105-
<HintPath>..\packages\System.Runtime.CompilerServices.Unsafe.4.7.0\lib\netstandard2.0\System.Runtime.CompilerServices.Unsafe.dll</HintPath>
120+
<Reference Include="System.Runtime.CompilerServices.Unsafe, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
121+
<HintPath>..\packages\System.Runtime.CompilerServices.Unsafe.5.0.0\lib\net45\System.Runtime.CompilerServices.Unsafe.dll</HintPath>
106122
<Private>True</Private>
107123
</Reference>
108124
<Reference Include="System.Runtime.Serialization" />
@@ -224,7 +240,9 @@
224240
</Compile>
225241
</ItemGroup>
226242
<ItemGroup>
227-
<None Include="App.config" />
243+
<None Include="App.config">
244+
<SubType>Designer</SubType>
245+
</None>
228246
</ItemGroup>
229247
<ItemGroup>
230248
<None Include="Resources\ChatLogger_Alert.wav" />
@@ -233,6 +251,18 @@
233251
<Content Include="ChatLogger_Logo.ico" />
234252
<None Include="Resources\ChatLogger_Success.wav" />
235253
</ItemGroup>
254+
<ItemGroup>
255+
<BootstrapperPackage Include=".NETFramework,Version=v4.6.1">
256+
<Visible>False</Visible>
257+
<ProductName>Microsoft .NET Framework 4.6.1 %28x86 and x64%29</ProductName>
258+
<Install>true</Install>
259+
</BootstrapperPackage>
260+
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
261+
<Visible>False</Visible>
262+
<ProductName>.NET Framework 3.5 SP1</ProductName>
263+
<Install>false</Install>
264+
</BootstrapperPackage>
265+
</ItemGroup>
236266
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
237267
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
238268
Other similar extension points exist, see Microsoft.Common.targets.

ChatLogger/EditAcc.Designer.cs

Lines changed: 5 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ChatLogger/Helpers/SteamPath.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
using System;
2-
using System.Linq;
3-
using Microsoft.Win32;
1+
using Microsoft.Win32;
42
namespace ChatLogger.Helpers
53
{
64
public static class SteamPath

0 commit comments

Comments
 (0)