Sunday, September 27, 2020

A race condition in npc scripts

today I just reviewed a paid script (I couldn't show because its paid)
and I saw multiple errors and mistakes on the said script !!

this one in particular, is something less well known, but it is VERY important if you are making a Game script

let's give an example

at first glance this script looks bug free, but there is a race condition going on after the *input command

step to reproduce :-
1. open up 4 client, first 2 player claim the reward normally
2. on 3rd client, type 'ragnarok' but don't hit enter yet
3. on 4th client, type 'ragnarok' and hit enter, now the script says the event has ended
4. back on 3rd client, hit the Enter key, now this event has 4 players won this event !

to prevent this from happening, needs to add another check right after the *input command


another example is on my Private MVP Room script, which can be found in rathena repo
https://github.com/rathena/rathena/blob/a4d57cb8a398368c0d720aedc669dff88f73c4d4/npc/custom/etc/mvp_room.txt#L62-L66

now try remove these line
1. let player A register an empty room, but left the menu window open
2. player B register the empty room faster than player A
3. now both player A and player B can go into the same room !
4. if this is register under party/guild, player's B party/guild member couldn't get in even after paying the fees !!

so remember, if you are making a Game or Event script, every time after hitting a next; *menu *select *input *progressbar
the value might have changed from the original value, and might lead to race conditions between players

No comments:

Post a Comment

Linux compiler error that never shown on Visual Studio

let's just admit Visual Studio sux ... ok ? right now, if you want to host a Private Ragnarok Online server, its just better to choose...