Ejemplo n.º 1
0
        public void AgentConnect(string name, string pass)
        {
            if (_agents == null)
                _agents = new ConcurrentDictionary<string, Agent>();

            if (_chatSessions == null)
                _chatSessions = new ConcurrentDictionary<string, string>();

            string hashPass = ToHash(pass);

            var config = GetConfig();
            if (config == null || config.Length < 2)
            {
                Clients.Caller.loginResult(false, "config", "");
            }
            else if ((config[0] == hashPass) || (config[1] == hashPass))
            {
                var agent = new Agent
                {
                    Id = Context.ConnectionId,
                    Name = name,
                    IsOnline = true
                };

                // if the agent is already signed-in
                if(_agents.Any(x => x.Key == name))
                {
                    agent = _agents[name];

                    Clients.Caller.loginResult(true, agent.Id, agent.Name);

                    Clients.All.onlineStatus(_agents.Count(x => x.Value.IsOnline) > 0);
                }
                else if (_agents.TryAdd(name, agent))
                {

                    Clients.Caller.loginResult(true, agent.Id, agent.Name);

                    Clients.All.onlineStatus(_agents.Count(x => x.Value.IsOnline) > 0);
                }
                else
                {
                    Clients.Caller.loginResult(false, "error", "");
                }
            }
            else
                Clients.Caller.loginResult(false, "pass", "");
        }
Ejemplo n.º 2
0
        public void AgentConnect(string name, string pass)
        {
            if (ChatSessions == null)
                ChatSessions = new ConcurrentDictionary<string, string>();

            string hashPass = ToHash(pass);

            var config = GetConfig();
            if (config == null || config.Length < 2)
            {
                Clients.Caller.loginResult(false, "config", "");
            }
            else if ((config[0] == hashPass) || (config[1] == hashPass))
            {
                var agent = new Agent()
                {
                    Id = Context.ConnectionId,
                    Name = name,
                    IsOnline = true
                };

                Agents.Add(agent);

                Clients.Caller.loginResult(true, agent.Id, agent.Name);

                Clients.All.onlineStatus(Agents.Count(x => x.IsOnline) > 0);
            }
            else
                Clients.Caller.loginResult(false, "pass", "");
        }