MySQL Bug, corrupting owned car ids on server start
#1

So the issue I am having is cars that players own seem to get completely ruined on start up.
The script I am using has MySQL databases that stores the account info, also the perm cars placed around that are not owned by players and then finally the cars that players own.

What happens is the server starts up and when it reaches the cars it will load the perm cars from the sql first and loads them correctly (Keep in mind there are around 500 cars using many types, colors, locations). After that it starts to load the players cars and from what I can tell is it's starting to load them but then gets stuck on a certain vehicle and then uses that info over and over again for the rest of the cars.

For example:

3 or 4 people each purchased 3-7 vehicles a piece. All of them were different cars maybe a couple were the same between them all. They all had different vehicle ids and different paint jobs and /park locations. When the server is shutdown the sql database seems to be unchanged. Once I start the server it will begin loading and when reaching vehicles it will say the following:

- Loaded perm cars...
- loading player vehicle 1
- loading player vehicle 2
- loading player vehicle 3
- loading player vehicle 3
- loading player vehicle 3
- loading player vehicle 3
- loading player vehicle 3
- loading player vehicle 3

Once logging into the server I see that all the cars that were once different have all been given the stats of 1 or 2 of the bunch, in a way duplicating the car while over writing the real ones.

Also once this has happened I can go into the sql and see that the data has in fact been changed by this bug and the cars are permanently ruined and everyone must be refunded.


I would really appreciate any help I can get, I have been trying to just disable the game mode ownership system and use separate filterscripts but in the end it just creates more smaller bugs and doesn't seem like the right solution.

I am not a master at PAWN but learn fast and understand things easily. I have been working on this server and debugging it myself as well as adding things as I learn. This issue seems to be beyond me though, below I will post some of the MySQL coding and if anything else is needed to assist please let me know so I can post it as well.

Thanks for your time in advance.

Code:

On console during load:
[08:00:18] [OnGameModeInit] NPC loading... (if enabled).
[08:00:20] [OnGameModeInit] Permanent vehicles loading...
[08:00:20] Loading vehicle 867...
[08:00:20] Loading vehicle 867...
[08:00:20] Loading vehicle 867...
[08:00:20] Loading vehicle 867...
[08:00:20] Loading vehicle 867...
[08:00:20] Loading vehicle 867...
[08:00:20] Loading vehicle 867...
[08:00:20] Loading vehicle 867...
[08:00:20] Loading vehicle 867...
[08:00:20] Loading vehicle 868...
[08:00:20] Loading vehicle 869...
[08:00:20] Loading vehicle 870...
[08:00:20] Loading vehicle 879...
[08:00:20] Loading vehicle 880...
[08:00:20] Loading vehicle 881...
[08:00:20] Loading vehicle 882...
[08:00:20] [OnGameModeInit] Dealership vehicles loading...
[16:40:16] Authenticated successfully.

(Note that when Permanent vehicles load it does not show any info on console it only does that for the dealership vehicles above the 'Dealership vehicles loading...' prompt.)

Here is the loading codes for Perm and Player vehicles:

Код:
    LoadPermanentVehicles();
	print("[OnGameModeInit] Permanent vehicles loading...");
	
    LoadVehicles();
        print("[OnGameModeInit] Dealership vehicles loading...");
Stock for perm vehicles:

