Simple rule based matchmaking for your online game with support of Redcon(RESP) protocol.


Simple Matchmaking

Simple rule based matchmaking for your online game with support of Redcon(RESP) protocol.

Go Report Card Go Cover Card GitHub license

1- Simple Match Rule

Easiest usage of system is "Direct Match Rule" in this rule players match each other without any rule.

package main

import (
	"github.com/fatihkahveci/simple-matchmaking/matchmaking"
	"github.com/fatihkahveci/simple-matchmaking/server"
	"github.com/fatihkahveci/simple-matchmaking/store"
	"time"
)

func main()  {
	inMemory := store.NewInMemoryStore()
	dur, _ := time.ParseDuration("10s")

	r := matchmaking.NewDirectMatchRule()


	respServer := server.NewRespServer(inMemory, ":1234")

	matcher := matchmaking.NewMatchmaking("test",respServer,inMemory, r, dur)

	matcher.Start()
}

2- Score Match Rule

In this example users match with given score rule which means match happens only user score 10 between 15.

package main

import (
	"github.com/fatihkahveci/simple-matchmaking"
	"github.com/fatihkahveci/simple-matchmaking/rules"
	"github.com/fatihkahveci/simple-matchmaking/server"
	"github.com/fatihkahveci/simple-matchmaking/store"
	"time"
)

func main()  {
	inMemory := store.NewInMemoryStore()
	dur, _ :=time.ParseDuration("10s")

	r := rules.NewScoreMatchRule(10,15)


	respServer := server.NewRespServer(inMemory, ":1234")

	matcher := simpe_mm.NewMatchmaking("score",respServer,inMemory, r, dur)

	matcher.Start()
}

3- Custom Match Rule

In this example we create our own rule. We just need to follow "MatchRule" interface.

= minLevel && user2Level <= maxLevel { return true } return false } func (r CustomFieldMatchRule) GetName() string { return "CustomField" } func main() { inMemory := store.NewInMemoryStore() dur, _ :=time.ParseDuration("10s") r := NewCustomFieldMatchRule("level",10,20) respServer := server.NewRespServer(inMemory, ":1234") matcher := simpe_mm.NewMatchmaking("custom",respServer,inMemory, r, dur) matcher.Start() } ">
package main

import (
	"github.com/fatihkahveci/simple-matchmaking"
	"github.com/fatihkahveci/simple-matchmaking/server"
	"github.com/fatihkahveci/simple-matchmaking/store"
	"time"
)


type CustomFieldMatchRule struct {
	Field string
	MinThreshold int
	MaxThreshold int
}

func NewCustomFieldMatchRule(field string,minThreshold, maxThreshold int) CustomFieldMatchRule {
	return CustomFieldMatchRule{
		Field: field,
		MinThreshold: minThreshold,
		MaxThreshold: maxThreshold,
	}
}

func (r CustomFieldMatchRule) Match(user1, user2 store.User) bool {
	user1Level := user1.Fields[r.Field].(int)
	user2Level := user2.Fields[r.Field].(int)


	minLevel := user1Level - r.MinThreshold
	maxLevel := user1Level + r.MaxThreshold

	if user2Level >= minLevel && user2Level <= maxLevel {
		return true
	}

	return false
}

func (r CustomFieldMatchRule) GetName() string {
	return "CustomField"
}

func main()  {
	inMemory := store.NewInMemoryStore()
	dur, _ :=time.ParseDuration("10s")

	r := NewCustomFieldMatchRule("level",10,20)


	respServer := server.NewRespServer(inMemory, ":1234")

	matcher := simpe_mm.NewMatchmaking("custom",respServer,inMemory, r, dur)

	matcher.Start()
}

Usage

You can add new user to pool using any redis client. Thanks for Redcon ❤️

redis-cli -p 1234 add '{
  "id": "55",
  "score": 5
}'

Also you need to subscribe your matchmaking channel.

redis-cli -p 1234
127.0.0.1:1234> subscribe simple
Reading messages... (press Ctrl-C to quit)
1) "subscribe"
2) "simple"
3) (integer) 1
1) "message"
2) "simple"
3) "{\"user_1\":{\"id\":\"12\",\"score\":5,\"join_time\":\"2021-08-31T22:57:27.109609+03:00\",\"fields\":null},\"user_2\":{\"id\":\"55\",\"score\":5,\"join_time\":\"2021-08-31T22:57:27.109614+03:00\",\"fields\":null},\"match_rule_name\":\"Direct\",\"time\":\"2021-08-31T22:57:27.116724+03:00\",\"action_type\":\"match\"}"

TODOS

  • More Server Support (WebSocket etc)
  • More Store Support (Redis, Mongo etc)
  • Multiple User Support (Team matchmaking)
Similar Resources

Scalable game server framework with clustering support and client libraries for iOS, Android, Unity and others through the C SDK.

pitaya Pitaya is an simple, fast and lightweight game server framework with clustering support and client libraries for iOS, Android, Unity and others

Jan 2, 2023

Battleblips - Work in progress multiplayer terminal base battleship game written in Go (with mouse support!) using tcell library

Battleblips - Work in progress multiplayer terminal base battleship game written in Go (with mouse support!) using tcell library

