Пример #1
0
 public void Connect(string photonAppId, string photonAppVersion, int historyLengthToFetch, float keepAliveTick, string playerID)
 {
     ChatCryptographyUtils.StaticInit();
     this.queuedMessagesToPublish = new Queue <SquadMsg>();
     this.encryptedPlayerId       = ChatCryptographyUtils.GetSHA256Hash(playerID);
     this.photonChatWrapper.InitAndConnect(photonAppId, photonAppVersion, historyLengthToFetch, keepAliveTick, this.encryptedPlayerId);
     this.InitChatFilter();
 }
Пример #2
0
        private void PopulateSquadMsgsReceivedFromPhoton(string channelName, string[] senders, object[] messages)
        {
            if (senders == null && messages == null && senders.Length != messages.Length)
            {
                Service.Logger.Error("Cannot populate squad messages, senders and messages count mismatch!");
                return;
            }
            if (messages.Length == 0)
            {
                return;
            }
            if (string.IsNullOrEmpty(this.messageEncryptionKey))
            {
                Service.Logger.Error("Failed to update received messages, message encryption key is null or blank!");
                return;
            }
            int i   = 0;
            int num = messages.Length;

            while (i < num)
            {
                string messageAndIV = messages[i] as string;
                string text         = ChatCryptographyUtils.DecryptMessageWithIV(messageAndIV, this.messageEncryptionKey);
                object obj          = null;
                if (!string.IsNullOrEmpty(text) && text.StartsWith("{"))
                {
                    obj = new JsonParser(text).Parse();
                }
                if (obj == null)
                {
                    Service.Logger.WarnFormat("Decrypted chat message is invalid:{0}", new object[]
                    {
                        (text != null) ? text : string.Empty
                    });
                }
                else
                {
                    PhotonChatMessageTO photonChatMessageTO = new PhotonChatMessageTO(obj);
                    if (this.filter != null)
                    {
                        photonChatMessageTO.Text = this.filter.Filter(photonChatMessageTO.Text);
                    }
                    SquadMsg squadMsg = SquadMsgUtils.GenerateMessageFromPhotonChatMessage(senders[i], photonChatMessageTO);
                    if (squadMsg != null)
                    {
                        if (this.IsMsgValid(squadMsg))
                        {
                            this.list.Add(squadMsg);
                            if (this.latestMsg == null || squadMsg.TimeSent > this.latestMsg.TimeSent)
                            {
                                this.latestMsg = squadMsg;
                            }
                        }
                    }
                }
                i++;
            }
        }
Пример #3
0
        private void OnPublishTimer(uint id, object cookie)
        {
            if (this.queuedMessagesToPublish.Count == 0)
            {
                Service.ViewTimerManager.KillViewTimer(this.publishTimerId);
                this.publishTimerId = 0u;
                return;
            }
            if (this.photonChatWrapper.SessionState != PhotonChatSessionState.Connected)
            {
                Service.Logger.Error("Chat is not connected, messages cannot be published.");
                return;
            }
            SquadMsg squadMsg = this.queuedMessagesToPublish.Dequeue();

            if (string.IsNullOrEmpty(this.messageEncryptionKey))
            {
                Service.Logger.Error("Failed to send message, message encryption key is null or blank!");
                return;
            }
            string serializedMessage = new PhotonChatMessageTO
            {
                UserName  = squadMsg.OwnerData.PlayerName,
                Text      = squadMsg.ChatData.Message,
                TimeStamp = squadMsg.TimeSent.ToString()
            }.GetSerializedMessage();
            string encryptedMessageWithIV = ChatCryptographyUtils.GetEncryptedMessageWithIV(serializedMessage, this.messageEncryptionKey);

            if (string.IsNullOrEmpty(encryptedMessageWithIV))
            {
                Service.Logger.Warn("Failed to send message, encryptedMessageWithIV is blank!");
                return;
            }
            this.photonChatWrapper.PublishMessage(encryptedMessageWithIV);
            Service.EventManager.SendEvent(EventId.SquadChatSent, null);
        }
Пример #4
0
        public void StartSession(ChatType chatType, string channelId)
        {
            string sHA256Hash = ChatCryptographyUtils.GetSHA256Hash(channelId);

            this.photonChatWrapper.StartSession(chatType, sHA256Hash);
        }