Beispiel #1
0
        private void GameplayInitializeAsync()
        {
            var serverComponent = _ioc.Get <ServerComponent>();

            if (_vars.SinglePlayer)
            {
                var wp = _ioc.Get <WorldParameters>();

                AbstractChunk.SetChunkHeight(wp.Configuration.WorldHeight);

                //wp not initialized ==> We are in "SandBox" mode, load from the "Utopia SandBox" Default WorldParameters
                if (wp.SeedName == null)
                {
                    wp.WorldName = "SandBox World";
                    wp.SeedName  = "Utopia SandBox";
                }

                //Create a local server for single player purpose
                if (_vars.LocalServer == null || _vars.LocalServer.IsDisposed)
                {
                    _vars.LocalServer = _ioc.Get <LocalServer>();
                }

                //Passed the WorldParameters to the server for single use purpose mode
                _vars.LocalServer.InitSinglePlayerServer(wp);

                if (serverComponent.ServerConnection == null ||
                    serverComponent.ServerConnection.Status != TcpConnectionStatus.Connected)
                {
                    serverComponent.MessageEntityIn += ServerConnectionMessageEntityIn;
                    var port = _vars.LocalServer.Server.SettingsManager.Settings.ServerPort;
                    serverComponent.BindingServer("127.0.0.1" + (port == 4815 ? "" : ":" + port), null);
                    serverComponent.ConnectToServer("local", _vars.DisplayName, "qwe123".GetSHA1Hash());
                    _vars.LocalDataBasePath = Path.Combine(_vars.ApplicationDataPath, "Client", "Singleplayer", wp.WorldName, "ClientWorldCache.db");
                }
            }
            else
            {
                if (serverComponent.ServerConnection == null ||
                    serverComponent.ServerConnection.Status != TcpConnectionStatus.Connected)
                {
                    serverComponent.MessageEntityIn += ServerConnectionMessageEntityIn;
                    serverComponent.BindingServer(_vars.CurrentServerAddress, _vars.CurrentServerLocalAddress);

                    // take server address without port to create server password hash
                    var srvAddr = _vars.CurrentServerAddress.Contains(":")
                                      ? _vars.CurrentServerAddress.Substring(0, _vars.CurrentServerAddress.IndexOf(':'))
                                      : _vars.CurrentServerAddress;

                    var userHash = (_vars.PasswordHash + _vars.Login.ToLower()).GetSHA1Hash();

                    serverComponent.ConnectToServer(_vars.Login, _vars.DisplayName, (srvAddr + userHash).GetSHA1Hash());
                    _vars.LocalDataBasePath = Path.Combine(_vars.ApplicationDataPath, _vars.Login, "Client", "Multiplayer", _vars.CurrentServerAddress.Replace(':', '_'), "ClientWorldCache.db");
                }
            }
        }