Day5 Game Frontend

今天我们来了解一下 Game Frontend 这个须由我们实作的部件,在 Open-Match 所设计的流程中,玩家用户端发送配对请求後,首先接收到配对请求的便是 Game Frontend。此部件内通常会实作使用者认证与获取使用者个人资料,用以确认可进行配对,与利用个人资料组成配对参数,最後产生配对请求 Tickets 给 Open-Match 核心。

https://i.imgur.com/mwH29cs.png

Ticket

一个配对中的最小单位,代表一次配对请求,里面含有配对所需要的条件参数,以下为 Ticket proto 定义,其中较为重要的为 SearchFields 与 Assignment。

type Ticket struct {
	state         protoimpl.MessageState
	sizeCache     protoimpl.SizeCache
	unknownFields protoimpl.UnknownFields

	// Id represents an auto-generated Id issued by Open Match.
	Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"`
	// An Assignment represents a game server assignment associated with a Ticket,
	// or whatever finalized matched state means for your use case.
	// Open Match does not require or inspect any fields on Assignment.
	Assignment *Assignment `protobuf:"bytes,3,opt,name=assignment,proto3" json:"assignment,omitempty"`
	// Search fields are the fields which Open Match is aware of, and can be used
	// when specifying filters.
	SearchFields *SearchFields `protobuf:"bytes,4,opt,name=search_fields,json=searchFields,proto3" json:"search_fields,omitempty"`
	// Customized information not inspected by Open Match, to be used by the match
	// making function, evaluator, and components making calls to Open Match.
	// Optional, depending on the requirements of the connected systems.
	Extensions map[string]*any.Any `protobuf:"bytes,5,rep,name=extensions,proto3" json:"extensions,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"`
	// Create time is the time the Ticket was created. It is populated by Open
	// Match at the time of Ticket creation.
	CreateTime *timestamp.Timestamp `protobuf:"bytes,6,opt,name=create_time,json=createTime,proto3" json:"create_time,omitempty"`
}

SearchFields

我们可以利用 SearchFields 满足 Ticket 所需要的配对参数,SearchFields 里面包含了两个 map,分别用来对应字串型别与数字型别参数,如果你原有的配对资料结构为巢状型,需先进行扁平化後平铺至 SearchFields 中。

type SearchFields struct {
	state         protoimpl.MessageState
	sizeCache     protoimpl.SizeCache
	unknownFields protoimpl.UnknownFields

	// Float arguments.  Filterable on ranges.
	DoubleArgs map[string]float64 `protobuf:"bytes,1,rep,name=double_args,json=doubleArgs,proto3" json:"double_args,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"fixed64,2,opt,name=value,proto3"`
	// String arguments.  Filterable on equality.
	StringArgs map[string]string `protobuf:"bytes,2,rep,name=string_args,json=stringArgs,proto3" json:"string_args,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"`
	// Filterable on presence or absence of given value.
	Tags []string `protobuf:"bytes,3,rep,name=tags,proto3" json:"tags,omitempty"`
}

example

此例来说包含了两个数值型条件,等级(level.lv)与连胜场数(win.streak),一个字串型条件,阶级(level.rank),最後有个 "3v3" tag,这些条件最终会被送至 Opne-Match 核心进行媒合。

SearchFields: &pb.SearchFields{
  DoubleArgs: map[string]float64{"level.lv": 500, "win.streak": 2},
  StringArgs: map[string]string{"level.rank": "master"},
  Tags: []string{"3v3"},
}

Assignment

Ticket 被建立时并不会包含 Assignment 内容,而是在完成配对後,才由 Director 将配对的 game server 位置等资讯放入

type Assignment struct {
	state         protoimpl.MessageState
	sizeCache     protoimpl.SizeCache
	unknownFields protoimpl.UnknownFields

	// Connection information for this Assignment.
	Connection string `protobuf:"bytes,1,opt,name=connection,proto3" json:"connection,omitempty"`
	// Customized information not inspected by Open Match, to be used by the match
	// making function, evaluator, and components making calls to Open Match.
	// Optional, depending on the requirements of the connected systems.
	Extensions map[string]*any.Any `protobuf:"bytes,4,rep,name=extensions,proto3" json:"extensions,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"`
}

参考 demo director example

在阶段 "Assigning Players" 的过程,将配对至相同局数的 ticket 与配对的 game server connection 指派回 Assignment

Assignment: &pb.Assignment{
		Connection: fmt.Sprintf("%d.%d.%d.%d:2222", rand.Intn(256), rand.Intn(256), rand.Intn(256), rand.Intn(256)),
}

<<:  Day.5 留个纪录好办事 - Mysql Log (日志纪录)-上

>>:  Day11- pandas(6)DataFrame有效率的检视资料方法

Windows Server 2019 英文语系更新至繁中

葛瑞部落格欢迎光顾 Windows Server 2019 语系更新手札 Windows设定 时间与...

[Python]使用Pillow,将图片由RGB转灰阶(Grayscale)

RGB -> Gray scale Gray scale(灰阶影像) from PIL imp...

Day21 跟着官方文件学习Laravel-Encryption

大家好,今天要介绍 Laravel 其中一个功能'加密',我会将这个加密加入我的专案实作之中。lar...

Python API Lab 1.0 –增加更多API需求

构造API请求 这是当前版本实验室中使用的API请求范例。该GET请求使用vms API,并列出所选...

找寻你的设计灵感、素材及好工具

制作网站前,通常需要找寻相关设计灵感,有时候想破头就是没想法,素材对网页内容来说很重要,好不容易找到...