How to identify a mobile User in Unity without an explicit registration - c#

First of all, I have been searching forums for about a year for a viable solution. What I am looking for is a way to identify a mobile User by an ID that is NOT linked to the device.
So no SystemInfo.deviceUniqueIdentifier
My thoughts go out towards identifying Users using the Google Account of the User (Android) or the Apple account (iOS).
What I have tried so far is connecting the application through the GooglePlayGames API. It is successfully connected and works fine. It logs in automatically when I start the application and I retrieve and store the googleId in my database.
The drawback here however is that the app is now dependent on GooglePlayGames, which is something I dislike. I don't like explicit dependencies on other apps. And I also need to find a suitable equivalent for iOS.
I have yet to implement the Unity IAP to enable in app purchasing. I could not find any info on how transactions are linked to Users on android/ iOS. Is there a way to retrieve/store any User related Id during transactions?
It seems to me that when working with in app purchasing, that you need to have some way to reimburse/reactivate purchases made by users when they switch phones for example.
Best case scenario would be an easy way to store an Id without depending on Unity IAP, so that Free To Play Users can also easily recover their account.

You can use Mac Address. This is unique for every device.
string GetMacAddress()
{
string reesult = "";
foreach (NetworkInterface ninf in NetworkInterface.GetAllNetworkInterfaces())
{
if (ninf.NetworkInterfaceType != NetworkInterfaceType.Ethernet) continue;
if (ninf.OperationalStatus == OperationalStatus.Up)
{
reesult += ninf.GetPhysicalAddress().ToString();
break;
}
}
return reesult;
}
Now, if the device is jail-broken or tampered with, the Mac Address can be spoofed or temporary changed.
SystemInfo.deviceUniqueIdentifier is not 100% reliable, especially not
on IOS. Furthermore I will lose the connection to the User if he
switches device.
You can use Unity's SocialPlatforms API to check if the user is logged in then obtain the user id. That you can use to determine the user on any device.
Social.localUser.Authenticate(success =>
{
if (success)
{
Debug.Log("Authentication successful");
string userInfo = Social.localUser.id;
Debug.Log(userInfo);
}
else
Debug.Log("Authentication failed");
});
If you really need more control over your users, you should implement your own token-based authentication such as oauth2. It's not really hard to make one yourself if you have background of PHP and MySQL.

For iOS you need to implement the Apple Game Center.
The docs make it look pretty easy, looks like a single function call that will prompt the user to sign in if they're not already signed in.
Should work the same as the Google Play Store API after that.

Related

Unity Play Games can't authenticate

I have a issue with play games services and unity.
I've done everything by the documentation. I'm a tester, testing is allowed and I've changed the sha1 in api console to the one used by the app. I'm using code from the docs and examples so here is a brief:
PlayGamesClientConfiguration conf = new PlayGamesClientConfiguration.Builder().Build();
PlayGamesPlatform.InitializeInstance(conf);
PlayGamesPlatform.DebugLogEnabled = true;
PlayGamesPlatform.Activate();
Debug.Log("Authenticating...");
Social.localUser.Authenticate((bool success) =>
{
if (success)
{
Debug.Log("Welcome " + Social.localUser.userName);
}
else
{
Debug.Log("Authentication failed.");
}
});
When I build the app in development mode the Play Games popup appears, starts loading and disappears and gives me a Authentication failed message. But when I build the app without the development mode nothing happens and I get the authentication failed message instantly. And yes I'm the correct sha1 key.
Please help me
I did a number of things and finally got it to work. I cannot be sure if they all contributed to solving this issue so here I will list what I did, from greatest to least of my guess of their relevance:
Match the SHA-1 certificates. If you are using an app downloaded from Play Store use the "app signing certificate", else use the upload certificate. These are found in the Play Console under YourApp/Release Management/App Signing. As a note, if you are building from Unity directly to your device, you should make sure that you are building with the same key used to upload to Google Play. More info here
If you are using a custom config and are requesting things such .RequestServerAuthCode(false), you must create an additional Web App. Go to your console project, and under create credentials choose OAuth client ID, and then select Web App.
If using internal testing, make sure to authorize accounts in the Play Console under Game Services/Your App/Testing.
Try disabling Anti-Piracy in the Play Console under Game Services/Your App/Linked Apps/Your App. Only do this if you are testing app outside Google Play. I think if you are logging in using verified test accounts this doesn't matter.
Edit: Publishing Game Services is required even for testing.. at least that seemed to be the case for me to get it working.
Try clearing the cache of your App on your device, I ran into this problem again and this solved it for me.
I finally think I have got it fixed for good.. after nearly a month later. :o Hope this helps.
Google Services can be published/unpublished separately from your app.
Check if they are correctly published doing the following:
Google Play Console
Game services
Select your game
Publishing
Check if Game Services are published.

ShareLinkTask, check if a user has connected to a network

I would like to user the ShareLinkTask in my Windows Phone app to enable users to share a link.
When I test the following code on the emulator:
// share to social networks
ShareLinkTask shareLinkTask = new ShareLinkTask();
shareLinkTask.Title = vine.description;
shareLinkTask.LinkUri = new Uri("link");
shareLinkTask.Message = "I want to share this link";
shareLinkTask.Show();
The emulator goes to a black screen and immediately backs out. I guess this is due to the fact that I haven't connected to a network on the emulator.
So my question is, how do I detect if a user has no connected networks so that I can show an appropriate message?
Do you mean connected to any accounts that could be used for sharing? You could use the Account class to determine if there are any user accounts set up before triggering the task.
Note that doing this requires the ID_CAP_CONTACTS and ID_CAP_APPOINTMENTS which may look weird to your users and seeing that this is an extreme edge case (there are very few phones that do not have any account on them) it may not be worth the extra code / capability requests.
If you do want to iterate accounts you can use:
(new Contacts()).Accounts
and if there is nothing there, there are no accounts.
The behaviour you are seeing on the emulator is because you are not signed in to the phone with a Microsoft account. As such there are no social networks associated that can be used to share the link.

