Exemple #1
0
 public static void Execute(object obj, ElapsedEventArgs args)
 {
     Logger.Debug("Job starting");
     try
     {
         foreach (var connection in GlobalConnectionManifest.WorldClients)
         {
             var  client       = connection.Value;
             var  connectionId = connection.Key;
             User user;
             if (World.ActiveUsers.TryGetValue(connectionId, out user))
             {
                 if (client.IsHeartbeatExpired())
                 {
                     Logger.InfoFormat("{0} (connection id {1}: heartbeat expired, disconnecting",
                                       user.Name, connectionId);
                     GlobalConnectionManifest.DeregisterClient(client);
                     World.MessageQueue.Add(new HybrasylControlMessage(ControlOpcodes.CleanupUser, connectionId));
                 }
             }
         }
     }
     catch (Exception e)
     {
         Logger.ErrorFormat("Exception occurred in job:", e);
     }
 }
Exemple #2
0
    public Client(Socket socket, Server server)
    {
        ClientState = new ClientState(socket);
        Server      = server;
        GameLog.InfoFormat("Connection {0} from {1}:{2}", ConnectionId,
                           ((IPEndPoint)Socket.RemoteEndPoint).Address.ToString(),
                           ((IPEndPoint)Socket.RemoteEndPoint).Port);

        if (server is Lobby)
        {
            EncryptionKey = Game.Config.ApiEndpoints.EncryptionEndpoint != null?GlobalConnectionManifest.RequestEncryptionKey(Game.Config.ApiEndpoints.EncryptionEndpoint.Url, ((IPEndPoint)socket.RemoteEndPoint).Address) : Encoding.ASCII.GetBytes("UrkcnItnI");

            GameLog.InfoFormat($"EncryptionKey is {Encoding.ASCII.GetString(EncryptionKey)}");

            var valid = Game.Config.ApiEndpoints.ValidationEndpoint != null?GlobalConnectionManifest.ValidateEncryptionKey(Game.Config.ApiEndpoints.ValidationEndpoint.Url, new ServerToken { Ip = ((IPEndPoint)socket.RemoteEndPoint).Address.ToString(), Seed = EncryptionKey }) : true;

            if (!valid)
            {
                GameLog.ErrorFormat("Invalid key from {IP}", ((IPEndPoint)Socket.RemoteEndPoint).Address.ToString());
                socket.Disconnect(true);
            }
        }

        EncryptionKeyTable = new byte[1024];
        _lastReceived      = DateTime.Now.Ticks;

        GlobalConnectionManifest.RegisterClient(this);

        ConnectedSince = DateTime.Now.Ticks;
    }
Exemple #3
0
    public void Redirect(Redirect redirect, bool isLogoff = false, int transmitDelay = 0)
    {
        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;

        if (Game.RedirectTarget != null)
        {
            addressBytes = Game.RedirectTarget.GetAddressBytes();
        }
        else
        {
            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);
        x03.TransmitDelay = transmitDelay == 0 ? 250 : transmitDelay;
        Enqueue(x03);
    }
Exemple #4
0
 public ClientState(Socket incoming)
 {
     this.WorkSocket = incoming;
     this.Id         = GlobalConnectionManifest.GetNewConnectionId();
     this.Connected  = true;
 }
Exemple #5
0
 public void Disconnect()
 {
     ClientState.Dispose();
     GlobalConnectionManifest.DeregisterClient(this);
 }