Example #1
0
        public static WrappedOp <DisconnectOp> CreateDisconnectOp(string reason)
        {
            var op = new DisconnectOp {
                Reason = reason
            };

            return(new WrappedOp <DisconnectOp>(op));
        }
 private void OnDisconnect(DisconnectOp op)
 {
     WorldCommands.DeallocateWorldCommandRequesters(EntityManager, worker.WorkerEntity);
     EntityManager.AddSharedComponentData(worker.WorkerEntity,
                                          new OnDisconnected {
         ReasonForDisconnect = op.Reason
     });
 }
Example #3
0
 internal static void SignalApplicationQuit()
 {
     if (!ConnectionWasSuccessful)
     {
         receivedDisconnectOp = new DisconnectOp
         {
             Reason = "An application quit signal was received."
         };
     }
 }
Example #4
0
        /// <summary>
        ///     Call this to cleanly disconnect from SpatialOS. All entities that exist will be despawned.
        /// </summary>
        /// <remarks>
        ///     It is invalid to call this method if Connect has not been called.
        /// </remarks>
        public static void Disconnect()
        {
            if (connectionLifecycle == null)
            {
                throw new InvalidOperationException("Disconnect called while not connected.");
            }

            receivedDisconnectOp = new DisconnectOp {
                Reason = "Disconnect was called by the user."
            };
            Disconnecting = true;
        }
Example #5
0
        /// <summary>
        /// Starts a new background thread that will keep the connection to SpatialOS alive.
        /// We do not use the connection to the simulated player deployment,
        /// but we must ensure it is kept open to prevent the coordinator worker
        /// from being killed.
        /// </summary>
        private static void KeepConnectionAlive(Connection connection, Logger logger)
        {
            var thread = new Thread(() =>
            {
                var isConnected = true;

                while (isConnected)
                {
                    using (OpList opList = connection.GetOpList(GetOpListTimeoutInMilliseconds))
                    {
                        var OpCount = opList.GetOpCount();
                        for (var i = 0; i < OpCount; ++i)
                        {
                            switch (opList.GetOpType(i))
                            {
                            case OpType.Disconnect:
                                {
                                    DisconnectOp op = opList.GetDisconnectOp(i);
                                    logger.WriteError("[disconnect] " + op.Reason, logToConnectionIfExists: false);
                                    isConnected = false;
                                }
                                break;

                            default:
                                break;
                            }
                        }
                    }
                }
            });

            // Don't keep thread / connection alive when main process stops.
            thread.IsBackground = true;

            thread.Start();
        }
Example #6
0
 private void HandleDisconnect(DisconnectOp op)
 {
     disconnectCallbacks.InvokeAll(op);
 }
Example #7
0
 internal static void Disconnected(DisconnectOp disconnectOp)
 {
     receivedDisconnectOp = disconnectOp;
     Disconnecting        = true;
 }
Example #8
0
 private void OnDisconnect(DisconnectOp op)
 {
     view.Disconnect(op.Reason);
 }