コード例 #1
0
ファイル: Bear.cs プロジェクト: Geramy/GAnimalServer
        byte[] HTTP_OnResponse(string[] Commands, string[] Variables)
        {
            string RetData = "";

            try
            {
                //System.Threading.Thread.Sleep(1);
                Dictionary <string, string> POST = new Dictionary <string, string>();
                int i = 0;
                for (i = 0; i < Commands.Length; i++)
                {
                    POST.Add(Commands[i], Variables[i]);
                }

                //System.Threading.Thread.Sleep(5);

                #region MainComs
                //Command <type>
                //Value <data>
                if (POST["Command"] == "NewBear")
                {//string OwnerName, string OwnerKey, string Breed, string type, string Region, string Position, string Rotation
                    BearStorage __BS = new BearStorage(POST["OwnerName"], POST["OwnerKey"], POST["Breed"], POST["type"], POST["Region"], POST["Position"], POST["Rotation"]);
                    BSUUID.Add(__BS.BearUUID.UUIDs, new BearStats(__BS, Status_time));
                    RetData = __BS.BearUUID.UUIDs;
                }
                else if (POST["Command"] == "DeleteBear")
                {
                    BSUUID[Regex.Replace(POST["UUID"], @"\s", "")].Stop();
                    SQL.DeleteBear(new UUID(Regex.Replace(POST["UUID"], @"\s", "")));
                    BSUUID.Remove(Regex.Replace(POST["UUID"], @"\s", ""));
                    RetData = "DELETED";
                }

                else if (POST["Command"] == "GetBears")
                {
                    RetData = "";
                    List <UUID> Uid = SQL.GetBears(POST["OwnerName"]);
                    foreach (UUID id in Uid)
                    {
                        RetData += id.UUIDs + "~";
                    }
                }

                else if (POST["Command"] == "StopBear")
                {
                    string key = Regex.Replace(POST["UUID"], @"\s", "");
                    if (BSUUID.ContainsKey(key))
                    {
                        RetData = (new BearStorage(new UUID(key)).Status == BearStorage.Stat.Online ? "Stopped" : "AlreadyStopped");
                        string var = (new BearStorage(new UUID(key)).Status == BearStorage.Stat.Online ? BSUUID[key].Stop() : "");
                    }
                    else
                    {
                        ActiveBears.Remove(key);
                        BSUUID[key].Stop();
                        BSUUID.Remove(key);
                        RetData = "NotStarted";
                    }
                }
                else if (POST["Command"] == "StartBear")
                {
                    string key = Regex.Replace(POST["UUID"], @"\s", "");
                    if (BSUUID.ContainsKey(key))
                    {
                        RetData = (new BearStorage(new UUID(key)).Status == BearStorage.Stat.Online ? "AlreadyStarted" : "Started");
                        string var = (new BearStorage(new UUID(key)).Status == BearStorage.Stat.Online ? "" : BSUUID[key].Start());
                    }
                    else
                    {
                        ActiveBears.Add(Regex.Replace(POST["UUID"], @"\s", ""), new BearStorage(new UUID(Regex.Replace(POST["UUID"], @"\s", ""))));
                        BSUUID.Add(key, new BearStats(ActiveBears[key], 5));
                        //BSUUID[key].Start();
                        RetData = "NewInstance";
                    }
                }
                #endregion
                #region BearStorage_GET_Coms
                else if (POST["Command"] == "GetHealth")
                {
                    BearCheck(new UUID(Regex.Replace(POST["UUID"], @"\s", "")));
                    RetData = BSUUID[Regex.Replace(POST["UUID"], @"\s", "")]._BS.Health;
                }
                else if (POST["Command"] == "GetHunger")
                {
                    BearCheck(new UUID(Regex.Replace(POST["UUID"], @"\s", "")));
                    RetData = BSUUID[Regex.Replace(POST["UUID"], @"\s", "")]._BS.Hunger;
                }
                else if (POST["Command"] == "GetThirst")
                {
                    BearCheck(new UUID(Regex.Replace(POST["UUID"], @"\s", "")));
                    RetData = BSUUID[Regex.Replace(POST["UUID"], @"\s", "")]._BS.Thirst;
                }
                else if (POST["Command"] == "GetFun")
                {
                    BearCheck(new UUID(Regex.Replace(POST["UUID"], @"\s", "")));
                    RetData = BSUUID[Regex.Replace(POST["UUID"], @"\s", "")]._BS.Fun;
                }
                else if (POST["Command"] == "GetDepression")
                {
                    BearCheck(new UUID(Regex.Replace(POST["UUID"], @"\s", "")));
                    RetData = BSUUID[Regex.Replace(POST["UUID"], @"\s", "")]._BS.Depression;
                }
                else if (POST["Command"] == "GetName")
                {
                    BearCheck(new UUID(Regex.Replace(POST["UUID"], @"\s", "")));
                    RetData = BSUUID[Regex.Replace(POST["UUID"], @"\s", "")]._BS.Name;
                }
                else if (POST["Command"] == "GetAge")
                {
                    BearCheck(new UUID(Regex.Replace(POST["UUID"], @"\s", "")));
                    RetData = BSUUID[Regex.Replace(POST["UUID"], @"\s", "")]._BS.Age;
                }
                else if (POST["Command"] == "GetGender")
                {
                    BearCheck(new UUID(Regex.Replace(POST["UUID"], @"\s", "")));
                    RetData = BSUUID[Regex.Replace(POST["UUID"], @"\s", "")]._BS.Gender;
                }
                else if (POST["Command"] == "GetRegion")
                {
                    BearCheck(new UUID(Regex.Replace(POST["UUID"], @"\s", "")));
                    RetData = BSUUID[Regex.Replace(POST["UUID"], @"\s", "")]._BS.Region;
                }
                else if (POST["Command"] == "GetPosition")
                {
                    BearCheck(new UUID(Regex.Replace(POST["UUID"], @"\s", "")));
                    RetData = BSUUID[Regex.Replace(POST["UUID"], @"\s", "")]._BS.Position.Vector;
                }
                else if (POST["Command"] == "GetRotation")
                {
                    BearCheck(new UUID(Regex.Replace(POST["UUID"], @"\s", "")));
                    RetData = BSUUID[Regex.Replace(POST["UUID"], @"\s", "")]._BS.Rotation;
                }
                else if (POST["Command"] == "GetOwnerName")
                {
                    BearCheck(new UUID(Regex.Replace(POST["UUID"], @"\s", "")));
                    RetData = SQL.GetOwnerName(new UUID(Regex.Replace(POST["UUID"], @"\s", "")));
                }
                else if (POST["Command"] == "GetOwnerKey")
                {
                    BearCheck(new UUID(Regex.Replace(POST["UUID"], @"\s", "")));
                    RetData = SQL.GetOwnerKey(new UUID(Regex.Replace(POST["UUID"], @"\s", "")));
                }
                else if (POST["Command"] == "GetBears")
                {
                    foreach (UUID Uid in SQL.GetBears(POST["OwnerName"]))
                    {
                        RetData += Uid.UUIDs + "~";
                    }
                }
                #endregion
                #region BearStorage_SET_Coms
                else if (POST["Command"] == "SetHealth")
                {
                    RetData = BSUUID[Regex.Replace(POST["UUID"], @"\s", "")]._BS.Health = POST["Health"];
                }
                else if (POST["Command"] == "SetHunger")
                {
                    RetData = BSUUID[Regex.Replace(POST["UUID"], @"\s", "")]._BS.Hunger = POST["Hunger"];
                }
                else if (POST["Command"] == "SetThirst")
                {
                    RetData = BSUUID[Regex.Replace(POST["UUID"], @"\s", "")]._BS.Thirst = POST["Thirst"];
                }
                else if (POST["Command"] == "SetFun")
                {
                    RetData = BSUUID[Regex.Replace(POST["UUID"], @"\s", "")]._BS.Fun = POST["Fun"];
                }
                else if (POST["Command"] == "SetDepression")
                {
                    RetData = BSUUID[Regex.Replace(POST["UUID"], @"\s", "")]._BS.Depression = POST["Depression"];
                }
                else if (POST["Command"] == "SetName")
                {
                    RetData = BSUUID[Regex.Replace(POST["UUID"], @"\s", "")]._BS.Name = POST["Name"];
                }
                else if (POST["Command"] == "SetGender")
                {
                    RetData = BSUUID[Regex.Replace(POST["UUID"], @"\s", "")]._BS.Gender = POST["Gender"];;
                }
                else if (POST["Command"] == "SetAge")
                {
                    RetData = BSUUID[Regex.Replace(POST["UUID"], @"\s", "")]._BS.Age = POST["Age"];
                }

                else if (POST["Command"] == "SetRegion")
                {
                    RetData = BSUUID[Regex.Replace(POST["UUID"], @"\s", "")]._BS.Region = POST["Region"];
                }
                else if (POST["Command"] == "SetPosition")
                {
                    BSUUID[Regex.Replace(POST["UUID"], @"\s", "")]._BS.Position = new Vector3D(POST["Position"]);
                    RetData = BSUUID[Regex.Replace(POST["UUID"], @"\s", "")]._BS.Position.Vector;
                }
                else if (POST["Command"] == "SetRotation")
                {
                    BSUUID[Regex.Replace(POST["UUID"], @"\s", "")]._BS.Rotation = POST["Rotation"];
                    RetData = BSUUID[Regex.Replace(POST["UUID"], @"\s", "")]._BS.Rotation;
                }

                else if (POST["Command"] == "SetOwnerName")
                {
                    SQL.SetOwnerName(new UUID(Regex.Replace(POST["UUID"], @"\s", "")), POST["OwnerName"]);
                    RetData = SQL.GetOwnerName(new UUID(Regex.Replace(POST["UUID"], @"\s", "")));
                }
                else if (POST["Command"] == "SetOwnerKey")
                {
                    SQL.SetOwnerKey(new UUID(Regex.Replace(POST["UUID"], @"\s", "")), POST["OwnerKey"]);
                    RetData = SQL.GetOwnerKey(new UUID(Regex.Replace(POST["UUID"], @"\s", "")));
                }
                #endregion
                #region StorageType
                else if (POST["Command"] == "NewStorageType")
                {
                    StorageType ST = new StorageType(POST["OwnerName"], POST["OwnerKey"], POST["StorageType"], POST["amount"], POST["Loss"]);
                    RetData = ST.sID.UUIDs;
                }
                else if (POST["Command"] == "DeleteStorageType")
                {
                    SQL.DeleteStorageUnit(new UUID(Regex.Replace(POST["UUID"], @"\s", "")));
                    RetData = "DELETED";
                }
                else if (POST["Command"] == "GetAmount")
                {
                    RetData = SQL.GetAmount(new UUID(Regex.Replace(POST["UUID"], @"\s", "")));
                }
                else if (POST["Command"] == "SetAmount")
                {
                    SQL.SetAmount(new UUID(Regex.Replace(POST["UUID"], @"\s", "")), POST["Amount"]);
                    RetData = SQL.GetAmount(new UUID(Regex.Replace(POST["UUID"], @"\s", "")));
                }
                #endregion
            }
            catch (Exception e)
            {
                //SQL.CloseConnection(ref SQL);
                RetData = e.Message;
                Console.WriteLine("An Error Occured " + e.Message);
            }
            //System.Threading.Thread.Sleep(5);
            return(ASCIIEncoding.ASCII.GetBytes(RetData));
        }
