Esempio n. 1
0
 public void resetLeaderboardOnFirebase()
 {
     for (int i = 1; i <= 10; i++)
     {
         IFirebase entry = root.Child(i.ToString());
         entry.Child("Name").SetValue("AAAAAAAAAA");
         entry.Child("Score").SetValue("0");
     }
 }
Esempio n. 2
0
    public static IEnumerator Push(string name, string content)
    {
        IFirebase pushed = firebase.Push();

        pushed.Child("IP").SetValue(Network.player.ipAddress);
        pushed.Child("name").SetValue(name);
        pushed.Child("content").SetValue(content);
        pushed.Child("time").SetValue(DateTime.Now.ToString());
        yield return(null);
    }
Esempio n. 3
0
    public void leaderboardEntriesToFirebase(LeaderboardEntry[] entriesTemp)
    {
        for (int i = 0; i < 9; i++)
        {
            IFirebase entry = root.Child((i + 1).ToString());
            entry.Child("Name").SetValue(entriesTemp[i].name);
            entry.Child("Score").SetValue(entriesTemp[i].score.ToString());

            leaderboardEntries [i].name  = entriesTemp [i].name;
            leaderboardEntries [i].score = entriesTemp [i].score;
        }
    }
Esempio n. 4
0
    public static void setBattleEventValue(IFirebase refFirebase, RemoteEventBase theEvent)
    {
        Dictionary <string, object> currentlocatoin = new Dictionary <string, object>();

        currentlocatoin.Add(RemoteEventBase.KEY_VECTOR_X, theEvent.getCurrentLocation().x);
        currentlocatoin.Add(RemoteEventBase.KEY_VECTOR_Y, theEvent.getCurrentLocation().y);
        currentlocatoin.Add(RemoteEventBase.KEY_VECTOR_Z, theEvent.getCurrentLocation().z);

        Dictionary <string, object> targetlocation = new Dictionary <string, object>();

        targetlocation.Add(RemoteEventBase.KEY_VECTOR_X, theEvent.getTargetLocation().x);
        targetlocation.Add(RemoteEventBase.KEY_VECTOR_Y, theEvent.getTargetLocation().y);
        targetlocation.Add(RemoteEventBase.KEY_VECTOR_Z, theEvent.getTargetLocation().z);

        Dictionary <string, object> value = new Dictionary <string, object>();

        value.Add(RemoteEventBase.KEY_ACTION_NAME, theEvent.getActionName());
        value.Add(RemoteEventBase.KEY_ACTOR, theEvent.getActorId());
        value.Add(RemoteEventBase.KEY_ACT_TARGET, theEvent.getActTarget());
        value.Add(RemoteEventBase.KEY_PLAYER_ID, theEvent.getPlayerId());

        value.Add(RemoteEventBase.KEY_LOC_CURRENT, currentlocatoin);
        value.Add(RemoteEventBase.KEY_LOC_TARGET, targetlocation);
        value.Add(RemoteEventBase.KEY_TIME_STAMP, theEvent.getTimeStamp());

        refFirebase.Child(RemoteEventBase.KEY_EVENT_ROOT).Push().SetValue(value);
    }
Esempio n. 5
0
        public JobQueue(IFirebase jobs, Func <T, bool> callback)
        {
            // create our own copy and ignore filters
            _jobs = jobs.Child("/");

            _query = _jobs
                     .On("child_changed", (snap, child, context) =>
            {
                if (snap.Exists)
                {
                    if (snap["Timestamp"][".sv"].Exists)
                    {
                        // local version
                        return;
                    }

                    T data = snap["Data"].Value <T>();

                    try
                    {
                        if (callback(data))
                        {
                            // remove from the queue
                            snap.Ref().Remove();
                        }
                    }
                    catch (Exception ex)
                    {
                        Debug.WriteLine("ERROR: {0}", ex);
                    }
                }
            });
        }
 // Use this for initialization
 void Start()
 {
     fbRootRef  = Firebase.CreateNew("https://" + AppConstants.kFirebaseAppID);
     primaryRef = fbRootRef.Child("FirstRoom");
     //primaryRef.ChildAdded += primaryRefChildAdded;
     //primaryRef.ValueUpdated += primaryRefValueUpdated;
 }
