Пример #1
0
        private void ProcessSkillGroups(RdlTagCollection tags)
        {
            List <RdlActor>    groups = tags.GetTags <RdlActor>(RdlTagName.OBJ.ToString(), RdlObjectTypeName.ACTOR.ToString());
            List <RdlProperty> skills = tags.GetTags <RdlProperty>(RdlTagName.OBJ.ToString(), RdlObjectTypeName.PROP.ToString());

            if (groups.Count > 0)
            {
                Game.SkillGroups.Clear();
                foreach (var group in groups)
                {
                    List <Skill> list = new List <Skill>();
                    foreach (var skill in skills.Where(s => s.ID == group.ID))
                    {
                        list.Add(new Skill {
                            Name = skill.Name, Value = Convert.ToInt32(skill.Value)
                        });
                    }
                    Game.SkillGroups.Add(group.Name, list);
                }
                if (_hasRequiredQuota && StorageManager.RequiresFileUpdate(FileNames.SkillGroups))
                {
                    RdlTagCollection groupTags = new RdlTagCollection();
                    groupTags.AddRange(groups.ToTagCollection());
                    groupTags.AddRange(skills.ToTagCollection());
                    StorageManager.WriteTags(FileNames.SkillGroups, groupTags);
                }
            }
        }
Пример #2
0
        public static MapChunk GetMapChunk(string mapName, int startX, int startY, bool includeActors)
        {
            RdlTagCollection tags   = new RdlTagCollection();
            List <Place>     places = Game.Server.World.Map.GetMap(mapName, startX, startY, Game.Server.World.Map.DefaultWidth, Game.Server.World.Map.DefaultHeight);

            if (places.Count > 0)
            {
                for (int i = 0; i < places.Count; i++)
                {
                    tags.AddRange(places[i].ToRdl());

                    if (includeActors)
                    {
                        // Send down actors in the places as well.
                        foreach (var actor in places[i].Children)
                        {
                            if (actor.ObjectType != ObjectType.Player)
                            {
                                tags.AddRange(actor.ToRdl());
                            }
                        }
                    }
                }
            }
            return(new MapChunk
            {
                MapName = mapName,
                StartX = startX,
                StartY = startY,
                Tags = tags.ToString()
            });
        }
Пример #3
0
        private void ProcessResponse(RdlTagCollection tags)
        {
            bool       validLogin = false;
            RdlAuthKey key        = tags.Where(t => t.TagName == "AUTH").FirstOrDefault() as RdlAuthKey;

            if (key != null)
            {
                if (!String.IsNullOrEmpty(key.Key))
                {
                    validLogin = true;
                }

                // Check for persist login token.
                if (!String.IsNullOrEmpty(key.PersistLoginToken))
                {
                    StorageManager.SetPersistLoginToken(key.PersistLoginToken);
                }
            }

            this.Dispatcher.BeginInvoke(() =>
            {
                _waitDialog.Close();
            });

            if (validLogin)
            {
                Settings.UserAuthKey = key.Key;
                ScreenManager.SetScreen(new HomeScreen());
            }
            else
            {
                valMain.Errors.Add(new ValidationSummaryItem("The username/password combination you supplied is invalid. Please ensure caps lock is not on and try again."));
            }
        }
Пример #4
0
 private void client_SaveActorCompleted(object sender, SaveActorCompletedEventArgs e)
 {
     try
     {
         if (e.Result.Success)
         {
             RdlTagCollection tags = RdlTagCollection.FromString(e.Result.TagString);
             if (tags != null)
             {
                 foreach (var actor in tags.GetActors())
                 {
                     var tile = _tiles.Where(t => t.Place.ID == actor.OwnerID).FirstOrDefault();
                     if (tile != null)
                     {
                         tile.Place.Actors.Add(actor);
                         this.PlaceChanged(new PlaceEventArgs(tile.Place));
                     }
                 }
             }
         }
     }
     finally
     {
         ctlWait.Hide();
     }
 }
