Пример #1
0
        public static ErrorCodes WriteMailToTargets(MassMail mail)
        {
            var ec = ErrorCodes.NoError;

            try
            {
                foreach (var target in mail.targets)
                {
                    Db.Query().CommandText(@"insert charactermessages (sender,folder,body,subject,type,targets,owner) values (@sender,@folder,@body,@subject,@type,@targets,@owner)")
                    .SetParameter("@sender", mail.sender.Id)
                    .SetParameter("@folder", mail.folder)
                    .SetParameter("@body", mail.body)
                    .SetParameter("@subject", mail.subject)
                    .SetParameter("@type", mail.type)
                    .SetParameter("@targets", GenxyConverter.SerializeObject(mail.targets.GetCharacterIDs().ToArray()))
                    .SetParameter("@owner", mail.owner.Id)
                    .SetParameter("@owner", target.Id)
                    .ExecuteNonQuery();
                }
            }
            catch (Exception ex)
            {
                Logger.Error("error occred in writeMailToTargetsSQL: " + ex.Message);
                ec = ErrorCodes.SQLExecutionError;
            }
            return(ec);
        }
Пример #2
0
        public static MassMail OpenMail(Character character, long mailId)
        {
            //                        0      1      2      3    4       5       6       7     8      9
            var m = Db.Query().CommandText("update charactermessages set wasread=1 where mailid=@mailID and owner=@characterID; select mailid,sender,folder,type,creation,wasread,targets,owner,subject,body from charactermessages where mailid=@mailID and owner=@characterID")
                    .SetParameter("@mailID", mailId)
                    .SetParameter("@characterID", character.Id)
                    .ExecuteSingleRow();

            if (m == null)
            {
                return(null);
            }

            return(new MassMail
            {
                mailID = m.GetValue <long>(0),
                sender = Character.Get(m.GetValue <int>(1)),
                folder = (MailFolder)m.GetValue <int>(2),
                type = (MailType)m.GetValue <int>(3),
                creation = m.GetValue <DateTime>(4),
                wasRead = m.GetValue <bool>(5),
                targets = GenxyConverter.DeserializeObject <int[]>(m.GetValue <string>(6)).ToCharacter().ToArray(),
                owner = Character.Get(m.GetValue <int>(7)),
                subject = m.GetValue <string>(8),
                body = m.GetValue <string>(9)
            });
        }
Пример #3
0
        public static void WriteEnvironmentToSql(int definition, EntityEnvironmentDescription nativeEnvironmentData)
        {
            var descriptionString = GenxyConverter.Serialize(nativeEnvironmentData.ToDictionary());

            Db.Query().CommandText("writeEnvironment")
            .SetParameter("@definition", definition)
            .SetParameter("@descriptionstring", descriptionString)
            .ExecuteScalar <int>().ThrowIfEqual(0, ErrorCodes.SQLInsertError);
        }
Пример #4
0
        public void Update(RobotTemplate template)
        {
            var descriptionString = GenxyConverter.Serialize(template.ToDictionary());

            Db.Query().CommandText("update robottemplates set name=@name,description=@description where id=@id")
            .SetParameter("@id", template.ID)
            .SetParameter("@name", template.Name)
            .SetParameter("@description", descriptionString)
            .ExecuteNonQuery().ThrowIfEqual(0, ErrorCodes.SQLUpdateError);
        }
Пример #5
0
        public GenxyString ToGenxyString()
        {
            var dictionary = new Dictionary <string, object>
            {
                { k.name, Name },
                { k.robot, Robot.Definition },
                { k.modules, _modules.ToDictionary("m", m => m.ToDictionary()) }
            };

            return(GenxyConverter.Serialize(dictionary));
        }
Пример #6
0
        public void Insert(RobotTemplate template)
        {
            var descriptionString = GenxyConverter.Serialize(template.ToDictionary());

            var id = Db.Query().CommandText("insert robottemplates (name,description) values (@name,@description); select cast(scope_identity() as integer)")
                     .SetParameter("@name", template.Name)
                     .SetParameter("@description", descriptionString)
                     .ExecuteScalar <int>().ThrowIfEqual(0, ErrorCodes.SQLInsertError);

            template.ID = id;
        }
Пример #7
0
        public override string ToString()
        {
            var sb = new StringBuilder();

            sb.Append(Command?.Text);
            sb.Append(':');
            sb.Append(Sender);
            sb.Append(':');
            sb.Append(GenxyConverter.Serialize(Data));
            return(sb.ToString());
        }
