testtest
This commit is contained in:
parent
a43848d7df
commit
9e0b05caf7
27
def.go
27
def.go
@ -58,6 +58,14 @@ type ChatWarsUser struct {
|
|||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type ChatWarsItem struct {
|
||||||
|
ObjID64 int64 `json:"obj_id"`
|
||||||
|
ItemTypeID int64 `json:"item_type_id"`
|
||||||
|
Code string `json:"code"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
Weight int `json:"weight"`
|
||||||
|
}
|
||||||
|
|
||||||
type ChatWarsMessage struct {
|
type ChatWarsMessage struct {
|
||||||
ObjID64 int64 `json:"obj_id"`
|
ObjID64 int64 `json:"obj_id"`
|
||||||
UserID64 int64 `json:"user_id"`
|
UserID64 int64 `json:"user_id"`
|
||||||
@ -289,15 +297,15 @@ const (
|
|||||||
objSubTypeMessageGoQuestAck = 353 // confirm quest destination/busyness (done)
|
objSubTypeMessageGoQuestAck = 353 // confirm quest destination/busyness (done)
|
||||||
objSubTypeMessageGRolesReq = 354 // /g_roles (done)
|
objSubTypeMessageGRolesReq = 354 // /g_roles (done)
|
||||||
objSubTypeMessageGRolesAck = 355 // result from /g_roles (done)
|
objSubTypeMessageGRolesAck = 355 // result from /g_roles (done)
|
||||||
objSubTypeMessageGStockResReq = 356 // /g_stock_res (not done)
|
objSubTypeMessageGStockResReq = 356 // /g_stock_res (done)
|
||||||
objSubTypeMessageGStockAlchReq = 357 // /g_stock_res (not done)
|
objSubTypeMessageGStockAlchReq = 357 // /g_stock_alch (done)
|
||||||
objSubTypeMessageGStockMiscReq = 358 // /g_stock_res (not done)
|
objSubTypeMessageGStockMiscReq = 358 // /g_stock_misc (done)
|
||||||
objSubTypeMessageGStockRecReq = 359 // /g_stock_res (not done)
|
objSubTypeMessageGStockRecReq = 359 // /g_stock_rec (done)
|
||||||
objSubTypeMessageGStockPartReq = 360 // /g_stock_res (not done)
|
objSubTypeMessageGStockPartReq = 360 // /g_stock_parts (done)
|
||||||
objSubTypeMessageGStockOthReq = 361 // /g_stock_res (not done)
|
objSubTypeMessageGStockOthReq = 361 // /g_stock_other (done)
|
||||||
objSubTypeMessageGStockAnyAck = 362 // result from any /g_stock_xxx (not done)
|
objSubTypeMessageGStockAnyAck = 362 // result from any /g_stock_xxx (done)
|
||||||
objSubTypeMessageGStockReq = 363 // /g_stock (not done)
|
objSubTypeMessageGStockReq = 363 // /g_stock (done)
|
||||||
objSubTypeMessageGStockAck = 364 // result from /g_stock (not done)
|
objSubTypeMessageGStockAck = 364 // result from /g_stock (done)
|
||||||
objSubTypeJobPillage = 601
|
objSubTypeJobPillage = 601
|
||||||
objSubTypeJobTribute = 602
|
objSubTypeJobTribute = 602
|
||||||
objSubTypeJobStatus = 603
|
objSubTypeJobStatus = 603
|
||||||
@ -312,6 +320,7 @@ const (
|
|||||||
objSubTypeItemRecipe = 704
|
objSubTypeItemRecipe = 704
|
||||||
objSubTypeItemPart = 705
|
objSubTypeItemPart = 705
|
||||||
objSubTypeItemOther = 706
|
objSubTypeItemOther = 706
|
||||||
|
objSubTypeItemUnique = 707
|
||||||
objSubTypeCastle = 801
|
objSubTypeCastle = 801
|
||||||
objSubTypeFair = 901
|
objSubTypeFair = 901
|
||||||
objSubTypeUnion = 1001
|
objSubTypeUnion = 1001
|
||||||
|
94
obj.go
94
obj.go
@ -10,6 +10,7 @@ var (
|
|||||||
cacheObjCastle *sync.Map
|
cacheObjCastle *sync.Map
|
||||||
cacheObjGuild *sync.Map
|
cacheObjGuild *sync.Map
|
||||||
cacheObjUser *sync.Map
|
cacheObjUser *sync.Map
|
||||||
|
cacheObjItem *sync.Map
|
||||||
)
|
)
|
||||||
|
|
||||||
func getObjTypeId(objId int64) (int64, error) {
|
func getObjTypeId(objId int64) (int64, error) {
|
||||||
@ -438,3 +439,96 @@ func addObjXP(userID64 int64, expNow int64, expLvl int64, level int64, date time
|
|||||||
}
|
}
|
||||||
return objId, nil
|
return objId, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func addObjItem(name string, code string, itemTypeID64 int64, weight int) (int64, error) {
|
||||||
|
tx, err := db.Begin()
|
||||||
|
logOnError(err, "addObjItem : start transaction")
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
|
||||||
|
res, err := tx.Exec(`INSERT INTO obj (obj_type_id, obj_sub_type_id)
|
||||||
|
VALUES (` + strconv.Itoa(objTypeItem) + `,` + strconv.Itoa(itemTypeID64) + `);`)
|
||||||
|
logOnError(err, "addObjItem : exec insert obj")
|
||||||
|
if err != nil {
|
||||||
|
err2 := tx.Rollback()
|
||||||
|
logOnError(err2, "addObjItem : rollback insert obj")
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
|
||||||
|
objId, err := res.LastInsertId()
|
||||||
|
if err != nil {
|
||||||
|
err2 := tx.Rollback()
|
||||||
|
logOnError(err2, "addObjItem : rollback get lastInsertId")
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
|
||||||
|
stmt, err := tx.Prepare(`INSERT INTO obj_item (obj_id, intl_id, name, weight)
|
||||||
|
VALUES (?, ?, ?, ?);`)
|
||||||
|
logOnError(err, "addObjItem : prepare insert obj_item")
|
||||||
|
if err != nil {
|
||||||
|
err2 := tx.Rollback()
|
||||||
|
logOnError(err2, "addObjItem : rollback prepare insert obj_item")
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
defer stmt.Close()
|
||||||
|
|
||||||
|
_, err = stmt.Exec(objId, code, name, weight)
|
||||||
|
logOnError(err, "addObjItem : exec insert obj_item")
|
||||||
|
if err != nil {
|
||||||
|
err2 := tx.Rollback()
|
||||||
|
logOnError(err2, "addObjItem : rollback exec insert obj_item")
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = tx.Commit()
|
||||||
|
logOnError(err, "addObjItem : commit")
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
return objId, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func getObjItemID(s string) int64 {
|
||||||
|
if v, ok := cacheObjItem.Load(s); ok {
|
||||||
|
i := v.(ChatWarsUser)
|
||||||
|
return i.ObjID64
|
||||||
|
} else {
|
||||||
|
s := fmt.Sprintf("Object unknown : %s\n", s)
|
||||||
|
clientSendCWMsg(cfg.Bot.Admin, s)
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func loadObjItem() error {
|
||||||
|
var (
|
||||||
|
id int64
|
||||||
|
intl_id string
|
||||||
|
name string
|
||||||
|
weight int
|
||||||
|
)
|
||||||
|
|
||||||
|
cacheObjItem = new(sync.Map)
|
||||||
|
|
||||||
|
items, err := db.Query(`SELECT oi.obj_id, oi.intl_id, oi.name, oi.weight FROM obj_item oi;`)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer items.Close()
|
||||||
|
|
||||||
|
for items.Next() {
|
||||||
|
err = items.Scan(&id, &intl_id, &name, &weight)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
c := new(ChatWarsItem)
|
||||||
|
c.ObjID64 = id
|
||||||
|
c.Code = intl_id
|
||||||
|
c.Name = name
|
||||||
|
c.Weight = weight
|
||||||
|
cacheObjItem.Store(intl_id, *c)
|
||||||
|
cacheObjItem.Store(name, *c)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
15
rules.go
15
rules.go
@ -139,6 +139,21 @@ func resetMsgParsingRules() {
|
|||||||
,(5000, ` + strconv.Itoa(objSubTypeMessageGoQuestAck) + `, "Go Quest Ack Devil's Valley", "^You went to the (?P<Place>[a-zA-Z ']+). Don't lose your soul. Back in (?P<Time>[0-9]+) minutes$")
|
,(5000, ` + strconv.Itoa(objSubTypeMessageGoQuestAck) + `, "Go Quest Ack Devil's Valley", "^You went to the (?P<Place>[a-zA-Z ']+). Don't lose your soul. Back in (?P<Time>[0-9]+) minutes$")
|
||||||
,(5000, ` + strconv.Itoa(objSubTypeMessageGRolesReq) + `, "Guild roles Req", "^/g_roles$")
|
,(5000, ` + strconv.Itoa(objSubTypeMessageGRolesReq) + `, "Guild roles Req", "^/g_roles$")
|
||||||
,(5000, ` + strconv.Itoa(objSubTypeMessageGRolesAck) + `, "Guild roles Req", "^Roles:\\nBartender:\\n(?P<Bartender>.*)\\n\\n\\nCommander:\\n(?P<Commander>.*)\\n\\n\\nSquire:\\n(?P<Squire>.*)\\n\\n\\nTreasurer:\\n(?P<Treasurer>.*)$")
|
,(5000, ` + strconv.Itoa(objSubTypeMessageGRolesAck) + `, "Guild roles Req", "^Roles:\\nBartender:\\n(?P<Bartender>.*)\\n\\n\\nCommander:\\n(?P<Commander>.*)\\n\\n\\nSquire:\\n(?P<Squire>.*)\\n\\n\\nTreasurer:\\n(?P<Treasurer>.*)$")
|
||||||
|
,(5000, ` + strconv.Itoa(objSubTypeMessageGStockReq) + `, "Guild stock Req", "^/g_stock$")
|
||||||
|
,(5000, ` + strconv.Itoa(objSubTypeMessageGStockAck) + `, "Guild stock Ack", "^Grouped by:\\n` +
|
||||||
|
`/g_stock_res - resources\\n` +
|
||||||
|
`/g_stock_alch - alchemist herbs\\n` +
|
||||||
|
`/g_stock_misc - miscellaneous stuff\\n` +
|
||||||
|
`/g_stock_rec - items recipes\\n` +
|
||||||
|
`/g_stock_parts - items parts\\n` +
|
||||||
|
`/g_stock_other - everything else$")
|
||||||
|
,(5000, ` + strconv.Itoa(objSubTypeMessageGStockResReq) + `, "Guild stock resources Req", "^/g_stock_res$")
|
||||||
|
,(5000, ` + strconv.Itoa(objSubTypeMessageGStockAlchReq) + `, "Guild stock alchemy Req", "^/g_stock_alch$")
|
||||||
|
,(5000, ` + strconv.Itoa(objSubTypeMessageGStockMiscReq) + `, "Guild stock misc Req", "^/g_stock_misc$")
|
||||||
|
,(5000, ` + strconv.Itoa(objSubTypeMessageGStockRecReq) + `, "Guild stock recipes Req", "^/g_stock_rec$")
|
||||||
|
,(5000, ` + strconv.Itoa(objSubTypeMessageGStockPartReq) + `, "Guild stock parts Req", "^/g_stock_parts$")
|
||||||
|
,(5000, ` + strconv.Itoa(objSubTypeMessageGStockOthReq) + `, "Guild stock other Req", "^/g_stock_other$")
|
||||||
|
,(5000, ` + strconv.Itoa(objSubTypeMessageGStockAnyAck) + `, "Guild stock any Ack", "^Guild Warehouse:(?P<Stock>(\\n[0-9a-z]+ (.*) x ([0-9]+))+)$")
|
||||||
;`)
|
;`)
|
||||||
failOnError(err, "resetMsgParsingRules : populate table msg_rules")
|
failOnError(err, "resetMsgParsingRules : populate table msg_rules")
|
||||||
}
|
}
|
||||||
|
11
workers.go
11
workers.go
@ -87,29 +87,26 @@ func SQLIdentifyMsgWorker(id int, objIds <-chan int64) {
|
|||||||
log.Printf("SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : Can't find message type in rules(%d)\n%s\n", objId, m.Text)
|
log.Printf("SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : Can't find message type in rules(%d)\n%s\n", objId, m.Text)
|
||||||
} else {
|
} else {
|
||||||
r := msgParsingRules[i].re
|
r := msgParsingRules[i].re
|
||||||
|
err = setObjSubTypeId(objId, msgParsingRules[i].MsgTypeID)
|
||||||
|
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : setObjSubTypeId")
|
||||||
switch msgParsingRules[i].MsgTypeID {
|
switch msgParsingRules[i].MsgTypeID {
|
||||||
case objSubTypeMessageReportAck:
|
case objSubTypeMessageReportAck:
|
||||||
cwm, err := parseSubTypeMessageReportAck(m, r)
|
cwm, err := parseSubTypeMessageReportAck(m, r)
|
||||||
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : Parsing objSubTypeMessageReportAck.")
|
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : Parsing objSubTypeMessageReportAck.")
|
||||||
cwm.ObjID64 = objId
|
cwm.ObjID64 = objId
|
||||||
err = setObjSubTypeId(objId, objSubTypeMessageReportAck)
|
|
||||||
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : setObjSubTypeId(ReportAck)")
|
|
||||||
case objSubTypeMessageMiniWar:
|
case objSubTypeMessageMiniWar:
|
||||||
cwm, err := parseSubTypeMessageMiniWar(m, r)
|
cwm, err := parseSubTypeMessageMiniWar(m, r)
|
||||||
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : Parsing objSubTypeMessageMiniWar.")
|
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : Parsing objSubTypeMessageMiniWar.")
|
||||||
cwm.ObjID64 = objId
|
cwm.ObjID64 = objId
|
||||||
err = insertMsgMiniWar(cwm)
|
err = insertMsgMiniWar(cwm)
|
||||||
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : insertMsgMiniWar")
|
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : insertMsgMiniWar")
|
||||||
err = setObjSubTypeId(objId, objSubTypeMessageMiniWar)
|
|
||||||
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : setObjSubTypeId(MiniWar)")
|
|
||||||
case objSubTypeMessagePillageInc:
|
case objSubTypeMessagePillageInc:
|
||||||
cwm, err := parseSubTypeMessagePillageInc(m, r)
|
cwm, err := parseSubTypeMessagePillageInc(m, r)
|
||||||
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : Parsing objSubTypeMessagePillageInc.")
|
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : Parsing objSubTypeMessagePillageInc.")
|
||||||
cwm.ObjID64 = objId
|
cwm.ObjID64 = objId
|
||||||
err = insertMsgPillageInc(cwm)
|
err = insertMsgPillageInc(cwm)
|
||||||
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : insertMsgPillageInc")
|
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : insertMsgPillageInc")
|
||||||
err = setObjSubTypeId(objId, objSubTypeMessagePillageInc)
|
|
||||||
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : setObjSubTypeId(PillageInc)")
|
|
||||||
// only catch live pillages
|
// only catch live pillages
|
||||||
if m.Date.Add(3 * time.Minute).After(time.Now()) {
|
if m.Date.Add(3 * time.Minute).After(time.Now()) {
|
||||||
s := TGCommand{
|
s := TGCommand{
|
||||||
@ -126,8 +123,6 @@ func SQLIdentifyMsgWorker(id int, objIds <-chan int64) {
|
|||||||
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : createJob(JobPillage)")
|
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : createJob(JobPillage)")
|
||||||
}
|
}
|
||||||
case objSubTypeMessageGo:
|
case objSubTypeMessageGo:
|
||||||
err = setObjSubTypeId(objId, objSubTypeMessageGo)
|
|
||||||
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : setObjSubTypeId(Go)")
|
|
||||||
case objSubTypeMessageReportReq:
|
case objSubTypeMessageReportReq:
|
||||||
err = setObjSubTypeId(objId, objSubTypeMessageReportReq)
|
err = setObjSubTypeId(objId, objSubTypeMessageReportReq)
|
||||||
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : setObjSubTypeId(ReportReq)")
|
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : setObjSubTypeId(ReportReq)")
|
||||||
|
Loading…
Reference in New Issue
Block a user