Exemplo n.º 1
0
 /// <summary>
 /// Invoke a call over the MessageSentCallback reference.<b>If the reference is null, nothing is performed at all.</b> Once the method is invoked the callback reference is set to null.
 /// </summary>
 /// <param name="caller"></param>
 /// <param name="arg"></param>
 public void MessageSent(NetworkEntity caller, object arg)
 {
     if (this.messageSentCallback != null)
     {
         this.messageSentCallback(caller, arg);
         this.messageSentCallback = null;
     }
 }
Exemplo n.º 2
0
 public SendMessageState Init(Socket socket, byte[] buffer,
                              int offset, int count, object state, MessageSentCallback callback)
 {
     Socket   = socket;
     Buffer   = buffer;
     Offset   = offset;
     Count    = count;
     State    = state;
     Callback = callback;
     return(this);
 }
Exemplo n.º 3
0
        public static void SendMessage(Socket socket, PeerMessage message, object state, MessageSentCallback callback)
        {
            var buffer = message.ToBytes();
            var data   = SendCache.Get().Init(socket, buffer, 0, buffer.Length, state, callback);

            SendMessageBase(data);
        }
Exemplo n.º 4
0
 public static void SendMessage(Socket socket, PeerMessage message, object state, MessageSentCallback callback)
 {
     byte[] buffer = message.ToBytes();
     SendMessageState data = SendCache.Get().Init(socket, buffer, 0, buffer.Length, state, callback);
     SendMessageBase(data);
 }
Exemplo n.º 5
0
 public SendMessageState Init(Socket socket, byte[] buffer,
                              int offset, int count, object state, MessageSentCallback callback)
 {
     Socket = socket;
     Buffer = buffer;
     Offset = offset;
     Count = count;
     State = state;
     Callback = callback;
     return this;
 }
Exemplo n.º 6
0
 public void SendMessage(MessageInfo m, MessageSentCallback success, MessageSendingError failure, NoConnectionCallback noconnection)
 {
     StartCoroutine(SendMessageCoroutine(m, success, failure, noconnection));
 }
Exemplo n.º 7
0
    public IEnumerator SendMessageCoroutine(MessageInfo m, MessageSentCallback success, MessageSendingError failure, NoConnectionCallback noconnection)
    {
        WWWForm form = new WWWForm();

        form.AddField("recipientId", m.recipient);
        form.AddField("title", m.title);
        form.AddField("messageBody", m.body);
        if (m.replyTo != null)
        {
            form.AddField("replyTo", m.replyTo);
        }

        bool hacked = m_UserManager.CurrentHackedUser != null;

        UnityWebRequest request;

        if (hacked)
        {
            form.AddField("targetId", m_UserManager.CurrentHackedUser);
            request = UnityWebRequest.Post(Constants.serverAddress + "api/hack/messages", form);
        }
        else
        {
            request = UnityWebRequest.Post(Constants.serverAddress + "api/messages", form);
        }

        m_UserManager.SetCurrentUserAuthorization(request);

        yield return(request.SendWebRequest());

        while (!request.isDone)
        {
            yield return(new WaitForEndOfFrame());
        }

        if (request.isNetworkError)
        {
            Debug.Log("Network error: Cannot send message: " + request.error + ", Code = " + request.responseCode);
            if (noconnection != null)
            {
                noconnection();
            }
        }
        else if (request.isHttpError)
        {
            if (request.responseCode == 400)
            {
                Debug.Log("Http error: Message data missing: " + request.error + ", Code = " + request.responseCode + " " + request.downloadHandler.text);
            }
            else if (request.responseCode == 404)
            {
                Debug.Log("Http error: Recipient or parent not found: " + request.error + ", Code = " + request.responseCode + " " + request.downloadHandler.text);
            }
            else if (request.responseCode == 500)
            {
                Debug.Log("Http error: Database search failed: " + request.error + ", Code = " + request.responseCode);
            }

            if (failure != null)
            {
                failure();
            }
        }
        else if (request.responseCode == 200)
        {
            // response contains the message
            //Debug.Log("Message sent: " + request.downloadHandler.text);
            GetMessages(true, () => { success(); }, noconnection, () => { failure(); });
        }
    }
Exemplo n.º 8
0
 /// <summary>
 /// Creates an empty NetworkEntity
 /// </summary>
 protected NetworkEntity()
     : base()
 {
     this.messageSentCallback = null;
 }
Exemplo n.º 9
0
 /// <summary>
 /// Constructs a new NetworkEntity
 /// </summary>
 /// <param name="entityOwner">Reference (ref) to the socket who will be the owner of this object.</param>
 public NetworkEntity(ref Socket entityOwner)
     : base(ref entityOwner)
 {
     this.messageSentCallback = null;
 }
Exemplo n.º 10
0
 /// <summary>
 /// Set the method to the underlaying callback reference.
 /// </summary>
 /// <param name="method">Method to be called.</param>
 public void SetMessageSentCallback(MessageSentCallback method)
 {
     this.messageSentCallback += method;
 }
Exemplo n.º 11
0
 internal static extern int SendMessage(IntPtr serviceHandle, IntPtr messageHandle, bool saveToSentbox, MessageSentCallback cb, IntPtr userData);