Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
HumanGamer committed Mar 17, 2024
2 parents c3747f6 + 56fc40e commit 4336385
Show file tree
Hide file tree
Showing 14 changed files with 444 additions and 11 deletions.
1 change: 1 addition & 0 deletions engine/source/discord/DiscordGame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ void onReady(const DiscordUser* request)
DiscordGame::get()->setActive(true);
Con::printf("Starting RPC for user %s", request->username);
DiscordGame::get()->setUsername(request->username);
DiscordGame::get()->setUserId(request->userId);
}

void onError(int errorCode, const char* message)
Expand Down
9 changes: 9 additions & 0 deletions engine/source/discord/DiscordGame.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,14 @@ class DiscordGame
delete[] buf;
return ste;
}
StringTableEntry getUserId()
{
return StringTable->insert(mUserId.c_str());
}
void setUserId(const char* uid)
{
mUserId = uid;
}
void setActive(bool a)
{
mActive = a;
Expand Down Expand Up @@ -121,6 +129,7 @@ class DiscordGame
StringTableEntry mJoinSecret;
StringTableEntry mPartyId;
std::string mUsername;
std::string mUserId;
//const char* mIcon;
//const char* mIconText;
};
Expand Down
11 changes: 10 additions & 1 deletion engine/source/xblive/xbliveFunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,17 @@ ConsoleFunction(XBLiveGetUserName, const char*, 1, 1, "()")
//char* ret = Con::getReturnBuffer(1024);
//dSprintf(ret, 1024, "%s", "Alex");
//return ret;
if (Con::getBoolVariable("pref::Player::UsingCustomName"))
{
return Con::getVariable("pref::Player::Name");
}
if (DiscordGame::get()->isActive())
return DiscordGame::get()->getUsername(15);
{
const char* res = DiscordGame::get()->getUsername(15);
Con::setVariable("Player::DiscordUsername", res);
Con::executef(2, "getDiscordUsername", DiscordGame::get()->getUserId());
return res;
}

// Use platform username until we set up a login system.
return Platform::getUserName(15); // X360 only supported at max 15 characters.
Expand Down
2 changes: 2 additions & 0 deletions game/common/local/englishStrings.inf
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,7 @@ $Text::LobbyHostPrivateSlots = "Private Slots";
$Text::LobbyHostPublicSlots = "Public Slots";
$Text::LobbyHostInviteCode = "Invite Code";
$Text::LobbyHostInviteVisibility = "Invite Visibility";
$Text::LobbyHostStreamerMode = "Streamer";

; separators
$Text::Colon = ":";
Expand Down Expand Up @@ -344,6 +345,7 @@ $Text::MarbleSkin = "Marble Type";
$Text::UIStyle = "UI Style";
$Text::UIStyleOptions = "Mouse/Keyboard\tXbox 360";
$Text::InviteVisibilityOptions = "Hidden\tVisible";
$Text::StreamerModeOptions = "No\tYes";

;This string is no longer used $Text::MarbleOptions = "one\ttwo\tthree\tfour\tfive\tsix\tseven\teight\tnine\tten\televen\ttwelve\tthirteen\tfourteen\tfifteen\tsixteen\tseventeen\teighteen\tnineteen\ttwenty";
;$Text::MarbleColor = "Marble Color";
Expand Down
2 changes: 2 additions & 0 deletions game/marble/client/defaults.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@
$pref::OpenGL::maxHardwareLights = 3;
$pref::VisibleDistanceMod = 1.0;
$pref::Lobby::InviteVisibility = true;
$pref::Lobby::StreamerMode = false;
$pref::Player::UsingCustomName = false;

/// The sound provider to select at startup. Typically
/// this is DirectSound, OpenAL, or XACT. There is also
Expand Down
9 changes: 9 additions & 0 deletions game/marble/client/init.cs
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ function initClient()
exec("./ui/StartupErrorGui.gui");
exec("./ui/controlerDisplayGui.gui");
exec("./ui/joinGameGui.gui");
exec("./ui/enterNameGui.gui");

//exec("./ui/AboutGui.gui");
//exec("./ui/LevelScoresGui.gui");
Expand Down Expand Up @@ -178,6 +179,14 @@ function initClient()
exec("./scripts/xbControler.cs");

exec("./scripts/interiorTest.cs");

if (isPCBuild())
{
// one time setup for these vars
echo("Using custom name " @ $pref::Player::UsingCustomName);
$Player::Name = XBLiveGetUserName();
$Player::XBLiveId = XBLiveGetUserId();
}

if (isObject(MusicPlayer))
MusicPlayer.activate();
Expand Down
18 changes: 16 additions & 2 deletions game/marble/client/scripts/playerList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,12 @@ function handleClientJoin(%msgType, %msgString, %clientName, %joinData, %isMe)
// spew about new player
echo(detag(%clientName) SPC "joined the game");
sfxPlay(PlayerJoinSfx);
%msg = avar($Text::Msg::PlayerJoin, detag(%clientName));
%displayName = detag(%clientName);
if ($pref::Lobby::StreamerMode)
{
%displayName = getSubStr(%displayName, 0, 1) @ "...";
}
%msg = avar($Text::Msg::PlayerJoin, %displayName);
addChatLine(%msg);
}

