stats

package
v0.0.0-...-2e4d9bc Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2021 License: BSD-3-Clause Imports: 5 Imported by: 0

Documentation

Overview

Package stats is teonet teoroom statistic (which writing to cdb) service client package.

Index

Examples

Constants

View Source
const (
	CmdSetRoomCreated = iota + 134 // 134 Set room created state
	CmdSetRoomState                // 135 Set room state changed
	CmdSetClientState              // 136 Set client state changed
	CmdRoomsByCreated              // 137 Get rooms by created time
)

Teoroom cdb commands

View Source
const (
	ClientAdded = iota
	ClientLoadded
	ClientStarted
	ClientLeave
	ClientDisconnected
	ClientGameStat
)

State of client state request

Variables

View Source
var TeoCdb = "teo-cdb"

TeoCdb is Teonet teo-cdb peer name

Functions

func SendClientState

func SendClientState(teo TeoConnector, state byte, roomID gocql.UUID,
	id gocql.UUID, statAr ...[]byte)

SendClientState sends ClientState to cdb

func SendRoomCreate

func SendRoomCreate(teo TeoConnector, roomID gocql.UUID, roomNum uint32)

SendRoomCreate sends RoomCreate to cdb

func SendRoomState

func SendRoomState(teo TeoConnector, roomID gocql.UUID, status byte)

SendRoomState sends RoomStatus to cdb

Types

type ClientStateRequest

type ClientStateRequest struct {
	State    byte // 0 - Added; 1 - Leave; 2 - GameStat;
	RoomID   gocql.UUID
	ID       gocql.UUID
	GameStat []byte
}

ClientStateRequest used in ComClientState command as request

func (*ClientStateRequest) MarshalBinary

func (req *ClientStateRequest) MarshalBinary() (data []byte, err error)

MarshalBinary encodes ClientStateRequest data into binary buffer.

func (*ClientStateRequest) UnmarshalBinary

func (req *ClientStateRequest) UnmarshalBinary(data []byte) (err error)

UnmarshalBinary decode binary buffer into ClientStateRequest receiver data.

type Room

type Room struct {
	ID      gocql.UUID // Room ID
	RoomNum uint32     // Room number
	Created time.Time  // Time when room created
	Started time.Time  // Time when room started
	Closed  time.Time  // Time when room closed to add players
	Stopped time.Time  // Time when room stopped
	State   uint8      // Current rooms state
}

Room data structure

type RoomByCreatedRequest

type RoomByCreatedRequest struct {
	ReqID uint32    // Request id
	From  time.Time // Time when room created
	To    time.Time // Time when room created
	Limit uint32    // Number of records to read
}

RoomByCreatedRequest request room by created field

func (*RoomByCreatedRequest) MarshalBinary

func (req *RoomByCreatedRequest) MarshalBinary() (data []byte, err error)

MarshalBinary encodes RoomCreatedRequest data into binary buffer.

func (*RoomByCreatedRequest) UnmarshalBinary

func (req *RoomByCreatedRequest) UnmarshalBinary(data []byte) (err error)

UnmarshalBinary decode binary buffer into RoomCreatedRequest receiver data.

type RoomByCreatedResponce

type RoomByCreatedResponce struct {
	ReqID uint32 // Request id
	Rooms []Room
}

RoomByCreatedResponce responce to room request

func SendRoomByCreated

func SendRoomByCreated(teo TeoConnector, from, to time.Time, limit uint32) (
	res RoomByCreatedResponce, err error)

SendRoomByCreated sends RoomByCreated Request to cdb

func (*RoomByCreatedResponce) MarshalBinary

func (res *RoomByCreatedResponce) MarshalBinary() (data []byte, err error)

MarshalBinary encodes RoomByCreatedResponce data into binary buffer.

func (*RoomByCreatedResponce) UnmarshalBinary

func (res *RoomByCreatedResponce) UnmarshalBinary(data []byte) (err error)