Пример #8
0
        public static RobotTemplate CreateFromRecord(int id, string name, string descGenXY, string note)
        {
            Dictionary <string, object> dict = GenxyConverter.Deserialize(descGenXY);
            RobotTemplate botTemp            = RobotTemplate.GetRobotTemplateFromXY(dict);

            botTemp.recordNote        = note;
            botTemp.recordID          = id;
            botTemp.recordName        = name;
            botTemp.recordDescription = descGenXY;
            return(botTemp);
        }
        private static Dictionary <string, object> CreateCharacterWizardData(IExtensionReader extensionReader)
        {
            var extensions   = extensionReader.GetExtensions();
            var corpProfiles = Db.Query().CommandText("select eid,publicprofile from corporations where defaultcorp = 1")
                               .Execute()
                               .ToDictionary(r => r.GetValue("eid"), r => GenxyConverter.Deserialize(r.GetValue <string>("publicprofile")));

            Dictionary <string, object> LoadCwData(string name, string idName, Action <IDataRecord, Dictionary <string, object> > action = null)
            {
                var cw = Db.Query().CommandText($"select * from {name}").Execute();
                var ex = Db.Query().CommandText($"select * from {name}_extension")
                         .Execute()
                         .Where(r => extensions.ContainsKey(r.GetValue <int>("extensionid"))).ToLookup(r => r.GetValue(idName));

                return(cw.ToDictionary("w", r =>
                {
                    var id = r.GetValue(idName);
                    var dd = new Dictionary <string, object>
                    {
                        ["ID"] = id,
                        ["name"] = r.GetValue("name"),
                        ["description"] = r.GetValue("descriptiontoken"),
                        ["extension"] = ex.GetOrEmpty(id).ToDictionary("e", x =>
                        {
                            return new Dictionary <string, object>
                            {
                                { k.extensionID, x.GetValue("extensionid") },
                                { k.add, x.GetValue("levelincrement") }
                            };
                        })
                    };

                    action?.Invoke(r, dd);
                    return dd;
                }));
            }

            var result = new Dictionary <string, object>
            {
                ["race"]        = LoadCwData("cw_race", "raceid"),
                ["spark"]       = LoadCwData("cw_spark", "sparkid"),
                ["school"]      = LoadCwData("cw_school", "schoolid", (r, d) => { d["raceID"] = r.GetValue("raceid"); }),
                ["major"]       = LoadCwData("cw_major", "majorid", (r, d) => { d["schoolID"] = r.GetValue("schoolid"); }),
                ["corporation"] = LoadCwData("cw_corporation", "corporationEID", (r, d) =>
                {
                    d["baseEID"]       = r.GetValue("baseEID");
                    d["schoolID"]      = r.GetValue("schoolid");
                    d["publicProfile"] = corpProfiles[r.GetValue <long>("corporationEID")];
                })
            };

            return(result);
        }
Пример #10
0
        private IRequest CreateRequest(string data)
        {
            var args = data.Split(':');

            if (args.Length < 3)
            {
                throw new PerpetuumException(ErrorCodes.TooManyOrTooFewArguments);
            }

            var commandText = args[0];

            var command = _commandFactory(commandText);

            if (command == null)
            {
                throw PerpetuumException.Create(ErrorCodes.NoSuchCommand).SetData("command", commandText);
            }

            if (!_accessLevel.HasFlag(command.AccessLevel))
            {
                throw PerpetuumException.Create(ErrorCodes.InsufficientPrivileges)
                      .SetData("command", command.Text)
                      .SetData("accessLevel", (int)_accessLevel);
            }

            var targetPlugin = args[1];

            var dictionary = GenxyConverter.Deserialize(args[2]);

            command.CheckArguments(dictionary);

            var request = new Request
            {
                Command = command,
                Session = this,
                Target  = _globalConfiguration.RelayName,
                Data    = dictionary,
            };

            if (!targetPlugin.StartsWith("zone_"))
            {
                return(request);
            }

            request.Target = targetPlugin;
            var zoneID = int.Parse(targetPlugin.Remove(0, 5));
            var zr     = new ZoneRequest(request)
            {
                Zone = _zoneManager.GetZone(zoneID)
            };

            return(zr);
        }
Пример #11
0
        public static Message Parse(string s)
        {
            var x       = s.Split(':');
            var command = Commands.GetCommandByText(x[0]) ?? new Command(x[0]);
            var sender  = x[1];
            var data    = GenxyConverter.Deserialize(x[2]);

            return(new Message(command, data)
            {
                Sender = sender
            });
        }
Пример #12
0
        public static ErrorCodes WriteToOutbox(MassMail mail)
        {
            var res = Db.Query().CommandText(@"insert charactermessages (sender,folder,body,subject,type,targets,owner) values (@sender,@folder,@body,@subject,@type,@targets,@owner)")
                      .SetParameter("@sender", mail.sender.Id)
                      .SetParameter("@folder", (int)MailFolder.outbox)
                      .SetParameter("@body", mail.body)
                      .SetParameter("@subject", mail.subject)
                      .SetParameter("@type", (int)mail.type)
                      .SetParameter("@targets", GenxyConverter.SerializeObject(mail.targets.GetCharacterIDs().ToArray()))
                      .SetParameter("@owner", mail.sender.Id)
                      .ExecuteNonQuery();

            return((res != 1) ? ErrorCodes.SQLInsertError : ErrorCodes.NoError);
        }
Пример #13
0
        private static EntityEnvironmentDescription ConvertFromString(string descriptionString)
        {
            var nativeDescription = new EntityEnvironmentDescription();

            var descriptionObjects = GenxyConverter.Deserialize(descriptionString);

            if (descriptionObjects.ContainsKey(k.blocks))
            {
                var tileDict = (Dictionary <string, object>)descriptionObjects[k.blocks];
                nativeDescription.blocksTiles = ConvertTilesToList(tileDict);
            }

            return(nativeDescription);
        }
        public void Save(IZone zone, Player owner, Unit killer, IEnumerable <CombatSummary> summaries)
        {
            var reportData = GenxyConverter.Serialize(CreateReportData(zone, owner, summaries));

            var reportId = Guid.NewGuid();

            Db.Query().CommandText("insert into killreports (id,date,data) values (@id,getdate(),@data)").SetParameter("@id", reportId).SetParameter("@data", reportData).ExecuteNonQuery().ThrowIfEqual(0, ErrorCodes.SQLInsertError);

            SaveParticipantsToDb(reportId, owner.Character, true, false);

            foreach (var summary in summaries)
            {
                var isKiller = summary.Source == killer;
                SaveParticipantsToDb(reportId, summary.Source.GetCharacter(), false, true, isKiller);
            }
        }
Пример #15
0
        private static RobotTemplate CreateRobotTemplateFromRecord(IDataRecord record)
        {
            var id          = record.GetValue <int>("id");
            var name        = record.GetValue <string>("name");
            var description = record.GetValue <string>("description");
            var dictionary  = GenxyConverter.Deserialize(description);
            var template    = RobotTemplate.CreateFromDictionary(name, dictionary);

            if (template == null)
            {
                return(null);
            }

            template.ID = id;
            return(template);
        }
        public void HandleRequest(IRequest request)
        {
            using (var scope = Db.CreateTransaction())
            {
                var tHash = (Dictionary <string, object>)(request.Data[k.data]);

                var character = request.Session.Character;
                Db.Query().CommandText("characterSettingsSetString")
                .SetParameter("@characterid", character.Id)
                .SetParameter("@data", GenxyConverter.Serialize(tHash))
                .ExecuteNonQuery();

                Message.Builder.FromRequest(request).WithOk().Send();

                scope.Complete();
            }
        }