Expand Down Expand Up @@ -170,7 +175,12 @@ function handleClientDrop(%msgType, %msgString, %clientName, %clientId, %xbLiveI
// spew about dropping player
echo(detag(%clientName) SPC "left the game");
sfxPlay(PlayerDropSfx);
%msg = avar($Text::Msg::PlayerDrop, detag(%clientName));
%displayName = detag(%clientName);
if ($pref::Lobby::StreamerMode)
{
%displayName = getSubStr(%displayName, 0, 1) @ "...";
}
%msg = avar($Text::Msg::PlayerDrop, %displayName);
addChatLine(%msg);
}

Expand All @@ -179,6 +189,10 @@ function handleClientDrop(%msgType, %msgString, %clientName, %clientId, %xbLiveI
function handleMPGameOver(%msgType, %msgString, %tied, %leaderName, %leaderPoints)
{
%name = detag(%leaderName);
if ($pref::Lobby::StreamerMode)
{
%name = getSubStr(%name, 0, 1) @ "...";
}

%msg = "";
if (%tied)
Expand Down
36 changes: 32 additions & 4 deletions game/marble/client/scripts/xbLive.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,36 @@
if (isPCBuild())
function getDiscordUsername(%userId)
{
// one time setup for these vars
$Player::Name = XBLiveGetUserName();
$Player::XBLiveId = XBLiveGetUserId();
echo("USER ID: " @ %userId);
if (isObject(DiscordUsernameRequest))
DiscordUsernameRequest.delete();
new HTTPObject(DiscordUsernameRequest);
DiscordUsernameRequest.get("https://openmbu.com", "/api/v1/discord/user/" @ %userId, "");
}

function DiscordUsernameRequest::onLine(%this, %line)
{
%resp = jsonParse(%line);
if (%resp.code == 200)
{
%this.success = true;
if ($Player::Name $= $Player::DiscordUsername && %resp.realname !$= "") // Change only if we haven't changed during the time the HTTP request was occuring
{
$Player::Name = %resp.realname;
}
}
else
{
%this.success = false;
}
%resp.delete();
}

function DiscordUsernameRequest::onDisconnect(%this)
{
if (!%this.success) {
echo("Failed to fetch discord display name!");
}
%this.delete();
}

function refreshPDLC()
Expand Down
3 changes: 3 additions & 0 deletions game/marble/client/ui/HelpAndOptionsGui.gui
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ function HelpAndOptionsGui::onA(%this)
RootGui.setContent(aboutMenuOptionsGui, %this.backGui);
case 5:
RootGui.setContent(helpGui, %this.backGui, 5);
case 6:
Canvas.pushDialog(enterNameGui);
}

return true;
Expand All @@ -75,6 +77,7 @@ function HelpAndOptionsGui::show(%this, %backGui)
HelpAndOptionsList.addRow($Text::HOMiscOptions, "", 0, 8);
HelpAndOptionsList.addRow($Text::HOInstructions, "", 0, 12);
HelpAndOptionsList.addRow($Text::HOCredits, "", 0, 12);
HelpAndOptionsList.addRow("Set Gamertag", "", 0, 12);

if ($pref::UI::LegacyUI)
RootGui.setA($Text::Go);
Expand Down
46 changes: 46 additions & 0 deletions game/marble/client/ui/JoinGameInviteDlg.gui
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ function JoinGameInviteDlg::show(%userId, %username, %avatar)
Canvas.pushDialog(JoinGameInviteDlg);
JoinGameInviteDlg.isShowing = true;
}
if ($pref::Lobby::StreamerMode)
{
%username = getSubStr(%username, 0, 1) @ "...";
}
serverplay2d(HelpDingSfx);
JoinGameInviteDlg.responded = false;
JoinGameInviteDlg.userId = %userId;
Expand Down Expand Up @@ -143,4 +147,46 @@ function DiscordAvatarDownload::downloadFailed(%this, %path)
function DiscordAvatarDownload::onDisconnect(%this)
{
%this.delete();
}

function getInviteDiscordUsername(%userId)
{
echo("USER ID: " @ %userId);
if (isObject(DiscordIUsernameRequest))
DiscordIUsernameRequest.delete();
new HTTPObject(DiscordIUsernameRequest);
DiscordIUsernameRequest.get("https://openmbu.com", "/api/v1/discord/user/" @ %userId, "");
}

function DiscordIUsernameRequest::onLine(%this, %line)
{
%resp = jsonParse(%line);
if (%resp.code == 200)
{
%this.success = true;

%username = %resp.realname;
if (%username !$= "")
{
if ($pref::Lobby::StreamerMode)
{
%username = getSubStr(%username, 0, 1) @ "...";
}

JoinGameInviteDlg.username = %username;
}
}
else
{
%this.success = false;
}
%resp.delete();
}

function DiscordIUsernameRequest::onDisconnect(%this)
{
if (!%this.success) {
echo("Failed to fetch discord display name!");
}
%this.delete();
}
Loading

0 comments on commit 4336385

Please sign in to comment.