diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml
index 984b7e2a..22ab19d4 100644
--- a/.github/workflows/CI.yml
+++ b/.github/workflows/CI.yml
@@ -60,7 +60,7 @@ jobs:
- name: Run Tests
run: |
- MSBuild -p:Configuration=Debug -p:CI=true src/TgSharp.sln
+ MSBuild -p:Configuration=Debug src/TgSharp.sln
certutil -decode encodedSession.dat src/TgSharp.Tests.NUnit/bin/Debug/session.dat
cp app.config src/TgSharp.Tests.NUnit/bin/Debug/TgSharp.Tests.NUnit.dll.config
diff --git a/src/TgSharp.Core/FileSessionStore.cs b/src/TgSharp.Core/FileSessionStore.cs
index 071656df..c77bee54 100644
--- a/src/TgSharp.Core/FileSessionStore.cs
+++ b/src/TgSharp.Core/FileSessionStore.cs
@@ -54,13 +54,6 @@ public static Session FromBytes (byte [] buffer, ISessionStore store, string ses
using (var reader = new BinaryReader (stream)) {
var id = reader.ReadUInt64 ();
var sequence = reader.ReadInt32 ();
-
- // we do this in CI when running tests so that the they can always use a
- // higher sequence than previous run
-#if CI
- sequence = Session.CurrentTime();
-#endif
-
var salt = reader.ReadUInt64 ();
var lastMessageId = reader.ReadInt64 ();
var timeOffset = reader.ReadInt32 ();
diff --git a/src/TgSharp.Core/Session.cs b/src/TgSharp.Core/Session.cs
index c20cdd56..b803c17e 100644
--- a/src/TgSharp.Core/Session.cs
+++ b/src/TgSharp.Core/Session.cs
@@ -4,6 +4,7 @@
using TgSharp.TL;
using TgSharp.Core.MTProto;
using TgSharp.Core.MTProto.Crypto;
+using System.Security.Cryptography;
namespace TgSharp.Core
{
@@ -39,6 +40,10 @@ internal static Session TryLoadOrCreateNew (ISessionStore store, string sessionU
DataCenter = defaultDataCenter,
};
}
+ session.Sequence = 0;
+ byte[] randomSessionId = new byte[8];
+ RandomNumberGenerator.Create().GetNonZeroBytes(randomSessionId);
+ session.Id = BitConverter.ToUInt64(randomSessionId, 0);
return session;
}
@@ -55,18 +60,6 @@ public class Session
internal object Lock = new object ();
public int Sequence { get; set; }
-#if CI
- // see the same CI-wrapped assignment in .FromBytes(), but this one will become useful
- // when we generate a new session.dat for CI again
- = CurrentTime ();
-
- // this is similar to the unixTime but rooted on the worst year of humanity instead of 1970
- internal static int CurrentTime ()
- {
- return (int)DateTime.UtcNow.Subtract (new DateTime (2020, 1, 1)).TotalSeconds;
- }
-#endif
-
public string SessionUserId { get; set; }
internal DataCenter DataCenter { get; set; }
public AuthKey AuthKey { get; set; }
diff --git a/src/TgSharp.Core/TgSharp.Core.csproj b/src/TgSharp.Core/TgSharp.Core.csproj
index d677b52f..ad18e23d 100644
--- a/src/TgSharp.Core/TgSharp.Core.csproj
+++ b/src/TgSharp.Core/TgSharp.Core.csproj
@@ -30,9 +30,6 @@
prompt
4
-
- $(DefineConstants);CI
-