Files
ls-2019-source/database/08_first_tournament.sql

22 lines
1.4 KiB
Transact-SQL

-- First regular tournament (Faction War / LS Cup panel). The main server only continues a row that exists;
-- nothing creates the first one. leagueType 1 = TYPE_REGULAR, leagueState 1 = STATE_TEAM_APP, accountIDX 0 = no owner.
-- Dates are YYMMDDHHMM in a DWORD (Help::ConvertCTimeToDate). Since 2022 that is above the int range, so the
-- int columns hold the wrapped value; the server reads the same bits back as a DWORD.
-- Starts on the last Monday 03:00 and runs next_tournament_hour (336) hours, like sp2_tournament_regular.ini.
USE [LosaGame]
GO
IF NOT EXISTS (SELECT 1 FROM dbo.userLeagueListDB WHERE leagueType = 1)
BEGIN
DECLARE @s datetime, @e datetime, @a bigint, @b bigint
SET @s = DATEADD(hour, 3, DATEADD(day, -(DATEDIFF(day, 0, GETDATE()) % 7), DATEDIFF(day, 0, GETDATE())))
SET @e = DATEADD(hour, 336, @s)
SET @a = CAST(YEAR(@s) % 100 AS bigint) * 100000000 + MONTH(@s) * 1000000 + DAY(@s) * 10000 + DATEPART(hour, @s) * 100
SET @b = CAST(YEAR(@e) % 100 AS bigint) * 100000000 + MONTH(@e) * 1000000 + DAY(@e) * 10000 + DATEPART(hour, @e) * 100
IF @a > 2147483647 SET @a = @a - 4294967296
IF @b > 2147483647 SET @b = @b - 4294967296
INSERT INTO dbo.userLeagueListDB (accountIDX, startDate, endDate, leagueType, leagueState, regDate)
VALUES (0, @a, @b, 1, 1, GETDATE())
END
SELECT idx, startDate, endDate, leagueType, leagueState FROM dbo.userLeagueListDB
GO