33 lines
544 B
Go
33 lines
544 B
Go
|
package main
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
"server/core"
|
||
|
"server/game"
|
||
|
"server/packet"
|
||
|
"time"
|
||
|
)
|
||
|
|
||
|
func main() {
|
||
|
// Init server
|
||
|
server := core.New()
|
||
|
server.SetHandler(packet.Ping, game.Ping)
|
||
|
server.SetHandler(packet.Login, game.Login)
|
||
|
|
||
|
// Show statistics
|
||
|
last := time.Now()
|
||
|
|
||
|
go func() {
|
||
|
for {
|
||
|
if time.Now().After(last.Add(time.Second)) {
|
||
|
fmt.Printf("%d packets per second, %d clients\n", server.PacketCount(), game.Clients.Count())
|
||
|
last = time.Now()
|
||
|
server.ResetPacketCount()
|
||
|
}
|
||
|
}
|
||
|
}()
|
||
|
|
||
|
// Start listening
|
||
|
server.Run(4242)
|
||
|
}
|