示例#1
0
        public ICommand GetCommand()
        {
            var File = new FileIO();

            if (connectedPlayer.Location == null)
            {
                string   startRoom = EngineSettings.Default.InitialRoom;
                string[] locations = startRoom.Split('>');

                if (locations.Length < 3)
                {
                    Log.Error("The Server does not have a starting room set!");
                    connectedPlayer.SendMessage(
                        "The server does not have a starting room set! Please contact the server administrator.");
                    return(new NoOpCommand());
                }

                IWorld world = director.Server.Game.World;

                if (world == null)
                {
                    Log.Fatal("Failed to get a instance of the game world!");
                    return(new NoOpCommand()); //If this is null, then we should end up in a infinite console spam
                }

                IRealm realm = world.GetRealm(locations[0]);
                if (realm == null)
                {
                    Log.Fatal(string.Format("Failed to load Realm {0}", locations[0]));
                    return(new NoOpCommand());
                }

                IZone zone = realm.GetZone(locations[1]);
                if (zone == null)
                {
                    Log.Fatal(string.Format("Failed to load Zone {0}", locations[1]));
                    return(new NoOpCommand());
                }

                IRoom room = zone.GetRoom(locations[2]);
                if (room == null)
                {
                    Log.Fatal(string.Format("Failed to load Room {0}", locations[2]));
                    return(new NoOpCommand());
                }

                connectedPlayer.Move(room);

                File.Save(connectedPlayer, Path.Combine(EngineSettings.Default.PlayerSavePath, string.Format("{0}.char", connectedPlayer.Username)));
            }
            else if (connectedPlayer.Director.Server.Game.World.RoomExists(connectedPlayer.Location.ToString()))
            {
                File.Save(connectedPlayer, Path.Combine(EngineSettings.Default.PlayerSavePath, string.Format("{0}.char", connectedPlayer.Username)));
            }
            else
            {
                //Set as null and re-run through this state again.
                connectedPlayer.Location = null;
                return(new NoOpCommand()); //Dont allow it to finish the setup
            }

            return(SetupDefaultState());
        }
