Skip to content
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

#pragma option #204

Merged
merged 5 commits into from
Nov 5, 2017
Merged

#pragma option #204

merged 5 commits into from
Nov 5, 2017

Conversation

Y-Less
Copy link
Member

@Y-Less Y-Less commented Oct 26, 2017

#pragma option

Allows you to specify command-line options within a script. Some don't work, some already have other pragma equivalents, but some can't be done yet. Could actually replace a huge number of other pragmas:

#pragma tabsize 4
#pragma option -t4

#pragma ctrlchar \
#pragma option -\

#pragma semicolon 1
#pragma option -;+

#pragma warning disable 202
#pragma option -w202

#pragma compat 1
#pragma option -Z+

#define HELLO 42
#pragma option HELLO=42

#pragma codepage 1424
#pragma option -c1424

// NO EQUIVALENT
#pragma option -(+

// NO EQUIVALENT
#pragma option -l

// NO EQUIVALENT
#pragma option -E

// NO EQUIVALENT
#pragma option -a

// etc...

Certain options are disabled in this manner, because they would alter details too fundamental, such as input and output files, that can't be changed after you already started reading said files:

-e
-o
-p
-r

Note that it will only read up to about 32 characters from the option, since it isn't really designed for long ones. Speaking of which, a lot of the existing pragma code uses i<sizeof name and name[i]='\0', which is technically a buffer overflow, but as far as I can see only ever writes an extra zero in to a subsequently unused variable, so is entirely safe.

@Romz24
Copy link

Romz24 commented Oct 26, 2017

Good idea and implementation.

@SysadminJeroen
Copy link
Contributor

How can this be used to specify a variable through command-line parameters?

I'm using multiple seds to pass environment variables to the gamemode

@Y-Less
Copy link
Member Author

Y-Less commented Oct 26, 2017

This can't, but the normal command-line already can.

pawncc MY_VAR=${MY_VAR} mode.pwn

@SysadminJeroen
Copy link
Contributor

@Y-Less Thank you! I already throught I read that somewhere but I couldn't find it when I tried to find it later.

Now I can finally throw away my hack-ish sed prompts.

Not even joking, it looks like this.

   sed -i "s/#define localmode 1/#define localmode $LOCALMODE/" $CI_PROJECT_DIR/gamemodes/SFCRRPG.pwn
   sed -i "s/#define SQL_SERVER		\"127.0.0.1\"/#define SQL_SERVER		\"$SQL_SERVER\"/" $CI_PROJECT_DIR/include/mysql.inc
   sed -i "s/#define SQL_USER		\"D3V1Lx\"/#define SQL_USER		\"$SQL_USER\"/" $CI_PROJECT_DIR/include/mysql.inc
   sed -i "s/#define SQL_DB			\"CNRUSERS\"/#define SQL_DB			\"$SQL_DB\"/" $CI_PROJECT_DIR/include/mysql.inc
   sed -i "s/#define SQL_PASS 		\"johncena\"/#define SQL_PASS 		\"$SQL_PASS\"/" $CI_PROJECT_DIR/include/mysql.inc

Even looking back at that, I could've easily made multiple replacements with only one sed. But I have only learnt that recently.

@Y-Less
Copy link
Member Author

Y-Less commented Oct 26, 2017

While that is correct, you shouldn't be building usernames and passwords in to scripts like that. Loading those is now one of the best remaining uses for an INI system to store your credentials for connecting to a database.

@SysadminJeroen
Copy link
Contributor

You're right, however the binaries containing the username and password are automatically compiled and sent to the server running the gamemode. The credentials itself are saved in GitLab.

And if someone were to obtain the AMX, I could just revoke the credentials and issue new ones.

@Y-Less
Copy link
Member Author

Y-Less commented Oct 26, 2017

You shouldn't be storing credentials in git either!

@SysadminJeroen
Copy link
Contributor

Not in Git, in GitLab as a protected secret variable.

I know very well that you shouldn't store secrets in Git.

@Y-Less
Copy link
Member Author

Y-Less commented Oct 28, 2017

Fixed a bug and added -c support (the bug being the whole code did absolutely nothing).

@Zeex Zeex merged commit c2a92d9 into pawn-lang:master Nov 5, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants