econetwork

package
v0.0.0-...-ef7076c Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2021 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrAccountNotExists   = errors.New("account doesnt exist")   // for when trying to login or get account
	ErrAccountExists      = errors.New("account already exists") // trying to register an already existing username/account
	ErrMissingCredentials = errors.New("neither username or password were provided")
)
View Source
var (
	ItemElectron = Item{0.01, 20, "electron", 0}
)

Functions

func SessionID

func SessionID() string

Generates a session id for a user

Types

type Account

type Account struct {
	Username string `db:"username"`
	Node     *Node  // pointer since a person won't have a node immediately on register
	Op       bool   `db:"op"`
}

A client's account

type AuthPayload

type AuthPayload struct {
	Password string
	Username string
}

For register and login methods

type Client

type Client struct {
	Account   *Account
	Conn      *websocket.Conn
	SessionID string
}

func (*Client) SendError

func (c *Client) SendError(method string, data interface{})

func (*Client) SendMalformed

func (c *Client) SendMalformed(method string)

func (*Client) SendSuccess

func (c *Client) SendSuccess(method string, data interface{})

type ClientResponse

type ClientResponse struct {
	SessionID string       `json:"sessionID"`
	Method    string       `json:"method"`
	Data      *interface{} `json:"data,omitempty"`
}

Fields we should expect from the client

type Econetwork

type Econetwork struct {
	Address string
	// contains filtered or unexported fields
}

func New

func New() (*Econetwork, error)

func (*Econetwork) Start

func (e *Econetwork) Start()

func (*Econetwork) Stop

func (e *Econetwork) Stop()

type EconodeInfoPayload

type EconodeInfoPayload struct {
	Name    string
	Owner   string
	Balance int
}

type EconodeNewPayload

type EconodeNewPayload struct {
	Name string
}

type Item

type Item struct {
	CPS   float64
	Price float64
	Name  string
	Count int
}

type Node

type Node struct {
	ID        int
	Name      string
	Balance   int
	Owner     int
	Members   []int
	Inventory map[string]*Item
	Multi     float64
}

Someone's econode The idea is that we can have other people growing a single node together

func (*Node) Buy

func (n *Node) Buy(purchase Item)

type ServerResponse

type ServerResponse struct {
	Code   string       `json:"code"`
	Method string       `json:"method"`
	Data   *interface{} `json:"data,omitempty"`
}

The server response struct What we should send, as defined by the procotol

type StatsPayload

type StatsPayload struct {
	Nodes          int
	Accounts       int
	NetworkVersion string
}

Jump to

Keyboard shortcuts

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