Skip to content

Commit

Permalink
Merge pull request #48 from DrMeepso/1.12
Browse files Browse the repository at this point in the history
1.4.4
  • Loading branch information
DrMeepso authored Jan 10, 2025
2 parents 2a433c6 + 03d6844 commit 75281a1
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 10 deletions.
1 change: 0 additions & 1 deletion Cove/GodotFormat/GDClasses.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
namespace Cove.GodotFormat
{

public class Vector3
{
public float x;
Expand Down
10 changes: 8 additions & 2 deletions Cove/Server/Chalk/ChalkCanvas.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ public ChalkCanvas(long canvasID)

public void drawChalk(Vector2 position, int color)
{
int[] allowedCanvas = { 0, 1, 2, 3 };
if (!Array.Exists(allowedCanvas, element => element == canvasID))
{
return;
}

chalkImage[position] = color;
}

Expand All @@ -35,16 +41,16 @@ public Dictionary<int, object> getChalkPacket()

return packet;
}

public void chalkUpdate(Dictionary<int, object> packet)
{
foreach (KeyValuePair<int, object> entry in packet)
{
Dictionary<int, object> arr = (Dictionary<int, object>)entry.Value;
Vector2 vector2 = (Vector2)arr[0];
Vector2 pos = new Vector2((int)Math.Round(vector2.x), (int)Math.Round(vector2.y));
Int64 color = (Int64)arr[1];

chalkImage[vector2] = (int)color;
chalkImage[pos] = (int)color;
}
}

Expand Down
34 changes: 34 additions & 0 deletions Cove/Server/HostedServices/HostSpawn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ limitations under the License.
using System;
using System.Threading;
using System.Threading.Tasks;
using Cove.GodotFormat;
using Cove.Server.Actor;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
Expand Down Expand Up @@ -143,6 +144,13 @@ private void DoWork(object state)

}

// random neumber between 0 and 2 for 3 values
int random = ran.Next() % 3;
if (random == 0)
{
spawnBirds();
}

}
catch (Exception e)
{
Expand All @@ -153,6 +161,32 @@ private void DoWork(object state)
}
}

void spawnBirds()
{
int birdCount = server.allActors.FindAll(a => a.Type == "ambient_bird").Count;
if (birdCount > 8)
return;

Random ran = new Random();
int count = ran.Next() % 3 + 1;

int randomRange(float min, float max)
{
return ran.Next() % (int)(max - min) + (int)min;
}

Vector3 point = server.trash_points[ran.Next() % server.trash_points.Count];

_logger.LogInformation("Spawning birds at " + point.ToString());
for (int i = 0; i < count; i++)
{
Vector3 pos = point + new Vector3(randomRange((float)-2.5,(float)2.5), 0, randomRange((float)-2.5, (float)2.5));
WFActor a = server.spawnGenericActor("ambient_bird", point);
a.despawnTime = 60;
}

}

// This method is called when the service is stopping.
public Task StopAsync(CancellationToken cancellationToken)
{
Expand Down
5 changes: 2 additions & 3 deletions Cove/Server/Server.Packet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,11 @@ void OnNetworkPacket(byte[] packet, CSteamID sender)

// all actor types that should not be spawned by anyone but the server!
string[] illegalTypes = ["fish_spawn_alien", "fish_spawn", "raincloud", "canvas", "ambient_bird", "void_portal", "metal_spawn"];
if (Array.LastIndexOf(illegalTypes, type) > -1)
if (Array.LastIndexOf(illegalTypes, type) > -1 && !isPlayerAdmin(sender))
{
WFPlayer offendingPlayer = AllPlayers.Find(p => p.SteamId.m_SteamID == sender.m_SteamID);

kickPlayer(sender);

WFPlayer offendingPlayer = AllPlayers.Find(p => p.SteamId.m_SteamID == sender.m_SteamID);
messageGlobal($"{offendingPlayer.Username} was kicked for spawning illegal actors");
}

Expand Down
8 changes: 4 additions & 4 deletions Cove/Server/Server.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@ public partial class CoveServer
Thread cbThread;
Thread networkThread;

List<Vector3> fish_points;
List<Vector3> trash_points;
List<Vector3> shoreline_points;
List<Vector3> hidden_spot;
public List<Vector3> fish_points;
public List<Vector3> trash_points;
public List<Vector3> shoreline_points;
public List<Vector3> hidden_spot;

Dictionary<string, IHostedService> services = new();
public readonly object serverActorListLock = new();
Expand Down

0 comments on commit 75281a1

Please sign in to comment.