From 3df8f29a4cc263906d3dbc40d3a92065f45bc79f Mon Sep 17 00:00:00 2001 From: Sky Johnson Date: Thu, 21 Aug 2025 23:05:10 -0500 Subject: [PATCH] start new database creation script --- database.sql | 350 +++++++++++++++++++++++++++++++ internal/models/babble/babble.go | 23 +- internal/models/forum/forum.go | 16 +- main.go | 48 ----- 4 files changed, 368 insertions(+), 69 deletions(-) create mode 100644 database.sql diff --git a/database.sql b/database.sql new file mode 100644 index 0000000..9feae27 --- /dev/null +++ b/database.sql @@ -0,0 +1,350 @@ +DROP TABLE IF EXISTS babble; +CREATE TABLE babble ( + `id` INTEGER PRIMARY KEY AUTOINCREMENT, + `posted` INTEGER NOT NULL DEFAULT (unixepoch()), + `author` INTEGER NOT NULL, + `babble` TEXT NOT NULL +); + +DROP TABLE IF EXISTS drops; +CREATE TABLE drops ( + `id` INTEGER PRIMARY KEY AUTOINCREMENT, + `name` TEXT NOT NULL, + `level` INTEGER NOT NULL DEFAULT 0, + `type` INTEGER NOT NULL DEFAULT 0, + `att` TEXT NOT NULL DEFAULT '', +); +INSERT INTO drops VALUES +(1, 'Life Pebble', 1, 1, 'maxhp,10'), +(2, 'Life Stone', 10, 1, 'maxhp,25'), +(3, 'Life Rock', 25, 1, 'maxhp,50'), +(4, 'Magic Pebble', 1, 1, 'maxmp,10'), +(5, 'Magic Stone', 10, 1, 'maxmp,25'), +(6, 'Magic Rock', 25, 1, 'maxmp,50'), +(7, 'Dragon''s Scale', 10, 1, 'defensepower,25'), +(8, 'Dragon''s Plate', 30, 1, 'defensepower,50'), +(9, 'Dragon''s Claw', 10, 1, 'attackpower,25'), +(10, 'Dragon''s Tooth', 30, 1, 'attackpower,50'), +(11, 'Dragon''s Tear', 35, 1, 'strength,50'), +(12, 'Dragon''s Wing', 35, 1, 'dexterity,50'), +(13, 'Demon''s Sin', 35, 1, 'maxhp,-50,strength,50'), +(14, 'Demon''s Fall', 35, 1, 'maxmp,-50,strength,50'), +(15, 'Demon''s Lie', 45, 1, 'maxhp,-100,strength,100'), +(16, 'Demon''s Hate', 45, 1, 'maxmp,-100,strength,100'), +(17, 'Angel''s Joy', 25, 1, 'maxhp,25,strength,25'), +(18, 'Angel''s Rise', 30, 1, 'maxhp,50,strength,50'), +(19, 'Angel''s Truth', 35, 1, 'maxhp,75,strength,75'), +(20, 'Angel''s Love', 40, 1, 'maxhp,100,strength,100'), +(21, 'Seraph''s Joy', 25, 1, 'maxmp,25,dexterity,25'), +(22, 'Seraph''s Rise', 30, 1, 'maxmp,50,dexterity,50'), +(23, 'Seraph''s Truth', 35, 1, 'maxmp,75,dexterity,75'), +(24, 'Seraph''s Love', 40, 1, 'maxmp,100,dexterity,100'), +(25, 'Ruby', 50, 1, 'maxhp,150'), +(26, 'Pearl', 50, 1, 'maxmp,150'), +(27, 'Emerald', 50, 1, 'strength,150'), +(28, 'Topaz', 50, 1, 'dexterity,150'), +(29, 'Obsidian', 50, 1, 'attackpower,150'), +(30, 'Diamond', 50, 1, 'defensepower,150'), +(31, 'Memory Drop', 5, 1, 'expbonus,10'), +(32, 'Fortune Drop', 5, 1, 'goldbonus,10'); + +DROP TABLE IF EXISTS forum; +CREATE TABLE forum ( + `id` INTEGER PRIMARY KEY AUTOINCREMENT, + `posted` INTEGER NOT NULL DEFAULT (unixepoch()), + `last_post` INTEGER NOT NULL DEFAULT (unixepoch()), + `author` INTEGER NOT NULL, + `parent` INTEGER NOT NULL DEFAULT 0, + `replies` INTEGER NOT NULL DEFAULT 0, + `title` TEXT NOT NULL DEFAULT '', + `content` TEXT NOT NULL +); + +DROP TABLE IF EXISTS items; +CREATE TABLE items ( + `id` INTEGER PRIMARY KEY AUTOINCREMENT, + `type` INTEGER NOT NULL DEFAULT 1, + `name` TEXT NOT NULL, + `value` INTEGER NOT NULL DEFAULT 0, + `att` INTEGER NOT NULL DEFAULT 0, + `special` TEXT NOT NULL DEFAULT '' +); +INSERT INTO items VALUES +(1, 1, 'Stick', 10, 2, ''), +(2, 1, 'Branch', 30, 4, ''), +(3, 1, 'Club', 40, 5, ''), +(4, 1, 'Dagger', 90, 8, ''), +(5, 1, 'Hatchet', 150, 12, ''), +(6, 1, 'Axe', 200, 16, ''), +(7, 1, 'Brand', 300, 25, ''), +(8, 1, 'Poleaxe', 500, 35, ''), +(9, 1, 'Broadsword', 800, 45, ''), +(10, 1, 'Battle Axe', 1200, 50, ''), +(11, 1, 'Claymore', 2000, 60, ''), +(12, 1, 'Dark Axe', 3000, 100, 'expbonus,-5'), +(13, 1, 'Dark Sword', 4500, 125, 'expbonus,-10'), +(14, 1, 'Bright Sword', 6000, 100, 'expbonus,10'), +(15, 1, 'Magic Sword', 10000, 150, 'maxmp,50'), +(16, 1, 'Destiny Blade', 50000, 250, 'strength,50'), +(17, 2, 'Skivvies', 25, 2, 'goldbonus,10'), +(18, 2, 'Clothes', 50, 5, ''), +(19, 2, 'Leather Armor', 75, 10, ''), +(20, 2, 'Hard Leather Armor', 150, 25, ''), +(21, 2, 'Chain Mail', 300, 30, ''), +(22, 2, 'Bronze Plate', 900, 50, ''), +(23, 2, 'Iron Plate', 2000, 100, ''), +(24, 2, 'Magic Armor', 4000, 125, 'maxmp,50'), +(25, 2, 'Dark Armor', 5000, 150, 'expbonus,-10'), +(26, 2, 'Bright Armor', 10000, 175, 'expbonus,10'), +(27, 2, 'Destiny Raiment', 50000, 200, 'dexterity,50'), +(28, 3, 'Reed Shield', 50, 2, ''), +(29, 3, 'Buckler', 100, 4, ''), +(30, 3, 'Small Shield', 500, 10, ''), +(31, 3, 'Large Shield', 2500, 30, ''), +(32, 3, 'Silver Shield', 10000, 60, ''), +(33, 3, 'Destiny Aegis', 25000, 100, 'maxhp,50'); + +DROP TABLE IF EXISTS classes; +CREATE TABLE classes ( + 'id' INTEGER PRIMARY KEY AUTOINCREMENT, + 'name' TEXT NOT NULL, + 'lore' TEXT NOT NULL, + 'exp_rate' INTEGER NOT NULL DEFAULT 3, + 'base_hp' INTEGER NOT NULL DEFAULT 15, + 'base_mp' INTEGER NOT NULL DEFAULT 10, + 'base_str' INTEGER NOT NULL DEFAULT 1, + 'base_dex' INTEGER NOT NULL DEFAULT 1, + 'hp_rate' INTEGER NOT NULL DEFAULT 2, + 'mp_rate' INTEGER NOT NULL DEFAULT 2, + 'str_rate' INTEGER NOT NULL DEFAULT 2, + 'dex_rate' INTEGER NOT NULL DEFAULT 2, +); +INSERT INTO classes VALUES +(1, 'Adventurer', '', 3, 15, 10, 4, 4, 2, 2, 2, 2), +(2, 'Mage', '', 1, 10, 15, 1, 7, 1, 3, 1, 2), +(3, 'Warrior', '', 2, 20, 5, 7, 1, 3, 1, 3, 1), +(4, 'Paladin', '', 5, 15, 15, 5, 5, 2, 2, 2, 2); + +DROP TABLE IF EXISTS monsters; +CREATE TABLE monsters ( + `id` INTEGER PRIMARY KEY AUTOINCREMENT, + `name` TEXT NOT NULL, + `max_hp` INTEGER NOT NULL DEFAULT 1, + `max_dmg` INTEGER NOT NULL DEFAULT 1, + `armor` INTEGER NOT NULL DEFAULT 0, + `level` INTEGER NOT NULL DEFAULT 0, + `max_exp` INTEGER NOT NULL DEFAULT 1, + `max_gold` INTEGER NOT NULL DEFAULT 1, + `immune` INTEGER NOT NULL DEFAULT 0 +); +INSERT INTO monsters VALUES +(1, 'Blue Slime', 4, 3, 1, 1, 1, 1, 0), +(2, 'Red Slime', 6, 5, 1, 1, 2, 1, 0), +(3, 'Critter', 6, 5, 2, 1, 4, 2, 0), +(4, 'Creature', 10, 8, 2, 2, 4, 2, 0), +(5, 'Shadow', 10, 9, 3, 2, 6, 2, 1), +(6, 'Drake', 11, 10, 3, 2, 8, 3, 0), +(7, 'Shade', 12, 10, 3, 3, 10, 3, 1), +(8, 'Drakelor', 14, 12, 4, 3, 10, 3, 0), +(9, 'Silver Slime', 15, 100, 200, 30, 15, 1000, 2), +(10, 'Scamp', 16, 13, 5, 4, 15, 5, 0), +(11, 'Raven', 16, 13, 5, 4, 18, 6, 0), +(12, 'Scorpion', 18, 14, 6, 5, 20, 7, 0), +(13, 'Illusion', 20, 15, 6, 5, 20, 7, 1), +(14, 'Nightshade', 22, 16, 6, 6, 24, 8, 0), +(15, 'Drakemal', 22, 18, 7, 6, 24, 8, 0), +(16, 'Shadow Raven', 24, 18, 7, 6, 26, 9, 1), +(17, 'Ghost', 24, 20, 8, 6, 28, 9, 0), +(18, 'Frost Raven', 26, 20, 8, 7, 30, 10, 0), +(19, 'Rogue Scorpion', 28, 22, 9, 7, 32, 11, 0), +(20, 'Ghoul', 29, 24, 9, 7, 34, 11, 0), +(21, 'Magician', 30, 24, 10, 8, 36, 12, 0), +(22, 'Rogue', 30, 25, 12, 8, 40, 13, 0), +(23, 'Drakefin', 32, 26, 12, 8, 40, 13, 0), +(24, 'Shimmer', 32, 26, 14, 8, 45, 15, 1), +(25, 'Fire Raven', 34, 28, 14, 9, 45, 15, 0), +(26, 'Dybbuk', 34, 28, 14, 9, 50, 17, 0), +(27, 'Knave', 36, 30, 15, 9, 52, 17, 0), +(28, 'Goblin', 36, 30, 15, 10, 54, 18, 0), +(29, 'Skeleton', 38, 30, 18, 10, 58, 19, 0), +(30, 'Dark Slime', 38, 32, 18, 10, 62, 21, 0), +(31, 'Silver Scorpion', 30, 160, 350, 40, 63, 2000, 2), +(32, 'Mirage', 40, 32, 20, 11, 64, 21, 1), +(33, 'Sorceror', 41, 33, 22, 11, 68, 23, 0), +(34, 'Imp', 42, 34, 22, 12, 70, 23, 0), +(35, 'Nymph', 43, 35, 22, 12, 70, 23, 0), +(36, 'Scoundrel', 43, 35, 22, 12, 75, 25, 0), +(37, 'Megaskeleton', 44, 36, 24, 13, 78, 26, 0), +(38, 'Grey Wolf', 44, 36, 24, 13, 82, 27, 0), +(39, 'Phantom', 46, 38, 24, 14, 85, 28, 1), +(40, 'Specter', 46, 38, 24, 14, 90, 30, 0), +(41, 'Dark Scorpion', 48, 40, 26, 15, 95, 32, 1), +(42, 'Warlock', 48, 40, 26, 15, 100, 33, 1), +(43, 'Orc', 49, 42, 28, 15, 104, 35, 0), +(44, 'Sylph', 49, 42, 28, 15, 106, 35, 0), +(45, 'Wraith', 50, 45, 30, 16, 108, 36, 0), +(46, 'Hellion', 50, 45, 30, 16, 110, 37, 0), +(47, 'Bandit', 52, 45, 30, 16, 114, 38, 0), +(48, 'Ultraskeleton', 52, 46, 32, 16, 116, 39, 0), +(49, 'Dark Wolf', 54, 47, 36, 17, 120, 40, 1), +(50, 'Troll', 56, 48, 36, 17, 120, 40, 0), +(51, 'Werewolf', 56, 48, 38, 17, 124, 41, 0), +(52, 'Hellcat', 58, 50, 38, 18, 128, 43, 0), +(53, 'Spirit', 58, 50, 38, 18, 132, 44, 0), +(54, 'Nisse', 60, 52, 40, 19, 132, 44, 0), +(55, 'Dawk', 60, 54, 40, 19, 136, 45, 0), +(56, 'Figment', 64, 55, 42, 19, 140, 47, 1), +(57, 'Hellhound', 66, 56, 44, 20, 140, 47, 0), +(58, 'Wizard', 66, 56, 44, 20, 144, 48, 0), +(59, 'Uruk', 68, 58, 44, 20, 146, 49, 0), +(60, 'Siren', 68, 400, 800, 50, 10000, 50, 2), +(61, 'Megawraith', 70, 60, 46, 21, 155, 52, 0), +(62, 'Dawkin', 70, 60, 46, 21, 155, 52, 0), +(63, 'Grey Bear', 70, 62, 48, 21, 160, 53, 0), +(64, 'Haunt', 72, 62, 48, 22, 160, 53, 0), +(65, 'Hellbeast', 74, 64, 50, 22, 165, 55, 0), +(66, 'Fear', 76, 66, 52, 23, 165, 55, 0), +(67, 'Beast', 76, 66, 52, 23, 170, 57, 0), +(68, 'Ogre', 78, 68, 54, 23, 170, 57, 0), +(69, 'Dark Bear', 80, 70, 56, 24, 175, 58, 1), +(70, 'Fire', 80, 72, 56, 24, 175, 58, 0), +(71, 'Polgergeist', 84, 74, 58, 25, 180, 60, 0), +(72, 'Fright', 86, 76, 58, 25, 180, 60, 0), +(73, 'Lycan', 88, 78, 60, 25, 185, 62, 0), +(74, 'Terra Elemental', 88, 80, 62, 25, 185, 62, 1), +(75, 'Necromancer', 90, 80, 62, 26, 190, 63, 0), +(76, 'Ultrawraith', 90, 82, 64, 26, 190, 63, 0), +(77, 'Dawkor', 92, 82, 64, 26, 195, 65, 0), +(78, 'Werebear', 92, 84, 65, 26, 195, 65, 0), +(79, 'Brute', 94, 84, 65, 27, 200, 67, 0), +(80, 'Large Beast', 96, 88, 66, 27, 200, 67, 0), +(81, 'Horror', 96, 88, 68, 27, 210, 70, 0), +(82, 'Flame', 100, 90, 70, 28, 210, 70, 0), +(83, 'Lycanthor', 100, 90, 70, 28, 210, 70, 0), +(84, 'Wyrm', 100, 92, 72, 28, 220, 73, 0), +(85, 'Aero Elemental', 104, 94, 74, 29, 220, 73, 1), +(86, 'Dawkare', 106, 96, 76, 29, 220, 73, 0), +(87, 'Large Brute', 108, 98, 78, 29, 230, 77, 0), +(88, 'Frost Wyrm', 110, 100, 80, 30, 230, 77, 0), +(89, 'Knight', 110, 102, 80, 30, 240, 80, 0), +(90, 'Lycanthra', 112, 104, 82, 30, 240, 80, 0), +(91, 'Terror', 115, 108, 84, 31, 250, 83, 0), +(92, 'Blaze', 118, 108, 84, 31, 250, 83, 0), +(93, 'Aqua Elemental', 120, 110, 90, 31, 260, 87, 1), +(94, 'Fire Wyrm', 120, 110, 90, 32, 260, 87, 0), +(95, 'Lesser Wyvern', 122, 110, 92, 32, 270, 90, 0), +(96, 'Doomer', 124, 112, 92, 32, 270, 90, 0), +(97, 'Armor Knight', 130, 115, 95, 33, 280, 93, 0), +(98, 'Wyvern', 134, 120, 95, 33, 290, 97, 0), +(99, 'Nightmare', 138, 125, 100, 33, 300, 100, 0), +(100, 'Fira Elemental', 140, 125, 100, 34, 310, 103, 1), +(101, 'Megadoomer', 140, 128, 105, 34, 320, 107, 0), +(102, 'Greater Wyvern', 145, 130, 105, 34, 335, 112, 0), +(103, 'Advocate', 148, 132, 108, 35, 350, 117, 0), +(104, 'Strong Knight', 150, 135, 110, 35, 365, 122, 0), +(105, 'Liche', 150, 135, 110, 35, 380, 127, 0), +(106, 'Ultradoomer', 155, 140, 115, 36, 395, 132, 0), +(107, 'Fanatic', 160, 140, 115, 36, 410, 137, 0), +(108, 'Green Dragon', 160, 140, 115, 36, 425, 142, 0), +(109, 'Fiend', 160, 145, 120, 37, 445, 148, 0), +(110, 'Greatest Wyvern', 162, 150, 120, 37, 465, 155, 0), +(111, 'Lesser Devil', 164, 150, 120, 37, 485, 162, 0), +(112, 'Liche Master', 168, 155, 125, 38, 505, 168, 0), +(113, 'Zealot', 168, 155, 125, 38, 530, 177, 0), +(114, 'Serafiend', 170, 155, 125, 38, 555, 185, 0), +(115, 'Pale Knight', 175, 160, 130, 39, 580, 193, 0), +(116, 'Blue Dragon', 180, 160, 130, 39, 605, 202, 0), +(117, 'Obsessive', 180, 160, 135, 40, 630, 210, 0), +(118, 'Devil', 184, 164, 135, 40, 666, 222, 0), +(119, 'Liche Prince', 190, 168, 138, 40, 660, 220, 0), +(120, 'Cherufiend', 195, 170, 140, 41, 690, 230, 0), +(121, 'Red Dragon', 200, 180, 145, 41, 720, 240, 0), +(122, 'Greater Devil', 200, 180, 145, 41, 750, 250, 0), +(123, 'Renegade', 205, 185, 150, 42, 780, 260, 0), +(124, 'Archfiend', 210, 190, 150, 42, 810, 270, 0), +(125, 'Liche Lord', 210, 190, 155, 42, 850, 283, 0), +(126, 'Greatest Devil', 215, 195, 160, 43, 890, 297, 0), +(127, 'Dark Knight', 220, 200, 160, 43, 930, 310, 0), +(128, 'Giant', 220, 200, 165, 43, 970, 323, 0), +(129, 'Shadow Dragon', 225, 200, 170, 44, 1010, 337, 0), +(130, 'Liche King', 225, 205, 170, 44, 1050, 350, 0), +(131, 'Incubus', 230, 205, 175, 44, 1100, 367, 1), +(132, 'Traitor', 230, 205, 175, 45, 1150, 383, 0), +(133, 'Demon', 240, 210, 180, 45, 1200, 400, 0), +(134, 'Dark Dragon', 245, 215, 180, 45, 1250, 417, 1), +(135, 'Insurgent', 250, 220, 190, 46, 1300, 433, 0), +(136, 'Leviathan', 255, 225, 190, 46, 1350, 450, 0), +(137, 'Grey Daemon', 260, 230, 190, 46, 1400, 467, 0), +(138, 'Succubus', 265, 240, 200, 47, 1460, 487, 1), +(139, 'Demon Prince', 270, 240, 200, 47, 1520, 507, 0), +(140, 'Black Dragon', 275, 250, 205, 47, 1580, 527, 1), +(141, 'Nihilist', 280, 250, 205, 47, 1640, 547, 0), +(142, 'Behemoth', 285, 260, 210, 48, 1700, 567, 0), +(143, 'Demagogue', 290, 260, 210, 48, 1760, 587, 0), +(144, 'Demon Lord', 300, 270, 220, 48, 1820, 607, 0), +(145, 'Red Daemon', 310, 280, 230, 48, 1880, 627, 0), +(146, 'Colossus', 320, 300, 240, 49, 1940, 647, 0), +(147, 'Demon King', 330, 300, 250, 49, 2000, 667, 0), +(148, 'Dark Daemon', 340, 320, 260, 49, 2200, 733, 1), +(149, 'Titan', 360, 340, 270, 50, 2400, 800, 0), +(150, 'Black Daemon', 400, 400, 280, 50, 3000, 1000, 1), +(151, 'Lucifuge', 600, 600, 400, 50, 10000, 10000, 2); + +DROP TABLE IF EXISTS news; +CREATE TABLE news ( + `id` INTEGER PRIMARY KEY AUTOINCREMENT, + `author` INTEGER NOT NULL DEFAULT 0, + `posted` INTEGER NOT NULL DEFAULT (unixepoch()), + `content` TEXT NOT NULL +); +INSERT INTO news (content) VALUES ('This is the first news post. Please use the admin control panel to add another one and make this one go away.'); + +DROP TABLE IF EXISTS spells; +CREATE TABLE spells ( + `id` INTEGER PRIMARY KEY AUTOINCREMENT, + `name` TEXT NOT NULL, + `mp` INTEGER NOT NULL DEFAULT 0, + `attribute` INTEGER NOT NULL DEFAULT 0, + `type` INTEGER NOT NULL DEFAULT 0 +); +INSERT INTO spells VALUES +(1, 'Heal', 5, 10, 1), +(2, 'Revive', 10, 25, 1), +(3, 'Life', 25, 50, 1), +(4, 'Breath', 50, 100, 1), +(5, 'Gaia', 75, 150, 1), +(6, 'Hurt', 5, 15, 2), +(7, 'Pain', 12, 35, 2), +(8, 'Maim', 25, 70, 2), +(9, 'Rend', 40, 100, 2), +(10, 'Chaos', 50, 130, 2), +(11, 'Sleep', 10, 5, 3), +(12, 'Dream', 30, 9, 3), +(13, 'Nightmare', 60, 13, 3), +(14, 'Craze', 10, 10, 4), +(15, 'Rage', 20, 25, 4), +(16, 'Fury', 30, 50, 4), +(17, 'Ward', 10, 10, 5), +(18, 'Fend', 20, 25, 5), +(19, 'Barrier', 30, 50, 5); + +DROP TABLE IF EXISTS towns; +CREATE TABLE towns ( + `id` INTEGER PRIMARY KEY AUTOINCREMENT, + `name` TEXT NOT NULL, + `x` INTEGER NOT NULL DEFAULT 0, + `y` INTEGER NOT NULL DEFAULT 0, + `inn_cost` INTEGER NOT NULL DEFAULT 0, + `map_cost` INTEGER NOT NULL DEFAULT 0, + `tp_cost` INTEGER NOT NULL DEFAULT 0, + `shop_list` TEXT NOT NULL +); +INSERT INTO towns VALUES +(1, 'Midworld', 0, 0, 5, 0, 0, '1,2,3,17,18,19,28,29'), +(2, 'Roma', 30, 30, 10, 25, 5, '2,3,4,18,19,29'), +(3, 'Bris', 70, -70, 25, 50, 15, '2,3,4,5,18,19,20,29.30'), +(4, 'Kalle', -100, 100, 40, 100, 30, '5,6,8,10,12,21,22,23,29,30'), +(5, 'Narcissa', -130, -130, 60, 500, 50, '4,7,9,11,13,21,22,23,29,30,31'), +(6, 'Hambry', 170, 170, 90, 1000, 80, '10,11,12,13,14,23,24,30,31'), +(7, 'Gilead', 200, -200, 100, 3000, 110, '12,13,14,15,24,25,26,32'), +(8, 'Endworld', -250, -250, 125, 9000, 160, '16,27,33'); \ No newline at end of file diff --git a/internal/models/babble/babble.go b/internal/models/babble/babble.go index 72a7ed3..63a2b73 100644 --- a/internal/models/babble/babble.go +++ b/internal/models/babble/babble.go @@ -12,7 +12,7 @@ import ( type Babble struct { ID int Posted int64 - Author string + Author int Babble string } @@ -20,7 +20,7 @@ type Babble struct { func New() *Babble { return &Babble{ Posted: time.Now().Unix(), - Author: "", + Author: 0, Babble: "", } } @@ -30,8 +30,8 @@ func (b *Babble) Validate() error { if b.Posted <= 0 { return fmt.Errorf("babble Posted timestamp must be positive") } - if strings.TrimSpace(b.Author) == "" { - return fmt.Errorf("babble Author cannot be empty") + if b.Author <= 0 { + return fmt.Errorf("babble Author must be a valid user ID") } if strings.TrimSpace(b.Babble) == "" { return fmt.Errorf("babble message cannot be empty") @@ -39,7 +39,6 @@ func (b *Babble) Validate() error { return nil } -// CRUD operations func (b *Babble) Delete() error { return database.Exec("DELETE FROM babble WHERE id = %d", b.ID) } @@ -53,7 +52,6 @@ func (b *Babble) Insert() error { return nil } -// Query functions func Find(id int) (*Babble, error) { var babble Babble err := database.Get(&babble, "SELECT * FROM babble WHERE id = %d", id) @@ -69,9 +67,9 @@ func All() ([]*Babble, error) { return babbles, err } -func ByAuthor(author string) ([]*Babble, error) { +func ByAuthor(authorID int) ([]*Babble, error) { var babbles []*Babble - err := database.Select(&babbles, "SELECT * FROM babble WHERE author = %s COLLATE NOCASE ORDER BY posted DESC, id DESC", author) + err := database.Select(&babbles, "SELECT * FROM babble WHERE author = %d ORDER BY posted DESC, id DESC", authorID) return babbles, err } @@ -100,13 +98,12 @@ func Search(term string) ([]*Babble, error) { return babbles, err } -func RecentByAuthor(author string, limit int) ([]*Babble, error) { +func RecentByAuthor(authorID int, limit int) ([]*Babble, error) { var babbles []*Babble - err := database.Select(&babbles, "SELECT * FROM babble WHERE author = %s COLLATE NOCASE ORDER BY posted DESC, id DESC LIMIT %d", author, limit) + err := database.Select(&babbles, "SELECT * FROM babble ORDER BY posted DESC, id DESC LIMIT %d", authorID, limit) return babbles, err } -// Helper methods func (b *Babble) PostedTime() time.Time { return time.Unix(b.Posted, 0) } @@ -123,8 +120,8 @@ func (b *Babble) Age() time.Duration { return time.Since(b.PostedTime()) } -func (b *Babble) IsAuthor(username string) bool { - return strings.EqualFold(b.Author, username) +func (b *Babble) IsAuthor(userID int) bool { + return b.Author == userID } func (b *Babble) Preview(maxLength int) string { diff --git a/internal/models/forum/forum.go b/internal/models/forum/forum.go index 81fb54a..985e1db 100644 --- a/internal/models/forum/forum.go +++ b/internal/models/forum/forum.go @@ -83,13 +83,13 @@ func Find(id int) (*Forum, error) { func All() ([]*Forum, error) { var forums []*Forum - err := database.Select(&forums, "SELECT * FROM forum ORDER BY last_post DESC, id DESC") + err := database.Select(&forums, "SELECT * FROM forum ORDER BY newpostdate DESC, id DESC") return forums, err } func Threads() ([]*Forum, error) { var forums []*Forum - err := database.Select(&forums, "SELECT * FROM forum WHERE parent = 0 ORDER BY last_post DESC, id DESC") + err := database.Select(&forums, "SELECT * FROM forum WHERE parent = 0 ORDER BY newpostdate DESC, id DESC") return forums, err } @@ -97,37 +97,37 @@ func ByParent(parentID int) ([]*Forum, error) { var forums []*Forum if parentID > 0 { // Replies sorted chronologically - err := database.Select(&forums, "SELECT * FROM forum WHERE parent = %d ORDER BY posted ASC, id ASC", parentID) + err := database.Select(&forums, "SELECT * FROM forum WHERE parent = %d ORDER BY postdate ASC, id ASC", parentID) return forums, err } else { // Threads sorted by last activity - err := database.Select(&forums, "SELECT * FROM forum WHERE parent = %d ORDER BY last_post DESC, id DESC", parentID) + err := database.Select(&forums, "SELECT * FROM forum WHERE parent = %d ORDER BY newpostdate DESC, id DESC", parentID) return forums, err } } func ByAuthor(authorID int) ([]*Forum, error) { var forums []*Forum - err := database.Select(&forums, "SELECT * FROM forum WHERE author = %d ORDER BY posted DESC, id DESC", authorID) + err := database.Select(&forums, "SELECT * FROM forum WHERE author = %d ORDER BY postdate DESC, id DESC", authorID) return forums, err } func Recent(limit int) ([]*Forum, error) { var forums []*Forum - err := database.Select(&forums, "SELECT * FROM forum ORDER BY last_post DESC, id DESC LIMIT %d", limit) + err := database.Select(&forums, "SELECT * FROM forum ORDER BY newpostdate DESC, id DESC LIMIT %d", limit) return forums, err } func Search(term string) ([]*Forum, error) { var forums []*Forum searchTerm := "%" + term + "%" - err := database.Select(&forums, "SELECT * FROM forum WHERE title LIKE %s OR content LIKE %s ORDER BY last_post DESC, id DESC", searchTerm, searchTerm) + err := database.Select(&forums, "SELECT * FROM forum WHERE title LIKE %s OR content LIKE %s ORDER BY newpostdate DESC, id DESC", searchTerm, searchTerm) return forums, err } func Since(since int64) ([]*Forum, error) { var forums []*Forum - err := database.Select(&forums, "SELECT * FROM forum WHERE last_post >= %d ORDER BY last_post DESC, id DESC", since) + err := database.Select(&forums, "SELECT * FROM forum WHERE newpostdate >= %d ORDER BY newpostdate DESC, id DESC", since) return forums, err } diff --git a/main.go b/main.go index dec7d5c..36248de 100644 --- a/main.go +++ b/main.go @@ -9,21 +9,10 @@ import ( "path/filepath" "syscall" - "dk/internal/models/babble" - "dk/internal/models/control" - "dk/internal/models/drops" - "dk/internal/models/fights" - "dk/internal/models/forum" - "dk/internal/models/items" - "dk/internal/models/monsters" - "dk/internal/models/news" - "dk/internal/models/spells" - "dk/internal/models/towns" "dk/internal/models/users" "dk/internal/routes" "dk/internal/template" - nigiri "git.sharkk.net/Sharkk/Nigiri" sushi "git.sharkk.net/Sharkk/Sushi" "git.sharkk.net/Sharkk/Sushi/auth" "git.sharkk.net/Sharkk/Sushi/csrf" @@ -68,11 +57,6 @@ func start(port string) error { template.InitializeCache(cwd) - db := nigiri.NewCollection(filepath.Join(cwd, "data")) - if err := setupStores(db); err != nil { - return fmt.Errorf("failed to setup Nigiri stores: %w", err) - } - app := sushi.New() sushi.InitSessions(filepath.Join(cwd, "data/_sessions.json")) @@ -108,11 +92,6 @@ func start(port string) error { <-c log.Println("\nReceived shutdown signal, shutting down gracefully...") - log.Println("Saving database...") - if err := db.Save(); err != nil { - log.Printf("Error saving database: %v", err) - } - log.Println("Saving sessions...") sushi.SaveSessions() @@ -120,33 +99,6 @@ func start(port string) error { return nil } -func setupStores(db *nigiri.Collection) error { - users.Init(db) - towns.Init(db) - spells.Init(db) - news.Init(db) - monsters.Init(db) - items.Init(db) - forum.Init(db) - drops.Init(db) - babble.Init(db) - fights.Init(db) - control.Init(db) - - db.Add("users", users.GetStore()) - db.Add("towns", towns.GetStore()) - db.Add("spells", spells.GetStore()) - db.Add("news", news.GetStore()) - db.Add("monsters", monsters.GetStore()) - db.Add("items", items.GetStore()) - db.Add("forum", forum.GetStore()) - db.Add("drops", drops.GetStore()) - db.Add("babble", babble.GetStore()) - db.Add("fights", fights.GetStore()) - - return nil -} - func getUserByID(userID int) any { return users.GetByID(userID) }