Esempio n. 1
0
        public void HandleRng()
        {
            string[] rngParameters = currentResponse.Split(" ");
            string   sessionId     = rngParameters[1];

            string[] addressAndPort = rngParameters[2].Split(":");
            int      sbPort;
            string   sbAddress = addressAndPort[0];

            int.TryParse(addressAndPort[1], out sbPort);
            string         authString     = rngParameters[4];
            string         principalEmail = rngParameters[5];
            string         principalName  = rngParameters[6];
            int            conversationId = random.Next(1000, 9999);
            SBConversation conversation   = new SBConversation(this, Convert.ToString(conversationId));

            SbConversations.Add(conversation);
            SwitchboardConnection switchboardConnection = new SwitchboardConnection(sbAddress, sbPort, email, authString, UserInfo.DisplayName, principalName, principalEmail, sessionId)
            {
                KeepMessagingHistory = KeepMessagingHistoryInSwitchboard
            };

            _ = switchboardConnection.AnswerRNG();
            SwitchboardCreated?.Invoke(this, new SwitchboardEventArgs()
            {
                switchboard = switchboardConnection
            });
            switchboardConnection.FillMessageHistory();
        }
        public void ReceivingCallback(IAsyncResult asyncResult)
        {
            SwitchboardConnection switchboardConnection = (SwitchboardConnection)asyncResult.AsyncState;
            int bytesReceived = switchboardConnection.sbSocket.StopReceiving(asyncResult);

            switchboardConnection.OutputString = Encoding.UTF8.GetString(switchboardConnection.OutputBuffer, 0, bytesReceived);
            string[] responses = switchboardConnection.OutputString.Split("\r\n");
            for (var i = 0; i < responses.Length; i++)
            {
                string[] responseParameters = responses[i].Split(" ");
                switchboardConnection.currentResponse = responses[i];
                try
                {
                    switchboardConnection.commandHandlers[responseParameters[0]]();
                }
                catch (KeyNotFoundException)
                {
                    continue;
                }
                catch (Exception e)
                {
                    var task = switchboardConnection.AddToErrorLog($"{responseParameters[0]} processing error: " + e.Message);
                }
            }
            if (bytesReceived > 0)
            {
                sbSocket.BeginReceiving(OutputBuffer, new AsyncCallback(ReceivingCallback), switchboardConnection);
            }
        }
Esempio n. 3
0
        public async Task HandleXfr()
        {
            string[] xfrParameters  = currentResponse.Split(" ");
            string[] addressAndPort = xfrParameters[3].Split(":");
            string   sbAddress      = addressAndPort[0];
            int      sbPort;

            int.TryParse(addressAndPort[1], out sbPort);
            string authString = "";

            switch (MsnpVersion)
            {
            case "MSNP12":
                authString = xfrParameters.Last();
                break;

            case "MSNP15":
                authString = xfrParameters[5];
                break;

            default:
                throw new Exceptions.VersionNotSelectedException();
            }
            SwitchboardConnection switchboardConnection = new SwitchboardConnection(sbAddress, sbPort, email, authString, UserInfo.DisplayName)
            {
                KeepMessagingHistory = KeepMessagingHistoryInSwitchboard
            };
            await switchboardConnection.LoginToNewSwitchboardAsync();

            await switchboardConnection.InvitePrincipal(ContactToChat.Email, ContactToChat.DisplayName);

            SwitchboardCreated?.Invoke(this, new SwitchboardEventArgs()
            {
                switchboard = switchboardConnection
            });
            switchboardConnection.FillMessageHistory();
        }