Created by: Andrew
This commit is contained in:
Andrew
2016-08-27 22:43:23 -04:00
commit 6d74d5b59e
31 changed files with 3002 additions and 0 deletions

View File

@@ -0,0 +1,51 @@
using KartExtreme.IO;
using KartExtreme.Net;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace KartExtreme
{
internal static class Application
{
private static bool _isRunning = false;
[STAThread]
private static void Main(string[] args)
{
Log.Entitle("KartExtreme");
DateTime dt = DateTime.Now;
try
{
Server.Initialize();
Application._isRunning = true;
}
catch (Exception e)
{
Log.Error(e);
}
if (Application._isRunning)
{
Log.Inform("Initialized in {0}ms.", (DateTime.Now - dt).TotalMilliseconds);
}
else
{
Log.Inform("Unable to initialize.");
}
Log.SkipLine();
while (Application._isRunning)
{
Console.Read();
}
Log.Quit();
}
}
}

View File

@@ -0,0 +1,61 @@
using KartExtreme.Data;
using KartExtreme.Net;
namespace KartExtreme.Kart
{
public class Player
{
public KartClient Client { get; private set; }
public int ID { get; private set; }
public string Name { get; private set; }
public byte Level { get; private set; }
public int Lucci { get; private set; }
private bool Assigned { get; set; }
public Player(int id = 0, KartClient client = null)
{
this.ID = id;
this.Client = client;
}
public void Load()
{
foreach (dynamic datum in new Datums("players").Populate("ID = '{0}'", this.ID))
{
this.Name = datum.Name;
this.Level = datum.Level;
this.Lucci = datum.Lucci;
this.Assigned = true;
}
}
public void Save()
{
dynamic datum = new Datum("players");
datum.ID = this.ID;
datum.Name = this.Name;
datum.Level = this.Level;
datum.Lucci = this.Lucci;
if (this.Assigned)
{
datum.Update("ID = '{0}'", this.ID);
}
else
{
datum.Insert();
}
}
public void Delete()
{
Database.Delete("players", "ID = '{0}'", this.ID);
this.Assigned = false;
}
}
}

View File

@@ -0,0 +1,70 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" 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>{C3521ADE-F5D2-4C53-8F2F-0E40A380AE6F}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>KartExtreme</RootNamespace>
<AssemblyName>KartExtreme</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<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="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Application.cs" />
<Compile Include="Kart\Player.cs" />
<Compile Include="Net\KartClient.cs" />
<Compile Include="Net\Server.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="app.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Common\Common.csproj">
<Project>{f163daab-bdd2-4510-9a20-604d73d334d0}</Project>
<Name>Common</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- 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.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

View File

