コード例 #1
0
        private void handlePM(PlayerCharacter pc, IncommingMessage msg)
        {
            if (pc.LoginState == PlayerCharacterLoginState.LoginSuccesfull)
            {
                SendPMIncommingMessage msgSendPM = (SendPMIncommingMessage)msg;
                PlayerCharacter sendToPlayer = getPlayerByName(msgSendPM.RecipientName);

                if (sendToPlayer == null)
                {
                    RawTextOutgoingMessage msgToSender =
                        (RawTextOutgoingMessage)OutgoingMessagesFactory.Create(OutgoingMessageType.RAW_TEXT);
                    msgToSender.Color = PredefinedColor.Blue1;
                    msgToSender.Channel = PredefinedChannel.CHAT_LOCAL;
                    msgToSender.Text = "The one you seek is not here...";
                    pc.PutMessageIntoMyQueue(msgToSender);
                }
                else
                {
                    RawTextOutgoingMessage msgToSender =
                        (RawTextOutgoingMessage)OutgoingMessagesFactory.Create(OutgoingMessageType.RAW_TEXT);
                    msgToSender.Color = PredefinedColor.Purple1;
                    msgToSender.Channel = PredefinedChannel.CHAT_PERSONAL;
                    msgToSender.Text = "[PM to " + sendToPlayer.Name + ": " + msgSendPM.Text + "]";
                    pc.PutMessageIntoMyQueue(msgToSender);

                    RawTextOutgoingMessage msgToRecipient =
                        (RawTextOutgoingMessage)OutgoingMessagesFactory.Create(OutgoingMessageType.RAW_TEXT);
                    msgToRecipient.Color = PredefinedColor.Purple1;
                    msgToRecipient.Channel = PredefinedChannel.CHAT_PERSONAL;
                    msgToRecipient.Text = "[PM from " + pc.Name + ": " + msgSendPM.Text + "]";
                    sendToPlayer.PutMessageIntoMyQueue(msgToRecipient);
                }
            }
        }
コード例 #2
0
 private void handleTurnRight(PlayerCharacter pc, IncommingMessage msg)
 {
     if (pc.LoginState == PlayerCharacterLoginState.LoginSuccesfull)
     {
         pc.LocationTurnRight();
     }
 }
コード例 #3
0
        private void handleHarvest(PlayerCharacter pc, IncommingMessage msg)
        {
            if (pc.LoginState == PlayerCharacterLoginState.LoginSuccesfull)
            {
                HarvestIncommingMessage msgHarvest = (HarvestIncommingMessage)msg;

                switch (pc.LocationCurrentMap.Name)
                {
                    case ("calindor_startmap.elm"):
                        {
                            switch (msgHarvest.TargetObjectID)
                            {
                                case(138):
                                case (139):
                                    {

                                        ActionDescriptor actDesc = new HarvestActionDescriptor(2000, 1000);
                                        actDesc.AddExperienceDescriptor(new ExperienceDescriptor(EntitySkillType.HarvestingPlants, 3, 15));
                                        HarvestableResourceDescriptor rscDef =
                                            new HarvestableResourceDescriptor(
                                            ItemDefinitionCache.GetItemDefinitionByID(2), actDesc , 1);
                                        pc.HarvestStart(rscDef);
                                        break;
                                    }
                                case (274):
                                    {
                                        ActionDescriptor actDesc = new HarvestActionDescriptor(3000, 1000);
                                        actDesc.AddExperienceDescriptor(new ExperienceDescriptor(EntitySkillType.HarvestingPlants, 10, 25));
                                        HarvestableResourceDescriptor rscDef =
                                            new HarvestableResourceDescriptor(
                                            ItemDefinitionCache.GetItemDefinitionByID(3), actDesc, 1);
                                        pc.HarvestStart(rscDef);
                                        break;
                                    }
                                case (194):
                                    {
                                        ActionDescriptor actDesc = new HarvestActionDescriptor(3000, 1000);
                                        actDesc.AddExperienceDescriptor(new ExperienceDescriptor(EntitySkillType.HarvestingPlants, 10, 25));
                                        HarvestableResourceDescriptor rscDef =
                                            new HarvestableResourceDescriptor(
                                            ItemDefinitionCache.GetItemDefinitionByID(3), actDesc, 2);
                                        pc.HarvestStart(rscDef);
                                        break;
                                    }
                                case (276):
                                    {
                                        ActionDescriptor actDesc = new HarvestActionDescriptor(3000, 1000);
                                        actDesc.AddExperienceDescriptor(new ExperienceDescriptor(EntitySkillType.HarvestingPlants, 8, 20));
                                        HarvestableResourceDescriptor rscDef =
                                            new HarvestableResourceDescriptor(
                                            ItemDefinitionCache.GetItemDefinitionByID(7), actDesc, 1);
                                        pc.HarvestStart(rscDef);
                                        break;
                                    }
                            }
                            break;
                        }
                }
            }
        }