Пример #17
0
        public static IEnumerable <MassMail> ListFolder(Character character, int folder)
        {
            //                                    0     1      2      3     4       5       6       7    8
            var mails = Db.Query().CommandText("select mailid,sender,folder,type,creation,wasread,targets,owner,subject from charactermessages where folder=@folder and owner=@owner")
                        .SetParameter("@folder", folder).SetParameter("@owner", character.Id)
                        .Execute();

            return(mails.Select(m => new MassMail
            {
                mailID = m.GetValue <long>(0),
                sender = Character.Get(m.GetValue <int>(1)),
                folder = (MailFolder)m.GetValue <int>(2),
                type = (MailType)m.GetValue <int>(3),
                creation = m.GetValue <DateTime>(4),
                wasRead = m.GetValue <bool>(5),
                targets = GenxyConverter.DeserializeObject <int[]>(m.GetValue <string>(6)).ToCharacter().ToArray(),
                owner = Character.Get(m.GetValue <int>(7)),
                subject = m.GetValue <string>(8)
            }));
        }
        public IDictionary <string, object> LoadSettingsFromFile(string path)
        {
            if (!_fileSystem.Exists(path))
            {
                Logger.Warning($"ini file not found: {path}");
                return(new Dictionary <string, object>());
            }

            var lines = _fileSystem.ReadAllText(path).GetLines().Select(l => l.RemoveComment()).Where(line => line.Length > 0).ToArray();

            var strSettings = new StringBuilder();

            foreach (var line in lines)
            {
                strSettings.Append(line);
                strSettings.Append('#');
            }

            var result = GenxyConverter.Deserialize(strSettings.ToString());

            return(result);
        }