Bluetooth and C# PC -> Cellphone connection without paring

I'm trying to write simple app, which sends short text message to cellphones in bluetooth adapter range.
My first try is sending files: I can send file from PC to cellphone, but i must enter PIN on cellphone, and on PC.
I would rather to send text messages (something like push message) - is it possible to send it without paring devices?
If isn't possible to send push messages, maybe I can send simple file without requesting PIN ?
I use 32feet library.
Sample code (used to send files to selected device)
static int BTSendFile(string adres, string FileName)
{
Uri uri = new Uri("obex://" + adres + '/' + Path.GetFileName(FileName));
ObexWebRequest req = new ObexWebRequest(uri);
req.ReadFile(FileName);
ObexWebResponse rsp = (ObexWebResponse)req.GetResponse();
return (int)rsp.StatusCode;
}
A quick answer would be; NO, you will ALWAYS need some kind of pairing.
But if you take a look at the different kinds of pairing out there, you would see that BT 2.1 supports Secure Simple Pairing (SSP) with the Just Works-mode. This allows you to pair devices (almost) without any user interaction. From Wikipedia:
Just works: As implied by the name, this method just works. No user interaction is required; however, a device may prompt the user to confirm the pairing process. This method is typically used by headsets with very limited IO capabilities, and is more secure than the fixed PIN mechanism which is typically used for legacy pairing by this set of limited devices. This method provides no man in the middle protection.
However, since "This method is typically used by headsets with very limited IO capabilities", it would probably not apply to the cellphones you are talking about, but I thought you should know :)
According to the offical Bluetooth Message Access Profile, i.e. the specific Bluetooth profile that deals with accessing SMS/MMS systems on phones via a remote device:
'The MCE device shall use the services of the MSE device only after successfully creating a secure connection. This includes exchanging of security initialization messages, creation of link keys, and enabling encryption'
From: https://developer.bluetooth.org/TechnologyOverview/Pages/MAP.aspx
There is also a link to the full spec there if you are interested.
This certtainly suggests that secure pairing is required, which I'd assume to involve the passkey. My experience is that once a device has been paired a connection can be made without repeating the pairing as long as that pairing is remembered by the devices (i.e. I've paired a device once and not had to do it again). As to simpler, non-keyed pairing mentioned by khellang above, I've not seen anything about this - if it is purely for devices like headsets then the security requirements may be lower due to their not likely wanting write access to a device?

ASP.NET - How to find out if the user is a mobile user?

I am trying to find out if a user viewing my site is a mobile user. I have used "HttpContext.Current.Request.Browser.IsMobileDevice " and found it pretty useless as it didn't not pick up on my usage when viewing the site on my phone.
Is there another way to find out if the user is a mobile user that works better?
I have looked at user agent and that just looks messy!
I should point out that this has nothing to do with CSS, I want to log if the user is a mobile user in a database table.
And yes, I know google analytics can do this already but unfortunately its not my decision!
Thanks
Check out
51degrees
It’s provided as a .NET open source class library that detects mobile
devices and browsers, enhancing the information available to .NET
programmers. Using 51Degrees.mobi Device Data, accurate screen sizes,
input methods, plus manufacturer and model information are all
available. Mobile handsets can optionally be redirected to content
designed for mobile devices. Smart phones, tablets and feature phones
are all supported.
As pointed out in the comments.
The detection and redirection part of the product offering is free.
The free trial is for their mobile optimzation products
See my comment on your question for a more thorough answer, but for a simple check to see if the user is a mobile user I would personally suggest
http://detectmobilebrowsers.com/
Try to test with this code....
string sUA = Request.UserAgent.Trim().ToLower();
uaString.InnerText = Request.UserAgent;
if (sUA.Contains("ipod") || sUA.Contains("iphone"))
isMobile = true;
if (sUA.Contains("android"))
isMobile = true;
if (sUA.Contains("opera mobi"))
isMobile = true;
if (sUA.Contains("windows phone os") && sUA.Contains("iemobile"))
isMobile = true;
if (sUA.Contains("fennec"))
isMobile = true;

How do I get a list of local Windows users who are logged in?

I'm trying to write a faster user switching app for Windows. Win+L and selecting users is very cumbersome. If I start Task Manager as administrator, it shows active users and I can select one and "Connect" (if I enter their password).
How do I get the list of all users (or all active users)?
I'm using C# (Visual Studio Express).
If you'd rather not deal with the P/Invokes, you can use Cassia, which wraps the ugly for you:
using Cassia;
foreach (ITerminalServicesSession session in new TerminalServicesManager().GetSessions())
{
if (!string.IsNullOrEmpty(session.UserName))
{
Console.WriteLine("Session {0} (User {1})", session.SessionId, session.UserName);
}
}
I'd try WTSEnumerateSessions to get all available sessions.
You can also use NetWkstaUserEnum to see all users currently logged in; it's not really necessarily better, but it's another option. It has one advantage that it will work on older systems which don't support terminal services, but that's probably not an issue if you're using C#. :)

Categories