コード例 #4
0
ファイル: SSLListener.cs プロジェクト: fiskmoz/Manchattan
        public void RaiseEvent(string incomming)
        {
            IncommingMessage message = new IncommingMessage(incomming);

            message.Message = incomming;
            IncommingMessage(this, message);
        }
コード例 #5
0
    public void ReceiveIncommingMessage(Player.Message m)
    {
        IncommingMessage msg = new IncommingMessage(m);

        //msg.Select(selection.Deselect);
        selection.Select(msg);
        selection.Process();
    }
コード例 #6
0
        private void handleMoveTo(PlayerCharacter pc, IncommingMessage msg)
        {
            if (pc.LoginState == PlayerCharacterLoginState.LoginSuccesfull)
            {
                MoveToIncommingMessage msgMoveTo = (MoveToIncommingMessage)msg;

                pc.LocationMoveTo(msgMoveTo.X, msgMoveTo.Y);
            }
        }
コード例 #7
0
        public void ProcessMessage(IncommingMessage incommingMessage)
        {
            switch (incommingMessage.Type)
            {
            case MessageType.REQUEST_PLAYER_NAME:
                _messageSender.SendMessage(CreatePlayerNameMessage(), _playerName);
                break;

            case MessageType.REQUEST_SESSION_CHOICE:
                _messageSender.SendMessage(CreateSessionChoiceMessage(), _playerName);
                break;

            case MessageType.SESSION_JOINED:
                // TODO
                break;

            case MessageType.DEAL_CARDS:
                _gameState.MyCards.UnionWith(incommingMessage.Cards);
                break;

            case MessageType.REQUEST_TRUMPF:
                var trumpf = new TrumpfChooser().ChooseTrumpf(_gameState.MyCards, incommingMessage.SchiebenAllowed);
                if (!trumpf.Mode.Equals(TrumpfMode.SCHIEBE))
                {
                    _gameState.DidNotSchiebe = true;
                }
                _messageSender.SendMessage(CreateChooseTrumpfMessage(trumpf), _playerName);
                break;

            case MessageType.BROADCAST_TRUMPF:
                _gameState.Trumpf = incommingMessage.Trumpf;
                break;

            case MessageType.REQUEST_CARD:
                _gameState.CardsOnTable = incommingMessage.CardsOnTable;
                var card = _cardChooser.ChooseCard(_gameState);
                _gameState.MyCards.Remove(card);
                _messageSender.SendMessage(CreateChooseCardMessage(card), _playerName);
                break;

            case MessageType.BROADCAST_STICH:
                Console.WriteLine(_playerName + ": " + incommingMessage.Stich);
                _gameState.StartNextRound();
                break;

            // One game finished (9 rounds)
            case MessageType.BROADCAST_GAME_FINISHED:
                _gameState.ResetAfterGameRound();
                break;

            case MessageType.BROADCAST_WINNER_TEAM:
                Console.Write("Game #" + _numberOfGamesPlayed + "Finished! Press any key to play another game.");
                _gameState = new GameState();
                _numberOfGamesPlayed++;
                break;
            }
        }
コード例 #8
0
        private void handleMoveInventoryItem(PlayerCharacter pc, IncommingMessage msg)
        {
            if (pc.LoginState == PlayerCharacterLoginState.LoginSuccesfull)
            {
                MoveInventoryItemIncommingMessage msgMoveInventoryItem =
                    (MoveInventoryItemIncommingMessage)msg;

                pc.InventoryMoveItemInInventory(msgMoveInventoryItem.Slot, msgMoveInventoryItem.NewSlot);
            }
        }
コード例 #9
0
        private void handleDropItem(PlayerCharacter pc, IncommingMessage msg)
        {
            if (pc.LoginState == PlayerCharacterLoginState.LoginSuccesfull)
            {
                DropItemIncommingMessage msgDropItem =
                    (DropItemIncommingMessage)msg;

                pc.InventoryDropItemToGround(msgDropItem.Slot, msgDropItem.Quantity);
            }
        }
コード例 #10
0
        private void handleLookAtInventoryItem(PlayerCharacter pc, IncommingMessage msg)
        {
            if (pc.LoginState == PlayerCharacterLoginState.LoginSuccesfull)
            {
                LookAtInventoryItemIncommingMessage msgLookAtInventoryItem =
                    (LookAtInventoryItemIncommingMessage)msg;

                pc.InventoryLookAtItem(msgLookAtInventoryItem.Slot);
            }
        }
