Skip to content

Commit

Permalink
Wait for host to be ready before counting down (mod compat)
Browse files Browse the repository at this point in the history
  • Loading branch information
Lacyway committed Jul 14, 2024
1 parent 053a583 commit 3f5d0c9
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
23 changes: 23 additions & 0 deletions Fika.Core/Coop/GameMode/CoopGame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -663,6 +663,27 @@ internal void DespawnBot(CoopHandler coopHandler, Player bot)
/// <returns></returns>
public override IEnumerator vmethod_1()
{
if (!isServer)
{
FikaClient fikaClient = Singleton<FikaClient>.Instance;
do
{
yield return new WaitForEndOfFrame();
} while (!fikaClient.HostReady);
}
else
{
FikaServer fikaServer = Singleton<FikaServer>.Instance;
InformationPacket packet = new(false)
{
NumberOfPlayers = fikaServer.NetServer.ConnectedPeersCount,
ReadyPlayers = fikaServer.ReadyClients,
HostReady = true
};

fikaServer.SendDataToAll(new(), ref packet, LiteNetLib.DeliveryMethod.ReliableUnordered);
}

CoopPlayer coopPlayer = (CoopPlayer)PlayerOwner.Player;
coopPlayer.PacketSender.Init();

Expand Down Expand Up @@ -1477,6 +1498,8 @@ private void OnMineExplode(MineDirectional directional)
/// </summary>
public override void vmethod_5()
{


GameTimer.Start(null, null);
gparam_0.Player.HealthController.DiedEvent += HealthController_DiedEvent;
gparam_0.vmethod_0();
Expand Down
1 change: 1 addition & 0 deletions Fika.Core/Networking/FikaClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public class FikaClient : MonoBehaviour, INetEventListener
public int Ping = 0;
public int ConnectedClients = 0;
public int ReadyClients = 0;
public bool HostReady = false;
public NetManager NetClient
{
get
Expand Down
4 changes: 3 additions & 1 deletion Fika.Core/Networking/Packets/Backend/InformationPacket.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,22 @@ public struct InformationPacket(bool isRequest) : INetSerializable
public bool IsRequest = isRequest;
public int NumberOfPlayers = 0;
public int ReadyPlayers = 0;

public bool HostReady = false;

public void Deserialize(NetDataReader reader)
{
IsRequest = reader.GetBool();
NumberOfPlayers = reader.GetInt();
ReadyPlayers = reader.GetInt();
HostReady = reader.GetBool();
}

public void Serialize(NetDataWriter writer)
{
writer.Put(IsRequest);
writer.Put(NumberOfPlayers);
writer.Put(ReadyPlayers);
writer.Put(HostReady);
}
}
}

0 comments on commit 3f5d0c9

Please sign in to comment.