예제 #1
0
    public void SetReceiver(CNSMessageClient client)
    {
        if (activeReceiver == client)
        {
            activeReceiver = null;
            active         = !active;
            return;
        }
        if (activeSender == client)
        {
            activeSender = null;
            active       = !active;
            return;
        }

        if (active)
        {
            activeSender = client;
        }
        else
        {
            activeReceiver = client;
        }
        active = !active;
    }
예제 #2
0
    public void SendMessage(CNSMessageClient receiver, string message)
    {
        AddMessageReceiver(receiver);
        MessageSendingParams p = outgoingMessages[receiver];
        string mess            = p.SendMessage(message);

        receiver.ReceiveMessage(this, mess);
    }
예제 #3
0
 public void AddMessageSender(CNSMessageClient other, MessageReceivingParams receivingParams)
 {
     if (incomingMessages.ContainsKey(other))
     {
         return;
     }
     incomingMessages.Add(other, receivingParams);
 }
예제 #4
0
    public void AddMessageReceiver(CNSMessageClient other)
    {
        if (outgoingMessages.ContainsKey(other))
        {
            return;
        }
        MessageSendingParams p = new MessageSendingParams();

        outgoingMessages.Add(other, p);
        other.AddMessageSender(this, new MessageReceivingParams(p.publicKey, p.encryptionKey, p.encryptionIV));
    }
예제 #5
0
    public void ReceiveMessage(CNSMessageClient sender, string cryptText)
    {
        MessageReceivingParams p = incomingMessages[sender];
        string message;

        if (p.DecryptMessage(cryptText, out message))
        {
            OnMessageRecievedCallback?.Invoke(message);
            CNSClientManager.WriteLine("Received a verified message at Client " + clientID + " from Client " + sender.clientID + " : " + message);
        }
        else
        {
            OnMessageFailedCallback?.Invoke();
        }
    }
예제 #6
0
 public static void RegisterClient(CNSMessageClient client)
 {
     client.GetComponent <Button>().onClick.AddListener(() => instance.SetReceiver(client));
     client.clientID = clientCount;
     clientCount++;
 }