mirror of
https://github.com/RaidMax/IW4M-Admin.git
synced 2025-06-11 15:52:25 -05:00
Miscellanous fixes
This commit is contained in:
@ -15,7 +15,7 @@ namespace IW4MAdmin
|
||||
{
|
||||
// it looks like there's a library error in
|
||||
// Kayak.Http.HttpServerTransactionDelegate.OnError
|
||||
if ((uint)e.HResult ==0x80004003)
|
||||
if ((uint)e.HResult == 0x80004003)
|
||||
return;
|
||||
|
||||
ApplicationManager.GetInstance().Logger.WriteWarning("Web service has encountered an error - " + e.Message);
|
||||
@ -77,19 +77,39 @@ namespace IW4MAdmin
|
||||
|
||||
catch (Exception e)
|
||||
{
|
||||
ApplicationManager.GetInstance().Logger.WriteError($"Webfront error during request");
|
||||
ApplicationManager.GetInstance().Logger.WriteDebug($"Message: {e.Message}");
|
||||
ApplicationManager.GetInstance().Logger.WriteDebug($"Stack Trace: {e.StackTrace}");
|
||||
|
||||
response.OnResponse(new HttpResponseHead()
|
||||
if (e.GetType() == typeof(FormatException))
|
||||
{
|
||||
Status = "500 Internal Server Error",
|
||||
Headers = new Dictionary<string, string>()
|
||||
ApplicationManager.GetInstance().Logger.WriteWarning("Request parameter data format was incorrect");
|
||||
ApplicationManager.GetInstance().Logger.WriteDebug($"Request Path {request.Path}");
|
||||
ApplicationManager.GetInstance().Logger.WriteDebug($"Request Query String {request.QueryString}");
|
||||
|
||||
response.OnResponse(new HttpResponseHead()
|
||||
{
|
||||
Status = "400 Bad Request",
|
||||
Headers = new Dictionary<string, string>()
|
||||
{
|
||||
{ "Content-Type", "text/html" },
|
||||
{ "Content-Length", "0"},
|
||||
}
|
||||
}, new BufferedProducer(""));
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
ApplicationManager.GetInstance().Logger.WriteError($"Webfront error during request");
|
||||
ApplicationManager.GetInstance().Logger.WriteDebug($"Message: {e.Message}");
|
||||
ApplicationManager.GetInstance().Logger.WriteDebug($"Stack Trace: {e.StackTrace}");
|
||||
|
||||
response.OnResponse(new HttpResponseHead()
|
||||
{
|
||||
Status = "500 Internal Server Error",
|
||||
Headers = new Dictionary<string, string>()
|
||||
{
|
||||
{ "Content-Type", "text/html" },
|
||||
{ "Content-Length", "0"},
|
||||
}
|
||||
}, new BufferedProducer(""));
|
||||
}, new BufferedProducer(""));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -98,7 +118,7 @@ namespace IW4MAdmin
|
||||
{
|
||||
ArraySegment<byte> data;
|
||||
|
||||
public BufferedProducer(string data) : this(data, Encoding.UTF8) { }
|
||||
public BufferedProducer(string data) : this(data, Encoding.ASCII) { }
|
||||
public BufferedProducer(string data, Encoding encoding) : this(encoding.GetBytes(data)) { }
|
||||
public BufferedProducer(byte[] data) : this(new ArraySegment<byte>(data)) { }
|
||||
|
||||
@ -109,8 +129,17 @@ namespace IW4MAdmin
|
||||
|
||||
public IDisposable Connect(IDataConsumer channel)
|
||||
{
|
||||
channel?.OnData(data, null);
|
||||
channel?.OnEnd();
|
||||
try
|
||||
{
|
||||
channel?.OnData(data, null);
|
||||
channel?.OnEnd();
|
||||
}
|
||||
|
||||
catch (Exception)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@ -129,19 +158,20 @@ namespace IW4MAdmin
|
||||
|
||||
public bool OnData(ArraySegment<byte> data, Action continuation)
|
||||
{
|
||||
buffer?.Add(data);
|
||||
// this should hopefully clean the non ascii characters out.
|
||||
buffer?.Add(new ArraySegment<byte>(Encoding.ASCII.GetBytes(Encoding.ASCII.GetString(data.ToArray()))));
|
||||
return false;
|
||||
}
|
||||
|
||||
public void OnError(Exception error)
|
||||
{
|
||||
errorCallback?.Invoke(error);
|
||||
// errorCallback?.Invoke(error);
|
||||
}
|
||||
|
||||
public void OnEnd()
|
||||
{
|
||||
var str = buffer
|
||||
.Select(b => Encoding.UTF8.GetString(b.Array, b.Offset, b.Count))
|
||||
.Select(b => Encoding.ASCII.GetString(b.Array, b.Offset, b.Count))
|
||||
.Aggregate((result, next) => result + next);
|
||||
|
||||
resultCallback(str);
|
||||
|
@ -15,7 +15,8 @@ namespace IW4MAdmin
|
||||
Info,
|
||||
Debug,
|
||||
Warning,
|
||||
Error
|
||||
Error,
|
||||
Assert
|
||||
}
|
||||
|
||||
string FileName;
|
||||
@ -72,5 +73,11 @@ namespace IW4MAdmin
|
||||
{
|
||||
Write(msg, LogType.Warning);
|
||||
}
|
||||
|
||||
public void WriteAssert(bool condition, string msg)
|
||||
{
|
||||
if (!condition)
|
||||
Write(msg, LogType.Assert);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -131,11 +131,14 @@ namespace IW4MAdmin
|
||||
|
||||
catch (ServerException e)
|
||||
{
|
||||
Logger.WriteWarning($"Not monitoring server {Conf.IP}:{Conf.Port} due to uncorrectable errors");
|
||||
Logger.WriteError($"Not monitoring server {Conf.IP}:{Conf.Port} due to uncorrectable errors");
|
||||
if (e.GetType() == typeof(DvarException))
|
||||
Logger.WriteError($"Could not get the dvar value for {(e as DvarException).Data["dvar_name"]} (ensure the server has a map loaded)");
|
||||
Logger.WriteDebug($"Could not get the dvar value for {(e as DvarException).Data["dvar_name"]} (ensure the server has a map loaded)");
|
||||
else if (e.GetType() == typeof(NetworkException))
|
||||
Logger.WriteError(e.Message);
|
||||
{
|
||||
Logger.WriteDebug(e.Message);
|
||||
Logger.WriteDebug($"Internal Exception: {e.Data["internal_exception"]}");
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -148,7 +151,7 @@ namespace IW4MAdmin
|
||||
Commands.Add(new CQuit("quit", "quit IW4MAdmin", "q", Player.Permission.Owner, 0, false));
|
||||
Commands.Add(new CKick("kick", "kick a player by name. syntax: !kick <player> <reason>.", "k", Player.Permission.Trusted, 2, true));
|
||||
Commands.Add(new CSay("say", "broadcast message to all players. syntax: !say <message>.", "s", Player.Permission.Moderator, 1, false));
|
||||
Commands.Add(new CTempBan("tempban", "temporarily ban a player for 1 hour. syntax: !tempban <player> <reason>.", "tb", Player.Permission.Moderator, 2, true));
|
||||
Commands.Add(new CTempBan("tempban", "temporarily ban a player for for specified time (defaults to 1 hour). syntax: !tempban <player> <time>(m|h|d|w|y) <reason>.", "tb", Player.Permission.Moderator, 2, true));
|
||||
Commands.Add(new CBan("ban", "permanently ban a player from the server. syntax: !ban <player> <reason>", "b", Player.Permission.SeniorAdmin, 2, true));
|
||||
Commands.Add(new CWhoAmI("whoami", "give information about yourself. syntax: !whoami.", "who", Player.Permission.User, 0, false));
|
||||
Commands.Add(new CList("list", "list active clients syntax: !list.", "l", Player.Permission.Moderator, 0, false));
|
||||
@ -199,7 +202,7 @@ namespace IW4MAdmin
|
||||
if (Status.RequestedTask == null || Status.RequestedTask.IsCompleted)
|
||||
{
|
||||
Status.Update(new Task(() => (Status.Dependant as Server).ProcessUpdatesAsync(Status.GetToken())));
|
||||
if (Status.RunAverage > 1000)
|
||||
if (Status.RunAverage > 1000 + UPDATE_FREQUENCY)
|
||||
Logger.WriteWarning($"Update task average execution is longer than desired for {(Status.Dependant as Server).GetIP()}::{(Status.Dependant as Server).GetPort()} [{Status.RunAverage}ms]");
|
||||
}
|
||||
}
|
||||
|
@ -27,6 +27,12 @@ namespace IW4MAdmin
|
||||
return true;
|
||||
}
|
||||
|
||||
if (P.Name.Length < 3)
|
||||
{
|
||||
await this.ExecuteCommandAsync($"clientkick {P.ClientID} \"Your name must contain atleast 3 characters.\"");
|
||||
return false;
|
||||
}
|
||||
|
||||
Logger.WriteDebug($"Client slot #{P.ClientID} now reserved");
|
||||
|
||||
try
|
||||
@ -332,7 +338,7 @@ namespace IW4MAdmin
|
||||
|
||||
if (ConnectionErrors > 0)
|
||||
{
|
||||
Logger.WriteInfo($"Connection has been reestablished with {IP}:{Port}");
|
||||
Logger.WriteVerbose($"Connection has been reestablished with {IP}:{Port}");
|
||||
Throttled = false;
|
||||
}
|
||||
ConnectionErrors = 0;
|
||||
@ -345,6 +351,7 @@ namespace IW4MAdmin
|
||||
if (ConnectionErrors == 1)
|
||||
{
|
||||
Logger.WriteError($"{e.Message} {IP}:{Port}, reducing polling rate");
|
||||
Logger.WriteDebug($"Internal Exception: {e.Data["internal_exception"]}");
|
||||
Throttled = true;
|
||||
}
|
||||
return;
|
||||
@ -478,7 +485,7 @@ namespace IW4MAdmin
|
||||
this.MaxClients = maxplayers.Value;
|
||||
this.FSGame = game.Value;
|
||||
|
||||
await this.SetDvarAsync("sv_kickbantime", 3600);
|
||||
await this.SetDvarAsync("sv_kickbantime", 60);
|
||||
await this.SetDvarAsync("sv_network_fps", 1000);
|
||||
await this.SetDvarAsync("com_maxfps", 1000);
|
||||
|
||||
@ -655,7 +662,7 @@ namespace IW4MAdmin
|
||||
|
||||
public override async Task TempBan(String Reason, TimeSpan length, Player Target, Player Origin)
|
||||
{
|
||||
await this.ExecuteCommandAsync($"tempbanclient {Target.ClientID } \"^1Player Temporarily Banned: ^5{ Reason }\"");
|
||||
await this.ExecuteCommandAsync($"clientkick {Target.ClientID } \"^1Player Temporarily Banned: ^5{ Reason }\"");
|
||||
Penalty newPenalty = new Penalty(Penalty.Type.TempBan, Reason.StripColors(), Target.NetworkID, Origin.NetworkID, DateTime.Now, Target.IP, DateTime.Now + length);
|
||||
await Task.Run(() =>
|
||||
{
|
||||
@ -678,10 +685,10 @@ namespace IW4MAdmin
|
||||
{
|
||||
if (server.GetPlayersAsList().Count > 0)
|
||||
{
|
||||
var activeClient = server.GetPlayersAsList().Find(x => x.NetworkID == Target.NetworkID);
|
||||
var activeClient = server.GetPlayersAsList().SingleOrDefault(x => x.NetworkID == Target.NetworkID);
|
||||
if (activeClient != null)
|
||||
{
|
||||
await server.ExecuteCommandAsync($"tempbanclient {activeClient.ClientID} \"{Message} ^7 ({Website}) ^7\"");
|
||||
await server.ExecuteCommandAsync($"clientkick {activeClient.ClientID} \"{Message} ^7 ({Website}) ^7\"");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
Binary file not shown.
@ -1,30 +1,47 @@
|
||||
<script src="/webfront/scripts/wordcloud2.js"></script>
|
||||
<div class="chat-history"></div>
|
||||
<canvas id="chat-word-cloud" width="625" height="625"></canvas>
|
||||
<div style="display:none;" class="chat-history">
|
||||
<h2>Chat history </h2>
|
||||
<br/>
|
||||
</div>
|
||||
<div id="word-cloud-wrapper" style="text-align: center; display: none;">
|
||||
<canvas id="chat-word-cloud" width="750" height="750"></canvas>
|
||||
</div>
|
||||
<script>
|
||||
if (parseGet("clientid") == "undefined") {
|
||||
$('#word-cloud-wrapper').show();
|
||||
$.getJSON("/_words", function (result) {
|
||||
var wordList = [];
|
||||
var largestWord = 0;
|
||||
$.each(result, function (i, word) {
|
||||
if (word.Count > largestWord)
|
||||
largestWord = word.Count;
|
||||
wordList.push([word.Word, word.Count]);
|
||||
});
|
||||
|
||||
WordCloud(document.getElementById('chat-word-cloud'), { list: wordList, backgroundColor: "rgb(34,34,34)", minSize: "14pt", color: "rgb(0, 122, 204)", wait: 20, weightFactor: 2 });
|
||||
var _weightFactor = Math.min(1, (1 / largestWord) / 0.003599);
|
||||
WordCloud(document.getElementById('chat-word-cloud'), { list: wordList, backgroundColor: "rgb(34,34,34)", color: "rgb(0, 122, 204)", wait: 0, weightFactor: _weightFactor });
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
else {
|
||||
$('.chat-history').show();
|
||||
$.getJSON("/_clientchat?clientid=" + parseGet("clientid"), function (result) {
|
||||
result = result.sort(function (a, b) {
|
||||
// Turn your strings into dates, and then subtract them
|
||||
// to get a value that is either negative, positive, or zero.
|
||||
return new Date(b.TimeSent) - new Date(a.TimeSent);
|
||||
});
|
||||
|
||||
|
||||
|
||||
if (result.length == 0) {
|
||||
$('.chat-history h2').append('is empty.');
|
||||
}
|
||||
|
||||
else {
|
||||
$('.chat-history h2').append('for <b>' + result[0].ClientName + '</b> (' + result.length + ' messages)');
|
||||
}
|
||||
|
||||
$.each(result, function (i, chat) {
|
||||
var date = new Date(chat.TimeSent);
|
||||
$('.chat-history').append("<div><span>" + date.toLocaleString() + " — </span><span><b>" + chat.Client.Name + "</b></span>: <span>" + chat.Message + "</span></div>");
|
||||
$('.chat-history').append("<div><span>" + date.toLocaleString() + " — </span><span><b>" + chat.ClientName + "</b></span>: <span>" + chat.Message + "</span></div>");
|
||||
});
|
||||
});
|
||||
}
|
||||
|
Reference in New Issue
Block a user