Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions LibraryCore/Network/BaseConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ public abstract class BaseConnection

public bool AdditionalLogging;

public string IPAddress => Client?.Client?.RemoteEndPoint?.ToString()?.Split(':')[0];

protected TcpClient Client;

public DateTime TimeConnected { get; set; }
Expand Down
2 changes: 1 addition & 1 deletion Server/Helpers/JsonImporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public static void Import<T>(JsonSerializerOptions options)
}
catch (Exception ex)
{
SEnvir.Log(ex.Message);
SEnvir.ServerLogger.Log(ex.Message);

XtraMessageBox.Show($"Failed to import all rows.\r\n\r\n{ex.Message}", "Fail", MessageBoxButtons.OK);
}
Expand Down
70 changes: 36 additions & 34 deletions Server/SMain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using PluginCore;
using Server.DBModels;
using Server.Envir;
using Server.Infrastructure.Network.Smtp;
using Server.Views;
using System;
using System.Collections.Generic;
Expand Down Expand Up @@ -47,7 +48,7 @@ private void SetupPlugin()

private void PluginLoader_Log(object sender, PluginCore.LogEventArgs e)
{
SEnvir.Log(e.Message);
SEnvir.ServerLogger.Log(e.Message);
}

private void PluginLoader_ShowView(object sender, ShowViewEventArgs e)
Expand Down Expand Up @@ -129,7 +130,7 @@ private void Application_Idle(object sender, EventArgs e)
}
catch (Exception ex)
{
SEnvir.Log(ex.ToString());
SEnvir.ServerLogger.Log(ex.ToString());
}
}

Expand All @@ -142,6 +143,7 @@ protected override void OnClosing(CancelEventArgs e)

if (SEnvir.EnvirThread == null) return;


SEnvir.Started = false;

while (SEnvir.EnvirThread != null) Thread.Sleep(1);
Expand Down Expand Up @@ -187,7 +189,7 @@ private void UpdateInterface()
StartServerButton.Enabled = SEnvir.EnvirThread == null;
StopServerButton.Enabled = SEnvir.Started;

ConnectionLabel.Caption = string.Format(@"Connections: {0:#,##0}", SEnvir.Connections.Count);
ConnectionLabel.Caption = string.Format(@"Connections: {0:#,##0}", SEnvir.UserConnectionService.ActiveConnections.Count);
ObjectLabel.Caption = string.Format(@"Objects: {0} of {1:#,##0}", SEnvir.ActiveObjects.Count, SEnvir.Objects.Count);
ProcessLabel.Caption = string.Format(@"Process Count: {0:#,##0}", SEnvir.ProcessObjectCount);
LoopLabel.Caption = string.Format(@"Loop Count: {0:#,##0}", SEnvir.LoopCount);
Expand All @@ -200,42 +202,42 @@ private void UpdateInterface()
const decimal MB = KB * 1024;
const decimal GB = MB * 1024;

if (SEnvir.TotalBytesReceived > GB)
TotalDownloadLabel.Caption = string.Format(@"Downloaded: {0:#,##0.0}GB", SEnvir.TotalBytesReceived / GB);
else if (SEnvir.TotalBytesReceived > MB)
TotalDownloadLabel.Caption = string.Format(@"Downloaded: {0:#,##0.0}MB", SEnvir.TotalBytesReceived / MB);
else if (SEnvir.TotalBytesReceived > KB)
TotalDownloadLabel.Caption = string.Format(@"Downloaded: {0:#,##0}KB", SEnvir.TotalBytesReceived / KB);
if (SEnvir.UserConnectionService.TotalBytesReceived > GB)
TotalDownloadLabel.Caption = string.Format(@"Downloaded: {0:#,##0.0}GB", SEnvir.UserConnectionService.TotalBytesReceived / GB);
else if (SEnvir.UserConnectionService.TotalBytesReceived > MB)
TotalDownloadLabel.Caption = string.Format(@"Downloaded: {0:#,##0.0}MB", SEnvir.UserConnectionService.TotalBytesReceived / MB);
else if (SEnvir.UserConnectionService.TotalBytesReceived > KB)
TotalDownloadLabel.Caption = string.Format(@"Downloaded: {0:#,##0}KB", SEnvir.UserConnectionService.TotalBytesReceived / KB);
else
TotalDownloadLabel.Caption = string.Format(@"Downloaded: {0:#,##0}B", SEnvir.TotalBytesReceived);