Esempio n. 7
0
    /// <summary>
    /// Create a Firebase object based on this current player logged in
    /// </summary>
    void InitFirebasePlayer(string id, Vector3 initialPosition)
    {
        identifier = id;
        IDictionary <string, object> data = new Dictionary <string, object>();

        data.Add("position", JsonUtility.ToJson(initialPosition));
        firebase.Child(identifier).SetValue(data);
    }
    void Awake()
    {
        if (singleton != null)
        {
            Destroy(singleton.gameObject);
        }
        singleton = this as MainManager;

        firebase_root  = Firebase.CreateNew(FIREBASE_URL);
        firebase_users = firebase_root.Child("users");

        user_id = "";

        //print("firebase_users: " + firebase_users);
        //firebase_users.Child("bob123").SetValue("test!");
        //print("key: " + firebase_users.Key);
    }
Esempio n. 9
0
    // Use this for initialization
    private void gameStart()
    {
        Debug.Log("GameController start+");
        _gameProcessing = true;
        controlUIPanelHost.SetActive(true);
        unitControlPanels = controlUIPanelHost.GetComponentsInChildren <UnitControlPanel>();

        createHumanoid();


        FireBase_battle_event = FireBase_battle.Child(RemoteEventBase.KEY_EVENT_ROOT);
        ////firebase.AuthWithPassword("*****@*****.**", "iloveawei", (AuthData auth) =>
        ////{
        ////    Debug.Log("auth success!!" + auth.Uid);
        ////}, (FirebaseError e) =>
        ////{
        ////    Debug.Log("auth failure!!");
        ////});

        FireBase_battle_event.ChildAdded += (object sender, ChangedEventArgs e) =>
        {
            IDataSnapshot dataSnap = e.DataSnapshot;


            Logger.firebase("Child added! " + sender + ", " + e + ", " + dataSnap.Key);

            try
            {
                List <RemoteEventBase> result = FireBaseUtil.getBattleEventValue(dataSnap);
                onRemoteEvents(result);
            } catch (Exception ex) {
                Debug.Log(ex.Message);
            }

            //    ////String x = dataSnap.Child("x").StringValue;
            //    ////String y = dataSnap.Child("y").StringValue;
            //    ////String z = dataSnap.Child("z").StringValue;

            //    //Dictionary<string, object> value = dataSnap.DictionaryValue;
            //    //string x = value["x"].ToString();
            //    //string y = value["y"].ToString();
            //    //string z = value["z"].ToString();

            //    //if (debugFirebase)
            //    //    Debug.Log("Child added! " + dataSnap.Key + ", s " + dataSnap.DictionaryValue + ", x " + x + ", y " + y + ", z " + z);

            //    //Vector3 p = new Vector3(float.Parse(x), float.Parse(y), float.Parse(z));
            //    //foreach (Humanoid h in humanoid)
            //    //{
            //    //    h.onRemoteUpdate(Int32.Parse(dataSnap.Key), p);
            //    //};
        };

        //firebase.ChildRemoved += (object sender, ChangedEventArgs e) =>
        //{
        //    IDataSnapshot dataSnap = e.DataSnapshot;
        //    if (debugFirebase)
        //        Debug.Log("Child removed! " + sender + ", " + e + ", " + dataSnap);
        //};

        FireBase_battle_event.ValueUpdated += (object sender, ChangedEventArgs ex) => {
            IDataSnapshot dataSnap = ex.DataSnapshot;
            Logger.firebase("Child ValueUpdated! " + sender + ", " + ex + ", " + dataSnap.Key);

            //    //String x = dataSnap.Child("x").StringValue;
            //    //String y = dataSnap.Child("y").StringValue;
            //    //String z = dataSnap.Child("z").StringValue;

            //    //Debug.Log("Child ValueUpdated! " + dataSnap.Key + ", " + dataSnap.StringValue + ", " + x + ", " + y + ", " + z);

            //    //Vector3 p = new Vector3(x, y, z);
            //    //foreach (Humanoid h in humanoid)
            //    //{
            //    //    h.onRemoteUpdate(Int32.Parse(dataSnap.Key), p);
            //    //};

            //    //try
            //    //{
            //    //    Dictionary<string, object> value = dataSnap.DictionaryValue;
            //    //    string x = value["x"].ToString();
            //    //    string y = value["y"].ToString();
            //    //    string z = value["z"].ToString();

            //    //    Debug.Log("Child ValueUpdated! " + dataSnap.Key + ", s " + dataSnap.DictionaryValue + ", x " + x + ", y " + y + ", z " + z);

            //    //    Vector3 p = new Vector3(float.Parse(x), float.Parse(y), float.Parse(z));
            //    //    foreach (Humanoid h in humanoid)
            //    //    {
            //    //        h.onRemoteUpdate(Int32.Parse(dataSnap.Key), p);
            //    //    };
            //    //}
            //    //catch (Exception exx) {
            //    //    Debug.Log(exx.ToString());
            //    //}
        };

        FireBase_battle_event.ChildChanged += (object sender, ChangedEventArgs e) => {
            //firebase.Child(enemyId.ToString()).ChildChanged += (object sender, ChangedEventArgs e) => {
            IDataSnapshot dataSnap = e.DataSnapshot;

            Logger.firebase("Child ChildChanged! " + sender + ", " + e + ", " + dataSnap.Key);

            //String x = dataSnap.Child("x").StringValue;
            //String y = dataSnap.Child("y").StringValue;
            //String z = dataSnap.Child("z").StringValue;

            //Debug.Log("Child ChildChanged! " + dataSnap.Key + ", " + x + ", " + y + ", " + z);

            //Vector3 p = new Vector3(float.Parse(x), float.Parse(y), float.Parse(z));
            //foreach (Humanoid h in humanoid)
            //{
            //    h.onRemoteUpdate(Int32.Parse(dataSnap.Key), p);
            //};

/*
 *          try
 *          {
 *              List<JsonBaseUnit> result = JsonBaseUnit.getFirebaseValue(dataSnap);
 *              foreach (Humanoid h in humanoid)
 *              {
 *                  foreach (JsonBaseUnit json in result)
 *                  {
 *                      h.onRemoteUpdate(json);
 *                  }
 *              }
 *          }
 *          catch (Exception ex)
 *          {
 *              Debug.Log(ex.ToString());
 *          }*/
        };

        //firebase.ChildChanged += (object sender, ChangedEventArgs e) => {
        //firebase.Child(playerId.ToString()).Child("attack").ChildChanged += (object sender, ChangedEventArgs e) => {
        //IDataSnapshot dataSnap = e.DataSnapshot;
        //if (debugFirebase)
        //    Debug.Log("attack ChildChanged! " + sender + ", " + e + ", " + dataSnap.Key);

        /*           try
         *         {
         *             List<JsonBaseAttack> result = JsonBaseAttack.getFirebaseValue(dataSnap);
         *             foreach (Humanoid h in humanoid)
         *             {
         *                 foreach (JsonBaseAttack json in result)
         *                 {
         *                     //h.onRemoteUpdate(json.getId(), json.getVector3());
         *                 }
         *             }
         *         }
         *         catch (Exception ex)
         *         {
         *             Debug.Log(ex.ToString());
         *         }*/
        //};

        FireBase_battle.SetValue("GameStart!");

        //Dictionary<string, object> value = new Dictionary<string, object>();
        //Dictionary<string, object> location = new Dictionary<string, object>();

        //location.Add("x", "9");
        //location.Add("y", "9");
        //location.Add("z", "999");
        //value.Add("action", "move");
        //value.Add("action_unit_id", "123");
        //value.Add("current_location", location);

        //firebase.Child("FightLog").Push().SetValue(value);

        //value.Add("target_location", location);
        //firebase.Child("FightLog").Push().SetValue(value);

        Debug.Log("GameController start-");
    }
