Files

88 lines
1.9 KiB
C#
Raw Permalink Normal View History

2022-12-04 19:19:07 +02:00
using UnityGGPO;
2022-12-26 03:47:56 +02:00
public enum PlayerConnectState
2022-12-06 12:22:07 +02:00
{
2022-12-26 03:47:56 +02:00
Connecting = 0,
Synchronizing,
Running,
Disconnected,
Disconnecting,
};
2022-12-04 19:19:07 +02:00
2022-12-26 03:47:56 +02:00
public struct PlayerConnectionInfo
{
public GGPOPlayerType type;
public int handle;
public PlayerConnectState state;
public int connect_progress;
public int disconnect_timeout;
public int disconnect_start;
public int controllerId;
};
public struct ChecksumInfo
{
public int framenumber;
public int checksum;
public override string ToString() => framenumber.ToString() + " " + checksum.ToString("X2");
};
public class GameInfo
{
public PlayerConnectionInfo[] players;
public string status;
public ChecksumInfo now;
public ChecksumInfo periodic;
public void SetConnectState(int handle, PlayerConnectState state)
2022-12-06 12:22:07 +02:00
{
2022-12-26 03:47:56 +02:00
for (int i = 0; i < players.Length; i++)
2022-12-06 12:22:07 +02:00
{
2022-12-26 03:47:56 +02:00
if (players[i].handle == handle)
2022-12-06 12:22:07 +02:00
{
2022-12-26 03:47:56 +02:00
players[i].connect_progress = 0;
2022-12-04 19:19:07 +02:00
players[i].state = state;
2022-12-26 03:47:56 +02:00
break;
2022-12-04 19:19:07 +02:00
}
}
}
2022-12-26 03:47:56 +02:00
public void SetDisconnectTimeout(int handle, int now, int timeout)
{
for (int i = 0; i < players.Length; i++)
{
if (players[i].handle == handle)
{
players[i].disconnect_start = now;
players[i].disconnect_timeout = timeout;
players[i].state = PlayerConnectState.Disconnecting;
break;
}
}
}
public void SetConnectState(PlayerConnectState state)
{
for (int i = 0; i < players.Length; i++)
{
players[i].state = state;
}
}
public void UpdateConnectProgress(int handle, int progress)
{
for (int i = 0; i < players.Length; i++)
{
if (players[i].handle == handle)
{
players[i].connect_progress = progress;
break;
}
}
}
}