示例#2
0
        private void roomsBtnLoadRoom_Click(object sender, EventArgs e)
        {
            //Can't load a room if nothing is selected
            if (roomsLstExistingRooms.SelectedIndex == -1)
            {
                MessageBox.Show("You must select a Room from within the Available Rooms list.", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            //If a Realm or Zone isn't selected, abort.
            if (roomsComRealms.SelectedIndex == -1 || roomsComZones.SelectedIndex == -1)
            {
                MessageBox.Show("You must select a Realm and a Zone from the Existing Realm and Existing Zone drop down menus.", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            //Our instance variables
            IRealm realm = null;
            IZone  zone  = null;
            IRoom  room  = null;

            //Get a reference to the currently selected Realm.
            realm = Editor.Game.World.GetRealm(roomsComRealms.SelectedItem.ToString());
            if (realm == null)
            {
                MessageBox.Show(roomsComRealms.SelectedItem.ToString() + " was not found within the games World collection!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            //If the Realm exists, we need to get a reference to the currently selected Zone too.
            else
            {
                zone = realm.GetZone(roomsComZones.SelectedItem.ToString());
            }

            if (zone == null)
            {
                MessageBox.Show(roomsComZones.SelectedItem.ToString() + " was not found within the " + realm.Name + " zone collection!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            //If the Zone exists, we need to get a reference to the currently selected Room
            else
            {
                room = zone.GetRoom(roomsLstExistingRooms.SelectedItem.ToString());
            }

            //Check if the Room is null
            if (room == null)
            {
                MessageBox.Show("The selected Room '" + roomsLstExistingRooms.SelectedItem.ToString() + "' was not located within the " + zone.Name + " room collection!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            //Room isn't null, set the static Editor types Current properties.
            //Lets us modify them with-out having to call a Get() method again.
            else
            {
                Editor.CurrentRealm = realm;
                Editor.CurrentZone  = zone;
                Editor.CurrentRoom  = room;
            }

            //Refresh our UI
            RefreshDoorwayList();
            RefreshRoomLabels(realm, zone, room);

            //Select the Room object in the property grid for editing.
            roomsPropertiesRoom.SelectedObject = room;
        }
示例#3
0
        private bool GetUserPassword()
        {
            //Recieve the user input
            var input = connectedPlayer.ReceiveInput();

            //Make sure the text entered is valid and not null, blank etc.
            if (!ValidateInput(input))
            {
                connectedPlayer.SendMessage("Your password is invalid!");
                return(false);
            }

            var file = new FileIO();

            IPlayer loadedplayer = (IPlayer)file.Load(
                Path.Combine(
                    EngineSettings.Default.PlayerSavePath,
                    string.Format("{0}.char", connectedPlayer.Username)),
                connectedPlayer.GetType());

            if (loadedplayer != null && loadedplayer.CheckPassword(input))
            {
                /*Make sure we are disconnecting the user if they are connected already.
                 * foreach (var connectedUser in director.ConnectedPlayers.Keys)
                 * {
                 *  if (connectedUser.Name == loadedplayer.Name && connectedUser != loadedplayer)
                 *      connectedUser.Disconnect();
                 * }
                 */

                connectedPlayer.SendMessage("Success!!");

                //Can use inherited built-in CopyState method instead
                //connectedPlayer.LoadPlayer(loadedplayer);

                //Use IGameObject.CopyState to use a uniform method across the engine
                //A little slower than the LoadPlayer method, but it can be revised to be quicker.
                //Notes on revising the method are under GameObject.cs
                IGameObject tmp = (IGameObject)loadedplayer;
                connectedPlayer.CopyState(ref tmp); //Copies loadedPlayer state to connectedPlayer.

                //Make sure the player is properly added to the world.
                IWorld world = connectedPlayer.Director.Server.Game.World;
                IRealm realm = world.GetRealm(connectedPlayer.Location.Zone.Realm.Name);

                if (realm == null)
                {
                    return(false);
                }

                IZone zone = realm.GetZone(connectedPlayer.Location.Zone.Name);
                if (zone == null)
                {
                    return(false);
                }

                IRoom room = zone.GetRoom(connectedPlayer.Location.Name);
                if (room == null)
                {
                    return(false);
                }

                connectedPlayer.Move(room);

                Log.Info(string.Format("{0} has just logged in.", connectedPlayer.Name));
                connectedPlayer.SwitchState(new LoginCompleted());

                return(true);
            }
            else
            {
                Log.Info(string.Format("{0} has failed logged in at IP Address: {1}.", connectedPlayer.Name,
                                       connectedPlayer.Connection.RemoteEndPoint));

                return(false);
            }
        }
示例#4
0
        public Engine.Commands.ICommand GetCommand()
        {
            switch (currentCreationState)
            {
            case CreationState.CharacterCreation:
                connectedPlayer.SwitchState(new CreateNewCharacter(director));
                break;

            case CreationState.GenderSelect:
                connectedPlayer.SwitchState(new GenderSelect(director));
                break;

            case CreationState.Completed:
                //Broacast we are now done creating the character
                connectedPlayer.SendMessage("You have completed the character creation process! Enjoy your stay in our world!");
                connectedPlayer.SendMessage(string.Empty);    //blank line.

                //Trace back up through the environment path to get the World
                IWorld world = director.Server.Game.World;

                //Get the initial Room location, and split it up into an array so we can parse it
                string[] roomPath = EngineSettings.Default.InitialRoom.Split('>');

                //Make sure we have three entries, Realm, Zone and Room
                if (roomPath.Length != 3)
                {
                    return(new NoOpCommand());
                }

                //Get the Realm
                IRealm realm = world.GetRealm(roomPath[0]);
                if (realm == null)
                {
                    return(new NoOpCommand());
                }

                //Get our Zone
                IZone zone = realm.GetZone(roomPath[1]);
                if (zone == null)
                {
                    return(new NoOpCommand());
                }

                //Get the initial Room
                IRoom room = zone.GetRoom(roomPath[2]);
                if (room == null)
                {
                    return(new NoOpCommand());
                }


                connectedPlayer.Move(room);

                //Make sure we have a valid save path
                var filePath = Path.Combine(Directory.GetCurrentDirectory(), EngineSettings.Default.PlayerSavePath, connectedPlayer.Username + ".char");
                var path     = Path.GetDirectoryName(filePath);

                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }

                //Save the player using our serialization class
                FileIO fileSave = new FileIO();
                fileSave.Save(connectedPlayer, filePath);

                connectedPlayer.SwitchState(new EnteringCommandState());
                Log.Info(string.Format("{0} has just logged in.", connectedPlayer.Name));
                return(new LookCommand());
            }

            return(new NoOpCommand());
        }