20.02.2017, 19:26
Hello everyone,
I'm having trouble with the code below. It's basically a custom RCON command that is called via PHP script when player purchases something in game shop. However, my server randomly crashes after someone makes a payment (triggers the PHP script, which calls the RCON command). Server also crashed by typing this RCON command manually in-game, so I'm pretty sure that there's something wrong with the following code, I just don't see it.
This code is stored in a filterscript (because of OnRconCommand):
Public that is called with "CallRemoteFunction":
Thank you in advance for any help!
I'm having trouble with the code below. It's basically a custom RCON command that is called via PHP script when player purchases something in game shop. However, my server randomly crashes after someone makes a payment (triggers the PHP script, which calls the RCON command). Server also crashed by typing this RCON command manually in-game, so I'm pretty sure that there's something wrong with the following code, I just don't see it.
This code is stored in a filterscript (because of OnRconCommand):
PHP код:
public OnRconCommand(cmd[])
{
new cmdtext[128], params[128];
sscanf(cmd, "s[128]s[128]", cmdtext, params);
if(!strcmp(cmdtext, "givecredits30", true))
{
if(isnull(params)) return print("RCON: null string called");
new str[128];
format(str, sizeof(str), "Player %s bought 30 credits.", params);
printf("%s", str);
if(!isnull(params))
{
CallRemoteFunction("Give30Credits", "s", params); // //This public is placed in gamemode
}
return 1;
}
if(!strcmp(cmdtext, "givecredits100", true))
{
if(isnull(params)) return print("RCON: null string called");
new str[128];
format(str, sizeof(str), "Player %s bought 100 credits.", params);
printf("%s", str);
if(!isnull(params))
{
CallRemoteFunction("Give100Credits", "s", params); //This public is placed in gamemode
}
return 1;
}
return true;
}
PHP код:
forward Give30Credits(params[]);
public Give30Credits(params[])
{
new bool:found=false;
for(new i=0; i<MAX_PLAYERS; i++)
{
if(!strcmp(params, pName(i), false)) //Check if the player (name) is connected
{
if(logged[i] == 1)
{
if(found == false)
{ //Player is online
ShowPlayerDialog(i, 0, DIALOG_STYLE_MSGBOX, "Hernн obchod", "Zakoupena poloћka v hernнm obchodě: {FF33CC}30 Kreditů", "Zavřнt",""); // Just some informational text, not in English
found = true;
PlayerInfo[i][Credits] += 30;
SaveCharacter(i);
}
}
}
}
if(found == false) //If player isn't online
{
new file[128];
format(file, sizeof(file), "Users/%s.ini", params);
if(dini_Exists(file))
{
dini_IntSet(file, "Credits", dini_Int(file, "Credits")+30);
dini_IntSet(file, "BoughtCredits", 30);
}
}
return 1;
}