server

package
v0.0.0-...-e716ecf Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 9, 2018 License: GPL-2.0, GPL-3.0 Imports: 13 Imported by: 5

Documentation

Overview

*

  • SpecterGO Copyright (C) 2018 SpecterTeam *
  • This program is free software: you can redistribute it and/or modify
  • it under the terms of the GNU General Public License as published by
  • the Free Software Foundation, either version 3 of the License, or
  • (at your option) any later version. *
  • This program is distributed in the hope that it will be useful,
  • but WITHOUT ANY WARRANTY; without even the implied warranty of
  • MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  • GNU General Public License for more details. *
  • You should have received a copy of the GNU General Public License
  • along with this program. If not, see <http://www.gnu.org/licenses/>.

*

  • SpecterGO Copyright (C) 2018 SpecterTeam *
  • This program is free software: you can redistribute it and/or modify
  • it under the terms of the GNU General Public License as published by
  • the Free Software Foundation, either version 3 of the License, or
  • (at your option) any later version. *
  • This program is distributed in the hope that it will be useful,
  • but WITHOUT ANY WARRANTY; without even the implied warranty of
  • MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  • GNU General Public License for more details. *
  • You should have received a copy of the GNU General Public License
  • along with this program. If not, see <http://www.gnu.org/licenses/>.

*

  • SpecterGO Copyright (C) 2018 SpecterTeam *
  • This program is free software: you can redistribute it and/or modify
  • it under the terms of the GNU General Public License as published by
  • the Free Software Foundation, either version 3 of the License, or
  • (at your option) any later version. *
  • This program is distributed in the hope that it will be useful,
  • but WITHOUT ANY WARRANTY; without even the implied warranty of
  • MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  • GNU General Public License for more details. *
  • You should have received a copy of the GNU General Public License
  • along with this program. If not, see <http://www.gnu.org/licenses/>.

*

  • SpecterGO Copyright (C) 2018 SpecterTeam *
  • This program is free software: you can redistribute it and/or modify
  • it under the terms of the GNU General Public License as published by
  • the Free Software Foundation, either version 3 of the License, or
  • (at your option) any later version. *
  • This program is distributed in the hope that it will be useful,
  • but WITHOUT ANY WARRANTY; without even the implied warranty of
  • MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  • GNU General Public License for more details. *
  • You should have received a copy of the GNU General Public License
  • along with this program. If not, see <http://www.gnu.org/licenses/>.

Index

Constants

View Source
const (
	PermanentExpire = -1
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Expire

type Expire struct {
	Time     time.Time
	Duration time.Duration
}

func (*Expire) IsPermanent

func (exp *Expire) IsPermanent() bool

type Handler

type Handler interface {

	// StartServer is called on the server is started
	StartServer()

	// CloseServer is called on the server is closed
	CloseServer()

	// HandlePing is called on a ping packet is received
	HandlePing(addr net.Addr)

	// OpenPreConn is called before a new session is created
	OpenPreConn(addr net.Addr)

	// OpenConn is called on a new session is created
	OpenConn(uid int64, addr net.Addr)

	// ClosePreConn is called before a session is closed
	ClosePreConn(uid int64)

	// CloseConn is called on a session is closed
	CloseConn(uid int64)

	// HandleSendPacket handles a packet sent from the server to a client
	HandleSendPacket(addr net.Addr, pk raknet.Packet)

	// HandleRawPacket handles a raw packet no processed in Raknet server
	HandleRawPacket(addr net.Addr, pk raknet.Packet)

	// HandlePacket handles a message packet
	HandlePacket(uid int64, pk raknet.Packet)

	// HandleUnknownPacket handles a unknown packet
	HandleUnknownPacket(uid int64, pk raknet.Packet)
}

Handler handles packets, connections and more from Raknet server

type Handlers

type Handlers []Handler

type Server

type Server struct {
	Logger         *utils.Logger
	Handlers       Handlers
	MaxConnections int
	MTU            int
	Identifier     identifier.Minecraft

	UUID uuid.UUID

	// BroadcastingEnabled broadcast the server for the outside
	// if it enabled, the server send UnconnectedPong when received UnconnectPing.
	BroadcastingEnabled bool
	// contains filtered or unexported fields
}

func (*Server) Cancel

func (s *Server) Cancel() context.CancelFunc

func (*Server) CloseSession

func (ser *Server) CloseSession(addr *net.UDPAddr, reason string) error

func (*Server) CloseSessionGUID

func (ser *Server) CloseSessionGUID(guid int64, reason string) error

func (*Server) Count

func (ser *Server) Count() int

func (*Server) GetSession

func (ser *Server) GetSession(addr *net.UDPAddr) (*Session, bool)

func (*Server) GetSessionGUID

func (ser *Server) GetSessionGUID(guid int64) (*Session, bool)

func (*Server) HasBlockedAddress

func (ser *Server) HasBlockedAddress(ip net.IP) bool

func (*Server) HasSession

func (ser *Server) HasSession(addr net.Addr) bool

func (*Server) HasSessionGUID

func (ser *Server) HasSessionGUID(guid int64) bool

func (*Server) IsClosed

func (ser *Server) IsClosed() bool

func (*Server) IsRunning

func (ser *Server) IsRunning() bool

func (*Server) ListenAndServe

func (ser *Server) ListenAndServe(ctx context.Context, addr *net.UDPAddr) error

func (*Server) RangeSessions

func (ser *Server) RangeSessions(f func(key string, value *Session) bool) error

RangeSessions processes for the sessions instead of "for range". if f returns false, stops the loop.

key is string(returned net.Addr.String()), value is *Session returns errors if key and value is invalid.

func (*Server) RemoveBlockedAddress

func (ser *Server) RemoveBlockedAddress(ip net.IP)

func (*Server) SendPacket

func (ser *Server) SendPacket(addr *net.UDPAddr, pk raknet.Packet)

func (*Server) SendRawPacket

func (ser *Server) SendRawPacket(addr *net.UDPAddr, b []byte)

func (*Server) Serve

func (ser *Server) Serve(ctx context.Context, l *net.UDPConn) error

Serve serves a Raknet server

func (*Server) SetBlockedAddress

func (ser *Server) SetBlockedAddress(ip net.IP, exp Expire)

func (*Server) SetCancel

func (s *Server) SetCancel(cancel context.CancelFunc)

func (*Server) Shutdown

func (s *Server) Shutdown()

func (*Server) Start

func (ser *Server) Start(ip string, port int)

func (*Server) State

func (ser *Server) State() ServerState

type ServerState

type ServerState int

ServerState is a server state

const (
	StateNew ServerState = iota
	StateRunning
	StateClosed
)

type Session

type Session struct {
	Addr              *net.UDPAddr
	Conn              *net.UDPConn
	Logger            *utils.Logger
	Server            *Server
	GUID              int64
	MTU               int
	LatencyEnabled    bool
	LatencyIdentifier int64

	State SessionState
	// contains filtered or unexported fields
}

Session

func (*Session) Close

func (session *Session) Close() error

Close closes the session

func (*Session) SendPacket

func (session *Session) SendPacket(pk raknet.Packet, rea raknet.Reliability, channel int) error

func (*Session) SendRawPacket

func (session *Session) SendRawPacket(pk raknet.Packet)

func (*Session) SystemAddress

func (session *Session) SystemAddress() *raknet.SystemAddress

type SessionState

type SessionState int
const (
	StateDisconected SessionState = iota
	StateHandshaking
	StateConnected
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL