core

package
v0.0.0-...-6b24a3f Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2019 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FmtBcMex

func FmtBcMex(mt MessageType) string

FmtBcMex : blockchain message as formatted string

func IntTo4Byte

func IntTo4Byte(b *[]byte, i int, rev bool)

IntTo4Byte : convert an in into a slice of bytes

Types

type BCMessage

type BCMessage interface {
	Message
	GenerateBCMessage() []byte
}

BCMessage : interface for a blockchain message

type EventFunc

type EventFunc func(Server, net.Conn)

EventFunc : is the type of the function passed to the events handler

type Message

type Message interface {
	GetType() MessageType
	GetContent() MessageContent
	Send(Server, net.Conn) error
	Mutate(MessageType, MessageContent)
	GenerateGameMessage() []byte
}

Message : the interface of the message

func NewMessage

func NewMessage(mt MessageType, mc MessageContent) Message

NewMessage : creates a new message

type MessageContent

type MessageContent interface{}

MessageContent : the content of the message to send

type MessageType

type MessageType byte

MessageType : the type of message to send

const (
	//AreYouNode ask a connection if it is a node
	AreYouNode MessageType = 1 //DELETE

	//IAmNode say that you are a node
	//Structure
	//1byte -> message type
	IAmNode MessageType = 3 //DELETE

	//AmReady say you are ready
	AmReady MessageType = 5

	//Config send my config for check
	//Structure
	//1byte -> message type
	//1byte -> hash len
	//Nbytes-> hash
	Config MessageType = 7

	//ConfirmConfig send the config after receiving a corrent config
	ConfirmConfig MessageType = 9

	//GiveYouNodes give other connected nodes
	GiveYouNodes MessageType = 11

	//GiveMeChain ask for the full chain starting from index
	GiveMeChain MessageType = 13

	//GiveYouChain sends the chain starting from index
	GiveYouChain MessageType = 15

	//MyStake communicate your intention to validate and your stake
	MyStake MessageType = 19

	//GiveMeValidators ask fot other validators connected
	GiveMeValidators MessageType = 21

	//GiveYouValidators send other validators connected
	GiveYouValidators MessageType = 23

	//ErrorCommitted error in the last block
	ErrorCommitted MessageType = 25

	//ErrorFound error in the full chain
	ErrorFound MessageType = 27

	//BanThisValidator ban a validator after suspiscius behavior
	BanThisValidator MessageType = 29

	//MyNextBlock propose a new block
	MyNextBlock MessageType = 31
)
const (
	//ForceTransform : forces the client to set the players
	//transform to the value sent
	//STRUCTURE:
	//1byte -> message type
	//12byte -> Vector3int position
	ForceTransform MessageType = 1 // s -> c

	//SimpleTransform : mesage containing a simple transform
	//STRUCTURE:
	//1byte -> message type
	//4byte -> owner
	//1byte -> player type
	//12byte -> Vector3int position
	SimpleTransform MessageType = 5 // s <-> c

	//CompleteTransform : message containing a coplete transform
	//STRUCTURE:
	//1byte -> message type
	//
	CompleteTransform MessageType = 7 // s <-> c

	//NewObject : message to declare creation of new object
	//STRUCTURE:
	//1byte -> message type
	//4byte -> owner
	//1byte -> owner type
	//1byte -> code type
	//1byte -> code obj
	//12byte -> position
	NewObject MessageType = 10

	//UpdateObject : message to update object
	//STRUCTURE:
	//1byte -> message type
	//4byte -> owner
	//1byte -> owner type
	//1byte -> code type
	//1byte -> code obj
	//12byte -> position
	UpdateObject MessageType = 13

	//DestroyObject :	destroy object in game
	//STRUCTURE:
	//1byte -> message type
	//4byte -> owner
	//1byte -> owner type
	//1byte -> code type
	//1byte -> code obj
	DestroyObject MessageType = 15

	//NewCollision : message to inform the server of a new collision
	//STRUCTURE:
	//1byte -> message type
	//4byte -> code owner
	//4byte -> player code
	//1byte -> bullet code type
	//1byte -> bullet code obj
	NewCollision MessageType = 20
)
const (
	//WelcomeMessage : message to send data to the client
	//STRUCTURE:
	//1byte -> message type
	//4byte -> client code
	WelcomeMessage MessageType = 0 // s-> c

	//StrangeMessage : message unknown to the clinet
	//STRUCTURE:
	//1byte -> message type
	//1byte -> (last peace)?0:10
	//1byte -> peace type
	//N1bytes -> in some cases, peace length (es string)
	//N2bytes ->peace
	StrangeMessage MessageType = 1 // s -> c

	//VoidMessage : message containing no information
	//STRUCTURE:
	//1byte -> message type
	VoidMessage MessageType = 3 // s <-> c

	//InGameMessage : defines a type of messages that are send diring game
	//STRUCTURE:
	//1byte -> message type
	//1byte -> in game message type
	//Nbyte -> message
	InGameMessage MessageType = 5

	//BChainMessage : defines a type of messages that are send diring game
	//STRUCTURE:
	//1byte -> message type
	//1byte -> blockchain message type
	//Nbyte -> message
	BChainMessage MessageType = 7

	//NameString : message containing the name of the player
	//STRUCTURE:
	//1byte -> message type
	//1byte -> name lenght
	//Nbyte -> name
	NameString MessageType = 18 // s <-> c

	//NewConnection : a new player connected
	//STRUCTURE:
	//1byte -> message type
	//4byte -> owner
	//1byte -> name length
	//Nbyte -> name
	NewConnection MessageType = 20 // s -> c

	//NewDisconnection : a player disconnected
	//STRUCTURE:
	//1byte -> message type
	//4byte -> owner
	NewDisconnection MessageType = 22 // s -> c

	//NewInRoom : a player just connected to the room
	//STRUCTURE:
	//1byte : message type
	//4byte : owner
	//1byte : player type
	//1byte -> name length
	//Nbyte -> name
	NewInRoom MessageType = 24 // s <-> c

	//NewOutRoom : a player exited the room
	//STRUCTURE:
	//1byte -> message type
	//4byte -> owner
	NewOutRoom MessageType = 26 // s <-> c

	//ChatAll : send text message to all players
	//STRUCTURE:
	//1byte -> message type
	//1byte -> owner name lenght
	//N1byte -> owner name
	//1byte -> text message lenth
	//N2byte -> text message
	ChatAll MessageType = 30 // s <-> c better to s -> c

	//ChatRoom : send text message to all in the room
	//STRUCTURE:
	//1byte -> message type
	//4byte -> owner
	//1byte -> text message lenght
	//Nbyte -> text message
	ChatRoom MessageType = 32 // s <-> c

	//ChatTo : send text message to specific user
	//STRUCTURE:
	//1byte -> message type
	//4byte -> owner
	//4byte -> destination
	//1byte -> text message length
	//Nbyte -> text message
	ChatTo MessageType = 34 // s <-> c
)
const (

	//VarString : sends a string with a numbr of bytes
	//equal to string lenght +1
	VarString MessageType = 70 // s <-> c

	//VarByte : send a byte
	VarByte MessageType = 80 // s <-> c

	//Vector2byte : send a vector of 2 bytes
	Vector2byte MessageType = 82 // s <-> c

	//Vector3byte : send a vector of 3 bytes
	Vector3byte MessageType = 84 // s <-> c

	//VarInt : send 32bit int
	VarInt MessageType = 90 // s <-> c

	//Vector2int : send a vector of 2 32bit int
	Vector2int MessageType = 92 // s <-> c

	//Vector3int : send a vector of 3 32bit int
	Vector3int MessageType = 94 // s <-> c

	//VarFloat : send a 32bit float
	VarFloat MessageType = 96 // s <-> c

	//Vector2float : send a vector of 2 32bit float
	Vector2float MessageType = 98 // s <-> c

	//Vector3float : send a vector of 3 32bit float
	Vector3float MessageType = 100 // s <-> c

	//VarInt64 : send 64bit int
	VarInt64 MessageType = 102 // s <-> c

	//Vector2int64 : send a vector of 2 64bit int
	Vector2int64 MessageType = 104 // s <-> c

	////Vector3int64 : send a vector of 3 64bit int
	Vector3int64 MessageType = 106 // s <-> c
)

