public static void AddFactionChatItem(long localPlayerId, long factionId1, long factionId2, MyFactionChatItem chatItem) { var factionChat = FindFactionChatHistory(factionId1, factionId2); if (factionChat == null) { factionChat = new MyFactionChatHistory(factionId1, factionId2); MySession.Static.FactionChatHistory.Add(factionChat); } if (factionChat.Chat.Count == MyChatConstants.MAX_FACTION_CHAT_HISTORY_COUNT) { factionChat.Chat.Dequeue(); } factionChat.Chat.Enqueue(chatItem); }
public MyFactionChatHistory(MyObjectBuilder_FactionChatHistory chatBuilder) : this(chatBuilder.FactionId1, chatBuilder.FactionId2) { if (chatBuilder.Chat != null) { m_chat = new Queue <MyFactionChatItem>(chatBuilder.Chat.Count); foreach (var chatItem in chatBuilder.Chat) { MyFactionChatItem newChatItem = new MyFactionChatItem(); newChatItem.Init(chatItem); m_chat.Enqueue(newChatItem); } } else { m_chat = new Queue <MyFactionChatItem>(); } m_factionId1 = chatBuilder.FactionId1; m_factionId2 = chatBuilder.FactionId2; }
public static bool RetryFactionMessage(long factionId1, long factionId2, MyFactionChatItem chatItem, MyIdentity currentSenderIdentity) { Debug.Assert(Sync.IsServer, "Faction message retries should only be done on server"); if (currentSenderIdentity == null || currentSenderIdentity.Character == null) { return false; } m_tempValidIds.Clear(); foreach (var playerToSendTo in chatItem.PlayersToSendTo) { if (!playerToSendTo.Value) { long receiverIdentityId = playerToSendTo.Key; if (Sync.Players.IdentityIsNpc(receiverIdentityId)) { continue; } MyIdentity receiverId = MySession.Static.Players.TryGetIdentity(receiverIdentityId); if (receiverId != null && receiverId.Character != null && MyAntennaSystem.Static.CheckConnection(currentSenderIdentity, receiverId)) { m_tempValidIds.Add(receiverIdentityId); } } } if (m_tempValidIds.Count == 0) { return false; } foreach (var id in m_tempValidIds) { chatItem.PlayersToSendTo[id] = true; } foreach (var id in m_tempValidIds) { MyPlayer.PlayerId receiverPlayerId; MySession.Static.Players.TryGetPlayerId(id, out receiverPlayerId); ulong steamId = receiverPlayerId.SteamId; MyMultiplayer.RaiseStaticEvent(x => OnFactionMessageSuccess, factionId1, factionId2, chatItem.GetObjectBuilder(), new EndpointId(steamId)); } foreach (var id in m_tempValidIds) { //Send confirmation to members of both factions SendConfirmMessageToFaction(factionId1, chatItem.PlayersToSendTo, factionId1, factionId2, chatItem.IdentityId, chatItem.Timestamp.Ticks, id, chatItem.Text); if (factionId1 != factionId2) { SendConfirmMessageToFaction(factionId2, chatItem.PlayersToSendTo, factionId1, factionId2, chatItem.IdentityId, chatItem.Timestamp.Ticks, id, chatItem.Text); } } return true; }
static private void OnFactionMessageSuccess(long factionId1, long factionId2, MyObjectBuilder_FactionChatItem chatItemBuilder) { long senderIdentityId = MyEntityIdentifier.ConstructId(MyEntityIdentifier.ID_OBJECT_TYPE.IDENTITY, chatItemBuilder.IdentityIdUniqueNumber); var factionChatItem = new MyFactionChatItem(); factionChatItem.Init(chatItemBuilder); if (!(Sync.IsServer && senderIdentityId != MySession.Static.LocalPlayerId)) { MyChatSystem.AddFactionChatItem(MySession.Static.LocalPlayerId, factionId1, factionId2, factionChatItem); } if (senderIdentityId != MySession.Static.LocalPlayerId) { MySession.Static.Gpss.ScanText(factionChatItem.Text, MyTexts.GetString(MySpaceTexts.TerminalTab_GPS_NewFromFactionComms)); } MySession.Static.ChatSystem.OnNewFactionMessage(factionId1, factionId2, senderIdentityId, true); }
static private void OnFactionMessageRequest(long factionId1, long factionId2, MyObjectBuilder_FactionChatItem chatItemBuilder) { //Ignore messages that have improper lengths if (chatItemBuilder.Text.Length == 0 || chatItemBuilder.Text.Length > MyChatConstants.MAX_CHAT_STRING_LENGTH) { return; } long currentSenderId = MyEntityIdentifier.ConstructId(MyEntityIdentifier.ID_OBJECT_TYPE.IDENTITY, chatItemBuilder.IdentityIdUniqueNumber); var senderId = MySession.Static.Players.TryGetIdentity(currentSenderId); var chatItem = new MyFactionChatItem(); chatItem.Init(chatItemBuilder); //Find all members that can receive this messages m_tempValidIds.Clear(); for (int i = 0; i < chatItemBuilder.PlayersToSendToUniqueNumber.Count; i++) { if (!chatItemBuilder.IsAlreadySentTo[i]) { long receiverIdentityId = MyEntityIdentifier.ConstructId(MyEntityIdentifier.ID_OBJECT_TYPE.IDENTITY, chatItemBuilder.PlayersToSendToUniqueNumber[i]); var receiverId = MySession.Static.Players.TryGetIdentity(receiverIdentityId); if (Sync.Players.IdentityIsNpc(receiverIdentityId) == false && receiverId != null && receiverId.Character != null && MyAntennaSystem.Static.CheckConnection(senderId, receiverId)) { m_tempValidIds.Add(receiverIdentityId); } } } //Set their sent flag to true, so that everyone knows they already got it (no need for confirm message) foreach (var id in m_tempValidIds) { chatItem.PlayersToSendTo[id] = true; } //Save the flags back in the message chatItemBuilder = chatItem.GetObjectBuilder(); //Send success message back to all recepient members foreach (var id in m_tempValidIds) { MyPlayer.PlayerId receiverPlayerId; MySession.Static.Players.TryGetPlayerId(id, out receiverPlayerId); ulong steamId = receiverPlayerId.SteamId; MyMultiplayer.RaiseStaticEvent(x => OnFactionMessageSuccess, factionId1, factionId2, chatItemBuilder, new EndpointId(steamId)); } //Save chat history on server for non-server players if (senderId.Character != MySession.Static.LocalCharacter) { MyChatSystem.AddFactionChatItem(senderId.IdentityId, factionId1, factionId2, chatItem); } }
public void SendNewFactionMessage(long factionId1, long factionId2, MyFactionChatItem chatItem) { MyMultiplayer.RaiseStaticEvent(x => OnFactionMessageRequest, factionId1, factionId2, chatItem.GetObjectBuilder()); }
private void SendMessage() { //Cannot send any message if local character is missing if (MySession.Static.LocalCharacter == null) { return; } m_chatboxText.Clear(); m_chatbox.GetText(m_chatboxText); MyDebug.AssertDebug(m_chatboxText.Length > 0, "Length of chat text should be positive"); MyDebug.AssertDebug(m_chatboxText.Length <= MyChatConstants.MAX_CHAT_STRING_LENGTH, "Length of chat text should not exceed maximum allowed"); var history = MyChatSystem.GetChatHistory(MySession.Static.LocalPlayerId); if (m_playerList.SelectedItems.Count > 0) { var selectedItem = m_playerList.SelectedItems[0]; if(selectedItem==m_globalItem) { //messages entered in the global chat history should be treated as normal ingame chat if ( MyMultiplayer.Static != null ) MyMultiplayer.Static.SendChatMessage( m_chatboxText.ToString() ); else MyHud.Chat.ShowMessage( MySession.Static.LocalHumanPlayer == null ? "Player" : MySession.Static.LocalHumanPlayer.DisplayName, m_chatboxText.ToString() ); //add the message to history //MySession.Static.GlobalChatHistory.GlobalChatHistory.Chat.Enqueue(new MyGlobalChatItem //{ // IdentityId = MySession.Static.LocalPlayerId, // Text = m_chatboxText.ToString() //}); RefreshGlobalChatHistory(); } else if (selectedItem == m_broadcastItem) { MySession.Static.LocalCharacter.SendNewGlobalMessage(MySession.Static.LocalHumanPlayer.Id, m_chatboxText.ToString()); } else { var playerIdentity = (MyIdentity)selectedItem.UserData; MySession.Static.ChatHistory[MySession.Static.LocalPlayerId].AddPlayerChatItem(new MyPlayerChatItem(m_chatboxText.ToString(), MySession.Static.LocalPlayerId, MySession.Static.ElapsedGameTime, false), playerIdentity.IdentityId); RefreshPlayerChatHistory(playerIdentity); } } else if (m_factionList.SelectedItems.Count > 0) { var toSendTo = new Dictionary<long, bool>(); var selectedItem = m_factionList.SelectedItems[0]; var targetFaction = (MyFaction)selectedItem.UserData; foreach (var member in targetFaction.Members) { toSendTo.Add(member.Value.PlayerId, false); } if (!targetFaction.IsMember(MySession.Static.LocalPlayerId)) { var localFaction = MySession.Static.Factions.TryGetPlayerFaction(MySession.Static.LocalPlayerId); if (localFaction != null) { foreach (var member in localFaction.Members) { toSendTo.Add(member.Value.PlayerId, false); } } } var factionChatItem = new MyFactionChatItem(m_chatboxText.ToString(), MySession.Static.LocalPlayerId, MySession.Static.ElapsedGameTime, toSendTo); //This has to exist! var currentFaction = MySession.Static.Factions.TryGetPlayerFaction(MySession.Static.LocalPlayerId); MySession.Static.LocalCharacter.SendNewFactionMessage(targetFaction.FactionId, currentFaction.FactionId, factionChatItem); RefreshFactionChatHistory(targetFaction); } m_chatbox.SetText(m_emptyText); }
public MyFactionChatHistory(MyObjectBuilder_FactionChatHistory chatBuilder) : this(chatBuilder.FactionId1, chatBuilder.FactionId2) { if (chatBuilder.Chat != null) { m_chat = new Queue<MyFactionChatItem>(chatBuilder.Chat.Count); foreach (var chatItem in chatBuilder.Chat) { MyFactionChatItem newChatItem = new MyFactionChatItem(); newChatItem.Init(chatItem); m_chat.Enqueue(newChatItem); } } else { m_chat = new Queue<MyFactionChatItem>(); } m_factionId1 = chatBuilder.FactionId1; m_factionId2 = chatBuilder.FactionId2; }
public static bool RetryFactionMessage(long factionId1, long factionId2, MyFactionChatItem chatItem, MyIdentity currentSenderIdentity) { Debug.Assert(Sync.IsServer, "Faction message retries should only be done on server"); if (currentSenderIdentity.Character == null) { return false; } m_tempValidIds.Clear(); foreach (var playerToSendTo in chatItem.PlayersToSendTo) { if (!playerToSendTo.Value) { long receiverIdentityId = playerToSendTo.Key; var receiverId = MySession.Static.Players.TryGetIdentity(receiverIdentityId); if (receiverId != null && receiverId.Character != null && MyAntennaSystem.CheckConnection(currentSenderIdentity, receiverId)) { m_tempValidIds.Add(receiverIdentityId); } } } if (m_tempValidIds.Count == 0) { return false; } foreach (var id in m_tempValidIds) { chatItem.PlayersToSendTo[id] = true; } var msg = new SendNewFactionMessageMsg(); msg.FactionId1 = factionId1; msg.FactionId2 = factionId2; msg.CharacterEntityId = currentSenderIdentity.Character.EntityId; msg.ChatItem = chatItem.GetObjectBuilder(); var confirmMessage = new ConfirmFactionMessageMsg(); confirmMessage.CharacterEntityId = currentSenderIdentity.Character.EntityId; confirmMessage.FactionId1 = msg.FactionId1; confirmMessage.FactionId2 = msg.FactionId2; confirmMessage.OriginalSenderId = chatItem.IdentityId; confirmMessage.Timestamp = chatItem.Timestamp.Ticks; confirmMessage.Text = msg.ChatItem.Text; foreach (var id in m_tempValidIds) { MyPlayer.PlayerId receiverPlayerId; MySession.Static.Players.TryGetPlayerId(id, out receiverPlayerId); ulong steamId = receiverPlayerId.SteamId; Sync.Layer.SendMessage(ref msg, steamId, MyTransportMessageEnum.Success); } foreach (var id in m_tempValidIds) { confirmMessage.ReceiverId = id; //Send confimation to members of both factions SendConfirmMessageToFaction(confirmMessage.FactionId1, chatItem.PlayersToSendTo, ref confirmMessage); if (confirmMessage.FactionId1 != confirmMessage.FactionId2) { SendConfirmMessageToFaction(confirmMessage.FactionId2, chatItem.PlayersToSendTo, ref confirmMessage); } } return true; }
private static void OnFactionMessageSuccess(MySyncCharacter sync, ref SendNewFactionMessageMsg msg, MyNetworkClient sender) { long senderIdentityId = MyEntityIdentifier.ConstructId(MyEntityIdentifier.ID_OBJECT_TYPE.IDENTITY, msg.ChatItem.IdentityIdUniqueNumber); var factionChatItem = new MyFactionChatItem(); factionChatItem.Init(msg.ChatItem); if (!(Sync.IsServer && senderIdentityId != MySession.LocalPlayerId)) { MyChatSystem.AddFactionChatItem(MySession.LocalPlayerId, msg.FactionId1, msg.FactionId2, factionChatItem); } if (senderIdentityId != MySession.LocalPlayerId) { MySession.Static.Gpss.ScanText(factionChatItem.Text, MyTexts.GetString(MySpaceTexts.TerminalTab_GPS_NewFromFactionComms)); } MySession.Static.ChatSystem.OnNewFactionMessage(msg.FactionId1, msg.FactionId2, senderIdentityId, true); }
private static void OnFactionMessageRequest(MySyncCharacter sync, ref SendNewFactionMessageMsg msg, MyNetworkClient sender) { //Ignore messages that have improper lengths if (msg.ChatItem.Text.Length == 0 || msg.ChatItem.Text.Length > MyChatConstants.MAX_CHAT_STRING_LENGTH) { return; } long currentSenderId = MyEntityIdentifier.ConstructId(MyEntityIdentifier.ID_OBJECT_TYPE.IDENTITY, msg.ChatItem.IdentityIdUniqueNumber); var senderId = MySession.Static.Players.TryGetIdentity(currentSenderId); var chatItem = new MyFactionChatItem(); chatItem.Init(msg.ChatItem); //Find all members that can receive this messages m_tempValidIds.Clear(); for (int i = 0; i < msg.ChatItem.PlayersToSendToUniqueNumber.Count; i++) { if (!msg.ChatItem.IsAlreadySentTo[i]) { long receiverIdentityId = MyEntityIdentifier.ConstructId(MyEntityIdentifier.ID_OBJECT_TYPE.IDENTITY, msg.ChatItem.PlayersToSendToUniqueNumber[i]); var receiverId = MySession.Static.Players.TryGetIdentity(receiverIdentityId); if (receiverId != null && receiverId.Character != null && MyAntennaSystem.CheckConnection(senderId, receiverId)) { m_tempValidIds.Add(receiverIdentityId); } } } //Set their sent flag to true, so that everyone knows they already got it (no need for confirm message) foreach (var id in m_tempValidIds) { chatItem.PlayersToSendTo[id] = true; } //Save the flags back in the message msg.ChatItem = chatItem.GetObjectBuilder(); //Send success message back to all recepient members foreach (var id in m_tempValidIds) { MyPlayer.PlayerId receiverPlayerId; MySession.Static.Players.TryGetPlayerId(id, out receiverPlayerId); ulong steamId = receiverPlayerId.SteamId; Sync.Layer.SendMessage(ref msg, steamId, MyTransportMessageEnum.Success); } //Save chat history on server for non-server players if (senderId.Character != MySession.LocalCharacter) { MyChatSystem.AddFactionChatItem(senderId.IdentityId, msg.FactionId1, msg.FactionId2, chatItem); } }
public void SendNewFactionMessage(long factionId1, long factionId2, MyFactionChatItem chatItem) { var msg = new SendNewFactionMessageMsg(); msg.CharacterEntityId = Entity.EntityId; msg.FactionId1 = factionId1; msg.FactionId2 = factionId2; msg.ChatItem = chatItem.GetObjectBuilder(); Sync.Layer.SendMessageToServer(ref msg, MyTransportMessageEnum.Request); }