コード例 #11
0
        private void handleAttackSomeone(PlayerCharacter pc, IncommingMessage msg)
        {
            if (pc.LoginState == PlayerCharacterLoginState.LoginSuccesfull)
            {
                AttackSomeoneClientMessage msgAttackSomeone =
                    (AttackSomeoneClientMessage)msg;

                Entity en = getEntityByEntityID((ushort)msgAttackSomeone.TargetObjectID);

                if (en == null)
                    return;

                pc.CombatInitiateAttack(en as EntityImplementation);
            }
        }
コード例 #12
0
        private void handleRespondToNPC(PlayerCharacter pc, IncommingMessage msg)
        {
            if (pc.LoginState == PlayerCharacterLoginState.LoginSuccesfull)
            {
                RespondToNPCIncommingMessage msgRespondToNPC = (RespondToNPCIncommingMessage)msg;

                Entity en = getEntityByEntityID(msgRespondToNPC.TargetEntityID);

                if ((en != null) && (en is ServerCharacter))
                {
                    // Can talk only to server characters
                    pc.NPCConversationRespond((en as ServerCharacter), msgRespondToNPC.OptionID);
                }
            }
        }
コード例 #13
0
        private void handleTouchPlayer(PlayerCharacter pc, IncommingMessage msg)
        {
            if (pc.LoginState == PlayerCharacterLoginState.LoginSuccesfull)
            {
                TouchPlayerIncommingMessage msgTouchPlayer = (TouchPlayerIncommingMessage)msg;

                Entity en = getEntityByEntityID(msgTouchPlayer.TargetEntityID);

                if ((en != null) && (en is ServerCharacter))
                {
                    // Can talk only to server characters
                    pc.NPCConversationStart(en as ServerCharacter);
                }
            }
        }
コード例 #14
0
        private void handleSitDown(PlayerCharacter pc, IncommingMessage msg)
        {
            if (pc.LoginState == PlayerCharacterLoginState.LoginSuccesfull)
            {
                SitDownIncommingMessage msgSitDown = (SitDownIncommingMessage)msg;

                if (msgSitDown.ShouldSit)
                {
                    pc.LocationSitDown();
                }
                else
                {
                    pc.LocationStandUp();
                }
            }
        }
コード例 #15
0
        private void handleRawText(PlayerCharacter pc, IncommingMessage msg)
        {
            if (pc.LoginState == PlayerCharacterLoginState.LoginSuccesfull)
            {
                RawTextIncommingMessage msgRawText = (RawTextIncommingMessage)msg;

                // Handling for different types of raw text
                // TODO: Rewrite - add a separate module for handling server commands
                switch (msgRawText.Text[0])
                {
                    case('#'):
                        if (msgRawText.Text.ToLower() == "#save")
                        {
                            RawTextOutgoingMessage msgRawTextOut =
                                (RawTextOutgoingMessage)OutgoingMessagesFactory.Create(OutgoingMessageType.RAW_TEXT);
                            msgRawTextOut.Channel = PredefinedChannel.CHAT_LOCAL;

                            try
                            {
                                pc.Serialize(pcSerializer);
                                msgRawTextOut.Text = "Another page in Book of Life is filled...";
                                msgRawTextOut.Color = PredefinedColor.Blue1;
                            }
                            catch (Exception ex)
                            {
                                logger.LogError(LogSource.World, "Failed to serialize player " + pc.Name, ex);
                                msgRawTextOut.Text = "Your page in Book of Life remains blank...";
                                msgRawTextOut.Color = PredefinedColor.Red2;
                            }

                            pc.PutMessageIntoMyQueue(msgRawTextOut);
                            return;
                        }
                        if (msgRawText.Text.ToLower() == "#list_commands")
                        {
                            RawTextOutgoingMessage msgRawTextOut =
                                (RawTextOutgoingMessage)OutgoingMessagesFactory.Create(OutgoingMessageType.RAW_TEXT);
                            msgRawTextOut.Channel = PredefinedChannel.CHAT_LOCAL;
                            msgRawTextOut.Color = PredefinedColor.Green3;
                            msgRawTextOut.Text = "Available commands: list_commands, save, follow, stop_following, release_followers, list_skills";
                            pc.PutMessageIntoMyQueue(msgRawTextOut);
                            return;
                        }
                        if (msgRawText.Text.ToLower() == "#stop_following")
                        {
                            pc.FollowingStopFollowing();
                            return;
                        }
                        if (msgRawText.Text.ToLower() == "#release_followers")
                        {
                            pc.FollowingReleaseFollowers();
                            return;
                        }
                        if (msgRawText.Text.ToLower().IndexOf("#follow") == 0)
                        {
                            RawTextOutgoingMessage msgRawTextOut =
                                (RawTextOutgoingMessage)OutgoingMessagesFactory.Create(OutgoingMessageType.RAW_TEXT);
                            msgRawTextOut.Channel = PredefinedChannel.CHAT_LOCAL;

                            string[] tokens = msgRawText.Text.Split(' ');
                            if (tokens.Length != 2)
                            {
                                msgRawTextOut.Color = PredefinedColor.Red2;
                                msgRawTextOut.Text = "You are replied by silence...";
                                pc.PutMessageIntoMyQueue(msgRawTextOut);
                                return;
                            }

                            // Does character exist
                            PlayerCharacter pcTakenByHand = getPlayerByName(tokens[1]);
                            if (pcTakenByHand == null)
                            {
                                msgRawTextOut.Color = PredefinedColor.Blue1;
                                msgRawTextOut.Text = "The one you seek is not here...";
                                pc.PutMessageIntoMyQueue(msgRawTextOut);
                                return;
                            }

                            pc.FollowingFollow(pcTakenByHand);

                            return;
                        }
                        if ((msgRawText.Text.ToLower().IndexOf("#change_health") != -1) &&
                            serverConfiguration.EnableTestCommands)
                        {
                            string[] tokens = msgRawText.Text.Split(' ');
                            short changeVal = Convert.ToInt16(tokens[1]);
                            pc.EnergiesUpdateHealth(changeVal);
                            return;
                        }
                        if ((msgRawText.Text.ToLower().IndexOf("#resurrect") != -1) &&
                            serverConfiguration.EnableTestCommands)
                        {
                            pc.EnergiesResurrect();
                            return;
                        }

                        if ((msgRawText.Text.ToLower().IndexOf("#add_item") != -1) &&
                            serverConfiguration.EnableTestCommands)
                        {
                            string[] tokens = msgRawText.Text.Split(' ');
                            if (tokens.Length != 3)
                                return;

                            ushort itemID = Convert.ToUInt16(tokens[1]);
                            int quantity = Convert.ToInt32(tokens[2]);

                            ItemDefinition itmDef = ItemDefinitionCache.GetItemDefinitionByID(itemID);
                            if (itmDef == null)
                                return;
                            Item itm = new Item(itmDef);
                            itm.Quantity = quantity;
                            pc.InventoryUpdateItem(itm);

                        }
                        if (msgRawText.Text.ToLower() == "#list_skills")
                        {
                            pc.SkillsListSkills();
                        }
                        break;
                    default:
                        break;
                }
            }
        }
