mirror of
https://github.com/OpenDiablo2/OpenDiablo2
synced 2024-12-25 19:46:50 -05:00
1f2771e8bc
* Move engine initialization to d2app * adding debug print of error returned from `App.Run` * adding ClampInt utility function to d2math * cleaned up argument parsing in app.go, dedicated server no longer starts a renderer Co-authored-by: gravestench <dknuth0101@gmail.com>
66 lines
1.2 KiB
Go
66 lines
1.2 KiB
Go
package d2networking
|
|
|
|
import (
|
|
"os"
|
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2asset"
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2networking/d2server"
|
|
)
|
|
|
|
// ServerEventFlag represents a server event
|
|
type ServerEventFlag = int
|
|
|
|
// Server events
|
|
const (
|
|
ServerEventStop ServerEventFlag = iota
|
|
)
|
|
|
|
// ServerMinPlayers is the minimum number of players a server can have
|
|
const (
|
|
ServerMinPlayers = 1
|
|
ServerMaxPlayersDefault = 8
|
|
)
|
|
|
|
func hasFlag(value, flag int) bool {
|
|
return (value & flag) == flag
|
|
}
|
|
|
|
/*
|
|
StartDedicatedServer Checks whether or not we should start a server i.e the -listen parameter has been passed in, and if so launches a
|
|
server hosted to the network, in theory. (this is still WIP)
|
|
*/
|
|
func StartDedicatedServer(
|
|
manager *d2asset.AssetManager,
|
|
in chan int,
|
|
log chan string,
|
|
maxPlayers int,
|
|
) error {
|
|
server, err := d2server.NewGameServer(manager, true, maxPlayers)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
err = server.Start()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
for {
|
|
msgIn := <-in
|
|
if hasFlag(msgIn, ServerEventStop) {
|
|
log <- "Stopping server"
|
|
|
|
server.Stop()
|
|
log <- "Exiting..."
|
|
|
|
os.Exit(0)
|
|
}
|
|
}
|
|
}
|
|
|
|
// ServerOptions represents game server options
|
|
type ServerOptions struct {
|
|
Dedicated *bool
|
|
MaxPlayers *int
|
|
}
|