-
-
Notifications
You must be signed in to change notification settings - Fork 452
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support mtasa:// protocol connect args #3211
base: master
Are you sure you want to change the base?
Conversation
Supplied to server via onPlayerConnect event parameters
marge |
Also it should work with |
What about also changing redirectPlayer? |
well done, lgtm |
the redirectPlayer functionality has uncovered an issue with the argument parser which needs resolving before this can be merged. See discussion on dev discord |
Works fine for me, can you confirm how you're using the command and what errors you're seeing? @fresholia |
We can't use For this reason I've changed to use However, I did have to implement a hash function for mtasa-blue/Client/mods/deathmatch/logic/lua/CLuaArgument.h Lines 68 to 78 in c96a8ff
|
I think it would be better to fix a crash instead of constructing hash related complicated things. I hope my PR #3246 will help. |
This reverts commit c96a8ff.
@@ -286,6 +288,9 @@ class CCore : public CCoreInterface, public CSingleton<CCore> | |||
bool IsUsingCustomStreamingMemorySize(); | |||
size_t GetStreamingMemory(); | |||
|
|||
void SetProtocolConnectArgs(const std::string&& args) { m_strProtocolConnectArgs = args; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately, const rvalue reference doesn't make sense. Even without a const qualifier it wont work as expected because in the function's body args
is actually lvalue reference. So you should remove const
and cast args
to the rvalue explicitly: SetProtocolConnectArgs(std::string&& args) { m_strProtocolConnectArgs = std::move(args); }
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with this.
Also, that custom hash function for CLuaArgument
isn't good at all, and should be avoided at all costs.
Actually, and kind of comparasion/hashing of it should be avoided.
@@ -190,6 +190,9 @@ class CCoreInterface | |||
virtual bool IsUsingCustomStreamingMemorySize() = 0; | |||
virtual size_t GetStreamingMemory() = 0; | |||
|
|||
virtual void SetProtocolConnectArgs(const std::string&& args) = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The same: const rvalue has no sense
@@ -44,6 +44,9 @@ class CPlayerJoinDataPacket final : public CPacket | |||
|
|||
bool IsOptionalUpdateInfoRequired() { return m_bOptionalUpdateInfoRequired; } | |||
|
|||
const char* GetConnectArgs() { return m_strConnectArgs; }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why don't you return a string object reference?
@@ -1735,6 +1735,11 @@ void CGame::Packet_PlayerJoinData(CPlayerJoinDataPacket& Packet) | |||
pPlayer->SetBitStreamVersion(Packet.GetBitStreamVersion()); | |||
g_pNetServer->SetClientBitStreamVersion(Packet.GetSourceSocket(), Packet.GetBitStreamVersion()); | |||
|
|||
const char* connectArgs = Packet.GetConnectArgs(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This related to a CPlayerJoinDataPacket class problem: it's probably better to use a string.
@@ -335,6 +335,9 @@ class CPlayer final : public CPed, public CClient | |||
const SString& GetQuitReasonForLog() { return m_strQuitReasonForLog; } | |||
void SetQuitReasonForLog(const SString& strReason) { m_strQuitReasonForLog = strReason; } | |||
|
|||
void SetConnectArgs(const SString&& args) { m_strConnectArgs = args; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The same problem with const rvalue ref
const char* connectArgs = Packet.GetConnectArgs(); | ||
|
||
if (std::strlen(connectArgs) > 0) | ||
pPlayer->SetConnectArgs(std::move(Packet.GetConnectArgs())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would recommend to remove std::move
here because Packet_PlayerJoinData(and even CGame) method doesn't own this string.
@@ -240,6 +240,20 @@ void CInputRPCs::ForceReconnect(NetBitStreamInterface& bitStream) | |||
|
|||
if (bitStream.Read(usPort)) | |||
{ | |||
char* szArgs = new char[MAX_PROTOCOL_CONNECT_ARGS_LENGTH + 1]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems that we have a memory leak here. Because szArgs
isn't deleted below.
Maybe a preallocated std::string
is the solution? It's null terminated and guaranteed to contiguous since C++11 and we have non-const ::data
member since C++17(please, use it).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But it's even better to use bitStream.ReadString()
(with the modification of a packet itself).
Here's the last status update on this PR: Dutchman101 — 01/07/2024 1:42 AM lopsi — 01/07/2024 3:04 PM |
Any updates on this? Would be a really nice feature. |
Bump |
Bump? |
Why would you use this weird syntax with slashes? Aren't usual ampersands enough, as seen in URLs? What if an argument is specified twice, what value will be in the table - first or last? What if it is specified thrice? E.g. a Are all the values of
and so on. What if an argument does not have value, then how will it be combined with the arguments following it - like this: Why not pass your "query" string as is and let the server/client script decide how to parse it? And to implement general querystring-like parsing, just add a new Don't reinvent the wheel please, we all (mostly) are used to web URLs and they do their job well, use them. |
What is syntax if one wants to encode slash to an argument key or a value? Is it possible at all, and if it is, how? A usual percent-encoding, as in web URLs? |
Requires much more thought and effort to ensure compatibility with existing services which utilize the standard protocol/parameters, such as updates. We'll have to change code surrounding that which hasn't changed in a while. Also please refer to existing comments to save time #3211 (comment) I haven't had much interest in this lately so, if you feel motivated, feel free to pick this up! |
All of your other questions can be answered by taking a glance at |
I've converted to draft and updated the description so there's no confusion on the state of this PR. |
Changes
onPlayerConnect
event parameters.redirectPlayer
which allows you to pass a table to achieve the same result (all keys, values are automatically converted to strings, in order to form the 'argument path').Additional Info
Total length of arguments is limited to 1024 including
/
delimiter per key/value pair (arguments are treated as path string for 99% of lifetime)Subject to change for typical url parameters e.g
?a=1&b=2
This feature is useful for the Discord RPC functionality, servers can create a party system using this or give rewards for joining via Discord (of course this can extend to other platforms).
Example
Have serverside script running:
mtasa://123.456.78.9:22003/foo/123/bar/456/baz/789
redirect
commandNotes
Computer\HKEY_CLASSES_ROOT\mtasa\shell\open\command
and set to your mtasa build path e.g"C:\mtasa-blue\Bin\Multi Theft Auto_d.exe"%1
To-do
/
in user provided keys/values, either remove character or URL encode? (/
is our delimiter so would affect converting to pairs)/
will be removed from user provided argsstd::unordered_map<type, type>
for Lua args?a=1&b=2
formatThe method used for URL parameters (key/value pairs delimited by slash) should be changed to use the standard URI parameter format
?foo=bar&baz=boz
This is going to require a lot of time to investigate how this is currently being used by various services, both public and private (internal). It will affect all areas, to do with downloads, updates, server connections, etc. This is the reason why I initially opted to use the key/value pairs delimited by slash, as it causes the least disruption to the client. This will be a major change, that fittingly should go into a major release.