Better minecraft pinger
This commit is contained in:
parent
084cc9d297
commit
d74b7e1415
|
@ -4,12 +4,13 @@ import (
|
|||
"net"
|
||||
"fmt"
|
||||
"time"
|
||||
"sync"
|
||||
)
|
||||
|
||||
const MAGIC = "\x00\xff\xff\x00\xfe\xfe\xfe\xfe\xfd\xfd\xfd\xfd\x12\x34\x56\x78"
|
||||
|
||||
func isAlive() bool {
|
||||
conn, err := net.Dial("udp", "h.woozle.org:30919")
|
||||
func isAlive(host string) bool {
|
||||
conn, err := net.Dial("udp", host)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
|
@ -28,24 +29,54 @@ func isAlive() bool {
|
|||
return true
|
||||
}
|
||||
|
||||
var wg sync.WaitGroup
|
||||
|
||||
func waitClose(c chan<- string) {
|
||||
wg.Wait()
|
||||
close(c)
|
||||
}
|
||||
|
||||
type HostEntry struct {
|
||||
host string
|
||||
owner string
|
||||
}
|
||||
|
||||
var hosts = []HostEntry{
|
||||
{"h.woozle.org:30919", "Ginnie"},
|
||||
{"h.woozle.org:44321", "Neale"},
|
||||
{"h.woozle.org:58000", "Amy"},
|
||||
}
|
||||
|
||||
func ping(results chan<- string, e HostEntry) {
|
||||
defer wg.Done()
|
||||
if isAlive(e.host) {
|
||||
results <- fmt.Sprintf("%s is playing at %s", e.owner, e.host)
|
||||
}
|
||||
}
|
||||
|
||||
func main() {
|
||||
results := make(chan string, 5)
|
||||
|
||||
for _, host := range hosts {
|
||||
wg.Add(1)
|
||||
go ping(results, host)
|
||||
}
|
||||
go waitClose(results)
|
||||
|
||||
fmt.Println("Content-type: text/html")
|
||||
fmt.Println("")
|
||||
fmt.Println("<!DOCTYPE html>")
|
||||
fmt.Println("<html>")
|
||||
fmt.Println("<head>")
|
||||
fmt.Println("<meta name=\"viewport\" content=\"width=device-width\">")
|
||||
fmt.Println("<style type=\"text/css\">#a{font-size: 500%; text-align: center; background: silver;}</style>")
|
||||
fmt.Println("<title>Is Ginnie playing Minecraft PE?</title></head>")
|
||||
fmt.Println("<style type=\"text/css\">#a{font-size: 120%; background: silver;}</style>")
|
||||
fmt.Println("<title>Minecraft PE ping</title></head>")
|
||||
fmt.Println("<body>")
|
||||
fmt.Println("<h1>Is Ginnie playing Minecraft PE?</h1>")
|
||||
fmt.Println("<p id=\"a\">")
|
||||
if isAlive() {
|
||||
fmt.Println("yes")
|
||||
} else {
|
||||
fmt.Println("no")
|
||||
fmt.Println("<h1>Are The Picketts playing Minecraft PE?</h1>")
|
||||
fmt.Println("<ul id=\"a\">")
|
||||
for msg := range results {
|
||||
fmt.Printf("<li>%s</li>\n", msg)
|
||||
}
|
||||
fmt.Println("</p>")
|
||||
fmt.Println("<p>Use the external server address <code>h.woozle.org</code>, port <code>30919</code> to join in.</p>")
|
||||
fmt.Println("</ul>")
|
||||
fmt.Println("</body></html>")
|
||||
}
|
||||
|
|
|
@ -4,7 +4,62 @@ All bets are for $1.
|
|||
Neale's prediction is the one stated.
|
||||
|
||||
Los Angeles Population (Blake)
|
||||
------------------------------
|
||||
==============================
|
||||
|
||||
On Feb 24, 2029, the metropolitan area commonly known as "Los Angeles"
|
||||
will have, at most recent measure, double-digit population decrease.
|
||||
|
||||
|
||||
Neale's Rationale
|
||||
-----------------
|
||||
|
||||
LA uses a ton of fresh water, brought in from all over the place.
|
||||
As droughts worsen, there will be increasingly large fights over water.
|
||||
Regardless of the political outcome,
|
||||
places closer to fresh water will tend to keep that water.
|
||||
LA is not close to fresh water.
|
||||
Las Vegas is going to have the same problem,
|
||||
but predicting the collapse of Las Vegas didn't seem as challenging.
|
||||
|
||||
------
|
||||
|
||||
This Page (Nemo Thorx)
|
||||
======================
|
||||
|
||||
|
||||
By 7 December, 2028, Neale will have updated this web page
|
||||
within the last 12 months.
|
||||
|
||||
|
||||
Neale's Rationale
|
||||
-----------------
|
||||
|
||||
I actually think Nemo's right,
|
||||
but this was such an amusing bet,
|
||||
I couldn't turn it down.
|
||||
|
||||
------
|
||||
|
||||
DC Power (Nobody yet!)
|
||||
======================
|
||||
|
||||
By 2030, over ⅓ of US residences currently being built will be wired with a DC power bus.
|
||||
|
||||
|
||||
Neale's Rationale
|
||||
-----------------
|
||||
|
||||
When I counted in 2014, we had only 5 electrical devices
|
||||
that used Alternating Current.
|
||||
Everything else ran off a "wall wart":
|
||||
an AC to DC transformer.
|
||||
|
||||
In addition to DC being tremendously safer
|
||||
(it won't stop Junior's heart when he sticks a fork in a USB port),
|
||||
it's also potentially more efficient to have a single transformer for the entire house.
|
||||
As more houses move to solar power with battery storage,
|
||||
the conversion from DC batteries to AC wall power,
|
||||
just to be converted again to DC,
|
||||
will be a tantalizing inefficiency to conquer.
|
||||
And with the introduction in 2015 of USB delivering up to 100W,
|
||||
there will even be a standard to use.
|
||||
|
|
Loading…
Reference in New Issue