After fixing his commands with sscanf, Alex's server became stable. No more parsing crashes. He could do complex commands like:
// /giveitem [player] [item] [amount] if(sscanf(params, "us[24]d", target, item, amount)) return UsageMsg(); // /setweather [hour] [minute] (optional weather ID) new hour, minute, weather = -1; if(sscanf(params, "ddD(0)", hour, minute, weather)) // D(0) = optional integer, default 0 samp sscanf
The Day My Roleplay Server Broke (And How sscanf Fixed It) After fixing his commands with sscanf, Alex's server
Alex spent 3 hours reading logs. The issue? A player typed /givecash 12a 500 . strval("12a") returned 12 , but the a caused the next parameter to be misaligned. Pure nightmare. The issue
One night, 35 players online. Alex's manual parsing failed on a single space. The command callback returned 0 (meaning "command not found"), so SAMP thought /givecash was an unknown command. Then another system tried to interpret it, and – . All 35 players disconnected.
new cmd[32], id, cash; if(sscanf(cmdtext, "s[32]dd", cmd, id, cash)) return SendClientMessage(playerid, -1, "Usage: /givecash [ID] [amount]"); if(strcmp(cmd, "/givecash", true) == 0) GivePlayerMoney(id, cash); GivePlayerMoney(playerid, -cash); return 1;