2016-09-15 03:52:57 +05:30
|
|
|
|
package worker
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"elyby/minecraft-skinsystem/lib/data"
|
2016-12-03 04:27:55 +05:30
|
|
|
|
"elyby/minecraft-skinsystem/lib/services"
|
2016-09-15 03:52:57 +05:30
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func handleChangeUsername(model usernameChanged) (bool) {
|
|
|
|
|
if (model.OldUsername == "") {
|
2017-03-25 18:24:17 +05:30
|
|
|
|
services.Logger.IncCounter("worker.change_username.empty_old_username", 1)
|
2016-09-15 03:52:57 +05:30
|
|
|
|
record := data.SkinItem{
|
|
|
|
|
UserId: model.AccountId,
|
|
|
|
|
Username: model.NewUsername,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
record.Save()
|
|
|
|
|
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-22 22:02:00 +05:30
|
|
|
|
record, err := data.FindSkinByUsername(model.OldUsername)
|
2016-09-15 03:52:57 +05:30
|
|
|
|
if (err != nil) {
|
2017-03-25 18:24:17 +05:30
|
|
|
|
services.Logger.IncCounter("worker.change_username.username_not_found", 1)
|
2016-09-15 03:52:57 +05:30
|
|
|
|
// TODO: я не уверен, что это валидное поведение
|
|
|
|
|
// Суть в том, что здесь может возникнуть ошибка в том случае, если записи в базе нету
|
|
|
|
|
// а значит его нужно, как минимум, зарегистрировать
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
record.Username = model.NewUsername
|
|
|
|
|
record.Save()
|
|
|
|
|
|
2017-03-25 18:24:17 +05:30
|
|
|
|
services.Logger.IncCounter("worker.change_username.processed", 1)
|
2016-09-15 03:52:57 +05:30
|
|
|
|
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func handleSkinChanged(model skinChanged) (bool) {
|
2016-09-22 22:02:00 +05:30
|
|
|
|
record, err := data.FindSkinById(model.AccountId)
|
2016-09-15 03:52:57 +05:30
|
|
|
|
if (err != nil) {
|
2017-03-25 18:24:17 +05:30
|
|
|
|
services.Logger.IncCounter("worker.skin_changed.id_not_found", 1)
|
2016-09-15 03:52:57 +05:30
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
record.SkinId = model.SkinId
|
|
|
|
|
record.Hash = model.Hash
|
|
|
|
|
record.Is1_8 = model.Is1_8
|
|
|
|
|
record.IsSlim = model.IsSlim
|
|
|
|
|
record.Url = model.Url
|
|
|
|
|
|
|
|
|
|
record.Save()
|
|
|
|
|
|
2017-03-25 18:24:17 +05:30
|
|
|
|
services.Logger.IncCounter("worker.skin_changed.processed", 1)
|
2016-12-03 04:27:55 +05:30
|
|
|
|
|
2016-09-15 03:52:57 +05:30
|
|
|
|
return true
|
|
|
|
|
}
|