Client crash at login packet ...

08/12/2014 13:17 abdeen#1
Hey people as title says and i am sure it's will be stupid question but i failed at this point ...

i am working on Redux source 5065 i am changed log-in way to this :

PHP Code:
#region Receive Data
        
private unsafe void Auth_OnReceive(ISocketWrapper arg2byte[] arg1)
        {
            if (
arg1.Length == 52)
            {
                
AuthState player arg2.Connector as AuthState;
                
player.Cryptographer.Decrypt(arg1arg1arg1.Length);
                
player.Info = new Authentication();
                
player.Info.Deserialize(arg1);
                
player.Account = new Database.AccountTable(player.Info.Username);
                
Forward Fw = new Forward();
                if (
player.Info.Password == player.Account.Password)
                {
                    if (
player.Account.State == Database.AccountTable.AccountState.Banned)
                        
Fw.Type = (uint)Forward.ForwardType.Banned;
                    else
                        
Fw.Type Forward.ForwardType.Ready;
                }
                else
                {
                    
Fw.Type Forward.ForwardType.InvalidInfo;
                }
                if (
Fw.Type != Forward.ForwardType.InvalidInfo)
                {

                    
Fw.Identifier Forward.Incrementer.Next;
                    
ServerBase.Kernel.AwaitingPool.Add(Fw.Identifierplayer.Account);
                }
                
Fw.IP "127.0.0.1";
                
Fw.Port 5816;
                
player.Send(Fw);
            }
            else
            {
                
arg2.Socket.Disconnect(false);
            }
                        
        }
        
#endregion 
and here is Forward packet class :

PHP Code:
    public class Forward Interfaces.IPacket
    
{
        public static 
ServerBase.Counter Incrementer;
        public 
enum ForwardType byte Ready 2InvalidInfo 1Banned }
        
byte[] Buffer;
        public 
Forward()
        {
            
Buffer = new byte[32];
            
Network.Writer.WriteUInt16(320Buffer);
            
Network.Writer.WriteUInt16(10552Buffer);
        }
        public 
uint Identifier
        
{
            
get
            
{
                return 
BitConverter.ToUInt32(Buffer4);
            }
            
set
            
{
                
Network.Writer.WriteUInt32(value4Buffer);
            }
        }
        public 
ForwardType Type
        
{
            
get
            
{
                return (
ForwardType)(byte)BitConverter.ToUInt32(Buffer8);
            }
            
set
            
{
                
Network.Writer.WriteUInt32((byte)value8Buffer);
            }
        }
        public 
string IP
        
{
            
get
            
{
                return 
Encoding.ASCII.GetString(Buffer1216);
            }
            
set
            
{
                
Network.Writer.WriteString(value12Buffer);
            }
        }
        public 
ushort Port
        
{
            
get
            
{
                return 
BitConverter.ToUInt16(Buffer28);
            }
            
set
            
{
                
Network.Writer.WriteUInt16(value28Buffer);
            }
        }
        public 
void Deserialize(byte[] buffer)
        {
            
//no implementation
        
}
        public 
byte[] ToArray()
        {
            return 
Buffer;
        }
    } 
and my problem i am facing is if the entered info is incorrect i get invalid info message , but if its correct or banned i get the client crashed.

it's only crash when it receive the type is ready or banned from the source , but if its invalid info type its show me the message successfully
08/12/2014 14:19 Super Aids#2
Most likely a cryptography issue.
08/12/2014 14:35 abdeen#3
Quote:
Originally Posted by Super Aids View Post
Most likely a cryptography issue.
here the AuthState.cs class :

and you can see i it's encrypt the packet before it be sent

PHP Code:
public class AuthState 
    
{
        
#region Variables
        
public ISocketWrapper Socket get; private set; }
        public 
AuthCryptography Cryptographer get; private set; }
        public 
Database.AccountTable Account;
        public 
Packets.Login.Authentication Info;
        private 
byte[] SendBuffer;
        public const 
int BaseSendBufferSize 512;
        
#endregion
        #region Constructor
        
public AuthState(ISocketWrapper client)
        {
            
Socket client;
            
Cryptographer = new AuthCryptography();
            
SendBuffer = new byte[BaseSendBufferSize];
        }
        
