Skip to content

Commit

Permalink
getting closer
Browse files Browse the repository at this point in the history
  • Loading branch information
dudash committed May 5, 2022
1 parent 95746a0 commit 293e0bb
Show file tree
Hide file tree
Showing 17 changed files with 311 additions and 76 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ export_presets.cfg
# Mono-specific ignores
.mono/
data_*/
mono_crash*
17 changes: 9 additions & 8 deletions .vs/srt-godot-client/xs/UserPrefs.xml
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
<Properties>
<MonoDevelop.Ide.Workbench ActiveDocument="Scenes/SupportScenes/PlayerShip.cs">
<MonoDevelop.Ide.Workbench ActiveDocument="README.md">
<Files>
<File FileName="Scenes/SupportScenes/PlayerShip.cs" Line="221" Column="54" />
<File FileName="Autoload/CSLogger.cs" Line="1" Column="1" />
<File FileName="Networking/Server.cs" Line="17" Column="42" />
<File FileName="Scenes/SupportScenes/SpaceMissile.cs" Line="23" Column="6" />
<File FileName="Scenes/SupportScenes/PlayerShip.cs" Line="129" Column="1" />
<File FileName="Autoload/CSLogger.cs" />
<File FileName="Networking/Server.cs" />
<File FileName="Scenes/SupportScenes/SpaceMissile.cs" />
<File FileName="README.md" Line="27" Column="1" />
</Files>
<Pads>
<Pad Id="ProjectPad">
<State name="__root__">
<Option id="ShowAllFiles" value="True" />
<Node name="srt-godot-client" expanded="True">
<Node name=".DS_Store" selected="True" />
<Node name="srt-godot-client" expanded="True">
<Node name="Autoload" expanded="True" />
<Node name="Networking" expanded="True" />
<Node name="Scenes" expanded="True">
<Node name="SupportScenes" expanded="True">
<Node name="PlayerShip.cs" selected="True" />
</Node>
<Node name="SupportScenes" expanded="True" />
</Node>
</Node>
</Node>
Expand Down
Binary file added Assets/Fonts/RedHatText-Italic.ttf
Binary file not shown.
7 changes: 7 additions & 0 deletions Assets/Fonts/RedHatText-Regular.tres
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[gd_resource type="DynamicFont" load_steps=2 format=2]

[ext_resource path="res://assets/Fonts/RedHatText-Regular.ttf" type="DynamicFontData" id=1]

[resource]
size = 30
font_data = ExtResource( 1 )
Binary file added Assets/Fonts/RedHatText-Regular.ttf
Binary file not shown.
6 changes: 6 additions & 0 deletions Assets/Fonts/RedHatTextItalic.tres
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[gd_resource type="DynamicFont" load_steps=2 format=2]

[ext_resource path="res://assets/Fonts/RedHatText-Italic.ttf" type="DynamicFontData" id=1]

[resource]
font_data = ExtResource( 1 )
6 changes: 6 additions & 0 deletions Assets/UIElements/MainTheme.tres
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[gd_resource type="Theme" load_steps=2 format=2]

[ext_resource path="res://Assets/Fonts/RedHatText-Regular.tres" type="DynamicFont" id=1]

[resource]
default_font = ExtResource( 1 )
49 changes: 0 additions & 49 deletions Networking/Server.cs

This file was deleted.

136 changes: 136 additions & 0 deletions Networking/ServerConnection.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
using Godot;
using System;
using System.Collections.Generic;
using System.IO;
using Amqp;
using Amqp.Framing;
using Amqp.Types;
using ProtoBuf;
using redhatgamedev.srt;

