示例#1
0
        private void JoinRoomTopic()
        {
            var msg = new NTopicJoinMessage.Builder().TopicRoom(RoomName).Build();

            NakamaManager.Instance.TopicJoin(RoomName, msg);
            _sendMessageButton.interactable = true;
        }
示例#2
0
        public void LeaveTopic()
        {
            ManualResetEvent evt   = new ManualResetEvent(false);
            INError          error = null;

            var message = new NTopicJoinMessage.Builder().TopicRoom("test-room").Build();

            client1.Send(message, (INResultSet <INTopic> topics) =>
            {
                var topic = topics.Results[0];
                client1.Send(NTopicLeaveMessage.Default(topic.Topic), (bool complete) =>
                {
                    evt.Set();
                }, (INError err) => {
                    error = err;
                    evt.Set();
                });
            }, (INError err) =>
            {
                error = err;
                evt.Set();
            });

            evt.WaitOne(5000, false);
            Assert.IsNull(error);
        }
示例#3
0
        public void LeaveTopic()
        {
            ManualResetEvent evt   = new ManualResetEvent(false);
            INError          error = null;

            var message = new NTopicJoinMessage.Builder().TopicRoom(Encoding.UTF8.GetBytes("test-room")).Build();

            client1.Send(message, (INTopic topic) =>
            {
                client1.Send(NTopicLeaveMessage.Default(topic.Topic), (bool complete) =>
                {
                    evt.Set();
                }, (INError err) => {
                    error = err;
                    evt.Set();
                });
            }, (INError err) =>
            {
                error = err;
                evt.Set();
            });

            evt.WaitOne(5000, false);
            Assert.IsNull(error);
        }
    public void LeaveRoom()
    {
        client = NakamaData.Singleton.Client;
        ManualResetEvent leaveEvent = new ManualResetEvent(false);

        var message = new NTopicJoinMessage.Builder().TopicRoom(Encoding.UTF8.GetBytes(currentRoom)).Build();

        client.Send(message, (INTopic topic) =>
        {
            client.Send(NTopicLeaveMessage.Default(topic.Topic), (bool complete) =>
            {
                leaveEvent.Set();
            }, (INError err) => {
                Debug.Log("Failed to complete leaving of room : " + err);
                leaveEvent.Set();
            });
        }, (INError err) =>
        {
            Debug.Log("Failed to leave room : " + err);
            leaveEvent.Set();
        });

        leaveEvent.WaitOne(1000, false);
        chatText.Clear();
        currentChatUsers.Clear();
        //chatUsersJoinedID.Clear();
        currentRoom = "";

        UnRegisterOnTopicMessagePresence();
    }
示例#5
0
    public void Player1JoinTopic()
    {
        NTopicJoinMessage topicJoin = new NTopicJoinMessage.Builder().TopicDirectMessage(idPlayer2).Build();

        client1.Send(topicJoin, (INTopic topic) => {
            topicPlayer1           = topic.Topic;
            JoinTopicPlayer1Enable = false;
            SendChatPlayer1Enable  = true;
        }, (INError error) => {
            Debug.LogErrorFormat("Player 1 could not join topic: '{0}'.", error.Message);
        });
    }
示例#6
0
    // enter room
    protected void EnterRoom()
    {
        var roomName = Encoding.UTF8.GetBytes("DefaultRoom");
        var message  = new NTopicJoinMessage.Builder().TopicRoom(roomName).Build();

        Application.client.Send(message, (INTopic topic) => {
            this.topicId = topic.Topic;

            Debug.Log("Successfully joined the topic");
        }, (INError error) => {
            Debug.LogErrorFormat("Could not join topic: '{0}'.", error.Message);
        });
    }
示例#7
0
        private void SubscribeToAllFriends()
        {
            for (var i = 0; i < StateManager.Instance.Friends.Count; i++)
            {
                var userId = StateManager.Instance.Friends[i].Id;

                // join a chat topic for users that we haven't seen previously
                if (!StateManager.Instance.Topics.ContainsKey(userId))
                {
                    var msg = new NTopicJoinMessage.Builder().TopicDirectMessage(userId).Build();
                    NakamaManager.Instance.TopicJoin(userId, msg);
                }
            }
        }
示例#8
0
    public void Player1JoinTopic()
    {
        NTopicJoinMessage topicJoin = new NTopicJoinMessage.Builder().TopicDirectMessage(session2.Id).Build();

        client1.Send(topicJoin, (INResultSet <INTopic> topics) => {
            foreach (var presence in topics.Results[0].Presences)
            {
                Debug.LogFormat("Presence initial state received by Player 1: User handle '{0}' is in the topic.", presence.Handle);
            }
            topicPlayer1           = topics.Results[0].Topic;
            JoinTopicPlayer1Enable = false;
            JoinTopicPlayer2Enable = true;
        }, (INError error) => {
            Debug.LogErrorFormat("Player 1 could not join topic: '{0}'.", error.Message);
        });
    }
