/// <summary>
        ///     Adds incoming chat event into all players' global chat history.
        /// </summary>
        /// <param name="obj"></param>
        public static void AddChat( ChatManager.ChatEvent obj )
        {
            if ( !_init )
            {
                _init = true;
                Init();
            }
            Wrapper.GameAction( () =>
                                {
                                    try
                                    {
                                        var player = MySession.Static.Players.GetAllPlayers().First( x => x.SteamId == obj.SourceUserId );
                                        var characterId = MySession.Static.Players.ControlledEntities.First( x => x.Value.SteamId == obj.SourceUserId ).Key;
                                        var character = MyEntities.GetEntityById( characterId ) as MyCharacter;
                                        if ( character == null )
                                        {
                                            //okay, the sending player doesn't have a character. just find any character
                                            character = MyEntities.GetEntities().FirstOrDefault( x => (x as MyCharacter) != null ) as MyCharacter;

                                            if ( character == null )
                                            {
                                                //we gave it our best shot :(
                                                return;
                                            }
                                        }

                                        character.SendNewGlobalMessage( player, obj.Message );
                                    }
                                    catch ( Exception ex )
                                    {
                                        Essentials.Log.Error( ex, "Fail ChatHistory" );
                                    }
                                } );
        }
        protected ChatManager()
        {
            m_instance = this;

            m_chatMessages = new List<string>();
            m_chatHandlerSetup = false;
            m_chatEvents = new List<ChatEvent>();

            SetupWCFService();

            Console.WriteLine("Finished loading ChatManager");
        }
		private bool SetupManagers()
		{
			m_serverWrapper = ServerAssemblyWrapper.Instance;
			m_pluginManager = PluginManager.Instance;
			m_gameAssemblyWrapper = SandboxGameAssemblyWrapper.Instance;
			m_factionsManager = FactionsManager.Instance;
			m_logManager = LogManager.Instance;
			m_entityEventManager = EntityEventManager.Instance;
			m_chatManager = ChatManager.Instance;

			return true;
		}
Exemple #4
0
 static void ChatCommand_GUI( ChatManager.ChatEvent chatEvent )
 {
     Thread uiThread = new Thread( StartGui );
     uiThread.SetApartmentState( ApartmentState.STA );
     uiThread.Start( );
 }
Exemple #5
0
		public void OnChatSent(ChatManager.ChatEvent obj)
		{

		}
Exemple #6
0
		public void OnChatReceived(ChatManager.ChatEvent obj)
		{
			if (obj.Message[0] != '/')
				return;

			HandleChatMessage(obj.SourceUserId, obj.Message);
		}