------------------------------------------------------------------ -------------------CONSTANTS-------------------------------------- ------------------------------------------------------------------

type Player

type Player interface {
	//GetTransform() Transform
	SendMessage(Message) error
	BroadcastRoom(Message) error
	SetRoom(Room) error
}

Player : the player interface

type Room

type Room interface {
	FreeSpots() int
	GetKey() string
	BroadcastMessage(Message) error
	AddConnection(string) error
	IsIn(string) bool
	Lock()
	RLock()
	Unlock()
	RUnlock()
}

Room : the interface of a room

func NewRoom

func NewRoom(s Server, key string, maxP int) Room

NewRoom : returns a new room given the key and max players

type RoomStatus

type RoomStatus int

RoomStatus : the type of the room status

const (

	//NullRoomStatus : the room is created but not usable
	NullRoomStatus RoomStatus = 0

	//AvalRoomStatus : the room is avalaible
	//and there is space for players
	AvalRoomStatus RoomStatus = 2

	//FullRoomStatus : the room is full
	FullRoomStatus RoomStatus = 5

	//ErrorRoomStatus : the room is reporting an error
	ErrorRoomStatus RoomStatus = -1
)

type Server

type Server interface {
	Start() error
	Close()
	AddListener(string, EventFunc) chan net.Conn
	RemoveListener(string, chan net.Conn)
	Emit(string, net.Conn)
	Status() string
	StatusIn(string)
	AddRoom(string, int) error
	GetRoom(string) (Room, error)
	RemoveRoom(string)
	AddConnection(string, net.Conn) int
	RemoveConnection(string)
	BroadcastMessage(Message) error
	BroadcastMessageRoom(Message, string) error
	SendMessageToConn(Message, net.Conn) error
	SendMessageToAddr(Message, string) error
	AssignRoom(string, string) error
	SetVar(string, interface{}) error
	GetVar(string) (interface{}, error)
}

Server : the server interface

func NewServer

func NewServer(sc ServerConfig) Server

NewServer : create a new server with given server config

type ServerConfig

type ServerConfig interface {
	Port() string
}

ServerConfig : the interface of the server config

func NewServerConfig

func NewServerConfig(port string, maxRooms int) ServerConfig

NewServerConfig : create a new server config

Jump to

Keyboard shortcuts

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