Follow the leader with help from a server
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

main.go 1.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. // NGnius 2020-01-30
  2. package main // leadercraft-server
  3. import (
  4. "fmt"
  5. "net/http"
  6. )
  7. const (
  8. // Version the current version
  9. Version = "0.1"
  10. // Name the program name
  11. Name = "leadercraft-s"
  12. )
  13. var (
  14. server *http.Server
  15. handler http.Handler
  16. port string
  17. root string
  18. boards map[string]Board
  19. )
  20. func init() {
  21. initArgs()
  22. serverMux := http.NewServeMux()
  23. serverMux.HandleFunc("/load", boardHandler)
  24. handler = serverMux
  25. boards = make(map[string]Board)
  26. // test data
  27. boards["test1"] = Board{
  28. ID: 1,
  29. Entries: []Entry{
  30. Entry{ID: 1, Rank: 1, Score: 1000, PlayerName: "NGnius", PlayerURL: "/player/1"},
  31. Entry{ID: 2, Rank: 2, Score: 900, PlayerName: "Also NGnius", PlayerURL: "/player/2"},
  32. Entry{ID: 4, Rank: 3, Score: 400, PlayerName: ".xX||eDgY TeeNaGeR||Xx.", PlayerURL: "/player/3"},
  33. Entry{ID: 3, Rank: 4, Score: 350, PlayerName: "New username who dis?", PlayerURL: "/player/4"},
  34. Entry{ID: 7, Rank: 5, Score: 350, PlayerName: "Extremely Ridiculously Long Name Please don't break things", PlayerURL: "/player/5"},
  35. Entry{ID: 5, Rank: 6, Score: 250, PlayerName: "P|P3 |o|z", PlayerURL: "/player/3333"},
  36. Entry{ID: 6, Rank: 7, Score: 200, PlayerName: "Simon", PlayerURL: "/player/456"},
  37. Entry{ID: 24, Rank: 8, Score: 175, PlayerName: "Zettagram.com", PlayerURL: "/player/32"},
  38. Entry{ID: 42, Rank: 9, Score: 150, PlayerName: "The Doctor", PlayerURL: "/player/9283"},
  39. Entry{ID: 43, Rank: 10, Score: 140, PlayerName: "Marvin the Paranoid Android", PlayerURL: "/player/6"},
  40. Entry{ID: 8, Rank: 11, Score: 100, PlayerName: "IDK HOW", PlayerURL: "/player/666"},
  41. },
  42. }
  43. }
  44. func main() {
  45. parseArgs()
  46. server = &http.Server{
  47. Addr: ":" + port,
  48. Handler: handler,
  49. }
  50. fmt.Println("Starting on " + server.Addr)
  51. fmt.Println(server.ListenAndServe())
  52. }