コード例 #16
0
        // TODO: Temporary implemenation. Must use sripting/configuration external to server for handling actions connected with map objects usage
        // TODO: Add checking distance from object. Execute only if close enough
        // TODO: If change map fails and player move to IP, display massage and stop script
        private void handleUseMapObject(PlayerCharacter pc, IncommingMessage msg)
        {
            if (pc.LoginState == PlayerCharacterLoginState.LoginSuccesfull)
            {
                UseMapObjectIncommingMessage msgUseMapObject = (UseMapObjectIncommingMessage)msg;

                // Right now only handling for changing IP and IP insides maps!!!
                switch (pc.LocationCurrentMap.Name)
                {
                    case ("calindor_startmap.elm"):
                        {
                            switch (msgUseMapObject.TargetObjectID)
                            {
                                case(78):
                                    {
                                        pc.LocationChangeLocation(118, 35);
                                        break;
                                    }
                            }
                            break;
                        }
                    /*case ("startmap.elm"):
                        {
                            switch (msgUseMapObject.TargetObjectID)
                            {
                                case (501): // Secret location
                                    {
                                        RawTextOutgoingMessage msgToSender =
                                            (RawTextOutgoingMessage)OutgoingMessagesFactory.Create(OutgoingMessageType.RAW_TEXT);
                                        msgToSender.Color = PredefinedColor.Blue1;
                                        msgToSender.Channel = PredefinedChannel.CHAT_LOCAL;
                                        msgToSender.Text = "The world blurs... and you are taken to a place you didn't expect...";
                                        pc.PutMessageIntoMyQueue(msgToSender);

                                        pc.LocationChangeMap("cont2map5_insides.elm",606,133);
                                        break;
                                    }
                                case (520): // Movement to WS
                                    {
                                        RawTextOutgoingMessage msgToSender =
                                            (RawTextOutgoingMessage)OutgoingMessagesFactory.Create(OutgoingMessageType.RAW_TEXT);
                                        msgToSender.Color = PredefinedColor.Blue1;
                                        msgToSender.Channel = PredefinedChannel.CHAT_LOCAL;
                                        msgToSender.Text = "This land seems deserted and dead...";
                                        pc.PutMessageIntoMyQueue(msgToSender);

                                        pc.LocationChangeMap("map2.elm", 707, 162);
                                        break;
                                    }
                                case (1137): // IP cave
                                    {
                                        pc.LocationChangeMap("misc1.elm", 60, 138);
                                        break;
                                    }
                                case (73): // IP House, near veggies
                                    {
                                        pc.LocationChangeMap("startmap_insides.elm", 57, 13);
                                        break;
                                    }
                                case (63): // IP House, grandma
                                    {
                                        pc.LocationChangeMap("startmap_insides.elm", 15, 55);
                                        break;
                                    }
                                case (72): // IP Tavern
                                    {
                                        pc.LocationChangeMap("startmap_insides.elm", 18, 13);
                                        break;
                                    }
                                case (193): // IP hause - locked
                                    {
                                        RawTextOutgoingMessage msgToSender =
                                            (RawTextOutgoingMessage)OutgoingMessagesFactory.Create(OutgoingMessageType.RAW_TEXT);
                                        msgToSender.Color = PredefinedColor.Blue1;
                                        msgToSender.Channel = PredefinedChannel.CHAT_LOCAL;
                                        msgToSender.Text = "You hear strange noises as you approach... and the doors are locked...";
                                        pc.PutMessageIntoMyQueue(msgToSender);
                                        break;
                                    }
                                case (97): // IP hause - south of closed hause
                                    {
                                        pc.LocationChangeMap("startmap_insides.elm", 52, 49);
                                        break;
                                    }
                                case (1023): // IP tower
                                    {
                                        pc.LocationChangeMap("map7_insides.elm", 19, 66);
                                        break;
                                    }
                                default:
                                    break;
                            }

                            break;
                        }
                    case ("startmap_insides.elm"):
                        {
                            switch (msgUseMapObject.TargetObjectID)
                            {
                                case (110): // IP House, near veggies
                                    {
                                        pc.LocationChangeMap("startmap.elm", 98, 162);
                                        break;
                                    }
                                case (108): // IP House, grandma
                                    {
                                        pc.LocationChangeMap("startmap.elm", 74, 150);
                                        break;
                                    }
                                case (107): // IP Tavern
                                    {
                                        pc.LocationChangeMap("startmap.elm", 66, 132);
                                        break;
                                    }
                                case (109): // IP House, hause near locked hause
                                    {
                                        pc.LocationChangeMap("startmap.elm", 89, 106);
                                        break;
                                    }
                                default:
                                    break;
                            }

                            break;
                        }
                    case ("map7_insides.elm"):
                        {
                            switch (msgUseMapObject.TargetObjectID)
                            {
                                case (1309): // IP Tower
                                    {
                                        pc.LocationChangeMap("startmap.elm", 122, 154);
                                        break;
                                    }
                            }

                            break;
                        }
                    case ("misc1.elm"):
                        {
                            switch (msgUseMapObject.TargetObjectID)
                            {
                                case (459): // IP cave
                                    {
                                        pc.LocationChangeMap("startmap.elm", 41, 69);
                                        break;
                                    }
                            }

                            break;
                        }
                    case ("map2.elm"):
                        {
                            switch (msgUseMapObject.TargetObjectID)
                            {
                                case (1015): // Movement from WS
                                    {
                                        pc.LocationChangeMap("startmap.elm", 25, 25);
                                        break;
                                    }
                            }

                            break;
                        }
                    case ("cont2map5_insides.elm"): //PV house
                        {
                            switch (msgUseMapObject.TargetObjectID)
                            {
                                case (2309): // Return from secret place
                                    {
                                        pc.LocationChangeMap("startmap.elm", 101, 147);
                                        break;
                                    }
                                case (2303):
                                    {
                                        pc.LocationChangeLocation(605, 143);
                                        break;
                                    }
                                case (2301):
                                    {
                                        pc.LocationChangeLocation(601,137);
                                        break;
                                    }
                                case (2304):
                                    {
                                        pc.LocationChangeLocation(599, 137);
                                        break;
                                    }
                                case (2302):
                                    {
                                        pc.LocationChangeLocation(605,141);
                                        break;
                                    }
                            }

                            break;
                        }*/
                    default:
                        break;
                }
            }
        }