#endregion
        #region Methods
        
public void Send(Interfaces.IPacket buffer)
        {
            
Send(buffer.ToArray());
        }
        public 
void Send(byte[] buffer)
        {
            
Cryptographer.Encrypt(bufferbufferbuffer.Length);
            
Socket.Send(buffer);
        }

        public 
void Disconnect()
        {
            if(
Socket.Alive)
                
Socket.Disconnect();
        }
        
#endregion
    

and this code shows that the packet decrypted before i use it :

PHP Code:
#region Receive Data
        
private unsafe void Auth_OnReceive(ISocketWrapper arg2byte[] arg1)
        {
            if (
arg1.Length == 52)
            {
                
AuthState player arg2.Connector as AuthState;
                
player.Cryptographer.Decrypt(arg1arg1arg1.Length);
                
player.Info = new Authentication();
                
player.Info.Deserialize(arg1);
                
player.Account = new Database.AccountTable(player.Info.Username);
                
Forward Fw = new Forward();
                if (
player.Info.Password == player.Account.Password)
                {
                    if (
player.Account.State == Database.AccountTable.AccountState.Banned)
                        
Fw.Type = (uint)Forward.ForwardType.Banned;
                    else
                        
Fw.Type Forward.ForwardType.Ready;
                }
                else
                {
                    
Fw.Type Forward.ForwardType.InvalidInfo;
                }
                if (
Fw.Type != Forward.ForwardType.InvalidInfo)
                {

                    
Fw.Identifier Forward.Incrementer.Next;
                    
ServerBase.Kernel.AwaitingPool.Add(Fw.Identifierplayer.Account);
                }
                
Fw.IP "127.0.0.1";
                
Fw.Port 5816;
                
player.Send(Fw);
            }
            else
            {
                
arg2.Socket.Disconnect(false);
            }
                        
        }
        
#endregion 
and at least here is AuthCryptography.cs :

PHP Code:
public class AuthCryptography 
    
{
        private 
ushort InCounter;
        private 
ushort OutCounter;

        public 
void Decrypt(byte[] Inbyte[] Outint Length)
        {
            
lock (this)
            {
                for (
int i 0Lengthi++)
                {
                    
Out[i] = (byte)(In[i] ^ 0xab);
                    
Out[i] = (byte)((Out[i] << 4) | (Out[i] >> 4));
                    
Out[i] = (byte)(Key2[this.InCounter >> 8] ^ Out[i]);
                    
Out[i] = (byte)(Key1[this.InCounter 0xff] ^ Out[i]);
                    
this.InCounter = (ushort)(this.InCounter 1);
                }
            }
        }

        public 
unsafe void Encrypt(byteInbyte[] Outint Length)
        {
            
lock (this)
            {
                for (
int i 0Lengthi++)
                {
                    
Out[i] = (byte)(In[i] ^ 0xab);
                    
Out[i] = (byte)((Out[i] << 4) | (Out[i] >> 4));
                    
Out[i] = (byte)(Key2[this.OutCounter >> 8] ^ Out[i]);
                    
Out[i] = (byte)(Key1[this.OutCounter 0xff] ^ Out[i]);
                    
this.OutCounter = (ushort)(this.OutCounter 1);
                }
            }
        }