battleblips Work in progress multiplayer terminal base battleship game written in Go (with mouse support!) using tcell library (see https://github.com

Apr 26, 2022

Tcell-game-template - A small template repository for simple tcell based games

tcell game template This is a template repository used for making small terminal

Jan 22, 2022

Lightweight, facility, high performance golang based game server framework

Lightweight, facility, high performance golang based game server framework

Nano Nano is an easy to use, fast, lightweight game server networking library for Go. It provides a core network architecture and a series of tools an

Jan 1, 2023

Terminal-based game engine for Go, built on top of Termbox

Terminal-based game engine for Go, built on top of Termbox

Termloop Termloop is a pure Go game engine for the terminal, built on top of the excellent Termbox. It provides a simple render loop for building game

Dec 29, 2022

Web-based Cloud Gaming service for Retro Game

Web-based Cloud Gaming service for Retro Game

CloudRetro provides an open-source cloud gaming platform for retro games. It started as an experiment for testing cloud gaming performance with WebRTC and libretro, and now it aims to deliver the most modern and convenient gaming experience through the technology.

Jan 8, 2023

Go-based 2D game to relax after a long coding time

MoreLoves As simple 2D game to play during time when you need to relax after a deep coding time. On your lovely terminal, use your keyboard keys to na

May 21, 2022

Gamespictionary - Scribble.rs is an alternative to the web-based drawing game skribbl.io

Scribble.rs Scribble.rs is an alternative to the web-based drawing game skribbl.

Apr 13, 2022

Librebird - A text based bird game made in Go

librebird a text based bird game made in Go, please contribute to the adventures

Feb 19, 2022
Comments
  • Package name and repo name difference

    Package name and repo name difference

    When the package name and repo name are different as in below, it increases complexity.

    repo name: github.com/fatihkahveci/simple-matchmaking package name: simple_mm

    I think you should change both with a single easy name like "matchmaker" or anything you like.

    Then you should change the NewMatchmaking function name as New because it is already being called with package name.

    matchmaker.NewMatchmaking <- Bad matchmaker.New <- Good and idiomatic ;)

  • added options as parameters

    added options as parameters

    In matchmaking.go the NewMatchmaking function takes too many parameters. Also these parameters are not simle string or int type parameters. They are domain spesific object which needs to be prepared beforehand.

    In such cases, it is preferable to collect the parameters in a single structure as an option. So I created Option struct and give it to NewMatchmaking function.

    Also because the package name (simple_mm) is different from the repo name (github.com/fatihkahveci/simple-matchmaking), it is better to add specify the import name like:

    simpe_mm "github.com/fatihkahveci/simple-matchmaking"

  • Start should accept context.Context

    Start should accept context.Context

    Project doesn't have context support. For graceful shutdown Start method and all functions after that should accept context from outside. If context is nil then context.Background() can be used.

Online multiplayer board game server written in Go, using WebSockets.

BfH Server The Battle for Hermannia is a board game created as a gift by the father of hermannm, a developer of this project. This digital edition of

Nov 7, 2022
A terminal Snake game that supports multiple players to play together online.
A terminal Snake game that supports multiple players to play together online.

GoSnake A Snake game that supports multiple players to play together online. The game is written in go language and does not use other third-party lib

Jun 25, 2022
A simple game that I created with Ebiten game library as a way to teach myself Go. Enjoy!
A simple game that I created with Ebiten game library as a way to teach myself Go. Enjoy!

galactic-asteroid-belt Overview A simple game that I created with Ebiten game library as a way to teach myself Go. Enjoy! Run To run, you will need Go

Dec 2, 2021
Simple 2D game to teach myself various things about game development and ECS, etc

2d-grass-game I really don't know what to name this game. Its a big grass field, and its in 2d so....2D Grass game This is a simple 2D game to teach m

Jan 17, 2022
Arkanoid game in Go using Ebiten game engine with ECS.
Arkanoid game in Go using Ebiten game engine with ECS.

Arkanoid-go Arkanoid game in Go using Ebiten game engine with ECS. You must have Git LFS installed when cloning the repository to download assets. See

Oct 9, 2022
AircraftWar - a game powered by Go+ spx game engine
AircraftWar - a game powered by Go+ spx game engine

AircraftWar - a game powered by Go+ spx game engine How to run Download Go+ and build it. See https://github.com/goplus/gop#how-to-build. Download thi

Jan 5, 2022
FlappyCalf - a game powered by Go+ spx game engine
FlappyCalf - a game powered by Go+ spx game engine

FlappyCalf - a game powered by Go+ spx game engine How to run Download Go+ and build it. See https://github.com/goplus/gop#how-to-build. Download this

Nov 6, 2022
FlappyCalf - a game powered by Go+ spx game engine
FlappyCalf - a game powered by Go+ spx game engine

FlappyCalf - a game powered by Go+ spx game engine How to run Download Go+ and build it. See https://github.com/goplus/gop#how-to-build. Download this

Nov 6, 2022
MazePlay - a game powered by Go+ spx game engine
MazePlay - a game powered by Go+ spx game engine

MazePlay - a game powered by Go+ spx game engine How to run Download Go+ and build it. See https://github.com/goplus/gop#how-to-build. Download this g

Dec 16, 2021
RundQuiz-Game - This is a Go exercise that implements and builds a quiz game from a list of math questions in a CSV file.

Go RundQuiz Game Exercise details This exercise is broken into two parts to help simplify the process of explaining it as well as to make it easier to

Jan 5, 2022