Пример #5
0
        private void btnSavePlace_Click(object sender, RoutedEventArgs e)
        {
            RdlPlace           place = new RdlPlace(_placeId, txtPlaceName.Text, _currentLocation.X, _currentLocation.Y, _currentLocation.Z);
            List <RdlProperty> props = new List <RdlProperty>();

            props.Add(new RdlProperty(place.ID, "Description", txtPlaceDesc.Text));
            props.Add(new RdlProperty(place.ID, "RuntimeType", ddlPlaceTypes.SelectedItem));
            props.Add(new RdlProperty(place.ID, "Terrain", ((Terrain)ddlTerrain.SelectedItem).ID));

            RdlTagCollection tags = new RdlTagCollection();

            tags.Add(place);
            tags.AddRange(props.ToArray());

            string cmdName = "ADMINCREATE";

            if (_placeId > 0)
            {
                cmdName = "ADMINSAVE";
            }

            RdlCommand cmd = new RdlCommand(cmdName);

            if (_placeId > 0)
            {
                cmd.Args.Add(_placeId);
            }
            else
            {
                cmd.Args.Add("place");
            }

            //ServerManager.Instance.SendCommand(Settings.UserAuthKey, "User", cmd, null, tags);
        }
Пример #6
0
        public override string ToString()
        {
            RdlTagCollection tags = new RdlTagCollection();

            tags.AddRange(this.ToRdl());
            return(tags.ToString());
        }
Пример #7
0
        public void LoadMap(RdlTagCollection tags)
        {
            _tags = tags;
            this.Tiles.Clear();

            List <RdlPlace> places = tags.GetObjects <RdlPlace>();

            foreach (var place in places)
            {
                Tile tile = new Tile(place);

                //var terrain = Game.Terrain.Where(t => t.ID == place.Properties.GetValue<int>("Terrain")).FirstOrDefault();
                //if (terrain != null)
                //{
                //    Color color = new Color();
                //    color.A = (byte)((terrain.Color & -16777216) >> 0x18);
                //    color.R = (byte)((terrain.Color & 0xff0000) >> 0x10);
                //    color.G = (byte)((terrain.Color & 0xff00) >> 8);
                //    color.B = (byte)(terrain.Color & 0xff);

                //    tile.Fill = Brushes.GetBrush(color);
                //}

                this.Tiles.Add(tile);
            }

            this.RenderMap();
        }
Пример #8
0
 /// <summary>
 /// Initializes a new instance of the Client class for an HTTP connected client.
 /// </summary>
 public Client()
 {
     this.Tags              = new RdlTagCollection();
     this.Context           = new HttpMessageContext(this.Tags);
     this.AuthKey           = AuthKey.Empty;
     this.LastHeartbeatDate = DateTime.Now;
     this.Handler           = new LoginCommandHandler(this);
     this.SessionId         = Guid.NewGuid();
 }
Пример #9
0
 private void client_GetActorsCompleted(object sender, GetActorsCompletedEventArgs e)
 {
     if (e.Result.Success && _selectedTile != null)
     {
         _selectedTile.Place.Actors.Clear();
         _selectedTile.Place.Actors.AddRange(RdlTagCollection.FromString(e.Result.TagString).GetActors());
         this.PlaceChanged(new PlaceEventArgs(_selectedTile.Place));
     }
 }
Пример #10
0
        private void ProcessFileUpdates(RdlTagCollection tags)
        {
            var updates = tags.GetTags <RdlTag>("FILEUPDATE", "FILEUPDATE");

            if (updates != null && updates.Count > 0)
            {
                StorageManager.LoadFileUpdatesFromServer(updates);
            }
        }
Пример #11
0
        private void LoadTemplates(string tagString, List <RdlActor> list, ActorList control)
        {
            List <RdlActor> actors = RdlTagCollection.FromString(tagString).GetActors();

            if (actors.Count > 0)
            {
                list.Clear();
                list.AddRange(actors);
                control.ItemsSource = list;
            }
        }
Пример #12
0
        private void client_GetMapNamesCompleted(object sender, GetMapNamesCompletedEventArgs e)
        {
            if (e.Result.Success)
            {
                // Handle map names.
                Game.LoadMapDetails(RdlTagCollection.FromString(e.Result.TagString).GetTags <RdlTag>("MAP", "MAP"));

                // Display points on the map where the map details are defined.
                this.Dispatcher.BeginInvoke(() => this.LoadMaps());
            }
        }