Пример #19
0
        public void HandleRequest(IRequest request)
        {
            using (var scope = Db.CreateTransaction())
            {
                var avatar   = request.Data.GetOrDefault <Dictionary <string, object> >(k.avatar);
                var rendered = request.Data.GetOrDefault <string>(k.rendered);

                var character = Character.Get(request.Data.GetOrDefault <int>(k.characterID));
                if (character == Character.None)
                {
                    character = request.Session.Character;
                }

                Db.Query().CommandText("update characters set avatar=@avatar where characterid=@characterID")
                .SetParameter("@characterID", character.Id)
                .SetParameter("@avatar", GenxyConverter.Serialize(avatar))
                .ExecuteNonQuery();

                Message.Builder.FromRequest(request).WithOk().Send();

                scope.Complete();
            }
        }
        protected static Corporation Create(EntityDefault entityDefault, SystemContainer container, CorporationDescription corporationDescription, EntityIDGenerator generator)
        {
            var corporation = Factory.Create(entityDefault, generator);

            corporation.Parent = container.Eid;
            corporation.Save();

            const string insertCommandText = @"insert into corporations (eid, name, nick, wallet, taxrate, publicProfile, privateProfile,defaultcorp, founder) 
                                                                 values (@eid, @name, @nick, @wallet, @taxrate, @publicProfile, @privateProfile,@defaultcorp,@founder)";

            Db.Query().CommandText(insertCommandText)
            .SetParameter("@eid", corporation.Eid)
            .SetParameter("@name", corporationDescription.name)
            .SetParameter("@nick", corporationDescription.nick)
            .SetParameter("@wallet", 0)
            .SetParameter("@taxrate", corporationDescription.taxRate)
            .SetParameter("@publicProfile", GenxyConverter.Serialize((Dictionary <string, object>)corporationDescription.publicProfile))
            .SetParameter("@privateProfile", GenxyConverter.Serialize((Dictionary <string, object>)corporationDescription.privateProfile))
            .SetParameter("@defaultCorp", corporationDescription.isDefault).SetParameter("@founder", corporationDescription.founder)
            .ExecuteNonQuery().ThrowIfEqual(0, ErrorCodes.SQLInsertError);

            return((Corporation)corporation);
        }
        public void HandleRequest(IRequest request)
        {
            var character = request.Session.Character;
            var dataStr   = Db.Query().CommandText("select settingsstring from charactersettings where characterid=@characterID")
                            .SetParameter("@characterID", character.Id)
                            .ExecuteScalar <string>();

            var result = GenxyConverter.Deserialize(dataStr);

            if (result.Count == 0)
            {
                Message.Builder.FromRequest(request).WithData(new Dictionary <string, object>(1)
                {
                    { k.state, k.empty }
                }).Send();
            }
            else
            {
                Message.Builder.FromRequest(request).WithData(new Dictionary <string, object>(1)
                {
                    { k.result, result }
                }).Send();
            }
        }
 public GenxyString ToGenxyString()
 {
     return(GenxyConverter.Serialize(_items));
 }
        // obviously everything coming in from the in-game chat is a string.
        // we have to take that string and chop it up, work out what command is being executed
        // then parse/cast/convert arguments as necessary.
        public void ParseAdminCommand(Character sender, string text, IRequest request, Channel channel, ISessionManager sessionManager, ChannelManager channelmanager)
        {
            string[] command = text.Split(new char[] { ',' });

            // channel is not secured. must be secured first.
            if (channel.Type != ChannelType.Admin)
            {
                if (command[0] == "#secure")
                {
                    channel.SetAdmin(true);
                    channel.SendMessageToAll(sessionManager, sender, "Channel Secured.");
                    return;
                }

                channel.SendMessageToAll(sessionManager, sender, "Channel must be secured before sending commands.");
                return;
            }

            if (command[0] == "#shutdown")
            {
                DateTime shutdownin = DateTime.Now;
                int      minutes    = 1;
                if (!int.TryParse(command[2], out minutes))
                {
                    throw PerpetuumException.Create(ErrorCodes.RequiredArgumentIsNotSpecified);
                }
                shutdownin = shutdownin.AddMinutes(minutes);

                Dictionary <string, object> dictionary = new Dictionary <string, object>()
                {
                    { "message", command[1] },
                    { "date", shutdownin }
                };

                string cmd = string.Format("serverShutDown:relay:{0}", GenxyConverter.Serialize(dictionary));
                request.Session.HandleLocalRequest(request.Session.CreateLocalRequest(cmd));
            }

            if (command[0] == "#shutdowncancel")
            {
                string cmd = string.Format("serverShutDownCancel:relay:null");
                request.Session.HandleLocalRequest(request.Session.CreateLocalRequest(cmd));
            }

            if (command[0] == "#jumpto")
            {
                bool err = false;
                err = !int.TryParse(command[1], out int zone);
                err = !int.TryParse(command[2], out int x);
                err = !int.TryParse(command[3], out int y);
                if (err)
                {
                    throw PerpetuumException.Create(ErrorCodes.RequiredArgumentIsNotSpecified);
                }

                Dictionary <string, object> dictionary = new Dictionary <string, object>()
                {
                    { "zoneID", zone },
                    { "x", x },
                    { "y", y }
                };

                string cmd = string.Format("jumpAnywhere:zone_{0}:{1}", sender.ZoneId, GenxyConverter.Serialize(dictionary));
                request.Session.HandleLocalRequest(request.Session.CreateLocalRequest(cmd));
            }

            if (command[0] == "#moveplayer")
            {
                bool err = false;
                err = !int.TryParse(command[1], out int characterID);
                err = !int.TryParse(command[2], out int zoneID);
                err = !int.TryParse(command[3], out int x);
                err = !int.TryParse(command[4], out int y);
                if (err)
                {
                    throw PerpetuumException.Create(ErrorCodes.RequiredArgumentIsNotSpecified);
                }

                // get the target character's session.
                var charactersession = sessionManager.GetByCharacter(characterID);

                if (charactersession.Character.ZoneId == null)
                {
                    channel.SendMessageToAll(sessionManager, sender, string.Format("ERR: Character with ID {0} does not have a zone. Are they docked?", characterID));
                    return;
                }

                // get destination zone.
                var zone = request.Session.ZoneMgr.GetZone(zoneID);

                if (charactersession.Character.ZoneId == null)
                {
                    channel.SendMessageToAll(sessionManager, sender, string.Format("ERR: Invalid Zone ID {0}", zoneID));
                    return;
                }

                // get a teleporter object to teleport the player.
                TeleportToAnotherZone tp = new TeleportToAnotherZone(zone);

                // we need the player (robot, etc) to teleport on the origin zone
                var player = request.Session.ZoneMgr.GetZone((int)charactersession.Character.ZoneId).GetPlayer(charactersession.Character.ActiveRobotEid);
                //var player = zone.GetPlayer(charactersession.Character.Eid);

                // set the position.
                tp.TargetPosition = new Position(x, y);

                // do it.
                tp.DoTeleportAsync(player);
                tp = null;

                channel.SendMessageToAll(sessionManager, sender, string.Format("Moved Character {0}-{1} to Zone {2} @ {3},{4}", characterID, charactersession.Character.Nick, zone.Id, x, y));
            }
#if DEBUG
            if (command[0] == "#currentzonecleanobstacleblocking")
            {
                string cmd = string.Format("zoneCleanObstacleBlocking:zone_{0}:null", sender.ZoneId);
                request.Session.HandleLocalRequest(request.Session.CreateLocalRequest(cmd));
            }

            if (command[0] == "#currentzonedrawblockingbyeid")
            {
                bool err = false;
                err = !Int64.TryParse(command[1], out Int64 eid);

                if (err)
                {
                    throw PerpetuumException.Create(ErrorCodes.RequiredArgumentIsNotSpecified);
                }

                Dictionary <string, object> dictionary = new Dictionary <string, object>()
                {
                    { "eid", eid }
                };

                string cmd = string.Format("zoneDrawBlockingByEid:zone_{0}:{1}", sender.ZoneId, GenxyConverter.Serialize(dictionary));
                request.Session.HandleLocalRequest(request.Session.CreateLocalRequest(cmd));
            }

            if (command[0] == "#currentzoneremoveobjectbyeid")
            {
                bool err = false;
                err = !Int64.TryParse(command[1], out Int64 eid);

                Dictionary <string, object> dictionary = new Dictionary <string, object>()
                {
                    { "target", eid }
                };

                string cmd = string.Format("zoneRemoveObject:zone_{0}:{1}", sender.ZoneId, GenxyConverter.Serialize(dictionary));
                request.Session.HandleLocalRequest(request.Session.CreateLocalRequest(cmd));
            }

            if (command[0] == "#zonecreateisland")
            {
                bool err = false;
                err = !int.TryParse(command[1], out int lvl);

                Dictionary <string, object> dictionary = new Dictionary <string, object>()
                {
                    { "low", lvl }
                };

                string cmd = string.Format("zoneCreateIsland:zone_{0}:{1}", sender.ZoneId, GenxyConverter.Serialize(dictionary));
                request.Session.HandleLocalRequest(request.Session.CreateLocalRequest(cmd));
            }

            if (command[0] == "#currentzoneplacewall")
            {
                string cmd = string.Format("zonePlaceWall:zone_{0}:null", sender.ZoneId);
                request.Session.HandleLocalRequest(request.Session.CreateLocalRequest(cmd));
            }

            if (command[0] == "#currentzoneclearwalls")
            {
                string cmd = string.Format("zoneClearWalls:zone_{0}:null", sender.ZoneId);
                request.Session.HandleLocalRequest(request.Session.CreateLocalRequest(cmd));
            }

            if (command[0] == "#currentzoneadddecor")
            {
                bool err = false;
                err = !int.TryParse(command[1], out int definition);
                err = !int.TryParse(command[2], out int x);
                err = !int.TryParse(command[3], out int y);
                err = !int.TryParse(command[4], out int z);
                err = !double.TryParse(command[5], out double qx);
                err = !double.TryParse(command[6], out double qy);
                err = !double.TryParse(command[7], out double qz);
                err = !double.TryParse(command[8], out double qw);
                err = !double.TryParse(command[9], out double scale);
                err = !int.TryParse(command[10], out int cat);

                if (err)
                {
                    throw PerpetuumException.Create(ErrorCodes.RequiredArgumentIsNotSpecified);
                }

                Dictionary <string, object> dictionary = new Dictionary <string, object>()
                {
                    { "definition", definition },
                    { "x", x *256 },
                    { "y", y *256 },
                    { "z", z *256 },
                    { "quaternionX", qx },
                    { "quaternionY", qy },
                    { "quaternionZ", qz },
                    { "quaternionW", qw },
                    { "scale", scale },
                    { "category", cat }
                };

                string cmd = string.Format("zoneDecorAdd:zone_{0}:{1}", sender.ZoneId, GenxyConverter.Serialize(dictionary));
                request.Session.HandleLocalRequest(request.Session.CreateLocalRequest(cmd));
            }

            if (command[0] == "#adddecortolockedtile")
            {
                var character = request.Session.Character;
                var zone      = request.Session.ZoneMgr.GetZone((int)character.ZoneId);
                var player    = zone.GetPlayer(character.ActiveRobotEid);

                var terrainLock = player.GetPrimaryLock() as TerrainLock;
                if (terrainLock == null)
                {
                    return;
                }

                double x = terrainLock.Location.X;
                double y = terrainLock.Location.Y;
                double z = terrainLock.Location.Z;

                bool err = !double.TryParse(command[2], out double scale);
                err = !int.TryParse(command[1], out int definition);

                if (err)
                {
                    throw PerpetuumException.Create(ErrorCodes.RequiredArgumentIsNotSpecified);
                }

                Dictionary <string, object> dictionary = new Dictionary <string, object>()
                {
                    { "definition", definition },
                    { "x", (int)x * 256 },
                    { "y", (int)y * 256 },
                    { "z", (int)z * 256 },
                    { "quaternionX", (double)0 },
                    { "quaternionY", (double)0 },
                    { "quaternionZ", (double)0 },
                    { "quaternionW", (double)0 },
                    { "scale", scale },
                    { "category", 1 }
                };

                string cmd = string.Format("zoneDecorAdd:zone_{0}:{1}", sender.ZoneId, GenxyConverter.Serialize(dictionary));
                request.Session.HandleLocalRequest(request.Session.CreateLocalRequest(cmd));
            }

            if (command[0] == "#zonedeletedecor")
            {
                bool err = false;
                err = !int.TryParse(command[1], out int idno);

                Dictionary <string, object> dictionary = new Dictionary <string, object>()
                {
                    { "ID", idno }
                };

                string cmd = string.Format("zoneDecorDelete:zone_{0}:{1}", sender.ZoneId, GenxyConverter.Serialize(dictionary));
                request.Session.HandleLocalRequest(request.Session.CreateLocalRequest(cmd));
            }

            if (command[0] == "#zoneclearlayer")
            {
                Dictionary <string, object> dictionary = new Dictionary <string, object>()
                {
                    { "layerName", command[1] }
                };

                string cmd = string.Format("zoneClearLayer:zone_{0}:{1}", sender.ZoneId, GenxyConverter.Serialize(dictionary));
                request.Session.HandleLocalRequest(request.Session.CreateLocalRequest(cmd));
            }

            if (command[0] == "#zonesetplantspeed")
            {
                bool err = false;
                err = !int.TryParse(command[1], out int speed);

                Dictionary <string, object> dictionary = new Dictionary <string, object>()
                {
                    { "speed", speed }
                };

                string cmd = string.Format("zoneSetPlantsSpeed:zone_{0}:{1}", sender.ZoneId, GenxyConverter.Serialize(dictionary));
                request.Session.HandleLocalRequest(request.Session.CreateLocalRequest(cmd));
            }

            if (command[0] == "#zonesetplantmode")
            {
                Dictionary <string, object> dictionary = new Dictionary <string, object>()
                {
                    { "mode", command[1] }
                };

                string cmd = string.Format("zoneSetPlantsMode:zone_{0}:{1}", sender.ZoneId, GenxyConverter.Serialize(dictionary));
                request.Session.HandleLocalRequest(request.Session.CreateLocalRequest(cmd));
            }

            if (command[0] == "#currentzonerestoreoriginalgamma")
            {
                string cmd = string.Format("zoneRestoreOriginalGamma:zone_{0}:null", sender.ZoneId);
                request.Session.HandleLocalRequest(request.Session.CreateLocalRequest(cmd));
            }

            if (command[0] == "#zonedrawblockingbydefinition")
            {
                bool err = false;
                err = !int.TryParse(command[1], out int def);
                int[] defs = new int[1];
                defs[0] = def;

                Dictionary <string, object> dictionary = new Dictionary <string, object>()
                {
                    { "definition", defs }
                };

                string cmd = string.Format("zoneDrawBlockingByDefinition:zone_{0}:{1}", sender.ZoneId, GenxyConverter.Serialize(dictionary));
                request.Session.HandleLocalRequest(request.Session.CreateLocalRequest(cmd));
            }

            if (command[0] == "#addblockingtotiles")
            {
                var character = request.Session.Character;
                var zone      = request.Session.ZoneMgr.GetZone((int)character.ZoneId);
                var player    = zone.GetPlayer(character.ActiveRobotEid);

                var lockedtiles = player.GetLocks();

                using (new TerrainUpdateMonitor(zone))
                {
                    foreach (Lock item in lockedtiles)
                    {
                        Position pos = (item as TerrainLock).Location;
                        zone.Terrain.Blocks.SetValue(pos, new BlockingInfo()
                        {
                            Obstacle = true
                        });
                        item.Cancel(); // cancel this lock. we processed it.
                    }
                }

                channel.SendMessageToAll(sessionManager, sender, string.Format("Added Blocking To {0} Tiles.", lockedtiles.Count));
            }

            if (command[0] == "#removeblockingfromtiles")
            {
                var character = request.Session.Character;
                var zone      = request.Session.ZoneMgr.GetZone((int)character.ZoneId);
                var player    = zone.GetPlayer(character.ActiveRobotEid);

                var lockedtiles = player.GetLocks();

                using (new TerrainUpdateMonitor(zone))
                {
                    foreach (Lock item in lockedtiles)
                    {
                        Position pos = (item as TerrainLock).Location;
                        zone.Terrain.Blocks.SetValue(pos, new BlockingInfo()
                        {
                            Obstacle = false
                        });
                        item.Cancel(); // cancel this lock. we processed it.
                    }
                }

                channel.SendMessageToAll(sessionManager, sender, string.Format("Removed Blocking From {0} Tiles.", lockedtiles.Count));
            }

            if (command[0] == "#zonedecorlock")
            {
                bool err = false;
                err = !int.TryParse(command[1], out int id);
                err = !int.TryParse(command[2], out int locked);

                Dictionary <string, object> dictionary = new Dictionary <string, object>()
                {
                    { "ID", id },
                    { "locked", locked }
                };

                string cmd = string.Format("zoneDecorLock:zone_{0}:{1}", sender.ZoneId, GenxyConverter.Serialize(dictionary));
                request.Session.HandleLocalRequest(request.Session.CreateLocalRequest(cmd));
            }

            if (command[0] == "#zonetileshighway")
            {
                bool.TryParse(command[1], out bool adddelete);
                bool.TryParse(command[2], out bool keeplock);

                var character = request.Session.Character;
                var zone      = request.Session.ZoneMgr.GetZone((int)character.ZoneId);
                var player    = zone.GetPlayer(character.ActiveRobotEid);

                var lockedtiles = player.GetLocks();

                using (new TerrainUpdateMonitor(zone))
                {
                    foreach (Lock item in lockedtiles)
                    {
                        Position           pos = (item as TerrainLock).Location;
                        TerrainControlInfo ti  = zone.Terrain.Controls.GetValue(pos);
                        ti.Highway = adddelete;
                        zone.Terrain.Controls.SetValue(pos, ti);
                        if (!keeplock)
                        {
                            item.Cancel(); // cancel this lock. we processed it.
                        }
                    }
                }
                channel.SendMessageToAll(sessionManager, sender, string.Format("Altered state of control layer on {0} Tiles (Highway)", lockedtiles.Count));
            }

            if (command[0] == "#zonetilesconcretea")
            {
                bool.TryParse(command[1], out bool adddelete);
                bool.TryParse(command[2], out bool keeplock);

                var character = request.Session.Character;
                var zone      = request.Session.ZoneMgr.GetZone((int)character.ZoneId);
                var player    = zone.GetPlayer(character.ActiveRobotEid);

                var lockedtiles = player.GetLocks();

                using (new TerrainUpdateMonitor(zone))
                {
                    foreach (Lock item in lockedtiles)
                    {
                        Position           pos = (item as TerrainLock).Location;
                        TerrainControlInfo ti  = zone.Terrain.Controls.GetValue(pos);
                        ti.ConcreteA = adddelete;
                        zone.Terrain.Controls.SetValue(pos, ti);
                        if (!keeplock)
                        {
                            item.Cancel(); // cancel this lock. we processed it.
                        }
                    }
                }
                channel.SendMessageToAll(sessionManager, sender, string.Format("Altered state of control layer on {0} Tiles (ConcreteA)", lockedtiles.Count));
            }

            if (command[0] == "#zonetilesconcreteb")
            {
                bool.TryParse(command[1], out bool adddelete);
                bool.TryParse(command[2], out bool keeplock);

                var character = request.Session.Character;
                var zone      = request.Session.ZoneMgr.GetZone((int)character.ZoneId);
                var player    = zone.GetPlayer(character.ActiveRobotEid);

                var lockedtiles = player.GetLocks();

                using (new TerrainUpdateMonitor(zone))
                {
                    foreach (Lock item in lockedtiles)
                    {
                        Position           pos = (item as TerrainLock).Location;
                        TerrainControlInfo ti  = zone.Terrain.Controls.GetValue(pos);
                        ti.ConcreteB = adddelete;
                        zone.Terrain.Controls.SetValue(pos, ti);
                        if (!keeplock)
                        {
                            item.Cancel(); // cancel this lock. we processed it.
                        }
                    }
                }
                channel.SendMessageToAll(sessionManager, sender, string.Format("Altered state of control layer on {0} Tiles (ConcreteB)", lockedtiles.Count));
            }

            if (command[0] == "#zonetilesroaming")
            {
                bool.TryParse(command[1], out bool adddelete);
                bool.TryParse(command[2], out bool keeplock);

                var character = request.Session.Character;
                var zone      = request.Session.ZoneMgr.GetZone((int)character.ZoneId);
                var player    = zone.GetPlayer(character.ActiveRobotEid);

                var lockedtiles = player.GetLocks();

                using (new TerrainUpdateMonitor(zone))
                {
                    foreach (Lock item in lockedtiles)
                    {
                        Position           pos = (item as TerrainLock).Location;
                        TerrainControlInfo ti  = zone.Terrain.Controls.GetValue(pos);
                        ti.Roaming = adddelete;
                        zone.Terrain.Controls.SetValue(pos, ti);
                        if (!keeplock)
                        {
                            item.Cancel(); // cancel this lock. we processed it.
                        }
                    }
                }
                channel.SendMessageToAll(sessionManager, sender, string.Format("Altered state of control layer on {0} Tiles (Roaming)", lockedtiles.Count));
            }

            if (command[0] == "#zonetilesPBSTerraformProtected")
            {
                bool.TryParse(command[1], out bool adddelete);
                bool.TryParse(command[2], out bool keeplock);

                var character = request.Session.Character;
                var zone      = request.Session.ZoneMgr.GetZone((int)character.ZoneId);
                var player    = zone.GetPlayer(character.ActiveRobotEid);

                var lockedtiles = player.GetLocks();

                using (new TerrainUpdateMonitor(zone))
                {
                    foreach (Lock item in lockedtiles)
                    {
                        Position           pos = (item as TerrainLock).Location;
                        TerrainControlInfo ti  = zone.Terrain.Controls.GetValue(pos);
                        ti.PBSTerraformProtected = adddelete;
                        zone.Terrain.Controls.SetValue(pos, ti);
                        if (!keeplock)
                        {
                            item.Cancel(); // cancel this lock. we processed it.
                        }
                    }
                }
                channel.SendMessageToAll(sessionManager, sender, string.Format("Altered state of control layer on {0} Tiles (PBSTerraformProtected)", lockedtiles.Count));
            }

            //MissionTestResolve - DEBUG ONLY
            if (command[0] == "#testmissions")
            {
                int.TryParse(command[1], out int charID);
                int.TryParse(command[2], out int zoneID);
                int.TryParse(command[3], out int level);
                int.TryParse(command[4], out int numAttempts);
                int.TryParse(command[5], out int displayFlag);
                int.TryParse(command[6], out int singleFlag);
                Dictionary <string, object> dictionary = new Dictionary <string, object>()
                {
                    { k.characterID, charID },
                    { k.zone, zoneID },
                    { k.level, level },
                    { "display", displayFlag },
                    { "attempts", numAttempts },
                    { "single", singleFlag },
                };

                string cmd = string.Format("{0}:relay:{1}", Commands.MissionResolveTest.Text, GenxyConverter.Serialize(dictionary));
                request.Session.HandleLocalRequest(request.Session.CreateLocalRequest(cmd));

                channel.SendMessageToAll(sessionManager, sender, string.Format("Running missionresolve test {0}", dictionary.ToDebugString()));
            }
#endif

            if (command[0] == "#giveitem")
            {
                int.TryParse(command[1], out int definition);
                int.TryParse(command[2], out int qty);

                Dictionary <string, object> dictionary = new Dictionary <string, object>()
                {
                    { "definition", definition },
                    { "quantity", qty }
                };


                string cmd = string.Format("createItem:relay:{0}", GenxyConverter.Serialize(dictionary));
                request.Session.HandleLocalRequest(request.Session.CreateLocalRequest(cmd));

                channel.SendMessageToAll(sessionManager, sender, string.Format("Gave Item {0} ", definition));
            }


            if (command[0] == "#getlockedtileproperties")
            {
                var character = request.Session.Character;
                var zone      = request.Session.ZoneMgr.GetZone((int)character.ZoneId);
                var player    = zone.GetPlayer(character.ActiveRobotEid);

                var lockedtile = player.GetPrimaryLock();

                TerrainControlInfo ti = zone.Terrain.Controls.GetValue((lockedtile as TerrainLock).Location);

                channel.SendMessageToAll(sessionManager, sender, string.Format("Tile at {0},{1} has the following flags..", (lockedtile as TerrainLock).Location.X, (lockedtile as TerrainLock).Location.Y));
                channel.SendMessageToAll(sessionManager, sender, "TerrainControlFlags:");
                foreach (TerrainControlFlags f in Enum.GetValues(typeof(TerrainControlFlags)))
                {
                    if (ti.Flags.HasFlag(f) && f != TerrainControlFlags.Undefined)
                    {
                        channel.SendMessageToAll(sessionManager, sender, string.Format("{0}", f.ToString()));
                    }
                }

                BlockingInfo bi = zone.Terrain.Blocks.GetValue((lockedtile as TerrainLock).Location);

                channel.SendMessageToAll(sessionManager, sender, "BlockingFlags:");
                foreach (BlockingFlags f in Enum.GetValues(typeof(BlockingFlags)))
                {
                    if (bi.Flags.HasFlag(f) && f != BlockingFlags.Undefined)
                    {
                        channel.SendMessageToAll(sessionManager, sender, string.Format("{0}", f.ToString()));
                    }
                }

                PlantInfo pi = zone.Terrain.Plants.GetValue((lockedtile as TerrainLock).Location);

                channel.SendMessageToAll(sessionManager, sender, "PlantType:");
                foreach (PlantType f in Enum.GetValues(typeof(PlantType)))
                {
                    if (pi.type.HasFlag(f) && f != PlantType.NotDefined)
                    {
                        channel.SendMessageToAll(sessionManager, sender, string.Format("{0}", f.ToString()));
                    }
                }

                channel.SendMessageToAll(sessionManager, sender, "GroundType:");
                foreach (GroundType f in Enum.GetValues(typeof(GroundType)))
                {
                    if (pi.groundType.HasFlag(f))
                    {
                        channel.SendMessageToAll(sessionManager, sender, string.Format("{0}", f.ToString()));
                    }
                }
            }

            if (command[0] == "#setvisibility")
            {
                bool.TryParse(command[1], out bool visiblestate);

                var character = request.Session.Character;
                var zone      = request.Session.ZoneMgr.GetZone((int)character.ZoneId);
                var player    = zone.GetPlayer(character.ActiveRobotEid);

                player.HasGMStealth = !visiblestate;

                channel.SendMessageToAll(sessionManager, sender, string.Format("Player {0} visibility is {1}", player.Character.Nick, visiblestate));
            }

            if (command[0] == "#zonedrawstatmap")
            {
                Dictionary <string, object> dictionary = new Dictionary <string, object>()
                {
                    { "type", command[1] }
                };

                string cmd = string.Format("zoneDrawStatMap:zone_{0}:{1}", sender.ZoneId, GenxyConverter.Serialize(dictionary));
                request.Session.HandleLocalRequest(request.Session.CreateLocalRequest(cmd));
            }


            if (command[0] == "#listplayersinzone")
            {
                int.TryParse(command[1], out int zoneid);

                channel.SendMessageToAll(sessionManager, sender, string.Format("Players On Zone {0}", zoneid));
                channel.SendMessageToAll(sessionManager, sender, string.Format("  AccountId    CharacterId    Nick    Access Level    Docked?    DockedAt    Position"));
                foreach (Character c in sessionManager.SelectedCharacters.Where(x => x.ZoneId == zoneid))
                {
                    channel.SendMessageToAll(sessionManager, sender, string.Format("   {0}       {1}        {2}        {3}       {4}       {5}      {6}",
                                                                                   c.AccountId, c.Id, c.Nick, c.AccessLevel, c.IsDocked, c.GetCurrentDockingBase().Eid, c.GetPlayerRobotFromZone().CurrentPosition));
                }
            }

            if (command[0] == "#countofplayers")
            {
                foreach (IZone z in request.Session.ZoneMgr.Zones)
                {
                    channel.SendMessageToAll(sessionManager, sender, string.Format("Players On Zone {0}: {1}", z.Id, z.Players.ToList().Count));
                }
            }

            if (command[0] == "#unsecure")
            {
                channel.SetAdmin(false);
                channel.SendMessageToAll(sessionManager, sender, "Channel is now public.");
            }

            if (command[0] == "#addtochannel")
            {
                int.TryParse(command[1], out int characterid);

                var c = sessionManager.GetByCharacter(characterid);

                channelmanager.JoinChannel(channel.Name, c.Character, ChannelMemberRole.Operator, string.Empty);

                channel.SendMessageToAll(sessionManager, sender, string.Format("Added character {0} to channel ", c.Character.Nick));
            }

            if (command[0] == "#removefromchannel")
            {
                int.TryParse(command[1], out int characterid);

                var c = sessionManager.GetByCharacter(characterid);

                channelmanager.LeaveChannel(channel.Name, c.Character);

                channel.SendMessageToAll(sessionManager, sender, string.Format("Removed character {0} from channel ", c.Character.Nick));
            }

            if (command[0] == "#listrifts")
            {
                foreach (IZone z in request.Session.ZoneMgr.Zones)
                {
                    var rift = z.Units.OfType <Rift>();
                    foreach (Rift r in rift)
                    {
                        channel.SendMessageToAll(sessionManager, sender, string.Format("Rift - Zone: {0}, Position: ({1}), Destination Zone:{2}", r.Zone, r.CurrentPosition, r.DestinationStrongholdZone));
                    }
                }
            }


            if (command[0] == "#flagplayernameoffensive")
            {
                bool err = false;
                err = !int.TryParse(command[1], out int characterID);
                err = !bool.TryParse(command[2], out bool isoffensive);

                var charactersession = sessionManager.GetByCharacter(characterID);
                charactersession.Character.IsOffensiveNick = isoffensive;

                channel.SendMessageToAll(sessionManager, sender, string.Format("Player with nick {0} is offensive:{1}", charactersession.Character.Nick, charactersession.Character.IsOffensiveNick));
            }

            //FreeAllLockedEP for account - by request of player
            if (command[0] == "#unlockallep")
            {
                bool err = false;
                err = !int.TryParse(command[1], out int accountID);
                if (err)
                {
                    throw PerpetuumException.Create(ErrorCodes.RequiredArgumentIsNotSpecified);
                }

                Dictionary <string, object> dictionary = new Dictionary <string, object>()
                {
                    { k.accountID, accountID }
                };

                string cmd = string.Format("{0}:relay:{1}", Commands.ExtensionFreeAllLockedEpCommand.Text, GenxyConverter.Serialize(dictionary));
                request.Session.HandleLocalRequest(request.Session.CreateLocalRequest(cmd));
            }

            //EPBonusCommands
            if (command[0] == "#epbonusset")
            {
                bool err = false;
                err = !int.TryParse(command[1], out int bonusBoost);
                err = !int.TryParse(command[2], out int hours);
                if (err)
                {
                    throw PerpetuumException.Create(ErrorCodes.RequiredArgumentIsNotSpecified);
                }

                Dictionary <string, object> dictionary = new Dictionary <string, object>()
                {
                    { k.bonus, bonusBoost },
                    { k.duration, hours }
                };

                string cmd = string.Format("{0}:relay:{1}", Commands.EPBonusSet.Text, GenxyConverter.Serialize(dictionary));
                request.Session.HandleLocalRequest(request.Session.CreateLocalRequest(cmd));
                channel.SendMessageToAll(sessionManager, sender, "EP Bonus Set with command: " + dictionary.ToDebugString());
            }
        }
Пример #24
0
 public string ToGenXY()
 {
     return(GenxyConverter.Serialize(this.ToDictionary()));
 }
 public string ToGenxyString()
 {
     return(GenxyConverter.Serialize(_dictionary));
 }
Пример #26
0
 public void SetPublicProfile(Dictionary <string, object> publicProfile)
 {
     WriteValueToDb("publicProfile", GenxyConverter.Serialize(publicProfile));
 }