feat: Converts OnLogin to a coded generated event (#2070)

This commit is contained in:
Kamron Batman 2025-01-17 15:21:45 -08:00 committed by GitHub
parent 3b698de556
commit 66a257ece2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
25 changed files with 127 additions and 122 deletions

View file

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Net;
using System.Runtime.CompilerServices;
using System.Xml;
using ModernUO.CodeGeneratedEvents;
using ModernUO.Serialization;
using Server.Accounting.Security;
using Server.Misc;
@ -768,31 +769,24 @@ public partial class Account : IAccount, IComparable<Account>
acc.TotalGameTime += Core.Now - pm.SessionStart;
}
public static void OnLogin(Mobile m)
[OnEvent(nameof(PlayerMobile.PlayerLoginEvent))]
public static void OnLogin(PlayerMobile pm)
{
if (m is not PlayerMobile pm)
if (pm.Account is not Account acc || !pm.Young || !acc.Young)
{
return;
}
if (m.Account is not Account acc)
var ts = YoungDuration - acc.TotalGameTime;
var hours = Math.Max((int)ts.TotalHours, 0);
if (hours == 1)
{
return;
pm.SendAsciiMessage($"You will enjoy the benefits and relatively safe status of a young player for {hours} more hour.");
}
if (pm.Young && acc.Young)
else
{
var ts = YoungDuration - acc.TotalGameTime;
var hours = Math.Max((int)ts.TotalHours, 0);
if (hours == 1)
{
m.SendAsciiMessage($"You will enjoy the benefits and relatively safe status of a young player for {hours} more hour.");
}
else
{
m.SendAsciiMessage($"You will enjoy the benefits and relatively safe status of a young player for {hours} more hours.");
}
pm.SendAsciiMessage($"You will enjoy the benefits and relatively safe status of a young player for {hours} more hours.");
}
}

View file

@ -1,7 +1,9 @@
using System;
using System.Buffers;
using System.Collections.Generic;
using ModernUO.CodeGeneratedEvents;
using Server.Gumps;
using Server.Mobiles;
using Server.Network;
namespace Server.Assistants;
@ -45,22 +47,23 @@ public static class AssistantHandler
m.NetState.LogInfo("Failed to negotiate assistant features.");
}
public static void OnLogin(Mobile m)
[OnEvent(nameof(PlayerMobile.PlayerLoginEvent))]
public static void OnLogin(PlayerMobile pm)
{
if (m?.NetState?.Running != true || !Enabled)
if (pm?.NetState?.Running != true || !Enabled)
{
return;
}
m.NetState.SendAssistVersionReq();
m.NetState.SendAssistHandshake();
pm.NetState.SendAssistVersionReq();
pm.NetState.SendAssistHandshake();
if (_handshakes.TryGetValue(m, out var t))
if (_handshakes.TryGetValue(pm, out var t))
{
t?.Stop();
}
_handshakes[m] = Timer.DelayCall(TimeSpan.FromSeconds(30), OnTimeout, m);
_handshakes[pm] = Timer.DelayCall(TimeSpan.FromSeconds(30), OnTimeout, pm);
}
public static void AssistVersion(NetState state, SpanReader reader)

View file

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using ModernUO.CodeGeneratedEvents;
using Server.Mobiles;
using Server.Network;
using Server.Targeting;
@ -15,10 +16,8 @@ namespace Server.Commands
CommandSystem.Register("VisClear", AccessLevel.Counselor, VisClear_OnCommand);
}
public static void OnLogin(Mobile m)
{
(m as PlayerMobile)?.VisibilityList.Clear();
}
[OnEvent(nameof(PlayerMobile.PlayerLoginEvent))]
public static void OnLogin(PlayerMobile pm) => pm.VisibilityList.Clear();
[Usage("Vis")]
[Description("Adds or removes a targeted player from your visibility list. Anyone on your visibility list will be able to see you at all times, even when you're hidden.")]

View file

