Beispiel #1
0
 /**
  *  ClientUser's constructor - Create an ClientUser instance
  *  @param  _id        The user's id.
  *  @param  _username  The user's name.
  *  @param  _position  The user's position.
  */
 public ClientUser(int _id, string _username, ClientPosition _position)
 {
     Id        = _id;
     Username  = _username;
     Position  = _position;
     CardsList = new Deck();
     Score     = 0;
     IsPlaying = false;
 }
Beispiel #2
0
        /// <summary>
        /// Extended GetPixel method
        /// <param name="position">Signal pixel position</param>
        /// <returns>RGB value</returns>
        /// </summary>
        public int GetPixel(ClientPosition position)
        {
            Point point = TranslatePosition(position);

            point.Offset(ClientToScreen);
            WoWDC dc = new WoWDC();

            return(dc.CaptureAndGetPixel(point.X, point.Y));
        }
Beispiel #3
0
        /// <summary>
        /// Wait until the pixel matches predefined color or timeout
        /// <param name="position">Client position.</param>
        /// <param name="timeout">Timeout in milliseconds, wait infinitely if this parameter is 0..</param>
        /// <returns>Return RGB value if matches, -1 otherwise.</returns>
        /// </summary>
        public int WaitForKnownPixel(ClientPosition position, int timeout)
        {
            Point point = TranslatePosition(position);

            point.Offset(ClientToScreen);
            WoWDC dc = new WoWDC();

            return(dc.WaitForKnownPixel(point.X, point.Y, timeout));
        }
Beispiel #4
0
        /// <summary>
        /// Translate a position into client coordinates
        /// <param name="position">Position</param>
        /// <returns>Client coordinates</returns>
        /// </summary>
        public Point TranslatePosition(ClientPosition position)
        {
            Point point = new Point(0, 0);

            switch (position)
            {
            case ClientPosition.TopLeft:
                point.X = 0;
                point.Y = 0;
                break;

            case ClientPosition.Top:
                point.X = ClientRect.Width / 2;
                point.Y = 0;
                break;

            case ClientPosition.TopRight:
                point.X = ClientRect.Width - 1;
                point.Y = 0;
                break;

            case ClientPosition.Right:
                point.X = ClientRect.Width - 1;
                point.Y = ClientRect.Height / 2;
                break;

            case ClientPosition.BottomRight:
                point.X = ClientRect.Width - 1;
                point.Y = ClientRect.Height - 1;
                break;

            case ClientPosition.Bottom:
                point.X = ClientRect.Width / 2;
                point.Y = ClientRect.Height - 1;
                break;

            case ClientPosition.BottomLeft:
                point.X = 0;
                point.Y = ClientRect.Height - 1;
                break;

            case ClientPosition.Left:
                point.X = 0;
                point.Y = ClientRect.Height / 2;
                break;

            case ClientPosition.Center:
                point.X = ClientRect.Width / 2;
                point.Y = ClientRect.Height / 2;
                break;

            default:
                break;
            }

            return(point);
        }
Beispiel #5
0
        public void Close()
        {
            if (!_isUsing)
            {
                return;
            }
            StorySceneCheckerPanelHideMessage message = new StorySceneCheckerPanelHideMessage();

            _connection.SendMessage(message);
            _position = ClientPosition.OBSERVER;
            _isUsing  = false;
        }
        private void Join(byte[] data, EndPoint sender)
        {
            if (OneShotJoin == true)
            {
                byte[] StartedAlready = new byte[1];
                StartedAlready[0] = 161;
                transport.Send(StartedAlready, sender);
            }
            else if (idCounter < 8)
            {
                idCounter++;
                if (!ClientsTable.ContainsKey(sender))
                {
                    ClientsTable.Add(sender, idCounter);
                    ClientPosition.Add(idCounter, playersInfo);
                    ClientAlive.Add(idCounter, 1);
                }
                byte[] ResponsePacketPosition = new byte[17];
                ResponsePacketPosition[0] = 2;

                byte[] id;
                byte[] joinPositionX;
                byte[] joinPositionY;
                byte[] joinPositionZ;

                id = BitConverter.GetBytes(idCounter);
                if (idCounter % 2 == 0)
                {
                    joinPositionX         = BitConverter.GetBytes(1f);
                    joinPositionY         = BitConverter.GetBytes(3.77f);
                    joinPositionZ         = BitConverter.GetBytes(-2f - spawnPositionCounter);
                    spawnPositionCounter += 2f;
                }
                else
                {
                    joinPositionX = BitConverter.GetBytes(-1.5f);
                    joinPositionY = BitConverter.GetBytes(3.77f);
                    joinPositionZ = BitConverter.GetBytes(-2f - spawnPositionCounter);
                }
                Buffer.BlockCopy(id, 0, ResponsePacketPosition, 1, 4);
                Buffer.BlockCopy(joinPositionX, 0, ResponsePacketPosition, 5, 4);
                Buffer.BlockCopy(joinPositionY, 0, ResponsePacketPosition, 9, 4);
                Buffer.BlockCopy(joinPositionZ, 0, ResponsePacketPosition, 13, 4);
                transport.Send(ResponsePacketPosition, sender);
            }
            else
            {
                byte[] tooManyPlayers = new byte[1];
                tooManyPlayers[0] = 162;
                transport.Send(tooManyPlayers, sender);
            }
        }
 public void KeepAlive()
 {
     keepAliveTimer += 0.005f;
     if (keepAliveTimer >= 3)
     {
         foreach (var item in ClientAlive)
         {
             if (item.Value == 0)
             {
                 foreach (var item2 in ClientsTable)
                 {
                     if (item.Key != item2.Value)
                     {
                         byte[] DestroyThisPlayer = new byte[5];
                         DestroyThisPlayer[0] = 88;
                         byte[] id = BitConverter.GetBytes(item.Key);
                         Buffer.BlockCopy(id, 0, DestroyThisPlayer, 1, 4);
                         transport.Send(DestroyThisPlayer, item2.Key);
                     }
                     else
                     {
                         PlayerToDestroyEndPoint = item2.Key;
                     }
                 }
                 PlayerToDestroyID = item.Key;
                 DictionaryRemover = true;
             }
         }
         if (DictionaryRemover)
         {
             ClientAlive.Remove(PlayerToDestroyID);
             ClientsTable.Remove(PlayerToDestroyEndPoint);
             ClientPosition.Remove(PlayerToDestroyID);
             //idCounter--;
             if (OneShotReady)
             {
                 ReadyCounter--;
             }
             DictionaryRemover = false;
         }
         foreach (var item in ClientsTable)
         {
             ClientAlive[item.Value] = 0;
             byte[] keepAlive = new byte[1];
             keepAlive[0] = 18;
             transport.Send(keepAlive, item.Key);
         }
         keepAliveTimer = 0;
     }
 }
