mirror of
https://github.com/Mezeporta/Erupe.git
synced 2025-12-12 23:14:36 +01:00
parse host as FQDN or IP
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"host_ip": "127.0.0.1",
|
"Host": "127.0.0.1",
|
||||||
"bin_path": "bin",
|
"BinPath": "bin",
|
||||||
"DisableSoftCrash": false,
|
"DisableSoftCrash": false,
|
||||||
"devmode": true,
|
"devmode": true,
|
||||||
"devmodeoptions": {
|
"devmodeoptions": {
|
||||||
|
|||||||
@@ -9,8 +9,8 @@ import (
|
|||||||
|
|
||||||
// Config holds the global server-wide config.
|
// Config holds the global server-wide config.
|
||||||
type Config struct {
|
type Config struct {
|
||||||
HostIP string `mapstructure:"host_ip"`
|
Host string `mapstructure:"Host"`
|
||||||
BinPath string `mapstructure:"bin_path"`
|
BinPath string `mapstructure:"BinPath"`
|
||||||
DisableSoftCrash bool // Disables the 'Press Return to exit' dialog allowing scripts to reboot the server automatically
|
DisableSoftCrash bool // Disables the 'Press Return to exit' dialog allowing scripts to reboot the server automatically
|
||||||
DevMode bool
|
DevMode bool
|
||||||
|
|
||||||
@@ -140,8 +140,8 @@ func LoadConfig() (*Config, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if c.HostIP == "" {
|
if c.Host == "" {
|
||||||
c.HostIP = getOutboundIP4().To4().String()
|
c.Host = getOutboundIP4().To4().String()
|
||||||
}
|
}
|
||||||
|
|
||||||
return c, nil
|
return c, nil
|
||||||
|
|||||||
14
main.go
14
main.go
@@ -3,6 +3,7 @@ package main
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
|
"net"
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
"syscall"
|
"syscall"
|
||||||
@@ -48,6 +49,19 @@ func main() {
|
|||||||
preventClose("Database password is blank")
|
preventClose("Database password is blank")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if net.ParseIP(erupeConfig.Host) == nil {
|
||||||
|
ips, _ := net.LookupIP(erupeConfig.Host)
|
||||||
|
for _, ip := range ips {
|
||||||
|
if ip != nil {
|
||||||
|
erupeConfig.Host = ip.String()
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if net.ParseIP(erupeConfig.Host) == nil {
|
||||||
|
preventClose("Invalid host address")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Discord bot
|
// Discord bot
|
||||||
var discordBot *discordbot.DiscordBot = nil
|
var discordBot *discordbot.DiscordBot = nil
|
||||||
|
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ func encodeServerInfo(config *config.Config, s *Server) []byte {
|
|||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
if si.IP == "" {
|
if si.IP == "" {
|
||||||
si.IP = config.HostIP
|
si.IP = config.Host
|
||||||
}
|
}
|
||||||
bf.WriteUint32(binary.LittleEndian.Uint32(net.ParseIP(si.IP).To4()))
|
bf.WriteUint32(binary.LittleEndian.Uint32(net.ParseIP(si.IP).To4()))
|
||||||
bf.WriteUint16(16 + uint16(serverIdx))
|
bf.WriteUint16(16 + uint16(serverIdx))
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ import (
|
|||||||
func serverList(s *Server, w http.ResponseWriter, r *http.Request) {
|
func serverList(s *Server, w http.ResponseWriter, r *http.Request) {
|
||||||
fmt.Fprintf(w,
|
fmt.Fprintf(w,
|
||||||
`<?xml version="1.0"?><server_groups><group idx='0' nam='Erupe' ip='%s' port="%d"/></server_groups>`,
|
`<?xml version="1.0"?><server_groups><group idx='0' nam='Erupe' ip='%s' port="%d"/></server_groups>`,
|
||||||
s.erupeConfig.HostIP,
|
s.erupeConfig.Host,
|
||||||
s.erupeConfig.Sign.Port,
|
s.erupeConfig.Sign.Port,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ func (s *Session) makeSignInResp(uid int) []byte {
|
|||||||
bf.WriteUint32(0xFFFFFFFF) // login_token_number
|
bf.WriteUint32(0xFFFFFFFF) // login_token_number
|
||||||
bf.WriteBytes([]byte(token)) // login_token
|
bf.WriteBytes([]byte(token)) // login_token
|
||||||
bf.WriteUint32(uint32(time.Now().Unix())) // current time
|
bf.WriteUint32(uint32(time.Now().Unix())) // current time
|
||||||
ps.Uint8(bf, fmt.Sprintf("%s:%d", s.server.erupeConfig.HostIP, s.server.erupeConfig.Entrance.Port), false)
|
ps.Uint8(bf, fmt.Sprintf("%s:%d", s.server.erupeConfig.Host, s.server.erupeConfig.Entrance.Port), false)
|
||||||
|
|
||||||
lastPlayed := uint32(0)
|
lastPlayed := uint32(0)
|
||||||
for _, char := range chars {
|
for _, char := range chars {
|
||||||
|
|||||||
Reference in New Issue
Block a user