This commit is contained in:
shoopea 2019-05-07 19:15:25 +08:00
parent b91ed6f98a
commit d2db3b9d1d
3 changed files with 65 additions and 22 deletions

42
def.go
View File

@ -9,27 +9,45 @@ type ChatWarsMessage struct {
Text string `json:"text"`
}
type MessageParsingRule struct {
ID int32
Priority int32
Description string
Rule string
MsgTypeID int32
}
const (
objTypeUser = 1
objTypeGuild = 2
objTypeMessage = 3
objTypeWar = 4
objTypeWarReport = 5
objTypeJob = 6
objSubTypeMessageUnprocess = 1
objSubTypeMessageUnknown = 2
objSubTypeMessageWar = 3
objSubTypeMessageMiniWar = 4
objSubTypeMessageGuildWar = 5
objSubTypeMessageReport = 6
objSubTypeMessageGReport = 7
objSubTypeMessageQuest = 8
objSubTypeMessageFight = 9
objSubTypeMessageHero = 10
objSubTypeMessageMe = 11
objSubTypeMessageInventory = 12
objSubTypeMessageUnknown = 301
objSubTypeMessageWar = 302
objSubTypeMessageMiniWar = 303
objSubTypeMessageGuildWar = 304
objSubTypeMessageReport = 305
objSubTypeMessageGReport = 306
objSubTypeMessageQuest = 307
objSubTypeMessageFight = 308
objSubTypeMessageHero = 309
objSubTypeMessageMe = 310
objSubTypeMessageInventory = 311
objSubTypeMessagePillageInc = 312
objSubTypeMessageTributeInc = 313
objSubTypeMessagePillageAck = 314
objSubTypeMessageTributeAck = 315
objSubTypeJobPillage = 601
objSubTypeJobTribute = 602
objSubTypeJobStatus = 603
objSubTypeJobWithdrawal = 604
objSubTypeJobGStock = 605
MQGetMsgWorkers = 3
SQLCWMsgWorkers = 6
SQLIdentifyMsgWorkers = 6
SQLJobWorkers = 3
)

30
sql.go
View File

