Ejemplo n.º 1
0
 internal NMatchData(MatchData message)
 {
     Data     = message.Data.ToByteArray();
     Id       = message.MatchId;
     OpCode   = message.OpCode;
     Presence = new NUserPresence(message.Presence);
 }
Ejemplo n.º 2
0
 internal NTopic(TTopic message)
 {
     Topic     = new NTopicId(message.Topic);
     Presences = new List <INUserPresence>();
     foreach (var presence in message.Presences)
     {
         Presences.Add(new NUserPresence(presence));
     }
     Self = new NUserPresence(message.Self);
 }
Ejemplo n.º 3
0
 private void OnMatchJoined(INResultSet <INMatch> matches)
 {
     if (matches != null)
     {
         _matchJoined = true;
         self         = matches.Results[0].Self;
         nakamaMatchPresences.AddRange(matches.Results[0].Presence);
         nakamaMatchPresences.Remove(nakamaMatchPresences.Single(x => x.Handle == self.Handle));
     }
 }
Ejemplo n.º 4
0
 internal NMatch(Match message)
 {
     Id       = message.MatchId;
     Presence = new List <INUserPresence>();
     foreach (var item in message.Presences)
     {
         Presence.Add(new NUserPresence(item));
     }
     Self = new NUserPresence(message.Self);
 }
 protected void OnMatchPresence()
 {
     Application.client.OnMatchPresence += (object src, NMatchPresenceEventArgs args) => {
         for (int i = 0; i < args.MatchPresence.Join.Count; i++)
         {
             INUserPresence p = args.MatchPresence.Join [i];
             this.newUserIds[Encoding.UTF8.GetString(p.UserId)] = true;
             Debug.LogFormat("User Enter Match {0}", p.UserId);
         }
         for (int i = 0; i < args.MatchPresence.Leave.Count; i++)
         {
             INUserPresence p = args.MatchPresence.Leave [i];
             this.newUserIds[Encoding.UTF8.GetString(p.UserId)] = false;
             Debug.LogFormat("User Leave Match {0}", p.UserId);
         }
     };
 }
Ejemplo n.º 6
0
    protected void OnMatchPresence()
    {
        Application.client.OnMatchPresence += (object src, NMatchPresenceEventArgs args) => {
            // user join
            for (int i = 0; i < args.MatchPresence.Join.Count; i++)
            {
                Debug.Log("user enter");
                INUserPresence p            = args.MatchPresence.Join [i];
                var            userIdString = Encoding.UTF8.GetString(p.UserId);
                if (!this.userWarriorBaseInfos.ContainsKey(userIdString))
                {
                    this.userWarriorBaseInfos [userIdString] = new Dictionary <int, PutWarriorMessage> ();
                }
                if (!this.userWarriors.ContainsKey(userIdString))
                {
                    this.userWarriors [userIdString] = new Dictionary <int, GameObject> ();
                }
            }

            // user leave
            for (int i = 0; i < args.MatchPresence.Leave.Count; i++)
            {
                Debug.Log("user leave");
                INUserPresence p            = args.MatchPresence.Leave [i];
                var            userIdString = Encoding.UTF8.GetString(p.UserId);
                if (this.userWarriorBaseInfos.ContainsKey(userIdString))
                {
                    this.userWarriorBaseInfos.Remove(userIdString);
                }
                if (this.userWarriors.ContainsKey(userIdString))
                {
                    this.userWarriors.Remove(userIdString);
                }
            }
        };
    }
Ejemplo n.º 7
0
        public void SendDataSubsetMatch()
        {
            INError        error = null;
            INMatch        m     = null;
            INUserPresence p     = null;

            ManualResetEvent evt1 = new ManualResetEvent(false);

            client1.Send(NMatchCreateMessage.Default(), (INMatch match) =>
            {
                m = match;
                client2.Send(NMatchJoinMessage.Default(match.Id), (INResultSet <INMatch> matches2) =>
                {
                    var match2 = matches2.Results[0];
                    foreach (var up in match2.Presence)
                    {
                        if (up.UserId.SequenceEqual(userId2))
                        {
                            p = up;
                            break;
                        }
                    }
                    evt1.Set();
                }, (INError err) =>
                {
                    error = err;
                    evt1.Set();
                });
            }, (INError err) =>
            {
                error = err;
                evt1.Set();
            });
            evt1.WaitOne(5000, false);
            Assert.IsNull(error);
            Assert.IsNotNull(m, "m was null");
            Assert.IsNotNull(p, "p was null");

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

            client1.OnMatchData = (INMatchData matchData) =>
            {
                d = matchData;
                evt2.Set();
            };
            var msg = new NMatchDataSendMessage.Builder(m.Id, opCode, data).Presences(new INUserPresence[] { p }).Build();

            client2.Send(msg, false, (bool completed) =>
            {
                // No action.
            }, (INError err) => {
                error = err;
                evt2.Set();
            });
            evt2.WaitOne(2000, false);
            Assert.IsNull(error);
            Assert.IsNull(d);
        }