Skip to content

Commit

Permalink
Added replication of actors and better actor code in general
Browse files Browse the repository at this point in the history
  • Loading branch information
DrMeepso committed Nov 8, 2024
1 parent 0b70ef7 commit 847f873
Show file tree
Hide file tree
Showing 12 changed files with 82 additions and 5 deletions.
Binary file modified .vs/WFSermver/v17/.suo
Binary file not shown.
4 changes: 3 additions & 1 deletion GDFormat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -513,8 +513,10 @@ private static void writeDouble(Double packet, BinaryWriter writer)
private static void writeString(string packet, BinaryWriter bw)
{
bw.Write((int) 4); // remeber to write the string header!
bw.Write((int) packet.Length);

byte[] bytes = Encoding.UTF8.GetBytes(packet);

bw.Write((int)bytes.Length);
// get the ammount to pad by!

// Step 3: Write the actual bytes of the string
Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ Because of this emulation to run the server you must run it from a steam account
- [X] Spawn actors required for the Metal Detector
- [X] Move entire server into a Program class (idk why .net gave me a classless program)
- [X] Improve error handling
- [ ] Improve GoDot serialization both ways
- [X] Add proper support for actor handling (its okay atm)
- [ ] Some sort of plugin or modding support (maybe)

Expand Down
6 changes: 6 additions & 0 deletions Server.chatEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ void OnPlayerChat(string message, SteamId id)
serverOwnedInstances.Last().pos = sender.PlayerPosition; // move it to the player
spawned = true;
break;

case "metal":
spawnMetal();
serverOwnedInstances.Last().pos = sender.PlayerPosition; // move it to the player
spawned = true;
break;
}
if (spawned)
{
Expand Down
4 changes: 4 additions & 0 deletions Server.cs
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,7 @@ int hostSpawn()
{
removeServerActor(inst);
}
//setActorZone(inst, "main_zone", -1);
}

// dont spawn too many because it WILL LAG players!
Expand Down Expand Up @@ -378,6 +379,9 @@ int hostSpawn()

int hostSpawnMetal()
{
// still got no idea
gameLobby.SetData("server_browser_value", "0");

int metalCount = serverOwnedInstances.FindAll(a => a.Type == "metal_spawn").Count;
if (metalCount > 7)
return 0;
Expand Down
7 changes: 7 additions & 0 deletions Server.networking.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Steamworks;
using System;
using System.Collections.Generic;
using System.Diagnostics.Metrics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
Expand Down Expand Up @@ -30,5 +31,11 @@ void sendPacketToPlayers(Dictionary<string, object> packet)
SteamNetworking.SendP2PPacket(member.Id, packetBytes, nChannel: 2);
}
}

void sendPacketToPlayer(Dictionary<string, object> packet, SteamId id)
{
byte[] packetBytes = writePacket(packet);
SteamNetworking.SendP2PPacket(id, packetBytes, nChannel: 2);
}
}
}
10 changes: 9 additions & 1 deletion Server.packetEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,19 @@ void OnNetworkPacket(P2Packet packet)
Dictionary<string, object> kickPacket = new Dictionary<string, object>();
kickPacket["type"] = "kick";

SteamNetworking.SendP2PPacket(packet.SteamId, writePacket(kickPacket), nChannel: 2);
sendPacketToPlayer(kickPacket, packet.SteamId);

messageGlobal($"{offendingPlayer.FisherName} was kicked for spawning illegal actors");
}
}

if ((string)packetInfo["type"] == "request_actors")
{
sendPlayerAllServerActors(packet.SteamId);
sendPacketToPlayer(createRequestActorResponce(), packet.SteamId); // this is empty because otherwise all the server actors are invisible!

}

}
}
}
55 changes: 53 additions & 2 deletions Server.utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;

Expand Down Expand Up @@ -93,10 +94,10 @@ WFInstance spawnGenericActor(string type, Vector3 pos = null)
if (pos == null)
pos = Vector3.zero;

WFInstance actor = new WFInstance(IId, "void_portal", pos);
WFInstance actor = new WFInstance(IId, type, pos);
serverOwnedInstances.Add(actor);

instanceSpacePrams["actor_type"] = "void_portal";
instanceSpacePrams["actor_type"] = type;
instanceSpacePrams["at"] = pos;
instanceSpacePrams["rot"] = new Vector3(0, 0, 0);
instanceSpacePrams["zone"] = "main_zone";
Expand All @@ -109,6 +110,28 @@ WFInstance spawnGenericActor(string type, Vector3 pos = null)
return actor;
}

void sendPlayerAllServerActors(SteamId id)
{
foreach (WFInstance actor in serverOwnedInstances)
{
Dictionary<string, object> spawnPacket = new Dictionary<string, object>();
spawnPacket["type"] = "instance_actor";

Dictionary<string, object> instanceSpacePrams = new Dictionary<string, object>();
spawnPacket["params"] = instanceSpacePrams;

instanceSpacePrams["actor_type"] = actor.Type;
instanceSpacePrams["at"] = actor.pos;
instanceSpacePrams["rot"] = new Vector3(0, 0, 0);
instanceSpacePrams["zone"] = "main_zone";
instanceSpacePrams["zone_owner"] = -1;
instanceSpacePrams["actor_id"] = actor.InstanceID;
instanceSpacePrams["creator_id"] = (long)SteamClient.SteamId.Value;

sendPacketToPlayer(spawnPacket, id); // spawn the rain!
}
}

void spawnServerPlayerActor(SteamId id)
{
Dictionary<string, object> spawnPacket = new Dictionary<string, object>();
Expand Down Expand Up @@ -205,6 +228,22 @@ void removeServerActor(WFInstance instance)
serverOwnedInstances.Remove(instance);
}

void setActorZone(WFInstance instance, string zoneName, int zoneOwner)
{
Dictionary<string, object> removePacket = new();
removePacket["type"] = "actor_action";
removePacket["actor_id"] = instance.InstanceID;
removePacket["action"] = "_set_zone";

Dictionary<int, object> prams = new Dictionary<int, object>();
removePacket["params"] = prams;

prams[0] = zoneName;
prams[1] = zoneOwner;

sendPacketToPlayers(removePacket); // remove
}

bool isPlayerAdmin(SteamId id)
{
string adminSteamID = Admins.Find(a => long.Parse(a) == long.Parse(id.ToString()));
Expand All @@ -228,5 +267,17 @@ public void disconnectPlayers()
sendPacketToPlayers(closePacket);
}

public Dictionary<string, object> createRequestActorResponce()
{
Dictionary <string, object> createPacket = new();

createPacket["type"] = "actor_request_send";

Dictionary<int, object> actorArray = new();
createPacket["list"] = actorArray;

return createPacket;
}

}
}
Binary file modified obj/Debug/net6.0/WFSermver.dll
Binary file not shown.
Binary file modified obj/Debug/net6.0/WFSermver.pdb
Binary file not shown.
Binary file modified obj/Debug/net6.0/ref/WFSermver.dll
Binary file not shown.
Binary file modified obj/Debug/net6.0/refint/WFSermver.dll
Binary file not shown.

0 comments on commit 847f873

Please sign in to comment.