Exemplo n.º 1
0
    void onTime(NetworkMessage msg)
    {
        Log.i("LanClient onTime", Log.Tag.Net);
        MsgTime m     = msg.ReadMessage <MsgTime> ();
        long    delay = (System.DateTime.UtcNow.Ticks - m.clientUtcNs) / 2;

        RTime.R.syncServerTime(m.serverUtcNs + delay, m.serverLocalNs + delay, false);
    }
Exemplo n.º 2
0
    void onTime(NetworkMessage msg)
    {
        Log.i("LanHost onTime", Log.Tag.Net);
        MsgTime m = msg.ReadMessage <MsgTime> ();

        m.serverUtcNs   = System.DateTime.UtcNow.Ticks;
        m.serverLocalNs = System.DateTime.Now.Ticks;
        sendTo(msg.conn.connectionId, (short)MyMsgId.Time, m);
    }
Exemplo n.º 3
0
    void onConnected(NetworkMessage msg)
    {
        mConn = msg.conn;
        mConn.SetMaxDelay(0.01f);
        startPing();

        //请求同步时间
        MsgTime m = new MsgTime();

        m.clientUtcNs = System.DateTime.UtcNow.Ticks;
        sendMsg((short)MyMsgId.Time, m);
    }
Exemplo n.º 4
0
        //加载DAtisMsg
        public void LoadDAtisMsg(string filePath)
        {
            try
            {
                string[] msgContents = File.ReadAllLines(filePath);
                //标准格式为5行

                /* [ATIS ARR]
                 *   Time=2011-06-21 05:13:09
                 *   Order=F
                 *   Temperature=40
                 *   QNH=1000
                 * */

                /*[ATIS DEP]
                 *  Time=2011-06-21 05:08:53
                 *  Order=E
                 *  Temperature=40
                 *  QNH=1000*/
                if (msgContents.Length > 0)
                {
                    int valueCount = 0;
                    for (int i = 0; i < msgContents.Length; i++)
                    {
                        if (msgContents[i] != null && msgContents[i].Length > 0)
                        {
                            //解析类型
                            if (msgContents[i].Contains("ATIS"))
                            {
                                if (msgContents[i].Contains("ARR"))
                                {
                                    this.Type = "ARR";
                                    valueCount++;
                                }
                                else
                                {
                                    if (msgContents[i].Contains("DEP"))
                                    {
                                        this.Type = "DEP";
                                        valueCount++;
                                    }
                                    else
                                    {
                                        throw new Exception("DAtis数据文件msg类型异常,请检查数据文件!");
                                    }
                                }
                            }
                            //解析时间
                            if (msgContents[i].Contains("Time"))
                            {
                                string[] timeValueStrs = msgContents[i].Split('=');
                                if (timeValueStrs.Length > 1 && timeValueStrs[1] != null)
                                {
                                    this.MsgTime = timeValueStrs[1];

                                    if (MsgTime != null)
                                    {
                                        string[] timestrs = MsgTime.Split(':');
                                        if (timestrs.Length > 2)
                                        {
                                            this.MsgTimeShort = timestrs[0].Substring(timestrs[0].Length - 2, 2) + timestrs[1];
                                        }
                                        else
                                        {
                                            throw new Exception("DAtis数据文件msg 时间 异常,请检查数据文件!");
                                        }
                                    }

                                    valueCount++;
                                }
                                else
                                {
                                    throw new Exception("DAtis数据文件msg 时间 异常,请检查数据文件!");
                                }
                            }

                            //解析版本
                            if (msgContents[i].Contains("Order"))
                            {
                                string[] orderValueStrs = msgContents[i].Split('=');
                                if (orderValueStrs.Length > 1 && orderValueStrs[1] != null)
                                {
                                    this.Order = orderValueStrs[1];
                                    valueCount++;
                                }
                                else
                                {
                                    throw new Exception("DAtis数据文件msg版本 异常,请检查数据文件!");
                                }
                            }
                            //解析场压
                            if (msgContents[i].Contains("QNH"))
                            {
                                string[] QNHValueStrs = msgContents[i].Split('=');
                                if (QNHValueStrs.Length > 1 && QNHValueStrs[1] != null)
                                {
                                    this.QNH = QNHValueStrs[1];
                                    valueCount++;
                                }
                                else
                                {
                                    throw new Exception("DAtis数据文件msg QNH 异常,请检查数据文件!");
                                }
                            }
                        }
                    }

                    if (!(valueCount == 4))
                    {
                        throw new Exception("DAtis数据文件属性不足4项,请检查数据文件!");
                    }
                }
                else
                {
                    throw new Exception("DAtis数据文件为空,请检查数据文件!");
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }