using System.Collections; using System.Collections.Generic; using System.Linq; using UnityEngine; using UnityEngine.Networking; namespace Networking.Server { [CreateAssetMenu(menuName = "Major Project/Networking/ClientList", order = 150)] public class ConnectionHandler : ScriptableObject { #region Public Variables /// /// All Clients which are Currently Connected; /// public List ConnectedClients; /// /// Clients which connected at one point but no longer are /// Usefull if a client needs to reconnect /// public List DisconnectedClients; #endregion Public Variables #region Private Variables public NetworkServerSimple server; #endregion Private Variables /// /// Clears the lists /// public void Reset() { ConnectedClients = new List(); DisconnectedClients = new List(); } /// /// Resets the client list + registers handlers with the server /// /// Server to register handlers with public void SetUp(ServerObject serverObject) { this.server = serverObject.server; Reset(); server.RegisterHandler(MsgType.Connect, OnClientConnect); } public void OnClientConnect(NetworkMessage msg) { if (ConnectedClients.Any(p => p.ID == msg.channelId)) { Debug.LogError("Client[" + msg.channelId + "] already connected"); return; } msg.conn.Send(LoginProtocols.RequestLoginDetails,new LoginProtocols.EmptyMsg()); } } [System.Serializable] public class ClientData { /// /// Client Name /// public string Name; /// /// Color which represents player, picked by player /// public Color Color; /// /// Clients Current Score /// public int Score; /// /// Network connection ID /// public int ID; /// /// Connection to Client /// public NetworkConnection conn; } }