@@ -0,0 +1,138 @@
using KartExtreme.IO;
using System;
using System.Net.Sockets;
using System.Text;
using KartExtreme.IO.Packet;
namespace KartExtreme.Net
{
public sealed class KartClient : Session
{
public KartClient(Socket socket)
: base(socket)
{
this.SendPatchData(Constants.Version, "http://kart.dn.nexoncdn.co.kr/patch");
/*
using (OutPacket outPacket = new OutPacket())
{
outPacket.WriteHexString("80 05 2B 28"); // NOTE: HEADER. DO NOT CHANGE. PROBABLY typeid() OF HANDLER?
// 8
outPacket.WriteShort(5002); // Note: Localisation.
// 10
outPacket.WriteShort(1); // NOTE: Service area/version.
// 12
outPacket.WriteShort(26); // NOTE: Subversion number? Current = 26. 25 = Incompatible with server, 27 = Close client.
// 14
outPacket.WriteString("http://kart.dn.nexoncdn.co.kr/patch");
// 18
// outPacket.WriteHexString("81 82 83 84 85 86 87 88");
// outPacket.WriteHexString("94 2E F9 A8 E1 4B 13 5D");
// outPacket.WriteHexString("01 02 03 04 05 06 07 08");
outPacket.WriteInt(0x11111111);
outPacket.WriteInt(0x22222222);
outPacket.WriteByte(0xE0);
outPacket.WriteHexString("03 00 09 03 00 00 03 00 00 00 00 00 83 A3 E5 47 00 00 15 00 0D 00 00 00 03 00 00 00 00 00 65");
// NOTE: Nothing more needed.
if (false)
{
outPacket.WriteHexString("80 05 2B 28"); // NOTE: HEADER. DO NOT CHANGE. PROBABLY typeid() OF HANDLER?
outPacket.WriteHexString("EA 00 03 00 95 0B");
outPacket.WriteString("");
// NOTE: Nothing more needed.
}
if (false)
{
outPacket.WriteHexString("80 05 2B 28 EA 03 03 00 95 0B");
outPacket.WriteString("");
// NOTE: Nothing more needed.
}
if (false)
{
// NOTE: Original (Korean KartRider).
outPacket.WriteHexString("80 05 2B 28");
outPacket.WriteHexString("EA 03 03 00 95 0B");
outPacket.WriteString("http://kart.dn.nexoncdn.co.kr/patch");
outPacket.WriteHexString("94 2E F9 A8 E1 4B 13 5D 76 03 00 09 03 00 00 03 00 00 00 00 00 83 A3 E5 47 00 00 15 00 0D 00 00 00 03 00 00 00 00 00 65");
}
this.Send(outPacket);
}
*/
}
public override void OnDisconnect()
{
Log.Inform("Lost connection from {0}.", this.Label);
Server.RemoveClient(this);
}
public override void OnPacket(InPacket inPacket)
{
try
{
//int typeId = inPacket.ReadInt();
//byte wdf = BitConverter.
Log.Hex("Received Packet ", inPacket.ToArray());
//Log.Inform("String val:" + Encoding.Unicode.GetString(inPacket.ToArray()));
byte typeId = inPacket.ReadByte();
byte a2 = inPacket.ReadByte();
byte a3 = inPacket.ReadByte();
byte a4 = inPacket.ReadByte();
int header = BitConverter.ToInt32(new byte[] { typeId, a2, a3, a4 }, 0);
switch (typeId)
{
case 0xBA:
using (OutPacket oPacket = new OutPacket())
{
oPacket.WriteInt(header + 1); // header
oPacket.WriteInt(0); // header
oPacket.WriteInt(0); // header
oPacket.WriteInt(0); // header
oPacket.WriteInt(0); // header
oPacket.WriteInt(0); // header
oPacket.WriteInt(0); // header
oPacket.WriteInt(0); // header
oPacket.WriteInt(0); // header
oPacket.WriteInt(0); // header
oPacket.WriteInt(0); // header
oPacket.WriteInt(0); // header
oPacket.WriteInt(0); // header
oPacket.WriteInt(0); // header
oPacket.WriteInt(0); // header
oPacket.WriteInt(0); // header
oPacket.WriteInt(0); // header
oPacket.WriteInt(0); // header
oPacket.WriteInt(0); // header
oPacket.WriteInt(0); // header
Send(oPacket);
//WALAO!
}
break;
default:
break;
}
}
catch (SendPacketException)
{
Log.Error("Client was disconnected while sending packet");
Close();
}
catch (Exception e)
{
Log.Error("Exception during packet handling from {0}: {1}", this.Label, e.ToString());
}
}
}
}

View File

@@ -0,0 +1,47 @@
using KartExtreme.Data;
using KartExtreme.IO;
using System;
using System.Collections.Generic;
using System.Net.Sockets;
namespace KartExtreme.Net
{
public static class Server
{
private static Acceptor _acceptor;
private static List<KartClient> _clients;
public static void Initialize()
{
Server._clients = new List<KartClient>();
Settings.Initialize();
Database.Test();
Database.Analyze();
Server._acceptor = new Acceptor(Settings.GetUShort("Net/Port"));
Server._acceptor.OnClientAccepted = Server.OnClientAccepted;
Server._acceptor.Start();
}
private static void OnClientAccepted(Socket socket)
{
KartClient client = new KartClient(socket);
Log.Inform("Accepted connection from {0}.", client.Label);
Server.AddClient(client);
}
public static void AddClient(KartClient client)
{
Server._clients.Add(client);
}
public static void RemoveClient(KartClient client)
{
Server._clients.Remove(client);
}
}
}

View File

@@ -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("KartExtreme")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("KartExtreme")]
[assembly: AssemblyCopyright("Copyright © 2014")]
[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("ae2be92d-a537-4b11-a719-5a6168df11df")]
// 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")]

View File

@@ -0,0 +1,3 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/></startup></configuration>