Skip to content

Commit

Permalink
Fixed joining via invite code
Browse files Browse the repository at this point in the history
  • Loading branch information
HumanGamer committed Jun 2, 2023
1 parent 94927ea commit 95f4b69
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 11 deletions.
27 changes: 18 additions & 9 deletions engine/source/game/net/serverQuery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1284,7 +1284,8 @@ static void processMasterServerQuery(U32 session)
out->write(sActiveFilter.minPlayers);
out->write(sActiveFilter.maxPlayers);
out->write(sActiveFilter.regionMask);
U32 version = (sActiveFilter.filterFlags & ServerFilter::CurrentVersion) ? getVersionNumber() : 0;
//U32 version = (sActiveFilter.filterFlags & ServerFilter::CurrentVersion) ? getVersionNumber() : 0;
U32 version = getVersionNumber();
out->write(version);
out->write(sActiveFilter.filterFlags);
out->write(sActiveFilter.maxBots);
Expand Down Expand Up @@ -1955,9 +1956,10 @@ static void handleGamePingResponse(const NetAddress* address, BitStream* stream,

// Get the server build version:
stream->read(&temp32);
if (applyFilter
&& (sActiveFilter.filterFlags & ServerFilter::CurrentVersion)
&& (temp32 != getVersionNumber()))
// if (applyFilter
// && (sActiveFilter.filterFlags & ServerFilter::CurrentVersion)
// && (temp32 != getVersionNumber()))
if (temp32 != getVersionNumber())
{
Con::printf("Server %s filtered out by version number.", addrString);
gFinishedList.push_back(*address);
Expand Down Expand Up @@ -2220,7 +2222,7 @@ static void joinGameByInvite(const char* inviteCode)
BitStream::sendPacketStream(&(*serverList)[i].address);
}

int netPort = Con::getIntVariable("pref::Net::Port");
int netPort = Con::getIntVariable("pref::Server::Port");

// Now for LAN
stream = BitStream::getPacketStream();
Expand Down Expand Up @@ -2437,16 +2439,19 @@ static void handleMasterServerJoinInvite(const NetAddress* address, BitStream* s
const char* ourInv = Con::getVariable("Server::InviteCode");
if (strcmp(ourInv, inv) == 0) {
// RESPOND
U16 netPort = Con::getIntVariable("pref::Net::Port");
U16 netPort = Con::getIntVariable("pref::Server::Port");

BitStream* stream = BitStream::getPacketStream();
stream->write(U8(NetInterface::MasterServerJoinInviteResponse));
U8 flags = 0;
U32 key = 0;
U8 found = 1;

stream->write(flags);
stream->write(key);

stream->write(found);

// We just replace the netNum with 255.255.255.255 and filter that out on client side
NetAddress theAddress;
theAddress.netNum[0] = 255;
Expand All @@ -2464,7 +2469,7 @@ static void handleMasterServerJoinInvite(const NetAddress* address, BitStream* s
}

static void handleMasterServerJoinInviteResponse(const NetAddress* address, BitStream* stream) {
U8 found;
U8 found = true;
stream->read(&found);
if (found)
{
Expand All @@ -2476,18 +2481,22 @@ static void handleMasterServerJoinInviteResponse(const NetAddress* address, BitS
stream->read(&theAddress.netNum[3]);
stream->read(&theAddress.port);

bool isLocal = false;
if (theAddress.netNum[0] == 255 && theAddress.netNum[1] == 255 && theAddress.netNum[2] == 255 && theAddress.netNum[3] == 255) {
theAddress.netNum[0] = address->netNum[0];
theAddress.netNum[1] = address->netNum[1];
theAddress.netNum[2] = address->netNum[2];
theAddress.netNum[3] = address->netNum[3];

isLocal = true;
}


char evalbuf[128];
dSprintf(evalbuf, 128, "%s(\"%d.%d.%d.%d:%d\");", joinGameAcceptCb, theAddress.netNum[0], theAddress.netNum[1], theAddress.netNum[2], theAddress.netNum[3], theAddress.port);
dSprintf(evalbuf, 128, "%s(\"%d.%d.%d.%d:%d\",%s);", joinGameAcceptCb, theAddress.netNum[0], theAddress.netNum[1], theAddress.netNum[2], theAddress.netNum[3], theAddress.port, isLocal ? "true" : "false");
Con::evaluatef(evalbuf);
}
else
else
{
char evalbuf[64];
dSprintf(evalbuf, 64, "%s();", joinGameRejectCb);
Expand Down
20 changes: 20 additions & 0 deletions game/MBU.torsion.exports
Original file line number Diff line number Diff line change
Expand Up @@ -3135,6 +3135,10 @@ More of a helper function than anything. If console access to the field list i
<method> <name>getText</name>
<desc>- returns the text of the button.</desc>
</method>
<method> <name>setHover</name>
<args>hover</args>
<desc>- sets the button hover state.</desc>
</method>
<method> <name>setText</name>
<args>string text</args>
<desc>- sets the text of the button to the string.</desc>
Expand Down Expand Up @@ -3900,6 +3904,9 @@ More of a helper function than anything. If console access to the field list i
</class>
<class> <name>NetConnection</name>
<base>SimGroup</base>
<method> <name>arrangeConnection</name>
<args>ip</args>
</method>
<method> <name>checkMaxRate</name>
</method>
<method> <name>clearPaths</name>
Expand Down Expand Up @@ -3927,6 +3934,9 @@ More of a helper function than anything. If console access to the field list i
</method>
<method> <name>getXnAddr</name>
</method>
<method> <name>relayConnection</name>
<args>ip</args>
</method>
<method> <name>resolveGhostID</name>
<args> S32 ghostID </args>
<desc>Convert a ghost id from this connection to a real id.</desc>
Expand Down Expand Up @@ -5814,6 +5824,9 @@ More of a helper function than anything. If console access to the field list i
<field> <name>DRLTarget</name>
<desc>float DRLTarget</desc>
</field>
<field> <name>shadowColor</name>
<desc>ColorF shadowColor</desc>
</field>
<field> <name>useBloom</name>
<desc>bool useBloom</desc>
</field>
Expand Down Expand Up @@ -7272,6 +7285,9 @@ Sim time is time since the game started.</desc>
</function>
<function> <name>isKoreanBuild</name>
</function>
<function> <name>isLocalAddress</name>
<args>addr</args>
</function>
<function> <name>isObject</name>
<args>object</args>
</function>
Expand Down Expand Up @@ -7304,6 +7320,10 @@ Sim time is time since the game started.</desc>
<function> <name>isXInputConnected</name>
<args> int controllerID </args>
</function>
<function> <name>joinGameByInvite</name>
<args>inviteCode, acceptCb(%ip</args>
<desc>, rejectCb)</desc>
</function>
<function> <name>lightScene</name>
<args>script_function completeCallback=NULL, string mode=""</args>
<desc>Relight the scene.
Expand Down
12 changes: 10 additions & 2 deletions game/marble/client/ui/joinGameGui.gui
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,12 @@ function JoinGameGui::show(%this)
{
RootGui.setTitle($Text::JoinGame);
RootGui.setB($Text::Back);

if (GameMissionInfo.getMode() !$= GameMissionInfo.MPMode)
{
GameMissionInfo.setMode(GameMissionInfo.MPMode);
GameMissionInfo.setDefaultMission();
}

JoinGameGui.inviteCode = "";
InviteCodeInput.setText(JoinGameGui.inviteCode);
Expand Down Expand Up @@ -273,22 +279,24 @@ function JoinGameGui::joinGame(%this)
RootGui.setContent(MissionLoadingGui);
}

function joinGameFound(%ip)
function joinGameFound(%ip, %isLocal)
{
cancel(JoinGameGui.joinTimeout);
setNetPort(0); // Get random port pls
establishConnection(%ip, true, false, JoinGameGui.inviteCode);
establishConnection(%ip, true, %isLocal, JoinGameGui.inviteCode);
}

function joinGameNotFound()
{
cancel(JoinGameGui.joinTimeout);
echo("Not Found");
if (RootGui.contentGui == MissionLoadingGui)
RootGui.setContent(JoinGameGui);
}

function JoinGameGui::textInput(%this, %chr)
{
cancel(JoinGameGui.joinTimeout);
if (%chr !$= "D")
{
if (strlen(JoinGameGui.inviteCode) < 6)
Expand Down

0 comments on commit 95f4b69

Please sign in to comment.