Exemple #1
0
        public static void SendMessageToAllPlayers(ModMessageBase messageContainer)
        {
            //MyAPIGateway.Multiplayer.SendMessageToOthers(StandardClientId, System.Text.Encoding.Unicode.GetBytes(ConvertData(content))); <- does not work as expected ... so it doesn't work at all?
            List <IMyPlayer> players = new List <IMyPlayer>();

            MyAPIGateway.Players.GetPlayers(players, p => p != null);
            foreach (IMyPlayer player in players)
            {
                SendMessageToPlayer(player.SteamUserId, messageContainer);
            }
        }
Exemple #2
0
        /// <summary>
        /// Creates and sends an entity with the given information for the server and all players.
        /// </summary>
        /// <param name="message"></param>
        public static void SendMessageToAll(ModMessageBase message)
        {
            if (MyAPIGateway.Multiplayer.IsServer)
            {
                message.SenderSteamId = MyAPIGateway.Multiplayer.ServerId;
            }
            if (MyAPIGateway.Session.Player != null)
            {
                message.SenderSteamId     = MyAPIGateway.Session.Player.SteamUserId;
                message.SenderDisplayName = MyAPIGateway.Session.Player.DisplayName;
            }
            message.SenderLanguage = (int)MyAPIGateway.Session.Config.Language;

            if (!MyAPIGateway.Multiplayer.IsServer)
            {
                SendMessageToServer(message);
            }
            SendMessageToAllPlayers(message);
        }
Exemple #3
0
 public static void SendMessageToPlayer(ulong steamId, ModMessageBase message)
 {
     if (MyAPIGateway.Multiplayer.IsServer)
     {
         message.SenderSteamId = MyAPIGateway.Multiplayer.ServerId;
     }
     MainChatCommandLogic.Instance.ServerLogger.WriteVerbose("SendMessageToPlayer {0} {1} {2}.", steamId, message.Side, message.GetType().Name);
     message.Side = MessageSide.ClientSide;
     try
     {
         byte[] byteData = MyAPIGateway.Utilities.SerializeToBinary(message);
         MyAPIGateway.Multiplayer.SendMessageTo(ModConfigurationConsts.ConnectionId, byteData, steamId);
     }
     catch (Exception ex)
     {
         MainChatCommandLogic.Instance.ServerLogger.WriteException(ex);
         MainChatCommandLogic.Instance.ClientLogger.WriteException(ex);
         //TODO: send exception detail to Server if on Client.
     }
 }
Exemple #4
0
        /// <summary>
        /// Creates and sends an entity with the given information for the server. Never call this on DS instance!
        /// </summary>

        public static void SendMessageToServer(ModMessageBase message)
        {
            message.Side = MessageSide.ServerSide;
            if (MyAPIGateway.Multiplayer.IsServer)
            {
                message.SenderSteamId = MyAPIGateway.Multiplayer.ServerId;
            }
            if (MyAPIGateway.Session.Player != null)
            {
                message.SenderSteamId     = MyAPIGateway.Session.Player.SteamUserId;
                message.SenderDisplayName = MyAPIGateway.Session.Player.DisplayName;
            }
            message.SenderLanguage = (int)MyAPIGateway.Session.Config.Language;
            try
            {
                byte[] byteData = MyAPIGateway.Utilities.SerializeToBinary(message);
                MyAPIGateway.Multiplayer.SendMessageToServer(ModConfigurationConsts.ConnectionId, byteData);
            }
            catch (Exception ex)
            {
                MainChatCommandLogic.Instance.ClientLogger.WriteException(ex, "Could not send message to Server.");
                //TODO: send exception detail to Server.
            }
        }