diff --git a/src/game.rs b/src/game.rs index 73f9a9d..811f0e0 100644 --- a/src/game.rs +++ b/src/game.rs @@ -1,4 +1,4 @@ -use crate::{page::new, Backend}; +use crate::{page::new, random_names::get_name_by_uuid, Backend}; use axum::{ extract::{Path, State}, response::{IntoResponse, Redirect, Response}, @@ -41,7 +41,9 @@ async fn index(State(backend): State>, cookies: CookieJar) -> Respo (rank.rank) } @if rank.uuid == client.uuid { (PreEscaped("")) } - @if let Some(name) = rank.name { (name) } @else { "Anonymer Bär" } + @if let Some(name) = rank.name { (name) } @else { + "Anonymous " + (get_name_by_uuid(&rank.uuid))} @if rank.uuid == client.uuid { (PreEscaped("")) } } span { diff --git a/src/main.rs b/src/main.rs index 2854467..2e7f7d5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -10,6 +10,7 @@ mod game; mod index; pub(crate) mod model; mod page; +pub(crate) mod random_names; pub(crate) enum Backend { Sqlite(SqlitePool), diff --git a/src/model/highscore.rs b/src/model/highscore.rs index 9749674..d980dec 100644 --- a/src/model/highscore.rs +++ b/src/model/highscore.rs @@ -9,12 +9,11 @@ pub(crate) struct Rank { impl Backend { pub(crate) async fn highscore(&self) -> Vec { - // TODO: proper rank calculation match self { Backend::Sqlite(db) => sqlx::query_as!( Rank, "SELECT - 1 as rank, + RANK() OVER (ORDER BY COUNT(s.client_uuid) DESC) as rank, c.name, c.uuid, COUNT(s.client_uuid) as amount diff --git a/src/random_names.rs b/src/random_names.rs new file mode 100644 index 0000000..957767d --- /dev/null +++ b/src/random_names.rs @@ -0,0 +1,480 @@ +use std::hash::{DefaultHasher, Hash, Hasher}; + +const NAMES: [&str; 467] = [ + "Canidae", + "Felidae", + "Cat", + "Cattle", + "Dog", + "Donkey", + "Goat", + "Guineapig", + "Horse", + "Pig", + "Rabbit", + "Fancyrat", + "Varieties", + "Laboratory", + "Strains", + "Sheep", + "Breeds", + "Water", + "Buffalo", + "Chicken", + "Duckbreeds", + "Goose", + "Pigeonbreeds", + "Turkeybreeds", + "Aardvark", + "Aardwolf", + "African", + "Elephant", + "Leopard", + "Albatross", + "Alligator", + "Alpaca", + "Robin", + "Amphibian", + "List", + "Anaconda", + "Angelfish", + "Anglerfish", + "Ant", + "Anteater", + "Antelope", + "Antlion", + "Ape", + "Aphid", + "Arabian", + "Arctic", + "Fox", + "Wolf", + "Armadillo", + "Arrow", + "Crab", + "Asp", + "Baboon", + "Badger", + "Baldeagle", + "Bandicoot", + "Barnacle", + "Barracuda", + "Basilisk", + "Bass", + "Bat", + "Beakedwhale", + "Bear", + "Beaver", + "Bedbug", + "Bee", + "Beetle", + "Bird", + "Bison", + "Blackbird", + "Black", + "Panther", + "Widow", + "Spider", + "Blue", + "Bird", + "Jay", + "Whale", + "Boa", + "Boar", + "Bobcat", + "Bobolink", + "Bonobo", + "Booby", + "Box", + "Jellyfish", + "Bovid", + "Buffalo", + "Bug", + "Butterfly", + "Buzzard", + "Camel", + "Canid", + "Cape", + "Capybara", + "Cardinal", + "Caribou", + "Carp", + "Catshark", + "Caterpillar", + "Catfish", + "Centipede", + "Cephalopod", + "Chameleon", + "Cheetah", + "Chickadee", + "Chimpanzee", + "Chinchilla", + "Chipmunk", + "Clam", + "Clownfish", + "Cobra", + "Cockroach", + "Cod", + "Condor", + "Constrictor", + "Coral", + "Cougar", + "Cow", + "Coyote", + "Crab", + "Crane", + "Fly", + "Crawdad", + "Crayfish", + "Cricket", + "Crocodile", + "Crow", + "Cuckoo", + "Cicada", + "Damselfly", + "Deer", + "Dingo", + "Dinosaur", + "Dolphin", + "Dormouse", + "Dove", + "Dragonfly", + "Dragon", + "Duck", + "Dung", + "Beetle", + "Eagle", + "Earthworm", + "Earwig", + "Echidna", + "Eel", + "Egret", + "Elephant", + "Seal", + "Elk", + "Emu", + "English", + "Pointer", + "Ermine", + "Falcon", + "Ferret", + "Finch", + "Firefly", + "Fish", + "Flamingo", + "Flea", + "Fly", + "Flyingfish", + "Fowl", + "Frog", + "Fruit", + "Bat", + "Gamefowl", + "Galliform", + "Gazelle", + "Gecko", + "Gerbil", + "Giant", + "Panda", + "Squid", + "Gibbon", + "Gila", + "Monster", + "Giraffe", + "Goldfish", + "Gopher", + "Gorilla", + "Grasshopper", + "Great", + "Blue", + "Heron", + "White", + "Shark", + "Grizzly", + "Bear", + "Ground", + "Sloth", + "Grouse", + "Guan", + "Guanaco", + "Guineafowl", + "Guinea", + "Pig", + "Gull", + "Guppy", + "Haddock", + "Halibut", + "Hammerhead", + "Hamster", + "Hare", + "Harrier", + "Hawk", + "Hedgehog", + "Hermit", + "Heron", + "Herring", + "Hippopotamus", + "Hookworm", + "Hornet", + "Hoverfly", + "Hummingbird", + "Humpback", + "Hyena", + "Iguana", + "Impala", + "Irukandji", + "Jackal", + "Jaguar", + "Jay", + "Jellyfish", + "Junglefowl", + "Kangaroo", + "Mouse", + "Rat", + "Kingfisher", + "Kite", + "Kiwi", + "Koala", + "Koi", + "Komodo", + "Dragon", + "Krill", + "Ladybug", + "Lamprey", + "Landfowl", + "Land", + "Snail", + "Lark", + "Leech", + "Lemming", + "Lemur", + "Leopard", + "Leopon", + "Limpet", + "Lion", + "Lizard", + "Llama", + "Lobster", + "Locust", + "Loon", + "Louse", + "Lungfish", + "Lynx", + "Macaw", + "Mackerel", + "Magpie", + "Mammal", + "Manatee", + "Mandrill", + "Manta", + "Ray", + "Marlin", + "Marmoset", + "Marmot", + "Marsupial", + "Marten", + "Mastodon", + "Meadowlark", + "Meerkat", + "Mink", + "Minnow", + "Mite", + "Mockingbird", + "Mole", + "Mollusk", + "Mongoose", + "Monitor", + "Lizard", + "Monkey", + "Moose", + "Mosquito", + "Moth", + "Mountain", + "Goat", + "Mouse", + "Mule", + "Muskox", + "Narwhal", + "Newt", + "World", + "Quail", + "Nightingale", + "Ocelot", + "Octopus", + "Old", + "Opossum", + "Orangutan", + "Orca", + "Ostrich", + "Otter", + "Owl", + "Ox", + "Panda", + "Panther", + "Panthera", + "Hybrid", + "Parakeet", + "Parrot", + "Parrotfish", + "Partridge", + "Peacock", + "Peafowl", + "Pelican", + "Penguin", + "Perch", + "Peregrine", + "Falcon", + "Pheasant", + "Pigeon", + "Pike", + "Pilot", + "Pinniped", + "Piranha", + "Planarian", + "Platypus", + "Polar", + "Pony", + "Porcupine", + "Porpoise", + "Portuguese", + "Possum", + "Prairie", + "Dog", + "Prawn", + "Praying", + "Mantis", + "Primate", + "Ptarmigan", + "Puffin", + "Puma", + "Python", + "Quail", + "Quelea", + "Quokka", + "Raccoon", + "Rainbow", + "Trout", + "Rat", + "Rattlesnake", + "Raven", + "Reindeer", + "Reptile", + "Rhinoceros", + "Right", + "Roadrunner", + "Rodent", + "Rook", + "Rooster", + "Roundworm", + "Cat", + "Sailfish", + "Salamander", + "Salmon", + "Sawfish", + "Scale", + "Insect", + "Scallop", + "Scorpion", + "Seahorse", + "Sea", + "Lion", + "Slug", + "Shark", + "Shrew", + "Shrimp", + "Silkworm", + "Silverfish", + "Skink", + "Skunk", + "Sloth", + "Slug", + "Smelt", + "Snail", + "Snake", + "Snipe", + "Snow", + "Sockeye", + "Salmon", + "Sole", + "Sparrow", + "Spider", + "Monkey", + "Spoonbill", + "Squid", + "Squirrel", + "Starfish", + "Mole", + "Steelhead", + "Stingray", + "Stoat", + "Stork", + "Sturgeon", + "Sugar", + "Glider", + "Swallow", + "Swan", + "Swift", + "Swordfish", + "Swordtail", + "Tahr", + "Takin", + "Tapir", + "Tarantula", + "Tarsier", + "Tasmanian", + "Devil", + "Termite", + "Tern", + "Thrush", + "Tick", + "Tiger", + "Tiglon", + "Toad", + "Tortoise", + "Toucan", + "Trapdoor", + "Tree", + "Frog", + "Trout", + "Tuna", + "Turkey", + "Turtle", + "Tyrannosaurus", + "Urial", + "Vampire", + "Vicuna", + "Viper", + "Vole", + "Vulture", + "Wallaby", + "Walrus", + "Wasp", + "Warbler", + "Weasel", + "Whale", + "Whippet", + "Whitefish", + "Whooping", + "Crane", + "Wildcat", + "Wildebeest", + "Wildfowl", + "Wolverine", + "Wombat", + "Woodpecker", + "Worm", + "Wren", + "Xerinae", + "Fish", + "Yak", + "Yellow", +]; + +pub(crate) fn get_name_by_uuid(uuid: &str) -> &str { + let mut hasher = DefaultHasher::new(); + uuid.hash(&mut hasher); + let hash = hasher.finish(); + + let index = (hash % NAMES.len() as u64) as usize; + NAMES[index] +}