コード例 #17
0
        private PlayerCharacterSerializer pcSerializer = null; // Used for storing pc data

        #endregion Fields

        #region Methods

        private void handleCreateChar(PlayerCharacter pc, IncommingMessage msg)
        {
            if (pc.LoginState == PlayerCharacterLoginState.ClientVersionCorrect)
            {
                CreateCharIncommingMessage msgCreateChar = (CreateCharIncommingMessage)msg;

                // Is acceptable character name
                if (!pcAuthentication.IsAcceptablePlayerName(msgCreateChar.UserName))
                {
                    CreateCharNotOkOutgoingMessage msgCreateCharNotOk =
                        (CreateCharNotOkOutgoingMessage)OutgoingMessagesFactory.Create(OutgoingMessageType.CREATE_CHAR_NOT_OK);
                    msgCreateCharNotOk.Message = "This character name is not acceptable.";
                    pc.PutMessageIntoMyQueue(msgCreateCharNotOk);
                    return;
                }

                // Does character exist?
                if (pcAuthentication.Exists(msgCreateChar.UserName))
                {
                    // Character already exists
                    CreateCharNotOkOutgoingMessage msgCreateCharNotOk =
                        (CreateCharNotOkOutgoingMessage)OutgoingMessagesFactory.Create(OutgoingMessageType.CREATE_CHAR_NOT_OK);
                    msgCreateCharNotOk.Message = "A character with that name already exists.";
                    pc.PutMessageIntoMyQueue(msgCreateCharNotOk);
                    return;
                }

                // TODO: Add check for appearace values

                // All ok. Create a character
                try
                {
                    pcAuthentication.Create(msgCreateChar.UserName, msgCreateChar.Password);
                }
                catch (Exception ex)
                {
                    logger.LogError(LogSource.World, "Failed to create player " + pc.Name, ex);
                    CreateCharNotOkOutgoingMessage msgCreateCharNotOk =
                        (CreateCharNotOkOutgoingMessage)OutgoingMessagesFactory.Create(OutgoingMessageType.CREATE_CHAR_NOT_OK);
                    msgCreateCharNotOk.Message = "Server could not create the character.";
                    pc.PutMessageIntoMyQueue(msgCreateCharNotOk);
                    return;
                }

                // Clear character (current state of character is undefined!)
                pc.ClearEntityImplementation();

                EntityAppearance appearance = new EntityAppearance(msgCreateChar.Type);

                appearance.Head = msgCreateChar.Head;
                appearance.Skin = msgCreateChar.Skin;
                appearance.Hair = msgCreateChar.Hair;
                appearance.Shirt = msgCreateChar.Shirt;
                appearance.Pants = msgCreateChar.Pants;
                appearance.Boots = msgCreateChar.Boots;
                pc.Name = msgCreateChar.UserName;
                pc.CreateSetInitialAppearance(appearance);

                EntityLocation location = new EntityLocation();
                short deviation = mapManager.StartPointDeviation;
                location.X = (short)(mapManager.StartPointX + (sbyte)WorldRNG.Next(-deviation, deviation));
                location.Y = (short)(mapManager.StartPointY + (sbyte)WorldRNG.Next(-deviation, deviation));
                location.Z = 0;
                location.Rotation = 0;
                location.CurrentMap = mapManager.StartPointMap;
                pc.CreateSetInitialLocation(location);

                // TODO: Apply race specific factors

                // Add bonus items
                ItemDefinition itmDef = null;

                // Royals
                itmDef = ItemDefinitionCache.GetItemDefinitionByID(5);
                if (itmDef != null)
                {
                    Item itm = new Item(itmDef);
                    itm.Quantity = 100;
                    pc.InventoryUpdateItem(itm);
                }

                // Recalculate enerigies
                pc.CreateRecalculateInitialEnergies();

                // Store data
                try
                {
                    pc.ForceSerialization();
                    pc.Serialize(pcSerializer);
                }
                catch (Exception ex)
                {
                    logger.LogError(LogSource.World, "Failed to serialize player " + pc.Name, ex);
                    CreateCharNotOkOutgoingMessage msgCreateCharNotOk =
                        (CreateCharNotOkOutgoingMessage)OutgoingMessagesFactory.Create(OutgoingMessageType.CREATE_CHAR_NOT_OK);
                    msgCreateCharNotOk.Message = "Server could not create the character.";
                    pc.PutMessageIntoMyQueue(msgCreateCharNotOk);
                    return;
                }

                // Send char created ok message
                pc.PutMessageIntoMyQueue(msgStdCreateCharOk);
            }
        }
