Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TEST] network relogin #2809

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Source/ACE.Adapter/ACE.Adapter.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<TargetFrameworks>netstandard2.0</TargetFrameworks>
<Platforms>AnyCPU</Platforms>
<Version>1.0.0</Version>
<Authors>ACEmulator Contributors</Authors>
Expand Down
9 changes: 1 addition & 8 deletions Source/ACE.Database/ACE.Database.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<TargetFrameworks>netstandard2.0</TargetFrameworks>
<Platforms>AnyCPU</Platforms>
<Authors>ACEmulator Contributors</Authors>
<RepositoryType>git</RepositoryType>
Expand All @@ -22,13 +22,6 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="2.2.6" />
<PackageReference Include="System.Diagnostics.Debug" Version="4.3.0" />
<PackageReference Include="System.IO.FileSystem" Version="4.3.0" />
<PackageReference Include="System.Net.NameResolution" Version="4.3.0" />
<PackageReference Include="System.Net.Primitives" Version="4.3.0" />
<PackageReference Include="System.Runtime" Version="4.3.0" />
<PackageReference Include="System.Runtime.Extensions" Version="4.3.0" />
<PackageReference Include="System.Runtime.InteropServices" Version="4.3.0" />
</ItemGroup>

<ItemGroup>
Expand Down
44 changes: 30 additions & 14 deletions Source/ACE.Server/Network/Handlers/AuthenticationHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ private static void DoLogin(Session session, PacketInboundLoginRequest loginRequ

try
{
log.Debug($"new client connected: {loginRequest.Account}. setting session properties");
AccountSelectCallback(account, session, loginRequest);
}
catch (Exception ex)
Expand All @@ -97,18 +96,9 @@ private static void DoLogin(Session session, PacketInboundLoginRequest loginRequ
}
}


