chirpnest/sql.go
2020-01-12 17:37:46 +08:00

805 lines
47 KiB
Go

package main
import (
"errors"
"fmt"
"log"
"regexp"
"strconv"
)
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")
failOnError(err, "initDB : set foreign_key_checks = 0")
var name string
rows, err := db.Query("show tables")
failOnError(err, "initDB : show tables")
for rows.Next() {
err = rows.Scan(&name)
failOnError(err, "initDB : show tables listing")
if ok, _ := regexp.MatchString(`^.*_v$`, name); ok {
_, 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)
}
}
err = rows.Err()
failOnError(err, "initDB : show tables listing end")
rows.Close()
_, err = tx.Exec("set foreign_key_checks = 1")
failOnError(err, "initDB : set foreign_key_checks = 1")
err = tx.Commit()
failOnError(err, "initDB : commit cleanup")
log.Println("initDB : Database cleaned up")
_, err = db.Exec(`CREATE TABLE code_obj_type (
id SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT
,intl_id VARCHAR(32) NOT NULL
,name VARCHAR(80) NOT NULL
,PRIMARY KEY (id)
,UNIQUE KEY (intl_id)
) ENGINE = InnoDB CHARSET=utf8mb4 COLLATE utf8mb4_bin;`)
failOnError(err, "initDB : create table code_obj_type")
log.Println("initDB : code_obj_type created ...")
_, err = db.Exec(`CREATE TABLE code_obj_sub_type (
id SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT
,intl_id VARCHAR(32) NOT NULL
,name VARCHAR(80) NOT NULL
,obj_type_id SMALLINT UNSIGNED NOT NULL
,PRIMARY KEY (id)
,UNIQUE KEY (intl_id)
,FOREIGN KEY (obj_type_id) REFERENCES code_obj_type(id) ON DELETE CASCADE
) ENGINE = InnoDB CHARSET=utf8mb4 COLLATE utf8mb4_bin;`)
failOnError(err, "initDB : create table code_obj_sub_type")
log.Println("initDB : code_obj_sub_type created ...")
_, err = db.Exec(`CREATE TABLE obj (
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT
,obj_type_id SMALLINT UNSIGNED NOT NULL
,obj_sub_type_id SMALLINT UNSIGNED NOT NULL
,timestamp TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
,PRIMARY KEY (id)
,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
) ENGINE = InnoDB AUTO_INCREMENT = 0 CHARSET=utf8mb4 COLLATE utf8mb4_bin;`)
failOnError(err, "initDB : create table obj")
log.Println("initDB : obj created ...")
_, err = db.Exec(`CREATE TABLE obj_item (
obj_id BIGINT UNSIGNED NOT NULL
,intl_id VARCHAR(32)
,weight SMALLINT NOT NULL
,exchange TINYINT NOT NULL
,auction TINYINT NOT NULL
,FOREIGN KEY (obj_id) REFERENCES obj(id) ON DELETE CASCADE
,UNIQUE KEY (intl_id)
) ENGINE = InnoDB CHARSET=utf8mb4 COLLATE utf8mb4_bin;`)
failOnError(err, "initDB : create table obj_item")
log.Println("initDB : obj_item created ...")
_, err = db.Exec(`CREATE TABLE obj_castle (
obj_id BIGINT UNSIGNED NOT NULL
,logo VARCHAR(32) NOT NULL
,name VARCHAR(80) NOT NULL
,FOREIGN KEY (obj_id) REFERENCES obj(id) ON DELETE CASCADE
) ENGINE = InnoDB CHARSET=utf8mb4 COLLATE utf8mb4_bin;`)
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
) ENGINE = InnoDB CHARSET=utf8mb4 COLLATE utf8mb4_bin;`)
failOnError(err, "initDB : create table obj_guild")
log.Println("initDB : obj_guild created ...")
_, 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
) ENGINE = InnoDB CHARSET=utf8mb4 COLLATE utf8mb4_bin;`)
failOnError(err, "initDB : create table obj_user")
log.Println("initDB : obj_user created ...")
_, 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 ...")
_, err = db.Exec(`CREATE TABLE obj_war (
obj_id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT
,start_time DATETIME NOT NULL
,end_time DATETIME NOT NULL
,FOREIGN KEY (obj_id) REFERENCES obj(id) ON DELETE CASCADE
) ENGINE = InnoDB CHARSET=utf8mb4 COLLATE utf8mb4_bin;`)
failOnError(err, "initDB : create table obj_war")
log.Println("initDB : obj_war created ...")
_, err = db.Exec(`CREATE TABLE obj_msg (
obj_id BIGINT UNSIGNED NOT NULL
,msg_id BIGINT NOT NULL
,chat_id BIGINT NOT NULL
,user_id BIGINT NOT NULL CHECK (user_id > 0)
,sender_user_id BIGINT NOT NULL CHECK (sender_user_id > 0)
,date DATETIME NOT NULL
,text VARCHAR(4096) NOT NULL
,FOREIGN KEY (obj_id) REFERENCES obj(id) ON DELETE CASCADE
,UNIQUE KEY (msg_id, chat_id, user_id, sender_user_id)
) ENGINE = InnoDB CHARSET=utf8mb4 COLLATE utf8mb4_bin;`)
failOnError(err, "initDB : create table obj_msg")
log.Println("initDB : obj_msg created ...")
_, err = db.Exec(`CREATE VIEW obj_msg_v AS
SELECT om.obj_id
,o.obj_sub_type_id AS msg_type_id
,cost.intl_id COLLATE utf8mb4_unicode_ci AS msg_type
,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
,obj o
,code_obj_sub_type cost
WHERE om.obj_id = o.id
AND cost.id = o.obj_sub_type_id;`)
failOnError(err, "initDB : create view obj_msg_v")
log.Println("initDB : obj_msg_v created ...")
_, err = db.Exec(`CREATE TABLE obj_msg_pillage_inc (
obj_id BIGINT UNSIGNED NOT NULL
,attacker VARCHAR(32)
,guild VARCHAR(32)
,castle_id BIGINT UNSIGNED NOT NULL
,FOREIGN KEY (obj_id) REFERENCES obj(id) ON DELETE CASCADE
,FOREIGN KEY (castle_id) REFERENCES obj_castle(obj_id) ON DELETE CASCADE
) ENGINE = InnoDB CHARSET=utf8mb4 COLLATE utf8mb4_bin;`)
failOnError(err, "initDB : create table obj_msg_report")
log.Println("initDB : obj_msg_report created ...")
_, err = db.Exec(`CREATE TABLE obj_msg_report (
obj_id BIGINT UNSIGNED NOT NULL
,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
) ENGINE = InnoDB CHARSET=utf8mb4 COLLATE utf8mb4_bin;`)
failOnError(err, "initDB : create table obj_msg_report")
log.Println("initDB : obj_msg_report created ...")
_, 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
,attack SMALLINT UNSIGNED NOT NULL
,defense SMALLINT UNSIGNED NOT NULL
,gold SMALLINT UNSIGNED NOT NULL
,stock SMALLINT UNSIGNED NOT NULL
,exp SMALLINT UNSIGNED NOT NULL
,stamina TINYINT NOT NULL
,crit TINYINT NOT NULL
,FOREIGN KEY (obj_id) REFERENCES obj(id) ON DELETE CASCADE
,FOREIGN KEY (war_id) REFERENCES obj(id) ON DELETE CASCADE
,UNIQUE KEY (user_id, war_id)
) ENGINE = InnoDB CHARSET=utf8mb4 COLLATE utf8mb4_bin;`)
failOnError(err, "initDB : create table obj_war_report")
log.Println("initDB : obj_war_report created ...")
_, err = db.Exec(`CREATE TABLE obj_msg_auction_announce (
obj_id BIGINT UNSIGNED NOT NULL
,lot_id BIGINT UNSIGNED NOT NULL
,item_id BIGINT UNSIGNED
,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
,FOREIGN KEY (obj_id) REFERENCES obj(id) ON DELETE CASCADE
,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
,KEY (lot_id)
) ENGINE = InnoDB CHARSET=utf8mb4 COLLATE utf8mb4_bin;`)
failOnError(err, "initDB : create table obj_msg_auction_announce")
log.Println("initDB : obj_msg_auction_announce created ...")
_, err = db.Exec(`CREATE TABLE obj_msg_duel_fight (
obj_id BIGINT UNSIGNED NOT NULL
,win_castle_id BIGINT UNSIGNED NOT NULL
,win_guild_id BIGINT UNSIGNED
,win_user_id BIGINT UNSIGNED NOT NULL
,win_life SMALLINT NOT NULL
,loss_castle_id BIGINT UNSIGNED NOT NULL
,loss_guild_id BIGINT UNSIGNED
,loss_user_id BIGINT UNSIGNED NOT NULL
,loss_life SMALLINT NOT NULL
,exp INT UNSIGNED NOT NULL
,weapon VARCHAR(80)
,FOREIGN KEY (obj_id) REFERENCES obj(id) ON DELETE CASCADE
,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
,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
,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
) ENGINE = InnoDB CHARSET=utf8mb4 COLLATE utf8mb4_bin;`)
failOnError(err, "initDB : create table obj_msg_duel_fight")
log.Println("initDB : obj_msg_duel_fight created ...")
_, 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
,KEY (lot_id)
) ENGINE = InnoDB CHARSET=utf8mb4 COLLATE utf8mb4_bin;`)
failOnError(err, "initDB : create table obj_msg_auction_upd_req")
log.Println("initDB : obj_msg_auction_upd_req created ...")
_, 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
) ENGINE = InnoDB CHARSET=utf8mb4 COLLATE utf8mb4_bin;`)
failOnError(err, "initDB : create table obj_msg_auction_upd_ack")
log.Println("initDB : obj_msg_auction_upd_ack created ...")
_, err = db.Exec(`CREATE TABLE obj_msg_exp (
obj_id BIGINT UNSIGNED NOT NULL
,exp INT NOT NULL
,FOREIGN KEY (obj_id) REFERENCES obj(id) ON DELETE CASCADE
) ENGINE = InnoDB CHARSET=utf8mb4 COLLATE utf8mb4_bin;`)
failOnError(err, "initDB : create table obj_msg_exp")
log.Println("initDB : obj_msg_exp created ...")
_, err = db.Exec(`CREATE TABLE obj_msg_gold (
obj_id BIGINT UNSIGNED NOT NULL
,gold INT NOT NULL
,FOREIGN KEY (obj_id) REFERENCES obj(id) ON DELETE CASCADE
) ENGINE = InnoDB CHARSET=utf8mb4 COLLATE utf8mb4_bin;`)
failOnError(err, "initDB : create table obj_msg_gold")
log.Println("initDB : obj_msg_gold created ...")
_, err = db.Exec(`CREATE TABLE obj_msg_item (
obj_id BIGINT UNSIGNED NOT NULL
,item_id BIGINT UNSIGNED NOT NULL
,quantity INT NOT NULL
,FOREIGN KEY (obj_id) REFERENCES obj(id) ON DELETE CASCADE
,FOREIGN KEY (item_id) REFERENCES obj_item(obj_id) ON DELETE CASCADE
) ENGINE = InnoDB CHARSET=utf8mb4 COLLATE utf8mb4_bin;`)
failOnError(err, "initDB : create table obj_msg_gold")
log.Println("initDB : obj_msg_item created ...")
_, 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
,msg_type_id SMALLINT UNSIGNED NOT NULL
,chat_id BIGINT NOT NULL
,user_id BIGINT NOT NULL
,UNIQUE KEY (id)
) ENGINE = InnoDB CHARSET=utf8mb4 COLLATE utf8mb4_bin;`)
failOnError(err, "initDB : create table msg_rules")
log.Println("initDB : msg_rules created ...")
_, err = db.Exec(`CREATE VIEW msg_rules_v AS
SELECT r.id
,r.prio
,r.descn COLLATE utf8mb4_unicode_ci AS descn
,r.rule COLLATE utf8mb4_unicode_ci AS rule
,cost.intl_id COLLATE utf8mb4_unicode_ci AS msg_type
FROM msg_rules r
,code_obj_sub_type cost
WHERE cost.id = r.msg_type_id;`)
failOnError(err, "initDB : create table msg_rules_v")
log.Println("initDB : msg_rules created ...")
_, 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)
) ENGINE = InnoDB CHARSET=utf8mb4 COLLATE utf8mb4_bin;`)
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)
) ENGINE = InnoDB CHARSET=utf8mb4 COLLATE utf8mb4_bin;`)
failOnError(err, "initDB : create table obj_xp")
log.Println("initDB : obj_xp created ...")
_, 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 ...")
_, err = db.Exec(`CREATE TABLE obj_job (
obj_id BIGINT UNSIGNED NOT NULL
,priority SMALLINT NOT NULL
,user_id BIGINT UNSIGNED NOT NULL
,trigger_id BIGINT UNSIGNED NOT NULL
,schedule DATETIME NOT NULL
,is_done TINYINT NOT NULL
,in_work TINYINT NOT NULL
,seq_nr BIGINT UNSIGNED
,inserted TIMESTAMP
,pulled TIMESTAMP
,started TIMESTAMP
,ended TIMESTAMP
,timeout TIMESTAMP
,payload VARBINARY(20000)
,FOREIGN KEY (obj_id) REFERENCES obj(id) ON DELETE CASCADE
,KEY (is_done)
,KEY (in_work)
,KEY (user_id)
) ENGINE = InnoDB CHARSET=utf8mb4 COLLATE utf8mb4_bin;`)
failOnError(err, "initDB : create table obj_job")
log.Println("initDB : obj_job created ...")
_, err = db.Exec(`CREATE VIEW obj_job_v AS
SELECT oj.obj_id
,o.obj_sub_type_id AS job_type_id
,cost.intl_id COLLATE utf8mb4_unicode_ci AS job_type
,oj.payload COLLATE utf8mb4_unicode_ci AS payload
FROM obj_job oj
,obj o
,code_obj_sub_type cost
WHERE o.id = oj.obj_id
AND cost.id = o.obj_sub_type_id;`)
failOnError(err, "initDB : create view obj_job_v")
log.Println("initDB : obj_job_v created ...")
_, 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)
) ENGINE = InnoDB CHARSET=utf8mb4 COLLATE utf8mb4_bin;`)
failOnError(err, "initDB : create table obj_name")
log.Println("initDB : obj_name created ...")
_, err = db.Exec(`CREATE VIEW obj_name_v AS
SELECT obn.obj_id
,obn.name COLLATE utf8mb4_unicode_ci AS name
,obn.priority
FROM obj_name obn;`)
failOnError(err, "initDB : create view obj_name_v")
log.Println("initDB : obj_name_v created ...")
_, err = db.Exec(`CREATE VIEW obj_item_name_v AS
SELECT obi.obj_id
,obi.intl_id COLLATE utf8mb4_unicode_ci AS intl_id
,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 ...")
/*
_, err = db.Exec(`INSERT INTO code_obj_type (id, intl_id, name)
VALUES (` + strconv.Itoa(cacheObjType[`user`]) + `, "user", "User")
,(` + strconv.Itoa(cacheObjType[`guild`]) + `, "guild", "Guild")
,(` + strconv.Itoa(cacheObjType[`msg`]) + `, "msg", "Message")
,(` + strconv.Itoa(cacheObjType[`war`]) + `, "war", "War")
,(` + strconv.Itoa(cacheObjType[`war_report`]) + `, "war_report", "War Report")
,(` + strconv.Itoa(cacheObjType[`job`]) + `, "job", "Job")
,(` + strconv.Itoa(cacheObjType[`item`]) + `, "item", "Item")
,(` + strconv.Itoa(cacheObjType[`castle`]) + `, "castle", "Castle")
,(` + strconv.Itoa(cacheObjType[`fair`]) + `, "fair", "Fair")
,(` + strconv.Itoa(cacheObjType[`union`]) + `, "union", "Trade Union")
,(` + strconv.Itoa(cacheObjType[`tribute`]) + `, "tribute", "Tribute")
,(` + strconv.Itoa(cacheObjType[`xp`]) + `, "xp", "Experience")
,(` + strconv.Itoa(cacheObjType[`quest`]) + `, "quest", "Quest")
;`)
failOnError(err, "initDB : populate table code_obj_type")
log.Println("initDB : code_obj_type populated ...")
*/
/*
_, err = db.Exec(`INSERT INTO code_obj_sub_type (id, intl_id, name, obj_type_id)
VALUES (` + strconv.Itoa(cacheObjSubType[`user`]) + `, "user", "User", ` + strconv.Itoa(cacheObjType[`user`]) + `)
,(` + strconv.Itoa(cacheObjSubType[`guild`]) + `, "guild", "Guild", ` + strconv.Itoa(cacheObjType[`guild`]) + `)
,(` + strconv.Itoa(cacheObjSubType[`msg`]) + `, "unknown", "Unknown", ` + strconv.Itoa(cacheObjType[`msg`]) + `)
,(` + strconv.Itoa(cacheObjSubType[`msg_war`]) + `, "war", "War report", ` + strconv.Itoa(cacheObjType[`msg`]) + `)
,(` + strconv.Itoa(cacheObjSubType[`msg_guild_war`]) + `, "guild_war", "Guilds war report", ` + strconv.Itoa(cacheObjType[`msg`]) + `)
,(` + strconv.Itoa(cacheObjSubType[`msg_report_req`]) + `, "report_req", "Player war report request", ` + strconv.Itoa(cacheObjType[`msg`]) + `)
,(` + strconv.Itoa(cacheObjSubType[`msg_report_ack`]) + `, "report_ack", "Player war report ack", ` + strconv.Itoa(cacheObjType[`msg`]) + `)
,(` + strconv.Itoa(cacheObjSubType[`msg_g_report_req`]) + `, "g_report_req", "Player guilds war report request", ` + strconv.Itoa(cacheObjType[`msg`]) + `)
,(` + strconv.Itoa(cacheObjSubType[`msg_g_report_ack`]) + `, "g_report_ack", "Player guilds war report ack", ` + strconv.Itoa(cacheObjType[`msg`]) + `)
,(` + strconv.Itoa(cacheObjSubType[`msg_quest_res`]) + `, "quest_res", "Quest result", ` + strconv.Itoa(cacheObjType[`msg`]) + `)
,(` + strconv.Itoa(cacheObjSubType[`msg_quest_res_ambush`]) + `, "quest_res_ambush", "Quest result with Ambush", ` + strconv.Itoa(cacheObjType[`msg`]) + `)
,(` + strconv.Itoa(cacheObjSubType[`msg_duel_fight`]) + `, "duel_fight", "Duel fight result", ` + strconv.Itoa(cacheObjType[`msg`]) + `)
,(` + strconv.Itoa(cacheObjSubType[`msg_hero_req`]) + `, "hero_req", "Hero summary request", ` + strconv.Itoa(cacheObjType[`msg`]) + `)
,(` + strconv.Itoa(cacheObjSubType[`msg_hero_ack`]) + `, "hero_ack", "Hero summary ack", ` + strconv.Itoa(cacheObjType[`msg`]) + `)
,(` + strconv.Itoa(cacheObjSubType[`msg_me_req`]) + `, "me_req", "Hero short summary request", ` + strconv.Itoa(cacheObjType[`msg`]) + `)
,(` + strconv.Itoa(cacheObjSubType[`msg_me_ack`]) + `, "me_ack", "Hero short summary ack", ` + strconv.Itoa(cacheObjType[`msg`]) + `)
,(` + strconv.Itoa(cacheObjSubType[`msg_inv_req`]) + `, "inv_req", "Inventory request", ` + strconv.Itoa(cacheObjType[`msg`]) + `)
,(` + strconv.Itoa(cacheObjSubType[`msg_inv_ack`]) + `, "inv_ack", "Inventory ack", ` + strconv.Itoa(cacheObjType[`msg`]) + `)
,(` + strconv.Itoa(cacheObjSubType[`msg_pillage_inc`]) + `, "pillage_inc", "Pillage incoming", ` + strconv.Itoa(cacheObjType[`msg`]) + `)
,(` + strconv.Itoa(cacheObjSubType[`msg_pillage_go`]) + `, "pillage_go", "Pillage go", ` + strconv.Itoa(cacheObjType[`msg`]) + `)
,(` + strconv.Itoa(cacheObjSubType[`msg_pillage_timeout`]) + `, "pillage_timeout", "Pillage timeout", ` + strconv.Itoa(cacheObjType[`msg`]) + `)
,(` + strconv.Itoa(cacheObjSubType[`msg_pillage_win`]) + `, "pillage_win", "Pillage win", ` + strconv.Itoa(cacheObjType[`msg`]) + `)
,(` + strconv.Itoa(cacheObjSubType[`msg_pillage_loss`]) + `, "pillage_loss", "Pillage loss", ` + strconv.Itoa(cacheObjType[`msg`]) + `)
,(` + strconv.Itoa(cacheObjSubType[`msg_tribute_inc`]) + `, "tribute_inc", "Tribute incoming", ` + strconv.Itoa(cacheObjType[`msg`]) + `)
,(` + strconv.Itoa(cacheObjSubType[`msg_tribute_ack`]) + `, "tribute_ack", "Tribute acknowledged", ` + strconv.Itoa(cacheObjType[`msg`]) + `)
,(` + strconv.Itoa(cacheObjSubType[`msg_auction_announce`]) + `, "auction_announce", "Auction announce", ` + strconv.Itoa(cacheObjType[`msg`]) + `)
,(` + strconv.Itoa(cacheObjSubType[`msg_auction_upd_req`]) + `, "auction_upd_req", "Auction update request", ` + strconv.Itoa(cacheObjType[`msg`]) + `)
,(` + strconv.Itoa(cacheObjSubType[`msg_auction_upd_ack`]) + `, "auction_upd_ack", "Auction update acknowledgment", ` + strconv.Itoa(cacheObjType[`msg`]) + `)
,(` + strconv.Itoa(cacheObjSubType[`msg_time_ack`]) + `, "time_ack", "Time Acknowledgment", ` + strconv.Itoa(cacheObjType[`msg`]) + `)
,(` + strconv.Itoa(cacheObjSubType[`msg_time_req`]) + `, "time_req", "Time Request", ` + strconv.Itoa(cacheObjType[`msg`]) + `)
,(` + strconv.Itoa(cacheObjSubType[`msg_go`]) + `, "go", "Go", ` + strconv.Itoa(cacheObjType[`msg`]) + `)
,(` + strconv.Itoa(cacheObjSubType[`msg_pledge`]) + `, "pledge", "Pledge", ` + strconv.Itoa(cacheObjType[`msg`]) + `)
,(` + strconv.Itoa(cacheObjSubType[`msg_go_quest_req`]) + `, "go_quest_req", "Go quest Req", ` + strconv.Itoa(cacheObjType[`msg`]) + `)
,(` + strconv.Itoa(cacheObjSubType[`msg_fast_fight`]) + `, "fast_fight", "Arena fast fight", ` + strconv.Itoa(cacheObjType[`msg`]) + `)
,(` + strconv.Itoa(cacheObjSubType[`msg_go_arena`]) + `, "go_arena", "Go arena", ` + strconv.Itoa(cacheObjType[`msg`]) + `)
,(` + strconv.Itoa(cacheObjSubType[`msg_top`]) + `, "top", "Top", ` + strconv.Itoa(cacheObjType[`msg`]) + `)
,(` + strconv.Itoa(cacheObjSubType[`msg_menu`]) + `, "menu", "Menu", ` + strconv.Itoa(cacheObjType[`msg`]) + `)
,(` + strconv.Itoa(cacheObjSubType[`msg_buy_req`]) + `, "buy_req", "Sell Req", ` + strconv.Itoa(cacheObjType[`msg`]) + `)
,(` + strconv.Itoa(cacheObjSubType[`msg_sell_req`]) + `, "sell_req", "Buy Req", ` + strconv.Itoa(cacheObjType[`msg`]) + `)
,(` + strconv.Itoa(cacheObjSubType[`msg_orderbook_req`]) + `, "orderbook_req", "Orderbook Req", ` + strconv.Itoa(cacheObjType[`msg`]) + `)
,(` + strconv.Itoa(cacheObjSubType[`msg_orderbook_acl`]) + `, "orderbook_acl", "Orderbook Ack", ` + strconv.Itoa(cacheObjType[`msg`]) + `)
,(` + strconv.Itoa(cacheObjSubType[`msg_withdraw_req`]) + `, "withdraw_req", "Withdraw Req", ` + strconv.Itoa(cacheObjType[`msg`]) + `)
,(` + strconv.Itoa(cacheObjSubType[`msg_withdraw_code`]) + `, "withdraw_code", "Withdraw Code", ` + strconv.Itoa(cacheObjType[`msg`]) + `)
,(` + strconv.Itoa(cacheObjSubType[`msg_withdraw_rcv`]) + `, "withdraw_rcv", "Withdraw Received", ` + strconv.Itoa(cacheObjType[`msg`]) + `)
,(` + strconv.Itoa(cacheObjSubType[`msg_stock_req`]) + `, "stock_req", "Stock Req", ` + strconv.Itoa(cacheObjType[`msg`]) + `)
,(` + strconv.Itoa(cacheObjSubType[`msg_stock_ack`]) + `, "stock_ack", "Stock Ack", ` + strconv.Itoa(cacheObjType[`msg`]) + `)
,(` + strconv.Itoa(cacheObjSubType[`msg_misc_req`]) + `, "misc_req", "Misc Req", ` + strconv.Itoa(cacheObjType[`msg`]) + `)
,(` + strconv.Itoa(cacheObjSubType[`msg_misc_ack`]) + `, "misc_ack", "Misc Ack", ` + strconv.Itoa(cacheObjType[`msg`]) + `)
,(` + strconv.Itoa(cacheObjSubType[`msg_tureport_req`]) + `, "tureport_req", "Trade Union War Report Req", ` + strconv.Itoa(cacheObjType[`msg`]) + `)
,(` + strconv.Itoa(cacheObjSubType[`msg_tureport_ack`]) + `, "tureport_ack", "Trade Union War Report Ack", ` + strconv.Itoa(cacheObjType[`msg`]) + `)
,(` + strconv.Itoa(cacheObjSubType[`msg_union_war`]) + `, "union_war", "Union war report", ` + strconv.Itoa(cacheObjType[`msg`]) + `)
,(` + strconv.Itoa(cacheObjSubType[`msg_timeout`]) + `, "timeout", "Generic timeout", ` + strconv.Itoa(cacheObjType[`msg`]) + `)
,(` + strconv.Itoa(cacheObjSubType[`msg_go_quest_ack`]) + `, "go_quest_ack", "Go Quest Ack", ` + strconv.Itoa(cacheObjType[`msg`]) + `)
,(` + strconv.Itoa(cacheObjSubType[`msg_groles_req`]) + `, "groles_req", "Guild roles Req", ` + strconv.Itoa(cacheObjType[`msg`]) + `)
,(` + strconv.Itoa(cacheObjSubType[`msg_groles_ack`]) + `, "groles_ack", "Guild roles Ack", ` + strconv.Itoa(cacheObjType[`msg`]) + `)
,(` + strconv.Itoa(cacheObjSubType[`msg_gstock_res_req`]) + `, "gstock_res_req", "GStock Res Req", ` + strconv.Itoa(cacheObjType[`msg`]) + `)
,(` + strconv.Itoa(cacheObjSubType[`msg_gstock_alch_req`]) + `, "gstock_alch_req", "GStock Alch Req", ` + strconv.Itoa(cacheObjType[`msg`]) + `)
,(` + strconv.Itoa(cacheObjSubType[`msg_gstock_misc_req`]) + `, "gstock_misc_req", "GStock Misc Req", ` + strconv.Itoa(cacheObjType[`msg`]) + `)
,(` + strconv.Itoa(cacheObjSubType[`msg_gstock_rec_req`]) + `, "gstock_rec_req", "GStock Rec Req", ` + strconv.Itoa(cacheObjType[`msg`]) + `)
,(` + strconv.Itoa(cacheObjSubType[`msg_gstock_part_req`]) + `, "gstock_part_req", "GStock Part Req", ` + strconv.Itoa(cacheObjType[`msg`]) + `)
,(` + strconv.Itoa(cacheObjSubType[`msg_gstock_oth_req`]) + `, "gstock_oth_req", "Gstock Oth Req", ` + strconv.Itoa(cacheObjType[`msg`]) + `)
,(` + strconv.Itoa(cacheObjSubType[`msg_gstock_any_ack`]) + `, "gstock_any_ack", "Gstock Any Ack", ` + strconv.Itoa(cacheObjType[`msg`]) + `)
,(` + strconv.Itoa(cacheObjSubType[`msg_gstock_req`]) + `, "gstock_req", "GStock Req", ` + strconv.Itoa(cacheObjType[`msg`]) + `)
,(` + strconv.Itoa(cacheObjSubType[`msg_gstock_ack`]) + `, "gstock_ack", "GStock Ack", ` + strconv.Itoa(cacheObjType[`msg`]) + `)
,(` + strconv.Itoa(cacheObjSubType[`msg_busy`]) + `, "busy", "Busy", ` + strconv.Itoa(cacheObjType[`msg`]) + `)
,(` + strconv.Itoa(cacheObjSubType[`msg_res_stock_req`]) + `, "res_stock_req", "Resources Stock Req", ` + strconv.Itoa(cacheObjType[`msg`]) + `)
,(` + strconv.Itoa(cacheObjSubType[`msg_alch_stock_req`]) + `, "alch_stock_req", "Alchemy Stock Req", ` + strconv.Itoa(cacheObjType[`msg`]) + `)
,(` + strconv.Itoa(cacheObjSubType[`msg_misc_stock_req`]) + `, "misc_stock_req", "Misc Stock Req", ` + strconv.Itoa(cacheObjType[`msg`]) + `)
,(` + strconv.Itoa(cacheObjSubType[`msg_equip_stock_req`]) + `, "equip_stock_req", "Equipment Stock Req", ` + strconv.Itoa(cacheObjType[`msg`]) + `)
,(` + strconv.Itoa(cacheObjSubType[`msg_craft_stock_req`]) + `, "craft_stock_req", "Equipment Stock Req", ` + strconv.Itoa(cacheObjType[`msg`]) + `)
,(` + strconv.Itoa(cacheObjSubType[`msg_stock_empty`]) + `, "stock_empty", "Stock Empty", ` + strconv.Itoa(cacheObjType[`msg`]) + `)
,(` + strconv.Itoa(cacheObjSubType[`msg_stock_any_ack`]) + `, "stock_any_ack", "Stock Any Ack", ` + strconv.Itoa(cacheObjType[`msg`]) + `)
,(` + strconv.Itoa(cacheObjSubType[`msg_g_deposit_req`]) + `, "g_deposit_req", "GDeposit Req", ` + strconv.Itoa(cacheObjType[`msg`]) + `)
,(` + strconv.Itoa(cacheObjSubType[`msg_g_deposit_ack`]) + `, "g_deposit_ack", "GDeposit Ack", ` + strconv.Itoa(cacheObjType[`msg`]) + `)
,(` + strconv.Itoa(cacheObjSubType[`msg_castle_attack_req`]) + `, "castle_attack_req", "Castle Attack Req", ` + strconv.Itoa(cacheObjType[`msg`]) + `)
,(` + strconv.Itoa(cacheObjSubType[`msg_castle_attack_ack`]) + `, "castle_attack_ack", "Castle Attack Ack", ` + strconv.Itoa(cacheObjType[`msg`]) + `)
,(` + strconv.Itoa(cacheObjSubType[`msg_castle_target_req`]) + `, "castle_target_req", "Castle Target Req", ` + strconv.Itoa(cacheObjType[`msg`]) + `)
,(` + strconv.Itoa(cacheObjSubType[`msg_castle_target_ack`]) + `, "castle_target_ack", "Castle Target Ack", ` + strconv.Itoa(cacheObjType[`msg`]) + `)
,(` + strconv.Itoa(cacheObjSubType[`msg_castle_def_req`]) + `, "castle_def_req", "Castle Defense Req", ` + strconv.Itoa(cacheObjType[`msg`]) + `)
,(` + strconv.Itoa(cacheObjSubType[`msg_castle_def_ack`]) + `, "castle_def_ack", "Castle Defense Ack", ` + strconv.Itoa(cacheObjType[`msg`]) + `)
,(` + strconv.Itoa(cacheObjSubType[`msg_back`]) + `, "back", "Back", ` + strconv.Itoa(cacheObjType[`msg`]) + `)
,(` + strconv.Itoa(cacheObjSubType[`msg_castle_req`]) + `, "castle_req", "Castle Req", ` + strconv.Itoa(cacheObjType[`msg`]) + `)
,(` + strconv.Itoa(cacheObjSubType[`msg_castle_ack`]) + `, "castle_ack", "Castle Ack", ` + strconv.Itoa(cacheObjType[`msg`]) + `)
,(` + strconv.Itoa(cacheObjSubType[`msg_exchange_req`]) + `, "exchange_req", "Exchange Req", ` + strconv.Itoa(cacheObjType[`msg`]) + `)
,(` + strconv.Itoa(cacheObjSubType[`msg_exchange_ack`]) + `, "exchange_ack", "Exchange Ack", ` + strconv.Itoa(cacheObjType[`msg`]) + `)
,(` + strconv.Itoa(cacheObjSubType[`msg_equip_req`]) + `, "equip_req", "Equip Req", ` + strconv.Itoa(cacheObjType[`msg`]) + `)
,(` + strconv.Itoa(cacheObjSubType[`msg_equip_ack`]) + `, "equip_ack", "Equip Ack", ` + strconv.Itoa(cacheObjType[`msg`]) + `)
,(` + strconv.Itoa(cacheObjSubType[`msg_unequip_req`]) + `, "unequip_req", "Unequip Req", ` + strconv.Itoa(cacheObjType[`msg`]) + `)
,(` + strconv.Itoa(cacheObjSubType[`msg_unequip_ack`]) + `, "unequip_ack", "Unequip Ack", ` + strconv.Itoa(cacheObjType[`msg`]) + `)
,(` + strconv.Itoa(cacheObjSubType[`msg_no_stamina`]) + `, "no_stamina", "No Stamina", ` + strconv.Itoa(cacheObjType[`msg`]) + `)
,(` + strconv.Itoa(cacheObjSubType[`msg_orderbook_search`]) + `, "orderbook_search", "Orderbook search", ` + strconv.Itoa(cacheObjType[`msg`]) + `)
,(` + strconv.Itoa(cacheObjSubType[`msg_quest_req`]) + `, "quest_req", "Quest Req", ` + strconv.Itoa(cacheObjType[`msg`]) + `)
,(` + strconv.Itoa(cacheObjSubType[`msg_quest_ack`]) + `, "quest_ack", "Quest Ack", ` + strconv.Itoa(cacheObjType[`msg`]) + `)
,(` + strconv.Itoa(cacheObjSubType[`msg_battle`]) + `, "battle", "Battle", ` + strconv.Itoa(cacheObjType[`msg`]) + `)
,(` + strconv.Itoa(cacheObjSubType[`msg_order_cancel_req`]) + `, "order_cancel_req", "Order Cancel Req", ` + strconv.Itoa(cacheObjType[`msg`]) + `)
,(` + strconv.Itoa(cacheObjSubType[`msg_order_cancel_ack`]) + `, "order_cancel_ack", "Order Cancel Ack", ` + strconv.Itoa(cacheObjType[`msg`]) + `)
,(` + strconv.Itoa(cacheObjSubType[`msg_stamina_restored`]) + `, "stamina_restored", "Stamina Restored", ` + strconv.Itoa(cacheObjType[`msg`]) + `)
,(` + strconv.Itoa(cacheObjSubType[`msg_heal_up`]) + `, "heal_up", "Heal Up", ` + strconv.Itoa(cacheObjType[`msg`]) + `)
,(` + strconv.Itoa(cacheObjSubType[`msg_arena_fight_ack`]) + `, "arena_fight_ack", "Arena Fight Ack", ` + strconv.Itoa(cacheObjType[`msg`]) + `)
,(` + strconv.Itoa(cacheObjSubType[`msg_go_arena`]Ack) + `, "go_arena_ack", "Go Arena Ack", ` + strconv.Itoa(cacheObjType[`msg`]) + `)
,(` + strconv.Itoa(cacheObjSubType[`msg_withdraw_nack`]) + `, "withdraw_nack", "Withdraw NAck", ` + strconv.Itoa(cacheObjType[`msg`]) + `)
,(` + strconv.Itoa(cacheObjSubType[`msg_pillage_defeat`]) + `, "pillage_defeat", "Pillage Defeat", ` + strconv.Itoa(cacheObjType[`msg`]) + `)
,(` + strconv.Itoa(cacheObjSubType[`msg_level_up_req`]) + `, "level_up_req", "Level Up Req", ` + strconv.Itoa(cacheObjType[`msg`]) + `)
,(` + strconv.Itoa(cacheObjSubType[`msg_level_up_ack`]) + `, "level_up_ack", "Level Up Ack", ` + strconv.Itoa(cacheObjType[`msg`]) + `)
,(` + strconv.Itoa(cacheObjSubType[`msg_top`]Req) + `, "top_req", "Top Req", ` + strconv.Itoa(cacheObjType[`msg`]) + `)
,(` + strconv.Itoa(cacheObjSubType[`job_pillage`]) + `, "job_pillage", "Pillage job", ` + strconv.Itoa(cacheObjType[`job`]) + `)
,(` + strconv.Itoa(cacheObjSubType[`job_tribute`]) + `, "job_tribute", "Tribute job", ` + strconv.Itoa(cacheObjType[`job`]) + `)
,(` + strconv.Itoa(cacheObjSubType[`job_gwithdraw`]) + `, "job_gwithdraw", "GWithdrawal job", ` + strconv.Itoa(cacheObjType[`job`]) + `)
,(` + strconv.Itoa(cacheObjSubType[`job_gstock`]) + `, "job_gstock", "GStock job", ` + strconv.Itoa(cacheObjType[`job`]) + `)
,(` + strconv.Itoa(cacheObjSubType[`job_rescan_msg`]) + `, "job_rescan_msg", "Rescan message job", ` + strconv.Itoa(cacheObjType[`job`]) + `)
,(` + strconv.Itoa(cacheObjSubType[`job_set_done`]) + `, "job_set_done", "Set job as done job", ` + strconv.Itoa(cacheObjType[`job`]) + `)
,(` + strconv.Itoa(cacheObjSubType[`job_msg_client`]) + `, "job_msg_client", "Send message via client", ` + strconv.Itoa(cacheObjType[`job`]) + `)
,(` + strconv.Itoa(cacheObjSubType[`job_msg_refresh`]) + `, "job_msg_refresh", "Refresh message from client", ` + strconv.Itoa(cacheObjType[`job`]) + `)
,(` + strconv.Itoa(cacheObjSubType[`job_backup_export`]) + `, "job_backup_export", "Export Backup", ` + strconv.Itoa(cacheObjType[`job`]) + `)
,(` + strconv.Itoa(cacheObjSubType[`job_backup_import`]) + `, "job_backup_import", "Import Backup", ` + strconv.Itoa(cacheObjType[`job`]) + `)
,(` + strconv.Itoa(cacheObjSubType[`job_gdeposit`]) + `, "job_gdeposit", "GDeposit job", ` + strconv.Itoa(cacheObjType[`job`]) + `)
,(` + strconv.Itoa(cacheObjSubType[`job_gdeposit_fwd`]) + `, "job_gdeposit_fwd", "GDeposit Forward job", ` + strconv.Itoa(cacheObjType[`job`]) + `)
,(` + strconv.Itoa(cacheObjSubType[`job_save_res`]) + `, "job_save_res", "Save resources job", ` + strconv.Itoa(cacheObjType[`job`]) + `)
,(` + strconv.Itoa(cacheObjSubType[`job_vault_user_status`]) + `, "job_vault_user_status", "Vault User Status job", ` + strconv.Itoa(cacheObjType[`job`]) + `)
,(` + strconv.Itoa(cacheObjSubType[`job_vault_item_status`]) + `, "job_vault_item_status", "Vault Item Status job", ` + strconv.Itoa(cacheObjType[`job`]) + `)
,(` + strconv.Itoa(cacheObjSubType[`job_msg_fwd`]) + `, "job_fwd_msg", "Forward Message job", ` + strconv.Itoa(cacheObjType[`job`]) + `)
,(` + strconv.Itoa(cacheObjSubType[`job_set_def`]) + `, "job_set_def", "Set Defense job", ` + strconv.Itoa(cacheObjType[`job`]) + `)
,(` + strconv.Itoa(cacheObjSubType[`job_msg_del`]) + `, "job_msg_del", "Msg Del job", ` + strconv.Itoa(cacheObjType[`job`]) + `)
,(` + strconv.Itoa(cacheObjSubType[`job_get_hammer_time`]) + `, "job_get_hammer_time", "Get Hammer Time job", ` + strconv.Itoa(cacheObjType[`job`]) + `)
,(` + strconv.Itoa(cacheObjSubType[`item_res`]) + `, "item_res", "Resource", ` + strconv.Itoa(cacheObjType[`item`]) + `)
,(` + strconv.Itoa(cacheObjSubType[`item_alch`]) + `, "item_alch", "Alchemy", ` + strconv.Itoa(cacheObjType[`item`]) + `)
,(` + strconv.Itoa(cacheObjSubType[`item_misc`]) + `, "item_misc", "Miscelaneous", ` + strconv.Itoa(cacheObjType[`item`]) + `)
,(` + strconv.Itoa(cacheObjSubType[`item_recipe`]) + `, "item_recipe", "Recipe", ` + strconv.Itoa(cacheObjType[`item`]) + `)
,(` + strconv.Itoa(cacheObjSubType[`item_part`]) + `, "item_part", "Part", ` + strconv.Itoa(cacheObjType[`item`]) + `)
,(` + strconv.Itoa(cacheObjSubType[`item_other`]) + `, "item_other", "Other", ` + strconv.Itoa(cacheObjType[`item`]) + `)
,(` + strconv.Itoa(cacheObjSubType[`castle`]) + `, "castle", "Castle", ` + strconv.Itoa(cacheObjType[`castle`]) + `)
,(` + strconv.Itoa(cacheObjSubType[`union`]) + `, "union", "Union", ` + strconv.Itoa(cacheObjType[`union`]) + `)
,(` + strconv.Itoa(cacheObjSubType[`fair`]) + `, "fair", "Fair", ` + strconv.Itoa(cacheObjType[`fair`]) + `)
,(` + strconv.Itoa(cacheObjSubType[`tribute`]) + `, "tribute", "Tribute", ` + strconv.Itoa(cacheObjType[`tribute`]) + `)
,(` + strconv.Itoa(cacheObjSubType[`xp`]) + `, "xp", "Experience", ` + strconv.Itoa(cacheObjType[`xp`]) + `)
,(` + strconv.Itoa(cacheObjSubType[`quest_forest`]) + `, "forest", "Forest", ` + strconv.Itoa(cacheObjType[`quest`]) + `)
,(` + strconv.Itoa(cacheObjSubType[`quest_swamp`]) + `, "swamp", "Swamp", ` + strconv.Itoa(cacheObjType[`quest`]) + `)
,(` + strconv.Itoa(cacheObjSubType[`quest_valley`]) + `, "valley", "Valley", ` + strconv.Itoa(cacheObjType[`quest`]) + `)
;`)
failOnError(err, "initDB : populate table code_obj_sub_type")
log.Println("initDB : code_obj_sub_type populated ...")
*/
_, err = db.Exec(`CREATE VIEW obj_msg_vault_v AS
SELECT obm.sender_user_id user_id
,obm.chat_id
,om.obj_sub_type_id msg_type_id
,omi.item_id
,oi.obj_sub_type_id item_type_id
,omi.quantity
FROM obj om
,obj_msg obm
,obj oi
,obj_msg_item omi
WHERE om.obj_type_id = ` + strconv.FormatInt(cacheObjType[`msg`], 10) + `
AND om.obj_sub_type_id in (` + strconv.FormatInt(cacheObjSubType[`msg_withdraw_rcv`], 10) + `, ` + strconv.FormatInt(cacheObjSubType[`msg_g_deposit_ack`], 10) + `)
AND obm.obj_id = om.id
AND omi.obj_id = om.id
AND oi.id = omi.item_id
ORDER BY obm.sender_user_id ASC
,omi.item_id ASC;`)
failOnError(err, "initDB : create view obj_msg_vault_v")
log.Println("initDB : obj_msg_vault_v created ...")
log.Println("initDB : Database set up")
}
func insertObjType(intlId string, name string) error {
stmt, err := db.Prepare(`INSERT INTO code_obj_type (intl_id, name)
VALUES (?, ?);`)
if err != nil {
return err
}
defer stmt.Close()
_, err = stmt.Exec(intlId, name)
if err != nil {
return err
}
return nil
}
func insertObjSubType(intlId string, name string, objType string) error {
stmt, err := db.Prepare(`INSERT INTO code_obj_sub_type
SELECT null id, ? intl_id, ? name, cot.id
FROM code_obj_type cot
WHERE cot.intl_id = ?;`)
if err != nil {
return err
}
defer stmt.Close()
_, err = stmt.Exec(intlId, name, objType)
if err != nil {
return err
}
return nil
}
func insertMsgItem(objId int64, itemId int64, quantity int64) error {
stmt, err := db.Prepare(`INSERT INTO obj_msg_item (obj_id, item_id, quantity)
VALUES (?, ?, ?);`)
if err != nil {
return err
}
defer stmt.Close()
_, err = stmt.Exec(objId, itemId, quantity)
if err != nil {
return err
}
return nil
}
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 != cacheObjSubType[`msg`] {
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
}
func insertMsgDuelFight(m *ChatWarsMessageDuelFight) error {
objSubTypeId, err := getObjSubTypeId(m.ObjID64)
if err != nil {
return err
}
if objSubTypeId != cacheObjSubType[`msg`] && objSubTypeId != cacheObjSubType[`msg_duel_fight`] {
return errors.New("Message type mismatch")
}
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 (?, ?, ?, ?, ?, ?, ?, ?, ?, ?);`)
if err != nil {
return err
}
defer stmt.Close()
_, 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)
if err != nil {
return err
}
return nil
}
func insertMsgAuctionAnnounce(m *ChatWarsMessageAuctionAnnounce) error {
objSubTypeId, err := getObjSubTypeId(m.ObjID64)
if err != nil {
return err
}
if objSubTypeId != cacheObjSubType[`msg`] && objSubTypeId != cacheObjSubType[`msg_auction_announce`] {
return errors.New("Message type mismatch")
}
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 (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);`)
if err != nil {
return err
}
defer stmt.Close()
_, 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)
if err != nil {
return err
}
return nil
}
func insertMsgPillageInc(m *ChatWarsMessagePillageInc) error {
objSubTypeId, err := getObjSubTypeId(m.ObjID64)
if err != nil {
return err
}
if objSubTypeId != cacheObjSubType[`msg`] && objSubTypeId != cacheObjSubType[`msg_pillage_inc`] {
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()
_, err = stmt.Exec(m.ObjID64, m.Attacker, m.Guild, getObjCastleID(m.Castle))
if err != nil {
return err
}
return nil
}
func getSQLListID64(q string) []int64 {
var (
id int64
ids []int64
)
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()
logOnError(err, "getSQLListID64 : query end")
rows.Close()
return ids
}