Пример #1
0
        //Get
        public bool TryGetConnection(string id, out NetworkClientObject cl)
        {
            cl = null;
            if (_clients.Exists(x => x.uid == id))
            {
                cl = _clients.Find(x => x.uid == id);

                return(true);
            }

            return(false);
        }
Пример #2
0
        public void SetConnectionValues(NetworkClientObject cl)
        {
            if (_clients.Exists(x => x.uid == cl.uid))
            {
                var i = _clients.FindIndex(x => x.uid == cl.uid);
                _clients[i] = cl;

                if (OnUpdateClient != null)
                {
                    OnUpdateClient(cl);
                }

                return;
            }

            Debug.LogError("Ops, some clients may be duplicated");
            _clients.Add(cl);
        }
Пример #3
0
 public void NetworkSendConnectionToClients(NetworkClientObject client)
 {
     _serverController.SendMessageToAll("NetworkReceiveConnectionUpdate", JsonConvert.SerializeObject(client));
 }
Пример #4
0
        //Set
        public void AddConnection(NetworkClientObject cl)
        {
#if HAS_SERVER
            if (_isServer)
            {
                if (_clients.Exists(x => x.uid == cl.uid))
                {
                    var i = _clients.FindIndex(x => x.uid == cl.uid);
                    _clients[i] = cl;

                    if (OnUpdateClient != null)
                    {
                        OnUpdateClient(cl);
                    }
                }
                else
                {
                    _clients.Add(cl);

                    if (OnAddClient != null)
                    {
                        OnAddClient(cl);
                    }
                }

                try
                {
                    _serverController.SendMessageByClient(cl, "NetworkonConnectFeedBack", "");
                    base.AddNewValue();

                    UpdateClientsData();

                    DebugLog("Added client " + cl.uid + " with connectionId " + cl.connectionId);
                }
                catch (Exception e)
                {
                    Debug.LogError(e.ToString());

                    _clients.RemoveAt(_clients.Count - 1);
                }
            }
            else
            {
                _idsData.NewId(cl.uid, _idsData.actualSession, false);

                if (_clients.Exists(x => x.uid == cl.uid))
                {
                    var i = _clients.FindIndex(x => x.uid == cl.uid);
                    _clients[i] = cl;
                    if (OnUpdateClient != null)
                    {
                        OnUpdateClient(cl);
                    }
                }
                else
                {
                    _clients.Add(cl);
                    if (OnAddClient != null)
                    {
                        OnAddClient(cl);
                    }
                }
            }
#endif
        }