if (SEnvir.TotalBytesSent > GB)
TotalUploadLabel.Caption = string.Format(@"Uploaded: {0:#,##0.0}GB", SEnvir.TotalBytesSent / GB);
else if (SEnvir.TotalBytesSent > MB)
TotalUploadLabel.Caption = string.Format(@"Uploaded: {0:#,##0.0}MB", SEnvir.TotalBytesSent / MB);
else if (SEnvir.TotalBytesSent > KB)
TotalUploadLabel.Caption = string.Format(@"Uploaded: {0:#,##0}KB", SEnvir.TotalBytesSent / KB);
TotalDownloadLabel.Caption = string.Format(@"Downloaded: {0:#,##0}B", SEnvir.UserConnectionService.TotalBytesReceived);

if (SEnvir.UserConnectionService.TotalBytesSent > GB)
TotalUploadLabel.Caption = string.Format(@"Uploaded: {0:#,##0.0}GB", SEnvir.UserConnectionService.TotalBytesSent / GB);
else if (SEnvir.UserConnectionService.TotalBytesSent > MB)
TotalUploadLabel.Caption = string.Format(@"Uploaded: {0:#,##0.0}MB", SEnvir.UserConnectionService.TotalBytesSent / MB);
else if (SEnvir.UserConnectionService.TotalBytesSent > KB)
TotalUploadLabel.Caption = string.Format(@"Uploaded: {0:#,##0}KB", SEnvir.UserConnectionService.TotalBytesSent / KB);
else
TotalUploadLabel.Caption = string.Format(@"Uploaded: {0:#,##0}B", SEnvir.TotalBytesSent);
TotalUploadLabel.Caption = string.Format(@"Uploaded: {0:#,##0}B", SEnvir.UserConnectionService.TotalBytesSent);


if (SEnvir.DownloadSpeed > GB)
DownloadSpeedLabel.Caption = string.Format(@"D/L Speed: {0:#,##0.0}GBps", SEnvir.DownloadSpeed / GB);
else if (SEnvir.DownloadSpeed > MB)
DownloadSpeedLabel.Caption = string.Format(@"D/L Speed: {0:#,##0.0}MBps", SEnvir.DownloadSpeed / MB);
else if (SEnvir.DownloadSpeed > KB)
DownloadSpeedLabel.Caption = string.Format(@"D/L Speed: {0:#,##0}KBps", SEnvir.DownloadSpeed / KB);
if (SEnvir.UserConnectionService.DownloadSpeed > GB)
DownloadSpeedLabel.Caption = string.Format(@"D/L Speed: {0:#,##0.0}GBps", SEnvir.UserConnectionService.DownloadSpeed / GB);
else if (SEnvir.UserConnectionService.DownloadSpeed > MB)
DownloadSpeedLabel.Caption = string.Format(@"D/L Speed: {0:#,##0.0}MBps", SEnvir.UserConnectionService.DownloadSpeed / MB);
else if (SEnvir.UserConnectionService.DownloadSpeed > KB)
DownloadSpeedLabel.Caption = string.Format(@"D/L Speed: {0:#,##0}KBps", SEnvir.UserConnectionService.DownloadSpeed / KB);
else
DownloadSpeedLabel.Caption = string.Format(@"D/L Speed: {0:#,##0}Bps", SEnvir.DownloadSpeed);

if (SEnvir.UploadSpeed > GB)
UploadSpeedLabel.Caption = string.Format(@"U/L Speed: {0:#,##0.0}GBps", SEnvir.UploadSpeed / GB);
else if (SEnvir.UploadSpeed > MB)
UploadSpeedLabel.Caption = string.Format(@"U/L Speed: {0:#,##0.0}MBps", SEnvir.UploadSpeed / MB);
else if (SEnvir.UploadSpeed > KB)
UploadSpeedLabel.Caption = string.Format(@"U/L Speed: {0:#,##0}KBps", SEnvir.UploadSpeed / KB);
DownloadSpeedLabel.Caption = string.Format(@"D/L Speed: {0:#,##0}Bps", SEnvir.UserConnectionService.DownloadSpeed);

if (SEnvir.UserConnectionService.UploadSpeed > GB)
UploadSpeedLabel.Caption = string.Format(@"U/L Speed: {0:#,##0.0}GBps", SEnvir.UserConnectionService.UploadSpeed / GB);
else if (SEnvir.UserConnectionService.UploadSpeed > MB)
UploadSpeedLabel.Caption = string.Format(@"U/L Speed: {0:#,##0.0}MBps", SEnvir.UserConnectionService.UploadSpeed / MB);
else if (SEnvir.UserConnectionService.UploadSpeed > KB)
UploadSpeedLabel.Caption = string.Format(@"U/L Speed: {0:#,##0}KBps", SEnvir.UserConnectionService.UploadSpeed / KB);
else
UploadSpeedLabel.Caption = string.Format(@"U/L Speed: {0:#,##0}Bps", SEnvir.UploadSpeed);
UploadSpeedLabel.Caption = string.Format(@"U/L Speed: {0:#,##0}Bps", SEnvir.UserConnectionService.UploadSpeed);
}