コード例 #18
0
        private void handleSendVersion(PlayerCharacter pc, IncommingMessage msg)
        {
            if (pc.LoginState == PlayerCharacterLoginState.NotInitialized)
            {
                SendVersionIncommingMessage svMsg = (SendVersionIncommingMessage)msg;

                if (serverConfiguration.CheckProtocolVersion)
                {
                    if (svMsg.ProtocolVersionFirstDigit == ProtocolVersion.FirstDigit &&
                        svMsg.ProtocolVersionSecondDigit == ProtocolVersion.SecondDigit)
                    {
                        pc.LoginState = PlayerCharacterLoginState.ClientVersionCorrect;
                    }
                    else
                    {
                        // Wrong version
                        pc.LoginState = PlayerCharacterLoginState.ClientVersionIncorrect;
                        pc.PutMessageIntoMyQueue(msgStdWrongClientVersion);
                        pc.LoginState = PlayerCharacterLoginState.LoggingOff; // Start purging procedure
                    }
                }
                else
                {
                    // Always correct
                    pc.LoginState = PlayerCharacterLoginState.ClientVersionCorrect;
                }
            }
        }
コード例 #19
0
 private void handleSendOpeningScreen(PlayerCharacter pc, IncommingMessage msg)
 {
     if (pc.LoginState == PlayerCharacterLoginState.ClientVersionCorrect ||
         pc.LoginState == PlayerCharacterLoginState.LoginSuccesfull)
     {
         // Send opening message
         pc.PutMessageIntoMyQueue(msgStdOpeningMessage);
     }
 }
