예제 #1
0
 public Deferred SelectCharacter(Character character)
 {
     if (isServer)
     {
         var cond = Conductor.GetConductor();
         if (cond == null)
         {
             Debug.LogError("A conductor is required to log in!", gameObject);
             return(Deferred.Fail(new Exception("A conductor is required to log in!")));
         }
         var ps = cond.GetLocalServiceByInterface <IPlayerService>();
         if (ps == null)
         {
             Debug.LogError("A player service is required!", gameObject);
             return(Deferred.Fail(new Exception("A player service is required!")));
         }
         var pc = GetComponent <PlayerCharacter>();
         return(ps.SelectCharacter(pc.account, character).AddCallback((obj, res) =>
         {
             pc.character = obj as Character;
             pc.name = "Player - " + pc.account.username + " - " + pc.character.name;
             return obj;
         }));
     }
     return(CallRemote(g => CmdSelectCharacter(new SerializedCharacter(character), g)).AddCallback((res, p) =>
     {
         var pc = GetComponent <PlayerCharacter>();
         pc.character = res as Character;
         pc.name = "Player - " + pc.account.username + " - " + pc.character.name;
         return res;
     }));
 }
예제 #2
0
 public Deferred LogIn(string username, string password)
 {
     if (isServer)
     {
         var cond = Conductor.GetConductor();
         if (cond == null)
         {
             Debug.LogError("A conductor is required to log in!", gameObject);
             return(Deferred.Fail(new Exception("A conductor is required to log in!")));
         }
         var ps = cond.GetLocalServiceByInterface <IMultiplayerService>();
         if (ps == null)
         {
             Debug.LogError("A player service is required!", gameObject);
             return(Deferred.Fail(new Exception("A player service is required!")));
         }
         return(ps.LogIn(Connection, username, password).AddCallback((obj, res) =>
         {
             var pc = GetComponent <PlayerCharacter>();
             pc.account = obj as Account;
             return obj;
         }));
     }
     return(CallRemote(g => CmdLogIn(username, password, g)).AddCallback((res, p) =>
     {
         var pc = GetComponent <PlayerCharacter>();
         pc.account = res as Account;
         name = "Player - " + pc.account.username;
         return res;
     }));
 }
예제 #3
0
        public void ExceptionThrownInFailShouldBeReportedToSinkExceptionHandler()
        {
            Promises.ResetSinkExceptionHandler(e => exceptions.Add(e));
            var source = new Deferred <TWrapper <int> > ();

            source.Fail(_ => {
                throw new Exception();
            });
            source.Fail(_ => {
                throw new Exception();
            });
            source.Reject(new Exception());
            source.Fail(_ => {
                throw new Exception();
            });
            source.Fail(_ => {
                throw new Exception();
            });
            Assert.That(exceptions.Count, Is.EqualTo(4));
        }
예제 #4
0
        public Deferred LogIn(IConnection connection, string username, string password)
        {
            var cond = Conductor.GetConductor();

            if (cond == null)
            {
                Debug.LogError("Can't log in without a conductor!");
                return(Deferred.Fail(new Exception("Can't log in without a conductor!")));
            }
            var ssvc = cond.GetLocalServiceByInterface <IStorageService>();

            if (ssvc == null)
            {
                Debug.LogError("Can't log in without a storage service!");
                return(Deferred.Fail(new Exception("Can't log in without a storage service!")));
            }
            return(ssvc.Load <Account>(new List <string> {
                username
            }).AddCallback((res, p) =>
            {
                var acct = res as Account;
                if (acct == null)
                {
                    Debug.LogError("Error logging in " + username + ". Account not found.");
                    return Deferred.Fail(new Exception("Authentication error!"));
                }
                if (acct.password != password)
                {
                    Debug.LogError("Error logging in " + username + ". Password doesn't match!");
                    return Deferred.Fail(new Exception("Authentication error!"));
                }
                var c = connection as ConnectedUser;
                c.account = acct;
                if (c.player != null)
                {
                    var pc = c.player.GetComponent <PlayerCharacter>();
                    if (pc != null)
                    {
                        pc.account = acct;
                        pc.gameObject.name = "Player - " + acct.username;
                    }
                }
                return res;
            }));
        }
예제 #5
0
 public Deferred GetCharacters()
 {
     if (isServer)
     {
         var cond = Conductor.GetConductor();
         if (cond == null)
         {
             Debug.LogError("A conductor is required to log in!", gameObject);
             return(Deferred.Fail(new Exception("A conductor is required to log in!")));
         }
         var ps = cond.GetLocalServiceByInterface <IPlayerService>();
         if (ps == null)
         {
             Debug.LogError("A player service is required!", gameObject);
             return(Deferred.Fail(new Exception("A player service is required!")));
         }
         var pl = GetComponent <PlayerCharacter>();
         return(ps.GetCharacters(pl.account));
     }
     return(CallRemote(g => CmdGetCharacters(g)));
 }
예제 #6
0
 public Deferred DeleteCharacter(Character character)
 {
     if (isServer)
     {
         var cond = Conductor.GetConductor();
         if (cond == null)
         {
             Debug.LogError("A conductor is required to log in!", gameObject);
             return(Deferred.Fail(new Exception("A conductor is required to log in!")));
         }
         var ps = cond.GetLocalServiceByInterface <IPlayerService>();
         if (ps == null)
         {
             Debug.LogError("A player service is required!", gameObject);
             return(Deferred.Fail(new Exception("A player service is required!")));
         }
         var conn = Connection as ConnectedUser;
         return(ps.DeleteCharacter(conn.account, character));
     }
     return(CallRemote(g => CmdDeleteCharacter(new SerializedCharacter(character), g)));
 }
예제 #7
0
 private void FailPromise()
 {
     promise.Fail(new Exception("Failed start promise"));
 }
예제 #8
0
        public void GetErrorTest()
        {
            CallCounter counter = new CallCounter();
            Deferred<System.String> d = new Deferred<System.String>();

            d.Fail(p => {
                Assert.AreEqual("UniDeffered", p.Error);
                counter.Fail++;
            });

            d.Reject("UniDeffered");
            Assert.AreEqual(1, counter.Fail);
        }