Skip to content

Commit

Permalink
Merge pull request #28 from hubastard/master
Browse files Browse the repository at this point in the history
fork update
  • Loading branch information
Baldie-dev authored Apr 17, 2021
2 parents a1c831e + d09b1fd commit e5e4a24
Show file tree
Hide file tree
Showing 33 changed files with 835 additions and 14 deletions.
50 changes: 50 additions & 0 deletions .github/workflows/build-winx64.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: Build - Win x64

on:
push:
branches: [ master ]
pull_request_review:
types: [ submitted ]

jobs:

build:
strategy:
matrix:
configuration: [Debug, Release]

# We *only* want to run this if a collaborator or owner of the repo approves a pull request, or if something is merged into the main branch
if: ${{ github.event.ref == 'refs/heads/master' || (github.event.review.state == 'approved' && (github.event.review.author_association == 'COLLABORATOR' || github.event.review.author_association == 'OWNER')) }}
runs-on: dsp-installed

env:
Solution_Name: Nebula.sln

steps:
- name: Checkout
uses: actions/checkout@v2
with:
submodules: true

- name: Clear output directory in DSP files
# We use SilentlyContinue here because it errors out of the folder does not exist otherwise
run: rm -R -ErrorAction SilentlyContinue "C:\Program Files (x86)\Steam\steamapps\common\Dyson Sphere Program\BepInEx\plugins\Nebula"

# Add MSBuild to the PATH: https://github.com/microsoft/setup-msbuild
- name: Setup MSBuild.exe
uses: microsoft/[email protected]

# Build it
- name: Build the application
run: msbuild $env:Solution_Name /restore /p:Configuration=$env:Configuration
env:
Configuration: ${{ matrix.configuration }}

# Upload it to the run results
- name: Upload a Build Artifact
uses: actions/[email protected]
with:
# Artifact name
name: build-artifacts
# A file, directory or wildcard pattern that describes what to upload
path: C:\Program Files (x86)\Steam\steamapps\common\Dyson Sphere Program\BepInEx\plugins\Nebula
11 changes: 11 additions & 0 deletions NebulaClient/MultiplayerClientSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using NebulaModel.Packets.Session;
using NebulaModel.Utils;
using NebulaWorld;
using System;
using System.Net;
using UnityEngine;
using WebSocketSharp;
Expand Down Expand Up @@ -81,6 +82,16 @@ public void DestroySession()
{
serverConnection?.SendPacket(new StarBroadcastPacket(PacketProcessor.Write(packet), GameMain.data.localStar?.id ?? -1));
}
public void SendPacketToLocalPlanet<T>(T packet) where T : class, new()
{
serverConnection?.SendPacket(new PlanetBroadcastPacket(PacketProcessor.Write(packet), GameMain.mainPlayer.planetId));
}
public void SendPacketToPlanet<T>(T packet, int planetId) where T : class, new()
{
//Should send packet to particular planet
//Not needed at the moment, used only on the host side
throw new NotImplementedException();
}