// NOTE: This is an autoloaded singleton class
// We use this class to represent a remote connection to the game servers
public class ServerConnection : Node
{
CSLogger cslogger;

// AMQ Broker connection details
String url = "amqp://127.0.0.1:5672";
bool disableCertValidation = true;
String commandsQueue = "COMMAND.IN";
String gameEventsTopic = "GAME.EVENT.OUT";
ConnectionFactory factory;
Connection amqpConnection;
Session amqpSession;
SenderLink commandsSender;
ReceiverLink gameEventsReceiver;

public override void _Ready()
{
cslogger = GetNode<CSLogger>("/root/CSLogger");
cslogger.Info("Space Ring Things (SRT) Game Client v???");

var clientConfig = new ConfigFile();
Godot.Error err = clientConfig.Load("res://Resources/client.cfg");
if (err == Godot.Error.Ok)
{
cslogger.Info("Successfully loaded the AMQ config from 'res://Resources/client.cfg'");
url = (String) clientConfig.GetValue("amqp","server_string", "amqp://127.0.0.1:5672");
cslogger.Verbose("config file: setting url to " + url);
disableCertValidation = (bool) clientConfig.GetValue("amqp", "disable_cert_validation", true);
cslogger.Verbose("config file: setting cert validation to " + disableCertValidation);
}

InitializeAMQP();
}

public void ConnectToServer()
{
cslogger.Debug("connecting to server");
}

private void OnConnectSuccess()
{
// TODO
cslogger.Debug("connected to server");
}

private void OnConnectFailed()
{
// TODO
cslogger.Error("failed to connect server - TBD why");
}

public void RemovePlayer(String UUID)
{
// TODO do we need this anymore? Delete and remove references to it
}

private void GameEventReceived(IReceiverLink receiver, Message message)
{
cslogger.Verbose("Game Event received!");
receiver.Accept(message);
byte[] binaryBody = (byte[])message.Body;
MemoryStream st = new MemoryStream(binaryBody, false);
CommandBuffer commandBuffer;
commandBuffer = Serializer.Deserialize<CommandBuffer>(st);
EmitSignal("ProcessGameEvent", commandBuffer); // TODO: create signal handler
}

public void SendCommand(CommandBuffer CommandBuffer)
{
cslogger.Verbose("ServerConnection: Sending command");
MemoryStream st = new MemoryStream();
Serializer.Serialize<CommandBuffer>(st, CommandBuffer);
byte[] msgBytes = st.ToArray();
Message msg = new Message(msgBytes);
commandsSender.Send(msg, null, null); // don't care about the ack on our message being received
}

async void InitializeAMQP()
{
cslogger.Debug("Initializing AMQP connection");
Connection.DisableServerCertValidation = disableCertValidation;
try
{
//Trace.TraceLevel = TraceLevel.Frame;
//Trace.TraceListener = (l, f, a) => Console.WriteLine(DateTime.Now.ToString("[hh:mm:ss.fff]") + " " + string.Format(f, a));
factory = new ConnectionFactory();
cslogger.Debug("connecting to " + url);
Address address = new Address(url);
amqpConnection = await factory.CreateAsync(address);
amqpSession = new Session(amqpConnection);
}
catch (Exception es)
{
cslogger.Error("AMQP connection/session failed for " + url);
// TODO: let player know
return;
}

cslogger.Debug("Creating AMQ receiver for game events");
Source eventInSource = new Source
{
Address = gameEventsTopic,
Capabilities = new Symbol[] { new Symbol("topic") }
};
gameEventsReceiver = new ReceiverLink(amqpSession, "srt-game-client-receiver", eventInSource, null);
gameEventsReceiver.Start(10, GameEventReceived);

cslogger.Debug("Creating AMQ sender for player commands");
Target commandOutTarget = new Target
{
Address = commandsQueue,
Capabilities = new Symbol[] { new Symbol("queue") }
};
commandsSender = new SenderLink(amqpSession, "srt-game-client-command-sender", commandOutTarget, null);

cslogger.Debug("Finished initializing AMQP connection");
}

// // Called every frame. 'delta' is the elapsed time since the previous frame.
// public override void _Process(float delta)
// {
//
// }
}
45 changes: 43 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,43 @@
# srt-godot-client
Space Rings Thing Game Client (for Red Hat Gaming)
# Space Rings Thing Game Client (for Red Hat Gaming)
This is the player side source code for the SRT game. A multiplayer space game written in Godot.

### How Can I Play This Game
Everything in currently in development. To play you'll need to roll up your sleves and do a little bit of build/operations work.

## Architecture
TBD

