handler

package
v0.0.0-...-212ad1a Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2017 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const ProtocolVersion = 19

ProtocolVersion is the version of the Bancho protocol.

Variables

View Source
var AdminPassword string

AdminPassword is md5 hash of the password.

View Source
var Redis *redis.Client

Redis client that will be used to fetch and retrieve information

View Source
var Sessions = SessionCollection("")

Sessions is a slice containing all the sessions of the online users.

Functions

func AddChannel

func AddChannel(c Channel)

AddChannel initialises a channel, creating it on redis.

func ChannelExists

func ChannelExists(ch string) bool

ChannelExists checks whether a channel exists

func GenerateGUID

func GenerateGUID() string

GenerateGUID creates a random GUID.

func RandString

func RandString(n int) string

RandString generats a random string [0-9a-f]{n}

func RegisterHandler

func RegisterHandler(f interface{})

RegisterHandler registers a handler function.

Handler functions are simply in the signature func (p *packets.<something>).

func RegisterHandlers

func RegisterHandlers(handlers ...interface{})

RegisterHandlers simply executes RegisterHandler for many handlers.

func RemoveChannel

func RemoveChannel(name string)

RemoveChannel removes a channel.

func SaveSession

func SaveSession(sess Session)

SaveSession saves the session currently being handled.

func SendMessageToChannel

func SendMessageToChannel(m *packets.BanchoSendMessage)

SendMessageToChannel broadcasts a BanchoSendMessage to all the members of a channel.

func Start

func Start()

Start runs all initialisations required for this package.

Types

type Channel

type Channel struct {
	Name        string
	Description string
}

A Channel is a group of users that can chat together.

func GetChannels

func GetChannels() []Channel

GetChannels makes a copy of channels.

func (Channel) ToChannelAvailable

func (c Channel) ToChannelAvailable() *packets.BanchoChannelAvailable

ToChannelAvailable converts a Channel to a BanchoChannelAvailable

func (Channel) Users

func (c Channel) Users() uint16

Users gets the number of users in a channel.

type Session

type Session struct {
	Username   string
	UserID     int32
	Token      string
	Admin      bool
	LastSeen   time.Time
	State      packets.OsuSendUserState
	Spectating string
}

Session is an user's session on Bancho.

func Authenticate

func Authenticate(username string, password string) Session

Authenticate logs in into lan.

func GetSession

func GetSession(token string) (sess *Session)

GetSession retrieves a Session by knowing its token.

func LogoutTokenNotFound

func LogoutTokenNotFound() Session

LogoutTokenNotFound returns a Session for attempts to connect when there's no such user stored with such token.

func NewSession

func NewSession(username string, passMD5 string) Session

NewSession creates a new session.

func (Session) Dispose

func (s Session) Dispose()

Dispose finalizes the session removing all references to it (including Sessions) and setting s.disposed to true.

func (Session) Handle

func (s Session) Handle(pks []packets.Packet)

Handle takes a set of packets, handles them and then pushes the results

func (Session) In

func (s Session) In(stream string) bool

In checks whether a Session is in a stream.

func (Session) Permissions

func (s Session) Permissions() int32

Permissions converts the bool Admin to osu!'s permissions.

func (Session) Send

func (s Session) Send(ps ...packets.Packet)

Send sends a packets to the session.

func (Session) SendBytes

func (s Session) SendBytes(b []byte)

SendBytes sends bytes to the session to be send to the client. These are usually packetified packets.

func (Session) SendUsers

func (s Session) SendUsers()

SendUsers sends to this session all the online users.

func (Session) Subscribe

func (s Session) Subscribe(stream string) bool

Subscribe adds the Session to a stream in streams.

func (Session) SubscribeChannel

func (s Session) SubscribeChannel(ch string)

SubscribeChannel subscribes the user to a channel.

func (Session) ToHandleUserUpdate

func (s Session) ToHandleUserUpdate() *packets.BanchoHandleUserUpdate

ToHandleUserUpdate converts a session to a packets.BanchoHandleUserUpdate

func (Session) ToUserPresence

func (s Session) ToUserPresence() *packets.BanchoUserPresence

ToUserPresence converts a session to a packets.BanchoUserPresence

func (Session) Unsubscribe

func (s Session) Unsubscribe(stream string)

Unsubscribe removes the user from a stream.

func (Session) UnsubscribeChannel

func (s Session) UnsubscribeChannel(ch string)

UnsubscribeChannel unsubscribes the user from a channel.

type SessionCollection

type SessionCollection string

SessionCollection is simply a string, and it mainly indicates a redis list of tokens.

func (SessionCollection) Add

func (s SessionCollection) Add(sess Session)

Add adds a Session to the collection.

func (SessionCollection) AllTokens

func (s SessionCollection) AllTokens() []string

AllTokens retrieves all the tokens in the session collection.

func (SessionCollection) AllUserIDs

func (s SessionCollection) AllUserIDs() []int32

AllUserIDs fetches all the user IDs in the SessionCollection.

func (SessionCollection) Delete

func (s SessionCollection) Delete(sess Session)

Delete removes a Session from the collection.

func (SessionCollection) Destroy

func (s SessionCollection) Destroy()

Destroy removes from redis all references to this SessionCollection.

func (SessionCollection) Len

func (s SessionCollection) Len() int

Len returns the length of the SessionCollection's slice.

func (SessionCollection) Send

func (s SessionCollection) Send(ps ...packets.Packet)

Send sends packets to all members of the SessionCollection

func (SessionCollection) SendExcept

func (s SessionCollection) SendExcept(except []int32, ps ...packets.Packet)

SendExcept sends packets to all members of the SessionCollection, except for those with the ID specified.

func (SessionCollection) TokenFromID

func (s SessionCollection) TokenFromID(u int32) string

TokenFromID retrieves a Session by its user's ID.

func (SessionCollection) TokenFromUsername

func (s SessionCollection) TokenFromUsername(u string) string

TokenFromUsername retrieves a token of a session using its user's username.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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