CREATE PROCEDURE ACCOUNT_LOGIN
(
@AccountID varchar(21),
@Password varchar(13),
@nRet smallint OUTPUT
)
AS
BEGIN
DELETE FROM CURRENTUSER
WHERE strAccountID = @AccountID
DECLARE @cnt bigint
DECLARE @nDays smallint
DECLARE @pwd varchar(13)
-- Check if account exists
SELECT @nRet = COUNT(*)
FROM TB_USER
WHERE strAccountID = @AccountID
-- Auto register account
IF @nRet = 0
BEGIN
INSERT INTO TB_USER
(
strAccountID,
strPasswd,
strSocNo,
iDays
)
VALUES
(
@AccountID,
@Password,
1,
6
)
END
-- Current online users
SELECT @cnt = COUNT(*)
FROM CURRENTUSER
-- Premium days
SELECT @nDays = nDays
FROM PREMIUM_SERVICE
WHERE strAccountID = @AccountID
-- Server full check
IF @cnt > 40 AND (@nDays = 0 OR @nDays IS NULL)
BEGIN
SET @nRet = 0
RETURN
END
-- Get password
SELECT @pwd = strPasswd
FROM TB_USER
WHERE strAccountID = @AccountID
-- Account not found
IF @pwd IS NULL
BEGIN
SET @nRet = 0
RETURN
END
-- Password check
IF @pwd <> @Password
BEGIN
SET @nRet = 0
RETURN
END
-- Success
SET @nRet = 1
END