|
المشاركات 1,941 |
+التقييم 1.00 |
تاريخ التسجيل Apr 2019 |
الاقامة Egypt |
نظام التشغيل windows 7 |
رقم العضوية 1 |
using System;
using System.IO;
using System.Text;
using MoDY.Network.Cryptography;
namespace MoDY.Network.AuthPackets
{
public unsafe class Authentication : Interfaces.IPacket
{
public string Username;
public string Password;
public string Server;
public Authentication()
{
}
public void Deserialize(byte[] buffer)
{
if (buffer.Length == 312)
{
ushort length = BitConverter.ToUInt16(buffer, 0);
if (length == 312)
{
ushort type = BitConverter.ToUInt16(buffer, 2);
byte[] temp = new byte[16];
if (type == 1542)
{
MemoryStream MS = new MemoryStream(buffer);
BinaryReader BR = new BinaryReader(MS);
BR.ReadUInt16();
BR.ReadUInt16();
Username = Encoding.Default.GetString(BR.ReadBytes(32));
Username = Username.Replace("\0", "");
BR.ReadBytes(36);
var PasswordArray = BR.ReadBytes(32);
LoaderEncryption.Decrypt(PasswordArray, 32);
Password = Encoding.Default.GetString(PasswordArray);
Password = Password.Replace("\0", "");
BR.ReadBytes(32);
Server = Encoding.Default.GetString(BR.ReadBytes(32));
Server = Server.Replace("\0", "");
BR.Close();
MS.Close();
}
}
}
}
public byte[] ToArray()
{
throw new NotImplementedException();
}
public void Send(Client.GameState client)
{
throw new NotImplementedException();
}
}
}
using System;
using System.Text;
namespace MoDY.Network.AuthPackets
{
public unsafe class Forward : Interfaces.IPacket
{
byte[] Buffer;
public enum ForwardType : byte
{
Ready = 2,
Ready2 = 3,
InvalidInfo = 1,
Banned = 25,
WrongAccount = 57
}
public Forward()
{
Buffer = new byte[52];
Writer.WriteUInt16(52, 0, Buffer);
Writer.WriteUInt16(1055, 2, Buffer);
}
public uint Identifier
{
get { return BitConverter.ToUInt32(Buffer, 4); }
set { Writer.WriteUInt32(value, 4, Buffer); }
}
public ForwardType Type
{
get { return (ForwardType)(byte)BitConverter.ToUInt32(Buffer, 8); }
set { Writer.WriteUInt32((byte)value, 8, Buffer); }
}
public ushort Port
{
get { return BitConverter.ToUInt16(Buffer, 12); }
set { Writer.WriteUInt16(value, 12, Buffer); }
}
public string IP
{
get { return Encoding.Default.GetString(Buffer, 20, 16); }
set { Writer.WriteString(value, 20, Buffer); }
}
public byte[] ToArray()
{
return Buffer;
}
public void Deserialize(byte[] buffer)
{
}
public void Send(Client.GameState client)
{
client.Send(Buffer);
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace MoDY.Network.Cryptography
{
public class LoaderEncryption
{
private static byte[] Key = { 12, 12, 215, 10, 20, 11, 60, 193, 11, 96, 53, 157, 71, 37, 150, 225, 86, 224, 178, 184, 230, 147, 79, 194, 160, 0, 99, 239, 218, 134, 179, 13, 247, 155, 237, 245, 165, 245, 128, 144 };
public static void Encrypt(byte[] arr)
{
int length = Key.Length;
for (int i = 0; i < arr.Length; i++)
{
arr[i] ^= Key[i % length];
arr[i] ^= Key[(i + 1) % length];
}
}
public static void Decrypt(byte[] arr, int size)
{
int length = Key.Length;
for (int i = 0; i < size; i++)
{
arr[i] ^= Key[(i + 1) % length];
arr[i] ^= Key[i % length];
}
}
}
}
#region GameServer|AuthServer
#region GameServer|AuthServer
static void GameServer_OnClientReceive(byte[] buffer, int length, ClientWrapper obj)
{
if (obj.Connector == null)
{
obj.Disconnect();
return;
}
Client.GameState Client = obj.Connector as Client.GameState;
if (Client.Exchange)
{
Client.Exchange = false;
Client.Action = 1;
var crypto = new Network.Cryptography.GameCryptography(System.Text.Encoding.Default.GetBytes(Constants.GameCryptographyKey));
byte[] otherData = new byte[length];
Array.Copy(buffer, otherData, length);
crypto.Decrypt(otherData, length);
bool extra = false;
int pos = 0;
if (BitConverter.ToInt32(otherData, length - 140) == 128)//no extra packet
{
pos = length - 140;
Client.Cryptography.Decrypt(buffer, length);
}
else if (BitConverter.ToInt32(otherData, length - 176) == 128)//extra packet
{
pos = length - 176;
extra = true;
Client.Cryptography.Decrypt(buffer, length - 36);
}
int len = BitConverter.ToInt32(buffer, pos); pos += 4;
if (len != 128)
{
Client.Disconnect();
return;
}
byte[] pubKey = new byte[128];
for (int x = 0; x < len; x++, pos++) pubKey[x] = buffer[pos];
string PubKey = System.Text.Encoding.Default.GetString(pubKey);
Client.Cryptography = Client.DHKeyExchange.HandleClientKeyPacket(PubKey, Client.Cryptography);
if (extra)
{
byte[] data = new byte[36];
Buffer.BlockCopy(buffer, length - 36, data, 0, 36);
processData(data, 36, Client);
}
}
else
{
processData(buffer, length, Client);
}
}
private static void processData(byte[] buffer, int length, Client.GameState Client)
{
Client.Cryptography.Decrypt(buffer, length);
Client.Queue.Enqueue(buffer, length);
if (Client.Queue.CurrentLength > 1224)
{
Console.WriteLine("[Disconnect]Reason:The packet size is too big. " + Client.Queue.CurrentLength);
Client.Disconnect();
return;
}
while (Client.Queue.CanDequeue())
{
byte[] data = Client.Queue.Dequeue();
MsgHandler.Process(data, Client);
}
}
static void GameServer_OnClientConnect(ClientWrapper obj)
{
Client.GameState client = new Client.GameState(obj);
client.Send(client.DHKeyExchange.CreateServerKeyPacket());
obj.Connector = client;
}
static void GameServer_OnClientDisconnect(ClientWrapper obj)
{
if (obj.Connector != null)
(obj.Connector as Client.GameState).Disconnect();
else
obj.Disconnect();
}
static void AuthServer_OnClientReceive(byte[] buffer, int length, ClientWrapper arg3)
{
var player = arg3.Connector as Client.AuthClient;
player.Cryptographer.Decrypt(buffer, length);
player.Queue.Enqueue(buffer, length);
while (player.Queue.CanDequeue())
{
byte[] packet = player.Queue.Dequeue();
ushort len = BitConverter.ToUInt16(packet, 0);
ushort id = BitConverter.ToUInt16(packet, 2);
if (len == 312)
{
player.Info = new Authentication();
player.Info.Deserialize(packet);
player.Account = new AccountTable(player.Info.Username);
msvcrt.msvcrt.srand(player.PasswordSeed);
Forward Fw = new Forward();
if (player.Account.Password == player.Info.Password && player.Account.exists)
Fw.Type = Forward.ForwardType.Ready;
else
Fw.Type = Forward.ForwardType.InvalidInfo;
if (IPBan.IsBanned(arg3.IP))
{
Fw.Type = Forward.ForwardType.Banned;
player.Send(Fw);
return;
}
if (Fw.Type == Network.AuthPackets.Forward.ForwardType.Ready)
{
Fw.Identifier = player.Account.GenerateKey();
Kernel.AwaitingPool[Fw.Identifier] = player.Account;
Fw.IP = GameIP;
Fw.Port = GamePort;
}
player.Send(Fw);
}
}
}
static void AuthServer_OnClientDisconnect(ClientWrapper obj)
{
obj.Disconnect();
}
static void AuthServer_OnClientConnect(ClientWrapper obj)
{
Client.AuthClient authState;
obj.Connector = (authState = new Client.AuthClient(obj));
authState.Cryptographer = new Network.Cryptography.AuthCryptography();
Network.AuthPackets.PasswordCryptographySeed pcs = new PasswordCryptographySeed();
pcs.Seed = Kernel.Random.Next();
authState.PasswordSeed = pcs.Seed;
authState.Send(pcs);
}
internal static Client.GameState FindClient(string name)
{
return GamePool.FirstOrDefault(p => p.Player.LoweredName == name);
}
#endregion
الذين يشاهدون محتوى الموضوع الآن : 4 ( الأعضاء 0 والزوار 4) | |
|
الموضوع | كاتب الموضوع | المنتدى | مشاركات | آخر مشاركة |
سيستم اقوي لودر حمايه لودر [XMeGo] | Mahmoud | البرامج والودرات | 305 | 2024-08-11 06:40 PM |
صفحه شحن سورسات اليكس حصريا Alex Xcard | محمد ياسر | صفحات التسجيل كونكر اونلاين | 16 | 2024-04-19 06:45 PM |
اضافة الشخصية الجديده لسورس البروتوا كامل | محمد ياسر | تطوير سيرفرات كونكر | 94 | 2024-02-10 02:57 PM |
لو سمحت محتاج مساعدة انا محتاج اتعلم ازاى اعدل على سورسات كونكر وافكسدها | fersony | مشكلات السيرفيرات كونكر الشخصيه | 2 | 2020-03-09 01:46 PM |
سورسات | mohamedomar | مشكلات السيرفيرات كونكر الشخصيه | 3 | 2020-01-24 06:47 PM |