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

Commit

Permalink
*Very* basic test to ensure server and client are same version
Browse files Browse the repository at this point in the history
  • Loading branch information
ForLoveOfCats committed Feb 13, 2019
1 parent d5b51ef commit f541d56
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Game/Game.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

public class Game : Node
{
public const string Version = "0.1-dev"; //Yes it's a string shush

public static Node RuntimeRoot;

public static int MaxPlayers = 8;
Expand Down
21 changes: 21 additions & 0 deletions Net/Net.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ public void _PlayerConnected(int Id)
Game.StartWorld();
PeerList.Add(Self.GetTree().GetNetworkUniqueId());
Game.SpawnPlayer(Self.GetTree().GetNetworkUniqueId(), true);

RpcId(ServerId, nameof(NotifyVersion), Game.Version);
}
else
{
Expand All @@ -55,11 +57,30 @@ public void _PlayerConnected(int Id)
Scripting.Self.RpcId(Id, nameof(Scripting.NetLoadClientScript), new object[] {Scripting.ClientGmScript});
}

RpcId(ServerId, nameof(NotifyVersion), Game.Version);
RpcId(Id, nameof(ReadyToRequestWorld), new object[] {});
}
}


[Remote]
public void NotifyVersion(string Version)
{
if(GetTree().GetNetworkUniqueId() == ServerId)
{
//The client sent its version and we are running on the server
if(Version != Game.Version)
{
((NetworkedMultiplayerENet)GetTree().GetNetworkPeer()).DisconnectPeer(GetTree().GetRpcSenderId());
}
}
else
{
//The server sent its version and we are running on the client
}
}


public void _PlayerDisconnected(int Id)
{
Console.Log("Player '" + Id.ToString() + "' disconnected");
Expand Down

0 comments on commit f541d56

Please sign in to comment.