@ -1291,13 +1291,9 @@ namespace Server.Engines.ConPVP
return false;
}
public static void OnLogin(Mobile m)
[OnEvent(nameof(PlayerMobile.PlayerLoginEvent))]
public static void OnLogin(PlayerMobile pm)
{
if (m is not PlayerMobile pm)
{
return;
}
var dc = pm.DuelContext;
if (dc == null)

View file

@ -1,3 +1,4 @@
using ModernUO.CodeGeneratedEvents;
using Server.Mobiles;
using Server.Regions;
@ -14,12 +15,13 @@ namespace Server.Engines.Doom
Register();
}
public static void OnLogin(Mobile m)
[OnEvent(nameof(PlayerMobile.PlayerLoginEvent))]
public static void OnLogin(PlayerMobile pm)
{
var rect = LeverPuzzleController.lr_Rect;
if (m.X >= rect.X && m.X <= rect.X + 10 && m.Y >= rect.Y && m.Y <= rect.Y + 10 && m.Map == Map.Internal)
if (pm.X >= rect.X && pm.X <= rect.X + 10 && pm.Y >= rect.Y && pm.Y <= rect.Y + 10 && pm.Map == Map.Internal)
{
Timer kick = new LeverPuzzleController.LampRoomKickTimer(m);
Timer kick = new LeverPuzzleController.LampRoomKickTimer(pm);
kick.Start();
}
}

View file

@ -1,5 +1,7 @@
using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using ModernUO.CodeGeneratedEvents;
using Server.Accounting;
using Server.Commands.Generic;
using Server.Engines.ConPVP;
@ -1259,7 +1261,9 @@ public abstract class Faction : IComparable<Faction>
}
}
public static void OnLogin(Mobile m) => CheckLeaveTimer(m);
[OnEvent(nameof(PlayerMobile.PlayerLoginEvent))]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void OnLogin(PlayerMobile pm) => CheckLeaveTimer(pm);
public static void WriteReference(IGenericWriter writer, Faction fact)
{

View file

@ -160,7 +160,8 @@ namespace Server.Engines.PartySystem
}
}
public static void OnLogin(Mobile from)
[OnEvent(nameof(PlayerMobile.PlayerLoginEvent))]
public static void OnLogin(PlayerMobile from)
{
var p = Get(from);

View file

@ -1,7 +1,9 @@
using System;
using ModernUO.CodeGeneratedEvents;
using ModernUO.Serialization;
using Server.Items;
using Server.Misc;
using Server.Mobiles;
namespace Server.Engines.Plants
{
@ -432,7 +434,8 @@ namespace Server.Engines.Plants
}
}
public static void OnLogin(Mobile from)
[OnEvent(nameof(PlayerMobile.PlayerLoginEvent))]
public static void OnLogin(PlayerMobile from)
{
Container cont = from.Backpack;
if (cont != null)

View file

@ -80,9 +80,10 @@ public class PlayerMurderSystem : GenericPersistence
UpdateMurderContext(context);
}
public static void OnLogin(Mobile m)
[OnEvent(nameof(PlayerMobile.PlayerLoginEvent))]
public static void OnLogin(PlayerMobile pm)
{
if (m is not PlayerMobile pm || !GetMurderContext(pm, out var context))
if (!GetMurderContext(pm, out var context))
{
return;
}

View file

@ -1,4 +1,5 @@
using System;
using ModernUO.CodeGeneratedEvents;
using Server.Accounting;
using Server.Gumps;
using Server.Items;
@ -562,35 +563,31 @@ namespace Server.Engines.VeteranRewards
RewardInterval = ServerConfiguration.GetOrUpdateSetting("vetRewards.rewardInterval", TimeSpan.FromDays(30.0));
}
public static void OnLogin(Mobile m)
[OnEvent(nameof(PlayerMobile.PlayerLoginEvent))]
public static void OnLogin(PlayerMobile pm)
{
if (!Enabled)
if (!Enabled || !pm.Alive)
{
return;
}
if (!m.Alive)
{
return;
}
ComputeRewardInfo(pm, out var cur, out var max, out var level);
ComputeRewardInfo(m, out var cur, out var max, out var level);
if (m.SkillsCap is 7000 or 7050 or 7100 or 7150 or 7200)
if (pm.SkillsCap is 7000 or 7050 or 7100 or 7150 or 7200)
{
level = Math.Clamp(level, 0, 4);
if (SkillCapRewards)
{
m.SkillsCap = 7000 + level * 50;
pm.SkillsCap = 7000 + level * 50;
}
else
{
m.SkillsCap = 7000;
pm.SkillsCap = 7000;
}
}
if (Core.ML && m is PlayerMobile pm && !pm.HasStatReward && HasHalfLevel(pm))
if (Core.ML && !pm.HasStatReward && HasHalfLevel(pm))
{
pm.HasStatReward = true;
pm.StatCap += 5;
@ -598,7 +595,7 @@ namespace Server.Engines.VeteranRewards
if (cur < max)
{
m.SendGump(new RewardNoticeGump(m));
pm.SendGump(new RewardNoticeGump(pm));
}
}
}

