Skip to content

Commit

Permalink
Merge pull request #3 from liquidiert/develop
Browse files Browse the repository at this point in the history
C# rewrite
  • Loading branch information
liquidiert authored Dec 13, 2020
2 parents 406c726 + ff3464e commit 5d2efc8
Show file tree
Hide file tree
Showing 33 changed files with 2,799 additions and 203 deletions.
459 changes: 339 additions & 120 deletions .gitignore

Large diffs are not rendered by default.

36 changes: 36 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
// Use IntelliSense to find out which attributes exist for C# debugging
// Use hover for the description of the existing attributes
// For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md
"version": "0.2.0",
"configurations": [
{
"name": ".NET Core Launch (web)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
// If you have changed target frameworks, make sure to update the program path.
"program": "${workspaceFolder}/bin/Debug/netcoreapp3.1/pactheman-server.dll",
"args": [],
"cwd": "${workspaceFolder}",
"stopAtEntry": false,
// Enable launching a web browser when ASP.NET Core starts. For more information: https://aka.ms/VSCode-CS-LaunchJson-WebBrowser
"serverReadyAction": {
"action": "openExternally",
"pattern": "\\bNow listening on:\\s+(https?://\\S+)"
},
"env": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"sourceFileMap": {
"/Views": "${workspaceFolder}/Views"
}
},
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach",
"processId": "${command:pickProcess}"
}
]
}
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"files.associations": {
"*.tcc": "cpp"
},
"python.pythonPath": "env/bin/python"

}
42 changes: 42 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"command": "dotnet",
"type": "process",
"args": [
"build",
"${workspaceFolder}/pactheman-server.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
},
{
"label": "publish",
"command": "dotnet",
"type": "process",
"args": [
"publish",
"${workspaceFolder}/pactheman-server.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
},
{
"label": "watch",
"command": "dotnet",
"type": "process",
"args": [
"watch",
"run",
"${workspaceFolder}/pactheman-server.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
}
]
}
4 changes: 4 additions & 0 deletions Bebop.Schemas/GameStates/GhostState.bop
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
struct GhostState {
map[string, Position] targets;
map[string, bool] clearTargets;
}
9 changes: 9 additions & 0 deletions Bebop.Schemas/GameStates/InitState.bop
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
struct InitState {
map[string, Position] ghostInitPositions;
map[string, Position] ghostInitVelocities;
map[string, uint32] ghostInitDelays;
map[guid, Position] playerInitPositions;
map[guid, uint32] playerInitScores;
map[guid, uint32] playerInitLives;
Position[] scorePointsInitPositions;
}
6 changes: 6 additions & 0 deletions Bebop.Schemas/GameStates/PlayerState.bop
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[opcode(0x1)]
struct PlayerState {
Session session;
map[string, Position] ghostPositions;
map[guid, Position] playerPositions;
}
4 changes: 4 additions & 0 deletions Bebop.Schemas/Messages/Error.bop
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[opcode(0x4)]
struct Error {
string errorMessage;
}
5 changes: 5 additions & 0 deletions Bebop.Schemas/Messages/Exit.bop
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[opcode(0x3)]
struct Exit {
Session session;
guid clientId;
}
4 changes: 4 additions & 0 deletions Bebop.Schemas/Messages/Join.bop
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[opcode(0x2)]
message Join {
1 -> Session session;
}
5 changes: 5 additions & 0 deletions Bebop.Schemas/NetworkMessage.bop
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
message NetworkMessage {
1 -> uint32 incomingOpCode;
2 -> byte[] playerState;
3 -> byte[] joinMsg;
}
4 changes: 4 additions & 0 deletions Bebop.Schemas/Objects/Position.bop
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
struct Position {
uint32 x;
uint32 y;
}
4 changes: 4 additions & 0 deletions Bebop.Schemas/Session.bop
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
message Session {
1 -> guid sessionId;
2 -> guid clientId;
}
39 changes: 39 additions & 0 deletions Controllers/WeatherForecastController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;

namespace pactheman_server.Controllers
{
[ApiController]
[Route("weather")]
public class WeatherForecastController : ControllerBase
{
private static readonly string[] Summaries = new[]
{
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
};

private readonly ILogger<WeatherForecastController> _logger;

public WeatherForecastController(ILogger<WeatherForecastController> logger)
{
_logger = logger;
}

[HttpGet]
public IEnumerable<WeatherForecast> Get()
{
var rng = new Random();
return Enumerable.Range(1, 5).Select(index => new WeatherForecast
{
Date = DateTime.Now.AddDays(index),
TemperatureC = rng.Next(-20, 55),
Summary = Summaries[rng.Next(Summaries.Length)]
})
.ToArray();
}
}
}
40 changes: 40 additions & 0 deletions Listeners/Multiplayer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using Bebop.Runtime;
using System;
using System.IO;
using System.Net;
using System.Linq;
using PacTheMan.Models;
using System.Net.Sockets;

namespace pactheman_server {
public class MultiplayerListener : TcpListener {

MultiplayerListener(IPAddress _ip, Int32 _port = 8083) : base(_ip, _port) {}

public void Listen() {
Start();

Byte[] buffer = new Byte[256];

try {
while(true) {
AcceptTcpClientAsync().ContinueWith(client => {
NetworkStream stream = client.Result.GetStream();

while(stream.Read(buffer, 0, buffer.Length) != 0) {
var message = NetworkMessage.Decode(buffer);
BebopMirror.HandleRecord(BebopMirror.GetRecordFromOpCode(message.IncomingOpCode ?? 0), message.PlayerState.ToArray(), client.Result);
}

});
}
} catch(SocketException ex) {
Console.WriteLine("SocketException: {0}", ex);
} finally {
Stop();
}

}

}
}
40 changes: 40 additions & 0 deletions Listeners/Singleplayer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using Bebop.Runtime;
using System;
using System.IO;
using System.Net;
using System.Linq;
using PacTheMan.Models;
using System.Net.Sockets;

namespace pactheman_server {
public class SingleplayerListener : TcpListener {

SingleplayerListener(IPAddress _ip, Int32 _port = 8082) : base(_ip, _port) {}

public void Listen() {
Start();

Byte[] buffer = new Byte[256];

try {
while(true) {
AcceptTcpClientAsync().ContinueWith(client => {
NetworkStream stream = client.Result.GetStream();

while(stream.Read(buffer, 0, buffer.Length) != 0) {
var message = NetworkMessage.Decode(buffer);
BebopMirror.HandleRecord(BebopMirror.GetRecordFromOpCode(message.IncomingOpCode ?? 0), message.PlayerState.ToArray(), client.Result);
}

});
}
} catch(SocketException ex) {
Console.WriteLine("SocketException: {0}", ex);
} finally {
Stop();
}

}

}
}
Loading

0 comments on commit 5d2efc8

Please sign in to comment.