示例#9
0
        public void JoinTopic()
        {
            ManualResetEvent evt   = new ManualResetEvent(false);
            INError          error = null;

            var message = new NTopicJoinMessage.Builder().TopicRoom("test-room").Build();

            client1.Send(message, (INResultSet <INTopic> topics) =>
            {
                evt.Set();
            }, (INError err) =>
            {
                error = err;
                evt.Set();
            });

            evt.WaitOne(5000, false);
            Assert.IsNull(error);
        }
示例#10
0
    /// <summary>
    /// The following is used to create a Match List. Hopefully Nakama releases the version that does this for us! Yay!
    /// TODO: Fix this once that release comes out
    /// Methods::::
    /// SendMatchInfoToMatchRoom(), JoinMatchRoom(),
    /// </summary>
    ///
    public void JoinMatchRoom()
    {
        client = NakamaData.Singleton.Client;
        ManualResetEvent joinEvent = new ManualResetEvent(false);
        var message = new NTopicJoinMessage.Builder().TopicRoom(Encoding.UTF8.GetBytes("match-list")).Build();

        client.Send(message, (INTopic topic) =>
        {
            matchListTopic = topic.Topic;
            joinEvent.Set();
        }, (INError err) =>
        {
            Debug.Log("Failed to join room : " + err);
            joinEvent.Set();
        });

        joinEvent.WaitOne(1000, false);
        RegisterMatchListRoom();
    }
示例#11
0
        public void PresenceUpdateJoinTopic()
        {
            INError error = null;

            ManualResetEvent evt1 = new ManualResetEvent(false);

            byte[] room    = Encoding.UTF8.GetBytes("test-room");
            var    message = new NTopicJoinMessage.Builder().TopicRoom(room).Build();

            client1.Send(message, (INTopic topic) =>
            {
                evt1.Set();
            }, (INError err) =>
            {
                error = err;
                evt1.Set();
            });
            evt1.WaitOne(5000, false);
            Assert.IsNull(error);

            byte[]           joinUserId = null;
            ManualResetEvent evt2       = new ManualResetEvent(false);

            client1.OnTopicPresence += (object source, NTopicPresenceEventArgs args) =>
            {
                joinUserId = args.TopicPresence.Join[0].UserId;
                evt2.Set();
            };
            client2.Send(new NTopicJoinMessage.Builder().TopicRoom(room).Build(), (INTopic topic) =>
            {
                // No action.
            }, (INError err) =>
            {
                error = err;
                evt2.Set();
            });
            evt2.WaitOne(5000, false);
            Assert.IsNull(error);
            Assert.AreEqual(joinUserId, userId2);
        }
示例#12
0
        public void PresenceUpdateJoinTopic()
        {
            INError error = null;

            ManualResetEvent evt1 = new ManualResetEvent(false);
            string           room = "test-room";
            var message           = new NTopicJoinMessage.Builder().TopicRoom(room).Build();

            client1.Send(message, (INResultSet <INTopic> topics) =>
            {
                evt1.Set();
            }, (INError err) =>
            {
                error = err;
                evt1.Set();
            });
            evt1.WaitOne(5000, false);
            Assert.IsNull(error);

            string           joinUserId = null;
            ManualResetEvent evt2       = new ManualResetEvent(false);

            client1.OnTopicPresence = (INTopicPresence presence) =>
            {
                joinUserId = presence.Join[0].UserId;
                evt2.Set();
            };
            client2.Send(new NTopicJoinMessage.Builder().TopicRoom(room).Build(), (INResultSet <INTopic> topic) =>
            {
                // No action.
            }, (INError err) =>
            {
                error = err;
                evt2.Set();
            });
            evt2.WaitOne(5000, false);
            Assert.IsNull(error);
            Assert.AreEqual(joinUserId, userId2);
        }
    //Will join a room for the client, and update that room's userlist for all clients
    public void JoinRoom(string roomName)
    {
        client = NakamaData.Singleton.Client;
        ManualResetEvent joinEvent = new ManualResetEvent(false);

        currentRoom = roomName;
        var message = new NTopicJoinMessage.Builder().TopicRoom(Encoding.UTF8.GetBytes(roomName)).Build();

        client.Send(message, (INTopic topic) =>
        {
            chatText.Add("Successfully joined the room '" + roomName + "'. There are currently " + topic.Presences.Count + " Users");
            Debug.Log("Successfully Joined Room");
            userList     = topic.Presences;
            currentTopic = topic.Topic;
            joinEvent.Set();
        }, (INError err) =>
        {
            Debug.Log("Failed to join room : " + err);
            joinEvent.Set();
        });

        joinEvent.WaitOne(1000, false);

        //Create the user list to display
        foreach (var userInList in userList)
        {
            if (!chatUsersJoinedID.Contains(userInList.UserId))
            {
                chatUsersJoinedID.Add(userInList.UserId);
            }
        }

        Debug.Log("JoinRoom::  ::chatUsersJoinedID.count: " + chatUsersJoinedID.Count);

        UserListChange = true;   //Run update to update UserList
        RegisterOnTopicMessagePresence();
    }