## Development Notes
### Networking Code Gen (Protobuf)
After making changes to the protocol buffer definitions, they need to be compiled to C# code.
You will need the `dotnet` command line tool (or equivalent) in order to do this.

Intstall the Protogen tooling:
```
dotnet tool install --global protobuf-net.Protogen --version 3.0.101
```

Then, in the `proto` folder:
```
protogen --csharp_out=. *.proto
```

### Building
TBD

### Running Your Own Server / Testing Locally
You will need to run the game server, the AMQ messaging server, and this game (client-side).

To run AMQ locally (in a container via podman/docker):
`podman run --name artemis -it -p 8161:8161 -p 5672:5672 --ip 10.88.0.2 -e AMQ_USER=admin -e AMQ_PASSWORD=admin -e AMQ_ALLOW_ANONYMOUS=true quay.io/artemiscloud/activemq-artemis-broker:latest`

In order to get a specific IP for a local container running Artemis, you will need to do this as the root system user.
Above command puts AMQ serving on IP address 10.88.0.2 with ports 8161 (the management console) and 5672 (the AMQP port).

Find/follow instructions for the [game server here](https://github.com/redhat-gamedev/srt-godot-server).

This repo is the player game client.

If you are debugging the Godot server and Godot client on the same machine you will want to do one of the following
Option 1. Goto `Editor->Editor Settings...` and search for the `Remote Port` setting (it's under `Network->Debug'). Change the port so that the client and server use different ports.
Option 2. In the Server project, goto `Project->Export...` and export to your platform, then run the exported server.
3 changes: 3 additions & 0 deletions Resources/client.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[amqp]
server_string="amqp://127.0.0.1:5672"
disable_cert_validation=true
13 changes: 6 additions & 7 deletions Resources/logger.cfg
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
[logger]

default_output_level=2
default_output_level=0
default_output_strategies=[ 1, 1, 1, 1, 1 ]
default_logfile_path="user://srt-godot-test.log"
default_logfile_path="user://srt-godot-client.log"
max_memory_size=30
external_sinks=[ {
"path": "user://srt-godot-test.log",
"path": "user://srt-godot-client.log",
"queue_mode": 0
} ]
modules=[ {
"external_sink": {
"path": "user://srt-godot-test.log",
"path": "user://srt-godot-client.log",
"queue_mode": 0
},
"name": "logger",
"output_level": 2,
"output_level": 0,
"output_strategies": [ 1, 1, 1, 1, 1 ]
}, {
"external_sink": {
"path": "user://srt-godot-test.log",
"path": "user://srt-godot-client.log",
"queue_mode": 0
},
"name": "main",
Expand Down
6 changes: 5 additions & 1 deletion Scenes/MainScenes/Map.tscn
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
[gd_scene format=2]
[gd_scene load_steps=2 format=2]

[ext_resource path="res://Scenes/MainScenes/MapOverlay.tscn" type="PackedScene" id=1]

[node name="Map" type="Node"]

[node name="MapOverlay" parent="." instance=ExtResource( 1 )]
35 changes: 35 additions & 0 deletions Scenes/MainScenes/MapOverlay.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
[gd_scene load_steps=2 format=2]

[ext_resource path="res://Assets/UIElements/MainTheme.tres" type="Theme" id=1]

[node name="MapOverlay" type="Control"]
anchor_right = 1.0
anchor_bottom = 1.0
margin_right = 896.0
margin_bottom = 480.0
__meta__ = {
"_edit_use_anchors_": false
}

[node name="SectorLabelTextureRect" type="TextureRect" parent="."]
margin_left = 850.0
margin_top = 20.0
margin_right = 1050.0
margin_bottom = 70.0
__meta__ = {
"_edit_use_anchors_": false
}

[node name="SectorLabel" type="Label" parent="."]
use_parent_material = true
margin_left = 850.0
margin_top = 25.0
margin_right = 1050.0
margin_bottom = 65.0
theme = ExtResource( 1 )
text = "SECTOR - X"
align = 1
valign = 1
__meta__ = {
"_edit_use_anchors_": false
}
Loading

0 comments on commit 293e0bb

Please sign in to comment.