コード例 #2
0
ファイル: BearStats.cs プロジェクト: Geramy/GAnimalServer
 void ProcessThread_Elapsed(object sender)
 {
     try
     {
         BearStorage N_BS = new BearStorage(new UUID((string)sender));
         if (DateTime.Today.Day != dt && DateTime.Today.Day < dt || DateTime.Today.Day > dt)
         {
             dt = DateTime.Today.Day;
             N_BS.Age = Convert.ToString((Convert.ToInt32(N_BS.Age) + 1));
         }
         List<UUID> Temp = SQL.GetStorageUnits(SQL.GetOwnerName(N_BS.BearUUID));
         List<StorageType> temp = new List<StorageType>();
         _ST.Clear();
         foreach (UUID Uid in Temp)
         {
             StorageType ST = new StorageType(Uid);
             if (Convert.ToInt32(ST.Amount) <= 0) SQL.DeleteStorageUnit(Uid);
             else
                 _ST.Add(ST);
         }
         int i = 0;
         foreach (StorageType st in _ST)
         {
             if (st.SType.ToLower() == "fun" && Convert.ToInt32(st.Amount) > 0) fun = i;
             if (st.SType.ToLower() == "hunger" && Convert.ToInt32(st.Amount) > 0) hunger = i;
             if (st.SType.ToLower() == "thirst" && Convert.ToInt32(st.Amount) > 0) thirst = i;
             i++;
         }
         //if (Convert.ToInt32(_ST[fun].Amount) < 0 && run_throughs == 0.0f || Convert.ToInt32(_ST[hunger].Amount) < 0 && run_throughs == 0.5f || Convert.ToInt32(_ST[thirst].Amount) < 0 && run_throughs == 1.0f) return;
         Random r = new Random();
         System.Threading.Thread.Sleep(r.Next(0, 10));
         Console.WriteLine(N_BS.BearUUID.UUIDs + "Time:" + (run_throughs == 0.0f ? "Fun" : run_throughs == 0.05f ? "Hunger" : "Thirst"));
         if (run_throughs == 0.0f)//fun
         {
             if (fun != -1)
             {
                 if (Convert.ToInt32(N_BS.Fun) + 2 <= 100 && Convert.ToInt32(_ST[fun].Amount) > 0)
                 {
                     N_BS.Fun = Convert.ToString(Convert.ToInt32(N_BS.Fun) + 2);
                     _ST[fun].Amount = Convert.ToString(Convert.ToInt32(_ST[fun].Amount) - Convert.ToInt32(_ST[fun].Loss));
                 }
                 else if (Convert.ToInt32(N_BS.Fun) + 2 <= 100 && Convert.ToInt32(_ST[fun].Amount) < 0)
                 {
                     N_BS.Fun = Convert.ToString(Convert.ToInt32(N_BS.Fun) - 2);
                 }
                 else if (Convert.ToInt32(N_BS.Fun) <= 0)
                 {//Gain Depression
                     if (Convert.ToInt32(N_BS.Depression) + 2 <= 100)
                     {
                         N_BS.Depression = Convert.ToString(Convert.ToInt32(N_BS.Depression) + 2);
                     }
                     else if (Convert.ToInt32(N_BS.Depression) <= 100 && Convert.ToInt32(N_BS.Health) - 2 >= 0)
                     {
                         N_BS.Health = Convert.ToString(Convert.ToInt32(N_BS.Health) - 2);
                     }
                 }
                 if (Convert.ToInt32(N_BS.Fun) - 1 >= 0)
                 {
                     N_BS.Fun = Convert.ToString(Convert.ToInt32(N_BS.Fun) - 1);
                 }
             }
             else
             {
                 if (Convert.ToInt32(N_BS.Fun) <= 100 && Convert.ToInt32(N_BS.Fun) > 0)
                 {
                     N_BS.Fun = Convert.ToString(Convert.ToInt32(N_BS.Fun) - 2);
                 }
                 else if (Convert.ToInt32(N_BS.Fun) <= 0)
                 {//Gain Depression
                     if (Convert.ToInt32(N_BS.Depression) + 2 <= 100)
                     {
                         N_BS.Depression = Convert.ToString(Convert.ToInt32(N_BS.Depression) + 2);
                     }
                     else if (Convert.ToInt32(N_BS.Depression) >= 100 && Convert.ToInt32(N_BS.Health) > 0)
                     {
                         N_BS.Health = Convert.ToString(Convert.ToInt32(N_BS.Health) - 2);
                     }
                 }
                 if (Convert.ToInt32(N_BS.Fun) > 0)
                 {
                     N_BS.Fun = Convert.ToString(Convert.ToInt32(N_BS.Fun) - 1);
                 }
             }
             run_throughs += 0.5f;
         }
         else if (run_throughs == 0.5f)//hunger
         {
             if (hunger != -1)
             {
                 if (Convert.ToInt32(N_BS.Hunger) + 2 <= 100 && Convert.ToInt32(_ST[hunger].Amount) > 0)
                 {
                     N_BS.Hunger = Convert.ToString(Convert.ToInt32(N_BS.Hunger) + 2);
                     _ST[hunger].Amount = Convert.ToString(Convert.ToInt32(_ST[hunger].Amount) - Convert.ToInt32(_ST[hunger].Loss));
                 }
                 else if (Convert.ToInt32(N_BS.Hunger) + 2 <= 100 && Convert.ToInt32(_ST[hunger].Amount) < 0)
                 {
                     N_BS.Hunger = Convert.ToString(Convert.ToInt32(N_BS.Hunger) - 2);
                 }
                 else if (Convert.ToInt32(N_BS.Hunger) <= 0)
                 {//Gain Depression
                     if (Convert.ToInt32(N_BS.Depression) + 2 <= 100)
                     {
                         N_BS.Depression = Convert.ToString(Convert.ToInt32(N_BS.Depression) + 2);
                     }
                     else if (Convert.ToInt32(N_BS.Depression) <= 100 && Convert.ToInt32(N_BS.Health) - 2 >= 0)
                     {
                         N_BS.Health = Convert.ToString(Convert.ToInt32(N_BS.Health) - 2);
                     }
                 }
                 if (Convert.ToInt32(N_BS.Hunger) - 1 >= 0)
                 {
                     N_BS.Hunger = Convert.ToString(Convert.ToInt32(N_BS.Hunger) - 1);
                 }
             }
             else
             {
                 if (Convert.ToInt32(N_BS.Hunger) <= 100 && Convert.ToInt32(N_BS.Hunger) > 0)
                 {
                     N_BS.Hunger = Convert.ToString(Convert.ToInt32(N_BS.Hunger) - 2);
                 }
                 else if (Convert.ToInt32(N_BS.Hunger) <= 0)
                 {//Gain Depression
                     if (Convert.ToInt32(N_BS.Depression) + 2 <= 100)
                     {
                         N_BS.Depression = Convert.ToString(Convert.ToInt32(N_BS.Depression) + 2);
                     }
                     else if (Convert.ToInt32(N_BS.Depression) >= 100 && Convert.ToInt32(N_BS.Health) > 0)
                     {
                         N_BS.Health = Convert.ToString(Convert.ToInt32(N_BS.Health) - 2);
                     }
                 }
                 if (Convert.ToInt32(N_BS.Hunger) > 0)
                 {
                     N_BS.Hunger = Convert.ToString(Convert.ToInt32(N_BS.Hunger) - 1);
                 }
             }
             run_throughs += 0.5f;
         }
         else if (run_throughs == 1.0f)//thirst
         {
             if (thirst != -1)
             {
                 if (Convert.ToInt32(N_BS.Thirst) + 2 <= 100 && Convert.ToInt32(_ST[thirst].Amount) > 0)
                 {
                     N_BS.Thirst = Convert.ToString(Convert.ToInt32(N_BS.Thirst) + 2);
                     _ST[thirst].Amount = Convert.ToString(Convert.ToInt32(_ST[thirst].Amount) - Convert.ToInt32(_ST[thirst].Loss));
                 }
                 else if (Convert.ToInt32(N_BS.Thirst) + 2 <= 100 && Convert.ToInt32(_ST[thirst].Amount) < 0)
                 {
                     N_BS.Thirst = Convert.ToString(Convert.ToInt32(N_BS.Thirst) - 2);
                 }
                 else if (Convert.ToInt32(N_BS.Thirst) <= 0)
                 {//Gain Depression
                     if (Convert.ToInt32(N_BS.Depression) + 2 <= 100)
                     {
                         N_BS.Depression = Convert.ToString(Convert.ToInt32(N_BS.Depression) + 2);
                     }
                     else if (Convert.ToInt32(N_BS.Depression) <= 100 && Convert.ToInt32(N_BS.Health) - 2 >= 0)
                     {
                         N_BS.Health = Convert.ToString(Convert.ToInt32(N_BS.Health) - 2);
                     }
                 }
                 if (Convert.ToInt32(N_BS.Thirst) - 1 >= 0)
                 {
                     N_BS.Thirst = Convert.ToString(Convert.ToInt32(N_BS.Thirst) - 1);
                 }
             }
             else
             {
                 if (Convert.ToInt32(N_BS.Thirst) <= 100 && Convert.ToInt32(N_BS.Thirst) > 0)
                 {
                     N_BS.Thirst = Convert.ToString(Convert.ToInt32(N_BS.Thirst) - 2);
                 }
                 else if (Convert.ToInt32(N_BS.Thirst) <= 0)
                 {//Gain Depression
                     if (Convert.ToInt32(N_BS.Depression) + 2 <= 100)
                     {
                         N_BS.Depression = Convert.ToString(Convert.ToInt32(N_BS.Depression) + 2);
                     }
                     else if (Convert.ToInt32(N_BS.Depression) >= 100 && Convert.ToInt32(N_BS.Health) > 0)
                     {
                         N_BS.Health = Convert.ToString(Convert.ToInt32(N_BS.Health) - 2);
                     }
                 }
                 if (Convert.ToInt32(N_BS.Thirst) > 0)
                 {
                     N_BS.Thirst = Convert.ToString(Convert.ToInt32(N_BS.Thirst) - 1);
                 }
             }
             run_throughs = 0.0f;
         }
         //_ST.Clear();
     }
     catch (Exception e)
     {
         Console.WriteLine(e.Data + " " + e.InnerException + " " + e.Source + " " + e.Message);
     }
 }