Код:
stock LoadPermanentVehicles()
{
	new data[64], query[128], vehicleid;
	for (new i = 1; i < MAX_VEHICLES; i++)
	{
     	format(query, sizeof(query), "SELECT * FROM `permcars` WHERE `permcarid` = '%d'", i);
		mysql_query(query);
		mysql_store_result();
		if (mysql_num_rows())
	    {
			while (mysql_retrieve_row())
			{
    			mysql_fetch_field_row(data, "permcarid"); PermanentVehicleStatistics[i][PermCarSQLID] = strval(data);
	        	mysql_fetch_field_row(data, "IsPermCar"); PermanentVehicleStatistics[i][IsPermCar] = strval(data);
	        	mysql_fetch_field_row(data, "PermCarModel"); PermanentVehicleStatistics[i][PermCarModel] = strval(data);
	        	mysql_fetch_field_row(data, "PermCarFaction"); PermanentVehicleStatistics[i][PermCarFaction] = strval(data);
	        	mysql_fetch_field_row(data, "PermCarX"); PermanentVehicleStatistics[i][PermCarX] = floatstr(data);
	        	mysql_fetch_field_row(data, "PermCarY"); PermanentVehicleStatistics[i][PermCarY] = floatstr(data);
	        	mysql_fetch_field_row(data, "PermCarZ"); PermanentVehicleStatistics[i][PermCarZ] = floatstr(data);
	        	mysql_fetch_field_row(data, "PermCarRot"); PermanentVehicleStatistics[i][PermCarRot] = floatstr(data);
	        	mysql_fetch_field_row(data, "PermCarColor1"); PermanentVehicleStatistics[i][PermCarColors][1] = strval(data);
	        	mysql_fetch_field_row(data, "PermCarColor2"); PermanentVehicleStatistics[i][PermCarColors][2] = strval(data);
	        	mysql_fetch_field_row(data, "PermCarFamily"); PermanentVehicleStatistics[i][PermCarFamily] = strval(data);
	        	mysql_fetch_field_row(data, "PermCarVIP"); PermanentVehicleStatistics[i][PermCarVIP] = strval(data);
			}
	        vehicleid = AddStaticVehicleEx(PermanentVehicleStatistics[i][PermCarModel], PermanentVehicleStatistics[i][PermCarX], PermanentVehicleStatistics[i][PermCarY], PermanentVehicleStatistics[i][PermCarZ], PermanentVehicleStatistics[i][PermCarRot], PermanentVehicleStatistics[i][PermCarColors][1], PermanentVehicleStatistics[i][PermCarColors][2], 1800);
	        permcars++;
	        
	        if (IsABicycle(vehicleid) || IsATrain(vehicleid) || IsVehicleRCVehicle(vehicleid)) SetVehicleEngine(vehicleid, 1);
			else SetVehicleEngine(vehicleid, 0);
	        
			SavePermanentVehicle(i);
			
			//vehicleid = 0;
		}
		mysql_free_result();
	}
	return 1;
}
Stock for player vehicles:

