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

OnFilterScriptInit not initializing properly #241

Closed
carlos-menezes opened this issue Aug 22, 2018 · 26 comments
Closed

OnFilterScriptInit not initializing properly #241

carlos-menezes opened this issue Aug 22, 2018 · 26 comments

Comments

@carlos-menezes
Copy link

carlos-menezes commented Aug 22, 2018

I've created a filterscript that's loading properly. However, I want a message to print upon the initialization of said filterscript:

public OnFilterScriptInit() {
    cursor = mysql_connect(HOST, USER, PASSWORD, DATABASE);
    
    print("Initializing samp-streets.");

    if(mysql_errno(cursor) != 0) {
        printf("samp-streets: Couldn't establish connection to \'%s\'.\nReason: %d | Reference: https://*******/2nU9uiB", DATABASE, mysql_errno(cursor));
        return SendRconCommand("unloadfs samp-streets");
    } else {
        printf("samp-streets: Connection to \'%s\' was established.", DATABASE);
    }

    return 1;
}

The filterscript loads fine:

  Loading filterscript 'street-maker.amx'...
  Loaded 1 filterscripts.

But it does not print the first message in the first print statement. This is the entire code, for reference:

#include <a_samp>
#include <a_mysql>
#include <streamer>
#include <sscanf2>
#include <Pawn.CMD>

#define HOST        "localhost"
#define USER        "root"
#define PASSWORD    "password"
#define DATABASE    "streets"

new MySQL:cursor;

enum E_PLAYER_DATA {
    bool:CREATING = false
}

enum E_STREET_DATA {
    ID,
    NAME[25],
    Float:POINTS[2] // xn, yn
}


public OnFilterScriptInit() {
    cursor = mysql_connect(HOST, USER, PASSWORD, DATABASE);
    
    print("Initializing samp-streets.");

    if(mysql_errno(cursor) != 0) {
        printf("samp-streets: Couldn't establish connection to \'%s\'.\nReason: %d | Reference: https://bit.ly/2nU9uiB", DATABASE, mysql_errno(cursor));
        return SendRconCommand("unloadfs samp-streets");
    } else {
        printf("samp-streets: Connection to \'%s\' was established.", DATABASE);
    }

    return 1;
}

public OnFilterScriptExit() {
    return 1;
}

I did check this thread from Marcel: http://forum.sa-mp.com/showthread.php?t=602193 — no helpful answer was given.

@carlos-menezes
Copy link
Author

Note: an user was able to run this filterscript without sampctl — view response.


This is my folder structure and both pawn.json:
Image

