I’m a long time XNA Game Studio developer that has recently converted to MonoGame so I can continue developing Indie games on the Xbox One
But I am absolutely stuck. I have no idea how to add the SDK to MonoGame, let alone access its functionality
For example: I am trying to implement a leaderboard
But the documentation is in C++. I have tried Google but I cannot find any documentation on C#. I don’t even know what the using command is to access the SDK
Your help will me much appreciated. I feel like I am at a dead end
Yes, I have signed up for the Creators Program. I have created an app in the developers portal, enabled it for Xbox Live services, have a leaderboard set up in the portal, and have a sandbox ready to go
I am using Visual Studio 2017. I have MonoGame installed, and a working game. I have installed this on an Xbox One and have it working perfectly in developers mode
So it appears something as follows:
1/ Use NuGet to add the SDK to the project
2/ Add the following statement: using Microsoft.Xbox.Services;
3/ Then write code as follows: // Create Xbox Live user Microsoft.Xbox.Services.System.XboxLiveUser user = new Microsoft.Xbox.Services.System.XboxLiveUser();
I am going to read through the link and adapt it for c#. I will then write a proper guide and post it here
Thanks for a nudge in the right direction. If anybody has any documentation for c# / monogame / visual studio please post here so I am not reinventing the wheel
Ok this is really really frustrating and there just doesn’t seem to be any documentation on this whatsoever
This is what I have tried so far
using Microsoft.Xbox.Services.System;
…
public class Game1 : Microsoft.Xna.Framework.Game {
… XboxLiveUser user;
…
protected override void Initialize() {
… user = new XboxLiveUser();
I get a system stack overflow error message on the line user = new XboxLiveUser(); and the game doesn’t progress any further
When Microsoft announced that Xbox Live supported monogame I thought it was a big announcement. Surely I cant be the only one trying this or who has tried this
Can we please get some documentation on this on the website
Thanks for the link however it takes me to the step I am up to but not past it
I have a fully working monogame on my XboxOne. I can play it perfectly with a controller, it saves to the storage, and works as one would expect. I haven’t had any issues
However the final step is that an XboxOne game must have a signed in user and the gamer tag displayed. This is done by accessing the Xbox SDK. Unfortunately this is the part that I cant find documented anywhere on the web
It will be something like:
Step 1/ Import SDK
Step 2/ Initialise the user
Step 3/ Get the signed in user asynchronously
Step 4/ Handle sign outs, offline etc…
However I do not know enough about what is going on to translate it. I also don’t know when to initialise the user and when to start the functions
I would very much appreciate if somebody who has a monogame in the Xbox store to post the code they used to handle the user sign in and obtain the user profile
So this is a pretty low effort response and I apologize about that, but here is what my file for handling Xbox Live sign in looks like.
using System;
using Engine;
using System.Diagnostics;
using Microsoft.Xbox.Services.System;
using Microsoft.Xbox.Services;
using Microsoft.Xbox.Services.Statistics.Manager;
using Microsoft.Xna.Framework;
namespace MonoGameTiles
{
public class XboxLiveObject : Entity
{
public XboxLiveUser CurrentUser { get; private set; }
public XboxLiveContext CurrentContext { get; private set; }
public StatisticManager StatsManager = null;
public string UserId
{
get
{
if (CurrentUser.IsSignedIn)
return CurrentUser.XboxUserId;
else
return null;
}
}
private readonly GameTimeSpan _timer_time_since_last_presence_post = new GameTimeSpan();
public XboxLivePresences CurrentPresence = XboxLivePresences.in_menus;
private XboxLivePresences _old_presence = XboxLivePresences.in_menus;
private bool _has_posted_initial_presence = false;
private bool _currently_attempting_sign_in = false;
public XboxLiveObject()
{
IsPersistent = true;
SignIn();
XboxLiveUser.SignOutCompleted += SignOutCompleted;
}
private void SignOutCompleted(object sender, SignOutCompletedEventArgs e)
{
if (StatsManager != null)
{
StatsManager.RequestFlushToService(e.User);
StatsManager.DoWork();
StatsManager.RemoveLocalUser(e.User);
StatsManager.DoWork();
StatsManager = null;
}
CurrentContext = null;
Action upon_returning_to_menu = delegate
{
UserData.ResetUserData();
SaveLoadSettings.Load();
};
Room_Main.ReturnToMainMenuAndShowMessage(new System.Collections.Generic.List<string>() { "User logged out of Xbox Live" }, 50, upon_returning_to_menu);
}
public async void SignIn(bool attempt_silent = true)
{
if (_currently_attempting_sign_in)
return;
_currently_attempting_sign_in = true;
CurrentUser = new XboxLiveUser();
if (!CurrentUser.IsSignedIn)
{
var coreDispatcher = Windows.ApplicationModel.Core.CoreApplication.GetCurrentView().CoreWindow.Dispatcher;
if (attempt_silent)
{
try
{
await CurrentUser.SignInSilentlyAsync(coreDispatcher);
}
catch
{
Debug.WriteLine("SignInSilentlyAsync Threw Exception");
}
}
if (!CurrentUser.IsSignedIn)
{
Debug.WriteLine("Silent Sign-In failed, requesting sign in");
try
{
await CurrentUser.SignInAsync(coreDispatcher);
}
catch
{
Debug.WriteLine("SingInAsync Threw Exception");
}
}
}
if (CurrentUser.IsSignedIn)
{
CurrentContext = new XboxLiveContext(CurrentUser);
StatsManager = StatisticManager.SingletonInstance;
StatsManager.AddLocalUser(CurrentUser);
StatsManager.DoWork();
UserData.ResetUserData();
SaveLoadSettings.Load();
if (!_has_posted_initial_presence)
{
SetPresenceAsync(XboxLivePresences.in_menus);
_has_posted_initial_presence = true;
}
AchievementSystem.CheckEarnedFavoritesCount();
}
WriteInfo();
_currently_attempting_sign_in = false;
}
private async void SetPresenceAsync(XboxLivePresences presence)
{
if (CurrentContext == null)
return;
try
{
string presence_string = presence.ToString();
Microsoft.Xbox.Services.Presence.PresenceData presenceData = new Microsoft.Xbox.Services.Presence.PresenceData(CurrentContext.AppConfig.ServiceConfigurationId, presence_string);
await CurrentContext.PresenceService.SetPresenceAsync(true, presenceData);
Debug.WriteLine("Posted Presence: " + presence.ToString());
}
catch
{
Debug.WriteLine("Error Setting Presence");
}
}
public bool HasPrivilege(GamingPrivilege privilege)
{
string privilege_string = ((int)privilege).ToString();
var privileges = CurrentUser.Privileges.Split(' ');
foreach (var item in privileges)
{
if (privilege_string == item.Trim())
return true;
}
return false;
}
public void RunExitCleanup()
{
if (CurrentUser.IsSignedIn)
{
StatsManager.RequestFlushToService(CurrentUser);
StatsManager.DoWork();
StatsManager.RemoveLocalUser(CurrentUser);
StatsManager.DoWork();
}
CurrentContext = null;
CurrentUser = null;
}
public override void onUpdate(GameTime gameTime)
{
base.onUpdate(gameTime);
if (_old_presence != CurrentPresence && _timer_time_since_last_presence_post.TotalMilliseconds > 10000)
{
_timer_time_since_last_presence_post.Mark();
_old_presence = CurrentPresence;
SetPresenceAsync(CurrentPresence);
}
}
public void WriteInfo()
{
Debug.WriteLine("############ Xbox Live Info ############");
Debug.WriteLine(CurrentUser.XboxUserId);
Debug.WriteLine(CurrentUser.WebAccountId);
Debug.WriteLine("############ Xbox Live Info ############");
}
}
}
Note that this is a singleton entity (using my own entity system), but that’s really just so it can have it’s own update loop where I set the rich presence string if needed.
There’s a lot of stuff here that’s specific to my game, but I just figured I could give you some sort of idea of how a person might set it up. Also feel free to learn from my mistakes , Microsoft is very liberal with the way it throws exceptions which was really odd for me. Things such as failed sign in attempts or failed rich presence posts will throw exceptions (even if it failed for a standard reason).
Let me know if you need an example of achievements, I’ve got that working too. In fact, I’ve got everything working on the Xbox right now except for the fact that the game closes if a person signs out of their account… which was actually the reason I was browsing the forums and stumbled on your question in the first place lol.
Hey there, so I’ve got a couple questions. You mentioned XDP, XDP is not where you set up your game if you are using UWP (which is what my example is for). I actually set up my game in XDP the first time out if confusion and learned the hard way that for UWP games you have to set it up in the Windows Dev Center. Though in my defense they didn’t even have an option for Xbox games in the Dev Center at the time .
Secondly, how often are you attempting to set the rich presence string? There’s a reason my code checks to see how long it’s been since the last set. If I remember right, setting it more than 3 times within 15 seconds will get you throttled by the server, if you get throttled the game will throw a failure to post exception. Personally I don’t agree with the idea of throwing an exception for something not working server side, but Microsoft seems to love exceptions.
Thanks for your reply!!!
Firstly, I did set up my game in the Windows Dev Center , but I created Sandbox and made service configurations in XDP. Then I associated UDC product with the XDP title. Since the rich presence string is a part of service configurations, I set that in XDP.
Secondly, I did set the rich presence strings very frequently… However , when I first set that , this exception has appeared.
I want to know if I use this API incorrectly? Or if I need to make other configurations and get data from the server ?
I’m not sure of your exact problem yet, but I would start with setting up your service configuration in Windows Dev Center, if your game is a UWP game you won’t use XDP at all. Again, I was confused on this too. Also, when you set up your game in Windows Dev Center you have to create it as a sandbox project if I remember right (I just know I had to delete and recreate mine).
I would reach out to IDDS, they are the ones in charge of making sure you’re set up properly in Dev Center. Once that’s done you can see where you stand.
Also, in your code when AddUser(XboxLiveUser user) gets called is that user already logged in? It’s apparently VERY IMPORTANT (for what reason I don’t know) that when you create the XboxLiveContext the user is already signed in. If not, parts of Xbox Live will work and other parts won’t, I struggled with this for days before figuring it out. https://forums.xboxlive.com/questions/65290/rich-presence-setpresenceasync-throws-bad-request.html
It’s something good to know up front, basically you have to wrap EVERY call to Xbox Live in a try/catch block. I’m really not used to programming in that mindset whatsoever, in practice I rarely use try/catch.
I have set the Rich Presence Strings successfully ! The real reason why my game threw that exception is I did not enable Internet (Client) capability in VS.(As this picture shows)
Since I could set up achievements successfully without this configuration , I ignored that.
I was inspired by an answer in the Xbox Developer Forum and I’m so grateful for your help !!!
Does anybody knows if (and how) a second player can be logged in into the second controller?
In PS4 when you connect a second controller you’re asked to log in the new controller with another PS4 account (or guest), so when playing N-player games it’s great because it can display your gamertag.
I’m porting a 2 player game and I’d like to add this feature, but I’m unable to find out how.
(I don’t know if it’s even possible as I’ve just had the X1 for a month and haven’t played a 2p game with it yet)