mirror of
https://github.com/RaidMax/IW4M-Admin.git
synced 2025-06-10 15:20:48 -05:00
refactored the welcome plugin to use a web api instead of a hard coded file
removed deprecated file class don't wait for response when setting dvar/sending command in T6 potential fix for duplicate kick message in JS plugin
This commit is contained in:
@ -220,7 +220,8 @@ namespace SharedLibraryCore
|
||||
{
|
||||
return (queuedEvent.Target != null && queuedEvent.Target.ClientNumber != -1) &&
|
||||
(queuedEvent.Target.State != Player.ClientState.Connected &&
|
||||
queuedEvent.Target.NetworkId != 0);
|
||||
queuedEvent.Target.NetworkId != 0 &&
|
||||
queuedEvent.Origin?.ClientId != 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,107 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
using System.Linq;
|
||||
|
||||
namespace SharedLibraryCore
|
||||
{
|
||||
public class RemoteFile : IFile
|
||||
{
|
||||
readonly string Location;
|
||||
string[] FileCache = new string[0];
|
||||
|
||||
public RemoteFile(string location) : base(string.Empty)
|
||||
{
|
||||
Location = location;
|
||||
}
|
||||
|
||||
private void Retrieve()
|
||||
{
|
||||
using (var cl = new HttpClient())
|
||||
FileCache = cl.GetStringAsync(Location).Result.Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
|
||||
}
|
||||
|
||||
public override long Length()
|
||||
{
|
||||
Retrieve();
|
||||
return FileCache.Sum(l => l.Length);
|
||||
}
|
||||
|
||||
public override Task<string[]> Tail(int lineCount)
|
||||
{
|
||||
return Task.FromResult(FileCache);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public class IFile
|
||||
{
|
||||
public IFile(String fileName)
|
||||
{
|
||||
if (fileName != string.Empty)
|
||||
{
|
||||
Name = fileName;
|
||||
Handle = new StreamReader(new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite, 4096, true), Utilities.EncodingType);
|
||||
|
||||
sze = Handle.BaseStream.Length;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual long Length()
|
||||
{
|
||||
sze = Handle.BaseStream.Length;
|
||||
return sze;
|
||||
}
|
||||
|
||||
public void Close()
|
||||
{
|
||||
Handle?.Close();
|
||||
}
|
||||
|
||||
public String[] ReadAllLines()
|
||||
{
|
||||
return Handle?.ReadToEnd().Split(new char[] { '\n' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
}
|
||||
|
||||
public String GetText()
|
||||
{
|
||||
return Handle?.ReadToEnd();
|
||||
}
|
||||
|
||||
public virtual async Task<String[]> Tail(int lineCount)
|
||||
{
|
||||
var buffer = new List<string>(lineCount);
|
||||
string line;
|
||||
for (int i = 0; i < lineCount; i++)
|
||||
{
|
||||
line = await Handle.ReadLineAsync();
|
||||
if (line == null) return buffer.ToArray();
|
||||
buffer.Add(line);
|
||||
}
|
||||
|
||||
int lastLine = lineCount - 1; //The index of the last line read from the buffer. Everything > this index was read earlier than everything <= this indes
|
||||
|
||||
while (null != (line = await Handle.ReadLineAsync()))
|
||||
{
|
||||
lastLine++;
|
||||
if (lastLine == lineCount) lastLine = 0;
|
||||
buffer[lastLine] = line;
|
||||
}
|
||||
|
||||
if (lastLine == lineCount - 1) return buffer.ToArray();
|
||||
var retVal = new string[lineCount];
|
||||
buffer.CopyTo(lastLine + 1, retVal, 0, lineCount - lastLine - 1);
|
||||
buffer.CopyTo(0, retVal, lineCount - lastLine - 1, lastLine + 1);
|
||||
return retVal;
|
||||
}
|
||||
//END
|
||||
|
||||
private long sze;
|
||||
private readonly String Name;
|
||||
private StreamReader Handle;
|
||||
}
|
||||
}
|
@ -95,6 +95,7 @@ namespace SharedLibraryCore.RCon
|
||||
Ttl = 42,
|
||||
ExclusiveAddressUse = true,
|
||||
};
|
||||
|
||||
connectionState.OnSentData.Reset();
|
||||
connectionState.OnReceivedData.Reset();
|
||||
connectionState.ConnectionAttempts++;
|
||||
@ -103,7 +104,7 @@ namespace SharedLibraryCore.RCon
|
||||
#endif
|
||||
try
|
||||
{
|
||||
response = await SendPayloadAsync(payload);
|
||||
response = await SendPayloadAsync(payload, waitForResponse);
|
||||
connectionState.OnComplete.Release(1);
|
||||
connectionState.ConnectionAttempts = 0;
|
||||
}
|
||||
@ -139,7 +140,7 @@ namespace SharedLibraryCore.RCon
|
||||
return splitResponse;
|
||||
}
|
||||
|
||||
private async Task<byte[]> SendPayloadAsync(byte[] payload)
|
||||
private async Task<byte[]> SendPayloadAsync(byte[] payload, bool waitForResponse)
|
||||
{
|
||||
var connectionState = ActiveQueries[this.Endpoint];
|
||||
var rconSocket = (Socket)connectionState.SendEventArgs.UserToken;
|
||||
@ -171,6 +172,11 @@ namespace SharedLibraryCore.RCon
|
||||
}
|
||||
}
|
||||
|
||||
if (!waitForResponse)
|
||||
{
|
||||
return new byte[0];
|
||||
}
|
||||
|
||||
connectionState.ReceiveEventArgs.SetBuffer(connectionState.ReceiveBuffer);
|
||||
|
||||
// get our response back
|
||||
|
@ -321,7 +321,6 @@ namespace SharedLibraryCore
|
||||
protected int ConnectionErrors;
|
||||
protected List<string> BroadcastMessages;
|
||||
protected TimeSpan LastMessage;
|
||||
protected IFile LogFile;
|
||||
protected DateTime LastPoll;
|
||||
protected ManualResetEventSlim OnRemoteCommandResponse;
|
||||
|
||||
|
@ -24,7 +24,6 @@ namespace SharedLibraryCore.Services
|
||||
PunisherId = newEntity.Punisher.ClientId,
|
||||
LinkId = newEntity.Link.AliasLinkId,
|
||||
Type = newEntity.Type,
|
||||
Active = true,
|
||||
Expires = newEntity.Expires,
|
||||
Offense = newEntity.Offense,
|
||||
When = newEntity.When,
|
||||
@ -69,19 +68,7 @@ namespace SharedLibraryCore.Services
|
||||
public async Task<IList<EFPenalty>> Find(Func<EFPenalty, bool> expression)
|
||||
{
|
||||
throw await Task.FromResult(new Exception());
|
||||
/*
|
||||
return await Task.FromResult(new List<EFPenalty>());
|
||||
// fixme: this is so slow!
|
||||
return await Task.Run(() =>
|
||||
{
|
||||
using (var context = new DatabaseContext())
|
||||
return context.Penalties
|
||||
.Include(p => p.Offender)
|
||||
.Include(p => p.Punisher)
|
||||
.Where(expression)
|
||||
.Where(p => p.Active)
|
||||
.ToList();
|
||||
});*/
|
||||
|
||||
}
|
||||
|
||||
public Task<EFPenalty> Get(int entityID)
|
||||
@ -225,8 +212,6 @@ namespace SharedLibraryCore.Services
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -27,7 +27,13 @@ namespace SharedLibraryCore
|
||||
#endif
|
||||
public static Encoding EncodingType;
|
||||
public static Localization.Layout CurrentLocalization = new Localization.Layout(new Dictionary<string, string>());
|
||||
public static Player IW4MAdminClient(Server server = null) => new Player() { ClientId = 1, Level = Player.Permission.Console, CurrentServer = server };
|
||||
public static Player IW4MAdminClient(Server server = null) => new Player()
|
||||
{
|
||||
ClientId = 1,
|
||||
State = Player.ClientState.Connected,
|
||||
Level = Player.Permission.Console,
|
||||
CurrentServer = server
|
||||
};
|
||||
|
||||
public static string HttpRequest(string location, string header, string headerValue)
|
||||
{
|
||||
|
Reference in New Issue
Block a user