├───.git
│   ├───logs
│   │   └───refs
│   │       ├───heads
│   │       └───remotes
│   │           └───origin
│   ├───objects
│   │   ├───02
│   │   ├───0c
│   │   ├───56
│   │   ├───67
│   │   ├───a1
│   │   ├───a4
│   │   ├───a5
│   │   ├───e6
│   │   ├───info
│   │   └───pack
│   └───refs
│       ├───heads
│       ├───remotes
│       │   └───origin
│       └───tags
├───.vscode
├───dependencies
│   ├───pawn-stdlib
│   │   └───.git
│   │       ├───objects
│   │       │   ├───info
│   │       │   └───pack
│   │       └───refs
│   │           ├───heads
│   │           ├───remotes
│   │           │   └───origin
│   │           └───tags
│   └───samp-stdlib
│       └───.git
│           ├───objects
│           │   ├───info
│           │   └───pack
│           └───refs
│               ├───heads
│               ├───remotes
│               │   └───origin
│               └───tags
├───filterscripts
│   └───street-maker
│       └───dependencies
│           ├───.resources
│           │   ├───SA-MP-MySQL-74cb22
│           │   │   └───include
│           │   ├───samp-streamer-plugin-7c00b9
│           │   │   └───include
│           │   └───sscanf-019253
│           │       └───include
│           ├───amx_assembly
│           │   ├───.git
│           │   │   ├───objects
│           │   │   │   ├───info
│           │   │   │   └───pack
│           │   │   └───refs
│           │   │       ├───heads
│           │   │       ├───remotes
│           │   │       │   └───origin
│           │   │       └───tags
│           │   ├───test
│           │   │   └───windows
│           │   └───windows
│           ├───pawn-stdlib
│           │   └───.git
│           │       ├───objects
│           │       │   ├───info
│           │       │   └───pack
│           │       └───refs
│           │           ├───heads
│           │           ├───remotes
│           │           │   └───origin
│           │           └───tags
│           ├───Pawn.CMD
│           │   ├───.git
│           │   │   ├───objects
│           │   │   │   ├───info
│           │   │   │   └───pack
│           │   │   └───refs
│           │   │       ├───heads
│           │   │       ├───remotes
│           │   │       │   └───origin
│           │   │       └───tags
│           │   ├───lib
│           │   │   ├───SDK
│           │   │   │   └───amx
│           │   │   └───urmem
│           │   └───src
│           ├───SA-MP-MySQL
│           │   ├───.git
│           │   │   ├───objects
│           │   │   │   ├───info
│           │   │   │   └───pack
│           │   │   └───refs
│           │   │       ├───heads
│           │   │       ├───remotes
│           │   │       │   └───origin
│           │   │       └───tags
│           │   ├───cmake
│           │   ├───example_scripts
│           │   ├───libs
│           │   │   ├───cmake
│           │   │   ├───samp-log-core
│           │   │   └───sdk
│           │   ├───src
│           │   └───tests
│           │       ├───include
│           │       │   └───amx
│           │       └───test_data
│           │           └───scriptfiles
│           ├───samp-stdlib
│           │   └───.git
│           │       ├───objects
│           │       │   ├───info
│           │       │   └───pack
│           │       └───refs
│           │           ├───heads
│           │           ├───remotes
│           │           │   └───origin
│           │           └───tags
│           ├───samp-streamer-plugin
│           │   ├───.git
│           │   │   ├───objects
│           │   │   │   ├───info
│           │   │   │   └───pack
│           │   │   └───refs
│           │   │       ├───heads
│           │   │       ├───remotes
│           │   │       │   └───origin
│           │   │       └───tags
│           │   ├───cmake
│           │   ├───lib
│           │   │   ├───cmake-modules
│           │   │   └───samp-plugin-sdk
│           │   └───src
│           │       ├───manipulation
│           │       ├───natives
│           │       └───utility
│           ├───sscanf
│           │   ├───.git
│           │   │   ├───objects
│           │   │   │   ├───info
│           │   │   │   └───pack
│           │   │   └───refs
│           │   │       ├───heads
│           │   │       ├───remotes
│           │   │       │   └───origin
│           │   │       └───tags
│           │   └───SDK
│           │       └───amx
│           └───YSI-Includes
│               ├───.git
│               │   ├───objects
│               │   │   ├───info
│               │   │   └───pack
│               │   └───refs
│               │       ├───heads
│               │       ├───remotes
│               │       │   └───origin
│               │       └───tags
│               ├───YSI
│               ├───YSI_Coding
│               │   ├───y_hooks
│               │   ├───y_inline
│               │   ├───y_malloc
│               │   ├───y_stringhash
│               │   ├───y_timers
│               │   └───y_va
│               ├───YSI_Core
│               │   ├───y_als
│               │   ├───y_cell
│               │   ├───y_functional
│               │   └───y_master
│               │       └───stack
│               ├───YSI_Data
│               │   ├───y_bintree
│               │   ├───y_bit
│               │   ├───y_foreach
│               │   ├───y_hashmap
│               │   ├───y_jaggedarray
│               │   └───y_simpletree
│               ├───YSI_Extra
│               ├───YSI_Game
│               │   └───y_vehicledata
│               ├───YSI_Internal
│               │   └───y_unique
│               ├───YSI_Players
│               │   ├───y_groups
│               │   ├───y_text
│               │   └───y_users
│               ├───YSI_Server
│               │   ├───y_colours
│               │   └───y_punycode
│               ├───YSI_Storage
│               │   ├───y_bitmap
│               │   ├───y_ini
│               │   └───y_svar
│               └───YSI_Visual
│                   ├───y_classes
│                   ├───y_commands
│                   ├───y_races
│                   └───y_zonepulse
├───gamemodes
├───plugins
└───scriptfiles

@Southclaws
Copy link
Owner

Thanks for the detailed report!

Can you check for me what the contents of server.cfg is after you've run either sampctl package ensure or sampctl package run? sampctl will compile the runtime section of pawn.json down to a server.cfg and it might be missing out on the filterscripts section. I did make some changes recently to how configuration is handled.

@carlos-menezes
Copy link
Author

Glad to help!
I did check server.cfg yesterday and I should've written that in the OP. Here's server.cfg:

