Skip to content
This repository has been archived by the owner on Jul 18, 2020. It is now read-only.

Commit

Permalink
Display the server version on disconnect
Browse files Browse the repository at this point in the history
  • Loading branch information
Zetrith committed Jan 19, 2019
1 parent 139ccbe commit 67e32e3
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Languages/English/Keyed/Multiplayer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<MpInvalidGameName>Invalid game name</MpInvalidGameName>

<MpWrongProtocol>Wrong protocol version</MpWrongProtocol>
<MpWrongModVersionInfo>Make sure you are using the same Multiplayer version as the host.</MpWrongModVersionInfo>
<MpWrongMultiplayerVersionInfo>The server is hosted on Multiplayer {0} (protocol {1}).</MpWrongMultiplayerVersionInfo>

<MpWrongDefs>Mod definition mismatch</MpWrongDefs>
<MpWrongDefsInfo>Make sure your installed mods, their versions and order match the host's.</MpWrongDefsInfo>
Expand Down
14 changes: 12 additions & 2 deletions Source/Client/MultiplayerSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

namespace Multiplayer.Client
{
[HotSwappable]
public class MultiplayerSession : IConnectionStatusListener
{
public string gameName;
Expand Down Expand Up @@ -123,7 +124,16 @@ public void HandleDisconnectReason(MpDisconnectReason reason, byte[] data)

if (reason == MpDisconnectReason.Generic) reasonKey = reader.ReadString();

if (reason == MpDisconnectReason.Protocol) { reasonKey = "MpWrongProtocol"; descKey = "MpWrongModVersionInfo"; }
if (reason == MpDisconnectReason.Protocol)
{
reasonKey = "MpWrongProtocol";

string strVersion = data.Length != 0 ? reader.ReadString() : "0.4.2";
int proto = data.Length != 0 ? reader.ReadInt32() : 11;

disconnectInfo = "MpWrongMultiplayerVersionInfo".Translate(strVersion, proto);
}

if (reason == MpDisconnectReason.UsernameLength) { reasonKey = "MpInvalidUsernameLength"; descKey = "MpChangeUsernameInfo"; }
if (reason == MpDisconnectReason.UsernameChars) { reasonKey = "MpInvalidUsernameChars"; descKey = "MpChangeUsernameInfo"; }
if (reason == MpDisconnectReason.UsernameAlreadyOnline) { reasonKey = "MpInvalidUsernameAlreadyPlaying"; descKey = "MpChangeUsernameInfo"; }
Expand All @@ -139,7 +149,7 @@ public void HandleDisconnectReason(MpDisconnectReason reason, byte[] data)

disconnectReason = reason;
disconnectReasonKey = reasonKey?.Translate();
disconnectInfo = descKey?.Translate();
disconnectInfo = disconnectInfo ?? descKey?.Translate();
}

public void Connected()
Expand Down
2 changes: 1 addition & 1 deletion Source/Common/ServerConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public void HandleProtocol(ByteReader data)
int clientProtocol = data.ReadInt32();
if (clientProtocol != MpVersion.Protocol)
{
Player.Disconnect(MpDisconnectReason.Protocol);
Player.Disconnect(MpDisconnectReason.Protocol, ByteWriter.GetBytes(MpVersion.Version, MpVersion.Protocol));
return;
}

Expand Down

0 comments on commit 67e32e3

Please sign in to comment.