private void StartServerButton_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
Expand All @@ -248,7 +250,7 @@ private void StartServerButton_ItemClick(object sender, DevExpress.XtraBars.Item
}
catch (Exception ex)
{
SEnvir.Log($"Exception: " + ex.ToString(), true);
SEnvir.ServerLogger.Log($"Exception: " + ex.ToString());
}
}

Expand Down
4 changes: 2 additions & 2 deletions Server/Views/ChatLogView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ public ChatLogView()

private void InterfaceTimer_Tick(object sender, EventArgs e)
{
while (!SEnvir.ChatLogs.IsEmpty)
while (!SEnvir.ChatAppLogs.IsEmpty) //TODO: not sure if this was a bug or intentional? why was it using SEnvir.ChatLogs instead of ChatDisplayLogs
{
string log;

if (!SEnvir.DisplayChatLogs.TryDequeue(out log)) continue;
if (!SEnvir.ChatAppLogs.TryDequeue(out log)) continue;

Logs.Add(log);
}
Expand Down
4 changes: 2 additions & 2 deletions Server/Views/ConfigView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ private void SyncronizeRemoteButton_Click(object sender, EventArgs e)

private void SyncronizeLocalButton_Click(object sender, EventArgs e)
{
SEnvir.Log($"Starting local syncronization...");
SEnvir.ServerLogger.Log($"Starting local syncronization...");

SMain.Session.Save(true);

File.Copy(SMain.Session.SystemPath, Path.Combine(Config.ClientPath, "Data\\", Path.GetFileName(SMain.Session.SystemPath)), true);

SEnvir.Log($"Syncronization completed...");
SEnvir.ServerLogger.Log($"Syncronization completed...");
}

protected override void OnLoad(EventArgs e)
Expand Down
4 changes: 2 additions & 2 deletions Server/Views/MapViewer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ private void RenderEnvironment()
}
catch (Exception ex)
{
SEnvir.Log(ex.ToString());
SEnvir.ServerLogger.Log(ex.ToString());

Manager.AttemptRecovery();
}
Expand Down Expand Up @@ -2152,7 +2152,7 @@ public void Load(string fileName)
}
catch (Exception ex)
{
SEnvir.Log(ex.ToString());
SEnvir.ServerLogger.Log(ex.ToString());
}
TextureValid = false;
}
Expand Down
15 changes: 3 additions & 12 deletions Server/Views/SyncForm.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,8 @@
using MirDB;
using Server.Envir;
using Server.Envir;
using Server.Infrastructure.Network.Http;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Server.Views
Expand All @@ -33,7 +24,7 @@ private void btnSync_Click(object sender, EventArgs e)

string key = Uri.EscapeDataString(txtKey.Text);

