Beispiel #1
0
func (s *Server) loadCharacters(_message *LoginMessage, _iduser string) {
	var err error
	var res *mysql.MySQLResult
	var rows map[string]interface{}
	var queryString string = "SELECT idserver, name FROM characters WHERE idaccount='" + _iduser + "'"
	if res, err = g_db.Query(queryString); err != nil {
		_message.Status = LOGINSTATUS_FAILPROFILELOAD
		return
	}

	_message.Status = LOGINSTATUS_READY

	for {
		if rows = res.FetchMap(); rows == nil {
			break
		}

		charname := rows["name"].(string)
		idserver := rows["idserver"].(int)

		// Fetch server
		if serverinfo, ok := s.Store.servers.Get(idserver); ok {
			_message.Servers[charname] = serverinfo
		}
	}
}
Beispiel #2
0
func (s *Server) checkCredentials(_username, _password string) (ret bool, iduser string) {
	iduser = ""
	_username = g_db.Escape(_username)
	_password = g_db.Escape(_password)

	var err error
	var res *mysql.MySQLResult
	var rows map[string]interface{}
	var queryString string = "SELECT iduser, password, password_salt FROM users WHERE username='******'"
	if res, err = g_db.Query(queryString); err != nil {
		ret = false
		return
	}

	if rows = res.FetchMap(); rows == nil {
		ret = false
		return
	}

	iduser = fmt.Sprintf("%d", rows["iduser"].(int))
	password, _ := rows["password"].(string)
	salt, _ := rows["password_salt"].(string)
	_password = _password + salt

	ret = PasswordTest(_password, password)
	return
}
Beispiel #3
0
func main() {
	flag.Parse()

	if *dbhost == "" || *dbname == "" || *dbuser == "" {
		flag.Usage()
		os.Exit(1)
	}

	var err os.Error
	var res *mysql.MySQLResult
	var row map[string]interface{}
	var key string
	var value interface{}

	// Create new instance
	db := mysql.New()

	// Enable logging
	db.Logging = true

	// Connect to database
	if err = db.Connect(*dbhost, *dbuser, *dbpass, *dbname); err != nil {
		fmt.Fprintf(os.Stderr, "%v\n", err)
		os.Exit(1)
	}

	defer db.Close()

	// Use UTF8
	if _, err = db.Query("SET NAMES utf8"); err != nil {
		fmt.Fprintf(os.Stderr, "%v\n", err)
		return
	}

	// Query database
	if res, err = db.Query("SELECT * FROM test1 LIMIT 5"); err != nil {
		fmt.Fprintf(os.Stderr, "%v\n", err)
		return
	}

	for {
		if row = res.FetchMap(); row == nil {
			break
		}

		for key, value = range row {
			fmt.Printf("%s:%v\n", key, value)
		}
	}

}
func (store *ServerStore) load() (err error) {
	var res *mysql.MySQLResult
	var row map[string]interface{}

	var queryString string = "SELECT idserver, name, address FROM servers"
	if res, err = g_db.Query(queryString); err != nil {
		return err
	}

	for {
		if row = res.FetchMap(); row == nil {
			break
		}

		idserver := row["idserver"].(int)
		name := row["name"].(string)
		address := row["address"].(string)

		info := ServerInfo{Name: name, Ip: address, Online: 0, LastCheck: 0}
		store.servers.Set(idserver, info)
	}

	return nil
}
Beispiel #5
0
func main() {
	flag.Parse()

	if *dbhost == "" || *dbname == "" || *dbuser == "" {
		flag.Usage()
		os.Exit(1)
	}

	var err os.Error
	var res *mysql.MySQLResult
	var row map[string]interface{}
	var key string
	var value interface{}
	var stmt *mysql.MySQLStatement

	// Create new instance
	db := mysql.New()

	// Connect to database
	if err = db.Connect(*dbhost, *dbuser, *dbpass, *dbname); err != nil {
		fmt.Fprintf(os.Stderr, "%v\n", err)
		os.Exit(1)
	}

	// Ensure connection is closed on exit.
	defer db.Close()

	// Use UTF8
	if _, err = db.Query("SET NAMES utf8"); err != nil {
		fmt.Fprintf(os.Stderr, "%v\n", err)
		return
	}

	// Initialise statement
	if stmt, err = db.InitStmt(); err != nil {
		fmt.Fprintf(os.Stderr, "%v\n", err)
		return
	}

	// Prepare statement
	if err = stmt.Prepare("SELECT * FROM test1 WHERE id > ? AND id < ?"); err != nil {
		fmt.Fprintf(os.Stderr, "%v\n", err)
		return
	}

	// Bind params
	stmt.BindParams(1, 5)

	// Execute statement
	if res, err = stmt.Execute(); err != nil {
		fmt.Fprintf(os.Stderr, "%v\n", err)
		return
	}

	defer stmt.Close()

	// Display results
	for {
		if row = res.FetchMap(); row == nil {
			break
		}

		for key, value = range row {
			fmt.Printf("%s:%v\n", key, value)
		}
	}
}