Steamworks checking if a user is logged in - c++

So the code that I've been using to get a user's Steam ID is:
CSteamID uid = SteamUser()->GetSteamID();
uint64 pid = uid.ConvertToUint64();
std::ostringstream sin;
sin << pid;
std::string s = sin.str();
return s.c_str();
This works just fine, but when a user is not logged into Steam, this crashes.
Access violation - code c0000005 (first/second chance not available)
Does Steam provide a function that I can use to check if the user is logged in before running code that depends on the user being logged in? Or is there some sort of try/catch block I can use here to make sure that this does not break and return false if the user is not logged in?

Thanks to #Lightning Racis in Orbit. A simple nullptr check fixed it.
if(SteamUser() == nullptr)
return false;

Related

resetting a session query variable

Looking for some pointers to resetting a session query Variable in coldfusion.
I'm currently implementing a lock account after 10 tries to a login form and I'm struggling to reset the number of failed tries once a user successfully logs in.
public function getLoginFails(required String Username, required String App){
getLoginFailsQuery = new Query();
getLoginFailsQuery.setDatasource(this.datasource)
getLoginFailsQuery.addParam(username)
getLoginFailsQuery.addParam(ip)
getLoginFailsQuery.addParam(application)
getLoginFailsQuery.setSQL(data inserted into db)
session.numFails = getloginFailsQuery.execute().getResult();
if(session.numFails.count < 10){
return session.numFails.count;
}else if(session.numFails.count == 10){
run a query to update accountLocked to = 1;
}
}
The above part works fine (I know some stuff is missing from the addparams() etc. It updates to 1 if 10 attempts and stores the tries in a session. session variable showing
My issues is resetting the variable when a successful login has occurred.
session.numFails.count = 0 doesn't work, am I missing something?

TgBot doesn't find owner ban power

I've started programming my own telegram-bot in cpp with tgbot-cpp and I've done the code for the ban. When the code checks if the user has the power to ban, it finds the needed power for admins, but not for the owner of the group. I looked in the documentation if there was a way to find the owner of the group, but I couldn't find it. This is the code section that checks the power.
/* Checks if the client has the permission to ban */
bool hasPermission = false;
for (unsigned i = 0; i < admins.size(); i++) {
if (admins[i]->user->id == message->from->id) {
printf("Admin username: %s\n", admins[i]->user->username.c_str());
printf("Can Restrict: %d\n", admins[i]->canRestrictMembers);
if (admins[i]->canRestrictMembers) {
hasPermission = true;
}
break;
}
}
if (!hasPermission) {
return;
}
When an admin uses the ban command, I get a Can Restrict: 1 in the console, but when the owner uses the command I get a Can Restrict: 0.
Is there a reason why the bot doesn't see the owner's power? Is there a way to look for the owner?
After looking better in the documentations, there is a value status for ChatMember that is setted to creator for the owner of the group. That seems to be the way for checking if someone is the owner or not, avoiding the permission issue

Unique identifier associated to the iCloud account

I would like to use a code to identify users, without asking them for their email address or other sensitive information, that would also possibly follow her when she changes device. Long ago I trustily implemented the following piece of code:
NSString *strApplicationUUID=nil;
+(NSString*) sharedUdid{
if (!strApplicationUUID){
NSString *appName=[[[NSBundle mainBundle] infoDictionary] objectForKey:(NSString*)kCFBundleNameKey];
strApplicationUUID = [SSKeychain passwordForService:appName account:#"incoding"];
if (strApplicationUUID == nil) {
strApplicationUUID=[[NSUserDefaults standardUserDefaults] objectForKey:#"udid"];
if (!strApplicationUUID) strApplicationUUID=[[[UIDevice currentDevice] identifierForVendor] UUIDString];
else strApplicationUUID = [[NSUUID UUID] UUIDString];
[SSKeychain setPassword:strApplicationUUID forService:appName account:#"incoding"];
}
}
return strApplicationUUID;
}
That I unfortunately found producing all but unique identifiers for each user. So I temporarily switched to using the token, notwithstanding its length and the fact it is linked to a single device. Is there some better solution?
I switched to using the CloudKit identifier.

C2664 cannot convert parameter 1 from from User *const to User in Qt C++

I am new to C++ and Qt, but I have been playing around with it for a couple of days and I need to come up with a basic prototype of my product by Friday, so there is not much time to convert my 7 years of PHP knowledge into C++ knowledge, as I am sure that it takes a lifetime to master C++. I am getting stuck from time to time in the last couple of days due to non-existing knowledge about the small bits and bytes. At this time I have even no idea what to look for on the Internet.
First of all, I am using Qt as my framework to do a simple GUI network client that can talk to my PHP application. I wanted to create a very simple WebAPI class in this application and have the class "webapi". The scenario is very simple, the user starts the application and the applications checks if the user is logged in or not. If not, then it opens up a login dialog. After entering the information (username / password) into the dialog the user object is filled and the method "authenticate" is called.
The authenticate method then calls the fUser method in the webapi class to make a request to the server holding some information to authenticate the user against the server's database.
In code it looks like this:
Savor.cpp:
user = new User();
while ( user->isLoggedIn() != true )
{
LoginDialog loginWindow;
loginWindow.setModal(true);
int result = loginWindow.exec();
if ( result == QDialog::Accepted )
{
user->authenticate(loginWindow.getUsername(), loginWindow.getPassword());
if ( !user->isLoggedIn() )
{
loginWindow.setUsername(loginWindow.getUsername());
loginWindow.exec();
}
}
else
{
exit(1);//exit with code 1
}
}
User.cpp:
void User::authenticate(QString username, QString password)
{
qDebug() << username;
qDebug() << password;
if ( username != "" && password != "")
{
webapi wapi;
loggedIn = wapi.fUser(this);
}
else
{
loggedIn = false;
}
}
webapi.cpp:
/**
Represents the fUser method on the server,
it wants to get a user object
the user will need to be authenticated with this
then all infos about user are transfered (RSA Keypair etc)
* #brief webapi::fUser
* #param username
* #param password
* #return User
*/
bool webapi::fUser(User baseUser)
{
return true;
}
Now you can clearly see that I am not doing anything at the moment in the webapi::fUser method. In fact, I am not even returning what I would like to return. Instead of a boolean I would like to return a User object, actually the same that I got in the first place through the parameter. However, i get a copy constructor error when I do that. (In my savor.h file I have declared a private attribute as a pointer => User *user;)
So the question is, what am I doing wrong when I call the fUser method? Why can I not simply pass the user object itself to the method ? I have not got around to fully understand const, and pointers and when to use what.
With Qt creator I actually use the MS Visual C++ compiler which throws the error as in the title:
C2664 'webapi::fUser' : cannot convert paramter 1 from 'User *const' to 'User'
I have read http://msdn.microsoft.com/en-us/library/s5b150wd(v=vs.71).aspx this page explaining when this happens, the only solutions is the conversion of the object itself.
If thats the case I might approach the entire problem in the wrong way.
I am looking forward to your tips and help on this matter.
Thank you very much.
webapi::fuser takes a User by value, but you are passing it a User* here:
wapi.fUser(this);
Either pass a User:
wapi.fUser(*this);
or change webapi to take a pointer to User.

Check if process user is an administrator c++

I want to get the process's user name and check if it is a local administrator . Or check directly if the current procees user is a local administrator
Get the current username with GetUserName(), then call NetUserGetInfo() with the server name (NULL for local) and username you just got. Pass it a USER_INFO_1 structure, and then access usri1_priv in the structure. If the value is USER_PRIV_ADMIN, then you'll know that the username is an admin.
Tested on Windows XP SP3, Windows 7 32 bit and 64 bit with admin user and non-admin user.
Code ported from equivalent C# and uses ATL windows security wrapper classes.
#include <atlbase.h>
#include <atlsecurity.h>
// The function returns true if the user who is running the
// application is a member of the Administrators group,
// which does not necessarily mean the process has admin privileges.
bool IsAdministrator(HRESULT &rHr)
{
bool bIsAdmin = false;
try
{
// Open the access token of the current process.
ATL::CAccessToken aToken;
if (!aToken.GetProcessToken(TOKEN_QUERY))
{
throw MAKE_SCODE(SEVERITY_ERROR, FACILITY_WIN32,
::GetLastError());
}
// Query for the access token's group information.
ATL::CTokenGroups groups;
if (!aToken.GetGroups(&groups))
{
throw MAKE_SCODE(SEVERITY_ERROR, FACILITY_WIN32,
::GetLastError());
}
// Iterate through the access token's groups
// looking for a match against the builtin admins group.
ATL::CSid::CSidArray groupSids;
ATL::CAtlArray<DWORD> groupAttribs;
groups.GetSidsAndAttributes(&groupSids, &groupAttribs);
for (UINT i = 0; !bIsAdmin && i < groupSids.GetCount(); ++i)
{
bIsAdmin = groupSids.GetAt(i) == ATL::Sids::Admins();
}
rHr = S_OK;
}
catch (HRESULT hr)
{
rHr = hr;
}
return bIsAdmin;
}
Presuming you're on a Window OS there's a shell function: IsUserAnAdmin
See MSDN article
This article does suggest rolling your own function though, use CheckTokenMembership. There is even a code example to help you along.