Initial commit of the FFXIV 1.0 lobby server.

This commit is contained in:
Filip Maj 2015-08-26 13:38:58 -04:00
commit c1e214175f
48 changed files with 55780 additions and 0 deletions

View file

@ -0,0 +1,74 @@
using System;
using System.Text;
using System.IO;
using System.Runtime.InteropServices;
namespace FFXIVClassic_Lobby_Server.common
{
public class Blowfish
{
[DllImport("../../../Debug/Blowfish.dll", CallingConvention = CallingConvention.Cdecl)]
private static extern short initializeBlowfish(byte[] key, short keySize, uint[] P, uint[,] S);
[DllImport("../../../Debug/Blowfish.dll", CallingConvention = CallingConvention.Cdecl)]
private static extern void blowfish_encipher(ref int xl, ref int xr, uint[] P);
[DllImport("../../../Debug/Blowfish.dll", CallingConvention = CallingConvention.Cdecl)]
private static extern void blowfish_decipher(ref int xl, ref int xr, uint[] P);
private uint[] P = new uint[16+2];
private uint[,] S = new uint[4,256];
public Blowfish(byte[] key)
{
InitBlowfish(key);
}
private int InitBlowfish(byte[] key)
{
return initializeBlowfish(key, (short)key.Length, P, S);
}
public void Encipher(byte[] data, int offset, int length)
{
if ((length - offset) % 8 != 0)
throw new ArgumentException("Needs to be a multiple of 8");
for (int i = offset; i < offset+length; i+=8)
{
int xl = (data[i + 0]) | (data[i + 1] << 8) | (data[i + 2] << 16) | (data[i + 3] << 24);
int xr = (data[i + 4]) | (data[i + 5] << 8) | (data[i + 6] << 16) | (data[i + 7] << 24);
blowfish_encipher(ref xl, ref xr, P);
data[i + 0] = (byte)(xl >> 0);
data[i + 1] = (byte)(xl >> 8);
data[i + 2] = (byte)(xl >> 16);
data[i + 3] = (byte)(xl >> 24);
data[i + 4] = (byte)(xr >> 0);
data[i + 5] = (byte)(xr >> 8);
data[i + 6] = (byte)(xr >> 16);
data[i + 7] = (byte)(xr >> 24);
}
}
public void Decipher(byte[] data, int offset, int length)
{
if ((length - offset) % 8 != 0)
throw new ArgumentException("Needs to be a multiple of 8");
for (int i = offset; i < offset + length; i += 8)
{
int xl = (data[i + 0]) | (data[i + 1] << 8) | (data[i + 2] << 16) | (data[i + 3] << 24);
int xr = (data[i + 4]) | (data[i + 5] << 8) | (data[i + 6] << 16) | (data[i + 7] << 24);
blowfish_decipher(ref xl, ref xr, P);
data[i + 0] = (byte)(xl >> 0);
data[i + 1] = (byte)(xl >> 8);
data[i + 2] = (byte)(xl >> 16);
data[i + 3] = (byte)(xl >> 24);
data[i + 4] = (byte)(xr >> 0);
data[i + 5] = (byte)(xr >> 8);
data[i + 6] = (byte)(xr >> 16);
data[i + 7] = (byte)(xr >> 24);
}
}
}
}

View file

@ -0,0 +1,63 @@
using System.Runtime.InteropServices;
using System.Text;
namespace FFXIVClassic_Lobby_Server.common
{
/// <summary>
/// Create a New INI file to store or load data
/// </summary>
public class IniFile
{
public string path;
[DllImport("kernel32")]
private static extern long WritePrivateProfileString(string section,
string key, string val, string filePath);
[DllImport("kernel32")]
private static extern int GetPrivateProfileString(string section,
string key, string def, StringBuilder retVal,
int size, string filePath);
[DllImport("kernel32")]
private static extern int GetPrivateProfileSectionNames(StringBuilder retVal,
int size, string filePath);
/// <summary>
/// INIFile Constructor.
/// </summary>
/// <PARAM name="INIPath"></PARAM>
public IniFile(string INIPath)
{
path = INIPath;
}
/// <summary>
/// Write Data to the INI File
/// </summary>
/// <PARAM name="Section"></PARAM>
/// Section name
/// <PARAM name="Key"></PARAM>
/// Key Name
/// <PARAM name="Value"></PARAM>
/// Value Name
public void IniWriteValue(string Section, string Key, string Value)
{
WritePrivateProfileString(Section, Key, Value, this.path);
}
/// <summary>
/// Read Data Value From the Ini File
/// </summary>
/// <PARAM name="Section"></PARAM>
/// <PARAM name="Key"></PARAM>
/// <PARAM name="Path"></PARAM>
/// <returns></returns>
public string IniReadValue(string Section, string Key)
{
StringBuilder temp = new StringBuilder(255);
int i = GetPrivateProfileString(Section, Key, "", temp,
255, this.path);
return temp.ToString();
}
}
}

View file

@ -0,0 +1,77 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FFXIVClassic_Lobby_Server.common
{
static class Utils
{
private static readonly uint[] _lookup32 = CreateLookup32();
private static uint[] CreateLookup32()
{
var result = new uint[256];
for (int i = 0; i < 256; i++)
{
string s = i.ToString("X2");
result[i] = ((uint)s[0]) + ((uint)s[1] << 16);
}
return result;
}
public static string ByteArrayToHex(byte[] bytes)
{
var lookup32 = _lookup32;
var result = new char[(bytes.Length * 3) + ((bytes.Length/16) < 1 ? 1 : (bytes.Length/16)*3) + bytes.Length+60];
int numNewLines = 0;
for (int i = 0; i < bytes.Length; i++)
{
var val = lookup32[bytes[i]];
result[(3 * i) + (17 * numNewLines) + 0] = (char)val;
result[(3 * i) + (17 * numNewLines) + 1] = (char)(val >> 16);
result[(3 * i) + (17 * numNewLines) + 2] = ' ';
result[(numNewLines * (3*16+17)) + (3 * 16) + (i % 16)] = (char)bytes[i] >= 32 && (char)bytes[i] <= 126 ? (char)bytes[i] : '.';
if (i != bytes.Length - 1 && bytes.Length > 16 && i != 0 && (i+1) % 16 == 0)
{
result[(numNewLines * (3*16+17)) + (3 * 16) + (16)] = '\n';
numNewLines++;
}
}
return new string(result);
}
/*
/// <summary>
/// Grabs an instance of a class directly from the MySqlDataReader instead of manually building from GetString() etc.
/// </summary>
/// <typeparam name="T">Type of object to return</typeparam>
/// <param name="reader">Reader instance</param>
/// <returns>new T</returns>
public static T GetSQLObject<T>(this MySql.Data.MySqlClient.MySqlDataReader reader)
{
var obj = Activator.CreateInstance(typeof(T));
var fields = obj.GetType().GetFields();
foreach (var field in obj.GetType().GetFields())
{
var attrs = field.GetCustomAttributes(typeof(System.Runtime.Serialization.DataMemberAttribute), true) as System.Runtime.Serialization.DataMemberAttribute[];
if (attrs.Length == 0)
{
continue;
}
var fieldID = attrs[0].Name;
var fieldType = field.FieldType;
field.SetValue(obj, reader.GetValue(reader.GetOrdinal(fieldID)));
}
return (T)obj;
}*/
}
}