Exemple #1
0
        public void Redirect(Redirect redirect)
        {
            Logger.DebugFormat("Processing redirect");
            GlobalConnectionManifest.DeregisterClient(this);

            redirect.Destination.ExpectedConnections.TryAdd(redirect.Id, redirect);

            var endPoint = Socket.RemoteEndPoint as IPEndPoint;

            byte[] addressBytes = IPAddress.IsLoopback(endPoint.Address) ? IPAddress.Loopback.GetAddressBytes() : Game.IpAddress.GetAddressBytes();

            Array.Reverse(addressBytes);

            var x03 = new ServerPacket(0x03);

            x03.Write(addressBytes);
            x03.WriteUInt16((ushort)redirect.Destination.Port);
            x03.WriteByte((byte)(redirect.EncryptionKey.Length + Encoding.GetEncoding(949).GetBytes(redirect.Name).Length + 7));
            x03.WriteByte(redirect.EncryptionSeed);
            x03.WriteByte((byte)redirect.EncryptionKey.Length);
            x03.Write(redirect.EncryptionKey);
            x03.WriteString8(redirect.Name);
            x03.WriteUInt32(redirect.Id);
            Enqueue(x03);
        }
Exemple #2
0
        public void Redirect(Redirect redirect, bool isLogoff = false)
        {
            GameLog.InfoFormat("Processing redirect");
            GlobalConnectionManifest.RegisterRedirect(this, redirect);
            GameLog.InfoFormat("Redirect: cid {0}", this.ConnectionId);
            GameLog.Info($"Redirect EncryptionKey is {Encoding.ASCII.GetString(redirect.EncryptionKey)}");
            if (isLogoff)
            {
                GlobalConnectionManifest.DeregisterClient(this);
            }
            redirect.Destination.ExpectedConnections.TryAdd(redirect.Id, redirect);

            var endPoint = Socket.RemoteEndPoint as IPEndPoint;

            byte[] addressBytes = IPAddress.IsLoopback(endPoint.Address) ? IPAddress.Loopback.GetAddressBytes() : Game.IpAddress.GetAddressBytes();

            Array.Reverse(addressBytes);

            var x03 = new ServerPacket(0x03);

            x03.Write(addressBytes);
            x03.WriteUInt16((ushort)redirect.Destination.Port);
            x03.WriteByte((byte)(redirect.EncryptionKey.Length + Encoding.ASCII.GetBytes(redirect.Name).Length + 7));
            x03.WriteByte(redirect.EncryptionSeed);
            x03.WriteByte((byte)redirect.EncryptionKey.Length);
            x03.Write(redirect.EncryptionKey);
            x03.WriteString8(redirect.Name);
            x03.WriteUInt32(redirect.Id);
            Thread.Sleep(100);
            Enqueue(x03);
        }
Exemple #3
0
 public void Disconnect()
 {
     GlobalConnectionManifest.DeregisterClient(this);
     World.MessageQueue.Add(new HybrasylControlMessage(ControlOpcodes.CleanupUser, ConnectionId));
     ClientState.Dispose();
 }
Exemple #4
0
        public void ClientLoop()
        {
            while (Connected)
            {
                if (recving == false)
                {
                    recving = true;

                    try
                    {
                        Socket.BeginReceive(recvBuffer, 0, recvBuffer.Length, SocketFlags.None, EndReceive, this);
                    }
                    catch (Exception e)
                    {
                        Logger.ErrorFormat(e.ToString());
                    }
                }

                while (!SendQueue.IsEmpty)
                {
                    Logger.DebugFormat("Dequeuing packet");
                    ServerPacket packet;
                    if (!SendQueue.TryDequeue(out packet))
                    {
                        Logger.ErrorFormat("SendQueue TryDequeue failed?");
                        continue;
                    }

                    if (packet.ShouldEncrypt)
                    {
                        ++serverOrdinal;
                        packet.Ordinal = serverOrdinal;

                        packet.GenerateFooter();
                        packet.Encrypt(this);
                    }
                    if (packet.TransmitDelay != 0)
                    {
                        Thread.Sleep(packet.TransmitDelay);
                    }
                    fullSendBuffer.AddRange((byte[])packet);
                }

                if (sending == false && fullSendBuffer.Count > 0)
                {
                    sending = true;
                    Logger.DebugFormat("Sending");
                    sendBuffer = fullSendBuffer.ToArray();
                    fullSendBuffer.Clear();

                    try
                    {
                        Socket.BeginSend(sendBuffer, 0, sendBuffer.Length, SocketFlags.None, EndSend, this);
                    }
                    catch (Exception e)
                    {
                        Logger.ErrorFormat(e.ToString());
                    }
                }
                Thread.Sleep(10);
            }

            GlobalConnectionManifest.DeregisterClient(this);
            World.MessageQueue.Add(new HybrasylControlMessage(ControlOpcodes.CleanupUser, ConnectionId));
            Socket.Close();
        }
Exemple #5
0
 public void Disconnect()
 {
     ClientState.Dispose();
     GlobalConnectionManifest.DeregisterClient(this);
 }