コード例 #20
0
ファイル: WorldSimulation.cs プロジェクト: ago1024/Calindor
        private void processMessage(PlayerCharacter pc, IncommingMessage msg)
        {
            pc.UpdateHeartBeat();

            try
            {
                switch (msg.MessageType)
                {
                    case (IncommingMessageType.SEND_OPENING_SCREEN):
                        handleSendOpeningScreen(pc, msg);
                        break;
                    case (IncommingMessageType.SEND_VERSION):
                        handleSendVersion(pc, msg);
                        break;
                    case (IncommingMessageType.LOG_IN):
                        handleLogIn(pc, msg);
                        break;
                    case (IncommingMessageType.HEART_BEAT):
                        pc.UpdateHeartBeat();
                        break;
                    case (IncommingMessageType.CREATE_CHAR):
                        handleCreateChar(pc, msg);
                        break;
                    case(IncommingMessageType.MOVE_TO):
                        handleMoveTo(pc, msg);
                        break;
                    case(IncommingMessageType.SEND_PM):
                        handlePM(pc, msg);
                        break;
                    case(IncommingMessageType.SIT_DOWN):
                        handleSitDown(pc, msg);
                        break;
                    case(IncommingMessageType.TURN_LEFT):
                        handleTurnLeft(pc, msg);
                        break;
                    case (IncommingMessageType.TURN_RIGHT):
                        handleTurnRight(pc, msg);
                        break;
                    case (IncommingMessageType.RAW_TEXT):
                        handleRawText(pc, msg);
                        break;
                    case(IncommingMessageType.USE_MAP_OBJECT):
                        handleUseMapObject(pc, msg);
                        break;
                    case(IncommingMessageType.LOOK_AT_INVENTORY_ITEM):
                        handleLookAtInventoryItem(pc, msg);
                        break;
                    case(IncommingMessageType.DROP_ITEM):
                        handleDropItem(pc, msg);
                        break;
                    case(IncommingMessageType.MOVE_INVENTORY_ITEM):
                        handleMoveInventoryItem(pc, msg);
                        break;
                    case(IncommingMessageType.HARVEST):
                        handleHarvest(pc, msg);
                        break;
                    case(IncommingMessageType.TOUCH_PLAYER):
                        handleTouchPlayer(pc, msg);
                        break;
                    case (IncommingMessageType.RESPOND_TO_NPC):
                        handleRespondToNPC(pc, msg);
                        break;
                    case(IncommingMessageType.ATTACK_SOMEONE):
                        handleAttackSomeone(pc, msg);
                        break;
                    default:
                        Logger.LogWarning(LogSource.World,
                            string.Format("Message {0} - no action taken", msg.ToString()), null);
                        break;
                }
            }
            catch (Exception ex)
            {
                Logger.LogError(LogSource.World,
                    string.Format("Failed to process message {0}", msg.ToString()), ex);
            }
        }
