mirror of
https://github.com/sochix/TLSharp.git
synced 2026-01-06 00:40:02 +01:00
Merge b12ecde8e6 into f2a394ea15
This commit is contained in:
commit
9801073b9c
|
|
@ -155,14 +155,24 @@ namespace TLSharp.Core
|
|||
_store.Save(this);
|
||||
}
|
||||
|
||||
public static Session TryLoadOrCreateNew(ISessionStore store, string sessionUserId)
|
||||
public static Session TryLoad(ISessionStore store, string sessionUserId)
|
||||
{
|
||||
return store.Load(sessionUserId) ?? new Session(store)
|
||||
return store.Load(sessionUserId);
|
||||
}
|
||||
|
||||
public static Session Create(
|
||||
ISessionStore store,
|
||||
string sessionUserId,
|
||||
string serverAddress = defaultConnectionAddress,
|
||||
int serverPort = defaultConnectionPort
|
||||
)
|
||||
{
|
||||
return new Session(store)
|
||||
{
|
||||
Id = GenerateRandomUlong(),
|
||||
SessionUserId = sessionUserId,
|
||||
ServerAddress = defaultConnectionAddress,
|
||||
Port = defaultConnectionPort
|
||||
ServerAddress = serverAddress,
|
||||
Port = serverPort
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ using TLSharp.Core.MTProto.Crypto;
|
|||
using TLSharp.Core.Network;
|
||||
using TLSharp.Core.Utils;
|
||||
using TLAuthorization = TeleSharp.TL.Auth.TLAuthorization;
|
||||
using System.Net;
|
||||
|
||||
namespace TLSharp.Core
|
||||
{
|
||||
|
|
@ -30,8 +31,13 @@ namespace TLSharp.Core
|
|||
private List<TLDcOption> dcOptions;
|
||||
private TcpClientConnectionHandler _handler;
|
||||
|
||||
public TelegramClient(int apiId, string apiHash,
|
||||
ISessionStore store = null, string sessionUserId = "session", TcpClientConnectionHandler handler = null)
|
||||
public TelegramClient(int apiId,
|
||||
string apiHash,
|
||||
ISessionStore store = null,
|
||||
string sessionUserId = "session",
|
||||
TcpClientConnectionHandler handler = null,
|
||||
IPEndPoint connectionAddress = null
|
||||
)
|
||||
{
|
||||
if (apiId == default(int))
|
||||
throw new MissingApiConfigurationException("API_ID");
|
||||
|
|
@ -45,7 +51,20 @@ namespace TLSharp.Core
|
|||
_apiId = apiId;
|
||||
_handler = handler;
|
||||
|
||||
_session = Session.TryLoadOrCreateNew(store, sessionUserId);
|
||||
_session = Session.TryLoad(store, sessionUserId);
|
||||
|
||||
if(_session == null)
|
||||
{
|
||||
if(connectionAddress != null)
|
||||
{
|
||||
_session = Session.Create(store, sessionUserId, connectionAddress.Address.ToString(), connectionAddress.Port);
|
||||
}
|
||||
else
|
||||
{
|
||||
_session = Session.Create(store, sessionUserId);
|
||||
}
|
||||
}
|
||||
|
||||
_transport = new TcpTransport(_session.ServerAddress, _session.Port, _handler);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue