Beispiel #1
0
 public void E_OnMapTypeResourcesNumberUpdatingCancelled(int mapId, resourseTypes type, bool isSuccess, string excComment = null) // mapProcessor
 {
     if (isSuccess) consoleHandler.WriteLine(String.Format(FindResource("i_MapController_mapResourcesCountsUpdated").ToString(), type.ToString(), mapId));
     else
     {
         consoleHandler.WriteLine(String.Format(FindResource("i_MapController_mapResourcesCountsNotUpdated").ToString(), type.ToString(), mapId));
         if(excComment != null)
         {
             consoleHandler.Write(String.Format(FindResource("c_General_reason").ToString(), excComment));
         }
     }
 }
Beispiel #2
0
        // collectors
        private /*KeyValuePair<List<ResourceSAMP>, int>*/List<ResourceSAMP> CollectAllTypeResourcesFromCode(resourseTypes type, string sourceCode)
        {
            List<ResourceSAMP> Storage = new List<ResourceSAMP>();
            Regex regex;
            MatchCollection matches;
            regex = new Regex(ResourceTools.GetMatchMaskValue(type)); // set up regex pattern as is a mask of this type
            matches = regex.Matches(sourceCode); // get all type mathces
            if (matches.Count > 0) // matches of this type exists
            {
                foreach (Match match in matches) // foreaching matches with this type
                {
                    ResourceSAMP newRes = null;

                    try
                    {

                        // eject args from matched string
                        string novaStr = match.Value.Replace(")", "");
                        for (int additionalSize = 0; additionalSize < ResourceTools.MAX_ADDITIONAL_SIZE; additionalSize++)
                        {
                            novaStr += ", #"; // provide tryParse in MakeObject
                        }
                        // 
                        string[] args = novaStr.Split(new char[] { ',' }, StringSplitOptions.None);

                        switch (type)
                        {
                            case resourseTypes.AddStaticVehicle:
                                {
                                    newRes = new AddedStaticVehicle(args);
                                    break;
                                }
                            case resourseTypes.AddStaticVehicleEx:
                                {
                                    newRes = new AddedStaticVehicleEx(args);
                                    break;
                                }
                            case resourseTypes.CreateDynamicObject:
                                {
                                    newRes = new CreatedDynamicObject(args);
                                    break;
                                }
                            case resourseTypes.CreateObject:
                                {
                                    newRes = new CreatedObject(args);
                                    break;
                                }
                            case resourseTypes.CreateVehicle:
                                {
                                    newRes = new CreatedVehicle(args);
                                    break;
                                }
                            case resourseTypes.RemoveBuildingForPlayer:
                                {
                                    newRes = new RemovedBuildingForPlayer(args);
                                    break;
                                }
                        }

                        Storage.Add(newRes);
                    }
                    catch (Exception e) // cannot build object from an iterated match
                    {
                        consoleHandler.WriteLine(String.Format(FindResource("i_MapLoader_cannotReadLine").ToString(), type.ToString(), match.Value, e.ToString()));
                        //newRes = null;
                        break;
                    }
                }
            }

            /*
            return new KeyValuePair<List<ResourceSAMP>, int>
            (
                Storage, Storage.Count
            );
             * */
            return Storage;
        }
Beispiel #3
0
        // update map type' resources number in mysql
        private bool updateMapResourcesNumberInMySQL(int mapId, resourseTypes type, int newValue, bool openConnection, bool startTransaction)
        {
            try
            {
                if (openConnection)
                {
                    sqlClient.getConn().Open();
                }

                MySqlCommand cmd;
                if (startTransaction)
                {
                    cmd = new MySqlCommand("START TRANSACTION", sqlClient.getConn());
                    cmd.ExecuteNonQuery();
                }

                cmd = new MySqlCommand(String.Format(@"
                    UPDATE `ssmm_maps` SET `Map{0}Count` = '{1}' WHERE `MapID` = {2}",
                        type.ToString(),
                        newValue,
                        mapId
                    ),
                sqlClient.getConn());
                cmd.ExecuteNonQuery();

                MAP thisMap = getMapById(mapId);
                thisMap.resourcesCount[type] = newValue;


                if (startTransaction)
                {
                    cmd = new MySqlCommand("COMMIT", sqlClient.getConn());
                    cmd.ExecuteNonQuery();
                }

                if (openConnection)
                {
                    sqlClient.getConn().Close();
                }

                appHandler.E_OnMapTypeResourcesNumberUpdatingCancelled(mapId, type, true);
            }
            catch(Exception e)
            {
                appHandler.E_OnMapTypeResourcesNumberUpdatingCancelled(mapId, type, false, e.ToString());
            }
            return true;
        }