Welcome!

Join our community of MMO enthusiasts and game developers! By registering, you'll gain access to discussions on the latest developments in MMO server files and collaborate with like-minded individuals. Join us today and unlock the potential of MMO server development!

Join Today!

GunZ 2 Alpha Source Code

Praise the Sun!
Loyal Member
Joined
Dec 4, 2007
Messages
2,502
Reaction score
986
It's yes right? Of course it's yes.

Yes, of course, there's plenty of highly experienced programmers out here. Just not in this particular section.

On-topic:
Keep in might you need in order for GNetwork to compile.
 
Pee Aitch Pee
Joined
Mar 30, 2011
Messages
630
Reaction score
422
Hereby a few mirrors of the client files. (Depositfiles is awful slow.)

 
Last edited:
Praise the Sun!
Loyal Member
Joined
Dec 4, 2007
Messages
2,502
Reaction score
986
Hereby a few mirrors of the client files. (Depositfiles is awful slow.)


Might take a while before Multiupload is done processing the uploads.

Thanks, I was about to cancel my broadband subscription and go back to a dialup connection since that'd probably be faster on depositfiles.

Edit:
Oh, I missed out on the sdk and client files folder, disregard my previous post.
 
Sharing is caring
Developer
Joined
Feb 1, 2007
Messages
2,086
Reaction score
728
How about u guise put your differences aside and collab on dev instead of being lone wolfs?
Been since Brittle Bullet anyway since I played a great Gunz server anyway.
Get at it Dagan, Peter, Jacob and the rest of the brady bunch.
Ok the heck with it, let even Dawson join in, just don't give stuff that's too good, he'll sell it (cause he's scum).
I love u guise.
 
Joined
Feb 4, 2010
Messages
2,204
Reaction score
1,012
How about u guise put your differences aside and collab on dev instead of being lone wolfs?
Been since Brittle Bullet anyway since I played a great Gunz server anyway.
Get at it Dagan, Peter, Jacob and the rest of the brady bunch.
Ok the heck with it, let even Dawson join in, just don't give stuff that's too good, he'll sell it (cause he's scum).
I love u guise.

I'd classify warz as "good" ain't sellin' that, nor am I even using it. Not sure where you get this preconceived notion of scum from. Alas, i'm better than this and will only get baited into one reply, any further attempts to sully my good name will only look bad on your behalf, a case of "trying too hard".
 
Sharing is caring
Developer
Joined
Feb 1, 2007
Messages
2,086
Reaction score
728
I'd classify warz as "good" ain't sellin' that, nor am I even using it. Not sure where you get this preconceived notion of scum from. Alas, i'm better than this and will only get baited into one reply, any further attempts to sully my good name will only look bad on your behalf, a case of "trying too hard".

Case of "joking" good sir.
You pulled me some crap, sure, but you gave stuff also that never saw the public.
If I was such a big meanie, would'nt I have dropped Gunz 2 and Raiderz by now then?
I have no grudges, you seem to have one for reasons unknown to me.
 
2D > 3D
Loyal Member
Joined
Dec 19, 2008
Messages
2,413
Reaction score
1,193
Ill work on the 3D side of things if someone were to start working on something, being held to RealSpace 2 gets kinda lame after awhile.

(Already worked with RS3 a bit with RaiderZ, GunZ 2 shouldnt be much different.)
 
Retired. Don't PM.
Developer
Joined
Jan 5, 2009
Messages
593
Reaction score
741
I'd be down for working on this source as a community effort in my spare time.

It would be cool if we made our own version of what the GunZ community envisions a game like GunZ2 would be like.
 
Daemonsring Developer
Joined
Jul 10, 2007
Messages
679
Reaction score
262
I'd be down for working on this source as a community effort in my spare time.

It would be cool if we made our own version of what the GunZ community envisions a game like GunZ2 would be like.
Or just port GunZ to realspace 3 *cough*
 
Joined
Feb 4, 2010
Messages
2,204
Reaction score
1,012


Blah blah randomly realized "Why do I suddenly have a lisp I dont normally have" blah blah, rambled about poop. I want you all to take this project on blah blah. Just generally making sure you all get the point that I want to see poop get done you all have immense amount of talent for just being fans of a game, you're dedicated to what you do. Make me proud :) (Come back Travis and Dagan! :eek:)

Oh, sorry for lack of new footage to talk over, no time for test server, sorry!
 
Praise the Sun!
Loyal Member
Joined
Dec 4, 2007
Messages
2,502
Reaction score
986
I'd be down for working on this source as a community effort in my spare time.

It would be cool if we made our own version of what the GunZ community envisions a game like GunZ2 would be like.

It would actually be cool if there was to be a real team working on this for sure.
 
Joined
Sep 1, 2011
Messages
453
Reaction score
191


Blah blah randomly realized "Why do I suddenly have a lisp I dont normally have" blah blah, rambled about poop. I want you all to take this project on blah blah. Just generally making sure you all get the point that I want to see poop get done you all have immense amount of talent for just being fans of a game, you're dedicated to what you do. Make me proud :) (Come back Travis and Dagan! :eek:)

Oh, sorry for lack of new footage to talk over, no time for test server, sorry!
qq I may just throw up a test server we will see (or i can just supply a dedi if you want to?). Been missing you mr dawson -_- And I don't even see you on skype or msn anymore anyways. Sad to see you leave. ):

Or just port GunZ to realspace 3 *cough*
Its being worked on by all sorts of people. I only know of a couple of people that really did get progress with Rs3. I've been working on it alone for the past few months on and off however I didn't get any really progress. I'd like to see that project come out of the shadows, I'm sure anyone that's tried or that is working on it currently can contest that its not easy.
 
Retired. Don't PM.
Developer
Joined
Jan 5, 2009
Messages
593
Reaction score
741
How about a team like you, Jacob, Secrets, Secured, PenguinGuy, n1x, Wucas and Ryo for the bigger good?

Yeah I'll be working on this in my spare time regardless of what happens or who works on it. If anyone is interested I can set up a subversion and you can watch my progress. I'll give read access to the public and write access to whomever.

At the end of the day though I think we should work on this in the public eye.
No closed source poop, no hoarding code until it's relatively developed to the point where we can customize a server.
No withholding exploits, I don't want people crashing each other's work.
And lastly, no infighting amongst developers. We have a common goal now, let's not duck this one up.
 
Experienced Elementalist
Joined
Feb 15, 2007
Messages
206
Reaction score
137
that will be good for all who want to learn and interested to complete this game, subversion its a good choice, we'll do a svn- checkout for each revision committed and the public users like us could release some stuff in the near future and maybe you will add that to the working folder.
 