コード例 #3
0
ファイル: Bear.cs プロジェクト: Geramy/GAnimalServer
        byte[] HTTP_OnResponse(string[] Commands, string[] Variables)
        {
            string RetData = "";
            try
            {
            //System.Threading.Thread.Sleep(1);
                Dictionary<string, string> POST = new Dictionary<string, string>();
                int i = 0;
                for (i = 0; i < Commands.Length; i++)
                {
                    POST.Add(Commands[i], Variables[i]);
                }

                //System.Threading.Thread.Sleep(5);

                #region MainComs
                //Command <type>
                //Value <data>
                if (POST["Command"] == "NewBear")
                {//string OwnerName, string OwnerKey, string Breed, string type, string Region, string Position, string Rotation
                    BearStorage __BS = new BearStorage(POST["OwnerName"], POST["OwnerKey"], POST["Breed"], POST["type"], POST["Region"], POST["Position"], POST["Rotation"]);
                    BSUUID.Add(__BS.BearUUID.UUIDs, new BearStats(__BS, Status_time));
                    RetData = __BS.BearUUID.UUIDs;
                }
                else if (POST["Command"] == "DeleteBear")
                {
                    BSUUID[Regex.Replace(POST["UUID"], @"\s", "" )].Stop();
                    SQL.DeleteBear(new UUID(Regex.Replace(POST["UUID"], @"\s", "" )));
                    BSUUID.Remove(Regex.Replace(POST["UUID"], @"\s", "" ));
                    RetData = "DELETED";
                }

                else if (POST["Command"] == "GetBears")
                {
                    RetData = "";
                    List<UUID> Uid = SQL.GetBears(POST["OwnerName"]);
                    foreach (UUID id in Uid)
                    {
                        RetData += id.UUIDs + "~";
                    }
                }

                else if (POST["Command"] == "StopBear")
                {
                    string key = Regex.Replace(POST["UUID"], @"\s", "");
                    if (BSUUID.ContainsKey(key))
                    {

                        RetData = (new BearStorage(new UUID(key)).Status == BearStorage.Stat.Online ? "Stopped" : "AlreadyStopped");
                        string var = (new BearStorage(new UUID(key)).Status == BearStorage.Stat.Online ? BSUUID[key].Stop() : "");
                    }
                    else
                    {
                        ActiveBears.Remove(key);
                        BSUUID[key].Stop();
                        BSUUID.Remove(key);
                        RetData = "NotStarted";
                    }

                }
                else if (POST["Command"] == "StartBear")
                {
                    string key = Regex.Replace(POST["UUID"], @"\s", "");
                    if (BSUUID.ContainsKey(key))
                    {
                        RetData = (new BearStorage(new UUID(key)).Status == BearStorage.Stat.Online ? "AlreadyStarted" : "Started");
                        string var = (new BearStorage(new UUID(key)).Status == BearStorage.Stat.Online ? "" : BSUUID[key].Start());

                    }
                    else
                    {
                        ActiveBears.Add(Regex.Replace(POST["UUID"], @"\s", ""), new BearStorage(new UUID(Regex.Replace(POST["UUID"], @"\s", ""))));
                        BSUUID.Add(key, new BearStats(ActiveBears[key], 5));
                        //BSUUID[key].Start();
                        RetData = "NewInstance";
                    }
                }
                #endregion
                #region BearStorage_GET_Coms
                else if (POST["Command"] == "GetHealth")
                {
                    BearCheck(new UUID(Regex.Replace(POST["UUID"], @"\s", "")));
                    RetData = BSUUID[Regex.Replace(POST["UUID"], @"\s", "")]._BS.Health;
                }
                else if (POST["Command"] == "GetHunger")
                {
                    BearCheck(new UUID(Regex.Replace(POST["UUID"], @"\s", "")));
                    RetData = BSUUID[Regex.Replace(POST["UUID"], @"\s", "")]._BS.Hunger;
                }
                else if (POST["Command"] == "GetThirst")
                {
                    BearCheck(new UUID(Regex.Replace(POST["UUID"], @"\s", "")));
                    RetData = BSUUID[Regex.Replace(POST["UUID"], @"\s", "")]._BS.Thirst;
                }
                else if (POST["Command"] == "GetFun")
                {
                    BearCheck(new UUID(Regex.Replace(POST["UUID"], @"\s", "")));
                    RetData = BSUUID[Regex.Replace(POST["UUID"], @"\s", "")]._BS.Fun;
                }
                else if (POST["Command"] == "GetDepression")
                {
                    BearCheck(new UUID(Regex.Replace(POST["UUID"], @"\s", "")));
                    RetData = BSUUID[Regex.Replace(POST["UUID"], @"\s", "")]._BS.Depression;
                }
                else if (POST["Command"] == "GetName")
                {
                    BearCheck(new UUID(Regex.Replace(POST["UUID"], @"\s", "")));
                    RetData = BSUUID[Regex.Replace(POST["UUID"], @"\s", "")]._BS.Name;
                }
                else if (POST["Command"] == "GetAge")
                {
                    BearCheck(new UUID(Regex.Replace(POST["UUID"], @"\s", "")));
                    RetData = BSUUID[Regex.Replace(POST["UUID"], @"\s", "")]._BS.Age;
                }
                else if (POST["Command"] == "GetGender")
                {
                    BearCheck(new UUID(Regex.Replace(POST["UUID"], @"\s", "")));
                    RetData = BSUUID[Regex.Replace(POST["UUID"], @"\s", "")]._BS.Gender;
                }
                else if (POST["Command"] == "GetRegion")
                {
                    BearCheck(new UUID(Regex.Replace(POST["UUID"], @"\s", "")));
                    RetData = BSUUID[Regex.Replace(POST["UUID"], @"\s", "")]._BS.Region;
                }
                else if (POST["Command"] == "GetPosition")
                {
                    BearCheck(new UUID(Regex.Replace(POST["UUID"], @"\s", "")));
                    RetData = BSUUID[Regex.Replace(POST["UUID"], @"\s", "")]._BS.Position.Vector;
                }
                else if (POST["Command"] == "GetRotation")
                {
                    BearCheck(new UUID(Regex.Replace(POST["UUID"], @"\s", "")));
                    RetData = BSUUID[Regex.Replace(POST["UUID"], @"\s", "")]._BS.Rotation;
                }
                else if (POST["Command"] == "GetOwnerName")
                {
                    BearCheck(new UUID(Regex.Replace(POST["UUID"], @"\s", "")));
                    RetData = SQL.GetOwnerName(new UUID(Regex.Replace(POST["UUID"], @"\s", "")));
                }
                else if (POST["Command"] == "GetOwnerKey")
                {
                    BearCheck(new UUID(Regex.Replace(POST["UUID"], @"\s", "")));
                    RetData = SQL.GetOwnerKey(new UUID(Regex.Replace(POST["UUID"], @"\s", "")));
                }
                else if (POST["Command"] == "GetBears")
                {
                    foreach (UUID Uid in SQL.GetBears(POST["OwnerName"])) { RetData += Uid.UUIDs + "~"; }
                }
                #endregion
                #region BearStorage_SET_Coms
                else if (POST["Command"] == "SetHealth")
                {
                    RetData = BSUUID[Regex.Replace(POST["UUID"], @"\s", "")]._BS.Health = POST["Health"];
                }
                else if (POST["Command"] == "SetHunger")
                {
                    RetData = BSUUID[Regex.Replace(POST["UUID"], @"\s", "")]._BS.Hunger = POST["Hunger"];
                }
                else if (POST["Command"] == "SetThirst")
                {
                    RetData = BSUUID[Regex.Replace(POST["UUID"], @"\s", "")]._BS.Thirst = POST["Thirst"];
                }
                else if (POST["Command"] == "SetFun")
                {
                    RetData = BSUUID[Regex.Replace(POST["UUID"], @"\s", "")]._BS.Fun = POST["Fun"];
                }
                else if (POST["Command"] == "SetDepression")
                {
                    RetData = BSUUID[Regex.Replace(POST["UUID"], @"\s", "")]._BS.Depression = POST["Depression"];
                }
                else if (POST["Command"] == "SetName")
                {
                    RetData = BSUUID[Regex.Replace(POST["UUID"], @"\s", "")]._BS.Name = POST["Name"];
                }
                else if (POST["Command"] == "SetGender")
                {
                    RetData = BSUUID[Regex.Replace(POST["UUID"], @"\s", "")]._BS.Gender = POST["Gender"]; ;
                }
                else if (POST["Command"] == "SetAge")
                {
                    RetData = BSUUID[Regex.Replace(POST["UUID"], @"\s", "")]._BS.Age = POST["Age"];
                }

                else if (POST["Command"] == "SetRegion")
                {
                    RetData = BSUUID[Regex.Replace(POST["UUID"], @"\s", "")]._BS.Region = POST["Region"];
                }
                else if (POST["Command"] == "SetPosition")
                {
                    BSUUID[Regex.Replace(POST["UUID"], @"\s", "")]._BS.Position = new Vector3D(POST["Position"]);
                    RetData = BSUUID[Regex.Replace(POST["UUID"], @"\s", "")]._BS.Position.Vector;
                }
                else if (POST["Command"] == "SetRotation")
                {
                    BSUUID[Regex.Replace(POST["UUID"], @"\s", "")]._BS.Rotation = POST["Rotation"];
                    RetData = BSUUID[Regex.Replace(POST["UUID"], @"\s", "")]._BS.Rotation;
                }

                else if (POST["Command"] == "SetOwnerName")
                {
                    SQL.SetOwnerName(new UUID(Regex.Replace(POST["UUID"], @"\s", "")), POST["OwnerName"]);
                    RetData = SQL.GetOwnerName(new UUID(Regex.Replace(POST["UUID"], @"\s", "")));
                }
                else if (POST["Command"] == "SetOwnerKey")
                {
                    SQL.SetOwnerKey(new UUID(Regex.Replace(POST["UUID"], @"\s", "")), POST["OwnerKey"]);
                    RetData = SQL.GetOwnerKey(new UUID(Regex.Replace(POST["UUID"], @"\s", "")));
                }
                #endregion
                #region StorageType
                else if (POST["Command"] == "NewStorageType")
                {
                    StorageType ST = new StorageType(POST["OwnerName"], POST["OwnerKey"], POST["StorageType"], POST["amount"], POST["Loss"]);
                    RetData = ST.sID.UUIDs;
                }
                else if (POST["Command"] == "DeleteStorageType")
                {
                    SQL.DeleteStorageUnit(new UUID(Regex.Replace(POST["UUID"], @"\s", "")));
                    RetData = "DELETED";
                }
                else if (POST["Command"] == "GetAmount")
                {
                    RetData = SQL.GetAmount(new UUID(Regex.Replace(POST["UUID"], @"\s", "")));
                }
                else if (POST["Command"] == "SetAmount")
                {
                    SQL.SetAmount(new UUID(Regex.Replace(POST["UUID"], @"\s", "")), POST["Amount"]);
                    RetData = SQL.GetAmount(new UUID(Regex.Replace(POST["UUID"], @"\s", "")));
                }
                #endregion
            }
            catch (Exception e)
            {
                //SQL.CloseConnection(ref SQL);
                RetData = e.Message;
                Console.WriteLine("An Error Occured " + e.Message);
            }
            //System.Threading.Thread.Sleep(5);
            return ASCIIEncoding.ASCII.GetBytes(RetData);
        }
