SF爱好求教:如何用lua实现游戏内调用数据库函数实现账号密码注册?

/************************************** 用户注册 **************************************/ ALTER PROCEDURE [dbo].[RegAccount]
@PlayerAccount char(20), @PlayerPassword char (20), @PlayerUserPwd char(20), @RetuValue int output

as declare @MaxPlayerID bigint, @TimeNow datetime, @UIDIncreaseOffset int, @MaxRegCount bigint

begin set @PlayerPassword = rtrim(@PlayerPassword); select @TimeNow = GETDATE(); select @MaxPlayerID = IdValue + 1 from SumTable where IndexId = 501; --查找当前用户的最大的PlayerUID号

if exists(select PlayerUID from PlayerID where Account = @PlayerAccount) --判断用户注册的用户名是否被注册过
begin   
    set @RetuValue = -1
    return ; 
end 
if exists(select PlayerUID from DreamWorkXYD_ESO.dbo.PlayerID where Account = @PlayerAccount)
begin   
    set @RetuValue = -1
    return ;
end
if exists(select PlayerUID from DreamWorkXYD_Unused.dbo.PlayerInfo where Account = @PlayerAccount)
begin   
    set @RetuValue = -1
    return;
end

update SumTable set IdValue = @MaxPlayerID where IndexId = 501;

begin Transaction
insert into PlayerID (Account,                                           
                      PlayerUID)
values(@PlayerAccount,
       @MaxPlayerID);
IF @@RowCount <> 1 GOTO Error 
insert into PlayerAccount (PlayerUID,    --保存用户信息
                           RegistTime,
                           UserPassword) 
values (@MaxPlayerID,
        @TimeNow,
        rtrim(@PlayerUserPwd)
        );
  IF @@RowCount <> 1 GOTO Error
insert into PlayerSecureQA(PlayerUID)
values (@MaxPlayerID)
IF @@RowCount <> 1 GOTO Error
Declare @date datetime

select @date =dateAdd(minute,1000,getdate()) --加40分钟

insert into PlayerCardPoint(PlayerUID,     --初始化用户游戏信息
                            --CardPoint,
                            [Password])
                            --FirstLogin,
                            --CardType,
                            --CardAvailableTime) 
values (@MaxPlayerID,
        --0,
        rtrim(@PlayerPassword))
        --convert(datetime, '1905-04-15'),
        --0,
       --null);

IF @@RowCount <> 1 GOTO Error Commit set @RetuValue = 1 return; Error: BEGIN ROLLBACK TRANSACTION SET @RetuValue = -1 RETURN END end

--------以下是游戏服务端lua脚本 RemoveObjectIndirect(111, 19033) CreateObjectIndirect( { regionId = 111,name = "注册",imageId = 0130, x = 8, y = 12 ,clickScript = 58339, dir = 4,objectType = 1, controlId = 19033} )

function OnClick58339() Zhuce()
end

function Zhuce() zhuce = zhuce or { cleanup = true, image_1 = "285,123,interface/faceplate/打造、鉴定1.spr", text_2 = "300,205,%\120请输入%\161账号*", text_3 = "300,250,%\120请输入%\161密码*", text_4 = "300,295,%\120请确认%\161密码*", ScriptEdit_8 = { pos = "400,205", Player = false,number = false, maxlength = 19}, ScriptEdit_9 = { pos = "400,250", Player = false,number = false, maxlength = 19}, ScriptEdit_10 = { pos = "400,295", Player = false,number = false, maxlength = 19}, SprButton_13 = { pos = "340,440", image = "Interface/okcancel/确定", action = "@rv,8,@rv,9,@rv,10,@rv,11,@rv,12,@E" },
SprButton_14 = { pos = "490,440", image = "Interface/okcancel/取消", action = "@E" },
} WndCustomize( zhuce, "Zhuce1" ) end

function Zhuce1(Account,Password,UserPwd)

if(Account == "" or Password == "" or UserPwd == "" )then   
    SetMessage(0,"账号密码必填,不能为空!!!#确定#",0,0)
    return
else
   if(PlayerPassword ~= PlayerUserPwd)then
        SetMessage(0,"两次密码不一致!!!#确定#",0,0)
        return
    else
        local call = {dbtype = 0, sp = 'RegAccount', args = 3, [1] = Account, [2] = Password, [3] = UserPwd}
        local callback = { callback = "Zhuce2", args = 1, [1] = "?4"}         
        DBRPC( call, callback )
    end
end

end

function Zhuce2(args) if(args == 1)then SetMessage(0,"注册成功。#确定#",0,0) elseif(args == 0)then SetMessage(0,"注册失败。#确定#",0,0) else SetMessage(0,"此账号已被注册。#确定#",0,0) end end

点赞