Esempio n. 10
0
    private void getPlayer_Battle_EnemyId()
    {
        FireBase_battlelist = Firebase.CreateNew(FIRE_BASE_HOST + BATTLE_LIST);
        playerId            = System.Guid.NewGuid().ToString();
        //IFirebase FireBase_battle = FireBase_battlelist.Push();
        //battleId = FireBase_battle.Key;

        Logger.gameControl("getPlayer_Battle_EnemyId playerId {0}, battleId {1}", playerId, BATTLE_ID);
        FireBase_battlelist.ChildAdded += (object sender, ChangedEventArgs e) =>
        {
            IDataSnapshot dataSnap = e.DataSnapshot;
            Logger.gameControl("FireBase_battlelist ChildAdded {0}, {1}", dataSnap.Key, dataSnap.StringValue);
        };

        battlelistvalueUpdateEventHandler = (object sender, ChangedEventArgs e) =>
        {
            IDataSnapshot dataSnap = e.DataSnapshot;
            Logger.gameControl("FireBase_battlelist ValueUpdated {0}, {1}", dataSnap.Key, dataSnap.StringValue);
            try
            {
                Dictionary <string, object> dic = dataSnap.DictionaryValue;
                object temp         = null;
                bool   findBattleId = false;
                foreach (string battleId in dic.Keys)
                {
                    if (battleId.Contains("skip"))
                    {
                        continue;
                    }
                    //dic.TryGetValue(battleId, out temp);
                    string status = dataSnap.Child(battleId).Child(BATTLE_STATUS).StringValue;
                    Logger.gameControl("FireBase_battlelist ValueUpdated {0}, {1}", battleId, status);
                    if (BATTLE_STATUS_WAITING.Equals(status))
                    {
                        dataSnap.Child(battleId).Ref.Child(playerId).SetValue(playerId);
                        dataSnap.Child(battleId).Child(BATTLE_STATUS).Ref.SetValue(BATTLE_STATUS_FIGHTING);
                        BATTLE_ID    = battleId;
                        findBattleId = true;
                        break;
                    }
                    //Dictionary<string, object> battlevalue = (Dictionary<string, object>)temp;
                    //object temp2 = null;
                    //foreach (string battleinfo in battlevalue.Keys)
                    //{
                    //    if ("status".Equals(battleinfo))
                    //    {
                    //        battlevalue.TryGetValue(battleId, out temp2);
                    //    }
                    //}
                }

                if (!findBattleId)
                {
                    IFirebase ref_battle = FireBase_battlelist.Push();
                    BATTLE_ID = ref_battle.Key;
                    ref_battle.Child(playerId).SetValue(playerId);
                    ref_battle.Child(BATTLE_STATUS).SetValue(BATTLE_STATUS_WAITING);
                }

                FireBase_battlelist.ValueUpdated -= battlelistvalueUpdateEventHandler;
                getEnemyId();
            }
            catch (Exception ex)
            {
                Debug.Log(ex.Message);
            }
        };

        FireBase_battlelist.ValueUpdated += battlelistvalueUpdateEventHandler;

        FireBase_battlelist.ChildChanged += (object sender, ChangedEventArgs e) =>
        {
            IDataSnapshot dataSnap = e.DataSnapshot;
            Logger.gameControl("FireBase_battlelist ChildChanged {0}, {1}", dataSnap.Key, dataSnap.StringValue);
        };
    }
Esempio n. 11
0
 public static void UpdatePainting(Painting painting)
 {
     Data.Child(painting.ID).Update(JsonConvert.SerializeObject(painting));
 }
Esempio n. 12
0
 private void Update(string path, object value) =>
 Root.Child(path).Set(value, LogError);