コード例 #1
0
        private static void OnGlobalMessageRequest(MySyncCharacter sync, ref SendGlobalMessageMsg msg, MyNetworkClient sender)
        {
            //Ignore messages that have improper lengths
            if (msg.Text.Length == 0 || msg.Text.Length > MyChatConstants.MAX_CHAT_STRING_LENGTH)
            {
                return;
            }

            var senderId   = MySession.Static.Players.TryGetPlayerIdentity(new MyPlayer.PlayerId(msg.SenderSteamId));
            var allPlayers = MySession.Static.Players.GetOnlinePlayers();

            foreach (var player in allPlayers)
            {
                var receiverId = player.Identity;
                if (receiverId != null && receiverId.Character != null && senderId != null && senderId.Character != null && MyAntennaSystem.CheckConnection(senderId, receiverId))
                {
                    Sync.Layer.SendMessage(ref msg, player.Id.SteamId, MyTransportMessageEnum.Success);

                    //Save chat history on server for non-server players
                    if (receiverId.Character != MySession.LocalCharacter)
                    {
                        MyChatSystem.AddGlobalChatItem(player.Identity.IdentityId, new MyGlobalChatItem(msg.Text, senderId.IdentityId));
                    }
                }
            }
        }
コード例 #2
0
        private static void OnGlobalMessageSuccess(MySyncCharacter sync, ref SendGlobalMessageMsg msg, MyNetworkClient sender)
        {
            var senderId = MySession.Static.Players.TryGetPlayerIdentity(new MyPlayer.PlayerId(msg.SenderSteamId));

            if (MySession.LocalCharacter != null)
            {
                MyChatSystem.AddGlobalChatItem(MySession.LocalPlayerId, new MyGlobalChatItem(msg.Text, senderId.IdentityId));
                MySession.Static.ChatSystem.OnNewGlobalMessage(senderId.IdentityId);

                if (MySession.LocalPlayerId != senderId.IdentityId)
                {
                    MySession.Static.Gpss.ScanText(msg.Text, MyTexts.GetString(MySpaceTexts.TerminalTab_GPS_NewFromBroadcast));
                }
            }
        }