コード例 #1
0
        public async Task <IActionResult> Handle()
        {
            Output = new JoinMapByCharName();

            //If ZoneName is empty, look it up from the character.  This is used for the inital login.
            if (String.IsNullOrEmpty(ZoneName) || ZoneName == "GETLASTZONENAME")
            {
                GetCharByCharName character = await charactersRepository.GetCharByCharName(CustomerGUID, CharacterName);

                //If we can't find the character by name, then return BadRequest.
                if (character == null)
                {
                    return(new BadRequestResult());
                }

                ZoneName = character.MapName;
            }

            //If the ZoneName is empty, return an error
            if (String.IsNullOrEmpty(ZoneName))
            {
                Output.Success      = false;
                Output.ErrorMessage = "GetServerToConnectTo: ZoneName is NULL or Empty.  Make sure the character is assigned to a Zone!";
                return(new OkObjectResult(Output));
            }

            JoinMapByCharName joinMapByCharacterName = await charactersRepository.JoinMapByCharName(CustomerGUID, CharacterName, ZoneName, PlayerGroupType);

            bool readyForPlayersToConenct = false;

            if (joinMapByCharacterName == null || joinMapByCharacterName.WorldServerID < 1)
            {
                Output.Success      = false;
                Output.ErrorMessage = "GetServerToConnectTo: WorldServerID is less than 1.  Make sure you setup at least one valid World Server and that it is currently running!";
                return(new OkObjectResult(Output));
            }

            //There is no zone server running that will accept our connection, so start up a new one
            if (joinMapByCharacterName.NeedToStartupMap)
            {
                bool requestSuccess = await RequestServerSpinUp(joinMapByCharacterName.WorldServerID, joinMapByCharacterName.MapInstanceID, joinMapByCharacterName.MapNameToStart, joinMapByCharacterName.Port);

                //Wait OWSGeneralConfig.SecondsToWaitBeforeFirstPollForSpinUp seconds before the first CheckMapInstanceStatus to give it time to spin up
                System.Threading.Thread.Sleep(owsGeneralConfig.Value.SecondsToWaitBeforeFirstPollForSpinUp);

                readyForPlayersToConenct = await WaitForServerReadyToConnect(CustomerGUID, joinMapByCharacterName.MapInstanceID);
            }
            //We found a zone server we can connect to, but it is still spinning up.  Wait until it is ready to connect to (up to OWSGeneralConfig.SecondsToWaitForServerSpinUp seconds).
            else if (joinMapByCharacterName.MapInstanceID > 0 && joinMapByCharacterName.MapInstanceStatus == 1)
            {
                //CheckMapInstanceStatus every OWSGeneralConfig.SecondsToWaitInBetweenSpinUpPolling seconds for up to OWSGeneralConfig.SecondsToWaitForServerSpinUp seconds
                readyForPlayersToConenct = await WaitForServerReadyToConnect(CustomerGUID, joinMapByCharacterName.MapInstanceID);
            }
            //We found a zone server we can connect to and it is ready to connect
            else if (joinMapByCharacterName.MapInstanceID > 0 && joinMapByCharacterName.MapInstanceStatus == 2)
            {
                //The zone server is ready to connect to
                readyForPlayersToConenct = true;
            }

            //The zone instance is ready, so connect the character to the map instance in our data store
            if (readyForPlayersToConenct)
            {
                await charactersRepository.AddCharacterToMapInstanceByCharName(CustomerGUID, CharacterName, joinMapByCharacterName.MapInstanceID);
            }

            Output              = joinMapByCharacterName;
            Output.Success      = true;
            Output.ErrorMessage = "";
            return(new OkObjectResult(Output));
        }
コード例 #2
0
        public async Task <IActionResult> Handle()
        {
            if (String.IsNullOrEmpty(ZoneName) || ZoneName == "GETLASTZONENAME")
            {
                GetCharByCharName character = await charactersRepository.GetCharByCharName(CustomerGUID, CharacterName);

                if (character == null || String.IsNullOrEmpty(character.MapName))
                {
                    return(new BadRequestResult());
                }

                ZoneName = character.MapName;
            }

            JoinMapByCharName joinMapByCharacterName = await charactersRepository.JoinMapByCharName(CustomerGUID, CharacterName, ZoneName, PlayerGroupType);

            bool readyForPlayersToConenct = false;

            if (joinMapByCharacterName.NeedToStartupMap)
            {
                var factory = new ConnectionFactory()
                {
                    HostName = "localhost"
                };

                using (var connection = factory.CreateConnection())
                {
                    using (var channel = connection.CreateModel())
                    {
                        channel.ExchangeDeclare(exchange: "ServerSpinUp",
                                                type: "direct",
                                                durable: false,
                                                autoDelete: false);

                        /*channel.QueueDeclare(queue: "ServerSpinUp",
                         *  durable: false,
                         *  exclusive: false,
                         *  autoDelete: false,
                         *  arguments: null);*/

                        MQSpinUpServerMessage testMessage = new MQSpinUpServerMessage();
                        testMessage.WorldServerID = joinMapByCharacterName.WorldServerID;
                        testMessage.MapName       = ZoneName;
                        testMessage.Port          = joinMapByCharacterName.WorldServerPort;

                        var body = testMessage.SerialiseIntoBinary();

                        channel.BasicPublish(exchange: "ServerSpinUp",
                                             routingKey: String.Format("ServerSpinUp.{0}" + joinMapByCharacterName.WorldServerID),
                                             basicProperties: null,
                                             body: body);
                    }
                }

                //Wait 5 seconds before the first CheckMapInstanceStatus to give it time to spin up
                System.Threading.Thread.Sleep(5);

                readyForPlayersToConenct = await WaitForServerReadyToConnect(joinMapByCharacterName.MapInstanceID);
            }
            else if (joinMapByCharacterName.MapInstanceID > 0 && joinMapByCharacterName.MapInstanceStatus == 1)
            {
                //CheckMapInstanceStatus every 2 seconds for up to 90 seconds
                readyForPlayersToConenct = await WaitForServerReadyToConnect(joinMapByCharacterName.MapInstanceID);
            }
            else if (joinMapByCharacterName.MapInstanceID > 0 && joinMapByCharacterName.MapInstanceStatus == 2)
            {
                //The zone server is ready to connect to
                readyForPlayersToConenct = true;
            }

            Output = joinMapByCharacterName;
            return(new OkObjectResult(Output));
        }