RemoveBuildingForPlayer - crash if player reconnects
#1

OK, so this is very weird. I have placed on OnPlayerConnect the function to remove the buildings for players. If a player loses connection and reconnects, that player's game will either crash or freeze. I did a lot of tests with this and still the game got stuck. I called the function once on OnPlayerSpawn but that still crashed me after I 'gmxed' the server. I also used a timer for this, but it gave me the same result. Moreover, I ran the function only one time for each player, meaning the first time the player connects, but the second time of connection, the server doesn't remove the objects.

PS: There are at least 600 objects that get removed.
Reply
#2

Just put it into a filterscript, it makes it much easier.(Atleast for me.)

So you can load/unload if it's bugged
Reply
#3

Remove only on spawn and once, after it, add stat which tells that player's objs is removed.

like

new Removed[MAX_PLAYERS];


OnPlayerSpawn()
{
if(!Removed[playerid])
{
//Remove script
Removed[playerid] = 1;
}


}
Reply
#4

We can't be sure, if a player has actually close his/her game or just loose his/her connection to the server and reconnects. (Sometimes bugged players can't send a quit request to the server, so they are going to be shown as "timed out"). A lot of RemoveBuildingForPlayer code can crash a player indeed, and if a player times out for a short period of time and reconnects, the script will execute RemoveBuildingForPlayer, even if the player has already the objects removed from his/her game.

It can be useful to unload "remove building" code after a player calls OnPlayerDisconnect(), but we don't have this feature yet in SA:MP.

Also a lot of "remove building" code can mess up dialog sync (a feature to prevent cheaters executing invalid/forbidden dialog IDs), making dialogs unable to use in the server.
Reply
#5

Another reason here why gmx is crappy anyways it's likely that your trying to remove objects too many times 600 is quite a lot to remove and it will usually start crashing players around 1000 objects.
Reply
#6

I see, thanks for the extra info fellas. Well, at least I fixed the issue with Windows 8 players, whose game would freeze.
Reply
#7

Yep also happened to me in my server, only about 200 removed objects.
Reply
#8

Well if you remove such area as LS docks, where is alot of same containers or lights, you can increase removed obj range, so you don't have to remove each one light/container.
Reply
#9

Quote:
Originally Posted by ikey07
View Post
Well if you remove such area as LS docks, where is alot of same containers or lights, you can increase removed obj range, so you don't have to remove each one light/container.
Thumbs up to that suggestion, just take a look at the mapping section some of those maps could have some lines reduced by doing this.
Reply
#10

Still the main problem is that if a player loose connection for a second, it will crash him on reconnect, because if you remove the same building twice for a player he crashes, I'm trying to find a fix to it...
Reply
#11

Quote:
Originally Posted by rt-2
View Post
Still the main problem is that if a player loose connection for a second, it will crash him on reconnect, because if you remove the same building twice for a player he crashes, I'm trying to find a fix to it...
Not really... Crashes happen only when a certain amount of removed buildings is reached. So, your players get crashed only because you remove a lot of objects, and when they reconnect, that amount is doubled and most likely that limit is reached
Reply
#12

Quote:
Originally Posted by Spmn
View Post
Not really... Crashes happen only when a certain amount of removed buildings is reached. So, your players get crashed only because you remove a lot of objects, and when they reconnect, that amount is doubled and most likely that limit is reached
So you mean that "When removing the same object for a player, they will crash. Commonly, players crash when reconnecting to the server because the server removes buildings on OnPlayerConnect." from https://sampwiki.blast.hk/wiki/RemoveBuildingForPlayer is wrong?

Anyway does anyone found a way to avoid re-removing buildings for players?
Thank you,
rt-2
Reply
#13

Had around 100 buildings removed on my server. Players barely crashed when they reconnected after connection loss.
Reply
#14

Quote:
Originally Posted by rt-2
View Post
So you mean that "When removing the same object for a player, they will crash. Commonly, players crash when reconnecting to the server because the server removes buildings on OnPlayerConnect." from https://sampwiki.blast.hk/wiki/RemoveBuildingForPlayer is wrong?

Anyway does anyone found a way to avoid re-removing buildings for players?
Thank you,
rt-2
You can "test" whether or not objects were removed.
Remove a building that has a collision for players joining the server that did NOT have a timeout the last time he left (just like usual).
If someone joins who timed out the last time he left, teleport him onto that building. After a second or two, check the player's position. If the player is still on the object, call your RemoveBuildingForPlayer code. If he falls through, the buildings were already removed (the player didn't crash, but loose connection).


It's ugly, not 100% reliable but technically the only way to find out whether or not a building exists client side.
Make sure the player doesn't pause and there is enough time for syncing before checking, then it should all work well.
I do this on my server and did not have any issues with this (local as well as real server), except players can use hacks/mods to teleport/freeze them.
I run this test during the very first spawn, if the camera is placed/pointed somewhere else it won't even be visible - it just takes 3 seconds. You can show the Rules or similar during this time period.
Reply
#15

I used a similar approach on a stunt server and it worked flawless:
1) teleport the player on this object, right above the sea level
2) wait 1-2 seconds (IIRC, I made use of player's ping and/or fps for more accurate results)
3) use GetPlayerAnimationIndex() to detect if player was swimming or not
-> if player isn't swimming -> call remove building code, INCLUDING that object
-> else -> skip

I also had a library based on this, but I can't find it right now.
Reply
#16

Thats very nice ideas guys.
Thank you,
Reply
#17

This bug is still present. It is necessary that Kalcor made after reconnect so that the remote objects returned to their places. Players complain, I do not know how to solve this problem.

It would also be cool to add a function that checks if the objects are removed from the player or not. In this case, it would be possible to simply check and, if necessary, delete objects on the connection.
Reply
#18

Code:
int RemovedBuilduing[1000];
int CountRemove;

void Remove(int objectid)
{
	RemovedBuilduing[CountRemove]=objectid;
	CountRemove++;
}
When CountRemove reach 1000 there is memory leak
it's how Kalcor did this function
Reply
#19

Quote:
Originally Posted by ][Noname][
View Post
Code:
int RemovedBuilduing[1000];
int CountRemove;

void Remove(int objectid)
{
	RemovedBuilduing[CountRemove]=objectid;
	CountRemove++;
}
When CountRemove reach 1000 there is memory leak
it's how Kalcor did this function
Is it fixed in the new DL version, because that would be very interesting.
I don't think this is even possible to fix in a fixes.inc fashion.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)