View file

@ -1,5 +1,7 @@
using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using ModernUO.CodeGeneratedEvents;
using ModernUO.Serialization;
using Server.Collections;
using Server.Engines.Plants;
@ -711,10 +713,9 @@ public abstract partial class BaseBeverage : Item, IHasQuantity
_quantity = reader.ReadInt();
}
public static void OnLogin(Mobile m)
{
CheckHeaveTimer(m);
}
[OnEvent(nameof(PlayerMobile.PlayerLoginEvent))]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void OnLogin(PlayerMobile pm) => CheckHeaveTimer(pm);
public static void CheckHeaveTimer(Mobile from)
{

View file

@ -1,5 +1,7 @@
using System;
using ModernUO.CodeGeneratedEvents;
using Server.Items;
using Server.Mobiles;
using Server.Network;
namespace Server
@ -55,10 +57,8 @@ namespace Server
}
}
public static void OnLogin(Mobile m)
{
m.CheckLightLevels(true);
}
[OnEvent(nameof(PlayerMobile.PlayerLoginEvent))]
public static void OnLogin(PlayerMobile pm) => pm.CheckLightLevels(true);
public static int ComputeLevelFor(Mobile from)
{

View file

@ -1,17 +1,18 @@
using Server.Mobiles;
using Server.Network;
namespace Server.Misc
{
public static class LoginStats
{
public static void OnLogin(Mobile m)
public static void OnLogin(PlayerMobile pm)
{
var userCount = NetState.Instances.Count;
var itemCount = World.Items.Count;
var mobileCount = World.Mobiles.Count;
m.SendMessage(
$"Welcome, {m.Name}! There {(userCount == 1 ? "is" : "are")} currently {userCount} user{(userCount == 1 ? "" : "s")} " +
pm.SendMessage(
$"Welcome, {pm.Name}! There {(userCount == 1 ? "is" : "are")} currently {userCount} user{(userCount == 1 ? "" : "s")} " +
$"online, with {itemCount} item{(itemCount == 1 ? "" : "s")} and {mobileCount} mobile{(mobileCount == 1 ? "" : "s")} in the world."
);
}

View file

@ -2,8 +2,10 @@ using System;
using System.Collections.Generic;
using System.Net;
using System.Text.RegularExpressions;
using ModernUO.CodeGeneratedEvents;
using ModernUO.Serialization;
using Server.Gumps;
using Server.Mobiles;
using Server.Network;
using Server.Prompts;
@ -125,14 +127,15 @@ public partial class ShardPoller : Item
Options[^1] = option;
}
public static void OnLogin(Mobile m)
[OnEvent(nameof(PlayerMobile.PlayerLoginEvent))]
public static void OnLogin(PlayerMobile pm)
{
if (_activePollers.Count == 0)
{
return;
}
Timer.StartTimer(TimeSpan.FromSeconds(1.0), () => EventSink_Login_Callback(m));
Timer.StartTimer(TimeSpan.FromSeconds(1.0), () => EventSink_Login_Callback(pm));
}
private static void EventSink_Login_Callback(Mobile from)

View file

@ -82,17 +82,19 @@ public static class StaminaSystem
RemoveEntry(m as IHasSteps);
}
public static void OnLogin(Mobile m)
[OnEvent(nameof(PlayerMobile.PlayerLoginEvent))]
public static void OnLogin(PlayerMobile pm)
{
bool exists;
if (EnableMountStamina)
{
// Start idle for mount
ref var stepsTaken = ref GetStepsTaken(m.Mount, out var exists);
ref var stepsTaken = ref GetStepsTaken(pm.Mount, out exists);
if (exists)
{
if (stepsTaken.Steps <= 0 || Core.Now >= stepsTaken.IdleStartTime + ResetDuration)
{
_stepsTaken.Remove(m.Mount);
_stepsTaken.Remove(pm.Mount);
}
else
{
@ -100,16 +102,13 @@ public static class StaminaSystem
}
}
_resetHash.Remove(m.Mount);
_resetHash.Remove(pm.Mount);
}
if (m is PlayerMobile pm)
ref var regenStepsTaken = ref RegenSteps(pm, out exists);
if (exists)
{
ref var stepsTaken = ref RegenSteps(pm, out var exists);
if (exists)
{
stepsTaken.IdleStartTime = Core.Now;
}
regenStepsTaken.IdleStartTime = Core.Now;
}
}

View file

@ -1220,6 +1220,10 @@ namespace Server.Mobiles
}
}
[GeneratedEvent(nameof(PlayerLoginEvent))]
public static partial void PlayerLoginEvent(PlayerMobile pm);
[OnEvent(nameof(PlayerLoginEvent))]
public static void OnLogin(PlayerMobile from)
{
if (AccountHandler.LockdownLevel > AccessLevel.Player)

View file

@ -1,3 +1,6 @@
using ModernUO.CodeGeneratedEvents;
using Server.Mobiles;
namespace Server.Misc
{
public static class Strandedness
@ -112,7 +115,8 @@ namespace Server.Misc
return false;
}
public static void OnLogin(Mobile from)
[OnEvent(nameof(PlayerMobile.PlayerLoginEvent))]
public static void OnLogin(PlayerMobile from)
{
if (!IsStranded(from))
{

View file

@ -314,34 +314,10 @@ public static class IncomingAccountPackets
state.SendPlayMusic(m.Region.Music);
StaminaSystem.OnLogin(m);
DuelContext.OnLogin(m);
LightCycle.OnLogin(m);
LoginStats.OnLogin(m);
AnimalForm.OnLogin(m);
BaseBeverage.OnLogin(m);
AntiMacroSystem.OnLogin(m);
Strandedness.OnLogin(m);
ShardPoller.OnLogin(m);
ReaperFormSpell.OnLogin(m);
Party.OnLogin(m);
PlantSystem.OnLogin(m);
LampRoomRegion.OnLogin(m);
HouseRegion.OnLogin(m);
Faction.OnLogin(m);
PlayerMurderSystem.OnLogin(m);
AssistantHandler.OnLogin(m);
VisibilityList.OnLogin(m);
if (m is PlayerMobile pm)
{
PlayerMobile.OnLogin(pm);
PlayerMobile.PlayerLoginEvent(pm);
}
Account.OnLogin(m);
GiftGiving.OnLogin(m);
PreventInaccess.OnLogin(m);
TwistedWealdDesertRegion.OnLogin(m);
RewardSystem.OnLogin(m);
}
private static int GenerateAuthID(this NetState state)

View file

@ -1,4 +1,5 @@
using System;
using ModernUO.CodeGeneratedEvents;
using Server.Gumps;
using Server.Items;
using Server.Mobiles;
@ -29,13 +30,14 @@ public class HouseRegion : BaseRegion
{
}
public static void OnLogin(Mobile m)
[OnEvent(nameof(PlayerMobile.PlayerLoginEvent))]
public static void OnLogin(PlayerMobile pm)
{
var house = BaseHouse.FindHouseAt(m);
var house = BaseHouse.FindHouseAt(pm);
if (house?.Public == false && !house.IsFriend(m))
if (house?.Public == false && !house.IsFriend(pm))
{
m.Location = house.BanLocation;
pm.Location = house.BanLocation;
}
}

View file

@ -1,4 +1,6 @@
using System.Text.Json.Serialization;
using ModernUO.CodeGeneratedEvents;
using Server.Mobiles;
using Server.Network;
using Server.Spells;
using Server.Spells.Ninjitsu;
@ -41,11 +43,12 @@ public class TwistedWealdDesertRegion : MondainRegion
}
}
public static void OnLogin(Mobile m)
[OnEvent(nameof(PlayerMobile.PlayerLoginEvent))]
public static void OnLogin(PlayerMobile pm)
{
if (m.Region.IsPartOf<TwistedWealdDesertRegion>() && m.AccessLevel == AccessLevel.Player)
if (pm.AccessLevel == AccessLevel.Player && pm.Region.IsPartOf<TwistedWealdDesertRegion>())
{
m.NetState.SendSpeedControl(SpeedControlSetting.Walk);
pm.NetState.SendSpeedControl(SpeedControlSetting.Walk);
}
}
}

