|
|
@ -11,6 +11,14 @@ namespace Networking.Server |
|
|
|
public class ClientList : ScriptableObject, IEnumerable<ClientData> |
|
|
|
{ |
|
|
|
|
|
|
|
#if UNITY_EDITOR
|
|
|
|
|
|
|
|
[SerializeField] |
|
|
|
[Multiline] |
|
|
|
private string DevNotes; |
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
[SerializeField] |
|
|
|
private Inventory StartInventory; |
|
|
|
|
|
|
@ -28,6 +36,8 @@ namespace Networking.Server |
|
|
|
public List<ClientData> DisconnectedClients; |
|
|
|
|
|
|
|
|
|
|
|
private List<NetworkConnection> PotentialClients = new List<NetworkConnection>(); |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Called when a client connects or disconnet
|
|
|
|
/// </summary>
|
|
|
@ -48,6 +58,7 @@ namespace Networking.Server |
|
|
|
{ |
|
|
|
ConnectedClients = new List<ClientData>(); |
|
|
|
DisconnectedClients = new List<ClientData>(); |
|
|
|
PotentialClients = new List<NetworkConnection>(); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
@ -73,11 +84,18 @@ namespace Networking.Server |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
if (!PotentialClients.Contains(msg.conn)) |
|
|
|
PotentialClients.Add(msg.conn); |
|
|
|
|
|
|
|
msg.conn.Send(LoginProtocols.RequestLoginDetails, new LoginProtocols.EmptyMsg()); |
|
|
|
ConnectedClients.ForEach(p => msg.conn.Send(LoginProtocols.OtherClientConnected, new LoginProtocols.LoginMsg(p.Name, p.Color, p.characterAnimal))); |
|
|
|
} |
|
|
|
|
|
|
|
public void OnClientDisconnect(NetworkMessage msg) |
|
|
|
{ |
|
|
|
|
|
|
|
PotentialClients.RemoveAll(p => p == msg.conn); |
|
|
|
|
|
|
|
if (!ConnectedClients.Any(p => p.ID == msg.conn.connectionId)) |
|
|
|
{ |
|
|
|
Debug.LogError("Unknown client disconnect [" + msg.conn.connectionId + "]"); |
|
|
@ -88,6 +106,9 @@ namespace Networking.Server |
|
|
|
ConnectedClients.Remove(client); |
|
|
|
DisconnectedClients.Add(client); |
|
|
|
|
|
|
|
|
|
|
|
ConnectedClients.ForEach(p => p.conn.Send(LoginProtocols.OtherClientDisconnected, new LoginProtocols.LoginMsg(client.Name, client.Color, client.characterAnimal))); |
|
|
|
PotentialClients.ForEach(p => p.Send(LoginProtocols.OtherClientDisconnected, new LoginProtocols.LoginMsg(client.Name, client.Color, client.characterAnimal))); |
|
|
|
Debug.Log("Disconnected: " + client.Name); |
|
|
|
OnClientsChange.Invoke(ConnectedClients); |
|
|
|
} |
|
|
@ -127,13 +148,21 @@ namespace Networking.Server |
|
|
|
newClient.Name = loginMsg.Name; |
|
|
|
newClient.conn = msg.conn; |
|
|
|
|
|
|
|
ConnectedClients.ForEach(p => p.conn.Send(LoginProtocols.OtherClientConnected, new LoginProtocols.LoginMsg(newClient.Name, newClient.Color, newClient.characterAnimal))); |
|
|
|
|
|
|
|
ConnectedClients.Add(newClient); |
|
|
|
PotentialClients.RemoveAll(p => p == newClient.conn); |
|
|
|
PotentialClients.ForEach(p => p.Send(LoginProtocols.OtherClientConnected, new LoginProtocols.LoginMsg(newClient.Name, newClient.Color, newClient.characterAnimal))); |
|
|
|
|
|
|
|
newClient.conn.Send(LoginProtocols.LoginSuccess, new LoginProtocols.LoginMsg(newClient.Name, newClient.Color, newClient.characterAnimal)); |
|
|
|
OnClientsChange.Invoke(ConnectedClients); |
|
|
|
newClient.SendInventory(); |
|
|
|
newClient.SendScore(); |
|
|
|
newClient.ChangeScene("WaitScene"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
#region IEnumerable Implementation
|
|
|
|