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

Commit 67e32e3

Browse files
committed
Display the server version on disconnect
1 parent 139ccbe commit 67e32e3

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

Languages/English/Keyed/Multiplayer.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<MpInvalidGameName>Invalid game name</MpInvalidGameName>
1212

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

1616
<MpWrongDefs>Mod definition mismatch</MpWrongDefs>
1717
<MpWrongDefsInfo>Make sure your installed mods, their versions and order match the host's.</MpWrongDefsInfo>

Source/Client/MultiplayerSession.cs

+12-2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
namespace Multiplayer.Client
1818
{
19+
[HotSwappable]
1920
public class MultiplayerSession : IConnectionStatusListener
2021
{
2122
public string gameName;
@@ -123,7 +124,16 @@ public void HandleDisconnectReason(MpDisconnectReason reason, byte[] data)
123124

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

126-
if (reason == MpDisconnectReason.Protocol) { reasonKey = "MpWrongProtocol"; descKey = "MpWrongModVersionInfo"; }
127+
if (reason == MpDisconnectReason.Protocol)
128+
{
129+
reasonKey = "MpWrongProtocol";
130+
131+
string strVersion = data.Length != 0 ? reader.ReadString() : "0.4.2";
132+
int proto = data.Length != 0 ? reader.ReadInt32() : 11;
133+
134+
disconnectInfo = "MpWrongMultiplayerVersionInfo".Translate(strVersion, proto);
135+
}
136+
127137
if (reason == MpDisconnectReason.UsernameLength) { reasonKey = "MpInvalidUsernameLength"; descKey = "MpChangeUsernameInfo"; }
128138
if (reason == MpDisconnectReason.UsernameChars) { reasonKey = "MpInvalidUsernameChars"; descKey = "MpChangeUsernameInfo"; }
129139
if (reason == MpDisconnectReason.UsernameAlreadyOnline) { reasonKey = "MpInvalidUsernameAlreadyPlaying"; descKey = "MpChangeUsernameInfo"; }
@@ -139,7 +149,7 @@ public void HandleDisconnectReason(MpDisconnectReason reason, byte[] data)
139149

140150
disconnectReason = reason;
141151
disconnectReasonKey = reasonKey?.Translate();
142-
disconnectInfo = descKey?.Translate();
152+
disconnectInfo = disconnectInfo ?? descKey?.Translate();
143153
}
144154

145155
public void Connected()

Source/Common/ServerConnection.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public void HandleProtocol(ByteReader data)
1919
int clientProtocol = data.ReadInt32();
2020
if (clientProtocol != MpVersion.Protocol)
2121
{
22-
Player.Disconnect(MpDisconnectReason.Protocol);
22+
Player.Disconnect(MpDisconnectReason.Protocol, ByteWriter.GetBytes(MpVersion.Version, MpVersion.Protocol));
2323
return;
2424
}
2525

0 commit comments

Comments
 (0)