seabotserver

package module
v0.0.0-...-d036b32 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2017 License: MIT Imports: 0 Imported by: 0

README

seabotserver

This is tcp server for seabattle game. Players are AI bots

tcp protocol

<- client to server
-> server to client

[0 0 0 19]{"field" : "value"}

first 4 butes = json length
первые 4 байта = длина json команды

auth

<- { "auth" : "12334yger5348fhf8d7tdg8s76g" }
-> { "auth" : 
		{ 
			"ok": 		false, 
			"error": 	"some error",
			"id" : 		123 // bot ID
			"userid" : 	11 // user ID 
		}
	}
<- { "exit" : true }
-> disconnect
// bot versus random
// if you want to debug your code, use this command.
<- { "bvr" : { "place": 0 } }
-> { "bvr" : { "id": -1, "name": "bot_-1", "ships": [0,0,0,0...] } }
// bot versus bot
// сервер сам расставляет корабли
<- { "bvb" : { "place": 0 } } 
// игрок расставляет корабли на поле
// сервер должен проверить и допустить или не допустить расстановку
<- { "bvb" : { "place":  1, "ships" : [0,0,0,0,0,0,0]	}
}
// no bots yet, wait
-> { "bvb" : { "wait": 1 } }
// start battle, opponent bot info
-> { "bvb" : { "id": 321, "name": "dopinfo", "ships": [0,0,0,0] } }
0 0 0 0 0 0 0 0 0 1
0 4 0 0 0 0 0 0 0 0
0 4 0 0 0 0 3 0 0 2
0 4 0 0 0 0 3 0 0 2
0 4 0 0 0 0 3 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0

LOOP: GAME
// сервер предлагает игроку 123 сделать ход
-> { "turn" : { "id" : 123 } }

// Бот сделал ход, выстрел пришелся в точку 
// (А1) - 0,0
// (Б8) - 1,7
// (А3) - 0,2
// (Г4) - 3,3
// АБВГДЕ....
// 0123456789
// первая цифра это номер ряда, вторая цифра номер колонки
<- { "turn" : { "shot": [y, x] } }

// результат выстрела, -1 - мимо, 1 - попал, 2 - убил
-> { "turn" : { "result": -1 } }

-> { "turn" : {"opponent": { "shot": [y, x], "result": 1 } } }
GOTO GAME
// 10 second timeout
// after timeout -> lose

Battle end

-> { "end": { "winner": 123, "opponent": [0,0,0] } }

DB structure draft

User
	ID
	email
	pass
	name
	
Bot
	ID айди бота
	User
	AuthKey
	
Tournament
	ID
	Type - тип турнира
		SandBox - все боты имеют доступ в песочницу
		Tournament - после отборочного тура админ переносит в турнир
		Quality - игрок подает заявку в диапазоне дат, пишем запись в таблицу TourBot
	Name - Имя турнира
	RegStart
	RegUntil


TourBot
	Bot
	Tour
	State: Access, Deny
	RegisteredDate
	Played - сыграно боев
	Win - побед
	Lose - поражений
	Disconnect - дисконектов


Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BotService

type BotService interface {
	Battle() interface{}
	SetBattle(b interface{})

	SetDBBot(*DBBot)
	DBBot() *DBBot

	Send(d interface{})
	SendError(err string)

	Sender()
	Handler()

	Disconnect()
}

type DBBot

type DBBot struct {
	ID      int64  `db:"id"`
	User    int64  `db:"user_id"`
	AuthKey string `db:"auth_key"`
}

func NewDBBot

func NewDBBot() *DBBot

type DBBotService

type DBBotService interface {
	Auth(string) (*DBBot, error)
}

type DBSandbox

type DBSandbox struct {
	Bot   int64 `db:"bot"`
	Wins  int64 `db:"wins"`
	Loses int64 `db:"loses"`
	Last  int64 `db:"last"`
}

type DBSandboxService

type DBSandboxService interface {
	Get(botid int64) *DBSandbox // return sandox record for botID, if not exists - return default
	Store(*DBSandbox) error     // saves data to database, changes Last to now
}

type DBVsai

type DBVsai struct {
	Bot int64 `db:"bot"`
	Bvr int64 `db:"bvr"`
	Bvl int64 `db:"bvl"`
}

type DBVsaiService

type DBVsaiService interface {
	Get(botid int64) *DBVsai
	Store(*DBVsai) error
}

type FBBvb

type FBBvb struct {
	Place int   `json:"place"`
	Ships []int `json:"ships"`
}

FROM BOT = FB

type FBProfile

type FBProfile struct {
	Info int `json:"info"`
}

type FBTurn

type FBTurn struct {
	Shot [2]int `json:"shot"`
}

type FromBot

type FromBot struct {
	Auth    string     `json:"auth"`
	Exit    bool       `json:"exit"`
	Bvb     *FBBvb     `json:"bvb"`
	Bvr     *FBBvb     `json:"bvr"`
	Turn    *FBTurn    `json:"turn"`
	Profile *FBProfile `json:"profile"`
}

type LogBattle

type LogBattle struct {
	BattleID  int64        `bson:"battle"`
	StartTime int64        `bson:"start"`
	EndTime   int64        `bson:"end"`
	Winner    int64        `bson:"winner"`
	Sides     [2]*LogSides `bson:"sides"`
	Turns     []*LogTurn   `bson:"turns"`
}

type LogSides

type LogSides struct {
	ID   int64     `bson:"id"`
	Name string    `bson:"name"`
	Sea  *[100]int `bson:"sea"`
}

type LogTurn

type LogTurn struct {
	ID     int64  `bson:"id"`
	Shot   [2]int `bson:"shot"`
	Result int    `bson:"result"`
}

type LoggingService

type LoggingService interface {
	Store(*LogBattle) error
}

type QueueData

type QueueData struct {
	Bot  BotService
	Bvb  *FBBvb
	Exit bool
}

type TBAuth

type TBAuth struct {
	OK    bool   `json:"ok"`
	Error string `json:"error"`
	ID    int64  `json:"id"`
	User  int64  `json:"userid"`
}

type TBBvb

type TBBvb struct {
	Wait  int       `json:"wait,omitempty"`
	ID    int64     `json:"id,omitempty"`
	Name  string    `json:"name,omitempty"`
	Ships *[100]int `json:"ships,omitempty"`
}

type TBEnd

type TBEnd struct {
	Winner int64     `json:"winner"`
	Ships  *[100]int `json:"opponent,omitempty"`
}

type TBError

type TBError struct {
	Error string `json:"error"`
}

type TBOpponentTurn

type TBOpponentTurn struct {
	Shot   [2]int `json:"shot"`
	Result int    `json:"result,omitempty"`
}

type TBProfile

type TBProfile struct {
	Gnum int `json:"gnum"`
}

type TBTurn

type TBTurn struct {
	ID       int64           `json:"id,omitempty"`
	Result   int             `json:"result,omitempty"`
	Opponent *TBOpponentTurn `json:"opponent,omitempty"`
}

type ToBot

type ToBot struct {
	Auth    *TBAuth    `json:"auth,omitempty"`
	Bvb     *TBBvb     `json:"bvb,omitempty"`
	Turn    *TBTurn    `json:"turn,omitempty"`
	End     *TBEnd     `json:"end,omitempty"`
	Error   *TBError   `json:"error,omitempty"`
	Profile *TBProfile `json:"profile,omitempty"`
}

Directories

Path Synopsis
gameplay
storage

Jump to

Keyboard shortcuts

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