var url = $"{txtRemoteIP.Text}?Type={WebServer.SystemDBSyncCommand}&Key={key}";
var url = $"{txtRemoteIP.Text}?Type={HttpWebServer.SystemDBSyncCommand}&Key={key}";
try
{
HttpResponseMessage response = client.PostAsync(url, content).Result;
Expand Down
4 changes: 2 additions & 2 deletions Server/Views/SystemLogView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ public SystemLogView()

private void InterfaceTimer_Tick(object sender, EventArgs e)
{
while (!SEnvir.DisplayLogs.IsEmpty)
while (!SEnvir.ServerAppLogs.IsEmpty)
{
string log;

if (!SEnvir.DisplayLogs.TryDequeue(out log)) continue;
if (!SEnvir.ServerAppLogs.TryDequeue(out log)) continue;

Logs.Add(log);
}
Expand Down
3 changes: 1 addition & 2 deletions ServerCore/Program.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Autofac;
using Library;
using Library;
using Server.Envir;
using System;
using System.Reflection;
Expand Down
3 changes: 2 additions & 1 deletion ServerLibrary/DBModels/AccountInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Library.SystemModels;
using MirDB;
using Server.Envir;
using Server.Infrastructure.Service.Connection;
using System;
using System.Collections.Generic;
using System.Linq;
Expand Down Expand Up @@ -617,7 +618,7 @@ public CharacterInfo LastCharacter


public int WrongPasswordCount;
public SConnection Connection;
public UserConnection Connection;
public string Key;

protected override void OnCreated()
Expand Down
2 changes: 1 addition & 1 deletion ServerLibrary/DBModels/GuildInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ protected override void OnLoaded()
{
if (item.Slot < 0 || item.Slot >= Storage.Length)
{
SEnvir.Log(string.Format("[BAD ITEM] Guild: {0}, Slot: {1}", GuildName, item.Slot));
SEnvir.ServerLogger.Log(string.Format("[BAD ITEM] Guild: {0}, Slot: {1}", GuildName, item.Slot));
continue;
}

Expand Down
5 changes: 3 additions & 2 deletions ServerLibrary/Envir/Commands/Command/Admin/ClearIPBlocks.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Server.Models;
using Server.Infrastructure.Network;
using Server.Models;

namespace Server.Envir.Commands.Command.Admin
{
Expand All @@ -8,7 +9,7 @@ class ClearIPBlocks : AbstractCommand<IAdminCommand>

public override void Action(PlayerObject player)
{
SEnvir.IPBlocks.Clear();
SEnvir.IpManager.Reset(); //TODO: this should be injected but need to rewrite everything to use DI (AutoFac) because reflection based creation is not flexible enough
}
}
}
4 changes: 3 additions & 1 deletion ServerLibrary/Envir/Commands/Command/Admin/GiveGameGold.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
using Server.Envir.Commands.Command;
using Server.Envir.Commands.Command.Admin;
using Server.Envir.Commands.Exceptions;
using Server.Infrastructure.Service.Connection;
using Server.Models;

namespace Server.Envir.Commands.Admin {
namespace Server.Envir.Commands.Admin
{
class GiveGameGold : AbstractParameterizedCommand<IAdminCommand> {
public override string VALUE => "GIVEGAMEGOLD";
public override int PARAMS_LENGTH => 3;
Expand Down
29 changes: 3 additions & 26 deletions ServerLibrary/Envir/Commands/Command/Admin/TakeCastle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Library.SystemModels;
using Server.DBModels;
using Server.Envir.Commands.Exceptions;
using Server.Infrastructure.Network;
using Server.Models;
using System;
using System.Linq;
Expand Down Expand Up @@ -30,19 +31,7 @@ public override void Action(PlayerObject player, string[] vals)
throw new UserCommandException(string.Format("No guild currently owns {0} castle.", castle.Name));
ownerGuild.Castle = null;

foreach (SConnection con in SEnvir.Connections)
{
switch (con.Stage)
{
case GameStage.Game:
case GameStage.Observer:
con.ReceiveChat(string.Format(con.Language.ConquestLost, ownerGuild.GuildName, castle.Name), MessageType.System);
break;
default:
continue;
}
}

SEnvir.BroadcastService.BroadcastSystemMessage(c => string.Format(c.Language.ConquestLost, ownerGuild.GuildName, castle.Name));
SEnvir.Broadcast(new S.GuildCastleInfo { Index = castle.Index, Owner = string.Empty });

foreach (PlayerObject user in SEnvir.Players)
Expand All @@ -53,19 +42,7 @@ public override void Action(PlayerObject player, string[] vals)
else
{
player.Character.Account.GuildMember.Guild.Castle = castle;
foreach (SConnection con in SEnvir.Connections)
{
switch (con.Stage)
{
case GameStage.Game:
case GameStage.Observer:
con.ReceiveChat(string.Format(con.Language.ConquestCapture, player.Character.Account.GuildMember.Guild.GuildName, castle.Name), MessageType.System);
break;
default:
continue;
}
}

SEnvir.BroadcastService.BroadcastSystemMessage(c => string.Format(c.Language.ConquestCapture, player.Character.Account.GuildMember.Guild.GuildName, castle.Name));
SEnvir.Broadcast(new S.GuildCastleInfo { Index = castle.Index, Owner = player.Character.Account.GuildMember.Guild.GuildName });
foreach (PlayerObject user in SEnvir.Players)
user.ApplyCastleBuff();
Expand Down
5 changes: 3 additions & 2 deletions ServerLibrary/Envir/Commands/ErrorHandlingCommandHandler.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Library;
using Server.Envir.Commands.Exceptions;
using Server.Envir.Commands.Handler;
using Server.Infrastructure.Service.Connection;
using Server.Models;
using System;
using System.Collections.Generic;
Expand Down Expand Up @@ -41,13 +42,13 @@ public void Handle(PlayerObject player, string[] commandParts)
player.Connection.ReceiveChat(exception.Message, MessageType.System);
if (!exception.userOnly)
{
foreach (SConnection connection in player.Connection.Observers)
foreach (UserConnection connection in player.Connection.Observers)
connection.ReceiveChat(exception.Message, MessageType.System);
}
}
catch (Exception exception)
{
SEnvir.Log("FatalCommandError [" + player.Name + "]: " + exception.Message);
SEnvir.ServerLogger.Log("FatalCommandError [" + player.Name + "]: " + exception.Message);
player.Connection.ReceiveChat("FatalCommandError: The error has been logged. Contact an admin.", MessageType.System);
}
}
Expand Down
2 changes: 1 addition & 1 deletion ServerLibrary/Envir/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ public static void LoadVersion()
}
catch (Exception ex)
{
SEnvir.Log(ex.ToString());
SEnvir.ServerLogger.Log(ex.ToString());
}
}
}
Expand Down
Loading