コード例 #1
0
        void Work()
        {
            State nextState = State.Initial;
            State actState  = State.Initial;
            State prevState = State.Initial;

            while (true)
            {
                Events events = (Events)notify.WaitOne();

                switch (actState)
                {
                case State.Initial:
                    nextState = State.Detached;
                    break;

                case State.Detached:
                    memoryManager.attach(map.ProcessName);
                    if (memoryManager.IsAttached())
                    {
                        nextState = State.Attached;
                    }
                    break;

                case State.Attached:
                    if (!memoryManager.IsAttached())
                    {
                        nextState = State.Detached;
                    }
                    PlayerInfo Playerinfo = new PlayerInfo();
                    Playerinfo.DirXPos    = GetFloat(map.AddressDirX);
                    Playerinfo.DirYPos    = GetFloat(map.AddressDirY);
                    Playerinfo.LocXPos    = GetFloat(map.AddressLocX);
                    Playerinfo.LocYPos    = GetFloat(map.AddressLocY);
                    Playerinfo.LastUpdate = DateTime.Now;
                    OnPlayerInfoUpdate?.Invoke(this, Playerinfo);
                    break;
                }


                if (actState != nextState)
                {
                    notify.SetBits((UInt32)Events.StateChanged);
                    prevState = actState;
                    actState  = nextState;
                    Console.WriteLine($"{this.GetType().Name}: State change '{prevState}' => {actState}");
                }
            }
        }
コード例 #2
0
        void Work()
        {
            State nextState = State.Initial;
            State actState  = State.Initial;
            State prevState = State.Initial;

            while (true)
            {
                Events events = (Events)notify.WaitOne();

                switch (actState)
                {
                case State.Initial:
                    if (socket.IsConnected)
                    {
                        nextState = State.ConnectedNoLease;
                    }
                    else if (socket.IsConnecting)
                    {
                    }
                    else
                    {
                        socket.ConnectAsync(Settings.ConnectionServer);
                    }
                    break;

                case State.ConnectedNoLease:

                    if (events.HasFlag(Events.Disconnected))
                    {
                        nextState = State.Disconnected;
                    }
                    else if (client.HasLease)
                    {
                        nextState = State.ConnectedWithLease;
                    }

                    break;

                case State.ConnectedWithLease:
                    if (events.HasFlag(Events.Disconnected))
                    {
                        nextState = State.Disconnected;
                    }
                    else if (!client.HasLease)
                    {
                        nextState = State.ConnectedNoLease;
                    }
                    else
                    {
                        //We are connected and have a lease.


                        foreach (PlayerInfo tx in tileClients)
                        {
                            foreach (PlayerInfo rx in tileClients.Where(p => p != tx))
                            {
                                client.SendMessage(rx.ID, serializer.Serialize(new TileCMD_UpdatePlayerInfo()
                                {
                                    Playerinfo = tx
                                }));
                            }
                        }



                        TileBaseCmd cmd;
                        if (commands.TryDequeue(out cmd))
                        {
                            ProcessCommand(cmd);
                            if (commands.Any())
                            {
                                notify.SetBits((UInt32)Events.CommandRecieved);
                            }
                        }
                    }
                    break;
                }


                if (actState != nextState)
                {
                    notify.SetBits((UInt32)Events.StateChanged);
                    prevState = actState;
                    actState  = nextState;
                    Console.WriteLine($"{this.GetType().Name}: State change '{prevState}' => {actState}");
                }
            }
        }
コード例 #3
0
ファイル: TileMapClient.cs プロジェクト: vanBassum/TileMap
        void Work()
        {
            State nextState = State.Initial;
            State actState  = State.Initial;
            State prevState = State.Initial;

            while (true)
            {
                Events events = (Events)notify.WaitOne();

                switch (actState)
                {
                case State.Initial:
                    if (socket.IsConnected)
                    {
                        nextState = State.ConnectedNoLease;
                    }
                    else if (socket.IsConnecting)
                    {
                    }
                    else
                    {
                        socket.ConnectAsync(Settings.ConnectionServer);
                    }
                    break;

                case State.ConnectedNoLease:

                    if (events.HasFlag(Events.Disconnected))
                    {
                        nextState = State.Disconnected;
                    }
                    else if (client.HasLease)
                    {
                        nextState = State.ConnectedWithLease;
                    }

                    break;

                case State.ConnectedWithLease:
                    if (events.HasFlag(Events.Disconnected))
                    {
                        nextState = State.Disconnected;
                    }
                    else if (!client.HasLease)
                    {
                        nextState = State.ConnectedNoLease;
                    }
                    else
                    {
                        //We are connected and have a lease.
                        //Find all servers and wait for the user to connect to one.

                        client.RequestSoftwareID(SoftwareID.TileMapServer);

                        lock (Servers)
                        {
                            foreach (TileServer serv in Servers.Where(a => a.Name == null))
                            {
                                client.SendMessage(serv.ID, serializer.Serialize(new TileCMD_GetServername()));
                            }
                        }

                        if (commands.Any())
                        {
                            TileBaseCmd cmd = commands.Dequeue();
                            ProcessCommand(cmd);
                            if (commands.Any())
                            {
                                notify.SetBits((UInt32)Events.CommandRecieved);
                            }
                        }

                        if (SelectedServer != null)
                        {
                            nextState = State.ConnectedToServer;
                        }
                    }
                    break;


                case State.ConnectedToServer:
                    if (events.HasFlag(Events.Disconnected))
                    {
                        nextState = State.Disconnected;
                    }
                    else if (!client.HasLease)
                    {
                        nextState = State.ConnectedNoLease;
                    }
                    else
                    {
                        if (events.HasFlag(Events.StateChanged))
                        {
                            //Request the map from the server
                            client.SendMessage(SelectedServer.ID, serializer.Serialize(new TileCMD_GetMapInfo()));
                        }

                        if (events.HasFlag(Events.UpdatePlayerInfo))
                        {
                            playerinfo.ID = client.ID;
                            client.SendMessage(SelectedServer.ID, serializer.Serialize(new TileCMD_UpdatePlayerInfo()
                            {
                                Playerinfo = playerinfo
                            }));
                        }

                        if (commands.Any())
                        {
                            TileBaseCmd cmd = commands.Dequeue();
                            ProcessCommand(cmd);
                            if (commands.Any())
                            {
                                notify.SetBits((UInt32)Events.CommandRecieved);
                            }
                        }
                    }
                    break;
                }


                if (actState != nextState)
                {
                    notify.SetBits((UInt32)Events.StateChanged);
                    prevState = actState;
                    actState  = nextState;
                    Console.WriteLine($"{this.GetType().Name}: State change '{prevState}' => {actState}");
                }
            }
        }