[SQL] Character overwrite fix / Dupe fix

Junior Spellweaver
Joined
Sep 16, 2009
Messages
137
Reaction score
105
Since the database doesn't check while creating a player if the slot is already taken here's a fix.

Open CHARACTER_STR and search for
PHP:
IF @iGu = 'I1'
and add above
PHP:
DECLARE
this one
PHP:
 IF EXISTS(SELECT [isblock] FROM [CHARACTER_TBL] WHERE [playerslot] = @iplayerslot AND [serverindex] = @iserverindex AND [isblock] = 'F')
BEGIN
SELECT fError = '0', fText = 'Can not overwrite player!'
RETURN
END

Now maybe the question for what this is good.
---
The CHARACTER_STR procedure does not check while creating a character if the slot is already taken or not.
If you overwrite the Slot from a player it'll be able to dupe items or whatever.
It's checked whether if there is already an existing player or not. If so users won't be able to overwrite this slot.

It's not checked whether the text is case sensitive or not because the CHARACTER_TBL has Latin1_General_CI_AS as collate and it's case insensitive.
 
Last edited:
Hmm nice this will solve some things.

However i am an bit curious on how it works?

I understand that how its before the fix. That it only checks if the name is in use. But how will you overwrite the slot?
Cause when you log in with the same details to overwrite it it will DC the other window correct?
 
This fix will not work.

PHP:
IF (SELECT [isblock] FROM [CHARACTER_TBL] WHERE [playerslot] = @iplayerslot AND [account] = @iaccount AND [serverindex] = @iserverindex) = 'F'
BEGIN
    SELECT fError = '0', fText = 'Can not overwrite player!'
    RETURN
END

What would happen if

PHP:
SELECT [isblock] FROM [CHARACTER_TBL] WHERE [playerslot] = @iplayerslot AND [account] = @iaccount AND [serverindex] = @iserverindex

returned multiple entries?(multiple characters deleted on that slot)

It would return the first entry('D'), bypassing your check.

Try:

PHP:
IF EXISTS(SELECT [isblock] FROM [CHARACTER_TBL] WHERE [account] = @iaccount AND [playerslot] = @iplayerslot AND [serverindex] = @iserverindex AND [isblock] = 'F')
BEGIN
    SELECT fError = '0', fText = 'Can not overwrite player!'
    RETURN
END

[Strike]I also ommitted "[account] = @iaccount", because it's inefficient(strcmp on non-indexed field is resource intensive) and redundant.[/Strike]

- Edited: checking account field is necessary, my bad.
 
Last edited:
Back