コード例 #21
0
        private void handleLogIn(PlayerCharacter pc, IncommingMessage msg)
        {
            if (pc.LoginState == PlayerCharacterLoginState.ClientVersionCorrect)
            {
                LogInIncommingMessage msgLogIn = (LogInIncommingMessage)msg;

                // Is acceptable character name
                if (!pcAuthentication.IsAcceptablePlayerName(msgLogIn.UserName))
                {
                    LogInNotOkOutgoingMessage msgLogInNotOk =
                        (LogInNotOkOutgoingMessage)OutgoingMessagesFactory.Create(OutgoingMessageType.LOG_IN_NOT_OK);
                    msgLogInNotOk.Message = "This character name is not acceptable.";
                    pc.PutMessageIntoMyQueue(msgLogInNotOk);
                    return;
                }

                // Does character exist
                if (!pcAuthentication.Exists(msgLogIn.UserName))
                {
                    pc.PutMessageIntoMyQueue(msgStdYouDontExist);
                    return;
                }

                try
                {
                    // Check the password
                    if (!pcAuthentication.Authenticate(msgLogIn.UserName, msgLogIn.Password))
                    {
                        LogInNotOkOutgoingMessage msgLogInNotOk =
                            (LogInNotOkOutgoingMessage)OutgoingMessagesFactory.Create(OutgoingMessageType.LOG_IN_NOT_OK);
                        msgLogInNotOk.Message = "The password is wrong!";
                        pc.PutMessageIntoMyQueue(msgLogInNotOk);
                        return;
                    }

                }
                catch (Exception ex)
                {
                    logger.LogError(LogSource.World, "Failed to authenticate player: " + pc.Name, ex);
                    LogInNotOkOutgoingMessage msgLogInNotOk =
                        (LogInNotOkOutgoingMessage)OutgoingMessagesFactory.Create(OutgoingMessageType.LOG_IN_NOT_OK);
                    msgLogInNotOk.Message = "Server could not load the character!";
                    pc.PutMessageIntoMyQueue(msgLogInNotOk);
                    return;
                }

                // Check if already logged in
                if (getPlayerByName(msgLogIn.UserName) != null)
                {
                    LogInNotOkOutgoingMessage msgLogInNotOk =
                        (LogInNotOkOutgoingMessage)OutgoingMessagesFactory.Create(OutgoingMessageType.LOG_IN_NOT_OK);
                    msgLogInNotOk.Message = "You are already logged in!";
                    pc.PutMessageIntoMyQueue(msgLogInNotOk);
                    return;
                }

                // Clear character (current state of character is undefined!)
                pc.ClearEntityImplementation();

                pc.Name = msgLogIn.UserName; // Temporary setting user name so that deserialization may work

                // Deserialize user data
                try
                {
                    pc.Deserialize(pcDeserializer);
                }
                catch (Exception ex)
                {
                    logger.LogError(LogSource.World, "Failed to deserialize player: " + pc.Name, ex);
                    LogInNotOkOutgoingMessage msgLogInNotOk =
                        (LogInNotOkOutgoingMessage)OutgoingMessagesFactory.Create(OutgoingMessageType.LOG_IN_NOT_OK);
                    msgLogInNotOk.Message = "Server could not load the character!";
                    pc.PutMessageIntoMyQueue(msgLogInNotOk);
                    return;
                }

                try
                {
                    // Add to dictionaries / Get EntityID
                    addEntityImplementationToWorld(pc);
                }
                catch (Exception ex)
                {
                    logger.LogError(LogSource.World, "Failed to register player: " + pc.Name, ex);
                    LogInNotOkOutgoingMessage msgLogInNotOk =
                        (LogInNotOkOutgoingMessage)OutgoingMessagesFactory.Create(OutgoingMessageType.LOG_IN_NOT_OK);
                    msgLogInNotOk.Message = "Server could not register the character!";
                    pc.PutMessageIntoMyQueue(msgLogInNotOk);
                    return;
                }

                // TODO: Send initial data to client

                // New Minute
                NewMinuteOutgoingMessage msgNewMinute =
                    (NewMinuteOutgoingMessage)OutgoingMessagesFactory.Create(OutgoingMessageType.NEW_MINUTE);
                msgNewMinute.MinuteOfTheDay = calendar.MinuteOfTheDay;
                pc.PutMessageIntoMyQueue(msgNewMinute);

                // You Are
                YouAreOutgoingMessage msgYouAre =
                    (YouAreOutgoingMessage)OutgoingMessagesFactory.Create(OutgoingMessageType.YOU_ARE);
                msgYouAre.EntityID = pc.EntityID;
                pc.PutMessageIntoMyQueue(msgYouAre);

                // Change Map
                pc.LocationChangeMapAtEnterWorld();

                // Here Your Inventory
                HereYourInventoryOutgoingMessage msgHereYourInventory =
                    (HereYourInventoryOutgoingMessage)OutgoingMessagesFactory.Create(OutgoingMessageType.HERE_YOUR_INVENTORY);
                pc.FillOutgoingMessage(msgHereYourInventory);
                pc.PutMessageIntoMyQueue(msgHereYourInventory);

                // Here Your Stats
                HereYourStatsOutgoingMessage msgHereYourStats =
                    (HereYourStatsOutgoingMessage)OutgoingMessagesFactory.Create(OutgoingMessageType.HERE_YOUR_STATS);
                pc.FillOutgoingMessage(msgHereYourStats);
                pc.PutMessageIntoMyQueue(msgHereYourStats);

                // Log In Ok
                pc.PutMessageIntoMyQueue(msgStdLogInOk);

                // All is OK
                pc.LoginState = PlayerCharacterLoginState.LoginSuccesfull;
            }
        }