Пример #13
0
 private void ProcessNews(RdlTagCollection tags)
 {
     //var messages = tags.GetMessages().Where(t => t.TypeName == "NEWS").Select(t => t as RdlNewsMessage);
     //StringBuilder sb = new StringBuilder();
     //foreach (var msg in messages)
     //{
     //    sb.Append("<strong>").Append(msg.Title.Replace("&nbsp;", "&#160;")).Append(" - ").Append(msg.Date).Append("</strong>");
     //    sb.Append(msg.Text.Replace("&nbsp;", "&#160;"));
     //}
     //txtNews.Text = sb.ToString();
 }
Пример #14
0
        private void ProcessQuestTemplates(RdlTagCollection tags)
        {
            // Templates will be actors.
            List <RdlActor> actors = tags.GetActors();

            if (actors.Count > 0)
            {
                this.QuestTemplates.Clear();
                this.QuestTemplates.AddRange(actors);
            }
        }
Пример #15
0
 public bool ReadTags(out RdlTagCollection tags)
 {
     lock (_receivedTags)
     {
         if (_receivedTags.Count > 0)
         {
             tags = _receivedTags.Dequeue();
             return(true);
         }
     }
     tags = null;
     return(false);
 }
Пример #16
0
        private void ProcessTags(RdlTagCollection tags)
        {
            var tag = tags.GetTags <RdlTag>("ISONLINE", "ISONLINE");

            if (tag.Count > 0)
            {
                if (_timer != null)
                {
                    _timer.Dispose();
                }
                ScreenManager.SetScreen(new HomeScreen());
            }
        }
Пример #17
0
        private static RdlTagCollection GetRdlTagsFromResource(string fileName)
        {
            var info = Application.GetResourceStream(new Uri(String.Concat(Asset.AssetPath, "Data/", fileName), UriKind.Relative));

            if (info == null || info.Stream == null)
            {
                return(new RdlTagCollection());
            }

            using (var sr = new StreamReader(info.Stream))
            {
                return(RdlTagCollection.FromString(sr.ReadToEnd()));
            }
        }
Пример #18
0
        private static void ProcessTerrain(RdlTagCollection tags)
        {
            List <RdlTerrain> terrain = tags.GetObjects <RdlTerrain>();

            if (terrain.Count > 0)
            {
                Game.Terrain.Clear();
                foreach (var t in terrain)
                {
                    Game.Terrain.Add(new Terrain {
                        ID = t.ID, Name = t.Name, Color = t.Color, ImageUri = t.ImageUrl
                    });
                }
            }
        }
Пример #19
0
        private static void ProcessSkills(RdlTagCollection tags)
        {
            List <RdlSkill> skills = tags.GetTags <RdlSkill>(RdlTagName.OBJ.ToString(), RdlObjectTypeName.SKILL.ToString());

            if (skills.Count > 0)
            {
                Game.Skills.Clear();
                foreach (var item in skills)
                {
                    Game.Skills.Add(new Skill {
                        Name = item.Name, Description = item.Description, Value = item.Value, GroupName = item.GroupName
                    });
                }
            }
        }
Пример #20
0
        public void LoadMap(RdlTagCollection tags)
        {
            _tags = tags;
            this.Tiles.Clear();

            List <RdlPlace> places = tags.GetObjects <RdlPlace>();

            Logger.LogDebug("Loading {0} map tags into the map control.", places.Count);
            foreach (var place in places)
            {
                this.Tiles.Add(new Tile(place));
            }

            this.RenderMap();
        }