Код:
stock LoadVehicles()
{
	new
	    query[128],
	    data[128],
		vehicleid;

	for (new i = 1; i < MAX_VEHICLES; i++)
	{
	    format(query, sizeof(query), "SELECT * FROM `vehicles` WHERE `veh_id` = '%d'", i);
		mysql_query(query);
		mysql_store_result();
		if (mysql_num_rows())
	    {
	        new model, Float:position[4];
            while (mysql_retrieve_row())
            {
	    		mysql_fetch_field_row(data, "veh_id");
				printf("Loading vehicle %d...", strval(data));
				VehicleEnum[vehicleid][veh_id] = strval(data);

                mysql_fetch_field_row(data, "veh_model"); model = strval(data);
				mysql_fetch_field_row(data, "veh_x"); position[0] = floatstr(data);
                mysql_fetch_field_row(data, "veh_y"); position[1] = floatstr(data);
                mysql_fetch_field_row(data, "veh_z"); position[2] = floatstr(data);
                mysql_fetch_field_row(data, "veh_rot"); position[3] = floatstr(data);
		        vehicleid = AddStaticVehicleEx(model, position[0], position[1], position[2], position[3], 1, 1, -1);

		        mysql_fetch_field_row(data, "veh_plate"); format(VehicleEnum[vehicleid][veh_plate], MAX_PLATE_LENGTH + 1, data);
		        mysql_fetch_field_row(data, "veh_owner"); format(VehicleEnum[vehicleid][veh_owner], MAX_PLAYER_NAME, data);

                mysql_fetch_field_row(data, "veh_price");
	  			VehicleEnum[vehicleid][veh_model] = model;
		        VehicleEnum[vehicleid][veh_owned] = 1;
		        VehicleEnum[vehicleid][veh_price] = strval(data);
		        VehicleEnum[vehicleid][veh_x] = position[0];
		        VehicleEnum[vehicleid][veh_y] = position[1];
		        VehicleEnum[vehicleid][veh_z] = position[2];
		        VehicleEnum[vehicleid][veh_rot] = position[3];

				for(new c = 1, var[32]; c < 18; c++)
				{
				    format(var, sizeof(var), "veh_component%d", c);
				    mysql_fetch_field_row(data, var);
				    VehicleEnum[vehicleid][veh_comp][c] = strval(data);
				}
				mysql_fetch_field_row(data, "veh_color1"); VehicleEnum[vehicleid][veh_colors][1] = strval(data);
				mysql_fetch_field_row(data, "veh_color2"); VehicleEnum[vehicleid][veh_colors][2] = strval(data);
				mysql_fetch_field_row(data, "veh_paintjob"); VehicleEnum[vehicleid][veh_paintjob] = strval(data);
				mysql_fetch_field_row(data, "veh_locked"); VehicleEnum[vehicleid][veh_locked] = strval(data);
				mysql_fetch_field_row(data, "veh_slot"); VehicleEnum[vehicleid][veh_slot] = strval(data);
				mysql_fetch_field_row(data, "veh_int"); VehicleEnum[vehicleid][veh_int] = strval(data);
				mysql_fetch_field_row(data, "veh_world"); VehicleEnum[vehicleid][veh_world] = strval(data);
				mysql_fetch_field_row(data, "veh_neon"); VehicleEnum[vehicleid][veh_neon] = strval(data);
				mysql_fetch_field_row(data, "veh_impounded"); VehicleEnum[vehicleid][veh_impounded] = strval(data);
				mysql_fetch_field_row(data, "veh_impoundprice"); VehicleEnum[vehicleid][veh_impoundprice] = strval(data);
	            mysql_fetch_field_row(data, "veh_haslock"); VehicleEnum[vehicleid][veh_haslock] = strval(data);
	            mysql_fetch_field_row(data, "veh_registerdate1"); VehicleEnum[vehicleid][veh_registerdate][1] = strval(data);
	            mysql_fetch_field_row(data, "veh_registerdate2"); VehicleEnum[vehicleid][veh_registerdate][2] = strval(data);
	            mysql_fetch_field_row(data, "veh_registerdate3"); VehicleEnum[vehicleid][veh_registerdate][3] = strval(data);
	            mysql_fetch_field_row(data, "veh_registerdate4"); VehicleEnum[vehicleid][veh_registerdate][4] = strval(data);
	            mysql_fetch_field_row(data, "veh_registerdate5"); VehicleEnum[vehicleid][veh_registerdate][5] = strval(data);
	            mysql_fetch_field_row(data, "veh_registerdate6"); VehicleEnum[vehicleid][veh_registerdate][6] = strval(data);
	            mysql_fetch_field_row(data, "NeonActivated"); NeonActivated[vehicleid] = strval(data);
	            mysql_fetch_field_row(data, "veh_trunkgun1"); VehicleEnum[vehicleid][veh_trunkgun1] = strval(data);
		        mysql_fetch_field_row(data, "veh_trunkgun2"); VehicleEnum[vehicleid][veh_trunkgun2] = strval(data);
		        mysql_fetch_field_row(data, "veh_trunkgun3"); VehicleEnum[vehicleid][veh_trunkgun3] = strval(data);
		        mysql_fetch_field_row(data, "veh_trunkgun4"); VehicleEnum[vehicleid][veh_trunkgun4] = strval(data);
		        mysql_fetch_field_row(data, "veh_trunkarmor"); VehicleEnum[vehicleid][veh_trunkarmor] = floatstr(data);
	            mysql_fetch_field_row(data, "veh_trunkcocaine"); VehicleEnum[vehicleid][veh_trunkcocaine] = strval(data);
	        	mysql_fetch_field_row(data, "veh_trunkweed"); VehicleEnum[vehicleid][veh_trunkweed] = strval(data);
	        	mysql_fetch_field_row(data, "veh_trunkmeth"); VehicleEnum[vehicleid][veh_trunkmeth] = strval(data);
	        	mysql_fetch_field_row(data, "veh_trunkheroin"); VehicleEnum[vehicleid][veh_trunkheroin] = strval(data);
	         	mysql_fetch_field_row(data, "veh_trunkmats"); VehicleEnum[vehicleid][veh_trunkmats] = strval(data);
	         	mysql_fetch_field_row(data, "veh_trunkcash"); VehicleEnum[vehicleid][veh_trunkcash] = strval(data);
			}
			ModifyVehicle(vehicleid);
			LinkVehicleToInterior(vehicleid, VehicleEnum[vehicleid][veh_int]);
			SetVehicleVirtualWorld(vehicleid, VehicleEnum[vehicleid][veh_world]);
			if(VehicleEnum[vehicleid][veh_locked]) LockVehicle(vehicleid);
			if (NeonActivated[vehicleid])
			{
			    AddNeonToVehicle(-1, vehicleid, VehicleEnum[vehicleid][veh_neon]);
			}
			if(vehicleid != INVALID_VEHICLE_ID) ownedcars++;
			if (IsABicycle(vehicleid) || IsATrain(vehicleid) || IsVehicleRCVehicle(vehicleid)) SetVehicleEngine(vehicleid, 1);
			else SetVehicleEngine(vehicleid, 0);
		}
		mysql_free_result();
	}
	return 1;
}
IF ANYTHING ELSE IS NEEDED PLEASE LET ME KNOW! THANKS AGAIN!
Reply
#2

