mirror of
https://github.com/islehorse/HISP.git
synced 2025-04-23 05:05:53 +12:00
Inital Commit
This commit is contained in:
parent
fc2b0206d6
commit
e8e0a0a519
145 changed files with 68819 additions and 0 deletions
98
Horse Isle Server/Horse Isle Server/Authentication.cs
Normal file
98
Horse Isle Server/Horse Isle Server/Authentication.cs
Normal file
|
@ -0,0 +1,98 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Horse_Isle_Server
|
||||
{
|
||||
class Authentication
|
||||
{
|
||||
public static string DecryptLogin(string encpass)
|
||||
{
|
||||
string decrypt = "";
|
||||
string ROTPOOL = "bl7Jgk61IZdnY mfDN5zjM2XLqTCty4WSEoKR3BFVQsaUhHOAx0rPwp9uc8iGve";
|
||||
string POSPOOL = "DQc3uxiGsKZatMmOS5qYveN71zoPTk8yU0H2w9VjprBXWn l4FJd6IRbhgACfEL";
|
||||
string ROTPOOL2 = "evGi8cu9pwPr0xAOHhUasQVFB3RKoESW4ytCTqLX2Mjz5NDfm YndZI16kgJ7lb";
|
||||
|
||||
|
||||
int i = 0;
|
||||
int ii = 0;
|
||||
while (i < encpass.Length)
|
||||
{
|
||||
int ROT = ROTPOOL.IndexOf(encpass[i].ToString());
|
||||
int POS = POSPOOL.IndexOf(encpass[i + 1].ToString());
|
||||
POS -= (ROT + ii);
|
||||
if (POS < 0)
|
||||
{
|
||||
POS = (POS / -1) - 1;
|
||||
|
||||
while (POS >= ROTPOOL.Length)
|
||||
{
|
||||
POS -= ROTPOOL.Length;
|
||||
}
|
||||
|
||||
decrypt += ROTPOOL2[POS];
|
||||
}
|
||||
else
|
||||
{
|
||||
while (POS >= ROTPOOL.Length)
|
||||
{
|
||||
POS -= ROTPOOL.Length;
|
||||
}
|
||||
|
||||
decrypt += ROTPOOL[POS];
|
||||
}
|
||||
|
||||
i += 2;
|
||||
ii += 1;
|
||||
}
|
||||
return decrypt.Replace(" ", "");
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static byte[] HashAndSalt(string plaintext, byte[] salt)
|
||||
{
|
||||
byte[] plaintextBytes = Encoding.UTF8.GetBytes(plaintext);
|
||||
|
||||
SHA512 sha512 = SHA512.Create();
|
||||
sha512.Initialize();
|
||||
byte[] hash = sha512.TransformFinalBlock(plaintextBytes, 0x00, plaintextBytes.Length);
|
||||
|
||||
for (int i = 0; i < hash.Length; i++)
|
||||
{
|
||||
hash[i] ^= salt[i];
|
||||
}
|
||||
|
||||
sha512 = SHA512.Create();
|
||||
sha512.Initialize();
|
||||
byte[] finalHash = sha512.TransformFinalBlock(hash, 0x00, hash.Length);
|
||||
|
||||
return finalHash;
|
||||
}
|
||||
|
||||
public static bool CheckPassword(string username, string password)
|
||||
{
|
||||
|
||||
try
|
||||
{
|
||||
byte[] expectedPassword = Database.GetPasswordHash(username);
|
||||
byte[] salt = Database.GetPasswordSalt(username);
|
||||
byte[] hashedPassword = HashAndSalt(password, salt);
|
||||
|
||||
if (Enumerable.SequenceEqual(expectedPassword, hashedPassword))
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
catch(KeyNotFoundException e)
|
||||
{
|
||||
Logger.DebugPrint(e.Message);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
116
Horse Isle Server/Horse Isle Server/Client.cs
Normal file
116
Horse Isle Server/Horse Isle Server/Client.cs
Normal file
|
@ -0,0 +1,116 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Net.Sockets;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Horse_Isle_Server
|
||||
{
|
||||
class Client
|
||||
{
|
||||
public Socket ClientSocket;
|
||||
public string RemoteIp;
|
||||
public bool LoggedIn = false;
|
||||
|
||||
private Thread recvPackets;
|
||||
|
||||
private const byte PACKET_LOGIN = 0x7F;
|
||||
private const byte PACKET_CHAT = 0x14;
|
||||
private const byte PACKET_MOVE = 0x15;
|
||||
private const byte PACKET_USERINFO = 0x81;
|
||||
|
||||
private void receivePackets()
|
||||
{
|
||||
// HI1 Packets are terminates by 0x00 so we have to read until we receive that terminator
|
||||
MemoryStream ms = new MemoryStream();
|
||||
|
||||
while(ClientSocket.Connected)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (ClientSocket.Available >= 1)
|
||||
{
|
||||
byte[] buffer = new byte[ClientSocket.Available];
|
||||
ClientSocket.Receive(buffer);
|
||||
|
||||
|
||||
foreach (Byte b in buffer)
|
||||
{
|
||||
ms.WriteByte(b);
|
||||
if (b == 0x00)
|
||||
{
|
||||
ms.Seek(0x00, SeekOrigin.Begin);
|
||||
byte[] fullPacket = ms.ToArray();
|
||||
parsePackets(fullPacket);
|
||||
ms.Close();
|
||||
ms = new MemoryStream();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
catch(SocketException e)
|
||||
{
|
||||
Logger.ErrorPrint("Socket exception occured: " + e.Message +" and so it was disconnected.");
|
||||
Disconnect();
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void parsePackets(byte[] Packet)
|
||||
{
|
||||
if (Packet.Length < 1)
|
||||
{
|
||||
Logger.ErrorPrint("Received an invalid packet (size: "+Packet.Length+")");
|
||||
}
|
||||
|
||||
byte identifier = Packet[0];
|
||||
if(!LoggedIn) // Must be either login or policy-file-request
|
||||
{
|
||||
if(Encoding.UTF8.GetString(Packet).StartsWith("<policy-file-request/>")) // Policy File Request
|
||||
{
|
||||
Server.OnCrossdomainPolicyRequest(this);
|
||||
}
|
||||
switch(identifier)
|
||||
{
|
||||
case PACKET_LOGIN:
|
||||
Server.OnLoginRequest(this,Packet);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Disconnect()
|
||||
{
|
||||
Server.ConnectedClients.Remove(this);
|
||||
ClientSocket.Dispose();
|
||||
}
|
||||
|
||||
public void SendPacket(byte[] PacketData)
|
||||
{
|
||||
ClientSocket.Send(PacketData);
|
||||
}
|
||||
|
||||
public Client(Socket clientSocket)
|
||||
{
|
||||
ClientSocket = clientSocket;
|
||||
RemoteIp = clientSocket.RemoteEndPoint.ToString();
|
||||
|
||||
Logger.DebugPrint("Client connected @ " + RemoteIp);
|
||||
|
||||
recvPackets = new Thread(() =>
|
||||
{
|
||||
receivePackets();
|
||||
});
|
||||
recvPackets.Start();
|
||||
}
|
||||
}
|
||||
}
|
100
Horse Isle Server/Horse Isle Server/ConfigReader.cs
Normal file
100
Horse Isle Server/Horse Isle Server/ConfigReader.cs
Normal file
|
@ -0,0 +1,100 @@
|
|||
using Horse_Isle_Server.Properties;
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
namespace Horse_Isle_Server
|
||||
{
|
||||
|
||||
class ConfigReader
|
||||
{
|
||||
public static int Port;
|
||||
public static string BindIP;
|
||||
|
||||
public static string DatabaseIP;
|
||||
public static string DatabaseUsername;
|
||||
public static string DatabaseName;
|
||||
public static string DatabasePassword;
|
||||
public static int DatabasePort;
|
||||
|
||||
|
||||
public static string MapFile;
|
||||
public static string OverlayMapFile;
|
||||
public static string CrossDomainPolicyFile;
|
||||
public static bool Debug;
|
||||
|
||||
private static string ConfigurationFileName = "server.properties";
|
||||
public static void OpenConfig()
|
||||
{
|
||||
if (!File.Exists(ConfigurationFileName))
|
||||
{
|
||||
Logger.ErrorPrint(ConfigurationFileName+" not found! writing default.");
|
||||
File.WriteAllText(ConfigurationFileName,Resources.DefaultServerProperties);
|
||||
}
|
||||
|
||||
string[] configFile = File.ReadAllLines(ConfigurationFileName);
|
||||
foreach (string setting in configFile)
|
||||
{
|
||||
/*
|
||||
* Avoid crashing.
|
||||
*/
|
||||
if (setting.Length < 1)
|
||||
continue;
|
||||
if (setting[0] == '#')
|
||||
continue;
|
||||
if (!setting.Contains("="))
|
||||
continue;
|
||||
|
||||
string[] dataPair = setting.Split('=');
|
||||
|
||||
string key = dataPair[0];
|
||||
string data = dataPair[1];
|
||||
/*
|
||||
* Parse configuration file
|
||||
*/
|
||||
|
||||
switch (key)
|
||||
{
|
||||
case "port":
|
||||
Port = int.Parse(data);
|
||||
break;
|
||||
case "ip":
|
||||
BindIP = data;
|
||||
break;
|
||||
case "db_ip":
|
||||
DatabaseIP = data;
|
||||
break;
|
||||
case "db_username":
|
||||
DatabaseUsername = data;
|
||||
break;
|
||||
case "db_password":
|
||||
DatabasePassword = data;
|
||||
break;
|
||||
case "db_name":
|
||||
DatabaseName = data;
|
||||
break;
|
||||
case "db_port":
|
||||
DatabasePort = int.Parse(data);
|
||||
break;
|
||||
case "map":
|
||||
MapFile = data;
|
||||
break;
|
||||
case "overlaymap":
|
||||
OverlayMapFile = data;
|
||||
break;
|
||||
case "crossdomain":
|
||||
CrossDomainPolicyFile = data;
|
||||
break;
|
||||
case "debug":
|
||||
Debug = data == "true";
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
38
Horse Isle Server/Horse Isle Server/Converters.cs
Normal file
38
Horse Isle Server/Horse Isle Server/Converters.cs
Normal file
|
@ -0,0 +1,38 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Horse_Isle_Server
|
||||
{
|
||||
class Converters
|
||||
{
|
||||
// Thanks Stackoverflow (https://stackoverflow.com/questions/321370/how-can-i-convert-a-hex-string-to-a-byte-array)
|
||||
private static int getHexVal(char hex)
|
||||
{
|
||||
int val = (int)hex;
|
||||
//For uppercase A-F letters:
|
||||
//return val - (val < 58 ? 48 : 55);
|
||||
//For lowercase a-f letters:
|
||||
//return val - (val < 58 ? 48 : 87);
|
||||
//Or the two combined, but a bit slower:
|
||||
return val - (val < 58 ? 48 : (val < 97 ? 55 : 87));
|
||||
}
|
||||
public static byte[] StringToByteArray(string hex)
|
||||
{
|
||||
if (hex.Length % 2 == 1)
|
||||
throw new ArgumentException("The binary key cannot have an odd number of digits");
|
||||
|
||||
byte[] arr = new byte[hex.Length >> 1];
|
||||
|
||||
for (int i = 0; i < hex.Length >> 1; ++i)
|
||||
{
|
||||
arr[i] = (byte)((getHexVal(hex[i << 1]) << 4) + (getHexVal(hex[(i << 1) + 1])));
|
||||
}
|
||||
|
||||
return arr;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
34
Horse Isle Server/Horse Isle Server/CrossDomainPolicy.cs
Normal file
34
Horse Isle Server/Horse Isle Server/CrossDomainPolicy.cs
Normal file
|
@ -0,0 +1,34 @@
|
|||
using Horse_Isle_Server.Properties;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Horse_Isle_Server
|
||||
{
|
||||
class CrossDomainPolicy
|
||||
{
|
||||
public static byte[] GetPolicy()
|
||||
{
|
||||
if (!File.Exists(ConfigReader.CrossDomainPolicyFile)) {
|
||||
if (ConfigReader.Debug)
|
||||
Console.WriteLine("[DEBUG] Cross domain policy file not found, using default");
|
||||
File.WriteAllText(ConfigReader.CrossDomainPolicyFile, Resources.DefaultCrossDomain);
|
||||
}
|
||||
|
||||
|
||||
MemoryStream ms = new MemoryStream();
|
||||
byte[] policyFileBytes = File.ReadAllBytes(ConfigReader.CrossDomainPolicyFile);
|
||||
ms.Write(policyFileBytes, 0x00, policyFileBytes.Length);
|
||||
ms.WriteByte(0x00);
|
||||
|
||||
ms.Seek(0x00, SeekOrigin.Begin);
|
||||
byte[] policyFileData = ms.ToArray();
|
||||
ms.Close();
|
||||
|
||||
return policyFileData;
|
||||
}
|
||||
}
|
||||
}
|
66
Horse Isle Server/Horse Isle Server/Database.cs
Normal file
66
Horse Isle Server/Horse Isle Server/Database.cs
Normal file
|
@ -0,0 +1,66 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using MySqlConnector;
|
||||
|
||||
namespace Horse_Isle_Server
|
||||
{
|
||||
class Database
|
||||
{
|
||||
|
||||
public static MySqlConnection db;
|
||||
|
||||
public static void OpenDatabase()
|
||||
{
|
||||
db = new MySqlConnection("server=" + ConfigReader.DatabaseIP + ";user=" + ConfigReader.DatabaseUsername + ";password=" + ConfigReader.DatabasePassword+";database="+ConfigReader.DatabaseName);
|
||||
db.Open();
|
||||
string UserTable = "CREATE TABLE Users(Id INT, Username TEXT(16),Email TEXT(128),Country TEXT(128),SecurityQuestion Text(128),SecurityAnswerHash TEXT(128),Age INT,PassHash TEXT(128), Salt TEXT(128),Gender TEXT(16), Admin TEXT(3), Moderator TEXT(3))";
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
MySqlCommand sqlCommand = db.CreateCommand();
|
||||
sqlCommand.CommandText = UserTable;
|
||||
sqlCommand.ExecuteNonQuery();
|
||||
}
|
||||
catch (Exception e) {
|
||||
Logger.ErrorPrint("Failed to setup database (perhaps its allready setup?) "+e.Message);
|
||||
};
|
||||
}
|
||||
|
||||
public static byte[] GetPasswordSalt(string username)
|
||||
{
|
||||
MySqlCommand sqlCommand = db.CreateCommand();
|
||||
sqlCommand.CommandText = "SELECT COUNT(1) FROM Users WHERE Username=$name";
|
||||
sqlCommand.Parameters.AddWithValue("$name", username);
|
||||
Int32 count = Convert.ToInt32(sqlCommand.ExecuteScalar());
|
||||
if (count >= 1)
|
||||
{
|
||||
sqlCommand.CommandText = "SELECT Salt FROM Users WHERE Username=$name";
|
||||
string expectedHash = sqlCommand.ExecuteScalar().ToString();
|
||||
return Converters.StringToByteArray(expectedHash);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new KeyNotFoundException("Username " + username + " not found in database.");
|
||||
}
|
||||
}
|
||||
public static byte[] GetPasswordHash(string username)
|
||||
{
|
||||
MySqlCommand sqlCommand = db.CreateCommand();
|
||||
sqlCommand.CommandText = "SELECT COUNT(1) FROM Users WHERE Username=$name";
|
||||
sqlCommand.Parameters.AddWithValue("$name", username);
|
||||
Int32 count = Convert.ToInt32(sqlCommand.ExecuteScalar());
|
||||
if(count >= 1)
|
||||
{
|
||||
sqlCommand.CommandText = "SELECT PassHash FROM Users WHERE Username=$name";
|
||||
string expectedHash = sqlCommand.ExecuteScalar().ToString();
|
||||
return Converters.StringToByteArray(expectedHash);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new KeyNotFoundException("Username " + username + " not found in database.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
99
Horse Isle Server/Horse Isle Server/Horse Isle Server.csproj
Normal file
99
Horse Isle Server/Horse Isle Server/Horse Isle Server.csproj
Normal file
|
@ -0,0 +1,99 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{C48CBD82-AB30-494A-8FFA-4DE7069B5827}</ProjectGuid>
|
||||
<OutputType>Exe</OutputType>
|
||||
<RootNamespace>Horse_Isle_Server</RootNamespace>
|
||||
<AssemblyName>Horse Isle Server</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
|
||||
<Deterministic>true</Deterministic>
|
||||
<NuGetPackageImportStamp>
|
||||
</NuGetPackageImportStamp>
|
||||
<TargetFrameworkProfile />
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<Prefer32Bit>false</Prefer32Bit>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<Prefer32Bit>false</Prefer32Bit>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="MySqlConnector, Version=1.0.0.0, Culture=neutral, PublicKeyToken=d33d3e53aa5f8c92, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\MySqlConnector.1.0.1\lib\net471\MySqlConnector.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Buffers, Version=4.0.2.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Buffers.4.4.0\lib\netstandard2.0\System.Buffers.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Memory, Version=4.0.1.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Memory.4.5.0\lib\netstandard2.0\System.Memory.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Net" />
|
||||
<Reference Include="System.Numerics" />
|
||||
<Reference Include="System.Numerics.Vectors, Version=4.1.3.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Numerics.Vectors.4.4.0\lib\net46\System.Numerics.Vectors.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Runtime.CompilerServices.Unsafe, Version=4.0.4.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Runtime.CompilerServices.Unsafe.4.5.0\lib\netstandard2.0\System.Runtime.CompilerServices.Unsafe.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Threading.Tasks.Extensions, Version=4.1.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Threading.Tasks.Extensions.4.3.0\lib\portable-net45+win8+wp8+wpa81\System.Threading.Tasks.Extensions.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Transactions" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Authentication.cs" />
|
||||
<Compile Include="Client.cs" />
|
||||
<Compile Include="Converters.cs" />
|
||||
<Compile Include="Database.cs" />
|
||||
<Compile Include="Logger.cs" />
|
||||
<Compile Include="ConfigReader.cs" />
|
||||
<Compile Include="CrossDomainPolicy.cs" />
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Properties\Resources.Designer.cs">
|
||||
<AutoGen>True</AutoGen>
|
||||
<DesignTime>True</DesignTime>
|
||||
<DependentUpon>Resources.resx</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Server.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="packages.config" />
|
||||
<None Include="Resources\server.properties" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="Properties\Resources.resx">
|
||||
<Generator>ResXFileCodeGenerator</Generator>
|
||||
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
|
||||
</EmbeddedResource>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="Resources\default_cross_domain.xml" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
21
Horse Isle Server/Horse Isle Server/Logger.cs
Normal file
21
Horse Isle Server/Horse Isle Server/Logger.cs
Normal file
|
@ -0,0 +1,21 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Horse_Isle_Server
|
||||
{
|
||||
class Logger
|
||||
{
|
||||
public static void DebugPrint(string text)
|
||||
{
|
||||
if (ConfigReader.Debug)
|
||||
Console.WriteLine("[DEBUG] " + text);
|
||||
}
|
||||
public static void ErrorPrint(string text)
|
||||
{
|
||||
Console.WriteLine("[ERROR] " + text);
|
||||
}
|
||||
}
|
||||
}
|
21
Horse Isle Server/Horse Isle Server/Program.cs
Normal file
21
Horse Isle Server/Horse Isle Server/Program.cs
Normal file
|
@ -0,0 +1,21 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net.Sockets;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Horse_Isle_Server
|
||||
{
|
||||
class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
Directory.SetCurrentDirectory(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location));
|
||||
ConfigReader.OpenConfig();
|
||||
Database.OpenDatabase();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("Horse Isle Server")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("Horse Isle Server")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2020")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// Setting ComVisible to false makes the types in this assembly not visible
|
||||
// to COM components. If you need to access a type in this assembly from
|
||||
// COM, set the ComVisible attribute to true on that type.
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
[assembly: Guid("c48cbd82-ab30-494a-8ffa-4de7069b5827")]
|
||||
|
||||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
// Major Version
|
||||
// Minor Version
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
104
Horse Isle Server/Horse Isle Server/Properties/Resources.Designer.cs
generated
Normal file
104
Horse Isle Server/Horse Isle Server/Properties/Resources.Designer.cs
generated
Normal file
|
@ -0,0 +1,104 @@
|
|||
//------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// This code was generated by a tool.
|
||||
// Runtime Version:4.0.30319.42000
|
||||
//
|
||||
// Changes to this file may cause incorrect behavior and will be lost if
|
||||
// the code is regenerated.
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace Horse_Isle_Server.Properties {
|
||||
using System;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// A strongly-typed resource class, for looking up localized strings, etc.
|
||||
/// </summary>
|
||||
// This class was auto-generated by the StronglyTypedResourceBuilder
|
||||
// class via a tool like ResGen or Visual Studio.
|
||||
// To add or remove a member, edit your .ResX file then rerun ResGen
|
||||
// with the /str option, or rebuild your VS project.
|
||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")]
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
||||
internal class Resources {
|
||||
|
||||
private static global::System.Resources.ResourceManager resourceMan;
|
||||
|
||||
private static global::System.Globalization.CultureInfo resourceCulture;
|
||||
|
||||
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
|
||||
internal Resources() {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the cached ResourceManager instance used by this class.
|
||||
/// </summary>
|
||||
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
|
||||
internal static global::System.Resources.ResourceManager ResourceManager {
|
||||
get {
|
||||
if (object.ReferenceEquals(resourceMan, null)) {
|
||||
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Horse_Isle_Server.Properties.Resources", typeof(Resources).Assembly);
|
||||
resourceMan = temp;
|
||||
}
|
||||
return resourceMan;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Overrides the current thread's CurrentUICulture property for all
|
||||
/// resource lookups using this strongly typed resource class.
|
||||
/// </summary>
|
||||
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
|
||||
internal static global::System.Globalization.CultureInfo Culture {
|
||||
get {
|
||||
return resourceCulture;
|
||||
}
|
||||
set {
|
||||
resourceCulture = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to <cross-domain-policy>
|
||||
/// <allow-access-from domain="*" to-ports="1080" secure="false"/>
|
||||
///</cross-domain-policy>.
|
||||
/// </summary>
|
||||
internal static string DefaultCrossDomain {
|
||||
get {
|
||||
return ResourceManager.GetString("DefaultCrossDomain", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to # Horse Isle Server Default Configuration File
|
||||
///
|
||||
///# Ip address the server will bind to (default: 0.0.0.0 ALL INTERFACES)
|
||||
///ip=0.0.0.0
|
||||
///# Port the server will bind to (default: 1080)
|
||||
///port=1080
|
||||
///
|
||||
///# MariaDB Database
|
||||
///db_ip=127.0.0.1
|
||||
///db_username=root
|
||||
///db_password=test123
|
||||
///db_port=3306
|
||||
///
|
||||
///# Map Data
|
||||
///map=MapData.bmp
|
||||
///overlaymap=oMapData.bmp
|
||||
///
|
||||
///# Cross-Domain Policy File
|
||||
///crossdomain="CrossDomainPolicy.xml
|
||||
///
|
||||
///# Should print debug logs
|
||||
///debug=false.
|
||||
/// </summary>
|
||||
internal static string DefaultServerProperties {
|
||||
get {
|
||||
return ResourceManager.GetString("DefaultServerProperties", resourceCulture);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
127
Horse Isle Server/Horse Isle Server/Properties/Resources.resx
Normal file
127
Horse Isle Server/Horse Isle Server/Properties/Resources.resx
Normal file
|
@ -0,0 +1,127 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
|
||||
<data name="DefaultCrossDomain" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>..\Resources\default_cross_domain.xml;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;Windows-1252</value>
|
||||
</data>
|
||||
<data name="DefaultServerProperties" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>..\Resources\server.properties;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;Windows-1252</value>
|
||||
</data>
|
||||
</root>
|
|
@ -0,0 +1,3 @@
|
|||
<cross-domain-policy>
|
||||
<allow-access-from domain="*" to-ports="1080" secure="false"/>
|
||||
</cross-domain-policy>
|
|
@ -0,0 +1,23 @@
|
|||
# Horse Isle Server Default Configuration File
|
||||
|
||||
# Ip address the server will bind to (default: 0.0.0.0 ALL INTERFACES)
|
||||
ip=0.0.0.0
|
||||
# Port the server will bind to (default: 1080)
|
||||
port=1080
|
||||
|
||||
# MariaDB Database
|
||||
db_ip=127.0.0.1
|
||||
db_name=beta
|
||||
db_username=root
|
||||
db_password=test123
|
||||
db_port=3306
|
||||
|
||||
# Map Data
|
||||
map=MapData.bmp
|
||||
overlaymap=oMapData.bmp
|
||||
|
||||
# Cross-Domain Policy File
|
||||
crossdomain=CrossDomainPolicy.xml
|
||||
|
||||
# Should print debug logs
|
||||
debug=false
|
72
Horse Isle Server/Horse Isle Server/Server.cs
Normal file
72
Horse Isle Server/Horse Isle Server/Server.cs
Normal file
|
@ -0,0 +1,72 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Net.Sockets;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Horse_Isle_Server
|
||||
{
|
||||
class Server
|
||||
{
|
||||
|
||||
public static Socket ServerSocket;
|
||||
public static List<Client> ConnectedClients = new List<Client>();
|
||||
|
||||
public static void OnCrossdomainPolicyRequest(Client sender) // When a cross-domain-policy request is received.
|
||||
{
|
||||
Logger.DebugPrint("Cross-Domain-Policy request received from: " + sender.RemoteIp);
|
||||
|
||||
byte[] crossDomainPolicyResponse = CrossDomainPolicy.GetPolicy(); // Generate response packet
|
||||
sender.SendPacket(crossDomainPolicyResponse); // Send to client.
|
||||
}
|
||||
|
||||
public static void OnLoginRequest(Client sender, byte[] packet)
|
||||
{
|
||||
string loginRequestString = Encoding.UTF8.GetString(packet).Substring(1);
|
||||
|
||||
if (!loginRequestString.Contains('|'))
|
||||
{
|
||||
Logger.ErrorPrint(sender.RemoteIp + " Sent an invalid login request" + loginRequestString);
|
||||
return;
|
||||
}
|
||||
|
||||
string[] loginParts = loginRequestString.Split('|');
|
||||
if(loginParts.Length < 3)
|
||||
{
|
||||
Logger.ErrorPrint(sender.RemoteIp + " Sent a login request of invalid length. " + loginRequestString);
|
||||
return;
|
||||
}
|
||||
|
||||
int version = int.Parse(loginParts[0]);
|
||||
string encryptedUsername = loginParts[1];
|
||||
string encryptedPassword = loginParts[2];
|
||||
string username = Authentication.DecryptLogin(encryptedUsername);
|
||||
string password = Authentication.DecryptLogin(encryptedPassword);
|
||||
|
||||
if(Authentication.CheckPassword(username, password))
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
public static void StartServer()
|
||||
{
|
||||
ServerSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
|
||||
IPAddress hostIP = IPAddress.Parse(ConfigReader.BindIP);
|
||||
IPEndPoint ep = new IPEndPoint(hostIP, ConfigReader.Port);
|
||||
ServerSocket.Bind(ep);
|
||||
Logger.DebugPrint("Binding to ip: " + ConfigReader.BindIP + " On port: " + ConfigReader.Port.ToString());
|
||||
ServerSocket.Listen(10000);
|
||||
|
||||
while(true)
|
||||
{
|
||||
Logger.DebugPrint("Waiting for new connections...");
|
||||
|
||||
Socket cientSocket = ServerSocket.Accept();
|
||||
Client client = new Client(cientSocket);
|
||||
ConnectedClients.Add(client);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
9
Horse Isle Server/Horse Isle Server/packages.config
Normal file
9
Horse Isle Server/Horse Isle Server/packages.config
Normal file
|
@ -0,0 +1,9 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="MySqlConnector" version="1.0.1" targetFramework="net48" />
|
||||
<package id="System.Buffers" version="4.4.0" targetFramework="net48" />
|
||||
<package id="System.Memory" version="4.5.0" targetFramework="net48" />
|
||||
<package id="System.Numerics.Vectors" version="4.4.0" targetFramework="net48" />
|
||||
<package id="System.Runtime.CompilerServices.Unsafe" version="4.5.0" targetFramework="net48" />
|
||||
<package id="System.Threading.Tasks.Extensions" version="4.3.0" targetFramework="net48" />
|
||||
</packages>
|
Loading…
Add table
Add a link
Reference in a new issue