UnmarshalBinary decode binary buffer into RoomByCreatedResponce receiver data.

type RoomCreateRequest

type RoomCreateRequest struct {
	RoomID  gocql.UUID
	RoomNum uint32
}

RoomCreateRequest used in ComRoomCreated command as request

func (*RoomCreateRequest) MarshalBinary

func (req *RoomCreateRequest) MarshalBinary() (data []byte, err error)

MarshalBinary encodes RoomCreateRequest data into binary buffer.

Example
var roomID = gocql.TimeUUID()
req := RoomCreateRequest{roomID, 123}
data, _ := req.MarshalBinary()
l := int(unsafe.Sizeof(roomID))
fmt.Println(data[l:])
Output:

[123 0 0 0]

func (*RoomCreateRequest) UnmarshalBinary

func (req *RoomCreateRequest) UnmarshalBinary(data []byte) (err error)

UnmarshalBinary decode binary buffer into RoomCreateRequest receiver data.

Example
var roomID = gocql.TimeUUID()
data := append(roomID.Bytes(), []byte{123, 0, 0, 0}...)
req := &RoomCreateRequest{}
req.UnmarshalBinary(data)
fmt.Println(req.RoomNum)
Output:

123

type RoomCreateResponce

type RoomCreateResponce struct {
	RoomID gocql.UUID
}

RoomCreateResponce used in ComRoomCreated command as responce

func (*RoomCreateResponce) MarshalBinary

func (res *RoomCreateResponce) MarshalBinary() (data []byte, err error)

MarshalBinary encodes RoomCreateResponce data into binary buffer.

Example
roomID, _ := gocql.ParseUUID("a5f8a6b5-f39e-11e9-adbc-40a3cc55de62")
res := &RoomCreateResponce{roomID}
data, _ := res.MarshalBinary()
fmt.Println(data)
Output:

[165 248 166 181 243 158 17 233 173 188 64 163 204 85 222 98]

func (*RoomCreateResponce) UnmarshalBinary

func (res *RoomCreateResponce) UnmarshalBinary(data []byte) (err error)

UnmarshalBinary decode binary buffer into RoomCreateResponce receiver data.

Example
data := []byte{
	165, 248, 166, 181, 243, 158, 17, 233, 173, 188, 64, 163, 204, 85, 222,
	98,
}
res := &RoomCreateResponce{}
res.UnmarshalBinary(data)
fmt.Println(res.RoomID)
Output:

a5f8a6b5-f39e-11e9-adbc-40a3cc55de62

type RoomStateRequest

type RoomStateRequest struct {
	RoomID gocql.UUID
	Status byte
}

RoomStateRequest used in ComRoomStatus command as request

func (*RoomStateRequest) MarshalBinary

func (req *RoomStateRequest) MarshalBinary() (data []byte, err error)

MarshalBinary encodes RoomStatusRequest data into binary buffer.

func (*RoomStateRequest) UnmarshalBinary

func (req *RoomStateRequest) UnmarshalBinary(data []byte) (err error)

UnmarshalBinary decode binary buffer into RoomStatusRequest receiver data.

type TeoConnector

type TeoConnector interface {
	SendTo(peer string, cmd byte, data []byte) (int, error)
	//SendAnswer(pac *teonet.Packet, cmd byte, data []byte) (int, error)
	SendAnswer(pac interface{}, cmd byte, data []byte) (int, error)
	// WaitFrom wait receiving data from peer. The third function parameter is
	// timeout. It may be omitted or contain timeout time of time.Duration type.
	// If timeout parameter is omitted than default timeout value sets to 2
	// second.
	WaitFrom(from string, cmd byte, ii ...interface{}) <-chan *struct {
		Data []byte
		Err  error
	}
}

TeoConnector is teonet connector interface. It may be servers (*Teonet) or clients (*TeoLNull) connector and must conain SendTo method.

Jump to

Keyboard shortcuts

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