Пример #21
0
        public static void LoadFileUpdatesFromServer(List <RdlTag> serverTags)
        {
            // Load the files updates from disk.
            RdlTagCollection localTagCollection = ReadTags(FileUpdateFileName);
            var localTags = localTagCollection.GetTags <RdlTag>("FILEUPDATE", "FILEUPDATE");

            FileUpdates.Clear();
            foreach (var serverTag in serverTags)
            {
                bool   requiresUpdate = true;
                string fileName       = serverTag.GetArg <string>(0);
                // Loop through all of the server tags, attempt to find a matching local tag by file name.
                var matchingLocalTag = localTags.Where(t => t.GetArg <string>(0) == fileName).FirstOrDefault();
                if (matchingLocalTag != null)
                {
                    // If a matching local tags exists compare the dates, if they don't match this file requires an update.
                    DateTime localDt  = new DateTime(matchingLocalTag.GetArg <long>(1));
                    DateTime serverDt = new DateTime(serverTag.GetArg <long>(1));
                    if (localDt.CompareTo(serverDt) == 0)
                    {
                        requiresUpdate = false;
                        if (!FileExists(RootDirectory, fileName))
                        {
                            if (!FileExists(GetPath(MapsDirectory), fileName))
                            {
                                if (!FileExists(GetPath(UserDirectory), fileName))
                                {
                                    // Could not find any version or form of the file.
                                    requiresUpdate = true;
                                }
                            }
                        }
                    }
                }

                if (FileUpdates.ContainsKey(fileName))
                {
                    FileUpdates[fileName] = requiresUpdate;
                }
                else
                {
                    FileUpdates.Add(fileName, requiresUpdate);
                }
            }

            // Write the values from the server to disk.
            WriteTags(FileUpdateFileName, serverTags.ToTagCollection());
        }
Пример #22
0
        private void ProcessTags(RdlTagCollection tags)
        {
            if (tags.Count == 0)
            {
                return;
            }

            this.ProcessFileUpdates(tags);
            this.ProcessCommands(tags);
            //this.ProcessSkills(tags);
            //this.ProcessTerrain(tags);
            //this.ProcessSkillGroups(tags);
            //this.ProcessRaces(tags);
            //this.ProcessNews(tags);

            //if (_step == Step.Characters)
            //{
            this.ProcessCharacters(tags);
            //}

            // Process any messages, send errors and system messages to the alert panel.
            List <RdlMessage> messages = tags.GetMessages();

            foreach (var msg in messages)
            {
                switch (msg.TypeName)
                {
                case "ERROR":
                case "SYSTEM":
                    _waitDialog.Text = msg.Text;
                    _hasErrors       = true;
                    break;
                }
            }

            //if (_step == Step.Role) _step = Step.FileUpdates;
            //else if (_step == Step.FileUpdates) _step = Step.Skills;
            //else if (_step == Step.Skills) _step = Step.SkillGroups;
            //else if (_step == Step.SkillGroups) _step = Step.Races;
            //else if (_step == Step.Races) _step = Step.Terrain;
            //else if (_step == Step.Terrain) _step = Step.Characters;
            //else if (_step == Step.Characters) _step = Step.News;
            //else if (_step == Step.News) _step = Step.None;

            //this.ExecuteCommand();
        }
Пример #23
0
        private void ProcessCommands(RdlTagCollection tags)
        {
            List <RdlCommand> commands = tags.GetCommands();

            if (commands != null && commands.Count > 0)
            {
                foreach (var cmd in commands)
                {
                    if (cmd.TypeName.Equals("EXIT"))
                    {
#if DEBUG
                        StorageManager.WriteError(String.Format("[ {0} ]{1}{2}", DateTime.Now, Environment.NewLine, cmd.ToString()));
#endif
                        ScreenManager.SetScreen(new GameOfflineScreen());
                        //System.Windows.Browser.HtmlPage.Window.Eval("window.location.reload();");
                    }
                    if (cmd.TypeName.Equals("CHECKROLE"))
                    {
                        // Args:
                        // 0 = role
                        // 1 = is in role
                        Settings.Role = cmd.GetArg <string>(0);
                        bool isInRole = cmd.GetArg <bool>(1);
                        if (!String.IsNullOrEmpty(Settings.Role) && Settings.Role.ToLower().Equals("god") && isInRole)
                        {
                            btnAdmin.Visibility = Visibility.Visible;
                        }
                        else
                        {
                            btnAdmin.Visibility = Visibility.Collapsed;
                        }
                    }
                    if (cmd.TypeName.Equals("CONNECT"))
                    {
                        if (_hasErrors)
                        {
                            _waitDialog.HasCloseButton = true;
                        }
                        else
                        {
                            _waitDialog.Close();
                        }
                    }
                }
            }
        }
Пример #24
0
        private void CompleteReceive(Message message)
        {
            CommunicatorResponseEventArgs args = new CommunicatorResponseEventArgs(this,
                                                                                   RdlTagCollection.FromString(message.GetBody <string>()));

            if (_altResponse != null)
            {
                _altResponse(args);
            }
            else
            {
                this.Response(args);
            }

            // Signal the thread pool to start another single asynchronous request to Receive messages from the server
            _waitObject.Set();
        }
