Esempio n. 1
0
        public int Connect(string name)
        {
            ServerUser user = new ServerUser()
            {
                ID               = nextId,
                Name             = name,
                operationContext = OperationContext.Current
            };

            nextId++;
            SendMessage(": " + user.Name + " подключился к чату!", 0);
            users.Add(user);
            return(user.ID);
        }
Esempio n. 2
0
        public int Connect(string name)
        {
            ServerUser serverUser = new ServerUser()
            {
                ID               = id,
                Name             = name,
                operationContext = OperationContext.Current
            };

            id++;

            Send_Message(": " + serverUser.Name + " Подключился к чату ", 0);
            users.Add(serverUser);

            return(serverUser.ID);
        }
Esempio n. 3
0
        public int Connect(string name)
        {
            if (name == "Anonimus")
            {
                name += "#" + (new Random()).Next(1, 256);
            }
            var cur_name_user = _users.FirstOrDefault(i => i.Name == name);
            var user          = (ServerUser)null;

            if (cur_name_user == null)
            {
                user = new ServerUser()
                {
                    ID               = _nextId++,
                    Name             = name,
                    OperationContext = OperationContext.Current,
                    Connected        = true
                };
                _users.Add(user);
            }
            else
            {
                if (cur_name_user.Connected)
                {
                    PrintLog($"[WARN] reject connection for {name}. Connection already exist.");
                    return(-1);
                }
                cur_name_user.Connected        = true;
                cur_name_user.OperationContext = OperationContext.Current;
                user = cur_name_user;
            }
            (new Thread(() => //иначе превышает время ожидания
            {
                Thread.Sleep(200);
                SendMessage($"{name} join the chat.");
                PrintLog($"[INFO] {name} join the chat.");
            })).Start();
            return(user.ID);
        }