Skip to content
This repository has been archived by the owner on Dec 13, 2024. It is now read-only.

Commit

Permalink
Add godot example
Browse files Browse the repository at this point in the history
  • Loading branch information
NathanFlurry committed Dec 26, 2023
1 parent e4e511c commit 951bbb9
Show file tree
Hide file tree
Showing 57 changed files with 1,191 additions and 7 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2023 Rivet
Copyright (c) 2024 Rivet

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
3 changes: 3 additions & 0 deletions _internal/templater/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ enum ConfigMetaLanguage {
CPlusPlus,
CSharp,
Rust,
GDScript,
}

impl ConfigMetaLanguage {
Expand All @@ -55,6 +56,7 @@ impl ConfigMetaLanguage {
Self::CPlusPlus => "https://isocpp.org",
Self::CSharp => "https://docs.microsoft.com/en-us/dotnet/csharp/",
Self::Rust => "https://www.rust-lang.org",
Self::GDScript => "https://docs.godotengine.org/en/stable/getting_started/scripting/gdscript/gdscript_basics.html",
}
}
}
Expand All @@ -67,6 +69,7 @@ impl std::fmt::Display for ConfigMetaLanguage {
Self::CPlusPlus => write!(f, "C++"),
Self::CSharp => write!(f, "C#"),
Self::Rust => write!(f, "Rust"),
Self::GDScript => write!(f, "GDScript"),
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion c/coredump/LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2023 Rivet
Copyright (c) 2024 Rivet

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
19 changes: 19 additions & 0 deletions godot/bomber/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Docker
Dockerfile
.dockerignore

# Godot 4+ specific ignores
.godot/

# Godot-specific ignores
.import/

# Mono-specific ignores
.mono/
data_*/
mono_crash.*.json

# System/tool-specific ignores
.directory
.DS_Store
*~
4 changes: 4 additions & 0 deletions godot/bomber/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Normalize EOL for all files that Git considers text files.
* text=auto eol=lf

*.hdr binary
19 changes: 19 additions & 0 deletions godot/bomber/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Godot 4+ specific ignores
.godot/

# Godot-specific ignores
.import/

# Mono-specific ignores
.mono/
data_*/
mono_crash.*.json

# System/tool-specific ignores
.directory
.DS_Store
*~

### Rivet ###
.rivet/
.env
33 changes: 33 additions & 0 deletions godot/bomber/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
FROM ubuntu:22.04 AS builder

# Install Godot & templates
ENV GODOT_VERSION="4.0.2"
RUN apt update -y \
&& apt install -y wget unzip \
&& wget https://downloads.tuxfamily.org/godotengine/${GODOT_VERSION}/Godot_v${GODOT_VERSION}-stable_linux.x86_64.zip \
&& wget https://downloads.tuxfamily.org/godotengine/${GODOT_VERSION}/Godot_v${GODOT_VERSION}-stable_export_templates.tpz

RUN mkdir -p ~/.cache ~/.config/godot ~/.local/share/godot/export_templates/${GODOT_VERSION}.stable \
&& unzip Godot_v${GODOT_VERSION}-stable_linux.x86_64.zip \
&& mv Godot_v${GODOT_VERSION}-stable_linux.x86_64 /usr/local/bin/godot \
&& unzip Godot_v${GODOT_VERSION}-stable_export_templates.tpz \
&& mv templates/* ~/.local/share/godot/export_templates/${GODOT_VERSION}.stable \
&& rm Godot_v${GODOT_VERSION}-stable_export_templates.tpz Godot_v${GODOT_VERSION}-stable_linux.x86_64.zip

# Build application
WORKDIR /app
COPY . .
RUN mkdir -p build/linux \
&& godot -v --export-release "Linux/X11" --headless ./build/linux/game.x86_64

# ===

FROM ubuntu:22.04
RUN apt update -y \
&& apt install -y expect-dev \
&& rm -rf /var/lib/apt/lists/*
COPY --from=builder /app/build/linux/ /app

# Unbuffer output so the logs get flushed
CMD ["sh", "-c", "unbuffer /app/game.x86_64 --verbose --headless -- --server | cat"]

21 changes: 21 additions & 0 deletions godot/bomber/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 Rivet

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
28 changes: 28 additions & 0 deletions godot/bomber/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Bomber



[Visit Tutorial](https://rivet.gg/learn/godot/tutorials/crash-course)


| Engine Version | Language | Networking |
| --- | --- | --- |
| 4.0.0 | [GDScript](https://docs.godotengine.org/en/stable/getting_started/scripting/gdscript/gdscript_basics.html) | [High-Level Multiplayer](https://docs.godotengine.org/en/stable/tutorials/networking/high_level_multiplayer.html) |

**Rivet Features**

- [♟️ Matchmaker](https://rivet.gg/docs/matchmaker)
- [🌐 Dynamic Servers](https://rivet.gg/docs/dynamic-servers)


## Running locally

1. [Clone the GitHub repo](https://docs.github.com/en/repositories/creating-and-managing-repositories/cloning-a-repository)
2. Open this folder
3. Run: `rivet init`
4. Run `yarn start`

## Deploying to Rivet

[Documentation](https://rivet.gg/learn/godot/tutorials/crash-course#step-4-deploy-to-rivet)

84 changes: 84 additions & 0 deletions godot/bomber/addons/rivet_api/dock/dock.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
@tool
extends VBoxContainer

var poll_timer: Timer
var rng := RandomNumberGenerator.new()

var server_pid = null

func _ready():
poll_timer = Timer.new()
poll_timer.autostart = true
poll_timer.timeout.connect(_poll_server_status)
add_child(poll_timer)


func exec_sh(script: String) -> int:
return OS.create_process("sh", ["-c", script])
# OS.create_process("CMD.exe", ["/C", script], output)


func run_rivet_command(args: PackedStringArray):
var execute_id = rng.randi()
return OS.create_process("rivet", args)


## Checks if the server process is still running.
func _poll_server_status():
# Check if server still running
if server_pid != null and !OS.is_process_running(server_pid):
print("Server stopped")
server_pid = null

# Update stop button
$StopServer.disabled = server_pid == null
if server_pid != null:
$StartServer.text = "Restart Server"
$ServerPID.text = "Process ID: %s" % server_pid
$ServerPID.visible = true
else:
$StartServer.text = "Start Server"
$StopServer.text = "Stop Server"
$ServerPID.visible = false

func start_server():
if server_pid != null:
stop_server()

server_pid = OS.create_process(OS.get_executable_path(), ["--headless", "--", "--server"])

_poll_server_status()


## Kills the server if running.
func stop_server():
if server_pid != null:
print("Stopped serer")
OS.kill(server_pid)
server_pid = null
_poll_server_status()
else:
print("Server not running")


# MARK: UI
func _on_dashboard_pressed():
run_rivet_command(["game", "dashboard"])


func _on_start_server_pressed():
start_server()


func _on_stop_server_pressed():
stop_server()


#func _on_edit_config_pressed():
# print(ProjectSettings.globalize_path("res://rivet.toml"))
# OS.shell_open("file://%s" % ProjectSettings.globalize_path("res://rivet.toml"))


#func _on_deploy_pressed():
# deploy_pid = run_rivet_command(["deploy", "--namespace", "prod"])
# _poll_server_status()
3 changes: 3 additions & 0 deletions godot/bomber/addons/rivet_api/dock/dock.tscn
Git LFS file not shown
33 changes: 33 additions & 0 deletions godot/bomber/addons/rivet_api/dotenv.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
extends Node
class_name DotEnv

func config():
var path = "res://.env"

# Check if .env exists
if !FileAccess.file_exists(path):
RivetHelper.rivet_print(".env does not exist")
return

# Read .env file
var file = FileAccess.open(path, FileAccess.READ)
while !file.eof_reached():
var line = file.get_line()

# Ignore comments
if line.begins_with("#"):
continue

# Split line
var split = line.split("=", true, 2)
if split.size() != 2:
continue
var key = split[0]
var value = split[1]

# Trim quotes from value
if value.begins_with("\"") and value.ends_with("\""):
value = value.substr(1, value.length() - 2)

# Set env
OS.set_environment(split[0], split[1])
3 changes: 3 additions & 0 deletions godot/bomber/addons/rivet_api/images/icon-circle.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions godot/bomber/addons/rivet_api/images/icon-circle.png.import
Git LFS file not shown
8 changes: 8 additions & 0 deletions godot/bomber/addons/rivet_api/plugin.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[plugin]

name="Rivet API"
description=""
author="Rivet Gaming, Inc."
version="0.0.1"
script="rivet_api.gd"

52 changes: 52 additions & 0 deletions godot/bomber/addons/rivet_api/rivet.toml.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# === Rivet Version Configuration ===
#
# - More info: https://docs.rivet.gg/general/concepts/rivet-version-config
# - Reference: https://docs.rivet.gg/cloud/api/post-games-versions#body
# - Publish a new version with `rivet publish`
#

# How the game lobbies run and how players connect to the game.
#
# https://docs.rivet.gg/matchmaker/introduction
[matchmaker]
# How many players can join a specific lobby.
#
# Read more about matchmaking: https://docs.rivet.gg/matchmaker/concepts/finding-lobby
max_players = 32

# The hardware to provide for lobbies.
#
# Available tiers: https://docs.rivet.gg/serverless-lobbies/concepts/available-tiers
tier = "basic-1d1"

# Which regions the game should be available in.
#
# Available regions: https://docs.rivet.gg/serverless-lobbies/concepts/available-regions
[matchmaker.regions]
lnd-sfo = {}
lnd-fra = {}

# Runtime configuration for the lobby's Docker container.
[matchmaker.docker]
# If you're unfamiliar with Docker, here's how to write your own
# Dockerfile:
# https://docker-curriculum.com/#dockerfile
dockerfile = "Dockerfile"

# Which ports to allow players to connect to. Multiple ports can be defined
# with different protocols.
#
# How ports work: https://docs.rivet.gg/serverless-lobbies/concepts/ports
ports.default = { port = 10567, protocol = "udp" }

# What game modes are avaiable.
#
# Properties like `max_players`, `tier`, `dockerfile`, `regions`, and more can
# be overriden for specific game modes.
[matchmaker.game_modes]
default = {}

[kv]

[identity]

27 changes: 27 additions & 0 deletions godot/bomber/addons/rivet_api/rivet_api.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
@tool
extends EditorPlugin

# MARK: Plugin
const AUTO_LOAD_RIVET_CLIENT = "RivetClient"
const AUTO_LOAD_RIVET_HELPER = "RivetHelper"

var dock: Control

func _enter_tree():
# Add singleton
add_autoload_singleton(AUTO_LOAD_RIVET_CLIENT, "res://addons/rivet_api/rivet_client.gd")
add_autoload_singleton(AUTO_LOAD_RIVET_HELPER, "res://addons/rivet_api/rivet_helper.gd")

# Add dock
dock = preload("res://addons/rivet_api/dock/dock.tscn").instantiate()
add_control_to_dock(DOCK_SLOT_LEFT_BR, dock)

func _exit_tree():
# Remove singleton
remove_autoload_singleton(AUTO_LOAD_RIVET_CLIENT)
remove_autoload_singleton(AUTO_LOAD_RIVET_HELPER)

# Remove dock
remove_control_from_docks(dock)
dock.free()

Loading

0 comments on commit 951bbb9

Please sign in to comment.