        public 
void Encrypt(byte[] Inbyte[] Outint Length)
        {
            
lock (this)
            {
                for (
int i 0Lengthi++)
                {
                    
Out[i] = (byte)(In[i] ^ 0xab);
                    
Out[i] = (byte)((Out[i] << 4) | (Out[i] >> 4));
                    
Out[i] = (byte)(Key2[this.OutCounter >> 8] ^ Out[i]);
                    
Out[i] = (byte)(Key1[this.OutCounter 0xff] ^ Out[i]);
                    
this.OutCounter = (ushort)(this.OutCounter 1);
                }
            }
        } 
        
        
#region  Key 1
        
public static byte[] Key1 = new byte[] { 
            
0x9d0x900x830x8a0xd11400xe70xf60x25400xeb1300x991000x8f0x2e
            
0x2d0x400xd32500xe10xbc0xb72300xb50xd80x3b0xf20xa90x940x5f30
            
0xbd2400x230x6a0xf10xec0x870xd60x450x880x8b0x620xb90xc40x2f14
            
0x4d1600x730xda10x1c0x570xc60xd50x380xdb2100xc90xf40xff0xfe
            
0xdd800xc30x4a0x110x4c0x270xb60x650xe80x2b0x420xd90x240xcf0xee
            
0x6d00x130xba0x210x7c0xf70xa60xf50x980x7b0xb20xe90x540x9f0xde
            
0xfd0xb00x630x2a0x310xac0xc71500x850x480xcb0x220xf90x840x6f0xce
            
0x8d0x600xb30x9a0x412200x970x860x150xf80x1b0x9291800x3f190
            
0x1d0x103100x51120x670x760xa50xa80x6b20x190xe4150xae
            
0xad0xc00x530x7a0x61600x370x660x350x580xbb0x720x29200xdf0x9e
            
0x3d0x700xa30xea0x710x6c70x560xc58110xe20x390x440xaf0x8e
            
0xcd0x200xf3900x810x9c0xd7700x550xb80x5b0x520x490x740x7f0x7e
            
0x5d0xd00x430xca0x910xcc0xa70x360xe50x680xab0xc20x590xa40x4f110
            
0xed0x800x930x3a0xa10xfc0x770x260x750x180xfb500x690xd40x1f0x5e
            
0x7d0x300xe31700xb10x2c0x470x1652000x4b0xa20x7940xef0x4e
            
130xe00x330x1a0xc10x5c0x1760x951200x9b0x120x890x340xbf0x3e
         
};
        
#endregion
        #region Key 2
        
public static byte[] Key2 = new byte[] { 
            
0x620x4f0xe80x150xde0xeb40x910x1a0xc70xe00x4d0x160xe30x7c0x49
            
2100x3f0xd80x850x4e0xdb0xf410x8a0xb70xd00xbd0x860xd30x6c0xb9
            
0x420x2f2000xf51900xcb0xe40x712500xa70xc00x2d0xf60xc30x5c0x29
            
0xb20x1f0xb80x650x2e0xbb0xd40xe10x6a0x970xb00x9d0x660xb30x4c0x99
            
0x22150xa80xd50x9e0xab0xc40x510xda0x87160130xd60xa3609
            
0x920xff0x980x45140x9b1800xc10x4a0x770x900x7d700x930x2c0x79
            
20xef0x880xb50x7e0x8b0xa40x310xba0x670x800xed0xb60x830x1c0xe9
            
0x720xdf1200x250xee0x7b0x940xa10x2a0x570x700x5d0x260x73120x59
            
0xe20xcf0x680x950x5e0x6b0x840x110x9a0x470x600xcd1500x630xfc0xc9
            
0x520xbf0x5850xce0x5b0x740x81100x37800x3d60x530xec0x39
            
0xc20xaf0x480x750x3e0x4b1000xf10x7a0x270x400xad0x760x432200xa9
            
500x9f0x380xe50xae0x3b0x540x610xea0x170x300x1d2300x330xcc0x19
            
0xa20x8f400x55300x2b0x440xd19070x200x8d0x560x230xbc0x89
            
0x120x7f0x180xc50x8e0x1b0x340x410xca0xf70x100xfd0xc60x130xac0xf9
            
1300x6f80x350xfe110x240xb10x3a0xe700x6d0x3630x9c0x69
            
0xf20x5f0xf80xa51100xfb200x211700xd72400xdd0xa60xf31400xd9
         
};

        
#endregion
    

so where is my issue in the codes ??
08/12/2014 14:44 kakamankoko#4
Fw.IP = "127.0.0.1"; make it your hamachi ip or 192.168.1.xx ip client will crash if you try to connect it to 127.0.0.1
08/12/2014 16:47 abdeen#5
Quote:
Originally Posted by kakamankoko View Post
Fw.IP = "127.0.0.1"; make it your hamachi ip or 192.168.1.xx ip client will crash if you try to connect it to 127.0.0.1
Thanks a lot its fixed now after i changed the ip to default gateway ip ...