Skip to content

Commit

Permalink
Added onNetworkPacket to CovePlugink class
Browse files Browse the repository at this point in the history
  • Loading branch information
DrMeepso committed Dec 5, 2024
1 parent efbda35 commit ec4ac18
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 52 deletions.
26 changes: 12 additions & 14 deletions Cove/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,16 @@ limitations under the License.
{
serverLogger.Fatal("Error occored on main thread");
serverLogger.Fatal(e.ToString());
closeServer();
}

void Log(string message)
{
serverLogger.Information(message);
}

Console.CancelKeyPress += Console_CancelKeyPress;
void Console_CancelKeyPress(object? sender, ConsoleCancelEventArgs e)
void closeServer()
{
Log("Application is closing...");

Dictionary<string, object> closePacket = new();
closePacket["type"] = "server_close";

Expand All @@ -60,6 +58,14 @@ void Console_CancelKeyPress(object? sender, ConsoleCancelEventArgs e)
webfishingServer.disconnectAllPlayers();
SteamMatchmaking.LeaveLobby(webfishingServer.SteamLobby);
SteamAPI.Shutdown();
Environment.Exit(0);
}

Console.CancelKeyPress += Console_CancelKeyPress;
void Console_CancelKeyPress(object? sender, ConsoleCancelEventArgs e)
{
Log("Server closed from input");
closeServer();
}

while (true)
Expand All @@ -70,16 +76,8 @@ void Console_CancelKeyPress(object? sender, ConsoleCancelEventArgs e)
switch(command)
{
case "exit":
Log("Application is closing...");
Dictionary<string, object> closePacket = new();
closePacket["type"] = "server_close";

webfishingServer.loadedPlugins.ForEach(plugin => plugin.plugin.onEnd()); // tell all plugins that the server is closing!

webfishingServer.disconnectAllPlayers();
SteamMatchmaking.LeaveLobby(webfishingServer.SteamLobby);
SteamAPI.Shutdown();
Environment.Exit(0);
Log("Server closed from console");
closeServer();
break;
case "say":
{
Expand Down
36 changes: 0 additions & 36 deletions Cove/SerilogTextWriter.cs

This file was deleted.

2 changes: 2 additions & 0 deletions Cove/Server/Plugins/CovePlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ public virtual void onChatMessage(WFPlayer sender, string message) { }
public virtual void onPlayerJoin(WFPlayer player) { }
// triggered when a player leaves the server
public virtual void onPlayerLeave(WFPlayer player) { }
// triggered when a packet arrives
public virtual void onNetworkPacket(WFPlayer sender, Dictionary<string, object> packet) { }

public WFPlayer[] GetAllPlayers()
{
Expand Down
15 changes: 15 additions & 0 deletions Cove/Server/Server.Commands.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;



namespace Cove.Server
{
public partial class CoveServer
{

}
}
7 changes: 7 additions & 0 deletions Cove/Server/Server.Packet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ void OnNetworkPacket(byte[] packet, CSteamID sender)
if (isPlayerBanned(sender))
banPlayer(sender);

var fromPlayer = AllPlayers.Find(p => p.SteamId.m_SteamID == sender.m_SteamID);
foreach (var loadedPlugin in loadedPlugins)
{
if (fromPlayer != null)
loadedPlugin.plugin.onNetworkPacket(fromPlayer, packetInfo);
}

switch ((string)packetInfo["type"])
{
case "handshake_request":
Expand Down
2 changes: 0 additions & 2 deletions Cove/Server/Server.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,11 @@ limitations under the License.
using Cove.Server.HostedServices;
using Microsoft.Extensions.Logging;
using Vector3 = Cove.GodotFormat.Vector3;
using System.Reflection;

namespace Cove.Server
{
public partial class CoveServer
{

public Serilog.Core.Logger logger;

public readonly string WebFishingGameVersion = "1.1"; // make sure to update this when the game updates!
Expand Down

0 comments on commit ec4ac18

Please sign in to comment.