gamemode0 main
filterscripts street-maker
rcon_password password
port 8192
hostname 0.3.DL | SAMP Street Maker
maxplayers 50
language 
mapname San Andreas
weburl www.sa-mp.com
gamemodetext Unknown
announce 1
lanmode 0
query 1
rcon 0
logqueries 0
sleep 5
maxnpc 0
stream_rate 1000
stream_distance 200.000000
onfoot_rate 30
incar_rate 30
weapon_rate 30
chatlogging 1
timestamp 1
messageholelimit 3000
messageslimit 500
ackslimit 3000
playertimeout 10000
minconnectiontime 0
lagcompmode 1
connseedtime 300000
db_logging 0
db_log_queries 0
conncookies 1
cookielogging 0
output 1

It does not change after ensuring and/or building (retested now).

@Southclaws
Copy link
Owner

So filterscripts street-maker is there, and it does load because Loaded 1 filterscripts appears.

Now that you've ensured and you have a generated cfg file, run the samp server executable manually and check the output.

Also it might be worth creating a simpler filterscript, to rule out any of the dependencies from the issue.

@carlos-menezes
Copy link
Author

carlos-menezes commented Aug 22, 2018

Running samp-server.exe:
Image

Then, I commented out a few parts of my code:

#include <a_samp>
/*#include <a_mysql>
#include <streamer>
#include <sscanf2>
#include <Pawn.CMD>

#define HOST        "localhost"
#define USER        "root"
#define PASSWORD    "password"
#define DATABASE    "streets"

new MySQL:cursor;

enum E_PLAYER_DATA {
    bool:CREATING = false
}

enum E_STREET_DATA {
    ID,
    NAME[25],
    Float:POINTS[2] // xn, yn
}
*/

public OnFilterScriptInit() {

    print("Initializing samp-streets.");

    /*cursor = mysql_connect(HOST, USER, PASSWORD, DATABASE);
    
    print("Initializing samp-streets.");

    if(mysql_errno(cursor) != 0) {
        printf("samp-streets: Couldn't establish connection to \'%s\'.\nReason: %d | Reference: https://bit.ly/2nU9uiB", DATABASE, mysql_errno(cursor));
        return SendRconCommand("unloadfs samp-streets");
    } else {
        printf("samp-streets: Connection to \'%s\' was established.", DATABASE);
    }*/

    return 1;
}

public OnFilterScriptExit() {
    return 1;
}

I also changed the filterscript's pawn.json:

{
	"user": "c-mnzs",
	"repo": "street-maker",
	"entry": "street-maker.pwn",
	"output": "../street-maker.amx",
	"dependencies": [
		"sampctl/samp-stdlib"
	],
	"runtime": {
		"version": "0.3.7",
		"rcon_password": "password",
		"port": 7777,
		"hostname": "SA-MP Server",
		"maxplayers": 50
	}
}

This does output Initializing samp-streets. to the console.

@Southclaws
Copy link
Owner

Looks like it's a problem with loading plugins.

@Y-Less
Copy link
Contributor

Y-Less commented Aug 22, 2018

Could you be using different include versions when compiling manually vs with sampctl? Maybe there's something that changed in one and so the wrong version is used and doesn't chain.

@carlos-menezes
Copy link
Author

Hey @Y-Less.

I always compiled with sampctl p build.

@Southclaws
Copy link
Owner

Can you test this on .31?

@carlos-menezes
Copy link
Author

I can't seem to update to the newest version (1.8.31) using scoop. I was on 1.8.29 and scoop update sampctl updated to 1.8.30. @Southclaws

@Southclaws
Copy link
Owner

.31 is releasing now, the build broke for some reason so I just restarted it and it worked!

@carlos-menezes
Copy link
Author

Updated to 1.8.31 and the issue persists.

@Southclaws
Copy link
Owner

Interesting, so it's not related to the changes to plugin order at all. It's strange that unit tests didn't catch this regression, MySQL is even part of some tests and it's also tested here: https://github.com/sampctl/plugin-build-tests

This one may require some more time to figure out what's different on your end so it can be covered in tests.

@carlos-menezes
Copy link
Author

This could be an issue on my end. Have you tried to replicate the issue yourself?

@Southclaws
Copy link
Owner

No, I successfully generated a server.cfg with the MySQL plugin with --platform=linux, I did not test Windows.

