This is my AuthServer.cs
Code:
/*
* Created by SharpDevelop.
* User: sams
* Date: 3/8/2009
* Time: 2:19 PM
*
* To change this template use Tools | Options | Coding | Edit Standard Headers.
*/
using System;
using System.IO;
using System.Net.Sockets;
namespace CoEmu_v2_LoginServer.Connections
{
/// <summary>
/// Description of AuthSocket.
/// </summary>
public static class AuthSocket
{
private static Socket Auth;
private const string SERVER_IP = "127.0.0.1";
public const string NANO_IP = "86.149.255.50";
private const int AUTH_PORT = 5817;
public static bool Authorize(string user, uint key, bool nano)
{
try{
Auth = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
if(!nano)
{
[COLOR="Red"]Auth.Connect(SERVER_IP, AUTH_PORT);[/COLOR] }
else{
Auth.Connect(NANO_IP, AUTH_PORT);
}
Auth.Send(System.Text.Encoding.ASCII.GetBytes("(A)" + user + "," + key));
Auth.Close();
}
catch(Exception e)
{
Console.WriteLine(e.ToString());
return false;
}
return true;
}
}
}
Help????
I this it has something to do with this....
Code:
/*
* Created by SharpDevelop.
* User: sams
* Date: 3/8/2009
* Time: 12:38 PM
*
* To change this template use Tools | Options | Coding | Edit Standard Headers.
*/
using System;
using CoEmu_v2_LoginServer.Connections;
using CoEmu_v2_LoginServer.Database;
namespace CoEmu_v2_LoginServer
{
/// <summary>
/// Allows for handling of packets from the client->loginserver or client->gameserver.
/// </summary>
public static class PacketProcessor
{
public static void ProcessPacket(byte[] Data, ClientSocket CSocket)
{
int Type = (Data[3] << 8) + Data[2];
switch(Type)
{
case 1086:
{
RequestLogin(Data, CSocket);
break;
}
default:
{
Console.WriteLine("[LoginServer] Unknown packet type: " + Type);
break;
}
}
}
public static void RequestLogin(byte[] Data, ClientSocket CSocket)
{
string AccountName = "";
string Password = "";
string ServerName = "";
if(Data.Length >= 276)
{
for (int i = 4; i < 0x114; i++)
{
if (i >= 0x14 && i < 0xf9)
{
if(Data[i] != 0x00)
Password += (Convert.ToString(Data[i], 16)).PadLeft(2, '0');
}
if (i < 0x14)
if (Data[i] != 0x00)
AccountName += Convert.ToChar(Data[i]);
if (i > 0xfa)
if (Data[i] != 0x00)
ServerName += Convert.ToChar(Data[i]);
}
}
else
{
return;
}
/* if(AccountName != "dsfreak")
{
CSocket.Disconnect();
return;
}*/
System.Random Random = new System.Random();
Console.WriteLine("[LoginServer] " + AccountName + " logging in to " + ServerName);
string DBPass = Database.Database.Password(AccountName);
//TODO: Check for ban.
if(DBPass != "ERROR")
{
if(DBPass == Password)
{
//OKAY to login!
uint Key = (uint)(Random.Next(10000000) << 32);
Key = Key << 32;
Key = (uint)(Key | (uint)Random.Next(10000000));
byte[] Key1 = new byte[4];
byte[] Key2 = new byte[4];
Key1[0] = (byte)(((ulong)Key & 0xff00000000000000L) >> 56);
Key1[1] = (byte)((Key & 0xff000000000000) >> 48);
Key1[2] = (byte)((Key & 0xff0000000000) >> 40);
Key1[3] = (byte)((Key & 0xff00000000) >> 32);
Key2[0] = (byte)((Key & 0xff000000) >> 24);
Key2[1] = (byte)((Key & 0xff0000) >> 16);
Key2[2] = (byte)((Key & 0xff00) >> 8);
Key2[3] = (byte)(Key & 0xff);
[COLOR="red"] if(ServerName == "PixelEmpire")
{
/*if(AuthSocket.Authorize(AccountName, Key, false))
{
CSocket.Send(Packets.AuthResponse("127.0.0.1", Key1, Key2));
}
else
{
CSocket.Disconnect();
}*/
if (AuthSocket.Authorize(AccountName, Key, false))
{
CSocket.Send(Packets.AuthResponse("127.0.0.1", Key1, Key2));
}
else
{
CSocket.Disconnect();
}
}
else if(ServerName == "CoEmu.Nano")
{
if(AuthSocket.Authorize(AccountName, Key, true))
{
CSocket.Send(Packets.AuthResponse("127.0.0.1", Key1, Key2));
}
else
{
CSocket.Disconnect();
}
}
}[/COLOR] else if(DBPass == "")
{
Console.WriteLine("[LoginServer](Diagnostic) Set password for " + AccountName);
Database.Database.SetPass(AccountName, Password);
//OKAY to login!
uint Key = (uint)(Random.Next(10000000) << 32);
Key = Key << 32;
Key = (uint)(Key | (uint)Random.Next(10000000));
byte[] Key1 = new byte[4];
byte[] Key2 = new byte[4];
Key1[0] = (byte)(((ulong)Key & 0xff00000000000000L) >> 56);
Key1[1] = (byte)((Key & 0xff000000000000) >> 48);
Key1[2] = (byte)((Key & 0xff0000000000) >> 40);
Key1[3] = (byte)((Key & 0xff00000000) >> 32);
Key2[0] = (byte)((Key & 0xff000000) >> 24);
Key2[1] = (byte)((Key & 0xff0000) >> 16);
Key2[2] = (byte)((Key & 0xff00) >> 8);
Key2[3] = (byte)(Key & 0xff);
[COLOR="RoyalBlue"] if(ServerName == "PixelEmpire")
{
/*if(AuthSocket.Authorize(AccountName, Key, false))
{
CSocket.Send(Packets.AuthResponse("86.149.255.50", Key1, Key2));
}
else
{
CSocket.Disconnect();
}*/
if (AuthSocket.Authorize(AccountName, Key, false))
{
CSocket.Send(Packets.AuthResponse("86.149.255.50", Key1, Key2));
}
else
{
CSocket.Disconnect();
}
}
else if(ServerName == "CoEmu.Nano")
{
if(AuthSocket.Authorize(AccountName, Key, true))
{
CSocket.Send(Packets.AuthResponse("86.149.255.50", Key1, Key2));
}
else
{
CSocket.Disconnect();
}
}
}
else
{
CSocket.Send(Packets.WrongPass());
CSocket.Disconnect();
}
}
else
{
Console.WriteLine("DBPass equals ERROR: " + DBPass);
CSocket.Disconnect();
}
}
}
}[/COLOR]






