Esempio n. 1
0
        private void ClientBeginAcceptCallback(IAsyncResult ar)
        {
            try
            {
                lock (this)
                {
                    if (!accepting)
                    {
                        return;
                    }

#if DEBUG_PROXY
                    Trace.WriteLine("[DEBUG] Proxy [ClientBeginAcceptCallback]");
#endif

                    if (loginClientSocket == null || worldClientSocket == null)
                    {
                        return;
                    }

                    accepting = false;

                    Protocol protocol = (Protocol)ar.AsyncState;
                    clientSocket = null;

                    if (protocol == Protocol.Login)
                    {
                        clientSocket = loginClientSocket.EndAccept(ar);
                    }
                    else
                    {
                        clientSocket = worldClientSocket.EndAccept(ar);

                        serverSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                        CharacterLoginInfo selectedChar = charList[client.SelectedChar];
                        serverSocket.Connect(new IPEndPoint(selectedChar.WorldIP, selectedChar.WorldPort));

                        serverInMessage.Reset();
                        serverSocket.BeginReceive(serverInMessage.Buffer, 0, 2, SocketFlags.None, ServerReceiveCallback, null);
                    }

                    clientSocket.LingerState = new LingerOption(true, 2);

                    loginClientSocket.Close();
                    worldClientSocket.Close();

                    loginClientSocket = null;
                    worldClientSocket = null;

                    clientInMessage.Reset();
                    clientSocket.BeginReceive(clientInMessage.Buffer, 0, 2, SocketFlags.None, ClientReceiveCallback, null);
                }
            }
            catch (Exception ex)
            {
                Trace.WriteLine("[Error] Proxy [ClientBeginAcceptCallback]: " + ex.Message);
            }
        }
Esempio n. 2
0
 public GameServerConnection(Constants.OperatingSystem opSystem, ushort version, string accountName,
                             string password, bool openTibia, bool debug, CharacterLoginInfo charInfo) :
     this(opSystem, version, accountName, password, openTibia, debug, charInfo.CharName, charInfo.WorldIPString, charInfo.WorldPort)
 {
 }