View file

@ -4,6 +4,7 @@ using System.Collections.Generic;
using System.IO;
using System.Runtime.InteropServices;
using System.Text.Json.Serialization;
using ModernUO.CodeGeneratedEvents;
using Server.Collections;
using Server.Json;
using Server.Mobiles;
@ -138,10 +139,11 @@ public static class AntiMacroSystem
}
}
public static void OnLogin(Mobile m)
[OnEvent(nameof(PlayerMobile.PlayerLoginEvent))]
public static void OnLogin(PlayerMobile pm)
{
// Stop the clear out timer
if (_logoutCleanup?.Remove(m, out var timer) == true)
if (_logoutCleanup?.Remove(pm, out var timer) == true)
{
timer.Stop();
}

View file

@ -1,6 +1,8 @@
using System;
using System.Collections.Generic;
using ModernUO.CodeGeneratedEvents;
using Server.Accounting;
using Server.Mobiles;
namespace Server.Misc
{
@ -19,9 +21,10 @@ namespace Server.Misc
m_Givers.Add(giver);
}
public static void OnLogin(Mobile m)
[OnEvent(nameof(PlayerMobile.PlayerLoginEvent))]
public static void OnLogin(PlayerMobile pm)
{
if (m.Account is not Account acct)
if (pm.Account is not Account acct)
{
return;
}
@ -47,7 +50,7 @@ namespace Server.Misc
continue; // already got one
}
giver.DelayGiveGift(TimeSpan.FromSeconds(5.0), m);
giver.DelayGiveGift(TimeSpan.FromSeconds(5.0), pm);
}
acct.LastLogin = now;

