2019-05-03 05:58:36 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2019-05-06 16:05:43 +02:00
|
|
|
"errors"
|
2019-05-10 16:13:14 +02:00
|
|
|
"fmt"
|
2019-05-03 05:58:36 +02:00
|
|
|
"log"
|
2019-05-08 12:47:32 +02:00
|
|
|
"regexp"
|
2019-05-06 06:01:01 +02:00
|
|
|
"strconv"
|
2019-05-03 05:58:36 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
func initDB() {
|
|
|
|
log.Println("Setting up database...")
|
|
|
|
|
|
|
|
tx, err := db.Begin()
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
defer tx.Rollback()
|
|
|
|
|
|
|
|
_, err = tx.Exec("set foreign_key_checks = 0")
|
2019-05-06 05:03:12 +02:00
|
|
|
failOnError(err, "initDB : set foreign_key_checks = 0")
|
2019-05-03 05:58:36 +02:00
|
|
|
|
|
|
|
var name string
|
2019-05-10 12:19:38 +02:00
|
|
|
rows, err := db.Query("show tables")
|
2019-05-06 05:03:12 +02:00
|
|
|
failOnError(err, "initDB : show tables")
|
|
|
|
|
2019-05-03 05:58:36 +02:00
|
|
|
for rows.Next() {
|
|
|
|
err = rows.Scan(&name)
|
2019-05-06 05:03:12 +02:00
|
|
|
failOnError(err, "initDB : show tables listing")
|
|
|
|
|
2019-07-08 05:49:56 +02:00
|
|
|
if ok, _ := regexp.MatchString(`^.*_v$`, name); ok {
|
2019-07-08 05:49:03 +02:00
|
|
|
_, err = tx.Exec("drop view " + name)
|
|
|
|
failOnError(err, "initDB : drop view "+name)
|
|
|
|
} else {
|
|
|
|
_, err = tx.Exec("drop table " + name)
|
|
|
|
failOnError(err, "initDB : drop table "+name)
|
|
|
|
}
|
2019-05-03 05:58:36 +02:00
|
|
|
}
|
|
|
|
err = rows.Err()
|
2019-05-06 05:03:12 +02:00
|
|
|
failOnError(err, "initDB : show tables listing end")
|
2019-05-03 05:58:36 +02:00
|
|
|
rows.Close()
|
|
|
|
|
|
|
|
_, err = tx.Exec("set foreign_key_checks = 1")
|
2019-05-06 05:03:12 +02:00
|
|
|
failOnError(err, "initDB : set foreign_key_checks = 1")
|
2019-05-03 05:58:36 +02:00
|
|
|
|
|
|
|
err = tx.Commit()
|
2019-05-06 05:03:12 +02:00
|
|
|
failOnError(err, "initDB : commit cleanup")
|
2019-05-03 05:58:36 +02:00
|
|
|
|
2019-05-11 09:48:39 +02:00
|
|
|
log.Println("initDB : Database cleaned up")
|
2019-05-04 10:57:24 +02:00
|
|
|
|
|
|
|
_, err = db.Exec(`CREATE TABLE code_obj_type (
|
2019-05-07 13:15:25 +02:00
|
|
|
id SMALLINT UNSIGNED NOT NULL
|
2019-05-04 10:57:24 +02:00
|
|
|
,intl_id VARCHAR(32) NOT NULL
|
|
|
|
,name VARCHAR(80) NOT NULL
|
|
|
|
,PRIMARY KEY (id)
|
2019-05-18 13:11:53 +02:00
|
|
|
,UNIQUE KEY (intl_id)
|
2019-06-25 11:54:46 +02:00
|
|
|
) ENGINE = InnoDB CHARSET=utf8mb4 COLLATE utf8mb4_bin;`)
|
2019-05-06 05:03:12 +02:00
|
|
|
failOnError(err, "initDB : create table code_obj_type")
|
2019-05-11 09:48:39 +02:00
|
|
|
log.Println("initDB : code_obj_type created ...")
|
2019-05-04 10:57:24 +02:00
|
|
|
|
2019-05-05 13:29:28 +02:00
|
|
|
_, err = db.Exec(`CREATE TABLE code_obj_sub_type (
|
2019-05-07 13:15:25 +02:00
|
|
|
id SMALLINT UNSIGNED NOT NULL
|
|
|
|
,intl_id VARCHAR(32) NOT NULL
|
|
|
|
,name VARCHAR(80) NOT NULL
|
2019-05-05 13:29:28 +02:00
|
|
|
,obj_type_id SMALLINT UNSIGNED NOT NULL
|
|
|
|
,PRIMARY KEY (id)
|
2019-05-18 13:11:53 +02:00
|
|
|
,UNIQUE KEY (intl_id)
|
2019-05-05 13:29:28 +02:00
|
|
|
,FOREIGN KEY (obj_type_id) REFERENCES code_obj_type(id) ON DELETE CASCADE
|
2019-06-25 11:54:46 +02:00
|
|
|
) ENGINE = InnoDB CHARSET=utf8mb4 COLLATE utf8mb4_bin;`)
|
2019-05-06 05:03:12 +02:00
|
|
|
failOnError(err, "initDB : create table code_obj_sub_type")
|
2019-05-11 09:48:39 +02:00
|
|
|
log.Println("initDB : code_obj_sub_type created ...")
|
2019-05-05 13:29:28 +02:00
|
|
|
|
2019-05-04 10:57:24 +02:00
|
|
|
_, err = db.Exec(`CREATE TABLE obj (
|
2019-05-06 05:09:31 +02:00
|
|
|
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT
|
|
|
|
,obj_type_id SMALLINT UNSIGNED NOT NULL
|
|
|
|
,obj_sub_type_id SMALLINT UNSIGNED NOT NULL
|
2019-05-10 11:23:47 +02:00
|
|
|
,timestamp TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
|
2019-05-04 10:57:24 +02:00
|
|
|
,PRIMARY KEY (id)
|
2019-05-08 12:36:29 +02:00
|
|
|
,FOREIGN KEY (obj_type_id) REFERENCES code_obj_type(id) ON DELETE CASCADE
|
|
|
|
,FOREIGN KEY (obj_sub_type_id) REFERENCES code_obj_sub_type(id) ON DELETE CASCADE
|
2019-06-25 11:54:46 +02:00
|
|
|
) ENGINE = InnoDB AUTO_INCREMENT = 0 CHARSET=utf8mb4 COLLATE utf8mb4_bin;`)
|
2019-05-06 05:03:12 +02:00
|
|
|
failOnError(err, "initDB : create table obj")
|
2019-05-11 09:48:39 +02:00
|
|
|
log.Println("initDB : obj created ...")
|
2019-05-04 10:57:24 +02:00
|
|
|
|
2019-05-25 09:25:11 +02:00
|
|
|
_, err = db.Exec(`CREATE TABLE obj_castle (
|
|
|
|
obj_id BIGINT UNSIGNED NOT NULL
|
2019-05-25 09:50:17 +02:00
|
|
|
,logo VARCHAR(32) NOT NULL
|
2019-05-25 09:25:11 +02:00
|
|
|
,name VARCHAR(80) NOT NULL
|
|
|
|
,FOREIGN KEY (obj_id) REFERENCES obj(id) ON DELETE CASCADE
|
2019-06-25 11:54:46 +02:00
|
|
|
) ENGINE = InnoDB CHARSET=utf8mb4 COLLATE utf8mb4_bin;`)
|
2019-05-25 09:25:11 +02:00
|
|
|
failOnError(err, "initDB : create table obj_castle")
|
|
|
|
log.Println("initDB : obj_guild created ...")
|
|
|
|
|
|
|
|
_, err = db.Exec(`CREATE TABLE obj_guild (
|
|
|
|
obj_id BIGINT UNSIGNED NOT NULL
|
|
|
|
,tag VARCHAR(32) NOT NULL
|
|
|
|
,name VARCHAR(80) NOT NULL
|
|
|
|
,chat_id BIGINT
|
|
|
|
,deposit_chat_id BIGINT
|
|
|
|
,FOREIGN KEY (obj_id) REFERENCES obj(id) ON DELETE CASCADE
|
2019-06-25 11:54:46 +02:00
|
|
|
) ENGINE = InnoDB CHARSET=utf8mb4 COLLATE utf8mb4_bin;`)
|
2019-05-25 09:25:11 +02:00
|
|
|
failOnError(err, "initDB : create table obj_guild")
|
|
|
|
log.Println("initDB : obj_guild created ...")
|
|
|
|
|
2019-05-04 10:57:24 +02:00
|
|
|
_, err = db.Exec(`CREATE TABLE obj_user (
|
|
|
|
obj_id BIGINT UNSIGNED NOT NULL
|
|
|
|
,name VARCHAR(80) NOT NULL
|
|
|
|
,FOREIGN KEY (obj_id) REFERENCES obj(id) ON DELETE CASCADE
|
2019-06-25 11:54:46 +02:00
|
|
|
) ENGINE = InnoDB CHARSET=utf8mb4 COLLATE utf8mb4_bin;`)
|
2019-05-06 05:03:12 +02:00
|
|
|
failOnError(err, "initDB : create table obj_user")
|
2019-05-11 09:48:39 +02:00
|
|
|
log.Println("initDB : obj_user created ...")
|
2019-05-04 10:57:24 +02:00
|
|
|
|
2019-07-09 10:07:46 +02:00
|
|
|
_, err = db.Exec(`CREATE VIEW obj_user_v AS
|
|
|
|
SELECT ou.obj_id
|
|
|
|
,ou.name COLLATE utf8mb4_unicode_ci AS name
|
|
|
|
FROM obj_user ou;`)
|
|
|
|
failOnError(err, "initDB : create view obj_user_v")
|
|
|
|
log.Println("initDB : obj_user_v created ...")
|
|
|
|
|
2019-05-07 05:12:03 +02:00
|
|
|
_, err = db.Exec(`CREATE TABLE obj_war (
|
|
|
|
obj_id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT
|
2019-05-09 12:36:45 +02:00
|
|
|
,start_time DATETIME NOT NULL
|
|
|
|
,end_time DATETIME NOT NULL
|
2019-05-07 05:12:03 +02:00
|
|
|
,FOREIGN KEY (obj_id) REFERENCES obj(id) ON DELETE CASCADE
|
2019-06-25 11:54:46 +02:00
|
|
|
) ENGINE = InnoDB CHARSET=utf8mb4 COLLATE utf8mb4_bin;`)
|
2019-05-07 05:12:03 +02:00
|
|
|
failOnError(err, "initDB : create table obj_war")
|
2019-05-11 09:48:39 +02:00
|
|
|
log.Println("initDB : obj_war created ...")
|
2019-05-07 05:12:03 +02:00
|
|
|
|
2019-05-04 10:57:24 +02:00
|
|
|
_, err = db.Exec(`CREATE TABLE obj_msg (
|
|
|
|
obj_id BIGINT UNSIGNED NOT NULL
|
|
|
|
,msg_id BIGINT NOT NULL
|
|
|
|
,chat_id BIGINT NOT NULL
|
2019-08-13 05:09:44 +02:00
|
|
|
,user_id BIGINT NOT NULL CHECK (user_id > 0)
|
|
|
|
,sender_user_id BIGINT NOT NULL CHECK (sender_user_id > 0)
|
2019-05-09 12:36:45 +02:00
|
|
|
,date DATETIME NOT NULL
|
2019-05-04 10:57:24 +02:00
|
|
|
,text VARCHAR(4096) NOT NULL
|
|
|
|
,FOREIGN KEY (obj_id) REFERENCES obj(id) ON DELETE CASCADE
|
2019-08-13 05:09:44 +02:00
|
|
|
,UNIQUE KEY (msg_id, chat_id, user_id, sender_user_id)
|
2019-06-25 11:54:46 +02:00
|
|
|
) ENGINE = InnoDB CHARSET=utf8mb4 COLLATE utf8mb4_bin;`)
|
2019-05-06 05:03:12 +02:00
|
|
|
failOnError(err, "initDB : create table obj_msg")
|
2019-05-11 09:48:39 +02:00
|
|
|
log.Println("initDB : obj_msg created ...")
|
2019-05-03 05:58:36 +02:00
|
|
|
|
2019-07-09 06:56:41 +02:00
|
|
|
_, err = db.Exec(`CREATE VIEW obj_msg_v AS
|
|
|
|
SELECT om.obj_id
|
|
|
|
,om.msg_id
|
|
|
|
,om.chat_id
|
|
|
|
,om.user_id
|
|
|
|
,om.sender_user_id
|
|
|
|
,om.date
|
|
|
|
,om.text COLLATE utf8mb4_unicode_ci AS text
|
|
|
|
FROM obj_msg om;`)
|
|
|
|
failOnError(err, "initDB : create view obj_msg_v")
|
|
|
|
log.Println("initDB : obj_msg_v created ...")
|
|
|
|
|
2019-05-15 12:02:17 +02:00
|
|
|
_, err = db.Exec(`CREATE TABLE obj_msg_pillage_inc (
|
|
|
|
obj_id BIGINT UNSIGNED NOT NULL
|
|
|
|
,attacker VARCHAR(32)
|
|
|
|
,guild VARCHAR(32)
|
2019-05-25 09:41:16 +02:00
|
|
|
,castle_id BIGINT UNSIGNED NOT NULL
|
2019-05-15 12:02:17 +02:00
|
|
|
,FOREIGN KEY (obj_id) REFERENCES obj(id) ON DELETE CASCADE
|
2019-05-25 09:41:16 +02:00
|
|
|
,FOREIGN KEY (castle_id) REFERENCES obj_castle(obj_id) ON DELETE CASCADE
|
2019-06-25 11:54:46 +02:00
|
|
|
) ENGINE = InnoDB CHARSET=utf8mb4 COLLATE utf8mb4_bin;`)
|
2019-05-15 12:02:17 +02:00
|
|
|
failOnError(err, "initDB : create table obj_msg_report")
|
|
|
|
log.Println("initDB : obj_msg_report created ...")
|
|
|
|
|
2019-05-05 13:29:28 +02:00
|
|
|
_, err = db.Exec(`CREATE TABLE obj_msg_report (
|
2019-05-06 12:43:42 +02:00
|
|
|
obj_id BIGINT UNSIGNED NOT NULL
|
2019-05-07 05:12:03 +02:00
|
|
|
,war_id BIGINT UNSIGNED NOT NULL
|
|
|
|
,FOREIGN KEY (obj_id) REFERENCES obj(id) ON DELETE CASCADE
|
|
|
|
,FOREIGN KEY (war_id) REFERENCES obj(id) ON DELETE CASCADE
|
2019-06-25 11:54:46 +02:00
|
|
|
) ENGINE = InnoDB CHARSET=utf8mb4 COLLATE utf8mb4_bin;`)
|
2019-05-07 05:12:03 +02:00
|
|
|
failOnError(err, "initDB : create table obj_msg_report")
|
2019-05-11 09:48:39 +02:00
|
|
|
log.Println("initDB : obj_msg_report created ...")
|
2019-05-07 05:12:03 +02:00
|
|
|
|
|
|
|
_, err = db.Exec(`CREATE TABLE obj_war_report (
|
|
|
|
obj_id BIGINT UNSIGNED NOT NULL
|
|
|
|
,user_id BIGINT UNSIGNED NOT NULL
|
|
|
|
,war_id BIGINT UNSIGNED NOT NULL
|
2019-05-06 12:43:42 +02:00
|
|
|
,attack SMALLINT UNSIGNED NOT NULL
|
|
|
|
,defense SMALLINT UNSIGNED NOT NULL
|
|
|
|
,gold SMALLINT UNSIGNED NOT NULL
|
2019-05-06 15:50:57 +02:00
|
|
|
,stock SMALLINT UNSIGNED NOT NULL
|
2019-05-05 13:29:28 +02:00
|
|
|
,exp SMALLINT UNSIGNED NOT NULL
|
2019-05-06 12:43:42 +02:00
|
|
|
,stamina TINYINT NOT NULL
|
|
|
|
,crit TINYINT NOT NULL
|
2019-05-05 13:29:28 +02:00
|
|
|
,FOREIGN KEY (obj_id) REFERENCES obj(id) ON DELETE CASCADE
|
2019-05-07 05:12:03 +02:00
|
|
|
,FOREIGN KEY (war_id) REFERENCES obj(id) ON DELETE CASCADE
|
|
|
|
,UNIQUE KEY (user_id, war_id)
|
2019-06-25 11:54:46 +02:00
|
|
|
) ENGINE = InnoDB CHARSET=utf8mb4 COLLATE utf8mb4_bin;`)
|
2019-05-11 09:48:39 +02:00
|
|
|
failOnError(err, "initDB : create table obj_war_report")
|
|
|
|
log.Println("initDB : obj_war_report created ...")
|
2019-05-05 13:29:28 +02:00
|
|
|
|
2019-05-09 11:19:02 +02:00
|
|
|
_, err = db.Exec(`CREATE TABLE obj_msg_auction_announce (
|
2019-06-06 07:52:22 +02:00
|
|
|
obj_id BIGINT UNSIGNED NOT NULL
|
|
|
|
,lot_id BIGINT UNSIGNED NOT NULL
|
2019-06-06 08:08:25 +02:00
|
|
|
,item_id BIGINT UNSIGNED
|
2019-06-06 07:52:22 +02:00
|
|
|
,cond VARCHAR(32)
|
|
|
|
,quality VARCHAR(32)
|
|
|
|
,seller_castle_id BIGINT UNSIGNED
|
|
|
|
,seller_guild_id BIGINT UNSIGNED
|
|
|
|
,seller_id BIGINT UNSIGNED
|
|
|
|
,buyer_castle_id BIGINT UNSIGNED
|
|
|
|
,buyer_guild_id BIGINT UNSIGNED
|
|
|
|
,buyer_id BIGINT UNSIGNED
|
|
|
|
,price SMALLINT NOT NULL
|
|
|
|
,status VARCHAR(32)
|
|
|
|
,end DATETIME NOT NULL
|
2019-05-08 15:39:04 +02:00
|
|
|
,FOREIGN KEY (obj_id) REFERENCES obj(id) ON DELETE CASCADE
|
2019-06-10 12:45:33 +02:00
|
|
|
,FOREIGN KEY (seller_id) REFERENCES obj_user(obj_id) ON DELETE CASCADE
|
|
|
|
,FOREIGN KEY (buyer_id) REFERENCES obj_user(obj_id) ON DELETE CASCADE
|
|
|
|
,FOREIGN KEY (seller_guild_id) REFERENCES obj_guild(obj_id) ON DELETE CASCADE
|
|
|
|
,FOREIGN KEY (buyer_guild_id) REFERENCES obj_guild(obj_id) ON DELETE CASCADE
|
|
|
|
,FOREIGN KEY (seller_castle_id) REFERENCES obj_castle(obj_id) ON DELETE CASCADE
|
|
|
|
,FOREIGN KEY (buyer_castle_id) REFERENCES obj_castle(obj_id) ON DELETE CASCADE
|
2019-05-11 09:55:42 +02:00
|
|
|
,KEY (lot_id)
|
2019-06-25 11:54:46 +02:00
|
|
|
) ENGINE = InnoDB CHARSET=utf8mb4 COLLATE utf8mb4_bin;`)
|
2019-05-09 11:19:02 +02:00
|
|
|
failOnError(err, "initDB : create table obj_msg_auction_announce")
|
2019-05-11 09:48:39 +02:00
|
|
|
log.Println("initDB : obj_msg_auction_announce created ...")
|
2019-05-08 15:39:04 +02:00
|
|
|
|
2019-05-14 04:28:26 +02:00
|
|
|
_, err = db.Exec(`CREATE TABLE obj_msg_mini_war (
|
|
|
|
obj_id BIGINT UNSIGNED NOT NULL
|
|
|
|
,date DATETIME NOT NULL
|
|
|
|
,FOREIGN KEY (obj_id) REFERENCES obj(id) ON DELETE CASCADE
|
|
|
|
,UNIQUE KEY (date)
|
2019-06-25 11:54:46 +02:00
|
|
|
) ENGINE = InnoDB CHARSET=utf8mb4 COLLATE utf8mb4_bin;`)
|
2019-05-14 04:28:26 +02:00
|
|
|
failOnError(err, "initDB : create table obj_msg_mini_war")
|
|
|
|
log.Println("initDB : obj_msg_mini_war created ...")
|
|
|
|
|
|
|
|
_, err = db.Exec(`CREATE TABLE obj_msg_mini_war_castle (
|
|
|
|
obj_id BIGINT UNSIGNED NOT NULL
|
2019-05-25 09:41:16 +02:00
|
|
|
,castle_id BIGINT UNSIGNED NOT NULL
|
2019-05-14 04:28:26 +02:00
|
|
|
,gardian TINYINT NOT NULL
|
|
|
|
,result VARCHAR(8)
|
2019-05-14 04:39:37 +02:00
|
|
|
,gold INT NOT NULL
|
|
|
|
,stock INT NOT NULL
|
|
|
|
,points INT NOT NULL
|
2019-05-14 04:28:26 +02:00
|
|
|
,FOREIGN KEY (obj_id) REFERENCES obj(id) ON DELETE CASCADE
|
2019-05-25 09:41:16 +02:00
|
|
|
,FOREIGN KEY (castle_id) REFERENCES obj_castle(obj_id) ON DELETE CASCADE
|
2019-05-14 04:28:26 +02:00
|
|
|
,UNIQUE KEY (obj_id, castle_id)
|
2019-06-25 11:54:46 +02:00
|
|
|
) ENGINE = InnoDB CHARSET=utf8mb4 COLLATE utf8mb4_bin;`)
|
2019-05-14 04:28:26 +02:00
|
|
|
failOnError(err, "initDB : create table obj_msg_mini_war_castle")
|
2019-05-19 14:00:18 +02:00
|
|
|
log.Println("initDB : obj_msg_mini_war_castle created ...")
|
|
|
|
|
|
|
|
_, err = db.Exec(`CREATE TABLE obj_msg_duel_fight (
|
|
|
|
obj_id BIGINT UNSIGNED NOT NULL
|
2019-05-25 09:41:16 +02:00
|
|
|
,win_castle_id BIGINT UNSIGNED NOT NULL
|
2019-05-25 10:24:59 +02:00
|
|
|
,win_guild_id BIGINT UNSIGNED
|
2019-05-25 10:56:13 +02:00
|
|
|
,win_user_id BIGINT UNSIGNED NOT NULL
|
2019-05-19 14:00:18 +02:00
|
|
|
,win_life SMALLINT NOT NULL
|
2019-05-25 09:41:16 +02:00
|
|
|
,loss_castle_id BIGINT UNSIGNED NOT NULL
|
2019-05-25 10:24:59 +02:00
|
|
|
,loss_guild_id BIGINT UNSIGNED
|
2019-05-25 10:56:13 +02:00
|
|
|
,loss_user_id BIGINT UNSIGNED NOT NULL
|
2019-05-19 14:00:18 +02:00
|
|
|
,loss_life SMALLINT NOT NULL
|
|
|
|
,exp INT UNSIGNED NOT NULL
|
|
|
|
,weapon VARCHAR(80)
|
|
|
|
,FOREIGN KEY (obj_id) REFERENCES obj(id) ON DELETE CASCADE
|
2019-05-25 09:41:16 +02:00
|
|
|
,FOREIGN KEY (win_castle_id) REFERENCES obj_castle(obj_id) ON DELETE CASCADE
|
|
|
|
,FOREIGN KEY (loss_castle_id) REFERENCES obj_castle(obj_id) ON DELETE CASCADE
|
2019-05-25 10:24:59 +02:00
|
|
|
,FOREIGN KEY (win_guild_id) REFERENCES obj_guild(obj_id) ON DELETE CASCADE
|
|
|
|
,FOREIGN KEY (loss_guild_id) REFERENCES obj_guild(obj_id) ON DELETE CASCADE
|
2019-05-25 10:56:13 +02:00
|
|
|
,FOREIGN KEY (win_user_id) REFERENCES obj_user(obj_id) ON DELETE CASCADE
|
|
|
|
,FOREIGN KEY (loss_user_id) REFERENCES obj_user(obj_id) ON DELETE CASCADE
|
2019-06-25 11:54:46 +02:00
|
|
|
) ENGINE = InnoDB CHARSET=utf8mb4 COLLATE utf8mb4_bin;`)
|
2019-05-19 14:00:18 +02:00
|
|
|
failOnError(err, "initDB : create table obj_msg_duel_fight")
|
|
|
|
log.Println("initDB : obj_msg_duel_fight created ...")
|
2019-05-14 04:28:26 +02:00
|
|
|
|
2019-05-10 04:26:37 +02:00
|
|
|
_, err = db.Exec(`CREATE TABLE obj_msg_auction_upd_req (
|
|
|
|
obj_id BIGINT UNSIGNED NOT NULL
|
|
|
|
,lot_id BIGINT UNSIGNED NOT NULL
|
|
|
|
,FOREIGN KEY (obj_id) REFERENCES obj(id) ON DELETE CASCADE
|
2019-05-11 09:45:20 +02:00
|
|
|
,KEY (lot_id)
|
2019-06-25 11:54:46 +02:00
|
|
|
) ENGINE = InnoDB CHARSET=utf8mb4 COLLATE utf8mb4_bin;`)
|
2019-05-10 04:26:37 +02:00
|
|
|
failOnError(err, "initDB : create table obj_msg_auction_upd_req")
|
2019-05-11 09:48:39 +02:00
|
|
|
log.Println("initDB : obj_msg_auction_upd_req created ...")
|
2019-05-10 04:26:37 +02:00
|
|
|
|
|
|
|
_, err = db.Exec(`CREATE TABLE obj_msg_auction_upd_ack (
|
|
|
|
obj_id BIGINT UNSIGNED NOT NULL
|
|
|
|
,seller VARCHAR(32)
|
|
|
|
,buyer VARCHAR(32)
|
|
|
|
,item VARCHAR(80)
|
|
|
|
,FOREIGN KEY (obj_id) REFERENCES obj(id) ON DELETE CASCADE
|
2019-06-25 11:54:46 +02:00
|
|
|
) ENGINE = InnoDB CHARSET=utf8mb4 COLLATE utf8mb4_bin;`)
|
2019-05-11 09:48:39 +02:00
|
|
|
failOnError(err, "initDB : create table obj_msg_auction_upd_ack")
|
|
|
|
log.Println("initDB : obj_msg_auction_upd_ack created ...")
|
2019-05-10 04:26:37 +02:00
|
|
|
|
2019-05-07 13:15:25 +02:00
|
|
|
_, err = db.Exec(`CREATE TABLE msg_rules (
|
|
|
|
id SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT
|
|
|
|
,prio SMALLINT NOT NULL
|
|
|
|
,descn VARCHAR(32) NOT NULL
|
|
|
|
,rule VARCHAR(4096) NOT NULL
|
2019-05-08 12:13:47 +02:00
|
|
|
,msg_type_id SMALLINT UNSIGNED NOT NULL
|
2019-05-07 13:15:25 +02:00
|
|
|
,UNIQUE KEY (id)
|
2019-06-25 11:54:46 +02:00
|
|
|
) ENGINE = InnoDB CHARSET=utf8mb4 COLLATE utf8mb4_bin;`)
|
2019-05-07 13:15:25 +02:00
|
|
|
failOnError(err, "initDB : create table msg_rules")
|
2019-05-11 09:48:39 +02:00
|
|
|
log.Println("initDB : msg_rules created ...")
|
2019-05-07 13:15:25 +02:00
|
|
|
|
2019-05-09 09:17:59 +02:00
|
|
|
_, err = db.Exec(`CREATE TABLE obj_item (
|
|
|
|
obj_id BIGINT UNSIGNED NOT NULL
|
|
|
|
,intl_id VARCHAR(32)
|
|
|
|
,weight SMALLINT NOT NULL
|
2019-08-21 05:46:42 +02:00
|
|
|
,exchange TINYINT NOT NULL
|
2019-08-19 12:41:43 +02:00
|
|
|
,auction TINYINT NOT NULL
|
2019-05-09 09:17:59 +02:00
|
|
|
,FOREIGN KEY (obj_id) REFERENCES obj(id) ON DELETE CASCADE
|
|
|
|
,UNIQUE KEY (intl_id)
|
2019-06-25 11:54:46 +02:00
|
|
|
) ENGINE = InnoDB CHARSET=utf8mb4 COLLATE utf8mb4_bin;`)
|
2019-05-11 08:45:44 +02:00
|
|
|
failOnError(err, "initDB : create table obj_item")
|
2019-05-11 09:48:39 +02:00
|
|
|
log.Println("initDB : obj_item created ...")
|
2019-05-09 09:17:59 +02:00
|
|
|
|
2019-05-31 04:02:21 +02:00
|
|
|
_, err = db.Exec(`CREATE TABLE obj_tribute (
|
|
|
|
obj_id BIGINT UNSIGNED NOT NULL
|
|
|
|
,user_id BIGINT UNSIGNED NOT NULL
|
|
|
|
,item_id BIGINT UNSIGNED NOT NULL
|
|
|
|
,quantity SMALLINT NOT NULL
|
|
|
|
,xp SMALLINT NOT NULL
|
|
|
|
,date DATETIME NOT NULL
|
|
|
|
,FOREIGN KEY (obj_id) REFERENCES obj(id) ON DELETE CASCADE
|
|
|
|
,FOREIGN KEY (user_id) REFERENCES obj_user(obj_id) ON DELETE CASCADE
|
|
|
|
,FOREIGN KEY (item_id) REFERENCES obj_item(obj_id) ON DELETE CASCADE
|
|
|
|
,UNIQUE KEY (user_id, date)
|
2019-06-25 11:54:46 +02:00
|
|
|
) ENGINE = InnoDB CHARSET=utf8mb4 COLLATE utf8mb4_bin;`)
|
2019-05-31 04:02:21 +02:00
|
|
|
failOnError(err, "initDB : create table obj_tribute")
|
|
|
|
log.Println("initDB : obj_tribute created ...")
|
|
|
|
|
|
|
|
_, err = db.Exec(`CREATE TABLE obj_xp (
|
|
|
|
obj_id BIGINT UNSIGNED NOT NULL
|
|
|
|
,user_id BIGINT UNSIGNED NOT NULL
|
|
|
|
,val BIGINT UNSIGNED NOT NULL
|
|
|
|
,target BIGINT UNSIGNED NOT NULL
|
|
|
|
,level SMALLINT UNSIGNED NOT NULL
|
|
|
|
,date DATETIME NOT NULL
|
|
|
|
,FOREIGN KEY (obj_id) REFERENCES obj(id) ON DELETE CASCADE
|
|
|
|
,FOREIGN KEY (user_id) REFERENCES obj_user(obj_id) ON DELETE CASCADE
|
|
|
|
,UNIQUE KEY (user_id, date)
|
2019-06-25 11:54:46 +02:00
|
|
|
) ENGINE = InnoDB CHARSET=utf8mb4 COLLATE utf8mb4_bin;`)
|
2019-05-31 04:02:21 +02:00
|
|
|
failOnError(err, "initDB : create table obj_xp")
|
|
|
|
log.Println("initDB : obj_xp created ...")
|
|
|
|
|
2019-07-09 06:56:41 +02:00
|
|
|
_, err = db.Exec(`CREATE TABLE obj_quest (
|
|
|
|
obj_id BIGINT UNSIGNED NOT NULL
|
|
|
|
,user_id BIGINT UNSIGNED NOT NULL
|
|
|
|
,duration SMALLINT UNSIGNED NOT NULL
|
|
|
|
,date DATETIME NOT NULL
|
|
|
|
,exp INT UNSIGNED NOT NULL
|
|
|
|
,gold INT UNSIGNED NOT NULL
|
|
|
|
,FOREIGN KEY (obj_id) REFERENCES obj(id) ON DELETE CASCADE
|
|
|
|
,FOREIGN KEY (user_id) REFERENCES obj_user(obj_id) ON DELETE CASCADE
|
|
|
|
,UNIQUE KEY (user_id, date)
|
|
|
|
) ENGINE = InnoDB CHARSET=utf8mb4 COLLATE utf8mb4_unicode_ci;`)
|
|
|
|
failOnError(err, "initDB : create table obj_quest")
|
|
|
|
log.Println("initDB : obj_xp obj_quest ...")
|
|
|
|
|
2019-05-10 11:23:47 +02:00
|
|
|
_, err = db.Exec(`CREATE TABLE obj_job (
|
|
|
|
obj_id BIGINT UNSIGNED NOT NULL
|
|
|
|
,priority SMALLINT NOT NULL
|
2019-05-15 12:31:03 +02:00
|
|
|
,user_id BIGINT UNSIGNED NOT NULL
|
2019-08-21 05:59:53 +02:00
|
|
|
,trigger_id BIGINT UNSIGNED NOT NULL
|
2019-05-10 11:23:47 +02:00
|
|
|
,schedule DATETIME NOT NULL
|
2019-05-11 06:54:12 +02:00
|
|
|
,is_done TINYINT NOT NULL
|
|
|
|
,in_work TINYINT NOT NULL
|
2019-06-03 03:19:06 +02:00
|
|
|
,seq_nr BIGINT UNSIGNED
|
2019-05-11 07:00:20 +02:00
|
|
|
,inserted TIMESTAMP
|
2019-05-11 06:54:12 +02:00
|
|
|
,pulled TIMESTAMP
|
|
|
|
,started TIMESTAMP
|
|
|
|
,ended TIMESTAMP
|
2019-08-23 14:09:08 +02:00
|
|
|
,timeout TIMESTAMP
|
2019-05-10 11:23:47 +02:00
|
|
|
,payload VARCHAR(4000)
|
|
|
|
,FOREIGN KEY (obj_id) REFERENCES obj(id) ON DELETE CASCADE
|
2019-05-18 16:36:04 +02:00
|
|
|
,KEY (is_done)
|
|
|
|
,KEY (in_work)
|
2019-05-15 12:31:03 +02:00
|
|
|
,KEY (user_id)
|
2019-06-25 11:54:46 +02:00
|
|
|
) ENGINE = InnoDB CHARSET=utf8mb4 COLLATE utf8mb4_bin;`)
|
2019-05-10 11:23:47 +02:00
|
|
|
failOnError(err, "initDB : create table obj_job")
|
2019-05-11 09:48:39 +02:00
|
|
|
log.Println("initDB : obj_job created ...")
|
2019-05-10 11:23:47 +02:00
|
|
|
|
2019-06-14 12:13:10 +02:00
|
|
|
_, err = db.Exec(`CREATE TABLE obj_name (
|
|
|
|
obj_id BIGINT UNSIGNED NOT NULL
|
|
|
|
,name VARCHAR(80)
|
|
|
|
,priority INT UNSIGNED NOT NULL
|
|
|
|
,FOREIGN KEY (obj_id) REFERENCES obj(id) ON DELETE CASCADE
|
|
|
|
,UNIQUE KEY(name)
|
2019-06-25 11:54:46 +02:00
|
|
|
) ENGINE = InnoDB CHARSET=utf8mb4 COLLATE utf8mb4_bin;`)
|
2019-06-14 12:13:10 +02:00
|
|
|
failOnError(err, "initDB : create table obj_name")
|
|
|
|
log.Println("initDB : obj_name created ...")
|
|
|
|
|
2019-07-08 05:44:23 +02:00
|
|
|
_, err = db.Exec(`CREATE VIEW obj_name_v AS
|
2019-07-09 06:56:41 +02:00
|
|
|
SELECT obn.obj_id
|
|
|
|
,obn.name COLLATE utf8mb4_unicode_ci AS name
|
|
|
|
,obn.priority
|
2019-07-08 05:44:23 +02:00
|
|
|
FROM obj_name obn;`)
|
|
|
|
failOnError(err, "initDB : create view obj_name_v")
|
|
|
|
log.Println("initDB : obj_name_v created ...")
|
|
|
|
|
2019-08-12 10:55:15 +02:00
|
|
|
_, err = db.Exec(`CREATE VIEW obj_item_name_v AS
|
|
|
|
SELECT obi.obj_id
|
2019-08-21 06:23:59 +02:00
|
|
|
,obi.intl_id COLLATE utf8mb4_unicode_ci AS intl_id
|
2019-08-12 10:55:15 +02:00
|
|
|
,obn.name COLLATE utf8mb4_unicode_ci AS name
|
|
|
|
,obn.priority
|
|
|
|
FROM obj_name obn
|
|
|
|
,obj_item obi
|
|
|
|
WHERE obi.obj_id = obn.obj_id
|
|
|
|
ORDER BY obi.intl_id ASC;`)
|
|
|
|
failOnError(err, "initDB : create view obj_item_name_v")
|
|
|
|
log.Println("initDB : obj_item_name_v created ...")
|
|
|
|
|
2019-05-04 10:57:24 +02:00
|
|
|
_, err = db.Exec(`INSERT INTO code_obj_type (id, intl_id, name)
|
2019-05-06 06:01:01 +02:00
|
|
|
VALUES (` + strconv.Itoa(objTypeUser) + `, "user", "User")
|
|
|
|
,(` + strconv.Itoa(objTypeGuild) + `, "guild", "Guild")
|
2019-05-07 05:12:03 +02:00
|
|
|
,(` + strconv.Itoa(objTypeMessage) + `, "msg", "Message")
|
|
|
|
,(` + strconv.Itoa(objTypeWar) + `, "war", "War")
|
|
|
|
,(` + strconv.Itoa(objTypeWarReport) + `, "war_report", "War Report")
|
2019-05-07 13:15:25 +02:00
|
|
|
,(` + strconv.Itoa(objTypeJob) + `, "job", "Job")
|
2019-05-09 09:17:59 +02:00
|
|
|
,(` + strconv.Itoa(objTypeItem) + `, "item", "Item")
|
2019-05-25 09:25:11 +02:00
|
|
|
,(` + strconv.Itoa(objTypeCastle) + `, "castle", "Castle")
|
|
|
|
,(` + strconv.Itoa(objTypeFair) + `, "fair", "Fair")
|
|
|
|
,(` + strconv.Itoa(objTypeUnion) + `, "union", "Trade Union")
|
2019-05-31 04:07:24 +02:00
|
|
|
,(` + strconv.Itoa(objTypeTribute) + `, "tribute", "Tribute")
|
|
|
|
,(` + strconv.Itoa(objTypeExperience) + `, "xp", "Experience")
|
2019-07-09 06:56:41 +02:00
|
|
|
,(` + strconv.Itoa(objTypeQuest) + `, "quest", "Quest")
|
2019-05-07 05:12:03 +02:00
|
|
|
;`)
|
2019-05-06 05:03:12 +02:00
|
|
|
failOnError(err, "initDB : populate table code_obj_type")
|
2019-05-11 09:49:42 +02:00
|
|
|
log.Println("initDB : code_obj_type populated ...")
|
2019-05-03 05:58:36 +02:00
|
|
|
|
2019-05-05 13:29:28 +02:00
|
|
|
_, err = db.Exec(`INSERT INTO code_obj_sub_type (id, intl_id, name, obj_type_id)
|
2019-05-25 09:25:11 +02:00
|
|
|
VALUES (` + strconv.Itoa(objSubTypeUser) + `, "user", "User", ` + strconv.Itoa(objTypeUser) + `)
|
2019-05-25 09:43:26 +02:00
|
|
|
,(` + strconv.Itoa(objSubTypeGuild) + `, "guild", "Guild", ` + strconv.Itoa(objTypeGuild) + `)
|
|
|
|
,(` + strconv.Itoa(objSubTypeMessageUnknown) + `, "unknown", "Unknown", ` + strconv.Itoa(objTypeMessage) + `)
|
2019-05-07 05:12:03 +02:00
|
|
|
,(` + strconv.Itoa(objSubTypeMessageWar) + `, "war", "War report", ` + strconv.Itoa(objTypeMessage) + `)
|
|
|
|
,(` + strconv.Itoa(objSubTypeMessageMiniWar) + `, "mini_war", "Mini war reprot", ` + strconv.Itoa(objTypeMessage) + `)
|
|
|
|
,(` + strconv.Itoa(objSubTypeMessageGuildWar) + `, "guild_war", "Guilds war report", ` + strconv.Itoa(objTypeMessage) + `)
|
2019-05-19 06:13:33 +02:00
|
|
|
,(` + strconv.Itoa(objSubTypeMessageReportReq) + `, "report_req", "Player war report request", ` + strconv.Itoa(objTypeMessage) + `)
|
|
|
|
,(` + strconv.Itoa(objSubTypeMessageReportAck) + `, "report_ack", "Player war report ack", ` + strconv.Itoa(objTypeMessage) + `)
|
|
|
|
,(` + strconv.Itoa(objSubTypeMessageGReportReq) + `, "g_report_req", "Player guilds war report request", ` + strconv.Itoa(objTypeMessage) + `)
|
|
|
|
,(` + strconv.Itoa(objSubTypeMessageGReportAck) + `, "g_report_ack", "Player guilds war report ack", ` + strconv.Itoa(objTypeMessage) + `)
|
|
|
|
,(` + strconv.Itoa(objSubTypeMessageQuestResult) + `, "quest_res", "Quest result", ` + strconv.Itoa(objTypeMessage) + `)
|
2019-05-18 13:15:50 +02:00
|
|
|
,(` + strconv.Itoa(objSubTypeMessageDuelFight) + `, "duel_fight", "Duel fight result", ` + strconv.Itoa(objTypeMessage) + `)
|
2019-05-19 06:13:33 +02:00
|
|
|
,(` + strconv.Itoa(objSubTypeMessageHeroReq) + `, "hero_req", "Hero summary request", ` + strconv.Itoa(objTypeMessage) + `)
|
|
|
|
,(` + strconv.Itoa(objSubTypeMessageHeroAck) + `, "hero_ack", "Hero summary ack", ` + strconv.Itoa(objTypeMessage) + `)
|
|
|
|
,(` + strconv.Itoa(objSubTypeMessageMeReq) + `, "me_req", "Hero short summary request", ` + strconv.Itoa(objTypeMessage) + `)
|
|
|
|
,(` + strconv.Itoa(objSubTypeMessageMeAck) + `, "me_ack", "Hero short summary ack", ` + strconv.Itoa(objTypeMessage) + `)
|
|
|
|
,(` + strconv.Itoa(objSubTypeMessageInventoryReq) + `, "inv_req", "Inventory request", ` + strconv.Itoa(objTypeMessage) + `)
|
|
|
|
,(` + strconv.Itoa(objSubTypeMessageInventoryAck) + `, "inv_ack", "Inventory ack", ` + strconv.Itoa(objTypeMessage) + `)
|
2019-05-07 13:15:25 +02:00
|
|
|
,(` + strconv.Itoa(objSubTypeMessagePillageInc) + `, "pillage_inc", "Pillage incoming", ` + strconv.Itoa(objTypeMessage) + `)
|
2019-05-18 12:33:53 +02:00
|
|
|
,(` + strconv.Itoa(objSubTypeMessagePillageGo) + `, "pillage_go", "Pillage go", ` + strconv.Itoa(objTypeMessage) + `)
|
2019-05-18 13:11:53 +02:00
|
|
|
,(` + strconv.Itoa(objSubTypeMessagePillageTimeout) + `, "pillage_timeout", "Pillage timeout", ` + strconv.Itoa(objTypeMessage) + `)
|
2019-05-18 12:33:53 +02:00
|
|
|
,(` + strconv.Itoa(objSubTypeMessagePillageWin) + `, "pillage_win", "Pillage win", ` + strconv.Itoa(objTypeMessage) + `)
|
|
|
|
,(` + strconv.Itoa(objSubTypeMessagePillageLoss) + `, "pillage_loss", "Pillage loss", ` + strconv.Itoa(objTypeMessage) + `)
|
2019-05-11 08:24:38 +02:00
|
|
|
,(` + strconv.Itoa(objSubTypeMessageTributeInc) + `, "tribute_inc", "Tribute incoming", ` + strconv.Itoa(objTypeMessage) + `)
|
|
|
|
,(` + strconv.Itoa(objSubTypeMessageTributeAck) + `, "tribute_ack", "Tribute acknowledged", ` + strconv.Itoa(objTypeMessage) + `)
|
2019-05-09 04:43:20 +02:00
|
|
|
,(` + strconv.Itoa(objSubTypeMessageAuctionAnnounce) + `, "auction_announce", "Auction announce", ` + strconv.Itoa(objTypeMessage) + `)
|
2019-05-11 08:24:38 +02:00
|
|
|
,(` + strconv.Itoa(objSubTypeMessageAuctionUpdReq) + `, "auction_upd_req", "Auction update request", ` + strconv.Itoa(objTypeMessage) + `)
|
|
|
|
,(` + strconv.Itoa(objSubTypeMessageAuctionUpdAck) + `, "auction_upd_ack", "Auction update acknowledgment", ` + strconv.Itoa(objTypeMessage) + `)
|
|
|
|
,(` + strconv.Itoa(objSubTypeMessageTimeAck) + `, "time_ack", "Time Acknowledgment", ` + strconv.Itoa(objTypeMessage) + `)
|
|
|
|
,(` + strconv.Itoa(objSubTypeMessageTimeReq) + `, "time_req", "Time Request", ` + strconv.Itoa(objTypeMessage) + `)
|
2019-05-18 10:49:47 +02:00
|
|
|
,(` + strconv.Itoa(objSubTypeMessageGo) + `, "go", "Go", ` + strconv.Itoa(objTypeMessage) + `)
|
2019-05-19 06:13:33 +02:00
|
|
|
,(` + strconv.Itoa(objSubTypeMessagePledge) + `, "pledge", "Pledge", ` + strconv.Itoa(objTypeMessage) + `)
|
2019-05-18 13:21:23 +02:00
|
|
|
,(` + strconv.Itoa(objSubTypeMessageGoQuest) + `, "go_quest", "Go quest", ` + strconv.Itoa(objTypeMessage) + `)
|
2019-05-19 06:13:33 +02:00
|
|
|
,(` + strconv.Itoa(objSubTypeMessageGoFastFight) + `, "fast_fight", "Arena fast fight", ` + strconv.Itoa(objTypeMessage) + `)
|
2019-05-18 13:21:23 +02:00
|
|
|
,(` + strconv.Itoa(objSubTypeMessageGoArena) + `, "go_arena", "Go arena", ` + strconv.Itoa(objTypeMessage) + `)
|
|
|
|
,(` + strconv.Itoa(objSubTypeMessageTop) + `, "top", "Top", ` + strconv.Itoa(objTypeMessage) + `)
|
2019-05-19 06:13:33 +02:00
|
|
|
,(` + strconv.Itoa(objSubTypeMessageMenu) + `, "menu", "Menu", ` + strconv.Itoa(objTypeMessage) + `)
|
2019-05-19 08:35:26 +02:00
|
|
|
,(` + strconv.Itoa(objSubTypeMessageBuyReq) + `, "buy_req", "Sell Req", ` + strconv.Itoa(objTypeMessage) + `)
|
|
|
|
,(` + strconv.Itoa(objSubTypeMessageSellReq) + `, "sell_req", "Buy Req", ` + strconv.Itoa(objTypeMessage) + `)
|
2019-05-20 14:29:11 +02:00
|
|
|
,(` + strconv.Itoa(objSubTypeMessageOrderbookReq) + `, "orderbook_req", "Orderbook Req", ` + strconv.Itoa(objTypeMessage) + `)
|
|
|
|
,(` + strconv.Itoa(objSubTypeMessageOrderbookAck) + `, "orderbook_acl", "Orderbook Ack", ` + strconv.Itoa(objTypeMessage) + `)
|
|
|
|
,(` + strconv.Itoa(objSubTypeMessageWithdrawReq) + `, "withdraw_req", "Withdraw Req", ` + strconv.Itoa(objTypeMessage) + `)
|
|
|
|
,(` + strconv.Itoa(objSubTypeMessageWithdrawCode) + `, "withdraw_code", "Withdraw Code", ` + strconv.Itoa(objTypeMessage) + `)
|
|
|
|
,(` + strconv.Itoa(objSubTypeMessageWithdrawRcv) + `, "withdraw_rcv", "Withdraw Received", ` + strconv.Itoa(objTypeMessage) + `)
|
|
|
|
,(` + strconv.Itoa(objSubTypeMessageDepositReq) + `, "deposit_req", "Deposit Req", ` + strconv.Itoa(objTypeMessage) + `)
|
|
|
|
,(` + strconv.Itoa(objSubTypeMessageDepositAck) + `, "deposit_ack", "Deposit Ack", ` + strconv.Itoa(objTypeMessage) + `)
|
2019-05-20 16:16:49 +02:00
|
|
|
,(` + strconv.Itoa(objSubTypeMessageStockReq) + `, "stock_req", "Stock Req", ` + strconv.Itoa(objTypeMessage) + `)
|
|
|
|
,(` + strconv.Itoa(objSubTypeMessageStockAck) + `, "stock_ack", "Stock Ack", ` + strconv.Itoa(objTypeMessage) + `)
|
|
|
|
,(` + strconv.Itoa(objSubTypeMessageMiscReq) + `, "misc_req", "Misc Req", ` + strconv.Itoa(objTypeMessage) + `)
|
2019-08-23 08:10:08 +02:00
|
|
|
,(` + strconv.Itoa(objSubTypeMessageMiscAck) + `, "misc_ack", "Misc Ack", ` + strconv.Itoa(objTypeMessage) + `)
|
2019-05-25 09:25:11 +02:00
|
|
|
,(` + strconv.Itoa(objSubTypeMessageTUReportReq) + `, "tureport_req", "Trade Union War Report Req", ` + strconv.Itoa(objTypeMessage) + `)
|
|
|
|
,(` + strconv.Itoa(objSubTypeMessageTUReportAck) + `, "tureport_ack", "Trade Union War Report Ack", ` + strconv.Itoa(objTypeMessage) + `)
|
2019-05-25 09:39:34 +02:00
|
|
|
,(` + strconv.Itoa(objSubTypeMessageUnionWar) + `, "union_war", "Union war report", ` + strconv.Itoa(objTypeMessage) + `)
|
2019-05-27 06:03:04 +02:00
|
|
|
,(` + strconv.Itoa(objSubTypeMessageTimeout) + `, "timeout", "Generic timeout", ` + strconv.Itoa(objTypeMessage) + `)
|
2019-05-28 09:00:37 +02:00
|
|
|
,(` + strconv.Itoa(objSubTypeMessageGoQuestAck) + `, "go_quest_ack", "Go Quest Ack", ` + strconv.Itoa(objTypeMessage) + `)
|
2019-05-30 10:36:40 +02:00
|
|
|
,(` + strconv.Itoa(objSubTypeMessageGRolesReq) + `, "groles_req", "Guild roles Req", ` + strconv.Itoa(objTypeMessage) + `)
|
|
|
|
,(` + strconv.Itoa(objSubTypeMessageGRolesAck) + `, "groles_ack", "Guild roles Ack", ` + strconv.Itoa(objTypeMessage) + `)
|
2019-05-31 18:36:30 +02:00
|
|
|
,(` + strconv.Itoa(objSubTypeMessageGStockResReq) + `, "gstock_res_req", "GStock Res Req", ` + strconv.Itoa(objTypeMessage) + `)
|
|
|
|
,(` + strconv.Itoa(objSubTypeMessageGStockAlchReq) + `, "gstock_alch_req", "GStock Alch Req", ` + strconv.Itoa(objTypeMessage) + `)
|
|
|
|
,(` + strconv.Itoa(objSubTypeMessageGStockMiscReq) + `, "gstock_misc_req", "GStock Misc Req", ` + strconv.Itoa(objTypeMessage) + `)
|
|
|
|
,(` + strconv.Itoa(objSubTypeMessageGStockRecReq) + `, "gstock_rec_req", "GStock Rec Req", ` + strconv.Itoa(objTypeMessage) + `)
|
|
|
|
,(` + strconv.Itoa(objSubTypeMessageGStockPartReq) + `, "gstock_part_req", "GStock Part Req", ` + strconv.Itoa(objTypeMessage) + `)
|
|
|
|
,(` + strconv.Itoa(objSubTypeMessageGStockOthReq) + `, "gstock_oth_req", "Gstock Oth Req", ` + strconv.Itoa(objTypeMessage) + `)
|
|
|
|
,(` + strconv.Itoa(objSubTypeMessageGStockAnyAck) + `, "gstock_any_ack", "Gstock Any Ack", ` + strconv.Itoa(objTypeMessage) + `)
|
|
|
|
,(` + strconv.Itoa(objSubTypeMessageGStockReq) + `, "gstock_req", "GStock Req", ` + strconv.Itoa(objTypeMessage) + `)
|
|
|
|
,(` + strconv.Itoa(objSubTypeMessageGStockAck) + `, "gstock_ack", "GStock Ack", ` + strconv.Itoa(objTypeMessage) + `)
|
2019-08-24 08:00:55 +02:00
|
|
|
,(` + strconv.Itoa(objSubTypeMessageBusy) + `, "busy", "Busy", ` + strconv.Itoa(objTypeMessage) + `)
|
2019-08-24 08:18:13 +02:00
|
|
|
,(` + strconv.Itoa(objSubTypeMessageStockEmpty) + `, "stock_empty", "Stock Empty", ` + strconv.Itoa(objTypeMessage) + `)
|
|
|
|
,(` + strconv.Itoa(objSubTypeMessageStockAnyAck) + `, "stock_any_ack", "Stock Any Ack", ` + strconv.Itoa(objTypeMessage) + `)
|
2019-05-10 16:19:21 +02:00
|
|
|
,(` + strconv.Itoa(objSubTypeJobPillage) + `, "job_pillage", "Pillage job", ` + strconv.Itoa(objTypeJob) + `)
|
2019-05-11 05:15:42 +02:00
|
|
|
,(` + strconv.Itoa(objSubTypeJobTribute) + `, "job_tribute", "Tribute job", ` + strconv.Itoa(objTypeJob) + `)
|
|
|
|
,(` + strconv.Itoa(objSubTypeJobWithdrawal) + `, "job_withdraw", "Withdrawal job", ` + strconv.Itoa(objTypeJob) + `)
|
|
|
|
,(` + strconv.Itoa(objSubTypeJobGStock) + `, "job_gstock", "GStock job", ` + strconv.Itoa(objTypeJob) + `)
|
|
|
|
,(` + strconv.Itoa(objSubTypeJobRescanMsg) + `, "job_rescan_msg", "Rescan message job", ` + strconv.Itoa(objTypeJob) + `)
|
2019-05-11 06:54:12 +02:00
|
|
|
,(` + strconv.Itoa(objSubTypeJobSetJobDone) + `, "job_set_done", "Set job as done job", ` + strconv.Itoa(objTypeJob) + `)
|
2019-05-26 15:09:43 +02:00
|
|
|
,(` + strconv.Itoa(objSubTypeJobMsgClient) + `, "job_msg_client", "Send message via client", ` + strconv.Itoa(objTypeJob) + `)
|
2019-06-08 17:28:07 +02:00
|
|
|
,(` + strconv.Itoa(objSubTypeJobMsgRefresh) + `, "job_msg_refresh", "Refresh message from client", ` + strconv.Itoa(objTypeJob) + `)
|
2019-06-11 03:59:20 +02:00
|
|
|
,(` + strconv.Itoa(objSubTypeJobBackupExport) + `, "job_backup_export", "Export Backup", ` + strconv.Itoa(objTypeJob) + `)
|
|
|
|
,(` + strconv.Itoa(objSubTypeJobBackupImport) + `, "job_backup_import", "Import Backup", ` + strconv.Itoa(objTypeJob) + `)
|
2019-08-16 12:29:07 +02:00
|
|
|
,(` + strconv.Itoa(objSubTypeJobGDeposit) + `, "job_gdeposit", "GDeposit job", ` + strconv.Itoa(objTypeJob) + `)
|
2019-08-17 08:18:25 +02:00
|
|
|
,(` + strconv.Itoa(objSubTypeJobSaveRes) + `, "job_save_res", "Save resources job", ` + strconv.Itoa(objTypeJob) + `)
|
2019-05-09 09:17:59 +02:00
|
|
|
,(` + strconv.Itoa(objSubTypeItemResource) + `, "item_res", "Time", ` + strconv.Itoa(objTypeItem) + `)
|
|
|
|
,(` + strconv.Itoa(objSubTypeItemAlch) + `, "item_alch", "Time", ` + strconv.Itoa(objTypeItem) + `)
|
|
|
|
,(` + strconv.Itoa(objSubTypeItemMisc) + `, "item_misc", "Time", ` + strconv.Itoa(objTypeItem) + `)
|
|
|
|
,(` + strconv.Itoa(objSubTypeItemRecipe) + `, "item_recipe", "Time", ` + strconv.Itoa(objTypeItem) + `)
|
|
|
|
,(` + strconv.Itoa(objSubTypeItemPart) + `, "item_part", "Time", ` + strconv.Itoa(objTypeItem) + `)
|
|
|
|
,(` + strconv.Itoa(objSubTypeItemOther) + `, "item_other", "Time", ` + strconv.Itoa(objTypeItem) + `)
|
2019-05-31 04:02:21 +02:00
|
|
|
,(` + strconv.Itoa(objSubTypeCastle) + `, "castle", "Castle", ` + strconv.Itoa(objTypeCastle) + `)
|
|
|
|
,(` + strconv.Itoa(objSubTypeUnion) + `, "union", "Union", ` + strconv.Itoa(objTypeUnion) + `)
|
|
|
|
,(` + strconv.Itoa(objSubTypeFair) + `, "fair", "Fair", ` + strconv.Itoa(objTypeFair) + `)
|
2019-05-31 04:07:24 +02:00
|
|
|
,(` + strconv.Itoa(objSubTypeTribute) + `, "tribute", "Tribute", ` + strconv.Itoa(objTypeTribute) + `)
|
|
|
|
,(` + strconv.Itoa(objSubTypeExperience) + `, "xp", "Experience", ` + strconv.Itoa(objTypeExperience) + `)
|
2019-07-09 06:56:41 +02:00
|
|
|
,(` + strconv.Itoa(objSubTypeQuestForest) + `, "forest", "Forest", ` + strconv.Itoa(objTypeQuest) + `)
|
|
|
|
,(` + strconv.Itoa(objSubTypeQuestSwamp) + `, "swamp", "Swamp", ` + strconv.Itoa(objTypeQuest) + `)
|
|
|
|
,(` + strconv.Itoa(objSubTypeQuestValley) + `, "valley", "Valley", ` + strconv.Itoa(objTypeQuest) + `)
|
2019-05-09 09:17:59 +02:00
|
|
|
;`)
|
2019-05-06 05:03:12 +02:00
|
|
|
failOnError(err, "initDB : populate table code_obj_sub_type")
|
2019-05-11 09:49:42 +02:00
|
|
|
log.Println("initDB : code_obj_sub_type populated ...")
|
2019-05-04 11:15:33 +02:00
|
|
|
|
2019-05-11 09:49:42 +02:00
|
|
|
log.Println("initDB : Database set up")
|
2019-05-04 11:15:33 +02:00
|
|
|
}
|
|
|
|
|
2019-05-08 17:18:17 +02:00
|
|
|
func insertMsgReport(objId int64, war_date int32, atk int32, def int32, exp int32, gold int32, stock int32, crit bool, stamina bool) error {
|
|
|
|
objSubTypeId, err := getObjSubTypeId(objId)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if objSubTypeId != objSubTypeMessageUnknown {
|
|
|
|
return errors.New("Message is not of type Unknown")
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
obj_id BIGINT UNSIGNED NOT NULL
|
|
|
|
,war_date TIMESTAMP NOT NULL
|
|
|
|
,attack SMALLINT UNSIGNED NOT NULL
|
|
|
|
,defense SMALLINT UNSIGNED NOT NULL
|
|
|
|
,gold SMALLINT UNSIGNED NOT NULL
|
|
|
|
,stock MALLINT UNSIGNED NOT NULL
|
|
|
|
,exp SMALLINT UNSIGNED NOT NULL
|
|
|
|
,stamina TINYINT NOT NULL
|
|
|
|
,crit TINYINT NOT NULL
|
|
|
|
|
|
|
|
stmt, err := db.Prepare(`INSERT INTO obj_msg_report (obj_id, war_date, attack, defense, gold, stock, exp, stamina, crit)
|
|
|
|
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?FROM_UNIXTIME(?), ?);`)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer stmt.Close()
|
|
|
|
|
|
|
|
_, err = stmt.Exec(objId, m.ID64, m.ChatID64, m.UserID64, m.SenderUserID64, m.Date, m.Text)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2019-05-19 14:00:18 +02:00
|
|
|
func insertMsgDuelFight(m *ChatWarsMessageDuelFight) error {
|
|
|
|
objSubTypeId, err := getObjSubTypeId(m.ObjID64)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if objSubTypeId != objSubTypeMessageUnknown && objSubTypeId != objSubTypeMessageDuelFight {
|
|
|
|
return errors.New("Message type mismatch")
|
|
|
|
}
|
|
|
|
|
2019-05-25 10:56:13 +02:00
|
|
|
stmt, err := db.Prepare(`INSERT INTO obj_msg_duel_fight (obj_id, win_castle_id, win_guild_id, win_user_id, win_life, loss_castle_id, loss_guild_id, loss_user_id, loss_life, weapon)
|
|
|
|
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?);`)
|
2019-05-19 14:00:18 +02:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer stmt.Close()
|
|
|
|
|
2019-05-25 10:56:13 +02:00
|
|
|
_, err = stmt.Exec(m.ObjID64, getObjCastleID(m.WinCastle), getObjGuildID(m.WinGuild), getObjUserID(m.WinUser), m.WinLife, getObjCastleID(m.LossCastle), getObjGuildID(m.LossGuild), getObjUserID(m.LossUser), m.LossLife, m.Weapon)
|
2019-05-19 14:00:18 +02:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2019-05-09 11:19:02 +02:00
|
|
|
func insertMsgAuctionAnnounce(m *ChatWarsMessageAuctionAnnounce) error {
|
2019-05-11 07:42:46 +02:00
|
|
|
objSubTypeId, err := getObjSubTypeId(m.ObjID64)
|
2019-05-06 16:05:43 +02:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2019-05-09 11:19:02 +02:00
|
|
|
if objSubTypeId != objSubTypeMessageUnknown && objSubTypeId != objSubTypeMessageAuctionAnnounce {
|
|
|
|
return errors.New("Message type mismatch")
|
2019-05-06 16:05:43 +02:00
|
|
|
}
|
2019-05-06 15:49:55 +02:00
|
|
|
|
2019-06-06 08:06:29 +02:00
|
|
|
stmt, err := db.Prepare(`INSERT INTO obj_msg_auction_announce (obj_id, lot_id, item_id, cond, quality, seller_id, seller_guild_id, seller_castle_id, buyer_id, buyer_guild_id, buyer_castle_id, price, status, end)
|
|
|
|
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);`)
|
2019-05-09 11:19:02 +02:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer stmt.Close()
|
2019-05-06 15:49:55 +02:00
|
|
|
|
2019-06-06 07:56:28 +02:00
|
|
|
_, err = stmt.Exec(m.ObjID64, m.LotID, m.ItemID64, m.Cond, m.Quality, m.SellerUserID64, m.SellerGuildID64, m.SellerCastleID64, m.BuyerUserID64, m.BuyerGuildID64, m.BuyerCastleID64, m.Price, m.Status, m.End)
|
2019-05-09 11:19:02 +02:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2019-05-15 10:58:25 +02:00
|
|
|
|
2019-05-06 12:43:42 +02:00
|
|
|
return nil
|
|
|
|
}
|
2019-05-08 12:13:47 +02:00
|
|
|
|
2019-05-14 04:28:26 +02:00
|
|
|
func insertMsgMiniWar(m *ChatWarsMessageMiniWar) error {
|
|
|
|
objSubTypeId, err := getObjSubTypeId(m.ObjID64)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if objSubTypeId != objSubTypeMessageUnknown && objSubTypeId != objSubTypeMessageMiniWar {
|
|
|
|
return errors.New("Message type mismatch")
|
|
|
|
}
|
|
|
|
|
|
|
|
stmt1, err := db.Prepare(`INSERT INTO obj_msg_mini_war (obj_id, date)
|
|
|
|
VALUES (?, ?);`)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer stmt1.Close()
|
|
|
|
|
2019-05-14 04:29:47 +02:00
|
|
|
_, err = stmt1.Exec(m.ObjID64, m.Time)
|
2019-05-14 04:28:26 +02:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2019-05-14 04:33:29 +02:00
|
|
|
stmt2, err := db.Prepare(`INSERT INTO obj_msg_mini_war_castle (obj_id, castle_id, gardian, result, gold, stock, points)
|
2019-05-14 04:28:26 +02:00
|
|
|
VALUES (?, ?, ?, ?, ?, ?, ?);`)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer stmt2.Close()
|
|
|
|
|
|
|
|
for c, r := range m.Report {
|
2019-05-25 09:39:34 +02:00
|
|
|
_, err = stmt2.Exec(m.ObjID64, getObjCastleID(c), r.Gardian, r.Result, r.Gold, r.Stock, r.Points)
|
2019-05-14 04:28:26 +02:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2019-05-15 12:02:17 +02:00
|
|
|
func insertMsgPillageInc(m *ChatWarsMessagePillageInc) error {
|
|
|
|
objSubTypeId, err := getObjSubTypeId(m.ObjID64)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if objSubTypeId != objSubTypeMessageUnknown && objSubTypeId != objSubTypeMessagePillageInc {
|
|
|
|
return errors.New("Message type mismatch")
|
|
|
|
}
|
|
|
|
|
|
|
|
stmt, err := db.Prepare(`INSERT INTO obj_msg_pillage_inc (obj_id, attacker, guild, castle_id)
|
|
|
|
VALUES (?, ?, ?, ?);`)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer stmt.Close()
|
|
|
|
|
2019-05-25 09:39:34 +02:00
|
|
|
_, err = stmt.Exec(m.ObjID64, m.Attacker, m.Guild, getObjCastleID(m.Castle))
|
2019-05-19 14:00:18 +02:00
|
|
|
|
2019-05-15 12:02:17 +02:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2019-05-08 13:12:30 +02:00
|
|
|
func loadMsgParsingRules() (m map[int]MessageParsingRule, err error) {
|
2019-05-08 12:13:47 +02:00
|
|
|
var (
|
|
|
|
id int32
|
|
|
|
priority int32
|
|
|
|
descn string
|
|
|
|
rule string
|
2019-06-02 08:57:42 +02:00
|
|
|
msgTypeID int64
|
2019-05-08 12:13:47 +02:00
|
|
|
)
|
|
|
|
|
2019-05-08 12:47:32 +02:00
|
|
|
log.Println("Loading message parsing rules...")
|
2019-05-08 13:12:30 +02:00
|
|
|
m = make(map[int]MessageParsingRule)
|
2019-05-08 12:13:47 +02:00
|
|
|
count := int(0)
|
|
|
|
|
2019-05-08 13:00:43 +02:00
|
|
|
defer func() {
|
|
|
|
if rec := recover(); rec != nil {
|
2019-05-08 13:16:38 +02:00
|
|
|
log.Println("Error parsing rules : ", rec)
|
2019-05-08 13:14:03 +02:00
|
|
|
err = errors.New("panic")
|
2019-05-08 13:00:43 +02:00
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
2019-05-08 12:37:53 +02:00
|
|
|
rules, err := db.Query(`SELECT r.id, r.prio, r.descn, r.rule, r.msg_type_id FROM msg_rules r ORDER BY r.prio DESC;`)
|
2019-05-08 12:13:47 +02:00
|
|
|
if err != nil {
|
|
|
|
return m, err
|
|
|
|
}
|
|
|
|
defer rules.Close()
|
|
|
|
|
|
|
|
for rules.Next() {
|
2019-05-08 12:17:07 +02:00
|
|
|
err = rules.Scan(&id, &priority, &descn, &rule, &msgTypeID)
|
2019-05-08 12:13:47 +02:00
|
|
|
if err != nil {
|
|
|
|
return m, err
|
|
|
|
}
|
2019-05-08 12:17:07 +02:00
|
|
|
i := new(MessageParsingRule)
|
|
|
|
i.ID = id
|
|
|
|
i.Priority = priority
|
|
|
|
i.Description = descn
|
|
|
|
i.Rule = rule
|
|
|
|
i.MsgTypeID = msgTypeID
|
2019-05-08 13:13:19 +02:00
|
|
|
i.re = regexp.MustCompile(rule)
|
2019-05-08 12:17:07 +02:00
|
|
|
m[count] = *i
|
2019-05-25 13:24:58 +02:00
|
|
|
// log.Printf("New rule : %s\n", rule)
|
2019-05-08 12:13:47 +02:00
|
|
|
count++
|
|
|
|
}
|
|
|
|
|
|
|
|
return m, nil
|
|
|
|
}
|
2019-05-10 11:23:47 +02:00
|
|
|
|
2019-05-11 06:54:12 +02:00
|
|
|
func getSQLListID64(q string) []int64 {
|
2019-05-11 06:56:48 +02:00
|
|
|
var (
|
|
|
|
id int64
|
|
|
|
ids []int64
|
|
|
|
)
|
2019-05-11 06:54:12 +02:00
|
|
|
|
|
|
|
rows, err := db.Query(q)
|
|
|
|
s := fmt.Sprintf("getSQLListID64 : Query(%s)", q)
|
|
|
|
logOnError(err, s)
|
|
|
|
|
|
|
|
for rows.Next() {
|
|
|
|
err = rows.Scan(&id)
|
|
|
|
logOnError(err, "getSQLListID64 : scan next val")
|
|
|
|
ids = append(ids, id)
|
|
|
|
}
|
|
|
|
err = rows.Err()
|
2019-05-11 06:56:58 +02:00
|
|
|
logOnError(err, "getSQLListID64 : query end")
|
2019-05-11 06:54:12 +02:00
|
|
|
rows.Close()
|
2019-05-16 05:09:51 +02:00
|
|
|
|
2019-05-11 06:54:12 +02:00
|
|
|
return ids
|
|
|
|
}
|