Exemplo n.º 1
0
        public void OnSendClicked()
        {
            // read input field
            string content = _message.text;

            _message.text = "";

            // diplay you own message
            messageToDisplay = "YOU: " + content;
            msgWaiting       = true;

            // encode string to byte array
            byte[] data = System.Text.Encoding.UTF8.GetBytes(content);
            var    msg  = NMatchDataSendMessage.Default(
                _networkManager.nakamaMatchId,
                0L,
                data);

            // send the message to all other clients
            _networkManager.client.Send(
                msg,
                (bool done) => { Debug.Log("Message send"); },
                (INError error) => { Debug.Log("Error on send message"); }
                );
        }
Exemplo n.º 2
0
        private void OnMatchPresencesUpdated(INMatchPresence presences)
        {
            _matchPresencesUpdated = true;
            foreach (var user in presences.Leave)
            {
                nakamaMatchPresences.Remove(nakamaMatchPresences.Single(x => x.Handle == user.Handle));
            }

            foreach (var user in presences.Join)
            {
                nakamaMatchPresences.Add(user);

                var playerCount = nakamaMatchPresences.Count();
                if (playerCount >= minNumberOfPlayers && playerCount <= maxNumberOfPlayers)
                {
                    Debug.Log("Game is ready");
                    Enqueue(
                        () => nvp_EventManager_scr.INSTANCE.InvokeEvent(GameEvents.OnMatchIsReady, this, nakamaMatchPresences)
                        );
                }
                else
                {
                    var matchIsFullMessage = NMatchDataSendMessage.Default(
                        nakamaMatchId,
                        99L,
                        System.Text.Encoding.UTF8.GetBytes(user.Handle));
                    _nakama.SendDataMessage(matchIsFullMessage);
                }
            }
        }
Exemplo n.º 3
0
    /// <summary>
    /// opCodes:
    /// 0 Joined
    /// 1 Player 1 turn
    /// 2 Player 2 turn
    /// 3 Card Drawn(by whoever sent this)
    /// 4 Attack(by whoever sent this)
    /// 5 current turn
    /// </summary>
    public void SendMatchData(int opCode, string dataString)
    {
        Debug.Log("Sending Match Data:: opCode: " + opCode + " datastring: " + dataString);
        byte[] data    = Encoding.ASCII.GetBytes(dataString);
        var    message = NMatchDataSendMessage.Default(matchID, opCode, data);

        client.Send(message, (bool complete) =>
        {
            Debug.Log("Successfully sent data to match.");
        }, (INError error) => {
            Debug.LogErrorFormat("Could not send data to match: '{0}'.", error.Message);
        });
    }
Exemplo n.º 4
0
        public void SendDataMatch()
        {
            INError error = null;
            INMatch m     = null;

            ManualResetEvent evt1 = new ManualResetEvent(false);

            client1.Send(NMatchCreateMessage.Default(), (INMatch match) =>
            {
                m = match;
                client2.Send(NMatchJoinMessage.Default(match.Id), (INResultSet <INMatch> match2) =>
                {
                    evt1.Set();
                }, (INError err) =>
                {
                    error = err;
                    evt1.Set();
                });
            }, (INError err) =>
            {
                error = err;
                evt1.Set();
            });
            evt1.WaitOne(5000, false);
            Assert.IsNull(error);
            Assert.IsNotNull(m);

            byte[]           data   = Encoding.ASCII.GetBytes("test-data");
            long             opCode = 9;
            INMatchData      d      = null;
            ManualResetEvent evt2   = new ManualResetEvent(false);

            client2.OnMatchData = (INMatchData matchData) =>
            {
                d = matchData;
                evt2.Set();
            };
            client1.Send(NMatchDataSendMessage.Default(m.Id, opCode, data), false, (bool completed) =>
            {
                // No action.
            }, (INError err) => {
                error = err;
                evt2.Set();
            });
            evt2.WaitOne(5000, false);
            Assert.IsNull(error);
            Assert.IsNotNull(d);
            Assert.AreEqual(d.Id, m.Id);
            Assert.AreEqual(d.OpCode, opCode);
            Assert.AreEqual(d.Data, data);
        }
