示例#1
0
        /// <summary>
        /// Adds user to user pool.
        /// Sends map scripts if they exists.
        /// </summary>
        /// <param name="pUser"></param>
        protected virtual void OnUserEnter(Character pUser)
        {
            if (Users.Count <= 0)
            {
                Init();
            }

            Users.Add(pUser);

            var provider = ServerApp.Container.Resolve <ScriptManager>();

            if (HasFirstUserEnterScript && !FirstUserEnterScriptActivated)
            {
#if DEBUG
                Log.Debug($"Begin FUE script in CField ({OnFirstUserEnterScript})");
#endif
                // script already executed -> should not be possible
                if (MapScript != null)
                {
                    throw new ScriptException($"First user enter script has already been activated. MapId: {MapId}. Script Name {OnFirstUserEnterScript}");
                }

                MapScript = provider.GetMapScript(OnFirstUserEnterScript, this, pUser.Socket);
                MapScript.Execute();
                FirstUserEnterScriptActivated = true;
#if DEBUG
                Log.Debug("End FUE script in CField");
#endif
            }
            else if (HasUserEnterScript)
            {
#if DEBUG
                Log.Debug($"Executing UE script in CField ({OnUserEnterScript})");
#endif
                provider.GetMapScript(OnUserEnterScript, pUser.Socket).Execute();
            }
        }