|
|
- 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
- /// <summary>
- /// All Clients which are Currently Connected;
- /// </summary>
- public List<ClientData> ConnectedClients;
-
-
- /// <summary>
- /// Clients which connected at one point but no longer are
- /// Usefull if a client needs to reconnect
- /// </summary>
- public List<ClientData> DisconnectedClients;
- #endregion Public Variables
-
- #region Private Variables
- public NetworkServerSimple server;
- #endregion Private Variables
-
-
-
-
- /// <summary>
- /// Clears the lists
- /// </summary>
- public void Reset()
- {
- ConnectedClients = new List<ClientData>();
- DisconnectedClients = new List<ClientData>();
- }
-
- /// <summary>
- /// Resets the client list + registers handlers with the server
- /// </summary>
- /// <param name="serverObject">Server to register handlers with</param>
- 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
- {
- /// <summary>
- /// Client Name
- /// </summary>
- public string Name;
-
- /// <summary>
- /// Color which represents player, picked by player
- /// </summary>
- public Color Color;
-
- /// <summary>
- /// Clients Current Score
- /// </summary>
- public int Score;
-
- /// <summary>
- /// Network connection ID
- /// </summary>
- public int ID;
-
- /// <summary>
- /// Connection to Client
- /// </summary>
- public NetworkConnection conn;
-
-
- }
- }
|