added nlog logging (todo: custom logger for packets)

This commit is contained in:
Tahir Akhlaq
2016-06-14 05:09:30 +01:00
parent c5516511b0
commit ed0a0a58f7
36 changed files with 5430 additions and 310 deletions
@@ -48,11 +48,13 @@
<Compile Include="Bitfield.cs" /> <Compile Include="Bitfield.cs" />
<Compile Include="Blowfish.cs" /> <Compile Include="Blowfish.cs" />
<Compile Include="EfficientHashTables.cs" /> <Compile Include="EfficientHashTables.cs" />
<Compile Include="Log.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="STA_INIFile.cs" /> <Compile Include="STA_INIFile.cs" />
<Compile Include="Utils.cs" /> <Compile Include="Utils.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets. Other similar extension points exist, see Microsoft.Common.targets.
-136
View File
@@ -1,136 +0,0 @@
using System;
using System.IO;
using System.Text;
using System.Collections.Generic;
using System.Linq;
namespace FFXIVClassic.Common
{
public class Log
{
public string LogDirectory;
public string LogFileName;
public int EnabledLogTypes;
public Queue<Tuple<String, LogType>> LogQueue;
public Log(string path, string file, int enabledtypes)
{
LogQueue = new Queue<Tuple<String, LogType>>();
EnabledLogTypes = enabledtypes;
LogDirectory = path;
LogFileName = file;
}
[Flags]
public enum LogType
{
None = 0x000,
Console = 0x001,
File = 0x002,
Status = 0x004,
Sql = 0x008,
Info = 0x010,
Debug = 0x020,
Error = 0x040,
}
[Flags]
public enum LogColour
{
Status = ConsoleColor.Green,
Sql = ConsoleColor.Magenta,
Info = ConsoleColor.White,
Debug = ConsoleColor.Cyan,
Error = ConsoleColor.Red
}
public void Status(String message, params object[] formatargs)
{
if (formatargs.Any())
message = String.Format(message, formatargs);
QueueMessage(message, LogType.Status);
}
public void Sql(String message, params object[] formatargs)
{
if (formatargs.Any())
message = String.Format(message, formatargs);
QueueMessage(message, LogType.Sql);
}
public void Info(String message, params object[] formatargs)
{
if (formatargs.Any())
message = String.Format(message, formatargs);
QueueMessage(message, LogType.Info);
}
public void Debug(String message, params object[] formatargs)
{
if (formatargs.Any())
message = String.Format(message, formatargs);
QueueMessage(message, LogType.Debug);
}
public void Error(String message, params object[] formatargs)
{
if (formatargs.Any())
message = String.Format(message, formatargs);
QueueMessage(message, LogType.Error);
}
public void Packet(String message, params object[] formatargs)
{
}
private void QueueMessage(String message, LogType colour)
{
LogQueue.Enqueue(Tuple.Create(message, colour));
}
public void WriteMessage(String message, LogType type)
{
if (((LogType)EnabledLogTypes & (LogType)type) == 0)
{
return;
}
string timestamp = String.Format("[{0}]", DateTime.Now.ToString("MM/dd/yyyy HH:mm:ss"));
string messageType = String.Format("[{0}] ", type.ToString().ToUpper());
if ((EnabledLogTypes & (int)LogType.Console) != 0)
{
Console.Write(timestamp);
Console.ForegroundColor = (ConsoleColor)Enum.Parse(typeof(LogColour),type.ToString());
Console.Write(messageType);
Console.ForegroundColor = ConsoleColor.Gray;
Console.WriteLine(message);
}
StringBuilder sb = new StringBuilder();
sb.AppendLine(String.Format("{0}{1}{2}", timestamp, messageType, message));
if ((EnabledLogTypes & (int)LogType.File) != 0)
{
// todo: add param to see if path has been changed during runtime and then check directory/file
if (!Directory.Exists(LogDirectory))
{
Directory.CreateDirectory(LogDirectory);
}
using (FileStream fs = new FileStream(Path.Combine(LogDirectory, LogFileName), FileMode.Append, FileAccess.Write))
using (StreamWriter sw = new StreamWriter(fs))
{
sw.WriteLine(sb.ToString());
}
}
}
}
}
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="NLog" version="4.3.5" targetFramework="net45" />
</packages>
@@ -59,7 +59,7 @@ namespace FFXIVClassic_Lobby_Server
socket.Send(packetBytes); socket.Send(packetBytes);
} }
catch(Exception e) catch(Exception e)
{ Program.Log.Error(String.Format("Weird case, socket was d/ced: {0}", e)); } { Program.Log.Error("Weird case, socket was d/ced: {0}", e); }
} }
} }
+1 -7
View File
@@ -9,9 +9,6 @@ namespace FFXIVClassic_Lobby_Server
public static String OPTIONS_BINDIP; public static String OPTIONS_BINDIP;
public static String OPTIONS_PORT; public static String OPTIONS_PORT;
public static bool OPTIONS_TIMESTAMP = false; public static bool OPTIONS_TIMESTAMP = false;
public static String OPTIONS_LOGPATH;
public static String OPTIONS_LOGFILE;
public static String OPTIONS_LOGLEVEL;
public static String DATABASE_HOST; public static String DATABASE_HOST;
public static String DATABASE_PORT; public static String DATABASE_PORT;
@@ -36,9 +33,6 @@ namespace FFXIVClassic_Lobby_Server
ConfigConstants.OPTIONS_BINDIP = configIni.GetValue("General", "server_ip", "127.0.0.1"); ConfigConstants.OPTIONS_BINDIP = configIni.GetValue("General", "server_ip", "127.0.0.1");
ConfigConstants.OPTIONS_PORT = configIni.GetValue("General", "server_port", "54994"); ConfigConstants.OPTIONS_PORT = configIni.GetValue("General", "server_port", "54994");
ConfigConstants.OPTIONS_TIMESTAMP = configIni.GetValue("General", "showtimestamp", "true").ToLower().Equals("true"); ConfigConstants.OPTIONS_TIMESTAMP = configIni.GetValue("General", "showtimestamp", "true").ToLower().Equals("true");
ConfigConstants.OPTIONS_LOGPATH = configIni.GetValue("General", "log_path", "./logs/");
ConfigConstants.OPTIONS_LOGFILE = configIni.GetValue("General", "log_file_name", String.Format("lobby_{0}_{1}.log", OPTIONS_BINDIP, OPTIONS_PORT));
ConfigConstants.OPTIONS_LOGLEVEL = configIni.GetValue("General", "log_level", "127");
ConfigConstants.DATABASE_HOST = configIni.GetValue("Database", "host", ""); ConfigConstants.DATABASE_HOST = configIni.GetValue("Database", "host", "");
ConfigConstants.DATABASE_PORT = configIni.GetValue("Database", "port", ""); ConfigConstants.DATABASE_PORT = configIni.GetValue("Database", "port", "");
@@ -47,7 +41,7 @@ namespace FFXIVClassic_Lobby_Server
ConfigConstants.DATABASE_PASSWORD = configIni.GetValue("Database", "password", ""); ConfigConstants.DATABASE_PASSWORD = configIni.GetValue("Database", "password", "");
Console.ForegroundColor = ConsoleColor.Green; Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine(String.Format("[OK]")); Console.WriteLine("[OK]");
Console.ForegroundColor = ConsoleColor.Gray; Console.ForegroundColor = ConsoleColor.Gray;
return true; return true;
+4 -4
View File
@@ -100,7 +100,7 @@ namespace FFXIVClassic_Lobby_Server
conn.Dispose(); conn.Dispose();
} }
Program.Log.Sql(String.Format("CID={0} created on 'characters' table.", cid)); Program.Log.Debug("[SQL] CID={0} created on 'characters' table.", cid);
} }
return alreadyExists; return alreadyExists;
@@ -242,7 +242,7 @@ namespace FFXIVClassic_Lobby_Server
} }
Program.Log.Sql(String.Format("CID={0} state updated to active(2).", cid)); Program.Log.Debug("[SQL] CID={0} state updated to active(2).", cid);
} }
public static bool renameCharacter(uint userId, uint characterId, uint serverId, String newName) public static bool renameCharacter(uint userId, uint characterId, uint serverId, String newName)
@@ -286,7 +286,7 @@ namespace FFXIVClassic_Lobby_Server
conn.Dispose(); conn.Dispose();
} }
Program.Log.Sql(String.Format("CID={0} name updated to \"{1}\".", characterId, newName)); Program.Log.Debug("[SQL] CID={0} name updated to \"{1}\".", characterId, newName);
return false; return false;
} }
@@ -320,7 +320,7 @@ namespace FFXIVClassic_Lobby_Server
} }
} }
Program.Log.Sql(String.Format("CID={0} deleted.", characterId)); Program.Log.Debug("[SQL] CID={0} deleted.", characterId);
} }
public static List<World> getServers() public static List<World> getServers()
@@ -65,6 +65,10 @@
<HintPath>..\packages\Newtonsoft.Json.8.0.3\lib\net45\Newtonsoft.Json.dll</HintPath> <HintPath>..\packages\Newtonsoft.Json.8.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
<Private>True</Private> <Private>True</Private>
</Reference> </Reference>
<Reference Include="NLog, Version=4.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c, processorArchitecture=MSIL">
<HintPath>..\packages\NLog.4.3.4\lib\net45\NLog.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" /> <Reference Include="System" />
<Reference Include="System.Core" /> <Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" /> <Reference Include="System.Xml.Linq" />
@@ -105,6 +109,12 @@
<Compile Include="utils\CharacterCreatorUtils.cs" /> <Compile Include="utils\CharacterCreatorUtils.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Content Include="NLog.config">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<None Include="NLog.xsd">
<SubType>Designer</SubType>
</None>
<None Include="packages.config" /> <None Include="packages.config" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
+45
View File
@@ -0,0 +1,45 @@
<?xml version="1.0" encoding="utf-8" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.nlog-project.org/schemas/NLog.xsd NLog.xsd"
autoReload="true"
throwExceptions="false"
internalLogLevel="Off" internalLogFile="c:\temp\nlog-internal.log" >
<!-- optional, add some variabeles
https://github.com/nlog/NLog/wiki/Configuration-file#variables
-->
<variable name="myvar" value="myvalue"/>
<!--
See https://github.com/nlog/nlog/wiki/Configuration-file
for information on customizing logging rules and outputs.
-->
<targets async="true">
<!--
add your targets here
See https://github.com/nlog/NLog/wiki/Targets for possible targets.
See https://github.com/nlog/NLog/wiki/Layout-Renderers for the possible layout renderers.
-->
<!--
Write events to a file with the date in the filename.
<target xsi:type="File" name="f" fileName="${basedir}/logs/${shortdate}.log"
layout="${longdate} ${uppercase:${level}} ${message}" />
-->
<target xsi:type="ColoredConsole" name="console" layout="[${longdate}] [${uppercase:${level}}] ${message}" />
<target xsi:type="File" name="file" fileName="${basedir}/logs/${shortdate}/lobby.log" layout="[${longdate}] [${uppercase:${level}}] ${message}" />
</targets>
<rules>
<!-- add your logging rules here -->
<logger name='*' minlevel='Trace' writeTo='file' />
<logger name='*' minlevel='Trace' writeTo='console' />
<!--
Write all events with minimal level of Debug (So Debug, Info, Warn, Error and Fatal, but not Trace) to "f"
<logger name="*" minlevel="Debug" writeTo="f" />
-->
</rules>
</nlog>
File diff suppressed because it is too large Load Diff
+16 -16
View File
@@ -53,7 +53,7 @@ namespace FFXIVClassic_Lobby_Server
case 0x0F: case 0x0F:
//Mod Retainers //Mod Retainers
default: default:
Program.Log.Debug(String.Format("Unknown command 0x{0:X} received.", subpacket.gameMessage.opcode)); Program.Log.Debug("Unknown command 0x{0:X} received.", subpacket.gameMessage.opcode);
break; break;
} }
} }
@@ -67,7 +67,7 @@ namespace FFXIVClassic_Lobby_Server
byte[] blowfishKey = GenerateKey(securityHandshake.ticketPhrase, securityHandshake.clientNumber); byte[] blowfishKey = GenerateKey(securityHandshake.ticketPhrase, securityHandshake.clientNumber);
client.blowfish = new Blowfish(blowfishKey); client.blowfish = new Blowfish(blowfishKey);
Program.Log.Info(String.Format("SecCNum: 0x{0:X}", securityHandshake.clientNumber)); Program.Log.Info("SecCNum: 0x{0:X}", securityHandshake.clientNumber);
//Respond with acknowledgment //Respond with acknowledgment
BasePacket outgoingPacket = new BasePacket(HardCoded_Packets.g_secureConnectionAcknowledgment); BasePacket outgoingPacket = new BasePacket(HardCoded_Packets.g_secureConnectionAcknowledgment);
@@ -81,8 +81,8 @@ namespace FFXIVClassic_Lobby_Server
SessionPacket sessionPacket = new SessionPacket(packet.data); SessionPacket sessionPacket = new SessionPacket(packet.data);
String clientVersion = sessionPacket.version; String clientVersion = sessionPacket.version;
Program.Log.Info(String.Format("Got acknowledgment for secure session.")); Program.Log.Info("Got acknowledgment for secure session.");
Program.Log.Info(String.Format("CLIENT VERSION: {0}", clientVersion)); Program.Log.Info("CLIENT VERSION: {0}", clientVersion);
uint userId = Database.getUserIdFromSession(sessionPacket.session); uint userId = Database.getUserIdFromSession(sessionPacket.session);
client.currentUserId = userId; client.currentUserId = userId;
@@ -96,11 +96,11 @@ namespace FFXIVClassic_Lobby_Server
BasePacket.encryptPacket(client.blowfish, errorBasePacket); BasePacket.encryptPacket(client.blowfish, errorBasePacket);
client.queuePacket(errorBasePacket); client.queuePacket(errorBasePacket);
Program.Log.Info(String.Format("Invalid session, kicking...")); Program.Log.Info("Invalid session, kicking...");
return; return;
} }
Program.Log.Info(String.Format("USER ID: {0}", userId)); Program.Log.Info("USER ID: {0}", userId);
List<Account> accountList = new List<Account>(); List<Account> accountList = new List<Account>();
Account defaultAccount = new Account(); Account defaultAccount = new Account();
@@ -115,7 +115,7 @@ namespace FFXIVClassic_Lobby_Server
private void ProcessGetCharacters(ClientConnection client, SubPacket packet) private void ProcessGetCharacters(ClientConnection client, SubPacket packet)
{ {
Program.Log.Info(String.Format("{0} => Get characters", client.currentUserId == 0 ? client.getAddress() : "User " + client.currentUserId)); Program.Log.Info("{0} => Get characters", client.currentUserId == 0 ? client.getAddress() : "User " + client.currentUserId);
sendWorldList(client, packet); sendWorldList(client, packet);
sendImportList(client, packet); sendImportList(client, packet);
@@ -128,7 +128,7 @@ namespace FFXIVClassic_Lobby_Server
{ {
SelectCharacterPacket selectCharRequest = new SelectCharacterPacket(packet.data); SelectCharacterPacket selectCharRequest = new SelectCharacterPacket(packet.data);
Program.Log.Info(String.Format("{0} => Select character id {1}", client.currentUserId == 0 ? client.getAddress() : "User " + client.currentUserId, selectCharRequest.characterId)); Program.Log.Info("{0} => Select character id {1}", client.currentUserId == 0 ? client.getAddress() : "User " + client.currentUserId, selectCharRequest.characterId);
Character chara = Database.getCharacter(client.currentUserId, selectCharRequest.characterId); Character chara = Database.getCharacter(client.currentUserId, selectCharRequest.characterId);
World world = null; World world = null;
@@ -187,7 +187,7 @@ namespace FFXIVClassic_Lobby_Server
BasePacket.encryptPacket(client.blowfish, basePacket); BasePacket.encryptPacket(client.blowfish, basePacket);
client.queuePacket(basePacket); client.queuePacket(basePacket);
Program.Log.Info(String.Format("User {0} => Error; invalid server id: \"{1}\"", client.currentUserId, worldId)); Program.Log.Info("User {0} => Error; invalid server id: \"{1}\"", client.currentUserId, worldId);
return; return;
} }
@@ -207,7 +207,7 @@ namespace FFXIVClassic_Lobby_Server
BasePacket.encryptPacket(client.blowfish, basePacket); BasePacket.encryptPacket(client.blowfish, basePacket);
client.queuePacket(basePacket); client.queuePacket(basePacket);
Program.Log.Info(String.Format("User {0} => Error; name taken: \"{1}\"", client.currentUserId, charaReq.characterName)); Program.Log.Info("User {0} => Error; name taken: \"{1}\"", client.currentUserId, charaReq.characterName);
return; return;
} }
else else
@@ -219,7 +219,7 @@ namespace FFXIVClassic_Lobby_Server
client.newCharaName = name; client.newCharaName = name;
} }
Program.Log.Info(String.Format("User {0} => Character reserved \"{1}\"", client.currentUserId, name)); Program.Log.Info("User {0} => Character reserved \"{1}\"", client.currentUserId, name);
break; break;
case 0x02://Make case 0x02://Make
CharaInfo info = CharaInfo.getFromNewCharRequest(charaReq.characterInfoEncoded); CharaInfo info = CharaInfo.getFromNewCharRequest(charaReq.characterInfoEncoded);
@@ -272,7 +272,7 @@ namespace FFXIVClassic_Lobby_Server
cid = client.newCharaCid; cid = client.newCharaCid;
name = client.newCharaName; name = client.newCharaName;
Program.Log.Info(String.Format("User {0} => Character created \"{1}\"", client.currentUserId, name)); Program.Log.Info("User {0} => Character created \"{1}\"", client.currentUserId, name);
break; break;
case 0x03://Rename case 0x03://Rename
@@ -286,20 +286,20 @@ namespace FFXIVClassic_Lobby_Server
BasePacket.encryptPacket(client.blowfish, basePacket); BasePacket.encryptPacket(client.blowfish, basePacket);
client.queuePacket(basePacket); client.queuePacket(basePacket);
Program.Log.Info(String.Format("User {0} => Error; name taken: \"{1}\"", client.currentUserId, charaReq.characterName)); Program.Log.Info("User {0} => Error; name taken: \"{1}\"", client.currentUserId, charaReq.characterName);
return; return;
} }
Program.Log.Info(String.Format("User {0} => Character renamed \"{1}\"", client.currentUserId, name)); Program.Log.Info("User {0} => Character renamed \"{1}\"", client.currentUserId, name);
break; break;
case 0x04://Delete case 0x04://Delete
Database.deleteCharacter(charaReq.characterId, charaReq.characterName); Database.deleteCharacter(charaReq.characterId, charaReq.characterName);
Program.Log.Info(String.Format("User {0} => Character deleted \"{1}\"", client.currentUserId, name)); Program.Log.Info("User {0} => Character deleted \"{1}\"", client.currentUserId, name);
break; break;
case 0x06://Rename Retainer case 0x06://Rename Retainer
Program.Log.Info(String.Format("User {0} => Retainer renamed \"{1}\"", client.currentUserId, name)); Program.Log.Info("User {0} => Retainer renamed \"{1}\"", client.currentUserId, name);
break; break;
} }
+5 -18
View File
@@ -4,12 +4,12 @@ using System.Threading;
using MySql.Data.MySqlClient; using MySql.Data.MySqlClient;
using System.Reflection; using System.Reflection;
using FFXIVClassic.Common; using FFXIVClassic.Common;
using NLog;
namespace FFXIVClassic_Lobby_Server namespace FFXIVClassic_Lobby_Server
{ {
class Program class Program
{ {
public static Log Log; public static Logger Log;
static void Main(string[] args) static void Main(string[] args)
{ {
@@ -24,20 +24,7 @@ namespace FFXIVClassic_Lobby_Server
if (!ConfigConstants.load()) if (!ConfigConstants.load())
startServer = false; startServer = false;
Log = new Log(ConfigConstants.OPTIONS_LOGPATH, ConfigConstants.OPTIONS_LOGFILE, Int32.Parse(ConfigConstants.OPTIONS_LOGLEVEL)); Log = LogManager.GetCurrentClassLogger();
Thread thread = new Thread(() =>
{
while (true)
{
if (Log.LogQueue.Count > 0)
{
var message = Program.Log.LogQueue.Dequeue();
Program.Log.WriteMessage(message.Item1, message.Item2);
}
}
});
thread.Start();
Program.Log.Info("--------FFXIV 1.0 Lobby Server--------"); Program.Log.Info("--------FFXIV 1.0 Lobby Server--------");
@@ -47,7 +34,7 @@ namespace FFXIVClassic_Lobby_Server
Program.Log.Info("Version: " + vers.ToString()); Program.Log.Info("Version: " + vers.ToString());
//Test DB Connection //Test DB Connection
Program.Log.Info(String.Format("Testing DB connection to \"{0}\"... ", ConfigConstants.DATABASE_HOST)); Program.Log.Info("Testing DB connection to \"{0}\"... ", ConfigConstants.DATABASE_HOST);
using (MySqlConnection conn = new MySqlConnection(String.Format("Server={0}; Port={1}; Database={2}; UID={3}; Password={4}", ConfigConstants.DATABASE_HOST, ConfigConstants.DATABASE_PORT, ConfigConstants.DATABASE_NAME, ConfigConstants.DATABASE_USERNAME, ConfigConstants.DATABASE_PASSWORD))) using (MySqlConnection conn = new MySqlConnection(String.Format("Server={0}; Port={1}; Database={2}; UID={3}; Password={4}", ConfigConstants.DATABASE_HOST, ConfigConstants.DATABASE_PORT, ConfigConstants.DATABASE_NAME, ConfigConstants.DATABASE_USERNAME, ConfigConstants.DATABASE_PASSWORD)))
{ {
try try
@@ -55,7 +42,7 @@ namespace FFXIVClassic_Lobby_Server
conn.Open(); conn.Open();
conn.Close(); conn.Close();
Program.Log.Status("[OK]"); Program.Log.Info("[OK]");
} }
catch (MySqlException e) catch (MySqlException e)
{ {
+7 -6
View File
@@ -5,6 +5,7 @@ using System.Net.Sockets;
using System.Threading; using System.Threading;
using FFXIVClassic_Lobby_Server.packets; using FFXIVClassic_Lobby_Server.packets;
using FFXIVClassic.Common; using FFXIVClassic.Common;
using NLog;
namespace FFXIVClassic_Lobby_Server namespace FFXIVClassic_Lobby_Server
{ {
@@ -25,7 +26,7 @@ namespace FFXIVClassic_Lobby_Server
private void socketCleanup() private void socketCleanup()
{ {
Program.Log.Debug(String.Format("Cleanup thread started; it will run every {0} seconds.", CLEANUP_THREAD_SLEEP_TIME)); Program.Log.Info("Cleanup thread started; it will run every {0} seconds.", CLEANUP_THREAD_SLEEP_TIME);
while (!killCleanupThread) while (!killCleanupThread)
{ {
int count = 0; int count = 0;
@@ -40,7 +41,7 @@ namespace FFXIVClassic_Lobby_Server
} }
} }
if (count != 0) if (count != 0)
Program.Log.Status(String.Format("{0} connections were cleaned up.", count)); Program.Log.Info("{0} connections were cleaned up.", count);
Thread.Sleep(CLEANUP_THREAD_SLEEP_TIME*1000); Thread.Sleep(CLEANUP_THREAD_SLEEP_TIME*1000);
} }
} }
@@ -80,7 +81,7 @@ namespace FFXIVClassic_Lobby_Server
} }
Console.ForegroundColor = ConsoleColor.White; Console.ForegroundColor = ConsoleColor.White;
Program.Log.Debug(String.Format("Lobby Server has started @ {0}:{1}", (mServerSocket.LocalEndPoint as IPEndPoint).Address, (mServerSocket.LocalEndPoint as IPEndPoint).Port)); Program.Log.Debug("Lobby Server has started @ {0}:{1}", (mServerSocket.LocalEndPoint as IPEndPoint).Address, (mServerSocket.LocalEndPoint as IPEndPoint).Port);
Console.ForegroundColor = ConsoleColor.Gray; Console.ForegroundColor = ConsoleColor.Gray;
mProcessor = new PacketProcessor(); mProcessor = new PacketProcessor();
@@ -105,7 +106,7 @@ namespace FFXIVClassic_Lobby_Server
conn.socket.BeginReceive(conn.buffer, 0, conn.buffer.Length, SocketFlags.None, new AsyncCallback(receiveCallback), conn); conn.socket.BeginReceive(conn.buffer, 0, conn.buffer.Length, SocketFlags.None, new AsyncCallback(receiveCallback), conn);
//Queue the accept of the next incomming connection //Queue the accept of the next incomming connection
mServerSocket.BeginAccept(new AsyncCallback(acceptCallback), mServerSocket); mServerSocket.BeginAccept(new AsyncCallback(acceptCallback), mServerSocket);
Program.Log.Status(String.Format("Connection {0}:{1} has connected.", (conn.socket.RemoteEndPoint as IPEndPoint).Address, (conn.socket.RemoteEndPoint as IPEndPoint).Port)); Program.Log.Info("Connection {0}:{1} has connected.", (conn.socket.RemoteEndPoint as IPEndPoint).Address, (conn.socket.RemoteEndPoint as IPEndPoint).Port);
} }
catch (SocketException) catch (SocketException)
{ {
@@ -179,7 +180,7 @@ namespace FFXIVClassic_Lobby_Server
} }
else else
{ {
Program.Log.Status(String.Format("{0} has disconnected.", conn.currentUserId == 0 ? conn.getAddress() : "User " + conn.currentUserId)); Program.Log.Info("{0} has disconnected.", conn.currentUserId == 0 ? conn.getAddress() : "User " + conn.currentUserId);
lock (mConnectionList) lock (mConnectionList)
{ {
@@ -192,7 +193,7 @@ namespace FFXIVClassic_Lobby_Server
{ {
if (conn.socket != null) if (conn.socket != null)
{ {
Program.Log.Status(String.Format("{0} has disconnected.", conn.currentUserId == 0 ? conn.getAddress() : "User " + conn.currentUserId)); Program.Log.Info("{0} has disconnected.", conn.currentUserId == 0 ? conn.getAddress() : "User " + conn.currentUserId);
lock (mConnectionList) lock (mConnectionList)
{ {
@@ -4,4 +4,7 @@
<package id="Dapper" version="1.42" targetFramework="net45" /> <package id="Dapper" version="1.42" targetFramework="net45" />
<package id="MySql.Data" version="6.9.7" targetFramework="net45" /> <package id="MySql.Data" version="6.9.7" targetFramework="net45" />
<package id="Newtonsoft.Json" version="8.0.3" targetFramework="net45" /> <package id="Newtonsoft.Json" version="8.0.3" targetFramework="net45" />
<package id="NLog" version="4.3.4" targetFramework="net45" />
<package id="NLog.Config" version="4.3.4" targetFramework="net45" />
<package id="NLog.Schema" version="4.3.4" targetFramework="net45" />
</packages> </packages>
@@ -336,7 +336,7 @@ namespace FFXIVClassic_Lobby_Server.packets
#if DEBUG #if DEBUG
Console.BackgroundColor = ConsoleColor.DarkYellow; Console.BackgroundColor = ConsoleColor.DarkYellow;
Program.Log.Debug(String.Format("IsAuth: {0} Size: 0x{1:X}, NumSubpackets: {2}{3}{4}", header.isAuthenticated, header.packetSize, header.numSubpackets, Environment.NewLine, Utils.ByteArrayToHex(getHeaderBytes()))); Program.Log.Debug("IsAuth: {0} Size: 0x{1:X}, NumSubpackets: {2}{3}{4}", header.isAuthenticated, header.packetSize, header.numSubpackets, Environment.NewLine, Utils.ByteArrayToHex(getHeaderBytes()));
foreach (SubPacket sub in getSubpackets()) foreach (SubPacket sub in getSubpackets())
{ {
@@ -140,20 +140,14 @@ namespace FFXIVClassic_Lobby_Server.packets
public void debugPrintSubPacket() public void debugPrintSubPacket()
{ {
#if DEBUG #if DEBUG
Console.BackgroundColor = ConsoleColor.DarkRed; Program.Log.Debug("Size: 0x{0:X}{1}{2}", header.subpacketSize, Environment.NewLine, Utils.ByteArrayToHex(getHeaderBytes()));
Program.Log.Debug(String.Format("Size: 0x{0:X}{1}{2}", header.subpacketSize, Environment.NewLine, Utils.ByteArrayToHex(getHeaderBytes())));
if (header.type == 0x03) if (header.type == 0x03)
{ {
Program.Log.Debug(String.Format("Opcode: 0x{0:X}{1}{2}", gameMessage.opcode, Environment.NewLine, Utils.ByteArrayToHex(getGameMessageBytes(), SUBPACKET_SIZE))); Program.Log.Debug("Opcode: 0x{0:X}{1}{2}", gameMessage.opcode, Environment.NewLine, Utils.ByteArrayToHex(getGameMessageBytes(), SUBPACKET_SIZE));
} }
Console.BackgroundColor = ConsoleColor.DarkMagenta; Program.Log.Debug("Data: {0}{1}", Environment.NewLine, Utils.ByteArrayToHex(data, SUBPACKET_SIZE + GAMEMESSAGE_SIZE));
Program.Log.Debug(String.Format("Data: {0}{1}", Environment.NewLine, Utils.ByteArrayToHex(data, SUBPACKET_SIZE + GAMEMESSAGE_SIZE)));
Console.BackgroundColor = ConsoleColor.Black;
#endif #endif
} }
+1 -1
View File
@@ -46,7 +46,7 @@ namespace FFXIVClassic_Map_Server
socket.Send(packetBytes); socket.Send(packetBytes);
} }
catch (Exception e) catch (Exception e)
{ Program.Log.Error(String.Format("Weird case, socket was d/ced: {0}", e)); } { Program.Log.Error("Weird case, socket was d/ced: {0}", e); }
} }
} }
+4 -4
View File
@@ -142,7 +142,7 @@ namespace FFXIVClassic_Map_Server
foreach (KeyValuePair<uint, ConnectedPlayer> entry in mConnectedPlayerList) foreach (KeyValuePair<uint, ConnectedPlayer> entry in mConnectedPlayerList)
{ {
Player p = entry.Value.getActor(); Player p = entry.Value.getActor();
Program.Log.Info(String.Format("{0}\'s position: ZoneID: {1}, X: {2}, Y: {3}, Z: {4}, Rotation: {5}", p.customDisplayName, p.zoneId, p.positionX, p.positionY, p.positionZ, p.rotation)); Program.Log.Info("{0}\'s position: ZoneID: {1}, X: {2}, Y: {3}, Z: {4}, Rotation: {5}", p.customDisplayName, p.zoneId, p.positionX, p.positionY, p.positionZ, p.rotation);
} }
} }
} }
@@ -607,7 +607,7 @@ namespace FFXIVClassic_Map_Server
{ {
if (client != null) if (client != null)
{ {
Program.Log.Info(String.Format("Got request to reset zone: {0}", client.getActor().zoneId)); Program.Log.Info("Got request to reset zone: {0}", client.getActor().zoneId);
client.getActor().zone.clear(); client.getActor().zone.clear();
client.getActor().zone.addActorToZone(client.getActor()); client.getActor().zone.addActorToZone(client.getActor());
client.getActor().sendInstanceUpdate(); client.getActor().sendInstanceUpdate();
@@ -621,11 +621,11 @@ namespace FFXIVClassic_Map_Server
#region !reloaditems #region !reloaditems
else if (split[0].Equals("reloaditems")) else if (split[0].Equals("reloaditems"))
{ {
Program.Log.Info(String.Format("Got request to reload item gamedata")); Program.Log.Info("Got request to reload item gamedata");
sendMessage(client, "Reloading Item Gamedata..."); sendMessage(client, "Reloading Item Gamedata...");
gamedataItems.Clear(); gamedataItems.Clear();
gamedataItems = Database.getItemGamedata(); gamedataItems = Database.getItemGamedata();
Program.Log.Info(String.Format("Loaded {0} items.", gamedataItems.Count)); Program.Log.Info("Loaded {0} items.", gamedataItems.Count);
sendMessage(client, String.Format("Loaded {0} items.", gamedataItems.Count)); sendMessage(client, String.Format("Loaded {0} items.", gamedataItems.Count));
return true; return true;
} }
+1 -7
View File
@@ -9,9 +9,6 @@ namespace FFXIVClassic_Map_Server
public static String OPTIONS_BINDIP; public static String OPTIONS_BINDIP;
public static String OPTIONS_PORT; public static String OPTIONS_PORT;
public static bool OPTIONS_TIMESTAMP = false; public static bool OPTIONS_TIMESTAMP = false;
public static String OPTIONS_LOGPATH;
public static String OPTIONS_LOGFILE;
public static String OPTIONS_LOGLEVEL;
public static uint DATABASE_WORLDID; public static uint DATABASE_WORLDID;
public static String DATABASE_HOST; public static String DATABASE_HOST;
@@ -37,9 +34,6 @@ namespace FFXIVClassic_Map_Server
ConfigConstants.OPTIONS_BINDIP = configIni.GetValue("General", "server_ip", "127.0.0.1"); ConfigConstants.OPTIONS_BINDIP = configIni.GetValue("General", "server_ip", "127.0.0.1");
ConfigConstants.OPTIONS_PORT = configIni.GetValue("General", "server_port", "54992"); ConfigConstants.OPTIONS_PORT = configIni.GetValue("General", "server_port", "54992");
ConfigConstants.OPTIONS_TIMESTAMP = configIni.GetValue("General", "showtimestamp", "true").ToLower().Equals("true"); ConfigConstants.OPTIONS_TIMESTAMP = configIni.GetValue("General", "showtimestamp", "true").ToLower().Equals("true");
ConfigConstants.OPTIONS_LOGPATH = configIni.GetValue("General", "log_path", "./logs/");
ConfigConstants.OPTIONS_LOGFILE = configIni.GetValue("General", "log_file_name", String.Format("map_{0}_{1}.log", OPTIONS_BINDIP, OPTIONS_PORT));
ConfigConstants.OPTIONS_LOGLEVEL = configIni.GetValue("General", "log_level", "127");
ConfigConstants.DATABASE_WORLDID = UInt32.Parse(configIni.GetValue("Database", "worldid", "0")); ConfigConstants.DATABASE_WORLDID = UInt32.Parse(configIni.GetValue("Database", "worldid", "0"));
ConfigConstants.DATABASE_HOST = configIni.GetValue("Database", "host", ""); ConfigConstants.DATABASE_HOST = configIni.GetValue("Database", "host", "");
@@ -49,7 +43,7 @@ namespace FFXIVClassic_Map_Server
ConfigConstants.DATABASE_PASSWORD = configIni.GetValue("Database", "password", ""); ConfigConstants.DATABASE_PASSWORD = configIni.GetValue("Database", "password", "");
Console.ForegroundColor = ConsoleColor.Green; Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine(String.Format("[OK]")); Console.WriteLine("[OK]");
Console.ForegroundColor = ConsoleColor.Gray; Console.ForegroundColor = ConsoleColor.Gray;
return true; return true;
+1 -1
View File
@@ -322,7 +322,7 @@ namespace FFXIVClassic_Map_Server
int slot = player.getQuestSlot(quest.actorId); int slot = player.getQuestSlot(quest.actorId);
if (slot == -1) if (slot == -1)
{ {
Program.Log.Error(String.Format("Tried saving quest player didn't have: Player: {0:x}, QuestId: {0:x}", player.actorId, quest.actorId)); Program.Log.Error("Tried saving quest player didn't have: Player: {0:x}, QuestId: {0:x}", player.actorId, quest.actorId);
return; return;
} }
else else
@@ -57,6 +57,10 @@
<HintPath>..\packages\Newtonsoft.Json.8.0.3\lib\net45\Newtonsoft.Json.dll</HintPath> <HintPath>..\packages\Newtonsoft.Json.8.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
<Private>True</Private> <Private>True</Private>
</Reference> </Reference>
<Reference Include="NLog, Version=4.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c, processorArchitecture=MSIL">
<HintPath>..\packages\NLog.4.3.5\lib\net45\NLog.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" /> <Reference Include="System" />
<Reference Include="System.Core" /> <Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" /> <Reference Include="System.Xml.Linq" />
@@ -268,6 +272,12 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Include="App.config" /> <None Include="App.config" />
<Content Include="NLog.config">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<None Include="NLog.xsd">
<SubType>Designer</SubType>
</None>
<None Include="packages.config" /> <None Include="packages.config" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
+45
View File
@@ -0,0 +1,45 @@
<?xml version="1.0" encoding="utf-8" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.nlog-project.org/schemas/NLog.xsd NLog.xsd"
autoReload="true"
throwExceptions="false"
internalLogLevel="Off" internalLogFile="c:\temp\nlog-internal.log" >
<!-- optional, add some variabeles
https://github.com/nlog/NLog/wiki/Configuration-file#variables
-->
<variable name="myvar" value="myvalue"/>
<!--
See https://github.com/nlog/nlog/wiki/Configuration-file
for information on customizing logging rules and outputs.
-->
<targets async="true">
<!--
add your targets here
See https://github.com/nlog/NLog/wiki/Targets for possible targets.
See https://github.com/nlog/NLog/wiki/Layout-Renderers for the possible layout renderers.
-->
<!--
Write events to a file with the date in the filename.
<target xsi:type="File" name="f" fileName="${basedir}/logs/${shortdate}.log"
layout="${longdate} ${uppercase:${level}} ${message}" />
-->
<target xsi:type="ColoredConsole" name="console" layout="[${longdate}] [${uppercase:${level}}] ${message}" />
<target xsi:type="File" name="file" fileName="${basedir}/logs/${shortdate}/map.log" layout="[${longdate}] [${uppercase:${level}}] ${message}"/>
</targets>
<rules>
<!-- add your logging rules here -->
<logger name='*' minlevel='Trace' writeTo='file' />
<logger name='*' minlevel='Trace' writeTo='console' />
<!--
Write all events with minimal level of Debug (So Debug, Info, Warn, Error and Fatal, but not Trace) to "f"
<logger name="*" minlevel="Debug" writeTo="f" />
-->
</rules>
</nlog>
File diff suppressed because it is too large Load Diff
+7 -7
View File
@@ -127,9 +127,9 @@ namespace FFXIVClassic_Map_Server
player.setConnection(packet.header.connectionType, client); player.setConnection(packet.header.connectionType, client);
if (packet.header.connectionType == BasePacket.TYPE_ZONE) if (packet.header.connectionType == BasePacket.TYPE_ZONE)
Program.Log.Debug(String.Format("Got {0} connection for ActorID {1} @ {2}.", "zone", actorID, client.getAddress())); Program.Log.Debug("Got {0} connection for ActorID {1} @ {2}.", "zone", actorID, client.getAddress());
else if (packet.header.connectionType == BasePacket.TYPE_CHAT) else if (packet.header.connectionType == BasePacket.TYPE_CHAT)
Program.Log.Debug(String.Format("Got {0} connection for ActorID {1} @ {2}.", "chat", actorID, client.getAddress())); Program.Log.Debug("Got {0} connection for ActorID {1} @ {2}.", "chat", actorID, client.getAddress());
//Create player actor //Create player actor
reply1.debugPrintPacket(); reply1.debugPrintPacket();
@@ -180,7 +180,7 @@ namespace FFXIVClassic_Map_Server
//Chat Received //Chat Received
case 0x0003: case 0x0003:
ChatMessagePacket chatMessage = new ChatMessagePacket(subpacket.data); ChatMessagePacket chatMessage = new ChatMessagePacket(subpacket.data);
Program.Log.Info(String.Format("Got type-{5} message: {0} @ {1}, {2}, {3}, Rot: {4}", chatMessage.message, chatMessage.posX, chatMessage.posY, chatMessage.posZ, chatMessage.posRot, chatMessage.logType)); Program.Log.Info("Got type-{5} message: {0} @ {1}, {2}, {3}, Rot: {4}", chatMessage.message, chatMessage.posX, chatMessage.posY, chatMessage.posZ, chatMessage.posRot, chatMessage.logType);
subpacket.debugPrintSubPacket(); subpacket.debugPrintSubPacket();
if (chatMessage.message.StartsWith("!")) if (chatMessage.message.StartsWith("!"))
@@ -268,7 +268,7 @@ namespace FFXIVClassic_Map_Server
ownerActor = player.getActor().currentDirector; ownerActor = player.getActor().currentDirector;
else else
{ {
Program.Log.Debug(String.Format("\n===Event START===\nCould not find actor 0x{0:X} for event started by caller: 0x{1:X}\nEvent Starter: {2}\nParams: {3}", eventStart.actorID, eventStart.scriptOwnerActorID, eventStart.triggerName, LuaUtils.dumpParams(eventStart.luaParams))); Program.Log.Debug("\n===Event START===\nCould not find actor 0x{0:X} for event started by caller: 0x{1:X}\nEvent Starter: {2}\nParams: {3}", eventStart.actorID, eventStart.scriptOwnerActorID, eventStart.triggerName, LuaUtils.dumpParams(eventStart.luaParams));
break; break;
} }
} }
@@ -276,7 +276,7 @@ namespace FFXIVClassic_Map_Server
LuaEngine.doActorOnEventStarted(player.getActor(), ownerActor, eventStart); LuaEngine.doActorOnEventStarted(player.getActor(), ownerActor, eventStart);
Program.Log.Debug(String.Format("\n===Event START===\nSource Actor: 0x{0:X}\nCaller Actor: 0x{1:X}\nVal1: 0x{2:X}\nVal2: 0x{3:X}\nEvent Starter: {4}\nParams: {5}", eventStart.actorID, eventStart.scriptOwnerActorID, eventStart.val1, eventStart.val2, eventStart.triggerName, LuaUtils.dumpParams(eventStart.luaParams))); Program.Log.Debug("\n===Event START===\nSource Actor: 0x{0:X}\nCaller Actor: 0x{1:X}\nVal1: 0x{2:X}\nVal2: 0x{3:X}\nEvent Starter: {4}\nParams: {5}", eventStart.actorID, eventStart.scriptOwnerActorID, eventStart.val1, eventStart.val2, eventStart.triggerName, LuaUtils.dumpParams(eventStart.luaParams));
break; break;
//Unknown, happens at npc spawn and cutscene play???? //Unknown, happens at npc spawn and cutscene play????
case 0x00CE: case 0x00CE:
@@ -285,7 +285,7 @@ namespace FFXIVClassic_Map_Server
case 0x012E: case 0x012E:
subpacket.debugPrintSubPacket(); subpacket.debugPrintSubPacket();
EventUpdatePacket eventUpdate = new EventUpdatePacket(subpacket.data); EventUpdatePacket eventUpdate = new EventUpdatePacket(subpacket.data);
Program.Log.Debug(String.Format("\n===Event UPDATE===\nSource Actor: 0x{0:X}\nCaller Actor: 0x{1:X}\nVal1: 0x{2:X}\nVal2: 0x{3:X}\nStep: 0x{4:X}\nParams: {5}", eventUpdate.actorID, eventUpdate.scriptOwnerActorID, eventUpdate.val1, eventUpdate.val2, eventUpdate.step, LuaUtils.dumpParams(eventUpdate.luaParams))); Program.Log.Debug("\n===Event UPDATE===\nSource Actor: 0x{0:X}\nCaller Actor: 0x{1:X}\nVal1: 0x{2:X}\nVal2: 0x{3:X}\nStep: 0x{4:X}\nParams: {5}", eventUpdate.actorID, eventUpdate.scriptOwnerActorID, eventUpdate.val1, eventUpdate.val2, eventUpdate.step, LuaUtils.dumpParams(eventUpdate.luaParams));
//Is it a static actor? If not look in the player's instance //Is it a static actor? If not look in the player's instance
Actor updateOwnerActor = Server.getStaticActors(player.getActor().currentEventOwner); Actor updateOwnerActor = Server.getStaticActors(player.getActor().currentEventOwner);
@@ -406,7 +406,7 @@ namespace FFXIVClassic_Map_Server
client.queuePacket(BasePacket.createPacket(EndGMTicketPacket.buildPacket(player.actorID), true, false)); client.queuePacket(BasePacket.createPacket(EndGMTicketPacket.buildPacket(player.actorID), true, false));
break; break;
default: default:
Program.Log.Debug(String.Format("Unknown command 0x{0:X} received.", subpacket.gameMessage.opcode)); Program.Log.Debug("Unknown command 0x{0:X} received.", subpacket.gameMessage.opcode);
subpacket.debugPrintSubPacket(); subpacket.debugPrintSubPacket();
break; break;
} }
+12 -17
View File
@@ -1,16 +1,21 @@
using System; using System;
using System.Diagnostics; using System.Diagnostics;
using System.Threading; using System.Threading;
using System.Text;
using MySql.Data.MySqlClient; using MySql.Data.MySqlClient;
using System.Reflection; using System.Reflection;
using FFXIVClassic_Map_Server.dataobjects; using FFXIVClassic_Map_Server.dataobjects;
using FFXIVClassic.Common; using FFXIVClassic.Common;
using NLog;
using NLog.Targets;
using NLog.Targets.Wrappers;
using NLog.Config;
namespace FFXIVClassic_Map_Server namespace FFXIVClassic_Map_Server
{ {
class Program class Program
{ {
public static Log Log; public static Logger Log;
static void Main(string[] args) static void Main(string[] args)
{ {
@@ -24,20 +29,9 @@ namespace FFXIVClassic_Map_Server
if (!ConfigConstants.load()) if (!ConfigConstants.load())
startServer = false; startServer = false;
Log = new Log(ConfigConstants.OPTIONS_LOGPATH, ConfigConstants.OPTIONS_LOGFILE, Int32.Parse(ConfigConstants.OPTIONS_LOGLEVEL)); // set up logging
Thread thread = new Thread(() => Log = LogManager.GetCurrentClassLogger();
{
while (true)
{
if (Log.LogQueue.Count > 0)
{
var message = Program.Log.LogQueue.Dequeue();
Program.Log.WriteMessage(message.Item1, message.Item2);
}
}
});
thread.Start();
Program.Log.Info("---------FFXIV 1.0 Map Server---------"); Program.Log.Info("---------FFXIV 1.0 Map Server---------");
@@ -54,7 +48,7 @@ namespace FFXIVClassic_Map_Server
conn.Open(); conn.Open();
conn.Close(); conn.Close();
Program.Log.Status("[OK]"); Program.Log.Info("[OK]");
} }
catch (MySqlException e) catch (MySqlException e)
{ {
@@ -66,7 +60,7 @@ namespace FFXIVClassic_Map_Server
//Check World ID //Check World ID
DBWorld thisWorld = Database.getServer(ConfigConstants.DATABASE_WORLDID); DBWorld thisWorld = Database.getServer(ConfigConstants.DATABASE_WORLDID);
if (thisWorld != null) if (thisWorld != null)
Program.Log.Info(String.Format("Successfully pulled world info from DB. Server name is {0}.", thisWorld.name)); Program.Log.Info("Successfully pulled world info from DB. Server name is {0}.", thisWorld.name);
else else
Program.Log.Info("World info could not be retrieved from the DB. Welcome and MOTD will not be displayed."); Program.Log.Info("World info could not be retrieved from the DB. Welcome and MOTD will not be displayed.");
@@ -77,9 +71,10 @@ namespace FFXIVClassic_Map_Server
CommandProcessor cp = new CommandProcessor(server.getConnectedPlayerList()); CommandProcessor cp = new CommandProcessor(server.getConnectedPlayerList());
server.startServer(); server.startServer();
while (true) while (startServer)
{ {
String input = Console.ReadLine(); String input = Console.ReadLine();
Log.Info("[Console Input] " + input);
cp.doCommand(input, null); cp.doCommand(input, null);
} }
} }
+8 -7
View File
@@ -6,6 +6,7 @@ using System.Threading;
using FFXIVClassic_Map_Server.dataobjects; using FFXIVClassic_Map_Server.dataobjects;
using FFXIVClassic_Map_Server.packets; using FFXIVClassic_Map_Server.packets;
using FFXIVClassic.Common; using FFXIVClassic.Common;
using NLog;
using FFXIVClassic_Map_Server.Actors; using FFXIVClassic_Map_Server.Actors;
using FFXIVClassic_Map_Server.lua; using FFXIVClassic_Map_Server.lua;
@@ -39,7 +40,7 @@ namespace FFXIVClassic_Map_Server
private void connectionHealth() private void connectionHealth()
{ {
Program.Log.Info(String.Format("Connection Health thread started; it will run every {0} seconds.", HEALTH_THREAD_SLEEP_TIME)); Program.Log.Info("Connection Health thread started; it will run every {0} seconds.", HEALTH_THREAD_SLEEP_TIME);
while (!killHealthThread) while (!killHealthThread)
{ {
lock (mConnectedPlayerList) lock (mConnectedPlayerList)
@@ -77,7 +78,7 @@ namespace FFXIVClassic_Map_Server
mStaticActors = new StaticActors(STATIC_ACTORS_PATH); mStaticActors = new StaticActors(STATIC_ACTORS_PATH);
gamedataItems = Database.getItemGamedata(); gamedataItems = Database.getItemGamedata();
Program.Log.Info(String.Format("Loaded {0} items.", gamedataItems.Count)); Program.Log.Info("Loaded {0} items.", gamedataItems.Count);
mWorldManager = new WorldManager(this); mWorldManager = new WorldManager(this);
mWorldManager.LoadZoneList(); mWorldManager.LoadZoneList();
@@ -113,7 +114,7 @@ namespace FFXIVClassic_Map_Server
} }
Console.ForegroundColor = ConsoleColor.White; Console.ForegroundColor = ConsoleColor.White;
Program.Log.Debug(String.Format("Map Server has started @ {0}:{1}", (mServerSocket.LocalEndPoint as IPEndPoint).Address, (mServerSocket.LocalEndPoint as IPEndPoint).Port)); Program.Log.Debug("Map Server has started @ {0}:{1}", (mServerSocket.LocalEndPoint as IPEndPoint).Address, (mServerSocket.LocalEndPoint as IPEndPoint).Port);
Console.ForegroundColor = ConsoleColor.Gray; Console.ForegroundColor = ConsoleColor.Gray;
mProcessor = new PacketProcessor(this, mConnectedPlayerList, mConnectionList); mProcessor = new PacketProcessor(this, mConnectedPlayerList, mConnectionList);
@@ -150,7 +151,7 @@ namespace FFXIVClassic_Map_Server
mConnectionList.Add(conn); mConnectionList.Add(conn);
} }
Program.Log.Status(String.Format("Connection {0}:{1} has connected.", (conn.socket.RemoteEndPoint as IPEndPoint).Address, (conn.socket.RemoteEndPoint as IPEndPoint).Port)); Program.Log.Info("Connection {0}:{1} has connected.", (conn.socket.RemoteEndPoint as IPEndPoint).Address, (conn.socket.RemoteEndPoint as IPEndPoint).Port);
//Queue recieving of data from the connection //Queue recieving of data from the connection
conn.socket.BeginReceive(conn.buffer, 0, conn.buffer.Length, SocketFlags.None, new AsyncCallback(receiveCallback), conn); conn.socket.BeginReceive(conn.buffer, 0, conn.buffer.Length, SocketFlags.None, new AsyncCallback(receiveCallback), conn);
//Queue the accept of the next incomming connection //Queue the accept of the next incomming connection
@@ -217,7 +218,7 @@ namespace FFXIVClassic_Map_Server
mConnectionList.Remove(conn); mConnectionList.Remove(conn);
} }
if (conn.connType == BasePacket.TYPE_ZONE) if (conn.connType == BasePacket.TYPE_ZONE)
Program.Log.Status(String.Format("{0} has disconnected.", conn.owner == 0 ? conn.getAddress() : "User " + conn.owner)); Program.Log.Info("{0} has disconnected.", conn.owner == 0 ? conn.getAddress() : "User " + conn.owner);
return; return;
} }
@@ -261,7 +262,7 @@ namespace FFXIVClassic_Map_Server
} }
else else
{ {
Program.Log.Status(String.Format("{0} has disconnected.", conn.owner == 0 ? conn.getAddress() : "User " + conn.owner)); Program.Log.Info("{0} has disconnected.", conn.owner == 0 ? conn.getAddress() : "User " + conn.owner);
lock (mConnectionList) lock (mConnectionList)
{ {
@@ -273,7 +274,7 @@ namespace FFXIVClassic_Map_Server
{ {
if (conn.socket != null) if (conn.socket != null)
{ {
Program.Log.Status(String.Format("{0} has disconnected.", conn.owner == 0 ? conn.getAddress() : "User " + conn.owner)); Program.Log.Info("{0} has disconnected.", conn.owner == 0 ? conn.getAddress() : "User " + conn.owner);
lock (mConnectionList) lock (mConnectionList)
{ {
+4 -4
View File
@@ -125,7 +125,7 @@ namespace FFXIVClassic_Map_Server
} }
} }
Program.Log.Info(String.Format("Loaded {0} zones and {1} private areas.", count1, count2)); Program.Log.Info("Loaded {0} zones and {1} private areas.", count1, count2);
} }
public void LoadZoneEntranceList() public void LoadZoneEntranceList()
@@ -178,7 +178,7 @@ namespace FFXIVClassic_Map_Server
} }
} }
Program.Log.Info(String.Format("Loaded {0} zone spawn locations.", count)); Program.Log.Info("Loaded {0} zone spawn locations.", count);
} }
public void LoadNPCs() public void LoadNPCs()
@@ -250,7 +250,7 @@ namespace FFXIVClassic_Map_Server
} }
} }
Program.Log.Info(String.Format("Loaded {0} npc(s).", count)); Program.Log.Info("Loaded {0} npc(s).", count);
} }
public void LoadNPCs(uint zoneId) public void LoadNPCs(uint zoneId)
@@ -323,7 +323,7 @@ namespace FFXIVClassic_Map_Server
} }
} }
Program.Log.Info(String.Format("Loaded {0} npc(s).", count)); Program.Log.Info("Loaded {0} npc(s).", count);
} }
//Moves the actor to the new zone if exists. No packets are sent nor position changed. //Moves the actor to the new zone if exists. No packets are sent nor position changed.
@@ -91,7 +91,7 @@ namespace FFXIVClassic_Map_Server.Actors
catch(FileNotFoundException e) catch(FileNotFoundException e)
{ Program.Log.Error("Could not find staticactors file."); return false; } { Program.Log.Error("Could not find staticactors file."); return false; }
Program.Log.Info(String.Format("Loaded {0} static actors.", mStaticActors.Count())); Program.Log.Info("Loaded {0} static actors.", mStaticActors.Count());
return true; return true;
} }
@@ -642,7 +642,7 @@ namespace FFXIVClassic_Map_Server.Actors
Database.savePlayerPlayTime(this); Database.savePlayerPlayTime(this);
Database.savePlayerPosition(this); Database.savePlayerPosition(this);
Program.Log.Info(String.Format("{0} has been logged out and saved.", this.customDisplayName)); Program.Log.Info("{0} has been logged out and saved.", this.customDisplayName);
} }
public Area getZone() public Area getZone()
@@ -68,7 +68,7 @@ namespace FFXIVClassic_Map_Server.Actors
{ {
if (bitIndex >= 32) if (bitIndex >= 32)
{ {
Program.Log.Error(String.Format("Tried to access bit flag >= 32 for questId: {0}", actorId)); Program.Log.Error("Tried to access bit flag >= 32 for questId: {0}", actorId);
return; return;
} }
@@ -86,7 +86,7 @@ namespace FFXIVClassic_Map_Server.Actors
{ {
if (bitIndex >= 32) if (bitIndex >= 32)
{ {
Program.Log.Error(String.Format("Tried to access bit flag >= 32 for questId: {0}", actorId)); Program.Log.Error("Tried to access bit flag >= 32 for questId: {0}", actorId);
return false; return false;
} }
else else
+1 -1
View File
@@ -217,7 +217,7 @@ namespace FFXIVClassic_Map_Server.lua
} }
catch(SyntaxErrorException e) catch(SyntaxErrorException e)
{ {
Program.Log.Error(String.Format("LUAERROR: {0}.", e.DecoratedMessage)); Program.Log.Error("LUAERROR: {0}.", e.DecoratedMessage);
return null; return null;
} }
return script; return script;
+3
View File
@@ -5,4 +5,7 @@
<package id="MoonSharp" version="1.2.1.0" targetFramework="net45" /> <package id="MoonSharp" version="1.2.1.0" targetFramework="net45" />
<package id="MySql.Data" version="6.9.7" targetFramework="net45" /> <package id="MySql.Data" version="6.9.7" targetFramework="net45" />
<package id="Newtonsoft.Json" version="8.0.3" targetFramework="net45" /> <package id="Newtonsoft.Json" version="8.0.3" targetFramework="net45" />
<package id="NLog" version="4.3.5" targetFramework="net45" />
<package id="NLog.Config" version="4.3.5" targetFramework="net45" />
<package id="NLog.Schema" version="4.3.4" targetFramework="net45" />
</packages> </packages>
@@ -334,7 +334,7 @@ namespace FFXIVClassic_Map_Server.packets
#if DEBUG #if DEBUG
Console.BackgroundColor = ConsoleColor.DarkYellow; Console.BackgroundColor = ConsoleColor.DarkYellow;
Program.Log.Debug(String.Format("IsAuth: {0} IsEncrypted: {1}, Size: 0x{2:X}, NumSubpackets: {3}{4}{5}", header.isAuthenticated, header.isCompressed, header.packetSize, header.numSubpackets, Environment.NewLine, Utils.ByteArrayToHex(getHeaderBytes()))); Program.Log.Debug("IsAuth: {0} IsEncrypted: {1}, Size: 0x{2:X}, NumSubpackets: {3}{4}{5}", header.isAuthenticated, header.isCompressed, header.packetSize, header.numSubpackets, Environment.NewLine, Utils.ByteArrayToHex(getHeaderBytes()));
foreach (SubPacket sub in getSubpackets()) foreach (SubPacket sub in getSubpackets())
{ {
+3 -3
View File
@@ -142,15 +142,15 @@ namespace FFXIVClassic_Map_Server.packets
#if DEBUG #if DEBUG
Console.BackgroundColor = ConsoleColor.DarkRed; Console.BackgroundColor = ConsoleColor.DarkRed;
Program.Log.Debug(String.Format("Size: 0x{0:X}{1}{2}", header.subpacketSize, Environment.NewLine, Utils.ByteArrayToHex(getHeaderBytes()))); Program.Log.Debug("Size: 0x{0:X}{1}{2}", header.subpacketSize, Environment.NewLine, Utils.ByteArrayToHex(getHeaderBytes()));
if (header.type == 0x03) if (header.type == 0x03)
{ {
Program.Log.Debug(String.Format("Opcode: 0x{0:X}{1}{2}", gameMessage.opcode, Environment.NewLine, Utils.ByteArrayToHex(getGameMessageBytes(), SUBPACKET_SIZE))); Program.Log.Debug("Opcode: 0x{0:X}{1}{2}", gameMessage.opcode, Environment.NewLine, Utils.ByteArrayToHex(getGameMessageBytes(), SUBPACKET_SIZE));
Console.BackgroundColor = ConsoleColor.DarkMagenta; Console.BackgroundColor = ConsoleColor.DarkMagenta;
Program.Log.Debug(String.Format("Data: {0}{1}", Environment.NewLine, Utils.ByteArrayToHex(data, SUBPACKET_SIZE + GAMEMESSAGE_SIZE))); Program.Log.Debug("Data: {0}{1}", Environment.NewLine, Utils.ByteArrayToHex(data, SUBPACKET_SIZE + GAMEMESSAGE_SIZE));
} }
Console.BackgroundColor = ConsoleColor.Black; Console.BackgroundColor = ConsoleColor.Black;
@@ -79,7 +79,7 @@ namespace FFXIVClassic_Map_Server.utils
cmd.Parameters["@placename"].Value = placenames[pId]; cmd.Parameters["@placename"].Value = placenames[pId];
Program.Log.Debug(String.Format("Wrote: {0}", id)); Program.Log.Debug("Wrote: {0}", id);
cmd.ExecuteNonQuery(); cmd.ExecuteNonQuery();
} }
@@ -137,7 +137,7 @@ namespace FFXIVClassic_Map_Server.utils
cmd.Parameters["@id"].Value = id; cmd.Parameters["@id"].Value = id;
cmd.Parameters["@displayNameId"].Value = nameId; cmd.Parameters["@displayNameId"].Value = nameId;
Program.Log.Debug(String.Format("Wrote: {0} : {1}", id, nameId)); Program.Log.Debug("Wrote: {0} : {1}", id, nameId);
cmd.ExecuteNonQuery(); cmd.ExecuteNonQuery();
} }
@@ -203,7 +203,7 @@ namespace FFXIVClassic_Map_Server.utils
cmd.Parameters["@id"].Value = id; cmd.Parameters["@id"].Value = id;
Program.Log.Debug(String.Format("Wrote: {0}", id)); Program.Log.Debug("Wrote: {0}", id);
cmd.ExecuteNonQuery(); cmd.ExecuteNonQuery();
} }
@@ -288,7 +288,7 @@ namespace FFXIVClassic_Map_Server.utils
else if (id == 1500) else if (id == 1500)
otherId = SetCompletedAchievementsPacket.CATEGORY_GRAND_COMPANY; otherId = SetCompletedAchievementsPacket.CATEGORY_GRAND_COMPANY;
Program.Log.Debug(String.Format("Wrote: {0} : {1} : {2} : {3}", id, name, otherId, points)); Program.Log.Debug("Wrote: {0} : {1} : {2} : {3}", id, name, otherId, points);
cmd.Parameters["@id"].Value = id; cmd.Parameters["@id"].Value = id;
cmd.Parameters["@name"].Value = name; cmd.Parameters["@name"].Value = name;
cmd.Parameters["@otherId"].Value = otherId; cmd.Parameters["@otherId"].Value = otherId;
-17
View File
@@ -2,23 +2,6 @@
server_ip=127.0.0.1 server_ip=127.0.0.1
showtimestamp = true showtimestamp = true
# log_level: add up values for types you want to enable
# then convert hex -> dec and set log_level = value
# 0x000 None,
# 0x001 Console,
# 0x002 File,
# 0x004 Status,
# 0x008 Sql,
# 0x010 Info,
# 0x020 Debug,
# 0x040 Error,
log_level = 127
#log_path = ./logs/
#log_file = lobby.log
[Database] [Database]
worldid=1 worldid=1
host=127.0.0.1 host=127.0.0.1
-17
View File
@@ -2,23 +2,6 @@
server_ip=127.0.0.1 server_ip=127.0.0.1
showtimestamp = true showtimestamp = true
# log_level: add up values for types you want to enable
# then convert hex -> dec and set log_level = value
# 0x000 None,
# 0x001 Console,
# 0x002 File,
# 0x004 Status,
# 0x008 Sql,
# 0x010 Info,
# 0x020 Debug,
# 0x040 Error,
log_level = 127
#log_path = ./logs/
#log_file = map.log
[Database] [Database]
worldid=1 worldid=1
host=127.0.0.1 host=127.0.0.1