Compare commits
5 Commits
aa03e87e00
...
b4f690ffd8
Author | SHA1 | Date |
---|---|---|
HimbeerserverDE | b4f690ffd8 | |
HimbeerserverDE | 2e9d4af86e | |
HimbeerserverDE | 132293e6b1 | |
HimbeerserverDE | 69e10e956b | |
HimbeerserverDE | 178c47e02f |
|
@ -1,6 +1,11 @@
|
|||
# multiserver
|
||||
Minetest reverse proxy supporting multiple servers and media multiplexing
|
||||
|
||||
## Obsolete
|
||||
This version has many bugs, is __NOT__ updated to work with Minetest 5.4.1
|
||||
and is unlikely to receive any future updates.
|
||||
It's untested and the code isn't very clean. __You should use [mt-multiserver-proxy](https://github.com/HimbeerserverDE/mt-multiserver-proxy) instead.__
|
||||
|
||||
## Credits
|
||||
This project was made possible by [anon55555's Minetest RUDP package](https://github.com/anon55555/mt/tree/master/rudp).
|
||||
|
||||
|
|
|
@ -157,10 +157,10 @@ func processPktCommand(src, dst *Conn, pkt *rudp.Pkt) bool {
|
|||
if ch == rpcCh {
|
||||
switch sig := ReadUint8(r); sig {
|
||||
case ModChSigJoinOk:
|
||||
src.SetUseRpc(true)
|
||||
src.SetUseRPC(true)
|
||||
case ModChSigSetState:
|
||||
if state == ModChStateRO {
|
||||
src.SetUseRpc(false)
|
||||
src.SetUseRPC(false)
|
||||
}
|
||||
}
|
||||
return true
|
||||
|
@ -168,7 +168,7 @@ func processPktCommand(src, dst *Conn, pkt *rudp.Pkt) bool {
|
|||
|
||||
return false
|
||||
case ToClientModChannelMSG:
|
||||
return processRpc(src, r)
|
||||
return processRPC(src, r)
|
||||
case ToClientBlockdata:
|
||||
data, drop := processBlockdata(dst, r)
|
||||
if drop {
|
||||
|
|
36
conn.go
36
conn.go
|
@ -42,9 +42,9 @@ type Conn struct {
|
|||
localPlayerCao uint16
|
||||
currentPlayerCao uint16
|
||||
|
||||
useRpcMu sync.RWMutex
|
||||
useRpc bool
|
||||
noClt bool
|
||||
useRPCMu sync.RWMutex
|
||||
useRPC bool
|
||||
noCLT bool
|
||||
modChs map[string]bool
|
||||
|
||||
huds map[uint32]bool
|
||||
|
@ -115,28 +115,28 @@ func (c *Conn) SetServer(s *Conn) {
|
|||
c.srv = s
|
||||
}
|
||||
|
||||
// UseRpc reports whether RPC messages can be sent to the Conn
|
||||
func (c *Conn) UseRpc() bool {
|
||||
c.useRpcMu.RLock()
|
||||
defer c.useRpcMu.RUnlock()
|
||||
// UseRPC reports whether RPC messages can be sent to the Conn
|
||||
func (c *Conn) UseRPC() bool {
|
||||
c.useRPCMu.RLock()
|
||||
defer c.useRPCMu.RUnlock()
|
||||
|
||||
return c.useRpc
|
||||
return c.useRPC
|
||||
}
|
||||
|
||||
// SetUseRpc sets the value returned by UseRpc
|
||||
func (c *Conn) SetUseRpc(useRpc bool) {
|
||||
c.useRpcMu.Lock()
|
||||
defer c.useRpcMu.Unlock()
|
||||
// SetUseRPC sets the value returned by UseRPC
|
||||
func (c *Conn) SetUseRPC(useRPC bool) {
|
||||
c.useRPCMu.Lock()
|
||||
defer c.useRPCMu.Unlock()
|
||||
|
||||
c.useRpc = useRpc
|
||||
c.useRPC = useRPC
|
||||
}
|
||||
|
||||
// NoClt reports whether the Conn is RPC-only
|
||||
func (c *Conn) NoClt() bool { return c.noClt }
|
||||
// NoCLT reports whether the Conn is RPC-only
|
||||
func (c *Conn) NoCLT() bool { return c.noCLT }
|
||||
|
||||
// MakeRpcOnly marks the Conn as RPC-only
|
||||
func (c *Conn) MakeRpcOnly() {
|
||||
c.noClt = true
|
||||
// MakeRPCOnly marks the Conn as RPC-only
|
||||
func (c *Conn) MakeRPCOnly() {
|
||||
c.noCLT = true
|
||||
}
|
||||
|
||||
// Inv returns the inventory of the Conn
|
||||
|
|
44
console.go
44
console.go
|
@ -10,6 +10,7 @@ import (
|
|||
)
|
||||
|
||||
var consoleInput []rune
|
||||
var cursorPos int
|
||||
|
||||
func draw(msgs []string) {
|
||||
prompt, ok := ConfKey("console_prompt").(string)
|
||||
|
@ -33,6 +34,11 @@ func draw(msgs []string) {
|
|||
}
|
||||
gocurses.Mvaddstr(row-i-1, 0, prompt+string(consoleInput))
|
||||
|
||||
if cursorPos >= len(consoleInput) {
|
||||
cursorPos = len(consoleInput)
|
||||
}
|
||||
gocurses.Mvaddstr(row-i-1, len(prompt)+len(string(consoleInput))-cursorPos, "")
|
||||
|
||||
gocurses.Refresh()
|
||||
}
|
||||
|
||||
|
@ -45,6 +51,8 @@ func autoComplete(all []string, current string) string {
|
|||
} else {
|
||||
return all[0]
|
||||
}
|
||||
} else if strings.HasPrefix(v, current) {
|
||||
return v
|
||||
}
|
||||
}
|
||||
} else if len(all) >= 1 {
|
||||
|
@ -99,12 +107,16 @@ func initCurses(l *Logger) {
|
|||
|
||||
for {
|
||||
var ch rune
|
||||
ch1 := gocurses.Stdscr.Getch() % 255
|
||||
if ch1 > 0x7F {
|
||||
ch2 := gocurses.Stdscr.Getch()
|
||||
ch1 := gocurses.Getch()
|
||||
if ch1%255 > 0x7F {
|
||||
ch2 := gocurses.Getch()
|
||||
ch, _ = utf8.DecodeRune([]byte{byte(ch1), byte(ch2)})
|
||||
} else {
|
||||
ch = rune(ch1)
|
||||
if ch1 != 3 && ch1 != 4 && ch1 != 5 && ch1 != 6 && ch1 != 339 && ch1 != 338 {
|
||||
ch = rune(ch1 % 255)
|
||||
} else {
|
||||
ch = rune(ch1)
|
||||
}
|
||||
}
|
||||
|
||||
switch ch {
|
||||
|
@ -113,6 +125,16 @@ func initCurses(l *Logger) {
|
|||
case 4:
|
||||
consoleInput = h.Prev(consoleInput)
|
||||
case 5:
|
||||
cursorPos += 1
|
||||
if cursorPos > len(consoleInput) {
|
||||
cursorPos = len(consoleInput)
|
||||
}
|
||||
case 6:
|
||||
cursorPos -= 1
|
||||
if cursorPos < 0 {
|
||||
cursorPos = 0
|
||||
}
|
||||
case 339:
|
||||
rows, _ := gocurses.Getmaxyx()
|
||||
start := len(l.lines) - rows + 1 - l.offset
|
||||
if start < 0 {
|
||||
|
@ -125,14 +147,18 @@ func initCurses(l *Logger) {
|
|||
l.offset = len(l.lines) - 1
|
||||
}
|
||||
}
|
||||
case 6:
|
||||
case 338:
|
||||
l.offset -= 1
|
||||
if l.offset < 0 {
|
||||
l.offset = 0
|
||||
}
|
||||
case '\b':
|
||||
if len(consoleInput) > 0 {
|
||||
consoleInput = consoleInput[:len(consoleInput)-1]
|
||||
if cursorPos > 0 {
|
||||
consoleInput = append(consoleInput[:len(consoleInput)-cursorPos-1], consoleInput[len(consoleInput)-cursorPos:]...)
|
||||
} else {
|
||||
consoleInput = consoleInput[:len(consoleInput)-1]
|
||||
}
|
||||
}
|
||||
case '\t':
|
||||
if strings.Count(string(consoleInput), " ") > 0 {
|
||||
|
@ -157,7 +183,11 @@ func initCurses(l *Logger) {
|
|||
|
||||
chatCommands[params[0]].function(nil, strings.Join(params[1:], " "))
|
||||
default:
|
||||
consoleInput = append(consoleInput, ch)
|
||||
if cursorPos > 0 {
|
||||
consoleInput = append(consoleInput[:len(consoleInput)-cursorPos], append([]rune{ch}, consoleInput[len(consoleInput)-cursorPos:]...)...)
|
||||
} else {
|
||||
consoleInput = append(consoleInput, ch)
|
||||
}
|
||||
}
|
||||
|
||||
rows, _ := gocurses.Getmaxyx()
|
||||
|
|
|
@ -4,7 +4,7 @@ import "sync"
|
|||
|
||||
const (
|
||||
MaxPlayerNameLength = 20
|
||||
PlayerNameChars = "[a-zA-Z0-9-_]"
|
||||
PlayerNameChars = "^[a-zA-Z0-9-_]*$"
|
||||
)
|
||||
|
||||
var onlinePlayers map[string]bool
|
||||
|
@ -35,7 +35,7 @@ func processJoin(c *Conn) {
|
|||
|
||||
rpcSrvMu.Lock()
|
||||
for srv := range rpcSrvs {
|
||||
srv.doRpc("->JOIN "+c.Username()+" "+cltSrv, "--")
|
||||
srv.doRPC("->JOIN "+c.Username()+" "+cltSrv, "--")
|
||||
}
|
||||
rpcSrvMu.Unlock()
|
||||
|
||||
|
@ -53,7 +53,7 @@ func processLeave(c *Conn) {
|
|||
|
||||
rpcSrvMu.Lock()
|
||||
for srv := range rpcSrvs {
|
||||
srv.doRpc("->LEAVE "+c.Username(), "--")
|
||||
srv.doRPC("->LEAVE "+c.Username(), "--")
|
||||
}
|
||||
rpcSrvMu.Unlock()
|
||||
|
||||
|
|
|
@ -30,7 +30,7 @@ func processRedirectDone(c *Conn, newsrv *string) {
|
|||
|
||||
rpcSrvMu.Lock()
|
||||
for srv := range rpcSrvs {
|
||||
srv.doRpc("->REDIRECTED "+c.Username()+" "+*newsrv+" "+successstr, "--")
|
||||
srv.doRPC("->REDIRECTED "+c.Username()+" "+*newsrv+" "+successstr, "--")
|
||||
}
|
||||
rpcSrvMu.Unlock()
|
||||
|
||||
|
|
70
rpc.go
70
rpc.go
|
@ -35,7 +35,7 @@ const (
|
|||
var rpcSrvMu sync.Mutex
|
||||
var rpcSrvs map[*Conn]struct{}
|
||||
|
||||
func (c *Conn) joinRpc() {
|
||||
func (c *Conn) joinRPC() {
|
||||
data := make([]byte, 4+len(rpcCh))
|
||||
data[0] = uint8(0x00)
|
||||
data[1] = uint8(ToServerModChannelJoin)
|
||||
|
@ -49,7 +49,7 @@ func (c *Conn) joinRpc() {
|
|||
<-ack
|
||||
}
|
||||
|
||||
func (c *Conn) leaveRpc() {
|
||||
func (c *Conn) leaveRPC() {
|
||||
data := make([]byte, 4+len(rpcCh))
|
||||
data[0] = uint8(0x00)
|
||||
data[1] = uint8(ToServerModChannelLeave)
|
||||
|
@ -63,7 +63,7 @@ func (c *Conn) leaveRpc() {
|
|||
<-ack
|
||||
}
|
||||
|
||||
func processRpc(c *Conn, r *bytes.Reader) bool {
|
||||
func processRPC(c *Conn, r *bytes.Reader) bool {
|
||||
ch := string(ReadBytes16(r))
|
||||
sender := string(ReadBytes16(r))
|
||||
msg := string(ReadBytes16(r))
|
||||
|
@ -84,16 +84,16 @@ func processRpc(c *Conn, r *bytes.Reader) bool {
|
|||
if !ok {
|
||||
return true
|
||||
}
|
||||
go c.doRpc("->DEFSRV "+defsrv, rq)
|
||||
go c.doRPC("->DEFSRV "+defsrv, rq)
|
||||
case "<-GETPEERCNT":
|
||||
cnt := strconv.Itoa(ConnCount())
|
||||
go c.doRpc("->PEERCNT "+cnt, rq)
|
||||
go c.doRPC("->PEERCNT "+cnt, rq)
|
||||
case "<-ISONLINE":
|
||||
online := "false"
|
||||
if IsOnline(strings.Join(strings.Split(msg, " ")[2:], " ")) {
|
||||
online = "true"
|
||||
}
|
||||
go c.doRpc("->ISONLINE "+online, rq)
|
||||
go c.doRPC("->ISONLINE "+online, rq)
|
||||
case "<-CHECKPRIVS":
|
||||
name := strings.Split(msg, " ")[2]
|
||||
privs := decodePrivs(strings.Join(strings.Split(msg, " ")[3:], " "))
|
||||
|
@ -104,7 +104,7 @@ func processRpc(c *Conn, r *bytes.Reader) bool {
|
|||
hasprivs = "true"
|
||||
}
|
||||
|
||||
go c.doRpc("->HASPRIVS "+hasprivs, rq)
|
||||
go c.doRPC("->HASPRIVS "+hasprivs, rq)
|
||||
case "<-GETPRIVS":
|
||||
name := strings.Split(msg, " ")[2]
|
||||
var r string
|
||||
|
@ -114,7 +114,7 @@ func processRpc(c *Conn, r *bytes.Reader) bool {
|
|||
r = strings.Replace(encodePrivs(privs), "|", ",", -1)
|
||||
}
|
||||
|
||||
go c.doRpc("->PRIVS "+r, rq)
|
||||
go c.doRPC("->PRIVS "+r, rq)
|
||||
case "<-SETPRIVS":
|
||||
name := strings.Split(msg, " ")[2]
|
||||
privs := decodePrivs(strings.Join(strings.Split(msg, " ")[3:], " "))
|
||||
|
@ -126,7 +126,7 @@ func processRpc(c *Conn, r *bytes.Reader) bool {
|
|||
if IsOnline(name) {
|
||||
srv = ConnByUsername(name).ServerName()
|
||||
}
|
||||
go c.doRpc("->SRV "+srv, rq)
|
||||
go c.doRPC("->SRV "+srv, rq)
|
||||
case "<-REDIRECT":
|
||||
name := strings.Split(msg, " ")[2]
|
||||
tosrv := strings.Split(msg, " ")[3]
|
||||
|
@ -139,7 +139,7 @@ func processRpc(c *Conn, r *bytes.Reader) bool {
|
|||
if IsOnline(name) {
|
||||
addr = ConnByUsername(name).Addr().String()
|
||||
}
|
||||
go c.doRpc("->ADDR "+addr, rq)
|
||||
go c.doRPC("->ADDR "+addr, rq)
|
||||
case "<-ISBANNED":
|
||||
target := strings.Split(msg, " ")[2]
|
||||
|
||||
|
@ -157,7 +157,7 @@ func processRpc(c *Conn, r *bytes.Reader) bool {
|
|||
r = "true"
|
||||
}
|
||||
|
||||
go c.doRpc("->ISBANNED "+r, rq)
|
||||
go c.doRPC("->ISBANNED "+r, rq)
|
||||
case "<-BAN":
|
||||
target := strings.Split(msg, " ")[2]
|
||||
err := Ban(target, "not known")
|
||||
|
@ -181,13 +181,13 @@ func processRpc(c *Conn, r *bytes.Reader) bool {
|
|||
}
|
||||
srvs = srvs[:len(srvs)-1]
|
||||
|
||||
go c.doRpc("->SRVS "+srvs, rq)
|
||||
go c.doRPC("->SRVS "+srvs, rq)
|
||||
case "<-MT2MT":
|
||||
msg := strings.Join(strings.Split(msg, " ")[2:], " ")
|
||||
rpcSrvMu.Lock()
|
||||
for srv := range rpcSrvs {
|
||||
if srv.Addr().String() != c.Addr().String() {
|
||||
go srv.doRpc("->MT2MT true "+msg, "--")
|
||||
go srv.doRPC("->MT2MT true "+msg, "--")
|
||||
}
|
||||
}
|
||||
rpcSrvMu.Unlock()
|
||||
|
@ -202,7 +202,7 @@ func processRpc(c *Conn, r *bytes.Reader) bool {
|
|||
rpcSrvMu.Lock()
|
||||
for srv := range rpcSrvs {
|
||||
if srv.Addr().String() == addr {
|
||||
go srv.doRpc("->MT2MT false "+msg, "--")
|
||||
go srv.doRPC("->MT2MT false "+msg, "--")
|
||||
}
|
||||
}
|
||||
rpcSrvMu.Unlock()
|
||||
|
@ -211,8 +211,8 @@ func processRpc(c *Conn, r *bytes.Reader) bool {
|
|||
return true
|
||||
}
|
||||
|
||||
func (c *Conn) doRpc(rpc, rq string) {
|
||||
if !c.UseRpc() {
|
||||
func (c *Conn) doRPC(rpc, rq string) {
|
||||
if !c.UseRPC() {
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -230,7 +230,7 @@ func (c *Conn) doRpc(rpc, rq string) {
|
|||
}
|
||||
}
|
||||
|
||||
func connectRpc() {
|
||||
func connectRPC() {
|
||||
log.Print("Establishing RPC connections")
|
||||
|
||||
servers := ConfKey("servers").(map[interface{}]interface{})
|
||||
|
@ -267,14 +267,14 @@ func connectRpc() {
|
|||
rpcSrvs[srv] = struct{}{}
|
||||
rpcSrvMu.Unlock()
|
||||
|
||||
go srv.joinRpc()
|
||||
go handleRpc(srv)
|
||||
go srv.joinRPC()
|
||||
go handleRPC(srv)
|
||||
}()
|
||||
}
|
||||
}
|
||||
|
||||
func handleRpc(srv *Conn) {
|
||||
srv.MakeRpcOnly()
|
||||
func handleRPC(srv *Conn) {
|
||||
srv.MakeRPCOnly()
|
||||
for {
|
||||
pkt, err := srv.Recv()
|
||||
if err != nil {
|
||||
|
@ -303,15 +303,15 @@ func handleRpc(srv *Conn) {
|
|||
|
||||
switch sig := ReadUint8(r); sig {
|
||||
case ModChSigJoinOk:
|
||||
srv.SetUseRpc(true)
|
||||
srv.SetUseRPC(true)
|
||||
case ModChSigSetState:
|
||||
if state == ModChStateRO {
|
||||
srv.SetUseRpc(false)
|
||||
srv.SetUseRPC(false)
|
||||
}
|
||||
}
|
||||
}
|
||||
case ToClientModChannelMSG:
|
||||
processRpc(srv, r)
|
||||
processRPC(srv, r)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -327,18 +327,18 @@ ServerLoop:
|
|||
continue
|
||||
}
|
||||
if c2.Server().Addr().String() == c.Addr().String() {
|
||||
if c.NoClt() {
|
||||
if c.NoCLT() {
|
||||
c.Close()
|
||||
} else {
|
||||
c.SetUseRpc(false)
|
||||
c.leaveRpc()
|
||||
c.SetUseRPC(false)
|
||||
c.leaveRPC()
|
||||
}
|
||||
|
||||
delete(rpcSrvs, c)
|
||||
|
||||
c3 := c2.Server()
|
||||
c3.SetUseRpc(true)
|
||||
c3.joinRpc()
|
||||
c3.SetUseRPC(true)
|
||||
c3.joinRPC()
|
||||
|
||||
rpcSrvs[c3] = struct{}{}
|
||||
|
||||
|
@ -358,10 +358,10 @@ ServerLoop:
|
|||
}
|
||||
}
|
||||
|
||||
go reconnectRpc(false)
|
||||
go reconnectRPC(false)
|
||||
}
|
||||
|
||||
func reconnectRpc(media bool) {
|
||||
func reconnectRPC(media bool) {
|
||||
servers := ConfKey("servers").(map[interface{}]interface{})
|
||||
ServerLoop:
|
||||
for server := range servers {
|
||||
|
@ -412,8 +412,8 @@ ServerLoop:
|
|||
rpcSrvs[srv] = struct{}{}
|
||||
rpcSrvMu.Unlock()
|
||||
|
||||
go srv.joinRpc()
|
||||
go handleRpc(srv)
|
||||
go srv.joinRPC()
|
||||
go handleRPC(srv)
|
||||
}()
|
||||
}
|
||||
}
|
||||
|
@ -428,7 +428,7 @@ func init() {
|
|||
reconnect = 600
|
||||
}
|
||||
|
||||
connectRpc()
|
||||
connectRPC()
|
||||
|
||||
go func() {
|
||||
reconnect := time.NewTicker(time.Duration(reconnect) * time.Second)
|
||||
|
@ -436,7 +436,7 @@ func init() {
|
|||
select {
|
||||
case <-reconnect.C:
|
||||
log.Print("Reintegrating servers")
|
||||
reconnectRpc(true)
|
||||
reconnectRPC(true)
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
|
|
@ -17,6 +17,8 @@ const (
|
|||
AnnounceDelete = "delete"
|
||||
)
|
||||
|
||||
const verString = "multiserver v1.13.3"
|
||||
|
||||
func Announce(action string) error {
|
||||
listsrv, ok := ConfKey("serverlist_url").(string)
|
||||
if !ok {
|
||||
|
@ -76,7 +78,7 @@ func Announce(action string) error {
|
|||
if action != AnnounceDelete {
|
||||
data["name"] = conf("serverlist_name")
|
||||
data["description"] = conf("serverlist_desc")
|
||||
data["version"] = "multiserver v1.13.2"
|
||||
data["version"] = verString
|
||||
data["proto_min"] = ProtoMin
|
||||
data["proto_max"] = ProtoLatest
|
||||
data["url"] = conf("serverlist_display_url")
|
||||
|
|
Loading…
Reference in New Issue