Exemple #7
0
		private bool SetupManagers( )
		{
			_dedicatedServerWrapper = DedicatedServerAssemblyWrapper.Instance;
			_pluginManager = PluginManager.Instance;
			_factionsManager = FactionsManager.Instance;
			_entityEventManager = EntityEventManager.Instance;
			_chatManager = ChatManager.Instance;
			_sessionManager = SessionManager.Instance;

			return true;
		}
        public static void HookChatMessage( Object plugin, Dictionary<Guid, IPlugin> plugins, Dictionary<Guid, bool> pluginState, ChatManager.ChatEvent chatEvent, out bool discard )
        {
            discard = false;

            foreach ( Guid key in plugins.Keys )
            {
                object hookPlugin = plugins[ key ];
                if ( !pluginState.ContainsKey( key ) )
                    continue;

                MethodInfo hookMethod = hookPlugin.GetType( ).GetMethod( "OnChatHook" );
                if ( hookMethod != null )
                {
                    const bool hookDiscard = false;
                    object[ ] args = { chatEvent, plugin, hookDiscard };
                    hookMethod.Invoke( hookPlugin, args );
                    discard = (bool)args[ 2 ];
                }
            }
        }
        /// <summary>
        /// Raised when a chat messages are received.
        /// NOTE: This is raised on a different thread
        /// </summary>
        /// <param name="obj"></param>
        public void OnChatReceived( ChatManager.ChatEvent obj )
        {
            if ( DateTime.Now - _lastMessageTime < TimeSpan.FromMilliseconds( 200 ) && obj.Message == _lastMessageString )
            {
                //if we've received a duplicate message, discard it
                _lastMessageTime = DateTime.Now;
                _lastMessageString = obj.Message;
                if ( ExtenderOptions.IsDebugging )
                    Log.Debug( "Received duplicate message: " + System.Environment.NewLine + obj.Message );
                return;
            }

            _lastMessageTime = DateTime.Now;
            _lastMessageString = obj.Message;

            if ( obj.Message[0] != '/' )
            {
                //ChatHistory.AddChat( obj );
                return;
            }

            HandleChatMessage( obj.SourceUserId, obj.Message );
        }
        protected ChatManager( )
        {
            m_instance = this;

            m_chatMessages = new List<string>( );
            m_chatHistory = new List<ChatEvent>( );
            m_chatHandlerSetup = false;
            m_resourceLock = new FastResourceLock( );
            m_chatEvents = new List<ChatEvent>( );
            m_chatCommands = new Dictionary<ChatCommand, Guid>( );

            ChatCommand deleteCommand = new ChatCommand( "delete", Command_Delete, true );

            ChatCommand tpCommand = new ChatCommand( "tp", Command_Teleport, true );

            ChatCommand stopCommand = new ChatCommand( "stop", Command_Stop, true );

            ChatCommand getIdCommand = new ChatCommand( "getid", Command_GetId, true );

            ChatCommand saveCommand = new ChatCommand( "save", Command_Save, true );

            ChatCommand ownerCommand = new ChatCommand( "owner", Command_Owner, true );

            ChatCommand exportCommand = new ChatCommand( "export", Command_Export, true );

            ChatCommand importCommand = new ChatCommand( "import", Command_Import, true );

            ChatCommand spawnCommand = new ChatCommand( "spawn", Command_Spawn, true );

            ChatCommand clearCommand = new ChatCommand( "clear", Command_Clear, true );

            ChatCommand listCommand = new ChatCommand( "list", Command_List, true );

            ChatCommand kickCommand = new ChatCommand( "kick", Command_Kick, true );

            ChatCommand onCommand = new ChatCommand( "on", Command_On, true );

            ChatCommand offCommand = new ChatCommand( "off", Command_Off, true );

            ChatCommand banCommand = new ChatCommand( "ban", Command_Ban, true );

            ChatCommand unbanCommand = new ChatCommand( "unban", Command_Unban, true );

            ChatCommand asyncSaveCommand = new ChatCommand( "savesync", Command_SyncSave, true );

            RegisterChatCommand( offCommand );
            RegisterChatCommand( onCommand );
            RegisterChatCommand( deleteCommand );
            RegisterChatCommand( tpCommand );
            RegisterChatCommand( stopCommand );
            RegisterChatCommand( getIdCommand );
            RegisterChatCommand( saveCommand );
            RegisterChatCommand( ownerCommand );
            RegisterChatCommand( exportCommand );
            RegisterChatCommand( importCommand );
            RegisterChatCommand( spawnCommand );
            RegisterChatCommand( clearCommand );
            RegisterChatCommand( listCommand );
            RegisterChatCommand( kickCommand );
            RegisterChatCommand( banCommand );
            RegisterChatCommand( unbanCommand );
            RegisterChatCommand( asyncSaveCommand );

            ApplicationLog.BaseLog.Info( "Finished loading ChatManager" );
        }
        protected ChatManager()
        {
            m_instance = this;

            m_chatMessages = new List<string>();
            m_chatHandlerSetup = false;
            m_chatEvents = new List<ChatEvent>();
            m_chatCommands = new List<ChatCommand>();

            ChatCommand deleteCommand = new ChatCommand();
            deleteCommand.command = "delete";
            deleteCommand.callback = Command_Delete;
            deleteCommand.requiresAdmin = true;

            ChatCommand tpCommand = new ChatCommand();
            tpCommand.command = "tp";
            tpCommand.callback = Command_Teleport;
            tpCommand.requiresAdmin = true;

            ChatCommand stopCommand = new ChatCommand();
            stopCommand.command = "stop";
            stopCommand.callback = Command_Stop;
            stopCommand.requiresAdmin = true;

            ChatCommand getIdCommand = new ChatCommand();
            getIdCommand.command = "getid";
            getIdCommand.callback = Command_GetId;
            getIdCommand.requiresAdmin = true;

            ChatCommand saveCommand = new ChatCommand();
            saveCommand.command = "save";
            saveCommand.callback = Command_Save;
            saveCommand.requiresAdmin = true;

            ChatCommand ownerCommand = new ChatCommand();
            ownerCommand.command = "owner";
            ownerCommand.callback = Command_Owner;
            ownerCommand.requiresAdmin = true;

            ChatCommand exportCommand = new ChatCommand();
            exportCommand.command = "export";
            exportCommand.callback = Command_Export;
            exportCommand.requiresAdmin = true;

            ChatCommand importCommand = new ChatCommand();
            importCommand.command = "import";
            importCommand.callback = Command_Import;
            importCommand.requiresAdmin = true;

            ChatCommand spawnCommand = new ChatCommand();
            spawnCommand.command = "spawn";
            spawnCommand.callback = Command_Spawn;
            spawnCommand.requiresAdmin = true;

            ChatCommand clearCommand = new ChatCommand();
            clearCommand.command = "clear";
            clearCommand.callback = Command_Clear;
            clearCommand.requiresAdmin = true;

            ChatCommand listCommand = new ChatCommand();
            listCommand.command = "list";
            listCommand.callback = Command_List;
            listCommand.requiresAdmin = true;

            ChatCommand offCommand = new ChatCommand();
            offCommand.command = "off";
            offCommand.callback = Command_Off;
            offCommand.requiresAdmin = true;

            RegisterChatCommand(deleteCommand);
            RegisterChatCommand(tpCommand);
            RegisterChatCommand(stopCommand);
            RegisterChatCommand(getIdCommand);
            RegisterChatCommand(saveCommand);
            RegisterChatCommand(ownerCommand);
            RegisterChatCommand(exportCommand);
            RegisterChatCommand(importCommand);
            RegisterChatCommand(spawnCommand);
            RegisterChatCommand(clearCommand);
            RegisterChatCommand(listCommand);
            RegisterChatCommand(offCommand);

            SetupWCFService();

            Console.WriteLine("Finished loading ChatManager");
        }
