/// <summary> /// Analyzes the login package to see if it is a valid login. If it is, then login the client. /// </summary> private void ProcessLoginPackage(ServerSideClient client, Package package) { // The client does not have its name yet. Use the name provided by its login attempt. LoginContent loginContent = LoginContent.Deserialize(package.Content); var reason = GetRefuseReason(loginContent.ClientName); // Here I am not rejecting the user and we will send the package out for // further processing. if (reason == ConnectionRefusedReason.None) { client.Name = loginContent.ClientName; client.Status = ClientStatus.LoggedIn; BroadcastPackageAsync(package); client.TimeStampLogin(); clientNames.Add(client.Name); OnClientLoggedIn(client.Name); } else { var args = new ConnectionRefusedContent(reason, loginContent.ClientName); // Here I am rejecting the user, we will send the reject message to the appropriate client var pkgResp = new Package(BaseCommand.ConnectionRefused, args.Serialize()); client.SendPackageAsync(pkgResp); clientNames.Remove(client.Name); clients.Remove(client); client.Socket.Shutdown(SocketShutdown.Both); client.Dispose(); OnConnectionRefused(args); } }
/// <summary> /// Sends the names of all of the clients which are logged in to a specified client. /// </summary> /// <param name="client">The client to send the names to.</param> private void SendClientNames(ServerSideClient client) { var contents = new ClientNamesContent(clients.Select(c => c.Name).ToArray()); client.SendPackageAsync((int)BaseCommand.ClientNames, contents); }