public void Reconnect()
{
Expand Down
4 changes: 4 additions & 0 deletions NebulaClient/NebulaClient.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
<Compile Include="PacketProcessors\Factory\Assembler\AssemblerRecipeEventProcessor.cs" />
<Compile Include="PacketProcessors\Factory\Assembler\AssemblerUpdateProducesProcessor.cs" />
<Compile Include="PacketProcessors\Factory\Assembler\AssemblerUpdateStorageProcessor.cs" />
<Compile Include="PacketProcessors\Factory\Belt\BeltUpdatePickupItemsProcessor.cs" />
<Compile Include="PacketProcessors\Factory\Belt\BeltUpdatePutItemOnProcessor.cs" />
<Compile Include="PacketProcessors\Factory\Entity\CreatePrebuildsRequestProcessor.cs" />
<Compile Include="PacketProcessors\Factory\Ejector\EjectorOrbitUpdateProcessor.cs" />
<Compile Include="PacketProcessors\Factory\Ejector\EjectorStorageUpdateProcessor.cs" />
Expand Down Expand Up @@ -80,9 +82,11 @@
<Compile Include="PacketProcessors\Planet\FactoryDataProcessor.cs" />
<Compile Include="PacketProcessors\Planet\PlanetDataResponseProcessor.cs" />
<Compile Include="PacketProcessors\Planet\VegetationMinedProcessor.cs" />
<Compile Include="PacketProcessors\Players\NewDroneOrderProcessor.cs" />
<Compile Include="PacketProcessors\Players\PlayerAnimationUpdateProcessor.cs" />
<Compile Include="PacketProcessors\Players\PlayerColorChangeProcessor.cs" />
<Compile Include="PacketProcessors\Players\PlayerMovementProcessor.cs" />
<Compile Include="PacketProcessors\Players\RemoveDroneOrdersProcessor.cs" />
<Compile Include="PacketProcessors\Session\HandshakeResponseProcessor.cs" />
<Compile Include="PacketProcessors\Session\PlayerDisconnectedProcessor.cs" />
<Compile Include="PacketProcessors\Session\PlayerJoiningProcessor.cs" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using NebulaModel.Attributes;
using NebulaModel.Networking;
using NebulaModel.Packets.Belt;
using NebulaModel.Packets.Processors;

namespace NebulaClient.PacketProcessors.Factory.Belt
{
[RegisterPacketProcessor]
class BeltUpdatePickupItemsProcessor : IPacketProcessor<BeltUpdatePickupItemsPacket>
{
public void ProcessPacket(BeltUpdatePickupItemsPacket packet, NebulaConnection conn)
{
if (GameMain.data.factories[packet.FactoryIndex]?.cargoTraffic != null)
{
//Iterate though belt updates and remove target items
for (int i = 0; i < packet.BeltUpdates.Length; i++)
{
CargoTraffic traffic = GameMain.data.factories[packet.FactoryIndex].cargoTraffic;
CargoPath cargoPath = traffic.GetCargoPath(traffic.beltPool[packet.BeltUpdates[i].BeltId].segPathId);
cargoPath.TryPickItem(packet.BeltUpdates[i].SegId - 4 - 1, 12);
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using NebulaModel.Attributes;
using NebulaModel.Networking;
using NebulaModel.Packets.Belt;
using NebulaModel.Packets.Processors;
using NebulaWorld.Factory;

namespace NebulaClient.PacketProcessors.Factory.Belt
{
[RegisterPacketProcessor]
class BeltUpdatePutItemOnProcessor : IPacketProcessor<BeltUpdatePutItemOnPacket>
{
public void ProcessPacket(BeltUpdatePutItemOnPacket packet, NebulaConnection conn)
{
if (GameMain.data.factories[packet.FactoryIndex]?.cargoTraffic != null)
{
FactoryManager.EventFromServer = true;
GameMain.data.factories[packet.FactoryIndex].cargoTraffic.PutItemOnBelt(packet.BeltId, packet.ItemId);
FactoryManager.EventFromServer = false;
}
}
}
}
17 changes: 17 additions & 0 deletions NebulaClient/PacketProcessors/Players/NewDroneOrderProcessor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using NebulaModel.Attributes;
using NebulaModel.Networking;
using NebulaModel.Packets.Players;
using NebulaModel.Packets.Processors;
using NebulaWorld;

namespace NebulaClient.PacketProcessors.Players
{
[RegisterPacketProcessor]
class NewDroneOrderProcessor : IPacketProcessor<NewDroneOrderPacket>
{
public void ProcessPacket(NewDroneOrderPacket packet, NebulaConnection conn)
{
SimulatedWorld.UpdateRemotePlayerDrone(packet);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using NebulaModel.Networking;
using NebulaHost.PacketProcessors.Players;
using NebulaModel.Packets.Processors;

namespace NebulaClient.PacketProcessors.Players
{
class RemoveDroneOrdersProcessor : IPacketProcessor<RemoveDroneOrdersPacket>
{
public void ProcessPacket(RemoveDroneOrdersPacket packet, NebulaConnection conn)
{
if (packet.QueuedEntityIds != null)
{
for (int i = 0; i < packet.QueuedEntityIds.Length; i++)
{
GameMain.mainPlayer.mecha.droneLogic.serving.Remove(packet.QueuedEntityIds[i]);
}
}
}
}
}
10 changes: 10 additions & 0 deletions NebulaHost/MultiplayerHostSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,16 @@ public void DestroySession()
PlayerManager.SendPacketToLocalStar(packet);
}

public void SendPacketToLocalPlanet<T>(T packet) where T : class, new()
{
PlayerManager.SendPacketToLocalPlanet(packet);
}

public void SendPacketToPlanet<T>(T packet, int planetId) where T : class, new()
{
PlayerManager.SendPacketToPlanet(packet, planetId);
}

private void Update()
{
gameStateUpdateTimer += Time.deltaTime;
Expand Down
4 changes: 4 additions & 0 deletions NebulaHost/NebulaHost.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@
<Compile Include="PacketProcessors\Factory\Assembler\AssemblerRecipeEventProcessor.cs" />
<Compile Include="PacketProcessors\Factory\Assembler\AssemblerUpdateProducesProcessor.cs" />
<Compile Include="PacketProcessors\Factory\Assembler\AssemblerUpdateStorageProcessor.cs" />
<Compile Include="PacketProcessors\Factory\Belt\BeltUpdatePickupItemsProcessor.cs" />
<Compile Include="PacketProcessors\Factory\Belt\BeltUpdatePutItemOnProcessor.cs" />
<Compile Include="PacketProcessors\Factory\Entity\CreatePrebuildsRequestProcessor.cs" />
<Compile Include="PacketProcessors\Factory\Ejector\EjectorOrbitUpdateProcessor.cs" />
<Compile Include="PacketProcessors\Factory\Ejector\EjectorStorageUpdateProcessor.cs" />
Expand Down Expand Up @@ -78,11 +80,13 @@
<Compile Include="PacketProcessors\GameHistory\GameHistoryResearchContributionProcessor.cs" />
<Compile Include="PacketProcessors\Planet\FactoryLoadRequestProcessor.cs" />
<Compile Include="PacketProcessors\Planet\PlanetDataRequestProcessor.cs" />
<Compile Include="PacketProcessors\Players\NewDroneOrderProcessor.cs" />
<Compile Include="PacketProcessors\Players\PlayerAnimationUpdateProcessor.cs" />
<Compile Include="PacketProcessors\Players\PlayerColorChangedProcessor.cs" />
<Compile Include="PacketProcessors\Players\PlayerMechaDataProcessor.cs" />
<Compile Include="PacketProcessors\Players\PlayerMovementProcessor.cs" />
<Compile Include="PacketProcessors\Planet\VegetationMinedProcessor.cs" />
<Compile Include="PacketProcessors\Routers\PlanetBroadcastProcessor.cs" />
<Compile Include="PacketProcessors\Players\PlayerUpdateLocalStarIdProcessor.cs" />
<Compile Include="PacketProcessors\Routers\StarBroadcastProcessor.cs" />
<Compile Include="PacketProcessors\Session\HandshakeRequestProcessor.cs" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using NebulaModel.Attributes;
using NebulaModel.Networking;
using NebulaModel.Packets.Belt;
using NebulaModel.Packets.Processors;

namespace NebulaHost.PacketProcessors.Factory.Belt
{
[RegisterPacketProcessor]
class BeltUpdatePickupItemsProcessor : IPacketProcessor<BeltUpdatePickupItemsPacket>
{
public void ProcessPacket(BeltUpdatePickupItemsPacket packet, NebulaConnection conn)
{
//Iterate though belt updates and remove target items
for (int i = 0; i < packet.BeltUpdates.Length; i++)
{
CargoTraffic traffic = GameMain.data.factories[packet.FactoryIndex].cargoTraffic;
CargoPath cargoPath = traffic.GetCargoPath(traffic.beltPool[packet.BeltUpdates[i].BeltId].segPathId);
cargoPath.TryPickItem(packet.BeltUpdates[i].SegId - 4 - 1, 12);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using NebulaModel.Attributes;
using NebulaModel.Networking;
using NebulaModel.Packets.Belt;
using NebulaModel.Packets.Processors;
using NebulaWorld.Factory;

namespace NebulaHost.PacketProcessors.Factory.Belt
{
[RegisterPacketProcessor]
class BeltUpdatePutItemOnProcessor : IPacketProcessor<BeltUpdatePutItemOnPacket>
{
public void ProcessPacket(BeltUpdatePutItemOnPacket packet, NebulaConnection conn)
{
FactoryManager.EventFromClient = true;
GameMain.data.factories[packet.FactoryIndex].cargoTraffic.PutItemOnBelt(packet.BeltId, packet.ItemId);
FactoryManager.EventFromClient = true;
}
}
}
45 changes: 45 additions & 0 deletions NebulaHost/PacketProcessors/Players/NewDroneOrderProcessor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using NebulaModel.Attributes;
using NebulaModel.Networking;
using NebulaModel.Packets.Players;
using NebulaModel.Packets.Processors;
using NebulaWorld;
using NebulaWorld.Player;

namespace NebulaHost.PacketProcessors.Players
{
[RegisterPacketProcessor]
class NewDroneOrderProcessor : IPacketProcessor<NewDroneOrderPacket>
{
private PlayerManager playerManager;

public NewDroneOrderProcessor()
{
playerManager = MultiplayerHostSession.Instance.PlayerManager;
}

public void ProcessPacket(NewDroneOrderPacket packet, NebulaConnection conn)
{
//Host does not need to know about flying drones of other players if he is not on the same planet
if (GameMain.mainPlayer.planetId != packet.PlanetId)
{
return;
}

Player player = playerManager.GetPlayer(conn);

if (player != null)
{
if (packet.Stage == 1 || packet.Stage == 2)
{
DroneManager.AddPlayerDronePlan(player.Id, packet.EntityId);
}
else if (packet.Stage == 3)
{
DroneManager.RemovePlayerDronePlan(player.Id, packet.EntityId);
}

SimulatedWorld.UpdateRemotePlayerDrone(packet);
}
}
}
}
28 changes: 28 additions & 0 deletions NebulaHost/PacketProcessors/Routers/PlanetBroadcastProcessor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using NebulaModel.Attributes;
using NebulaModel.Networking;
using NebulaModel.Packets.Processors;
using NebulaModel.Packets.Routers;

namespace NebulaHost.PacketProcessors.Routers
{
[RegisterPacketProcessor]
class PlanetBroadcastProcessor : IPacketProcessor<PlanetBroadcastPacket>
{
private PlayerManager playerManager;
public PlanetBroadcastProcessor()
{
playerManager = MultiplayerHostSession.Instance.PlayerManager;
}
public void ProcessPacket(PlanetBroadcastPacket packet, NebulaConnection conn)
{
Player player = playerManager.GetPlayer(conn);
if (player != null)
{
//Forward packet to other users
playerManager.SendRawPacketToPlanet(packet.PacketObject, packet.PlanetId, conn);
//Forward packet to the host
MultiplayerHostSession.Instance.PacketProcessor.EnqueuePacketForProcessing(packet.PacketObject, conn);
}
}
}
}
Loading

0 comments on commit e5e4a24

Please sign in to comment.