Authentication Problems.

12/18/2013 14:12 killersub#1
Hello guys it's been a long time since I've been here.

Anyways cutting to conclusion, I've recently came back to maybe try and learn a "bit" of the C# language by using trial/error and building up a source released here in the forums. Yes, it is a 5700+ source. I know what you think, why start at such a high patch and why not a lower patch? Well, simply because I've been developing lower patches since the day I started here lol. I also wanted to get "in sync" with the conquer world as I have felt "left out of it".

Anyways... I have here a decent but buggy source that is aimed around patch 5730 or 5733. I am having the problem of the source not logging characters back in the game after they have logged out successfully. The usual error I get in the client is this:
Quote:
Error: Disconnected with game server. Please login again!
I am not going to lie, I have been trying to figure out how to do this but I just can't seem to figure out why. Please bare with me as I have lost most, if not, all of my knowledge in C# being gone all this time. I am going to put here my AuthState.cs:
Code:
using System;
using Conquer_Online_Server.Network.Cryptography;
using System.Net.Sockets;
using System.Collections.Generic;
using Conquer_Online_Server.Network.Sockets;
using System.Collections.Concurrent;
using Conquer_Online_Server.Network.GamePackets;

namespace Conquer_Online_Server.Client
{
    public class AuthState
    {
        private bool Alive = false;
        public Network.AuthPackets.Authentication Info;

        public Database.AccountTable Account;
        public Network.Cryptography.AuthCryptography Cryptographer;
        //public int PasswordSeed;
        public WinSocket _socket;

        public AuthState(WinSocket socket)
        {
            _socket = socket;
            Alive = true;
        }
        public void Send(byte[] buffer)
        {
            if (Alive)
            {
                byte[] _buffer = new byte[buffer.Length];
                Buffer.BlockCopy(buffer, 0, _buffer, 0, buffer.Length);
                lock (Cryptographer)
                {
                    Cryptographer.Encrypt(_buffer);
                    try
                    {
                        _socket.Send(_buffer);
                    }
                    catch (Exception e)//posible proxy/food with proxy
                    {
                        Console.WriteLine(e.ToString());
                        Program.SaveException(e);
                        this.Disconnect();
                    }
                }
            }
        }
        public void Send(Interfaces.IPacket buffer)
        {
            Send(buffer.ToArray());
        }

        public void Disconnect()
        {
            if (Alive)
            {
                Alive = false;
                _socket.Disconnect(false);
            }
        }
        public static uint nextID = 0;


        public int PasswordSeed = 0;
    }
}
Any ideas/countermeasures that will help me with this problem are highly appreciated. And please, don't flame me for using "this type of source".

Thanks a lot!
12/18/2013 15:04 Super Aids#2
"Error: Disconnected with game server. Please login again! " is not an issue in the auth server.

It's when you don't handle the login sequence at the game server proper and that it gets disconnected meanwhile.

Check that you aren't throwing any exceptions, that may disconnect it OR that the authentication at the game server goes through so it doesn't disconnect for ex. invalid UID.

I'd suggest you set a breakpoint at packet 1052.
12/18/2013 16:24 killersub#3
Quote:
Originally Posted by Super Aids View Post
"Error: Disconnected with game server. Please login again! " is not an issue in the auth server.

It's when you don't handle the login sequence at the game server proper and that it gets disconnected meanwhile.

Check that you aren't throwing any exceptions, that may disconnect it OR that the authentication at the game server goes through so it doesn't disconnect for ex. invalid UID.

I'd suggest you set a breakpoint at packet 1052.
Oh! silly me, I almost forgot that this wasn't anywhere near the Auth sequence.

Anyways, I set the breakpoint and it seems this tricky little error(that I've seen before) has shown its face.

here is the error it's throwing:
Quote:
A call to PInvoke function 'Conquer_Online_Server!Conquer_Online_Server.Netwo rk.Cryptography.Blowfish::CAST_set_key' has unbalanced the stack. This is likely because the managed PInvoke signature does not match the unmanaged target signature. Check that the calling convention and parameters of the PInvoke signature match the target unmanaged signature.
It is coming from this void:
Code:
public void SetKey(byte[] data)
        {
            _encryptNum = 0;
            _decryptNum = 0;
            this line--> CAST_set_key(_key, data.Length, data);
        }
and here is that line of code:
Code:
[DllImport("Libeay36.dll")]
        public extern static void CAST_set_key(IntPtr _key, int len, byte[] data);
I have tried the CallingConnvection method but it does not seem to fix the problem.

Sorry for another post but seeing as no one wants to reply, is this error very tricky to figure out? It doesn't even want to create an account now.

Sorry for another post but I'm really stumped as to what may be causing this error to throw. I have tried breakpoints everywhere but that doesn't seem to be getting me anywhere; Also, I have tried a method that should've worked now but worked back then called the: CallingConvection.Cdecl which supposedly dissolves this error but not in my case.
12/18/2013 20:16 Super Aids#4
You calling convention is invalid.
Code:
[DllImport("libeay32.dll", CallingConvention = CallingConvention.Cdecl)]
Change that for ALL of them
12/18/2013 21:21 killersub#5
Quote:
Originally Posted by Super Aids View Post
You calling convention is invalid.
Code:
[DllImport("libeay32.dll", CallingConvention = CallingConvention.Cdecl)]
Change that for ALL of them
for some reason the original uploader of the source included 3 .dll files of 32,34 and 36. Like I said, I have tried the CallingConvention before and it gave me great results, with other sources that is.

EDIT: I have tried this and it does NOT work. for characters that exist it will give me the aforementioned error, for characters that do not exist yet it gives me the invalid account id/password error.

EDIT2: I seem to be logged in now using a new account, I will try an existing account and see if it also gives me errors.

EDIT3: I have fully logged back into accounts numerous times without error in the debug console/without the debug console. Believe me when I say that I have tried that method earlier today and it still flashed me the same error for some apparent reason. Supposedly, now it is working fine.

Thanks for the help mate.