[Release] Correct DB SP for Punishment system.

10/30/2011 18:34 KOC2000#1
Hello,
Here's my fixed Stored Procedures for a working Punishment system (Both AutoPunishment and SMC SR_UserPunishment)

All you need is to execute the following fixed SP:-

_RegisterPunishment
PHP Code:
USE [SRO_VT_ACCOUNT]
GO
/****** Object:  StoredProcedure [dbo].[_RegisterPunishment]    UPDATED BY KOC2000 at: 10/30/2011 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- 
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
ALTER procedure [dbo].[_RegisterPunishment]
    @
UserJID     int,
    @
Type          tinyint,
    @
Executor    varchar(128),
    @
Shard        smallint,
    @
CharName    varchar(16),
    @
CharInfo    varchar(256),
    @
PosInfo    varchar(64),
    @
Guide        varchar(512),
    @
Description    varchar(1024),
    @
RaiseTime    datetime,
    @
BlockStartTime    datetime,
    @
BlockEndTime    datetime,
    @
PunishTime    datetime
as
    -- ?? ??? 
Blocking??? ?????
    if( 
existsselect UserJID from _BlockedUser with(NOLOCKwhere UserJID = @UserJID and Type = @Type))
    
begin
        select 
-1    -- ?? ??? ?? ??? ???
        RETURN
    
end
    
declare @NewSerialNo int    
    set 
@NewSerialNo 0
    
    insert _Punishment values
( @UserJID, @Type, @Executor, @Shard, @CharName, @CharInfo,
                @
PosInfo, @Guide, @Description, @RaiseTime, @BlockStartTime, @BlockEndTime, @PunishTime0)
    
set @NewSerialNo = @@identity
    
if( @@rowcount or @@error <> or @NewSerialNo or @NewSerialNo is null)
    
begin
        select 
-2    -- insert??? ?? ??
        return
    
end
    
    
-- Getting username (KiMO)
    declare @
UserID varchar(25)
    
SELECT @UserID StrUserID FROM TB_User WITH (NOLOCKWHERE JID = @UserJID
    
if( @@rowcount or @@error <> or @UserID is null)
    
BEGIN
        SELECT 
-1
        
RETURN
    
END
    
/*
    declare @UserID varchar(128)
    select @UserID = sr_id from sr_member1 where sr_code = @UserJID
    if( @@rowcount = 0 or @@error <> 0 or @UserID is null)
    begin
        select - 2
        return
    end
    */
    
    
-- ??? blocking? ????
    
insert _BlockedUser values( @UserJID, @UserID, @Type, @NewSerialNo, @BlockStartTime, @BlockEndTime)
    
select 0 

_UpdatePunishment
PHP Code:

USE [SRO_VT_ACCOUNT]
GO
/****** Object:  StoredProcedure [dbo].[_UpdatePunishment]    UPDATED BY KOC2000 at: 10/30/2011 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
--
ALTER procedure [dbo].[_UpdatePunishment]
    @
SerialNo    int,
    @
UserJID    int,
    @
Type        int,
    @
Executor    varchar(32),
    @
Shard        smallint,
    @
CharName    varchar(32),
    @
CharInfo    varchar(256),
    @
PosInfo    varchar(64),
    @
Guide        varchar(512),
    @
Description    varchar(1024),
    @
RaiseTime    datetime,
    @
BlockStartTime    datetime,
    @
BlockEndTime    datetime,
    @
PunishTime    datetime
as
    if( 
not existsselect SerialNo from _Punishment with(NOLOCKwhere SerialNo = @SerialNo))
    
begin
        select 
-1    -- valid?? ??
        RETURN
    
end
    
declare @NewSerialNo int    
    set 
@NewSerialNo 0
    
    
-- Getting username (KiMO)
    declare @
UserID varchar(25)
    
SELECT @UserID StrUserID FROM TB_User WITH (NOLOCKWHERE JID = @UserJID
    
if( @@rowcount or @@error <> or @UserID is null)
    
BEGIN
        SELECT 
-1
        
RETURN
    
END
    
/*
    declare @UserID varchar(128)
    select @UserID = sr_id from sr_member1 where sr_code = @UserJID
    if( @@rowcount = 0 or @@error <> 0 or @UserID is null)
    begin
        select -1
        return
    end
    */
    
    
