/// <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); } }
private void OnPackageReceivedCore(ServerSideClient client, Package e) { switch ((BaseCommand)e.Command) { case BaseCommand.ClientNames: SendClientNames(client); break; case BaseCommand.Logout: clients.Remove(client); BroadcastPackageAsync(e, client); clientNames.Remove(client.Name); client.Dispose(); OnClientLoggedOut(LogoutContent.Deserialize(e.Content)); break; case BaseCommand.Login: ProcessLoginPackage(client, e); break; case BaseCommand.Sync: Synchronize(client); break; } OnPackageReceived(client, e); }