Skip to content

Commit ffad9a4

Browse files
authored
p34.11 (#515)
1 parent d6e60f3 commit ffad9a4

File tree

7 files changed

+39
-65
lines changed

7 files changed

+39
-65
lines changed

src/Perpetuum.Bootstrapper/Modules/TerrainsModule.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ protected override void Load(ContainerBuilder builder)
2828
{
2929
IMineralConfigurationReader reader = ctx.Resolve<IMineralConfigurationReader>();
3030
OreNpcSpawner oreNpcSpawnlistener = new OreNpcSpawner(zone, ctx.Resolve<INpcReinforcementsRepository>(), ctx.Resolve<ISapAttackersRepository>(), reader);
31-
SapAttackerSpawner sapAttackerSpawnlistener = new SapAttackerSpawner(zone, ctx.Resolve<INpcReinforcementsRepository>(), ctx.Resolve<ISapAttackersRepository>());
31+
//SapAttackerSpawner sapAttackerSpawnlistener = new SapAttackerSpawner(zone, ctx.Resolve<INpcReinforcementsRepository>(), ctx.Resolve<ISapAttackersRepository>());
3232
EventListenerService eventListenerService = ctx.Resolve<EventListenerService>();
3333
eventListenerService.AttachListener(oreNpcSpawnlistener);
34-
eventListenerService.AttachListener(sapAttackerSpawnlistener);
34+
//eventListenerService.AttachListener(sapAttackerSpawnlistener);
3535
if (zone is TrainingZone)
3636
{
3737
GravelRepository repo = ctx.Resolve<GravelRepository>();

src/Perpetuum.Bootstrapper/PerpetuumBootstrapper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,7 @@ private void InitRelayManager()
556556
_ = _builder.RegisterType<SapStateAnnouncer>();
557557
_ = _builder.RegisterType<OreNpcSpawner>().As<NpcSpawnEventHandler<OreNpcSpawnMessage>>();
558558
_ = _builder.RegisterType<NpcReinforcementSpawner>().As<NpcSpawnEventHandler<NpcReinforcementsMessage>>();
559-
_ = _builder.RegisterType<SapAttackerSpawner>().As<NpcSpawnEventHandler<SapAttackersSpawnMessage>>();
559+
//_ = _builder.RegisterType<SapAttackerSpawner>().As<NpcSpawnEventHandler<SapAttackersSpawnMessage>>();
560560
_ = _builder.RegisterType<DiscordIntegrationHandler>();
561561

562562
_ = _builder.RegisterType<EventListenerService>().SingleInstance().OnActivated(e =>

src/Perpetuum/Network/ClientConnection.cs

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -14,36 +14,36 @@ public class ClientConnection : EncryptedTcpConnection
1414
private ClientConnection(Socket socket) : base(socket)
1515
{
1616
_rc4 = new Rc4(FastRandom.NextBytes(40));
17-
ObjectHelper.Swap(ref inIncrement,ref outIncrement);
18-
ObjectHelper.Swap(ref inDecodingByte,ref outEncodingByte);
17+
ObjectHelper.Swap(ref inIncrement, ref outIncrement);
18+
ObjectHelper.Swap(ref inDecodingByte, ref outEncodingByte);
1919
}
2020

2121
protected override void OnReceived(byte[] data)
2222
{
2323
_rc4.Decrypt(data, 1, data.Length - 1);
2424

25-
var dataOffset = 4;
25+
int dataOffset = 4;
2626

27-
var compressionLevel = data[0];
27+
byte compressionLevel = data[0];
2828
if (compressionLevel == 2)
2929
{
3030
data = GZip.Decompress(data, 5);
3131
dataOffset--;
3232
}
3333

34-
var messageText = Encoding.UTF8.GetString(data,dataOffset,data.Length - dataOffset);
34+
string messageText = Encoding.UTF8.GetString(data, dataOffset, data.Length - dataOffset);
3535
OnReceived(messageText);
3636

3737
base.OnReceived(data);
3838
}
3939

4040
public new event Action<string> Received;
4141

42-
private readonly ConcurrentDictionary<Command,ConcurrentQueue<TaskCompletionSource<IMessage>>> _commandQueue = new ConcurrentDictionary<Command, ConcurrentQueue<TaskCompletionSource<IMessage>>>();
42+
private readonly ConcurrentDictionary<Command, ConcurrentQueue<TaskCompletionSource<IMessage>>> _commandQueue = new ConcurrentDictionary<Command, ConcurrentQueue<TaskCompletionSource<IMessage>>>();
4343

4444
public IMessage Send(Command command)
4545
{
46-
var t = SendAsync(command);
46+
Task<IMessage> t = SendAsync(command);
4747
return t.Result;
4848
}
4949

@@ -54,49 +54,49 @@ public Task<IMessage> SendAsync(Command command)
5454

5555
public IMessage Send(string messageText)
5656
{
57-
var t = SendAsync(messageText);
57+
Task<IMessage> t = SendAsync(messageText);
5858
return t.Result;
5959
}
6060

6161
public Task<IMessage> SendAsync(string messageText)
6262
{
63-
var m = Message.Parse(messageText);
63+
Message m = Message.Parse(messageText);
6464
return SendAsync(m);
6565
}
6666

6767
public IMessage Send(IMessage clientMessage)
6868
{
69-
var t = SendAsync(clientMessage);
69+
Task<IMessage> t = SendAsync(clientMessage);
7070
return t.Result;
7171
}
7272

7373
public Task<IMessage> SendAsync(IMessage clientMessage)
7474
{
75-
var source = new TaskCompletionSource<IMessage>();
76-
EnqueueCompletionSource(clientMessage.Command,source);
75+
TaskCompletionSource<IMessage> source = new TaskCompletionSource<IMessage>();
76+
EnqueueCompletionSource(clientMessage.Command, source);
7777
Send(clientMessage.ToBytes());
7878
return source.Task;
7979
}
8080

81-
private void EnqueueCompletionSource(Command command,TaskCompletionSource<IMessage> source)
81+
private void EnqueueCompletionSource(Command command, TaskCompletionSource<IMessage> source)
8282
{
83-
var q = _commandQueue.GetOrAdd(command,() => new ConcurrentQueue<TaskCompletionSource<IMessage>>());
83+
ConcurrentQueue<TaskCompletionSource<IMessage>> q = _commandQueue.GetOrAdd(command, () => new ConcurrentQueue<TaskCompletionSource<IMessage>>());
8484
q.Enqueue(source);
8585
}
8686

8787
public override void Send(byte[] data)
8888
{
89-
var t = new byte[data.Length + 4];
90-
Array.Copy(data,0,t,4,data.Length);
91-
_rc4.Encrypt(t,1,t.Length - 1);
89+
byte[] t = new byte[data.Length + 4];
90+
Array.Copy(data, 0, t, 4, data.Length);
91+
_rc4.Encrypt(t, 1, t.Length - 1);
9292
base.Send(t);
9393
}
9494

9595
public static ClientConnection Connect(IPEndPoint endPoint)
9696
{
97-
var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
97+
Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
9898
socket.Connect(endPoint);
99-
var connect = new ClientConnection(socket);
99+
ClientConnection connect = new ClientConnection(socket);
100100
connect.Receive();
101101
return connect;
102102
}
@@ -108,12 +108,12 @@ public void SendHandshake()
108108

109109
public Task SendHandshakeAsync()
110110
{
111-
var e = Rsa.Encrypt(_rc4.streamKey);
112-
var data = new byte[e.Length + 4];
113-
Array.Copy((Array) e, (int) 0, (Array) data, (int) 4, (int) e.Length);
111+
byte[] e = Rsa.Encrypt(_rc4.streamKey);
112+
byte[] data = new byte[e.Length + 4];
113+
Array.Copy(e, 0, data, 4, e.Length);
114114

115-
var source = new TaskCompletionSource<IMessage>();
116-
EnqueueCompletionSource(Commands.Welcome,source);
115+
TaskCompletionSource<IMessage> source = new TaskCompletionSource<IMessage>();
116+
EnqueueCompletionSource(Commands.Welcome, source);
117117

118118
base.Send(data);
119119
return source.Task;
@@ -122,11 +122,11 @@ public Task SendHandshakeAsync()
122122
public event TcpConnectionEventHandler<IMessage> MessageReceived;
123123
protected virtual void OnReceived(string messageText)
124124
{
125-
var message = Message.Parse(messageText);
126-
MessageReceived?.Invoke(this,message);
125+
Message message = Message.Parse(messageText);
126+
MessageReceived?.Invoke(this, message);
127127

128128

129-
var q = _commandQueue.GetOrDefault(message.Command);
129+
ConcurrentQueue<TaskCompletionSource<IMessage>> q = _commandQueue.GetOrDefault(message.Command);
130130
if (q != null)
131131
{
132132
if (q.TryDequeue(out TaskCompletionSource<IMessage> source))

src/Perpetuum/Services/Channels/ChannelManager.cs

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -323,36 +323,6 @@ public void Talk(string channelName, Character sender, string message, IRequest
323323
sender.Nick,
324324
message));
325325
}
326-
327-
/*
328-
if (channel.Name == HelpChat)
329-
{
330-
// Sending message to discord
331-
332-
string webhookId = _globalConfiguration.WebHookId;
333-
string webhookOAuth = _globalConfiguration.WebHookOAuth;
334-
335-
if (string.IsNullOrEmpty(webhookId) || string.IsNullOrEmpty(webhookOAuth))
336-
{
337-
return;
338-
}
339-
340-
string url = $"https://discord.com/api/webhooks/{webhookId}/{webhookOAuth}";
341-
HttpClient httpClient = new HttpClient();
342-
DiscordPayload payload = new DiscordPayload
343-
{
344-
content = $"**<{sender.Nick}>**: {message}",
345-
};
346-
347-
string json = JsonConvert.SerializeObject(payload);
348-
StringContent content = new StringContent(json, Encoding.UTF8, "application/json");
349-
350-
Task.Run(async () =>
351-
{
352-
HttpResponseMessage response = await httpClient.PostAsync(url, content);
353-
});
354-
}
355-
*/
356326
}
357327
}
358328

src/Perpetuum/Services/EventServices/EventListenerService.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@ public class EventListenerService : Process
1919
private readonly object _lock = new object();
2020
private readonly IDictionary<EventType, IList<IEventProcessor>> _observers;
2121
private readonly ConcurrentQueue<IEventMessage> _queue;
22-
2322
private readonly DiscordSocketClient _client;
23+
24+
//private readonly DiscordSocketClient _client;
2425
private readonly GlobalConfiguration _globalConfiguration;
2526

2627
public EventListenerService(GlobalConfiguration globalConfiguration)
@@ -32,6 +33,7 @@ public EventListenerService(GlobalConfiguration globalConfiguration)
3233
{
3334
GatewayIntents = GatewayIntents.AllUnprivileged | GatewayIntents.MessageContent
3435
});
36+
3537
_globalConfiguration = globalConfiguration;
3638
}
3739

src/Perpetuum/Zones/Intrusion/Outpost.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ protected override void OnUpdate(TimeSpan time)
169169
base.OnUpdate(time);
170170
_decay.OnUpdate(time);
171171

172+
/*
172173
if (CurrentSap != null && _cultistsAttackTimer != null)
173174
{
174175
_cultistsAttackTimer.Update(time);
@@ -178,6 +179,7 @@ protected override void OnUpdate(TimeSpan time)
178179
_eventChannel.PublishMessage(new SapAttackersSpawnMessage(CurrentSap, SapState.Opened, Zone.Id, GetIntrusionSiteStability()));
179180
}
180181
}
182+
*/
181183

182184
if (!Enabled || IntrusionInProgress)
183185
{
@@ -389,7 +391,7 @@ private void OnSAPTakeOver(SAP sap)
389391
TimeSpan randomDelay = FastRandom.NextTimeSpan(TimeSpan.FromMinutes(MinAnnouncementDelay), TimeSpan.FromMinutes(MaxAnnouncementDelay));
390392
DateTime timeStamp = DateTime.UtcNow;
391393

392-
_eventChannel.PublishMessage(new SapAttackersSpawnMessage(CurrentSap, SapState.Completed, Zone.Id, GetIntrusionSiteStability()));
394+
//_eventChannel.PublishMessage(new SapAttackersSpawnMessage(CurrentSap, SapState.Completed, Zone.Id, GetIntrusionSiteStability()));
393395

394396
_ = Task.Delay(randomDelay).ContinueWith((t) =>
395397
{
@@ -585,7 +587,7 @@ private void OnSAPTimeOut(SAP sap)
585587
TimeSpan randomDelay = FastRandom.NextTimeSpan(TimeSpan.FromMinutes(MinAnnouncementDelay), TimeSpan.FromMinutes(MaxAnnouncementDelay));
586588
DateTime timeStamp = DateTime.UtcNow;
587589

588-
_eventChannel.PublishMessage(new SapAttackersSpawnMessage(CurrentSap, SapState.Closed, Zone.Id, GetIntrusionSiteStability()));
590+
//_eventChannel.PublishMessage(new SapAttackersSpawnMessage(CurrentSap, SapState.Closed, Zone.Id, GetIntrusionSiteStability()));
589591
CurrentSap = null;
590592

591593
_ = Task.Delay(randomDelay).ContinueWith((t) =>

src/Perpetuum/Zones/NpcSystem/Npc.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,8 @@ protected override bool IsHostileFor(Unit unit)
192192

193193
internal override bool IsHostile(Npc npc)
194194
{
195-
return (npc.ED.Options.Faction == Faction.Syndicate && npc.ED.Options.Faction != Faction.Syndicate) ||
196-
(npc.ED.Options.Faction != Faction.Syndicate && npc.ED.Options.Faction == Faction.Syndicate);
195+
return (ED.Options.Faction == Faction.Syndicate && npc.ED.Options.Faction != Faction.Syndicate) ||
196+
(ED.Options.Faction != Faction.Syndicate && npc.ED.Options.Faction == Faction.Syndicate);
197197
}
198198

199199
internal override bool IsHostile(SAP sap)

0 commit comments

Comments
 (0)