update _Punishment set Status 1 where SerialNo = @SerialNo
    
    
-- ?? blocking? ????
    
delete _BlockedUser where UserJID = @UserJID
    
    insert _Punishment values
( @UserJID, @Type, @Executor, @Shard, @CharName, @CharInfo,
                @
PosInfo, @Guide, @Description, @RaiseTime, @BlockStartTime, @BlockEndTime, @PunishTime2)
    
set @NewSerialNo = @@identity
    
if( @@rowcount or @@error <> or @NewSerialNo or @NewSerialNo is null)
    
begin
        select 
-2    -- insert??? ?? ??
        return
    
end
    
-- ??? blocking? ????
    
insert _BlockedUser values( @UserJID, @UserID, @Type, @NewSerialNo, @BlockStartTime, @BlockEndTime)
    
select 0 

_RegisterAutomatedPunishment
PHP Code:

USE [SRO_VT_ACCOUNT]
GO
/****** Object:  StoredProcedure [dbo].[_RegisterAutomatedPunishment]    UPDATED BY KOC2000 at: 10/30/2011 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO

ALTER PROCEDURE 
[dbo].[_RegisterAutomatedPunishment]
    @
Account    VARCHAR(128),    --This is "strUserID"
    
@Type          TINYINT,
    @
Executor    VARCHAR(128),
    @
Guide        VARCHAR(512),
    @
Description    VARCHAR(1024),
    @
BlockTimeElapse    INT
AS
    ------------------------------------------------------------------------------------
    -- 
novice with deepdark
    
-- depend only on db time.. we dont have to sync the time between DB and GlobalManager for accuracy
    
DECLARE @BlockStartTime    VARCHAR(128)
    DECLARE @
BlockEndTime    VARCHAR(128)

    
SET @BlockStartTime     getdate()
    
SET @BlockEndTime    dateaddmi, @BlockTimeElapse, @BlockStartTime)
    ------------------------------------------------------------------------------------

    DECLARE @
UserJID INT
    SET 
@UserJID 0

    
-- Get UserJID from provided @Account.
    
SELECT @UserJID JID FROM TB_User WITH (NOLOCKWHERE strUserID = @Account
    
IF @@ERROR <> OR @UserJID 0
    BEGIN
        SELECT 
-1
        
RETURN
    
END
    
    
DECLARE    @return_value int
    
-- Check if user is blocked before and execute proper SP.
    IF( 
EXISTS SELECT UserJID FROM _BlockedUser WITH (NOLOCKWHERE UserJID = @UserJID AND Type = @Type))
    
BEGIN
        
DECLARE @SerialNo INT
        SET 
@SerialNo 0
        SELECT 
@SerialNo SerialNo FROM _Punishment WITH (NOLOCKWHERE UserJID = @UserJID
        EXEC    
@return_value = [dbo].[_UpdatePunishment] @SerialNo, @UserJID, @Type, @Executor,0'''''', @Guide, @Description, @BlockStartTime, @BlockStartTime, @BlockEndTime, @BlockStartTime
    END
    
    
ELSE 
    
BEGIN
        EXEC    
@return_value = [dbo].[_RegisterPunishment] @UserJID, @Type, @Executor,0'''''', @Guide, @Description, @BlockStartTime, @BlockStartTime, @BlockEndTime, @BlockStartTime
    END


    SELECT 
@UserJID 
10/30/2011 18:50 Miki Maus#2
Posting RZ stuff and claiming it as yours is not a nice thing.
10/31/2011 05:53 alexutublade#3
If u check the RZ forums you'll see that there is the same owner of the thread.
10/31/2011 15:21 ✗EpicSoul✗#4
nice copying skills..