Fix RPC func casing

master
HimbeerserverDE 2 years ago
parent 178c47e02f
commit 69e10e956b
No known key found for this signature in database
GPG Key ID: 1A651504791E6A8B
  1. 6
      command.go
  2. 36
      conn.go
  3. 4
      player.go
  4. 2
      redirect.go
  5. 70
      rpc.go
  6. 4
      serverlist.go

@ -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 {

@ -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

@ -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()

@ -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…
Cancel
Save