Beispiel #1
0
 public void RegisterUser(string name)
 {
     if (UsersDictionary.ContainsKey(Context.ConnectionId))
     {
         return;
     }
     UsersDictionary.Add(Context.ConnectionId, name);
     Clients.All.updateUserNamesList(UsersDictionary.Select(p =>
                                                            new { value = p.Value }).ToList());
 }
Beispiel #2
0
 public async Task PopulateUsers()
 {
     foreach (String nextLine in DatabaseUtilities.ReadDB(@"Users"))
     {
         String[] singleUser = nextLine.Split('#');
         UsersDictionary.Add(int.Parse(singleUser[0]), singleUser[1] + " " + singleUser[2]);
         UserObjDictionary.Add(int.Parse(singleUser[0]), (new AllUsersObj {
             Name = singleUser[1], Surname = singleUser[2], Password = singleUser[3], AccessGroup = int.Parse(singleUser[4])
         }));
         UserID = int.Parse(singleUser[0]);
     }
 }
        // TODO: Add user list
        public static void OnUserConnect(IAsyncResult ar)
        {
            SausageConnection user;

            try
            {
                user = new SausageConnection(MainSocket.EndAccept(ar));
            }
            catch (SocketException ex)
            {
                Close();
                return;
            }
            catch (ObjectDisposedException ex)
            {
                return;
            }
            if (!Blacklisted.Any(x => x == user.Ip.Address))
            {
                UiCtx.Send(x => ConnectedUsers.Add(user));
                UiCtx.Send(x => Vm.ConnectedUsers = SortUsersList());
                UiCtx.Send(x => Vm.Messages.Add(new ServerMessage($"{user} has connected")));
                UiCtx.Send(x => Mw.AddTextToDebugBox($"User connected on {user.Ip}\n"));
                // global packet for all the users to know the user has joined
                PacketFormat GlobalPacket = new PacketFormat(PacketOption.UserConnected)
                {
                    Guid    = user.UserInfo.Guid,
                    NewName = user.UserInfo.Name
                };
                // local packet for the user (who joined) to get his GUID
                PacketFormat LocalPacket = new PacketFormat(PacketOption.GetGuid)
                {
                    Guid      = user.UserInfo.Guid,
                    UsersList = UsersDictionary.ToArray()
                };
                UsersDictionary.Add(user.UserInfo);
                user.SendAsync(LocalPacket);
                Log(GlobalPacket, user);
            }
            else
            {
                // doesn't log if the user is blacklisted
                user.Disconnect();
            }
            MainSocket.BeginAccept(OnUserConnect, null);
        }