Really needing some help if someone could take a look at this code!! Thanks!
Reply
#3

Does anyone have experience with this? Bump.
Reply
#4

Bump! Hoping someone can spot whats going wrong!
Reply
#5

I have been trying to solve the issue some more and it seems that if I set the MySQL column for vehicle ID to unique that the data will not get corrupted.

After doing so I have found that the issue may actually have to do with the way keys work. They are saved to a separate folder each player has a file and it identifies what car id goes into each players car slot as a key.

When starting the server the keys get cloned and overwritten like above but the SQL stays untouched.

Ive tried to go into the files and edit them to match the SQL and then start the server but it ends up cloning them again and it's not the same pattern of ids getting reused each time.

If anyone can help me please I would appreciate it a lot!
Reply
#6

This is the coding that loads the key data files.

Код:
stock VerifyVehicle(playerid, slot)
{
	new playername[24];
	GetPlayerName(playerid, playername, sizeof(playername));
	for(new i = 1; i < MAX_VEHICLES; i++)
	{
		if (strcmp(playername, VehicleEnum[i][veh_owner], false) == 0)
		{
		    if (slot == VehicleEnum[i][veh_slot])
		    {
		        if (VehicleKeys[playerid][slot] != i)
		        {
		            VehicleKeys[playerid][slot] = i;
				}
			}
		}
	}
	return 1;
}

public LoadVehicleKeys(playerid)
{
    //if(!IsPlayerConnected(playerid)) return 0;
    if(!gPlayerLogged[playerid]) return 1;
	new
	    filename[52],
		playername[24],
		string[48];
	GetPlayerName(playerid, playername, sizeof(playername));
	format(filename, sizeof(filename), "DealerInfo/keys/%s.kdat", playername);
	if(fexist(filename) && INI_Open(filename))
	{
	    for (new i = 1; i <= MAX_OWNED_CARS; i++)
	    {
	        format(string, sizeof(string), "VehicleKey%d", i);
			VehicleKeys[playerid][i] = INI_ReadInt(string);
		}
		INI_Close();
	}
	for (new i = 1; i <= MAX_OWNED_CARS; i++)
	{
		VerifyVehicle(playerid, i);
	}
	return 1;
}
Here is an example of the key data file.

VehicleKey1=867
VehicleKey2=0
VehicleKey3=0
VehicleKey4=0
VehicleKey5=0
VehicleKey6=0
VehicleKey7=0
VehicleKey8=0
VehicleKey9=0
VehicleKey10=0
VehicleKey11=0
VehicleKey12=0
VehicleKey13=0
VehicleKey14=0
VehicleKey15=0
VehicleKey16=0
VehicleKey17=0
VehicleKey18=0
VehicleKey19=0
VehicleKey20=0
Reply
#7

Anyone wanna take a stab at this?? Will appreciate it a lot!
Reply
#8

hi there,

I have got the same problem too, i wish someone would help
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)