-
Notifications
You must be signed in to change notification settings - Fork 164
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
Backend: SQL LIKE command added #312
Conversation
I think I'm gonna test this a bit before merging it, but it looks reasonable at first glance. |
I checked it out and it seems reasonable at first glance for me as well. Definitely needs some testing. Do any other games besides Fortune Street use it? I think it's a pretty rare command so not entirely urgent, but I'd like to get this merged eventually. |
I assume others games use it. According to gslist.txt from Luigi Auriemma work:
Then the peer.h file from OpenSpy Core states: // The filter argument is a SQL WHERE-clause-style boolean statement used
// to further restrict the list of prospective game hosts that will be
// returned to the peerListingGamesCallback, such as:
//
// "gametype='ctf'" or
// "numplayers > 1 and numplayers < 8" or
// "hostname like '%[gsf]%'" or
// "(country = 'DE' or country = 'FR') and maxplayers >= 8".
//
// The filter can be arbitrarily complex and supports standard SQL conditions
// and Boolean operations.
//
// The following fields can be filtered: hostport, gamever, location, hostname,
// mapname, gametype, gamemode, numplayers, maxplayers, groupid. |
I'm just going to merge this. I'm going to try rewriting a bit of the server to work better over the next few months when I have some free time, so if any bugs pop up then we'll cover it then I guess. |
After a long time thinking concerning how to add the LIKE command in the ast/parser backend, I explored various possibilities:
Let's begin with the main issue, the
ast.parse
function need a string that contains valid Python code. Obviously LIKE isn't a keyword in this langage and is the real problem. I saw two possibilities:LIKE(A, B)
A | LIKE | B
Convert it with regular expressions:
It might not be a good solution if there is a variable substitution that contains weird characters in a string such as parenthesis or spaces, the regex will be noneffective with string literals and others weird syntaxes like:
(1)LIKE"1"
Replacing with a python function:
I tried to do so but each time I had to find a workaround wherever I put the conversion. I need
A LIKE B
to be a function, for examplesql_like(A, B)
. If I replace it at the end of the process (i.e. when the string has been generated), I obviously need a regular expression to catch its operands and the case insensitiveness. Otherwise I need to mess around with the output/variables lists to change the 1st operand index in thetranslate_expression
function and probably add the token ",", otherwise the translation can fail ifget_token
is called with "," as token. Plus, I also have to extend the white-list in thevalidate_ast
function to support function calls.Possible workaround:
Unfortunately, there is no way to add operators in python language. However, there is a hackish way to add an infix operator and we'll be able to replace
LIKE
with|LIKE|
, this way we only need to replace the LIKE command. Easier to add because I don't have to mess with its operands. However, I needed to add another optional parameter in thevalidate_ast
function because binary operators' constraints shouldn't be applied against it.In sum, I tested it with Fortune Street and it works and solved the issue #277.
Ready to be reviewed and merged.