// un résultat sans auteur (0) ni dateCdm (valeur 0) signifie qu'on n'a pas la réponse à la question func (store *MysqlStore) GetBlessure(db *mysql.Client, numMonstre uint, trollId int, amis []int) (blessure uint, auteurCDM int, dateCDM int64, err os.Error) { sql := "select blessure, author, date_adition from cdm where" sql += " num_monstre=" + strconv.Uitoa(numMonstre) + " and" sql += " author in (" + strconv.Itoa(trollId) for _, id := range amis { sql += "," + strconv.Itoa(id) } sql += ") order by date_adition desc limit 1" err = db.Query(sql) if err != nil { return } result, err := db.UseResult() if err != nil { return } row := result.FetchRow() db.FreeResult() if row == nil { return } blessure = fieldAsUint(row[0]) auteurCDM = fieldAsInt(row[1]) dateCDM = fieldAsInt64(row[2]) return }
// Count the number of chunks this player has func countChunks(db *mysql.Client, uid uint32) int { // Build a query for the given chunk coordinate as an argument query := fmt.Sprintf("SELECT * FROM chunkdata WHERE avatarID=%d", uid) err := db.Query(query) if err != nil { // Fatal error log.Println(err) return ConfigHandicapLimit } // Store the result result, err := db.StoreResult() if err != nil { log.Println(err) return ConfigHandicapLimit } numRows := result.RowCount() db.FreeResult() return int(numRows) }
func Authenticate(username string, passwordHash string, dbConn *mysql.Client) (reply *AuthenticationReply, err os.Error) { // Default return argument reply = NewAuthenticationReply(false, -1, "") // Escape input username = dbConn.Escape(username) password := dbConn.Escape(passwordHash) fmt.Printf("Authenticating user: '******'\n", username, password) err = dbConn.Query("SELECT * FROM users WHERE nick = '" + username + "' AND password = '******' limit 1") if err != nil { return } result, err := dbConn.UseResult() defer dbConn.FreeResult() if err != nil { return } // Fetch the row row := result.FetchMap() // If we found it the client got the username and password right if row != nil { id := row["id"].(int64) nick := row["nick"].(string) reply = NewAuthenticationReply(true, id, nick) return } else { err = os.NewError("Wrong username or password.") } return }
/** * estime les caractéristiques du monstre. * Si l'id est fourni (i.e. pas 0) et si on a des cdm concernant ce monstre précis, on n'utilise que celles là [EN COURS] */ func (store *MysqlStore) ComputeMonsterStats(db *mysql.Client, completeName string, monsterId uint) (be *BestiaryExtract, err os.Error) { // On utilise des max pour les champs de type chaine. C'est sans doute trop lourd (à moins que MySQL ne mette en place un index // spécifique). L'objectif réel est de récupérer la chaine la plus longue. if monsterId != 0 { sql := "select count(*), count(distinct num_monstre)," sql += namaxmin("niveau") + ", " sql += namaxmin("points_de_vie") + ", " sql += "max(capacite_text), " sql += namaxmin("des_attaque") + ", " sql += namaxmin("des_esquive") + ", " sql += namaxmin("des_degats") + ", " sql += namaxmin("des_regeneration") + ", " sql += namaxmin("armure") + ", " sql += namaxmin("vue") + ", " sql += namaxmin("maitrise_magique") + ", " sql += namaxmin("resistance_magique") + ", " sql += " max(famille_text), " sql += " max(nombre_attaques), " sql += " max(vitesse_deplacement_text), " sql += " max(voir_le_cache_boolean), " sql += " max(attaque_a_distance_boolean), " sql += namaxmin("duree_tour") + ", " sql += " max(portee_du_pouvoir_text)" sql += " from cdm where nom_complet=" + toMysqlString(completeName) sql += " and num_monstre=" + strconv.Uitoa(monsterId) //fmt.Println("SQL :\n" + sql + "\n") err = db.Query(sql) if err != nil { return nil, err } result, err := db.UseResult() if err != nil { return nil, err } row := result.FetchRow() db.FreeResult() if row != nil { be = rowToBestiaryExtract(completeName, row) if be.NbCdm > 0 { be.PreciseMonster = true return be, nil } } } sql := "select count(*), count(distinct num_monstre)," sql += namaxmin("niveau") + ", " // namaxmin car le niveau d'un monstre est fixe pour un nom complet donné sql += naminmax("points_de_vie") + ", " sql += "max(capacite_text), " sql += naminmax("des_attaque") + ", " sql += naminmax("des_esquive") + ", " sql += naminmax("des_degats") + ", " sql += naminmax("des_regeneration") + ", " sql += naminmax("armure") + ", " sql += naminmax("vue") + ", " sql += naminmax("maitrise_magique") + ", " sql += naminmax("resistance_magique") + ", " sql += " max(famille_text), " sql += " max(nombre_attaques), " sql += " max(vitesse_deplacement_text), " sql += " max(voir_le_cache_boolean), " sql += " max(attaque_a_distance_boolean), " sql += naminmax("duree_tour") + ", " sql += " max(portee_du_pouvoir_text)" sql += " from cdm where nom_complet=" + toMysqlString(completeName) //fmt.Println(sql) err = db.Query(sql) if err != nil { return nil, err } result, err := db.UseResult() if err != nil { return nil, err } row := result.FetchRow() db.FreeResult() if row == nil { //fmt.Println("ComputeMonsterStats : no result") return nil, nil } be = rowToBestiaryExtract(completeName, row) be.PreciseMonster = false return be, nil }
// renvoie les actions, en incluant les résumés de CDM func (store *MysqlStore) GetActions(db *mysql.Client, typeCible string, numCible int, trollId int, amis []int) (actions []*Action, err error) { strnum := strconv.Itoa(numCible) //> d'abord les vraies "actions" sql := "select date_action, type_action, auteur, succes, degats, pv, esquive from action where type_cible='" + typeCible + "' and num_cible=" + strnum sql += " and auteur in (" + strconv.Itoa(trollId) for _, id := range amis { sql += "," + strconv.Itoa(id) } sql += ")" fmt.Println(sql) err = db.Query(sql) if err != nil { return } result, err := db.UseResult() if err != nil { return } actions = make([]*Action, 0, 10) for { row := result.FetchRow() fmt.Printf("row : %v\n", row) if row == nil { break } a := new(Action) a.Date = fieldAsInt64(row[0]) a.Type = fieldAsString(row[1]) a.Auteur = fieldAsInt(row[2]) a.TypeCible = typeCible a.NumCible = numCible if fieldAsString(row[3]) == "oui" { a.Succes = true } else { a.Succes = false } a.Degats = fieldAsInt(row[4]) a.PV = fieldAsInt(row[5]) a.Esquive = fieldAsInt(row[6]) actions = append(actions, a) } db.FreeResult() //> ensuite les cdm if typeCible != "monstre" { return } sql = "select date_adition, author , blessure from cdm where num_monstre=" + strnum sql += " and author in (" + strconv.Itoa(trollId) for _, id := range amis { sql += "," + strconv.Itoa(id) } sql += ")" fmt.Println(sql) err = db.Query(sql) if err != nil { return } result, err = db.UseResult() if err != nil { return } for { row := result.FetchRow() fmt.Printf("row : %v\n", row) if row == nil { break } a := new(Action) a.Date = fieldAsInt64(row[0]) a.Auteur = fieldAsInt(row[1]) a.PourcentageBlessure = fieldAsInt(row[2]) a.Type = "CDM" a.TypeCible = typeCible a.NumCible = numCible a.Succes = true actions = append(actions, a) } db.FreeResult() return }