Skip to content

Commit

Permalink
proper ask to join
Browse files Browse the repository at this point in the history
  • Loading branch information
RandomityGuy committed Mar 4, 2024
1 parent e4976c5 commit 55247c3
Show file tree
Hide file tree
Showing 6 changed files with 105 additions and 12 deletions.
11 changes: 7 additions & 4 deletions engine/source/discord/DiscordGame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,7 @@ void onJoinGame(const char* joinSecret)

void onJoinRequest(const DiscordUser* request)
{
int reply = DISCORD_REPLY_IGNORE;
reply = atoi(Con::executef(4, "onDiscordJoinRequest", request->userId, request->username, request->avatar));
Discord_Respond(request->userId, reply);
Con::executef(4, "onDiscordJoinRequest", request->userId, request->username, request->avatar);
}


Expand Down Expand Up @@ -315,4 +313,9 @@ const char* DiscordGame::ProcessLevel(StringTableEntry guid) {
else
return mGuidLookup[mGUID];

}
}

void DiscordGame::respondJoinRequest(const char* userId, int value)
{
Discord_Respond(userId, value);
}
1 change: 1 addition & 0 deletions engine/source/discord/DiscordGame.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class DiscordGame
//void sendData(const char* data);
void update();
const char* ProcessLevel(StringTableEntry guid);
void respondJoinRequest(const char* userId, int value);

void setStatus(const char* status)
{
Expand Down
5 changes: 5 additions & 0 deletions engine/source/xblive/xbliveFunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,11 @@ ConsoleFunction(XBLivePresenceStopTimer, void, 1, 1, "()")
DiscordGame::get()->setTimer(0, 0);
}

ConsoleFunction(XBLiveRespondJoinRequest, void, 3, 3, "(userId, reply)")
{
DiscordGame::get()->respondJoinRequest(argv[1], atoi(argv[2]));
}

ConsoleFunction(XBLiveLoadAchievements, void, 3, 3, "(port, callback)")
{
argc;
Expand Down
17 changes: 10 additions & 7 deletions game/common/server/clientConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,16 +115,19 @@ function updateServerParams()
return "";
}

function onDiscordJoinRequest(%userId, %username, %userAvatar)
function onDiscordJoinRequest(%userId, %username, %avatar)
{
if (!$Server::Hosting)
return 0;
if (!$Server::Hosting) {
XBLiveRespondJoinRequest(%userId, 0);
return;
}

if ($Server::PlayerCount >= ($pref::Server::MaxPlayers - $Pref::Server::PrivateSlots) || $Server::IsPrivate)
return 0;

return 1;
if ($Server::PlayerCount >= ($pref::Server::MaxPlayers - $Pref::Server::PrivateSlots) || $Server::IsPrivate) {
XBLiveRespondJoinRequest(%userId, 0);
return;
}

JoinGameInviteDlg::show(%userId, %username, %avatar);
}

// populate client data fields, send join messages and server param updates, update xblive records.
Expand Down
3 changes: 2 additions & 1 deletion game/marble/client/init.cs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,8 @@ function initClient()

exec("./ui/AchievementDlg.gui");
exec("./ui/AchievementListGui.gui");

exec("./ui/JoinGameInviteDlg.gui");

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

exec("./ui/chathud/init.cs");
Expand Down
80 changes: 80 additions & 0 deletions game/marble/client/ui/JoinGameInviteDlg.gui
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
//--- OBJECT WRITE BEGIN ---
new GuiControl(JoinGameInviteDlg) {
profile = "GuiDefaultProfile";
horizSizing = "width";
vertSizing = "height";
position = "0 0";
extent = "640 480";
minExtent = "8 8";
visible = "1";
noCursor = "1";

new GuiAchievementPopupCtrl(JoinGameInviteFrame) {
profile = "AchievementDlgProfile";
horizSizing = "center";
vertSizing = "top";
position = "0 350";
extent = "507 116";
//minExtent = "48 92";
visible = "1";
icon = "";
wrap = "0";
};

};
//--- OBJECT WRITE END ---

function JoinGameInviteDlg::onWake(%this)
{
enableGamepad();
moveMap.push();
//AchievementFrame.setPosition("70", "0");
AchievementFrame.setHeader($Text::AchievementUnlocked);
AchievementFrame.setIcon("./achievement/" @ $AchievementId);
AchievementFrame.setTitle(%title);
}

function JoinGameInviteDlg::show(%userId, %username, %avatar)
{
if (!JoinGameInviteDlg.isShowing) {
Canvas.pushDialog(JoinGameInviteDlg);
JoinGameInviteDlg.isShowing = true;
}
JoinGameInviteDlg.responded = false;
JoinGameInviteDlg.userId = %userId;
JoinGameInviteDlg.username = %username;
JoinGameInviteDlg.animState = 0;
JoinGameInviteFrame.setHeader("Join Request");
JoinGameInviteFrame.setTitle(%username SPC "wants to join");
cancel(JoinGameInviteDlg.closeSchedule);
JoinGameInviteDlg.closeSchedule = JoinGameInviteDlg.schedule(5000, "close");
cancel(JoinGameInviteDlg.animSchedule);
JoinGameInviteDlg.animSchedule = JoinGameInviteDlg.schedule(1000, "animate");
}

function JoinGameInviteDlg::animate(%this)
{
%this.animState = !%this.animState;
if (%this.animState)
JoinGameInviteFrame.setTitle("Press Y to accept");
else
JoinGameInviteFrame.setTitle(%this.username SPC "wants to join");
%this.animSchedule = %this.schedule(1000, "animate");
}

function JoinGameInviteDlg::onY(%this)
{
if (%this.responded) return;
%this.responded = true;
XBLiveRespondJoinRequest(%this.userId, 1);
JoinGameInviteFrame.setTitle("Accepted join request");
cancel(%this.closeSchedule);
%this.closeSchedule = %this.schedule(2000, "close");
}

function JoinGameInviteDlg::close(%this)
{
cancel(%this.animSchedule);
Canvas.popDialog(%this);
%this.isShowing = false;
}

0 comments on commit 55247c3

Please sign in to comment.