Skip to content

Commit

Permalink
Feat: new budget/donations database
Browse files Browse the repository at this point in the history
  • Loading branch information
Bizzonium committed Feb 26, 2022
1 parent 7823e6a commit 10b9f83
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 11 deletions.
20 changes: 20 additions & 0 deletions SQL/paradise_schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -619,3 +619,23 @@ CREATE TABLE `ban_whitelist`
KEY `computerid` (`computerid`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `budget`
--
DROP TABLE IF EXISTS `budget`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `budget`
(
`id` INT(11) NOT NULL AUTO_INCREMENT,
`date` DATETIME DEFAULT now() NOT NULL,
`ckey` VARCHAR(32) NOT NULL,
`amount` INT(10) UNSIGNED NOT NULL,
`source` VARCHAR(32) NOT NULL,
`date_start` DATETIME DEFAULT now() NOT NULL,
`date_end` DATETIME DEFAULT (now() + INTERVAL 1 MONTH),
`is_valid` BOOLEAN DEFAULT true NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
/*!40101 SET character_set_client = @saved_cs_client */;
19 changes: 19 additions & 0 deletions SQL/paradise_schema_prefixed.sql
Original file line number Diff line number Diff line change
Expand Up @@ -600,3 +600,22 @@ CREATE TABLE `SS13_ckey_whitelist`
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `budget`
--
DROP TABLE IF EXISTS `budget`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `budget`
(
`id` INT(11) NOT NULL AUTO_INCREMENT,
`date` DATETIME DEFAULT now() NOT NULL,
`ckey` VARCHAR(32) NOT NULL,
`amount` INT(10) UNSIGNED NOT NULL,
`source` VARCHAR(32) NOT NULL,
`date_start` DATETIME DEFAULT now() NOT NULL,
`date_end` DATETIME DEFAULT (now() + INTERVAL 1 MONTH),
`is_valid` BOOLEAN DEFAULT true NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
/*!40101 SET character_set_client = @saved_cs_client */;
19 changes: 19 additions & 0 deletions SQL/updates/buget.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
--
-- Table structure for table `budget`
--
DROP TABLE IF EXISTS `budget`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `budget`
(
`id` INT(11) NOT NULL AUTO_INCREMENT,
`date` DATETIME DEFAULT now() NOT NULL,
`ckey` VARCHAR(32) NOT NULL,
`amount` INT(10) UNSIGNED NOT NULL,
`source` VARCHAR(32) NOT NULL,
`date_start` DATETIME DEFAULT now() NOT NULL,
`date_end` DATETIME DEFAULT (now() + INTERVAL 1 MONTH),
`is_valid` BOOLEAN DEFAULT true NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
/*!40101 SET character_set_client = @saved_cs_client */;
29 changes: 18 additions & 11 deletions code/modules/client/client_procs.dm
Original file line number Diff line number Diff line change
Expand Up @@ -443,23 +443,30 @@
return

//Donator stuff.
var/datum/db_query/query_donor_select = SSdbcore.NewQuery("SELECT ckey, tier, active FROM [sqlfdbkdbutil].[format_table_name("donators")] WHERE ckey=:ckey", list(
"ckey" = ckey
))
var/datum/db_query/query_donor_select = SSdbcore.NewQuery({"
SELECT CAST(SUM(amount) as UNSIGNED INTEGER) FROM [sqlfdbkdbutil].[format_table_name("budget")]
WHERE ckey=:ckey
AND is_valid=true
AND date_start <= NOW()
AND (NOW() < date_end OR date_end IS NULL)
GROUP BY ckey
"}, list("ckey" = ckey))

if(!query_donor_select.warn_execute())
qdel(query_donor_select)
return

while(query_donor_select.NextRow())
if(!text2num(query_donor_select.item[3]))
// Inactive donator.
donator_level = 0
qdel(query_donor_select)
return
donator_level = text2num(query_donor_select.item[2])
if(query_donor_select.NextRow())
var/total = query_donor_select.item[1]
if(total >= 100)
donator_level = 1
if(total >= 300)
donator_level = 2
if(total >= 500)
donator_level = 3
if(total >= 1000)
donator_level = DONATOR_LEVEL_MAX
donor_loadout_points()
break
qdel(query_donor_select)

/client/proc/donor_loadout_points()
Expand Down

0 comments on commit 10b9f83

Please sign in to comment.