コード例 #4
0
ファイル: BearStats.cs プロジェクト: Geramy/GAnimalServer
 void ProcessThread_Elapsed(object sender)
 {
     try
     {
         BearStorage N_BS = new BearStorage(new UUID((string)sender));
         if (DateTime.Today.Day != dt && DateTime.Today.Day < dt || DateTime.Today.Day > dt)
         {
             dt       = DateTime.Today.Day;
             N_BS.Age = Convert.ToString((Convert.ToInt32(N_BS.Age) + 1));
         }
         List <UUID>        Temp = SQL.GetStorageUnits(SQL.GetOwnerName(N_BS.BearUUID));
         List <StorageType> temp = new List <StorageType>();
         _ST.Clear();
         foreach (UUID Uid in Temp)
         {
             StorageType ST = new StorageType(Uid);
             if (Convert.ToInt32(ST.Amount) <= 0)
             {
                 SQL.DeleteStorageUnit(Uid);
             }
             else
             {
                 _ST.Add(ST);
             }
         }
         int i = 0;
         foreach (StorageType st in _ST)
         {
             if (st.SType.ToLower() == "fun" && Convert.ToInt32(st.Amount) > 0)
             {
                 fun = i;
             }
             if (st.SType.ToLower() == "hunger" && Convert.ToInt32(st.Amount) > 0)
             {
                 hunger = i;
             }
             if (st.SType.ToLower() == "thirst" && Convert.ToInt32(st.Amount) > 0)
             {
                 thirst = i;
             }
             i++;
         }
         //if (Convert.ToInt32(_ST[fun].Amount) < 0 && run_throughs == 0.0f || Convert.ToInt32(_ST[hunger].Amount) < 0 && run_throughs == 0.5f || Convert.ToInt32(_ST[thirst].Amount) < 0 && run_throughs == 1.0f) return;
         Random r = new Random();
         System.Threading.Thread.Sleep(r.Next(0, 10));
         Console.WriteLine(N_BS.BearUUID.UUIDs + "Time:" + (run_throughs == 0.0f ? "Fun" : run_throughs == 0.05f ? "Hunger" : "Thirst"));
         if (run_throughs == 0.0f)//fun
         {
             if (fun != -1)
             {
                 if (Convert.ToInt32(N_BS.Fun) + 2 <= 100 && Convert.ToInt32(_ST[fun].Amount) > 0)
                 {
                     N_BS.Fun        = Convert.ToString(Convert.ToInt32(N_BS.Fun) + 2);
                     _ST[fun].Amount = Convert.ToString(Convert.ToInt32(_ST[fun].Amount) - Convert.ToInt32(_ST[fun].Loss));
                 }
                 else if (Convert.ToInt32(N_BS.Fun) + 2 <= 100 && Convert.ToInt32(_ST[fun].Amount) < 0)
                 {
                     N_BS.Fun = Convert.ToString(Convert.ToInt32(N_BS.Fun) - 2);
                 }
                 else if (Convert.ToInt32(N_BS.Fun) <= 0)
                 {//Gain Depression
                     if (Convert.ToInt32(N_BS.Depression) + 2 <= 100)
                     {
                         N_BS.Depression = Convert.ToString(Convert.ToInt32(N_BS.Depression) + 2);
                     }
                     else if (Convert.ToInt32(N_BS.Depression) <= 100 && Convert.ToInt32(N_BS.Health) - 2 >= 0)
                     {
                         N_BS.Health = Convert.ToString(Convert.ToInt32(N_BS.Health) - 2);
                     }
                 }
                 if (Convert.ToInt32(N_BS.Fun) - 1 >= 0)
                 {
                     N_BS.Fun = Convert.ToString(Convert.ToInt32(N_BS.Fun) - 1);
                 }
             }
             else
             {
                 if (Convert.ToInt32(N_BS.Fun) <= 100 && Convert.ToInt32(N_BS.Fun) > 0)
                 {
                     N_BS.Fun = Convert.ToString(Convert.ToInt32(N_BS.Fun) - 2);
                 }
                 else if (Convert.ToInt32(N_BS.Fun) <= 0)
                 {//Gain Depression
                     if (Convert.ToInt32(N_BS.Depression) + 2 <= 100)
                     {
                         N_BS.Depression = Convert.ToString(Convert.ToInt32(N_BS.Depression) + 2);
                     }
                     else if (Convert.ToInt32(N_BS.Depression) >= 100 && Convert.ToInt32(N_BS.Health) > 0)
                     {
                         N_BS.Health = Convert.ToString(Convert.ToInt32(N_BS.Health) - 2);
                     }
                 }
                 if (Convert.ToInt32(N_BS.Fun) > 0)
                 {
                     N_BS.Fun = Convert.ToString(Convert.ToInt32(N_BS.Fun) - 1);
                 }
             }
             run_throughs += 0.5f;
         }
         else if (run_throughs == 0.5f)//hunger
         {
             if (hunger != -1)
             {
                 if (Convert.ToInt32(N_BS.Hunger) + 2 <= 100 && Convert.ToInt32(_ST[hunger].Amount) > 0)
                 {
                     N_BS.Hunger        = Convert.ToString(Convert.ToInt32(N_BS.Hunger) + 2);
                     _ST[hunger].Amount = Convert.ToString(Convert.ToInt32(_ST[hunger].Amount) - Convert.ToInt32(_ST[hunger].Loss));
                 }
                 else if (Convert.ToInt32(N_BS.Hunger) + 2 <= 100 && Convert.ToInt32(_ST[hunger].Amount) < 0)
                 {
                     N_BS.Hunger = Convert.ToString(Convert.ToInt32(N_BS.Hunger) - 2);
                 }
                 else if (Convert.ToInt32(N_BS.Hunger) <= 0)
                 {//Gain Depression
                     if (Convert.ToInt32(N_BS.Depression) + 2 <= 100)
                     {
                         N_BS.Depression = Convert.ToString(Convert.ToInt32(N_BS.Depression) + 2);
                     }
                     else if (Convert.ToInt32(N_BS.Depression) <= 100 && Convert.ToInt32(N_BS.Health) - 2 >= 0)
                     {
                         N_BS.Health = Convert.ToString(Convert.ToInt32(N_BS.Health) - 2);
                     }
                 }
                 if (Convert.ToInt32(N_BS.Hunger) - 1 >= 0)
                 {
                     N_BS.Hunger = Convert.ToString(Convert.ToInt32(N_BS.Hunger) - 1);
                 }
             }
             else
             {
                 if (Convert.ToInt32(N_BS.Hunger) <= 100 && Convert.ToInt32(N_BS.Hunger) > 0)
                 {
                     N_BS.Hunger = Convert.ToString(Convert.ToInt32(N_BS.Hunger) - 2);
                 }
                 else if (Convert.ToInt32(N_BS.Hunger) <= 0)
                 {//Gain Depression
                     if (Convert.ToInt32(N_BS.Depression) + 2 <= 100)
                     {
                         N_BS.Depression = Convert.ToString(Convert.ToInt32(N_BS.Depression) + 2);
                     }
                     else if (Convert.ToInt32(N_BS.Depression) >= 100 && Convert.ToInt32(N_BS.Health) > 0)
                     {
                         N_BS.Health = Convert.ToString(Convert.ToInt32(N_BS.Health) - 2);
                     }
                 }
                 if (Convert.ToInt32(N_BS.Hunger) > 0)
                 {
                     N_BS.Hunger = Convert.ToString(Convert.ToInt32(N_BS.Hunger) - 1);
                 }
             }
             run_throughs += 0.5f;
         }
         else if (run_throughs == 1.0f)//thirst
         {
             if (thirst != -1)
             {
                 if (Convert.ToInt32(N_BS.Thirst) + 2 <= 100 && Convert.ToInt32(_ST[thirst].Amount) > 0)
                 {
                     N_BS.Thirst        = Convert.ToString(Convert.ToInt32(N_BS.Thirst) + 2);
                     _ST[thirst].Amount = Convert.ToString(Convert.ToInt32(_ST[thirst].Amount) - Convert.ToInt32(_ST[thirst].Loss));
                 }
                 else if (Convert.ToInt32(N_BS.Thirst) + 2 <= 100 && Convert.ToInt32(_ST[thirst].Amount) < 0)
                 {
                     N_BS.Thirst = Convert.ToString(Convert.ToInt32(N_BS.Thirst) - 2);
                 }
                 else if (Convert.ToInt32(N_BS.Thirst) <= 0)
                 {//Gain Depression
                     if (Convert.ToInt32(N_BS.Depression) + 2 <= 100)
                     {
                         N_BS.Depression = Convert.ToString(Convert.ToInt32(N_BS.Depression) + 2);
                     }
                     else if (Convert.ToInt32(N_BS.Depression) <= 100 && Convert.ToInt32(N_BS.Health) - 2 >= 0)
                     {
                         N_BS.Health = Convert.ToString(Convert.ToInt32(N_BS.Health) - 2);
                     }
                 }
                 if (Convert.ToInt32(N_BS.Thirst) - 1 >= 0)
                 {
                     N_BS.Thirst = Convert.ToString(Convert.ToInt32(N_BS.Thirst) - 1);
                 }
             }
             else
             {
                 if (Convert.ToInt32(N_BS.Thirst) <= 100 && Convert.ToInt32(N_BS.Thirst) > 0)
                 {
                     N_BS.Thirst = Convert.ToString(Convert.ToInt32(N_BS.Thirst) - 2);
                 }
                 else if (Convert.ToInt32(N_BS.Thirst) <= 0)
                 {//Gain Depression
                     if (Convert.ToInt32(N_BS.Depression) + 2 <= 100)
                     {
                         N_BS.Depression = Convert.ToString(Convert.ToInt32(N_BS.Depression) + 2);
                     }
                     else if (Convert.ToInt32(N_BS.Depression) >= 100 && Convert.ToInt32(N_BS.Health) > 0)
                     {
                         N_BS.Health = Convert.ToString(Convert.ToInt32(N_BS.Health) - 2);
                     }
                 }
                 if (Convert.ToInt32(N_BS.Thirst) > 0)
                 {
                     N_BS.Thirst = Convert.ToString(Convert.ToInt32(N_BS.Thirst) - 1);
                 }
             }
             run_throughs = 0.0f;
         }
         //_ST.Clear();
     }
     catch (Exception e)
     {
         Console.WriteLine(e.Data + " " + e.InnerException + " " + e.Source + " " + e.Message);
     }
 }