Beispiel #8
0
        public AboutViewModel()
        {
            _info    = SumericsInfo.FromCurrentAssembly();
            _gps     = new Gps();
            _compass = new Compass();
            _client  = new ClientPosition
            {
                Direction = _compass.CurrentHeading.Magnetic,
                Latitude  = _gps.CurrentLocation.Latitude,
                Longitude = _gps.CurrentLocation.Longitude
            };

            _gps.Changed     += PositionChanged;
            _compass.Changed += DirectionChanged;
        }
Beispiel #9
0
        public void Open(Character initiative, Character passive, ClientPosition clientState)
        {
            if (_isUsing)
            {
                return;
            }
            StorySceneCheckerPanelShowMessage message = new StorySceneCheckerPanelShowMessage();

            message.initiativeCharacterID = initiative.ID;
            message.initiativeView        = initiative.View;
            message.passiveCharacterID    = passive.ID;
            message.passiveView           = passive.View;
            message.playerState           = (int)(_position = clientState);
            _connection.SendMessage(message);
            _isUsing = true;
        }
        private void UpdatePlayerPosition(byte[] data, EndPoint sender)
        {
            ID = BitConverter.ToUInt32(data, 1);
            float x    = BitConverter.ToSingle(data, 5);
            float y    = BitConverter.ToSingle(data, 9);
            float z    = BitConverter.ToSingle(data, 13);
            float rotY = BitConverter.ToSingle(data, 17);

            playersInfo = new float[4] {
                x, y, z, rotY
            };
            if (ClientPosition.ContainsKey(ID))
            {
                ClientPosition[ID][0] = playersInfo[0];
                ClientPosition[ID][1] = playersInfo[1];
                ClientPosition[ID][2] = playersInfo[2];
                ClientPosition[ID][3] = playersInfo[3];
            }
        }
 public override string ToString()
 {
     return(Button.ToString() + ": " + ClientPosition.ToString());
 }
Beispiel #12
0
        public static PositionsCSVDTO GetPositions(string positionsCSV)
        {
            Dictionary <string, List <ClientPosition> > firmPositions = new Dictionary <string, List <ClientPosition> >();
            Dictionary <string, double> todayDSPs = new Dictionary <string, double>();
            Dictionary <string, double> prevDSPs  = new Dictionary <string, double>();

            bool   firmsRow    = false;
            string currentFirm = null;

            using (var reader = new StreamReader(positionsCSV))
            {
                List <string> listA = new List <string>();
                int           i     = 0;
                while (!reader.EndOfStream)
                {
                    var line   = reader.ReadLine();
                    var values = line.Split(',');


                    if (i == 0)
                    {
                        i++;
                        continue;
                    }

                    if (!firmsRow)
                    {
                        if (line.StartsWith(_ROW_FIRM))
                        {
                            currentFirm = line.Split(',')[0].Replace(_ROW_FIRM, "").Trim();

                            List <ClientPosition> positions = new List <ClientPosition>();

                            if (!firmPositions.ContainsKey(currentFirm))
                            {
                                firmsRow = true;
                                firmPositions.Add(currentFirm, positions);
                            }
                            else
                            {
                                throw new Exception(string.Format("Repetated firm positions secion: {0}", currentFirm));
                            }
                        }
                        else
                        {
                            if (currentFirm != null)
                            {
                                string symbol = values[2];
                                //read positions row and add it to the firmPositions dict
                                ClientPosition position = new ClientPosition()
                                {
                                    Symbol    = symbol,
                                    Contracts = values[5] != _EMPTY_CELL?Convert.ToInt32(values[5]) : 0,
                                                    MarginFunded = true,
                                                    Msg          = "ClientPosition",
                                                    Price        = values[7] != _EMPTY_CELL?Convert.ToDouble(values[7]) : 0
                                };

                                if (!todayDSPs.ContainsKey(symbol) && values[8] != _EMPTY_CELL)
                                {
                                    todayDSPs.Add(symbol, Convert.ToDouble(values[8]));
                                }

                                if (!prevDSPs.ContainsKey(symbol) && values[6] != _EMPTY_CELL)
                                {
                                    prevDSPs.Add(symbol, Convert.ToDouble(values[6]));
                                }

                                firmPositions[currentFirm].Add(position);
                            }
                        }
                    }
                    else
                    {
                        firmsRow = false;
                    }
                }
            }

            return(new PositionsCSVDTO()
            {
                FirmPositions = firmPositions, PrevDSPs = prevDSPs, TodayDSPs = todayDSPs
            });
        }