CREATE procedure WZ_WriteMail
@SendName varchar(10),
@RecvName varchar(10),
@Subject varchar(32),
@Dir tinyint,
@Act tinyint
as
BEGIN
Set nocount on
DECLARE @userguid int
DECLARE @memocount int
DECLARE @return int
DECLARE @MemoTotal int
DECLARE @FriendLevel int
SET XACT_ABORT ON
SET @return = 0
-- b´Â »ç|ëTÚTÇ GUID¸¦ >H´Â´n
SELECT @userguid=GUID, @MemoTotal=MemoTotal FROM T_FriendMain where Name= @RecvName
if( @@ROWCOUNT < 1 )
BEGIN
SET @return = 2
GOTO EndProc
END
IF( @MemoTotal > 49 )
BEGIN
SET @return = 5
GOTO EndProc
END
-- ÄA±¸TÇ ·_§T» >H´Â´n.
select @FriendLevel=cLevel FROM Character where Name=@RecvName
IF( @@Error <> 0 )
begin
SET @return = 2
GOTO EndProc
end
ELSE
BEGIN
-- ·_§T 6_¸´n Tp´n¸é
if( @FriendLevel < 6 )
begin
SET @return = 6
GOTO EndProc
end
END
begin transaction
-- b´Â »ç|ëTÚTÇ íÁö YA¸¦ >H´Â´n.
update T_FriendMain set @memocount = MemoCount = MemoCount+1, MemoTotal=MemoTotal+1 where Name = @RecvName
if( @@error <> 0 )
BEGIN
SET @return = 3
GOTO EndProcTran
END
-- íÁö¸¦ ß°ÇÇC´n.
INSERT INTO T_FriendMail (MemoIndex, GUID, FriendName, wDate, Subject,bRead, Dir, Act) VALUES(@memocount,@userguid, @SendName, getdate(), @Subject, 0, @Dir, @Act)
if( @@error <> 0 )
BEGIN
SET @return = 4
GOTO EndProcTran
END
EndProcTran:
if ( @return <> 0 )
begin
rollback transaction
end
else
begin
commit transaction
SET @return = @memocount
end
EndProc:
SET XACT_ABORT OFF
Set nocount off
SELECT @return, @userguid
End
GO