Joined
Apr 18, 2010
Messages
674
Reaction score
393
I'll see what I can do. As it is now I'm running GunzDev's standalone build to see if my computer is capable of even running this game, I can't afford a new PSU and graphics card now :( All I'm getting is shenanigans with thread's read/write permissions. Great.

If I am capable I'll pitch in on my free time.
 
2D > 3D
Loyal Member
Joined
Dec 19, 2008
Messages
2,413
Reaction score
1,193
Ill be busy in mid to late 2013, seeing I have to switch Unis and everything, but I'm game to work on stuff until then. Would be quite fun to work with some of the older devs again.

I really can't do much until we at least get some basic groundwork laid though (since programming is quite beyond me), but as for the XML scripting and stuff, I could work with that until I can actually get ingame.
 
Joined
Jan 4, 2007
Messages
1,600
Reaction score
217
I would chip in some of my knowledge for this huge project.

Anyway, the database is extremely incomplete in this. Recreated some stored procedures, and only managed to get here so far:

X4yNG - GunZ 2 Alpha Source Code - RaGEZONE Forums
 

Attachments

You must be registered for see attachments list
Joined
Sep 10, 2007
Messages
970
Reaction score
815
Oh, did not Dawson not include the database?

Structure:
Code:
CREATE TABLE ChallengeQuestionRecord 
(
	ChallengeQuestionID		int NOT NULL
	, CID					int NOT NULL
	, SecondTime 			int NOT NULL
) 
GO
----------------------------------------------------------------------------------------------
          
		  
CREATE TABLE Character 
(
	CID	 			int 		NOT NULL	IDENTITY(1,1) 
	, AID 			int 		NOT NULL
	, DeleteFlag 	bit 		NOT NULL
	, SlotIndex 	smallint 	NOT NULL	DEFAULT(0)
	, CharPlayTime	int	 		NOT NULL	DEFAULT(0)
	, Sex 			tinyint 	NOT NULL	DEFAULT(0)
	, Class 		tinyint		NOT NULL	DEFAULT(0)
	, AdminLevel 	tinyint		NOT NULL
	, BP 			int 		NOT NULL
	, Cash 			int 		NOT NULL
	, Level 		smallint	NOT NULL	DEFAULT(1)
	, Name 			nvarchar(20) NOT NULL	DEFAULT(N'UnKnown')
	, LatestBattleType tinyint 	NOT NULL	DEFAULT(0)
) 
GO
----------------------------------------------------------------------------------------------




CREATE TABLE CharacterLook 
(
	AID 			int NOT NULL
	, CID 			int NOT NULL
	, DeleteFlag 		bit NOT NULL	DEFAULT(0)
	, UnderwearItemID	int NOT NULL	DEFAULT(0)
	, UnderwearColor 	int NOT NULL	DEFAULT(0)
	, TopItemID 		int NOT NULL	DEFAULT(0)
	, TopColor		int NOT NULL	DEFAULT(0)
	, PantsItemID		int NOT NULL	DEFAULT(0)
	, PantsColor 		int NOT NULL	DEFAULT(0)
	, HandItemID 		int NOT NULL	DEFAULT(0)	
	, HandColor		int NOT NULL	DEFAULT(0)
	, FootItemID		int NOT NULL	DEFAULT(0)
	, FootColor 		int NOT NULL	DEFAULT(0)
	, BackItemID 		int NOT NULL	DEFAULT(0)
	, BackColor 		int NOT NULL	DEFAULT(0)
	, HeadItemID 		int NOT NULL	DEFAULT(0)
	, HeadColor		int NOT NULL	DEFAULT(0)
	, FaceItemID 		int NOT NULL	DEFAULT(0)
	, FaceColor 		int NOT NULL	DEFAULT(0)
	, EarringItemID 	int NOT NULL	DEFAULT(0)
	, EarringColor 		int NOT NULL	DEFAULT(0)
	, NeckItemID 		int NOT NULL	DEFAULT(0)
	, NeckColor	 	int NOT NULL	DEFAULT(0)
	, FingerItemID 		int NOT NULL	DEFAULT(0)
	, FingerColor 		int NOT NULL	DEFAULT(0)
	, SetItemID 		int NOT NULL	DEFAULT(0)
	, SetColor 		int NOT NULL	DEFAULT(0) 
) 
GO
----------------------------------------------------------------------------------------------




CREATE TABLE CharBattleRecord 
(
	CID		int 		NOT NULL
	, Type	smallint	NOT NULL
	, Value int 		NOT NULL
)
GO
----------------------------------------------------------------------------------------------




CREATE TABLE ChoiceProduct 
(
	ChoiceProdID		bigint	NOT NULL	IDENTITY(1,1)
	, CID 				int 	NOT NULL
	, Type 				tinyint	NOT NULL
	, ProdSellPoliID	int		NOT NULL
	, ProdID 			int	 	NOT NULL
)
GO
----------------------------------------------------------------------------------------------




CREATE TABLE Friend 
(
	CID			int NOT NULL
	, FriendCID	int NOT NULL
)
GO
----------------------------------------------------------------------------------------------




CREATE TABLE ItemInstance 
( 
	IUID				bigint 		NOT NULL	IDENTITY(1,1)
	, ItemID 			int		 	NOT NULL
	, CID 				int	 		NOT NULL
	, Durability		float		NOT NULL
	, Color				int 		NOT NULL
	, SlotType			tinyint 	NOT NULL
	, SlotID 			smallint	NOT NULL
	, UsagePeriod		int 		NOT NULL
	, AddUsagePeriod	int 		NOT NULL	DEFAULT(0)
	, ExpiDate			datetime 	NULL
	, CharPlayTime		int 		NOT NULL
	, UseCharPlayTime	int 		NOT NULL	DEFAULT(0)
	, AccumuUsageTime	int 		NOT NULL	DEFAULT(0)
	, UsageState		tinyint		NOT NULL	DEFAULT(0)
	, ExpirationType	tinyint 	NOT NULL	DEFAULT(0)
) 
GO
----------------------------------------------------------------------------------------------




CREATE TABLE Login 
(
	AID		int 			NOT NULL 	IDENTITY(1,1) 
	, ID 	nvarchar(20) 	NOT NULL	DEFAULT(N'UnKnown')
	, PWD 	nvarchar(20) 	NOT NULL	DEFAULT(N'None')
) 
GO
----------------------------------------------------------------------------------------------




CREATE TABLE ServerList 
(
	ID			int 	NOT NULL
	, Type		tinyint NOT NULL
	, GSID 		bigint 	NOT NULL
	, TCPPort 	int 	NOT NULL
	, UDPPort	int		NOT NULL
	, Name		varchar(50) NOT NULL	DEFAULT('None')
	, IP 		varchar(50) NOT NULL	DEFAULT('0.0.0.0')
	, Memo		varchar(100) NOT NULL	DEFAULT('None')
	, KeeperID	smallint NOT NULL		DEFAULT(0)
) 
GO
----------------------------------------------------------------------------------------------




CREATE TABLE KeeperList 
(
	ID		int	 		NOT NULL
	, IP 	varchar(24) NOT NULL
	, Port 	int	 		NOT NULL
	, Name 	varchar(24) NOT NULL
) 
GO
----------------------------------------------------------------------------------------------




CREATE TABLE ServerOperationLog 
(
	OperationID		int	 	NOT NULL	IDENTITY(1,1)
	, ProgramID 	int	 	NOT NULL
	, SrartTime 	datetime NOT NULL
	, EndTime	 	datetime NULL
) 
GO
----------------------------------------------------------------------------------------------




CREATE TABLE ServerPatchLog 
(
	ProgramID 		int			NOT NULL
	, PatchTime 	datetime	NOT NULL
	, PatchResult 	int 		NOT NULL
) 
GO
----------------------------------------------------------------------------------------------




CREATE TABLE ServerPatchSchedule 
( 
	PatchID			int 		NOT NULL	IDENTITY(1,1)
	, KeeperID	 	int 		NOT NULL
	, ProgramID 	int 		NOT NULL
	, PatchTime 	datetime	NOT NULL
	, CycleMinute 	int 		NULL
) 
GO
----------------------------------------------------------------------------------------------






CREATE TABLE PlayerDataStageSetup 
(
	ID			int	 	NOT NULL	IDENTITY(1,1)
	, CID 			int	 		NOT NULL 
	, BattleType	smallint 	NOT NULL
	, Name			nvarchar(33) NOT NULL	
	, MapID 		smallint NOT NULL 
	, MaxPlayer 	smallint NOT NULL 
	, BattleRoundNum 		smallint NOT NULL 
	, BattleTime 		smallint NOT NULL 
) 
GO
----------------------------------------------------------------------------------------------








CREATE TABLE [dbo].[GameLog_BattleInfo] 
(
	BattleUID		bigint		NOT NULL	IDENTITY(1,1)
	, MasterCID	 	int			NOT NULL 
	, MasetrServerGroupNum	smallint	NOT NULL 
	, HostCID		int 		NOT NULL
	, HostServerGroupNum	smallint	NOT NULL
	, MapID	 		int 		NOT NULL
	, BattleType 	smallint	NOT NULL
	, RoundCount	smallint	NOT NULL
	, PlayTime		smallint 	NOT NULL
	, StartDate		smalldatetime NOT NULL
	, EndDate 		smalldatetime NOT NULL
	, IsCompleted 	tinyint 	NOT NULL
)
GO
----------------------------------------------------------------------------------------------         
           
CREATE TABLE [dbo].[GameLog_KillDeath]
(
	BattleUID		bigint	NOT NULL,
	RoundNumber		smallint NOT NULL, 
	AttackerCID		int		NOT NULL,
	VictimCID		int		NOT NULL,
	AttackerServerGroupNum	smallint	NOT NULL,
	VictimServerGroupNum		smallint	NOT NULL,
	AttackerNPCID	int		NOT NULL,
	VictimNPCID		int		NOT NULL,
	WeaponID		int		NOT NULL,
	REG_DATE		datetime NOT NULL
)
GO
----------------------------------------------------------------------------------------------


CREATE TABLE [dbo].[GameLog_WeaponShot]
(
	BattleUID	bigint		NOT NULL,
	RoundNumber		smallint NOT NULL, 
	CID			int			NOT NULL,
	PlayerServerGroupNum	smallint		NOT NULL,
	WeaponID	int			NOT NULL,
	FireCount	int			NOT NULL,
	HitCount	int			NOT NULL,
	Damage		int			NOT NULL, 
	REG_DATE	datetime	NOT NULL
) 
GO
----------------------------------------------------------------------------------------------


CREATE TABLE [dbo].[GameLog_WeaponTime]
(
	BattleUID	bigint	NOT NULL,
	CID			int		NOT NULL, 
	PlayerServerGroupNum	smallint		NOT NULL,
	WeaponID	int		NOT NULL,
	UseTime		int		NOT NULL, 
	REG_DATE	datetime NOT NULL
) 
GO 
----------------------------------------------------------------------------------------------




CREATE TABLE [dbo].[GameLog_REFDATA_ITEM](
	[ID] [int] NOT NULL,
	[Name] [nvarchar](50) NOT NULL,
	[Type] [int] NOT NULL,
	[Level] [smallint] NOT NULL,
	[Sex] [smallint] NOT NULL,
	[CharRes] [smallint] NOT NULL,
	[WeaponType] [smallint] NOT NULL,
	[ItemType] [int] NOT NULL,
	[Description] [nvarchar](150) NOT NULL,
 CONSTRAINT [PK_GameLog_REFDATA_ITEM] PRIMARY KEY CLUSTERED 
(
	[ID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]


GO

Stored procs:
Code:
CREATE PROCEDURE spChangeEquItemInstance
(
	@IUID1 bigint, @SlotID1 smallint, @UseCharPlayTime1 int, @AccumuUsageTime1 int,  
	@IUID2 bigint, @SlotID2 smallint, @UseCharPlayTime2 int, @AccumuUsageTime2 int,  
	@IUID3 bigint, @SlotID3 smallint, @UseCharPlayTime3 int, @AccumuUsageTime3 int 
)
AS	
BEGIN
	SET NOCOUNT ON;
	DECLARE @RowCount	int
	
	BEGIN TRAN
	
	-- 1
	UPDATE ItemInstance SET SlotID=@SlotID1, UseCharPlayTime=@UseCharPlayTime1, 
				AccumuUsageTime=@AccumuUsageTime1 WHERE IUID=@IUID1;	SET @RowCount = @@ROWCOUNT	
	
	IF( @RowCount < 1 OR @@ERROR <> 0 )
	BEGIN
		GOTO ERROR_HANDLER;
	END
	
	-- 2
	IF( @IUID2 <> 0 )
	BEGIN
		UPDATE ItemInstance SET SlotID=@SlotID2, UseCharPlayTime=@UseCharPlayTime2, 
				AccumuUsageTime=@AccumuUsageTime2 WHERE IUID=@IUID2;	SET @RowCount = @@ROWCOUNT	
		
		IF( @RowCount < 1 OR @@ERROR <> 0 )
		BEGIN
			GOTO ERROR_HANDLER;
		END
	END
	
	-- 3
	IF( @IUID3 <> 0 )
	BEGIN
		UPDATE ItemInstance SET SlotID=@SlotID3, UseCharPlayTime=@UseCharPlayTime3, 
				AccumuUsageTime=@AccumuUsageTime3 WHERE IUID=@IUID3;	SET @RowCount = @@ROWCOUNT	
		
		IF( @RowCount < 1 OR @@ERROR <> 0 )
		BEGIN
			GOTO ERROR_HANDLER;
		END
	END
	
	
	COMMIT TRAN
	return;
	
ERROR_HANDLER:
	IF @@TRANCOUNT <> 0 ROLLBACK TRAN
	
	RAISERROR(N'Failed Update IUID1(%d), IUID2(%d), IUID3(%d).'
		, 11
		, 1
		, @IUID1, @IUID2, @IUID3);
END
GO
-------------------------------------------------------------------------------------------------------




CREATE PROC spCharBattleRecordUpdate
(
	  @Update VARCHAR(2000)
	, @Insert VARCHAR(2000)
)
AS
BEGIN
	SET NOCOUNT ON;


	BEGIN TRAN;


	UPDATE cbr
	SET	   cbr.Value = cbr.Value + C.Value
	FROM  (SELECT B.CID
				, CAST(SUBSTRING(B.Val, 1, CHARINDEX('.', B.Val) - 1) AS SMALLINT) Kind	 
				, CAST(SUBSTRING(B.Val + '.', CHARINDEX('.', B.Val) + 1, LEN(B.Val) - CHARINDEX('.', B.Val)) AS INT) Value
		   FROM  (SELECT CAST(SUBSTRING(A.val_str, 1, CHARINDEX('.', A.val_str) - 1) AS INT) CID	 
					   , SUBSTRING(A.val_str + '.', CHARINDEX('.', A.val_str) + 1, LEN(val_str) - CHARINDEX('.', A.val_str)) Val
				  FROM  (SELECT LTRIM(RTRIM(SUBSTRING(@Update, c.num, CHARINDEX(',', @Update + ',', c.num) - c.num))) AS val_str
			  			 FROM   dbo.cpt c
						 WHERE  c.num <= LEN(@Update)
						 AND	SUBSTRING(',' + @Update, c.num, 1) = ',') A) B) C
		 , dbo.CharBattleRecord cbr
	WHERE  cbr.CID = C.CID AND cbr.Type = C.Type;
	
	IF (0 <> @@ERROR) 
	BEGIN
		ROLLBACK TRAN;
		RAISERROR(N'ERROR BATTLE UPDATE.', 11, 1);
	END




	INSERT INTO dbo.CharBattleRecord(CID, Type, Value)
	SELECT B.CID
		 , CAST(SUBSTRING(B.Val, 1, CHARINDEX('.', B.Val) - 1) AS SMALLINT) Type	 
		 , CAST(SUBSTRING(B.Val + '.', CHARINDEX('.', B.Val) + 1, LEN(B.Val) - CHARINDEX('.', B.Val)) AS INT) Value
	FROM  (SELECT CAST(SUBSTRING(A.val_str, 1, CHARINDEX('.', A.val_str) - 1) AS INT) CID	 
				, SUBSTRING(A.val_str + '.', CHARINDEX('.', A.val_str) + 1, LEN(val_str) - CHARINDEX('.', A.val_str)) Val
		   FROM  (SELECT LTRIM(RTRIM(SUBSTRING(@Insert, c.num, CHARINDEX(',', @Insert + ',', c.num) - c.num))) AS val_str
				  FROM   dbo.cpt c
				  WHERE  c.num <= LEN(@Insert)
				  AND	  SUBSTRING(',' + @Insert, c.num, 1) = ',') A) B;
				  
	IF (0 <> @@ERROR) 
	BEGIN
		ROLLBACK TRAN;
		RAISERROR(N'ERROR BATTLE INSERT.', 11, 1);
	END


	COMMIT TRAN;
END
GO
-------------------------------------------------------------------------------------------------------




CREATE PROC spDeleteCharacter
(
	@cid int
)
AS
BEGIN
	SET NOCOUNT ON;


	UPDATE Character SET DeleteFlag = 1 WHERE cid = @cid


	IF (0 = @@ROWCOUNT)
	BEGIN
		RAISERROR(N'invalid character(CID:%d).'
			, 11
			, 1
			, @CID);
	END


	UPDATE CharacterLook SET DeleteFlag = 1 WHERE CID = @cid
	UPDATE ItemInstance SET UsageState = 10 WHERE CID = @cid
	DELETE FROM Friend WHERE CID = @cid OR FriendCID = @cid
	DELETE FROM ChoiceProduct WHERE CID = @cid
END
GO
-------------------------------------------------------------------------------------------------------




CREATE PROC spDeleteChoiceProduct
(
	@ChoiceProdID bigint
)
AS
BEGIN
	SET NOCOUNT ON;


	DELETE FROM ChoiceProduct WHERE ChoiceProdID = @ChoiceProdID


	IF (0 = @@ROWCOUNT)
	BEGIN
		RAISERROR(N'invalid ChoiceProdID(ChoiceProdID:%I64d).'
			, 11
			, 1
			, @ChoiceProdID);
	END
END
GO
-------------------------------------------------------------------------------------------------------




CREATE PROC spDeleteFriend
(
	@CID int,
	@FriendCID	int
)
AS
BEGIN
	SET NOCOUNT ON;
	DELETE FROM Friend WHERE CID = @CID AND FriendCID = @FriendCID


	IF (0 = @@ROWCOUNT)
	BEGIN
		RAISERROR(N'invalid character(CID:%d), friend(CID:%d).'
			, 11
			, 1
			, @CID, @FriendCID);
	END
END
GO
-------------------------------------------------------------------------------------------------------




CREATE PROC spDeleteItemInstance
(
	@CID	int,
	@IUID	bigint
)
AS
BEGIN
	SET NOCOUNT ON;
	UPDATE ItemInstance SET UsageState = 10 WHERE CID = @CID AND IUID = @IUID
END	
GO
-------------------------------------------------------------------------------------------------------




CREATE PROC spDeletePatchSchedule
(
	@PatchID int
)
AS
BEGIN
	DELETE FROM ServerPatchSchedule WHERE PatchID = @PatchID
END
GO
-------------------------------------------------------------------------------------------------------




CREATE PROC spDevAddItemInstance
(
	@ItemId int,
	@CID int,
	@Durability float,
	@SlotType tinyint,
	@CurTime int,
	@ExpirationType tinyint,
	@UsagePeriod int
)
AS
BEGIN
	SET NOCOUNT ON;
	DECLARE @IUID bigint


	INSERT INTO ItemInstance (ItemID, CID, Durability, Color, SlotType, 
				SlotID, UsagePeriod, AddUsagePeriod, CharPlayTime, UseCharPlayTime, AccumuUsageTime, 
				UsageState, ExpirationType ) VALUES 
				(@ItemId, @CID, @Durability, 0, @SlotType, 
				-1, @UsagePeriod, 0, @CurTime, 0, 0, 
				0, @ExpirationType)


	SET @IUID = SCOPE_IDENTITY()
	SELECT @IUID AS IUID
END
GO
-------------------------------------------------------------------------------------------------------




CREATE PROC spInsertCharacter
(
	@AID int,
	@Name nvarchar(20),
	@SlotIndex smallint,
	@Sex tinyint,
	@Class tinyint
)
AS
BEGIN
	SET NOCOUNT ON;
	DECLARE @FindCID int
	SELECT @FindCID = CID FROM Character WHERE Name = @Name AND DeleteFlag = 0
	IF (@FindCID is not null)
	BEGIN
		SELECT CID = -1
		return
	END
	
	INSERT INTO Character (AID, Name, DeleteFlag, SlotIndex, Sex, Class, Level, AdminLevel, BP, Cash) 
	VALUES (@AID, @Name, 0, @SlotIndex, @Sex, @Class, 1, 0, 0, 0)
	
	SET @FindCID = SCOPE_IDENTITY()


	INSERT INTO CharacterLook (AID, CID) VALUES (@AID, @FindCID)
	/*
	IF (1 = @Class)
	BEGIN
		-- 1 Head(4)
		INSERT INTO ItemInstance (ItemID, CID, Durability, Color 
				   ,SlotType, SlotID, UsagePeriod, AddUsagePeriod, ExpiDate 
				   ,CharPlayTime, UseCharPlayTime, AccumuUsageTime, UsageState, ExpirationType) 
			 VALUES (10179002, @FindCID, 0, 0 
				   , 1, 17, 0, 0, '2011-12-25' 
				   , 0, 0, 0, 0, 0)
		--  2 Top(1)
		INSERT INTO ItemInstance (ItemID, CID, Durability, Color 
				   ,SlotType, SlotID, UsagePeriod, AddUsagePeriod, ExpiDate 
				   ,CharPlayTime, UseCharPlayTime, AccumuUsageTime, UsageState, ExpirationType) 
			 VALUES (10129002, @FindCID, 0, 0 
				   , 1, 12, 0, 0, '2011-12-25' 
				   , 0, 0, 0, 0, 0)
		-- 3 Pants(2)
		INSERT INTO ItemInstance (ItemID, CID, Durability, Color 
				   ,SlotType, SlotID, UsagePeriod, AddUsagePeriod, ExpiDate 
				   ,CharPlayTime, UseCharPlayTime, AccumuUsageTime, UsageState, ExpirationType) 
			 VALUES (10139002, @FindCID, 0, 0 
				   , 1, 13, 0, 0, '2011-12-25' 
				   , 0, 0, 0, 0, 0)
		-- 4 Hand(12)
		INSERT INTO ItemInstance (ItemID, CID, Durability, Color 
				  ,SlotType, SlotID, UsagePeriod, AddUsagePeriod, ExpiDate 
				   ,CharPlayTime, UseCharPlayTime, AccumuUsageTime, UsageState, ExpirationType) 
			 VALUES (10149002, @FindCID, 0, 0 
				   , 1, 14, 0, 0, '2011-12-25' 
				   , 0, 0, 0, 0, 0)
		-- 5 Foot(3)
		INSERT INTO ItemInstance (ItemID, CID, Durability, Color 
				   ,SlotType, SlotID, UsagePeriod, AddUsagePeriod, ExpiDate 
				   ,CharPlayTime, UseCharPlayTime, AccumuUsageTime, UsageState, ExpirationType) 
			 VALUES (10159002, @FindCID, 0, 0 
				   , 1, 15, 0, 0, '2011-12-25' 
				   , 0, 0, 0, 0, 0)
	END
	*/		  
	-- ¾î½Ø½Å 
	IF (1 = @Class)
	BEGIN		  
		-- ¸ÞÀÎ 1
		INSERT INTO ItemInstance (ItemID, CID, Durability, Color 
				   ,SlotType, SlotID, UsagePeriod, AddUsagePeriod, ExpiDate 
				   ,CharPlayTime, UseCharPlayTime, AccumuUsageTime, UsageState, ExpirationType) 
			 VALUES (10400001, @FindCID, 0, 0 
				   , 1, 101, 0, 0, '2012-12-25' 
				   , 0, 0, 0, 0, 0)
		-- ¸ÞÀÎ 2
		INSERT INTO ItemInstance (ItemID, CID, Durability, Color 
				   ,SlotType, SlotID, UsagePeriod, AddUsagePeriod, ExpiDate 
				   ,CharPlayTime, UseCharPlayTime, AccumuUsageTime, UsageState, ExpirationType) 
			 VALUES (10500002, @FindCID, 0, 0 
				   , 1, 102, 0, 0, '2012-12-25' 
				   , 0, 0, 0, 0, 0)           
		-- ¼­ºê 1
		INSERT INTO ItemInstance (ItemID, CID, Durability, Color 
				   ,SlotType, SlotID, UsagePeriod, AddUsagePeriod, ExpiDate 
				   ,CharPlayTime, UseCharPlayTime, AccumuUsageTime, UsageState, ExpirationType) 
			 VALUES (10560001, @FindCID, 0, 0 
				   , 1, 201, 0, 0, '2012-12-25' 
				   , 0, 0, 0, 0, 0)           
		-- ¸ÞÀÎ 3
		INSERT INTO ItemInstance (ItemID, CID, Durability, Color 
				   ,SlotType, SlotID, UsagePeriod, AddUsagePeriod, ExpiDate 
				   ,CharPlayTime, UseCharPlayTime, AccumuUsageTime, UsageState, ExpirationType) 
			 VALUES (10470001, @FindCID, 0, 0 
				   , 1, 103, 0, 0, '2012-12-25' 
				   , 0, 0, 0, 0, 0)           
		-- ¸ÞÀÎ 4
		INSERT INTO ItemInstance (ItemID, CID, Durability, Color 
				   ,SlotType, SlotID, UsagePeriod, AddUsagePeriod, ExpiDate 
				   ,CharPlayTime, UseCharPlayTime, AccumuUsageTime, UsageState, ExpirationType) 
			 VALUES (10420001, @FindCID, 0, 0 
				   , 1, 104, 0, 0, '2012-12-25' 
				   , 0, 0, 0, 0, 0)
		-- ¸ÞÀÎ 5
		INSERT INTO ItemInstance (ItemID, CID, Durability, Color 
				   ,SlotType, SlotID, UsagePeriod, AddUsagePeriod, ExpiDate 
				   ,CharPlayTime, UseCharPlayTime, AccumuUsageTime, UsageState, ExpirationType) 
			 VALUES (10440001, @FindCID, 0, 0 
				   , 1, 105, 0, 0, '2012-12-25' 
				   , 0, 0, 0, 0, 0)
	END
	
	-- ÆÄÀÌÅÍ
	IF (2 = @Class)
	BEGIN		  
		-- ¸ÞÀÎ 1
		INSERT INTO ItemInstance (ItemID, CID, Durability, Color 
				   ,SlotType, SlotID, UsagePeriod, AddUsagePeriod, ExpiDate 
				   ,CharPlayTime, UseCharPlayTime, AccumuUsageTime, UsageState, ExpirationType) 
			 VALUES (10410001, @FindCID, 0, 0 
				   , 1, 101, 0, 0, '2012-12-25' 
				   , 0, 0, 0, 0, 0)
		-- ¸ÞÀÎ 2
		INSERT INTO ItemInstance (ItemID, CID, Durability, Color 
				   ,SlotType, SlotID, UsagePeriod, AddUsagePeriod, ExpiDate 
				   ,CharPlayTime, UseCharPlayTime, AccumuUsageTime, UsageState, ExpirationType) 
			 VALUES (10510001, @FindCID, 0, 0 
				   , 1, 102, 0, 0, '2012-12-25' 
				   , 0, 0, 0, 0, 0)           
		-- ¼­ºê 1
		INSERT INTO ItemInstance (ItemID, CID, Durability, Color 
				   ,SlotType, SlotID, UsagePeriod, AddUsagePeriod, ExpiDate 
				   ,CharPlayTime, UseCharPlayTime, AccumuUsageTime, UsageState, ExpirationType) 
			 VALUES (10570001, @FindCID, 0, 0 
				   , 1, 201, 0, 0, '2012-12-25' 
				   , 0, 0, 0, 0, 0)           
		-- ¸ÞÀÎ 3
		INSERT INTO ItemInstance (ItemID, CID, Durability, Color 
				   ,SlotType, SlotID, UsagePeriod, AddUsagePeriod, ExpiDate 
				   ,CharPlayTime, UseCharPlayTime, AccumuUsageTime, UsageState, ExpirationType) 
			 VALUES (10430001, @FindCID, 0, 0 
				   , 1, 103, 0, 0, '2012-12-25' 
				   , 0, 0, 0, 0, 0)           
		-- ¸ÞÀÎ 4
		INSERT INTO ItemInstance (ItemID, CID, Durability, Color 
				   ,SlotType, SlotID, UsagePeriod, AddUsagePeriod, ExpiDate 
				   ,CharPlayTime, UseCharPlayTime, AccumuUsageTime, UsageState, ExpirationType) 
			 VALUES (10470001, @FindCID, 0, 0 
				   , 1, 104, 0, 0, '2012-12-25' 
				   , 0, 0, 0, 0, 0)
		-- ¸ÞÀÎ 5
		INSERT INTO ItemInstance (ItemID, CID, Durability, Color 
				   ,SlotType, SlotID, UsagePeriod, AddUsagePeriod, ExpiDate 
				   ,CharPlayTime, UseCharPlayTime, AccumuUsageTime, UsageState, ExpirationType) 
			 VALUES (10480001, @FindCID, 0, 0 
				   , 1, 105, 0, 0, '2012-12-25' 
				   , 0, 0, 0, 0, 0)
	END           
	
	-- Çìºñ
	IF (4 = @Class)
	BEGIN		  
		-- ¸ÞÀÎ 1
		INSERT INTO ItemInstance (ItemID, CID, Durability, Color 
				   ,SlotType, SlotID, UsagePeriod, AddUsagePeriod, ExpiDate 
				   ,CharPlayTime, UseCharPlayTime, AccumuUsageTime, UsageState, ExpirationType) 
			 VALUES (10450001, @FindCID, 0, 0 
				   , 1, 101, 0, 0, '2012-12-25' 
				   , 0, 0, 0, 0, 0)
		-- ¸ÞÀÎ 2
		INSERT INTO ItemInstance (ItemID, CID, Durability, Color 
				   ,SlotType, SlotID, UsagePeriod, AddUsagePeriod, ExpiDate 
				   ,CharPlayTime, UseCharPlayTime, AccumuUsageTime, UsageState, ExpirationType) 
			 VALUES (10460001, @FindCID, 0, 0 
				   , 1, 102, 0, 0, '2012-12-25' 
				   , 0, 0, 0, 0, 0)           
		-- ¸ÞÀÎ 3
		INSERT INTO ItemInstance (ItemID, CID, Durability, Color 
				   ,SlotType, SlotID, UsagePeriod, AddUsagePeriod, ExpiDate 
				   ,CharPlayTime, UseCharPlayTime, AccumuUsageTime, UsageState, ExpirationType) 
			 VALUES (10530001, @FindCID, 0, 0 
				   , 1, 103, 0, 0, '2012-12-25' 
				   , 0, 0, 0, 0, 0)           
		-- ¸ÞÀÎ 4
		INSERT INTO ItemInstance (ItemID, CID, Durability, Color 
				   ,SlotType, SlotID, UsagePeriod, AddUsagePeriod, ExpiDate 
				   ,CharPlayTime, UseCharPlayTime, AccumuUsageTime, UsageState, ExpirationType) 
			 VALUES (10550001, @FindCID, 0, 0 
				   , 1, 104, 0, 0, '2012-12-25' 
				   , 0, 0, 0, 0, 0)
		-- ¸ÞÀÎ 5
		INSERT INTO ItemInstance (ItemID, CID, Durability, Color 
				   ,SlotType, SlotID, UsagePeriod, AddUsagePeriod, ExpiDate 
				   ,CharPlayTime, UseCharPlayTime, AccumuUsageTime, UsageState, ExpirationType) 
			 VALUES (10470001, @FindCID, 0, 0 
				   , 1, 105, 0, 0, '2012-12-25' 
				   , 0, 0, 0, 0, 0)
	END
						  
			   
	select @FindCID AS CID
END
GO
-------------------------------------------------------------------------------------------------------




CREATE PROC spInsertChoiceProduct
(
	@CID int,
	@Type tinyint,
	@ProdSellPoliID int, 
	@ProdID int
)
AS
BEGIN
	SET NOCOUNT ON;
	DECLARE @ChoiceProdID bigint


	INSERT INTO ChoiceProduct (CID, Type, ProdSellPoliID, ProdID) 
	VALUES (@CID, @Type, @ProdSellPoliID, @ProdID)


	SET @ChoiceProdID = SCOPE_IDENTITY()
	SELECT @ChoiceProdID AS ChoiceProdID
END
GO
-------------------------------------------------------------------------------------------------------




CREATE PROC spInsertFriend
(
	@CID int,
	@FriendName varchar(20)
)
AS
BEGIN
	SET NOCOUNT ON;
	DECLARE @FindCID int
	
	SELECT @FindCID = CID FROM Character WHERE Name = @FriendName AND DeleteFlag = 0
	
	IF (@FindCID is null)
	BEGIN
		SELECT FriendCID = 0
		return
	END
	
	INSERT INTO Friend (CID, FriendCID) VALUES (@CID, @FindCID)
	SELECT FriendCID = @FindCID
END
GO
-------------------------------------------------------------------------------------------------------




CREATE PROC spInsertKeeperInfo
(
	@ID int,
	@IP varchar(24),
	@Port int,
	@Name varchar(24)
)
AS
BEGIN
	INSERT INTO KeeperList(ID, IP, Port, Name) VALUES (@ID, @IP, @Port, @Name)
END
GO
-------------------------------------------------------------------------------------------------------




CREATE PROC spInsertPatchSchedule
(
	@KeeperID int,
	@ProgramID int,
	@PatchTime datetime,
	@CycleMinute int
)
AS
BEGIN
	IF (@CycleMinute = 0 AND datediff(minute, getdate(), @PatchTime) < 0)
		return;


	INSERT INTO ServerPatchSchedule(KeeperID, ProgramID, PatchTime, CycleMinute) 
	VALUES (@KeeperID, @ProgramID, @PatchTime, @CycleMinute)
END
GO
-------------------------------------------------------------------------------------------------------




CREATE PROC spInsertProgramInfo
(
	@ProgramID int,
	@KeeperID int,
	@ProgramName varchar(32)
)
AS
BEGIN 
	INSERT INTO ProgramList(ProgramID, KeeperID, ProgramName) VALUES (@ProgramID, @KeeperID, @ProgramName)
END
GO
-------------------------------------------------------------------------------------------------------




CREATE PROC spInsertServerPatchLog
(
	@ProgramID int,
	@PatchResult int
)
AS
BEGIN
	INSERT INTO ServerPatchLog(ProgramID, PatchTime, PatchResult) VALUES (@ProgramID, getdate(), @PatchResult)
END
GO
-------------------------------------------------------------------------------------------------------




CREATE PROC spInsertServerStartLog
(
	@ProgramID int
)
AS
BEGIN 
	INSERT INTO ServerOperationLog (ProgramID, SrartTime, EndTime) VALUES (@ProgramID, getdate(), null)
END
GO
-------------------------------------------------------------------------------------------------------




CREATE PROC spInsertServerStopLog
(
	@ProgramID int
)
AS
BEGIN 
	DECLARE @FindOperationID int
	SELECT @FindOperationID = max(OperationID) FROM ServerOperationLog WHERE ProgramID = @ProgramID
	
	IF @FindOperationID is not null
	BEGIN
		UPDATE ServerOperationLog SET EndTime = getdate() WHERE OperationID = @FindOperationID
	END
END
GO
-------------------------------------------------------------------------------------------------------




CREATE PROC spLogin
(
	@ID nvarchar(20)
)
AS
BEGIN 
	SELECT AID, PWD FROM Login WHERE id = @ID
END
GO
-------------------------------------------------------------------------------------------------------




CREATE PROC spSaveCharacterData
(
	@CID int, @CharPlayTime int, @BP int, @LatestBattleType tinyint, 
	@SetItemID int, @SetColor int, @UnderwearItemID int, @UnderwearColor int, @TopItemID int, @TopColor int, 
	@PantsItemID int, @PantsColor int, @HandItemID int, @HandColor int, @FootItemID int, @FootColor int, 
	@BackItemID int, @BackColor int, @HeadItemID int, @HeadColor int, @FaceItemID int, @FaceColor int, 
	@EarringItemID int, @EarringColor int, @NeckItemID int, @NeckColor int, @FingerItemID int, @FingerColor int 
)
AS	
BEGIN
	set nocount on;
	DECLARE @RowCount	int
	
	BEGIN TRAN
	
	-- 1
	UPDATE Character SET CharPlayTime=@CharPlayTime, BP=@BP, LatestBattleType=@LatestBattleType WHERE CID=@CID;	SET @RowCount = @@ROWCOUNT	
	
	IF( @RowCount < 1 OR @@ERROR <> 0 )
	BEGIN
		SELECT UpdateRowCount = -1;
		GOTO ERROR_HANDLER;
	END
	
	-- 2
	UPDATE CharacterLook SET SetItemID=@SetItemID, SetColor=@SetColor, 
							UnderwearItemID=@UnderwearItemID, UnderwearColor=@UnderwearColor, 
							TopItemID=@TopItemID, TopColor=@TopColor, 
							PantsItemID=@PantsItemID, PantsColor=@PantsColor, 
							HandItemID=@HandItemID, HandColor=@HandColor, 
							FootItemID=@FootItemID, FootColor=@FootColor, 
							BackItemID=@BackItemID, BackColor=@BackColor, 
							HeadItemID=@HeadItemID, HeadColor=@HeadColor, 
							FaceItemID=@FaceItemID, FaceColor=@FaceColor, 
							EarringItemID=@EarringItemID, EarringColor=@EarringColor, 
							NeckItemID=@NeckItemID, NeckColor=@NeckColor, 
							FingerItemID=@FingerItemID, FingerColor=@FingerColor 
		WHERE CID=@CID;	SET @RowCount = @@ROWCOUNT	
	
	IF( @RowCount < 1 OR @@ERROR <> 0 )
	BEGIN
		SELECT UpdateRowCount = -2;
		GOTO ERROR_HANDLER;
	END
	
		
	COMMIT TRAN
	SELECT UpdateRowCount = 1
	return;
	
ERROR_HANDLER:
	IF @@TRANCOUNT <> 0 ROLLBACK TRAN
END
GO
-------------------------------------------------------------------------------------------------------




CREATE PROC spSelectChallengeQuestionNumber
(
	@CID	int
)
AS
BEGIN
	SET NOCOUNT ON;


	SELECT ChallengeQuestionID FROM ChallengeQuestionRecord WITH (NOLOCK)
	WHERE CID = @CID 
END
GO
-------------------------------------------------------------------------------------------------------




CREATE PROC spSelectCharacterBattleRecord
(
	@CID	int
)
AS
BEGIN 
	SET NOCOUNT ON;


	SELECT Type, Value FROM CharBattleRecord WITH (NOLOCK)
	WHERE CID = @CID 
END
GO
-------------------------------------------------------------------------------------------------------




CREATE PROC spSelectCharacterList
(
	@AID int
)
AS
BEGIN 
	select Charac.CID, Name, SlotIndex, Sex, Class, Charac.Level, CharPlayTime, AdminLevel, BP, Cash, LatestBattleType, 
		SetItemID, SetColor, UnderwearItemID, UnderwearColor, TopItemID, TopColor,  
		PantsItemID, PantsColor, HandItemID, HandColor, FootItemID, FootColor,  
		BackItemID, BackColor, HeadItemID, HeadColor, FaceItemID, FaceColor, 
		EarringItemID, EarringColor, NeckItemID, NeckColor, FingerItemID, FingerColor 
	from Character as Charac, CharacterLook as Look 
	where Charac.AID = @AID and Look.AID = @AID and Charac.CID = Look.CID and Charac.DeleteFlag = 0
END
GO
-------------------------------------------------------------------------------------------------------




CREATE PROC spSelectChoiceProductList 
(
	@CID	int
) 
AS
BEGIN 
	SET NOCOUNT ON;


	SELECT ChoiceProdID, Type, ProdSellPoliID, ProdID FROM ChoiceProduct WITH (NOLOCK)
	WHERE CID = @CID 
END
GO
-------------------------------------------------------------------------------------------------------




CREATE PROC spSelectFriendList
(
	@CID int
) 
AS
BEGIN 
	SELECT f.FriendCID, Name 
	FROM (SELECT FriendCID FROM Friend WHERE CID = @CID) AS f, Character
	WHERE CID = f.FriendCID
END
GO
-------------------------------------------------------------------------------------------------------




CREATE PROC spSelectItemInstanceList
(
	@CID	int
) 
AS
BEGIN 
	SET NOCOUNT ON;


	DECLARE @ExpirationTime int
   
    SELECT IUID, ItemID, Durability, Color, SlotType, SlotID
		, UsagePeriod, AddUsagePeriod, CharPlayTime, UseCharPlayTime, AccumuUsageTime
		, ExpirationType, DATEDIFF(mi, GETDATE(), ExpiDate) AS ExpirationTime		
	FROM dbo.ItemInstance WITH (NOLOCK)
	WHERE CID = @CID AND UsageState = 0 AND SlotType = 1;
END
GO
-------------------------------------------------------------------------------------------------------




CREATE PROC spSelectKeeperList
AS
BEGIN
	SELECT ID, IP, Port, Name FROM KeeperList
END
GO
-------------------------------------------------------------------------------------------------------




CREATE PROC spSelectObserverList
(	
	@CID int
) 
AS
BEGIN 
	SELECT CID FROM Friend WHERE FriendCID = @CID
END
GO
-------------------------------------------------------------------------------------------------------




CREATE PROC spSelectPatchSchedule
AS
BEGIN 
	SELECT PatchID, KeeperID, ProgramID, PatchTime, CycleMinute
	FROM ServerPatchSchedule
	WHERE CycleMinute <> 0 or datediff(minute, getdate(), PatchTime) > 0
END
GO
-------------------------------------------------------------------------------------------------------




CREATE PROC spSelectProgramList
AS
BEGIN 
	SELECT ID, KeeperID, Name FROM ServerList
END
GO
-------------------------------------------------------------------------------------------------------




CREATE PROC spSelectServerPatchSchedule
(
	@KeeperID int
) 
AS
BEGIN 
	SELECT PatchID, ProgramID, PatchTime, CycleMinute
	FROM ServerPatchSchedule
	WHERE KeeperID = @KeeperID AND (CycleMinute <> 0 OR datediff(minute, getdate(), PatchTime) > 0)
END
GO
-------------------------------------------------------------------------------------------------------




CREATE PROC spTempInsertLogin
(
	@ID nvarchar(20),
	@PWD nvarchar(20)
) 
AS
BEGIN 
	SET NOCOUNT ON;
	DECLARE @FindAID int
	
	SELECT @FindAID = AID FROM Login WHERE ID = @ID
	
	IF (@FindAID is null)
	BEGIN
		INSERT INTO Login (ID, PWD) VALUES (@ID, @PWD)
		SELECT aid FROM Login WHERE id = @ID
	END
END
GO
-------------------------------------------------------------------------------------------------------






CREATE PROCEDURE spChangeWeaponSlot
(
	@SlotID1 smallint, @IUID1 bigint, @SlotID2 smallint, @IUID2 bigint  
)
AS	
BEGIN
	SET NOCOUNT ON;
	DECLARE @RowCount	int
	
	BEGIN TRAN
	
	-- 1
	UPDATE ItemInstance SET SlotID=@SlotID1 WHERE IUID=@IUID1;	SET @RowCount = @@ROWCOUNT	
	
	IF( @RowCount < 1 OR @@ERROR <> 0 )
	BEGIN
		GOTO ERROR_HANDLER;
	END
	
	-- 2
	IF( @IUID2 <> 0 )
	BEGIN
		UPDATE ItemInstance SET SlotID=@SlotID2 WHERE IUID=@IUID2;	SET @RowCount = @@ROWCOUNT	
		
		IF( @RowCount < 1 OR @@ERROR <> 0 )
		BEGIN
			GOTO ERROR_HANDLER;
		END
	END
		
	
	COMMIT TRAN
	return;
	
ERROR_HANDLER:
	IF @@TRANCOUNT <> 0 ROLLBACK TRAN
	
	RAISERROR(N'Failed ChangeWeaponSlot Update IUID1(%d), IUID2(%d).'
		, 11
		, 1
		, @IUID1, @IUID2);
END
GO
-------------------------------------------------------------------------------------------------------






CREATE PROCEDURE spSelectPlayerDataStageSetup
(
	@CID int
)
AS
BEGIN 
	SELECT ID, CID, BattleType, Name, MapID, MaxPlayer, BattleRoundNum, BattleTime FROM PlayerDataStageSetup where CID = @CID 
END
GO


-------------------------------------------------------------------------------------------------------


CREATE PROCEDURE spSavePlayerDataStageSetupUpdate
(
	@ID int,
	@MapID smallint,
	@Name nvarchar(33), 
	@MaxPlayer smallint,
	@BattleRoundNum smallint,
	@BattleTime smallint
)
AS
BEGIN
	UPDATE PlayerDataStageSetup SET MapID = @MapID, Name = @Name, MaxPlayer = @MaxPlayer, BattleRoundNum = @BattleRoundNum, 
							BattleTime = @BattleTime WHERE ID = @ID
END


CREATE PROCEDURE spSavePlayerDataStageSetupInsert
(
	@CID int, 
	@BattleType tinyint, 
	@MapID smallint,
	@Name nvarchar(33), 
	@MaxPlayer smallint,
	@BattleRoundNum smallint,
	@BattleTime smallint
)
AS
BEGIN
	INSERT INTO PlayerDataStageSetup (CID, BattleType, MapID, Name, MaxPlayer, BattleRoundNum, BattleTime) 
			VALUES(@CID, @BattleType, @MapID, @Name, @MaxPlayer, @BattleRoundNum, @BattleTime )
END
-------------------------------------------------------------------------------------------------------


CREATE PROC spGameLogInsertBattleInfo
(
	@MasterCID int,
	@HostCID int,
	@MasterServerGroupNum smallint, 
	@HostServerGroupNum smallint, 
	@MapID int,
	@BattleType smallint, 
	@RoundCount smallint, 
	@PlayTime	smallint
)
AS
BEGIN
	SET NOCOUNT ON;
	DECLARE @BattleUID bigint


	INSERT INTO GameLog_BattleInfo (MasterCID, HostCID, MasterServerGroupNum, HostServerGroupNum, MapID, BattleType, RoundCount, PlayTime, StartDate, EndDate, IsCompleted) 
	 VALUES (@MasterCID, @HostCID, @MasterServerGroupNum, @HostServerGroupNum, @MapID, @BattleType, @RoundCount, @PlayTime, getdate(), getdate(), 0)


	SET @BattleUID = SCOPE_IDENTITY()
	SELECT @BattleUID AS BattleUID
END
GO
-----------------------------------------------------------------------------------------------------------




CREATE PROC spGameLogUpdateEndBattle
(
	@BattleUID bigint,
	@IsCompleted tinyint
)
AS
BEGIN
	SET NOCOUNT ON;
	DECLARE @RowCount	int


	UPDATE GameLog_BattleInfo SET IsCompleted=@IsCompleted, EndDate=GETDATE() WHERE BattleUID=@BattleUID;	
	SET @RowCount = @@ROWCOUNT 
	
	IF( @RowCount < 1 OR @@ERROR <> 0 )
	BEGIN
		RAISERROR(N'Failed spGameLogUpdateEndBattle Update BattleUID(%d).'
		, 11
		, 1
		, @BattleUID);
	END
END
GO
-----------------------------------------------------------------------------------------------------------




CREATE PROC spGameLogInsertKillDeath
(
    @BattleUID BIGINT, 
    @RoundNumber_1 smallint, @AttackerCID_1 int, @VictimCID_1 int, @AttackerServerGroupNum_1 smallint, @VictimServerGroupNum_1 smallint, 
    @AttackerNPCID_1 int, @VictimNPCID_1 int, @WeaponID_1 int, 
    @RoundNumber_2 smallint, @AttackerCID_2 int, @VictimCID_2 int, @AttackerServerGroupNum_2 smallint, @VictimServerGroupNum_2 smallint, 
    @AttackerNPCID_2 int, @VictimNPCID_2 int, @WeaponID_2 int, 
    @RoundNumber_3 smallint, @AttackerCID_3 int, @VictimCID_3 int, @AttackerServerGroupNum_3 smallint, @VictimServerGroupNum_3 smallint, 
    @AttackerNPCID_3 int, @VictimNPCID_3 int, @WeaponID_3 int, 
    @RoundNumber_4 smallint, @AttackerCID_4 int, @VictimCID_4 int, @AttackerServerGroupNum_4 smallint, @VictimServerGroupNum_4 smallint, 
    @AttackerNPCID_4 int, @VictimNPCID_4 int, @WeaponID_4 int, 
    @RoundNumber_5 smallint, @AttackerCID_5 int, @VictimCID_5 int, @AttackerServerGroupNum_5 smallint, @VictimServerGroupNum_5 smallint, 
    @AttackerNPCID_5 int, @VictimNPCID_5 int, @WeaponID_5 int, 
    @RoundNumber_6 smallint, @AttackerCID_6 int, @VictimCID_6 int, @AttackerServerGroupNum_6 smallint, @VictimServerGroupNum_6 smallint, 
    @AttackerNPCID_6 int, @VictimNPCID_6 int, @WeaponID_6 int, 
    @RoundNumber_7 smallint, @AttackerCID_7 int, @VictimCID_7 int, @AttackerServerGroupNum_7 smallint, @VictimServerGroupNum_7 smallint, 
    @AttackerNPCID_7 int, @VictimNPCID_7 int, @WeaponID_7 int, 
    @RoundNumber_8 smallint, @AttackerCID_8 int, @VictimCID_8 int, @AttackerServerGroupNum_8 smallint, @VictimServerGroupNum_8 smallint, 
    @AttackerNPCID_8 int, @VictimNPCID_8 int, @WeaponID_8 int
)
AS
    SET NOCOUNT ON;
    
    WITH KLOG (RoundNumber, AttackerCID, VictimCID, AttackerServerGroupNum, VictimServerGroupNum, AttackerNPCID, VictimNPCID, WeaponID) AS
        (
            SELECT @RoundNumber_1, @AttackerCID_1, @VictimCID_1, @AttackerServerGroupNum_1, @VictimServerGroupNum_1, @AttackerNPCID_1, @VictimNPCID_1, @WeaponID_1  
             UNION ALL
            SELECT @RoundNumber_2, @AttackerCID_2, @VictimCID_2, @AttackerServerGroupNum_2, @VictimServerGroupNum_2, @AttackerNPCID_2, @VictimNPCID_2, @WeaponID_2 
             UNION ALL
            SELECT @RoundNumber_3, @AttackerCID_3, @VictimCID_3, @AttackerServerGroupNum_3, @VictimServerGroupNum_3, @AttackerNPCID_3, @VictimNPCID_3, @WeaponID_3 
			 UNION ALL	
            SELECT @RoundNumber_4, @AttackerCID_4, @VictimCID_4, @AttackerServerGroupNum_4, @VictimServerGroupNum_4, @AttackerNPCID_4, @VictimNPCID_4, @WeaponID_4 
             UNION ALL
            SELECT @RoundNumber_5, @AttackerCID_5, @VictimCID_5, @AttackerServerGroupNum_5, @VictimServerGroupNum_5, @AttackerNPCID_5, @VictimNPCID_5, @WeaponID_5 
             UNION ALL
            SELECT @RoundNumber_6, @AttackerCID_6, @VictimCID_6, @AttackerServerGroupNum_6, @VictimServerGroupNum_6, @AttackerNPCID_6, @VictimNPCID_6, @WeaponID_6
              UNION ALL
            SELECT @RoundNumber_7, @AttackerCID_7, @VictimCID_7, @AttackerServerGroupNum_7, @VictimServerGroupNum_7, @AttackerNPCID_7, @VictimNPCID_7, @WeaponID_7
             UNION ALL
            SELECT @RoundNumber_8, @AttackerCID_8, @VictimCID_8, @AttackerServerGroupNum_8, @VictimServerGroupNum_8, @AttackerNPCID_8, @VictimNPCID_8, @WeaponID_8
        )
    INSERT INTO GameLog_KillDeath (BattleUID, RoundNumber, AttackerCID, VictimCID, AttackerServerGroupNum, VictimServerGroupNum, AttackerNPCID, VictimNPCID, WeaponID, REG_DATE)    
    SELECT @BattleUID, RoundNumber, AttackerCID, VictimCID, AttackerServerGroupNum, VictimServerGroupNum, AttackerNPCID, VictimNPCID, WeaponID, GETDATE()
      FROM KLOG
     WHERE WeaponID > 0;
GO
-----------------------------------------------------------------------------------------------------------




CREATE PROC spGameLogInsertWeaponShot
(
    @BattleUID BIGINT, 
    @RoundNumber_1 smallint, @CID_1 int, @PlayerServerGroupNum_1 smallint, @WeaponID_1 int, @FireCount_1 int, @HitCount_1 int, @Damage_1 float, 
    @RoundNumber_2 smallint, @CID_2 int, @PlayerServerGroupNum_2 smallint, @WeaponID_2 int, @FireCount_2 int, @HitCount_2 int, @Damage_2 float, 
    @RoundNumber_3 smallint, @CID_3 int, @PlayerServerGroupNum_3 smallint, @WeaponID_3 int, @FireCount_3 int, @HitCount_3 int, @Damage_3 float, 
    @RoundNumber_4 smallint, @CID_4 int, @PlayerServerGroupNum_4 smallint, @WeaponID_4 int, @FireCount_4 int, @HitCount_4 int, @Damage_4 float, 
    @RoundNumber_5 smallint, @CID_5 int, @PlayerServerGroupNum_5 smallint, @WeaponID_5 int, @FireCount_5 int, @HitCount_5 int, @Damage_5 float, 
    @RoundNumber_6 smallint, @CID_6 int, @PlayerServerGroupNum_6 smallint, @WeaponID_6 int, @FireCount_6 int, @HitCount_6 int, @Damage_6 float, 
    @RoundNumber_7 smallint, @CID_7 int, @PlayerServerGroupNum_7 smallint, @WeaponID_7 int, @FireCount_7 int, @HitCount_7 int, @Damage_7 float, 
    @RoundNumber_8 smallint, @CID_8 int, @PlayerServerGroupNum_8 smallint, @WeaponID_8 int, @FireCount_8 int, @HitCount_8 int, @Damage_8 float, 
    @RoundNumber_9 smallint, @CID_9 int, @PlayerServerGroupNum_9 smallint, @WeaponID_9 int, @FireCount_9 int, @HitCount_9 int, @Damage_9 float, 
    @RoundNumber_10 smallint, @CID_10 int, @PlayerServerGroupNum_10 smallint, @WeaponID_10 int, @FireCount_10 int, @HitCount_10 int, @Damage_10 float, 
    @RoundNumber_11 smallint, @CID_11 int, @PlayerServerGroupNum_11 smallint, @WeaponID_11 int, @FireCount_11 int, @HitCount_11 int, @Damage_11 float, 
    @RoundNumber_12 smallint, @CID_12 int, @PlayerServerGroupNum_12 smallint, @WeaponID_12 int, @FireCount_12 int, @HitCount_12 int, @Damage_12 float
)
AS
    SET NOCOUNT ON;
    
    WITH KLOG (RoundNumber, CID, PlayerServerGroupNum, WeaponID, FireCount, HitCount, Damage) AS
        (
            SELECT @RoundNumber_1, @CID_1, @PlayerServerGroupNum_1, @WeaponID_1, @FireCount_1, @HitCount_1, @Damage_1  
             UNION ALL
            SELECT @RoundNumber_2, @CID_2, @PlayerServerGroupNum_2, @WeaponID_2, @FireCount_2, @HitCount_2, @Damage_2 
             UNION ALL
            SELECT @RoundNumber_3, @CID_3, @PlayerServerGroupNum_3, @WeaponID_3, @FireCount_3, @HitCount_3, @Damage_3 
			 UNION ALL	
            SELECT @RoundNumber_4, @CID_4, @PlayerServerGroupNum_4, @WeaponID_4, @FireCount_4, @HitCount_4, @Damage_4 
             UNION ALL
            SELECT @RoundNumber_5, @CID_5, @PlayerServerGroupNum_5, @WeaponID_5, @FireCount_5, @HitCount_5, @Damage_5 
             UNION ALL
            SELECT @RoundNumber_6, @CID_6, @PlayerServerGroupNum_6, @WeaponID_6, @FireCount_6, @HitCount_6, @Damage_6
              UNION ALL
            SELECT @RoundNumber_7, @CID_7, @PlayerServerGroupNum_7, @WeaponID_7, @FireCount_7, @HitCount_7, @Damage_7
             UNION ALL
            SELECT @RoundNumber_8, @CID_8, @PlayerServerGroupNum_8, @WeaponID_8, @FireCount_8, @HitCount_8, @Damage_8
             UNION ALL
            SELECT @RoundNumber_9, @CID_9, @PlayerServerGroupNum_9, @WeaponID_9, @FireCount_9, @HitCount_9, @Damage_9
             UNION ALL
            SELECT @RoundNumber_10, @CID_10, @PlayerServerGroupNum_10, @WeaponID_10, @FireCount_10, @HitCount_10, @Damage_10
             UNION ALL
            SELECT @RoundNumber_11, @CID_11, @PlayerServerGroupNum_11, @WeaponID_11, @FireCount_11, @HitCount_11, @Damage_11
             UNION ALL
            SELECT @RoundNumber_12, @CID_12, @PlayerServerGroupNum_12, @WeaponID_12, @FireCount_12, @HitCount_12, @Damage_12
        )
    INSERT INTO GameLog_WeaponShot (BattleUID, RoundNumber, CID, PlayerServerGroupNum, WeaponID, FireCount, HitCount, Damage, REG_DATE)    
    SELECT @BattleUID, RoundNumber, CID, PlayerServerGroupNum, WeaponID, FireCount, HitCount, Damage, GETDATE()
      FROM KLOG
     WHERE CID > 0;
GO
-----------------------------------------------------------------------------------------------------------




CREATE PROC spGameLogInsertWeaponTime
(
    @BattleUID BIGINT, 
    @CID_1 int, @PlayerServerGroupNum_1 smallint, @WeaponID_1 int, @UseTime_1 int, 
    @CID_2 int, @PlayerServerGroupNum_2 smallint, @WeaponID_2 int, @UseTime_2 int, 
    @CID_3 int, @PlayerServerGroupNum_3 smallint, @WeaponID_3 int, @UseTime_3 int, 
    @CID_4 int, @PlayerServerGroupNum_4 smallint, @WeaponID_4 int, @UseTime_4 int, 
    @CID_5 int, @PlayerServerGroupNum_5 smallint, @WeaponID_5 int, @UseTime_5 int, 
    @CID_6 int, @PlayerServerGroupNum_6 smallint, @WeaponID_6 int, @UseTime_6 int, 
    @CID_7 int, @PlayerServerGroupNum_7 smallint, @WeaponID_7 int, @UseTime_7 int, 
    @CID_8 int, @PlayerServerGroupNum_8 smallint, @WeaponID_8 int, @UseTime_8 int, 
    @CID_9 int, @PlayerServerGroupNum_9 smallint, @WeaponID_9 int, @UseTime_9 int, 
    @CID_10 int, @PlayerServerGroupNum_10 smallint, @WeaponID_10 int, @UseTime_10 int, 
    @CID_11 int, @PlayerServerGroupNum_11 smallint, @WeaponID_11 int, @UseTime_11 int, 
    @CID_12 int, @PlayerServerGroupNum_12 smallint, @WeaponID_12 int, @UseTime_12 int 
)
AS
    SET NOCOUNT ON;
    
    WITH KLOG (CID, PlayerServerGroupNum, WeaponID, UseTime) AS
        (
            SELECT @CID_1, @PlayerServerGroupNum_1, @WeaponID_1, @UseTime_1  
             UNION ALL
            SELECT @CID_2, @PlayerServerGroupNum_2, @WeaponID_2, @UseTime_2 
             UNION ALL
            SELECT @CID_3, @PlayerServerGroupNum_3, @WeaponID_3, @UseTime_3 
			 UNION ALL	
            SELECT @CID_4, @PlayerServerGroupNum_4, @WeaponID_4, @UseTime_4 
             UNION ALL
            SELECT @CID_5, @PlayerServerGroupNum_5, @WeaponID_5, @UseTime_5 
             UNION ALL
            SELECT @CID_6, @PlayerServerGroupNum_6, @WeaponID_6, @UseTime_6 
              UNION ALL
            SELECT @CID_7, @PlayerServerGroupNum_7, @WeaponID_7, @UseTime_7 
             UNION ALL
            SELECT @CID_8, @PlayerServerGroupNum_8, @WeaponID_8, @UseTime_8 
             UNION ALL
            SELECT @CID_9, @PlayerServerGroupNum_9, @WeaponID_9, @UseTime_9 
             UNION ALL
            SELECT @CID_10, @PlayerServerGroupNum_10, @WeaponID_10, @UseTime_10 
             UNION ALL
            SELECT @CID_11, @PlayerServerGroupNum_11, @WeaponID_11, @UseTime_11 
             UNION ALL
            SELECT @CID_12, @PlayerServerGroupNum_12, @WeaponID_12, @UseTime_12 
        )
    INSERT INTO GameLog_WeaponTime (BattleUID, CID, PlayerServerGroupNum, WeaponID, UseTime, REG_DATE)    
    SELECT @BattleUID, CID, PlayerServerGroupNum, WeaponID, UseTime, GETDATE()
      FROM KLOG
     WHERE CID > 0;
GO
-----------------------------------------------------------------------------------------------------------
 
Back
Top