gameserver

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Aug 23, 2023 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewMafiaServer

func NewMafiaServer[T any](s Server[T], driverName string, dbUrl string, initDb bool) mafiaServer[T]

NewMafiaServer creates new instance of server for mafia game. s is a server that will be used internally. driverName and dbUrl specify connection to database/sql.DB. initDb specifies if "CREATE TABLE IF NOT EXISTS" should be called for tables needed internally.

func Run

func Run[T any](ms mafiaServer[T])

Run starts listening mafiaServer

Types

type Server

type Server[T any] interface {
	GetUpdatesChan() <-chan T       // channel of updates from user
	UpdateToMessage(T) *UserMessage // transforms update to standard format
	SendMessage(ServerMessage)      // sends message to user
	GetDefaultNick(int64) string    // gets default user's nickname
}

Server represents any endpoint user can chat with. Type T is an update from user format which is suitable for sending in chan

type ServerMessage

type ServerMessage struct {
	User    int64    // receiver of message
	Text    string   // text
	Options []string // options for user; if Options isn't nil and have 0 len, means previous options should be hidden
}

ServerMessage represents message sent from server to user

type UserMessage

type UserMessage struct {
	User    int64  // user sent
	Text    string // text
	Command bool   // if message is a command
}

UserMessage represents message sent from user to server

Jump to

Keyboard shortcuts

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