Exemple #12
0
        protected bool RunBaseReflectionUnitTests()
        {
            bool result = true;

            if (!DedicatedServerAssemblyWrapper.ReflectionUnitTest())
            {
                result = false;
                BaseLog.Warn("DedicatedServerAssemblyWrapper reflection validation failed!");
            }

            if (!ServerNetworkManager.ReflectionUnitTest())
            {
                result = false;
                BaseLog.Warn("ServerNetworkManager reflection validation failed!");
            }

            if (!UtilityFunctions.ReflectionUnitTest())
            {
                result = false;
                BaseLog.Warn("UtilityFunctions reflection validation failed!");
            }

            if (!ChatManager.ReflectionUnitTest())
            {
                result = false;
                BaseLog.Warn("ChatManager reflection validation failed!");
            }

            if (!PlayerMap.ReflectionUnitTest())
            {
                result = false;
                BaseLog.Warn("PlayerMap reflection validation failed!");
            }

            if (!PlayerManager.ReflectionUnitTest())
            {
                result = false;
                BaseLog.Warn("PlayerManager reflection validation failed!");
            }

            if (!WorldManager.ReflectionUnitTest())
            {
                result = false;
                BaseLog.Warn("WorldManager reflection validation failed!");
            }

            if (!RadioManager.ReflectionUnitTest())
            {
                result = false;
                BaseLog.Warn("RadioManager reflection validation failed!");
            }

            if (!RadioManagerNetworkManager.ReflectionUnitTest())
            {
                result = false;
                BaseLog.Warn("RadioManagerNetworkManager reflection validation failed!");
            }

            if (!FactionsManager.ReflectionUnitTest())
            {
                result = false;
                BaseLog.Warn("FactionsManager reflection validation failed!");
            }

            if (!Faction.ReflectionUnitTest())
            {
                result = false;
                BaseLog.Warn("Faction reflection validation failed!");
            }

            if (!GameEntityManager.ReflectionUnitTest())
            {
                result = false;
                BaseLog.Warn("GameEntityManager reflection validation failed!");
            }

            if (result)
            {
                BaseLog.Info("All main types passed reflection unit tests!");
            }

            return(result);
        }
        protected bool RunBaseReflectionUnitTests()
        {
            bool result = true;

            if (!SandboxGameAssemblyWrapper.ReflectionUnitTest())
            {
                result = false;
                Console.WriteLine("SandboxGameAssemblyWrapper reflection validation failed!");
            }

            if (!ServerAssemblyWrapper.ReflectionUnitTest())
            {
                result = false;
                Console.WriteLine("ServerAssemblyWrapper reflection validation failed!");
            }

            if (!NetworkManager.ReflectionUnitTest())
            {
                result = false;
                Console.WriteLine("NetworkManager reflection validation failed!");
            }

            if (!ServerNetworkManager.ReflectionUnitTest())
            {
                result = false;
                Console.WriteLine("ServerNetworkManager reflection validation failed!");
            }

            if (!UtilityFunctions.ReflectionUnitTest())
            {
                result = false;
                Console.WriteLine("UtilityFunctions reflection validation failed!");
            }

            if (!ChatManager.ReflectionUnitTest())
            {
                result = false;
                Console.WriteLine("ChatManager reflection validation failed!");
            }

            if (!PlayerMap.ReflectionUnitTest())
            {
                result = false;
                Console.WriteLine("PlayerMap reflection validation failed!");
            }

            if (!PlayerManager.ReflectionUnitTest())
            {
                result = false;
                Console.WriteLine("PlayerManager reflection validation failed!");
            }

            if (!WorldManager.ReflectionUnitTest())
            {
                result = false;
                Console.WriteLine("WorldManager reflection validation failed!");
            }

            if (!RadioManager.ReflectionUnitTest())
            {
                result = false;
                Console.WriteLine("RadioManager reflection validation failed!");
            }

            if (!RadioManagerNetworkManager.ReflectionUnitTest())
            {
                result = false;
                Console.WriteLine("RadioManagerNetworkManager reflection validation failed!");
            }

            if (!PowerManager.ReflectionUnitTest())
            {
                result = false;
                Console.WriteLine("PowerManager reflection validation failed!");
            }

            if (!FactionsManager.ReflectionUnitTest())
            {
                result = false;
                Console.WriteLine("FactionsManager reflection validation failed!");
            }

            if (!Faction.ReflectionUnitTest())
            {
                result = false;
                Console.WriteLine("Faction reflection validation failed!");
            }

            if (!GameEntityManager.ReflectionUnitTest())
            {
                result = false;
                Console.WriteLine("GameEntityManager reflection validation failed!");
            }

            if (result)
            {
                Console.WriteLine("All main types passed reflection unit tests!");
            }

            return(result);
        }
        public void OnChatReceived(ChatManager.ChatEvent obj)
        {
            if (obj.sourceUserId == 0)
                return;

            if (obj.message[0] == '/')
            {
                bool isadmin = SandboxGameAssemblyWrapper.Instance.IsUserAdmin(obj.sourceUserId);
                string[] words = obj.message.Split(' ');
                string rem = "";
                //proccess
                if (words.Count() > 2 && isadmin)
                {
                    rem = String.Join(" ", words, 2, words.Count() - 2);
                    if (words[0] == "/set")
                    {

                        if (words[1] == "pm-ore")
                        {
                            ore_amt = Convert.ToDouble(rem.Trim());
                            ChatManager.Instance.SendPrivateChatMessage(obj.sourceUserId, "Ore amount set to " + ore_amt.ToString());
                        }
                        if (words[1] == "pm-interval")
                        {
                            interval = Convert.ToInt32(rem.Trim());
                            ChatManager.Instance.SendPrivateChatMessage(obj.sourceUserId, "Meteroid storm interval set to " + interval.ToString());
                        }
                        if (words[1] == "pm-randominterval")
                        {
                            randinterval = Convert.ToInt32(rem.Trim());
                            ChatManager.Instance.SendPrivateChatMessage(obj.sourceUserId, "Meteroid storm random interval set to " + randinterval.ToString());
                        }
                    }
                }
                if (isadmin && words[0] == "/pm-spawnwave")
                {
                    Thread t = new Thread(createMeteorStorm);
                    t.Start();
                    ChatManager.Instance.SendPrivateChatMessage(obj.sourceUserId, "Starting meteoriod storm");
                    return;
                }
                if (isadmin && words[0] == "/pm-enable")
                {
                    ChatManager.Instance.SendPrivateChatMessage(obj.sourceUserId, "Automatic Meteoroid storms enabled");
                    settings.meteorOn = true;
                    return;
                }

                if (isadmin && words[0] == "/pm-disable")
                {
                    ChatManager.Instance.SendPrivateChatMessage(obj.sourceUserId, "Automatic Meteoroid storms disabled");
                    settings.meteorOn = false;
                    return;
                }

                if (isadmin && words[0] == "/pm-save")
                {

                    saveXML();
                    ChatManager.Instance.SendPrivateChatMessage(obj.sourceUserId, "Physics Meteoroid Configuration Saved.");
                    return;
                }
                if (isadmin && words[0] == "/pm-load")
                {
                    loadXML(false);
                    ChatManager.Instance.SendPrivateChatMessage(obj.sourceUserId, "Physics Meteoroid Configuration Loaded.");
                    return;
                }
                if (isadmin && words[0] == "/pm-loaddefault")
                {
                    loadXML(true);
                    ChatManager.Instance.SendPrivateChatMessage(obj.sourceUserId, "Physics Meteoroid Configuration Defaults Loaded.");
                    return;
                }
            }
            return;
        }