Ejemplo n.º 1
0
        public IPRunner(User user, GameEngine engine)
        {
            m_user = user;
            m_scriptOutputStream = new MyStream(user.Send);

            m_scriptEngine = IronPython.Hosting.Python.CreateEngine();

            InitRuntime(m_scriptEngine.Runtime);

            m_scopeVars = new Dictionary<string, object>()
            {
                { "engine", engine },
                { "world", engine.World },
                { "get", new Func<object, BaseObject>(engine.World.IPGet) },
            };

            m_exprScope = m_scriptEngine.CreateScope(m_scopeVars);
            InitScopeImports(m_exprScope);
        }
Ejemplo n.º 2
0
		async void OnNewConnection(object state)
		{
			VerifyAccess();

			IConnection connection = (IConnection)state;

			var msg = await connection.GetMessageAsync();
			if (msg == null)
				return;

			var request = msg as Messages.LogOnRequestMessage;
			if (request == null)
				throw new Exception("bad initial message received");

			var name = request.Name;

			// from universal user object
			int userID = GetUserID(name);

			if (m_users.Any(u => u.UserID == userID))
				throw new Exception("User already connected");

			connection.NewMessageEvent += Signal;

			var user = new User(connection, userID, name, this, m_config.IronPythonEnabled);
			user.DisconnectEvent += OnUserDisconnected;
			m_users.Add(user);

			trace.TraceInformation("User {0} connected", user);

			var player = m_players.SingleOrDefault(p => p.UserID == userID);

			if (player == null)
			{
				player = m_players.FirstOrDefault(p => p.UserID == 0);

				if (player == null)
					throw new Exception("game full");
			}

			user.SetPlayer(player);

			m_playersConnected++;

			CheckForStartTick();
		}
Ejemplo n.º 3
0
		void OnUserDisconnected(User user)
		{
			trace.TraceInformation("User {0} disconnected", user);
			// Note: user will be removed from m_users in the MainWork
		}
Ejemplo n.º 4
0
        // Called from User
        internal void ConnectUser(User user)
        {
            if (this.User != null)
                throw new Exception();

            this.User = user;
            this.UserID = user.UserID;

            OnConnected();
        }