@ -42,7 +42,7 @@ func initDB() {
log.Println("Database cleaned up")
_, err = db.Exec(`CREATE TABLE code_obj_type (
id SMALLINT(5) UNSIGNED NOT NULL
id SMALLINT UNSIGNED NOT NULL
,intl_id VARCHAR(32) NOT NULL
,name VARCHAR(80) NOT NULL
,PRIMARY KEY (id)
@ -50,7 +50,7 @@ func initDB() {
failOnError(err, "initDB : create table code_obj_type")
_, err = db.Exec(`CREATE TABLE code_obj_sub_type (
id SMALLINT(5) UNSIGNED NOT NULL
id SMALLINT UNSIGNED NOT NULL
,intl_id VARCHAR(32) NOT NULL
,name VARCHAR(80) NOT NULL
,obj_type_id SMALLINT UNSIGNED NOT NULL
@ -64,6 +64,8 @@ func initDB() {
,obj_type_id SMALLINT UNSIGNED NOT NULL
,obj_sub_type_id SMALLINT UNSIGNED NOT NULL
,PRIMARY KEY (id)
,FOREIGN KEY (obj_type_id) REFERENCSE code_obj_type(id) ON DELETE CASCADE
,FOREIGN KEY (obj_sub_type_id) REFERENCSE code_obj_sub_type(id) ON DELETE CASCADE
) ENGINE = InnoDB AUTO_INCREMENT = 0 CHARSET=utf8mb4 COLLATE utf8mb4_unicode_ci;`)
failOnError(err, "initDB : create table obj")
@ -81,7 +83,7 @@ func initDB() {
failOnError(err, "initDB : create table obj_user")
_, err = db.Exec(`CREATE TABLE obj_guild (
obj_id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT
obj_id BIGINT UNSIGNED NOT NULL
,tag VARCHAR(32) NOT NULL
,name VARCHAR(80) NOT NULL
,chat_id BIGINT NOT NULL
@ -136,18 +138,28 @@ func initDB() {
) ENGINE = InnoDB CHARSET=utf8mb4 COLLATE utf8mb4_unicode_ci;`)
failOnError(err, "initDB : create table obj_msg_report")
_, 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
,UNIQUE KEY (id)
) ENGINE = InnoDB CHARSET=utf8mb4 COLLATE utf8mb4_unicode_ci;`)
failOnError(err, "initDB : create table msg_rules")
_, err = db.Exec(`INSERT INTO code_obj_type (id, intl_id, name)
VALUES (` + strconv.Itoa(objTypeUser) + `, "user", "User")
,(` + strconv.Itoa(objTypeGuild) + `, "guild", "Guild")
,(` + strconv.Itoa(objTypeMessage) + `, "msg", "Message")
,(` + strconv.Itoa(objTypeWar) + `, "war", "War")
,(` + strconv.Itoa(objTypeWarReport) + `, "war_report", "War Report")
,(` + strconv.Itoa(objTypeJob) + `, "job", "Job")
;`)
failOnError(err, "initDB : populate table code_obj_type")
_, err = db.Exec(`INSERT INTO code_obj_sub_type (id, intl_id, name, obj_type_id)
VALUES (` + strconv.Itoa(objSubTypeMessageUnprocess) + `, "unprocessed", "Unprocessed", ` + strconv.Itoa(objTypeMessage) + `)
,(` + strconv.Itoa(objSubTypeMessageUnknown) + `, "unknown", "Unknown", ` + strconv.Itoa(objTypeMessage) + `)
VALUES (` + strconv.Itoa(objSubTypeMessageUnknown) + `, "unknown", "Unknown", ` + strconv.Itoa(objTypeMessage) + `)
,(` + 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) + `)
@ -157,7 +169,11 @@ func initDB() {
,(` + strconv.Itoa(objSubTypeMessageFight) + `, "fight", "Fight result", ` + strconv.Itoa(objTypeMessage) + `)
,(` + strconv.Itoa(objSubTypeMessageHero) + `, "hero", "Hero summary", ` + strconv.Itoa(objTypeMessage) + `)
,(` + strconv.Itoa(objSubTypeMessageMe) + `, "me", "Hero short summary", ` + strconv.Itoa(objTypeMessage) + `)
,(` + strconv.Itoa(objSubTypeMessageInventory) + `, "inv", "Inventory", ` + strconv.Itoa(objTypeMessage) + `);`)
,(` + strconv.Itoa(objSubTypeMessageInventory) + `, "inv", "Inventory", ` + strconv.Itoa(objTypeMessage) + `)
,(` + strconv.Itoa(objSubTypeMessagePillageInc) + `, "pillage_inc", "Pillage incoming", ` + strconv.Itoa(objTypeMessage) + `)
,(` + strconv.Itoa(objSubTypeMessageTributeInc) + `, "tribute_inc", "Request incoming", ` + strconv.Itoa(objTypeMessage) + `)
,(` + strconv.Itoa(objSubTypeMessagePillageInc) + `, "pillage_ack", "Pillage acknoledged", ` + strconv.Itoa(objTypeMessage) + `)
,(` + strconv.Itoa(objSubTypeMessageTributeInc) + `, "tribute_ack", "Request acknoledged", ` + strconv.Itoa(objTypeMessage) + `);`)
failOnError(err, "initDB : populate table code_obj_sub_type")
log.Println("Database set up")
@ -228,7 +244,7 @@ func insertMsgReport(objId int64, war_date int32, atk int32, def int32, exp int3
if err != nil {
return err
}
if objSubTypeId != objSubTypeMessageUnprocess {
if objSubTypeId != objSubTypeMessageUnknown {
return errors.New("Message is not of type Unknown")
}
/*

View File

@ -93,7 +93,6 @@ func SQLIdentifyMsgWorker(id int, objIds <-chan int64) {
log.Printf("SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : Stock : %s (%d)\n", r.ReplaceAllString(m.Text, "${Stock}"), objId)
log.Printf("SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : Stamina : %s (%d)\n", r.ReplaceAllString(m.Text, "${Stamina}"), objId)
log.Printf("SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : Crit : %s (%d)\n", r.ReplaceAllString(m.Text, "${Crit}"), objId)
log.Printf("SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : Test : %s (%d)\n", r.ReplaceAllString(m.Text, "${Test}"), objId)
} else {
log.Printf("SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : Unknown message type (%d)\n", objId)
}
@ -101,3 +100,13 @@ func SQLIdentifyMsgWorker(id int, objIds <-chan int64) {
}
log.Printf("SQLIdentifyMsgWorker[" + strconv.Itoa(id) + "] : Closing.")
}
func SQLJobWorker(id int) {
var tick time.Time
log.Printf("SQLJobWorker[" + strconv.Itoa(id) + "] : Starting.")
for true {
time.Sleep(100 * time.Millisecond)
tick = time.Now()
}
log.Printf("SQLJobWorker[" + strconv.Itoa(id) + "] : Closing.")
}