private static void AccountSelectCallback(Account account, Session session, PacketInboundLoginRequest loginRequest)
private static void SendConnectRequest(Session session)
{
packetLog.DebugFormat("ConnectRequest TS: {0}", Timers.PortalYearTicks);

if (session.Network.ConnectionData.ServerSeed == null || session.Network.ConnectionData.ClientSeed == null)
{
// these are null if ConnectionData.DiscardSeeds() is called because of some other error condition.
session.Terminate(SessionTerminationReason.BadHandshake, new GameMessageCharacterError(CharacterError.ServerCrash1));
return;
}

// verify: should this happen if server responds with connection error?
var connectRequest = new PacketOutboundConnectRequest(
Timers.PortalYearTicks,
session.Network.ConnectionData.ConnectionCookie,
Expand All @@ -119,15 +109,27 @@ private static void AccountSelectCallback(Account account, Session session, Pack
session.Network.ConnectionData.DiscardSeeds();

session.Network.EnqueueSend(connectRequest);
}


private static void AccountSelectCallback(Account account, Session session, PacketInboundLoginRequest loginRequest)
{
packetLog.DebugFormat("ConnectRequest TS: {0}", Timers.PortalYearTicks);

if (session.State != SessionState.WorldConnected && (session.Network.ConnectionData.ServerSeed == null || session.Network.ConnectionData.ClientSeed == null))
{
// these are null if ConnectionData.DiscardSeeds() is called because of some other error condition.
session.Terminate(SessionTerminationReason.BadHandshake, new GameMessageCharacterError(CharacterError.ServerCrash1));
return;
}

if (loginRequest.NetAuthType < NetAuthType.AccountPassword)
{
if (loginRequest.Account == "acservertracker:jj9h26hcsggc")
{
//log.Info($"Incoming ping from a Thwarg-Launcher client... Sending Pong...");

SendConnectRequest(session);
session.Terminate(SessionTerminationReason.PongSentClosingConnection, new GameMessageCharacterError(CharacterError.ServerCrash1));

return;
}

Expand All @@ -136,13 +138,15 @@ private static void AccountSelectCallback(Account account, Session session, Pack
else
log.Debug($"client {loginRequest.Account} connected with no Password or GlsTicket included so booting");

SendConnectRequest(session);
session.Terminate(SessionTerminationReason.NotAuthorizedNoPasswordOrGlsTicketIncludedInLoginReq, new GameMessageCharacterError(CharacterError.AccountInvalid));

return;
}

if (account == null)
{
SendConnectRequest(session);
session.Terminate(SessionTerminationReason.NotAuthorizedAccountNotFound, new GameMessageCharacterError(CharacterError.AccountDoesntExist));
return;
}
Expand All @@ -151,6 +155,7 @@ private static void AccountSelectCallback(Account account, Session session, Pack
{
if (NetworkManager.Find(account.AccountName) != null)
{
SendConnectRequest(session);
session.Terminate(SessionTerminationReason.AccountInUse, new GameMessageCharacterError(CharacterError.Logon));
return;
}
Expand All @@ -165,6 +170,7 @@ private static void AccountSelectCallback(Account account, Session session, Pack
else
log.Debug($"client {loginRequest.Account} connected with non matching password so booting");

SendConnectRequest(session);
session.Terminate(SessionTerminationReason.NotAuthorizedPasswordMismatch, new GameMessageBootAccount(" because the password entered for this account was not correct."));

// TO-DO: temporary lockout of account preventing brute force password discovery
Expand All @@ -179,10 +185,15 @@ private static void AccountSelectCallback(Account account, Session session, Pack

if (previouslyConnectedAccount != null)
{
// do not send connection request here, or else vials will fill up on new client,
// and it won't try to repeatedly reconnect until previous char is logged out of world
previouslyConnectedAccount.Terminate(SessionTerminationReason.AccountLoggedIn, new GameMessageCharacterError(CharacterError.Logon));
return;
}
}

log.Debug($"new client connected: {loginRequest.Account}. setting session properties");

if (WorldManager.WorldStatus == WorldManager.WorldStatusState.Open)
log.Info($"client {loginRequest.Account} connected with verified password");
else
Expand All @@ -195,6 +206,7 @@ private static void AccountSelectCallback(Account account, Session session, Pack
else
log.Debug($"client {loginRequest.Account} connected with GlsTicket which is not implemented yet so booting");

SendConnectRequest(session);
session.Terminate(SessionTerminationReason.NotAuthorizedGlsTicketNotImplementedToProcLoginReq, new GameMessageCharacterError(CharacterError.AccountInvalid));

return;
Expand All @@ -206,6 +218,7 @@ private static void AccountSelectCallback(Account account, Session session, Pack
if (now < account.BanExpireTime.Value)
{
var reason = account.BanReason;
SendConnectRequest(session);
session.Terminate(SessionTerminationReason.AccountBanned, new GameMessageBootAccount($"{(reason != null ? $" - {reason}" : null)}"), null, reason);
return;
}
Expand All @@ -215,9 +228,12 @@ private static void AccountSelectCallback(Account account, Session session, Pack
}
}

SendConnectRequest(session);

account.UpdateLastLogin(session.EndPoint.Address);

session.SetAccount(account.AccountId, account.AccountName, (AccessLevel)account.AccessLevel);

session.State = SessionState.AuthConnectResponse;
}

Expand Down
11 changes: 11 additions & 0 deletions Source/ACE.Server/Network/Managers/NetworkManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,17 @@ public static void ProcessPacket(ConnectionListener connectionListener, ClientPa
var ipAllowsUnlimited = ConfigManager.Config.Server.Network.AllowUnlimitedSessionsFromIPAddresses.Contains(endPoint.Address.ToString());
if (ipAllowsUnlimited || ConfigManager.Config.Server.Network.MaximumAllowedSessionsPerIPAddress == -1 || GetSessionEndpointTotalByAddressCount(endPoint.Address) < ConfigManager.Config.Server.Network.MaximumAllowedSessionsPerIPAddress)
{
// if a character from a previous session is still logged into the world,
// we really want FindOrCreateSession to return the previous session here
// if the previous session is dropped immediately, before the character has completely exited world,
// in-game packets from the previous character will start broadcasting to client @ char select screen,
// which can cause ac client to get into weird state.

// for example, if the server responds with 'character already in world' when character tries to log in again,
// if in-game packets from previous session are broadcast @ char select screen,
// it causes client to go into an automatic continuous loop very quickly,
// where the client tries to repeatedly re-enter the world

var session = FindOrCreateSession(connectionListener, endPoint);
if (session != null)
{
Expand Down
22 changes: 16 additions & 6 deletions Source/ACE.Server/Network/Session.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,10 @@ public Session(ConnectionListener connectionListener, IPEndPoint endPoint, ushor

private bool CheckState(ClientPacket packet)
{
if (packet.Header.HasFlag(PacketHeaderFlags.LoginRequest) && State != SessionState.AuthLoginRequest)
return false;
// if existing session was found in WorldConnected state, it should be pushed through for AccountSelectCallback() to terminate

//if (packet.Header.HasFlag(PacketHeaderFlags.LoginRequest) && State != SessionState.AuthLoginRequest)
//return false;

if (packet.Header.HasFlag(PacketHeaderFlags.ConnectResponse) && State != SessionState.AuthConnectResponse)
return false;
Expand Down Expand Up @@ -249,11 +251,14 @@ public void Terminate(SessionTerminationReason reason, GameMessage message = nul
{
Network.EnqueueSend(message);
}
PendingTermination = new SessionTerminationDetails()
if (PendingTermination == null)
{
ExtraReason = extraReason,
Reason = reason
};
PendingTermination = new SessionTerminationDetails()
{
ExtraReason = extraReason,
Reason = reason
};
}
}

public void DropSession()
Expand Down Expand Up @@ -283,7 +288,12 @@ public void DropSession()

// At this point, if the player was on a landblock, they'll still exist on that landblock until the logout animation completes (~6s).
}
else
DropSessionPost();
}

public void DropSessionPost()
{
NetworkManager.RemoveSession(this);

// This is a temp fix to mark the Session.Network portion of the Session as released
Expand Down
6 changes: 6 additions & 0 deletions Source/ACE.Server/WorldObjects/Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,9 @@ public void LogOut_Inner(bool clientSessionTerminatedAbruptly = false)
SetPropertiesAtLogOut();
SavePlayerToDatabase();
PlayerManager.SwitchPlayerFromOnlineToOffline(this);

if (Session.PendingTermination != null || ServerManager.ShutdownInProgress)
Session.DropSessionPost();
});

// close any open landblock containers (chests / corpses)
Expand Down Expand Up @@ -592,6 +595,9 @@ public void LogOut_Inner(bool clientSessionTerminatedAbruptly = false)
SetPropertiesAtLogOut();
SavePlayerToDatabase();
PlayerManager.SwitchPlayerFromOnlineToOffline(this);

if (Session.PendingTermination != null || ServerManager.ShutdownInProgress)
Session.DropSessionPost();
}
}

Expand Down