Exemplo n.º 5
0
    public void SendMatchData(byte[] matchId, PutWarriorMessage putWarriorMessage)
    {
//		Debug.Log ("SendMatchData " + Encoding.UTF8.GetString(matchId));

        long opCode  = 1;
        var  data    = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(putWarriorMessage));
        var  message = NMatchDataSendMessage.Default(matchId, opCode, data);

        Application.client.Send(message, (bool complete) => {
//			Debug.Log("Successfully sent data to match.");
        }, (INError error) => {
            Debug.LogErrorFormat("Could not send data to match: '{0}'.", error.Message);
        });
    }
    public void SendMatchMessage(long opCode, string strMessage)
    {
        //TODO: only if current match excist
        string id = _match.Id;         // an INMatch Id.

        Debug.Log("Sending Match Message to id " + _match.Id);
        byte[] data    = Encoding.UTF8.GetBytes(strMessage);
        var    message = NMatchDataSendMessage.Default(id, opCode, data);

        _client.Send(message, (bool done) => {
            Debug.Log("Successfully sent data message.");
        }, (INError err) => {
            Debug.LogErrorFormat("Error: code '{0}' with '{1}'.", err.Code, err.Message);
        });
    }
 internal void SendDataMessage(NMatchDataSendMessage msg)
 {
     _client.Send(
         msg,
         (bool done) => { if (OnMatchDataMessageSent != null)
                          {
                              OnMatchDataMessageSent(done);
                          }
         },
         (INError Error) => { if (OnMatchDataMessageSent != null)
                              {
                                  OnMatchDataMessageSent(false);
                              }
         }
         );
 }
    public void SendMatchData(byte[] matchId, Vector3 position)
    {
//		Debug.Log ("SendMatchData");

        long opCode = 1;
        UpdatePositionMessage updatePositionMessage = new UpdatePositionMessage();

        updatePositionMessage.x = position.x;
        updatePositionMessage.y = position.y;
        updatePositionMessage.z = position.z;

        var data    = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(updatePositionMessage));
        var message = NMatchDataSendMessage.Default(matchId, opCode, data);

        Application.client.Send(message, (bool complete) => {
//			Debug.Log("Successfully sent data to match.");
        }, (INError error) => {
            Debug.LogErrorFormat("Could not send data to match: '{0}'.", error.Message);
        });
    }
Exemplo n.º 9
0
    // Update is called once per frame
    void Update()
    {
        if (isLocal)
        {
            // get input
            var input = Input.GetAxis("Vertical");

            // move
            transform.Translate(Vector3.up * Time.deltaTime * input * speed, Space.World);

            // push position
            List <float> data    = new List <float>().AddVector(transform.position);
            var          message = NMatchDataSendMessage.Default(matchId, 1, data.Serialize());
            client.Send(message, (bool done) => { Debug.Log("done"); }, (INError error) => Debug.LogError(error.Message));
        }
        else
        {
            transform.position = networkPosition;
        }
    }
Exemplo n.º 10
0
    // This is invoked by clicking on the scene UI button.
    public void SendMatchData()
    {
        var text = new Text();

        text.timestamp = DateTime.Now.ToString("yyyy/MM/dd-HH:mm:ss");
        text.message   = "Hello world.";

        var json = JsonUtility.ToJson(text);
        var data = Encoding.UTF8.GetBytes(json);

        // `matchId` is the `byte[]` ID of the match to send to.
        // `opCode` is any desired integer.
        // `data` is any `byte[]` of data to send.
        var message = NMatchDataSendMessage.Default(_match.Id, MatchOpCode, data);

        _client.Send(message, (bool complete) => {
            Debug.Log("Successfully sent data to match.");
        }, error => {
            Debug.LogErrorFormat("Send error: code '{1}' with '{0}'.", error.Message, error.Code);
        });
    }
Exemplo n.º 11
0
        public void SendDataNoEchoMatch()
        {
            INError error = null;
            INMatch m     = null;

            ManualResetEvent evt1 = new ManualResetEvent(false);

            client1.Send(NMatchCreateMessage.Default(), (INMatch match) =>
            {
                m = match;
                evt1.Set();
            }, (INError err) =>
            {
                error = err;
                evt1.Set();
            });
            evt1.WaitOne(5000, false);
            Assert.IsNull(error);
            Assert.IsNotNull(m);

            INMatchData      d    = null;
            ManualResetEvent evt2 = new ManualResetEvent(false);

            client1.OnMatchData = (INMatchData data) =>
            {
                d = data;
                evt2.Set();
            };
            client1.Send(NMatchDataSendMessage.Default(m.Id, 9, Encoding.ASCII.GetBytes("test-data")), false, (bool completed) =>
            {
                // No action.
            }, (INError err) => {
                error = err;
                evt2.Set();
            });
            evt2.WaitOne(1000, false);
            Assert.IsNull(error);
            Assert.IsNull(d);
        }