Ejemplo n.º 1
0
        private int _totalLength; // Total length of the station.xml file

        #endregion Fields

        #region Constructors

        public StationProvider(NetworkManager manager)
        {
            _clientStatus = new Dictionary<GameClient, int>();
            _clientWaiting = new Dictionary<GameClient, bool>();
            _clientFails = new Dictionary<GameClient, int>();
            _stationData = new List<byte[]>();
            _netManager = manager;

            using (BinaryReader reader = StationZipManager.OpenStationXmlReadOnly())
            {
                long flength = reader.BaseStream.Length;
                _totalLength = 0;
                byte[] total = new byte[flength];
                while (_totalLength < flength)
                {
                    byte[] raw = reader.ReadBytes(1024);
                    int length = raw.Length;
                    _totalLength += length;
                    byte[] data = new byte[length];
                    Array.Copy(raw, data, length);
                    Array.Copy(raw, 0, total, _totalLength - length, length);
                    _stationData.Add(data);
                }

                using (MD5 check = MD5.Create())
                {
                    byte[] hash = check.ComputeHash(total);
                    StringBuilder sb = new StringBuilder();
                    foreach (byte b in hash)
                        sb.Append(b.ToString("x2"));
                    _checksum = sb.ToString();
                }
            }

            Debug.LogSys("Station zip file loaded into memory in " + _stationData.Count + " chunks.");
            Debug.LogSys("Station zip checksum: " + _checksum + ".");
        }
Ejemplo n.º 2
0
        // Loads in the server settings and opens the server for connections
        public void Start()
        {
            Debug.BeginBlock("ServerStart");

            // TODO: Starting stuff

            // Unpack the station file
            try
            {
                StationZipManager.UnpackStation();
            }
            catch (Exception e)
            {
                Debug.LogError("Unable to unpack the station files. Error:");
                Debug.LogException(e);
                return;
            }

            try
            {
                _netManager = GameServiceManager.Resolve<NetworkManager>();
            }
            catch
            {
                Debug.LogError("Server could not start up the network manager. Server shutting down.");
                return;
            }
            GameServiceManager.Resolve<NetWrapper>().SetNetManager(_netManager);
            _netManager.Start();
            Debug.LogSys("Server is started and accepting connections.");

            IsActive = true;
            Debug.EndBlock();
        }