The latest release includes a ton of new --verbose logging calls for debugging these sorts of issues, can you run the test again and if it fails, post all the output with --verbose here, thanks!

@carlos-menezes
Copy link
Author

carlos-menezes commented Aug 23, 2018

Well, this is new.

PS C:\Users\CARLOS MENEZES\Desktop\samp-streets\filterscripts\street-maker> sampctl p build
ERROR: failed to interpret directory as Pawn package: failed to read package definition: open C:\Users\CARLOS MENEZES\Desktop\samp-streets\filterscripts\street-maker\.env: The system cannot find the file specified.```

@Southclaws
Copy link
Owner

#243 solved that

@carlos-menezes
Copy link
Author

Did the build break again?

sampctl: 1.8.32 (latest version)

@Southclaws
Copy link
Owner

No it just takes a while: https://github.com/Southclaws/sampctl/releases/tag/1.8.33

@carlos-menezes
Copy link
Author

Only just managed to get the latest version. Can confirm the issue persists.

@Southclaws
Copy link
Owner

Can you run the command with --verbose at the end and post all the output here, thanks!

@carlos-menezes
Copy link
Author

Command: sampctl p run
Output with --verbose flag:

sampctl p run --verbose
INFO: open C:\Users\CARLOS MENEZES\Desktop\samp-streets\.env: The system cannot find the file specified.
INFO: c-mnzs/samp-streets read package from directory C:\Users\CARLOS MENEZES\Desktop\samp-streets
INFO: c-mnzs/samp-streets building dependency tree and ensuring cached copies
INFO: |- c-mnzs/samp-streets is parent
INFO: |- iterating 1 dependencies of c-mnzs/samp-streets
INFO: |-|- github.com/sampctl/samp-stdlib ensured
INFO: open C:\Users\CARLOS MENEZES\.samp\packages\sampctl\samp-stdlib\default\.env: The system cannot find the file specified.
INFO: |-|- iterating 1 dependencies of sampctl/samp-stdlib
INFO: |-|-|- github.com/sampctl/pawn-stdlib ensured
INFO: open C:\Users\CARLOS MENEZES\.samp\packages\sampctl\pawn-stdlib\default\.env: The system cannot find the file specified.
INFO: |-|-|- iterating 0 dependencies of sampctl/pawn-stdlib
INFO: c-mnzs/samp-streets flattened dependencies to 2 leaves
INFO: getting runtime config
INFO: c-mnzs/samp-streets using config from 'runtime' field
INFO: c-mnzs/samp-streets package is local, using working directory
INFO: c-mnzs/samp-streets gathering plugins pre-run
INFO: c-mnzs/samp-streets gathering 0 plugins from package context
INFO: c-mnzs/samp-streets gathered plugins: []
INFO: c-mnzs/samp-streets ensuring runtime pre-run
INFO: ensuring server binaries
INFO: ensuring all dependency and static plugins
INFO: ensuring all compiled scripts
INFO: generating legacy server configuration file
INFO: starting ./samp-server.exe in C:\Users\CARLOS MENEZES\Desktop\samp-streets
INFO: running with mode server

----------
Loaded log file: "server_log.txt".
----------

SA-MP Dedicated Server
----------------------
v0.3.DL-R1, (C)2005-2018 SA-MP Team

language = ""  (string)

Server Plugins
--------------
 Loaded 0 plugins.


Started server on port: 8192, with maxplayers: 50 lanmode is OFF.


Filterscripts
---------------
  Loading filterscript 'street-maker.amx'...
  Loaded 1 filterscripts.

Number of vehicle models: 0

@Southclaws
Copy link
Owner

Ah, right everything is running find, it just took a while to nail the issue.

Until #138 is implemented, sampctl has no knowledge of the package that exists at ./filterscripts/street-maker/ therefore it doesn't know about its dependency on MySQL. For now, you'll have to add those dependencies manually - sampctl doesn't work too well with filterscripts and subpackages yet, this is further discussed with solutions proposed in: #138 #55 #153

The odd thing about this is that no missing native errors were raised. Maybe these don't apply to filterscripts.

@carlos-menezes
Copy link
Author

What do you mean with adding the dependencies manually?

@Southclaws
Copy link
Owner

Southclaws commented Aug 26, 2018

Copy the dependencies of the filterscript's pawn.json to the server's pawn.json

@carlos-menezes
Copy link
Author

That seems to have fixed things. Cheers.

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

No branches or pull requests

3 participants