Пример #1
0
        private void ProcessLogOn(object sender, LogOnEventArgs e)
        {
            var id = e.UserId;

            AddRecord(id, new UserRecord(e.Client, id));
            MessageHandler.SendMessage(QueryRecord(e.UserId).Client,
                                       new ServerProtocol.PacketHeader(ServerProtocol.MessageKind.Info, ErrorKind.Ok, e.SequenceNumber),
                                       new InfoPacket(new UserInfo {
                UserID = e.UserId
            }, GetOnlineUsers()));
            _rwLock.EnterReadLock();
            foreach (var user in _userRecords)
            {
                var record = user.Value;
                if (user.Key != e.UserId)
                {
                    Console.WriteLine($"Told {user.Key}  {e.UserId} online!");
                    MessageHandler.SendMessage(record.Client, new ServerProtocol.PacketHeader(ServerProtocol.MessageKind.NewBodyOnline, ErrorKind.Ok, 0),
                                               new NewBodyOnlinePacket(e.UserId, new UserInfo {
                        UserID = e.UserId
                    }));
                }
            }
            _rwLock.ExitReadLock();
        }
Пример #2
0
        private void ProcessLogOn(object sender, LogOnEventArgs e)
        {
            var id = e.UserId;
            AddRecord(id, new UserRecord(e.Client, id));
            MessageHandler.SendMessage(QueryRecord(e.UserId).Client,
                new ServerProtocol.PacketHeader(ServerProtocol.MessageKind.Info, ErrorKind.Ok, e.SequenceNumber),
            new InfoPacket(new UserInfo { UserID = e.UserId }, GetOnlineUsers()));
            _rwLock.EnterReadLock();
            foreach(var user in _userRecords)
            {
                var record = user.Value;
                if (user.Key != e.UserId)
                {
                    Console.WriteLine($"Told {user.Key}  {e.UserId} online!");
                    MessageHandler.SendMessage(record.Client, new ServerProtocol.PacketHeader(ServerProtocol.MessageKind.NewBodyOnline, ErrorKind.Ok, 0),
                       new NewBodyOnlinePacket(e.UserId, new UserInfo { UserID = e.UserId }));
                }

            }
            _rwLock.ExitReadLock();
        }