View file

@ -1,4 +1,6 @@
using System.Collections.Generic;
using ModernUO.CodeGeneratedEvents;
using Server.Mobiles;
namespace Server.Misc
{
@ -34,7 +36,8 @@ namespace Server.Misc
m_MoveHistory = new Dictionary<Mobile, LocationInfo>();
}
public static void OnLogin(Mobile from)
[OnEvent(nameof(PlayerMobile.PlayerLoginEvent))]
public static void OnLogin(PlayerMobile from)
{
if (!Enabled)
{

View file

@ -64,11 +64,12 @@ public class AnimalForm : NinjaSpell
new(typeof(Reptalon), 1075202, 11669, 0, 1075222, 90.0, 0x114, 0, 0, false, false)
};
public static void OnLogin(Mobile m)
[OnEvent(nameof(PlayerMobile.PlayerLoginEvent))]
public static void OnLogin(PlayerMobile pm)
{
if (GetContext(m)?.SpeedBoost == true)
if (GetContext(pm)?.SpeedBoost == true)
{
m.NetState.SendSpeedControl(SpeedControlSetting.Mount);
pm.NetState.SendSpeedControl(SpeedControlSetting.Mount);
}
}

View file

@ -1,4 +1,6 @@
using System;
using ModernUO.CodeGeneratedEvents;
using Server.Mobiles;
using Server.Network;
namespace Server.Spells.Spellweaving
@ -27,13 +29,14 @@ namespace Server.Spells.Spellweaving
public virtual int SwingSpeedBonus => 10 + FocusLevel;
public virtual int SpellDamageBonus => 10 + FocusLevel;
public static void OnLogin(Mobile m)
[OnEvent(nameof(PlayerMobile.PlayerLoginEvent))]
public static void OnLogin(PlayerMobile pm)
{
var context = TransformationSpellHelper.GetContext(m);
var context = TransformationSpellHelper.GetContext(pm);
if (context?.Type == typeof(ReaperFormSpell))
{
m.NetState.SendSpeedControl(SpeedControlSetting.Walk);
pm.NetState.SendSpeedControl(SpeedControlSetting.Walk);
}
}