PlayerConnection
public class PlayerConnection
{
//STATIC
public static float Time_Out_Timer_Max = 10000;//10 seconds of nothing
public static int currentPlayerID = 1;
public static void IncrementPlayerID()
{
currentPlayerID++;
}
public static void ResetPlayerID()
{
currentPlayerID = 1;
}
//ATTRIBUTES
public int playerID;
public NetPeer netPeer;
public int mostRecentPlayerInputID = 0;
public string currentScene = "";//unassigned until they are pushed into it
public bool active;
public bool onboarded = false; //you may require more data from them before you throw them into battle
public List<PlayerInput> receivedInputs = new List<PlayerInput>();
public string name;
public float timeOutTimer = Time_Out_Timer_Max;
//NOTE add any other relevant player stuff here, like lv, gear, class, rank wtf ever
//...
A PlayerConnection stores some basic data on a player such as their playerID, whether they are active and onboarded, as well a NetPeer so we can send packets to them. In the example player name is stored, but this is a good space to store other player specific details such as level, gear, etc.
This information is stored on the server side, a PlayerConnection per connected client. When clients do inputs they send them to the server which stores them (or at least the most recent). When a server actions an input from this list, it sends its gameTick id back with the next snapshot to the client so the client knows which inputs have been confirmed on the server.
Methods
public PlayerConnection(NetPeer netPeer)
Constructor taking a connected players NetPeer and then sets up a unique ID
public void AddReceivedInput(PlayerInput input)
Adds input to the receivedInputs list if it hasn’t been already and then sorts them