Skip to content

Commit

Permalink
Introduce concept of a head server
Browse files Browse the repository at this point in the history
- Treat the lowest server id as the head server.
- Head server runs the timer task
- When timer task fires, if individual channel actions are required, use
  the RPC manager to send an internal message.
- Update the EpitaphWeeklyReward task to send a message to all channels.
  • Loading branch information
pacampbell committed Dec 12, 2024
1 parent 70e5835 commit fefb32f
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 8 deletions.
9 changes: 9 additions & 0 deletions Arrowgene.Ddon.GameServer/Characters/EpitaphRoadManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1321,5 +1321,14 @@ public List<InstancedGatheringItem> RollGatheringLoot(GameClient client, Charact

return results;
}

public void PerformWeeklyReset()
{
// Clear out cached data related to epitaph weekly rewards
foreach (var client in _Server.ClientLookup.GetAll())
{
client.Character.EpitaphRoadState.WeeklyRewardsClaimed.Clear();
}
}
}
}
7 changes: 6 additions & 1 deletion Arrowgene.Ddon.GameServer/DdonGameServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,13 @@ public DdonGameServer(GameServerSetting setting, IDatabase database, AssetReposi
public override void Start()
{
QuestManager.LoadQuests(this.AssetRepository);
ScheduleManager.Start();
GpCourseManager.EvaluateCourses();

if (ServerUtils.IsHeadServer(this))
{
ScheduleManager.StartServerTasks();
}

LoadChatHandler();
LoadPacketHandler();
base.Start();
Expand Down
12 changes: 12 additions & 0 deletions Arrowgene.Ddon.GameServer/RpcManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@
using Arrowgene.Logging;
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
using System.Net.Http;
using System.Net.Http.Json;
using System.Security.Claims;
using System.Text.Json;
using System.Text.Json.Serialization;
using System.Threading.Tasks;
Expand Down Expand Up @@ -142,6 +144,11 @@ public List<CDataGameServerListInfo> ServerListInfo()
return ChannelInfo.Keys.Select(x => ServerListInfo(x)).ToList();
}

public ServerInfo HeadServer()
{
return ChannelInfo.Values.ToList().OrderBy(x => x.Id).ToList()[0];
}

public CDataGameServerListInfo ServerListInfo(ushort channelId)
{
var info = ChannelInfo[channelId].ToCDataGameServerListInfo();
Expand Down Expand Up @@ -412,5 +419,10 @@ public void AnnounceClanPacket<T>(uint clanId, T packet, uint characterId = 0)
AnnounceClan(clanId, "internal/packet", RpcInternalCommand.AnnouncePacketClan, data);
}
}

public void AnnounceEpitaphWeeklyReset()
{
AnnounceAll("internal/packet", RpcInternalCommand.EpitaphRoadWeeklyReset, null);
}
}
}
2 changes: 1 addition & 1 deletion Arrowgene.Ddon.GameServer/ScheduleManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ private int GetTimerTick(ScheduleInterval interval)
}
}

public void Start()
public void StartServerTasks()
{
Dictionary<TaskType, SchedulerTaskEntry> entries = Server.Database.SelectAllTaskEntries();

Expand Down
12 changes: 12 additions & 0 deletions Arrowgene.Ddon.GameServer/ServerUtils.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System.Linq;

namespace Arrowgene.Ddon.GameServer
{
public class ServerUtils
{
public static bool IsHeadServer(DdonGameServer server)
{
return server.RpcManager.HeadServer().Id == server.Id;
}
}
}
8 changes: 2 additions & 6 deletions Arrowgene.Ddon.GameServer/Tasks/EpitaphSchedulerTask.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Arrowgene.Ddon.Server;
using Arrowgene.Ddon.Shared.Model;
using Arrowgene.Ddon.Shared.Model.Rpc;
using Arrowgene.Ddon.Shared.Model.Scheduler;
using Arrowgene.Logging;
using System;
Expand All @@ -23,14 +24,9 @@ public override bool IsEnabled(DdonGameServer server)
public override void RunTask(DdonGameServer server)
{
Logger.Info("Performing weekly epitaph reset");
server.ChatManager.SendMessage("Performing weekly epitaph reset", string.Empty, string.Empty, LobbyChatMsgType.ManagementAlertN, server.ClientLookup.GetAll());

server.Database.DeleteWeeklyEpitaphClaimedRewards();

foreach (var client in server.ClientLookup.GetAll())
{
client.Character.EpitaphRoadState.WeeklyRewardsClaimed.Clear();
}
server.RpcManager.AnnounceEpitaphWeeklyReset();
}
}
}
6 changes: 6 additions & 0 deletions Arrowgene.Ddon.GameServer/Tasks/SchedulerTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ public SchedulerTask(ScheduleInterval interval, TaskType type)
Interval = interval;
}

/// <summary>
/// Runs on the head server. Should deal with things like modifying the database.
/// Should use the RPC manage if it is required to update clients on different channels
/// or send annoucements to players.
/// </summary>
/// <param name="server"></param>
public abstract void RunTask(DdonGameServer server);
public abstract long NextTimestamp();

Expand Down
3 changes: 3 additions & 0 deletions Arrowgene.Ddon.Rpc.Web/Route/Internal/PacketRoute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,9 @@ public override RpcCommandResult Execute(DdonGameServer gameServer)
Message = $"AnnouncePacketClan Ch.{_entry.Origin} ClanID {data.ClanId} -> {packet.Id}"
};
}
case RpcInternalCommand.EpitaphRoadWeeklyReset:
gameServer.EpitaphRoadManager.PerformWeeklyReset();
return new RpcCommandResult(this, true);
default:
return new RpcCommandResult(this, false);
}
Expand Down
2 changes: 2 additions & 0 deletions Arrowgene.Ddon.Shared/Model/Rpc/RpcInternalCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,7 @@ public enum RpcInternalCommand

AnnouncePacketAll, // RpcPacketData
AnnouncePacketClan, // RpcPacketData

EpitaphRoadWeeklyReset
}
}

0 comments on commit fefb32f

Please sign in to comment.