Esempio n. 1
0
        protected override void OnAfterTransition(RegulatorState oldState, RegulatorState newState, object data)
        {
            switch (newState.Name)
            {
            case "SelectLot":
                IsDisconnecting = false;
                AsyncTransition("FindLot", data);
                break;

            case "FindLot":
                //LotId = ((JoinLotRequest)data).LotId;
                City.Write(new FSO.Server.Protocol.Electron.Packets.FindLotRequest {
                    LotId = ((JoinLotRequest)data).LotId
                });
                break;

            case "FoundLot":
                var result = (FindLotResponse)data;
                if (result.Status == Server.Protocol.Electron.Model.FindLotResponseStatus.FOUND)
                {
                    LotId           = result.LotId;
                    FindLotResponse = result;
                    AsyncTransition("OpenSocket", result.Address);
                }
                else
                {
                    ThrowErrorAndReset(result.Status);
                }
                break;

            case "OpenSocket":
                ReestablishAttempt = 0;
                var address = data as string;
                LastAddress = address;
                if (address == null)
                {
                    this.ThrowErrorAndReset(new Exception("Unknown parameter"));
                }
                else
                {
                    //101 is plain
                    Client.Connect(address + "101");
                }
                break;

            case "SocketOpen":
                break;

            case "RequestClientSession":
                Client.Write(new RequestClientSessionResponse
                {
                    Password = FindLotResponse.LotServerTicket,
                    User     = FindLotResponse.User
                });
                break;

            case "HostOnline":
                Client.Write(
                    new ClientOnlinePDU
                {
                }
                    );

                AsyncTransition("PartiallyConnected");

                //When we join a property, get the lot info to update the thumbnail cache
                DataService.Request(Server.DataService.Model.MaskedStruct.PropertyPage_LotInfo, LotId);
                break;

            case "UnexpectedDisconnect":
                if (ReestablishAttempt > 0)
                {
                    IsDisconnecting = true;
                    AsyncTransition("Disconnected");
                }
                else
                {
                    GameThread.SetTimeout(() =>
                    {
                        if (CurrentState?.Name == "UnexpectedDisconnect")
                        {
                            AsyncTransition("Reestablish");
                        }
                        else if (CurrentState?.Name != "Disconnected")
                        {
                            IsDisconnecting = true;
                            AsyncTransition("Disconnected");
                        }
                    }, 100);
                }
                break;

            case "Reestablish":
                ReestablishAttempt++;
                Client.Connect(LastAddress + "101");
                break;

            case "Reestablishing":
                Client.Write(new RequestClientSessionResponse
                {
                    Password = FindLotResponse.LotServerTicket,
                    User     = FindLotResponse.User,
                    Unknown2 = 1
                });
                break;

            case "Reestablished":
                Client.Write(
                    new ClientOnlinePDU
                {
                }
                    );
                ReestablishAttempt = 0;
                AsyncTransition("LotCommandStream");
                break;

            case "ReestablishFail":
                if (ReestablishAttempt < 10)
                {
                    GameThread.SetTimeout(() =>
                    {
                        if (CurrentState?.Name == "ReestablishFail")
                        {
                            AsyncTransition("Reestablish");
                        }
                    }, 1000);
                }
                else
                {
                    AsyncTransition("UnexpectedDisconnect");
                }
                break;


            case "Disconnect":
                if (Client.IsConnected && !IsDisconnecting)
                {
                    Client.Write(new ClientByePDU());
                    Client.Disconnect();

                    //When we leave a property, get the lot info to update the thumbnail cache
                    DataService.Request(Server.DataService.Model.MaskedStruct.PropertyPage_LotInfo, LotId);
                }
                else
                {
                    AsyncTransition("Disconnected");
                }
                break;

            case "Disconnected":
                ReestablishAttempt = 0;
                break;
            }
        }
Esempio n. 2
0
        protected override void OnAfterTransition(RegulatorState oldState, RegulatorState newState, object data)
        {
            switch (newState.Name)
            {
            case "SelectLot":
                IsDisconnecting = false;
                AsyncTransition("FindLot", data);
                break;

            case "FindLot":
                //LotId = ((JoinLotRequest)data).LotId;
                City.Write(new FindLotRequest
                {
                    LotId = ((JoinLotRequest)data).LotId
                });
                break;

            case "FoundLot":
                var result = (FindLotResponse)data;
                if (result.Status == Server.Protocol.Electron.Model.FindLotResponseStatus.FOUND)
                {
                    LotId           = result.LotId;
                    FindLotResponse = result;
                    AsyncTransition("OpenSocket", result.Address);
                }
                else
                {
                    ThrowErrorAndReset(result.Status);
                }
                break;

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

            case "SocketOpen":
                break;

            case "RequestClientSession":
                Client.Write(new RequestClientSessionResponse
                {
                    Password = FindLotResponse.LotServerTicket,
                    User     = FindLotResponse.User
                });
                break;

            case "HostOnline":
                Client.Write(
                    new ClientOnlinePDU
                {
                }
                    );

                AsyncTransition("PartiallyConnected");

                //When we join a property, get the lot info to update the thumbnail cache
                DataService.Request(Server.DataService.Model.MaskedStruct.PropertyPage_LotInfo, LotId);
                break;

            case "UnexpectedDisconnect":
                IsDisconnecting = true;
                AsyncTransition("Disconnected");
                break;

            case "Disconnect":
                if (Client.IsConnected && !IsDisconnecting)
                {
                    Client.Write(new ClientByePDU());
                    Client.Disconnect();

                    //When we leave a property, get the lot info to update the thumbnail cache
                    DataService.Request(Server.DataService.Model.MaskedStruct.PropertyPage_LotInfo, LotId);
                }
                else
                {
                    AsyncTransition("Disconnected");
                }
                break;
            }
        }