Пример #1
0
 public void Connect(CityConnectionMode mode, ShardSelectorServletRequest shard)
 {
     if (shard.ShardName == null && this.CurrentShard != null)
     {
         shard.ShardName = this.CurrentShard.ShardName;
     }
     Mode = mode;
     if (CurrentState.Name != "Disconnected")
     {
         CurrentShard = shard;
         AsyncTransition("Reconnect");
     }
     else
     {
         AsyncProcessMessage(shard);
     }
 }
Пример #2
0
        public ShardSelectorServletResponse ShardSelectorServlet(ShardSelectorServletRequest input)
        {
            var client = Client();

            var request = new RestRequest("cityselector/app/ShardSelectorServlet")
                          .AddQueryParameter("shardName", input.ShardName)
                          .AddQueryParameter("avatarId", input.AvatarID);

            var response = client.Execute(request);

            if (response.StatusCode != System.Net.HttpStatusCode.OK)
            {
                throw new Exception("Unknown error during ShardSelectorServlet");
            }

            return(XMLUtils.Parse <ShardSelectorServletResponse>(response.Content));
        }
Пример #3
0
        protected override void OnBeforeTransition(RegulatorState oldState, RegulatorState newState, object data)
        {
            switch (newState.Name)
            {
            case "SelectCity":
                //TODO: Do this on logout / disconnect rather than on connect
                ResetGame();

                var shard = data as ShardSelectorServletRequest;
                if (shard == null)
                {
                    this.ThrowErrorAndReset(new Exception("Unknown parameter"));
                }

                this.AsyncTransition("ConnectToCitySelector", shard);
                break;

            case "ConnectToCitySelector":
                shard               = data as ShardSelectorServletRequest;
                CurrentShard        = shard;
                ShardSelectResponse = CityApi.ShardSelectorServlet(shard);
                this.AsyncProcessMessage(ShardSelectResponse);
                break;

            case "CitySelected":
                this.AsyncProcessMessage(data);
                break;

            case "OpenSocket":
                var settings = data as ShardSelectorServletResponse;
                if (settings == null)
                {
                    this.ThrowErrorAndReset(new Exception("Unknown parameter"));
                }
                else
                {
                    //101 is plain
                    Client.Connect(settings.Address + "101");
                }
                break;

            case "SocketOpen":
                break;

            case "RequestClientSession":
                Client.Write(new RequestClientSessionResponse {
                    Password = ShardSelectResponse.Ticket,
                    User     = ShardSelectResponse.PlayerID.ToString()
                });
                break;

            case "HostOnline":
                ((ClientShards)Shards).CurrentShard = Shards.GetByName(CurrentShard.ShardName).Id;

                Client.Write(
                    new ClientOnlinePDU {
                },
                    new SetIgnoreListPDU {
                    PlayerIds = new List <uint>()
                },
                    new SetInvinciblePDU {
                    Action = 0
                }
                    );
                AsyncTransition("PartiallyConnected");
                break;

            case "PartiallyConnected":
                if (Mode == CityConnectionMode.NORMAL)
                {
                    AsyncTransition("AskForAvatarData");
                }
                break;

            case "CompletePartialConnection":
                var shardRequest = (ShardSelectorServletRequest)data;
                if (shardRequest.ShardName != CurrentShard.ShardName)
                {
                    //Should never get into this state
                    throw new Exception("You cant complete a partial connection for a different city");
                }
                CurrentShard = shardRequest;
                AsyncTransition("AskForAvatarData");
                break;

            case "AskForAvatarData":
                DB.LoadAvatarById(new LoadAvatarByIDRequest
                {
                    AvatarId = uint.Parse(CurrentShard.AvatarID)
                }).ContinueWith(x =>
                {
                    if (x.IsFaulted)
                    {
                        ThrowErrorAndReset(new Exception("Failed to load avatar from db"));
                    }
                    else
                    {
                        AsyncProcessMessage(x.Result);
                    }
                });
                break;

            case "ReceivedAvatarData":
                AsyncTransition("AskForCharacterData");
                break;

            case "AskForCharacterData":
                DataService.Request(MaskedStruct.MyAvatar, uint.Parse(CurrentShard.AvatarID)).ContinueWith(x =>
                {
                    if (x.IsFaulted)
                    {
                        ThrowErrorAndReset(new Exception("Failed to load character from db"));
                    }
                    else
                    {
                        AsyncTransition("ReceivedCharacterData");
                    }
                });
                break;

            case "ReceivedCharacterData":
                //For now, we will call this connected
                AsyncTransition("Connected");
                break;

            case "Connected":
                break;

            case "UnexpectedDisconnect":
                FSOFacade.Controller.FatalNetworkError(23);
                break;

            case "Disconnect":
                ShardSelectResponse = null;
                if (Client.IsConnected)
                {
                    Client.Write(new ClientByePDU());
                    Client.Disconnect();
                }
                else
                {
                    AsyncTransition("Disconnected");
                }
                break;

            case "Reconnect":
                ShardSelectResponse = null;
                if (Client.IsConnected)
                {
                    Client.Write(new ClientByePDU());
                    Client.Disconnect();
                }
                else
                {
                    AsyncTransition("Reconnecting");
                }
                break;

            case "Reconnecting":
                AsyncProcessMessage(CurrentShard);
                break;

            case "Disconnected":
                ((ClientShards)Shards).CurrentShard = null;
                break;
            }
        }