diff --git a/Cove/Server/Actor/Actor.cs b/Cove/Server/Actor/Actor.cs index 10d8663..1efc826 100644 --- a/Cove/Server/Actor/Actor.cs +++ b/Cove/Server/Actor/Actor.cs @@ -35,6 +35,8 @@ public class WFActor public int despawnTime = -1; public bool despawn = true; + public CSteamID owner = new CSteamID(0); // 0 is the server + public WFActor(long ID, string Type, Vector3 entPos, Vector3 entRot = null) { InstanceID = ID; diff --git a/Cove/Server/Actor/Player.cs b/Cove/Server/Actor/Player.cs index 6257455..d2d2915 100644 --- a/Cove/Server/Actor/Player.cs +++ b/Cove/Server/Actor/Player.cs @@ -38,6 +38,8 @@ public WFPlayer(CSteamID id, string fisherName) : base(0, "player", Vector3.zero FisherID = randomID; Username = fisherName; + owner = id; + pos = new Vector3(0, 0, 0); despawn = false; // players down despawn! } diff --git a/Cove/Server/Server.Debug.cs b/Cove/Server/Server.Debug.cs index ab7b143..918013f 100644 --- a/Cove/Server/Server.Debug.cs +++ b/Cove/Server/Server.Debug.cs @@ -14,7 +14,6 @@ You may obtain a copy of the License at limitations under the License. */ - using System; using System.Collections.Generic; using System.Linq; @@ -25,21 +24,17 @@ namespace Cove.Server { public partial class CoveServer { - // purely for debug + // purely for debug, yes i know its 100% fucked public static void printStringDict(Dictionary obj, string sub = "") { foreach (var kvp in obj) { if (kvp.Value is Dictionary) - { printStringDict((Dictionary)kvp.Value, sub + "." + kvp.Key); - } else if (kvp.Value is Dictionary) - { printArray((Dictionary)kvp.Value, sub + "." + kvp.Key); - } else { + else Console.WriteLine($"{sub} {kvp.Key}: {kvp.Value}"); - } } } public static void printArray(Dictionary obj, string sub = "") @@ -47,15 +42,11 @@ public static void printArray(Dictionary obj, string sub = "") foreach (var kvp in obj) { if (kvp.Value is Dictionary) - { printStringDict((Dictionary)kvp.Value, sub + "." + kvp.Key); - } else if (kvp.Value is Dictionary) - { printArray((Dictionary)kvp.Value, sub + "." + kvp.Key); - } else { + else Console.WriteLine($"{sub} {kvp.Key}: {kvp.Value}"); - } } } } diff --git a/Cove/Server/Server.Packet.cs b/Cove/Server/Server.Packet.cs index 949d29d..686be8b 100644 --- a/Cove/Server/Server.Packet.cs +++ b/Cove/Server/Server.Packet.cs @@ -14,12 +14,10 @@ You may obtain a copy of the License at limitations under the License. */ - using Steamworks; using Cove.GodotFormat; using Cove.Server.Actor; using Cove.Server.Utils; -using System.Reflection; namespace Cove.Server { @@ -56,10 +54,9 @@ void OnNetworkPacket(byte[] packet, CSteamID sender) hostPacket["type"] = "recieve_host"; hostPacket["host_id"] = SteamUser.GetSteamID().m_SteamID.ToString(); sendPacketToPlayers(hostPacket); + if (isPlayerAdmin(sender)) - { messagePlayer("You're an admin on this server!", sender); - } Thread ChalkInformer = new Thread(() => SendStagedChalkPackets(sender)); ChalkInformer.Start(); // send the player all the chalk data @@ -90,13 +87,17 @@ void OnNetworkPacket(byte[] packet, CSteamID sender) { WFPlayer thisPlayer = AllPlayers.Find(p => p.SteamId.m_SteamID == sender.m_SteamID); if (thisPlayer == null) - { Console.WriteLine("No fisher found for player instance!"); - } else { thisPlayer.InstanceID = actorID; + allActors.Add(thisPlayer); // add the player to the actor list } + + } else { + WFActor cActor = new WFActor(actorID, type, Vector3.zero, Vector3.zero); + cActor.owner = sender; + allActors.Add(cActor); } } diff --git a/Cove/Server/Server.Utils.cs b/Cove/Server/Server.Utils.cs index c1590ff..a3e1e52 100644 --- a/Cove/Server/Server.Utils.cs +++ b/Cove/Server/Server.Utils.cs @@ -71,7 +71,9 @@ public void spawnRainCloud() sendPacketToPlayers(rainSpawnPacket); // spawn the rain! RainCloud cloud = new RainCloud(IId, pos); cloud.despawn = true; + serverOwnedInstances.Add(cloud); + allActors.Add(cloud); } public WFActor spawnFish(string fishType = "fish_spawn") @@ -130,6 +132,7 @@ public WFActor spawnGenericActor(string type, Vector3 pos = null) WFActor actor = new WFActor(IId, type, pos); serverOwnedInstances.Add(actor); + allActors.Add(actor); instanceSpacePrams["actor_type"] = type; instanceSpacePrams["at"] = pos; diff --git a/Cove/Server/Server.cs b/Cove/Server/Server.cs index 5921cdb..fb7125b 100644 --- a/Cove/Server/Server.cs +++ b/Cove/Server/Server.cs @@ -14,16 +14,14 @@ You may obtain a copy of the License at limitations under the License. */ - using Steamworks; using Cove.Server.Plugins; -using Cove.GodotFormat; using Cove.Server.Actor; using Cove.Server.Utils; using Microsoft.Extensions.Hosting; using Cove.Server.HostedServices; using Microsoft.Extensions.Logging; -using System.Reflection; +using Vector3 = Cove.GodotFormat.Vector3; namespace Cove.Server { @@ -52,6 +50,7 @@ public partial class CoveServer public List AllPlayers = new(); public List serverOwnedInstances = new(); + public List allActors = new(); Thread cbThread; Thread networkThread; @@ -65,7 +64,6 @@ public partial class CoveServer public void Init() { - cbThread = new(runSteamworksUpdate); networkThread = new(RunNetwork); @@ -73,7 +71,6 @@ public void Init() string worldFile = $"{AppDomain.CurrentDomain.BaseDirectory}worlds/main_zone.tscn"; if (!File.Exists(worldFile)) { - Console.WriteLine("-- ERROR --"); Console.WriteLine("main_zone.tscn is missing!"); Console.WriteLine("please put a world file in the /worlds folder so the server may load it!"); @@ -287,11 +284,9 @@ public void Init() WFPlayer newPlayer = new WFPlayer(userChanged, Username); AllPlayers.Add(newPlayer); - //Console.WriteLine($"{Username} has been assigned the fisherID: {newPlayer.FisherID}"); - - foreach (PluginInstance plugin in loadedPlugins) + foreach (PluginInstance p in loadedPlugins) { - plugin.plugin.onPlayerJoin(newPlayer); + p.plugin.onPlayerJoin(newPlayer); } // check if the player is banned @@ -310,25 +305,18 @@ public void Init() if (stateChange.HasFlag(EChatMemberStateChange.k_EChatMemberStateChangeLeft) || stateChange.HasFlag(EChatMemberStateChange.k_EChatMemberStateChangeDisconnected)) { - string Username = SteamFriends.GetFriendPersonaName(userChanged); Console.WriteLine($"{Username} [{userChanged.m_SteamID}] has left the game!"); updatePlayercount(); - foreach (var player in AllPlayers) + WFPlayer leavingPlayer = AllPlayers.Find(p => p.SteamId.m_SteamID == userChanged.m_SteamID); + foreach (PluginInstance plugin in loadedPlugins) { - if (player.SteamId.m_SteamID == userChanged.m_SteamID) - { - - foreach (PluginInstance plugin in loadedPlugins) - { - plugin.plugin.onPlayerLeave(player); - } - - AllPlayers.Remove(player); - } + plugin.plugin.onPlayerLeave(leavingPlayer); } + AllPlayers.Remove(leavingPlayer); + allActors.RemoveAll(a => a.owner.m_SteamID == userChanged.m_SteamID); } }); @@ -363,25 +351,17 @@ public void Init() private bool getBoolFromString(string str) { if (str.ToLower() == "true") - { return true; - } else if (str.ToLower() == "false") - { return false; - } else - { return false; - } } void runSteamworksUpdate() { while (true) - { SteamAPI.RunCallbacks(); - } } void RunNetwork() @@ -423,6 +403,13 @@ void OnPlayerChat(string message, CSteamID id) { WFPlayer sender = AllPlayers.Find(p => p.SteamId == id); + if (sender == null) + { + Console.WriteLine($"[UNKNOWN] {id}: {message}"); + // should probbaly kick the player here + return; + } + Console.WriteLine($"[{sender.FisherID}] {sender.Username}: {message}"); foreach (PluginInstance plugin in loadedPlugins)