Пример #25
0
        private void ProcessCheckNameResponse(RdlTagCollection tags)
        {
            RdlCommandResponse response = tags.GetTags <RdlCommandResponse>(RdlTagName.RESP.ToString(), "CHECKNAME").FirstOrDefault();

            if (response != null)
            {
                this.IsNameAvailable = response.Result;
                this.NameCheckComplete(new NameCheckEventArgs {
                    IsAvailable = response.Result, Message = response.Message
                });
            }
            //else
            //{
            //    this.IsNameAvailable = false;
            //    this.NameCheckComplete(new NameCheckEventArgs { IsAvailable = false, Message = "Name check failed, please try again." });
            //}
            this.Cursor = Cursors.Arrow;
        }
Пример #26
0
        public static RdlTagCollection GetMapNames()
        {
            RdlTagCollection tags = new RdlTagCollection();

            foreach (var detail in Game.Server.World.Map.MapDetails.Values)
            {
                RdlTag tag = new RdlTag("MAP", "MAP");
                tag.Args.Add(detail.Name);
                tag.Args.Add(detail.Width);
                tag.Args.Add(detail.Height);
                tag.Args.Add(detail.Key.StartX);
                tag.Args.Add(detail.Key.StartY);
                tag.Args.Add(detail.Key.EndX);
                tag.Args.Add(detail.Key.EndY);
                tags.Add(tag);
            }
            return(tags);
        }
Пример #27
0
        private void ProcessTerrain(RdlTagCollection tags)
        {
            List <RdlTerrain> terrain = tags.GetObjects <RdlTerrain>();

            if (terrain.Count > 0)
            {
                Game.Terrain.Clear();
                foreach (var t in terrain)
                {
                    Game.Terrain.Add(new Terrain {
                        ID = t.ID, Name = t.Name, Color = t.Color, ImageUri = t.ImageUrl
                    });
                }
                if (_hasRequiredQuota && StorageManager.RequiresFileUpdate(FileNames.Terrain))
                {
                    StorageManager.WriteTags(FileNames.Terrain, terrain.ToTagCollection());
                }
            }
        }
Пример #28
0
        public void Flush()
        {
            var tags = new RdlTagCollection();

            lock (_sendQueue)
            {
                while (_sendQueue.Count > 0)
                {
                    tags.Add(_sendQueue.Dequeue());
                }
            }
            if (tags.Count > 0)
            {
                var data = tags.ToBytes();
                //Logger.LogDebug("SERVER: Sending tags to client {0}: {1}", this.Client.UserName, tags);
                Logger.LogDebug("SERVER: Sending {0} tags for a total of {1} bytes to the client.", tags.Count, data.Length);
                Send(data);
            }
        }
Пример #29
0
        private void btnSave_Click(object sender, RoutedEventArgs e)
        {
            ctlWait.Show("Saving map informations...");
            var places            = _tiles.Where(t => t.Place.ID == 0 || t.IsModified).Select(t => t.Place);
            RdlTagCollection tags = new RdlTagCollection();

            _placesToSaveCount = places.Count();
            _placesSavedCount  = 0;
            foreach (var place in places)
            {
                tags.Add(place);
                tags.AddRange(place.Properties.ToArray());

                //BuilderServiceClient client = ServiceManager.CreateBuilderServiceClient();
                //client.SavePlacesCompleted += new EventHandler<SavePlacesCompletedEventArgs>(client_SavePlacesCompleted);
                //client.SavePlacesAsync(_token, tags.ToString(), place);
                tags = new RdlTagCollection();
            }
        }
Пример #30
0
        public string Process(string data)
        {
            var response = String.Empty;

            var client = Game.Server.ProcessCommands(this, RdlCommandGroup.FromString(data), Guid.NewGuid(), OperationContext.Current.Channel.LocalAddress.ToString());

            if (client != null)
            {
                var    tags = new RdlTagCollection();
                RdlTag tag;
                while (client.Context.Read(out tag))
                {
                    tags.Add(tag);
                }
                response = tags.ToString();
            }

            return(response);
        }